xbintsc 0.7.0 → 0.7.6

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 (323) hide show
  1. package/dist/src/ast/common.d.ts +10 -0
  2. package/dist/src/checker/source.js +4 -0
  3. package/dist/src/checker/source.js.map +1 -1
  4. package/dist/src/cli/help.d.ts +1 -1
  5. package/dist/src/cli/main.js +15 -3
  6. package/dist/src/cli/main.js.map +1 -1
  7. package/dist/src/codegen/generator/calls/access.js +4 -11
  8. package/dist/src/codegen/generator/calls/access.js.map +1 -1
  9. package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
  10. package/dist/src/codegen/generator/calls/element-inline.js +388 -0
  11. package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
  12. package/dist/src/codegen/generator/calls/invocation.js +82 -1
  13. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  14. package/dist/src/codegen/generator/calls.d.ts +3 -1
  15. package/dist/src/codegen/generator/calls.js +3 -1
  16. package/dist/src/codegen/generator/calls.js.map +1 -1
  17. package/dist/src/codegen/generator/debug.js +20 -3
  18. package/dist/src/codegen/generator/debug.js.map +1 -1
  19. package/dist/src/codegen/generator/expressions/assignment.js +10 -2
  20. package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
  21. package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
  22. package/dist/src/codegen/generator/expressions/global-values.js +49 -0
  23. package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
  24. package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
  25. package/dist/src/codegen/generator/expressions/primary.js +4 -24
  26. package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
  27. package/dist/src/codegen/generator/expressions.d.ts +2 -1
  28. package/dist/src/codegen/generator/expressions.js +2 -1
  29. package/dist/src/codegen/generator/expressions.js.map +1 -1
  30. package/dist/src/codegen/generator/layout.d.ts +65 -0
  31. package/dist/src/codegen/generator/layout.js +50 -0
  32. package/dist/src/codegen/generator/layout.js.map +1 -0
  33. package/dist/src/codegen/generator/state.js +4 -0
  34. package/dist/src/codegen/generator/state.js.map +1 -1
  35. package/dist/src/diagnostics/diagnostic.js +1 -1
  36. package/dist/src/diagnostics/diagnostic.js.map +1 -1
  37. package/dist/src/diagnostics/source-text.d.ts +37 -9
  38. package/dist/src/diagnostics/source-text.js +124 -23
  39. package/dist/src/diagnostics/source-text.js.map +1 -1
  40. package/dist/src/diagnostics/source.d.ts +16 -6
  41. package/dist/src/diagnostics/source.js +25 -4
  42. package/dist/src/diagnostics/source.js.map +1 -1
  43. package/dist/src/driver/build-key.d.ts +14 -0
  44. package/dist/src/driver/build-key.js +6 -1
  45. package/dist/src/driver/build-key.js.map +1 -1
  46. package/dist/src/driver/bundler/concatenate.js +11 -4
  47. package/dist/src/driver/bundler/concatenate.js.map +1 -1
  48. package/dist/src/driver/bundler/graph.js +2 -2
  49. package/dist/src/driver/bundler/graph.js.map +1 -1
  50. package/dist/src/driver/bundler/merge.js +11 -5
  51. package/dist/src/driver/bundler/merge.js.map +1 -1
  52. package/dist/src/driver/bundler/reexport-resolution.js +3 -0
  53. package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
  54. package/dist/src/driver/compiler.js +13 -3
  55. package/dist/src/driver/compiler.js.map +1 -1
  56. package/dist/src/driver/frontend.js +3 -4
  57. package/dist/src/driver/frontend.js.map +1 -1
  58. package/dist/src/driver/runtime-objects.d.ts +1 -1
  59. package/dist/src/driver/runtime-objects.js +4 -0
  60. package/dist/src/driver/runtime-objects.js.map +1 -1
  61. package/dist/src/driver/toolchain.js +28 -5
  62. package/dist/src/driver/toolchain.js.map +1 -1
  63. package/dist/src/driver/version.d.ts +1 -1
  64. package/dist/src/driver/version.js +1 -1
  65. package/dist/src/extensions/gui/html.js +42 -10
  66. package/dist/src/extensions/gui/html.js.map +1 -1
  67. package/dist/src/extensions/gui/index.js +48 -0
  68. package/dist/src/extensions/gui/index.js.map +1 -1
  69. package/dist/src/extensions/registry.d.ts +20 -0
  70. package/dist/src/extensions/registry.js.map +1 -1
  71. package/dist/src/parser/expressions.js +2 -2
  72. package/dist/src/parser/expressions.js.map +1 -1
  73. package/dist/src/parser/helpers.d.ts +8 -0
  74. package/dist/src/parser/helpers.js +21 -0
  75. package/dist/src/parser/helpers.js.map +1 -1
  76. package/dist/tests/cli/main.test.js +9 -0
  77. package/dist/tests/cli/main.test.js.map +1 -1
  78. package/dist/tests/codegen/element-layout.test.d.ts +19 -0
  79. package/dist/tests/codegen/element-layout.test.js +80 -0
  80. package/dist/tests/codegen/element-layout.test.js.map +1 -0
  81. package/dist/tests/codegen/expressions.test.js +25 -0
  82. package/dist/tests/codegen/expressions.test.js.map +1 -1
  83. package/dist/tests/codegen/llvm.test.js +13 -0
  84. package/dist/tests/codegen/llvm.test.js.map +1 -1
  85. package/dist/tests/diagnostics/diagnostic.test.js +9 -0
  86. package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
  87. package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
  88. package/dist/tests/diagnostics/source-text.test.js +50 -0
  89. package/dist/tests/diagnostics/source-text.test.js.map +1 -0
  90. package/dist/tests/diagnostics/source.test.js +17 -0
  91. package/dist/tests/diagnostics/source.test.js.map +1 -1
  92. package/dist/tests/driver/build-key.test.d.ts +1 -0
  93. package/dist/tests/driver/build-key.test.js +49 -0
  94. package/dist/tests/driver/build-key.test.js.map +1 -0
  95. package/dist/tests/driver/toolchain.test.js +8 -1
  96. package/dist/tests/driver/toolchain.test.js.map +1 -1
  97. package/dist/tests/driver/usage.test.js +2 -1
  98. package/dist/tests/driver/usage.test.js.map +1 -1
  99. package/dist/tests/e2e/async-await.test.js +16 -0
  100. package/dist/tests/e2e/async-await.test.js.map +1 -1
  101. package/dist/tests/e2e/compile-builtins.test.js +29 -0
  102. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  103. package/dist/tests/e2e/compile-modules.test.js +13 -0
  104. package/dist/tests/e2e/compile-modules.test.js.map +1 -1
  105. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
  106. package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
  107. package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
  108. package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
  109. package/dist/tests/e2e/differential-language.test.js +25 -0
  110. package/dist/tests/e2e/differential-language.test.js.map +1 -1
  111. package/dist/tests/e2e/differential-values.test.js +59 -0
  112. package/dist/tests/e2e/differential-values.test.js.map +1 -1
  113. package/dist/tests/e2e/gc.test.js +22 -0
  114. package/dist/tests/e2e/gc.test.js.map +1 -1
  115. package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
  116. package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
  117. package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
  118. package/dist/tests/e2e/gui-browser.test.js +35 -2
  119. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  120. package/dist/tests/e2e/gui-dom.test.js +88 -0
  121. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  122. package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
  123. package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
  124. package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
  125. package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
  126. package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
  127. package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
  128. package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
  129. package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
  130. package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
  131. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
  132. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
  133. package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
  134. package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
  135. package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
  136. package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
  137. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
  138. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
  139. package/dist/tests/e2e/gui-webgl2.test.js +59 -1
  140. package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
  141. package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
  142. package/dist/tests/e2e/hang-watchdog.test.js +50 -0
  143. package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
  144. package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
  145. package/dist/tests/e2e/method-call-cache.test.js +65 -0
  146. package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
  147. package/dist/tests/e2e/performance-now.test.d.ts +9 -0
  148. package/dist/tests/e2e/performance-now.test.js +36 -0
  149. package/dist/tests/e2e/performance-now.test.js.map +1 -0
  150. package/dist/tests/e2e/property-ic.test.js +33 -0
  151. package/dist/tests/e2e/property-ic.test.js.map +1 -1
  152. package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
  153. package/dist/tests/e2e/shape-interning.test.js +55 -0
  154. package/dist/tests/e2e/shape-interning.test.js.map +1 -0
  155. package/dist/tests/e2e/string-utf16.test.js +9 -0
  156. package/dist/tests/e2e/string-utf16.test.js.map +1 -1
  157. package/dist/tests/e2e/typed-array-views.test.js +26 -0
  158. package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
  159. package/dist/tests/e2e/url-search-params.test.js +19 -0
  160. package/dist/tests/e2e/url-search-params.test.js.map +1 -1
  161. package/dist/tests/extensions/gui.test.js +16 -1
  162. package/dist/tests/extensions/gui.test.js.map +1 -1
  163. package/dist/tests/helpers.js +1 -0
  164. package/dist/tests/helpers.js.map +1 -1
  165. package/dist/tests/parser/expressions.test.js +36 -0
  166. package/dist/tests/parser/expressions.test.js.map +1 -1
  167. package/doc/ai/contributing.md +8 -5
  168. package/doc/ai/extensions.md +12 -3
  169. package/doc/ai/language-support.md +2 -1
  170. package/doc/ai/troubleshooting.md +14 -0
  171. package/doc/ai/zh-CN/contributing.md +6 -3
  172. package/doc/ai/zh-CN/extensions.md +10 -2
  173. package/doc/ai/zh-CN/language-support.md +2 -1
  174. package/doc/ai/zh-CN/troubleshooting.md +12 -0
  175. package/doc/gui/api.md +26 -4
  176. package/doc/gui/dom.md +8 -0
  177. package/doc/gui/known-issues.md +35 -6
  178. package/doc/gui/runtime.md +16 -1
  179. package/doc/gui/webgl.md +97 -26
  180. package/doc/gui-scripts.md +2 -1
  181. package/doc/gui.md +8 -5
  182. package/doc/implemented/checker.md +9 -0
  183. package/doc/implemented/codegen.md +7 -0
  184. package/doc/implemented/parser.md +2 -1
  185. package/doc/implemented/runtime-core.md +9 -2
  186. package/doc/implemented/stdlib.md +10 -2
  187. package/doc/implemented/typed-arrays.md +18 -2
  188. package/doc/zh-CN/gui/api.md +19 -5
  189. package/doc/zh-CN/gui/dom.md +6 -0
  190. package/doc/zh-CN/gui/known-issues.md +24 -5
  191. package/doc/zh-CN/gui/runtime.md +13 -1
  192. package/doc/zh-CN/gui/webgl.md +20 -7
  193. package/doc/zh-CN/gui-scripts.md +2 -1
  194. package/doc/zh-CN/gui.md +4 -1
  195. package/doc/zh-CN/implemented/checker.md +7 -0
  196. package/doc/zh-CN/implemented/codegen.md +7 -0
  197. package/doc/zh-CN/implemented/parser.md +2 -1
  198. package/doc/zh-CN/implemented/runtime-core.md +9 -2
  199. package/doc/zh-CN/implemented/stdlib.md +6 -2
  200. package/doc/zh-CN/implemented/typed-arrays.md +14 -2
  201. package/package.json +7 -7
  202. package/runtime/ext_gui/audio.cpp +39 -3
  203. package/runtime/ext_gui/audio_extra.cpp +353 -0
  204. package/runtime/ext_gui/audio_extra.h +47 -0
  205. package/runtime/ext_gui/audio_fft.h +76 -0
  206. package/runtime/ext_gui/audio_internal.h +21 -0
  207. package/runtime/ext_gui/audio_mixer.cpp +46 -1
  208. package/runtime/ext_gui/audio_mixer.h +89 -1
  209. package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
  210. package/runtime/ext_gui/audio_nodes.cpp +242 -0
  211. package/runtime/ext_gui/audio_nodes_internal.h +81 -0
  212. package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
  213. package/runtime/ext_gui/browser.cpp +9 -0
  214. package/runtime/ext_gui/browser_screen.cpp +73 -0
  215. package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
  216. package/runtime/ext_gui/dom_api_internal.h +3 -0
  217. package/runtime/ext_gui/dom_api_node.cpp +21 -0
  218. package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
  219. package/runtime/ext_gui/dom_api_proto.cpp +3 -0
  220. package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
  221. package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
  222. package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
  223. package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
  224. package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
  225. package/runtime/ext_gui/dom_api_webgl_state.cpp +4 -2
  226. package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
  227. package/runtime/ext_gui/gui.cpp +6 -1
  228. package/runtime/ext_gui/gui_engine.h +2 -0
  229. package/runtime/ext_gui/gui_events.cpp +13 -8
  230. package/runtime/ext_gui/gui_webgl.cpp +3 -2
  231. package/runtime/ext_gui/style_ua.cpp +4 -0
  232. package/runtime/ext_gui/warnings.cpp +1 -1
  233. package/runtime/ext_gui/webgl.h +102 -7
  234. package/runtime/ext_gui/webgl_api.h +3 -2
  235. package/runtime/ext_gui/webgl_blit.cpp +109 -15
  236. package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
  237. package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
  238. package/runtime/ext_gui/webgl_buffer.cpp +20 -170
  239. package/runtime/ext_gui/webgl_context.cpp +117 -169
  240. package/runtime/ext_gui/webgl_draw.cpp +116 -5
  241. package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
  242. package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
  243. package/runtime/ext_gui/webgl_draw_state.h +2 -0
  244. package/runtime/ext_gui/webgl_feature.cpp +2 -2
  245. package/runtime/ext_gui/webgl_feature.h +4 -3
  246. package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
  247. package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
  248. package/runtime/ext_gui/webgl_objects.h +16 -2
  249. package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
  250. package/runtime/ext_gui/webgl_state.cpp +45 -36
  251. package/runtime/ext_gui/webgl_targets.cpp +440 -0
  252. package/runtime/ext_gui/webgl_texture.cpp +81 -25
  253. package/runtime/ext_gui/window.cpp +8 -0
  254. package/runtime/rt.h +27 -27
  255. package/runtime/rt_binary.h +44 -0
  256. package/runtime/rt_internal.h +52 -60
  257. package/runtime/rt_object.h +83 -0
  258. package/runtime/rt_profile.h +45 -0
  259. package/runtime/xt_alloc.c +88 -133
  260. package/runtime/xt_array_buffer.c +99 -71
  261. package/runtime/xt_builtins.c +3 -1
  262. package/runtime/xt_constructors.c +1 -0
  263. package/runtime/xt_containers/access.inc +96 -11
  264. package/runtime/xt_containers/arrays.inc +2 -1
  265. package/runtime/xt_containers/cstr_cache.inc +56 -0
  266. package/runtime/xt_containers/method_cache.inc +121 -0
  267. package/runtime/xt_containers/object_keys.inc +58 -0
  268. package/runtime/xt_containers/objects.inc +47 -79
  269. package/runtime/xt_containers/shapes.inc +153 -8
  270. package/runtime/xt_containers.c +4 -0
  271. package/runtime/xt_gc_release.c +70 -0
  272. package/runtime/xt_gc_stack.c +83 -0
  273. package/runtime/xt_gc_verify.c +1 -0
  274. package/runtime/xt_io/console.inc +66 -0
  275. package/runtime/xt_io/exception.inc +32 -6
  276. package/runtime/xt_io/watchdog.inc +101 -0
  277. package/runtime/xt_io.c +1 -0
  278. package/runtime/xt_loop.c +23 -3
  279. package/runtime/xt_pool.c +151 -0
  280. package/runtime/xt_profile.c +126 -0
  281. package/runtime/xt_stdlib/dispatch.inc +7 -1
  282. package/runtime/xt_stdlib/math.inc +272 -57
  283. package/runtime/xt_stdlib2/json_stringify.inc +1 -2
  284. package/runtime/xt_stdlib2/regexp-match.inc +17 -0
  285. package/runtime/xt_storage/indexed_db.c +4 -1
  286. package/runtime/xt_structured_clone.c +2 -1
  287. package/runtime/xt_typed_array/construction.inc +10 -0
  288. package/runtime/xt_typed_array/elements.inc +43 -23
  289. package/runtime/xt_url.c +50 -0
  290. package/runtime/xt_values/constructors.inc +4 -1
  291. package/runtime/xt_values/strings.inc +3 -1
  292. package/src/ast/common.ts +10 -0
  293. package/src/checker/source.ts +3 -0
  294. package/src/cli/main.ts +14 -3
  295. package/src/codegen/generator/calls/access.ts +5 -10
  296. package/src/codegen/generator/calls/element-inline.ts +433 -0
  297. package/src/codegen/generator/calls/invocation.ts +87 -1
  298. package/src/codegen/generator/calls.ts +5 -0
  299. package/src/codegen/generator/debug.ts +21 -3
  300. package/src/codegen/generator/expressions/assignment.ts +11 -2
  301. package/src/codegen/generator/expressions/global-values.ts +57 -0
  302. package/src/codegen/generator/expressions/primary.ts +4 -27
  303. package/src/codegen/generator/expressions.ts +3 -0
  304. package/src/codegen/generator/layout.ts +54 -0
  305. package/src/codegen/generator/state.ts +5 -0
  306. package/src/diagnostics/diagnostic.ts +1 -1
  307. package/src/diagnostics/source-text.ts +118 -22
  308. package/src/diagnostics/source.ts +29 -7
  309. package/src/driver/build-key.ts +21 -1
  310. package/src/driver/bundler/concatenate.ts +12 -5
  311. package/src/driver/bundler/graph.ts +2 -2
  312. package/src/driver/bundler/merge.ts +11 -4
  313. package/src/driver/bundler/reexport-resolution.ts +2 -0
  314. package/src/driver/compiler.ts +14 -3
  315. package/src/driver/frontend.ts +3 -4
  316. package/src/driver/runtime-objects.ts +4 -0
  317. package/src/driver/toolchain.ts +28 -5
  318. package/src/driver/version.ts +1 -1
  319. package/src/extensions/gui/html.ts +41 -11
  320. package/src/extensions/gui/index.ts +50 -1
  321. package/src/extensions/registry.ts +20 -0
  322. package/src/parser/expressions.ts +2 -2
  323. package/src/parser/helpers.ts +22 -0
@@ -182,10 +182,20 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
182
182
  const storage = resolveStorage(options.storage);
183
183
 
184
184
  const runtimeDir = findRuntimeDir();
185
+ /* The toolchain is part of the cache key, so it has to be resolved before
186
+ * the freshness check. `emit: "ir"` is front-end only and must keep working
187
+ * without clang, so it is the one build that does not resolve one. */
188
+ const toolchain: Pick<ResolvedToolchain, "clang" | "linkerArgs" | "env" | "sdkRoot"> | undefined =
189
+ emit === "ir"
190
+ ? undefined
191
+ : options.clang
192
+ ? { clang: options.clang, linkerArgs: [], env: {} }
193
+ : resolveToolchain(runner);
185
194
  const cacheKey = buildCacheKey({
186
195
  sourceText: parsed.cacheText,
187
196
  emit,
188
197
  optimize,
198
+ arch: process.arch,
189
199
  registry,
190
200
  runtimeDir,
191
201
  icon,
@@ -197,6 +207,7 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
197
207
  pgo,
198
208
  pgoDir,
199
209
  features: linkFeatures.map((feature) => feature.name),
210
+ ...(toolchain === undefined ? {} : { toolchain }),
200
211
  });
201
212
 
202
213
  // A `.app` bundle is deterministic from the output path and name, so it can be
@@ -255,10 +266,10 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
255
266
  }
256
267
 
257
268
  // -- toolchain -----------------------------------------------------------
269
+ if (toolchain === undefined) {
270
+ throw new Error("xbintsc: internal error: no toolchain resolved for a linked build");
271
+ }
258
272
  const clangStarted = Date.now();
259
- const toolchain: Pick<ResolvedToolchain, "clang" | "linkerArgs" | "env" | "sdkRoot"> = options.clang
260
- ? { clang: options.clang, linkerArgs: [], env: {} }
261
- : resolveToolchain(runner);
262
273
  const clang = toolchain.clang;
263
274
  if (pgo === "use") {
264
275
  try {
@@ -7,11 +7,10 @@
7
7
  * `run` and `build`.
8
8
  */
9
9
 
10
- import { readFileSync } from "node:fs";
11
10
  import { resolve } from "node:path";
12
11
  import { DiagnosticBag } from "../diagnostics/diagnostic.js";
13
12
  import { SourceFile } from "../diagnostics/source.js";
14
- import { sourceTextBytes } from "../diagnostics/source-text.js";
13
+ import { readSourceText, sourceTextBytes } from "../diagnostics/source-text.js";
15
14
  import { Parser } from "../parser/parser.js";
16
15
  import { generate } from "../codegen/llvm.js";
17
16
  import { SyntaxKind, type SourceFileNode } from "../ast/nodes.js";
@@ -63,7 +62,7 @@ export function parseEntry(
63
62
  moduleOverrides?: Readonly<Record<string, string>>,
64
63
  ): ParsedEntry {
65
64
  const absoluteEntry = resolve(entryPath);
66
- const sourceText = sourceTextBytes(readFileSync(absoluteEntry, "utf8"));
65
+ const sourceText = readSourceText(absoluteEntry);
67
66
  const file = new SourceFile(absoluteEntry, sourceText);
68
67
  const parser = new Parser(file, diagnostics);
69
68
  let sourceFile = parser.parseSourceFile();
@@ -92,7 +91,7 @@ export function compileString(
92
91
  extensions?: ExtensionRegistry,
93
92
  options: FrontendOptions = {},
94
93
  ): CompileStringResult {
95
- const file = new SourceFile(fileName, source);
94
+ const file = new SourceFile(fileName, sourceTextBytes(source));
96
95
  const diagnostics = new DiagnosticBag();
97
96
  const parser = new Parser(file, diagnostics);
98
97
  const sourceFile = parser.parseSourceFile();
@@ -18,6 +18,7 @@ import { COMPILER_VERSION } from "./version.js";
18
18
  /** Core runtime translation units (each compiled and cached independently). */
19
19
  export const RUNTIME_SOURCES = [
20
20
  "xt_alloc.c",
21
+ "xt_gc_stack.c",
21
22
  "xt_values.c",
22
23
  "xt_bigint.c",
23
24
  "xt_containers.c",
@@ -44,6 +45,9 @@ export const RUNTIME_SOURCES = [
44
45
  "xt_constructors.c",
45
46
  "xt_structured_clone.c",
46
47
  "xt_performance.c",
48
+ "xt_profile.c",
49
+ "xt_pool.c",
50
+ "xt_gc_release.c",
47
51
  "xt_random.c",
48
52
  "xt_crypto.c",
49
53
  "xt_text_codec.c",
@@ -34,14 +34,37 @@ export const realRunner: Runner = {
34
34
  };
35
35
  if (options.env) spawnOptions.env = Object.assign({}, process.env, options.env);
36
36
  const result = spawnSync(command, [...args], spawnOptions);
37
- return {
38
- status: result.status ?? (result.error ? 1 : 0),
39
- stdout: result.stdout?.toString() ?? "",
40
- stderr: result.stderr?.toString() ?? (result.error ? String(result.error.message) : ""),
41
- };
37
+ const stdout = result.stdout?.toString() ?? "";
38
+ const baseStderr = result.stderr?.toString() ?? "";
39
+ /* `status === null` is never success: the child either failed to start
40
+ * (`error`) or was terminated by a signal. Treating the signal case as 0
41
+ * made a killed clang look like a successful compile and let `build`
42
+ * record a missing/truncated artifact. */
43
+ if (result.error) {
44
+ const detail = result.error.message;
45
+ return {
46
+ status: result.status ?? 1,
47
+ stdout,
48
+ stderr: appendLine(baseStderr, detail),
49
+ };
50
+ }
51
+ if (result.status === null) {
52
+ return {
53
+ status: 1,
54
+ stdout,
55
+ stderr: appendLine(baseStderr, `terminated by signal ${result.signal ?? "unknown"}`),
56
+ };
57
+ }
58
+ return { status: result.status, stdout, stderr: baseStderr };
42
59
  },
43
60
  };
44
61
 
62
+ /** Append `line` to `text` without losing an existing final newline. */
63
+ function appendLine(text: string, line: string): string {
64
+ if (text.length === 0) return line;
65
+ return text.endsWith("\n") ? `${text}${line}` : `${text}\n${line}`;
66
+ }
67
+
45
68
  export class ToolchainError extends Error {
46
69
  readonly command: string;
47
70
  readonly status: number;
@@ -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.0";
12
+ export const COMPILER_VERSION = "0.7.6";
@@ -24,7 +24,7 @@
24
24
  * "eager" execution point), i.e. every script is effectively `defer`red.
25
25
  */
26
26
 
27
- import { existsSync, readFileSync } from "node:fs";
27
+ import { existsSync } from "node:fs";
28
28
  import { dirname, relative, resolve } from "node:path";
29
29
  import {
30
30
  ModifierKind,
@@ -37,6 +37,7 @@ import {
37
37
  } from "../../ast/nodes.js";
38
38
  import { DiagnosticBag } from "../../diagnostics/diagnostic.js";
39
39
  import { SourceFile } from "../../diagnostics/source.js";
40
+ import { readSourceText } from "../../diagnostics/source-text.js";
40
41
  import { Parser } from "../../parser/parser.js";
41
42
  import { artifactPath } from "../../canonical.js";
42
43
  import { hashString } from "../../driver/cache.js";
@@ -81,6 +82,22 @@ function isExecutable(type: string | undefined, lang: string | undefined): boole
81
82
  }
82
83
  }
83
84
 
85
+ /**
86
+ * Whether an executable `<script>` is plain JavaScript rather than TypeScript.
87
+ *
88
+ * A browser page's script is JavaScript by default; only `lang="ts"` or a
89
+ * TypeScript MIME type opts into type checking. Untyped scripts skip the
90
+ * checker's inference (see `isPlainJavaScriptNode`), which is what keeps
91
+ * minified bundles — `Game.foo = …` installed after the literal, a closure
92
+ * variable initialized to `null`, calls that rely on default parameters — from
93
+ * failing on heuristics that a real browser never applies.
94
+ */
95
+ function isPlainScript(type: string | undefined, lang: string | undefined): boolean {
96
+ if (lang !== undefined && /^(ts|tsx|typescript)$/i.test(lang)) return false;
97
+ if (type === undefined) return true;
98
+ return !/^(text\/typescript|application\/typescript)$/i.test(type);
99
+ }
100
+
84
101
  /** Rewrite a relative import specifier so it resolves from the HTML file. */
85
102
  function rewriteSpecifier(htmlPath: string, scriptPath: string, specifier: string): string {
86
103
  if (!specifier.startsWith(".")) return specifier;
@@ -274,8 +291,9 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
274
291
  const page = new SourceFile(path, source).text;
275
292
  /* `file` is set for an external `<script src>`: its body keeps that file as
276
293
  * the origin of every node, so a `.js` script stays untyped and diagnostics
277
- * name the script, not the HTML page. */
278
- const scripts: Array<{ id: string; body: string; prelude: string[]; file?: string }> = [];
294
+ * name the script, not the HTML page. `untyped` marks an inline body that is
295
+ * JavaScript (the default) rather than `lang="ts"`. */
296
+ const scripts: Array<{ id: string; body: string; prelude: string[]; file?: string; untyped?: boolean }> = [];
279
297
  const imports: string[] = [];
280
298
  const lazyImports: string[] = [];
281
299
  const importedText = new Set<string>();
@@ -301,12 +319,18 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
301
319
  bound.add(name);
302
320
  }
303
321
  };
304
- const register = (compiled: CompiledModule, file?: string): string => {
322
+ const register = (compiled: CompiledModule, options?: { file?: string; untyped?: boolean }): string => {
305
323
  /* Hash the wrapped body, prelude included: the engine keys the registry by
306
324
  * id, so two scripts with the same statements but different deferred
307
325
  * imports must not collapse into one entry. */
308
326
  const id = hashString([...compiled.prelude, compiled.body].join("\n"));
309
- scripts.push({ id, body: compiled.body, prelude: compiled.prelude, ...(file ? { file } : {}) });
327
+ scripts.push({
328
+ id,
329
+ body: compiled.body,
330
+ prelude: compiled.prelude,
331
+ ...(options?.file ? { file: options.file } : {}),
332
+ ...(options?.untyped ? { untyped: true } : {}),
333
+ });
310
334
  return id;
311
335
  };
312
336
 
@@ -314,7 +338,9 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
314
338
  * would be dropped at runtime. Inline it (and its `@import`s) now. */
315
339
  const styles = inlineStylesheets(path, page);
316
340
  const html = styles.html.replace(SCRIPT_RE, (match, attributes: string, inlineBody: string) => {
317
- if (!isExecutable(attribute(attributes, "type"), attribute(attributes, "lang"))) return match;
341
+ const lang = attribute(attributes, "lang");
342
+ const type = attribute(attributes, "type");
343
+ if (!isExecutable(type, lang)) return match;
318
344
  const src = attribute(attributes, "src");
319
345
 
320
346
  if (src !== undefined && !URL_SPEC.test(src) && !src.startsWith("//")) {
@@ -322,9 +348,9 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
322
348
  if (!existsSync(scriptPath)) {
323
349
  throw new Error(`gui: <script src="${src}"> not found (looked for ${scriptPath})`);
324
350
  }
325
- const compiled = compileModuleSource(path, scriptPath, readFileSync(scriptPath, "utf8"), scripts.length);
351
+ const compiled = compileModuleSource(path, scriptPath, readSourceText(scriptPath), scripts.length);
326
352
  hoistImports(compiled, `<script src="${src}">`, `alias it in ${scriptPath}`);
327
- const id = register(compiled, scriptPath);
353
+ const id = register(compiled, { file: scriptPath });
328
354
  return `<script data-xt-id="${id}"></script>`;
329
355
  }
330
356
 
@@ -339,7 +365,7 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
339
365
  * where codegen cannot link its binding (TS5001). */
340
366
  const compiled = compileModuleSource(path, path, inlineBody, scripts.length);
341
367
  hoistImports(compiled, "inline <script>", "alias it");
342
- const id = register(compiled);
368
+ const id = register(compiled, { untyped: isPlainScript(type, lang) });
343
369
  return `<script data-xt-id="${id}"></script>`;
344
370
  });
345
371
 
@@ -348,14 +374,18 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
348
374
  /* Offset of the next part once joined with "\n", so a body's span in the
349
375
  * generated module can be reported back as the file it was copied from. */
350
376
  let offset = parts.reduce((total, part) => total + part.length + 1, 0);
351
- for (const { id, body, prelude, file } of scripts) {
377
+ for (const { id, body, prelude, file, untyped } of scripts) {
352
378
  const header = `function __xt_script_${id}(window: any, document: any): void {\n`;
353
379
  const preludeText = prelude.length > 0 ? `${prelude.join("\n")}\n` : "";
354
380
  const part =
355
381
  `${header}${preludeText}${body}\n}\n` + `__registerScript(${JSON.stringify(id)}, __xt_script_${id});`;
382
+ const bodyStart = offset + header.length + preludeText.length;
356
383
  if (file !== undefined) {
357
- const bodyStart = offset + header.length + preludeText.length;
358
384
  sourceRanges.push({ start: bodyStart, end: bodyStart + body.length, file });
385
+ } else if (untyped) {
386
+ /* An inline JavaScript body: its origin is the page itself, and the
387
+ * checker must treat it as untyped JavaScript, not as TypeScript. */
388
+ sourceRanges.push({ start: bodyStart, end: bodyStart + body.length, file: path, untyped: true });
359
389
  }
360
390
  parts.push(part);
361
391
  offset += part.length + 1;
@@ -66,6 +66,12 @@ const hostTypes = [
66
66
  "HTMLImageElement",
67
67
  "HTMLVideoElement",
68
68
  "HTMLAudioElement",
69
+ /* Media-source and offline-rendering types. `VideoFrame` is a real
70
+ * constructor value so `frame instanceof VideoFrame` is a safe `false`
71
+ * instead of a `TypeError`; `OfflineAudioContext` renders through the same
72
+ * mixer as `AudioContext`. */
73
+ "VideoFrame",
74
+ "OfflineAudioContext",
69
75
  "HTMLElement",
70
76
  "Element",
71
77
  "Node",
@@ -145,7 +151,7 @@ const hostTypes = [
145
151
  "GPUDeviceLostInfo",
146
152
  ] as const;
147
153
 
148
- const browserGlobals: Record<string, { symbol: string; argument?: string }> = {
154
+ const browserGlobals: Record<string, { symbol: string; argument?: string; member?: string }> = {
149
155
  window: { symbol: "xt_browser_window" },
150
156
  self: { symbol: "xt_browser_window" },
151
157
  document: { symbol: "xt_browser_document" },
@@ -154,8 +160,51 @@ const browserGlobals: Record<string, { symbol: string; argument?: string }> = {
154
160
  * by the SQLite `storage` link feature, so a page reaches them through core
155
161
  * rather than the engine's in-memory `window.localStorage` store. */
156
162
  __THREE_DEVTOOLS__: { symbol: "xt_browser_missing" },
163
+ /* Half-precision typed arrays exist in very new engines only, and the
164
+ * runtime has no 16-bit float element type. Answering `undefined` keeps
165
+ * feature probes (`typeof Float16Array < "u"`) on their fallback path instead
166
+ * of handing back a constructor that cannot hold data. */
167
+ Float16Array: { symbol: "xt_browser_missing" },
157
168
  createImageBitmap: { symbol: "xt_browser_create_image_bitmap" },
158
169
  };
170
+
171
+ /**
172
+ * Window members that a browser also exposes as bare globals.
173
+ *
174
+ * In a browser the global scope *is* the window, so `innerWidth`,
175
+ * `location.reload()` and `addEventListener("resize", …)` work without a
176
+ * `window.` prefix — pages and libraries (three.js probes `innerWidth`) rely on
177
+ * that. xbintsc has no global object here, so each name is declared as a member
178
+ * read of the window value: the read lowers to `xt_get(window, name)` and a
179
+ * call to `xt_call_method(window, name, …)`, which keeps getter-backed members
180
+ * live instead of capturing a value at startup.
181
+ */
182
+ const windowGlobals: readonly string[] = [
183
+ "innerWidth",
184
+ "innerHeight",
185
+ "outerWidth",
186
+ "outerHeight",
187
+ "devicePixelRatio",
188
+ "location",
189
+ "screen",
190
+ "scrollX",
191
+ "scrollY",
192
+ "addEventListener",
193
+ "removeEventListener",
194
+ "dispatchEvent",
195
+ "setTimeout",
196
+ "clearTimeout",
197
+ "setInterval",
198
+ "clearInterval",
199
+ "queueMicrotask",
200
+ "focus",
201
+ "blur",
202
+ "scrollTo",
203
+ "scrollBy",
204
+ ];
205
+ for (const member of windowGlobals) {
206
+ browserGlobals[member] = { symbol: "xt_browser_window", member };
207
+ }
159
208
  for (const type of hostTypes) {
160
209
  browserGlobals[type] = { symbol: "xt_browser_type", argument: type };
161
210
  }
@@ -38,6 +38,20 @@ export interface GlobalValue {
38
38
  readonly symbol: string;
39
39
  /** Passed as the only argument; omit to call the getter with none. */
40
40
  readonly argument?: string;
41
+ /**
42
+ * Read (and call) this global as a *member of the object `symbol` returns*
43
+ * instead of as the getter's own result.
44
+ *
45
+ * Browsers put `innerWidth`, `location` or `addEventListener` in the global
46
+ * scope because the global object *is* the window; xbintsc's globals are
47
+ * compiler-provided names with no global object behind them. Declaring
48
+ * `{ symbol: "xt_browser_window", member: "innerWidth" }` gives the name the
49
+ * browser semantics with the host object the extension already exposes: a
50
+ * read lowers to `xt_get(window, "innerWidth")` (getters run with the window
51
+ * as `this`, so the value is live rather than snapshotted at startup) and a
52
+ * call lowers to `xt_call_method(window, "addEventListener", …)`.
53
+ */
54
+ readonly member?: string;
41
55
  }
42
56
 
43
57
  /**
@@ -110,6 +124,12 @@ export interface AssetSourceRange {
110
124
  readonly start: number;
111
125
  readonly end: number;
112
126
  readonly file: string;
127
+ /**
128
+ * The copied source is plain JavaScript even though `file` is not a `.js`
129
+ * file (an inline `<script>` body in an HTML page). Nodes inside the span
130
+ * then skip the type checker, exactly like an external `.js` script.
131
+ */
132
+ readonly untyped?: boolean;
113
133
  }
114
134
 
115
135
  /** Rewrites an imported file (selected by extension) into a TS module. */
@@ -32,7 +32,7 @@ import {
32
32
  binaryPrecedence,
33
33
  prefixUnaryOperator,
34
34
  } from "./operators.js";
35
- import { isAssignmentTarget } from "./helpers.js";
35
+ import { endsExpression, isAssignmentTarget } from "./helpers.js";
36
36
  import { SpeculationError } from "./speculation.js";
37
37
  import type { Parser } from "./parser.js";
38
38
 
@@ -284,7 +284,7 @@ export const expressionMethods: ExpressionMethods = {
284
284
  this.nextToken();
285
285
  delegate = true;
286
286
  }
287
- if (!this.canInsertSemicolon() && !this.at(TokenKind.Semicolon) && !this.at(TokenKind.CloseParen)) {
287
+ if (!this.canInsertSemicolon() && !endsExpression(this.token.kind)) {
288
288
  expression = this.parseAssignmentExpression();
289
289
  }
290
290
  return { kind: SyntaxKind.YieldExpression, expression, delegate, start: token.start, end: expression?.end ?? token.end };
@@ -3,8 +3,30 @@
3
3
  */
4
4
 
5
5
  import { SyntaxKind } from "../ast/kinds.js";
6
+ import { TokenKind } from "../lexer/token.js";
6
7
  import type { Expression, PropertyName } from "../ast/nodes.js";
7
8
 
9
+ /**
10
+ * Whether a token can never begin an expression, so an operand-optional prefix
11
+ * operator (`yield`, `return`) placed before it has no operand. `yield, x` and
12
+ * `[yield]` are the common minified shapes: `yield` on its own is a valid
13
+ * expression, and a comma or a closing bracket ends it.
14
+ */
15
+ export function endsExpression(kind: TokenKind): boolean {
16
+ switch (kind) {
17
+ case TokenKind.Comma:
18
+ case TokenKind.Semicolon:
19
+ case TokenKind.Colon:
20
+ case TokenKind.CloseParen:
21
+ case TokenKind.CloseBracket:
22
+ case TokenKind.CloseBrace:
23
+ case TokenKind.EndOfFile:
24
+ return true;
25
+ default:
26
+ return false;
27
+ }
28
+ }
29
+
8
30
  export function expressionToPropertyName(expr: Expression): PropertyName | undefined {
9
31
  switch (expr.kind) {
10
32
  case SyntaxKind.StringLiteral: