You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It'd be pretty neat if you could do something like:
let foo = function!{
foo(a: u32, b: CustomStruct, c: Ptr<i32>) -> u32{
entry:
a <- 3
br end
end:
return1;
}};
Which would return a function value or Result<FunctionValue, Box<Error>> with that definition. It might need to make some assumptions, like always using the global Context, though. Maybe you could optionally specify a context.
The text was updated successfully, but these errors were encountered:
Working with heterogeneous collections is a pain in rust.. We could also provide a macro which simplifies the process for the user. (We may even want this earlier than 0.3.0)
For example,
let values = mixed_value_array!(BasicValue, [
float_value,
int_value,
...
]);
If we do end up adding this macro, I'd strongly consider switching the current homogeneous function params from say, &[&BasicValue] to &[BasicValueEnum] since the former generally requires an extra heap allocation (unless you happen to have a fixed size of values on the stack, which probably isn't realistic) for the extra trait indirection which could be avoided.
Then, this macro could expand to something like let values: Vec<BasicValueEnum> = array.iter().map(|val| val.into()).collect(). Might need associated type to derive BasicValueEnum from BasicValue, though.
The example function! macro you showed above would require the power brought by proc_macro, but it can be achieved similarly using a Lisp-like syntax (like clap.rs) with the macro_rules system.
Here's an example of doing dynamic code generation using this syntax: primitives.rs (note: it's part of a legacy compiler I wrote last year, the code is ugly in some places). The macro itself is defined here.
Proc macros are probably fine; I don't expect to get to this issue before Macros 2.0 lands in stable(it seems pretty close: rust-lang/rust#38356), but who knows.
It'd be pretty neat if you could do something like:
Which would return a function value or
Result<FunctionValue, Box<Error>>
with that definition. It might need to make some assumptions, like always using the global Context, though. Maybe you could optionally specify a context.The text was updated successfully, but these errors were encountered: