Sigma: An Interpreted Extension Language for C++


What It Is

Components

Download

Documentation

To Do

Licensing

Reading List

Acknowledgements


What It Is:

Sigma is a small, interpreted, functional programming language implemented in C++ as a set of modular library components. It was designed with the intention of making it easy to embed in an application so as to serve as an extension language. The purpose of an extension langauge is to provide the benefits of an interactive programming language to an application written in a non-interactive programming language.

In addition, the libraries from which Sigma is assembled were intended as much as possible to be useful independent of their use in Sigma. And in fact nearly all of them are used in other projects.

Greenspun's Tenth Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp." Sigma is an attempt to make that inevitably-embedded lisp implementation a little less ad-hoc, and a little less bug-ridden.

Components:

A smart pointer implementation with the following features:

Function objects supporting dynamic multimethod dispatching (a.k.a. generic functions). The programmer can specify collections of functions (methods) distinguished only by the types and number of arguments. These collections can be treated as a single function which can be evoked with a list of untyped smart pointers. The appropriate method (if one exists) is selected and executed at run time.

A lexer generator. The lexer generator is dynamic in the sense that a lexer object is created at run-time out of a programatically-specified collection of regular expressions. There is no intervening compilation step.

An SLR parser generator. The parser generator is also dynamic in the sense that a parser object is created at run-time from a programatically-specified collection of production rules.

Support for arbitrary-precision integer and rational arithmetic.

Download:

The source has been successfully compiled using gcc 2.96 on RedHat Linux 7.3 and gcc 3.1 on MacOS 10.2. Sigma itself hasn't been compiled for Windows, but most of the components that make up Sigma have been compiled in other projects using Microsoft Visual C++ .NET 2003. (The unconventional makefile was inspired by Peter Miller's brilliant paper Recursive Make Considered Harmful.)

http://www.standarddeviance.com/sigma_0.6/sigma_0.6.tar.gz

Documentation:

I regret there is as yet no documentation beyond a very sparse tutorial of the interpreter.

To Do:

Sigma's value as an extension language is obviously sabotaged by the lack of documentation describing how to use it as an extension language. This is Sigma's most glaring weakness at this point.

The intention was that the usefulness of Sigma lie not in what specific data structures it supports or what libraries it offers, but in the ease with which it can be modified and extended to support application-specific tasks. Having said that, a richer set of built-in data types and functions would go a long way toward making the language more useful out of the box.

Licensing:

Free as in beer. This is an art project. I hope this code proves useful to others in whole or in parts, and I welcome feedback, but I promise no support of any kind, and I make no guarantees about its usefulness for any purpose.

Reading List:

The Structure and Interpretation of Computer Programs, by Harold Abelson and Gerald Jay Sussman with Julie Sussman (The best book on computer programming ever written.)

Lisp in Small Pieces, by Christian Queinnec, Translated by Kathleen Callaway

Modern C++ Design, by Andrei Alexandrescu (Sigma doesn't use anything specific from this book, but Sigma leverages C++ templates heavily, and this book is a good place to learn about the kind of things that can be done with templates.)

Compilers: Principles, Techniques, and Tools, Alfred V. Aho, Ravi Sethi, Jeffrey D Ulman (The Sigma lexer generator was based on the description in section 3.9 of this book.)

Modern Compiler Implementation in ML, by Andrew W. Appel (The Sigma SLR parser generator is based on the description of the technique given in this book.)

Adding Generic Functions to Scheme, Thant Tessman, SIGPLAN Notices, Volume 30, Number 5, May 1995. This describes a Scheme implementation of multimethod dispatching. A version of the code described in the paper that works for Petite Chez Scheme can be found here. At the time I failed to give proper reference to Meroon and Oaklisp. Also, Oscar Waddell made suggestions that greatly improved the paper's readability.

Acknowledgements:

The motivation for Sigma was my experiences using Scheme as an extension language. Chez Scheme served beautifly as an extension language for a virtual reality engine I co-implemented while working at Walt Disney Imagineering. I've also used Oliver Laumann's ELK on other smaller projects. Sigma is an attempt to do something similar to ELK, but in a way that leverages the strengths of C++ and avoids platform-specific magic. Sigma is less ambitious than ELK, but my hope is that it also has a lower barrier to entry.

Sigma's design borrows ideas from the programming langauges Scheme, SML, and Dylan.

Hyman Rosen suggested the test used to determine whether a smart pointer was contained in a given object. It was the practicality of this test that made me realize that a mark-and-sweep garbage-collecting smart pointer was possible to implement using 'straight' C++. William Kemph suggested the technique that allows this implementation of smart pointers to handle multiple inheritance correctly. He has his own implementation of smart pointers inspired by an earlier version of the implementation used in Sigma.


Last updated November 5, 2005