From 19f7927515e97b81527b81f19e955d54187f7445 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 20 Oct 2018 15:47:59 +0200 Subject: [PATCH] compiler: compare booleans Implement == and != for booleans. --- compiler/compiler.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/compiler.go b/compiler/compiler.go index 2e840792..e42bcdb8 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -2823,6 +2823,16 @@ func (c *Compiler) parseBinOp(frame *Frame, binop *ssa.BinOp) (llvm.Value, error default: return llvm.Value{}, errors.New("todo: binop on float: " + binop.Op.String()) } + } else if typ.Info()&types.IsBoolean != 0 { + // Operations on booleans + switch binop.Op { + case token.EQL: // == + return c.builder.CreateICmp(llvm.IntEQ, x, y, ""), nil + case token.NEQ: // != + return c.builder.CreateICmp(llvm.IntNE, x, y, ""), nil + default: + return llvm.Value{}, errors.New("todo: binop on boolean: " + binop.Op.String()) + } } else if typ.Kind() == types.UnsafePointer { // Operations on pointers switch binop.Op {