{-# LINE 1 "src/Data/Emacs/Module/Env/Functions.hsc" #-}
----------------------------------------------------------------------------
-- |
-- Module      :  Data.Emacs.Module.Env.Functions
-- Copyright   :  (c) Sergey Vinokurov 2018
-- License     :  Apache-2.0 (see LICENSE)
-- Maintainer  :  serg.foo@gmail.com
----------------------------------------------------------------------------

module Data.Emacs.Module.Env.Functions
  ( FuncallExit(..)
  , funcallExitToNum
  , funcallExitFromNum
  , foldFuncallExitFromNum
  ) where

import Data.Data (Data)
import Language.Haskell.TH.Syntax (Lift)
import Prettyprinter.Generics



-- | Possible Emacs function call outcomes. This is Haskell's version of
data FuncallExit a
  = -- | Function has returned normally.
    FuncallExitReturn
  | -- | Function has signaled an error using @signal@.
    FuncallExitSignal a
  | -- | Function has exit using @throw@.
    FuncallExitThrow a
  deriving (FuncallExit a -> FuncallExit a -> Bool
forall a. Eq a => FuncallExit a -> FuncallExit a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FuncallExit a -> FuncallExit a -> Bool
$c/= :: forall a. Eq a => FuncallExit a -> FuncallExit a -> Bool
== :: FuncallExit a -> FuncallExit a -> Bool
$c== :: forall a. Eq a => FuncallExit a -> FuncallExit a -> Bool
Eq, FuncallExit a -> FuncallExit a -> Bool
FuncallExit a -> FuncallExit a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (FuncallExit a)
forall a. Ord a => FuncallExit a -> FuncallExit a -> Bool
forall a. Ord a => FuncallExit a -> FuncallExit a -> Ordering
forall a. Ord a => FuncallExit a -> FuncallExit a -> FuncallExit a
min :: FuncallExit a -> FuncallExit a -> FuncallExit a
$cmin :: forall a. Ord a => FuncallExit a -> FuncallExit a -> FuncallExit a
max :: FuncallExit a -> FuncallExit a -> FuncallExit a
$cmax :: forall a. Ord a => FuncallExit a -> FuncallExit a -> FuncallExit a
>= :: FuncallExit a -> FuncallExit a -> Bool
$c>= :: forall a. Ord a => FuncallExit a -> FuncallExit a -> Bool
> :: FuncallExit a -> FuncallExit a -> Bool
$c> :: forall a. Ord a => FuncallExit a -> FuncallExit a -> Bool
<= :: FuncallExit a -> FuncallExit a -> Bool
$c<= :: forall a. Ord a => FuncallExit a -> FuncallExit a -> Bool
< :: FuncallExit a -> FuncallExit a -> Bool
$c< :: forall a. Ord a => FuncallExit a -> FuncallExit a -> Bool
compare :: FuncallExit a -> FuncallExit a -> Ordering
$ccompare :: forall a. Ord a => FuncallExit a -> FuncallExit a -> Ordering
Ord, Int -> FuncallExit a -> ShowS
forall a. Show a => Int -> FuncallExit a -> ShowS
forall a. Show a => [FuncallExit a] -> ShowS
forall a. Show a => FuncallExit a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FuncallExit a] -> ShowS
$cshowList :: forall a. Show a => [FuncallExit a] -> ShowS
show :: FuncallExit a -> String
$cshow :: forall a. Show a => FuncallExit a -> String
showsPrec :: Int -> FuncallExit a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> FuncallExit a -> ShowS
Show, FuncallExit a -> DataType
FuncallExit a -> Constr
forall {a}. Data a => Typeable (FuncallExit a)
forall a. Data a => FuncallExit a -> DataType
forall a. Data a => FuncallExit a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> FuncallExit a -> FuncallExit a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> FuncallExit a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> FuncallExit a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FuncallExit a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FuncallExit a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> FuncallExit a -> m (FuncallExit a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> FuncallExit a -> m (FuncallExit a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (FuncallExit a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FuncallExit a -> c (FuncallExit a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (FuncallExit a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (FuncallExit a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (FuncallExit a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FuncallExit a -> c (FuncallExit a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (FuncallExit a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> FuncallExit a -> m (FuncallExit a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> FuncallExit a -> m (FuncallExit a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> FuncallExit a -> m (FuncallExit a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> FuncallExit a -> m (FuncallExit a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> FuncallExit a -> m (FuncallExit a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> FuncallExit a -> m (FuncallExit a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FuncallExit a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> FuncallExit a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> FuncallExit a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> FuncallExit a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FuncallExit a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FuncallExit a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FuncallExit a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FuncallExit a -> r
gmapT :: (forall b. Data b => b -> b) -> FuncallExit a -> FuncallExit a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> FuncallExit a -> FuncallExit a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (FuncallExit a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (FuncallExit a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (FuncallExit a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (FuncallExit a))
dataTypeOf :: FuncallExit a -> DataType
$cdataTypeOf :: forall a. Data a => FuncallExit a -> DataType
toConstr :: FuncallExit a -> Constr
$ctoConstr :: forall a. Data a => FuncallExit a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (FuncallExit a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (FuncallExit a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FuncallExit a -> c (FuncallExit a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FuncallExit a -> c (FuncallExit a)
Data, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (FuncallExit a) x -> FuncallExit a
forall a x. FuncallExit a -> Rep (FuncallExit a) x
$cto :: forall a x. Rep (FuncallExit a) x -> FuncallExit a
$cfrom :: forall a x. FuncallExit a -> Rep (FuncallExit a) x
Generic, forall a (m :: * -> *). (Lift a, Quote m) => FuncallExit a -> m Exp
forall a (m :: * -> *).
(Lift a, Quote m) =>
FuncallExit a -> Code m (FuncallExit a)
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => FuncallExit a -> m Exp
forall (m :: * -> *).
Quote m =>
FuncallExit a -> Code m (FuncallExit a)
liftTyped :: forall (m :: * -> *).
Quote m =>
FuncallExit a -> Code m (FuncallExit a)
$cliftTyped :: forall a (m :: * -> *).
(Lift a, Quote m) =>
FuncallExit a -> Code m (FuncallExit a)
lift :: forall (m :: * -> *). Quote m => FuncallExit a -> m Exp
$clift :: forall a (m :: * -> *). (Lift a, Quote m) => FuncallExit a -> m Exp
Lift, forall a b. a -> FuncallExit b -> FuncallExit a
forall a b. (a -> b) -> FuncallExit a -> FuncallExit b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> FuncallExit b -> FuncallExit a
$c<$ :: forall a b. a -> FuncallExit b -> FuncallExit a
fmap :: forall a b. (a -> b) -> FuncallExit a -> FuncallExit b
$cfmap :: forall a b. (a -> b) -> FuncallExit a -> FuncallExit b
Functor, forall a. Eq a => a -> FuncallExit a -> Bool
forall a. Num a => FuncallExit a -> a
forall a. Ord a => FuncallExit a -> a
forall m. Monoid m => FuncallExit m -> m
forall a. FuncallExit a -> Bool
forall a. FuncallExit a -> Int
forall a. FuncallExit a -> [a]
forall a. (a -> a -> a) -> FuncallExit a -> a
forall m a. Monoid m => (a -> m) -> FuncallExit a -> m
forall b a. (b -> a -> b) -> b -> FuncallExit a -> b
forall a b. (a -> b -> b) -> b -> FuncallExit a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => FuncallExit a -> a
$cproduct :: forall a. Num a => FuncallExit a -> a
sum :: forall a. Num a => FuncallExit a -> a
$csum :: forall a. Num a => FuncallExit a -> a
minimum :: forall a. Ord a => FuncallExit a -> a
$cminimum :: forall a. Ord a => FuncallExit a -> a
maximum :: forall a. Ord a => FuncallExit a -> a
$cmaximum :: forall a. Ord a => FuncallExit a -> a
elem :: forall a. Eq a => a -> FuncallExit a -> Bool
$celem :: forall a. Eq a => a -> FuncallExit a -> Bool
length :: forall a. FuncallExit a -> Int
$clength :: forall a. FuncallExit a -> Int
null :: forall a. FuncallExit a -> Bool
$cnull :: forall a. FuncallExit a -> Bool
toList :: forall a. FuncallExit a -> [a]
$ctoList :: forall a. FuncallExit a -> [a]
foldl1 :: forall a. (a -> a -> a) -> FuncallExit a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> FuncallExit a -> a
foldr1 :: forall a. (a -> a -> a) -> FuncallExit a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> FuncallExit a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> FuncallExit a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> FuncallExit a -> b
foldl :: forall b a. (b -> a -> b) -> b -> FuncallExit a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> FuncallExit a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> FuncallExit a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> FuncallExit a -> b
foldr :: forall a b. (a -> b -> b) -> b -> FuncallExit a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> FuncallExit a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> FuncallExit a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> FuncallExit a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> FuncallExit a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> FuncallExit a -> m
fold :: forall m. Monoid m => FuncallExit m -> m
$cfold :: forall m. Monoid m => FuncallExit m -> m
Foldable, Functor FuncallExit
Foldable FuncallExit
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
FuncallExit (m a) -> m (FuncallExit a)
forall (f :: * -> *) a.
Applicative f =>
FuncallExit (f a) -> f (FuncallExit a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FuncallExit a -> m (FuncallExit b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FuncallExit a -> f (FuncallExit b)
sequence :: forall (m :: * -> *) a.
Monad m =>
FuncallExit (m a) -> m (FuncallExit a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
FuncallExit (m a) -> m (FuncallExit a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FuncallExit a -> m (FuncallExit b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FuncallExit a -> m (FuncallExit b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
FuncallExit (f a) -> f (FuncallExit a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
FuncallExit (f a) -> f (FuncallExit a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FuncallExit a -> f (FuncallExit b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FuncallExit a -> f (FuncallExit b)
Traversable)

instance Pretty a => Pretty (FuncallExit a) where
  pretty :: forall ann. FuncallExit a -> Doc ann
pretty = forall a ann. (Generic a, GPretty (Rep a)) => a -> Doc ann
ppGeneric

{-# INLINE funcallExitToNum #-}
funcallExitToNum :: Num a => FuncallExit b -> a
funcallExitToNum :: forall a b. Num a => FuncallExit b -> a
funcallExitToNum = \case
  FuncallExit b
FuncallExitReturn   -> (a
0)
{-# LINE 39 "src/Data/Emacs/Module/Env/Functions.hsc" #-}
  FuncallExitSignal{} -> (1)
{-# LINE 40 "src/Data/Emacs/Module/Env/Functions.hsc" #-}
  FuncallExitThrow{}  -> (2)
{-# LINE 41 "src/Data/Emacs/Module/Env/Functions.hsc" #-}

{-# INLINE funcallExitFromNum #-}
funcallExitFromNum :: (Eq a, Num a) => a -> Maybe (FuncallExit ())
funcallExitFromNum :: forall a. (Eq a, Num a) => a -> Maybe (FuncallExit ())
funcallExitFromNum = \case
  (a
0) -> forall a. a -> Maybe a
Just forall a. FuncallExit a
FuncallExitReturn
{-# LINE 46 "src/Data/Emacs/Module/Env/Functions.hsc" #-}
  (1) -> Just $ FuncallExitSignal ()
{-# LINE 47 "src/Data/Emacs/Module/Env/Functions.hsc" #-}
  (2)  -> Just $ FuncallExitThrow ()
{-# LINE 48 "src/Data/Emacs/Module/Env/Functions.hsc" #-}
  _                                  -> Nothing

{-# INLINE foldFuncallExitFromNum #-}
foldFuncallExitFromNum :: (Eq a, Num a) => a -> b -> (FuncallExit () -> b) -> b
foldFuncallExitFromNum :: forall a b. (Eq a, Num a) => a -> b -> (FuncallExit () -> b) -> b
foldFuncallExitFromNum a
x b
def FuncallExit () -> b
f = case a
x of
  (a
0) -> FuncallExit () -> b
f forall a. FuncallExit a
FuncallExitReturn
{-# LINE 54 "src/Data/Emacs/Module/Env/Functions.hsc" #-}
  (1) -> f $ FuncallExitSignal ()
{-# LINE 55 "src/Data/Emacs/Module/Env/Functions.hsc" #-}
  (2)  -> f $ FuncallExitThrow ()
{-# LINE 56 "src/Data/Emacs/Module/Env/Functions.hsc" #-}
  _                                  -> def