mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
fix the effect Main.roc file and lib.rs file
This commit is contained in:
parent
2dbf430892
commit
1022b4ef42
4 changed files with 14 additions and 32 deletions
|
@ -1806,7 +1806,8 @@ fn expose_function_to_host_help<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
// STEP 3: build a {} -> u64 function that gives the size of the return type
|
// STEP 3: build a {} -> u64 function that gives the size of the return type
|
||||||
let size_function_type = env.context.i64_type().fn_type(&[], false);
|
let size_function_type = env.context.i64_type().fn_type(&[], false);
|
||||||
let size_function_name: String = format!("{}_size", roc_function.get_name().to_str().unwrap());
|
let size_function_name: String =
|
||||||
|
format!("roc_{}_size", roc_function.get_name().to_str().unwrap());
|
||||||
|
|
||||||
let size_function = env.module.add_function(
|
let size_function = env.module.add_function(
|
||||||
size_function_name.as_str(),
|
size_function_name.as_str(),
|
||||||
|
@ -2119,8 +2120,9 @@ pub fn build_closure_caller<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
// STEP 1: build function header
|
// STEP 1: build function header
|
||||||
|
|
||||||
|
// e.g. `roc__main_1_Fx_caller`
|
||||||
let function_name = format!(
|
let function_name = format!(
|
||||||
"{}_{}_caller",
|
"roc_{}_{}_caller",
|
||||||
def_name,
|
def_name,
|
||||||
alias_symbol.ident_string(&env.interns)
|
alias_symbol.ident_string(&env.interns)
|
||||||
);
|
);
|
||||||
|
@ -2200,7 +2202,7 @@ pub fn build_closure_caller<'a, 'ctx, 'env>(
|
||||||
// STEP 3: build a {} -> u64 function that gives the size of the return type
|
// STEP 3: build a {} -> u64 function that gives the size of the return type
|
||||||
let size_function_type = env.context.i64_type().fn_type(&[], false);
|
let size_function_type = env.context.i64_type().fn_type(&[], false);
|
||||||
let size_function_name: String = format!(
|
let size_function_name: String = format!(
|
||||||
"{}_{}_size",
|
"roc_{}_{}_size",
|
||||||
def_name,
|
def_name,
|
||||||
alias_symbol.ident_string(&env.interns)
|
alias_symbol.ident_string(&env.interns)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,31 +1,11 @@
|
||||||
app "effect-example" provides [ main ] imports [ Effect, RBTree ]
|
app "effect-example" imports [ Effect, RBTree ] provides [ main ] to "./platform"
|
||||||
|
|
||||||
toAndFro : Int
|
|
||||||
toAndFro =
|
|
||||||
empty : RBTree.Dict Int {}
|
|
||||||
empty = RBTree.empty
|
|
||||||
|
|
||||||
empty
|
|
||||||
|> (\d -> RBTree.insert 1 {} d)
|
|
||||||
|> RBTree.toList
|
|
||||||
|> List.len
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
main : Effect.Effect {} as Fx
|
main : Effect.Effect {} as Fx
|
||||||
main =
|
main =
|
||||||
# if RBTree.isEmpty empty then
|
if RBTree.isEmpty (RBTree.insert 1 2 Empty) then
|
||||||
if toAndFro == 2 then
|
|
||||||
Effect.putLine "Yay"
|
Effect.putLine "Yay"
|
||||||
|> Effect.after (\{} -> Effect.getLine)
|
|> Effect.after (\{} -> Effect.getLine)
|
||||||
|> Effect.after (\line -> Effect.putLine line)
|
|> Effect.after (\line -> Effect.putLine line)
|
||||||
else
|
else
|
||||||
Effect.putLine "Nay"
|
Effect.putLine "Nay"
|
||||||
|
|
||||||
|
|
||||||
# Effect.always "Write a thing"
|
|
||||||
# |> Effect.map (\line -> Str.concat line "!")
|
|
||||||
# |> Effect.after (\line -> Effect.putLine line)
|
|
||||||
# |> Effect.after (\{} -> Effect.getLine)
|
|
||||||
# |> Effect.after (\line -> Effect.putLine line)
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
interface RBTree exposes [ Dict, empty, size, singleton, isEmpty, insert, remove, update, fromList, toList ] imports []
|
interface RBTree exposes [ Dict, empty, size, singleton, isEmpty, insert, remove, update, fromList, toList, balance ] imports []
|
||||||
|
|
||||||
# The color of a node. Leaves are considered Black.
|
# The color of a node. Leaves are considered Black.
|
||||||
NodeColor : [ Red, Black ]
|
NodeColor : [ Red, Black ]
|
||||||
|
|
|
@ -7,16 +7,16 @@ use std::alloc::Layout;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[link_name = "Main_main_1_exposed"]
|
#[link_name = "roc__main_1_exposed"]
|
||||||
fn roc_main(output: *mut u8) -> ();
|
fn roc_main(output: *mut u8) -> ();
|
||||||
|
|
||||||
#[link_name = "Main_main_1_size"]
|
#[link_name = "roc__main_1_size"]
|
||||||
fn roc_main_size() -> i64;
|
fn roc_main_size() -> i64;
|
||||||
|
|
||||||
#[link_name = "Main_main_1_Fx_caller"]
|
#[link_name = "roc__main_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_main_1_Fx_size"]
|
#[link_name = "roc__main_1_Fx_size"]
|
||||||
fn size_Fx() -> i64;
|
fn size_Fx() -> i64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,10 +60,10 @@ unsafe fn call_the_closure(function_pointer: *const u8, closure_data_ptr: *const
|
||||||
buffer as *mut u8,
|
buffer as *mut u8,
|
||||||
);
|
);
|
||||||
|
|
||||||
let output = &*(buffer as *mut RocCallResult<i64>);
|
let output = &*(buffer as *mut RocCallResult<()>);
|
||||||
|
|
||||||
match output.into() {
|
match output.into() {
|
||||||
Ok(v) => v,
|
Ok(_) => 0,
|
||||||
Err(e) => panic!("failed with {}", e),
|
Err(e) => panic!("failed with {}", e),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue