module()
함수, 작성 분류
Assemble a module from its declarations.
import { module } from 'typeshade'
시그니처, 설명, 예제는 커밋 26de7be8의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
function module(parts: ModuleParts): ModuleDecl매개변수
partsModulePartsthe declaration arrays, the optional
funcsrecord, anduses.
반환값
the assembled module.
예외
ErrorErrorwhen afuncsrecord key renames a declaration that was already assembled under a different name, which would corrupt the earlier module’s re-emit.
설명
consts, structs, bindings and funcs are
the four arrays a module is made of, and each defaults to empty; overrides, externs,
enables and uses are the optional rest. The result is a plain ModuleDecl, the
value emitModule, emitGlslModule, reflect and compileModule
all take.
The order of funcs is the emit order, and two things depend on it. GLSL ES 3.00 requires
declare-before-use: the backend topologically sorts its own function section and emits a
forward prototype where the call graph forces one, and a callee-first list keeps working
without them. A fixed order also keeps the emitted bytes deterministic across rebuilds. A
function reached only through a handle call is collected transitively and prepended
callee-first, so listing the entry points is usually enough.
funcs also accepts a record. Each key renames the handle it holds, an anonymous
fn(params, body) handle included, and key order is the emit order, since JavaScript
preserves string-key insertion order. The record therefore names every function
deterministically and no auto-generated _fn0 name reaches the output, which matters when
a snapshot test compares the output or another declaration refers to a function by name.
Keep the array form when the list is spread across sources or post-processed as data.
uses takes declarator handles, uniformStruct, storageBuffer,
resource, ioStruct, structDecl, constDecl and
fp64Guard among them, and derives the struct, binding and const entries from what
each handle already knows. Explicit arrays still work and merge with the derived ones.
예제
예제
import { module } from 'typeshade'
// Array form: the order is the emit order, callees first.const m = module({ structs: [VsOut.decl], bindings: [U.binding], funcs: [wrap, vs, fs] })
// Record form: each key is the emitted name, and key order is the emit order.const n = module({ uses: [U, VsOut], funcs: { wrap, vs_main: vs, fs_main: fs } })관련 가이드
함께 보기
소스
src/core/ir/builder.ts, 1264행, 커밋 26de7be8 기준