xbintsc 0.7.7 → 0.7.9

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.
Files changed (160) hide show
  1. package/dist/src/cli/help.d.ts +1 -1
  2. package/dist/src/cli/help.js +1 -1
  3. package/dist/src/codegen/generator/calls/invocation.js +6 -4
  4. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  5. package/dist/src/codegen/generator/context.d.ts +4 -3
  6. package/dist/src/codegen/generator/context.js +6 -5
  7. package/dist/src/codegen/generator/context.js.map +1 -1
  8. package/dist/src/codegen/generator/expressions/assignment.js +3 -3
  9. package/dist/src/driver/config.d.ts +1 -1
  10. package/dist/src/driver/options.d.ts +1 -1
  11. package/dist/src/driver/version.d.ts +1 -1
  12. package/dist/src/driver/version.js +1 -1
  13. package/dist/src/extensions/gui/features.d.ts +14 -6
  14. package/dist/src/extensions/gui/features.js +34 -6
  15. package/dist/src/extensions/gui/features.js.map +1 -1
  16. package/dist/src/extensions/gui/index.js +3 -3
  17. package/dist/tests/codegen/llvm.test.js +1 -1
  18. package/dist/tests/e2e/gui-audio.test.js +24 -0
  19. package/dist/tests/e2e/gui-audio.test.js.map +1 -1
  20. package/dist/tests/e2e/gui-draw-perf.test.js +9 -0
  21. package/dist/tests/e2e/gui-draw-perf.test.js.map +1 -1
  22. package/dist/tests/e2e/gui-font-face.test.d.ts +3 -1
  23. package/dist/tests/e2e/gui-font-face.test.js +99 -7
  24. package/dist/tests/e2e/gui-font-face.test.js.map +1 -1
  25. package/dist/tests/e2e/gui-frame-pacing.test.d.ts +15 -0
  26. package/dist/tests/e2e/gui-frame-pacing.test.js +68 -0
  27. package/dist/tests/e2e/gui-frame-pacing.test.js.map +1 -0
  28. package/dist/tests/e2e/gui-initial-url.test.d.ts +10 -0
  29. package/dist/tests/e2e/gui-initial-url.test.js +49 -0
  30. package/dist/tests/e2e/gui-initial-url.test.js.map +1 -0
  31. package/dist/tests/e2e/gui-layout.test.js +85 -0
  32. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  33. package/dist/tests/e2e/gui-webgl-depth-init.test.d.ts +13 -0
  34. package/dist/tests/e2e/gui-webgl-depth-init.test.js +144 -0
  35. package/dist/tests/e2e/gui-webgl-depth-init.test.js.map +1 -0
  36. package/dist/tests/e2e/gui-webgl-depth-range.test.d.ts +18 -0
  37. package/dist/tests/e2e/gui-webgl-depth-range.test.js +140 -0
  38. package/dist/tests/e2e/gui-webgl-depth-range.test.js.map +1 -0
  39. package/dist/tests/e2e/gui-webgl.test.js +49 -0
  40. package/dist/tests/e2e/gui-webgl.test.js.map +1 -1
  41. package/dist/tests/e2e/gui-webgpu-attachment.test.d.ts +19 -0
  42. package/dist/tests/e2e/gui-webgpu-attachment.test.js +258 -0
  43. package/dist/tests/e2e/gui-webgpu-attachment.test.js.map +1 -0
  44. package/dist/tests/e2e/method-call-cache.test.js +27 -0
  45. package/dist/tests/e2e/method-call-cache.test.js.map +1 -1
  46. package/dist/tests/extensions/gui-features.test.js +27 -2
  47. package/dist/tests/extensions/gui-features.test.js.map +1 -1
  48. package/doc/ai/extensions.md +10 -4
  49. package/doc/ai/zh-CN/extensions.md +8 -3
  50. package/doc/gui/animation.md +1 -1
  51. package/doc/gui/api.md +35 -2
  52. package/doc/gui/build.md +34 -15
  53. package/doc/gui/dom.md +3 -2
  54. package/doc/gui/known-issues.md +1 -1
  55. package/doc/gui/layout.md +9 -3
  56. package/doc/gui/rendering.md +45 -8
  57. package/doc/gui/runtime.md +13 -0
  58. package/doc/gui/webgl.md +29 -3
  59. package/doc/gui/webgpu.md +20 -0
  60. package/doc/gui.md +9 -4
  61. package/doc/implemented/codegen.md +4 -3
  62. package/doc/zh-CN/gui/animation.md +1 -1
  63. package/doc/zh-CN/gui/api.md +25 -2
  64. package/doc/zh-CN/gui/build.md +20 -7
  65. package/doc/zh-CN/gui/dom.md +3 -2
  66. package/doc/zh-CN/gui/known-issues.md +1 -1
  67. package/doc/zh-CN/gui/layout.md +7 -4
  68. package/doc/zh-CN/gui/rendering.md +33 -8
  69. package/doc/zh-CN/gui/runtime.md +9 -0
  70. package/doc/zh-CN/gui/webgl.md +7 -4
  71. package/doc/zh-CN/gui/webgpu.md +18 -0
  72. package/doc/zh-CN/gui.md +10 -5
  73. package/doc/zh-CN/implemented/codegen.md +4 -3
  74. package/package.json +7 -7
  75. package/runtime/ext_gui/audio_graph_commands.cpp +127 -0
  76. package/runtime/ext_gui/audio_mixer.cpp +84 -163
  77. package/runtime/ext_gui/audio_mixer.h +59 -3
  78. package/runtime/ext_gui/audio_mixer_extra.cpp +8 -0
  79. package/runtime/ext_gui/audio_param_apply.cpp +160 -0
  80. package/runtime/ext_gui/browser.cpp +6 -19
  81. package/runtime/ext_gui/browser_location.cpp +78 -0
  82. package/runtime/ext_gui/css.cpp +1 -0
  83. package/runtime/ext_gui/css.h +4 -0
  84. package/runtime/ext_gui/css_sheet.cpp +4 -2
  85. package/runtime/ext_gui/document_animation.cpp +7 -0
  86. package/runtime/ext_gui/dom_api_computed_style.cpp +3 -2
  87. package/runtime/ext_gui/dom_api_webgl.cpp +39 -2
  88. package/runtime/ext_gui/dom_api_webgl_extensions.cpp +134 -0
  89. package/runtime/ext_gui/dom_api_webgl_internal.h +4 -0
  90. package/runtime/ext_gui/dom_api_webgl_shader.cpp +28 -4
  91. package/runtime/ext_gui/dom_api_webgl_state.cpp +6 -103
  92. package/runtime/ext_gui/gui.cpp +100 -1
  93. package/runtime/ext_gui/gui_events.cpp +8 -2
  94. package/runtime/ext_gui/layout_flex.cpp +5 -2
  95. package/runtime/ext_gui/layout_flow.cpp +24 -1
  96. package/runtime/ext_gui/layout_flow_internal.h +11 -2
  97. package/runtime/ext_gui/media_query.cpp +3 -0
  98. package/runtime/ext_gui/perf.cpp +18 -6
  99. package/runtime/ext_gui/perf.h +37 -0
  100. package/runtime/ext_gui/style.cpp +28 -10
  101. package/runtime/ext_gui/style.h +10 -1
  102. package/runtime/ext_gui/style_length.cpp +4 -0
  103. package/runtime/ext_gui/style_print.cpp +7 -1
  104. package/runtime/ext_gui/style_values.cpp +6 -5
  105. package/runtime/ext_gui/text.cpp +4 -0
  106. package/runtime/ext_gui/text_font_bytes.cpp +117 -0
  107. package/runtime/ext_gui/text_font_bytes.h +65 -0
  108. package/runtime/ext_gui/text_font_db.cpp +5 -0
  109. package/runtime/ext_gui/text_font_sfnt.cpp +71 -24
  110. package/runtime/ext_gui/text_font_sfnt.h +5 -2
  111. package/runtime/ext_gui/text_hb.cpp +34 -5
  112. package/runtime/ext_gui/text_stb.cpp +7 -30
  113. package/runtime/ext_gui/text_webfont.cpp +217 -0
  114. package/runtime/ext_gui/warnings.cpp +26 -0
  115. package/runtime/ext_gui/warnings.h +8 -0
  116. package/runtime/ext_gui/webfont_bridge.c +23 -0
  117. package/runtime/ext_gui/webgl.h +36 -39
  118. package/runtime/ext_gui/webgl_blit_color.cpp +5 -0
  119. package/runtime/ext_gui/webgl_buffer_objects.cpp +19 -5
  120. package/runtime/ext_gui/webgl_context.cpp +2 -0
  121. package/runtime/ext_gui/webgl_draw.cpp +72 -12
  122. package/runtime/ext_gui/webgl_draw_setup.cpp +8 -2
  123. package/runtime/ext_gui/webgl_draw_state.h +13 -2
  124. package/runtime/ext_gui/webgl_framebuffer.cpp +8 -0
  125. package/runtime/ext_gui/webgl_objects.h +19 -0
  126. package/runtime/ext_gui/webgl_program.h +64 -0
  127. package/runtime/ext_gui/webgl_state.cpp +7 -0
  128. package/runtime/ext_gui/webgl_targets.cpp +31 -7
  129. package/runtime/ext_gui/webgl_uniform.cpp +78 -0
  130. package/runtime/ext_gui/webgpu.h +10 -0
  131. package/runtime/ext_gui/webgpu_buffer.cpp +3 -1
  132. package/runtime/ext_gui/webgpu_canvas.cpp +1 -0
  133. package/runtime/ext_gui/webgpu_command.cpp +51 -11
  134. package/runtime/ext_gui/webgpu_convert.cpp +7 -2
  135. package/runtime/ext_gui/webgpu_pass.cpp +12 -0
  136. package/runtime/ext_gui/webgpu_queue.cpp +3 -0
  137. package/runtime/ext_gui/webgpu_resources.cpp +1 -0
  138. package/runtime/ext_gui/window.cpp +6 -0
  139. package/runtime/rt_object.h +6 -0
  140. package/runtime/rt_profile.h +6 -0
  141. package/runtime/xt_containers/access.inc +2 -47
  142. package/runtime/xt_containers/ic_get.inc +70 -0
  143. package/runtime/xt_containers/method_cache.inc +42 -11
  144. package/runtime/xt_containers/objects.inc +12 -1
  145. package/runtime/xt_containers/shapes.inc +78 -0
  146. package/runtime/xt_containers.c +1 -0
  147. package/runtime/xt_profile.c +3 -0
  148. package/scripts/build-gui.ts +43 -49
  149. package/scripts/gui-engine-build.ts +58 -0
  150. package/scripts/gui-vendor-source.ts +53 -0
  151. package/scripts/gui-webfont-build.ts +138 -0
  152. package/src/cli/help.ts +1 -1
  153. package/src/codegen/generator/calls/invocation.ts +6 -4
  154. package/src/codegen/generator/context.ts +6 -6
  155. package/src/codegen/generator/expressions/assignment.ts +3 -3
  156. package/src/driver/config.ts +1 -1
  157. package/src/driver/options.ts +1 -1
  158. package/src/driver/version.ts +1 -1
  159. package/src/extensions/gui/features.ts +34 -6
  160. package/src/extensions/gui/index.ts +3 -3
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Fetch a pinned release tarball into `vendor/` and extract it under a stable
3
+ * directory name.
4
+ *
5
+ * Split out of `build-gui.ts` (which has a file-size budget) because the same
6
+ * "fetch, extract, rename" step is repeated for every vendored build dependency
7
+ * (SDL3 is a git clone, but FreeType, HarfBuzz, glslang, SPIRV-Cross, Brotli and
8
+ * the woff2 decoder all arrive this way).
9
+ *
10
+ * Release tarballs are used rather than git clones because they ship generated
11
+ * sources, so no ragel/autotools step is needed. `marker` is a file that only
12
+ * exists once the tarball has been extracted (e.g. `CMakeLists.txt`), which is
13
+ * what makes a cached extraction reusable.
14
+ */
15
+
16
+ import { existsSync, mkdirSync, renameSync, rmSync } from "node:fs";
17
+ import { join } from "node:path";
18
+
19
+ export interface VendorFetchContext {
20
+ /** Root `vendor/` directory, created on demand. */
21
+ readonly vendorDir: string;
22
+ /** Run a command (curl/tar), failing the build on a non-zero exit. */
23
+ run(command: string, args: readonly string[]): void;
24
+ /** Abort the build with a one-line message. */
25
+ fail(message: string): never;
26
+ }
27
+
28
+ /** Download `url` into `vendor/` and extract it under `name`, returning the
29
+ * extracted directory (an already-extracted copy is reused). */
30
+ export function ensureTarballSource(
31
+ context: VendorFetchContext,
32
+ name: string,
33
+ url: string,
34
+ extractedName: string,
35
+ marker = "CMakeLists.txt",
36
+ ): string {
37
+ const { vendorDir, run, fail } = context;
38
+ const destination = join(vendorDir, name);
39
+ if (existsSync(join(destination, marker))) return destination;
40
+ /* Keep the URL's compression suffix: `tar -xf` sniffs the format anyway, but a
41
+ * misleading name makes a failed extraction harder to diagnose. */
42
+ const tarball = join(vendorDir, `${name}${url.endsWith(".tar.gz") ? ".tar.gz" : ".tar.xz"}`);
43
+ console.log(`xbintsc: fetching ${name} from ${url}`);
44
+ mkdirSync(vendorDir, { recursive: true });
45
+ run("curl", ["-sL", "--fail", "-o", tarball, url]);
46
+ run("tar", ["-xf", tarball, "-C", vendorDir]);
47
+ const extracted = join(vendorDir, extractedName);
48
+ if (!existsSync(extracted)) fail(`expected ${extractedName} after extracting ${name}`);
49
+ rmSync(destination, { recursive: true, force: true });
50
+ renameSync(extracted, destination);
51
+ rmSync(tarball, { force: true });
52
+ return destination;
53
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Compile the WOFF/WOFF2 decompression sources into the GUI archive.
3
+ *
4
+ * Kept out of `build-gui.ts` (which has a file-size budget) and next to it so
5
+ * the "what does the `webfonts` feature cost?" question is reviewable in one
6
+ * place. The sources are fetched, not committed (see `fetch-vendored.ts` and
7
+ * the repository's vendor policy): they are compiled once into `gui.a`, and a
8
+ * program that never loads a compressed font never extracts them.
9
+ *
10
+ * Layers, from the outside in:
11
+ * - `text_webfont.cpp` (the engine, compiled with the other engine objects)
12
+ * parses the WOFF 1.0 container itself and calls the woff2 reference
13
+ * decoder for WOFF 2.0;
14
+ * - `vendor/woff2` reconstructs the transformed `glyf`/`loca`/`hmtx` tables
15
+ * from the Brotli-compressed stream;
16
+ * - `vendor/brotli` decodes that stream (decoder only: the encoder, CLI
17
+ * tools and the shared-dictionary API are not compiled);
18
+ * - `vendor/miniz`'s `miniz_tinfl.c` inflates each WOFF 1.0 table.
19
+ */
20
+
21
+ import { join } from "node:path";
22
+ import { SECTION_FLAGS } from "./gui-build-options.js";
23
+ import { sysrootFlags } from "../src/driver/toolchain.js";
24
+
25
+ /** Pinned versions; override to test a different decoder release. */
26
+ export const BROTLI_VERSION = process.env.BROTLI_VERSION || "1.1.0";
27
+ export const WOFF2_VERSION = process.env.WOFF2_VERSION || "1.0.2";
28
+ const BROTLI_URL = `https://codeload.github.com/google/brotli/tar.gz/refs/tags/v${BROTLI_VERSION}`;
29
+ const WOFF2_URL = `https://codeload.github.com/google/woff2/tar.gz/refs/tags/v${WOFF2_VERSION}`;
30
+
31
+ /** Brotli files the decoder needs (`common/` holds the static dictionary and
32
+ * the context/transform tables; `dec/` is the decoder itself). */
33
+ const BROTLI_COMMON = ["constants", "context", "dictionary", "platform", "shared_dictionary", "transform"];
34
+ const BROTLI_DECODER = ["bit_reader", "decode", "huffman", "state"];
35
+
36
+ /** woff2 files the decoder needs; the encoder/compressor and the CLI are not
37
+ * compiled. */
38
+ const WOFF2_SOURCES = ["woff2_dec", "woff2_common", "table_tags", "variable_length", "woff2_out"];
39
+
40
+ /** Include directories these sources need, for the engine compile as well
41
+ * (`text_webfont.cpp` includes `<woff2/decode.h>` and `miniz_tinfl.h`). */
42
+ export function webfontIncludeFlags(vendorDir: string): string[] {
43
+ return [
44
+ "-I", join(vendorDir, "miniz"),
45
+ "-I", join(vendorDir, "brotli", "c", "include"),
46
+ "-I", join(vendorDir, "woff2", "include"),
47
+ "-I", join(vendorDir, "woff2", "src"),
48
+ ];
49
+ }
50
+
51
+ /** Fetch and extract a release tarball into `vendor/<name>`. */
52
+ export type FetchSource = (name: string, url: string, extractedName: string) => void;
53
+
54
+ /**
55
+ * Fetch Brotli and woff2 (an already-extracted copy is reused). This must run
56
+ * before the engine is compiled: `text_webfont.cpp` includes `<woff2/decode.h>`
57
+ * and `miniz_tinfl.h`, so the include directories have to exist by then.
58
+ */
59
+ export function fetchWebfontSources(fetchSource: FetchSource): void {
60
+ fetchSource("brotli", BROTLI_URL, `brotli-${BROTLI_VERSION}`);
61
+ fetchSource("woff2", WOFF2_URL, `woff2-${WOFF2_VERSION}`);
62
+ }
63
+
64
+ export interface WebfontBuildOptions {
65
+ readonly vendorDir: string;
66
+ /** Directory the engine objects are written to. */
67
+ readonly objDir: string;
68
+ /** `.o` or `.obj`, matching the archive's ABI. */
69
+ readonly objectSuffix: string;
70
+ /** C and C++ compilers from the same toolchain as the driver. */
71
+ readonly clang: string;
72
+ readonly clangxx: string;
73
+ /** Include directories, including the ones these sources need. */
74
+ readonly includeFlags: readonly string[];
75
+ /** macOS SDK for `-isysroot`; absent elsewhere. */
76
+ readonly sdkRoot?: string;
77
+ /** True for the MSVC ABI (`-fPIC` is rejected there). */
78
+ readonly msvc: boolean;
79
+ /** Run a command, failing the build on a non-zero exit. */
80
+ run(command: string, args: readonly string[]): void;
81
+ /** Fetch and extract a release tarball into `vendor/<name>`. */
82
+ fetchSource: FetchSource;
83
+ }
84
+
85
+ /**
86
+ * Compile Brotli, the woff2 reference decoder and miniz's inflater into
87
+ * `objDir` with the same flags as the engine. Returns the object paths to add
88
+ * to the archive.
89
+ */
90
+ export function buildWebfontObjects(options: WebfontBuildOptions): string[] {
91
+ const { vendorDir, objDir, objectSuffix, clang, clangxx, includeFlags, msvc, run } = options;
92
+ fetchWebfontSources(options.fetchSource);
93
+
94
+ /* Brotli and miniz are C, so they get the C flags (the C++ standard would be
95
+ * rejected for a `.c` input); woff2 additionally gets the C++ standard.
96
+ * Neither layer is warned about: upstream code is not ours to keep
97
+ * `-Wall`-clean. */
98
+ const common = [
99
+ "-O2",
100
+ ...SECTION_FLAGS,
101
+ ...sysrootFlags(options.sdkRoot),
102
+ ...(msvc ? [] : ["-fPIC"]),
103
+ ...includeFlags,
104
+ ];
105
+
106
+ const sources: readonly { readonly source: string; readonly cxx: boolean }[] = [
107
+ ...BROTLI_COMMON.map((name) => ({
108
+ source: join(vendorDir, "brotli", "c", "common", `${name}.c`),
109
+ cxx: false,
110
+ })),
111
+ ...BROTLI_DECODER.map((name) => ({
112
+ source: join(vendorDir, "brotli", "c", "dec", `${name}.c`),
113
+ cxx: false,
114
+ })),
115
+ { source: join(vendorDir, "miniz", "miniz_tinfl.c"), cxx: false },
116
+ ...WOFF2_SOURCES.map((name) => ({
117
+ source: join(vendorDir, "woff2", "src", `${name}.cc`),
118
+ cxx: true,
119
+ })),
120
+ ];
121
+
122
+ const objects: string[] = [];
123
+ for (const entry of sources) {
124
+ const name = entry.source.replace(/^.*[\\/]/, "").replace(/\.(?:c|cc)$/, "");
125
+ const object = join(objDir, `webfont_${name}${objectSuffix}`);
126
+ console.log(`xbintsc: compiling ${entry.source.slice(vendorDir.length + 1)}`);
127
+ run(entry.cxx ? clangxx : clang, [
128
+ ...(entry.cxx ? ["-std=c++17"] : []),
129
+ ...common,
130
+ "-c",
131
+ entry.source,
132
+ "-o",
133
+ object,
134
+ ]);
135
+ objects.push(object);
136
+ }
137
+ return objects;
138
+ }
package/src/cli/help.ts CHANGED
@@ -26,7 +26,7 @@ Options:
26
26
  --emit <kind> exe | obj | ir (default: exe)
27
27
  -O0..-O3 Optimization level (default: -O2)
28
28
  --ext <names> Comma separated extensions (e.g. node,gui)
29
- --feature <names> Force optional link features on (media,gpu,images,shaping,webgl,storage,tls,wasm,all)
29
+ --feature <names> Force optional link features on (media,gpu,images,shaping,webfonts,webgl,storage,tls,wasm,all)
30
30
  --no-feature <n> Keep optional link features out even when detected
31
31
  --ext-native <m> Register a C++/Rust extension from a JSON manifest
32
32
  (comma separated for several)
@@ -133,14 +133,16 @@ export const invocationCallMethods: InvocationCallMethods = {
133
133
  const args = this.emitArguments(node.arguments);
134
134
  const result = this.reg();
135
135
  /* Method dispatch is monomorphic at most sites, so the call carries a
136
- * three-word inline cache: a shape/slot hit calls the cached method value
136
+ * four-word inline cache: a shape/slot hit calls the cached method value
137
137
  * directly instead of walking the dispatch tables and the prototype
138
- * chain. See `runtime/xt_containers/access.inc`. */
138
+ * chain. The fourth word records the receiver's shape, so an own property
139
+ * added later cannot be shadowed by a cached prototype method. See
140
+ * `runtime/xt_containers/method_cache.inc`. */
139
141
  this.extraDeclarations.add("declare i64 @xt_call_method_ic(i64, i64, i32, i64*, i64*)");
140
142
  const cache = `@mt.${this.icCounter++}`;
141
- this.globals.push(`${cache} = internal global [3 x i64] zeroinitializer`);
143
+ this.globals.push(`${cache} = internal global [4 x i64] zeroinitializer`);
142
144
  const slot = this.reg();
143
- this.emit(` ${slot} = getelementptr [3 x i64], [3 x i64]* ${cache}, i64 0, i64 0`);
145
+ this.emit(` ${slot} = getelementptr [4 x i64], [4 x i64]* ${cache}, i64 0, i64 0`);
144
146
  this.emit(
145
147
  ` ${result} = call i64 @xt_call_method_ic(i64 ${object}, i64 ${name}, i32 ${args.argc}, i64* ${args.ptr}, i64* ${slot})`,
146
148
  );
@@ -331,18 +331,18 @@ export class GeneratorContext {
331
331
  }
332
332
 
333
333
  /**
334
- * Allocate a two-word inline cache for one property-access site and return
335
- * the `i64*` the runtime fills with (shape, property index). The global is
336
- * zero-initialised, which the runtime treats as an empty cache.
334
+ * Allocate a four-entry inline cache for one property access and return the
335
+ * `i64*` the runtime fills with (shape, property index) pairs. One entry made
336
+ * the cache monomorphic: generic call sites read a field across several
337
+ * layouts and missed nearly every time. Zero-initialised means empty.
337
338
  */
338
339
  icCachePointer(): string {
339
340
  const name = `@ic.${this.icCounter++}`;
340
- this.globals.push(`${name} = internal global [2 x i64] zeroinitializer`);
341
+ this.globals.push(`${name} = internal global [8 x i64] zeroinitializer`);
341
342
  const ptr = this.reg();
342
- this.emit(` ${ptr} = getelementptr [2 x i64], [2 x i64]* ${name}, i64 0, i64 0`);
343
+ this.emit(` ${ptr} = getelementptr [8 x i64], [8 x i64]* ${name}, i64 0, i64 0`);
343
344
  return ptr;
344
345
  }
345
-
346
346
  /** Lay already-computed values out as a contiguous `i64*` argument buffer. */
347
347
  emitValueArguments(values: readonly string[]): { argc: string; ptr: string } {
348
348
  if (values.length === 0) return { argc: "0", ptr: "null" };
@@ -144,14 +144,14 @@ export const assignmentExpressionMethods: AssignmentExpressionMethods = {
144
144
  }
145
145
  const object = this.emitExpression(access.expression);
146
146
  const key = this.stringValue(access.name.text);
147
- /* A store site gets the same monomorphic inline cache a read site has:
147
+ /* A store site gets the same four-entry inline cache a read site has:
148
148
  * `obj.x = v` in a hot loop otherwise resolves the property (own scan,
149
149
  * prototype-chain walk for setters) on every assignment. */
150
150
  this.extraDeclarations.add("declare i64 @xt_set_ic(i64, i64, i64, i64*)");
151
151
  const cache = `@st.${this.icCounter++}`;
152
- this.globals.push(`${cache} = internal global [2 x i64] zeroinitializer`);
152
+ this.globals.push(`${cache} = internal global [8 x i64] zeroinitializer`);
153
153
  const slot = this.reg();
154
- this.emit(` ${slot} = getelementptr [2 x i64], [2 x i64]* ${cache}, i64 0, i64 0`);
154
+ this.emit(` ${slot} = getelementptr [8 x i64], [8 x i64]* ${cache}, i64 0, i64 0`);
155
155
  this.emit(` call i64 @xt_set_ic(i64 ${object}, i64 ${key}, i64 ${value}, i64* ${slot})`);
156
156
  return;
157
157
  }
@@ -55,7 +55,7 @@ export interface ProjectConfig {
55
55
  readonly pgoDir?: string;
56
56
  readonly extensions?: readonly string[];
57
57
  readonly extNative?: readonly string[];
58
- /** Optional link features to force on (`media`, `gpu`, `images`, `shaping`, `webgl`, `all`). */
58
+ /** Optional link features to force on (`media`, `gpu`, `images`, `shaping`, `webfonts`, `webgl`, `all`). */
59
59
  readonly features?: readonly string[];
60
60
  /** Optional link features to keep out even when auto-detection finds a use. */
61
61
  readonly noFeatures?: readonly string[];
@@ -64,7 +64,7 @@ export interface BuildOptions {
64
64
  /** Profile directory (default: `<outDir>/pgo`). */
65
65
  readonly pgoDir?: string;
66
66
  /**
67
- * Optional link features to force on (`media`, `gpu`, `images`, `shaping`, `webgl`, or `all`). Features are
67
+ * Optional link features to force on (`media`, `gpu`, `images`, `shaping`, `webfonts`, `webgl`, or `all`). Features are
68
68
  * otherwise selected from a static scan of the bundled program; forcing one
69
69
  * is the escape hatch for HTML/CSS built from runtime data.
70
70
  */
@@ -9,4 +9,4 @@
9
9
  * `main`/`master` only (see `.githooks/pre-commit`), so feature branches never
10
10
  * change this line and merging two of them cannot conflict here.
11
11
  */
12
- export const COMPILER_VERSION = "0.7.7";
12
+ export const COMPILER_VERSION = "0.7.9";
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Optional link features of the `gui` extension.
3
3
  *
4
- * The GUI engine itself is always linked with `--ext gui`; these are the two
5
- * heavy halves a program may never touch:
4
+ * The GUI engine itself is always linked with `--ext gui`; these are the heavy
5
+ * halves a program may never touch:
6
6
  *
7
7
  * - `media` — the FFmpeg decoder backend (`runtime/xt_media/`, `media.a`).
8
8
  * The DOM media surface lives in `gui.a`; only decoding is optional, and an
@@ -11,12 +11,16 @@
11
11
  * by WebGL *and* by the `mix-blend-mode` / `backdrop-filter` offscreen
12
12
  * compositor. The engine's own shaders are precompiled, so a DOM page
13
13
  * never needs it.
14
+ * - `webfonts` — WOFF/WOFF2 decompression (miniz + Brotli + the woff2
15
+ * reference decoder) for author `@font-face` sources. A page that only
16
+ * names local sfnt faces never pays for it.
14
17
  *
15
18
  * Detection is static: the compiler sees imported `.html`/`.css` assets and all
16
- * bundled modules, so it can recognise `<video>`/`<audio>`, `getContext("webgl")`
17
- * and `mix-blend-mode`/`backdrop-filter`. When markup can be built at run time
18
- * the usage collector sets `dynamicMarkup`, which conservatively enables both
19
- * features; users who know better can shrink the binary with `--no-feature`.
19
+ * bundled modules, so it can recognise `<video>`/`<audio>`, `getContext("webgl")`,
20
+ * `mix-blend-mode`/`backdrop-filter` and `.woff`/`.woff2` sources. When markup
21
+ * can be built at run time the usage collector sets `dynamicMarkup`, which
22
+ * conservatively enables the optional features; users who know better can
23
+ * shrink the binary with `--no-feature`.
20
24
  */
21
25
 
22
26
  import { join } from "node:path";
@@ -28,6 +32,10 @@ import { findRuntimeLibrary, runtimeLibDir } from "../../driver/runtime-lib.js";
28
32
  const MEDIA_TAG = /<(?:video|audio)\b/i;
29
33
  /** A literal tag name handed to `createElement("video")`. */
30
34
  const MEDIA_TAG_NAME = /^(?:video|audio)$/i;
35
+ /** A `.woff`/`.woff2` source anywhere in the program's strings. An imported
36
+ * `.css` asset is bundled as a string, so an author `@font-face` rule that
37
+ * names a compressed font is visible here. */
38
+ const WEBFONT_TOKEN = /\bwoff2?\b/i;
31
39
  /** Anything that needs the GLSL translator. */
32
40
  const GPU_TOKEN = /webgl|mix-blend-mode|mixBlendMode|backdrop-filter|backdropFilter/i;
33
41
 
@@ -92,6 +100,14 @@ export function hasShapingUsage(usage: ProgramUsage): boolean {
92
100
  });
93
101
  }
94
102
 
103
+ /** True when the program may load a compressed webfont. WOFF/WOFF2 `@font-face`
104
+ * sources need a decompressor (miniz + Brotli/woff2) that a page with plain
105
+ * sfnt files never pays for. */
106
+ export function hasWebfontUsage(usage: ProgramUsage): boolean {
107
+ if (usage.dynamicMarkup) return true;
108
+ return usage.strings.some((value) => WEBFONT_TOKEN.test(value));
109
+ }
110
+
95
111
  /** Absolute path to the per-platform prebuilt media archive. */
96
112
  function mediaArchive(): string {
97
113
  return join(runtimeLibDir(), process.platform === "win32" ? "media.lib" : "media.a");
@@ -163,6 +179,18 @@ export const guiLinkFeatures: readonly LinkFeature[] = [
163
179
  runtimeSources: () => [join(findRuntimeDir(), "ext_gui", "text_bridge.c")],
164
180
  used: hasShapingUsage,
165
181
  },
182
+ {
183
+ name: "webfonts",
184
+ description: "WOFF/WOFF2 decompression for author @font-face sources",
185
+ /**
186
+ * `webfont_bridge.c` installs the decoder and references `text_webfont.cpp`,
187
+ * pulling miniz (zlib inflate), Brotli and the woff2 reference decoder out
188
+ * of `gui.a`. A page whose fonts are plain sfnt files — the common case for
189
+ * system faces — links none of them.
190
+ */
191
+ runtimeSources: () => [join(findRuntimeDir(), "ext_gui", "webfont_bridge.c")],
192
+ used: hasWebfontUsage,
193
+ },
166
194
  {
167
195
  name: "webgpu",
168
196
  description: "WebGPU (navigator.gpu, WGSL) rendering over SDL_GPU (requires gpu)",
@@ -311,9 +311,9 @@ export const guiExtension: Extension = {
311
311
  /** Rewrite imported `.html` assets and patch three.js's shader unroller. */
312
312
  assetLoaders: () => ({ ".html": loadHtmlAsset, ".js": loadScriptAsset, ".mjs": loadScriptAsset }),
313
313
  /**
314
- * FFmpeg and glslang are optional halves of the engine, selected from the
315
- * program (see `features.ts`). A program that only renders HTML/CSS never
316
- * links either.
314
+ * FFmpeg, glslang and the WOFF/WOFF2 decompressors are optional halves of the
315
+ * engine, selected from the program (see `features.ts`). A program that only
316
+ * renders HTML/CSS never links them.
317
317
  */
318
318
  linkFeatures: () => guiLinkFeatures,
319
319
  };