diff options
Diffstat (limited to 'app/Interpreter.hs')
| -rw-r--r-- | app/Interpreter.hs | 16 |
1 files changed, 13 insertions, 3 deletions
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 |
