summaryrefslogtreecommitdiff
path: root/app/Code.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2022-12-14 19:47:41 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2022-12-14 19:47:41 +0100
commit60ff47250b5064c38b8f4889766696cb4a5683b0 (patch)
treeeddd52364cd1b2fbfd7219061a5ed5b9c846711e /app/Code.hs
parent32f6fe0291e289c88d29710e42da3e6aca47a3fa (diff)
downloadprlg-60ff47250b5064c38b8f4889766696cb4a5683b0.tar.gz
prlg-60ff47250b5064c38b8f4889766696cb4a5683b0.tar.bz2
slight cleanup, metacall
Diffstat (limited to 'app/Code.hs')
-rw-r--r--app/Code.hs20
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