diff --git a/examples/balance/.gitignore b/examples/balance/.gitignore new file mode 100644 index 0000000000..ba2906d066 --- /dev/null +++ b/examples/balance/.gitignore @@ -0,0 +1 @@ +main diff --git a/examples/balance/Main.roc b/examples/balance/Main.roc index bb87fb29b2..441dfb50f3 100644 --- a/examples/balance/Main.roc +++ b/examples/balance/Main.roc @@ -1,7 +1,7 @@ -app Main provides [ rocMain ] imports [ Effect ] +app "main" imports [ Effect ] provides [ rocMain ] to "./platform" + rocMain : Effect.Effect {} as Fx rocMain = when List.len (Str.split "hello" "JJJJ there") is _ -> Effect.putLine "Yay" - diff --git a/examples/balance/platform/Pkg-Config.roc b/examples/balance/platform/Pkg-Config.roc index a463e3bbb9..0d66513ebe 100644 --- a/examples/balance/platform/Pkg-Config.roc +++ b/examples/balance/platform/Pkg-Config.roc @@ -1,7 +1,9 @@ platform folkertdev/foo - provides [ mainForHost ] - requires { main : Effect {} } + requires { rocMain : Effect {} } + exposes [] + packages {} imports [] + provides [ mainForHost ] effects Effect { putChar : Int -> Effect {}, @@ -10,4 +12,4 @@ platform folkertdev/foo } mainForHost : Effect {} as Fx -mainForHost = main +mainForHost = rocMain diff --git a/examples/balance/platform/src/lib.rs b/examples/balance/platform/src/lib.rs index 61957ea485..0aa8e17445 100644 --- a/examples/balance/platform/src/lib.rs +++ b/examples/balance/platform/src/lib.rs @@ -7,16 +7,16 @@ use std::alloc::Layout; use std::time::SystemTime; extern "C" { - #[link_name = "Main_rocMain_1_exposed"] + #[link_name = "roc__rocMain_1_exposed"] fn roc_main(output: *mut u8) -> (); - #[link_name = "Main_rocMain_1_size"] + #[link_name = "roc__rocMain_1_size"] fn roc_main_size() -> i64; - #[link_name = "Main_rocMain_1_Fx_caller"] + #[link_name = "roc__rocMain_1_Fx_caller"] fn call_Fx(function_pointer: *const u8, closure_data: *const u8, output: *mut u8) -> (); - #[link_name = "Main_rocMain_1_Fx_size"] + #[link_name = "roc__rocMain_1_Fx_size"] fn size_Fx() -> i64; } @@ -62,11 +62,10 @@ unsafe fn call_the_closure(function_pointer: *const u8, closure_data_ptr: *const let output = &*(buffer as *mut RocCallResult); - // match output.into() { - // Ok(v) => v, - // Err(e) => panic!("failed with {}", e), - // } - 32 + match output.into() { + Ok(_) => 0, + Err(e) => panic!("failed with {}", e), + } }) } @@ -96,7 +95,12 @@ pub fn rust_main() -> isize { let closure_data_ptr = buffer.offset(16); - call_the_closure(function_pointer as *const u8, closure_data_ptr as *const u8) + let result = + call_the_closure(function_pointer as *const u8, closure_data_ptr as *const u8); + + std::alloc::dealloc(buffer, layout); + + result } Err(msg) => { std::alloc::dealloc(buffer, layout); diff --git a/examples/closure/.gitignore b/examples/closure/.gitignore new file mode 100644 index 0000000000..3b89e1b9f3 --- /dev/null +++ b/examples/closure/.gitignore @@ -0,0 +1 @@ +closure diff --git a/examples/closure/platform/src/lib.rs b/examples/closure/platform/src/lib.rs index b442d4d4e7..bbaca0733a 100644 --- a/examples/closure/platform/src/lib.rs +++ b/examples/closure/platform/src/lib.rs @@ -1,19 +1,21 @@ +#![allow(non_snake_case)] + use roc_std::alloca; use roc_std::RocCallResult; use std::alloc::Layout; use std::time::SystemTime; extern "C" { - #[link_name = "Main_makeClosure_1_exposed"] + #[link_name = "roc__makeClosure_1_exposed"] fn make_closure(output: *mut u8) -> (); - #[link_name = "Main_makeClosure_1_size"] + #[link_name = "roc__makeClosure_1_size"] fn closure_size() -> i64; - #[link_name = "Main_makeClosure_1_MyClosure_caller"] + #[link_name = "roc__makeClosure_1_MyClosure_caller"] fn call_MyClosure(function_pointer: *const u8, closure_data: *const u8, output: *mut u8) -> (); - #[link_name = "Main_makeClosure_1_MyClosure_size"] + #[link_name = "roc__makeClosure_1_MyClosure_size"] fn size_MyClosure() -> i64; } @@ -65,7 +67,12 @@ pub fn rust_main() -> isize { let closure_data_ptr = buffer.offset(16); - call_the_closure(function_pointer as *const u8, closure_data_ptr as *const u8) + let result = + call_the_closure(function_pointer as *const u8, closure_data_ptr as *const u8); + + std::alloc::dealloc(buffer, layout); + + result } Err(msg) => { std::alloc::dealloc(buffer, layout); @@ -80,7 +87,6 @@ pub fn rust_main() -> isize { println!( "Roc closure took {:.4} ms to compute this answer: {:?}", duration.as_secs_f64() * 1000.0, - // truncate the answer, so stdout is not swamped answer ); diff --git a/examples/effect/.gitignore b/examples/effect/.gitignore new file mode 100644 index 0000000000..ffc7415330 --- /dev/null +++ b/examples/effect/.gitignore @@ -0,0 +1 @@ +effect-example diff --git a/examples/shared-quicksort/.gitignore b/examples/shared-quicksort/.gitignore new file mode 100644 index 0000000000..19abff6005 --- /dev/null +++ b/examples/shared-quicksort/.gitignore @@ -0,0 +1 @@ +quicksort diff --git a/examples/shared-quicksort/platform/src/lib.rs b/examples/shared-quicksort/platform/src/lib.rs index 85d5c80781..974dc2592c 100644 --- a/examples/shared-quicksort/platform/src/lib.rs +++ b/examples/shared-quicksort/platform/src/lib.rs @@ -1,9 +1,11 @@ +#![allow(non_snake_case)] + use roc_std::RocCallResult; use roc_std::RocList; use std::time::SystemTime; extern "C" { - #[link_name = "_quicksort_1_exposed"] + #[link_name = "roc__quicksort_1_exposed"] fn quicksort(list: RocList, output: &mut RocCallResult>) -> (); }