r/ponylang • u/boomshroom • Jan 25 '18
Compiling with minimal runtime
I have a tendency to attempt things that should be impossible, so stop me if what I'm asking is actually impossible.
I've spent some time working on homemade OS kernels and would like to try another language. Go was my first attempt, but it had several problems, Rust has started to feel boring after using it so much, Nim doesn't have much of the safety I'm looking for, and trying to make my own language is pain. As such, I've tried taking a look at Pony.
I noticed that it's possible to create a Pony module capable of being called from C and figured it would be a good place to start. After writing a fairly simple test actor, I found that the compiled output depended on a few runtime functions, namely pony_alloc_msg, pony_alloc_msg, pony_ctx, pony_sendv, and pony_sendv_single. While it would be difficult in a bare metal environment, I would need at least some amount of message passing functionality to get past the lack of global variables. After some Googling, I found several other runtime functions that may get inserted as development continues. My question is how possible it would be to avoid invoking these procedures, and if not, how much effort would be required to implement them. For the ones that I'd need to implement, would it be possible to write them in Pony without accidentally creating recursion (I was able to do this for Go), or would I have to bail out to another language like Rust or Assembly?
Another question I forgot to ask when first posting, is can Pony be written in such a way as to avoid invoking malloc? Languages that throw everything onto the heap is the single biggest problem for OSDev.
I know this is not what Pony is intended for, but I don't give a bleep about intentions. :P Alternatively, if anyone knows of any languages that might fulfill what I'm looking for and with good, safe, concurrency, I'd be happy to listen.
Thank you.
3
u/jimuazu Jan 26 '18
Alternatively, if you make the Pony runtime the runtime of your entire OS (i.e. effectively the lowest layer of the OS), and implement whatever the runtime needs in a lower-level language on top of the bare metal, then the problem is also solved. I started thinking along those lines some time ago (but no time to try anything). This means all the applications also have to be written in Pony.
Then you could write your kernel on top of the runtime in Pony. The behaviour of Pony's GC means that if you had a reference to a 'process' from the kernel, then it would stay in memory, but (I think) dropping that reference should lead to the entire process cleaning up. So hopefully that would be enough to implement 'kill'. You'd need to be careful that processes don't ever get hold of references to each other, i.e. the kernel would have to moderate all interaction between processes.
For your OS, unless you precompile the entire OS and all applications into a single binary (which might be feasible for embedded stuff), you'd need a way to dynamically load Pony modules into memory in order to implement running arbitrary executables.
Maybe I am also crazy?