Merge pull request #395 from nspcc-dev/fix/append-codegen
VM: fix codegen for APPEND After changes in #391 some tests started to fail. This PR fixes codegen for APPEND.
This commit is contained in:
commit
cd3d22d150
2 changed files with 15 additions and 1 deletions
|
@ -203,6 +203,10 @@ func isSyscall(fun *funcScope) bool {
|
|||
return ok
|
||||
}
|
||||
|
||||
func isByteArrayType(t types.Type) bool {
|
||||
return t.String() == "[]byte"
|
||||
}
|
||||
|
||||
func isStringType(t types.Type) bool {
|
||||
return t.String() == "string"
|
||||
}
|
||||
|
|
|
@ -614,7 +614,17 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
|||
emitOpcode(c.prog, vm.ARRAYSIZE)
|
||||
}
|
||||
case "append":
|
||||
emitOpcode(c.prog, vm.APPEND)
|
||||
arg := expr.Args[0]
|
||||
typ := c.typeInfo.Types[arg].Type
|
||||
if isByteArrayType(typ) {
|
||||
emitOpcode(c.prog, vm.CAT)
|
||||
} else {
|
||||
emitOpcode(c.prog, vm.SWAP)
|
||||
emitOpcode(c.prog, vm.DUP)
|
||||
emitOpcode(c.prog, vm.PUSH2)
|
||||
emitOpcode(c.prog, vm.XSWAP)
|
||||
emitOpcode(c.prog, vm.APPEND)
|
||||
}
|
||||
case "SHA256":
|
||||
emitOpcode(c.prog, vm.SHA256)
|
||||
case "SHA1":
|
||||
|
|
Loading…
Reference in a new issue