Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
my first rust macro
fn when(&mut self, v:VID, val:NID, nid:NID)->NID {
macro_rules! op {
[not $x:ident] => {{ let x1 = self.when(v, val, $x); self.not(x1) }};
[$f:ident $x:ident $y:ident] => {{
let x1 = self.when(v, val, $x);
let y1 = self.when(v, val, $y);
self.$f(x1,y1) }}}
if v >= self.vars.len() { nid }
else { match self[nid] {
Op::Var(x) if x==v => val,
Op::O | Op::I | Op::Var(_) => nid,
Op::Not(x) => op![not x],
Op::And(x, y) => op![and x y],
Op::Xor(x, y) => op![xor x y],
other => { println!("unhandled match: {:?}", other); nid }}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.