vm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package vm handles the line-by-line execution of vise bytecode.

Index

Constants

View Source
const (
	NOOP   = 0
	CATCH  = 1
	CROAK  = 2
	LOAD   = 3
	RELOAD = 4
	MAP    = 5
	MOVE   = 6
	HALT   = 7
	INCMP  = 8
	MSINK  = 9
	MOUT   = 10
	MNEXT  = 11
	MPREV  = 12
)

VM Opcodes

View Source
const VERSION = 0

Variables

View Source
var (
	OpcodeString = map[Opcode]string{
		NOOP:   "NOOP",
		CATCH:  "CATCH",
		CROAK:  "CROAK",
		LOAD:   "LOAD",
		RELOAD: "RELOAD",
		MAP:    "MAP",
		MOVE:   "MOVE",
		HALT:   "HALT",
		INCMP:  "INCMP",
		MSINK:  "MSINK",
		MOUT:   "MOUT",
		MNEXT:  "MNEXT",
		MPREV:  "MPREV",
	}

	OpcodeIndex = map[string]Opcode{
		"NOOP":   NOOP,
		"CATCH":  CATCH,
		"CROAK":  CROAK,
		"LOAD":   LOAD,
		"RELOAD": RELOAD,
		"MAP":    MAP,
		"MOVE":   MOVE,
		"HALT":   HALT,
		"INCMP":  INCMP,
		"MSINK":  MSINK,
		"MOUT":   MOUT,
		"MNEXT":  MNEXT,
		"MPREV":  MPREV,
	}
)

Functions

func CheckTarget

func CheckTarget(target []byte, st *state.State) (bool, error)

CheckTarget tests whether the navigation state transition is available in the current state.

Fails if target is formally invalid, or if navigation is unavailable.

func NewInvalidInputError

func NewInvalidInputError(input string) error

NewInvalidInputError creates a new InvalidInputError

func NewLine

func NewLine(instructionList []byte, instruction uint16, strargs []string, byteargs []byte, numargs []uint8) []byte

NewLine creates a new instruction line for the VM.

func ParseAll

func ParseAll(b []byte, w io.Writer) (int, error)

ParseAll parses and verifies all instructions from bytecode.

If writer is not nil, the parsed instruction as assembly code line string is written to it.

Bytecode is consumed (and written) one instruction at a time.

It fails on any parse error encountered before the bytecode EOF is reached.

func ParseCatch

func ParseCatch(b []byte) (string, uint32, bool, []byte, error)

ParseCatch parses and extracts the expected argument portion of a CATCH instruction

func ParseCroak

func ParseCroak(b []byte) (uint32, bool, []byte, error)

ParseCroak parses and extracts the expected argument portion of a CROAK instruction

func ParseHalt

func ParseHalt(b []byte) ([]byte, error)

ParseHalt parses and extracts the expected argument portion of a HALT instruction

func ParseInCmp

func ParseInCmp(b []byte) (string, string, []byte, error)

ParseInCmp parses and extracts the expected argument portion of a INCMP instruction

func ParseLoad

func ParseLoad(b []byte) (string, uint32, []byte, error)

ParseLoad parses and extracts the expected argument portion of a LOAD instruction

func ParseMNext

func ParseMNext(b []byte) (string, string, []byte, error)

ParseMNext parses and extracts the expected argument portion of a MNEXT instruction

func ParseMOut

func ParseMOut(b []byte) (string, string, []byte, error)

ParseMOut parses and extracts the expected argument portion of a MOUT instruction

func ParseMPrev

func ParseMPrev(b []byte) (string, string, []byte, error)

ParseMPrev parses and extracts the expected argument portion of a MPREV instruction

func ParseMSink

func ParseMSink(b []byte) ([]byte, error)

ParseMSink parses and extracts the expected argument portion of a MSINK instruction

func ParseMap

func ParseMap(b []byte) (string, []byte, error)

ParseMap parses and extracts the expected argument portion of a MAP instruction

func ParseMove

func ParseMove(b []byte) (string, []byte, error)

ParseMove parses and extracts the expected argument portion of a MOVE instruction

func ParseReload

func ParseReload(b []byte) (string, []byte, error)

ParseReload parses and extracts the expected argument portion of a RELOAD instruction

func ToString

func ToString(b []byte) (string, error)

ToString verifies all instructions in bytecode and returns an assmebly code instruction for it.

func ValidInput

func ValidInput(input []byte) error

CheckInput validates the given byte string as client input.

func ValidSym

func ValidSym(input []byte) error

CheckSym validates the given byte string as a node symbol.

Types

type ExternalCodeError

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

ExternalCodeError indicates an error that occurred when resolving an external code symbol (LOAD, RELOAD).

func NewExternalCodeError

func NewExternalCodeError(sym string, err error) *ExternalCodeError

NewExternalCodeError creates a new ExternalCodeError.

func (ExternalCodeError) Error

func (e ExternalCodeError) Error() string

Error implements the Error interface.

func (*ExternalCodeError) WithCode

func (e *ExternalCodeError) WithCode(code int) *ExternalCodeError

type InvalidInputError

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

InvalidInputError indicates client input that was unhandled by the bytecode (INCMP fallthrough)

func (InvalidInputError) Error

func (e InvalidInputError) Error() string

Error implements the Error interface.

type Opcode

type Opcode uint16

func ParseOp

func ParseOp(b []byte) (Opcode, []byte, error)

ParseOp verifies and extracts the expected opcode portion of an instruction

type Vm

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

Vm holds sub-components mutated by the vm execution. TODO: Renderer should be passed to avoid proxy methods not strictly related to vm operation

func NewVm

func NewVm(st *state.State, rs resource.Resource, ca cache.Memory, sizer *render.Sizer) *Vm

NewVm creates a new Vm.

func (*Vm) Render

func (vm *Vm) Render(ctx context.Context) (string, error)

Render wraps output rendering, and handles error when attempting to browse beyond the rendered page count.

func (*Vm) Reset

func (vmi *Vm) Reset()

Reset re-initializes sub-components for output rendering.

func (*Vm) Run

func (vm *Vm) Run(ctx context.Context, b []byte) ([]byte, error)

Run extracts individual op codes and arguments and executes them.

Each step may update the state.

On error, the remaining instructions will be returned. State will not be rolled back.

Source Files

  • debug.go
  • doc.go
  • input.go
  • log.go
  • opcodes.go
  • runner.go
  • vm.go

Jump to

Keyboard shortcuts

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