HVM icon indicating copy to clipboard operation
HVM copied to clipboard

Basic line-oriented IO loop

Open nmushegian opened this issue 3 years ago • 5 comments

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.

nmushegian avatar Apr 08 '22 17:04 nmushegian

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.

nmushegian avatar Apr 08 '22 17:04 nmushegian

This would be nice.

hhefesto avatar Apr 11 '22 21:04 hhefesto

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.

VictorTaelin avatar Apr 13 '22 16:04 VictorTaelin

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 avatar Apr 26 '22 01:04 hhefesto

@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.

steinerkelvin avatar May 04 '22 12:05 steinerkelvin

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.

VictorTaelin avatar Nov 23 '22 15:11 VictorTaelin