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
@@ -0,0 +1,70 @@
1
+ /*
2
+ * xbintsc runtime — release the backing storage of one collected block.
3
+ *
4
+ * Split out of xt_alloc.c to keep the collector within the file-size budget;
5
+ * called from the sweep with the block already unlinked from the heap list.
6
+ */
7
+
8
+ #include "rt_internal.h"
9
+
10
+ #include <stdlib.h>
11
+
12
+ void xt_gc_release(xt_header *header) {
13
+ const size_t block_size = (size_t)header->size;
14
+ const int pooled = (header->flags & XT_GC_POOLED) != 0;
15
+ switch (header->kind) {
16
+ case XT_OBJECT_KIND_STRING:
17
+ free(((xt_string *)header)->flat);
18
+ break;
19
+ case XT_OBJECT_KIND_BIGINT:
20
+ free(((xt_bigint *)header)->limbs);
21
+ break;
22
+ case XT_OBJECT_KIND_OBJECT:
23
+ case XT_OBJECT_KIND_ERROR:
24
+ xt_raw_free(((xt_object *)header)->properties);
25
+ break;
26
+ case XT_OBJECT_KIND_ARRAY_BUFFER: {
27
+ xt_object *object = (xt_object *)header;
28
+ free(object->buffer_bytes);
29
+ xt_raw_free(object->properties);
30
+ break;
31
+ }
32
+ case XT_OBJECT_KIND_ARRAY:
33
+ xt_raw_free(((xt_array *)header)->items);
34
+ break;
35
+ case XT_OBJECT_KIND_FUNCTION:
36
+ free(((xt_function *)header)->environment);
37
+ break;
38
+ case XT_OBJECT_KIND_MAP:
39
+ free(((xt_map *)header)->keys);
40
+ free(((xt_map *)header)->values);
41
+ break;
42
+ case XT_OBJECT_KIND_SET:
43
+ free(((xt_set_object *)header)->values);
44
+ break;
45
+ case XT_OBJECT_KIND_WEAK_MAP:
46
+ free(((xt_weak_map *)header)->keys);
47
+ free(((xt_weak_map *)header)->values);
48
+ break;
49
+ case XT_OBJECT_KIND_WEAK_SET:
50
+ free(((xt_weak_set *)header)->values);
51
+ break;
52
+ case XT_OBJECT_KIND_PROMISE:
53
+ xt_promise_gc_release(header);
54
+ break;
55
+ case XT_OBJECT_KIND_GENERATOR:
56
+ xt_generator_gc_release(header);
57
+ break;
58
+ case XT_OBJECT_KIND_ASYNC:
59
+ xt_async_gc_release(header);
60
+ break;
61
+ default:
62
+ break;
63
+ }
64
+ if (pooled) {
65
+ xt_pool_free_block(header, block_size);
66
+ } else {
67
+ free(header);
68
+ }
69
+ }
70
+
@@ -0,0 +1,83 @@
1
+ /*
2
+ * xbintsc runtime — GC stack-region table.
3
+ *
4
+ * A coroutine has a private C stack; while it runs (or while it is suspended
5
+ * under a deeper coroutine) the conservative collector must scan that region.
6
+ * The table grows on demand: an `async` call chain can be deeper than any fixed
7
+ * limit, and silently dropping a push would desynchronise push/pop, so a later
8
+ * pop evicted a still-live parent region and the collector stopped scanning it.
9
+ */
10
+
11
+ #include "rt_internal.h"
12
+
13
+ #include <stddef.h>
14
+ #include <stdio.h>
15
+ #include <stdlib.h>
16
+
17
+ typedef struct {
18
+ uintptr_t low;
19
+ uintptr_t high;
20
+ /* Lower bound captured from the stack below this region when a deeper region
21
+ * was entered on top of it. `UINTPTR_MAX` means "this is the top region"; the
22
+ * collector then scans from the current stack pointer. */
23
+ uintptr_t scan_low;
24
+ } xt_stack_region;
25
+
26
+ static xt_stack_region *g_stack_regions = NULL;
27
+ static size_t g_stack_depth = 0;
28
+ static size_t g_stack_capacity = 0;
29
+
30
+ /** Ensure room for one more region; aborts when the process is out of memory. */
31
+ static void xt_gc_reserve_stack_region(void) {
32
+ if (g_stack_depth < g_stack_capacity) return;
33
+ size_t capacity = g_stack_capacity == 0 ? 16 : g_stack_capacity * 2;
34
+ xt_stack_region *grown = (xt_stack_region *)realloc(g_stack_regions, sizeof(xt_stack_region) * capacity);
35
+ if (!grown) {
36
+ fprintf(stderr, "xbintsc: out of memory growing the GC stack-region table\n");
37
+ abort();
38
+ }
39
+ g_stack_regions = grown;
40
+ g_stack_capacity = capacity;
41
+ }
42
+
43
+ void xt_gc_init_main_stack(uintptr_t high) {
44
+ xt_gc_reserve_stack_region();
45
+ if (g_stack_depth == 0) {
46
+ g_stack_regions[0].low = 0;
47
+ g_stack_regions[0].high = high;
48
+ g_stack_regions[0].scan_low = UINTPTR_MAX;
49
+ g_stack_depth = 1;
50
+ } else if (high > g_stack_regions[0].high) {
51
+ g_stack_regions[0].high = high;
52
+ }
53
+ }
54
+
55
+ void xt_gc_push_stack(uintptr_t low, uintptr_t high) {
56
+ xt_gc_reserve_stack_region();
57
+ g_stack_regions[g_stack_depth].low = low;
58
+ g_stack_regions[g_stack_depth].high = high;
59
+ g_stack_regions[g_stack_depth].scan_low = low;
60
+ g_stack_depth++;
61
+ }
62
+
63
+ void xt_gc_suspend(uintptr_t sp) {
64
+ if (g_stack_depth == 0) return;
65
+ uintptr_t *scan = &g_stack_regions[g_stack_depth - 1].scan_low;
66
+ if (*scan == UINTPTR_MAX || sp < *scan) *scan = sp;
67
+ }
68
+
69
+ void xt_gc_pop_stack(void) {
70
+ if (g_stack_depth <= 1) return;
71
+ g_stack_depth--;
72
+ /* Back on the underlying stack: resume scanning it from the current frame. */
73
+ if (g_stack_depth > 0) g_stack_regions[g_stack_depth - 1].scan_low = UINTPTR_MAX;
74
+ }
75
+
76
+ size_t xt_gc_stack_region_count(void) {
77
+ return g_stack_depth;
78
+ }
79
+
80
+ void xt_gc_stack_region_bounds(size_t index, uintptr_t current, uintptr_t *low, uintptr_t *high) {
81
+ *high = g_stack_regions[index].high;
82
+ *low = index + 1 == g_stack_depth ? current : g_stack_regions[index].scan_low;
83
+ }
@@ -0,0 +1,136 @@
1
+ /*
2
+ * `XT_GC_VERIFY=1`: check that the collector keeps every object a live object
3
+ * points at.
4
+ *
5
+ * After the mark phase and *before* the sweep, walk every marked object's
6
+ * payload conservatively (the same way the collector scans the stack) and
7
+ * report each heap block it references that is not marked. A hit means either
8
+ * the tracer for that object kind skips a field, or the referenced block was
9
+ * never reachable from a root — both are the class of bug that ends in a
10
+ * use-after-free far away from the collection.
11
+ *
12
+ * Debug-only: the walk is O(live objects × payload) and allocates nothing.
13
+ */
14
+
15
+ #include "rt_internal.h"
16
+
17
+ #include <stdio.h>
18
+ #include <stdlib.h>
19
+ #include <string.h>
20
+
21
+ /** Lookup a raw address in the collector's table (xt_alloc.c). */
22
+ xt_header *xt_gc_lookup_raw(uintptr_t address);
23
+
24
+ static const char *xt_gc_kind_name(uint8_t kind) {
25
+ switch (kind) {
26
+ case XT_OBJECT_KIND_STRING: return "string";
27
+ case XT_OBJECT_KIND_OBJECT: return "object";
28
+ case XT_OBJECT_KIND_ARRAY: return "array";
29
+ case XT_OBJECT_KIND_FUNCTION: return "function";
30
+ case XT_OBJECT_KIND_PROMISE: return "promise";
31
+ case XT_OBJECT_KIND_MAP: return "map";
32
+ case XT_OBJECT_KIND_SET: return "set";
33
+ case XT_OBJECT_KIND_DATE: return "date";
34
+ case XT_OBJECT_KIND_REGEXP: return "regexp";
35
+ case XT_OBJECT_KIND_SYMBOL: return "symbol";
36
+ case XT_OBJECT_KIND_BIGINT: return "bigint";
37
+ case XT_OBJECT_KIND_ERROR: return "error";
38
+ case XT_OBJECT_KIND_GENERATOR: return "generator";
39
+ case XT_OBJECT_KIND_ITERATOR: return "iterator";
40
+ case XT_OBJECT_KIND_ASYNC: return "async";
41
+ case XT_OBJECT_KIND_ASYNC_ITERATOR: return "async-iterator";
42
+ case XT_OBJECT_KIND_WEAK_MAP: return "weakmap";
43
+ case XT_OBJECT_KIND_WEAK_SET: return "weakset";
44
+ case XT_OBJECT_KIND_WEAK_REF: return "weakref";
45
+ case XT_OBJECT_KIND_ARRAY_BUFFER: return "array-buffer";
46
+ default: return "?";
47
+ }
48
+ }
49
+
50
+ /** Does `word` name a heap block (raw pointer or NaN-boxed value)? */
51
+ static xt_header *xt_gc_verify_word(uint64_t word) {
52
+ if (XT_IS_STRING(word) || XT_IS_OBJECT(word) || XT_IS_ARRAY(word) || XT_IS_FUNCTION(word) ||
53
+ XT_IS_BIGINT(word)) {
54
+ return xt_gc_lookup_raw((uintptr_t)XT_GET_PTR(word));
55
+ }
56
+ return xt_gc_lookup_raw((uintptr_t)word);
57
+ }
58
+
59
+ void xt_gc_verify_payloads(void) {
60
+ size_t misses = 0;
61
+ for (xt_header *header = xt_gc_heap_head(); header != NULL; header = header->gc_next) {
62
+ if ((header->flags & XT_GC_MARK) == 0) continue;
63
+ if (header->size <= sizeof(xt_header)) continue;
64
+ const uint64_t *words = (const uint64_t *)((const char *)header + sizeof(xt_header));
65
+ size_t count = (header->size - sizeof(xt_header)) / sizeof(uint64_t);
66
+ for (size_t i = 0; i < count; i++) {
67
+ xt_header *target = xt_gc_verify_word(words[i]);
68
+ if (target == NULL || (target->flags & XT_GC_MARK) != 0) continue;
69
+ fprintf(stderr,
70
+ "xbintsc: gc verify: %s(%u bytes) at word %zu references unmarked %s(%u bytes)\n",
71
+ xt_gc_kind_name(header->kind), (unsigned)header->size, i,
72
+ xt_gc_kind_name(target->kind), (unsigned)target->size);
73
+ if (++misses >= 8) {
74
+ fprintf(stderr, "xbintsc: gc verify: stopping after 8 reports\n");
75
+ return;
76
+ }
77
+ }
78
+ }
79
+ if (misses == 0) fprintf(stderr, "xbintsc: gc verify: ok\n");
80
+ }
81
+
82
+ /* -- freed-block ring, for crash triage ----------------------------------- */
83
+
84
+ /* Every block the sweep releases is recorded here: a crash handler that knows
85
+ * the faulting address can say whether it was inside a freed block. */
86
+
87
+ typedef struct {
88
+ uintptr_t address;
89
+ size_t size;
90
+ uint8_t kind;
91
+ } xt_gc_freed_entry;
92
+
93
+ #define XT_GC_FREED_RING 512
94
+ static xt_gc_freed_entry g_freed[XT_GC_FREED_RING];
95
+ static size_t g_freed_count = 0;
96
+
97
+ void xt_gc_debug_record_free(uintptr_t address, size_t size, int kind) {
98
+ xt_gc_freed_entry *entry = &g_freed[g_freed_count % XT_GC_FREED_RING];
99
+ entry->address = address;
100
+ entry->size = size;
101
+ entry->kind = (uint8_t)kind;
102
+ g_freed_count++;
103
+ }
104
+
105
+ /** Describe `address` if it falls inside a block the sweep released. */
106
+ int xt_gc_debug_describe(uintptr_t address, char *out, size_t capacity) {
107
+ size_t live = g_freed_count < XT_GC_FREED_RING ? g_freed_count : XT_GC_FREED_RING;
108
+ {
109
+ xt_header *live_block = xt_gc_lookup_raw(address);
110
+ snprintf(out, capacity,
111
+ " fault address 0x%llx (%zu frees recorded)%s\n",
112
+ (unsigned long long)address, g_freed_count,
113
+ live_block ? ", inside a LIVE block" : ", not in the live heap");
114
+ if (live_block) return 1;
115
+ }
116
+ for (size_t i = 0; i < live; i++) {
117
+ const xt_gc_freed_entry *entry = &g_freed[i];
118
+ if (address < entry->address || address >= entry->address + entry->size) continue;
119
+ snprintf(out, capacity,
120
+ " fault address 0x%llx is +0x%llx inside a %s block of %u bytes that the "
121
+ "collector freed (%zu frees ago)\n",
122
+ (unsigned long long)address, (unsigned long long)(address - entry->address),
123
+ xt_gc_kind_name(entry->kind), (unsigned)entry->size, i);
124
+ return 1;
125
+ }
126
+ return 0;
127
+ }
128
+
129
+ /** A typed pointer that is not a live block: name it under `XT_GC_VERIFY=1`. */
130
+ void xt_gc_verify_rejected(uintptr_t address) {
131
+ static int reported = 0;
132
+ if (getenv("XT_GC_VERIFY") == NULL) return;
133
+ if (reported++ >= 8) return;
134
+ fprintf(stderr, "xbintsc: gc verify: skipped stale typed pointer 0x%llx\n",
135
+ (unsigned long long)address);
136
+ }
@@ -0,0 +1,224 @@
1
+ /*
2
+ * xbintsc runtime — the `Intl` global object.
3
+ *
4
+ * Only `Intl.Segmenter` is provided: the TUI subdivides strings into grapheme
5
+ * clusters (terminal width, truncation) and words (cursor movement), and both
6
+ * segmenters are constructed at module load. ICU is not linked, so the
7
+ * segmentation is a documented approximation of UAX #29:
8
+ *
9
+ * - grapheme: a code point plus the marks, variation selectors, emoji
10
+ * modifiers and ZWJ sequences that attach to it, and paired regional
11
+ * indicators (flags);
12
+ * - word: runs of whitespace, word characters and punctuation.
13
+ *
14
+ * `segment(text)` returns an **array** of `{ segment, index, isWordLike }`.
15
+ * Node returns an iterable of the same records; every consumer in the
16
+ * ecosystem spreads or iterates it, so the array is a compatible subset.
17
+ *
18
+ * Locale arguments are ignored, and `resolvedOptions()` reports `en`.
19
+ */
20
+
21
+ #include "rt_internal.h"
22
+
23
+ #include <stdio.h>
24
+ #include <stdlib.h>
25
+ #include <string.h>
26
+
27
+ static xt_value xt_intl_object_value = 0;
28
+
29
+ /* -- code point classification -------------------------------------------- */
30
+
31
+ #define XT_CP_ZWJ 0x200D
32
+
33
+ static int xt_cp_is_mark(int32_t cp) {
34
+ return (cp >= 0x0300 && cp <= 0x036f) || (cp >= 0x1ab0 && cp <= 0x1aff) ||
35
+ (cp >= 0x1dc0 && cp <= 0x1dff) || (cp >= 0x20d0 && cp <= 0x20ff) ||
36
+ (cp >= 0xfe20 && cp <= 0xfe2f) || (cp >= 0x0900 && cp <= 0x0903) ||
37
+ (cp >= 0x093a && cp <= 0x094f) || (cp >= 0x0e31 && cp <= 0x0e3a) ||
38
+ (cp >= 0x0e47 && cp <= 0x0e4e) || (cp >= 0x3099 && cp <= 0x309a);
39
+ }
40
+
41
+ static int xt_cp_is_variation_selector(int32_t cp) {
42
+ return (cp >= 0xfe00 && cp <= 0xfe0f) || (cp >= 0xe0100 && cp <= 0xe01ef);
43
+ }
44
+
45
+ static int xt_cp_is_emoji_modifier(int32_t cp) { return cp >= 0x1f3fb && cp <= 0x1f3ff; }
46
+
47
+ static int xt_cp_is_regional_indicator(int32_t cp) { return cp >= 0x1f1e6 && cp <= 0x1f1ff; }
48
+
49
+ static int xt_cp_is_whitespace(int32_t cp) {
50
+ return cp == 0x20 || (cp >= 0x09 && cp <= 0x0d) || cp == 0xa0 || cp == 0x1680 ||
51
+ (cp >= 0x2000 && cp <= 0x200a) || cp == 0x2028 || cp == 0x2029 || cp == 0x202f ||
52
+ cp == 0x205f || cp == 0x3000;
53
+ }
54
+
55
+ static int xt_cp_is_ascii_word(int32_t cp) {
56
+ return (cp >= '0' && cp <= '9') || (cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || cp == '_';
57
+ }
58
+
59
+ /* Non-ASCII letters are word characters for segmentation purposes; CJK,
60
+ * Cyrillic, Greek and accents all land here. Ranges that are clearly symbols
61
+ * (arrows, emoji, box drawing) are not. */
62
+ static int xt_cp_is_word(int32_t cp) {
63
+ if (xt_cp_is_ascii_word(cp)) return 1;
64
+ if (cp < 0x80) return 0;
65
+ if (xt_cp_is_whitespace(cp) || xt_cp_is_mark(cp)) return 0;
66
+ if (cp >= 0x1f000) return 0;
67
+ if (cp >= 0x2190 && cp <= 0x2bff) return 0;
68
+ if (cp >= 0x2500 && cp <= 0x259f) return 0;
69
+ if (cp >= 0x3000 && cp <= 0x303f) return 0;
70
+ return 1;
71
+ }
72
+
73
+ /* -- segment extraction ---------------------------------------------------- */
74
+
75
+ /** The text of `[start, end)` (UTF-16 units) as a JavaScript string. */
76
+ static xt_value xt_segment_text(xt_string *text, int32_t start, int32_t end) {
77
+ size_t capacity = (size_t)(end - start + 1) * 4;
78
+ char *buffer = (char *)malloc(capacity);
79
+ if (!buffer) return xt_string_from_cstr("");
80
+ size_t length = 0;
81
+ for (int32_t index = start; index < end;) {
82
+ int32_t code = xt_string_code_point_at(text, index);
83
+ if (code < 0) break;
84
+ index += code > 0xffff ? 2 : 1;
85
+ length += xt_utf8_encode((uint32_t)code, buffer + length);
86
+ }
87
+ xt_value segment = xt_string_new(buffer, length);
88
+ free(buffer);
89
+ return segment;
90
+ }
91
+
92
+ static void xt_segment_push(xt_value array, xt_string *text, int32_t start, int32_t end, int word_like) {
93
+ if (end <= start) return;
94
+ xt_value record = xt_object_new();
95
+ xt_object_set(record, xt_string_from_cstr("segment"), xt_segment_text(text, start, end));
96
+ xt_object_set(record, xt_string_from_cstr("index"), xt_number((double)start));
97
+ xt_object_set(record, xt_string_from_cstr("isWordLike"), xt_bool(word_like));
98
+ xt_array_push(array, record);
99
+ }
100
+
101
+ /* True when `code` attaches to the preceding cluster instead of starting one. */
102
+ static int xt_cp_extends_cluster(int32_t code) {
103
+ return xt_cp_is_mark(code) || xt_cp_is_variation_selector(code) || xt_cp_is_emoji_modifier(code) ||
104
+ code == XT_CP_ZWJ;
105
+ }
106
+
107
+ static xt_value xt_segment_graphemes(xt_string *text) {
108
+ xt_value array = xt_array_new(0, NULL);
109
+ int32_t units = (int32_t)xt_string_utf16_length(text);
110
+ int32_t start = 0;
111
+ int32_t index = 0;
112
+ int32_t cluster_codepoints = 0;
113
+ int32_t last_code = 0;
114
+ while (index < units) {
115
+ int32_t code = xt_string_code_point_at(text, index);
116
+ if (code < 0) break;
117
+ int32_t width = code > 0xffff ? 2 : 1;
118
+ int extends = index > start && xt_cp_extends_cluster(code);
119
+ /* A pair of regional indicators is one flag. */
120
+ if (!extends && index > start && xt_cp_is_regional_indicator(code) &&
121
+ xt_cp_is_regional_indicator(last_code) && cluster_codepoints == 1) {
122
+ extends = 1;
123
+ }
124
+ /* A ZWJ consumes the code point that follows it (emoji sequences). */
125
+ if (!extends && index > start && last_code == XT_CP_ZWJ) extends = 1;
126
+ if (!extends && index > start) {
127
+ xt_segment_push(array, text, start, index, 0);
128
+ start = index;
129
+ cluster_codepoints = 0;
130
+ }
131
+ cluster_codepoints++;
132
+ last_code = code;
133
+ index += width;
134
+ }
135
+ xt_segment_push(array, text, start, units, 0);
136
+ return array;
137
+ }
138
+
139
+ static xt_value xt_segment_words(xt_string *text) {
140
+ xt_value array = xt_array_new(0, NULL);
141
+ int32_t units = (int32_t)xt_string_utf16_length(text);
142
+ int32_t start = 0;
143
+ int32_t index = 0;
144
+ int class_of_run = -1; /* 0 punctuation, 1 word, 2 whitespace */
145
+ while (index < units) {
146
+ int32_t code = xt_string_code_point_at(text, index);
147
+ if (code < 0) break;
148
+ int32_t width = code > 0xffff ? 2 : 1;
149
+ int kind = xt_cp_is_whitespace(code) ? 2 : (xt_cp_is_word(code) ? 1 : 0);
150
+ /* Marks continue whatever run they land in. */
151
+ if (xt_cp_is_mark(code) && class_of_run >= 0) kind = class_of_run;
152
+ if (class_of_run >= 0 && kind != class_of_run) {
153
+ xt_segment_push(array, text, start, index, class_of_run == 1);
154
+ start = index;
155
+ }
156
+ class_of_run = kind;
157
+ index += width;
158
+ }
159
+ xt_segment_push(array, text, start, units, class_of_run == 1);
160
+ return array;
161
+ }
162
+
163
+ /* -- segmenter objects ---------------------------------------------------- */
164
+
165
+ static const char *xt_segmenter_granularity(xt_value segmenter) {
166
+ xt_value value = xt_object_get_cstr(segmenter, "__granularity");
167
+ const char *granularity = XT_IS_STRING(value) ? xt_string_data(value) : NULL;
168
+ return granularity ? granularity : "grapheme";
169
+ }
170
+
171
+ static xt_value xt_intl_segment(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
172
+ (void)env;
173
+ const char *granularity = xt_segmenter_granularity(thisValue);
174
+ xt_value input = xt_arg(argc, argv, 0);
175
+ xt_string *text = xt_as_string(xt_to_string(input));
176
+ if (!text) return xt_array_new(0, NULL);
177
+ if (strcmp(granularity, "word") == 0) return xt_segment_words(text);
178
+ if (strcmp(granularity, "sentence") == 0) return xt_segment_words(text);
179
+ return xt_segment_graphemes(text);
180
+ }
181
+
182
+ static xt_value xt_intl_resolved_options(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
183
+ (void)env;
184
+ (void)argc;
185
+ (void)argv;
186
+ xt_value options = xt_object_new();
187
+ xt_object_set(options, xt_string_from_cstr("locale"), xt_string_from_cstr("en"));
188
+ xt_object_set(options, xt_string_from_cstr("granularity"),
189
+ xt_string_from_cstr(xt_segmenter_granularity(thisValue)));
190
+ return options;
191
+ }
192
+
193
+ /* `new Intl.Segmenter(locale, { granularity })` returns the segmenter object
194
+ * itself; `xt_new` keeps it because a constructor that returns an object wins. */
195
+ static xt_value xt_intl_segmenter_ctor(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
196
+ (void)thisValue;
197
+ (void)env;
198
+ const char *granularity = "grapheme";
199
+ xt_value options = xt_arg(argc, argv, 1);
200
+ if (XT_IS_OBJECT(options)) {
201
+ xt_value requested = xt_object_get_cstr(options, "granularity");
202
+ if (XT_IS_STRING(requested)) granularity = xt_string_data(requested);
203
+ }
204
+ xt_value segmenter = xt_object_new();
205
+ xt_object_set(segmenter, xt_string_from_cstr("__granularity"), xt_string_from_cstr(granularity));
206
+ xt_value segment = xt_closure_new((void *)xt_intl_segment, 0, NULL);
207
+ xt_function_set_metadata(segment, xt_string_from_cstr("segment"), 1);
208
+ xt_object_set(segmenter, xt_string_from_cstr("segment"), segment);
209
+ xt_value resolved = xt_closure_new((void *)xt_intl_resolved_options, 0, NULL);
210
+ xt_function_set_metadata(resolved, xt_string_from_cstr("resolvedOptions"), 0);
211
+ xt_object_set(segmenter, xt_string_from_cstr("resolvedOptions"), resolved);
212
+ return segmenter;
213
+ }
214
+
215
+ xt_value xt_intl_object(void) {
216
+ xt_gc_add_root(&xt_intl_object_value);
217
+ if (xt_intl_object_value) return xt_intl_object_value;
218
+ xt_value intl = xt_object_new();
219
+ xt_value segmenter = xt_closure_new((void *)xt_intl_segmenter_ctor, 0, NULL);
220
+ xt_function_set_metadata(segmenter, xt_string_from_cstr("Segmenter"), 0);
221
+ xt_object_set(intl, xt_string_from_cstr("Segmenter"), segmenter);
222
+ xt_intl_object_value = intl;
223
+ return xt_intl_object_value;
224
+ }
@@ -129,3 +129,69 @@ xt_value xt_console_time_end(int32_t argc, xt_value *argv) {
129
129
  }
130
130
  return XT_UNDEFINED;
131
131
  }
132
+
133
+ /* ------------------------------------------------------------------------- */
134
+ /* The global `console` object */
135
+ /* ------------------------------------------------------------------------- */
136
+
137
+ /*
138
+ * `console` is a global *value* as well as a namespace: code writes
139
+ * `const log = console.log`, `console.error.bind(console)` and
140
+ * `const { warn } = console`, so the binding has to be a real object whose
141
+ * methods are ordinary first-class functions. The object is built once and
142
+ * rooted; each method is a closure over the raw `(argc, argv)` runtime symbol,
143
+ * so a method keeps its behaviour when detached from the object.
144
+ */
145
+
146
+ typedef void (*xt_console_void_method)(int32_t, xt_value *);
147
+ typedef xt_value (*xt_console_value_method)(int32_t, xt_value *);
148
+
149
+ static xt_value xt_console_void_bridge(xt_value thisValue, xt_value env, int32_t argc,
150
+ xt_value *argv) {
151
+ (void)thisValue;
152
+ ((xt_console_void_method)(uintptr_t)xt_closure_env(env, 0))(argc, argv);
153
+ return XT_UNDEFINED;
154
+ }
155
+
156
+ static xt_value xt_console_value_bridge(xt_value thisValue, xt_value env, int32_t argc,
157
+ xt_value *argv) {
158
+ (void)thisValue;
159
+ return ((xt_console_value_method)(uintptr_t)xt_closure_env(env, 0))(argc, argv);
160
+ }
161
+
162
+ static void xt_console_add(xt_value object, const char *name, void *method, int returnsValue) {
163
+ xt_value env[1];
164
+ env[0] = (xt_value)(uintptr_t)method;
165
+ xt_value closure = xt_closure_new(
166
+ returnsValue ? (void *)xt_console_value_bridge : (void *)xt_console_void_bridge, 1, env);
167
+ xt_value key = xt_string_from_cstr(name);
168
+ xt_function_set_metadata(closure, key, returnsValue ? 1 : 0);
169
+ xt_object_set(object, key, closure);
170
+ }
171
+
172
+ xt_value xt_console_object(int32_t argc, xt_value *argv) {
173
+ (void)argc;
174
+ (void)argv;
175
+ static xt_value cached = 0;
176
+ if (cached != 0) return cached;
177
+ xt_value object = xt_object_new();
178
+ xt_console_add(object, "log", (void *)xt_console_log, 0);
179
+ xt_console_add(object, "info", (void *)xt_console_info, 0);
180
+ xt_console_add(object, "warn", (void *)xt_console_warn, 0);
181
+ xt_console_add(object, "error", (void *)xt_console_error, 0);
182
+ xt_console_add(object, "debug", (void *)xt_console_log, 0);
183
+ xt_console_add(object, "dir", (void *)xt_console_dir, 1);
184
+ xt_console_add(object, "trace", (void *)xt_console_trace, 1);
185
+ xt_console_add(object, "assert", (void *)xt_console_assert, 1);
186
+ xt_console_add(object, "count", (void *)xt_console_count, 1);
187
+ xt_console_add(object, "countReset", (void *)xt_console_count_reset, 1);
188
+ xt_console_add(object, "group", (void *)xt_console_group, 1);
189
+ xt_console_add(object, "groupEnd", (void *)xt_console_group_end, 1);
190
+ xt_console_add(object, "table", (void *)xt_console_table, 1);
191
+ xt_console_add(object, "time", (void *)xt_console_time, 1);
192
+ xt_console_add(object, "timeEnd", (void *)xt_console_time_end, 1);
193
+ xt_console_add(object, "timeLog", (void *)xt_console_time_log, 1);
194
+ cached = object;
195
+ xt_gc_add_root(&cached);
196
+ return object;
197
+ }