News for hackers. Stuff that matters.
Re:A small scheme VM, compiler, and REPL in 4k by throwaway81523 on Friday November 26, 2021 @05:13AM (#29348924)
Paper is acm-walled but code repo is https://github.com/udem-dlteam/ribbit . I would like to have seen Hedgehog Lisp ( https://github.com/sbp/hedgehog ) in the comparison chart, since it has actually been used for practical projects. Its VM is around 20KB of object code. 4KB is impressively tiny, but any machine where 4k vs 20k makes a big difference is unlikely to have enough ram to run garbage collected applications. That seems to call more something more like Forth rather than Scheme.

Hedgehog is a somewhat weird functional dialect of Lisp and I've been wanting for a while to convert it to a Scheme subset (mostly just using Scheme syntax instead of defun, etc) so people would be more familiar with it.

Added: paper is here http://www.iro.umontreal.ca/~feeley/papers/YvonFeeleyVMIL21....

Re:A small scheme VM, compiler, and REPL in 4k by bsder on Friday November 26, 2021 @08:36AM (#29350071)
The rib encoding looks very clever. I need to digest the full implications of that.

> 4KB is impressively tiny, but any machine where 4k vs 20k makes a big difference is unlikely to have enough ram to run garbage collected applications.

Yeah, the paper itself says that the heap was 240K. A 4K system isn't very helpful if your heap is 240K.

I'd like to see how this runs (if at all) with a 4K heap. Deceptively straightforward things like map and apply can cons up a whopping amount of intermediate garbage.

> I would like to have seen Hedgehog Lisp ( https://github.com/sbp/hedgehog ) in the comparison chart, since it has actually been used for practical projects

Links to projects?

Re:A small scheme VM, compiler, and REPL in 4k by djwatson24 on Friday November 26, 2021 @01:07PM (#29352478)
I agree the optimization looks backwards to me - in most of the microcontrollers I work on, the flash program space can easily be multiple megabytes, but the ram is usually the limiter around 128-512k.
Re:A small scheme VM, compiler, and REPL in 4k by feeley on Friday November 26, 2021 @02:59PM (#29353537)
The introduction in the paper explains the motivation for Ribbit:

The use case which has motivated our work is code mobility where an executable program can be embedded in a document, email, or website. In that use case the size of the program must be small to minimize the transmission or loading time or to satisfy space constraints, such as the size of a disk boot sector, the URL length limit and the UDP packet size. On the other hand, the space used while the program is executing is of secondary importance.

So the main target application is not microcontrollers, even if it can obviously be used for some microcontrollers (for example a 1-2$ ESP32-C3 has 400 KB of RAM).

One of the possible applications of Ribbit is to implement the RVM (Ribbit VM) in the Excel spreadsheet formula language (which will soon be turing-complete with the addition of the LAMBDA form) to be able to program spreadsheets in Scheme. The execution environment has lots and lots of RAM, but you want the .xls file itself (which contains the RVM) to be as small as possible so it can easily be sent in emails, etc.

Re:A small scheme VM, compiler, and REPL in 4k by pumanoir on Friday November 26, 2021 @05:30PM (#29354909)
Can Ribbit w/ the max lib run everything from SICP? It'd be really cool to have a self contained (html or other text) file of the SICP book.
Re:A small scheme VM, compiler, and REPL in 4k by feeley on Friday November 26, 2021 @05:59PM (#29355158)
Ribbit's max library contains most of the R4RS predefined procedures (even call/cc). The main things missing are variadic procedures (unfortunately this includes the "list" procedure so you need to replace (list 1 2 3) by (cons 1 (cons 2 (cons 3 '())))) and also all the file opening operations. There is read-char, write-char, etc but they only do console I/O. These things could be added at the price of a larger footprint. One simple way to do this is to have the RVM run the code of a meta-circular Scheme evaluator written in Scheme.

If you are interested in building a a self-contained HTML document that embeds a full featured Scheme implementation, you should look into Gambit. Check out https://try.gambitscheme.org

Re:A small scheme VM, compiler, and REPL in 4k by pumanoir on Sunday November 28, 2021 @03:31PM (#29372680)
Thanks. I will check it out.
Re:A small scheme VM, compiler, and REPL in 4k by rcarmo on Friday November 26, 2021 @08:08AM (#29349919)
Added to https://taoofmac.com/space/dev/lisp along with a few others, since I'm fascinated by this kind of thing.
Re:A small scheme VM, compiler, and REPL in 4k by feeley on Friday November 26, 2021 @03:51PM (#29353988)
In your list you say "small and portable Scheme implementation with AOT compilation and 4K footprint". However the presence of an AOT compiler is not the most interesting part. The distinguishing feature is that in 4K there is a REPL that uses a dynamic compiler to do the "eval". In other words, the code entered at the REPL runs essentially as fast as if it was compiled by the AOT compiler.
Re:A small scheme VM, compiler, and REPL in 4k by throwaway81523 on Saturday November 27, 2021 @05:31AM (#29359104)
It seems to me (granted I haven't gotten it to work reliably at all yet) that the REPL is somewhat fragile, and I wonder if it might be easier as well as smaller to use a remote (tethered) compiler, as some Forth systems do.

Re the repl, I may have figured out what went wrong with user-defined functions. Instead of saying (define (sq x) (* x x)) I apparently have to say (define sq (lambda (x) (* x x))). Maybe that is documented in the paper, which I still have to read.