vm

package
v6.5.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 5 Imported by: 338

Documentation

Overview

The GADGT VM implementation and instruction set

Index

Constants

View Source
const (
	Unused int = iota
	Null
	Boolean
	Int
	Long
	Float
	Double
	Bytes
	String
	UnionElem
	UnusedLong
)

Constants for the data types supported by the Read and Set operations. If the value is > 9 it's assumed to be the length of a Fixed type.

View Source
const NoopField = 65535

The value of NoopField as the pperand signifies the operand is unused.

Variables

This section is empty.

Functions

func Eval

func Eval(r io.Reader, program *Program, target types.Field) (err error)

func WriteBool

func WriteBool(r bool, w io.Writer) error

func WriteBytes

func WriteBytes(r []byte, w io.Writer) error

func WriteDouble

func WriteDouble(r float64, w io.Writer) error

func WriteFloat

func WriteFloat(r float32, w io.Writer) error

func WriteInt

func WriteInt(r int32, w io.Writer) error

func WriteLong

func WriteLong(r int64, w io.Writer) error

func WriteNull

func WriteNull(_ interface{}, _ io.Writer) error

func WriteString

func WriteString(r string, w io.Writer) error

Types

type ByteReader

type ByteReader interface {
	ReadByte() (byte, error)
}

type ByteWriter

type ByteWriter interface {
	Grow(int)
	WriteByte(byte) error
}

type Instruction

type Instruction struct {
	Op      Op
	Operand int
}

Represents a single VM instruction consisting of an opcode and 0 or 1 operands.

func (Instruction) String

func (i Instruction) String() string

type Op

type Op int

OP represents an opcode for the VM. Operations take 0 or 1 operands.

const (
	// Read a value of the operand type from the wire and put itin the frame
	Read Op = iota

	// Set the current target to the value of the operand type from the frame
	Set

	// Allocate a new frame and make the target the field with the operand index
	Enter

	// Move to the previous frame
	Exit

	// Append a value to the current target and enter the new value
	AppendArray

	// Append a new key-value pair (where the key is the String value in the current frame) to the current target and enter the new value
	AppendMap

	// Set the value of the field at the operand index to it's default value
	SetDefault

	// Push the current address onto the call stack and move the PC to the operand address
	Call

	// Pop the top value frmm the call stack and set the PC to that address
	Return

	// Stop the VM. If the operand is greater than zero, look up the corresponding error message and return it
	Halt

	// Move the PC to the operand
	Jump

	// Evaluate whether the Long register is equal to the operand, and set the condition register to the result
	EvalEqual

	// Evaluate whether the Long register is greater than the operand, and set the condition register to the result
	EvalGreater

	// If the condition register is true, jump to the operand instruction
	CondJump

	// Set the Long register to the operand value
	SetLong

	// Add the operand value to the Long register
	AddLong

	// Multiply the operand value by the Long register
	MultLong

	// Push the current Long register value onto the loop stack
	PushLoop

	// Pop the top of the loop stack and store the value in the Long register
	PopLoop
)

func (Op) String

func (o Op) String() string

type Program

type Program struct {
	// The list of instructions that make up the deserializer program
	Instructions []Instruction

	// A list of errors that can be triggered by halt(x), where x is the index in this array + 1
	Errors []string
}

func (*Program) String

func (p *Program) String() string

type StringWriter

type StringWriter interface {
	WriteString(string) (int, error)
}

Directories

Path Synopsis
Wrappers for Avro primitive types implementing the methods required by GADGT
Wrappers for Avro primitive types implementing the methods required by GADGT

Jump to

Keyboard shortcuts

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