Skip to content

Instantly share code, notes, and snippets.

@udoprog
Last active December 21, 2018 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udoprog/8c330d2cba9b4e0383f507a25610df9d to your computer and use it in GitHub Desktop.
Save udoprog/8c330d2cba9b4e0383f507a25610df9d to your computer and use it in GitHub Desktop.
test_fixed:
movl 112(%rdi), %eax
movl 116(%rdi), %edx
retq
test_array:
movl 116(%rdi), %edx
xorl %eax, %eax
cmpl $1, 112(%rdi)
sete %al
retq
macro_rules! expand {
($len:expr, ($($member:ident),*), $get:ident) => {
#[allow(unused)]
#[derive(Clone, Copy, fixed_map::Key)]
pub enum FixedKey {
$($member,)*
}
#[no_mangle]
pub fn test_fixed(map: &fixed_map::Map<FixedKey, u32>) -> Option<u32> {
map.get(FixedKey::$get).cloned()
}
#[allow(unused)]
#[repr(usize)]
pub enum ArrayKey {
$($member,)*
}
#[no_mangle]
pub fn test_array(map: &[Option<u32>; $len]) -> Option<u32> {
map[ArrayKey::$get as usize].clone()
}
}
}
expand! {
16,
(T00, T01, T02, T03, T04, T05, T06, T07, T8, T9, T10, T11, T12, T13, T14, T15),
T14
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment