mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
apply created closure immediately
This commit is contained in:
parent
3b267392b3
commit
1ef0d82c5c
2 changed files with 40 additions and 4 deletions
|
@ -692,7 +692,9 @@ pub fn build_exp_call<'a, 'ctx, 'env>(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
CallType::ByPointer { name, .. } => {
|
CallType::ByPointer {
|
||||||
|
name, full_layout, ..
|
||||||
|
} => {
|
||||||
let sub_expr = load_symbol(scope, name);
|
let sub_expr = load_symbol(scope, name);
|
||||||
|
|
||||||
let mut arg_vals: Vec<BasicValueEnum> =
|
let mut arg_vals: Vec<BasicValueEnum> =
|
||||||
|
@ -702,10 +704,25 @@ pub fn build_exp_call<'a, 'ctx, 'env>(
|
||||||
arg_vals.push(load_symbol(scope, arg));
|
arg_vals.push(load_symbol(scope, arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
let call = match sub_expr {
|
let call = match (full_layout, sub_expr) {
|
||||||
BasicValueEnum::PointerValue(ptr) => {
|
(_, BasicValueEnum::PointerValue(ptr)) => {
|
||||||
env.builder.build_call(ptr, arg_vals.as_slice(), "tmp")
|
env.builder.build_call(ptr, arg_vals.as_slice(), "tmp")
|
||||||
}
|
}
|
||||||
|
(Layout::Closure(_, _, _), BasicValueEnum::StructValue(closure_struct)) => {
|
||||||
|
let fpointer = env
|
||||||
|
.builder
|
||||||
|
.build_extract_value(closure_struct, 0, "fpointer")
|
||||||
|
.unwrap()
|
||||||
|
.into_pointer_value();
|
||||||
|
|
||||||
|
let closure_data = env
|
||||||
|
.builder
|
||||||
|
.build_extract_value(closure_struct, 1, "closure_data")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
arg_vals.push(closure_data);
|
||||||
|
env.builder.build_call(fpointer, arg_vals.as_slice(), "tmp")
|
||||||
|
}
|
||||||
non_ptr => {
|
non_ptr => {
|
||||||
panic!(
|
panic!(
|
||||||
"Tried to call by pointer, but encountered a non-pointer: {:?}",
|
"Tried to call by pointer, but encountered a non-pointer: {:?}",
|
||||||
|
|
|
@ -2215,4 +2215,23 @@ mod gen_primitives {
|
||||||
i64
|
i64
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn build_then_apply_closure() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
app "test" provides [ main ] to "./platform"
|
||||||
|
|
||||||
|
main : Str
|
||||||
|
main =
|
||||||
|
x = "long string that is malloced"
|
||||||
|
|
||||||
|
(\_ -> x) {}
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
"long string that is malloced",
|
||||||
|
&'static str
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue