diff --git a/crates/compiler/gen_llvm/src/llvm/build.rs b/crates/compiler/gen_llvm/src/llvm/build.rs index dd68e16de6..0fc712ec75 100644 --- a/crates/compiler/gen_llvm/src/llvm/build.rs +++ b/crates/compiler/gen_llvm/src/llvm/build.rs @@ -4591,9 +4591,6 @@ pub fn build_procedures<'a, 'ctx, 'env>( let niche = Niche::NONE; for (symbol, top_level) in glue_layouts.getters.iter().copied() { - dbg!(symbol, unsafe { - std::mem::transmute::(symbol) - }); let it = top_level.arguments.iter().copied(); let bytes = roc_alias_analysis::func_name_bytes_help(symbol, it, niche, &top_level.result); let func_name = FuncName(&bytes); @@ -4613,6 +4610,8 @@ pub fn build_procedures<'a, 'ctx, 'env>( let name = getter_fn.get_name().to_str().unwrap(); let getter_name = symbol.as_str(&env.interns); + dbg!(&getter_name); + // Add the getter function to the module. let _ = expose_function_to_host_help_c_abi( env, diff --git a/crates/glue/src/types.rs b/crates/glue/src/types.rs index fbd9662e4d..c5c3855882 100644 --- a/crates/glue/src/types.rs +++ b/crates/glue/src/types.rs @@ -974,7 +974,7 @@ fn add_type_help<'a>( add_type_help(env, ret_layout, *ret_var, None, types) }; - let name = format!("TODO_roc_function_{:?}", closure_var); + let name = format!("RocFunction_{:?}", closure_var); let fn_type_id = types.add_named( &env.layout_cache.interner, name.clone(), diff --git a/examples/platform-switching/rust-platform/main.roc b/examples/platform-switching/rust-platform/main.roc index b39ac0ad9d..dee750bbfa 100644 --- a/examples/platform-switching/rust-platform/main.roc +++ b/examples/platform-switching/rust-platform/main.roc @@ -7,5 +7,9 @@ platform "echo-in-rust" Op : [StdoutWrite Str ({} -> Op), StderrWrite Str ({} -> Op), Done] + +# mainForHost : { bar: Str, foo: I64 -> I64 } +# mainForHost = { bar: main, foo: \x -> x } + mainForHost : Op mainForHost = main diff --git a/examples/platform-switching/rust-platform/src/glue.rs b/examples/platform-switching/rust-platform/src/glue.rs index d52fe5bfeb..f5c2863cec 100644 --- a/examples/platform-switching/rust-platform/src/glue.rs +++ b/examples/platform-switching/rust-platform/src/glue.rs @@ -97,6 +97,21 @@ union union_Op { _sizer: [u8; 8], } +#[derive(Clone)] +struct RocFunction_3 { + closure_data: T +} + +impl RocFunction_3 { + pub fn call(self) -> U { + extern "C" { + fn call_the_closure(T) -> U ; + } + + call_the_closure(self.closure_data) + } +} + impl Op { #[cfg(any( target_arch = "arm", diff --git a/examples/platform-switching/rust-platform/src/lib.rs b/examples/platform-switching/rust-platform/src/lib.rs index 414731d7c2..38346b9b44 100644 --- a/examples/platform-switching/rust-platform/src/lib.rs +++ b/examples/platform-switching/rust-platform/src/lib.rs @@ -93,7 +93,7 @@ pub extern "C" fn rust_main() -> i32 { println!("Let's do things!"); - let op: Op = unsafe { + let mut op: Op = unsafe { let mut mem = MaybeUninit::uninit(); roc_main(mem.as_mut_ptr()); @@ -101,26 +101,33 @@ pub extern "C" fn rust_main() -> i32 { mem.assume_init() }; - match dbg!(op.discriminant()) { - StdoutWrite => { - let output: RocStr = unsafe { op.get_StdoutWrite_0() }; - // let _next = unsafe { op.get_StdoutWrite_1() }; + loop { + match dbg!(op.discriminant()) { + StdoutWrite => { + let output: RocStr = unsafe { op.get_StdoutWrite_0() }; + op = unsafe { op.get_StdoutWrite_1() }; - dbg!(&output); + dbg!(&output); - if let Err(e) = std::io::stdout().write_all(output.as_bytes()) { - panic!("Writing to stdout failed! {:?}", e); + if let Err(e) = std::io::stdout().write_all(output.as_bytes()) { + panic!("Writing to stdout failed! {:?}", e); + } + } + StderrWrite => { + let output: RocStr = unsafe { op.get_StderrWrite_0() }; + // let _next = unsafe { op.get_StderrWrite_1() }; + dbg!(&output); + + break; + + if let Err(e) = std::io::stderr().write_all(output.as_bytes()) { + panic!("Writing to stderr failed! {:?}", e); + } + } + Done => { + break; } } - StderrWrite => { - let output: RocStr = unsafe { op.get_StderrWrite_0() }; - // let _next = unsafe { op.get_StderrWrite_1() }; - - if let Err(e) = std::io::stderr().write_all(output.as_bytes()) { - panic!("Writing to stderr failed! {:?}", e); - } - } - Done => {} } println!("Done!"); diff --git a/examples/platform-switching/zig-platform/main.roc b/examples/platform-switching/zig-platform/main.roc index a52fe9a480..0088f5320b 100644 --- a/examples/platform-switching/zig-platform/main.roc +++ b/examples/platform-switching/zig-platform/main.roc @@ -5,5 +5,5 @@ platform "echo-in-zig" imports [] provides [mainForHost] -mainForHost : Str -mainForHost = main +mainForHost : { bar: Str, foo: I64 -> I64 } +mainForHost = { bar: main, foo: \x -> x }