VM

package
v0.0.0-...-97f3c37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	String  dataType = 0
	Integer dataType = 1
)
View Source
const MaxSize int = 20000

Variables

View Source
var OpcodeIntToString = map[byte]string{
	0:  "Halt",
	1:  "ADD",
	2:  "SUB",
	3:  "MUL",
	4:  "DIV",
	10: "GT",
	11: "LT",
	12: "GT_EQ",
	13: "LT_EQ",
	14: "SGT",
	15: "SLT",
	16: "EQ",
	17: "AND",
	18: "OR",
	19: "NOT",
	20: "XOR",
	21: "ISZERO",
	22: "ISNEGATIVE",
	30: "POP",
	31: "PUSH32",
	32: "PUSHBOOl",
	33: "PUSHTIME",
	34: "PUSH64",
	35: "PUSH256",
	36: "PUSHSTRING",
	37: "LOAD",
	38: "STORE",
	40: "JUMP",
	41: "JUMPI",
	42: "AddToPC",
	50: "SUBSCRIBE",
	51: "EXECUTEPERIODICALLY",
	52: "WAIT_FOR_DATA",
	53: "TRANSFER",
}

Functions

func AddOP

func AddOP(interpreter *Interpreter) error

func AddToPCOp

func AddToPCOp(interpreter *Interpreter) error

func AndOP

func AndOP(interpreter *Interpreter) error

func DivOP

func DivOP(interpreter *Interpreter) error

func EqOP

func EqOP(interpreter *Interpreter) error

func ExecutePeriodicallyOp

func ExecutePeriodicallyOp(interpreter *Interpreter) error

func GTEQ_OP

func GTEQ_OP(interpreter *Interpreter) error

func GenerateByteCode

func GenerateByteCode(fileName string) []byte

func GeneratePush

func GeneratePush(a int) []byte

func GreaterOp

func GreaterOp(interpreter *Interpreter) error

GreaterOp Return 1 if a > b

func IntToByte

func IntToByte(integer uint32) []byte

func IsNegativeOp

func IsNegativeOp(interpreter *Interpreter) error

func IsZeroOp

func IsZeroOp(interpreter *Interpreter) error

func JumpIOp

func JumpIOp(interpreter *Interpreter) error

JumpIOp conditional Jump

func JumpOp

func JumpOp(interpreter *Interpreter) error

func LTEQ_OP

func LTEQ_OP(interpreter *Interpreter) error

func LessOP

func LessOP(interpreter *Interpreter) error

func LoadOp

func LoadOp(interpreter *Interpreter) error

func MulOP

func MulOP(interpreter *Interpreter) error

func NotOP

func NotOP(interpreter *Interpreter) error

func OrOP

func OrOP(interpreter *Interpreter) error

func PopOp

func PopOp(interpreter *Interpreter) error

func PushOp

func PushOp(interpreter *Interpreter) error

func PushStringOp

func PushStringOp(interpreter *Interpreter) error

func Read

func Read(dir string) []byte

func SGreaterOP

func SGreaterOP(interpreter *Interpreter) error

func SLessOP

func SLessOP(interpreter *Interpreter) error

func StoreOp

func StoreOp(interpreter *Interpreter) error

func SubOP

func SubOP(interpreter *Interpreter) error

func SubscribeOp

func SubscribeOp(interpreter *Interpreter) error

func Test1

func Test1()

func Test2

func Test2()

func Test3

func Test3()

func Test4

func Test4()

func TestInterpreter_Run

func TestInterpreter_Run(t *testing.T)

func Transfer

func Transfer(interpreter *Interpreter) error

Transfer TODO

func WaitOp

func WaitOp(interpreter *Interpreter) error

func XorOP

func XorOP(interpreter *Interpreter) error

Types

type Frequency

type Frequency byte

type Interpreter

type Interpreter struct {
	Id int

	ContractCode    []byte
	OraclePool      *OracleListener.OraclePool
	TimeListener    *TimeListener.TimeListener
	ReceiveChan     chan *Messages.BroadcastMsg
	TransactionChan chan interface{}

	IsBlocked       bool
	IsTimeDependent bool
	// contains filtered or unexported fields
}

Interpreter TODO Blocked is initially false

func NewInterpreter

func NewInterpreter(id int, contractCode []byte, pool *OracleListener.OraclePool, gasLimit uint64, timeListener *TimeListener.TimeListener) *Interpreter

func (*Interpreter) Run

func (interpreter *Interpreter) Run() error

Run TODO when error happens --> unsubscribe from the oraclePool

type JumpTable

type JumpTable [100]Operation

func NewJumpTable

func NewJumpTable() *JumpTable

type Memory

type Memory []*DataTypes.DataWord

type OPCODE

type OPCODE byte
const (
	Halt                OPCODE = 0
	ADD                 OPCODE = 1
	SUB                 OPCODE = 2
	MUL                 OPCODE = 3
	DIV                 OPCODE = 4
	GT                  OPCODE = 10
	LT                  OPCODE = 11
	GT_EQ               OPCODE = 12
	LT_EQ               OPCODE = 13
	SGT                 OPCODE = 14
	SLT                 OPCODE = 15
	EQ                  OPCODE = 16
	AND                 OPCODE = 17
	OR                  OPCODE = 18
	NOT                 OPCODE = 19
	XOR                 OPCODE = 20
	ISZERO              OPCODE = 21
	ISNEGATIVE          OPCODE = 22
	POP                 OPCODE = 30
	PUSH32              OPCODE = 31
	PUSHBOOl            OPCODE = 32
	PUSHTIME            OPCODE = 33
	PUSH64              OPCODE = 34
	PUSH256             OPCODE = 35
	PUSHSTRING          OPCODE = 36
	LOAD                OPCODE = 37
	STORE               OPCODE = 38
	JUMP                OPCODE = 40
	JUMPI               OPCODE = 41
	AddToPC             OPCODE = 42
	SUBSCRIBE           OPCODE = 50
	EXECUTEPERIODICALLY OPCODE = 51
	WAIT_FOR_DATA       OPCODE = 52
	TRANSFER            OPCODE = 53
)

type Operation

type Operation struct {
	// contains filtered or unexported fields
}

type OperationType

type OperationType func(interpreter *Interpreter) error

type Stack

type Stack []*DataTypes.DataWord

func (*Stack) IsEmpty

func (stack *Stack) IsEmpty() bool

func (*Stack) Peek

func (stack *Stack) Peek() (*DataTypes.DataWord, bool)

func (*Stack) Pop

func (stack *Stack) Pop() *DataTypes.DataWord

func (*Stack) Push

func (stack *Stack) Push(x *DataTypes.DataWord)

func (*Stack) Size

func (stack *Stack) Size() int

type State

type State struct {
	Stack  *Stack
	Memory Memory
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL