Mon Aug 3 14:36:10 CEST 2009
Task-based C interface
Here's the basic idea I'm trying out for writing reusable C primitives
for different kinds of scripting languages (operating systems, in
essence Scheme and PF, a linear concatenative language).
C code shouldn't CONS.
C code should only communicate with the outside world using _channels_
which have a limited number of primitive types, but do not allow for
All aggregate data types should be transferred using _protocols_ :
explicit sequencing of primitive types to represent data structure.
Doing it this way makes it possible to write C code that doesn't
perform any memory management, except for allocation of local
variables. This makes automatic wrapping very simple, and allows a
single abstract object: the task (zipper). Moreover: the code itself
can be incorporated in a static scheduling policy (whole program
optimization: compile time weaving).
This technique is essentialy premature deforestation: eliminating
intermediate data structures using compile-time transformation. The
slogan is something like this:
Replace data structures with protocols.
From the outside, it doesn't matter that C code is stateful, as long
as _all_ the state is contained in the continuation. The essential
insight is that all memory and control management can be abstracted.
Funny how I got here. I've rediscovered concurrency-oriented
programming by looking for the simplest way to interface C code with