From 906bdc59b750fa3bbb73177fce47a87c4635a457 Mon Sep 17 00:00:00 2001 From: crumbtoo Date: Thu, 14 Dec 2023 11:59:27 -0700 Subject: [PATCH] arith fixes (everything seems to work) --- src/GM.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/GM.hs b/src/GM.hs index 9f3a27b..b973a54 100644 --- a/src/GM.hs +++ b/src/GM.hs @@ -701,11 +701,16 @@ buildInitialHeap (Program ss) = mapAccumL allocateSc mempty compiledScs compileBinder (_ := v, a) = compileC g' v <> [Update a] -- special cases for prim functions; essentially inlining - compileE g ("negate#" :$ a) = compileE g a <> [Neg] - compileE g ("+#" :$ a :$ b) = compileE g a <> compileE g b <> [Add] - compileE g ("-#" :$ a :$ b) = compileE g a <> compileE g b <> [Sub] - compileE g ("*#" :$ a :$ b) = compileE g a <> compileE g b <> [Mul] - compileE g ("/#" :$ a :$ b) = compileE g a <> compileE g b <> [Div] + compileE g ("negate#" :$ a) = compileE g a <> [Neg] + compileE g ("+#" :$ a :$ b) = compileE g a <> compileE g b <> [Add] + -- note that we only bother offsetting the environment and evaluationg + -- in the "correct" order with non-commutative operations. if we + -- implemented Sub the same way as Add, (-#) 3 2 would evaluate to -1. + compileE g ("-#" :$ a :$ b) = compileE g b <> compileE g' a <> [Sub] + where g' = argOffset 1 g + compileE g ("*#" :$ a :$ b) = compileE g a <> compileE g b <> [Mul] + compileE g ("/#" :$ a :$ b) = compileE g a <> compileE g' b <> [Div] + where g' = argOffset 1 g compileE g ("==#" :$ a :$ b) = compileE g a <> compileE g b <> [Equals] compileE g (Case e as) = compileE g e <> [CaseJump (compileD g as)]