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 NewInvalidInputError(input string) error
- func NewLine(instructionList []byte, instruction uint16, strargs []string, byteargs []byte, ...) []byte
- 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 ParseMSink(b []byte) ([]byte, error)
- func ParseMap(b []byte) (string, []byte, error)
- func ParseMove(b []byte) (string, []byte, error)
- func ParseReload(b []byte) (string, []byte, error)
- func RegisterInputValidator(k int, v string) error
- func Rewind(sym string, st *state.State, ca cache.Memory) (string, error)
- func ValidInput(input []byte) (int, error)
- func ValidSym(input []byte) error
- type ExternalCodeError
- type InvalidInputError
- type Opcode
- type ParseHandler
- type Vm
Constants ¶
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
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", 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 ¶
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 ¶
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 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 ParseHalt ¶
ParseHalt parses and extracts the expected argument portion of a HALT instruction
func ParseInCmp ¶
ParseInCmp parses and extracts the expected argument portion of a INCMP instruction
func ParseLoad ¶
ParseLoad parses and extracts the expected argument portion of a LOAD instruction
func ParseMNext ¶
ParseMNext parses and extracts the expected argument portion of a MNEXT instruction
func ParseMOut ¶
ParseMOut parses and extracts the expected argument portion of a MOUT instruction
func ParseMPrev ¶
ParseMPrev parses and extracts the expected argument portion of a MPREV instruction
func ParseMSink ¶
ParseMSink parses and extracts the expected argument portion of a MSINK instruction
func ParseMap ¶
ParseMap parses and extracts the expected argument portion of a MAP instruction
func ParseMove ¶
ParseMove parses and extracts the expected argument portion of a MOVE instruction
func ParseReload ¶
ParseReload parses and extracts the expected argument portion of a RELOAD instruction
func Rewind ¶ added in v0.3.0
func ValidInput ¶
CheckInput validates the given byte string as client input.
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 ParseHandler ¶ added in v0.3.0
type ParseHandler struct { Catch func(string, uint32, bool) error Croak func(uint32, bool) error Load func(string, uint32) error Reload func(string) error Map func(string) error Move func(string) error Halt func() error InCmp func(string, string) error MOut func(string, string) error MSink func() error MNext func(string, string) error MPrev func(string, string) error // contains filtered or unexported fields }
func NewParseHandler ¶ added in v0.3.0
func NewParseHandler() *ParseHandler
func (*ParseHandler) Length ¶ added in v0.3.0
func (ph *ParseHandler) Length() int
func (*ParseHandler) ParseAll ¶ added in v0.3.0
func (ph *ParseHandler) ParseAll(b []byte) (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 (*ParseHandler) ToString ¶ added in v0.3.0
func (ph *ParseHandler) ToString(b []byte) (string, error)
ToString verifies all instructions in bytecode and returns an assmebly code instruction for it.
func (*ParseHandler) WithDefaultHandlers ¶ added in v0.3.0
func (ph *ParseHandler) WithDefaultHandlers() *ParseHandler
func (*ParseHandler) WithWriter ¶ added in v0.3.0
func (ph *ParseHandler) WithWriter(w io.Writer) *ParseHandler
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 ¶
NewVm creates a new Vm.
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.