compiler for compiler for compiler

Started by
2 comments, last by Oluseyi 16 years, 1 month ago
I've always wondered what compiler produced the VStudio 6/7/8/9 executables or the RHIDE/GCC/CodeBlocks' executables (they had to be compiled somewhere!). Also what compiler put together THAT compiler and so on...
Advertisement
Compilers can be used to compile their own source code (pretty sure that's called "self-hosting"). Obviously that isn't possible for a new language, in which case the compiler is first written in another language.

In the absence of any higher level languages, the compiler would need to be manually entered machine code I guess.
It's been building since the dawn of computing. At first there was nothing but switches (or worse, hard-wired programs). Then, someone along the way made an assembler which took human-readable instruction mnemonics and produced machine code. That program would have been re-written in the assembly language itself to make it easier to change.

To implement a high-level language in itself, you'd first have to implement a small subset of that language in assembly code (or some other available language). Then do as was done before and re-write the language in the subset of itself. At this point it can now compile itself. Write new features for the language then go back and use those features to make the compiler better. The cycle continues until the language is "done" or it's used to bootstrap yet another self-hosting language.
Quote:Original post by pala_
Compilers can be used to compile their own source code (pretty sure that's called "self-hosting").

Correct.

@asdqwe:
The case of PyPy might prove instructive - and demonstrates that self-hosting is not limited to any particular type of language or execution model. The Mono C# compiler is also self-hosting, as are the Mono Visual Basic.NET and Oberon compilers.

As you can see, self-hosting implementation is quite common among programming languages, and is sometimes considered a significant benchmark of the language's adaptability to both expressiveness and performance.

This topic is closed to new replies.

Advertisement