case exprs!

This commit is contained in:
crumbtoo
2023-12-06 16:41:38 -07:00
parent 07c3064a72
commit f6d87cfb6b
2 changed files with 15 additions and 3 deletions

View File

@@ -144,8 +144,6 @@ isFinal st = null $ st ^. gmCode
step :: GmState -> GmState
step st = case head (st ^. gmCode) of
-- TODO: clean this up. let transition functions use the 'state' parameter
-- instead of passing it to them.
Unwind -> unwindI
PushGlobal n -> pushGlobalI n
PushConstr t n -> pushConstrI t n
@@ -164,8 +162,22 @@ step st = case head (st ^. gmCode) of
Div -> divI
Split n -> splitI n
Pack t n -> packI t n
CaseJump as -> caseJumpI as
where
caseJumpI :: [(Tag, Code)] -> GmState
caseJumpI as = st
& advanceCode
& gmCode %~ (i'++)
where
h = st ^. gmHeap
s = st ^. gmStack
NConstr t ss = head s
& hViewUnsafe h
i' = fromMaybe
(error $ "unmatched tag: " <> show t)
(lookup t as)
packI :: Tag -> Int -> GmState
packI t n = st
& advanceCode