Hi, trying to understand what is under the hood, I fell on the missing definition of:
hosted Effect
...
generates Effect with [after, map, always, forever, loop]
It seems to come from compiler/can/src/effect_module.rs
where I found a good definition and documentation.
But how generates
work? I didn't find other call of it. Are loop
, after
etc.. generic functions? Why are they implemented in the compiler instead of the platform?
I would also be very interested in this. I want to try my hand at a simple zig-based platform for aoc input fetching, but there is a lot of what seems like magic going on in the platform definitions I found.
we're in the process of hopefully getting rid of all this, such that the entire hosted
module concept would no longer be necessary, but it's not ready yet!
sounds like some good progress, I'm looking forward to seeing it. in the meantime, is there anything to read up on here? I'm particularly interested in how the whole roc__mainForHost_1__Init_caller
stuff gets created. Specifically
1
come fromundefined
for top level function?)I know this is a lot of questions, especially when some of this is going to change very soon :sweat_smile:
Where does the
1
come from
1
is the specialization number. For exposed functions, they will always use concrete types and that should always be 1
.
Why do these functions take an additional argument
Yep flags and closure data. It is sometimes used from the host, but that is pretty rare and generally not needed.
How do complex types in roc get exposed to the platform?
It's complicated. We can work through types one at a time, but it is a huge time sync full of segfaults that often greatly slows down platform development. Currently roc glue
only works for rust. That generates everything for the platform developer. The long term goal is make it pluggable such that it can be used for any language. I would honestly advise just sticking wit rust as the platform language for now if you are ok with that, but if you want to use zig, will help you as you run into issues.
Do I somehow get the app name in the platform?
Nope. Though you could either make the app pass it to you or use the executable name to get it.
I generally have more experience in rust than zig, so I’d be fine with that. It just seemed that currently there is more overhead involved in the rust bindings because zig has an easier time arbitrarily allocating memory and exposing functions c-style.
Of course in the future having something like bindgen for creating rust-based platforms would be amazing
Yeah, I would agree that zig is a better fit for this kind of binding. But having some form of roc glue
, even if not fully functional, is huge for iteration and small correctness bugs that lead to segfaults.
Last updated: Jul 06 2025 at 12:14 UTC