mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
remove another instance of RocCallResult
This commit is contained in:
parent
51de420ee7
commit
83de4b55ef
3 changed files with 19 additions and 28 deletions
|
@ -3186,7 +3186,6 @@ fn expose_function_to_host_help_c_abi_generic<'a, 'ctx, 'env>(
|
|||
|
||||
let call_unwrapped_result = call_unwrapped.try_as_basic_value().left().unwrap();
|
||||
|
||||
// make_good_roc_result(env, call_unwrapped_result)
|
||||
call_unwrapped_result
|
||||
}
|
||||
};
|
||||
|
@ -3464,7 +3463,6 @@ fn expose_function_to_host_help_c_abi<'a, 'ctx, 'env>(
|
|||
|
||||
let call_unwrapped_result = call_unwrapped.try_as_basic_value().left().unwrap();
|
||||
|
||||
// make_good_roc_result(env, call_unwrapped_result)
|
||||
call_unwrapped_result
|
||||
};
|
||||
|
||||
|
@ -4044,10 +4042,7 @@ pub fn build_closure_caller<'a, 'ctx, 'env>(
|
|||
|
||||
let result_type = basic_type_from_layout(env, result);
|
||||
|
||||
let roc_call_result_type =
|
||||
context.struct_type(&[context.i64_type().into(), result_type], false);
|
||||
|
||||
let output_type = { roc_call_result_type.ptr_type(AddressSpace::Generic) };
|
||||
let output_type = { result_type.ptr_type(AddressSpace::Generic) };
|
||||
argument_types.push(output_type.into());
|
||||
|
||||
// STEP 1: build function header
|
||||
|
@ -4104,9 +4099,7 @@ pub fn build_closure_caller<'a, 'ctx, 'env>(
|
|||
|
||||
call.set_call_convention(evaluator.get_call_conventions());
|
||||
|
||||
let call_result = call.try_as_basic_value().left().unwrap();
|
||||
|
||||
make_good_roc_result(env, call_result)
|
||||
call.try_as_basic_value().left().unwrap()
|
||||
};
|
||||
|
||||
builder.build_store(output, call_result);
|
||||
|
@ -4114,13 +4107,7 @@ pub fn build_closure_caller<'a, 'ctx, 'env>(
|
|||
builder.build_return(None);
|
||||
|
||||
// STEP 3: build a {} -> u64 function that gives the size of the return type
|
||||
build_host_exposed_alias_size_help(
|
||||
env,
|
||||
def_name,
|
||||
alias_symbol,
|
||||
Some("result"),
|
||||
roc_call_result_type.into(),
|
||||
);
|
||||
build_host_exposed_alias_size_help(env, def_name, alias_symbol, Some("result"), result_type);
|
||||
|
||||
// STEP 4: build a {} -> u64 function that gives the size of the closure
|
||||
build_host_exposed_alias_size(
|
||||
|
|
|
@ -29,7 +29,6 @@ extern fn roc__mainForHost_1_Fx_caller(*const u8, [*]u8, [*]u8) void;
|
|||
extern fn roc__mainForHost_1_Fx_size() i64;
|
||||
extern fn roc__mainForHost_1_Fx_result_size() i64;
|
||||
|
||||
|
||||
const Align = 2 * @alignOf(usize);
|
||||
extern fn malloc(size: usize) callconv(.C) ?*align(Align) c_void;
|
||||
extern fn realloc(c_ptr: [*]align(Align) u8, size: usize) callconv(.C) ?*c_void;
|
||||
|
@ -137,15 +136,8 @@ fn call_the_closure(closure_data_pointer: [*]u8) void {
|
|||
|
||||
roc__mainForHost_1_Fx_caller(&flags, closure_data_pointer, output);
|
||||
|
||||
const elements = @ptrCast([*]u64, @alignCast(8, output));
|
||||
|
||||
var flag = elements[0];
|
||||
|
||||
if (flag == 0) {
|
||||
// The closure returns result, nothing interesting to do with it
|
||||
return;
|
||||
} else {
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
pub export fn roc_fx_putInt(int: i64) i64 {
|
||||
|
|
|
@ -104,6 +104,18 @@ fn call_the_closure(closure_data_pointer: [*]u8) void {
|
|||
const allocator = std.heap.page_allocator;
|
||||
|
||||
const size = roc__mainForHost_1_Fx_result_size();
|
||||
|
||||
if (size == 0) {
|
||||
// the function call returns an empty record
|
||||
// allocating 0 bytes causes issues because the allocator will return a NULL pointer
|
||||
// So it's special-cased
|
||||
const flags: u8 = 0;
|
||||
var result: [1]u8 = .{0};
|
||||
roc__mainForHost_1_Fx_caller(&flags, closure_data_pointer, &result);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const raw_output = allocator.allocAdvanced(u8, @alignOf(u64), @intCast(usize, size), .at_least) catch unreachable;
|
||||
var output = @ptrCast([*]u8, raw_output);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue