vm

package
v6.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2019 License: MIT Imports: 5 Imported by: 0

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 added in v6.3.0

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

func WriteBytes added in v6.3.0

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

func WriteDouble added in v6.3.0

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

func WriteFloat added in v6.3.0

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

func WriteInt added in v6.3.0

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

func WriteLong added in v6.3.0

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

func WriteNull added in v6.3.0

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

func WriteString added in v6.3.0

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

Types

type ByteReader

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

type ByteWriter added in v6.3.0

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 added in v6.3.0

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