vm

package
v0.0.9-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: AGPL-3.0 Imports: 11 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
	MSIZE  = 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",
		MSIZE:  "MSIZE",
		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,
		"MSIZE":  MSIZE,
		"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 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 ParseMSize

func ParseMSize(b []byte) (uint32, uint32, []byte, error)

ParseMSize parses and extracts the expected argument portion of a MSIZE 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 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.

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(b []byte, ctx context.Context) ([]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.

func (*Vm) RunCatch

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

RunMap executes the CATCH opcode

func (*Vm) RunCroak

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

RunMap executes the CROAK opcode

func (*Vm) RunDeadCheck

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

RunDeadCheck determines whether a state of empty bytecode should result in termination.

If there is remaining bytecode, this method is a noop.

If input has not been matched, a default invalid input page should be generated aswell as a possiblity of return to last screen (or exit).

If the termination flag has been set but not yet handled, execution is allowed to terminate.

func (*Vm) RunHalt

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

RunHalt executes the HALT opcode

func (*Vm) RunInCmp

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

RunIncmp executes the INCMP opcode TODO: create state transition table and simplify flow

func (*Vm) RunLoad

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

RunLoad executes the LOAD opcode

func (*Vm) RunMNext

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

RunMNext executes the MNEXT opcode

func (*Vm) RunMOut

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

RunMOut executes the MOUT opcode

func (*Vm) RunMPrev

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

RunMPrev executes the MPREV opcode

func (*Vm) RunMSize

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

RunMSize executes the MSIZE opcode

func (*Vm) RunMap

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

RunMap executes the MAP opcode

func (*Vm) RunMove

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

RunLoad executes the MOVE opcode

func (*Vm) RunReload

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

RunLoad executes the RELOAD opcode

Jump to

Keyboard shortcuts

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