summaryrefslogtreecommitdiff
path: root/app/IR.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/IR.hs')
-rw-r--r--app/IR.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/IR.hs b/app/IR.hs
index fa987e5..ac929fa 100644
--- a/app/IR.hs
+++ b/app/IR.hs
@@ -1,5 +1,6 @@
module IR where
+import Data.List (mapAccumL)
import qualified Data.Map as M
data PrlgStr
@@ -31,3 +32,11 @@ strtablize t@(StrTable nxt fwd rev) str =
case fwd M.!? str of
Just i -> (t, i)
_ -> (StrTable (nxt + 1) (M.insert str nxt fwd) (M.insert nxt str rev), nxt)
+
+internPrlg :: StrTable -> PrlgStr -> (StrTable, PrlgInt)
+internPrlg = go
+ where
+ go t (LiteralS str) = LiteralI <$> strtablize t str
+ go t (CallS str ps) =
+ let (t', i) = strtablize t str
+ in CallI (Id i $ length ps) <$> mapAccumL go t' ps