식과 타입
타입 주장은 지워집니다. GPU에 대응하는 말이 있는 모양은 남습니다. TypeScript가 실행 시점에 만들 값은 적힌 자리에서 거절합니다.
-
구조 분해
이름마다 선언이 하나씩, 적힌 순서대로 풀립니다.
TypeScript export function swapped(v: vec2): vec2 {const { x, y } = vreturn vec2(y, x)}생성된 WGSL fn swapped(v: vec2<f32>) -> vec2<f32> {let x = v.x;let y = v.y;return vec2<f32>(y, x);} -
객체 스프레드
구조체의 필드마다 읽기가 하나씩 생기고, 뒤에 적은 필드가 그 위를 덮습니다.
TypeScript export function lifted(p: Point): Point {return { ...p, y: 9. }}생성된 WGSL fn lifted(p: Point) -> Point {return Point(p.x, 9.0);} -
배열 리터럴
배열 초기자입니다. 선언이
array<T, N>을 밝힌 자리에서만 씁니다. array-literal-rampTypeScript export function step3(i: i32): f32 {const xs: array<f32, 3> = [0.15, 0.5, 0.9]return xs[i]}생성된 WGSL fn step3(i: i32) -> f32 {let xs = array<f32, 3>(0.15, 0.5, 0.9);return xs[i];} -
튜플
튜플은 타입이 길이를 고정한 배열입니다. 반환 자리에서도 그렇습니다. tuple-and-brand
TypeScript export function bounds(x: f32): [f32, f32] {return [x - 1., x + 1.]}생성된 WGSL fn bounds(x: f32) -> array<f32, 2> {return array<f32, 2>((x - 1.0), (x + 1.0));} -
리터럴 유니온
멤버가 모두 한 타입을 가리키는 유니온은 그 타입을 가리킵니다.
TypeScript export function isWire(m: 0 | 1 | 2): bool {return m === 2}생성된 WGSL fn isWire(m: i32) -> bool {return (m == 2);} -
브랜드 타입
브랜드는 지워지고 매개변수는
f32입니다. tuple-and-brandTypeScript type Metres = f32 & { readonly [m]: 'metres' }생성된 WGSL fn deeper(d: f32) -> f32 {return (d * 2.0);} -
타입 주장
타입에 대한 주장일 뿐 변환이 아니라서, 피연산자가 생성하는 코드를 그대로 생성합니다.
TypeScript export function claimed(x: f32): f32 {const a = x as f32const b = (x satisfies f32)!const k = 2. as constreturn a + b * k}생성된 WGSL fn claimed(x: f32) -> f32 {return (x + (x * 2.0));} -
거듭제곱 연산자
두 타깃 모두
pow입니다.TypeScript export function curved(x: f32): f32 {return x ** 2.2}생성된 WGSL fn curved(x: f32) -> f32 {return pow(x, 2.2);} -
bool에 쓰는&&두 타깃이 모두 가진 연산자이며, 한 번에
bool하나를 다룹니다.TypeScript export function both(a: bool, b: bool): bool {return a && b}생성된 WGSL fn both(a: bool, b: bool) -> bool {return (a && b);} -
마스크에 쓰는
거절&&마스크는
all이나any나select로 묶으십시오. bool-selectTypeScript export function both(a: vec2b, b: vec2b): bool {return a && b}컴파일러 진단
TS8003 Logical "&&" requires bool operands.
-
선택 필드
거절구조체 필드는 호스트가 채우는 메모리에 언제나 있습니다.
TypeScript class Disc {center: vec2radius?: f32}컴파일러 진단
TS8010 Optional field "radius?" on "Disc" is not supported: a struct field is always present in the buffer the host fills.
-
문자열 값
거절GPU에 문자열은 없습니다. 경우를 enum으로 적으십시오.
TypeScript export function label(x: f32): f32 {const name = `band ${x}`return x}컴파일러 진단
TS8013 Template strings are JS. TypeShade has no string type.
-
거절numberGPU의 수에는 너비가 있습니다.
TypeScript export function twice(x: number): number {return x * 2}컴파일러 진단
TS8002 A number on the GPU has a width. Write f32 for a float, i32 or u32 for an integer.
-
거절boolean셰이더 표기는
bool입니다.TypeScript export function on(x: boolean): f32 {return x ? 1. : 0.}컴파일러 진단
TS8002 TypeShade spells the boolean "bool".
-
정수 리터럴
정수로 적은 지역 초기값은 선언된 비제네릭 함수, 생성자나 메서드의 인자 자리에서 요구하는
i32또는u32를 따를 수 있습니다. 타입이 명시된 초기화와 단순 대입도 지역 변수에 의존하지 않고 타입이 정해져 있으면 양쪽 방향으로 같은 요구를 전달합니다. 서로 다른 구체 타입이 요구되면TS8003을 보고하므로 타입 표기나 캐스트로 정합니다. 정수 타입을 요구하는 사용처가 없으면 타입 표기 없는 지역 변수는f32입니다. 실수로 적은 초기값, 모듈 상수와 루프 유도 변수는 기존 규칙을 따릅니다.TypeScript class Hit {constructor(public index: i32) {}offset(value: i32): i32 { return this.index + value; }}export function counts(): i32 {let n = -1;const hit = new Hit(n);n = hit.index;return hit.offset(n);}생성된 WGSL fn Hit_new(index: i32) -> Hit {var self_: Hit = Hit(0);self_.index = index;return self_;}fn Hit_offset(self_: Hit, value: i32) -> i32 {return (self_.index + value);}fn counts() -> i32 {var n: i32 = -1;let hit = Hit_new(n);n = hit.index;return Hit_offset(hit, n);} -
증감 연산자
값이 한 걸음 옮겨 간 결과를 대입합니다.
TypeScript export function stepped(x: f32): f32 {let acc: f32 = xacc++acc--return acc}생성된 WGSL fn stepped(x: f32) -> f32 {var acc: f32 = x;acc = (acc + 1.0);acc = (acc - 1.0);return acc;}