Which produces
github.com/zwizwa/uc_tool
Conversation
Anything that crosses an SM_READ macro (the blocking call) is stored in a C struct. The rest goes on the C stack. This is ANF with constants bound to variables as well, to make implementation simpler. C compiler can take care of optimizing those away.
1
The yield/block points are (later) implemented on top of this protothread code. See e.g. SM_WAIT
1
Started adding support for CSP rendezvous (csp.h in uc_tools, written in hard-to-use C macros).
Added support for zero-copy mode. Eventually this needs to be fast (for the app: 137k int/sec on 72MHz CM3). Might need to specialize the scheduler further.
1
BTW doing this in Lua isn't all that bad. Of course refactoring is hard, but doable at this 1kloc complexity level.
However manual let-insertion is annoying. Older Haskell code used a state-continuation monad for that, which is really convenient. Almost magic.
2
End of winter break. Experiment succeeded. Anything more complex needs better abstraction. Feeling a Racket itch coming up...
1
C output doesn't look too bad. Compiles to invocation of csp.h macros for event setup (CSP_EVT_BUF), blocking select call (CSP_SEL) and case statement for dispatch.
1
From select form in
github.com/zwizwa/uc_tool
2
Going to have to specialize the CSP scheduler as well to make this fast. A bit more than a weekend project, but hey I'm learning things.
3
Of course, while procrastinating, had to do the Scheme interpreter in Lua thing as well:
github.com/zwizwa/uc_tool
1
1
And preliminary compiler from Scheme subset to Lua github.com/zwizwa/uc_tool
We're using luajit so this might even be useful. Direct mapping, no tail calls.
