Skip to content

Commit aeddcd9

Browse files
dgryskideadprogram
authored andcommitted
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
1 parent bf0b05e commit aeddcd9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

compiler/compiler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,16 +2276,16 @@ func (b *builder) createBinOp(op token.Token, typ, ytyp types.Type, x, y llvm.Va
22762276
case token.NEQ: // !=
22772277
result := b.createRuntimeCall("stringEqual", []llvm.Value{x, y}, "")
22782278
return b.CreateNot(result, ""), nil
2279-
case token.LSS: // <
2279+
case token.LSS: // x < y
22802280
return b.createRuntimeCall("stringLess", []llvm.Value{x, y}, ""), nil
2281-
case token.LEQ: // <=
2281+
case token.LEQ: // x <= y becomes NOT (y < x)
22822282
result := b.createRuntimeCall("stringLess", []llvm.Value{y, x}, "")
22832283
return b.CreateNot(result, ""), nil
2284-
case token.GTR: // >
2284+
case token.GTR: // x > y becomes y < x
2285+
return b.createRuntimeCall("stringLess", []llvm.Value{y, x}, ""), nil
2286+
case token.GEQ: // x >= y becomes NOT (x < y)
22852287
result := b.createRuntimeCall("stringLess", []llvm.Value{x, y}, "")
22862288
return b.CreateNot(result, ""), nil
2287-
case token.GEQ: // >=
2288-
return b.createRuntimeCall("stringLess", []llvm.Value{y, x}, ""), nil
22892289
default:
22902290
panic("binop on string: " + op.String())
22912291
}

0 commit comments

Comments
 (0)