Sun Dec 22 11:04:45 CET 2019

Transforming packet processors

Small experience report for converting a blocking recursive algorithm
into a non-blocking variant.  1. Converting to explicit stack is very
straightforward, and 2. The real problem is properly handling resume

I know of two ways to do this: keep the algorithm's structure, but use
computed gotos.  I.e. sm.h

Or split it up into explicit continuation functions.

The latter leaves the code less recognizable, but probably makes for
more readable C code.

Let's go for the latter.  Make the continuations explicit.

Morale: write CPS.

EDIT: Keep the code in blocking form until all blocking calls are
lifted out into a main "next loop".

EDIT: Variable management becomes a problem when all variables are
tucked into a single struct.  It would be nice to be able to use real
lexical scope here.

EDIT: This lack of sum types is the single most annoying point in C.
Each state really should be its own type, which ultimately derives
from the lexical scope of the continuations.

I think this is then also the way to make a transformation from a high
level description into C: the flattening of all the continuation types
into a single C struct, attempting to re-use shared state.