rawStmt
이 페이지에서

rawStmt()

함수, 작성 분류

Author a raw statement, the escape hatch that splices verbatim text into a function body.

import { rawStmt } from 'typeshade'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

function rawStmt(payload: RawPayload): RawStmt

매개변수

payload RawPayload

the per-target spellings, at least one of wgsl and glsl.

반환값

RawStmt

the raw statement node, ready to place in a body array.

예외

SD0030

One side may be omitted, and the other backend then throws SD0030 naming the missing side and quoting the side you did give, so leaving a side out states that the module does not build for that target.

설명

Reach for it when a statement has to be hand-written: a string from another generator, or a construct the IR does not model.

The payload carries one spelling per target, { wgsl, glsl }. The meaning is fixed, only the spelling differs, and each backend splices its own side. One side may be omitted, and the other backend then throws SD0030 naming the missing side and quoting the side you did give, so leaving a side out states that the module does not build for that target. At least one side is required at the type level: rawStmt({}) does not compile.

Only the first line receives the enclosing body’s indent. The emitter prepends that indent to the payload as a whole, so line two onward of a multi-line payload lands at column zero. Indent the continuation lines yourself when the output shape matters.

Identifiers inside the payload are yours to keep valid. Nothing reads into raw text, so nothing rewrites it, and the GLSL backend renames params and locals that collide with GLSL reserved words (in, sample, filter, texture, and the rest); a glsl payload naming the pre-rename identifier references a variable the renamed text does not have. Only the GLSL backend renames, so the risk is one-sided even though the contract is the same on both. For the same reason a module holding a raw statement makes mangle a no-op module-wide, and the CPU oracle, the same module run in double precision on the CPU, throws when it reaches raw text it cannot evaluate.

This factory returns the Stmt, which is what you want when assembling a Stmt[] body by hand. Inside a fluent fn body use b.raw(payload) instead: a bare rawStmt(...) call there is a discarded expression, since the returned statement is never pushed and nothing is emitted.

예제

예제

import { fn, rawStmt, vec4fT } from 'typeshade'
// Inside a fn body, through the builder:
const fs = fn('fs_main', {}, vec4fT, (_p, b) => {
b.raw({ wgsl: 'return vec4<f32>(1.0, 0.0, 0.0, 1.0);', glsl: 'return vec4(1.0, 0.0, 0.0, 1.0);' })
}, { stage: 'fragment' })
// Assembling a Stmt[] by hand:
const stmt = rawStmt({ wgsl: 'discard;', glsl: 'discard;' })

관련 가이드

함께 보기

소스

src/core/ir/builder.ts, 1451행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고