state

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package state handles execution state, including navigation and state flags.

Index

Constants

View Source
const (
	// Currently reading input. Set by first INCMP instruction encontered.
	FLAG_READIN = iota
	// Input matched a selector. Set by first INCMP matching input.
	FLAG_INMATCH
	// The instruction HALT has been encountered.
	FLAG_WAIT
	// The last LOAD or RELOAD executed returneded an error.
	FLAG_LOADFAIL
	// A LOAD or RELOAD has returned fresh data.
	FLAG_DIRTY
	// Not currently in use.
	FLAG_RESERVED
	// VM execution is blocked.
	FLAG_TERMINATE
	// The return value from a LOAD or RELOAD is a new language selection.
	FLAG_LANG
	// User-defined flags start here.
	FLAG_USERSTART = 8
)
View Source
const (
	INPUT_LIMIT = 255
)

Variables

View Source
var (
	IndexError = fmt.Errorf("already at first index")
	MaxLevel   = 128
)
View Source
var (
	FlagDebugger = newFlagDebugger()
)

Functions

func IsWriteableFlag

func IsWriteableFlag(flag uint32) bool

IsWriteableFlag returns true if flag can be set by implementer code.

Types

type State

type State struct {
	Code     []byte         // Pending bytecode to execute
	ExecPath []string       // Command symbols stack
	BitSize  uint32         // Size of (32-bit capacity) bit flag byte array
	SizeIdx  uint16         // Lateral page browse index in current frame
	Flags    []byte         // Error state
	Moves    uint32         // Number of times navigation has been performed
	Language *lang.Language // Language selector for rendering
	// contains filtered or unexported fields
}

State holds the command stack, error condition of a unique execution session.

It also holds cached values for all results of executed symbols.

Cached values are linked to the command stack level it which they were loaded. When they go out of scope they are freed.

It can hold a single argument, which is freed once it is read.

Values must be mapped to a level in order to be available for retrieval and count towards size.

Symbols are loaded with individual size limitations. The limitations apply if a load symbol is updated. Symbols may be added with a 0-value for limits, called a "sink." If mapped, the sink will consume all net remaining size allowance unused by other symbols. Only one sink may be mapped per level.

Symbol keys do not count towards cache size limitations.

8 first flags are reserved.

func NewState

func NewState(BitSize uint32) *State

NewState creates a new State object with BitSize number of error condition states in ADDITION to the 8 builtin flags.

func (*State) AppendCode

func (st *State) AppendCode(b []byte) error

Appendcode adds the given bytecode to the end of the existing code.

func (*State) CloneEmpty

func (st *State) CloneEmpty() *State

func (*State) Depth

func (st *State) Depth() int

Depth returns the current call stack depth.

func (*State) Down

func (st *State) Down(input string) error

Down adds the given symbol to the command stack.

Clears mapping and sink.

func (*State) FlagBitSize

func (st *State) FlagBitSize() uint32

FlagBitSize reports the amount of bits available in the bit field index.

func (*State) FlagByteSize

func (st *State) FlagByteSize() uint8

FlagBitSize reports the amount of bits available in the bit field index.

func (*State) GetCode

func (st *State) GetCode() ([]byte, error)

Get the remaning cached bytecode

func (*State) GetFlag

func (st *State) GetFlag(bitIndex uint32) bool

GetFlag returns the state of the flag at the given bit field index.

Fails if bit field index is out of range.

func (*State) GetIndex

func (st *State) GetIndex(flags []byte) bool

GetIndex scans a byte slice in same order as in storage, and returns the index of the first set bit.

If the given byte slice is too small for the bit field bitsize, the check will terminate at end-of-data without error.

func (*State) GetInput

func (st *State) GetInput() ([]byte, error)

GetInput gets the most recent client input.

func (*State) Invalid

func (st *State) Invalid() bool

Invalid returns true if state is invalid.

An invalid state should not be persisted or propagated

func (*State) Invalidate

func (st *State) Invalidate()

Invalidate marks a state as invalid.

An invalid state should not be persisted or propagated

func (*State) MatchFlag

func (st *State) MatchFlag(sig uint32, matchSet bool) bool

MatchFlag matches the current state of the given flag.

The flag is specified given its bit index in the bit field.

If matchSet is set, a positive result will be returned if the flag is set.

func (*State) Next

func (st *State) Next() (uint16, error)

Next moves to the next sink page index.

func (*State) Previous

func (st *State) Previous() (uint16, error)

Previous moves to the next sink page index.

Fails if try to move beyond index 0.

func (*State) ResetFlag

func (st *State) ResetFlag(bitIndex uint32) bool

ResetFlag resets the flag at the given bit field index.

Returns true if bit state was changed.

Fails if bitindex is out of range.

func (*State) Restart

func (st *State) Restart() error

Reset re-initializes the state to run from top node with accumulated client state.

func (*State) Same

func (st *State) Same()

func (*State) SetCode

func (st *State) SetCode(b []byte)

SetCode replaces the current bytecode with the given bytecode.

func (*State) SetFlag

func (st *State) SetFlag(bitIndex uint32) bool

SetFlag sets the flag at the given bit field index

Returns true if bit state was changed.

Fails if bitindex is out of range.

func (*State) SetInput

func (st *State) SetInput(input []byte) error

SetInput is used to record the latest client input.

func (*State) SetLanguage

func (st *State) SetLanguage(code string) error

SetLanguage validates and sets language according to the given ISO639 language code.

func (*State) Sides

func (st *State) Sides() (bool, bool)

Sides informs the caller which index page options will currently succeed.

Two values are returned, for the "next" and "previous" options in that order. A false value means the option is not available in the current state.

func (*State) String

func (st *State) String() string

String implements String interface

func (*State) Top

func (st *State) Top() (bool, error)

Top returns true if currently at topmode node.

Fails if first Down() was never called.

func (*State) Up

func (st *State) Up() (string, error)

Up removes the latest symbol to the command stack, and make the previous symbol current.

Frees all symbols and associated values loaded at the previous stack level. Cache capacity is increased by the corresponding amount.

Clears mapping and sink.

Fails if called at top frame.

func (*State) UseDebug

func (st *State) UseDebug()

UseDebug enables rendering of registered string values of state flags in the string representation.

func (*State) Where

func (st *State) Where() (string, uint16)

Where returns the current active rendering symbol.

Jump to

Keyboard shortcuts

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