Latest updates

Posted: May 11th, 2011 | Author: Mars | Filed under: Uncategorized | 2 Comments »

The foreign-function interface can just about do something useful now. You can load a function pointer from some external library, explain how you’d like to marshal values, then invoke it as an IO action. The value it returns will be marshalled back, according to your previous specification, into some kind of Radian object.

I’ve been sort of picking gently at the remaining bugs in the system while I think about a better syntax for doing asynchronous I/O. All Radian I/O operations are asynchronous, by nature, since the only way to execute an IO action is to yield it back to the system. Thus you must construct I/O activity as a callback-driven state machine.

This is actually the way I learned to do I/O back in the ’80s, on the non-preemptive classic Mac OS, and I’ve used similar techniques in microcontroller code. Nostalgic as the style may be, however, Radian’s lack of shared mutable state makes doing actual work this way something of a mind-bender.

There’s no getting around the fact that IO is asynchronous and callback-driven, but the pattern for writing sequential IO code in such an environment is predictable, and it should be possible to build in some support that makes the process less tedious. I’d like to introduce an async statement, or an async operator, which does all the relevant housekeeping work. It would split the current function apart: anything downstream of the returned value would be captured and passed in as an implicit callback function, which would carry on with the results of the process whenever the initial IO action had completed.

It has been difficult to wrap my head around this semantic transformation, but I think I’ve come up with a way to do it. Along the way I accidentally found a way to implement C-style continue, break, and return statements, and worked out most of what I would need to do in order to introduce Python-style generator functions (yield, or in C# yield return), so it’s been some productive thinking-time even if I haven’t written much code.

It always feels like there is a lot of work piled up ahead of me, but I’ve been keeping a to-do list, and after the async system is done, the only significant task left before “first public beta” is the garbage collector. At that point I plan to spend some time polishing things up, writing documentation, and preparing an installer package.


2 Comments on “Latest updates”

  1. 1 Guyren G Howe said at 20:54 on May 11th, 2011:

    “split the current function apart: anything downstream…” == continuation

    Surely.

    Which is to say, it’s a well-studied and kinda solved problem.

  2. 2 Mars Saxman said at 07:56 on May 12th, 2011:

    Yes, exactly – I’ve been figuring out how to implement a continuation scheme. Radian’s semantic model has a nebulous notion of time and no representation of control flow, so it took me a while to re-think my understanding of continuations in a way I could imagine implementing here.

    I’m sure that many people have worked on this problem, but I have no idea who they might be or where I might find anything they’d written. In any case, I’ve had little or no sucess extracting meaningful information from the CS papers I’ve encountered recently.