summaryrefslogtreecommitdiff
path: root/app/Interpreter.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2022-11-12 17:47:51 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2022-11-12 17:47:51 +0100
commitb9633a33182f5b381e912366273709e59f469bb9 (patch)
tree0b7eb7f1e67792253cfaf9caee3a92570ab60407 /app/Interpreter.hs
parentfe6666d204c0728b4556574ddc184bc46013b193 (diff)
downloadprlg-b9633a33182f5b381e912366273709e59f469bb9.tar.gz
prlg-b9633a33182f5b381e912366273709e59f469bb9.tar.bz2
reorg.
Diffstat (limited to 'app/Interpreter.hs')
-rw-r--r--app/Interpreter.hs73
1 files changed, 3 insertions, 70 deletions
diff --git a/app/Interpreter.hs b/app/Interpreter.hs
index b42f079..c29b701 100644
--- a/app/Interpreter.hs
+++ b/app/Interpreter.hs
@@ -1,78 +1,11 @@
{- VAM 2P, done the lazy way -}
module Interpreter where
-import Data.Function
+--import Data.Function
import qualified Data.Map as M
-data StrTable =
- StrTable Int (M.Map String Int) (M.Map Int String)
- deriving (Show)
-
-emptystrtable = StrTable 0 M.empty M.empty
-
-strtablize t@(StrTable nxt fwd rev) str =
- case fwd M.!? str of
- 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 Datum
- = Atom Int -- unifies a constant
- | Struct Id -- unifies a structure with arity
- | 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)
-
-data Instr
- = U Datum -- something unifiable
- | NoGoal -- trivial goal
- | Goal -- we start a new goal, set up backtracking etc
- | Call -- all seems okay, call the goal
- | LastCall -- tail call the goal
- | Cut -- remove all alternative clauses of the current goal
- deriving (Show)
-
-type Code = [Instr]
-
-type Defs = M.Map Id [Code]
-
-data Heap =
- Heap Int (M.Map Int Datum)
- deriving (Show)
-
-emptyHeap = Heap 0 M.empty
-
-type Scope = M.Map Int Int
-
-emptyScope :: Scope
-emptyScope = M.empty
-
-data Cho =
- Cho
- { hed :: Code -- head pointer
- , hvar :: Scope -- variables unified in head (so far)
- , gol :: Code -- goal pointer
- , gvar :: Scope -- variables unified in the goal
- , heap :: Heap -- a snapshot of the heap (there's no trail; we rely on CoW copies in other choicepoints)
- , stk :: [(Code, Scope, [Cho])] -- remaining goals together with their vars and cuts
- , cut :: [Cho] -- snapshot of choicepoints before entering
- }
- deriving (Show)
-
-data Interp =
- Interp
- { defs :: Defs -- global definitions for lookup (TODO can we externalize?)
- , cur :: Cho -- the choice that is being evaluated right now
- , cho :: [Cho] -- remaining choice points
- }
- deriving (Show)
+import Code
+import IR (Id(..))
prove :: Code -> Defs -> (Interp, Either String Bool)
prove g ds =