concatenate strings using CAT opcode (CityOfZion/neo-storm#54)

Imported from CityOfZion/neo-storm (7d759a23e3af792657c7515645b890eadfa7329f).
This commit is contained in:
Evgenii Stratonikov 2018-10-29 18:36:13 +03:00 committed by Roman Khimov
parent 36b253872f
commit 74602b6143

View file

@ -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)
// 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
}