forked from TrueCloudLab/neoneo-go
Merge pull request #1155 from nspcc-dev/interop-compiler-fixes-for-3.0
Interop and compiler fixes for 3.0
This commit is contained in:
commit
8532d76401
4 changed files with 31 additions and 5 deletions
|
@ -1173,7 +1173,13 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
||||||
|
|
||||||
switch name {
|
switch name {
|
||||||
case "len":
|
case "len":
|
||||||
|
emit.Opcode(c.prog.BinWriter, opcode.DUP)
|
||||||
|
emit.Opcode(c.prog.BinWriter, opcode.ISNULL)
|
||||||
|
emit.Instruction(c.prog.BinWriter, opcode.JMPIF, []byte{2 + 1 + 2})
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.SIZE)
|
emit.Opcode(c.prog.BinWriter, opcode.SIZE)
|
||||||
|
emit.Instruction(c.prog.BinWriter, opcode.JMP, []byte{2 + 1 + 1})
|
||||||
|
emit.Opcode(c.prog.BinWriter, opcode.DROP)
|
||||||
|
emit.Opcode(c.prog.BinWriter, opcode.PUSH0)
|
||||||
case "append":
|
case "append":
|
||||||
arg := expr.Args[0]
|
arg := expr.Args[0]
|
||||||
typ := c.typeInfo.Types[arg].Type
|
typ := c.typeInfo.Types[arg].Type
|
||||||
|
@ -1515,7 +1521,8 @@ func (c *codegen) writeJumps(b []byte) error {
|
||||||
case opcode.JMP, opcode.JMPIFNOT, opcode.JMPIF, opcode.CALL,
|
case opcode.JMP, opcode.JMPIFNOT, opcode.JMPIF, opcode.CALL,
|
||||||
opcode.JMPEQ, opcode.JMPNE,
|
opcode.JMPEQ, opcode.JMPNE,
|
||||||
opcode.JMPGT, opcode.JMPGE, opcode.JMPLE, opcode.JMPLT:
|
opcode.JMPGT, opcode.JMPGE, opcode.JMPLE, opcode.JMPLT:
|
||||||
panic("short jumps are not yet supported")
|
// Noop, assumed to be correct already. If you're fixing #905,
|
||||||
|
// make sure not to break "len" handling above.
|
||||||
case opcode.JMPL, opcode.JMPIFL, opcode.JMPIFNOTL,
|
case opcode.JMPL, opcode.JMPIFL, opcode.JMPIFNOTL,
|
||||||
opcode.JMPEQL, opcode.JMPNEL,
|
opcode.JMPEQL, opcode.JMPNEL,
|
||||||
opcode.JMPGTL, opcode.JMPGEL, opcode.JMPLEL, opcode.JMPLTL,
|
opcode.JMPGTL, opcode.JMPGEL, opcode.JMPLEL, opcode.JMPLTL,
|
||||||
|
|
|
@ -187,3 +187,14 @@ func TestBuiltinPackage(t *testing.T) {
|
||||||
}`
|
}`
|
||||||
eval(t, src, big.NewInt(1))
|
eval(t, src, big.NewInt(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLenForNil(t *testing.T) {
|
||||||
|
src := `
|
||||||
|
package foo
|
||||||
|
func Main() bool {
|
||||||
|
var a []int = nil
|
||||||
|
return len(a) == 0
|
||||||
|
}`
|
||||||
|
|
||||||
|
eval(t, src, true)
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
var syscalls = map[string]map[string]string{
|
var syscalls = map[string]map[string]string{
|
||||||
|
"binary": {
|
||||||
|
"Serialize": "System.Binary.Serialize",
|
||||||
|
"Deserialize": "System.Binary.Deserialize",
|
||||||
|
},
|
||||||
"crypto": {
|
"crypto": {
|
||||||
"ECDsaVerify": "Neo.Crypto.ECDsaVerify",
|
"ECDsaVerify": "Neo.Crypto.ECDsaVerify",
|
||||||
},
|
},
|
||||||
|
@ -37,8 +41,6 @@ var syscalls = map[string]map[string]string{
|
||||||
"Notify": "System.Runtime.Notify",
|
"Notify": "System.Runtime.Notify",
|
||||||
"Log": "System.Runtime.Log",
|
"Log": "System.Runtime.Log",
|
||||||
"GetTime": "System.Runtime.GetTime",
|
"GetTime": "System.Runtime.GetTime",
|
||||||
"Serialize": "System.Binary.Serialize",
|
|
||||||
"Deserialize": "System.Binary.Deserialize",
|
|
||||||
},
|
},
|
||||||
"blockchain": {
|
"blockchain": {
|
||||||
"GetBlock": "System.Blockchain.GetBlock",
|
"GetBlock": "System.Blockchain.GetBlock",
|
||||||
|
|
|
@ -43,16 +43,22 @@ func GetTrigger() byte {
|
||||||
return 0x00
|
return 0x00
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// System returns the System trigger type value to compare with
|
||||||
|
// GetTrigger return value.
|
||||||
|
func System() byte {
|
||||||
|
return 0x01
|
||||||
|
}
|
||||||
|
|
||||||
// Application returns the Application trigger type value to compare with
|
// Application returns the Application trigger type value to compare with
|
||||||
// GetTrigger return value.
|
// GetTrigger return value.
|
||||||
func Application() byte {
|
func Application() byte {
|
||||||
return 0x10
|
return 0x40
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verification returns the Verification trigger type value to compare with
|
// Verification returns the Verification trigger type value to compare with
|
||||||
// GetTrigger return value.
|
// GetTrigger return value.
|
||||||
func Verification() byte {
|
func Verification() byte {
|
||||||
return 0x00
|
return 0x20
|
||||||
}
|
}
|
||||||
|
|
||||||
// GasLeft returns the amount of gas available for the current execution.
|
// GasLeft returns the amount of gas available for the current execution.
|
||||||
|
|
Loading…
Reference in a new issue