Self-hosting

From Wikipedia, the free encyclopedia
Jump to: navigation, search

The term self-hosting was coined to refer to the use of a computer program as part of the toolchain or operating system that produces new versions of that same program—for example, a compiler that can compile its own source code. Self-hosting software is commonplace on personal computers and larger systems. Other programs that are typically self-hosting include kernels, assemblers, command-line interpreters and revision control software.

If a system is so new that no software has been written for it, then software is developed on another self-hosting system and placed on a storage device that the new system can read. Development continues this way until the new system can reliably host its own development. Development of the Linux kernel, for example, was initially hosted on a Minix system. Writing new software development tools "from the metal" (that is, without using another host system) is rare and in many cases impractical.

History[edit]

The first self-hosting compiler (excluding assemblers) was written for Lisp by Hart and Levin at MIT in 1962. They wrote a Lisp compiler in Lisp, testing it inside an existing Lisp interpreter. Once they had improved the compiler to the point where it could compile its own source code, it was self-hosting.[1]

The compiler as it exists on the standard compiler tape is a machine language program that was obtained by having the S-expression definition of the compiler work on itself through the interpreter.

—AI Memo 39[1]

This technique is only possible when an interpreter already exists for the very same language that is to be compiled. It borrows directly from the notion of running a program on itself as input, which is also used in various proofs in theoretical computer science, such as the proof that the halting problem is undecidable.

Examples[edit]

Many programming languages have self-hosted implementations: compilers that are both in and for the same language. Such languages include Ada, BASIC, C, C++,[2] C#,[3] CoffeeScript, Dylan, F#, FASM, Forth, Gambas, Haskell, Java, Lisp, Modula-2, OCaml, Oberon, Pascal, Python, Rust, Scala, Smalltalk, Vala, and Visual Basic.[3]

In some of these cases, the initial implementation was not self-hosted, but rather, written in another language (or even in machine language); in other cases, the initial implementation was developed using bootstrapping.

See also[edit]

References[edit]

  1. ^ a b Tim Hart and Mike Levin. "AI Memo 39-The new compiler". Retrieved 2008-05-23. 
  2. ^ gcc 4.8, LLVM/clang
  3. ^ a b Mono gmcs and Microsoft Roslyn