cps/environment

Search:
Group by:
Source   Edit  

The Env(ironment) tracks continuation types and the variables of which they are comprised.

Types

CachePair = tuple[key: Name, val: VarLetIdentDef]
Source   Edit  
Env = ref object
  when cpsReparent:
Source   Edit  

Procs

proc createBootstrap(env: Env; n: ProcDef; goto: NormNode): ProcDef {.
    ...raises: [Exception], tags: [RootEffect], forbids: [].}
the bootstrap needs to create a continuation and trampoline it Source   Edit  
proc createCallbackShim(env: Env; whelp: ProcDef): ProcDef {.
    ...raises: [ValueError], tags: [], forbids: [].}
this is a version of whelp that returns the base continuation type Source   Edit  
proc createContinuation(e: Env; name: Name; goto: NimNode): NimNode {.
    ...raises: [], tags: [], forbids: [].}
allocate a continuation as name and maybe aim it at the leg goto Source   Edit  
proc createRecover(env: Env; exported = false): NimNode {....raises: [ValueError],
    tags: [], forbids: [].}

define procedures for retrieving the result of a continuation

exported determines whether these procedures will be exported

Source   Edit  
proc createWhelp(env: Env; n: ProcDef; goto: NormNode): ProcDef {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
the whelp needs to create a continuation Source   Edit  
proc first(e: Env): Name {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc firstDef(e: Env): IdentDef {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc genException(e: var Env): NimNode {....raises: [ValueError, Exception],
    tags: [RootEffect], forbids: [].}

generates a new symbol of type ref Exception, then put it in the env.

returns the access to the exception symbol from the env.

Source   Edit  
proc getResult(e: Env): NormNode {....raises: [], tags: [], forbids: [].}
retrieve a continuation's result value from the env Source   Edit  
proc identity(e: Env): Name {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc identity(e: var Env): Name {....raises: [], tags: [], forbids: [].}
identifier of our continuation type Source   Edit  
proc inherits(e: Env): Name {....raises: [], tags: [], forbids: [].}
Source   Edit  
func isDirty(e: Env): bool {....raises: [], tags: [], forbids: [].}
the type hasn't been written since an add occurred Source   Edit  
proc isEmpty(e: Env): bool {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc len(e: Env): int {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc localSection(e: var Env; n: IdentDef; into: NimNode = nil) {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
consume nnkIdentDefs and populate into with assignments, even if into is nil, the n will be cached locally Source   Edit  
proc localSection(e: var Env; n: RoutineParam; into: NimNode = nil) {.borrow,
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
consume proc definition params and yield name, node pairs representing assignments to local scope. Source   Edit  
proc localSection(e: var Env; n: VarLet; into: NimNode = nil) {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
consume a var|let section and yield name, node pairs representing assignments to local scope Source   Edit  
proc makeType(e: Env): NimNode {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc maybeConvertToRoot(e: Env; locals: NormNode): NormNode {....raises: [],
    tags: [], forbids: [].}
add an Obj(foo: bar).Other conversion if necessary Source   Edit  
proc newEnv(c: Name; store: var NormNode; via: Name; rs: NormNode;
            procedure: string): Env {....raises: [ValueError, Exception],
                                      tags: [RootEffect], forbids: [].}
the initial version of the environment; c names the first parameter of continuations, store is where we add types and procedures, via is the type from which we inherit, rs is the return type (if not nnkEmpty) of the continuation. Source   Edit  
proc newEnv(parent: Env; copy = off): Env {....raises: [ValueError, Exception],
    tags: [RootEffect], forbids: [].}
this is called as part of the recursion in the front-end, or on-demand in the back-end (with copy = on) Source   Edit  
proc newEnv(store: var NormNode; via: Name; rs: NormNode; procedure: string): Env {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
Source   Edit  
proc procedure(e: Env): string {....raises: [], tags: [], forbids: [].}
the name of the procedure undergoing transformation to cps Source   Edit  
proc rewriteResult(e: Env; n: NormNode): NormNode {....raises: [Exception],
    tags: [RootEffect], forbids: [].}
replaces result symbols with the env's result; this should be safe to run on sem'd ast (for obvious reasons) Source   Edit  
proc rewriteReturn(e: var Env; n: NormNode): NormNode {....raises: [], tags: [],
    forbids: [].}
Rewrite a return statement to use our result field. Source   Edit  
proc rewriteSymbolsIntoEnvDotField(e: var Env; n: NormNode): NormNode {.
    ...raises: [Exception], tags: [RootEffect], forbids: [].}
swap symbols for those in the continuation Source   Edit  
proc rewriteVoodoo(env: Env; n: NormNode): NormNode {....raises: [Exception],
    tags: [RootEffect], forbids: [].}
Rewrite non-yielding cpsCall calls by inserting the continuation as the first argument Source   Edit  
proc root(e: Env): Name {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc storeType(e: Env; force = off): Env {....raises: [ValueError, Exception],
    tags: [RootEffect], forbids: [].}
turn an env into a complete typedef in a type section Source   Edit