summaryrefslogtreecommitdiff
path: root/DSL/Types.hs
blob: 7bd9f56a665aff5dd2c0b78b1cf843a3d9b3ef8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
module DSL.Types where

import DSL.BaseParsers (Parser(..))

data StackData
  = StackInt Integer
  | StackBool Bool
  | StackString String
    deriving (Eq)

instance Show StackData where
  show (StackInt x)      = show x
  show (StackBool True)  = "true"
  show (StackBool False) = "false"
  show (StackString s)   = show s

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 string operations
  | I_STRCAT
  -- core logical operations
  | I_EQUAL
  | I_LESSTHAN
  | I_GREATERTHAN
    deriving (Show, Eq)

type ProcName = String

data Operation
  = OpPushData StackData
  | OpIntrinsic Intrinsic
  | OpCall ProcName
    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 ProcSpec = (ProcName, [Block])

type Program = [Block]

data Machine = Machine { ok :: Bool
                       , stack :: Stack
                       , pTable :: [(ProcName, [Block])]
                       }

data TokenTag
  = T_WHITESPACE
  | T_PROC
  | T_IF
  | T_ELSE
  | T_WHILE
  | T_DO
  | T_END
  | T_INT_LITERAL
  | T_BOOL_LITERAL
  | T_STRING_LITERAL
  | T_INTRINSIC Intrinsic
  | T_IDENTIFIER
    deriving (Show, Eq)

data Token = Token { tStr :: String -- original text
                   , tTag :: TokenTag -- actual data
                   } deriving (Show)

type DSLLexer  = Parser Char Token
type DSLParser = Parser Token