When compiling Ocaml from source code, it uses /boot/ocamlc
to compile the .ml
files.
So ocaml uses ocamlc itself to build itself. Where did the first ocamlc
file come from? How can I compile the first ocamlc
binary without /boot/ocamlc
?
OCaml has a long history, and wasn't always OCaml. It used to be CAML, possibly even earlier it was something else. Anyway, if you just call all these languages earlier forms of OCaml, the story probably goes roughly like this. (Note: I wasn't there, but I did build a compiler more or less this way one time.)
A long time ago, some ancients wrote the first OCaml compiler in a language other than OCaml. It compiled OCaml to bytecodes of a virtual machine. These ancients then rewrote the compiler in OCaml and used the first OCaml compiler to compile the second one (written in OCaml). This gave them a bytecode representation of an OCaml compiler. That's essentially what's in boot/ocamlc.
If you write a virtual machine implementation in a language other than OCaml (in C, say), you can build and run the VM on any machine with a C compiler and run the bytecode OCaml compiler on it. So you have a working OCaml implementation on any system with a C compiler.
In fact this virtual machine coded in C exists and is called ocamlrun.
If you're careful not to use new features too soon, you can modify the second OCaml compiler (coded in OCaml) and add new features. You just recompile it with the previous OCaml compiler, then recompile it again with itself (to take advantage of any improvements). After these two compiles, you can start to use the new features for implementing the compiler itself.
Since you can extend and improve the compiler later on in this way, you usually start with a compiler for a small subset of your eventual target language. That way you don't have to do as much work in the original language. After you get a working compiler coded in OCaml, you're going to throw the original compiler away, so there's no sense in making it more complicated than necessary.
If you don't want to use boot/ocamlc, seems like you'd have to write your own OCaml-to-bytecode compiler from scratch in some other language that you have available. You can still run the bytecodes with ocamlrun.
It's usually pretty hard to go back and find the original bootstrap compiler (written in some other language, probably for a very small subset of today's OCaml). But maybe it's out there somewhere....