[Nickle] continuation bug in nickle
Keith Packard
nickle@nickle.org
Sun, 20 Apr 2003 00:21:13 -0700
Around 22 o'clock on Apr 18, "Plutonium 186" wrote:
> poly p = setjmp ( &c, <> );
You were fooled by nickle's bizarre top-level semantics. Nickle compiles
each top-level statement separately and runs them each in a separate
thread. What happened in the case you've included was that the longjump
returned back to the point of the setjmp, but the code for that block
ended at the end of the statement and didn't continue on to the following
statements.
The problem is that nickle wants to execute the top level statements
independently so that interactive use is possible while you're expecting
the statements to be connected in some way, but separate compilation
prevents that from occuring naturally. Restructure the code by placing the
top-level statements inside a single statement so that they are all
compiled together:
typedef tree;
typedef struct {
int key;
poly data;
&poly left, right;
} tree;
void function search ( tree t, int i, &continuation c ) {
if ( i < t.key && ! is_void ( t.left ) )
search ( t.left, i, &c );
else if ( i > t.key && ! is_void ( t.right ) )
search ( t.right, i, &c );
else if ( i == t.key ) {
printf ( "key found\n" );
longjmp ( c, t.data );
assert(false, "longjmp failed\n" );
}
}
tree t = { key = 2, data = "blah", left = reference ( <> ), right =
reference ( <> ) };
{
continuation c;
int i = 0;
poly p = setjmp ( &c, <> );
++i;
printf ( "I have been here %d times.\n", i );
if ( is_void ( p ) )
search ( t, 2, &c );
else
printf ( "value = %g\n", p );
}