This commit is contained in:
crumbtoo
2023-12-04 18:43:06 -07:00
parent 799cc8e398
commit 43454fa2e0
4 changed files with 119 additions and 10 deletions

View File

@@ -7,6 +7,8 @@ Description : The G-Machine
{-# LANGUAGE OverloadedStrings #-}
module GM
( hdbgProg
, evalProg
, Node(..)
)
where
----------------------------------------------------------------------------------
@@ -89,6 +91,15 @@ pure []
----------------------------------------------------------------------------------
evalProg :: Program -> Maybe (Node, Stats)
evalProg p = res <&> (,sts)
where
final = eval (compile p) & last
h = final ^. gmHeap
sts = final ^. gmStats
resAddr = final ^. gmStack ^? _head
res = resAddr >>= flip hLookup h
hdbgProg :: Program -> Handle -> IO (Node, Stats)
hdbgProg p hio = do
(renderOut . showState) `traverse_` states