4 ms·
Great timing. It's my turn to write a Lisp, and I was just thinking about implementing reader macros this morning :-) My goal is to create the barest-metal Lis
by sph 4y ago
Great timing. It's my turn to write a Lisp, and I was just thinking about implementing reader macros this morning :-)
My goal is to create the barest-metal Lisp OS (basically Lisp REPL with full ring-0 access, the OS) with an asm reader macro to write low level assembly opcodes you can jmp into.
(defn add1 (x)
(declare x int64)
#asm(
mov rax, %x
add rax, 1
))
(Just thought of this syntax on the spot, I'm a few dozen hours away from that still.)
- timonoko 4y ago1970's calling. Been there. Done that: https://news.ycombinator.com/item?id=33517092#33517797 https://news.ycombinator.com/item?id=33517092#33517797
- sph 4y agoThanks for the inspiration. The fact that you've already done it won't stop me. Got more details/links to study?
- timonoko 4y agohttps://github.com/timonoko/nokolisp_addons/blob/master/assembly.lsp https://github.com/timonoko/nokolisp_addons/blob/master/asse... Keyword is the line (dos-eval '(debug < TO.DEB > NUL)) ("mapc" and "map" had their parameters in wrong order, which annoys me even today)
- macoovacany 4y agohttps://movitz.common-lisp.dev/ https://movitz.common-lisp.dev/
- moonchild 4y agoWhy a reader macro? Just use s-expressions, like sbcl and ccl.
- guenthert 4y agoIndeed. That would ease making other tools, e.g. a super-optimizer, which generate or modify assembly code.
- User23 4y agoI’m guessing #ASM does the assembly at read or load time? Does it desugar to something like this? (assemble ‘((mov rax %x) (add rax 1))) Anyhow I think this is a great project. I hope you share it! I’ve often thought bootstrapping an assembler with lisp macros would be an interesting way to build a compiler from the very ground up. Assembler macros are nothing new, but I’ve never heard of an homoiconic implementation.
- rst 4y agoThe original LISP's "Lisp Assembly Program" was rather like this -- see Appendix C in the Lisp 1.5 manual, from 1962: https://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf https://www.softwarepreservation.org/projects/LISP/book/LISP...
- jlarocco 4y agoOut of curiosity, why not write a Scheme or Common Lisp compiler? Or just a subset?
- sph 4y agoI want an operating system from first principles. To write the smallest OS with the smallest language and the least amount of restriction. The goal is being able to replace every single part of the runtime/interpreter if you wish, but the OS itself starts with the fewest functions/features possible. cons, lambda, and the other usual suspects, a way of running actual native machine code, the homoiconicity of LISP, a runtime-editable image, packed into a UEFI binary. You could build yourself a Scheme or a Common Lisp on top of it if you wish.
- jlarocco 4y ago> You could build yourself a Scheme or a Common Lisp on top of it if you wish. No offense, but if it were Common Lisp I would take a look, but I don't have much interest in learning a one off language. Sounds like you're having so fun, though, so good luck!