From 42c776df8812f31d72331141ab5c07d538594c31 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 11 Sep 2022 20:44:14 +0100 Subject: More folding --- src/Micro/Compiler.hs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') 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 -- cgit v1.2.3