Giter VIP home page Giter VIP logo

monkey's Introduction

The Monkey Compiler

The Monkey Compiler is a small open sourced compiling system. The goal of this project is to assist understanding the phases in compiling functional programming languages. You can explore the compiling procedures and intermediate representations by specifying and examining the output. In particular, the Monkey Compiler provides two parallel methods to eliminate higher-order functions, which may reveal some aspects to improve the efficiency of the target program and facilitate further study.

###Source Language

The source language of Monkey Compiler is basically a subset of Standard ML. Chapter 1 (CPS Conversion) of the document describes the abstract syntax of the source language (basically the same with the concrete syntax). Chapter 0 (Front End) also provides some details about source language syntax.

###Structure

The figure below descirbes the basic structure of the compiler.

###How to use

You may compile the source code to some certain platform using tool such as MLton or SML/NJ. The Monkey Compiler cannot compile itself for now.

Once you have the executive version of the Monkey Compiler, you may run it with command (given that the compiler's executive file is named "monkey", and it can be found in Path):

monkey [option ...] filename

Then the corresponding .c file will be generated. (Currently it needs to be compiled together with runtime.c and runtime.h by some C compiler to obtain an executive. As an alternative, we can encode the garbage collection code into the generated .c file. I guess this is one of the reasons why choosing Java bytecode as the target language will be a good idea.)

###Options

The following options are supported:

  • -defunc

    Use the defunctionalization strategy for higher-order function elimination. This is the default setting.

  • -closure

    Use closure conversion strategy for higher-order function elimination.

  • -all

    Output the codes of all the intermediate representations. Note that the output for CPS representaion, closure passing representaion and defunctionalized representaion (all ends with ".sml") cannot be compiled and run, for SML compilers cannot infer the type information.

  • -t

    The executive file you generated will print its run time to the console.

Multiple options can be selected.




monkey's People

Contributors

zhaohouhou avatar

Stargazers

Eason Wang avatar

Watchers

James Cloos avatar  avatar

Forkers

e1iu

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.