compiler: allow to use += on strings

This commit is contained in:
Evgenii Stratonikov 2020-08-23 13:12:10 +03:00
parent fd7af77895
commit 59367c96d1
3 changed files with 24 additions and 11 deletions

View file

@ -1440,7 +1440,11 @@ func (c *codegen) emitToken(tok token.Token, typ types.Type) {
func convertToken(tok token.Token, typ types.Type) (opcode.Opcode, error) {
switch tok {
case token.ADD_ASSIGN:
case token.ADD_ASSIGN, token.ADD:
// VM has separate opcodes for number and string concatenation
if isString(typ) {
return opcode.CAT, nil
}
return opcode.ADD, nil
case token.SUB_ASSIGN:
return opcode.SUB, nil
@ -1450,12 +1454,6 @@ func convertToken(tok token.Token, typ types.Type) (opcode.Opcode, error) {
return opcode.DIV, nil
case token.REM_ASSIGN:
return opcode.MOD, nil
case token.ADD:
// VM has separate opcodes for number and string concatenation
if isString(typ) {
return opcode.CAT, nil
}
return opcode.ADD, nil
case token.SUB:
return opcode.SUB, nil
case token.MUL: