I have been thinking about making an application that compiles itself (primarily because it's fun and I will probably learn a lot of new stuff). After some research, I figured that this is called a Self-Hosted application.
My main criteria are:
- The code must have a quine of it's own code to be compiled
- The code must be portable. That means the code cannot use external tools (i.e. an Assembler or another compiler ) because then it is not self hosted. It only has a copy of its code that it passes to another program.
In the beginning I tried to do it in GoLang, because the golang compiler (gc) is bootsrapped (i.e. written in golang), but after diving into the GoLang compiler code I figured that the compilation process consists of a lot of stages. As far as I know, it goes like this:
- A (perbuilt) GoLang compiler is used to build $GOROOT/src/cmd/dist
- The dist tool is run
- The dist tool compiles all the tools and stages of the gc compiler
I tried to figure out exactly what the dist tool does, but (after a few days of trying to understand the code) I wasn't able to figure it out.
Other people have tried to do it in Lisp, but I haven't found anybody that doesn't use external tools...
So is there an easier way to do this? Is there a language that provides the ability to build it code from within itself?
Can this be done without a creating a new bootstrapped language from scratch or writing a Compiler+Linker+Assembler from scratch?