compiler: support CONVERT interops

When result is needed to have certain type, we should have ability
to convert it, with the help of CONVERT opcode.
This commit is contained in:
Evgenii Stratonikov 2020-04-28 15:46:03 +03:00
parent bfcb1a409f
commit 2fd63387c0
4 changed files with 89 additions and 0 deletions

View file

@ -1055,6 +1055,15 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
} else {
c.prog.Err = errors.New("panic should have string or nil argument")
}
case "ToInteger", "ToByteArray", "ToBool":
typ := vm.IntegerT
switch name {
case "ToByteArray":
typ = vm.ByteArrayT
case "ToBool":
typ = vm.BooleanT
}
emit.Instruction(c.prog.BinWriter, opcode.CONVERT, []byte{byte(typ)})
case "SHA256":
emit.Opcode(c.prog.BinWriter, opcode.SHA256)
case "SHA1":