From 865d63a103d119e51a4fba3a0d185ff1c6394176 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Sun, 16 Oct 2022 21:49:59 +0200 Subject: some small stuff --- app/Interpreter.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'app/Interpreter.hs') diff --git a/app/Interpreter.hs b/app/Interpreter.hs index 81ecb3d..7df773e 100644 --- a/app/Interpreter.hs +++ b/app/Interpreter.hs @@ -5,11 +5,21 @@ import qualified Data.Map as M {- VAM 2P, done the lazy way -} data StrTable = - StrTable Int (M.Map Int String) + StrTable Int (M.Map String Int) (M.Map Int String) + deriving Show + +emptystrtable = StrTable 0 M.empty M.empty + +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) + +data Id = Id {str::Int,arity::Int} deriving (Show, Eq, Ord) data Datum = Atom Int -- unifies a constant - | Struct (Int, Int) -- unifies a structure with arity + | Struct Id -- unifies a structure with arity -- | VoidVar -- unifies with anything -- | LocalVar Int -- unifies with a local variable (possibly making a new one when it's not in use yet) -- | Ref Int -- unifies with the referenced value on the heap (not to be used in code) @@ -26,7 +36,7 @@ data Instr type Code = [Instr] -type Defs = M.Map (Int, Int) [Code] +type Defs = M.Map Id [Code] data Cho = Cho -- cgit v1.2.3