I have programmatically constructed a C function in memory, and I'm able to call it in Rust like so.
type AddFn = extern "C" fn(isize, isize) -> isize;
let Add = build_function::<AddFn>(®ion, code);
fn build_function<T>(region: &MappedRegion, contents: &[u8]) -> Box<T> {
unsafe {
...
mem::transmute(Box::new(region.addr))
}
}
This requires me to know the signature for my generated function, in this case AddFn
. I would like to be able to construct this signature at runtime e.g. let x = 3u8; macro!(x, f64) == fn(f64, f64, f64) -> f64
. I can find no means to generate functions in this manner. A related issue is the inability to call functions generated at runtime. Without partial application or a means to accomplish the logic above I cannot figure out how to call a generated function without a known signature. Is it possible to generate a function signature programmatically this way in Rust?
UPDATE:
Rust's support for variadic C functions (extern "C" fn(x:int, ...)
allows for arbitrary sysv ABI compatible function signatures. Now the only issue is calling them at runtime. Is there any way to perform partial application on named functions?