diff options
Diffstat (limited to 'app/Code.hs')
| -rw-r--r-- | app/Code.hs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/app/Code.hs b/app/Code.hs index 8bea782..0556415 100644 --- a/app/Code.hs +++ b/app/Code.hs @@ -65,14 +65,30 @@ data Interp = type PrlgEnv a = StateT Interp (InputT IO) a -type BuiltinFn = PrlgEnv (Maybe (Either String Bool)) +type InterpFn = PrlgEnv (Maybe (Either String Bool)) data Builtin = - Builtin BuiltinFn + Builtin InterpFn instance Show Builtin where show _ = "Builtin _" +data Dereferenced + = FreeRef Int + | BoundRef Int Datum + | NoRef + +-- TRICKY: HeapRefs alone must not form a cycle other than the FreeRef case. +derefHeap :: Heap -> Int -> Dereferenced +derefHeap h@(Heap _ hmap) x = + case hmap M.!? x of + Just (HeapRef x') -> + if x == x' + then FreeRef x' + else derefHeap h x' + Just x' -> BoundRef x x' + _ -> NoRef + -- TODO are we actually going to use this? codeStruct :: Monad m |
