pub enum Stack {
Show 13 variants
Push(Word),
Pop,
Dup,
DupFrom,
Swap,
SwapIndex,
Select,
SelectRange,
Repeat,
RepeatEnd,
Reserve,
Load,
Store,
}
Expand description
Operations related to stack manipulation.
Variants§
Push(Word)
0x01
Push one word onto the stack.
§Bytecode Argument
This operation expects a 8-byte (1-word) argument following its opcode within bytecode.
§Stack Output
[value]
Pop
Dup
DupFrom
0x04
: DUPF
Duplicate the word at the given stack depth index.
0
is the index of the element at the top of the stack.
§Stack Input
[index]
§Stack Output
[value_i]
Swap
SwapIndex
0x06
: SWAPI
Swap the top word on the stack with the word at the given stack depth index.
0
is the index of the element at the top of the stack.
§Stack Input
[a, b, c, d, index]
§Stack Output
[a, d, c, b]
§Panics
- Index is out of range.
Select
0x07
: SEL
Conditionally keep one of the top two elements on the stack.
If condition is true
, the top element is kept.
§Stack Input
[a, b, cond]
§Stack Output
[b]
SelectRange
0x08
: SLTR
Conditionally keep one of the top two ranges on the stack.
If condition is true
, the top range is kept.
The ranges must be of equal length.
The ranges must be stacked sequentially.
Here N
is len -1
.
§Stack Input
[arr_a_0, ..arr_a_N, arr_b_0, ..arr_b_N, len, cond]
§Stack Output
[arr_b_0, ..arr_b_N]
Repeat
0x09
: REP
Repeat a section of code the number of times. Takes a boolean to either count from 0 up or from the number of repeats down to 0.
§Stack Input
[num_repeats, count_up_bool]
RepeatEnd
0x0A
: REPE
Increment or decrements the top counter on the repeat stack.
If the counter is counting up and counter == limit - 1
then this pops the counter and continues with the program.
If the counter is counting down and the counter is 0
then this pops the counter and continues with the program.
If it is < limit - 1
or > 0
respectively then the program jumps to
the last Repeat
§Panics
- If there is no counter on the repeat stack.
- If there is no repeat registered to return to.
Reserve
0x0B
: RES
Reserve space on the stack for len
words.
The reserved space is set to 0.
§Stack Input
[len]
Load
0x0C
: LODS
Load the value at the given stack depth index relative to the bottom.
0
is the index of the element at the bottom of the stack.
§Stack Input
[index]
§Stack Output
[value]
§Panics
- Index is out of range.