Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

is it not common to write compilers for languages in the language being compiled itself? rust does this i think?


It is fairly common, yes. Sometimes those compilers (or interpreters) aren't the primary implementation, but it's certainly a thing that happens often.

Most of the Rust compiler is in Rust, that's correct, but it does by default use LLVM to do code generation, which is in C++.


note that as others have said, "compiled" is a stretch, but nevertheless...


Programs that are less than full compilers in some sense can be bootstrapped.

For instance, this compiler for a pattern matching notation has parts of it implementation using the notation itself:

https://www.kylheku.com/cgit/txr/tree/stdlib/match.tl

Some pattern matching occurs in the function match-case-to-casequal. This is why it is preceded by a dummy implementation of non-triv-pat-p, a function needed by the pattern matching logic for classifying whether a pattern is trivial or not; it has to be defined so that the if-match and other macros in the following function can expand. The sub just says every pattern is nontrivial, a conservative guess.

non-triv-pat-p is later redefined. And it uses match-case! So the pattern matcher has bootstrapped this function: a fundamental pattern classification function in the pattern matcher is written using pattern matching. Because of the way the file is staged, with the stub initial implementation of that function, this is all boostrapped in a single pass.




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

Search: