remove another instance of RocCallResult

This commit is contained in:
Folkert 2021-10-22 12:24:55 +02:00
parent 51de420ee7
commit 83de4b55ef
3 changed files with 19 additions and 28 deletions

View file

@ -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(); let call_unwrapped_result = call_unwrapped.try_as_basic_value().left().unwrap();
// make_good_roc_result(env, call_unwrapped_result)
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(); let call_unwrapped_result = call_unwrapped.try_as_basic_value().left().unwrap();
// make_good_roc_result(env, call_unwrapped_result)
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 result_type = basic_type_from_layout(env, result);
let roc_call_result_type = let output_type = { result_type.ptr_type(AddressSpace::Generic) };
context.struct_type(&[context.i64_type().into(), result_type], false);
let output_type = { roc_call_result_type.ptr_type(AddressSpace::Generic) };
argument_types.push(output_type.into()); argument_types.push(output_type.into());
// STEP 1: build function header // 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()); call.set_call_convention(evaluator.get_call_conventions());
let call_result = call.try_as_basic_value().left().unwrap(); call.try_as_basic_value().left().unwrap()
make_good_roc_result(env, call_result)
}; };
builder.build_store(output, call_result); builder.build_store(output, call_result);
@ -4114,13 +4107,7 @@ pub fn build_closure_caller<'a, 'ctx, 'env>(
builder.build_return(None); builder.build_return(None);
// STEP 3: build a {} -> u64 function that gives the size of the return type // STEP 3: build a {} -> u64 function that gives the size of the return type
build_host_exposed_alias_size_help( build_host_exposed_alias_size_help(env, def_name, alias_symbol, Some("result"), result_type);
env,
def_name,
alias_symbol,
Some("result"),
roc_call_result_type.into(),
);
// STEP 4: build a {} -> u64 function that gives the size of the closure // STEP 4: build a {} -> u64 function that gives the size of the closure
build_host_exposed_alias_size( build_host_exposed_alias_size(

View file

@ -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_size() i64;
extern fn roc__mainForHost_1_Fx_result_size() i64; extern fn roc__mainForHost_1_Fx_result_size() i64;
const Align = 2 * @alignOf(usize); const Align = 2 * @alignOf(usize);
extern fn malloc(size: usize) callconv(.C) ?*align(Align) c_void; 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; 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); roc__mainForHost_1_Fx_caller(&flags, closure_data_pointer, output);
const elements = @ptrCast([*]u64, @alignCast(8, output)); // The closure returns result, nothing interesting to do with it
var flag = elements[0];
if (flag == 0) {
return; return;
} else {
unreachable;
}
} }
pub export fn roc_fx_putInt(int: i64) i64 { pub export fn roc_fx_putInt(int: i64) i64 {

View file

@ -54,11 +54,11 @@ export fn roc_panic(c_ptr: *c_void, tag_id: u32) callconv(.C) void {
std.process.exit(0); std.process.exit(0);
} }
export fn roc_memcpy(dst: [*]u8, src: [*]u8, size: usize) callconv(.C) void{ export fn roc_memcpy(dst: [*]u8, src: [*]u8, size: usize) callconv(.C) void {
return memcpy(dst, src, size); return memcpy(dst, src, size);
} }
export fn roc_memset(dst: [*]u8, value: i32, size: usize) callconv(.C) void{ export fn roc_memset(dst: [*]u8, value: i32, size: usize) callconv(.C) void {
return memset(dst, value, size); return memset(dst, value, size);
} }
@ -104,6 +104,18 @@ fn call_the_closure(closure_data_pointer: [*]u8) void {
const allocator = std.heap.page_allocator; const allocator = std.heap.page_allocator;
const size = roc__mainForHost_1_Fx_result_size(); 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; const raw_output = allocator.allocAdvanced(u8, @alignOf(u64), @intCast(usize, size), .at_least) catch unreachable;
var output = @ptrCast([*]u8, raw_output); var output = @ptrCast([*]u8, raw_output);