From dfad80b163e2fdee17a2b07f4117d3d391884f26 Mon Sep 17 00:00:00 2001 From: crumbtoo Date: Mon, 12 Feb 2024 07:34:16 -0700 Subject: [PATCH] lt --- src/GM.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/GM.hs b/src/GM.hs index 15e7e14..3feb86b 100644 --- a/src/GM.hs +++ b/src/GM.hs @@ -89,7 +89,7 @@ data Instr = Unwind -- arith | Neg | Add | Sub | Mul | Div -- comparison - | Equals + | Equals | Lesser | Pack Tag Int -- Pack Tag Arity | CaseJump [(Tag, Code)] | Split Int @@ -212,6 +212,7 @@ step st = case head (st ^. gmCode) of Mul -> mulI Div -> divI Equals -> equalsI + Lesser -> lesserI Split n -> splitI n Pack t n -> packI t n CaseJump as -> caseJumpI as @@ -411,8 +412,9 @@ step st = case head (st ^. gmCode) of mulI = primitive2 boxInt unboxInt (*) st divI = primitive2 boxInt unboxInt div st - equalsI :: GmState + lesserI, equalsI :: GmState equalsI = primitive2 boxBool unboxInt (==) st + lesserI = primitive2 boxBool unboxInt (<) st splitI :: Int -> GmState splitI n = st @@ -595,6 +597,7 @@ compiledPrims = , binop "*#" Mul , binop "/#" Div , binop "==#" Equals + , binop "<#" Lesser ] where unop k i = (k, 1, [Push 0, Eval, i, Update 1, Pop 1, Unwind]) @@ -733,6 +736,7 @@ buildInitialHeap (view programScDefs -> ss) = mapAccumL allocateSc mempty compil compileE g ("*#" :$ a :$ b) = inlineOp2 g Mul a b compileE g ("/#" :$ a :$ b) = inlineOp2 g Div a b compileE g ("==#" :$ a :$ b) = inlineOp2 g Equals a b + compileE g ("<#" :$ a :$ b) = inlineOp2 g Lesser a b compileE g (Case e as) = compileE g e <> [CaseJump (compileD g as)]