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:
Roman Khimov 2019-09-13 18:32:55 +03:00 committed by GitHub
commit cd3d22d150
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -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"
}

View file

@ -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":