Enum acs::vm::instruction::VmInstruction
source · [−]pub enum VmInstruction {
}
Expand description
Sort of intermediate code designed to run on a stack machine. Part of a two-tier compilation model, where a high level language is first translated to this representation and then to machine language.
Variants
Push(Segment, u16)
Pushes segment[index]
on top of the stack
Pop(Segment, u16)
Pops an element from the stack and stores it into segment[index]
Add
Pops y
, pops x
, and pushes x + y
Sub
Pops y
, pops x
, and pushes x - y
Eq
Pops y
, pops x
, and pushes x == y
Lt
Pops y
, pops x
, and pushes x < y
Gt
Pops y
, pops x
, and pushes x > y
Neg
Pops x
, and pushes -x
And
Pops y
, pops x
, and pushes x & y
Or
Pops y
, pops x
, and pushes x | y
Not
Pops x
, and pushes ~x
(bitwise not)
Label(String)
Marks current code location for jumping
Goto(String)
Unconditional jump to the location marked by the label
IfGoto(String)
Pops topmost value from stack and, if it is not 0
,
jumps to the location marked by the label
Function(String, u16)
Marks the beginning of a function with a name and the number of words to allocate for the local segment
Call(String, u16)
Calls the function with that name with the number of arguments pushed onto the stack before calling.
Return(u16)
Jumps to the command following the Call
command that called the
current function, copying a number of words as the return value at the
beginning of the Argument
section.
Implementations
sourceimpl VmInstruction
impl VmInstruction
pub fn parse(code: &str) -> Vec<VmInstruction>
Trait Implementations
sourceimpl Clone for VmInstruction
impl Clone for VmInstruction
sourcefn clone(&self) -> VmInstruction
fn clone(&self) -> VmInstruction
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more