this post was submitted on 03 Aug 2024
1104 points (99.1% liked)

Programmer Humor

32472 readers
627 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
1104
submitted 3 months ago* (last edited 3 months ago) by sag@lemm.ee to c/programmerhumor@lemmy.ml
 
you are viewing a single comment's thread
view the rest of the comments
[–] henfredemars@infosec.pub 20 points 3 months ago (1 children)

I saw a Scheme interpreter written in assembly running a C compiler written in Scheme.

[–] davel@lemmy.ml 30 points 3 months ago (1 children)
[–] henfredemars@infosec.pub 4 points 3 months ago* (last edited 3 months ago)

There’s actually good reasons for this design. It’s easy to write a Scheme interpreter in assembly, but it’s hard to write a C compiler in assembly that handles everything correctly. Much rather write it in higher level language if possible and Scheme lowers the bar to getting there, so you can get away from using assembly as quickly as possible. Or you can copy somebody else’s Scheme implementation of a C compiler because now you’re platform independent.

Then you can write your C compiler in C (or steal a better compiler already written in C) and close the loop. For your final step, you use the C compiler to compile itself.