added partial syscall mapping
Imported from CityOfZion/neo-storm (26d10c72f6e3d298135ec3995eb2d821640c3b7c).
This commit is contained in:
parent
33c512032f
commit
1927bc54d5
5 changed files with 83 additions and 34 deletions
|
@ -6,7 +6,6 @@ import (
|
|||
"go/types"
|
||||
"log"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/vm"
|
||||
"golang.org/x/tools/go/loader"
|
||||
)
|
||||
|
||||
|
@ -203,7 +202,7 @@ func isByteArray(lit *ast.CompositeLit, tInfo *types.Info) bool {
|
|||
}
|
||||
|
||||
func isSyscall(name string) bool {
|
||||
_, ok := vm.Syscalls[name]
|
||||
_, ok := syscalls[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
|
|
|
@ -532,7 +532,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
}
|
||||
|
||||
func (c *codegen) convertSyscall(name string) {
|
||||
api, ok := vm.Syscalls[name]
|
||||
api, ok := syscalls[name]
|
||||
if !ok {
|
||||
log.Fatalf("unknown VM syscall api: %s", name)
|
||||
}
|
||||
|
|
|
@ -12,16 +12,16 @@ import (
|
|||
"github.com/CityOfZion/neo-go/pkg/vm"
|
||||
)
|
||||
|
||||
func emit(w *bytes.Buffer, op vm.Instruction, b []byte) error {
|
||||
if err := w.WriteByte(byte(op)); err != nil {
|
||||
func emit(w *bytes.Buffer, instr vm.Instruction, b []byte) error {
|
||||
if err := w.WriteByte(byte(instr)); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := w.Write(b)
|
||||
return err
|
||||
}
|
||||
|
||||
func emitOpcode(w io.ByteWriter, op vm.Instruction) error {
|
||||
return w.WriteByte(byte(op))
|
||||
func emitOpcode(w io.ByteWriter, instr vm.Instruction) error {
|
||||
return w.WriteByte(byte(instr))
|
||||
}
|
||||
|
||||
func emitBool(w io.ByteWriter, ok bool) error {
|
||||
|
@ -89,21 +89,21 @@ func emitSyscall(w *bytes.Buffer, api string) error {
|
|||
return emit(w, vm.SYSCALL, buf)
|
||||
}
|
||||
|
||||
func emitCall(w *bytes.Buffer, op vm.Instruction, label int16) error {
|
||||
return emitJmp(w, op, label)
|
||||
func emitCall(w *bytes.Buffer, instr vm.Instruction, label int16) error {
|
||||
return emitJmp(w, instr, label)
|
||||
}
|
||||
|
||||
func emitJmp(w *bytes.Buffer, op vm.Instruction, label int16) error {
|
||||
if !isInstructionJmp(op) {
|
||||
return fmt.Errorf("opcode %s is not a jump or call type", op)
|
||||
func emitJmp(w *bytes.Buffer, instr vm.Instruction, label int16) error {
|
||||
if !isInstrJmp(instr) {
|
||||
return fmt.Errorf("opcode %s is not a jump or call type", instr)
|
||||
}
|
||||
buf := make([]byte, 2)
|
||||
binary.LittleEndian.PutUint16(buf, uint16(label))
|
||||
return emit(w, op, buf)
|
||||
return emit(w, instr, buf)
|
||||
}
|
||||
|
||||
func isInstructionJmp(op vm.Instruction) bool {
|
||||
if op == vm.JMP || op == vm.JMPIFNOT || op == vm.JMPIF || op == vm.CALL {
|
||||
func isInstrJmp(instr vm.Instruction) bool {
|
||||
if instr == vm.JMP || instr == vm.JMPIFNOT || instr == vm.JMPIF || instr == vm.CALL {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
|
69
pkg/vm/compiler/syscall.go
Normal file
69
pkg/vm/compiler/syscall.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
package compiler
|
||||
|
||||
var syscalls = map[string]string{
|
||||
//
|
||||
// Standard library API
|
||||
//
|
||||
|
||||
// Storage API
|
||||
"GetContext": "System.Storage.GetContext",
|
||||
"Put": "System.Storage.Put",
|
||||
"Get": "System.Storage.Get",
|
||||
"Delete": "System.Storage.Delete",
|
||||
"Find": "System.Storage.Find",
|
||||
|
||||
// Runtime API
|
||||
"GetTrigger": "System.Runtime.GetTrigger",
|
||||
"CheckWitness": "System.Runtime.CheckWitness",
|
||||
"Notify": "System.Runtime.Notify",
|
||||
"Log": "System.Runtime.Log",
|
||||
"GetTime": "System.Runtime.GetTime",
|
||||
"Serialize": "System.Runtime.Serialize",
|
||||
"Deserialize": "System.Runtime.Deserialize",
|
||||
|
||||
// Blockchain API
|
||||
"GetHeight": "System.Blockchain.GetHeight",
|
||||
"GetHeader": "System.Blockchain.GetHeader",
|
||||
"GetBlock": "System.Blockchain.GetBlock",
|
||||
"GetTransaction": "System.Blockchain.GetTransaction",
|
||||
"GetTransactionHeight": "System.Blockchain.GetTransactionHeight",
|
||||
"GetContract": "System.Blockchain.GetContract",
|
||||
|
||||
// Header API
|
||||
"GetIndex": "System.Header.GetContract",
|
||||
"GetHash": "System.Header.GetHash",
|
||||
"GetPrevHash": "System.Header.GetPrevHash",
|
||||
"GetTimestamp": "System.Header.GetTimestamp",
|
||||
|
||||
// Block API
|
||||
"GetTransactionCount": "System.Block.GetTransactionCount",
|
||||
"GetTransactions": "System.Block.GetTransactions",
|
||||
// TODO: Find solution for duplicated map entry
|
||||
"NGetTransaction": "System.Block.GetTransaction",
|
||||
|
||||
//
|
||||
// NEO specific API
|
||||
//
|
||||
|
||||
// Blockchain API
|
||||
"GetAccount": "Neo.Blockchain.GetAccount",
|
||||
"GetValidators": "Neo.Blockchain.GetValidators",
|
||||
"GetAsset": "Neo.Blockchain.GetAsset",
|
||||
|
||||
// Header API
|
||||
"GetVersion": "Neo.Header.GetVersion",
|
||||
"GetMerkleRoot": "Neo.Header.GetMerkleRoot",
|
||||
"GetConsensusData": "Neo.Header.GetConsensusData",
|
||||
"GetNextConsensus": "Neo.Header.GetNextConsensus",
|
||||
|
||||
// Transaction API
|
||||
"GetType": "Neo.Transaction.GetType",
|
||||
"GetAttributes": "Neo.Transaction.GetAttributes",
|
||||
"GetInputs": "Neo.Transaction.GetInputs",
|
||||
"GetOutputs": "Neo.Transaction.GetOutputs",
|
||||
"GetReferences": "Neo.Transaction.GetReferences",
|
||||
"GetUnspentCoins": "Neo.Transaction.GetUnspentCoins",
|
||||
"GetScript": "Neo.InvocationTransaction.GetScript",
|
||||
|
||||
// TODO: Add the rest of the interop APIS
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package vm
|
||||
|
||||
// Syscalls are a mapping between the syscall function name
|
||||
// and the registered VM interop API.
|
||||
var Syscalls = map[string]string{
|
||||
// Storage API
|
||||
"GetContext": "Neo.Storage.GetContext",
|
||||
"Put": "Neo.Storage.Put",
|
||||
"Get": "Neo.Storage.Get",
|
||||
"Delete": "Neo.Storage.Delete",
|
||||
|
||||
// Runtime API
|
||||
"GetTrigger": "Neo.Runtime.GetTrigger",
|
||||
"CheckWitness": "Neo.Runtime.CheckWitness",
|
||||
"GetCurrentBlock": "Neo.Runtime.GetCurrentBlock",
|
||||
"GetTime": "Neo.Runtime.GetTime",
|
||||
"Notify": "Neo.Runtime.Notify",
|
||||
"Log": "Neo.Runtime.Log",
|
||||
}
|
Loading…
Reference in a new issue