mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
concatenate strings using CAT opcode (CityOfZion/neo-storm#54)
Imported from CityOfZion/neo-storm (7d759a23e3af792657c7515645b890eadfa7329f).
This commit is contained in:
parent
36b253872f
commit
74602b6143
1 changed files with 14 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue