Build and call a function programmatically

I programmatically constructed a C function in memory, and I can call it in Rust like that.

type AddFn = extern "C" fn(isize, isize) -> isize; let Add = build_function::<AddFn>(&region, code); fn build_function<T>(region: &MappedRegion, contents: &[u8]) -> Box<T> { unsafe { ... mem::transmute(Box::new(region.addr)) } } 

This requires that I know the signature for my generated function, in this case AddFn . I would like to be able to build this signature at runtime, for example. let x = 3u8; macro!(x, f64) == fn(f64, f64, f64) -> f64 let x = 3u8; macro!(x, f64) == fn(f64, f64, f64) -> f64 . I cannot find a way to generate functions this way. A related problem is the inability to call functions generated at run time. Without a partial application or tool to execute the above logic, I cannot figure out how to call the generated function without a known signature. Is it possible to programmatically generate a function signature in Rust?

UPDATE: Support for rust variable functions C (extern "C" fn(x:int, ...) allows you to execute arbitrary function signatures compatible with sysv ABI. Now the only problem is calling them at runtime. Is there a way to execute a partial application for the named functions?

+4
source share

All Articles