Giter Club home page Giter Club logo

toy-macro-ml's Introduction

An implementation of MacroML

This is an implementation of MacroML [1]. It consists of

  • a type checker for MacroML (which also performs the translation of MacroML programs to MetaML [2]), and
  • a naïve back-end interpreter of MetaML.

The syntax and the type system are naturally extended from the original version as to macro parameters. See the paper below [1] for detail:

  1. Steve Ganz, Amr Sabry, and Walid Taha. Macros as multi-stage computations: Type-safe, generative, binding macros in MacroML. In Proceedings of the International Conference on Functional Programming (ICFP’01), pages 74–85, 2001.
  2. Walid Taha and Tim Sheard. MetaML: Multi-stage programming with explicit annotations. In Proceedings of the Symposium on Partial Evaluation and Semantic-Based Program Manipulation (PEPM’97), pages 203–217, 1997.

How to Compile

Under the condition that make and dune are installed, invoke:

$ make

and then the executable file ./main will be created.

Usage

Just invoke:

$ ./main <source-file>

and then you can see on stdout:

Type: <type>
Result1: <code-generated-by-macro-expansion>
Result0: <result-of-running-the-code>

Syntax

an expression:
  e ::=
    | '(' e ')'
    | b                                              (a Boolean value)
    | n                                              (an integer)
    | x
    | 'fun' '(' x ':' ty ')' '->' e
    | e e
    | 'let' '(' x ':' ty ')' '=' e 'in' e
    | 'letrec' '('x ':' ty ')' '=' e 'in' e
    | 'if' e 'then' e 'else e
    | 'letmac' x '!' '(' ps ')' ':' ty '=' e 'in' e  (a macro definition)
    | x '!' '(' as ')'                               (a macro application)
    | '~' e                                          (so-called an escape)
    | '@' e                                          (so-called a bracket)

a non-empty sequence of macro parameter(s):
  ps ::= p | p ',' ps

a macro parameter:
  p ::=
    | '~' '(' x ':' ty ')'                    (an early parameter)
    | x ':' ty                                (a late parameter)
    | '(' x ':' ty ')' '->' '(' x ':' ty ')'  (a binder/bindee parameter)

a non-empty sequence of macro argument(s):
  as ::= a | a ',' as

a macro argument:
  a ::=
    | '~' e     (an early argument)
    | e         (a late argument)
    | x '->' e  (a binder/bindee argument)

a monomorphic type:
  ty ::=
    | '(' ty ')'
    | 'bool'
    | 'int'
    | ty '->' ty
    | '@' ty      (a code type)

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.