From 74602b6143f030b3e5e9ff9410f3092c5adf404c Mon Sep 17 00:00:00 2001 From: fyrchik Date: Mon, 29 Oct 2018 18:36:13 +0300 Subject: [PATCH] concatenate strings using CAT opcode (CityOfZion/neo-storm#54) Imported from CityOfZion/neo-storm (7d759a23e3af792657c7515645b890eadfa7329f). --- pkg/vm/compiler/codegen.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/vm/compiler/codegen.go b/pkg/vm/compiler/codegen.go index 8a1ceb622..60c6bf081 100644 --- a/pkg/vm/compiler/codegen.go +++ b/pkg/vm/compiler/codegen.go @@ -372,14 +372,26 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor { // example: // const x = 10 // x + 2 will results into 12 - if tinfo := c.typeInfo.Types[n]; tinfo.Value != nil { + tinfo := c.typeInfo.Types[n] + if tinfo.Value != nil { c.emitLoadConst(tinfo) return nil } ast.Walk(c, n.X) ast.Walk(c, n.Y) - c.convertToken(n.Op) + + // 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 { + emitOpcode(c.prog, vm.CAT) + } else { + emitOpcode(c.prog, vm.ADD) + } + } else { + c.convertToken(n.Op) + } return nil }