Tue Aug 6 19:56:00 EDT 2013
Suspend / Resume syntax translation
Essentially, a yield point in a piece of code needs to:
- capture all variables visible at exit
- re-instate them at re-entry
Instead of re-instating variables (C implementation), it seems simpler
to just replace variables with object references.
However, the C optimizer can eliminate re-instantiation of variables
that are not used.
Still, re-using storage space is not something that happens this way.
How to go about that? It requires some form of register-allocation
algorithm on the variables visible from different states.
The trade-off is that copying is wasteful, but indirect accesses are
more expensive. Keeping all state in an indirect object makes task
switching very fast, and maybe that is what we should optimize for
when aiming at a design that can support high task count.
A dumb direct approach is to prefix all variables with level names
that unambiguously encode the position of the variable in a scope
nesting. E.g. l_1_2_<name> is the variable <name> in the second level
2 block nested in the first level 1 block.
An additional optimization step could use this encoding to perform
sharing, i.e. l_1_<x> and l_2<x> can be shared, since they are never
visible at the same time.
In a first iteration, we could stick to a single function body,
i.e. no nesting. Later, nesting can be implemented using inlining.
Is this all there is?
- Functionality: flatten variable scope into a structure, using block
coordinate name prefixing.
- Leave "temp" variables on the stack, i.e. those that do not cross
a yield point.
- Share storage space between mutually exclusive block scopes.