Giter Club home page Giter Club logo

klister's Introduction

Klister

This repository contains a partial implementation of a macro expander in which macros can get stuck. The idea is that if a macro depends on information that will be the result of later macro expansion or type checking, it can pause its execution until that information has become available.

For a description of one way in which stuck macros might be useful, please see this talk.

Installation

Klister is written in Haskell, and is built with HPack and Cabal. You can build it like so:

hpack package.yaml
cabal v2-build

You can use v2-install instead of v2-build to install the Klister executable and associated files to your home directory.

Usage

Run klister repl to be dropped into a read-eval-print loop where you can try out writing some Klister expressions.

klister run file.kl will evaluate the contents of file.kl.

Imports

The import form will search for modules in the same directory as the importing module, and in directories listed in the KLISTERPATH environment variable, a :-separated list of directories.

Overall Design

The macro expander itself is a set-of-scopes expander, based on Matthew Flatt's paper from POPL 2016 and described quite accessibly in his talk from Strange Loop.

Additionally, there is a module system patterned after Racket's.

This macro expander has a few differences:

  • Rather than performing a depth-first traversal of the input syntax, expanding as it goes, our expander maintains a queue of expansion tasks. Tasks indicate the expression to be expanded as well as its resulting location in the final output. Dependency information is tracked in order to constrain the scheduling of expansion tasks.
  • The core language does not coincide with the input language. Having an independent core language will hopefully allow us to overcome the overhead associated with recursive uses of local-expand, as well as enabling a second, trusted type checking pass.
  • Type checking and macro expansion are interleaved. Every expansion step in an expression or pattern context knows what type the resulting program will have.

The type checker is a mostly-vanilla Hindley-Milner, based on Sestoft's description in Programming Language Concepts, extended with user-definable datatypes and Racket-style phase stratification of bindings. It uses Rémy's optimization of generalization, where type metavariables are assigned levels to avoid scanning the context at generalization time.

Initially, macros can get stuck by blocking until a signal has been sent. Signals are essentially just integers. Other macros can send signals, at which point the blocked macros get un-stuck. This is reminiscent of the blockOnMeta operation in Agda's reflection system. Eventually, we plan to replace this with the ability to block on the solution to a type unification variable.

FAQ

Why "Klister"?

"Klister" is Danish for "adhesive", and is also used to form words describing sticky things. And our macros get stuck.

klister's People

Contributors

david-christiansen avatar gelisam avatar langston-barrett avatar xplat 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.