module DSL.Types where import DSL.BaseParsers (Parser(..)) data StackData = StackInt Integer | StackBool Bool deriving (Eq) instance Show StackData where show (StackInt x) = show x show (StackBool True) = "true" show (StackBool False) = "false" type TypeCheck = StackData -> Bool type Stack = [StackData] data Intrinsic -- core stack operations = I_DUMP | I_DROP | I_SWAP | I_DUP | I_OVER | I_ROT -- core arithmetic operations | I_PLUS | I_MINUS | I_TIMES | I_DIVMOD -- core boolean operations | I_NOT | I_AND | I_OR | I_XOR -- core logical operations | I_EQUAL | I_LESSTHAN | I_GREATERTHAN deriving (Show, Eq) data Operation = OpPushData StackData | OpIntrinsic Intrinsic deriving (Show) data StackModifier = StackModifier { smName :: String , smTypes :: [TypeCheck] , smFunc :: Stack -> IO Stack } data Block = BLinear [Operation] | BIf [Block] [Block] | BIfElse [Block] [Block] [Block] | BWhile [Block] [Block] deriving (Show) type Program = [Block] data Machine = Machine { ok :: Bool , stack :: Stack } data TokenData = T_WHITESPACE | T_IF | T_ELSE | T_WHILE | T_DO | T_END | T_BOOL_LITERAL Bool | T_INT_LITERAL Integer | T_INTRINSIC Intrinsic deriving (Show, Eq) data DSLToken = DSLToken { tStr :: String -- original text , tData :: TokenData -- actual data } deriving (Show) type DSLLexer = Parser Char DSLToken type DSLParser = Parser DSLToken