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

@@ -406,7 +406,7 @@ Core Transition Rules
.. math:: .. math::
\gmrule \gmrule
{ \mathtt{CaseJump} \begin{bmatrix} t \to c \end{bmatrix} : i { \mathtt{CaseJump} \begin{bmatrix} t : c \end{bmatrix} : i
& a : s & a : s
& d & d
& h & h

View File

@@ -144,8 +144,6 @@ isFinal st = null $ st ^. gmCode
step :: GmState -> GmState step :: GmState -> GmState
step st = case head (st ^. gmCode) of 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 Unwind -> unwindI
PushGlobal n -> pushGlobalI n PushGlobal n -> pushGlobalI n
PushConstr t n -> pushConstrI t n PushConstr t n -> pushConstrI t n
@@ -164,8 +162,22 @@ step st = case head (st ^. gmCode) of
Div -> divI Div -> divI
Split n -> splitI n Split n -> splitI n
Pack t n -> packI t n Pack t n -> packI t n
CaseJump as -> caseJumpI as
where 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 :: Tag -> Int -> GmState
packI t n = st packI t n = st
& advanceCode & advanceCode