From 60ff47250b5064c38b8f4889766696cb4a5683b0 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Wed, 14 Dec 2022 19:47:41 +0100 Subject: slight cleanup, metacall --- app/Code.hs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'app/Code.hs') 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 -- cgit v1.2.3