mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-13 09:49:11 +03:00
use exposed_generic in hello world examples
This commit is contained in:
parent
bc492fa22b
commit
9d9e7d10d4
@ -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| {
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user