Code Monkey home page Code Monkey logo

modular-lang-proto's Introduction

Goal

The goal of this project is to prototype extensible languages in OCaml to find a good way to represent extensible ASTs which can form the base of a type safe and convenient macro system.

Step one is to experiment with OCamls variant and GADT types and module system to find the things which do not work well. Step two will be to design a language for extensible ASTs.

Languages

The following small languages will be implemented and combined:

calc-int

Arithmetic expressions with integers

calc-float

Arithmetic expressions with floats

calc

calc-int + calc-float and conversions

algo-int

Extending calc-int with conditional evaluation

algo

Extending calc with conditional evaluation, loops, and booleans

algo-generic

Extending a given language with conditional evaluation and loops

General language combination

A system to combine fragments of languages to form new ones

binding

Define values and use them, for dynamic variables and compiled w/o runtime

More complex compiler analysis

Constant folding, transformations

Parser

Parsers which can be combined easily

Source Location handling

Track source locations and use them for error reporting

Optimization framework

Should be able to combine contexts of Eval_compiled and Parser, combine several bottom/up or top/down passes into a single one

Approaches

There are two different approaches so far:

  1. Extensible ASTs using extensible tagged unions in source/ast

    This works well to make languages which can be extended. But it does not scale well to multiple levels of language layers, compare Algo with the implementation for tagless unions

  2. Functors and tagless staged interpreters in source/tagless

    This works well for multiple layers of languages which can extend each other multiple times. Also reusable language layers are very simple to do.

Building

Initial one time setup

opam switch create . ocaml-base-compiler.4.10.0 --deps-only

Build the project

dune build

Running demo app

dune exec calc-demo
dune exec algo-demo
dune exec tagless-demo

Build in Emacs

  • Open any .ml file
  • Call ‘(tuareg-opam-update-env)’
  • Run above build commands

Using Nix

This will install all dependencies into the Nix store and compile the project

nix-build

Run it by calling ./result/bin/tagless-demo

modular-lang-proto's People

Contributors

sheijk avatar

Stargazers

Richard Höchenberger avatar

Watchers

 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.