summaryrefslogtreecommitdiff
path: root/app/Interpreter.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/Interpreter.hs')
-rw-r--r--app/Interpreter.hs49
1 files changed, 26 insertions, 23 deletions
diff --git a/app/Interpreter.hs b/app/Interpreter.hs
index ebec859..743f68b 100644
--- a/app/Interpreter.hs
+++ b/app/Interpreter.hs
@@ -1,39 +1,42 @@
{- VAM 2P, done the lazy way -}
module Interpreter where
+import Code
--import Data.Function
import qualified Data.Map as M
-
-import Code
+import Env (PrlgEnv(..))
import IR (Id(..))
+import qualified Control.Monad.Trans.State.Lazy as St
-prove :: Code -> Defs -> (Interp, Either String Bool)
-prove g ds =
- let i0 =
- Interp
- { defs = ds
- , cur =
- Cho
- { hed = g
- , hvar = emptyScope
- , gol = [LastCall]
- , gvar = emptyScope
- , heap = emptyHeap
- , stk = []
- , cut = []
- }
- , cho = []
- }
- run (Left x) = x
- run (Right x) = run $ proveStep Right (\i e -> Left (i, e)) x
- in run (Right i0)
+prove :: Code -> PrlgEnv (Either String Bool)
+prove g = do
+ St.modify $ \i ->
+ i
+ { cur =
+ Cho
+ { hed = g
+ , hvar = emptyScope
+ , gol = [LastCall]
+ , gvar = emptyScope
+ , heap = emptyHeap
+ , stk = []
+ , cut = []
+ }
+ , cho = []
+ }
+ loop
+ where
+ loop = do
+ i <- St.get
+ proveStep cont finish i
+ cont i = St.put i >> loop
+ finish i res = St.put i >> return res
data Dereferenced
= FreeRef Int
| BoundRef Int Datum
| NoRef
-{- this gonna need Either String Bool for errors later -}
proveStep :: (Interp -> a) -> (Interp -> Either String Bool -> a) -> Interp -> a
proveStep c f i = go i
where