Hendrik Boom scripsit:

> > Applications include
> > 
> >   - First class continuations as implemented in Chez Scheme
> 
> Is there something specific I should know about Chez Scheme here?  As fat 
> as I know, first-class continuations are standard in all Schemes.

Yes, but the implementation methods differ greatly (tree of frames in
the heap, separate stack with copy-in/copy-out, Cheney on the MTA).
In Chez, the approach is to use large stack segments which can hold
many frames (each frame is of bounded size).  When a segment overflows,
a new segment is allocated and a reasonable number of frames is moved
from the top of the old segment to the bottom of the new, and the old
segment is shortened.  This is done to prevent allocation thrashing as
a result of allocating and deallocating a whole stack segment simply
because the top frame on the stack calls a sequence of procedures.

To capture a continuation, the current segment is split into two
segments constituting the used and unused portions of the segment.
The continuation object is made to point to the lower segment, and the
upper segment becomes the new current stack segment.  The lower segment
is marked to prevent it from being eagerly discarded on underflow.
Precautions are taken so that the stack is not split more than once if
only tail-recursions have been taken since the last split.

To reinstate a continuation, the captured segment is split again, and
a reasonable number of frames are moved from the top of the captured
segment to the bottom of the current segment.  (By construction, the
current segment cannot contain any captured frames, so all of its frames
are garbage when a continuation is reinstated.)

-- 
John Cowan  [email protected]  http://ccil.org/~cowan
If I have seen farther than others, it is because I was standing on
the shoulders of giants.
        --Isaac Newton
_______________________________________________
Cminusminus mailing list
[email protected]
https://cminusminus.org/mailman/listinfo/cminusminus

Reply via email to