summaryrefslogtreecommitdiff
path: root/app/Env.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2022-11-12 17:47:51 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2022-11-12 17:47:51 +0100
commitb9633a33182f5b381e912366273709e59f469bb9 (patch)
tree0b7eb7f1e67792253cfaf9caee3a92570ab60407 /app/Env.hs
parentfe6666d204c0728b4556574ddc184bc46013b193 (diff)
downloadprlg-b9633a33182f5b381e912366273709e59f469bb9.tar.gz
prlg-b9633a33182f5b381e912366273709e59f469bb9.tar.bz2
reorg.
Diffstat (limited to 'app/Env.hs')
-rw-r--r--app/Env.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/Env.hs b/app/Env.hs
new file mode 100644
index 0000000..7ede4c2
--- /dev/null
+++ b/app/Env.hs
@@ -0,0 +1,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