mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
Merge pull request #774 from rtfeldman/adjust-examples
Adjust examples to current platform interface
This commit is contained in:
commit
05a05fed42
1
examples/balance/.gitignore
vendored
Normal file
1
examples/balance/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
main
|
@ -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"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<i64>);
|
||||
|
||||
// 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);
|
||||
|
1
examples/closure/.gitignore
vendored
Normal file
1
examples/closure/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
closure
|
@ -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
|
||||
);
|
||||
|
||||
|
1
examples/effect/.gitignore
vendored
Normal file
1
examples/effect/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
effect-example
|
1
examples/shared-quicksort/.gitignore
vendored
Normal file
1
examples/shared-quicksort/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
quicksort
|
@ -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<i64>, output: &mut RocCallResult<RocList<i64>>) -> ();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user