emitFunc
On this page

emitFunc()

Function in Emit

Emit one FuncDecl as a WGSL function, exactly as given.

import { emitFunc } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

const emitFunc: (f: FuncDecl) => string

Parameters

f FuncDecl

Return value

string

Description

Prefer emitFuncs for authored functions. This function skips every pass emitModule runs before writing: autoVars, match lowering (lowerModule), double-precision lowering (fp64Lower) and the optimizer. A function that still contains a match expression or an f64 type therefore throws, because those constructs exist only before lowering, and a function the optimizer would have simplified is written as authored. Use it only when the declaration needs none of those passes, such as a hand-written helper built from plain f32 arithmetic.

Parenthesisation is always 'full'. emitModule passes its parens option down to the same speller, so a module emitted with parens: 'minimal' spells the same function with fewer parentheses. A function emitted here matches its text inside a module emitted with the default option, and may differ from its text inside a 'minimal' one.

Targets

TargetSupportNotes
WGSL (WebGPU) Supported

Writes WGSL for WebGPU.

GLSL ES 3.00 (WebGL2) Does not apply
CPU oracle Does not apply

See also

Source

src/core/backends/wgsl.ts, line 532, at commit 26de7be8

Edit this page Report a problem