lowerModule()
Function in Emit
Rewrites every matchExpr in a module into a form the backends can emit: a hoisted variable assigned from a switch statement, placed immediately before the statement that contained the expression.
import { lowerModule } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function lowerModule(m: ModuleDecl): ModuleDeclParameters
mModuleDeclThe module to rewrite. It is not modified.
Return value
A new module whose function bodies contain no matchExpr.
Exceptions
ErrorWhen a
matchExprappears in aforloop header (the init, condition or update part). Hoisting it out of the header would evaluate it once where the loop evaluates it on every iteration. Compute the value into avarinside the loop body, or before the loop when it does not depend on the loop variable.
Description
WGSL and GLSL have switch only as a statement, so a multi-arm
conditional expression cannot be emitted in place.
emitModule runs this pass automatically, so a shader author never calls it. It is
exported for tests and for hosts that drive the emit pipeline step by step. The pass
rebuilds every node it touches, so the returned module does not share node identity with
the authored one and diagnostics cannot map its nodes back to authored source
locations. Run validate and diagnose() on the module before this pass.
See also
Source
src/core/passes/match-lower.ts, line 62, at commit 26de7be8