Op

Enum Op 

Source
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}

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)}

§

Print

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§

Source§

impl Clone for Op

Source§

fn clone(&self) -> Op

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Op

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Op

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>

Change the foreground color to black
Source§

fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>

Change the foreground color to black
Source§

fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>

Change the foreground color to red
Source§

fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>

Change the foreground color to red
Source§

fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>

Change the foreground color to green
Source§

fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>

Change the foreground color to green
Source§

fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>

Change the foreground color to yellow
Source§

fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>

Change the foreground color to blue
Source§

fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the foreground color to magenta
Source§

fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the foreground color to purple
Source§

fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>

Change the foreground color to cyan
Source§

fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>

Change the foreground color to white
Source§

fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>

Change the foreground color to white
Source§

fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>

Change the foreground color to bright red
Source§

fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>

Make the text bold
Source§

fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>

Make the text dim
Source§

fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>

Make the text italicized
Source§

fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>

Make the text italicized
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>

Swap the foreground and background colors
Source§

fn hidden<'a>(&'a self) -> HiddenDisplay<'a, Self>

Hide the text
Source§

fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.