From a26f0f29c02bfb4ec56781397d60abeb498b8c12 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Sat, 26 Nov 2022 13:35:19 +0100 Subject: massive cleanup --- app/IR.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/IR.hs') 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 -- cgit v1.2.3