sheredom / yair

🦜 yair - a high-level compiler IR entirely written in Rust
https://sheredom.github.io/yair
Creative Commons Zero v1.0 Universal
37 stars 1 forks source link

Function arguments provided from an array or iterator. #20

Closed otrho closed 2 years ago

otrho commented 2 years ago

At the moment the FunctionBuilder only allows args to be added via with_arg(). In the io::Assembler::parse_fn() it's using a for-loop to pump args in one at a time, which feels a bit clumsy. Adding a .with_args() would be good IMO, taking a slice of pairs, or even an iterator.

I've also used the following to fold the builder, which felt more functional than a for-loop, but is still fairly inelegant:

    let func = args
        .iter()
        .fold(
            module
                .create_function(context)
                .with_attributes(attrs)
                .with_name(name)
                .with_return_type(ret_type),
            |bldr, &arg: &(&str, Type)| bldr.with_arg(arg.0, arg.1),
        )
        .build();
sheredom commented 2 years ago

Adding a with_args would be fine yeah, nothing against that!