News for hackers. Stuff that matters.
Re:Reader Macros in Common Lisp (2014) by sph on Sunday November 20, 2022 @06:54AM (#33680238)
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.)
Re:Reader Macros in Common Lisp (2014) by moonchild on Sunday November 20, 2022 @07:25AM (#33680393)
Why a reader macro? Just use s-expressions, like sbcl and ccl.
Re:Reader Macros in Common Lisp (2014) by guenthert on Sunday November 20, 2022 @02:07PM (#33684095)
Indeed. That would ease making other tools, e.g. a super-optimizer, which generate or modify assembly code.
Re:Reader Macros in Common Lisp (2014) by timonoko on Sunday November 20, 2022 @07:01AM (#33680267)
1970's calling. Been there. Done that: https://news.ycombinator.com/item?id=33517092#33517797
Re:Reader Macros in Common Lisp (2014) by sph on Sunday November 20, 2022 @07:02AM (#33680276)
Thanks for the inspiration. The fact that you've already done it won't stop me.

Got more details/links to study?

Re:Reader Macros in Common Lisp (2014) by timonoko on Sunday November 20, 2022 @07:10AM (#33680316)
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)
Re:Reader Macros in Common Lisp (2014) by macoovacany on Sunday November 20, 2022 @07:09AM (#33680308)
Re:Reader Macros in Common Lisp (2014) by User23 on Sunday November 20, 2022 @11:24AM (#33682248)
I’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.
Re:Reader Macros in Common Lisp (2014) by rst on Sunday November 20, 2022 @11:54AM (#33682646)
The 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...
Re:Reader Macros in Common Lisp (2014) by jlarocco on Sunday November 20, 2022 @02:18PM (#33684204)
Out of curiosity, why not write a Scheme or Common Lisp compiler? Or just a subset?
Re:Reader Macros in Common Lisp (2014) by sph on Sunday November 20, 2022 @06:52PM (#33686878)
I 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.

Re:Reader Macros in Common Lisp (2014) by jlarocco on Monday November 21, 2022 @10:46AM (#33693852)
> 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!