blob: 7ede4c222835f608923fcb2b23471a5ed5b76097 (
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
|
module Env where
import qualified Code
import Control.Monad.IO.Class
import Control.Monad.Trans.State.Lazy
import qualified IR
import qualified Operators
import System.Console.Haskeline
data PrlgState =
PrlgState
{ defs :: Code.Defs
, ops :: Operators.Ops
, strtable :: IR.StrTable
}
deriving (Show)
type PrlgEnv a = StateT PrlgState (InputT IO) a
withStrTable :: (IR.StrTable -> (IR.StrTable, a)) -> PrlgEnv a
withStrTable f = do
st <- gets strtable
let (st', x) = f st
modify (\s -> s {strtable = st'})
return x
findStruct :: String -> Int -> PrlgEnv IR.Id
findStruct str arity = do
stri <- findAtom str
return IR.Id {IR.str = stri, IR.arity = arity}
findAtom :: String -> PrlgEnv Int
findAtom = withStrTable . flip IR.strtablize
|