Documentation ¶
Overview ¶
Package vm handles the line-by-line execution of vise bytecode.
Index ¶
- Constants
- Variables
- func CheckTarget(target []byte, st *state.State) (bool, error)
- func NewLine(instructionList []byte, instruction uint16, strargs []string, byteargs []byte, ...) []byte
- func ParseAll(b []byte, w io.Writer) (int, error)
- func ParseCatch(b []byte) (string, uint32, bool, []byte, error)
- func ParseCroak(b []byte) (uint32, bool, []byte, error)
- func ParseHalt(b []byte) ([]byte, error)
- func ParseInCmp(b []byte) (string, string, []byte, error)
- func ParseLoad(b []byte) (string, uint32, []byte, error)
- func ParseMNext(b []byte) (string, string, []byte, error)
- func ParseMOut(b []byte) (string, string, []byte, error)
- func ParseMPrev(b []byte) (string, string, []byte, error)
- func ParseMSize(b []byte) (uint32, uint32, []byte, error)
- func ParseMap(b []byte) (string, []byte, error)
- func ParseMove(b []byte) (string, []byte, error)
- func ParseReload(b []byte) (string, []byte, error)
- func ToString(b []byte) (string, error)
- func ValidInput(input []byte) error
- func ValidSym(input []byte) error
- type Opcode
- type Vm
- func (vm *Vm) Render(ctx context.Context) (string, error)
- func (vmi *Vm) Reset()
- func (vm *Vm) Run(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunCatch(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunCroak(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunHalt(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunLoad(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunMNext(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunMOut(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunMPrev(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunMSize(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunMap(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunMove(b []byte, ctx context.Context) ([]byte, error)
- func (vm *Vm) RunReload(b []byte, ctx context.Context) ([]byte, error)
Constants ¶
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
const VERSION = 0
Variables ¶
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 ¶
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 ¶
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 ¶
ParseCatch parses and extracts the expected argument portion of a CATCH instruction
func ParseCroak ¶
ParseCroak parses and extracts the expected argument portion of a CROAK instruction
func ParseInCmp ¶
ParseInCmp parses and extracts the expected argument portion of a INCMP instruction
func ParseMNext ¶
ParseMNext parses and extracts the expected argument portion of a MNEXT instruction
func ParseMPrev ¶
ParseMPrev parses and extracts the expected argument portion of a MPREV instruction
func ParseMSize ¶
ParseMSize parses and extracts the expected argument portion of a MSIZE instruction
func ParseReload ¶
ParseReload parses and extracts the expected argument portion of a RELOAD instruction
func ToString ¶
ToString verifies all instructions in bytecode and returns an assmebly code instruction for it.
func ValidInput ¶
CheckInput validates the given byte string as client input.
Types ¶
type Vm ¶
type Vm struct {
// contains filtered or unexported fields
}
Vm holds sub-components mutated by the vm execution.
func (*Vm) Render ¶
Render wraps output rendering, and handles error when attempting to browse beyond the rendered page count.
func (*Vm) Run ¶
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) RunDeadCheck ¶
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) RunInCmp ¶
RunIncmp executes the INCMP opcode TODO: create state transition table and simplify flow