use exposed_generic in hello world examples

This commit is contained in:
Folkert 2022-03-12 14:42:14 +01:00
parent bc492fa22b
commit 9d9e7d10d4
No known key found for this signature in database
GPG Key ID: 1F17F6FFD112B97C
4 changed files with 12 additions and 8 deletions

View File

@ -150,7 +150,7 @@ pub export fn roc_fx_putInt(int: i64) i64 {
return 0;
}
export fn roc_fx_putLine(rocPath: str.RocStr) callconv(.C) void {
export fn roc_fx_putLine(rocPath: *str.RocStr) callconv(.C) void {
const stdout = std.io.getStdOut().writer();
for (rocPath.asSlice()) |char| {

View File

@ -54,10 +54,12 @@ size_t roc_str_len(struct RocStr str) {
}
}
extern struct RocStr roc__mainForHost_1_exposed();
extern void roc__mainForHost_1_exposed_generic(*RocStr);
int main() {
struct RocStr str = roc__mainForHost_1_exposed();
struct RocStr str;
roc__mainForHost_1_exposed_generic(&str);
// Determine str_len and the str_bytes pointer,
// taking into account the small string optimization.

View File

@ -6,8 +6,8 @@ use std::ffi::CStr;
use std::os::raw::c_char;
extern "C" {
#[link_name = "roc__mainForHost_1_exposed"]
fn roc_main() -> RocStr;
#[link_name = "roc__mainForHost_1_exposed_generic"]
fn roc_main(_: &mut RocStr);
}
#[no_mangle]
@ -56,7 +56,8 @@ pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut
#[no_mangle]
pub extern "C" fn rust_main() -> i32 {
unsafe {
let roc_str = roc_main();
let mut roc_str = RocStr::default();
roc_main(&mut roc_str);
let len = roc_str.len();
let str_bytes = roc_str.as_bytes().as_ptr() as *const libc::c_void;

View File

@ -77,7 +77,7 @@ export fn roc_memset(dst: [*]u8, value: i32, size: usize) callconv(.C) void {
const mem = std.mem;
const Allocator = mem.Allocator;
extern fn roc__mainForHost_1_exposed() RocStr;
extern fn roc__mainForHost_1_exposed_generic(*RocStr) void;
const Unit = extern struct {};
@ -90,7 +90,8 @@ pub fn main() u8 {
std.os.clock_gettime(std.os.CLOCK_REALTIME, &ts1) catch unreachable;
// actually call roc to populate the callresult
var callresult = roc__mainForHost_1_exposed();
var callresult = RocStr.empty();
roc__mainForHost_1_exposed_generic(&callresult);
// end time
var ts2: std.os.timespec = undefined;