compiler: use separate opcodes for string and number equality
This commit is contained in:
parent
1e09037902
commit
d58fbe0c88
1 changed files with 12 additions and 5 deletions
|
@ -382,15 +382,22 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
ast.Walk(c, n.X)
|
||||
ast.Walk(c, n.Y)
|
||||
|
||||
// VM has separate opcode for string concatenation
|
||||
if n.Op == token.ADD {
|
||||
typ, ok := tinfo.Type.Underlying().(*types.Basic)
|
||||
if ok && typ.Kind() == types.String {
|
||||
switch {
|
||||
case n.Op == token.ADD:
|
||||
// VM has separate opcodes for number and string concatenation
|
||||
if isStringType(tinfo.Type) {
|
||||
emitOpcode(c.prog, vm.CAT)
|
||||
} else {
|
||||
emitOpcode(c.prog, vm.ADD)
|
||||
}
|
||||
} else {
|
||||
case n.Op == token.EQL:
|
||||
// VM has separate opcodes for number and string equality
|
||||
if isStringType(tinfo.Type) {
|
||||
emitOpcode(c.prog, vm.EQUAL)
|
||||
} else {
|
||||
emitOpcode(c.prog, vm.NUMEQUAL)
|
||||
}
|
||||
default:
|
||||
c.convertToken(n.Op)
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue