June 01, 2005

Harnessing Evil for the power of... well, less evil

There are days I think the $WORK_PROJECT is an exercise in extended programming irony.

The parrot code my compiler generates for $WORK_LANGUAGE makes heavy use of continuations. Really heavy use of continuations, to the point where reports are taking (and discarding) three continuations per record plus another two or three per page of the output.

For a language which doesn't have functions, blocks, or lexical variables, and whose idea of sophisticated control flow is goto or gosub to bare labels.

Go figure.

Posted by Dan at June 1, 2005 11:16 AM
Comments

How is the performance with all those continuations? I haven't followed Parrot development very close, but from my, admittedly limited, understanding of continuations, it seems like creating a heap load of them could be rather heavy. Do they work out fine in practice? And what kinds of things are you using them for?

Posted by: Kurt at June 3, 2005 03:35 PM

I'm using them to skip sections. For example, the language has a report mode where you can declare any number of footnote statements or header statements. If any of them issues an end, all the rest of the statements in the section should be skipped. What I do is have the compiler take a continuation at the start of each section with the resume address be the section cleanup code, and if an end happens that continuation is invoked. We jump right to the end of the section no matter how many levels deep in subroutines we might be, which is really handy.

I'm not sure how the performance looks, since right now database access tends to dominate. Continuations are pretty cheap, though, so I don't expect there to be much cost involved.

Posted by: Dan at June 4, 2005 05:53 PM