Git Product home page Git Product logo

compiler's Introduction

Bootstrapping GCC from combinatory logic

Build Status

The stage0, mes-m2 and mescc-tools projects combined would make it possible to compile GCC starting from a minimal trusted binary less than 1 KB in size. This project represents a promising alternative approach based on Ben Lynn's compiler for a subset of Haskell. The entire process starts with a single C file which reads ION assembly, then a few trusted compilers (which could be compiled manually by a motivated person), until the first self-hosting version is reached.

Then a successive chain of compilers ends with a dialect of Haskell 98. We can take advantage of this to complete the bootstrapping to GCC. The goals in mind are to complete the bootstrap in as little effort as possible, while still maintaining correctness and readability.

Proposed bootstrapping paths

From a Scheme interpreter in Haskell

Since Ben Lynn's compiler already bootstraps a large subset of Haskell (layout parsing, monadic I/O, typeclasses, etc.), it would not be difficult to write a Scheme interpreter (see r5rs-denot for a semantics-conforming R5RS interpreter). This Scheme interpreter would accept Scheme code from stdin and interpret it.

Advantages

  • Heavy work of implementing many of Haskell's features has been done already.
  • Can use GHC to aid development of the interpreter (Ben Lynn's Haskell dialect with a short preamble can be read by GHC), especially with testing, type checking and linting.
  • Easier verification of interpreter since written in standard Haskell and should be based on denotational semantics.

Disadvantages

  • Bootstrapping is slower, more resource intensive intermediate phases, compared to an alternative approach below.
  • Fully understanding and verifying all the passes requires knowledge of parser combinators, type inference, semantic bracket abstraction, among others.

From a Scheme compiler in Haskell

See this folder for the technical details of the intermediate languages.

Advantages

  • More precise bootstrapping path, i.e. implementing type inference, parsing fixity declarations are not needed.
  • Scheme compiler could be more efficient than interpretation.

Disadvantages

  • More work to do, and since the intermediate languages are custom and typeless we cannot really reuse existing tooling elsewhere to aid us.
  • Requires to compile a call-by-value language into one that is call-by-name, probably via CPS conversion, effect on time and space usage unknown.

Resources

It is recommended to have good knowledge of functional languages, their theory and implementation. For more specialized topics the relevant resources are shown below.

Parsing

Type system

Compilation

  • Scott encoding
    • Turns out compiling algebraic data types and pattern matching isn't hard at all, if you know how to rewrite it to lambda calculus. Scott encoding is one such method.
  • Lambda to SKI, Semantically
    • Without the results from this paper, compiling to combinators would be far more inefficient. The paper uses a semantic translation rather than the usual syntactic translation, thus making compositionality and correctness-preservation more self-evident.

compiler's People

Contributors

blynn avatar oriansj avatar pder avatar siraben avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.