-
-
Save andy-morris/e4011785b2003dcf0f3f80a6397fcb14 to your computer and use it in GitHub Desktop.
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
#[derive(Clone, Copy)] | |
struct Op(fn(u16, u16)); | |
// lets you call foo() instead of foo.0() (where foo: Op) | |
impl std::ops::Deref for Op { | |
type Target = fn(u16, u16); | |
fn deref(&self) -> &fn(u16, u16) { &self.0 } | |
} | |
fn op_mov(one: u16, two: u16) { | |
} | |
fn op_add(one: u16, two: u16) { | |
} | |
fn op_nand(one: u16, two: u16) { | |
} | |
fn op_shl(one: u16, two: u16) { | |
} | |
fn op_shr(one: u16, two: u16) { | |
} | |
fn op_jz(one: u16, two: u16) { | |
} | |
fn op_lt(one: u16, two: u16) { | |
} | |
fn op_gt(one: u16, two: u16) { | |
} | |
fn op_in(one: u16, two: u16) { | |
} | |
fn op_out(one: u16, two: u16) { | |
} | |
fn main() { | |
let methods: std::collections::HashMap<u16, Op> = | |
[(0b0000, Op(op_mov)), | |
(0b0001, Op(op_add)), | |
(0b0010, Op(op_nand)), | |
(0b0011, Op(op_shl)), | |
(0b0100, Op(op_shr)), | |
(0b0101, Op(op_jz)), | |
(0b0110, Op(op_lt)), | |
(0b0111, Op(op_gt)), | |
// No 0b1000-0b1101. | |
(0b1110, Op(op_in)), | |
(0b1111, Op(op_out))].iter().cloned().collect(); | |
methods.get(&0b0000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment