Tue Jan 7 18:51:19 CET 2020


Some reflections after working with sm.h.

I do not want nested polling as is used in sm.h's CALL mechanism.  A
state machine should be compiled to:

  - one function per continuation

  - single flat function with switch() or computed goto

The latter two are essentially the same.  The former is also
essentially the same if there is no need for shared context that could
be implemented in the body of the function.

Let's assume individual functions.

It's probably beneficial to use ANF, i.e. to have explicit stack
frames.  Stack frames map directly to nested unions.


The "root" union is the collection of resume points in the main
function.  Suppose 3 resume points A,B,C this then maps to the
following nesting.  Suppose each of these has 2,1,3 resume points

union k {
   union {
      struct { ... } frameAA;
      struct { ... } frameAB;
   } frameA;
   union {
      struct { ... } frameBA;
   } frameB;
   union {
      struct { ... } frameCA;
      struct { ... } frameCB;
      struct { ... } frameCC;
   } frameC;

Something like that.  Should tail recursion be supported?  Probably
not.  Loops are likely simpler to work with.  This will be a language
that supports macros, so much can be built on top.

To make this more understandable, create some example programs and
print stack frames at suspension points.  Basically abstract
interpretation will need to be used to enumerate all the suspension
points.  Only programs that have a finite number of suspension points
will be representable.