pub enum Op {
Show 47 variants
Illegal,
Pop,
PopUpvalue,
Copy(usize),
Swap,
Constant(usize),
Tuple(usize),
List(usize),
Set(usize),
Dict(usize),
GetIndex,
GetConstIndex(i64),
AssignIndex,
Contains,
GetField(usize),
AssignField(usize),
Add,
Sub,
Mul,
Div,
Neg,
And,
Or,
Not,
Is,
Jmp(usize),
JmpFalse(usize),
JmpNPop(usize, usize),
Equal,
Less,
Greater,
Assert,
Unreachable,
ReadLocal(usize),
AssignLocal(usize),
ReadUpvalue(usize),
AssignUpvalue(usize),
ReadGlobal(usize),
AssignGlobal(usize),
Define(usize),
Force(usize),
Union,
Link(usize),
Call(usize),
Print,
Return,
Yield,
}
Expand description
Ops are operations that the virtual machine carries out when running the “byte-code”.
Variants§
Illegal
This instruction should never be run. Finding it in a program is a critical error.
Pop
Pops one value from the stack.
{A, B} - Pop - {A}
PopUpvalue
Assumes the value on the top of the stack has an upvalue, and closes that upvalue.
{A, B} - Pop - {A}
Copy(usize)
Copies the N values on the top of the stack and puts them on top of the stack.
{A, B} - Copy(2) - {A, B, A, B}
Swap
Swaps the two top stack elements.
{A, B} - Swap(2) - {B, A}
Constant(usize)
Adds the value indexed in the constants-vector
to the top of the stack.
Also links upvalues if the value is a function.
{A} - Constant(B) - {A, B}
Tuple(usize)
Creates a new [Value::Tuple] with the given size and place it on the top of the stack.
{A, B, C} - Tuple(3) - {D(A, B, C)}
List(usize)
Creates a new [Value::List] with the given size and place it on the top of the stack.
{A, B, C} - List(3) - {D(A, B, C)}
Set(usize)
Creates a new [Value::Set] with the given elements and place it on the top of the stack.
{A, B, A} - Set(3) - {D(A, B)}
Dict(usize)
Creates a new [Value::Dict] with the given elements and place it on the top of the stack.
{A, B, C, D, A, E} - Dict(6) - {D(A:E, C:D)}
GetIndex
Indexes something indexable, and adds that element to the stack.
{T, I} - Index - {T[I]}
GetConstIndex(i64)
Indexes something indexable with a constant integer, and adds that element to the stack.
{T} - Index(I) - {T[I]}
AssignIndex
Assigns the indexes of something indexable. T[I] = V
{T, I, V} - Index - {}
Contains
Looks up a field by the given name and replaces the parent with it. Currently only expects [Value::Blob]. (name is looked up in the internal string-list)
{O} - Get(F) - {O.F}
GetField(usize)
Checks if the given value is inside the container. Pushes a bool to the stack.
{I, A} - Contains - {I in A}
AssignField(usize)
Looks up a field by the given name and replaces the current value in the object. Currently only expects [Value::Blob]. (name is looked up in the internal string-list)
{O} - Set(F) - {}
Add
Adds the two top elements on the stack, using the function [op::add]. The result is the pushed.
{A, B} - Add - {A + B}
Sub
Sub the two top elements on the stack, using the function [op::sub]. The result is the pushed.
{A, B} - Sub - {A - B}
Mul
Multiples the two top elements on the stack, using the function [op::mul]. The result is the pushed.
{A, B} - Mul - {A - B}
Div
Divides the two top elements on the stack, using the function [op::div]. The result is the pushed.
{A, B} - Div - {A / B}
Neg
Negates the top element on the stack.
{A} - Neg - {-A}
And
Performs a boolean and on the top 2 stack elements using [op::and].
{A, B} - And - {A && B}
Or
Performs a boolean or on the top 2 stack elements using [op::or].
{A, B} - Or - {A || B}
Not
Performs a boolean not on the top stack element using [op::not].
{A} - Not - {!A}
Is
Checks if the type of the value on the left is the type on the right.
{A, B} - Is - {A is B}
Jmp(usize)
Sets the instruction pointer to the given value.
Does not affect the stack.
JmpFalse(usize)
Sets the instruction pointer to the given value, if the topmost value is false, also pops this value.
{A} - JmpFalse(n) - {}
JmpNPop(usize, usize)
Sets the instruction pointer to the given value and pops the given amount of values.
Used for ‘break’ and ‘continue’.
{A, B, C} - JmpNPop(n, 2) - {A}
Equal
Compares the two topmost elements on the stack for equality, and pushes the result. Compares using [op::eq].
{A, B} - Equal - {A == B}
Less
Compares the two topmost elements on the stack for order, and pushes the result. Compares using [op::less].
{A, B} - Less - {A < B}
Greater
Compares the two topmost elements on the stack for order, and pushes the result. Compares using [op::less].
{A, B} - Greater - {B < A}
Assert
Pops the top value of the stack, and crashes the program if it is false.
{A} - Assert - {}
Unreachable
This instruction should not be executed. If it is the program crashes.
Does not affect the stack.
ReadLocal(usize)
Reads the value counted from the bottom of the stack and adds it to the top.
{A, B} - ReadLocal(0) - {A, B, A}
AssignLocal(usize)
Sets the value at the given index of the stack, to the topmost value. Pops the topsmost element.
{A, B} - AssignLocal(0) - {B}
ReadUpvalue(usize)
Reads the upvalue, and adds it to the top of the stack.
{} - ReadUpvalue(0) - {A}
AssignUpvalue(usize)
Sets the given upvalue, and pops the topmost element.
{A} - AssignUpvalue(0) - {}
ReadGlobal(usize)
Reads the global, and adds it to the top of the stack.
Globals are stored at the bottom of the stack and initalized when the program starts.
{} - ReadGlobal(0) - {C}
AssignGlobal(usize)
Sets the given constant, and pops the topmost element.
{A} - AssignGlobal(0) - {}
Define(usize)
A helper instruction for the type checker. Makes sure that the top value on the stack is of the given type, and is meant to signal that the “variable” is added. (The type is looked up in the constants vector.)
Does not affect the stack.
Force(usize)
A helper instruction for the typechecker, assumes top value on the stack is of the given type. Usefull for helping the type system where it just can’t do it. (The type is looked up in the constants vector)
Does not affect the stack.
Union
A helper instruction for the typechecker, combines the two top value on the stack into a union type.
Skipped in the runtime. In the typechecker: {A, B} - Union - {A | B}
Link(usize)
Links the upvalues for the given constant function. This updates the constant stack.
Does not affect the stack.
Call(usize)
Calls “something” with the given number of arguments. The callable value is then replaced with the result.
Callable things are: [Value::Blob], [Value::Function], and [Value::ExternFunction].
{F, A, B} - Call(2) - {F(A, B)}
Prints and pops the top value on the stack.
{A} - Print - {}
Return
Pops the current stackframe and replaces slot 0 with the top value. Also pops upvalues.
{F, A, B} - Return - {…, B}
Yield
Temporarily stops execution and returns to the call site.
Does not affect the stack.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Op
impl RefUnwindSafe for Op
impl Send for Op
impl Sync for Op
impl Unpin for Op
impl UnwindSafe for Op
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>
fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>
Source§fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>
fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>
Source§fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>
fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>
Source§fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>
fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>
Source§fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>
fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>
Source§fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>
fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>
Source§fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>
fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>
Source§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
Source§fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>
fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>
Source§fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>
fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>
Source§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
Source§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
Source§fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
Source§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
Source§fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>
fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>
Source§fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>
fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>
Source§fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>
fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>
Source§fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>
fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>
Source§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
Source§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
Source§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
Source§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
Source§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
Source§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
Source§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
Source§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
Source§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
Source§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
Source§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
Source§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
Source§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
Source§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
Source§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
Source§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
Source§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
Source§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
Source§fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>
fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>
Source§fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>
fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>
Source§fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>
fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>
Source§fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>
fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>
Source§fn blink<'a>(&'a self) -> BlinkDisplay<'a, Self>
fn blink<'a>(&'a self) -> BlinkDisplay<'a, Self>
Source§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
Source§fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>
fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>
Source§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more