jit_macros::jit_func! [] [src]

macro_rules! jit_func(
    ($ctx:expr, $name:ident, fn() -> $ret:ty {$($st:stmt;)+}, $value:expr) => ({
        use std::mem;
        let func = UncompiledFunction::new($ctx, &get::<fn() -> $ret>());
        {
            let $name = &func;
            $($st;)+
        };
        func.compile().with(|comp: extern fn(()) -> $ret| {
            let $name: extern fn() -> $ret = unsafe { mem::transmute(comp) };
            $value
        })
    });
    ($ctx:expr, $name:ident, fn($($arg:ident:$ty:ty),+) -> $ret:ty {$($st:stmt;)+}, $value:expr) => ({
        use std::mem;
        let func = UncompiledFunction::new($ctx, &get::<fn($($ty),+) -> $ret>());
        {
            let $name = &func;
            let mut i = 0;
            $(let $arg = {
                i += 1;
                &$name[i - 1]
            };)*
            $($st;)+
        };
        func.compile().with(|comp: extern fn(($($ty),+)) -> $ret| {
            let $name: extern fn($($ty),+) -> $ret = unsafe { mem::transmute(comp) };
            $value
        })
    });
);