[][src]Enum lasm::asm::Instruct

pub enum Instruct {
    Refer(Register),
    DerefLoad,
    DerefStore,
    Load(Register),
    Store(Register),
    Push(Literal),
    Pop,
    Alloc(Register),
    Free(Register),
    Duplicate,
    Add,
    Subtract,
    Multiply,
    Divide,
    OutputChar,
    OutputNumber,
    InputChar,
    InputNumber,
    Compare,
    WhileNotZero,
    EndWhile,
}

This enum represents a single instruction that can be assembled. The majority of the work to implement Target for a target programming language is defining how to convert an instruction to a properly formatted string for the target.

Variants

Refer(Register)

The refer instruction takes a register and pushes a pointer to that register onto the stack. The motivation for only allowing registers to be referenced is very simple to explain. Values on the stack are meant to be temporary. Literals pretty much exclusively exist on the stack. Allowing references to literals promotes bad practices.

DerefLoad

The deref_ld instruction takes no arguments. This instruction pops an address off the stack and pushes the value stored at the cell the address points to.

Essentially, this derefences the pointer as a double precision float pointer.

DerefStore

The deref_st instruction takes no arguments. This instruction pops an address cell and a value cell off the stack. The value cell is stored as a double precision float at the location the pointer points to.

This is equivalent to *(double*)address = value

Load(Register)

The ld instruction takes a register as an argument. This instruction loads the value stored in the register and pushes it onto the stack.

Store(Register)

The st instruction takes a register as an argument. This instruction pops a value off of the stack and stores it in the register.

This is equivalent to register = value

Push(Literal)

The push instruction takes either a literal as an argument. This literal can either be a character or a double precision float. This instruction pushes the literal onto the stack.

Pop

The pop instruction pops a value off of the stack and stores it in the ACC register.

This is equivalent to ACC = value

Alloc(Register)

The alloc instruction takes a register as an argument, and pops a size value off of the stack. Then, alloc stores a pointer size number of consecutive free cells.

This is equivalent to register = (double*)malloc(size)

Free(Register)

The free instruction takes a register as an argument, and pops a size value off of the stack. Then, free frees size number of values at the location the register points to.

Duplicate

The dup instruction takes no argument, and simply duplicates the top item on the stack.

Add

The add instruction pops two cells off the stack and pushes their sum

Subtract

The sub instruction pops two cells off the stack and pushes the first minus the second

Multiply

The mul instruction pops two cells off the stack and pushes their product

Divide

The div instruction pops two cells off the stack and pushes the first divided by the second

OutputChar

The outc instruction pops a cell off the stack and prints cell % 256 as a character to STDOUT

OutputNumber

The outn instruction pops a cell off the stack and prints the cell as a number to STDOUT

InputChar

The inc instruction pushes a character from STDIN onto the stack

InputNumber

The inn instruction pushes a double precision float from STDIN onto the stack

Compare

The cmp instruction compares two cells on the stack. If the first popped value is less than the second, -1 is pushed. If the first popped value is equal to the second, 0 is pushed. If the first popped value is greater than to the second, 1 is pushed.

WhileNotZero

The loop instruction the start of a loop. At the start of each iteration, a test value is popped from the stack. While the value is not zero, the loop continues. Else, the loop jumps to the matching endloop

EndWhile

The endloop instruction marks the end of a loop

Trait Implementations

impl Clone for Instruct[src]

impl Debug for Instruct[src]

impl PartialEq<Instruct> for Instruct[src]

impl PartialOrd<Instruct> for Instruct[src]

impl StructuralPartialEq for Instruct[src]

Auto Trait Implementations

impl RefUnwindSafe for Instruct

impl Send for Instruct

impl Sync for Instruct

impl Unpin for Instruct

impl UnwindSafe for Instruct

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 = !

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.