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)
isCons(x, y)
. The empty list isnil
.- each instruction is described as a state transition
(s, e, c, d) → (s´, e´, c´, d´)
Variants
NIL
nil
Pushes an empty list (nil) onto the stack.
Operational semantics: (s, e, (NIL.c), d) → ( (nil.s), e, c, d )
LDC
ldc
: L
oad
C
onstant. Loads a constant (atom)
LD
ld
: L
oad
. 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
ldf
: L
oad
F
unction.
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
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
ap
: Ap
ply.
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
ret
: Ret
urn.
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
dum
: Dum
my.
Pops a dummy environment (an empty list) onto the $e
stack.
RAP
rap
: R
ecursive Ap
ply.
Works like ap
, only that it replaces an occurrence of a
dummy environment with the current one, thus making recursive
functions possible.
SEL
sel
: Sel
ect 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
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
sub
: Sub
tract
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
mul
: Mul
tiply
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
div
: Div
ide
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
fdiv
: F
loating-point div
ide
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
mod
: Mod
ulo
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
eq
: Eq
uality of atoms
GT
gt
: G
reater t
han
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
gte
: G
reater t
han or e
qual
LT
lt
: L
ess t
han
LTE
lte
: L
ess t
han or e
qual
ATOM
atom
: test if atom
Pops an item from the stack and returns true if it's an atom, false otherwise.
CAR
car
: C
ontents of A
ddress R
egister
Pops a list from the stack and returns the list's car
(head)
CDR
cdr
: C
ontents of D
ecrement R
egister
Pops a list from the stack and returns the list's cdr
(tail)
CONS
cons
: Cons
truct
Pops an item and a list from the stack and returns the list, with the item prepended.
NULL
null
: test if null
Pops an item from the stack and returns true if it is nil
, false
otherwise.
STOP
stop
: stop
execution
Terminates program execution. The eval_program()
function will return
the last state of the VM.
READC
readc
: read
c
haracter
Reads a character from the machine's input stream and places it on top of the stack
WRITEC
writec
: write
c
haracter
Writes a character from the top of the stack to the machine's output stream.
APCC
apcc
: ap
ply with c
urrent c
ontinuation
Applies a closure and captures the continuation that can
then be applied with ap
.
Trait Implementations
impl Debug for Inst
[src]
impl Copy for Inst
[src]
impl Clone for Inst
[src]
fn clone(&self) -> Inst
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more