Skip to main content

Instruction

Enum Instruction 

Source
pub enum Instruction {
Show 36 variants PushNum(f64), PushBool(bool), PushSym(String), Pop, Dup, Add, Sub, Mul, Div, Pow, Mod, Neg, Abs, Sqrt, Exp, Log, Min, Max, Eq, Ne, Lt, Le, Gt, Ge, And, Or, Not, JumpIfFalse(usize), JumpIfTrue(usize), Jump(usize), LoadVar(String), StoreVar(String), TNorm, TCoNorm, FuzzyNot, Halt,
}
Expand description

Stack-based VM instruction.

Instructions operate on a Vec<VmValue> stack and an instruction pointer. All binary operations pop two values and push one; all unary operations pop one and push one.

Variants§

§

PushNum(f64)

Push a numeric constant onto the stack.

§

PushBool(bool)

Push a boolean constant onto the stack.

§

PushSym(String)

Push a symbol literal onto the stack.

§

Pop

Discard the top-of-stack value.

§

Dup

Duplicate the top-of-stack value.

§

Add

Pop b, pop a; push a + b.

§

Sub

Pop b, pop a; push a - b.

§

Mul

Pop b, pop a; push a * b.

§

Div

Pop b, pop a; push a / b (error on zero divisor).

§

Pow

Pop b, pop a; push a ^ b.

§

Mod

Pop b, pop a; push a % b.

§

Neg

Pop a; push -a.

§

Abs

Pop a; push |a|.

§

Sqrt

Pop a; push √a.

§

Exp

Pop a; push e^a.

§

Log

Pop a; push ln(a).

§

Min

Pop b, pop a; push min(a, b).

§

Max

Pop b, pop a; push max(a, b).

§

Eq

Pop b, pop a; push a == b.

§

Ne

Pop b, pop a; push a != b.

§

Lt

Pop b, pop a; push a < b.

§

Le

Pop b, pop a; push a <= b.

§

Gt

Pop b, pop a; push a > b.

§

Ge

Pop b, pop a; push a >= b.

§

And

Pop b, pop a; push a && b (both must be truthy-compatible).

§

Or

Pop b, pop a; push a || b.

§

Not

Pop a; push !a.

§

JumpIfFalse(usize)

If TOS is falsy, jump to absolute instruction index; otherwise fall through. TOS is consumed.

§

JumpIfTrue(usize)

If TOS is truthy, jump to absolute instruction index; otherwise fall through. TOS is consumed.

§

Jump(usize)

Unconditional jump to absolute instruction index.

§

LoadVar(String)

Push the value of the named variable from the execution environment.

§

StoreVar(String)

Pop TOS and bind it to the named variable in the execution environment.

§

TNorm

Product t-norm: pop b, pop a; push a * b.

§

TCoNorm

Probabilistic sum t-conorm: pop b, pop a; push a + b - a*b.

§

FuzzyNot

Standard fuzzy NOT: pop a; push 1.0 - a.

§

Halt

Stop execution; TOS is the result.

Trait Implementations§

Source§

impl Clone for Instruction

Source§

fn clone(&self) -> Instruction

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 Instruction

Source§

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

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

impl PartialEq for Instruction

Source§

fn eq(&self, other: &Instruction) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Instruction

Auto Trait Implementations§

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<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.