[][src]Enum ketos::bytecode::Instruction

pub enum Instruction {
    Load(u32),
    LoadC(u32),
    UnboundToUnit(u32),
    GetDef(u32),
    Push,
    Unit,
    True,
    False,
    Const(u32),
    Store(u32),
    LoadPush(u32),
    LoadCPush(u32),
    GetDefPush(u32),
    UnitPush,
    TruePush,
    FalsePush,
    ConstPush(u32),
    SetDef(u32),
    List(u32),
    Quote(u32),
    Quasiquote(u32),
    Comma(u32),
    CommaAt(u32),
    BuildClosure(u32u32),
    Jump(u32),
    JumpIf(u32),
    JumpIfBound(u32u32),
    JumpIfNot(u32),
    JumpIfNull(u32),
    JumpIfNotNull(u32),
    JumpIfEq(u32),
    JumpIfNotEq(u32),
    JumpIfEqConst(u32u32),
    JumpIfNotEqConst(u32u32),
    Null,
    NotNull,
    Eq,
    NotEq,
    EqConst(u32),
    NotEqConst(u32),
    Not,
    Inc,
    Dec,
    Append,
    First,
    Tail,
    Init,
    Last,
    FirstPush,
    TailPush,
    InitPush,
    LastPush,
    CallSys(u32),
    CallSysArgs(u32u32),
    CallConst(u32u32),
    Call(u32),
    Apply(u32),
    ApplyConst(u32u32),
    ApplySelf(u32),
    TailApplySelf(u32),
    CallSelf(u32),
    TailCallSelf(u32),
    Skip(u32),
    Return,
}

Represents an instruction and any immediate parameters.

Any addition, deletion, or modification to this enum constitutes a breaking change to the bytecode format.

Variants

Load(u32)

Load a value from the stack

LoadC(u32)

Load a value from enclosed values

UnboundToUnit(u32)

If value n on the stack is Unbound, replace it with ().

GetDef(u32)

Load a named value from global scope

Push

Push a value onto the stack; value is invalidated.

Unit

Load () into value

True

Load true into value

False

Load false into value

Const(u32)

Load a const into value

Store(u32)

Store a value in the stack; value is invalidated.

LoadPush(u32)

Load, then push

LoadCPush(u32)

Load enclosed value, then push

GetDefPush(u32)

Load a name from global scope, then push

UnitPush

Load (), then push

TruePush

Load true, then push

FalsePush

Load false, then push

ConstPush(u32)

Load a const, then push

SetDef(u32)

Assign a value to a name into global scope

List(u32)

Build a list of n values from the stack

Quote(u32)

Transform value into an n-quoted value

Quasiquote(u32)

Transform value into an n-quasiquoted value

Comma(u32)

Transform value into an n-comma'd value

CommaAt(u32)

Transform value into an n-comma-at'd value

BuildClosure(u32u32)

Create a closure from code object in n_const and a list of n_values values on the stack; parameters are (n_const, n_values).

Jump(u32)

Jump to a label

JumpIf(u32)

Jump if value is true

JumpIfBound(u32u32)

Jump if value n from the stack is bound; parameters are (label, n)

JumpIfNot(u32)

Jump if value is false

JumpIfNull(u32)

Jump if value is ()

JumpIfNotNull(u32)

Jump if value is not ()

JumpIfEq(u32)

Jump if value is equal to top of stack

JumpIfNotEq(u32)

Jump if value is not equal to top of stack

JumpIfEqConst(u32u32)

Jump if value is equal to const; parameters are (label, n)

JumpIfNotEqConst(u32u32)

Jump if value is not equal to const; parameters are (label, n)

Null

Test whether value is ()

NotNull

Test whether value is not ()

Eq

Pops from the top of the stack and tests for equality with value.

NotEq

Pops from the top of the stack and tesst for inequality with value.

EqConst(u32)

Tests value for equality with const n

NotEqConst(u32)

Tests value for inequality with const n

Not

Negate boolean value

Inc

Increment integer value

Dec

Decrement integer value

Append

Append value to list on top of stack; result will be in value

First

Take first element of list or string and assign to value

Tail

Take tail of list or string and assign to value

Init

Take head of list or string and assign to value

Last

Take last element of list or string and assign to value

FirstPush

Push first value from list or string

TailPush

Push tail from list or string

InitPush

Push head from list or string

LastPush

Push last value from list or string

CallSys(u32)

Call system function n with known number of arguments on stack. Only functions with Exact arity may be called in this manner.

CallSysArgs(u32u32)

Call system function with n arguments on the stack; parameters are (sys_fn, n_args).

CallConst(u32u32)

Call const function with arguments on the stack; parameters are (const, n_args).

Call(u32)

Call function on the stack with n arguments from the top of the stack

Apply(u32)

Call function on the stack with n stack arguments, plus additional arguments from list value

ApplyConst(u32u32)

Call const function with n stack arguments, plus additional arguments from list value; parameters are (const, n_args).

ApplySelf(u32)

Call current code object with n stack arguments, plus additional arguments from list value; does not perform a tail call

TailApplySelf(u32)

Call current code object with n stack arguments, plus additional arguments from list value

CallSelf(u32)

Call current code object with n arguments from the top of the stack; this does not perform a tail call

TailCallSelf(u32)

Perform tail-recursive call with n arguments from the top of the stack

Skip(u32)

Remove n values from the top of the stack

Return

Return value from function

Methods

impl Instruction[src]

pub fn decode(r: &mut CodeReader) -> Result<Instruction, ExecError>[src]

Decodes a single Instruction from a CodeReader.

pub fn encode(&self, w: &mut CodeBlock, short: bool) -> Result<(), CompileError>[src]

Encodes a single Instruction into a CodeBlock.

pub fn is_trivial(&self) -> bool[src]

Returns whether the Instruction is trivial; that is, in valid top-level code, it does not produce any side effects.

pub fn jump_label(&self) -> Option<u32>[src]

If the instruction is a jump instruction, returns the jump offset. Otherwise, returns None.

pub fn max_len() -> usize[src]

Returns the maximum length, in bytes, of an encoded instruction.

Trait Implementations

impl Clone for Instruction[src]

impl Copy for Instruction[src]

impl Debug for Instruction[src]

impl Eq for Instruction[src]

impl PartialEq<Instruction> for Instruction[src]

impl StructuralEq for Instruction[src]

impl StructuralPartialEq for Instruction[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,