diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-09-11 16:54:35 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-09-11 16:54:35 +0100 |
commit | b8f7dd3220564fa641f4f0b23adadce7b2543436 (patch) | |
tree | 02831496edd14607c5977a095165a03520bb6fd7 | |
parent | 3139a5a2ef1668549b2247ad832c59cc89d9758e (diff) | |
download | micro-lang-hs-b8f7dd3220564fa641f4f0b23adadce7b2543436.tar.gz micro-lang-hs-b8f7dd3220564fa641f4f0b23adadce7b2543436.zip |
Prevent infinite loop
-rw-r--r-- | src/Micro/Compiler.hs | 8 |
1 files changed, 6 insertions, 2 deletions
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 |