From b8f7dd3220564fa641f4f0b23adadce7b2543436 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 11 Sep 2022 16:54:35 +0100 Subject: Prevent infinite loop --- src/Micro/Compiler.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Micro/Compiler.hs') diff --git a/src/Micro/Compiler.hs b/src/Micro/Compiler.hs index 85e4037..9cfaddf 100644 --- a/src/Micro/Compiler.hs +++ b/src/Micro/Compiler.hs @@ -120,7 +120,7 @@ compileOne x = do (A.BinOp A.Plus pos (A.Num a _) (A.Num b _)) -> -- TODO: overflow check return $ typeResult (Just $ A.Type "u8") (A.Num (a + b) pos) - (A.BinOp op pos a b) -> do + orig@(A.BinOp op pos a b) -> do ra <- compileOne a let (ta, ea) = (crType ra, crExpr ra) rb <- compileOne b @@ -132,7 +132,11 @@ compileOne x = do Just err -> addError $ Error TypeError err pos _ -> addError $ Error InvalidTarget "invalid assignment target" pos _ -> case typecheck ta tb of - Nothing -> compileOne (A.BinOp op pos ea eb) + Nothing -> do + let new = (A.BinOp op pos ea eb) + if orig == new + then return $ typeResult ta orig + else compileOne new Just err -> addError $ Error TypeError err pos (A.Func ident params ret body priv anon pos) -> do -- current env -- cgit v1.2.3