xbintsc 0.6.28 → 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 (540) hide show
  1. package/dist/src/ast/common.d.ts +10 -0
  2. package/dist/src/binder/declarations.d.ts +1 -0
  3. package/dist/src/binder/declarations.js +37 -0
  4. package/dist/src/binder/declarations.js.map +1 -1
  5. package/dist/src/binder/references.js +12 -0
  6. package/dist/src/binder/references.js.map +1 -1
  7. package/dist/src/checker/globals.js +1 -0
  8. package/dist/src/checker/globals.js.map +1 -1
  9. package/dist/src/checker/source.js +4 -0
  10. package/dist/src/checker/source.js.map +1 -1
  11. package/dist/src/checker/type-system.d.ts +5 -0
  12. package/dist/src/checker/type-system.js +22 -3
  13. package/dist/src/checker/type-system.js.map +1 -1
  14. package/dist/src/cli/help.d.ts +1 -1
  15. package/dist/src/cli/main.js +15 -3
  16. package/dist/src/cli/main.js.map +1 -1
  17. package/dist/src/codegen/generator/calls/access.js +29 -11
  18. package/dist/src/codegen/generator/calls/access.js.map +1 -1
  19. package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
  20. package/dist/src/codegen/generator/calls/element-inline.js +388 -0
  21. package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
  22. package/dist/src/codegen/generator/calls/invocation.js +95 -1
  23. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  24. package/dist/src/codegen/generator/calls/super.js +3 -4
  25. package/dist/src/codegen/generator/calls/super.js.map +1 -1
  26. package/dist/src/codegen/generator/calls/unwrap.d.ts +18 -0
  27. package/dist/src/codegen/generator/calls/unwrap.js +45 -0
  28. package/dist/src/codegen/generator/calls/unwrap.js.map +1 -0
  29. package/dist/src/codegen/generator/calls.d.ts +3 -1
  30. package/dist/src/codegen/generator/calls.js +3 -1
  31. package/dist/src/codegen/generator/calls.js.map +1 -1
  32. package/dist/src/codegen/generator/debug.js +20 -3
  33. package/dist/src/codegen/generator/debug.js.map +1 -1
  34. package/dist/src/codegen/generator/expressions/assignment.js +24 -2
  35. package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
  36. package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
  37. package/dist/src/codegen/generator/expressions/global-values.js +49 -0
  38. package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
  39. package/dist/src/codegen/generator/expressions/module-values.d.ts +6 -0
  40. package/dist/src/codegen/generator/expressions/module-values.js +51 -17
  41. package/dist/src/codegen/generator/expressions/module-values.js.map +1 -1
  42. package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
  43. package/dist/src/codegen/generator/expressions/primary.js +13 -29
  44. package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
  45. package/dist/src/codegen/generator/expressions.d.ts +2 -1
  46. package/dist/src/codegen/generator/expressions.js +2 -1
  47. package/dist/src/codegen/generator/expressions.js.map +1 -1
  48. package/dist/src/codegen/generator/generator.js +4 -0
  49. package/dist/src/codegen/generator/generator.js.map +1 -1
  50. package/dist/src/codegen/generator/layout.d.ts +65 -0
  51. package/dist/src/codegen/generator/layout.js +50 -0
  52. package/dist/src/codegen/generator/layout.js.map +1 -0
  53. package/dist/src/codegen/generator/lookup-tables.d.ts +22 -0
  54. package/dist/src/codegen/generator/lookup-tables.js +48 -0
  55. package/dist/src/codegen/generator/lookup-tables.js.map +1 -0
  56. package/dist/src/codegen/generator/module.js +38 -7
  57. package/dist/src/codegen/generator/module.js.map +1 -1
  58. package/dist/src/codegen/generator/state.js +21 -0
  59. package/dist/src/codegen/generator/state.js.map +1 -1
  60. package/dist/src/codegen/generator/tables.d.ts +2 -6
  61. package/dist/src/codegen/generator/tables.js +18 -12
  62. package/dist/src/codegen/generator/tables.js.map +1 -1
  63. package/dist/src/diagnostics/diagnostic.js +1 -1
  64. package/dist/src/diagnostics/diagnostic.js.map +1 -1
  65. package/dist/src/diagnostics/source-text.d.ts +37 -9
  66. package/dist/src/diagnostics/source-text.js +124 -23
  67. package/dist/src/diagnostics/source-text.js.map +1 -1
  68. package/dist/src/diagnostics/source.d.ts +16 -6
  69. package/dist/src/diagnostics/source.js +25 -4
  70. package/dist/src/diagnostics/source.js.map +1 -1
  71. package/dist/src/driver/build-key.d.ts +14 -0
  72. package/dist/src/driver/build-key.js +6 -1
  73. package/dist/src/driver/build-key.js.map +1 -1
  74. package/dist/src/driver/bundler/commonjs.d.ts +9 -2
  75. package/dist/src/driver/bundler/commonjs.js +11 -4
  76. package/dist/src/driver/bundler/commonjs.js.map +1 -1
  77. package/dist/src/driver/bundler/concatenate.d.ts +20 -0
  78. package/dist/src/driver/bundler/concatenate.js +79 -8
  79. package/dist/src/driver/bundler/concatenate.js.map +1 -1
  80. package/dist/src/driver/bundler/deferred.d.ts +29 -1
  81. package/dist/src/driver/bundler/deferred.js +114 -5
  82. package/dist/src/driver/bundler/deferred.js.map +1 -1
  83. package/dist/src/driver/bundler/dynamic-import.d.ts +6 -0
  84. package/dist/src/driver/bundler/dynamic-import.js +59 -3
  85. package/dist/src/driver/bundler/dynamic-import.js.map +1 -1
  86. package/dist/src/driver/bundler/graph.d.ts +13 -0
  87. package/dist/src/driver/bundler/graph.js +4 -4
  88. package/dist/src/driver/bundler/graph.js.map +1 -1
  89. package/dist/src/driver/bundler/merge.js +43 -13
  90. package/dist/src/driver/bundler/merge.js.map +1 -1
  91. package/dist/src/driver/bundler/namespace-object.d.ts +11 -0
  92. package/dist/src/driver/bundler/namespace-object.js +32 -0
  93. package/dist/src/driver/bundler/namespace-object.js.map +1 -1
  94. package/dist/src/driver/bundler/reexport-resolution.js +11 -2
  95. package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
  96. package/dist/src/driver/bundler/symbols.d.ts +4 -0
  97. package/dist/src/driver/bundler/symbols.js +14 -1
  98. package/dist/src/driver/bundler/symbols.js.map +1 -1
  99. package/dist/src/driver/compiler.js +13 -3
  100. package/dist/src/driver/compiler.js.map +1 -1
  101. package/dist/src/driver/config.d.ts +1 -1
  102. package/dist/src/driver/frontend.js +3 -4
  103. package/dist/src/driver/frontend.js.map +1 -1
  104. package/dist/src/driver/options.d.ts +1 -4
  105. package/dist/src/driver/runtime-lib.d.ts +27 -0
  106. package/dist/src/driver/runtime-lib.js +78 -2
  107. package/dist/src/driver/runtime-lib.js.map +1 -1
  108. package/dist/src/driver/runtime-objects.d.ts +1 -1
  109. package/dist/src/driver/runtime-objects.js +28 -5
  110. package/dist/src/driver/runtime-objects.js.map +1 -1
  111. package/dist/src/driver/toolchain.js +28 -5
  112. package/dist/src/driver/toolchain.js.map +1 -1
  113. package/dist/src/driver/version.d.ts +1 -1
  114. package/dist/src/driver/version.js +1 -1
  115. package/dist/src/driver/version.js.map +1 -1
  116. package/dist/src/extensions/gui/html.js +42 -10
  117. package/dist/src/extensions/gui/html.js.map +1 -1
  118. package/dist/src/extensions/gui/index.js +48 -0
  119. package/dist/src/extensions/gui/index.js.map +1 -1
  120. package/dist/src/extensions/node/buffer/index.d.ts +5 -4
  121. package/dist/src/extensions/node/buffer/index.js +5 -4
  122. package/dist/src/extensions/node/buffer/index.js.map +1 -1
  123. package/dist/src/extensions/node/events/index.js +8 -1
  124. package/dist/src/extensions/node/events/index.js.map +1 -1
  125. package/dist/src/extensions/node/fs/callbacks.d.ts +9 -0
  126. package/dist/src/extensions/node/fs/callbacks.js +42 -0
  127. package/dist/src/extensions/node/fs/callbacks.js.map +1 -0
  128. package/dist/src/extensions/node/fs/index.d.ts +2 -3
  129. package/dist/src/extensions/node/fs/index.js +11 -4
  130. package/dist/src/extensions/node/fs/index.js.map +1 -1
  131. package/dist/src/extensions/node/process/index.d.ts +10 -3
  132. package/dist/src/extensions/node/process/index.js +30 -5
  133. package/dist/src/extensions/node/process/index.js.map +1 -1
  134. package/dist/src/extensions/registry.d.ts +27 -0
  135. package/dist/src/extensions/registry.js +13 -4
  136. package/dist/src/extensions/registry.js.map +1 -1
  137. package/dist/src/lexer/scanner.d.ts +7 -1
  138. package/dist/src/lexer/scanner.js +15 -0
  139. package/dist/src/lexer/scanner.js.map +1 -1
  140. package/dist/src/parser/context.d.ts +10 -0
  141. package/dist/src/parser/context.js +42 -3
  142. package/dist/src/parser/context.js.map +1 -1
  143. package/dist/src/parser/expressions.js +2 -2
  144. package/dist/src/parser/expressions.js.map +1 -1
  145. package/dist/src/parser/helpers.d.ts +8 -0
  146. package/dist/src/parser/helpers.js +21 -0
  147. package/dist/src/parser/helpers.js.map +1 -1
  148. package/dist/src/parser/literals.js +6 -2
  149. package/dist/src/parser/literals.js.map +1 -1
  150. package/dist/tests/binder/binder.test.js +43 -0
  151. package/dist/tests/binder/binder.test.js.map +1 -1
  152. package/dist/tests/cli/main.test.js +9 -0
  153. package/dist/tests/cli/main.test.js.map +1 -1
  154. package/dist/tests/codegen/element-layout.test.d.ts +19 -0
  155. package/dist/tests/codegen/element-layout.test.js +80 -0
  156. package/dist/tests/codegen/element-layout.test.js.map +1 -0
  157. package/dist/tests/codegen/expressions.test.js +25 -0
  158. package/dist/tests/codegen/expressions.test.js.map +1 -1
  159. package/dist/tests/codegen/llvm.test.js +28 -0
  160. package/dist/tests/codegen/llvm.test.js.map +1 -1
  161. package/dist/tests/diagnostics/diagnostic.test.js +9 -0
  162. package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
  163. package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
  164. package/dist/tests/diagnostics/source-text.test.js +50 -0
  165. package/dist/tests/diagnostics/source-text.test.js.map +1 -0
  166. package/dist/tests/diagnostics/source.test.js +17 -0
  167. package/dist/tests/diagnostics/source.test.js.map +1 -1
  168. package/dist/tests/driver/build-key.test.d.ts +1 -0
  169. package/dist/tests/driver/build-key.test.js +49 -0
  170. package/dist/tests/driver/build-key.test.js.map +1 -0
  171. package/dist/tests/driver/bundler-resolve.test.js +12 -0
  172. package/dist/tests/driver/bundler-resolve.test.js.map +1 -1
  173. package/dist/tests/driver/commonjs-prelude.test.d.ts +11 -0
  174. package/dist/tests/driver/commonjs-prelude.test.js +69 -0
  175. package/dist/tests/driver/commonjs-prelude.test.js.map +1 -0
  176. package/dist/tests/driver/compiler.test.js +42 -1
  177. package/dist/tests/driver/compiler.test.js.map +1 -1
  178. package/dist/tests/driver/html-deferred-cycles.test.d.ts +10 -0
  179. package/dist/tests/driver/html-deferred-cycles.test.js +75 -0
  180. package/dist/tests/driver/html-deferred-cycles.test.js.map +1 -0
  181. package/dist/tests/driver/namespace-type-exports.test.d.ts +9 -0
  182. package/dist/tests/driver/namespace-type-exports.test.js +59 -0
  183. package/dist/tests/driver/namespace-type-exports.test.js.map +1 -0
  184. package/dist/tests/driver/runtime-lib.test.js +49 -1
  185. package/dist/tests/driver/runtime-lib.test.js.map +1 -1
  186. package/dist/tests/driver/toolchain.test.js +8 -1
  187. package/dist/tests/driver/toolchain.test.js.map +1 -1
  188. package/dist/tests/driver/usage.test.js +2 -1
  189. package/dist/tests/driver/usage.test.js.map +1 -1
  190. package/dist/tests/e2e/async-await.test.js +16 -0
  191. package/dist/tests/e2e/async-await.test.js.map +1 -1
  192. package/dist/tests/e2e/compile-basics.test.js +53 -0
  193. package/dist/tests/e2e/compile-basics.test.js.map +1 -1
  194. package/dist/tests/e2e/compile-builtins.test.js +29 -0
  195. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  196. package/dist/tests/e2e/compile-deferred-marker.test.d.ts +14 -0
  197. package/dist/tests/e2e/compile-deferred-marker.test.js +68 -0
  198. package/dist/tests/e2e/compile-deferred-marker.test.js.map +1 -0
  199. package/dist/tests/e2e/compile-deferred-reexport.test.d.ts +12 -0
  200. package/dist/tests/e2e/compile-deferred-reexport.test.js +89 -0
  201. package/dist/tests/e2e/compile-deferred-reexport.test.js.map +1 -0
  202. package/dist/tests/e2e/compile-error-module.test.d.ts +9 -0
  203. package/dist/tests/e2e/compile-error-module.test.js +29 -0
  204. package/dist/tests/e2e/compile-error-module.test.js.map +1 -0
  205. package/dist/tests/e2e/compile-gc-promises.test.d.ts +11 -0
  206. package/dist/tests/e2e/compile-gc-promises.test.js +52 -0
  207. package/dist/tests/e2e/compile-gc-promises.test.js.map +1 -0
  208. package/dist/tests/e2e/compile-modules.test.js +53 -0
  209. package/dist/tests/e2e/compile-modules.test.js.map +1 -1
  210. package/dist/tests/e2e/compile-node-fs-callbacks.test.d.ts +6 -0
  211. package/dist/tests/e2e/compile-node-fs-callbacks.test.js +46 -0
  212. package/dist/tests/e2e/compile-node-fs-callbacks.test.js.map +1 -0
  213. package/dist/tests/e2e/compile-node-inheritance.test.d.ts +6 -0
  214. package/dist/tests/e2e/compile-node-inheritance.test.js +48 -0
  215. package/dist/tests/e2e/compile-node-inheritance.test.js.map +1 -0
  216. package/dist/tests/e2e/compile-node-require.test.d.ts +9 -0
  217. package/dist/tests/e2e/compile-node-require.test.js +29 -0
  218. package/dist/tests/e2e/compile-node-require.test.js.map +1 -0
  219. package/dist/tests/e2e/compile-node-stats.test.d.ts +8 -0
  220. package/dist/tests/e2e/compile-node-stats.test.js +26 -0
  221. package/dist/tests/e2e/compile-node-stats.test.js.map +1 -0
  222. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
  223. package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
  224. package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
  225. package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
  226. package/dist/tests/e2e/compile-proxy.test.d.ts +6 -0
  227. package/dist/tests/e2e/compile-proxy.test.js +66 -0
  228. package/dist/tests/e2e/compile-proxy.test.js.map +1 -0
  229. package/dist/tests/e2e/compile-web-globals.test.d.ts +6 -0
  230. package/dist/tests/e2e/compile-web-globals.test.js +94 -0
  231. package/dist/tests/e2e/compile-web-globals.test.js.map +1 -0
  232. package/dist/tests/e2e/differential-language.test.js +25 -0
  233. package/dist/tests/e2e/differential-language.test.js.map +1 -1
  234. package/dist/tests/e2e/differential-values.test.js +59 -0
  235. package/dist/tests/e2e/differential-values.test.js.map +1 -1
  236. package/dist/tests/e2e/fetch.test.js +1 -1
  237. package/dist/tests/e2e/gc.test.js +22 -0
  238. package/dist/tests/e2e/gc.test.js.map +1 -1
  239. package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
  240. package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
  241. package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
  242. package/dist/tests/e2e/gui-browser.test.js +35 -2
  243. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  244. package/dist/tests/e2e/gui-dom.test.js +88 -0
  245. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  246. package/dist/tests/e2e/gui-script-import-order.test.js +24 -0
  247. package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
  248. package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
  249. package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
  250. package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
  251. package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
  252. package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
  253. package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
  254. package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
  255. package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
  256. package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
  257. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
  258. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
  259. package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
  260. package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
  261. package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
  262. package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
  263. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
  264. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
  265. package/dist/tests/e2e/gui-webgl2.test.js +59 -1
  266. package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
  267. package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
  268. package/dist/tests/e2e/hang-watchdog.test.js +50 -0
  269. package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
  270. package/dist/tests/e2e/json-stringify-to-json.test.d.ts +10 -0
  271. package/dist/tests/e2e/json-stringify-to-json.test.js +61 -0
  272. package/dist/tests/e2e/json-stringify-to-json.test.js.map +1 -0
  273. package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
  274. package/dist/tests/e2e/method-call-cache.test.js +65 -0
  275. package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
  276. package/dist/tests/e2e/node-process.test.d.ts +7 -0
  277. package/dist/tests/e2e/node-process.test.js +50 -0
  278. package/dist/tests/e2e/node-process.test.js.map +1 -0
  279. package/dist/tests/e2e/performance-now.test.d.ts +9 -0
  280. package/dist/tests/e2e/performance-now.test.js +36 -0
  281. package/dist/tests/e2e/performance-now.test.js.map +1 -0
  282. package/dist/tests/e2e/property-ic.test.js +33 -0
  283. package/dist/tests/e2e/property-ic.test.js.map +1 -1
  284. package/dist/tests/e2e/runtime-coverage-buffer.test.js +31 -0
  285. package/dist/tests/e2e/runtime-coverage-buffer.test.js.map +1 -1
  286. package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
  287. package/dist/tests/e2e/shape-interning.test.js +55 -0
  288. package/dist/tests/e2e/shape-interning.test.js.map +1 -0
  289. package/dist/tests/e2e/string-utf16.test.js +9 -0
  290. package/dist/tests/e2e/string-utf16.test.js.map +1 -1
  291. package/dist/tests/e2e/typed-array-views.test.js +26 -0
  292. package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
  293. package/dist/tests/e2e/url-search-params.test.js +19 -0
  294. package/dist/tests/e2e/url-search-params.test.js.map +1 -1
  295. package/dist/tests/e2e/web-streams.test.js +44 -29
  296. package/dist/tests/e2e/web-streams.test.js.map +1 -1
  297. package/dist/tests/extensions/gui.test.js +16 -1
  298. package/dist/tests/extensions/gui.test.js.map +1 -1
  299. package/dist/tests/helpers.js +1 -0
  300. package/dist/tests/helpers.js.map +1 -1
  301. package/dist/tests/parser/expressions.test.js +36 -0
  302. package/dist/tests/parser/expressions.test.js.map +1 -1
  303. package/dist/tests/parser/literals.test.js +19 -0
  304. package/dist/tests/parser/literals.test.js.map +1 -1
  305. package/dist/tests/parser/statements.test.js +13 -0
  306. package/dist/tests/parser/statements.test.js.map +1 -1
  307. package/doc/ai/cli.md +1 -0
  308. package/doc/ai/contributing.md +8 -5
  309. package/doc/ai/extensions.md +12 -3
  310. package/doc/ai/language-support.md +2 -1
  311. package/doc/ai/troubleshooting.md +14 -0
  312. package/doc/ai/zh-CN/cli.md +1 -0
  313. package/doc/ai/zh-CN/contributing.md +6 -3
  314. package/doc/ai/zh-CN/extensions.md +10 -2
  315. package/doc/ai/zh-CN/language-support.md +2 -1
  316. package/doc/ai/zh-CN/troubleshooting.md +12 -0
  317. package/doc/gui/api.md +26 -4
  318. package/doc/gui/dom.md +8 -0
  319. package/doc/gui/known-issues.md +35 -6
  320. package/doc/gui/runtime.md +16 -1
  321. package/doc/gui/webgl.md +97 -26
  322. package/doc/gui-scripts.md +2 -1
  323. package/doc/gui.md +8 -5
  324. package/doc/implemented/binder.md +2 -1
  325. package/doc/implemented/checker.md +14 -0
  326. package/doc/implemented/codegen.md +7 -0
  327. package/doc/implemented/lexer.md +1 -1
  328. package/doc/implemented/modules.md +23 -1
  329. package/doc/implemented/node/buffer.md +18 -5
  330. package/doc/implemented/node/fs.md +22 -1
  331. package/doc/implemented/node/process.md +65 -5
  332. package/doc/implemented/node.md +7 -1
  333. package/doc/implemented/operators.md +3 -1
  334. package/doc/implemented/parser.md +3 -2
  335. package/doc/implemented/runtime-core.md +13 -2
  336. package/doc/implemented/stdlib.md +79 -4
  337. package/doc/implemented/typed-arrays.md +18 -2
  338. package/doc/unimplemented/classes.md +1 -0
  339. package/doc/unimplemented/modules.md +1 -0
  340. package/doc/unimplemented/stdlib.md +2 -1
  341. package/doc/xbintsc.config.schema.json +5 -0
  342. package/doc/zh-CN/gui/api.md +19 -5
  343. package/doc/zh-CN/gui/dom.md +6 -0
  344. package/doc/zh-CN/gui/known-issues.md +24 -5
  345. package/doc/zh-CN/gui/runtime.md +13 -1
  346. package/doc/zh-CN/gui/webgl.md +20 -7
  347. package/doc/zh-CN/gui-scripts.md +2 -1
  348. package/doc/zh-CN/gui.md +4 -1
  349. package/doc/zh-CN/implemented/binder.md +2 -1
  350. package/doc/zh-CN/implemented/checker.md +10 -0
  351. package/doc/zh-CN/implemented/codegen.md +7 -0
  352. package/doc/zh-CN/implemented/lexer.md +1 -1
  353. package/doc/zh-CN/implemented/modules.md +17 -1
  354. package/doc/zh-CN/implemented/node/buffer.md +3 -1
  355. package/doc/zh-CN/implemented/node/fs.md +19 -1
  356. package/doc/zh-CN/implemented/node/process.md +59 -5
  357. package/doc/zh-CN/implemented/node.md +1 -1
  358. package/doc/zh-CN/implemented/operators.md +2 -1
  359. package/doc/zh-CN/implemented/parser.md +3 -2
  360. package/doc/zh-CN/implemented/runtime-core.md +10 -2
  361. package/doc/zh-CN/implemented/stdlib.md +64 -4
  362. package/doc/zh-CN/implemented/typed-arrays.md +14 -2
  363. package/doc/zh-CN/unimplemented/classes.md +1 -0
  364. package/doc/zh-CN/unimplemented/modules.md +1 -0
  365. package/doc/zh-CN/unimplemented/stdlib.md +2 -1
  366. package/package.json +7 -7
  367. package/runtime/ext_gui/audio.cpp +39 -3
  368. package/runtime/ext_gui/audio_extra.cpp +353 -0
  369. package/runtime/ext_gui/audio_extra.h +47 -0
  370. package/runtime/ext_gui/audio_fft.h +76 -0
  371. package/runtime/ext_gui/audio_internal.h +21 -0
  372. package/runtime/ext_gui/audio_mixer.cpp +46 -1
  373. package/runtime/ext_gui/audio_mixer.h +89 -1
  374. package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
  375. package/runtime/ext_gui/audio_nodes.cpp +242 -0
  376. package/runtime/ext_gui/audio_nodes_internal.h +81 -0
  377. package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
  378. package/runtime/ext_gui/browser.cpp +9 -0
  379. package/runtime/ext_gui/browser_screen.cpp +73 -0
  380. package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
  381. package/runtime/ext_gui/dom_api_internal.h +3 -0
  382. package/runtime/ext_gui/dom_api_node.cpp +21 -0
  383. package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
  384. package/runtime/ext_gui/dom_api_proto.cpp +3 -0
  385. package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
  386. package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
  387. package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
  388. package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
  389. package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
  390. package/runtime/ext_gui/dom_api_webgl_state.cpp +4 -2
  391. package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
  392. package/runtime/ext_gui/gui.cpp +6 -1
  393. package/runtime/ext_gui/gui_engine.h +2 -0
  394. package/runtime/ext_gui/gui_events.cpp +13 -8
  395. package/runtime/ext_gui/gui_webgl.cpp +3 -2
  396. package/runtime/ext_gui/style_ua.cpp +4 -0
  397. package/runtime/ext_gui/warnings.cpp +1 -1
  398. package/runtime/ext_gui/webgl.h +102 -7
  399. package/runtime/ext_gui/webgl_api.h +3 -2
  400. package/runtime/ext_gui/webgl_blit.cpp +109 -15
  401. package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
  402. package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
  403. package/runtime/ext_gui/webgl_buffer.cpp +20 -170
  404. package/runtime/ext_gui/webgl_context.cpp +117 -169
  405. package/runtime/ext_gui/webgl_draw.cpp +116 -5
  406. package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
  407. package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
  408. package/runtime/ext_gui/webgl_draw_state.h +2 -0
  409. package/runtime/ext_gui/webgl_feature.cpp +2 -2
  410. package/runtime/ext_gui/webgl_feature.h +4 -3
  411. package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
  412. package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
  413. package/runtime/ext_gui/webgl_objects.h +16 -2
  414. package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
  415. package/runtime/ext_gui/webgl_state.cpp +45 -36
  416. package/runtime/ext_gui/webgl_targets.cpp +440 -0
  417. package/runtime/ext_gui/webgl_texture.cpp +81 -25
  418. package/runtime/ext_gui/window.cpp +8 -0
  419. package/runtime/ext_node/buffer/buffer.c +5 -4
  420. package/runtime/ext_node/buffer/parts/byte-access.inc +115 -11
  421. package/runtime/ext_node/buffer/parts/prototype.inc +4 -1
  422. package/runtime/ext_node/events/events.c +9 -0
  423. package/runtime/ext_node/fs/callbacks.c +138 -0
  424. package/runtime/ext_node/fs/fs_ops.c +28 -15
  425. package/runtime/ext_node/module/module.c +18 -9
  426. package/runtime/ext_node/process/process.c +117 -32
  427. package/runtime/ext_node/process/streams.c +370 -0
  428. package/runtime/ext_node/process/streams.h +20 -0
  429. package/runtime/rt.h +63 -27
  430. package/runtime/rt_binary.h +44 -0
  431. package/runtime/rt_internal.h +61 -69
  432. package/runtime/rt_object.h +83 -0
  433. package/runtime/rt_profile.h +45 -0
  434. package/runtime/xt_alloc.c +154 -181
  435. package/runtime/xt_array_buffer.c +99 -71
  436. package/runtime/xt_async_io.c +3 -0
  437. package/runtime/xt_builtins.c +29 -24
  438. package/runtime/xt_constructors.c +102 -2
  439. package/runtime/xt_containers/access.inc +125 -12
  440. package/runtime/xt_containers/arrays.inc +2 -1
  441. package/runtime/xt_containers/cstr_cache.inc +56 -0
  442. package/runtime/xt_containers/function_prototypes.inc +58 -0
  443. package/runtime/xt_containers/method_cache.inc +121 -0
  444. package/runtime/xt_containers/object_keys.inc +58 -0
  445. package/runtime/xt_containers/objects.inc +59 -75
  446. package/runtime/xt_containers/shapes.inc +153 -8
  447. package/runtime/xt_containers.c +5 -0
  448. package/runtime/xt_exit.c +34 -0
  449. package/runtime/xt_fetch/headers.inc +1 -0
  450. package/runtime/xt_fetch/response.inc +28 -8
  451. package/runtime/xt_fetch/webapi.inc +82 -0
  452. package/runtime/xt_fetch.c +5 -0
  453. package/runtime/xt_gc_release.c +70 -0
  454. package/runtime/xt_gc_stack.c +83 -0
  455. package/runtime/xt_gc_verify.c +136 -0
  456. package/runtime/xt_intl.c +224 -0
  457. package/runtime/xt_io/console.inc +66 -0
  458. package/runtime/xt_io/exception.inc +66 -1
  459. package/runtime/xt_io/watchdog.inc +101 -0
  460. package/runtime/xt_io.c +1 -0
  461. package/runtime/xt_loop.c +23 -3
  462. package/runtime/xt_module_values.c +82 -0
  463. package/runtime/xt_pool.c +151 -0
  464. package/runtime/xt_profile.c +126 -0
  465. package/runtime/xt_proxy.c +140 -0
  466. package/runtime/xt_stdlib/dispatch.inc +104 -9
  467. package/runtime/xt_stdlib/math.inc +272 -57
  468. package/runtime/xt_stdlib2/date.inc +7 -1
  469. package/runtime/xt_stdlib2/json.inc +28 -0
  470. package/runtime/xt_stdlib2/json_stringify.inc +71 -55
  471. package/runtime/xt_stdlib2/regexp-match.inc +17 -0
  472. package/runtime/xt_storage/indexed_db.c +4 -1
  473. package/runtime/xt_structured_clone.c +2 -1
  474. package/runtime/xt_typed_array/construction.inc +10 -0
  475. package/runtime/xt_typed_array/elements.inc +43 -23
  476. package/runtime/xt_url.c +50 -0
  477. package/runtime/xt_values/constructors.inc +4 -1
  478. package/runtime/xt_values/strings.inc +3 -1
  479. package/runtime/xt_web.h +27 -0
  480. package/runtime/xt_web_abort.c +373 -0
  481. package/scripts/build-runtime.ts +8 -0
  482. package/src/ast/common.ts +10 -0
  483. package/src/binder/declarations.ts +34 -0
  484. package/src/binder/references.ts +12 -0
  485. package/src/checker/globals.ts +1 -0
  486. package/src/checker/source.ts +3 -0
  487. package/src/checker/type-system.ts +23 -3
  488. package/src/cli/main.ts +14 -3
  489. package/src/codegen/generator/calls/access.ts +28 -10
  490. package/src/codegen/generator/calls/element-inline.ts +433 -0
  491. package/src/codegen/generator/calls/invocation.ts +99 -1
  492. package/src/codegen/generator/calls/super.ts +5 -4
  493. package/src/codegen/generator/calls/unwrap.ts +47 -0
  494. package/src/codegen/generator/calls.ts +5 -0
  495. package/src/codegen/generator/debug.ts +21 -3
  496. package/src/codegen/generator/expressions/assignment.ts +26 -2
  497. package/src/codegen/generator/expressions/global-values.ts +57 -0
  498. package/src/codegen/generator/expressions/module-values.ts +57 -19
  499. package/src/codegen/generator/expressions/primary.ts +13 -36
  500. package/src/codegen/generator/expressions.ts +3 -0
  501. package/src/codegen/generator/generator.ts +4 -0
  502. package/src/codegen/generator/layout.ts +54 -0
  503. package/src/codegen/generator/lookup-tables.ts +63 -0
  504. package/src/codegen/generator/module.ts +38 -7
  505. package/src/codegen/generator/state.ts +22 -0
  506. package/src/codegen/generator/tables.ts +18 -12
  507. package/src/diagnostics/diagnostic.ts +1 -1
  508. package/src/diagnostics/source-text.ts +118 -22
  509. package/src/diagnostics/source.ts +29 -7
  510. package/src/driver/build-key.ts +21 -1
  511. package/src/driver/bundler/commonjs.ts +12 -5
  512. package/src/driver/bundler/concatenate.ts +96 -12
  513. package/src/driver/bundler/deferred.ts +122 -6
  514. package/src/driver/bundler/dynamic-import.ts +75 -2
  515. package/src/driver/bundler/graph.ts +4 -4
  516. package/src/driver/bundler/merge.ts +42 -9
  517. package/src/driver/bundler/namespace-object.ts +44 -0
  518. package/src/driver/bundler/reexport-resolution.ts +14 -2
  519. package/src/driver/bundler/symbols.ts +17 -0
  520. package/src/driver/compiler.ts +14 -3
  521. package/src/driver/config.ts +1 -1
  522. package/src/driver/frontend.ts +3 -4
  523. package/src/driver/options.ts +1 -4
  524. package/src/driver/runtime-lib.ts +87 -2
  525. package/src/driver/runtime-objects.ts +28 -5
  526. package/src/driver/toolchain.ts +28 -5
  527. package/src/driver/version.ts +1 -1
  528. package/src/extensions/gui/html.ts +41 -11
  529. package/src/extensions/gui/index.ts +50 -1
  530. package/src/extensions/node/buffer/index.ts +5 -4
  531. package/src/extensions/node/events/index.ts +8 -1
  532. package/src/extensions/node/fs/callbacks.ts +45 -0
  533. package/src/extensions/node/fs/index.ts +11 -4
  534. package/src/extensions/node/process/index.ts +30 -5
  535. package/src/extensions/registry.ts +41 -4
  536. package/src/lexer/scanner.ts +16 -1
  537. package/src/parser/context.ts +39 -3
  538. package/src/parser/expressions.ts +2 -2
  539. package/src/parser/helpers.ts +22 -0
  540. package/src/parser/literals.ts +6 -2
@@ -39,6 +39,21 @@ function escapeMetadata(text: string): string {
39
39
  return escapeBytes(utf8Bytes(text));
40
40
  }
41
41
 
42
+ /**
43
+ * DWARF/Verifier limits for `!DILocation`. The column is a 16-bit field, so a
44
+ * minified source line (`<script>` bundles are routinely 60–80k columns wide)
45
+ * makes the verifier reject the whole module. The line has its own, larger
46
+ * limit; clamp both rather than failing the build: a debug location is a
47
+ * best-effort hint, and a wrong-but-valid one still points at the statement.
48
+ */
49
+ const MAX_DEBUG_LINE = 0xffffff;
50
+ const MAX_DEBUG_COLUMN = 0xffff;
51
+
52
+ function clampDebugPosition(value: number, limit: number): number {
53
+ if (!Number.isFinite(value) || value < 0) return 0;
54
+ return Math.min(Math.floor(value), limit);
55
+ }
56
+
42
57
  /**
43
58
  * Create the compile unit and module flags once. LLVM requires the `Debug Info
44
59
  * Version` flag for any `!dbg` attachment, and clang only emits DWARF/CodeView
@@ -97,10 +112,11 @@ export const debugMethods: DebugMethods = {
97
112
  : fn.isConstructor && fn.classInfo
98
113
  ? `new ${this.displayNameOf(fn.classInfo.name)}`
99
114
  : this.displayNameOf(fn.name.length > 0 ? fn.name : "anonymous");
115
+ const line = clampDebugPosition(position.line, MAX_DEBUG_LINE);
100
116
  const subprogram = this.addMetadata(
101
117
  'distinct !DISubprogram(name: ' +
102
118
  `"${escapeMetadata(displayName)}", scope: ${this.debugUnit}, file: ${file}, ` +
103
- `line: ${position.line}, type: ${this.debugSubroutineType}, scopeLine: ${position.line}, ` +
119
+ `line: ${line}, type: ${this.debugSubroutineType}, scopeLine: ${line}, ` +
104
120
  `spFlags: DISPFlagDefinition, unit: ${this.debugUnit})`,
105
121
  );
106
122
  this.debugSubprograms.set(fn.id, subprogram);
@@ -110,11 +126,13 @@ export const debugMethods: DebugMethods = {
110
126
  setDebugLocation(node) {
111
127
  if (!this.debug || this.current.debugSubprogram === undefined) return;
112
128
  const position = this.positionOf(node);
113
- const key = `${this.current.debugSubprogram}:${position.line}:${position.column}`;
129
+ const line = clampDebugPosition(position.line, MAX_DEBUG_LINE);
130
+ const column = clampDebugPosition(position.column, MAX_DEBUG_COLUMN);
131
+ const key = `${this.current.debugSubprogram}:${line}:${column}`;
114
132
  let location = this.debugLocations.get(key);
115
133
  if (!location) {
116
134
  location = this.addMetadata(
117
- `!DILocation(line: ${position.line}, column: ${position.column}, scope: ${this.current.debugSubprogram})`,
135
+ `!DILocation(line: ${line}, column: ${column}, scope: ${this.current.debugSubprogram})`,
118
136
  );
119
137
  this.debugLocations.set(key, location);
120
138
  }
@@ -19,6 +19,7 @@ import {
19
19
  import { SymbolKind } from "../../../binder/binder.js";
20
20
  import { DiagnosticCode } from "../../../diagnostics/diagnostic.js";
21
21
  import { i64, numberLiteral, XT_UNDEFINED } from "../../values.js";
22
+ import { NAMESPACE_PROPERTY_SETTERS } from "../lookup-tables.js";
22
23
  import { BINARY_RUNTIME, compoundToBinary, propertyNameText } from "../tables.js";
23
24
  import type { Generator } from "../generator.js";
24
25
 
@@ -127,16 +128,38 @@ export const assignmentExpressionMethods: AssignmentExpressionMethods = {
127
128
  }
128
129
  case SyntaxKind.PropertyAccessExpression: {
129
130
  const access = target as PropertyAccessExpression;
131
+ /* `process.exitCode = 1`: a namespace property with a runtime setter.
132
+ * Reads go through `NAMESPACE_PROPERTIES`, writes through the matching
133
+ * entry here; a namespace without one keeps the generic object path. */
134
+ const holder =
135
+ access.expression.kind === SyntaxKind.Identifier ? (access.expression as Identifier) : undefined;
136
+ const symbol = holder ? this.binding.symbolOfIdentifier.get(holder) : undefined;
137
+ const namespace = holder ? (symbol ? this.namespaceOfSymbol(symbol) : holder.text) : undefined;
138
+ const setter = namespace === undefined ? undefined : NAMESPACE_PROPERTY_SETTERS[namespace];
139
+ if (setter) {
140
+ const key = this.stringValue(access.name.text);
141
+ this.extraDeclarations.add(`declare i64 @${setter}(i64, i64)`);
142
+ this.emit(` call i64 @${setter}(i64 ${key}, i64 ${value})`);
143
+ return;
144
+ }
130
145
  const object = this.emitExpression(access.expression);
131
146
  const key = this.stringValue(access.name.text);
132
- this.emit(` call i64 @xt_set(i64 ${object}, i64 ${key}, i64 ${value})`);
147
+ /* A store site gets the same monomorphic inline cache a read site has:
148
+ * `obj.x = v` in a hot loop otherwise resolves the property (own scan,
149
+ * prototype-chain walk for setters) on every assignment. */
150
+ this.extraDeclarations.add("declare i64 @xt_set_ic(i64, i64, i64, i64*)");
151
+ const cache = `@st.${this.icCounter++}`;
152
+ this.globals.push(`${cache} = internal global [2 x i64] zeroinitializer`);
153
+ const slot = this.reg();
154
+ this.emit(` ${slot} = getelementptr [2 x i64], [2 x i64]* ${cache}, i64 0, i64 0`);
155
+ this.emit(` call i64 @xt_set_ic(i64 ${object}, i64 ${key}, i64 ${value}, i64* ${slot})`);
133
156
  return;
134
157
  }
135
158
  case SyntaxKind.ElementAccessExpression: {
136
159
  const access = target as ElementAccessExpression;
137
160
  const object = this.emitExpression(access.expression);
138
161
  const key = this.emitExpression(access.argumentExpression);
139
- this.emit(` call i64 @xt_set(i64 ${object}, i64 ${key}, i64 ${value})`);
162
+ this.emitElementWrite(object, key, value);
140
163
  return;
141
164
  }
142
165
  case SyntaxKind.ParenthesizedExpression:
@@ -229,3 +252,4 @@ export const assignmentExpressionMethods: AssignmentExpressionMethods = {
229
252
  }
230
253
  },
231
254
  };
255
+
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Extension-provided global values.
3
+ *
4
+ * An extension names a global (`window`, `document`, `Image`, `location`) and
5
+ * the runtime getter that produces it; this group turns such a name into a
6
+ * value, including the two richer shapes:
7
+ *
8
+ * - a global that is a *member of a host object* (`location` off the window),
9
+ * so a browser global that only exists as a window property is still live;
10
+ * - `console`, which is both a namespace at call sites and a first-class
11
+ * object as a value (`console.error.bind(console)`).
12
+ */
13
+
14
+ import type { GlobalValue } from "../../../extensions/registry.js";
15
+ import type { Generator } from "../generator.js";
16
+
17
+ export interface GlobalValueMethods {
18
+ emitGlobalValue(this: Generator, value: GlobalValue): string;
19
+ emitConsoleObject(this: Generator): string;
20
+ }
21
+
22
+ export const globalValueMethods: GlobalValueMethods = {
23
+ /**
24
+ * Read an extension-provided global (`window`, `document`, `new Image()`).
25
+ * The getter is a normal runtime call with the uniform ABI; the optional
26
+ * argument is how one getter serves a whole family of host types.
27
+ */
28
+ emitGlobalValue(value: GlobalValue): string {
29
+ this.extraDeclarations.add(`declare i64 @${value.symbol}(i32, i64*)`);
30
+ let argc = "0";
31
+ let pointer = "i64* null";
32
+ if (value.argument !== undefined) {
33
+ const argument = this.stringValue(value.argument);
34
+ const slot = `%gval${this.current.allocas.length}`;
35
+ this.current.allocas.push(`${slot} = alloca i64, i32 1`);
36
+ const cell = this.reg();
37
+ this.emit(` ${cell} = getelementptr i64, i64* ${slot}, i32 0`);
38
+ this.emit(` store i64 ${argument}, i64* ${cell}`);
39
+ argc = "1";
40
+ pointer = `i64* ${slot}`;
41
+ }
42
+ const result = this.reg();
43
+ this.emit(` ${result} = call i64 @${value.symbol}(i32 ${argc}, ${pointer})`);
44
+ if (value.member === undefined) return result;
45
+ /* A browser global that lives on the window object (`location`): read it
46
+ * off the host object so a getter runs and answers a live value. */
47
+ const name = this.stringValue(value.member);
48
+ return this.runtimeCall("xt_get", [result, name]);
49
+ },
50
+
51
+ /** The global `console` object (see `runtime/xt_io/console.inc`). */
52
+ emitConsoleObject(): string {
53
+ const result = this.reg();
54
+ this.emit(` ${result} = call i64 @xt_console_object(i32 0, i64* null)`);
55
+ return result;
56
+ },
57
+ };
@@ -17,6 +17,12 @@ import type { Generator } from "../generator.js";
17
17
  export interface ModuleValueExpressionMethods {
18
18
  /** Lower one module export to a first-class closure value. */
19
19
  emitModuleExportValue(this: Generator, exported: ModuleExport): string;
20
+ /**
21
+ * Build (once) and register the table of linked extension modules, and return
22
+ * the table value. `createRequire`'s function and a computed `import()` look
23
+ * their specifier up in it.
24
+ */
25
+ ensureModuleRegistry(this: Generator): string;
20
26
  /** Build a namespace object holding every export of an imported module. */
21
27
  emitNamespaceObject(this: Generator, exports: ModuleExports): string;
22
28
  /** Lower a non-literal `import(specifier)` to a rejected promise. */
@@ -27,15 +33,30 @@ export const moduleValueExpressionMethods: ModuleValueExpressionMethods = {
27
33
  emitModuleExportValue(this: Generator, exported: ModuleExport): string {
28
34
  if (exported.symbol) {
29
35
  // A direct runtime function: wrap its `(argc, argv)` pointer in a closure.
30
- this.extraDeclarations.add(`declare i64 @${exported.symbol}(i32, i64*)`);
36
+ // A `void` binding (the console output methods) keeps that return type so
37
+ // the declaration matches the runtime's, and gets a trampoline that
38
+ // answers `undefined`.
39
+ const returnsVoid = exported.returnVoid === true;
40
+ const resultType = returnsVoid ? "void" : "i64";
41
+ this.extraDeclarations.add(`declare ${resultType} @${exported.symbol}(i32, i64*)`);
31
42
  const fnPtr = this.reg();
32
- this.emit(` ${fnPtr} = ptrtoint i64 (i32, i64*)* @${exported.symbol} to i64`);
43
+ this.emit(` ${fnPtr} = ptrtoint ${resultType} (i32, i64*)* @${exported.symbol} to i64`);
33
44
  const env = this.alloca();
34
45
  this.emit(` store i64 ${fnPtr}, i64* ${env}`);
46
+ const trampoline = returnsVoid ? "xt_voidptr_trampoline" : "xt_fnptr_trampoline";
35
47
  const closure = this.reg();
36
48
  this.emit(
37
- ` ${closure} = call i64 @xt_closure_new(i8* bitcast (i64 (i64, i64, i32, i64*)* @xt_fnptr_trampoline to i8*), i32 1, i64* ${env})`,
49
+ ` ${closure} = call i64 @xt_closure_new(i8* bitcast (i64 (i64, i64, i32, i64*)* @${trampoline} to i8*), i32 1, i64* ${env})`,
38
50
  );
51
+ /* A native constructor publishes its prototype object, so a class that
52
+ * extends this value chains onto the real `X.prototype` (with its
53
+ * methods) instead of a fresh plain object. */
54
+ if (exported.prototypeSymbol) {
55
+ this.extraDeclarations.add(`declare i64 @${exported.prototypeSymbol}(i32, i64*)`);
56
+ const prototype = this.reg();
57
+ this.emit(` ${prototype} = call i64 @${exported.prototypeSymbol}(i32 0, i64* null)`);
58
+ this.emit(` call i64 @xt_function_set_prototype(i64 ${closure}, i64 ${prototype})`);
59
+ }
39
60
  return closure;
40
61
  }
41
62
  if (exported.valueSymbol) {
@@ -84,22 +105,39 @@ export const moduleValueExpressionMethods: ModuleValueExpressionMethods = {
84
105
  return object;
85
106
  },
86
107
 
108
+ ensureModuleRegistry(this: Generator): string {
109
+ /* Built at each use site: the value is a local register, so a cached one
110
+ * would not be readable from another function. Programs that both call
111
+ * `createRequire` and use a computed `import()` are rare enough that the
112
+ * duplicate table is cheaper than a program-wide global plus a guard. */
113
+ const table = this.reg();
114
+ this.emit(` ${table} = call i64 @xt_object_new()`);
115
+ for (const [name, linked] of Object.entries(this.modules)) {
116
+ const exports = linked.exports;
117
+ if (!exports) continue;
118
+ const namespace = this.emitNamespaceObject(exports);
119
+ const keys = name.startsWith("node:") ? [name] : [name, `node:${name}`];
120
+ for (const key of keys) {
121
+ this.emit(` call i64 @xt_set(i64 ${table}, i64 ${this.stringValue(key)}, i64 ${namespace})`);
122
+ }
123
+ }
124
+ this.extraDeclarations.add("declare void @xt_module_registry_set(i64)");
125
+ this.emit(` call void @xt_module_registry_set(i64 ${table})`);
126
+ return table;
127
+ },
128
+
87
129
  emitDynamicImportReject(this: Generator, specifier: Expression): string {
88
- // Evaluate the specifier for its side effects, then reject: a compiled
89
- // binary has no runtime module loader to resolve a computed specifier.
90
- this.emitExpression(specifier);
91
- const message = this.stringValue(
92
- "dynamic import with a non-literal specifier is not supported in compiled binaries",
93
- );
94
- const argPtr = `%dynimp${this.current.allocas.length}`;
95
- this.current.allocas.push(`${argPtr} = alloca i64, i32 1`);
96
- const argSlot = this.reg();
97
- this.emit(` ${argSlot} = getelementptr i64, i64* ${argPtr}, i32 0`);
98
- this.emit(` store i64 ${message}, i64* ${argSlot}`);
99
- const error = this.reg();
100
- this.emit(` ${error} = call i64 @xt_error_ctor(i32 1, i64* ${argPtr})`);
101
- const promise = this.reg();
102
- this.emit(` ${promise} = call i64 @xt_promise_reject(i64 ${error})`);
103
- return promise;
130
+ /* A compiled binary has no module loader, but the modules linked into it
131
+ * are still there: the specifier can name any enabled extension module, so
132
+ * build a table of their namespace objects and let the runtime look it up.
133
+ * Anything else rejects with a message that names the specifier. This is
134
+ * what makes `import("node:" + "fs")` — the usual "load Node built-ins
135
+ * without a bundler" idiom — work. */
136
+ const value = this.emitExpression(specifier);
137
+ const table = this.ensureModuleRegistry();
138
+ this.extraDeclarations.add("declare i64 @xt_dynamic_import(i64, i64)");
139
+ const result = this.reg();
140
+ this.emit(` ${result} = call i64 @xt_dynamic_import(i64 ${table}, i64 ${value})`);
141
+ return result;
104
142
  },
105
143
  };
@@ -41,8 +41,8 @@ import {
41
41
  NAMESPACE_VALUES,
42
42
  WEB_GLOBALS,
43
43
  } from "../tables.js";
44
- import type { GlobalValue } from "../../../extensions/registry.js";
45
44
  import type { Generator } from "../generator.js";
45
+ import { newCalleeName } from "../calls/unwrap.js";
46
46
 
47
47
  export interface PrimaryExpressionMethods {
48
48
  emitExpression(this: Generator, node: Expression): string;
@@ -56,7 +56,6 @@ export interface PrimaryExpressionMethods {
56
56
  */
57
57
  emitTypeOf(this: Generator, operand: Expression): string;
58
58
  globalTypeOf(this: Generator, name: string): string | undefined;
59
- emitGlobalValue(this: Generator, value: GlobalValue): string;
60
59
  emitFunctionValue(this: Generator, symbol: SymbolInfo): string;
61
60
  emitTemplate(this: Generator, node: TemplateLiteral): string;
62
61
  emitTaggedTemplate(this: Generator, node: TaggedTemplateExpression): string;
@@ -293,7 +292,10 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
293
292
  case "Infinity":
294
293
  return numberLiteral(Infinity);
295
294
  case "console":
296
- return i64(XT_UNDEFINED);
295
+ /* `console` is a namespace at call sites (`console.log(...)`) and a
296
+ * first-class object as a value: `const log = console.log`,
297
+ * `console.error.bind(console)`, `const { warn } = console`. */
298
+ return this.emitConsoleObject();
297
299
  case "arguments": {
298
300
  const argc = this.reg();
299
301
  this.emit(` ${argc} = load i32, i32* %saved.argc`);
@@ -349,10 +351,9 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
349
351
  return this.runtimeCall("xt_error_constructor", [nameValue]);
350
352
  }
351
353
  // A bare `require` reference is CommonJS; steer the user to `import`.
352
- if (identifier.text === "require") {
353
- this.reportRequireUse(identifier);
354
- return i64(XT_UNDEFINED);
355
- }
354
+ if (identifier.text === "require") { this.reportRequireUse(identifier); return i64(XT_UNDEFINED); }
355
+ // `globalThis` / Node's `global` as a value is the (plain-bag) global object.
356
+ if (identifier.text === "globalThis" || identifier.text === "global") return this.runtimeCall("xt_global_object", []);
356
357
  // Recognized web globals with no runtime yet lower to `undefined`.
357
358
  if (WEB_GLOBALS.has(identifier.text)) return i64(XT_UNDEFINED);
358
359
  /* The parser's recovery node for a missing expression. The syntax
@@ -375,30 +376,6 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
375
376
  }
376
377
  },
377
378
 
378
- /**
379
- * Read an extension-provided global (`window`, `document`, `new Image()`).
380
- * The getter is a normal runtime call with the uniform ABI; the optional
381
- * argument is how one getter serves a whole family of host types.
382
- */
383
- emitGlobalValue(value: GlobalValue): string {
384
- this.extraDeclarations.add(`declare i64 @${value.symbol}(i32, i64*)`);
385
- let argc = "0";
386
- let pointer = "i64* null";
387
- if (value.argument !== undefined) {
388
- const argument = this.stringValue(value.argument);
389
- const slot = `%gval${this.current.allocas.length}`;
390
- this.current.allocas.push(`${slot} = alloca i64, i32 1`);
391
- const cell = this.reg();
392
- this.emit(` ${cell} = getelementptr i64, i64* ${slot}, i32 0`);
393
- this.emit(` store i64 ${argument}, i64* ${cell}`);
394
- argc = "1";
395
- pointer = `i64* ${slot}`;
396
- }
397
- const result = this.reg();
398
- this.emit(` ${result} = call i64 @${value.symbol}(i32 ${argc}, ${pointer})`);
399
- return result;
400
- },
401
-
402
379
  emitFunctionValue(symbol: SymbolInfo): string {
403
380
  const fn = implementationFunctionInfo(this.binding, symbol);
404
381
  if (!fn) return i64(XT_UNDEFINED);
@@ -446,9 +423,9 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
446
423
 
447
424
  emitNew(node: NewExpression): string {
448
425
  const callee = node.expression;
449
- // A `new` expression is where the innermost frame's line should point for
450
- // `Error.stack`; harmless for every other constructor.
451
426
  this.emit(` call void @xt_stack_set_line(i32 ${this.lineOf(node)})`);
427
+ const calleeText = newCalleeName(callee);
428
+ const calleeName = calleeText === undefined ? i64(XT_UNDEFINED) : this.stringValue(calleeText);
452
429
  if (callee.kind === SyntaxKind.Identifier) {
453
430
  const identifier = callee as Identifier;
454
431
  const symbol = this.binding.symbolOfIdentifier.get(identifier);
@@ -459,7 +436,7 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
459
436
  const ctor = this.emitClassReference(info);
460
437
  const args = this.emitArguments(node.arguments);
461
438
  const result = this.reg();
462
- this.emit(` ${result} = call i64 @xt_new(i64 ${ctor}, i32 ${args.argc}, i64* ${args.ptr})`);
439
+ this.emit(` ${result} = call i64 @xt_new_named(i64 ${ctor}, i64 ${calleeName}, i32 ${args.argc}, i64* ${args.ptr})`);
463
440
  return result;
464
441
  }
465
442
  }
@@ -476,7 +453,7 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
476
453
  const ctorValue = this.emitGlobalValue(extensionConstructor);
477
454
  const args = this.emitArguments(node.arguments);
478
455
  const result = this.reg();
479
- this.emit(` ${result} = call i64 @xt_new(i64 ${ctorValue}, i32 ${args.argc}, i64* ${args.ptr})`);
456
+ this.emit(` ${result} = call i64 @xt_new_named(i64 ${ctorValue}, i64 ${calleeName}, i32 ${args.argc}, i64* ${args.ptr})`);
480
457
  return result;
481
458
  }
482
459
  if (identifier.text === "Object") {
@@ -500,7 +477,7 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
500
477
  const ctorValue = this.emitExpression(callee);
501
478
  const args = this.emitArguments(node.arguments);
502
479
  const result = this.reg();
503
- this.emit(` ${result} = call i64 @xt_new(i64 ${ctorValue}, i32 ${args.argc}, i64* ${args.ptr})`);
480
+ this.emit(` ${result} = call i64 @xt_new_named(i64 ${ctorValue}, i64 ${calleeName}, i32 ${args.argc}, i64* ${args.ptr})`);
504
481
  return result;
505
482
  },
506
483
 
@@ -9,12 +9,14 @@
9
9
  */
10
10
 
11
11
  import { primaryExpressionMethods, type PrimaryExpressionMethods } from "./expressions/primary.js";
12
+ import { globalValueMethods, type GlobalValueMethods } from "./expressions/global-values.js";
12
13
  import { moduleValueExpressionMethods, type ModuleValueExpressionMethods } from "./expressions/module-values.js";
13
14
  import { operatorExpressionMethods, type OperatorExpressionMethods } from "./expressions/operators.js";
14
15
  import { assignmentExpressionMethods, type AssignmentExpressionMethods } from "./expressions/assignment.js";
15
16
 
16
17
  export interface ExpressionMethods
17
18
  extends PrimaryExpressionMethods,
19
+ GlobalValueMethods,
18
20
  ModuleValueExpressionMethods,
19
21
  OperatorExpressionMethods,
20
22
  AssignmentExpressionMethods {}
@@ -22,6 +24,7 @@ export interface ExpressionMethods
22
24
  export const expressionMethods: ExpressionMethods = Object.assign(
23
25
  {},
24
26
  primaryExpressionMethods,
27
+ globalValueMethods,
25
28
  moduleValueExpressionMethods,
26
29
  operatorExpressionMethods,
27
30
  assignmentExpressionMethods,
@@ -12,6 +12,7 @@ import type { DiagnosticBag } from "../../diagnostics/diagnostic.js";
12
12
  import { bind } from "../../binder/binder.js";
13
13
  import { checkProgram } from "../../checker/checker.js";
14
14
  import { GeneratorContext } from "./context.js";
15
+ import { hardenLookupTables } from "./lookup-tables.js";
15
16
  import { moduleMethods, type ModuleMethods } from "./module.js";
16
17
  import { statementMethods, type StatementMethods } from "./statements.js";
17
18
  import { expressionMethods, type ExpressionMethods } from "./expressions.js";
@@ -47,6 +48,9 @@ export function generate(
47
48
  diagnostics: DiagnosticBag,
48
49
  options: CodegenOptions = {},
49
50
  ): CodegenResult {
51
+ // Lookup tables must not answer for inherited members (`toString`) before
52
+ // any name is lowered; see `lookup-tables.ts`.
53
+ hardenLookupTables();
50
54
  // Bind once: the checker and the generator must see the same symbol table.
51
55
  const binding = bind(sourceFile);
52
56
  if (options.check !== false) {
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Byte offsets into the runtime's container structs that generated code reads
3
+ * directly.
4
+ *
5
+ * The element fast path (`element-inline.ts`) skips the generic dispatch by
6
+ * looking at a value's tag and then loading the fields it needs — an array's
7
+ * `items`/`length`, a typed-array view's `view_bytes`/`view_length`/kind — out of
8
+ * the object header. That only works if the compiler knows the layout, so these
9
+ * constants mirror `runtime/rt_object.h`; `tests/codegen/element-layout.test.ts`
10
+ * compiles a C probe against the runtime header and fails when the two drift
11
+ * apart.
12
+ */
13
+
14
+ import { XT_ARRAY, XT_NUMBER_MASK, XT_OBJECT, XT_TAG_MASK } from "../values.js";
15
+
16
+ export const XT_LAYOUT = {
17
+ /** `xt_header` size: the payload starts here in every heap object. */
18
+ headerSize: 16,
19
+ /** `xt_array.length` (uint32). */
20
+ arrayLength: 16,
21
+ /** `xt_array.items` (i64 pointer to the element vector). */
22
+ arrayItems: 24,
23
+ /** `xt_object.reserved2` (uint16): a typed-array view's `kind + 1`. */
24
+ objectTypedKind: 50,
25
+ /** `xt_object.view_bytes` (i64 raw pointer): the view's first element. */
26
+ objectViewBytes: 96,
27
+ /** `xt_object.view_length` (uint32): bytes available from `view_bytes`. */
28
+ objectViewLength: 104,
29
+ } as const;
30
+
31
+ /** Tags and masks the inline guards compare against (`runtime/rt.h`). */
32
+ export const XT_INLINE_TAGS = {
33
+ tagMask: XT_TAG_MASK,
34
+ numberMask: XT_NUMBER_MASK,
35
+ array: XT_ARRAY,
36
+ object: XT_OBJECT,
37
+ } as const;
38
+
39
+ /** Typed-array element kinds, in `XT_TA_*` order (`runtime/xt_typed_array.c`). */
40
+ export const XT_TYPED_KINDS = [
41
+ { name: "Uint8Array", width: 1 },
42
+ { name: "Int8Array", width: 1 },
43
+ { name: "Uint8ClampedArray", width: 1 },
44
+ { name: "Uint16Array", width: 2 },
45
+ { name: "Int16Array", width: 2 },
46
+ { name: "Uint32Array", width: 4 },
47
+ { name: "Int32Array", width: 4 },
48
+ { name: "Float32Array", width: 4 },
49
+ { name: "Float64Array", width: 8 },
50
+ ] as const;
51
+
52
+ /** Index of `Float32Array` / `Float64Array` in {@link XT_TYPED_KINDS}. */
53
+ export const XT_KIND_F32 = 7;
54
+ export const XT_KIND_F64 = 8;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Hardening and extras for the builtin lookup tables in `./tables.ts`.
3
+ *
4
+ * The generator reads every table with `table[name]`, where `name` comes from the
5
+ * program's source. A plain object literal inherits `Object.prototype`, so
6
+ * `NAMESPACE_VALUES["toString"]` resolves to `Object.prototype.toString` and the
7
+ * generator used to emit that function's text as an LLVM symbol
8
+ * (`declare i64 @function toString() { [native code] }(i32, i64*)`), which clang
9
+ * rejects. `constructor`, `valueOf` and the other inherited members did the same.
10
+ *
11
+ * `hardenLookupTables` drops the prototype of every table once, before code
12
+ * generation starts. It lives here rather than in `tables.ts` so the tables stay
13
+ * a data module (and the file stays inside the repository's length budget).
14
+ */
15
+
16
+ import {
17
+ BINARY_RUNTIME,
18
+ BUILTIN_FUNCTION_VALUES,
19
+ BUILTIN_INSTANCEOF,
20
+ CONSOLE_METHODS,
21
+ CTOR_FUNCTIONS,
22
+ ERROR_CONSTRUCTORS,
23
+ GLOBAL_FUNCTIONS,
24
+ MATH_CONSTANTS,
25
+ NAMESPACE_PROPERTIES,
26
+ NAMESPACE_STATICS,
27
+ NAMESPACE_VALUES,
28
+ TYPED_ARRAYS,
29
+ } from "./tables.js";
30
+
31
+ /**
32
+ * Namespaces whose properties are writable from JavaScript (`process.exitCode =
33
+ * 1`), mapped to the runtime setter `(key, value)`. A namespace without an entry
34
+ * is read-only: assigning to one of its properties takes the generic object path.
35
+ */
36
+ export const NAMESPACE_PROPERTY_SETTERS: Record<string, string> = {
37
+ process: "xt_process_set",
38
+ };
39
+
40
+ const LOOKUP_TABLES: readonly Record<string, unknown>[] = [
41
+ BINARY_RUNTIME,
42
+ BUILTIN_FUNCTION_VALUES,
43
+ BUILTIN_INSTANCEOF,
44
+ CONSOLE_METHODS,
45
+ CTOR_FUNCTIONS,
46
+ ERROR_CONSTRUCTORS,
47
+ GLOBAL_FUNCTIONS,
48
+ MATH_CONSTANTS,
49
+ NAMESPACE_PROPERTIES,
50
+ NAMESPACE_PROPERTY_SETTERS,
51
+ NAMESPACE_STATICS,
52
+ NAMESPACE_VALUES,
53
+ TYPED_ARRAYS,
54
+ ];
55
+
56
+ let hardened = false;
57
+
58
+ /** Idempotent: called by `generate` before the first expression is lowered. */
59
+ export function hardenLookupTables(): void {
60
+ if (hardened) return;
61
+ hardened = true;
62
+ for (const table of LOOKUP_TABLES) Object.setPrototypeOf(table, null);
63
+ }
@@ -215,6 +215,19 @@ export const moduleMethods: ModuleMethods = {
215
215
  this.declareSlot(symbol, i64(XT_UNDEFINED));
216
216
  }
217
217
 
218
+ /* `var` is function scoped and hoisted, so a reference textually *before*
219
+ * the declaration must already have a slot holding `undefined`:
220
+ * `tsIsDeclarationStart() { return (e = this.state.type) >= 124; var e }`.
221
+ * The binder lifts every `var` into the function scope, so declaring the
222
+ * slots now makes the later statement a plain store (minified bundles use
223
+ * this idiom constantly — it used to report "no slot for 'e'"). */
224
+ for (const symbol of fn.locals) {
225
+ if (symbol.kind !== SymbolKind.Var) continue;
226
+ if (this.moduleGlobals.has(symbol.id)) continue;
227
+ if (this.current.slots.has(symbol.id)) continue;
228
+ this.declareSlot(symbol, i64(XT_UNDEFINED));
229
+ }
230
+
218
231
  // Hoisted function declarations: create their closure values in this
219
232
  // frame (before the body runs) so a nested function that references one
220
233
  // gets the closure built against the declaring frame, not against the
@@ -245,11 +258,10 @@ export const moduleMethods: ModuleMethods = {
245
258
  this.emit(` ${proto} = call i64 @xt_function_get_prototype(i64 ${owner})`);
246
259
  const parentProto = this.reg();
247
260
  this.emit(` ${parentProto} = call i64 @xt_object_get_prototype(i64 ${proto})`);
248
- const ctorKey = this.stringValue("__ctor");
249
- const parentCtor = this.reg();
250
- this.emit(` ${parentCtor} = call i64 @xt_get(i64 ${parentProto}, i64 ${ctorKey})`);
251
261
  const superThis = this.emitThis();
252
- this.emit(` call i64 @xt_call_with_this(i64 ${parentCtor}, i64 ${superThis}, i32 %argc, i64* %argv)`);
262
+ this.emit(
263
+ ` call i64 @xt_super_construct(i64 ${superThis}, i64 ${owner}, i64 ${parentProto}, i32 %argc, i64* %argv)`,
264
+ );
253
265
  } else if (!explicitBody && errorName) {
254
266
  // `extends Error` / `extends TypeError` with no explicit constructor:
255
267
  // initialise the instance's name and message from the arguments.
@@ -286,7 +298,21 @@ export const moduleMethods: ModuleMethods = {
286
298
 
287
299
  // Body.
288
300
  if (fn.node.kind === SyntaxKind.SourceFile) {
289
- this.emitStatements(this.sourceFile.statements);
301
+ /* Record which module is initialising. Every module of a bundle shares
302
+ * this one function, so without it a crash (or an `Error.stack`) inside a
303
+ * module body points at the entry file's offsets — the coordinates say
304
+ * `cli.ts:653` no matter where it really happened. */
305
+ let currentModule: string | undefined;
306
+ for (const statement of this.sourceFile.statements) {
307
+ const origin = this.sourceFile.origins?.get(statement);
308
+ if (origin !== undefined && origin !== currentModule) {
309
+ currentModule = origin;
310
+ this.emit(` call void @xt_stack_set_module(i8* ${this.internStatic(artifactPath(origin))})`);
311
+ }
312
+ this.emitStatement(statement);
313
+ }
314
+ /* Module bodies are done; later errors should not name the last module. */
315
+ this.emit(` call void @xt_stack_set_module(i8* null)`);
290
316
  } else if (fn.node.kind === SyntaxKind.ArrowFunction && (fn.node as ArrowFunction).body.kind !== SyntaxKind.Block) {
291
317
  const value = this.emitExpression((fn.node as ArrowFunction).body as Expression);
292
318
  this.emitFunctionReturn(value);
@@ -338,12 +364,17 @@ export const moduleMethods: ModuleMethods = {
338
364
  " call void @xt_gc_init()",
339
365
  ...rootLines,
340
366
  ...stringInit,
367
+ " call void @xt_gc_begin_startup()",
341
368
  " call void @xt_gc_arm()",
342
369
  " call void @xt_set_program_args(i32 %argc, i8** %argv)",
343
370
  ` %result = call i64 @${moduleName}(i64 ${i64(XT_UNDEFINED)}, i64 ${i64(XT_UNDEFINED)}, i32 0, i64* null)`,
371
+ " call void @xt_gc_end_startup()",
344
372
  " call void @xt_drain_microtasks()",
345
373
  " call void @xt_run_event_loop()",
346
- " ret i32 0",
374
+ /* Run the exit hook (Node's `process` "exit" listeners) and report the
375
+ * status the program asked for (`process.exitCode` / `process.exit`). */
376
+ " %exitstatus = call i32 @xt_finish()",
377
+ " ret i32 %exitstatus",
347
378
  "}",
348
379
  "",
349
380
  ].join(ARTIFACT_LINE_ENDING),
@@ -443,7 +474,7 @@ export const moduleMethods: ModuleMethods = {
443
474
  this.emit(` call i64 @xt_object_set_prototype(i64 ${proto}, i64 ${parentProto})`);
444
475
  } else {
445
476
  const parentProto = this.reg();
446
- this.emit(` ${parentProto} = call i64 @xt_function_get_prototype(i64 ${parentValue})`);
477
+ this.emit(` ${parentProto} = call i64 @xt_parent_prototype(i64 ${parentValue})`);
447
478
  this.emit(` call i64 @xt_object_set_prototype(i64 ${proto}, i64 ${parentProto})`);
448
479
  }
449
480
  }