From aeddcd9c5fe6a8cb7ef65dc838128cd749d6b5a8 Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Wed, 17 Nov 2021 13:35:10 -0800 Subject: [PATCH] compiler: fix string compare functions Before: x < x false x <= x true x == x true x >= x false x > x true After: x < x false x <= x true x == x true x >= x true x > x false --- compiler/compiler.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/compiler.go b/compiler/compiler.go index ae1ba07b0..fe04ae642 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -2276,16 +2276,16 @@ func (b *builder) createBinOp(op token.Token, typ, ytyp types.Type, x, y llvm.Va case token.NEQ: // != result := b.createRuntimeCall("stringEqual", []llvm.Value{x, y}, "") return b.CreateNot(result, ""), nil - case token.LSS: // < + case token.LSS: // x < y return b.createRuntimeCall("stringLess", []llvm.Value{x, y}, ""), nil - case token.LEQ: // <= + case token.LEQ: // x <= y becomes NOT (y < x) result := b.createRuntimeCall("stringLess", []llvm.Value{y, x}, "") return b.CreateNot(result, ""), nil - case token.GTR: // > + case token.GTR: // x > y becomes y < x + return b.createRuntimeCall("stringLess", []llvm.Value{y, x}, ""), nil + case token.GEQ: // x >= y becomes NOT (x < y) result := b.createRuntimeCall("stringLess", []llvm.Value{x, y}, "") return b.CreateNot(result, ""), nil - case token.GEQ: // >= - return b.createRuntimeCall("stringLess", []llvm.Value{y, x}, ""), nil default: panic("binop on string: " + op.String()) }