summaryrefslogtreecommitdiff
path: root/app/IR.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2022-11-26 13:35:19 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2022-11-26 13:35:19 +0100
commita26f0f29c02bfb4ec56781397d60abeb498b8c12 (patch)
tree9c351e8d2283a8b2564ea770ca0d42d2c4d30701 /app/IR.hs
parent58367975aed706172487727330670d62fcb0e6d1 (diff)
downloadprlg-a26f0f29c02bfb4ec56781397d60abeb498b8c12.tar.gz
prlg-a26f0f29c02bfb4ec56781397d60abeb498b8c12.tar.bz2
massive cleanup
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