xbintsc 0.3.87 → 0.5.20

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 (458) hide show
  1. package/AGENTS.md +23 -11
  2. package/README.md +11 -9
  3. package/README.zh-CN.md +7 -7
  4. package/dist/src/binder/declarations.js +14 -3
  5. package/dist/src/binder/declarations.js.map +1 -1
  6. package/dist/src/cli/hints.js +7 -1
  7. package/dist/src/cli/hints.js.map +1 -1
  8. package/dist/src/cli/main.js +115 -15
  9. package/dist/src/cli/main.js.map +1 -1
  10. package/dist/src/cli/watch.d.ts +25 -0
  11. package/dist/src/cli/watch.js +93 -0
  12. package/dist/src/cli/watch.js.map +1 -0
  13. package/dist/src/codegen/generator/calls/access.js +17 -4
  14. package/dist/src/codegen/generator/calls/access.js.map +1 -1
  15. package/dist/src/codegen/generator/calls/closures.js +13 -1
  16. package/dist/src/codegen/generator/calls/closures.js.map +1 -1
  17. package/dist/src/codegen/generator/calls/invocation.js +4 -3
  18. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  19. package/dist/src/codegen/generator/context.d.ts +8 -0
  20. package/dist/src/codegen/generator/context.js +22 -3
  21. package/dist/src/codegen/generator/context.js.map +1 -1
  22. package/dist/src/codegen/generator/expressions/operators.js +17 -15
  23. package/dist/src/codegen/generator/expressions/operators.js.map +1 -1
  24. package/dist/src/codegen/generator/expressions/primary.js +11 -1
  25. package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
  26. package/dist/src/codegen/generator/module.d.ts +0 -1
  27. package/dist/src/codegen/generator/module.js +10 -17
  28. package/dist/src/codegen/generator/module.js.map +1 -1
  29. package/dist/src/codegen/generator/numeric.d.ts +6 -3
  30. package/dist/src/codegen/generator/numeric.js +54 -11
  31. package/dist/src/codegen/generator/numeric.js.map +1 -1
  32. package/dist/src/codegen/generator/state.js +27 -0
  33. package/dist/src/codegen/generator/state.js.map +1 -1
  34. package/dist/src/codegen/generator/statements/control-flow.js +2 -7
  35. package/dist/src/codegen/generator/statements/control-flow.js.map +1 -1
  36. package/dist/src/codegen/generator/statements/loops.js +48 -16
  37. package/dist/src/codegen/generator/statements/loops.js.map +1 -1
  38. package/dist/src/codegen/generator/tables.d.ts +9 -0
  39. package/dist/src/codegen/generator/tables.js +100 -3
  40. package/dist/src/codegen/generator/tables.js.map +1 -1
  41. package/dist/src/diagnostics/diagnostic.d.ts +3 -1
  42. package/dist/src/diagnostics/diagnostic.js +23 -3
  43. package/dist/src/diagnostics/diagnostic.js.map +1 -1
  44. package/dist/src/driver/app-artifacts.d.ts +42 -0
  45. package/dist/src/driver/app-artifacts.js +53 -0
  46. package/dist/src/driver/app-artifacts.js.map +1 -0
  47. package/dist/src/driver/build-key.d.ts +29 -0
  48. package/dist/src/driver/build-key.js +35 -0
  49. package/dist/src/driver/build-key.js.map +1 -0
  50. package/dist/src/driver/bundler/graph.js +61 -12
  51. package/dist/src/driver/bundler/graph.js.map +1 -1
  52. package/dist/src/driver/bundler/merge.js +7 -1
  53. package/dist/src/driver/bundler/merge.js.map +1 -1
  54. package/dist/src/driver/compiler.d.ts +10 -67
  55. package/dist/src/driver/compiler.js +94 -230
  56. package/dist/src/driver/compiler.js.map +1 -1
  57. package/dist/src/driver/config.d.ts +3 -0
  58. package/dist/src/driver/config.js +8 -0
  59. package/dist/src/driver/config.js.map +1 -1
  60. package/dist/src/driver/frontend.d.ts +37 -0
  61. package/dist/src/driver/frontend.js +92 -0
  62. package/dist/src/driver/frontend.js.map +1 -0
  63. package/dist/src/driver/index.d.ts +1 -1
  64. package/dist/src/driver/index.js.map +1 -1
  65. package/dist/src/driver/options.d.ts +64 -0
  66. package/dist/src/driver/options.js +9 -0
  67. package/dist/src/driver/options.js.map +1 -0
  68. package/dist/src/driver/runtime-objects.d.ts +38 -0
  69. package/dist/src/driver/runtime-objects.js +111 -0
  70. package/dist/src/driver/runtime-objects.js.map +1 -0
  71. package/dist/src/driver/toolchain-provider.d.ts +4 -0
  72. package/dist/src/driver/toolchain-provider.js +4 -0
  73. package/dist/src/driver/toolchain-provider.js.map +1 -1
  74. package/dist/src/driver/toolchain.d.ts +32 -1
  75. package/dist/src/driver/toolchain.js +115 -11
  76. package/dist/src/driver/toolchain.js.map +1 -1
  77. package/dist/src/driver/version.d.ts +12 -0
  78. package/dist/src/driver/version.js +13 -0
  79. package/dist/src/driver/version.js.map +1 -0
  80. package/dist/src/driver/win-icon.d.ts +7 -9
  81. package/dist/src/driver/win-icon.js +37 -35
  82. package/dist/src/driver/win-icon.js.map +1 -1
  83. package/dist/src/parser/declarations/classes.js +5 -0
  84. package/dist/src/parser/declarations/classes.js.map +1 -1
  85. package/dist/src/parser/declarations/functions.js +13 -1
  86. package/dist/src/parser/declarations/functions.js.map +1 -1
  87. package/dist/src/parser/modules.js +8 -3
  88. package/dist/src/parser/modules.js.map +1 -1
  89. package/dist/src/parser/parser.d.ts +1 -0
  90. package/dist/src/parser/parser.js +23 -0
  91. package/dist/src/parser/parser.js.map +1 -1
  92. package/dist/tests/cli/check.test.d.ts +6 -0
  93. package/dist/tests/cli/check.test.js +68 -0
  94. package/dist/tests/cli/check.test.js.map +1 -0
  95. package/dist/tests/cli/main.test.js +19 -0
  96. package/dist/tests/cli/main.test.js.map +1 -1
  97. package/dist/tests/cli/watch.test.d.ts +6 -0
  98. package/dist/tests/cli/watch.test.js +72 -0
  99. package/dist/tests/cli/watch.test.js.map +1 -0
  100. package/dist/tests/codegen/closures.test.js +8 -0
  101. package/dist/tests/codegen/closures.test.js.map +1 -1
  102. package/dist/tests/codegen/expressions.test.js +15 -3
  103. package/dist/tests/codegen/expressions.test.js.map +1 -1
  104. package/dist/tests/codegen/llvm.test.js +16 -0
  105. package/dist/tests/codegen/llvm.test.js.map +1 -1
  106. package/dist/tests/diagnostics/diagnostic.test.js +8 -0
  107. package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
  108. package/dist/tests/docs/structure.test.d.ts +1 -0
  109. package/dist/tests/docs/structure.test.js +92 -0
  110. package/dist/tests/docs/structure.test.js.map +1 -0
  111. package/dist/tests/driver/compiler.test.js +6 -0
  112. package/dist/tests/driver/compiler.test.js.map +1 -1
  113. package/dist/tests/driver/config.test.js +9 -0
  114. package/dist/tests/driver/config.test.js.map +1 -1
  115. package/dist/tests/driver/icon.test.js +19 -32
  116. package/dist/tests/driver/icon.test.js.map +1 -1
  117. package/dist/tests/driver/invalid-input.test.d.ts +10 -0
  118. package/dist/tests/driver/invalid-input.test.js +29 -0
  119. package/dist/tests/driver/invalid-input.test.js.map +1 -0
  120. package/dist/tests/driver/modules.test.js +42 -3
  121. package/dist/tests/driver/modules.test.js.map +1 -1
  122. package/dist/tests/driver/toolchain-provider.test.js +27 -1
  123. package/dist/tests/driver/toolchain-provider.test.js.map +1 -1
  124. package/dist/tests/driver/toolchain.test.js +60 -2
  125. package/dist/tests/driver/toolchain.test.js.map +1 -1
  126. package/dist/tests/e2e/array-buffer.test.d.ts +5 -0
  127. package/dist/tests/e2e/array-buffer.test.js +38 -0
  128. package/dist/tests/e2e/array-buffer.test.js.map +1 -0
  129. package/dist/tests/e2e/array-from-iterables.test.d.ts +7 -0
  130. package/dist/tests/e2e/array-from-iterables.test.js +34 -0
  131. package/dist/tests/e2e/array-from-iterables.test.js.map +1 -0
  132. package/dist/tests/e2e/array-symbol-iterator.test.d.ts +8 -0
  133. package/dist/tests/e2e/array-symbol-iterator.test.js +42 -0
  134. package/dist/tests/e2e/array-symbol-iterator.test.js.map +1 -0
  135. package/dist/tests/e2e/async-await.test.d.ts +10 -0
  136. package/dist/tests/e2e/async-await.test.js +247 -0
  137. package/dist/tests/e2e/async-await.test.js.map +1 -0
  138. package/dist/tests/e2e/async-generators.test.d.ts +1 -0
  139. package/dist/tests/e2e/async-generators.test.js +154 -0
  140. package/dist/tests/e2e/async-generators.test.js.map +1 -0
  141. package/dist/tests/e2e/await-ordering.test.d.ts +5 -0
  142. package/dist/tests/e2e/await-ordering.test.js +37 -0
  143. package/dist/tests/e2e/await-ordering.test.js.map +1 -0
  144. package/dist/tests/e2e/compile-builtins.test.js +1 -1
  145. package/dist/tests/e2e/compile-modules.test.js +7 -0
  146. package/dist/tests/e2e/compile-modules.test.js.map +1 -1
  147. package/dist/tests/e2e/date-parse.test.d.ts +8 -0
  148. package/dist/tests/e2e/date-parse.test.js +38 -0
  149. package/dist/tests/e2e/date-parse.test.js.map +1 -0
  150. package/dist/tests/e2e/default-anonymous-exports.test.d.ts +7 -0
  151. package/dist/tests/e2e/default-anonymous-exports.test.js +23 -0
  152. package/dist/tests/e2e/default-anonymous-exports.test.js.map +1 -0
  153. package/dist/tests/e2e/globals-microtask.test.d.ts +9 -0
  154. package/dist/tests/e2e/globals-microtask.test.js +37 -0
  155. package/dist/tests/e2e/globals-microtask.test.js.map +1 -0
  156. package/dist/tests/e2e/gui-media.test.js +8 -1
  157. package/dist/tests/e2e/gui-media.test.js.map +1 -1
  158. package/dist/tests/e2e/inspect-builtins.test.d.ts +10 -0
  159. package/dist/tests/e2e/inspect-builtins.test.js +43 -0
  160. package/dist/tests/e2e/inspect-builtins.test.js.map +1 -0
  161. package/dist/tests/e2e/json-builtin-objects.test.d.ts +9 -0
  162. package/dist/tests/e2e/json-builtin-objects.test.js +23 -0
  163. package/dist/tests/e2e/json-builtin-objects.test.js.map +1 -0
  164. package/dist/tests/e2e/json-circular.test.d.ts +6 -0
  165. package/dist/tests/e2e/json-circular.test.js +43 -0
  166. package/dist/tests/e2e/json-circular.test.js.map +1 -0
  167. package/dist/tests/e2e/json-parse-reviver.test.d.ts +6 -0
  168. package/dist/tests/e2e/json-parse-reviver.test.js +29 -0
  169. package/dist/tests/e2e/json-parse-reviver.test.js.map +1 -0
  170. package/dist/tests/e2e/json-stringify-replacer.test.d.ts +6 -0
  171. package/dist/tests/e2e/json-stringify-replacer.test.js +27 -0
  172. package/dist/tests/e2e/json-stringify-replacer.test.js.map +1 -0
  173. package/dist/tests/e2e/json-stringify-space.test.d.ts +6 -0
  174. package/dist/tests/e2e/json-stringify-space.test.js +23 -0
  175. package/dist/tests/e2e/json-stringify-space.test.js.map +1 -0
  176. package/dist/tests/e2e/method-dispatch-errors.test.d.ts +9 -0
  177. package/dist/tests/e2e/method-dispatch-errors.test.js +38 -0
  178. package/dist/tests/e2e/method-dispatch-errors.test.js.map +1 -0
  179. package/dist/tests/e2e/native-extensions.test.js +1 -1
  180. package/dist/tests/e2e/native-extensions.test.js.map +1 -1
  181. package/dist/tests/e2e/promise-with-resolvers.test.d.ts +5 -0
  182. package/dist/tests/e2e/promise-with-resolvers.test.js +20 -0
  183. package/dist/tests/e2e/promise-with-resolvers.test.js.map +1 -0
  184. package/dist/tests/e2e/property-descriptors.test.d.ts +5 -0
  185. package/dist/tests/e2e/property-descriptors.test.js +25 -0
  186. package/dist/tests/e2e/property-descriptors.test.js.map +1 -0
  187. package/dist/tests/e2e/property-ic.test.d.ts +1 -0
  188. package/dist/tests/e2e/property-ic.test.js +55 -0
  189. package/dist/tests/e2e/property-ic.test.js.map +1 -0
  190. package/dist/tests/e2e/runtime-coverage-globals.test.js +46 -0
  191. package/dist/tests/e2e/runtime-coverage-globals.test.js.map +1 -1
  192. package/dist/tests/e2e/runtime-errors.test.d.ts +10 -0
  193. package/dist/tests/e2e/runtime-errors.test.js +52 -0
  194. package/dist/tests/e2e/runtime-errors.test.js.map +1 -0
  195. package/dist/tests/e2e/string-utf16.test.d.ts +6 -0
  196. package/dist/tests/e2e/string-utf16.test.js +133 -0
  197. package/dist/tests/e2e/string-utf16.test.js.map +1 -0
  198. package/dist/tests/e2e/structured-clone.test.d.ts +6 -0
  199. package/dist/tests/e2e/structured-clone.test.js +49 -0
  200. package/dist/tests/e2e/structured-clone.test.js.map +1 -0
  201. package/dist/tests/e2e/text-codec.test.d.ts +6 -0
  202. package/dist/tests/e2e/text-codec.test.js +24 -0
  203. package/dist/tests/e2e/text-codec.test.js.map +1 -0
  204. package/dist/tests/e2e/typed-array-views.test.d.ts +6 -0
  205. package/dist/tests/e2e/typed-array-views.test.js +39 -0
  206. package/dist/tests/e2e/typed-array-views.test.js.map +1 -0
  207. package/dist/tests/e2e/url-search-params.test.d.ts +5 -0
  208. package/dist/tests/e2e/url-search-params.test.js +30 -0
  209. package/dist/tests/e2e/url-search-params.test.js.map +1 -0
  210. package/dist/tests/e2e/weak-collections.test.d.ts +1 -0
  211. package/dist/tests/e2e/weak-collections.test.js +88 -0
  212. package/dist/tests/e2e/weak-collections.test.js.map +1 -0
  213. package/dist/tests/parser/declarations.test.js +12 -0
  214. package/dist/tests/parser/declarations.test.js.map +1 -1
  215. package/dist/tests/parser/module-syntax.test.js +9 -0
  216. package/dist/tests/parser/module-syntax.test.js.map +1 -1
  217. package/dist/tests/parser/parser.test.js +7 -0
  218. package/dist/tests/parser/parser.test.js.map +1 -1
  219. package/dist/tests/version.test.js +5 -1
  220. package/dist/tests/version.test.js.map +1 -1
  221. package/doc/ai/README.md +4 -3
  222. package/doc/ai/cli.md +41 -0
  223. package/doc/ai/contributing.md +26 -21
  224. package/doc/ai/extensions.md +12 -9
  225. package/doc/ai/language-support.md +26 -19
  226. package/doc/ai/troubleshooting.md +15 -12
  227. package/doc/ai/zh-CN/README.md +3 -2
  228. package/doc/ai/zh-CN/cli.md +35 -0
  229. package/doc/ai/zh-CN/contributing.md +19 -18
  230. package/doc/ai/zh-CN/extensions.md +10 -7
  231. package/doc/ai/zh-CN/language-support.md +26 -20
  232. package/doc/ai/zh-CN/troubleshooting.md +12 -10
  233. package/doc/gui/build.md +13 -4
  234. package/doc/gui/known-issues.md +9 -5
  235. package/doc/gui/rendering.md +3 -1
  236. package/doc/gui.md +4 -3
  237. package/doc/icon.md +5 -4
  238. package/doc/implemented/async.md +38 -0
  239. package/doc/implemented/binder.md +13 -0
  240. package/doc/implemented/cli.md +47 -0
  241. package/doc/implemented/codegen.md +33 -0
  242. package/doc/implemented/collections.md +26 -0
  243. package/doc/implemented/driver.md +19 -0
  244. package/doc/implemented/extensions.md +19 -0
  245. package/doc/implemented/fetch.md +12 -0
  246. package/doc/implemented/lexer.md +23 -0
  247. package/doc/implemented/modules.md +28 -0
  248. package/doc/implemented/node/assert.md +17 -0
  249. package/doc/implemented/node/buffer.md +29 -0
  250. package/doc/implemented/node/child-process.md +29 -0
  251. package/doc/implemented/node/crypto.md +9 -0
  252. package/doc/implemented/node/dgram.md +15 -0
  253. package/doc/implemented/node/events.md +37 -0
  254. package/doc/implemented/node/fs-promises.md +38 -0
  255. package/doc/implemented/node/fs.md +112 -0
  256. package/doc/implemented/node/http.md +21 -0
  257. package/doc/implemented/node/net.md +17 -0
  258. package/doc/implemented/node/os.md +22 -0
  259. package/doc/implemented/node/path.md +33 -0
  260. package/doc/implemented/node/process.md +23 -0
  261. package/doc/implemented/node/querystring.md +20 -0
  262. package/doc/implemented/node/stream-promises.md +8 -0
  263. package/doc/implemented/node/stream.md +19 -0
  264. package/doc/implemented/node/test.md +10 -0
  265. package/doc/implemented/node/url.md +8 -0
  266. package/doc/implemented/node/util.md +25 -0
  267. package/doc/implemented/node/worker-threads.md +10 -0
  268. package/doc/implemented/node/zlib.md +8 -0
  269. package/doc/implemented/node.md +48 -0
  270. package/doc/implemented/operators.md +38 -0
  271. package/doc/implemented/parser.md +58 -0
  272. package/doc/implemented/pipeline.md +28 -0
  273. package/doc/implemented/runtime-core.md +32 -0
  274. package/doc/implemented/stdlib.md +78 -0
  275. package/doc/implemented/strings.md +27 -0
  276. package/doc/implemented/tests.md +10 -0
  277. package/doc/implemented/typed-arrays.md +26 -0
  278. package/doc/implemented/value-model.md +18 -0
  279. package/doc/implemented.md +54 -352
  280. package/doc/node-implemented.md +3 -585
  281. package/doc/node-unimplemented.md +3 -164
  282. package/doc/requirements.md +23 -8
  283. package/doc/unimplemented/classes.md +22 -0
  284. package/doc/unimplemented/deviations.md +27 -0
  285. package/doc/unimplemented/expressions.md +26 -0
  286. package/doc/unimplemented/functions.md +21 -0
  287. package/doc/unimplemented/modules.md +22 -0
  288. package/doc/unimplemented/node/async.md +17 -0
  289. package/doc/unimplemented/node/bun.md +9 -0
  290. package/doc/unimplemented/node/fs-promises.md +16 -0
  291. package/doc/unimplemented/node/fs.md +31 -0
  292. package/doc/unimplemented/node/globals.md +23 -0
  293. package/doc/unimplemented/node/modules.md +21 -0
  294. package/doc/unimplemented/node.md +21 -0
  295. package/doc/unimplemented/statements.md +18 -0
  296. package/doc/unimplemented/stdlib.md +54 -0
  297. package/doc/unimplemented/toolchain.md +14 -0
  298. package/doc/unimplemented/types.md +12 -0
  299. package/doc/unimplemented.md +18 -274
  300. package/doc/xbintsc.config.schema.json +12 -0
  301. package/doc/zh-CN/gui/build.md +11 -3
  302. package/doc/zh-CN/gui/known-issues.md +9 -4
  303. package/doc/zh-CN/gui/rendering.md +2 -1
  304. package/doc/zh-CN/gui.md +3 -2
  305. package/doc/zh-CN/icon.md +5 -4
  306. package/doc/zh-CN/implemented/async.md +38 -0
  307. package/doc/zh-CN/implemented/binder.md +13 -0
  308. package/doc/zh-CN/implemented/cli.md +46 -0
  309. package/doc/zh-CN/implemented/codegen.md +33 -0
  310. package/doc/zh-CN/implemented/collections.md +26 -0
  311. package/doc/zh-CN/implemented/driver.md +19 -0
  312. package/doc/zh-CN/implemented/extensions.md +19 -0
  313. package/doc/zh-CN/implemented/fetch.md +12 -0
  314. package/doc/zh-CN/implemented/lexer.md +23 -0
  315. package/doc/zh-CN/implemented/modules.md +28 -0
  316. package/doc/zh-CN/implemented/node/assert.md +17 -0
  317. package/doc/zh-CN/implemented/node/buffer.md +25 -0
  318. package/doc/zh-CN/implemented/node/child-process.md +27 -0
  319. package/doc/zh-CN/implemented/node/crypto.md +9 -0
  320. package/doc/zh-CN/implemented/node/dgram.md +15 -0
  321. package/doc/zh-CN/implemented/node/events.md +36 -0
  322. package/doc/zh-CN/implemented/node/fs-promises.md +27 -0
  323. package/doc/zh-CN/implemented/node/fs.md +105 -0
  324. package/doc/zh-CN/implemented/node/http.md +17 -0
  325. package/doc/zh-CN/implemented/node/net.md +17 -0
  326. package/doc/zh-CN/implemented/node/os.md +21 -0
  327. package/doc/zh-CN/implemented/node/path.md +26 -0
  328. package/doc/zh-CN/implemented/node/process.md +23 -0
  329. package/doc/zh-CN/implemented/node/querystring.md +20 -0
  330. package/doc/zh-CN/implemented/node/stream-promises.md +8 -0
  331. package/doc/zh-CN/implemented/node/stream.md +15 -0
  332. package/doc/zh-CN/implemented/node/test.md +10 -0
  333. package/doc/zh-CN/implemented/node/url.md +8 -0
  334. package/doc/zh-CN/implemented/node/util.md +25 -0
  335. package/doc/zh-CN/implemented/node/worker-threads.md +9 -0
  336. package/doc/zh-CN/implemented/node/zlib.md +8 -0
  337. package/doc/zh-CN/implemented/node.md +45 -0
  338. package/doc/zh-CN/implemented/operators.md +38 -0
  339. package/doc/zh-CN/implemented/parser.md +58 -0
  340. package/doc/zh-CN/implemented/pipeline.md +25 -0
  341. package/doc/zh-CN/implemented/runtime-core.md +31 -0
  342. package/doc/zh-CN/implemented/stdlib.md +76 -0
  343. package/doc/zh-CN/implemented/strings.md +27 -0
  344. package/doc/zh-CN/implemented/tests.md +10 -0
  345. package/doc/zh-CN/implemented/typed-arrays.md +26 -0
  346. package/doc/zh-CN/implemented/value-model.md +18 -0
  347. package/doc/zh-CN/implemented.md +50 -347
  348. package/doc/zh-CN/node-implemented.md +4 -531
  349. package/doc/zh-CN/node-unimplemented.md +4 -139
  350. package/doc/zh-CN/plan-require-node-modules.md +4 -4
  351. package/doc/zh-CN/requirements.md +20 -6
  352. package/doc/zh-CN/unimplemented/classes.md +22 -0
  353. package/doc/zh-CN/unimplemented/deviations.md +24 -0
  354. package/doc/zh-CN/unimplemented/expressions.md +24 -0
  355. package/doc/zh-CN/unimplemented/functions.md +21 -0
  356. package/doc/zh-CN/unimplemented/modules.md +19 -0
  357. package/doc/zh-CN/unimplemented/node/async.md +17 -0
  358. package/doc/zh-CN/unimplemented/node/bun.md +8 -0
  359. package/doc/zh-CN/unimplemented/node/fs-promises.md +12 -0
  360. package/doc/zh-CN/unimplemented/node/fs.md +24 -0
  361. package/doc/zh-CN/unimplemented/node/globals.md +14 -0
  362. package/doc/zh-CN/unimplemented/node/modules.md +15 -0
  363. package/doc/zh-CN/unimplemented/node.md +18 -0
  364. package/doc/zh-CN/unimplemented/statements.md +15 -0
  365. package/doc/zh-CN/unimplemented/stdlib.md +54 -0
  366. package/doc/zh-CN/unimplemented/toolchain.md +14 -0
  367. package/doc/zh-CN/unimplemented/types.md +11 -0
  368. package/doc/zh-CN/unimplemented.md +14 -236
  369. package/llms.txt +32 -4
  370. package/package.json +1 -1
  371. package/runtime/ext_gui/renderer_shaders.h +2 -2
  372. package/runtime/ext_gui/stb_image.h +1 -17
  373. package/runtime/ext_node/child_process/child_process.c +173 -73
  374. package/runtime/rt.h +47 -0
  375. package/runtime/rt_internal.h +205 -10
  376. package/runtime/xt_alloc.c +49 -7
  377. package/runtime/xt_array_buffer.c +284 -0
  378. package/runtime/xt_async.c +222 -0
  379. package/runtime/xt_bigint/helpers.inc +3 -3
  380. package/runtime/xt_builtins.c +59 -51
  381. package/runtime/xt_constructors.c +399 -0
  382. package/runtime/xt_containers/access.inc +195 -14
  383. package/runtime/xt_containers/arrays.inc +26 -2
  384. package/runtime/xt_containers/objects.inc +226 -5
  385. package/runtime/xt_containers/shapes.inc +71 -0
  386. package/runtime/xt_containers.c +1 -0
  387. package/runtime/xt_coroutine.c +229 -0
  388. package/runtime/xt_generator.c +325 -167
  389. package/runtime/xt_io/inspect.inc +147 -2
  390. package/runtime/xt_loop.c +35 -4
  391. package/runtime/xt_performance.c +37 -0
  392. package/runtime/xt_promise.c +125 -18
  393. package/runtime/xt_stdlib/arrays.inc +1 -1
  394. package/runtime/xt_stdlib/dispatch.inc +64 -13
  395. package/runtime/xt_stdlib/strings.inc +74 -17
  396. package/runtime/xt_stdlib2/array-statics.inc +28 -3
  397. package/runtime/xt_stdlib2/arrays.inc +5 -3
  398. package/runtime/xt_stdlib2/container.inc +5 -0
  399. package/runtime/xt_stdlib2/date.inc +111 -3
  400. package/runtime/xt_stdlib2/error.inc +35 -0
  401. package/runtime/xt_stdlib2/json.inc +353 -33
  402. package/runtime/xt_stdlib2/number-string-statics.inc +24 -15
  403. package/runtime/xt_stdlib2/objects.inc +123 -1
  404. package/runtime/xt_stdlib2/regexp-match.inc +2 -2
  405. package/runtime/xt_stdlib2/set.inc +7 -1
  406. package/runtime/xt_stdlib2/strings.inc +70 -40
  407. package/runtime/xt_structured_clone.c +159 -0
  408. package/runtime/xt_symbol.c +2 -2
  409. package/runtime/xt_text_codec.c +69 -0
  410. package/runtime/xt_typed_array/construction.inc +78 -7
  411. package/runtime/xt_typed_array/elements.inc +159 -0
  412. package/runtime/xt_typed_array/methods.inc +21 -5
  413. package/runtime/xt_typed_array.c +11 -10
  414. package/runtime/xt_url.c +375 -0
  415. package/runtime/xt_values/arithmetic.inc +2 -2
  416. package/runtime/xt_values/constructors.inc +8 -0
  417. package/runtime/xt_values/conversions.inc +1 -1
  418. package/runtime/xt_values/strings.inc +19 -3
  419. package/runtime/xt_values/utf16.inc +340 -0
  420. package/runtime/xt_values.c +1 -0
  421. package/runtime/xt_weak.c +281 -0
  422. package/scripts/build-gui.ts +133 -60
  423. package/scripts/check-version.ts +3 -3
  424. package/src/binder/declarations.ts +14 -3
  425. package/src/cli/hints.ts +8 -1
  426. package/src/cli/main.ts +119 -18
  427. package/src/cli/watch.ts +101 -0
  428. package/src/codegen/generator/calls/access.ts +17 -4
  429. package/src/codegen/generator/calls/closures.ts +12 -1
  430. package/src/codegen/generator/calls/invocation.ts +4 -3
  431. package/src/codegen/generator/context.ts +23 -3
  432. package/src/codegen/generator/expressions/operators.ts +27 -13
  433. package/src/codegen/generator/expressions/primary.ts +10 -1
  434. package/src/codegen/generator/module.ts +10 -19
  435. package/src/codegen/generator/numeric.ts +85 -11
  436. package/src/codegen/generator/state.ts +27 -0
  437. package/src/codegen/generator/statements/control-flow.ts +2 -6
  438. package/src/codegen/generator/statements/loops.ts +50 -16
  439. package/src/codegen/generator/tables.ts +110 -3
  440. package/src/diagnostics/diagnostic.ts +23 -3
  441. package/src/driver/app-artifacts.ts +77 -0
  442. package/src/driver/build-key.ts +55 -0
  443. package/src/driver/bundler/graph.ts +63 -13
  444. package/src/driver/bundler/merge.ts +4 -1
  445. package/src/driver/compiler.ts +93 -324
  446. package/src/driver/config.ts +11 -0
  447. package/src/driver/frontend.ts +120 -0
  448. package/src/driver/index.ts +0 -1
  449. package/src/driver/options.ts +70 -0
  450. package/src/driver/runtime-objects.ts +133 -0
  451. package/src/driver/toolchain-provider.ts +4 -0
  452. package/src/driver/toolchain.ts +154 -10
  453. package/src/driver/version.ts +12 -0
  454. package/src/driver/win-icon.ts +36 -36
  455. package/src/parser/declarations/classes.ts +4 -0
  456. package/src/parser/declarations/functions.ts +12 -1
  457. package/src/parser/modules.ts +8 -4
  458. package/src/parser/parser.ts +28 -0
package/runtime/rt.h CHANGED
@@ -96,7 +96,10 @@ xt_value xt_string_from_cstr(const char *data);
96
96
  * Materialises a lazily concatenated string, so the returned pointer is stable
97
97
  * until the string is collected. */
98
98
  const char *xt_string_data(xt_value value);
99
+ /** Byte length of the UTF-8 storage (what I/O and C extensions consume). */
99
100
  int32_t xt_string_length_value(xt_value value);
101
+ /** JavaScript `String.prototype.length`: UTF-16 code units. */
102
+ int32_t xt_string_utf16_length_value(xt_value value);
100
103
 
101
104
  /* -- bigint -------------------------------------------------------------- */
102
105
  xt_value xt_bigint_from_string(const char *data, size_t len);
@@ -125,6 +128,12 @@ xt_value xt_instance_of(xt_value value, xt_value ctor);
125
128
  xt_value xt_instance_of_builtin(xt_value value, int32_t id);
126
129
  xt_value xt_function_set_prototype(xt_value fn, xt_value proto);
127
130
  xt_value xt_function_get_prototype(xt_value fn);
131
+ /** Mark a closure as a generator so calling it creates a suspended generator. */
132
+ xt_value xt_function_set_generator(xt_value fn);
133
+ /** Mark a closure as an `async` function so calling it starts a coroutine. */
134
+ xt_value xt_function_set_async(xt_value fn);
135
+ /** Mark a closure as an `async function*` (generator + async iterator). */
136
+ xt_value xt_function_set_async_generator(xt_value fn);
128
137
 
129
138
  /* -- conversions ---------------------------------------------------------- */
130
139
  int xt_truthy(xt_value v);
@@ -163,6 +172,10 @@ xt_value xt_not(xt_value a);
163
172
  /* -- objects -------------------------------------------------------------- */
164
173
  xt_value xt_object_new(void);
165
174
  xt_value xt_object_new_with_proto(xt_value proto);
175
+ /** The shared `Object.prototype` object (root of the ordinary object chain). */
176
+ xt_value xt_object_prototype(void);
177
+ /** The shared `Function.prototype` object. */
178
+ xt_value xt_function_prototype(void);
166
179
  xt_value xt_object_get(xt_value obj, xt_value key);
167
180
  xt_value xt_object_get_prototype(xt_value obj);
168
181
  xt_value xt_object_set_prototype(xt_value obj, xt_value proto);
@@ -193,6 +206,17 @@ xt_value xt_symbol_static(xt_value name, int32_t argc, xt_value *argv);
193
206
  xt_value xt_symbol_get(xt_value name);
194
207
 
195
208
  /* -- standard library dispatch -------------------------------------------- */
209
+ /* -- built-in constructors as first-class values -------------------------- */
210
+ /** The first-class value of a built-in constructor (`Array`, `Map`, ...). */
211
+ xt_value xt_builtin_constructor(xt_value name);
212
+ /** A static method/value of a first-class constructor (`A.isArray`, ...). */
213
+ xt_value xt_builtin_static_value(xt_value ctor, xt_value key);
214
+ /** The constructor prototype for a runtime object kind (`Map` -> Map.prototype). */
215
+ xt_value xt_builtin_prototype_for_kind(int32_t kind);
216
+ /** `Array(...)` / `new Array(...)`. */
217
+ xt_value xt_array_ctor(int32_t argc, xt_value *argv);
218
+ /** `Object(...)` / `new Object(...)`. */
219
+ xt_value xt_object_ctor(int32_t argc, xt_value *argv);
196
220
  /** Call `target[name](...)`, falling back to built-in Array/String methods. */
197
221
  xt_value xt_call_method(xt_value target, xt_value name, int32_t argc, xt_value *argv);
198
222
  /** Implements `Math.<name>(...)`; the name is interned by the compiler. */
@@ -207,6 +231,14 @@ xt_value xt_object_static(xt_value name, int32_t argc, xt_value *argv);
207
231
  /** Implements `Number.<name>(...)` / `String.<name>(...)` statics. */
208
232
  xt_value xt_number_static(xt_value name, int32_t argc, xt_value *argv);
209
233
  xt_value xt_string_static(xt_value name, int32_t argc, xt_value *argv);
234
+ /** Typed-array constructor/static/prototype dispatch by constructor name. */
235
+ xt_value xt_typed_array_ctor_by_name(xt_value name, int32_t argc, xt_value *argv);
236
+ xt_value xt_typed_array_static_by_name(xt_value name, xt_value method, int32_t argc, xt_value *argv);
237
+ xt_value xt_typed_array_prototype(xt_value name);
238
+ /** Error-family construction and prototype lookup by constructor name. */
239
+ xt_value xt_error_ctor_by_name(xt_value name, int32_t argc, xt_value *argv);
240
+ xt_value xt_error_prototype(xt_value name);
241
+ xt_value xt_error_constructor(xt_value name);
210
242
  /** Map / Set constructors and dispatch. */
211
243
  xt_value xt_map_ctor(int32_t argc, xt_value *argv);
212
244
  xt_value xt_set_ctor(int32_t argc, xt_value *argv);
@@ -229,6 +261,8 @@ xt_value xt_child_process_spawn_sync(int32_t argc, xt_value *argv);
229
261
  xt_value xt_fetch(int32_t argc, xt_value *argv);
230
262
  /** Construct a `TypeError` with one message argument (used by `fetch`). */
231
263
  xt_value xt_type_error_ctor(int32_t argc, xt_value *argv);
264
+ /** Construct a `RangeError` with one message argument. */
265
+ xt_value xt_range_error_ctor(int32_t argc, xt_value *argv);
232
266
 
233
267
  /* -- promises / async ----------------------------------------------------- */
234
268
  xt_value xt_promise_resolve(xt_value value);
@@ -285,6 +319,12 @@ xt_value xt_set_timeout(int32_t argc, xt_value *argv);
285
319
  xt_value xt_clear_timeout(int32_t argc, xt_value *argv);
286
320
  xt_value xt_set_interval(int32_t argc, xt_value *argv);
287
321
  xt_value xt_clear_interval(int32_t argc, xt_value *argv);
322
+ /* `setImmediate` runs on the timer queue with a zero delay; `clearImmediate`
323
+ * is an alias of `clearTimeout` (ids share one namespace). */
324
+ xt_value xt_set_immediate(int32_t argc, xt_value *argv);
325
+ xt_value xt_clear_immediate(int32_t argc, xt_value *argv);
326
+ /* Schedule `callback` on the promise microtask queue (same FIFO as `.then`). */
327
+ xt_value xt_queue_microtask(int32_t argc, xt_value *argv);
288
328
 
289
329
  /* -- global functions ------------------------------------------------------ */
290
330
  xt_value xt_parse_int(int32_t argc, xt_value *argv);
@@ -298,6 +338,8 @@ xt_value xt_decode_uri(int32_t argc, xt_value *argv);
298
338
  xt_value xt_number_ctor(int32_t argc, xt_value *argv);
299
339
  xt_value xt_string_ctor(int32_t argc, xt_value *argv);
300
340
  xt_value xt_boolean_ctor(int32_t argc, xt_value *argv);
341
+ /* Deep clone arrays/objects/Map/Set/Date/RegExp/typed arrays. */
342
+ xt_value xt_structured_clone(int32_t argc, xt_value *argv);
301
343
  /** `key in obj` (the key is the left operand). */
302
344
  xt_value xt_in(xt_value key, xt_value obj);
303
345
  /** `delete obj[key]`; removes object properties, clears array elements. */
@@ -314,6 +356,8 @@ extern char **xt_program_argv;
314
356
 
315
357
  /* -- arrays --------------------------------------------------------------- */
316
358
  xt_value xt_array_new(int32_t count, xt_value *items);
359
+ /** The shared `Array.prototype` array. */
360
+ xt_value xt_array_prototype(void);
317
361
  xt_value xt_array_get(xt_value arr, xt_value index);
318
362
  xt_value xt_array_set(xt_value arr, xt_value index, xt_value value);
319
363
  xt_value xt_array_push(xt_value arr, xt_value value);
@@ -328,6 +372,9 @@ xt_value xt_iter_value(xt_value value, xt_value index);
328
372
 
329
373
  /* -- generic member access ------------------------------------------------ */
330
374
  xt_value xt_get(xt_value target, xt_value key);
375
+ /** Interned shape/offset inline cache for a property read. `cache` points at
376
+ * two zero-initialised i64 words owned by the generated code. */
377
+ xt_value xt_get_ic(xt_value target, xt_value key, int64_t *cache);
331
378
  xt_value xt_set(xt_value target, xt_value key, xt_value value);
332
379
  /* Materialise a first-class runtime method value (`arr.map`) as an unbound
333
380
  * closure that expects the receiver through `this`. Returns `XT_UNDEFINED` when
@@ -21,12 +21,15 @@
21
21
  * code free of write barriers and makes the first implementation small and
22
22
  * predictable. Replacing it with a precise/conservative collector is an
23
23
  * isolated change behind `xt_alloc` plus root registration.
24
- * * Strings are UTF-8. Concatenation is lazy: a `+` between two non-empty
25
- * strings builds an immutable cons node (`flat == NULL`) and the bytes are
26
- * materialised once, on first observation, by `xt_string_bytes`. This keeps
27
- * `s += x` in a loop linear instead of copying the accumulated prefix every
28
- * iteration. JavaScript measures string length in UTF-16 code units;
29
- * `xt_string_length` currently reports code points (see README).
24
+ * * Strings are stored as UTF-8 (with lone surrogate halves kept as WTF-8) but
25
+ * expose JavaScript's UTF-16 view: `length`, indexing, slicing, searching
26
+ * and splitting all count UTF-16 code units. `xt_string_length` is the raw
27
+ * byte length (what extensions and I/O need), while
28
+ * `xt_string_utf16_length` is the JavaScript `.length`. Concatenation is
29
+ * lazy: a `+` between two non-empty strings builds an immutable cons node
30
+ * (`flat == NULL`) and the bytes are materialised once, on first
31
+ * observation, by `xt_string_bytes`. This keeps `s += x` in a loop linear
32
+ * instead of copying the accumulated prefix every iteration.
30
33
  * * Objects use a small linear property list. Fine for the language subset
31
34
  * xbintsc targets today; swap for a hash map when the profile demands it.
32
35
  */
@@ -55,6 +58,11 @@
55
58
  #define XT_OBJECT_KIND_ERROR 12
56
59
  #define XT_OBJECT_KIND_GENERATOR 13
57
60
  #define XT_OBJECT_KIND_ITERATOR 14
61
+ #define XT_OBJECT_KIND_ASYNC 15
62
+ #define XT_OBJECT_KIND_ASYNC_ITERATOR 16
63
+ #define XT_OBJECT_KIND_WEAK_MAP 17
64
+ #define XT_OBJECT_KIND_WEAK_SET 18
65
+ #define XT_OBJECT_KIND_WEAK_REF 19
58
66
 
59
67
  /* Common header for every heap object. `flags` bit 0 is the collector's mark
60
68
  * bit; it is cleared on every surviving object at the end of a sweep. */
@@ -70,13 +78,18 @@ typedef struct xt_header {
70
78
 
71
79
  /* A string is either *flat* (`flat` points at `capacity` bytes, the last one
72
80
  * NUL) or a *cons* node (`flat == NULL`, `left`/`right` name the operands).
73
- * `length` is always the total byte length, so `.length`, comparisons and the
74
- * GC never need to force a cons node. `xt_string_bytes` turns a cons node into
75
- * a flat one in place; treat the result as immutable and never write through a
76
- * pointer obtained from it. */
81
+ * `length` is the raw UTF-8 byte length; `utf16_length` (cached, 0 means
82
+ * "not computed yet" and is also the length of the empty string) is the same
83
+ * text measured in UTF-16 code units, which is what JavaScript observes.
84
+ * `code_point_count` is the number of Unicode scalar values (used by
85
+ * `for...of` and `Array.from`). `xt_string_bytes` turns a cons node into a flat
86
+ * one in place; treat the result as immutable and never write through a pointer
87
+ * obtained from it. */
77
88
  typedef struct xt_string {
78
89
  xt_header header;
79
90
  uint32_t length;
91
+ uint32_t utf16_length;
92
+ uint32_t code_point_count;
80
93
  uint32_t capacity;
81
94
  char *flat;
82
95
  struct xt_string *left;
@@ -102,11 +115,24 @@ typedef struct {
102
115
  xt_value setter;
103
116
  } xt_property;
104
117
 
118
+ /* Hidden-class descriptor for ordinary objects. Shapes are interned by their
119
+ * (parent, key) transition and never freed, so an object's shape pointer is a
120
+ * stable layout identity. Shape keys are rooted by a collector provider in
121
+ * xt_containers/shapes.inc. */
122
+ typedef struct xt_shape {
123
+ xt_value key;
124
+ uint32_t count;
125
+ struct xt_shape *parent;
126
+ struct xt_shape *next; /* hash-bucket chain */
127
+ struct xt_shape *all_next; /* every shape, for the GC root provider */
128
+ } xt_shape;
129
+
105
130
  typedef struct {
106
131
  xt_header header;
107
132
  uint32_t count;
108
133
  uint32_t capacity;
109
134
  xt_property *properties;
135
+ xt_shape *shape;
110
136
  xt_value prototype;
111
137
  uint8_t frozen;
112
138
  uint8_t is_array_base;
@@ -125,6 +151,10 @@ typedef struct {
125
151
  /* Named (non-index) properties such as `raw` on template strings or
126
152
  * `index`/`input` on RegExp match results, stored in an `xt_object`. */
127
153
  xt_value extra;
154
+ /* The array's [[Prototype]] (`Array.prototype` for ordinary arrays). Arrays
155
+ * are a distinct allocation kind, so this field is what lets
156
+ * `Object.getPrototypeOf([])` and `x instanceof <Array alias>` work. */
157
+ xt_value prototype;
128
158
  } xt_array;
129
159
 
130
160
  typedef struct {
@@ -139,6 +169,16 @@ typedef struct {
139
169
  /* Set on generator function objects: calling the closure does not run the
140
170
  * body, it creates a suspended generator (see xt_generator.c). */
141
171
  uint8_t is_generator;
172
+ /* Set on `async` function objects: calling the closure starts a coroutine
173
+ * (see xt_async.c) and immediately returns the promise it resolves. */
174
+ uint8_t is_async;
175
+ /* Set on `async function*` objects. `is_generator` is also set, but the call
176
+ * path checks this flag first so the generator is created in async mode. */
177
+ uint8_t is_async_generator;
178
+ /* Non-NULL for the first-class value of a built-in constructor ("Array",
179
+ * "Map", ...). It lets property access resolve the constructor's statics
180
+ * (`const A = Array; A.isArray(x)`). Points at a static string. */
181
+ const char *builtin_name;
142
182
  } xt_function;
143
183
 
144
184
  /* Allocation and garbage collection (xt_alloc.c).
@@ -197,10 +237,40 @@ void xt_gc_scan_region(const void *base, size_t bytes);
197
237
 
198
238
  /* Kind-specific hooks for allocations with separately allocated sub-objects.
199
239
  * Implemented by the translation unit that owns the representation. */
240
+ /* Weak-reference processing. `xt_weak_gc_process_once` marks values whose
241
+ * WeakMap key is already marked and returns 1 when it marked anything (the
242
+ * caller repeats until the ephemeron fixed point). `xt_weak_gc_clear` empties
243
+ * WeakRefs whose target stayed unmarked, and `xt_weak_gc_compact` drops dead
244
+ * WeakMap/WeakSet entries. */
245
+ int xt_weak_gc_process_once(void);
246
+ void xt_weak_gc_clear(void);
247
+ void xt_weak_gc_compact(void);
248
+ /* Mark-state queries used by the weak-reference pass. */
249
+ int xt_gc_value_is_marked(xt_value value);
250
+ /* Iterate every allocation (used by the weak-reference pass). */
251
+ xt_header *xt_gc_heap_head(void);
252
+
200
253
  void xt_promise_gc_trace(xt_header *header);
201
254
  void xt_promise_gc_release(xt_header *header);
202
255
  void xt_generator_gc_trace(xt_header *header);
203
256
  void xt_generator_gc_release(xt_header *header);
257
+ void xt_async_gc_trace(xt_header *header);
258
+ void xt_async_gc_release(xt_header *header);
259
+ void xt_async_iterator_gc_trace(xt_header *header);
260
+
261
+ /* Stackful coroutines (xt_coroutine.c). A coroutine owns a private C stack and
262
+ * switches to it with `ucontext`/fibers; `enter` runs until the body calls
263
+ * `leave`. Exception frames and GC stack regions are swapped alongside the C
264
+ * stack. Generators and async functions own one each. */
265
+ typedef struct xt_coroutine xt_coroutine;
266
+ xt_coroutine *xt_coroutine_create(void (*entry)(void *), void *arg);
267
+ void xt_coroutine_enter(xt_coroutine *co);
268
+ void xt_coroutine_leave(xt_coroutine *co);
269
+ /* The coroutine whose body is currently executing, or NULL on the main stack. */
270
+ xt_coroutine *xt_coroutine_current(void);
271
+ int xt_coroutine_is_current(xt_coroutine *co);
272
+ void xt_coroutine_gc_trace(xt_coroutine *co);
273
+ void xt_coroutine_release(xt_coroutine *co);
204
274
 
205
275
  /* Value / string helpers shared across translation units (xt_values.c). */
206
276
  xt_string *xt_string_alloc(size_t length);
@@ -210,6 +280,42 @@ int xt_string_equals(xt_string *a, xt_string *b);
210
280
  /* Contiguous UTF-8 bytes of a string, flattening a cons node in place on first
211
281
  * use. The result is NUL-terminated at `s->length`; never write through it. */
212
282
  const char *xt_string_bytes(xt_string *s);
283
+
284
+ /* UTF-8 <-> UTF-16 helpers (xt_values/utf16.inc). Decoding accepts WTF-8, so
285
+ * lone surrogate halves produced by indexing survive a round trip. */
286
+ uint32_t xt_utf8_decode(const char *data, size_t length, size_t *width);
287
+ size_t xt_utf8_encode(uint32_t code, char *out);
288
+ uint32_t xt_utf8_utf16_length(const char *data, size_t length);
289
+ void xt_utf8_measure(const char *data, size_t length, uint32_t *units, uint32_t *points);
290
+ /* Combine an adjacent WTF-8 high/low surrogate pair into one four-byte
291
+ * sequence, in place. Returns the resulting byte length. */
292
+ size_t xt_utf8_normalize_surrogates(char *data, size_t length);
293
+
294
+ /* Publish a manually filled buffer (`xt_string_alloc` + `xt_string_mutable`):
295
+ * normalises surrogate pairs, records the byte length and caches the UTF-16 and
296
+ * code-point counts. */
297
+ void xt_string_finish(xt_string *s);
298
+ uint32_t xt_string_utf16_length(xt_string *s);
299
+ uint32_t xt_string_code_point_count(xt_string *s);
300
+ /* UTF-16 code unit at `index`, or -1 when out of range. */
301
+ int32_t xt_string_code_unit(xt_string *s, int32_t index);
302
+ /* Unicode code point beginning at UTF-16 index `index` (combining a surrogate
303
+ * pair), or -1 when out of range. */
304
+ int32_t xt_string_code_point_at(xt_string *s, int32_t index);
305
+ /* A one-code-unit string (a lone surrogate when `index` points into a pair). */
306
+ xt_value xt_string_unit_value(xt_string *s, int32_t index);
307
+ xt_value xt_string_from_code_point(uint32_t code);
308
+ xt_value xt_string_from_units(const uint16_t *units, size_t count);
309
+ /* Copy UTF-16 range [start, end), splitting a surrogate pair when needed. */
310
+ xt_value xt_string_slice_units(xt_string *s, int32_t start, int32_t end);
311
+ /* Byte offset / UTF-16 index conversions; both clamp to the string bounds. */
312
+ int32_t xt_string_byte_offset(xt_string *s, int32_t unit_index);
313
+ int32_t xt_string_unit_offset(xt_string *s, int32_t byte_offset);
314
+ /* True when `unit_index` sits on a code-point boundary (not between the two
315
+ * halves of a surrogate pair). */
316
+ int xt_string_is_boundary(xt_string *s, int32_t unit_index);
317
+ /* The `index`-th Unicode code point (for `for...of` and `Array.from`). */
318
+ xt_value xt_string_code_point_value(xt_string *s, int32_t index);
213
319
  /* Mutable bytes of a string just created with `xt_string_alloc` (never a cons
214
320
  * node). Used by the constructors that fill a buffer before publishing it. */
215
321
  char *xt_string_mutable(xt_string *s);
@@ -251,6 +357,11 @@ void xt_array_reserve(xt_array *array, uint32_t needed);
251
357
  /* Object helpers used by the standard library. */
252
358
  xt_object *xt_as_object(xt_value value);
253
359
  xt_property *xt_object_find_property(xt_object *obj, xt_value key);
360
+ /* Hidden-class helpers. `xt_object_shape_changed` rebuilds the shape after a
361
+ * property was inserted out of order or deleted. `xt_shape_empty` stays local
362
+ * to xt_containers.c, which is why it has no prototype here. */
363
+ xt_shape *xt_shape_transition(xt_shape *parent, xt_value key);
364
+ void xt_object_shape_changed(xt_object *obj);
254
365
 
255
366
  /* Property keys are either strings or symbols. */
256
367
  xt_value xt_to_property_key(xt_value key);
@@ -278,6 +389,14 @@ xt_value xt_regexp_split(xt_value value, xt_value regexp, xt_value limit);
278
389
  xt_value xt_regexp_get_property(xt_value regexp, xt_value key);
279
390
  int32_t xt_map_size(xt_value value);
280
391
  int32_t xt_set_size(xt_value value);
392
+ /* WeakMap / WeakSet / WeakRef (xt_weak.c). */
393
+ int xt_is_weak_map(xt_value value);
394
+ int xt_is_weak_set(xt_value value);
395
+ int xt_is_weak_ref(xt_value value);
396
+ xt_value xt_weak_map_ctor(int32_t argc, xt_value *argv);
397
+ xt_value xt_weak_set_ctor(int32_t argc, xt_value *argv);
398
+ xt_value xt_weak_ref_ctor(int32_t argc, xt_value *argv);
399
+ xt_value xt_weak_method(xt_value target, const char *method, int32_t argc, xt_value *argv, int *handled);
281
400
  /* `for...of` iteration: dispatch over arrays, strings, Maps and Sets. */
282
401
  xt_value xt_iter_length(xt_value value);
283
402
  xt_value xt_iter_value(xt_value value, xt_value index);
@@ -288,6 +407,9 @@ xt_value xt_iter_has(xt_value value, xt_value index);
288
407
  * protocols, or a wrapper around `value[Symbol.iterator]()` otherwise. */
289
408
  xt_value xt_iter_open(xt_value value);
290
409
 
410
+ /* Monotonic clock in fractional milliseconds (xt_loop.c), for `performance.now`. */
411
+ double xt_monotonic_ms(void);
412
+
291
413
  /* Stackful generators (xt_generator.c). */
292
414
  int xt_is_generator(xt_value value);
293
415
  xt_value xt_generator_new(xt_value function, xt_value thisValue, int32_t argc, xt_value *argv);
@@ -298,6 +420,40 @@ xt_value xt_yield(xt_value value);
298
420
  xt_value xt_yield_star(xt_value delegate);
299
421
  int xt_generator_has_next(xt_value generator);
300
422
  xt_value xt_generator_iter_value(xt_value generator);
423
+ /* Async-generator support. `xt_generator_await` handles an `await` inside an
424
+ * async generator and returns 1; it returns 0 when no async generator is
425
+ * running (ordinary/async code handles the await itself). */
426
+ int xt_generator_await(xt_value value, xt_value *result);
427
+ void xt_generator_wake(void *generator, xt_value value, int rejected);
428
+ int xt_is_async_generator(xt_value value);
429
+ /* `[Symbol.asyncIterator]()` for a generator object. */
430
+ xt_value xt_async_iterator_method(void);
431
+ /* `for await...of`: resolve the async iteration protocol once, then pull one
432
+ * step per call. Both return a promise for the step object. */
433
+ xt_value xt_async_iter_open(xt_value value);
434
+ xt_value xt_async_iter_next(xt_value iterator);
435
+
436
+ /* Async coroutines (xt_async.c). Calling an `async` function runs its body on
437
+ * a coroutine that suspends at a pending `await` and resumes when the awaited
438
+ * promise settles, so the event loop can make progress in between. */
439
+ #define XT_PROMISE_PENDING 0
440
+ #define XT_PROMISE_FULFILLED 1
441
+ #define XT_PROMISE_REJECTED 2
442
+ xt_value xt_async_call(xt_value function, xt_value thisValue, int32_t argc, xt_value *argv);
443
+ /* Resume `async` with the settlement of the promise it awaited. Called by the
444
+ * microtask runner when the promise settles. */
445
+ void xt_async_wake(void *async, xt_value value, int rejected);
446
+ /* Create a pending promise / settle an existing one (used by xt_async.c). */
447
+ xt_value xt_promise_create(void);
448
+ void xt_promise_fulfill(xt_value promise, xt_value value);
449
+ void xt_promise_reject_value(xt_value promise, xt_value value);
450
+ /* `-1` when `value` is not a promise, otherwise PENDING / FULFILLED / REJECTED. */
451
+ int xt_promise_state_of(xt_value value);
452
+ xt_value xt_promise_value_of(xt_value value);
453
+ /* Register a coroutine to resume when `promise` settles (it must be pending). */
454
+ void xt_promise_add_async_waiter(xt_value promise, void *async);
455
+ /* Queue a microtask that resumes `async` with an already settled value. */
456
+ void xt_promise_queue_async_wake(void *async, xt_value settled, int rejected);
301
457
 
302
458
  /* Exception-frame plumbing shared with the generator runtime. The struct is
303
459
  * public so a coroutine can `_setjmp` its own boundary directly (a `setjmp`
@@ -359,6 +515,29 @@ typedef struct {
359
515
  uint32_t capacity;
360
516
  } xt_set_object;
361
517
 
518
+ /* Weak collections. Keys (WeakMap/WeakSet) and the target of a WeakRef are
519
+ * deliberately not traced by the collector: `xt_weak_gc_*` in xt_weak.c
520
+ * implements the ephemeron fixed point and clears unreachable refs. */
521
+ typedef struct {
522
+ xt_header header;
523
+ xt_value *keys;
524
+ xt_value *values;
525
+ uint32_t count;
526
+ uint32_t capacity;
527
+ } xt_weak_map;
528
+
529
+ typedef struct {
530
+ xt_header header;
531
+ xt_value *values;
532
+ uint32_t count;
533
+ uint32_t capacity;
534
+ } xt_weak_set;
535
+
536
+ typedef struct {
537
+ xt_header header;
538
+ xt_value target;
539
+ } xt_weak_ref;
540
+
362
541
  typedef struct {
363
542
  xt_header header;
364
543
  double time;
@@ -379,6 +558,9 @@ xt_value xt_ext_object_method(xt_value target, const char *method, int32_t argc,
379
558
 
380
559
  /* Error family helpers (xt_stdlib2.c). */
381
560
  xt_value xt_error_to_string(xt_value error);
561
+ /* Turn an internal "TypeError: message" / "RangeError: message" string into a
562
+ * real Error-family value so `catch` observes an Error, not a string. */
563
+ xt_value xt_error_from_message(const char *message);
382
564
  xt_value xt_aggregate_error_ctor(int32_t argc, xt_value *argv);
383
565
  xt_value xt_ext_container_method(xt_value target, const char *method, int32_t argc, xt_value *argv, int *handled);
384
566
  xt_value xt_promise_method(xt_value target, const char *method, int32_t argc, xt_value *argv, int *handled);
@@ -393,5 +575,18 @@ xt_value xt_arg_at(int32_t argc, xt_value *argv, int32_t index);
393
575
  /* Typed arrays (xt_typed_array.c). */
394
576
  int xt_typed_array_kind_of(xt_value value);
395
577
  double xt_typed_array_coerce(int kind, double value);
578
+ /* Buffer-backed element access; the array must be a typed-array value. */
579
+ xt_value xt_typed_array_read(xt_value array, uint32_t index);
580
+ void xt_typed_array_write(xt_value array, uint32_t index, xt_value value);
581
+ xt_value xt_typed_array_buffer_of(xt_value array);
582
+ uint32_t xt_typed_array_byte_offset_of(xt_value array);
583
+ const char *xt_typed_array_name_of(int kind);
584
+
585
+ /* ArrayBuffer helpers (xt_array_buffer.c). */
586
+ int xt_is_array_buffer(xt_value value);
587
+ uint32_t xt_array_buffer_byte_length(xt_value value);
588
+ uint8_t xt_array_buffer_get_byte(xt_value buffer, uint32_t index);
589
+ void xt_array_buffer_set_byte(xt_value buffer, uint32_t index, uint8_t value);
590
+ xt_value xt_array_buffer_ctor(int32_t argc, xt_value *argv);
396
591
 
397
592
  #endif /* XT_RT_INTERNAL_H */
@@ -303,6 +303,17 @@ void xt_gc_mark_value(xt_value value) {
303
303
  }
304
304
  }
305
305
 
306
+ int xt_gc_value_is_marked(xt_value value) {
307
+ if (!(XT_IS_STRING(value) || XT_IS_OBJECT(value) || XT_IS_ARRAY(value) ||
308
+ XT_IS_FUNCTION(value) || XT_IS_BIGINT(value))) {
309
+ return 0;
310
+ }
311
+ xt_header *header = xt_gc_table_lookup((uintptr_t)XT_GET_PTR(value));
312
+ return header != NULL && (header->flags & XT_GC_MARK) != 0;
313
+ }
314
+
315
+ xt_header *xt_gc_heap_head(void) { return g_heap_head; }
316
+
306
317
  void xt_gc_scan_region(const void *base, size_t bytes) {
307
318
  if (!base) return;
308
319
  const uint64_t *words = (const uint64_t *)base;
@@ -389,6 +400,18 @@ static void xt_gc_process(xt_header *header) {
389
400
  case XT_OBJECT_KIND_GENERATOR:
390
401
  xt_generator_gc_trace(header);
391
402
  return;
403
+ case XT_OBJECT_KIND_ASYNC:
404
+ xt_async_gc_trace(header);
405
+ return;
406
+ case XT_OBJECT_KIND_ASYNC_ITERATOR:
407
+ xt_async_iterator_gc_trace(header);
408
+ return;
409
+ case XT_OBJECT_KIND_WEAK_MAP:
410
+ case XT_OBJECT_KIND_WEAK_SET:
411
+ case XT_OBJECT_KIND_WEAK_REF:
412
+ /* Weak references are not traced; `xt_weak_gc_*` owns the ephemeron
413
+ * fixed point after the ordinary mark phase. */
414
+ return;
392
415
  default:
393
416
  /* Symbols, regexps, iterators and any future kind whose references live
394
417
  * inline: the payload scan covers them. */
@@ -426,12 +449,22 @@ static void xt_gc_release(xt_header *header) {
426
449
  case XT_OBJECT_KIND_SET:
427
450
  free(((xt_set_object *)header)->values);
428
451
  break;
452
+ case XT_OBJECT_KIND_WEAK_MAP:
453
+ free(((xt_weak_map *)header)->keys);
454
+ free(((xt_weak_map *)header)->values);
455
+ break;
456
+ case XT_OBJECT_KIND_WEAK_SET:
457
+ free(((xt_weak_set *)header)->values);
458
+ break;
429
459
  case XT_OBJECT_KIND_PROMISE:
430
460
  xt_promise_gc_release(header);
431
461
  break;
432
462
  case XT_OBJECT_KIND_GENERATOR:
433
463
  xt_generator_gc_release(header);
434
464
  break;
465
+ case XT_OBJECT_KIND_ASYNC:
466
+ xt_async_gc_release(header);
467
+ break;
435
468
  default:
436
469
  break;
437
470
  }
@@ -472,16 +505,25 @@ void xt_gc_collect(void) {
472
505
 
473
506
  xt_gc_table_build();
474
507
  xt_gc_mark_roots();
475
- while (g_gray_count > 0) {
476
- xt_header *header = g_gray[--g_gray_count];
477
- xt_gc_process(header);
508
+ /* Ephemeron fixed point: a WeakMap value is reachable only when its key is
509
+ * reachable. Marking a value can reach further keys, so repeat until a pass
510
+ * marks nothing new. WeakRefs are cleared only after this settles, because
511
+ * an ephemeron may still keep their target alive. */
512
+ for (;;) {
513
+ while (g_gray_count > 0) {
514
+ xt_header *header = g_gray[--g_gray_count];
515
+ xt_gc_process(header);
516
+ }
517
+ if (!xt_weak_gc_process_once()) break;
478
518
  }
519
+ xt_weak_gc_clear();
520
+ xt_weak_gc_compact();
479
521
 
480
522
  xt_header **link = &g_heap_head;
481
523
  xt_header *header = g_heap_head;
482
- size_t live_by_kind[16];
483
- size_t bytes_by_kind[16];
484
- for (int i = 0; i < 16; i++) {
524
+ size_t live_by_kind[32];
525
+ size_t bytes_by_kind[32];
526
+ for (int i = 0; i < 32; i++) {
485
527
  live_by_kind[i] = 0;
486
528
  bytes_by_kind[i] = 0;
487
529
  }
@@ -491,7 +533,7 @@ void xt_gc_collect(void) {
491
533
  header->flags &= (uint8_t)~XT_GC_MARK;
492
534
  link = &header->gc_next;
493
535
  if (trace) {
494
- size_t kind = header->kind < 16 ? header->kind : 0;
536
+ size_t kind = header->kind < 32 ? header->kind : 0;
495
537
  live_by_kind[kind]++;
496
538
  bytes_by_kind[kind] += header->size;
497
539
  }