Staapl

TL;DR

Staapl is a programming language designed for low-memory PIC18 microcontrollers aimed at writing maintainable programs with severe RAM and Flash/ROM constraints. It goes where C can't go, and where assembler would be too complicated. It is both wicked cool and a bit weird.

About

Staapl is a collection of tools for resource constrained / deeply embedded programming. It has a strong emphasis on code generation techniques (macros, partial evaluation, metaprogramming, staging, ...). Staapl is an extension of the Racket programming language. The aim is to provide a general framework to experiment with point-free (algebraic) domain specific languages, but currently the focus is on stack languages.

Stack languages are an important class of point-free languages. Staapl contains a general-purpose low level language based on Forth. It currently has an optimizing compiler for the Microchip PIC18 architecture, and a tethering mechanism with interactive console for running-target code updates.

Unlike traditional Forth which is highly reflective, Staapl is built using macros with phase separation. Most of Staapl is organized around a convenient abstract syntax based on a typical concatenative combinator language like Joy. This syntax can then be used as a base for different interpretations or as a target for concrete syntax frontends.

Point-free languages are easily manipulated on the meta-level which makes them an ideal code generation target. 1. Such languages have no variables that complicate code generation due to scope issues (hygiene). 2. Thanks to the associativity of the operations of concatenation (syntactically) and function composition (semantically), computations are trivially partitioned in compile time and run time. 3. Reliance on combinators for program structure (as opposed to explicit recursion and loops) allows for the derivation of program transformation laws that can be used for program derivation or compilation to efficient implementations.

Status

The phase I goal - to build a practical, well-factored, easily extensible base system - is completed and put in maintenance mode. It will serve as the basis for phase II: further experiments with point-free domain specific languages for DSP/control, static verification, and more elaborate compilation techniques to implement them.

Staapl contains a preliminary port for the 12 and 14 bit PIC cores, and I've been looking into porting staapl to PIC24/30/33 (dsPIC). Other architectures will be implemented when needed. Currently a a C code generator and analyser is in the works. Prospected are an LLVM generator and a TI C64x linear assembly backend.

Documentation

Documentation is loosely split into two parts: one that documents the whole system from a Scheme p.o.v. and one that exposes only the low-level Forth language view.

Since this is a developer-oriented project with a lot of effort put into clean organization, I suggest looking at the source code to pierce through the top-layer of workflow glue. Staapl is structured as a library with multiple entry points, not a monolithic application. I encourage you to build your own workflow on top of it, and integrate it with other tools. (And share that code!).

Projects

I am currently looking for projects that apply Staapl to practical problems in the embedded DSP/control field. Read this as: I would like to raise the abstraction layer for your embedded application by building a code generator for your specific ASM or C target. I am particularly interested in integration with existing development systems. Additionally, I am looking for projects that allow the development of backends for different machine architectures, and tune the backend API to make this process as simple as possible. For more information please contact me directly.

The PIC18 Forth language has been used in:

Download

Staapl is part of PLaneT. To install the command line Forth compiler frontend, install PLT Scheme 4.1 or newer (only MzScheme is required) and type this with administrator privileges:

  mzscheme -p zwizwa/staapl/install
This will install the staaplc wrapper application alongside mzscheme. All Scheme modules are accessible using standard PLaneT paths.

For the latest changes track the darcs archive (hashed darcs-2 format). If you need a snapshot that doesn't depend on darcs, just ask. The Staapl source code, including that of its subprojects, is released to the public under the terms of the GPL v2. Staapl is written by Tom Schouten.

Wed Nov  9 10:57:07 EST 2011