Hacker News new | past | comments | ask | show | jobs | submit login
Writing a Lisp to x86-64 compiler
81 points by tekknolagi on Aug 31, 2020 | hide | past | favorite | 22 comments
I'm starting to write a series on compiling Lisp to x86-64 and I would appreciate any and all feedback.

Find the first post at https://bernsteinbear.com/blog/compiling-a-lisp-0/





This first post is nicely done. The basics of building a JIT compiler in just a few lines of C, and everything thoroughly explained.

Also, the “getting your hands dirty” and “making your own mistakes” approach is how you really learn something.


Just finished the second post this morning if you're interested: https://bernsteinbear.com/blog/compiling-a-lisp-2/


Thanks! I appreciate the feedback.


The raw concept of executing modified memory is neat. It looks so clean and simple.


This is something I was looking forward to! Thanks you so much <3

Do you follow John Carmack's coding standard?


Just finished the second post this morning if you're interested: https://bernsteinbear.com/blog/compiling-a-lisp-2/


I'm glad you enjoyed! I don't know anything about John Carmack's coding standard, so probably not.


Why not Arc to x86-64 compiler?


I don't know anything about Arc. I also want a bit of creative license to change the host language as needed, and people might not appreciate "Arc with Max's edits".


You're missing the forest for the trees. What's the tiniest x86-64 code generator that can bootstrap John McCarthy's meta-circular evaluator, as it is written in his original paper. Now that's something I'd love to see. What he accomplished there is so profound and has served as the center of gravity that's attracted folks to LISP ever since. Also if you build it with APE your distributables will run on all platforms https://justine.storage.googleapis.com/ape.html


> You're missing the forest for the trees. What's the tiniest x86-64 code generator that can bootstrap John McCarthy's meta-circular evaluator,

I don't think I am, and that's explicitly not the focus of the series. The goal is to learn about writing a Lisp compiler and to learn about x86-64. I don't care if I compile more in C than I need to.


> Also if you build it with APE your distributables will run on all platforms

Did anybody show that that format is actually usable for distribution of something that's not expected to be very, very small? I've got an impression it's more a hacking achievement than a really practical solution.


UNIX philosophy is to have lots of small executables. This is a brand new scrappy project that offers a lot of value in terms of better enabling that vision. It uses normal GNU C / C++ / FORTRAN (which are all fantastic toys) combined with a linker script that emits a new executable format.


> What's the tiniest x86-64 code generator that can bootstrap John McCarthy's meta-circular evaluator, as it is written in his original paper. Now that's something I'd love to see.

If a C code generator will do, this will be the topic of my upcoming book.


Wow I'm not sure if I've ever influenced someone to write a book before. That's certainly something I'd pay to read. Can we call it "The LISP Challenge"? https://twitter.com/JustineTunney/status/971235177002225665/... I think C code generation is great. The problem generalizes well across languages, which is why I love suggesting it to my friends who are getting into the latest one: take The LISP Challenge!


> Wow I'm not sure if I've ever influenced someone to write a book before.

I hope I am not disappointing you too much, but the book was already in progress when you posted your message! Coincidence! :) And the title is pretty much set at this point, I'm afraid...


@nils-m-holm - Having thoroughly enjoyed mLight's codebase and playing with mLight in general and worked through your SubC compiler - very much looking forward to the upcoming book.


Thanks!

Oh, mLite! That was a while ago! Fun times! :)


It's great to see you in the thread! I very much enjoyed Lisp from outer space. Your work has been helpful in teaching me programming languages stuff.


Good to hear, thank you!


Thank you for that article, it was a joy to read. The lively discussion last week about APE:

αcτµαlly pδrταblε εxεcµταblε - https://news.ycombinator.com/item?id=24256883




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: