diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-02-16 23:05:24 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-02-16 23:05:24 +1300 |
| commit | b83325c4b5c324a42acfe366cf58b455f8aa941f (patch) | |
| tree | 7c78add5c12970ebd3f3c50f08808a4d6a636778 /DSL/Types.hs | |
| parent | ea59151d80958f14c69105ba6b40162b8e191597 (diff) | |
Big file-structure refactor
Diffstat (limited to 'DSL/Types.hs')
| -rw-r--r-- | DSL/Types.hs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/DSL/Types.hs b/DSL/Types.hs new file mode 100644 index 0000000..2c33aad --- /dev/null +++ b/DSL/Types.hs @@ -0,0 +1,84 @@ +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 + |
