Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Self-hosting (compilers)

From Wikipedia, the free encyclopedia
(Redirected fromSelf-hosting compiler)
Software that can produce new versions of itself
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Self-hosting" compilers – news ·newspapers ·books ·scholar ·JSTOR
(April 2010) (Learn how and when to remove this message)

Incomputer programming,self-hosting is the use of aprogram as part of thetoolchain oroperating system that produces new versions of that same program—for example, acompiler that can compile its ownsource code. Self-hostingsoftware is commonplace onpersonal computers and larger systems. Other programs that are typically self-hosting includekernels,assemblers,command-line interpreters andrevision control software.

Operating systems

[edit]

An operating system is self-hosted when the toolchain to build the operating system runs on that same operating system. For example, Windows can be built on a computer running Windows.

Before a system can become self-hosted, another system is needed to develop it until it reaches a stage where self-hosting is possible. When developing for a new computer or operating system, a system to run the development software is needed, but development software used to write and build the operating system is also necessary. This is called abootstrapping problem or, more generically, achicken or the egg dilemma.

A solution to this problem is thecross compiler (or cross assembler when working with assembly language). A cross compiler allowssource code on one platform to be compiled for a different machine or operating system, making it possible to create an operating system for a machine for which a self-hosting compiler does not yet exist. Once written, software can be deployed to the target system using means such as anEPROM,floppy diskette,flash memory (such as a USB thumb drive), orJTAG device. This is similar to the method used to write software for gaming consoles or for handheld devices like cellular phones or tablets, which do not host their own development tools.

Once the system is mature enough to compile its own code, the cross-development dependency ends. At this point, an operating system is said to be self-hosted.

Compilers

[edit]

Software development using compiler or interpreters can also be self hosted when the compiler is capable of compiling itself.[1]

Since self-hosted compilers suffer from the same bootstrap problems as operating systems, a compiler for a new programming language needs to be written in an existing language. So the developer may use something like assembly language,C/C++, or even a scripting language likePython orLua to build the first version of the compiler. Once the language is mature enough, development of the compiler can shift to the compiler's native language, allowing the compiler to build itself.

Advantages

[edit]

Self-hosting a compiler has the following advantages:[2]

  • It is a non-trivial test of the language being compiled, and as such is a form ofdogfooding.
  • Compiler developers and bug reporters only need to know the language being compiled.
  • Compiler development can be performed in the higher-level language being compiled.
  • Improvements to the compiler's back-end improve not only general-purpose programs but also the compiler itself.
  • It is a comprehensive consistency check as it should be able to reproduce its own object code.

Note that some of these points assume that the languageruntime is also written in the same language.

History

[edit]
Main article:History of compiler construction

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

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

— AI Memo 39[3]

This technique is usually only practicable when an interpreter already exists for the very same language that is to be compiled; though possible, it is extremely uncommon to humanly compile a compiler with itself.[4] The concept borrows directly from and is an example of the broader notion of running a program on itself as input, used also in various proofs intheoretical computer science, such as the proof that thehalting problem is undecidable.

Examples

[edit]

Ken Thompson started development onUnix in 1968 by writing and compiling programs on theGE-635 and carrying them over to thePDP-7 for testing. After the initial Unix kernel, acommand interpreter, an editor, an assembler, and a few utilities were completed, the Unix operating system was self-hosting – programs could be written and tested on the PDP-7 itself.[5]

Douglas McIlroy wroteTMG (acompiler-compiler) in TMG on a piece of paper and "decided to give his piece of paper to his piece of paper", doing the computation himself, thus compiling a TMG compiler intoassembly, which he typed up and assembled on Ken Thompson's PDP-7.[4]

Development of theGNU system relies largely onGCC (the GNU Compiler Collection) and GNUEmacs (a popular editor), making possible the self contained, maintained and sustained development offree software for theGNU Project.

Manyprogramming languages have self-hosted implementations: compilers that are both in and for the same language. An approach isbootstrapping, where a core version of the language is initially implemented using another high-level language, assembler, or evenmachine language; the resulting compiler is then used to start building successive expanded versions of itself.

List of languages having self-hosting compilers

[edit]

The following programming languages have self-hosting compilers:[citation needed]

See also

[edit]

References

[edit]
  1. ^Heaton, Robert."What is a self-hosting compiler?".robertheaton.com/.
  2. ^Patrick D. Terry (1997)."3. Compiler Construction and Bootstrapping".Compilers and Compiler Generators: An Introduction With C++. International Thomson Computer Press.ISBN 1-85032-298-8. Archived fromthe original on 2009-11-23.
  3. ^abHart, Tim; Levin, Mike."AI Memo 39-The new compiler"(PDF).publications.ai.mit.edu (FTP). Retrieved2008-05-23.[dead ftp link](To view documents seeHelp:FTP)
  4. ^abThompson, Ken (6 May 2019)."VCF East 2019 -- Brian Kernighan interviews Ken Thompson".YouTube. Retrieved2019-10-28.
  5. ^Dennis M. Ritchie."The Development of the C Language". 1993.
  6. ^BASICO compiler bootstrapping example
  7. ^ClojureScript Next
  8. ^"flat assembler". Retrieved7 January 2022.The flat assembler is self-hosting and the complete source code is included.
  9. ^"Haskell Communities and Activities Report".
  10. ^https://www.pyret.orgArchived 2018-04-10 at theWayback Machine
  11. ^"Implement TCL in TCL".Archived from the original on 2017-06-04. Retrieved2017-09-19.
  12. ^"V FAQ".GitHub.
  13. ^"Virgil".GitHub.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Self-hosting_(compilers)&oldid=1333192171"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp