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:
|
// example:
|
||||||
// const x = 10
|
// const x = 10
|
||||||
// x + 2 will results into 12
|
// 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)
|
c.emitLoadConst(tinfo)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ast.Walk(c, n.X)
|
ast.Walk(c, n.X)
|
||||||
ast.Walk(c, n.Y)
|
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)
|
c.convertToken(n.Op)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue