Merge branch 'trunk' into dict-more

This commit is contained in:
Richard Feldman 2021-02-17 23:47:13 -05:00 committed by GitHub
commit fe98229aa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 691 additions and 193 deletions

View file

@ -735,10 +735,25 @@ pub fn build_exp_call<'a, 'ctx, 'env>(
arg_vals.push(load_symbol(scope, arg));
}
let call = match sub_expr {
BasicValueEnum::PointerValue(ptr) => {
let call = match (full_layout, sub_expr) {
(_, BasicValueEnum::PointerValue(ptr)) => {
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 => {
panic!(
"Tried to call by pointer, but encountered a non-pointer: {:?} {:?} {:?}",

View file

@ -1952,7 +1952,7 @@ mod gen_primitives {
main =
x : Tree F64
x = singleton 3
when x is
when x is
Tree 3.0 _ -> True
_ -> False
"#
@ -2215,4 +2215,23 @@ mod gen_primitives {
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
);
}
}