@u84u/gl 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,334 @@
1
+ Creative Commons Attribution 4.0 International Public License
2
+
3
+ By exercising the Licensed Rights (defined below), You accept and agree
4
+ to be bound by the terms and conditions of this Creative Commons
5
+ Attribution 4.0 International Public License ("Public License"). To the
6
+ extent this Public License may be interpreted as a contract, You are
7
+ granted the Licensed Rights in consideration of Your acceptance of
8
+ these terms and conditions, and the Licensor grants You such rights in
9
+ consideration of benefits the Licensor receives from making the
10
+ Licensed Material available under these terms and conditions.
11
+
12
+
13
+ Section 1 -- Definitions.
14
+
15
+ a. Adapted Material means material subject to Copyright and Similar
16
+ Rights that is derived from or based upon the Licensed Material and
17
+ in which the Licensed Material is translated, altered, arranged,
18
+ transformed, or otherwise modified in a manner requiring permission
19
+ under the Copyright and Similar Rights held by the Licensor. For
20
+ purposes of this Public License, where the Licensed Material is a
21
+ musical work, performance, or sound recording, Adapted Material is
22
+ always produced where the Licensed Material is synched in timed
23
+ relation with a moving image.
24
+
25
+ b. Adapter's License means the license You apply to Your Copyright
26
+ and Similar Rights in Your contributions to Adapted Material in
27
+ accordance with the terms and conditions of this Public License.
28
+
29
+ c. Copyright and Similar Rights means copyright and/or similar
30
+ rights closely related to copyright including, without limitation,
31
+ performance, broadcast, sound recording, and Sui Generis Database
32
+ Rights, without regard to how the rights are labeled or categorized.
33
+ For purposes of this Public License, the rights specified in
34
+ Section 2(b)(1)-(2) are not Copyright and Similar Rights.
35
+
36
+ d. Effective Technological Measures means those measures that, in
37
+ the absence of proper authority, may not be circumvented under laws
38
+ fulfilling obligations under Article 11 of the WIPO Copyright Treaty
39
+ adopted on December 20, 1996, and/or similar international
40
+ agreements.
41
+
42
+ e. Exceptions and Limitations means fair use, fair dealing, and/or
43
+ any other exception or limitation to Copyright and Similar Rights
44
+ that applies to Your use of the Licensed Material.
45
+
46
+ f. Licensed Material means the artistic or literary work, database,
47
+ or other material to which the Licensor applied this Public License.
48
+
49
+ g. Licensed Rights means the rights granted to You subject to the
50
+ terms and conditions of this Public License, which are limited to
51
+ all Copyright and Similar Rights that apply to Your use of the
52
+ Licensed Material and that the Licensor has authority to license.
53
+
54
+ h. Licensor means the individual(s) or entity(ies) granting rights
55
+ under this Public License.
56
+
57
+ i. Share means to provide material to the public by any means or
58
+ process that requires permission under the Licensed Rights, such as
59
+ reproduction, public display, public performance, distribution,
60
+ dissemination, communication, or importation, and to make material
61
+ available to the public including in ways that members of the public
62
+ may access the material from a place and at a time individually
63
+ chosen by them.
64
+
65
+ j. Sui Generis Database Rights means rights other than copyright
66
+ resulting from Directive 96/9/EC of the European Parliament and of
67
+ the Council of 11 March 1996 on the legal protection of databases,
68
+ as amended and/or succeeded, as well as other essentially equivalent
69
+ rights anywhere in the world.
70
+
71
+ k. You means the individual or entity exercising the Licensed Rights
72
+ under this Public License. Your has a corresponding meaning.
73
+
74
+
75
+ Section 2 -- Scope.
76
+
77
+ a. License grant.
78
+
79
+ 1. Subject to the terms and conditions of this Public License,
80
+ the Licensor hereby grants You a worldwide, royalty-free,
81
+ non-sublicensable, non-exclusive, irrevocable license to
82
+ exercise the Licensed Rights in the Licensed Material to:
83
+
84
+ a. reproduce and Share the Licensed Material, in whole or
85
+ in part; and
86
+
87
+ b. produce, reproduce, and Share Adapted Material.
88
+
89
+ 2. Exceptions and Limitations. For the avoidance of doubt, where
90
+ Exceptions and Limitations apply to Your use, this Public
91
+ License does not apply, and You do not need to comply with
92
+ its terms and conditions.
93
+
94
+ 3. Term. The term of this Public License is specified in
95
+ Section 6(a).
96
+
97
+ 4. Media and formats; technical modifications allowed. The
98
+ Licensor authorizes You to exercise the Licensed Rights in
99
+ all media and formats whether now known or hereafter created,
100
+ and to make technical modifications necessary to do so. The
101
+ Licensor waives and/or agrees not to assert any right or
102
+ authority to forbid You from making technical modifications
103
+ necessary to exercise the Licensed Rights, including
104
+ technical modifications necessary to circumvent Effective
105
+ Technological Measures. For purposes of this Public License,
106
+ simply making modifications authorized by this Section
107
+ 2(a)(4) never produces Adapted Material.
108
+
109
+ 5. Downstream recipients.
110
+
111
+ a. Offer from the Licensor -- Licensed Material. Every
112
+ recipient of the Licensed Material automatically
113
+ receives an offer from the Licensor to exercise the
114
+ Licensed Rights under the terms and conditions of this
115
+ Public License.
116
+
117
+ b. No downstream restrictions. You may not offer or impose
118
+ any additional or different terms or conditions on, or
119
+ apply any Effective Technological Measures to, the
120
+ Licensed Material if doing so restricts exercise of the
121
+ Licensed Rights by any recipient of the Licensed
122
+ Material.
123
+
124
+ 6. No endorsement. Nothing in this Public License constitutes
125
+ or may be construed as permission to assert or imply that
126
+ You are, or that Your use of the Licensed Material is,
127
+ connected with, or sponsored, endorsed, or granted official
128
+ status by, the Licensor or others designated to receive
129
+ attribution as provided in Section 3(a)(1)(A)(i).
130
+
131
+ b. Other rights.
132
+
133
+ 1. Moral rights, such as the right of integrity, are not
134
+ licensed under this Public License, nor are publicity,
135
+ privacy, and/or other similar personality rights; however, to
136
+ the extent possible, the Licensor waives and/or agrees not to
137
+ assert any such rights held by the Licensor to the limited
138
+ extent necessary to allow You to exercise the Licensed
139
+ Rights, but not otherwise.
140
+
141
+ 2. Patent and trademark rights are not licensed under this
142
+ Public License.
143
+
144
+ 3. To the extent possible, the Licensor waives any right to
145
+ collect royalties from You for the exercise of the Licensed
146
+ Rights, whether directly or through a collecting society
147
+ under any voluntary or waivable statutory or compulsory
148
+ licensing scheme. In all other cases, the Licensor expressly
149
+ reserves any right to collect such royalties.
150
+
151
+
152
+ Section 3 -- License Conditions.
153
+
154
+ Your exercise of the Licensed Rights is expressly made subject to the
155
+ following conditions.
156
+
157
+ a. Attribution.
158
+
159
+ 1. If You Share the Licensed Material (including in modified
160
+ form), You must:
161
+
162
+ a. retain the following if it is supplied by the Licensor
163
+ with the Licensed Material:
164
+
165
+ i. identification of the creator(s) of the Licensed
166
+ Material and any others designated to receive
167
+ attribution, in any reasonable manner requested by
168
+ the Licensor (including by pseudonym if
169
+ designated);
170
+
171
+ ii. a copyright notice;
172
+
173
+ iii. a notice that refers to this Public License;
174
+
175
+ iv. a notice that refers to the disclaimer of
176
+ warranties;
177
+
178
+ v. a URI or hyperlink to the Licensed Material to the
179
+ extent reasonably practicable;
180
+
181
+ b. indicate if You modified the Licensed Material and
182
+ retain an indication of any previous modifications; and
183
+
184
+ c. indicate the Licensed Material is licensed under this
185
+ Public License, and include the text of, or the URI or
186
+ hyperlink to, this Public License.
187
+
188
+ 2. You may satisfy the conditions in Section 3(a)(1) in any
189
+ reasonable manner based on the medium, means, and context in
190
+ which You Share the Licensed Material. For example, it may
191
+ be reasonable to satisfy the conditions by providing a URI
192
+ or hyperlink to a resource that includes the required
193
+ information.
194
+
195
+ 3. If requested by the Licensor, You must remove any of the
196
+ information required by Section 3(a)(1)(A) to the extent
197
+ reasonably practicable.
198
+
199
+ 4. If You Share Adapted Material You produce, the Adapter's
200
+ License You apply must not prevent recipients of the
201
+ Adapted Material from complying with this Public License.
202
+
203
+
204
+ Section 4 -- Sui Generis Database Rights.
205
+
206
+ Where the Licensed Rights include Sui Generis Database Rights that
207
+ apply to Your use:
208
+
209
+ a. for the avoidance of doubt, Section 2(a)(1) grants You the right
210
+ to extract, reuse, reproduce, and Share all or a substantial
211
+ portion of the contents of the database;
212
+
213
+ b. if You include all or a substantial portion of the database
214
+ contents in a database in which You have Sui Generis Database
215
+ Rights, but not its individual contents, is Adapted Material;
216
+ and
217
+
218
+ c. You must comply with the conditions in Section 3(a) if You Share
219
+ all or a substantial portion of the contents of the database.
220
+
221
+ For the avoidance of doubt, this Section 4 supplements and does not
222
+ replace Your obligations under this Public License where the Licensed
223
+ Rights include other Copyright and Similar Rights.
224
+
225
+
226
+ Section 5 -- Disclaimer of Warranties and Limitation of Liability.
227
+
228
+ a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
229
+ EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
230
+ AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY
231
+ KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, IMPLIED,
232
+ STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, WARRANTIES
233
+ OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
234
+ NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR
235
+ THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT KNOWN OR
236
+ DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT ALLOWED IN
237
+ FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
238
+
239
+ b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
240
+ TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
241
+ NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
242
+ INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
243
+ COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
244
+ USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN ADVISED
245
+ OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR DAMAGES.
246
+ WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR IN PART,
247
+ THIS LIMITATION MAY NOT APPLY TO YOU.
248
+
249
+ c. The disclaimer of warranties and limitation of liability provided
250
+ above shall be interpreted in a manner that, to the extent possible,
251
+ most closely approximates an absolute disclaimer and waiver of all
252
+ liability.
253
+
254
+
255
+ Section 6 -- Term and Termination.
256
+
257
+ a. This Public License applies for the term of the Copyright and
258
+ Similar Rights licensed here. However, if You fail to comply with
259
+ this Public License, then Your rights under this Public License
260
+ terminate automatically.
261
+
262
+ b. Where Your right to use the Licensed Material has terminated
263
+ under Section 6(a), it reinstates:
264
+
265
+ 1. automatically as of the date the violation is cured,
266
+ provided it is cured within 30 days of Your discovery of the
267
+ violation; or
268
+
269
+ 2. upon express reinstatement by the Licensor.
270
+
271
+ For the avoidance of doubt, this Section 6(b) does not affect any
272
+ right the Licensor may have to seek remedies for Your violations
273
+ of this Public License.
274
+
275
+ c. Where the Licensor may also offer the Licensed Material under
276
+ separate terms or conditions or stop distributing the Licensed
277
+ Material at any time; however, doing so will not terminate this
278
+ Public License.
279
+
280
+ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
281
+ License.
282
+
283
+
284
+ Section 7 -- Other Terms and Conditions.
285
+
286
+ a. The Licensor shall not be bound by any additional or different
287
+ terms or conditions communicated by You unless expressly agreed.
288
+
289
+ b. Any arrangements, understandings, or agreements regarding the
290
+ Licensed Material not stated herein are separate from and
291
+ independent of the terms and conditions of this Public License.
292
+
293
+
294
+ Section 8 -- Interpretation.
295
+
296
+ a. For the avoidance of doubt, this Public License does not, and
297
+ shall not be interpreted to, reduce, limit, restrict, or impose
298
+ conditions on any use of the Licensed Material that could lawfully
299
+ be made without permission under this Public License.
300
+
301
+ b. To the extent possible, if any provision of this Public License
302
+ is deemed unenforceable, it shall be automatically reformed to the
303
+ minimum extent necessary to make it enforceable. If the provision
304
+ cannot be reformed, it shall be severed from this Public License
305
+ without affecting the enforceability of the remaining terms and
306
+ conditions.
307
+
308
+ c. No term or condition of this Public License will be waived and
309
+ no failure to comply consented to unless expressly agreed to by the
310
+ Licensor.
311
+
312
+ d. Nothing in this Public License constitutes or may be interpreted
313
+ to be a limitation upon, or waiver of, any privileges and immunities
314
+ that apply to the Licensor or You, including from the legal
315
+ processes of any jurisdiction or authority.
316
+
317
+
318
+ Creative Commons is not a party to its public licenses.
319
+ Notwithstanding, Creative Commons may elect to apply one of its public
320
+ licenses to material it publishes and in those instances will be
321
+ considered the “Licensor.” The text of the Creative Commons public
322
+ licenses is dedicated to the public domain under the CC0 Public
323
+ Domain Dedication. Except for the limited purpose of indicating that
324
+ material is shared under a Creative Commons public license or as
325
+ otherwise permitted by the Creative Commons policies published at
326
+ creativecommons.org/policies, Creative Commons does not authorize the
327
+ use of the trademark "Creative Commons" or any other trademark or
328
+ logo of Creative Commons without its prior written consent including,
329
+ without limitation, in connection with any unauthorized modifications
330
+ to any other arrangements, understandings, or agreements concerning
331
+ use of licensed material. For the avoidance of doubt, this paragraph
332
+ does not form part of the public licenses.
333
+
334
+ Creative Commons may be contacted at creativecommons.org.
package/README.md CHANGED
@@ -1,3 +1,107 @@
1
- # Temporary Holding Version
1
+ # @u84u/gl
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Compile `gl`, a statically-typed shading language, to GLSL (450 core, ES 3.00) or WGSL.
4
+
5
+ ## Install
6
+
7
+ Not on npm. Install from GitHub:
8
+
9
+ ```bash
10
+ npm install github:u84u/gl
11
+ ```
12
+
13
+ ## CLI
14
+
15
+ ```bash
16
+ gl <input.gl> [--target=glsl|wgsl] [--output=<file>] [--format] [--check]
17
+ ```
18
+
19
+ See `LANGUAGE.md` for the full language reference, shader stages, imports, and built-ins.
20
+
21
+ ## Library API
22
+
23
+ ```ts
24
+ import { compileSync } from "@u84u/gl";
25
+
26
+ const result = compileSync({
27
+ target: "wgsl",
28
+ source: `fn main(): vec4 { return vec4(1.0, 0.0, 0.0, 1.0) }`,
29
+ file: "shader.gl",
30
+ });
31
+
32
+ if (result.diagnostics.some((d) => d.severity === "error")) {
33
+ // handle diagnostics
34
+ } else {
35
+ // result.code is the legacy single-output convenience path
36
+ // result.shaders contains the complete artifact list with reflection
37
+ console.log(result.shaders[0]?.code);
38
+ }
39
+ ```
40
+
41
+ ### Options
42
+
43
+ | Option | Type | Description |
44
+ |--------|------|-------------|
45
+ | `target` | `string` | Backend target ID: `"glsl"`, `"glsl-450"`, `"glsl-es-300"`, `"wgsl"` (or a custom registered target) |
46
+ | `file` | `string` | Source file identity for diagnostics |
47
+ | `sourceId` | `string` | Stable canonical identity for the main source (defaults to `file`) |
48
+ | `source` | `string` | Source text to parse and compile (mutually exclusive with `ast`) |
49
+ | `ast` | `Program` | Pre-built AST to type-check and codegen (mutually exclusive with `source`) |
50
+ | `resolver` | `SourceResolver` | Required for `compileAsync` when source contains imports |
51
+ | `registry` | `BackendRegistry` | Optional backend registry (defaults to the shared default registry) |
52
+ | `provenance` | `Map<Statement, string>` | Maps statements to source files for imported-module diagnostics |
53
+
54
+ ### Entry points
55
+
56
+ - `compileSync(options)` — sync; no imports in source. Returns `CompileResult`.
57
+ - `compileAsync(options)` — async; `resolver` required when source contains imports. Returns `Promise<CompileResult>`.
58
+ - `compile(options)` — deprecated alias for `compileSync`.
59
+
60
+ ### CompileResult
61
+
62
+ ```ts
63
+ interface CompileResult {
64
+ code: string | null; // convenience: first shader's code, or null
65
+ shaders: ShaderArtifact[]; // full artifact list with code, stage, entry point, reflection
66
+ ast: Program; // type-checked program
67
+ diagnostics: Diagnostic[]; // structured diagnostics
68
+ target: string; // resolved target ID
69
+ }
70
+ ```
71
+
72
+ Each `ShaderArtifact` includes `stage`, `entryPoint`, `code`, and `reflection` (entry points, resources, uniforms).
73
+
74
+ ### Shader reflection
75
+
76
+ `ShaderReflection` includes:
77
+ - `entryPoints`: entry point name, stage, inputs (params with name/type), outputs (return values with name/type/location/builtin)
78
+ - `resources`: every binding with `kind` ("sampler"/"sampledTexture"/"uniform"/"uniformBuffer"), `binding`, `set`, `stageVisibility`. GLSL non-sampler bindings are reported as standalone `"uniform"` declarations; WGSL `var<uniform>` bindings are reported as `"uniformBuffer"`. Synthesized sampler bindings for texture bindings are included (WGSL) with the binding actually emitted by codegen.
79
+ - `uniforms`: uniform declarations with `name`, `type`, `offset`, `size`. GLSL standalone uniforms each have `offset: 0`; WGSL uniform buffers are sized using WGSL uniform address-space layout rules.
80
+
81
+ ### Backend capability enforcement
82
+
83
+ Backends reject unsupported features with structured diagnostics instead of silently narrowing types:
84
+ - `WGSL_UNSUPPORTED_SCALAR`, `WGSL_UNSUPPORTED_STAGE`, `WGSL_UNSUPPORTED_RESOURCE`, `WGSL_UNSUPPORTED_MATRIX`
85
+ - `GLSL_UNSUPPORTED_SCALAR`, `GLSL_UNSUPPORTED_STAGE`, `GLSL_UNSUPPORTED_RESOURCE`
86
+
87
+ Validation checks shader stages, scalar types, and resource kinds against each backend's `BackendCapabilities`.
88
+
89
+ ### Custom backends
90
+
91
+ Backends register themselves in a `BackendRegistry`. Use `createDefaultBackendRegistry()` to copy the built-in registry, then `registry.register(backend)` or `registry.replace(backend)` to add or override targets. Pass your registry via `options.registry`.
92
+
93
+ Package entry points: `@u84u/gl` (core), `@u84u/gl/node` (filesystem resolver), `@u84u/gl/browser` (fetch resolver), `@u84u/gl/cli`.
94
+
95
+ ## Development
96
+
97
+ ```bash
98
+ npm install # dependencies
99
+ npm run build # tsup bundle to dist/ (ESM)
100
+ npm run typecheck # tsc --noEmit (strict)
101
+ npm test # vitest — full test suite
102
+ npm run validate # build & run C shader validator (needs libOSMesa, libGL)
103
+ ```
104
+
105
+ ## License
106
+
107
+ CC BY 4.0
@@ -0,0 +1,23 @@
1
+ import { S as SourceResolver, a as SourceModule } from '../resolver-Fn4_IKEu.js';
2
+
3
+ /**
4
+ * Browser source resolver. Resolves `.gl` import specifiers relative to the
5
+ * importing module's canonical URL using `fetch`.
6
+ *
7
+ * All network I/O is confined to this adapter; the compiler core never
8
+ * accesses `fetch`, `window`, or `navigator`.
9
+ */
10
+ declare class FetchSourceResolver implements SourceResolver {
11
+ /** Base URL used to resolve relative import specifiers. */
12
+ readonly baseUrl: string;
13
+ /** Optional fetch implementation (defaults to global fetch). */
14
+ private readonly fetchFn;
15
+ constructor(
16
+ /** Base URL used to resolve relative import specifiers. */
17
+ baseUrl: string,
18
+ /** Optional fetch implementation (defaults to global fetch). */
19
+ fetchFn?: typeof fetch);
20
+ resolve(specifier: string, importer: SourceModule): Promise<SourceModule>;
21
+ }
22
+
23
+ export { FetchSourceResolver };
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/browser/resolver.ts
4
+ var FetchSourceResolver = class {
5
+ constructor(baseUrl, fetchFn = fetch) {
6
+ this.baseUrl = baseUrl;
7
+ this.fetchFn = fetchFn;
8
+ }
9
+ baseUrl;
10
+ fetchFn;
11
+ async resolve(specifier, importer) {
12
+ const importerUrl = new URL(importer.id, this.baseUrl);
13
+ const resolvedUrl = new URL(specifier, importerUrl.href);
14
+ let response;
15
+ try {
16
+ response = await this.fetchFn(resolvedUrl.href);
17
+ } catch (err) {
18
+ throw new Error(
19
+ `Failed to fetch imported module "${specifier}" from ${resolvedUrl.href}: ${err instanceof Error ? err.message : String(err)}`
20
+ );
21
+ }
22
+ if (!response.ok) {
23
+ throw new Error(
24
+ `Failed to fetch imported module "${specifier}": HTTP ${response.status} ${response.statusText}`
25
+ );
26
+ }
27
+ const source = await response.text();
28
+ return {
29
+ id: resolvedUrl.href,
30
+ displayName: specifier,
31
+ source
32
+ };
33
+ }
34
+ };
35
+ export {
36
+ FetchSourceResolver
37
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }