Sign in to follow this  
asdqwe

compiler for compiler for compiler

Recommended Posts

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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this