HVM
HVM copied to clipboard
Basic line-oriented IO loop
I think we could get a lot of mileage out of HVM already by exposing stdio through a minimalist line-oriented IO primitive that might look like this.
(IO Input (State s) (Line c s)) = (IO Output (YourProgram (State s) (Line c s)))
(YourProgram state inputline) = ((State ...) (Line ...))
Here I write out (Line c s) to show it is a cons list of characters (atoms). (State s) is I guess a state burrito.
A line is a zero-terminated byte list representing an ascii string. Then we can pipe into stdin and out of stdout and have some useful programs.
I see this is covered in “improvements needed”, I think I could give a go at this so this issue could be for discussing the API.
This would be nice.
Yep, that is the plan. Should not be hard to do at all. Only complication is we'd need to do it twice, for both the interpreter and C runtime.
I would be glad to try and help with this. Any pointers/suggestions?
My use of hvm has been as a backend/evaluator of an intermediate representation of another language (https://github.com/Stand-In-Language/stand-in-language).
The down side is that I can't do the full evaluation of my intermediate representation without IO. I currently do some file shenanigans plus the use of haskell's IO to do a full evaluation, but that requires a lot of unnecessary file reading and writing.
So that's my motivation for IO on hvm.
I'll try to read through the code and find a good place to implement this, but I do hope I can gather some suggestions or even a semi worked out starting point.
Cheers! Daniel
@hhefesto
I'm very inclined to make an interface that enables us to inject some rules that implement the primitives that would be exposed to the programs, instead of implementing the IO directly on the runtime evaluation code (runtime.rs). Something on the lines of https://github.com/Kindelia/HVM/issues/38#issuecomment-1099276995.
What do you think?
Also, for the C runtime, we should eventually expose Rust code to it so we duplicate less code.
We have some IO primitives now, and it is possible to extend HVM with more IOs if you need so (see the guide). Let me know if there is anything else you're missing.