fix host.zig

This commit is contained in:
Folkert 2021-05-14 23:34:24 +02:00
parent 3914f9d1cd
commit 8f95647c00

View File

@ -25,7 +25,7 @@ const Allocator = mem.Allocator;
extern fn roc__mainForHost_1_exposed([*]u8) void;
extern fn roc__mainForHost_1_size() i64;
extern fn roc__mainForHost_1_Fx_caller(*const u8, *const u8, [*]u8, [*]u8) void;
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;
@ -54,10 +54,9 @@ pub export fn main() u8 {
if (flag == 0) {
// all is well
const function_pointer = @intToPtr(*const u8, 1);
const closure_data_pointer = @ptrCast([*]u8, output[8..size]);
call_the_closure(function_pointer, closure_data_pointer);
call_the_closure(closure_data_pointer);
} else {
const msg = @intToPtr([*:0]const u8, elements[1]);
stderr.print("Application crashed with message\n\n {s}\n\nShutting down\n", .{msg}) catch unreachable;
@ -79,7 +78,7 @@ fn to_seconds(tms: std.os.timespec) f64 {
return @intToFloat(f64, tms.tv_sec) + (@intToFloat(f64, tms.tv_nsec) / 1_000_000_000.0);
}
fn call_the_closure(function_pointer: *const u8, closure_data_pointer: [*]u8) void {
fn call_the_closure(closure_data_pointer: [*]u8) void {
const size = roc__mainForHost_1_Fx_result_size();
const raw_output = std.heap.c_allocator.alloc(u8, @intCast(usize, size)) catch unreachable;
var output = @ptrCast([*]u8, raw_output);
@ -90,7 +89,7 @@ fn call_the_closure(function_pointer: *const u8, closure_data_pointer: [*]u8) vo
const flags: u8 = 0;
roc__mainForHost_1_Fx_caller(&flags, function_pointer, closure_data_pointer, output);
roc__mainForHost_1_Fx_caller(&flags, closure_data_pointer, output);
const elements = @ptrCast([*]u64, @alignCast(8, output));