Code Monkey home page Code Monkey logo

purelang's Introduction

PureLang

A rust implementation of Dr. William Bowman's book on compiler construction. The book can be found here.

Structure

Please observe the following directory structure for the compiler:

/src
|-- /imperative_abstractions
|-- /register_allocation
|-- /structured_control_flow
|-- /x64

Each phase exposes a compile: Source -> Target function. This function, as the type suggests, compiles the program through its stack. Each phase is responsible for a different 'meta' purpose; i.e., the register_allocator phase is responsible for assigning registers to abstract locations, etc.

Each directory inside of each phase corresponds to a language (as well as the corresponding method to compile it to the next language in the stack). Generally, this looks like the below:

mod phase1 {
    mod language1 {
        use crate::phase1::language2 as target;

        pub struct Language1(..);

        impl Language1 {
            fn pass1(self) -> target::Language2 {
                // ...
            }
        }
    }

    mod language2 {
        use crate::phase2::language3 as target;

        pub struct Language2(..);

        impl Language2 {
            fn pass2(self) -> target::Language3 {
                // ...
            }
        }
    }

    pub type Source = language1::Language1;

    pub type Target = crate::phase2::Source;

    pub fn compile(p: Source) -> Target {
        p
            .pass1()
            .pass2()
    }
}

Notice the compile: Source -> Target function in phase1.

purelang's People

Contributors

raunakab avatar

Watchers

James Cloos 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.