Developing TameScheme

These pages will provide details on developing extensions to TameScheme: adding new functions or syntax with .NET and general scheme hacking. Readers of this section should also consult the 'Embedding' section, which describes how TameScheme and .NET usually talk to each other.

This section will develop into a series of pages eventually, describing the inner workings of TameScheme.

BExpressions

The BExpression class represents a 'compiled' BExpression, containing operations in an intermediate language detailing how the expression should be executed. Presently, BExpressions must be compiled in this way: it's not possible to execute a scheme expression directly.

BExpressions are built using 'BuildExpression' static method: this has two jobs: the compilation of 'simple' forms (such as symbols, function calls, etc), and the recognition of syntax. Syntax forms build their own BExpressions. lambda, for example, just creates an BExpression that pushes the object representing the function onto the stack. if creates a more complicated expression that performs a comparison.

Syntax elements are expected to be in the Environment specified as a parameter to the BuildExpression function. These are SchemeSyntax objects: this class links together a Syntax object (describing the syntax patterns to match) and an object implementing the ISyntax interface (describing the BExpression to build for the specified syntax). ISyntax objects take a matched syntax string and produce a BExpression that must leave a single object on the stack.

Take the 'if' syntax, for example. This is defined with a SyntaxElement representing the syntax ((cond then) (cond then else)), and the If ISyntax class. The If class produces an BExpression that evaluates the BExpression, then eveluates the then or else portions of the expression depending on the result.

Operations

Each BExpression consists of a list of operations. These are in effect 'one-address' code. They consist of an operation from the Op enumeration, a parameter and a canBeTail flag. The canBeTail flag represents if the operation is at the 'tail' of an expression, and is used when changing an BExpression to its tail context equivalent.

SContinuations

The SContinuation class has the job of evaluating BExpressions. Normally, these are created automatically by the Interpreter, but there may be circumstances where you need to create these manually.

SContinuations represent the scheme notion of a continuation. They contain the state of the interpreter at a given point in an evaluation, and so can be cloned and stored.

The IContinuation is provided to allow alternative means of implementing scheme expressions to be implemented. Eventual developments of this might be a CContinuation class: 'compiled' continuation, or a continuation in a .NET context. A continuation class that deals with scheme expressions directly rather than in a semi-compiled form is also a possibility (this would allow for 'recoverable' errors as found in many scheme systems. However, some earlier experimentation with this was producing a very slow interpreter).