compiler: add ConvertResultToStruct flag
Part of #1055. There'll be a lot of interops which result with a struct on stack instead of interop interface, and sometimes their names are the same, so it's unrelyable to take into account interop name only and don't pay attention to it's API (package). Also sort syscalls by package and name.
This commit is contained in:
parent
75dc62fa81
commit
a1f98f92fe
2 changed files with 71 additions and 67 deletions
|
@ -1139,14 +1139,13 @@ func (c *codegen) getByteArray(expr ast.Expr) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *codegen) convertSyscall(expr *ast.CallExpr, api, name string) {
|
func (c *codegen) convertSyscall(expr *ast.CallExpr, api, name string) {
|
||||||
api, ok := syscalls[api][name]
|
syscall, ok := syscalls[api][name]
|
||||||
if !ok {
|
if !ok {
|
||||||
c.prog.Err = fmt.Errorf("unknown VM syscall api: %s", name)
|
c.prog.Err = fmt.Errorf("unknown VM syscall api: %s.%s", api, name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
emit.Syscall(c.prog.BinWriter, api)
|
emit.Syscall(c.prog.BinWriter, syscall.API)
|
||||||
switch name {
|
if syscall.ConvertResultToStruct {
|
||||||
case "GetTransaction", "GetBlock", "GetScriptContainer":
|
|
||||||
c.emitConvert(stackitem.StructT)
|
c.emitConvert(stackitem.StructT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,73 +1,78 @@
|
||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
var syscalls = map[string]map[string]string{
|
// Syscall represents NEO or System syscall API with flag for proper AVM generation
|
||||||
"binary": {
|
type Syscall struct {
|
||||||
"Serialize": "System.Binary.Serialize",
|
API string
|
||||||
"Deserialize": "System.Binary.Deserialize",
|
ConvertResultToStruct bool
|
||||||
},
|
}
|
||||||
"crypto": {
|
|
||||||
"ECDsaSecp256r1Verify": "Neo.Crypto.VerifyWithECDsaSecp256r1",
|
|
||||||
"ECDsaSecp256k1Verify": "Neo.Crypto.VerifyWithECDsaSecp256k1",
|
|
||||||
"ECDSASecp256r1CheckMultisig": "Neo.Crypto.CheckMultisigWithECDsaSecp256r1",
|
|
||||||
"ECDSASecp256k1CheckMultisig": "Neo.Crypto.CheckMultisigWithECDsaSecp256k1",
|
|
||||||
},
|
|
||||||
"enumerator": {
|
|
||||||
"Concat": "System.Enumerator.Concat",
|
|
||||||
"Create": "System.Enumerator.Create",
|
|
||||||
"Next": "System.Enumerator.Next",
|
|
||||||
"Value": "System.Enumerator.Value",
|
|
||||||
},
|
|
||||||
"json": {
|
|
||||||
"Serialize": "System.Json.Serialize",
|
|
||||||
"Deserialize": "System.Json.Deserialize",
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"ConvertContextToReadOnly": "System.Storage.AsReadOnly",
|
|
||||||
"Delete": "System.Storage.Delete",
|
|
||||||
"Find": "System.Storage.Find",
|
|
||||||
"Get": "System.Storage.Get",
|
|
||||||
"GetContext": "System.Storage.GetContext",
|
|
||||||
"GetReadOnlyContext": "System.Storage.GetReadOnlyContext",
|
|
||||||
"Put": "System.Storage.Put",
|
|
||||||
},
|
|
||||||
"runtime": {
|
|
||||||
"GetScriptContainer": "System.Runtime.GetScriptContainer",
|
|
||||||
"GetCallingScriptHash": "System.Runtime.GetCallingScriptHash",
|
|
||||||
"GetEntryScriptHash": "System.Runtime.GetEntryScriptHash",
|
|
||||||
"GetExecutingScriptHash": "System.Runtime.GetExecutingScriptHash",
|
|
||||||
"GetNotifications": "System.Runtime.GetNotifications",
|
|
||||||
"GetInvocationCounter": "System.Runtime.GetInvocationCounter",
|
|
||||||
|
|
||||||
"GasLeft": "System.Runtime.GasLeft",
|
// All lists are sorted, keep 'em this way, please.
|
||||||
"GetTrigger": "System.Runtime.GetTrigger",
|
var syscalls = map[string]map[string]Syscall{
|
||||||
"CheckWitness": "System.Runtime.CheckWitness",
|
"binary": {
|
||||||
"Notify": "System.Runtime.Notify",
|
"Deserialize": {"System.Binary.Deserialize", false},
|
||||||
"Log": "System.Runtime.Log",
|
"Serialize": {"System.Binary.Serialize", false},
|
||||||
"GetTime": "System.Runtime.GetTime",
|
|
||||||
},
|
},
|
||||||
"blockchain": {
|
"blockchain": {
|
||||||
"GetBlock": "System.Blockchain.GetBlock",
|
"GetBlock": {"System.Blockchain.GetBlock", true},
|
||||||
"GetContract": "System.Blockchain.GetContract",
|
"GetContract": {"System.Blockchain.GetContract", false},
|
||||||
"GetHeight": "System.Blockchain.GetHeight",
|
"GetHeight": {"System.Blockchain.GetHeight", false},
|
||||||
"GetTransaction": "System.Blockchain.GetTransaction",
|
"GetTransaction": {"System.Blockchain.GetTransaction", true},
|
||||||
"GetTransactionFromBlock": "System.Blockchain.GetTransactionFromBlock",
|
"GetTransactionFromBlock": {"System.Blockchain.GetTransactionFromBlock", false},
|
||||||
"GetTransactionHeight": "System.Blockchain.GetTransactionHeight",
|
"GetTransactionHeight": {"System.Blockchain.GetTransactionHeight", false},
|
||||||
},
|
},
|
||||||
"contract": {
|
"contract": {
|
||||||
"Create": "System.Contract.Create",
|
"Create": {"System.Contract.Create", false},
|
||||||
"Destroy": "System.Contract.Destroy",
|
"CreateStandardAccount": {"System.Contract.CreateStandardAccount", false},
|
||||||
"Update": "System.Contract.Update",
|
"Destroy": {"System.Contract.Destroy", false},
|
||||||
|
"IsStandard": {"System.Contract.IsStandard", false},
|
||||||
"IsStandard": "System.Contract.IsStandard",
|
"Update": {"System.Contract.Update", false},
|
||||||
"CreateStandardAccount": "System.Contract.CreateStandardAccount",
|
},
|
||||||
|
"crypto": {
|
||||||
|
"ECDsaSecp256k1Verify": {"Neo.Crypto.VerifyWithECDsaSecp256k1", false},
|
||||||
|
"ECDSASecp256k1CheckMultisig": {"Neo.Crypto.CheckMultisigWithECDsaSecp256k1", false},
|
||||||
|
"ECDsaSecp256r1Verify": {"Neo.Crypto.VerifyWithECDsaSecp256r1", false},
|
||||||
|
"ECDSASecp256r1CheckMultisig": {"Neo.Crypto.CheckMultisigWithECDsaSecp256r1", false},
|
||||||
|
},
|
||||||
|
"enumerator": {
|
||||||
|
"Concat": {"System.Enumerator.Concat", false},
|
||||||
|
"Create": {"System.Enumerator.Create", false},
|
||||||
|
"Next": {"System.Enumerator.Next", false},
|
||||||
|
"Value": {"System.Enumerator.Value", false},
|
||||||
},
|
},
|
||||||
"iterator": {
|
"iterator": {
|
||||||
"Concat": "System.Iterator.Concat",
|
"Concat": {"System.Iterator.Concat", false},
|
||||||
"Create": "System.Iterator.Create",
|
"Create": {"System.Iterator.Create", false},
|
||||||
"Key": "System.Iterator.Key",
|
"Key": {"System.Iterator.Key", false},
|
||||||
"Keys": "System.Iterator.Keys",
|
"Keys": {"System.Iterator.Keys", false},
|
||||||
"Next": "System.Enumerator.Next",
|
"Next": {"System.Enumerator.Next", false},
|
||||||
"Value": "System.Enumerator.Value",
|
"Value": {"System.Enumerator.Value", false},
|
||||||
"Values": "System.Iterator.Values",
|
"Values": {"System.Iterator.Values", false},
|
||||||
|
},
|
||||||
|
"json": {
|
||||||
|
"Deserialize": {"System.Json.Deserialize", false},
|
||||||
|
"Serialize": {"System.Json.Serialize", false},
|
||||||
|
},
|
||||||
|
"runtime": {
|
||||||
|
"GasLeft": {"System.Runtime.GasLeft", false},
|
||||||
|
"GetInvocationCounter": {"System.Runtime.GetInvocationCounter", false},
|
||||||
|
"GetCallingScriptHash": {"System.Runtime.GetCallingScriptHash", false},
|
||||||
|
"GetEntryScriptHash": {"System.Runtime.GetEntryScriptHash", false},
|
||||||
|
"GetExecutingScriptHash": {"System.Runtime.GetExecutingScriptHash", false},
|
||||||
|
"GetNotifications": {"System.Runtime.GetNotifications", false},
|
||||||
|
"GetScriptContainer": {"System.Runtime.GetScriptContainer", true},
|
||||||
|
"GetTime": {"System.Runtime.GetTime", false},
|
||||||
|
"GetTrigger": {"System.Runtime.GetTrigger", false},
|
||||||
|
"CheckWitness": {"System.Runtime.CheckWitness", false},
|
||||||
|
"Log": {"System.Runtime.Log", false},
|
||||||
|
"Notify": {"System.Runtime.Notify", false},
|
||||||
|
},
|
||||||
|
"storage": {
|
||||||
|
"ConvertContextToReadOnly": {"System.Storage.AsReadOnly", false},
|
||||||
|
"Delete": {"System.Storage.Delete", false},
|
||||||
|
"Find": {"System.Storage.Find", false},
|
||||||
|
"Get": {"System.Storage.Get", false},
|
||||||
|
"GetContext": {"System.Storage.GetContext", false},
|
||||||
|
"GetReadOnlyContext": {"System.Storage.GetReadOnlyContext", false},
|
||||||
|
"Put": {"System.Storage.Put", false},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue