-
Notifications
You must be signed in to change notification settings - Fork 1
/
Types.hs
46 lines (35 loc) · 1.03 KB
/
Types.hs
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
module Types where
import AbsXYZgrammar
import Data.Map as Map
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Except
data Mode = StdinMode | FileMode
type IdentString = String
type Location = Integer
type Env = Map IdentString Location
data Memory =
IntVar Integer
| BoolVar Bool
| StringVar String
| GenVar (Type, [Stmt], Env)
| FuncDef (Type, [Arg], [Stmt], Env)
| GenDef (Type, [Arg], [Stmt], Env)
deriving Eq
type PState = (Map Location Memory, Location, Mode)
data RuntimeException =
ZeroDivException
| ZeroModException
| NoReturnStmtException
| NoGenResultException
| WrongRefArgException
-- (mem value we need to pass ex. with return, next env)
type Result = (Maybe Memory, Env)
type GenResult = (Maybe Memory, [Stmt], Env)
-- Main monad holds env and state using Exception
type PStateMonad = ReaderT Env (StateT PState (ExceptT RuntimeException IO))
-- Show for Memory
instance Show Memory where
show (IntVar i) = show i
show (BoolVar b) = show b
show (StringVar s) = s