4 ms·
If you like this, you might like Lisp interpreter written in assembly in a single file. It is one of the best commented code ever written imo. https://github.c
by akashakya 9y ago
If you like this, you might like Lisp interpreter written in assembly in a single file. It is one of the best commented code ever written imo.
https://github.com/marcpaq/arpilisp https://github.com/marcpaq/arpilisp
- sparkie 9y agoAnother small lisp implementation: http://piumarta.com/software/lysp/ http://piumarta.com/software/lysp/ Also, another, more interesting Lisp by the same author: (http://piumarta.com/software/maru/ http://piumarta.com/software/maru/). Maru is basically a lisp where some of the core functions like eval and apply are extensible from user code. There's basically a global map of types to evaluators and applicators, with some functions for you to register your own types and get the evaluation behavior you want.
- fasquoika 9y agoIt seems like arpilisp is inspired by jonesforth[0]. Although not directly stated, the style is similar and the acknowledgements mentions Richard Jones. Anyone interested in implementing simple programming languages might also want to take a look at jonesforth. [0]: https://github.com/nornagon/jonesforth https://github.com/nornagon/jonesforth
- marcpaq 9y agoArpilisp author here. Yes, jonesforth definitely inspired and influenced me; that's why Jones is first in the Acknowledgements section. If you're curious, I keep a list of single-file implementations of programming languages (including jonesforth): https://github.com/marcpaq/b1fipl https://github.com/marcpaq/b1fipl
- _sdegutis 9y agoSince this is written in assembly is it much faster than a C version since this one can manage its own stack frames and stack variables and such? I always imagined that’s the case and that a lisp implemented fully in assembly would be the trick to a super fast lisp that can complete with Go.
- ci5er 9y agoLISP was created a long time ago. Assembly was the weapon of choice. Thinking Machines, Symbolics and Macsyma might already say: We did that. But, uh, no.
- klmr 9y agoThe first LISP implementation was famously done in machine code, not assembly.
- tom_mellior 9y agoAn interpreter written in assembly is still an interpreter. Yes, it may have control over stack frames. But so does a compiler, and the code generated by a compiler doesn't incur interpretation overhead. If you want performance, compliation is the way to go. And that's what fast Lisps do.
- marcpaq 9y agoArpilisp author here. If you were to implement the same Lisp in C then compare, then maybe the assembly variant would be faster for the reasons you mention. Or maybe not. Also, I modeled arpilisp after the original Lisp. That's barely a first step, and possibly the wrong first step, for anything non-trivial, including applications requiring a "super fast lisp that can compete with Go." But I didn't write arpilisp for performance. I wrote it to learn and share. Enjoy!
- nielsbot 9y agoSomeone once suggested to me the easiest way to "bootstrap the world" is to write a Forth implementation in assembly, and then write your Lisp in Forth.
- z29LiTp5qUC30n 9y agoas there is a project aiming to "bootstrap the world" https://savannah.nongnu.org/projects/stage0/ https://savannah.nongnu.org/projects/stage0/ and they hand wrote a FORTH http://git.savannah.nongnu.org/cgit/stage0.git/tree/stage2/forth.s http://git.savannah.nongnu.org/cgit/stage0.git/tree/stage2/f... and a compacting garbage collecting lisp http://git.savannah.nongnu.org/cgit/stage0.git/tree/stage2/lisp.s http://git.savannah.nongnu.org/cgit/stage0.git/tree/stage2/l... and their opinion was that it was easier to do the lisp than it was to do the FORTH. Although right now they are trying to improve their C Compiler prototype https://github.com/oriansj/M2-Planet https://github.com/oriansj/M2-Planet before they convert it to assembly