summaryrefslogtreecommitdiff
path: root/app/Interpreter.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2022-11-04 17:56:31 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2022-11-04 17:56:31 +0100
commit8f47919624f0153ff9afa299d994d66bb63037ef (patch)
tree6e85d5586f580bdee56e85770adeb51852a2e858 /app/Interpreter.hs
parent14b77cd058ad3780d73df8bb41be946599150d18 (diff)
downloadprlg-8f47919624f0153ff9afa299d994d66bb63037ef.tar.gz
prlg-8f47919624f0153ff9afa299d994d66bb63037ef.tar.bz2
better shunting errors
Diffstat (limited to 'app/Interpreter.hs')
-rw-r--r--app/Interpreter.hs22
1 files changed, 15 insertions, 7 deletions
diff --git a/app/Interpreter.hs b/app/Interpreter.hs
index 7df773e..76cef52 100644
--- a/app/Interpreter.hs
+++ b/app/Interpreter.hs
@@ -6,7 +6,7 @@ import qualified Data.Map as M
{- VAM 2P, done the lazy way -}
data StrTable =
StrTable Int (M.Map String Int) (M.Map Int String)
- deriving Show
+ deriving (Show)
emptystrtable = StrTable 0 M.empty M.empty
@@ -15,12 +15,17 @@ strtablize t@(StrTable nxt fwd rev) str =
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 Id =
+ Id
+ { str :: Int
+ , arity :: Int
+ }
+ deriving (Show, Eq, Ord)
data Datum
= Atom Int -- unifies a constant
| Struct Id -- unifies a structure with arity
- -- | VoidVar -- unifies with anything
+ | 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)
deriving (Show, Eq, Ord)
@@ -89,10 +94,13 @@ proveStep c f i = go i
= unify a b
where
uok = c i {cur = cur {hed = hs, gol = gs}}
- unify (Atom a) (Atom b)
- | a == b = uok
- unify (Struct a) (Struct b)
- | a == b = uok
+ unify VoidVar VoidVar = uok
+ unify (Atom a) (Atom b) | a == b = uok
+ unify VoidVar (Atom _) = uok
+ unify (Atom _) VoidVar = uok
+ unify (Struct a) (Struct b) | a == b = uok
+ 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 _ _ = backtrack i
{- Resulution -}
go i@Interp { cur = cur@Cho {hed = hed, gol = gol, stk = stk, cut = cut}