From: Luke Lau Date: Sun, 10 Mar 2019 16:11:02 +0000 (+0000) Subject: Check the type of if condition X-Git-Url: https://git.lukelau.me/?p=kaleidoscope-hs-old.git;a=commitdiff_plain;h=f250f7c0e621f1f94b6d2377f6a634314f306ace Check the type of if condition --- diff --git a/Main.hs b/Main.hs index 89fd91a..328aaf3 100644 --- a/Main.hs +++ b/Main.hs @@ -23,6 +23,7 @@ import LLVM.AST.Float import LLVM.AST.FloatingPointPredicate hiding (False, True) import LLVM.AST.Operand import LLVM.AST.Type as Type +import LLVM.AST.Typed import LLVM.Pretty import Debug.Trace @@ -90,7 +91,9 @@ buildExpr binds (AST.BinOp op a b) = do buildExpr binds (AST.If cond thenE elseE) = mdo _ifB <- block `named` "if" + condV <- buildExpr binds cond + when (typeOf condV /= i1) $ lift $ lift $ Left "Not a boolean" condBr condV thenB elseB thenB <- block `named` "then"