diff options
Diffstat (limited to 'app/IR.hs')
| -rw-r--r-- | app/IR.hs | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -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 |
