Procs
proc alloc[T: Continuation](U: typedesc[T]; E: typedesc): E:type {.used, inline.}
- Reimplement this symbol to customize continuation allocation; U is the type supplied by the user as the cps macro argument, while E is the type of the environment composed for the specific continuation. Source Edit
proc dealloc[T: Continuation](c: sink T; E: typedesc[T]): E:type {.used, inline.}
- Reimplement this symbol to customize continuation deallocation; c is the continuation to be deallocated, while E is the type of its environment. This procedure should generally return nil, as its result may be assigned to another continuation reference. Source Edit
proc disarm[T: Continuation](c: T) {.used, inline.}
- Reimplement this symbol to customize preparation of a continuation for deallocation. Source Edit
proc state(c: Continuation): State {.inline, ...raises: [], tags: [], forbids: [].}
- Get the current state of a continuation Source Edit
proc tail[T: Continuation](parent: Continuation; child: T): T {.used, inline.}
-
Reimplement this symbol to configure a continuation for use when it has been instantiated from inside another continuation; currently, this means assigning the parent to the child's mom field. The return value specifies the child continuation.
NOTE: If you implement this as a template, be careful that you assign the child to a variable before manipulating its fields, as it may be an expression...
Source Edit proc traceDeque(hook: Hook; c, n: NimNode; fun: string; info: LineInfo; body: NimNode): NimNode {.used, ...raises: [], tags: [], forbids: [].}
- This is the default tracing implementation which can be reused when implementing your own trace macros. Source Edit
Macros
macro stack[T: Continuation](frame: TraceFrame; target: T): T {.used.}
- Reimplement this symbol to alter the recording of "stack" frames. The return value evaluates to the continuation. Source Edit
macro trace(hook: static[Hook]; source, target: typed; fun: string; info: LineInfo; body: typed): untyped {.used.}
- Reimplement this symbol to introduce control-flow tracing of each hook and entry to each continuation leg. The fun argument holds a simple stringification of the target that emitted the trace, while target holds the symbol itself. Source Edit
macro whelp(call: typed): untyped
-
Instantiate the given continuation call but do not begin running it; instead, return the continuation as a value.
If you pass whelp a continuation procedure symbol instead, the result is a Callback which you can use to create many individual continuations or recover the result of an extant continuation.
Source Edit macro whelp(parent: Continuation; call: typed): untyped
- As in whelp(call(...)), but also links the new continuation to the supplied parent for the purposes of exception handling and similar. Source Edit
Templates
template boot[T: Continuation](c: T): T {.used.}
- Reimplement this symbol to refine a continuation after it has been allocated but before it is first run. The return value specifies the continuation. Source Edit
template coop[T: Continuation](c: T): T {.used.}
- Reimplement this symbol as a .cpsMagic. to introduce a cooperative yield at appropriate continuation exit points. The return value specifies the continuation. Source Edit
template dismissed(c: Continuation): bool
- true if the continuation was dimissed. Source Edit
template finished(c: Continuation): bool
- true if the continuation is finished. Source Edit
template head[T: Continuation](first: T): T {.used.}
- Reimplement this symbol to configure a continuation for use when there is no parent continuation available. The return value specifies the continuation. Source Edit
template recover(c: Continuation): untyped {.used.}
- Returns the result, i.e. the return value, of a continuation. Source Edit
template running(c: Continuation): bool
- true if the continuation is running. Source Edit