Skip to content

Instantly share code, notes, and snippets.

@duckinator
Created October 11, 2016 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save duckinator/9d7e7b105460b50b284df72bb9add83c to your computer and use it in GitHub Desktop.
Save duckinator/9d7e7b105460b50b284df72bb9add83c to your computer and use it in GitHub Desktop.
type Op = Fn(u16, u16);
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() {
// Oh come the FUCK on. There has GOT to be a better
// way than this?!
let mut methods = std::collections::HashMap::<u16, Box<Op>>::new();
methods.insert(0b0000, Box::new(op_mov));
methods.insert(0b0001, Box::new(op_add));
methods.insert(0b0010, Box::new(op_nand));
methods.insert(0b0011, Box::new(op_shl));
methods.insert(0b0100, Box::new(op_shr));
methods.insert(0b0101, Box::new(op_jz));
methods.insert(0b0110, Box::new(op_lt));
methods.insert(0b0111, Box::new(op_gt));
// No 0b1000-0b1101.
methods.insert(0b1110, Box::new(op_in));
methods.insert(0b1111, Box::new(op_out));
methods.get(0b0000);
}
~/dev/tuna-isa/escolar$ cargo run
Compiling escolar v0.1.0 (file:///home/ellen/dev/tuna-isa/escolar)
src/main.rs:50:17: 50:23 error: mismatched types [E0308]
src/main.rs:50 methods.get(0b0000);
^~~~~~
src/main.rs:50:17: 50:23 help: run `rustc --explain E0308` to see a detailed explanation
src/main.rs:50:17: 50:23 note: expected type `&u16`
src/main.rs:50:17: 50:23 note: found type `_`
error: aborting due to previous error
error: Could not compile `escolar`.
To learn more, run the command again with --verbose.
~/dev/tuna-isa/escolar$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment