mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Adjust examples to current platform interface
This commit is contained in:
parent
54ba54680d
commit
ba11f9b7b9
9 changed files with 40 additions and 22 deletions
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 : Effect.Effect {} as Fx
|
||||||
rocMain =
|
rocMain =
|
||||||
when List.len (Str.split "hello" "JJJJ there") is
|
when List.len (Str.split "hello" "JJJJ there") is
|
||||||
_ -> Effect.putLine "Yay"
|
_ -> Effect.putLine "Yay"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
platform folkertdev/foo
|
platform folkertdev/foo
|
||||||
provides [ mainForHost ]
|
requires { rocMain : Effect {} }
|
||||||
requires { main : Effect {} }
|
exposes []
|
||||||
|
packages {}
|
||||||
imports []
|
imports []
|
||||||
|
provides [ mainForHost ]
|
||||||
effects Effect
|
effects Effect
|
||||||
{
|
{
|
||||||
putChar : Int -> Effect {},
|
putChar : Int -> Effect {},
|
||||||
|
@ -10,4 +12,4 @@ platform folkertdev/foo
|
||||||
}
|
}
|
||||||
|
|
||||||
mainForHost : Effect {} as Fx
|
mainForHost : Effect {} as Fx
|
||||||
mainForHost = main
|
mainForHost = rocMain
|
||||||
|
|
|
@ -7,16 +7,16 @@ use std::alloc::Layout;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[link_name = "Main_rocMain_1_exposed"]
|
#[link_name = "roc__rocMain_1_exposed"]
|
||||||
fn roc_main(output: *mut u8) -> ();
|
fn roc_main(output: *mut u8) -> ();
|
||||||
|
|
||||||
#[link_name = "Main_rocMain_1_size"]
|
#[link_name = "roc__rocMain_1_size"]
|
||||||
fn roc_main_size() -> i64;
|
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) -> ();
|
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;
|
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>);
|
let output = &*(buffer as *mut RocCallResult<i64>);
|
||||||
|
|
||||||
// match output.into() {
|
match output.into() {
|
||||||
// Ok(v) => v,
|
Ok(_) => 0,
|
||||||
// Err(e) => panic!("failed with {}", e),
|
Err(e) => panic!("failed with {}", e),
|
||||||
// }
|
}
|
||||||
32
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +95,12 @@ pub fn rust_main() -> isize {
|
||||||
|
|
||||||
let closure_data_ptr = buffer.offset(16);
|
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) => {
|
Err(msg) => {
|
||||||
std::alloc::dealloc(buffer, layout);
|
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::alloca;
|
||||||
use roc_std::RocCallResult;
|
use roc_std::RocCallResult;
|
||||||
use std::alloc::Layout;
|
use std::alloc::Layout;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[link_name = "Main_makeClosure_1_exposed"]
|
#[link_name = "roc__makeClosure_1_exposed"]
|
||||||
fn make_closure(output: *mut u8) -> ();
|
fn make_closure(output: *mut u8) -> ();
|
||||||
|
|
||||||
#[link_name = "Main_makeClosure_1_size"]
|
#[link_name = "roc__makeClosure_1_size"]
|
||||||
fn closure_size() -> i64;
|
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) -> ();
|
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;
|
fn size_MyClosure() -> i64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +67,12 @@ pub fn rust_main() -> isize {
|
||||||
|
|
||||||
let closure_data_ptr = buffer.offset(16);
|
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) => {
|
Err(msg) => {
|
||||||
std::alloc::dealloc(buffer, layout);
|
std::alloc::dealloc(buffer, layout);
|
||||||
|
@ -80,7 +87,6 @@ pub fn rust_main() -> isize {
|
||||||
println!(
|
println!(
|
||||||
"Roc closure took {:.4} ms to compute this answer: {:?}",
|
"Roc closure took {:.4} ms to compute this answer: {:?}",
|
||||||
duration.as_secs_f64() * 1000.0,
|
duration.as_secs_f64() * 1000.0,
|
||||||
// truncate the answer, so stdout is not swamped
|
|
||||||
answer
|
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::RocCallResult;
|
||||||
use roc_std::RocList;
|
use roc_std::RocList;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[link_name = "_quicksort_1_exposed"]
|
#[link_name = "roc__quicksort_1_exposed"]
|
||||||
fn quicksort(list: RocList<i64>, output: &mut RocCallResult<RocList<i64>>) -> ();
|
fn quicksort(list: RocList<i64>, output: &mut RocCallResult<RocList<i64>>) -> ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue