summaryrefslogtreecommitdiff
path: root/app/Interpreter.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2022-11-11 22:10:26 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2022-11-11 22:10:26 +0100
commitfe6666d204c0728b4556574ddc184bc46013b193 (patch)
treef0e33f3d379ce562c02620660ebdbd1fcb870fe7 /app/Interpreter.hs
parent5d186de9c8483b4de749459fda9c507c68f8fa73 (diff)
downloadprlg-fe6666d204c0728b4556574ddc184bc46013b193.tar.gz
prlg-fe6666d204c0728b4556574ddc184bc46013b193.tar.bz2
looks like vars work
Diffstat (limited to 'app/Interpreter.hs')
-rw-r--r--app/Interpreter.hs39
1 files changed, 13 insertions, 26 deletions
diff --git a/app/Interpreter.hs b/app/Interpreter.hs
index 6a80232..b42f079 100644
--- a/app/Interpreter.hs
+++ b/app/Interpreter.hs
@@ -25,7 +25,7 @@ data Id =
data Datum
= Atom Int -- unifies a constant
| Struct Id -- unifies a structure with arity
- | VoidVar -- in code this unifies with anything; everywhere else this is an unbound variable
+ | VoidRef -- in code this unifies with anything; everywhere else this is an unbound variable
| LocalRef Int -- local variable idx
| HeapRef Int -- heap structure idx
deriving (Show, Eq, Ord)
@@ -47,7 +47,7 @@ data Heap =
Heap Int (M.Map Int Datum)
deriving (Show)
-emptyHeap = Heap 1 M.empty
+emptyHeap = Heap 0 M.empty
type Scope = M.Map Int Int
@@ -154,35 +154,22 @@ proveStep c f i = go i
m'
in cont (map HeapRef $ tail addrs) (Heap nxt' m'')
{- simple cases first -}
- unify VoidVar VoidVar = uok
+ unify VoidRef VoidRef = uok
unify (Atom a) (Atom b)
| a == b = uok
- unify VoidVar (Atom _) = uok
- unify (Atom _) VoidVar = uok
+ unify VoidRef (Atom _) = uok
+ unify (Atom _) VoidRef = uok
unify (Struct a) (Struct b)
| a == b = uok
{- unifying a struct with void must cause us to skip the void -}
- unify VoidVar (Struct Id {arity = a}) =
- c i {cur = cur {hed = replicate a (U VoidVar) ++ hs, gol = gs}}
- unify (Struct Id {arity = a}) VoidVar =
- c i {cur = cur {hed = hs, gol = replicate a (U VoidVar) ++ gs}}
+ unify VoidRef (Struct Id {arity = a}) =
+ c i {cur = cur {hed = replicate a (U VoidRef) ++ hs, gol = gs}}
+ unify (Struct Id {arity = a}) VoidRef =
+ c i {cur = cur {hed = hs, gol = replicate a (U VoidRef) ++ gs}}
{- handle local refs; first ignore their combination with voids to save memory -}
- unify (LocalRef _) VoidVar = uok
- unify VoidVar (LocalRef _) = uok
+ unify (LocalRef _) VoidRef = uok
+ unify VoidRef (LocalRef _) = uok
{- allocate heap for LocalRefs and retry with HeapRefs -}
- unify (LocalRef hv) (LocalRef gv) =
- allocLocal gv (gvar cur) $ \gvar' heap' addr ->
- c
- i
- { cur =
- cur
- { hed = U (HeapRef addr) : hs
- , hvar = M.insert hv addr (hvar cur)
- , gol = U (HeapRef addr) : gs
- , gvar = gvar'
- , heap = heap'
- }
- }
unify (LocalRef hv) _ =
allocLocal hv (hvar cur) $ \hvar' heap' addr ->
c
@@ -200,8 +187,8 @@ proveStep c f i = go i
{gol = U (HeapRef addr) : gs, gvar = gvar', heap = heap'}
}
{- handle heap refs; first ignore their combination with voids again -}
- unify (HeapRef _) VoidVar = uok
- unify VoidVar (HeapRef _) = uok
+ unify (HeapRef _) VoidRef = uok
+ unify VoidRef (HeapRef _) = uok
{- actual HeapRefs, these are dereferenced and then unified; decide between copying and linking -}
unify (HeapRef hr') g =
case deref hr' of