0

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:

  1. The code must have a quine of it's own code to be compiled
  2. 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:

  1. A (perbuilt) GoLang compiler is used to build $GOROOT/src/cmd/dist
  2. The dist tool is run
  3. 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?

  • ...a quine of its own code... ? – Jan Doggen Sep 16 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.