Skip to content

Instantly share code, notes, and snippets.

@nickik
Created October 20, 2014 23:50
Show Gist options
  • Save nickik/8a614bc360c702fee43f to your computer and use it in GitHub Desktop.
Save nickik/8a614bc360c702fee43f to your computer and use it in GitHub Desktop.
#[deriving(Show, Clone)]
pub enum Slot {
Nil,
Int(i64),
Float(f64),
Bool(bool),
Str(String),
Key(Keyword),
Func(uint),
VFunc(uint),
Obj(CljObject),
CType(uint),
SCC(Closure),
}
macro_rules! execute (
(using $vm:ident with $args:ident
$($op:pat as $ty:ty => $code:expr),+) => (
impl Execute for Instr {
fn execute(&self, $vm:&mut Vm) -> Instr {
match self.decode() {
$($op => { let $args : $ty = from_instr(self); $code }),+
}
}
}
)
)
vm::GETFREEVAR as OpAD => {
let idx = args.d as uint;
let dst_idx = args.a as uint;
let freevar = match vm.slots.slot[1].clone() {
SCC(clos) => clos.freevar[idx].clone(),
_ => fail!("Not Closure in Slot")
}
vm.slots.store(dst_idx, freevar);
vm.fetch_next()
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment