Created
March 24, 2018 03:08
-
-
Save tangentstorm/e69a78361cfff6ac6d5e75c14217a827 to your computer and use it in GitHub Desktop.
my first rust macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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