1. 20
  1.  

  2. 3

    Can someone explain what’s going on step by step? I don’t get how it works.

    1. 5

      I was also a bit confused. My confusion was around how strong the word “bootstrap” is I suppose. This process lets them bootstrap an OCaml compiler from gcc without needing the OCaml build toolchain, but they do still need an existing OCaml runtime that can run OCaml bytecode, as a step in the process.

      The steps, as I understand them:

      1. There is a compiler, written in Guile Scheme, that compiles a subset of OCaml (called miniml) to OCaml bytecode.

      2. There is an interpreter, written in miniml, that can interpret the full OCaml language. The Scheme compiler in step 1 can therefore compile a full OCaml interpreter from miniml source code to OCaml bytecode.

      3. [This step requires an OCaml runtime.] The interpreter produced in the previous steps can now be used to (very slowly) run the full/regular OCaml compiler. This interpreted compiler will be fed its own source code as input, and will compile itself, using the interpreted OCaml compiler to produce a compiled OCaml compiler, which completes the bootstrapping.

      1. 3

        Thanks. The bit that I was missing was step 3: using these tools to provide run the OCaml compiler that’s written in OCaml. Without that, it just sounds like an OCaml implementation that isn’t written in OCaml.

        For bootstrapping, I really like the way that Squeak does it. The core of the Squeak VM is written in a subset of Smalltalk that can be statically translated to C. To bring up on a new platform, you translate the core to C, and that gives you enough to run the rest (which is Smalltalk bytecode). You generate the image (the bytecode) on another machine and then just bring it across. I believe Pharo can use a JIT compiler to replace some of the bits that were translated through C, but once you’ve got a working Smalltalk VM you’ve done the bootstrap process and can use that to run any other Smalltalk tools.

        Bootstrapping is far less important if you have a good cross compiler. Clang, for example, can compile itself targeting any platform that it can target as a native compiler. This means that, as long as I have a VM image somewhere that contains any clang version, I can always use that to bootstrap a modern clang for any supported target.

        1. 2

          OCaml runtime is written in C, so that makes sense.