Hacker News new | past | comments | ask | show | jobs | submit login
Let's write a compiler, part 4: Testing (briancallahan.net)
96 points by ingve on Aug 17, 2021 | hide | past | favorite | 6 comments



For context, there was some discussion here on HN about parts 1 and 3 of this series:

https://news.ycombinator.com/item?id=28183062

https://news.ycombinator.com/item?id=28197876


Looking at the code it feels more like an assembler than a compiler since there is no mess and it outputs C code.

But it is very clean and nice. I like the pattern.


It seems like we're going to have the same discussion on this topic every day until all parts are posted.


> more like an assembler than a compiler since there is no mess and it outputs C code.

Yes, translating between closely related languages is often like this: the mapping between their constructs is 1-to-1 and almost trivial. But try translating e.g. λ-calculus into C in one go, without separate lambda-lifting/closure-converting steps: it's absolutely doable but quite messy.


> feels more like an assembler than a compiler

Yes it's a kind of transpiler, or template compiler, a typically 1-1 mapping.


When absolute compiler perf isn't required, I love nanopass compilers for this. Each pass slowly massages a slightly different IR towards the final form and there isn't really a limit to how different the code source and end target can be, just needs more passes.




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

Search: