Documentation
¶
Overview ¶
Package state handles execution state, including navigation and state flags.
Index ¶
- Constants
- Variables
- func IsWriteableFlag(flag uint32) bool
- type State
- func (st *State) AppendCode(b []byte) error
- func (st *State) Back() bool
- func (st *State) CloneEmpty() *State
- func (st *State) Depth() int
- func (st *State) Down(input string) error
- func (st *State) FlagBitSize() uint32
- func (st *State) FlagByteSize() uint8
- func (st *State) GetCode() ([]byte, error)
- func (st *State) GetFlag(bitIndex uint32) bool
- func (st *State) GetIndex(flags []byte) bool
- func (st *State) GetInput() ([]byte, error)
- func (st *State) Invalid() bool
- func (st *State) Invalidate()
- func (st *State) Lateral() bool
- func (st *State) MatchFlag(sig uint32, matchSet bool) bool
- func (st *State) Next() (uint16, error)
- func (st *State) Previous() (uint16, error)
- func (st *State) ResetFlag(bitIndex uint32) bool
- func (st *State) Restart() error
- func (st *State) Same()
- func (st *State) SetCode(b []byte)
- func (st *State) SetFlag(bitIndex uint32) bool
- func (st *State) SetInput(input []byte) error
- func (st *State) SetLanguage(code string) error
- func (st *State) Sides() (bool, bool)
- func (st *State) String() string
- func (st *State) Top() (bool, error)
- func (st *State) Up() (string, error)
- func (st *State) UseDebug()
- func (st *State) Where() (string, uint16)
Constants ¶
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 )
const (
INPUT_LIMIT = 255
)
Variables ¶
var (
FlagDebugger = newFlagDebugger()
)
Functions ¶
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 ¶
NewState creates a new State object with BitSize number of error condition states in ADDITION to the 8 builtin flags.
func (*State) AppendCode ¶
Appendcode adds the given bytecode to the end of the existing code.
func (*State) Back ¶ added in v0.2.2
Back returns true if the last state move was Up()
func (*State) FlagBitSize ¶
FlagBitSize reports the amount of bits available in the bit field index.
func (*State) FlagByteSize ¶
FlagBitSize reports the amount of bits available in the bit field index.
func (*State) GetFlag ¶
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 ¶
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 ¶
GetInput gets the most recent client input.
func (*State) Invalid ¶
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) Lateral ¶ added in v0.2.2
Lateral returns true if the last state move was Next() or Previous()
func (*State) MatchFlag ¶
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 ¶
Next moves to the next sink page index.
func (*State) Previous ¶
Previous moves to the next sink page index.
Fails if try to move beyond index 0.
func (*State) ResetFlag ¶
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 ¶
Reset re-initializes the state to run from top node with accumulated client state.
func (*State) SetCode ¶
SetCode replaces the current bytecode with the given bytecode.
func (*State) SetFlag ¶
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 ¶
SetInput is used to record the latest client input.
func (*State) SetLanguage ¶
SetLanguage validates and sets language according to the given ISO639 language code.
func (*State) Sides ¶
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) Top ¶
Top returns true if currently at topmode node.
Fails if first Down() was never called.
func (*State) Up ¶
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.