[intro www tom@zwizwa.be**20090513180138 Ignore-this: fb202a7260a5e77816c9657e72675481 ] hunk ./doc/staapl-ramblings.txt 46927 + +Entry: full lazyness +Date: Wed May 13 11:06:48 CEST 2009 + +On page 55 of [1] "full lazyness" is defined as giving each term +minimal scope. Then it is remarked that: + + It is possible to achieve full laziness in a lazy language by + transforming the syntactic representation of functions so that the + scope of every function is minimal. + + + +[1] http://thyer.name/phd-thesis/ + + +Entry: next: documentation update +Date: Wed May 13 11:51:13 CEST 2009 + + * website: this needs to be simplified a bit. + * scribble docs: they are probably broken. + * papers: less important but best moved to scribble + +The emphasis should be on the following: + + * it works: + - you can compile .f -> .hex / .dict + - you can interact with target using .dict + + * it's simple: bottom-up macro system using PLT's module system. + +Then there should be examples examples and examples. + + +Entry: pe reordering +Date: Wed May 13 16:34:50 CEST 2009 + +With eager evaluation (not evaluating under lambda) the trick is to +make sure that reducable expressions are exposed in the right order. + +How to do this in Coma? + + hunk ./www/index.html 12 - Staapl is a collection of abstractions for metaprogramming - microcontrollers for the PLT - Scheme family of programming languages. + Staapl is a collection of tools for programming microcontrollers + using techniques based on + the Forth + and Scheme + programming languages. While Staapl can be used as a Forth + compiler, the main focus of the project is on providing + metaprogramming + abstractions in the Scheme language, to build special-purpose code + generators as an extension of a low-level Forth-like language. hunk ./www/index.html 22 - At its core is a functional - - concatenative macro language Coma, extended with quasiquotation to - provide Scheme to Coma template programming. +

Staapl is piggy-backed on + the PLT Scheme family of + programming languages. Self-contained Staapl programs are + implemented as PLT modules. Unlike traditional Forth which is + highly reflective, Staapl is built + using macros + with phase separation. This makes it fit better in a functional + programming framework. hunk ./www/index.html 31 -

Staapl uses a simple 2-stack virtual machine model to abstract - low-end microcontroller architectures. Primitives for the Coma - language are stack machine code transformers, implemented in Scheme - using a pattern matching mechanism. The use of partial evaluation - rules in the definition of primitives allows the elimination of - unnecessary run-time computation and interpretation. - -

On top of these two mechanisms Staapl includes a +

Next to the language building toolbox, Staapl includes a hunk ./www/index.html 39 -

-Summarized, Staapl builds on: -

hunk ./www/index.html 41 +

Basic Elements

+ +

+ Metaprogramming is about manipulating programs as data. A key + element here is the representation of programs. Being a compiler, + Staapl has two languages to deal with: a high-level input language + and a low-level output language. Both languages are + concatenative. +

+ +

A meaning can be attached to high-level concatenative source + code using the following compilation algorithm: +

    +
  1. Start with the empty output program []. +
  2. Read the next token from the input program source, and + associate it with an [op]->[op] transformer. +
  3. Apply this function to the accumulated output program. +
  4. If there are input tokens left continue with step 2. +
+ From this one could infer that each [op]->[op] + function appends a small machine code fragment to the code + accumulator, essentially behaving as + an assembler + macro. However, the function is free to modify the accumulated code in + its entirety, performing any optimization it sees fit. + +

Using this representation building code generators can be +split in these parts +

+ +

Macro Forth

+ +

By interpreting the code list [op] as a stack it is + possible to extend a pure macro language implementing Forth with + partial evaluation. A pure macro language is built + using [op]->[op] transformers that only append code. + +

I.e. the function associated to the token word + would + normally only compile machine code that pops 2 numbers of the + run-time + parameter + stack, adds them and pushes the result. Instead it could be + made to inspect the code it is passed for any instructions that load + literal values on the runtime stack, remove those, perform the + addition at compile time, and generate code for a constant instead. + To make this work well, the op instructions contain a + pseudo instruction [qw .] which represents the + loading of a literal value on the runtime stack.