module Emacs.Type where
import Prelude(Show(..))
import Protolude hiding (show)
import Data.IORef
import GHC.Ptr
import Foreign.C.Types
import Foreign.StablePtr
import Control.Monad.Reader
import Data.Data hiding(typeOf)
data PState = PState
{ symbolMap :: IORef (Map Text GlobalEmacsValue)
}
data Ctx = Ctx
{ pstateStablePtr :: StablePtr PState
, pstate :: PState
, emacsEnv :: EmacsEnv
}
type EmacsM =
ReaderT Ctx IO
data EmacsType = ESymbol
| EInteger
| EFunction
| EString
| ECons
| ENil
deriving (Show, Eq, Data)
emacsTypeSymbolName :: EmacsType -> Text
emacsTypeSymbolName ESymbol = "symbol"
emacsTypeSymbolName EInteger = "integer"
emacsTypeSymbolName EFunction = "function"
emacsTypeSymbolName EString = "string"
emacsTypeSymbolName ECons = "cons"
emacsTypeSymbolName ENil = "nil"
emacsTypes :: [EmacsType]
emacsTypes = fromConstr <$> dataTypeConstrs (dataTypeOf ESymbol)
type EmacsModule = Ptr () -> IO CInt
newtype EmacsEnv = EmacsEnv (Ptr ())
deriving (Storable)
newtype EmacsValue = EmacsValue (Ptr ())
deriving (Storable)
newtype GlobalEmacsValue = GlobalEmacsValue (Ptr ())
deriving (Storable)
castGlobalToEmacsValue :: GlobalEmacsValue -> EmacsValue
castGlobalToEmacsValue (GlobalEmacsValue p) =
EmacsValue p
newtype EmacsSymbol = EmacsSymbol EmacsValue
newtype EmacsKeyword = EmacsKeyword EmacsValue
newtype EmacsCons = EmacsCons EmacsValue
newtype EmacsFunction = EmacsFunction EmacsValue
newtype EmacsList = EmacsList EmacsValue
newtype Symbol = Symbol Text
newtype Keyword = Keyword Text
data Cons = Cons EmacsValue EmacsValue
data EmacsFuncallExit
= EmacsFuncallExitReturn
| EmacsFuncallExitSignal
| EmacsFuncallExitThrow
deriving (Show,Eq,Enum)
data EmacsException
= EmacsException EmacsFuncallExit EmacsValue EmacsValue
instance Show EmacsException where
show (EmacsException funcallExit _ _) =
"EmacsException(" <> show funcallExit <> ")"
instance Exception EmacsException
type EFunctionStub
= EmacsEnv
-> CPtrdiff
-> Ptr (Ptr ())
-> StablePtr PState
-> IO EmacsValue
data InteractiveForm = InteractiveNoArgs
newtype Doc = Doc Text
newtype Arity = Arity Int