Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.

src/cleanup.x

What a cleanup region runs, and which exits run it.

Functions

FunctionSummary
Compiler.mark_cleanup_regionsNames each cleanup region, records the statements that leave it, and runs them on every exit that leaves it.
Compiler.static_value_is_runtimeReports whether the static local initializer value has to run at runtime, because it reads an automatic object or another static this function initializes.

Compiler

Compiler.mark_cleanup_regions

List Compiler.mark_cleanup_regions(Compiler c, List ast)

Names each cleanup region, records the statements that leave it, and runs them on every exit that leaves it. ast must be a transformed top-level unit whose defer and try forms are final; the pass rewrites transfers, so it runs once, after the transform driver reaches its fixed point.

Source: src/cleanup.x:757

Compiler.static_value_is_runtime

int Compiler.static_value_is_runtime(Compiler c, List value, Map runtime)

Reports whether the static local initializer value has to run at runtime, because it reads an automatic object or another static this function initializes. runtime holds the statics already known to run that way, and gains this one’s bindings.

Source: src/cleanup.x:269

Design notes

defer and try regions reach this pass as the forms transform.x produced. It names each region’s runtime record, builds the statements that leave the region, and runs them on every exit that leaves it: the region’s own end, a return, a break or continue that leaves the construct, and an outward goto. emit.x prints the frames, records, and statements this pass decided on.

A break or continue only transfers inside its own loop or switch, so it leaves the regions opened inside that construct and no others. A return leaves every open region, after saving its value, because cleanup may change what the expression read. A goto leaves exactly the regions between it and its label, and entering a region it did not open is rejected here.