aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-11 20:44:14 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-11 20:44:14 +0100
commit42c776df8812f31d72331141ab5c07d538594c31 (patch)
tree541777923846baa7ec502f2f7fb3f676b00224b5
parent230276c8a3e45a0079232739976e117db2d26b00 (diff)
downloadmicro-lang-hs-42c776df8812f31d72331141ab5c07d538594c31.tar.gz
micro-lang-hs-42c776df8812f31d72331141ab5c07d538594c31.zip
More folding
-rw-r--r--src/Micro/Compiler.hs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/Micro/Compiler.hs b/src/Micro/Compiler.hs
index 6d2a35d..40d9c1a 100644
--- a/src/Micro/Compiler.hs
+++ b/src/Micro/Compiler.hs
@@ -182,7 +182,11 @@ compileOne x = do
foldConstant :: A.Expr -> A.Expr
foldConstant x =
case x of
+ -- FIXME: overflow, invalid, etc
(A.BinOp A.Plus pos (A.Num a _) (A.Num b _)) -> A.Num (a + b) pos
+ (A.BinOp A.Minus pos (A.Num a _) (A.Num b _)) -> A.Num (a - b) pos
+ (A.BinOp A.Mul pos (A.Num a _) (A.Num b _)) -> A.Num (a * b) pos
+ (A.BinOp A.Div pos (A.Num a _) (A.Num b _)) -> A.Num (a `div` b) pos
(A.BinOp op pos a b) -> do
let newOp = A.BinOp op pos (foldConstant a) (foldConstant b)
if newOp /= x then foldConstant newOp else newOp