libccf - Closures and Control Flow
libccg - garbage Collected C Generics
libccx - garbage Collected C eXpressions


The Closure and Control Flow Library (libccf)
=============================================

The libccf is a low-level C library which

  1. defines an efficient way to encapsulate closures.

  2. allows a C program to create continuations which can be called
     even after the stack frame of the continuation is unwound.

  3. provides low-level exception mechanism and nondeterministic
     control flow (backtracking).

libccf requires a garbage collector, except if only the closures are
needed.  It is presently written to use the Boehm-Demers-Weiser
conservative garbage collector.  A garbage collector is not strictly
needed to implement the library, but it is expected that client code
will need to use garbage colletion (see below), and thus, memory
returned by libccf should be collected, as well.

Client code which only uses the closures, and does not need garbage
collection may call 'chi_closure_alloc_nogc', 'chi_closure_fn_nogc'
and 'chi_closure_free_nogc'.


Why Garbage Collection?
-----------------------

In client code which uses the continuation and backtracking
functionality, functions may exit more than once.  Therefore, it
becomes difficult to follow the usual allocate-free scheme for
resoures.  Extensive use of dynamic winding could solve the problem,
but this is inefficient.  Since most of the allocate-free pairs
handles memory, the author believes the most efficient and easy
solution is to use garbage collection for memory and a combination of
dynamic winding and object finalizers for other resources.


Portability
-----------

Since libccf manipulates the stack, it may have to be handwired for
specific platforms.  A library which assumes an underlying stack model
is not guaranteed to be portable to any architecture.  Notice,
however, a conservative garbage collector also typically depends on
this assumtion, and without it, using non-trivial control flow may be
infeasible, anyway.

The supplied test programs have been tested to work on

    Linux 2.4.16 i686, gcc-3.0.3
    Alpha OSF1 V4.0 878, gcc-2.97
