Next: Evaluation, Previous: Type Conversions, Up: Operations [Contents][Index]
The source files continue.h and continue.c are designed to function as an independent resource for programs wishing to use continuations, but without all the rest of the SCM machinery. The concept of continuations is explained in call-with-current-continuation in Revised(5) Scheme.
The C constructs jmp_buf
, setjmp
, and longjmp
implement escape continuations. On VAX and Cray platforms, the setjmp
provided does not save all the registers. The source files
setjump.mar, setjump.s, and ugsetjump.s provide
implementations which do meet this criteria.
SCM uses the names jump_buf
, setjump
, and longjump
in lieu of jmp_buf
, setjmp
, and longjmp
to prevent
name and declaration conflicts.
is a typedef
ed structure holding all the information needed to
represent a continuation. The other slot can be used to hold any
data the user wishes to put there by defining the macro
CONTINUATION_OTHER
.
If SHORT_ALIGN
is #define
d (in scmfig.h), then the
it is assumed that pointers in the stack can be aligned on short
int
boundaries.
is a pointer to objects of the size specified by SHORT_ALIGN
being #define
d or not.
If CHEAP_CONTINUATIONS
is #define
d (in scmfig.h)
each CONTINUATION
has size sizeof CONTINUATION
.
Otherwise, all but root CONTINUATION
s have additional
storage (immediately following) to contain a copy of part of the stack.
Note On systems with nonlinear stack disciplines (multiple
stacks or non-contiguous stack frames) copying the stack will not work
properly. These systems need to #define CHEAP_CONTINUATIONS
in
scmfig.h.
Expresses which way the stack grows by its being #define
d or not.
Gets set to the value passed to throw_to_continuation
.
Returns the number of units of size STACKITEM
which fit between
start and the current top of stack. No check is done in this
routine to ensure that start is actually in the current stack
segment.
Allocates (malloc
) storage for a CONTINUATION
of the
current extent of stack. This newly allocated CONTINUATION
is
returned if successful, 0
if not. After
make_root_continuation
returns, the calling routine still needs
to setjump(new_continuation->jmpbuf)
in order to complete
the capture of this continuation.
Allocates storage for the current CONTINUATION
, copying (or
encapsulating) the stack state from parent_cont->stkbse
to
the current top of stack. The newly allocated CONTINUATION
is
returned if successful, 0
q if not. After
make_continuation
returns, the calling routine still needs to
setjump(new_continuation->jmpbuf)
in order to complete the
capture of this continuation.
Frees the storage pointed to by cont. Remember to free storage
pointed to by cont->other
.
Sets thrown_value
to value and returns from the
continuation cont.
If CHEAP_CONTINUATIONS
is #define
d, then
throw_to_continuation
does longjump(cont->jmpbuf, val)
.
If CHEAP_CONTINUATIONS
is not #define
d, the CONTINUATION
cont contains a copy of a portion of the C stack (whose bound must
be CONT(root_cont)->stkbse
). Then:
longjump(cont->jmpbuf, val)
;
Next: Evaluation, Previous: Type Conversions, Up: Operations [Contents][Index]