Traditionally compilers compile themselves.
This chicken and egg situation can be resolved in serveral ways, eg a
cross
compiler, or an initial run through an interpreter build specially for the
purpose.
<--
While that's reasonably common (although far from universal, or even
true for the majority of implementation) with C, C++, and a few other
high level languages, the vast majority of compilers in existence do
not, and cannot, compile themselves. Consider, for example, any of
the 50 or so C (or C-like) compilers for the 8051 - likely none of
those would be up to compiling a whole C compiler. Or the vast number
of compiled small languages. Or consider that many C++ compilers are
written in C++, and most (all?) of those are also C compilers, which
are then implicitly also written in C++. Or just look at the
different languages in the GCC.
Compilers should be written in a language that's convenient for
writing a compiler. For some definition of "convenient" - two obvious
definitions are a language good at manipulating data structures like
you commonly find in a compiler (which might suggest a language like
Haskell), or a language commonly available on the target platforms
(which would suggest something like C). The language a compiler
compiles is fairly orthogonal to that.
The compiler bootstrapping thing seems to be more an intro-to-CS gee-
whiz concept, which should be mostly ignored in practice.
Which is not to say that all sorts of languages haven't been used to
write compilers. I know of examples of Cobol, Fortran and Basic
compilers that *are* self hosted. Although none of those three
languages would be my first choice for writing a compiler. And I know
of Cobol and Basic compilers written in assembler and C too. I also
know of Ada implementations in Ada (which is no less reasonable a
language for a compiler than C), and in C.
-->
yep...
sadly, not even my compiler, which compiles C (and is written in C), can
compile itself...
partly, it is because it focuses instead on JIT...
partly, it is because the thing is so damn buggy, that I have yet to even
make it work very well for even writing scripts... (it is more sort of "hit
or miss" whether or not the code actually compiles and works...).
more of an "oh, wow, cool", followed by a "this compiler doesn't really
actually work" experience...
at least... now the compiler doesn't tend to crash the app which tries to
use it, but I am faced with buggy output...
however, at least most of the "superstructure" is working "good enough" (the
system is not just a compiler, but a big mass of surrounding machinery as
well, comprising what is essentially a VM framework of sorts...).
this superstructure competes in terms of "usefulness" with the compiler
itself, where it is basically an ad-hoc collection of utility code, and
special purpose automatic code generation (which to a large extent give C
"reflection" abilities...). it differs from the compiler in that, it does
not have a centralized code generator, rather just lots of functions for
generating code for doing various tasks.
the reason for the split (a centralized codegen + a bunch of decentralized
code generation), is that it allows simplifying the core compiler (it does
not have to worry as much about the details of the runtime or the object
system, since a lot of this code will be generated automatically by the
runtime, allowing specific subsystems to generate those parts of code
relating to themselves...).
this allows the core codegen to be more generic as well, provided the
runtime provides the needed utilities (typically interfaced with via the
linker).
granted, I am now using the compiler on a different architecture (Win64 /
x86-64) than I originally wrote it to work with (Win32 / x86), which may be
part of at least some of the problems (a great big bug shakeout...).
now, what compiler do I use to compile it all (at present):
MSVC...
or such...