Enum seax_util::cell::Inst [] [src]

pub enum Inst {
    NIL,
    LDC,
    LD,
    LDF,
    JOIN,
    AP,
    RET,
    DUM,
    RAP,
    SEL,
    ADD,
    SUB,
    MUL,
    DIV,
    FDIV,
    MOD,
    EQ,
    GT,
    GTE,
    LT,
    LTE,
    ATOM,
    CAR,
    CDR,
    CONS,
    NULL,
    STOP,
    READC,
    WRITEC,
    APCC,
}

SVM instruction types.

Each SVM instruction will be described using operational semantics through the use of the following notation:

  • a state is written (s, e, c, d)
  • (x.y) is Cons(x, y). The empty list is nil.
  • each instruction is described as a state transition (s, e, c, d) → (s´, e´, c´, d´)

Variants

nil

Pushes an empty list (nil) onto the stack.

Operational semantics: (s, e, (NIL.c), d) → ( (nil.s), e, c, d )

ldc: Load Constant. Loads a constant (atom)

ld: Load. Pushes a variable onto the stack.

The variable is indicated by the argument, a pair. The pair's car specifies the level, the cdr the position. So (1 . 3) gives the current function's (level 1) third parameter.

Operational semantics: (s, e, LDC.v.c, d) → (v.s, e, c, d)

ldf: Load Function.

Takes one list argument representing a function and constructs a closure (a pair containing the function and the current environment) and pushes that onto the stack.

Operational semantics: (s, e, (LDF f.c), d) → ( ([f e].s), e, c, d)

join

Pops a list reference from the dump and makes thi64 the new value of C. This instruction occurs at the end of both alternatives of a sel.

Operational semantics: (s, e, JOIN.c, c´.d) → (s, e, c´, d)

ap: Apply.

Pops a closure and a list of parameter values from the stack. The closure is applied to the parameters by installing its environment as the current one, pushing the parameter list in front of that, clearing the stack, and setting c to the closure's function pointer. The previous values of s, e, and the next value of c are saved on the dump.

Operational semantics: (([f e´] v.s), e, (AP.c), d) → (nil, (v.e&prime), f, (s e c.d))

ret: Return.

Pops one return value from the stack, restores $s, $e, and $c from the dump, and pushes the return value onto the now-current stack.

dum: Dummy.

Pops a dummy environment (an empty list) onto the $e stack.

rap: Recursive Apply. Works like ap, only that it replaces an occurrence of a dummy environment with the current one, thus making recursive functions possible.

sel: Select branch

Expects two list arguments on the control stack, and pops a value from the stack. The first list is executed if the popped value was non-nil, the second list otherwise. Before one of these list pointers is made the new $c, a pointer to the instruction following sel is saved on the dump.

Operational semantics: (v.s, e, SEL.true.false.c, d) → (s, e, (if v then true else false), c.d)

add

Pops two numbers off of the stack and adds them, pu64hing the result onto the stack. This will up-convert integers to floating point if necessary.

TODO: figure out what happens when you try to add things that aren't numbers (maybe the compiler won't let this happen?).

sub: Subtract

Pops two numbers off of the stack and subtracts the first from the second, pu64hing the result onto the stack. This will up-convert integers to floating point if necessary.

TODO: figure out what happens when you try to subtract things that aren't numbers (maybe the compiler won't let thi64 happen?).

mul: Multiply

Pops two numbers off of the stack and multiplies them, pu64hing the result onto the stack. This will up-convert integers to floating point if necessary.

TODO: figure out what happens when you try to multiply things that aren't numbers (maybe the compiler won't let thi64 happen?).

div: Divide

Pops two numbers off of the stack and divides the first by the second, pushing the result onto the stack. This performs integer divi64ion.

TODO: figure out what happens when you try to divide things that aren't numbers (maybe the compiler won't let thi64 happen?).

fdiv: Floating-point divide

Pops two numbers off of the stack and divides the first by the second, pu64hing the result onto the stack. This performs float divi64ion.

TODO: figure out what happens when you try to divide things that aren't numbers (maybe the compiler won't let this happen?).

TODO: Not sure if there should be separate float and int divide words I guess the compiler can figure this out

mod: Modulo

Pops two numbers off of the stack and divides the first by the second, pushing the remainder onto the stack.

TODO: figure out what happens when you try to modulo things that aren't numbers (maybe the compiler won't let this happen?).

eq: Equality of atoms

gt: Greater than

Pops two numbers on the stack and puts a 'true' on the stack if the first atom i64 greater than the other atom, false otherwi64e.

gte: Greater than or equal

lt: Less than

lte: Less than or equal

atom: test if atom

Pops an item from the stack and returns true if it's an atom, false otherwise.

car: Contents of Address Register

Pops a list from the stack and returns the list's car (head)

cdr: Contents of Decrement Register

Pops a list from the stack and returns the list's cdr (tail)

cons: Construct

Pops an item and a list from the stack and returns the list, with the item prepended.

null: test if null

Pops an item from the stack and returns true if it is nil, false otherwise.

stop: stop execution

Terminates program execution. The eval_program() function will return the last state of the VM.

readc: read character

Reads a character from the machine's input stream and places it on top of the stack

writec: write character

Writes a character from the top of the stack to the machine's output stream.

apcc: apply with current continuation

Applies a closure and captures the continuation that can then be applied with ap.

Trait Implementations

impl Debug for Inst
[src]

Formats the value using the given formatter.

impl Copy for Inst
[src]

impl Clone for Inst
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for Inst
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.