xbintsc 0.7.0 → 0.7.7

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 (351) hide show
  1. package/dist/src/ast/common.d.ts +10 -0
  2. package/dist/src/binder/references.js +13 -7
  3. package/dist/src/binder/references.js.map +1 -1
  4. package/dist/src/checker/source.js +4 -0
  5. package/dist/src/checker/source.js.map +1 -1
  6. package/dist/src/cli/help.d.ts +1 -1
  7. package/dist/src/cli/main.js +15 -3
  8. package/dist/src/cli/main.js.map +1 -1
  9. package/dist/src/codegen/generator/calls/access.js +4 -11
  10. package/dist/src/codegen/generator/calls/access.js.map +1 -1
  11. package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
  12. package/dist/src/codegen/generator/calls/element-inline.js +388 -0
  13. package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
  14. package/dist/src/codegen/generator/calls/invocation.js +82 -1
  15. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  16. package/dist/src/codegen/generator/calls.d.ts +3 -1
  17. package/dist/src/codegen/generator/calls.js +3 -1
  18. package/dist/src/codegen/generator/calls.js.map +1 -1
  19. package/dist/src/codegen/generator/debug.js +20 -3
  20. package/dist/src/codegen/generator/debug.js.map +1 -1
  21. package/dist/src/codegen/generator/expressions/assignment.js +10 -2
  22. package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
  23. package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
  24. package/dist/src/codegen/generator/expressions/global-values.js +49 -0
  25. package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
  26. package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
  27. package/dist/src/codegen/generator/expressions/primary.js +4 -24
  28. package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
  29. package/dist/src/codegen/generator/expressions.d.ts +2 -1
  30. package/dist/src/codegen/generator/expressions.js +2 -1
  31. package/dist/src/codegen/generator/expressions.js.map +1 -1
  32. package/dist/src/codegen/generator/layout.d.ts +65 -0
  33. package/dist/src/codegen/generator/layout.js +50 -0
  34. package/dist/src/codegen/generator/layout.js.map +1 -0
  35. package/dist/src/codegen/generator/state.js +4 -0
  36. package/dist/src/codegen/generator/state.js.map +1 -1
  37. package/dist/src/diagnostics/diagnostic.js +1 -1
  38. package/dist/src/diagnostics/diagnostic.js.map +1 -1
  39. package/dist/src/diagnostics/source-text.d.ts +37 -9
  40. package/dist/src/diagnostics/source-text.js +124 -23
  41. package/dist/src/diagnostics/source-text.js.map +1 -1
  42. package/dist/src/diagnostics/source.d.ts +16 -6
  43. package/dist/src/diagnostics/source.js +25 -4
  44. package/dist/src/diagnostics/source.js.map +1 -1
  45. package/dist/src/driver/build-key.d.ts +14 -0
  46. package/dist/src/driver/build-key.js +6 -1
  47. package/dist/src/driver/build-key.js.map +1 -1
  48. package/dist/src/driver/bundler/concatenate.js +11 -4
  49. package/dist/src/driver/bundler/concatenate.js.map +1 -1
  50. package/dist/src/driver/bundler/graph.js +2 -2
  51. package/dist/src/driver/bundler/graph.js.map +1 -1
  52. package/dist/src/driver/bundler/merge.js +11 -5
  53. package/dist/src/driver/bundler/merge.js.map +1 -1
  54. package/dist/src/driver/bundler/reexport-resolution.js +3 -0
  55. package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
  56. package/dist/src/driver/compiler.js +13 -3
  57. package/dist/src/driver/compiler.js.map +1 -1
  58. package/dist/src/driver/frontend.js +3 -4
  59. package/dist/src/driver/frontend.js.map +1 -1
  60. package/dist/src/driver/runtime-objects.d.ts +1 -1
  61. package/dist/src/driver/runtime-objects.js +4 -0
  62. package/dist/src/driver/runtime-objects.js.map +1 -1
  63. package/dist/src/driver/toolchain.js +28 -5
  64. package/dist/src/driver/toolchain.js.map +1 -1
  65. package/dist/src/driver/version.d.ts +1 -1
  66. package/dist/src/driver/version.js +1 -1
  67. package/dist/src/extensions/gui/html.js +42 -10
  68. package/dist/src/extensions/gui/html.js.map +1 -1
  69. package/dist/src/extensions/gui/index.js +53 -0
  70. package/dist/src/extensions/gui/index.js.map +1 -1
  71. package/dist/src/extensions/registry.d.ts +20 -0
  72. package/dist/src/extensions/registry.js.map +1 -1
  73. package/dist/src/parser/expressions.js +2 -2
  74. package/dist/src/parser/expressions.js.map +1 -1
  75. package/dist/src/parser/helpers.d.ts +8 -0
  76. package/dist/src/parser/helpers.js +21 -0
  77. package/dist/src/parser/helpers.js.map +1 -1
  78. package/dist/tests/binder/binder.test.js +26 -4
  79. package/dist/tests/binder/binder.test.js.map +1 -1
  80. package/dist/tests/checker/checker.test.js +16 -0
  81. package/dist/tests/checker/checker.test.js.map +1 -1
  82. package/dist/tests/cli/main.test.js +9 -0
  83. package/dist/tests/cli/main.test.js.map +1 -1
  84. package/dist/tests/codegen/element-layout.test.d.ts +19 -0
  85. package/dist/tests/codegen/element-layout.test.js +80 -0
  86. package/dist/tests/codegen/element-layout.test.js.map +1 -0
  87. package/dist/tests/codegen/expressions.test.js +25 -0
  88. package/dist/tests/codegen/expressions.test.js.map +1 -1
  89. package/dist/tests/codegen/llvm.test.js +13 -0
  90. package/dist/tests/codegen/llvm.test.js.map +1 -1
  91. package/dist/tests/diagnostics/diagnostic.test.js +9 -0
  92. package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
  93. package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
  94. package/dist/tests/diagnostics/source-text.test.js +50 -0
  95. package/dist/tests/diagnostics/source-text.test.js.map +1 -0
  96. package/dist/tests/diagnostics/source.test.js +17 -0
  97. package/dist/tests/diagnostics/source.test.js.map +1 -1
  98. package/dist/tests/driver/build-key.test.d.ts +1 -0
  99. package/dist/tests/driver/build-key.test.js +49 -0
  100. package/dist/tests/driver/build-key.test.js.map +1 -0
  101. package/dist/tests/driver/toolchain.test.js +8 -1
  102. package/dist/tests/driver/toolchain.test.js.map +1 -1
  103. package/dist/tests/driver/usage.test.js +2 -1
  104. package/dist/tests/driver/usage.test.js.map +1 -1
  105. package/dist/tests/e2e/async-await.test.js +16 -0
  106. package/dist/tests/e2e/async-await.test.js.map +1 -1
  107. package/dist/tests/e2e/compile-builtins.test.js +29 -0
  108. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  109. package/dist/tests/e2e/compile-modules.test.js +13 -0
  110. package/dist/tests/e2e/compile-modules.test.js.map +1 -1
  111. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
  112. package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
  113. package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
  114. package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
  115. package/dist/tests/e2e/differential-language.test.js +25 -0
  116. package/dist/tests/e2e/differential-language.test.js.map +1 -1
  117. package/dist/tests/e2e/differential-values.test.js +59 -0
  118. package/dist/tests/e2e/differential-values.test.js.map +1 -1
  119. package/dist/tests/e2e/gc.test.js +22 -0
  120. package/dist/tests/e2e/gc.test.js.map +1 -1
  121. package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
  122. package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
  123. package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
  124. package/dist/tests/e2e/gui-browser.test.js +66 -2
  125. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  126. package/dist/tests/e2e/gui-dom.test.js +88 -0
  127. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  128. package/dist/tests/e2e/gui-events.test.js +89 -0
  129. package/dist/tests/e2e/gui-events.test.js.map +1 -1
  130. package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
  131. package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
  132. package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
  133. package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
  134. package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
  135. package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
  136. package/dist/tests/e2e/gui-webgl2-anisotropy.test.d.ts +10 -0
  137. package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
  138. package/dist/tests/e2e/gui-webgl2-anisotropy.test.js.map +1 -0
  139. package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
  140. package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
  141. package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
  142. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
  143. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
  144. package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
  145. package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
  146. package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
  147. package/dist/tests/e2e/gui-webgl2-sampler-array.test.d.ts +11 -0
  148. package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
  149. package/dist/tests/e2e/gui-webgl2-sampler-array.test.js.map +1 -0
  150. package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
  151. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
  152. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
  153. package/dist/tests/e2e/gui-webgl2.test.js +59 -1
  154. package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
  155. package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
  156. package/dist/tests/e2e/hang-watchdog.test.js +50 -0
  157. package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
  158. package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
  159. package/dist/tests/e2e/method-call-cache.test.js +65 -0
  160. package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
  161. package/dist/tests/e2e/performance-now.test.d.ts +9 -0
  162. package/dist/tests/e2e/performance-now.test.js +36 -0
  163. package/dist/tests/e2e/performance-now.test.js.map +1 -0
  164. package/dist/tests/e2e/property-ic.test.js +33 -0
  165. package/dist/tests/e2e/property-ic.test.js.map +1 -1
  166. package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
  167. package/dist/tests/e2e/shape-interning.test.js +55 -0
  168. package/dist/tests/e2e/shape-interning.test.js.map +1 -0
  169. package/dist/tests/e2e/string-utf16.test.js +9 -0
  170. package/dist/tests/e2e/string-utf16.test.js.map +1 -1
  171. package/dist/tests/e2e/typed-array-views.test.js +26 -0
  172. package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
  173. package/dist/tests/e2e/url-search-params.test.js +19 -0
  174. package/dist/tests/e2e/url-search-params.test.js.map +1 -1
  175. package/dist/tests/extensions/gui.test.js +16 -1
  176. package/dist/tests/extensions/gui.test.js.map +1 -1
  177. package/dist/tests/helpers.js +1 -0
  178. package/dist/tests/helpers.js.map +1 -1
  179. package/dist/tests/parser/expressions.test.js +36 -0
  180. package/dist/tests/parser/expressions.test.js.map +1 -1
  181. package/doc/ai/contributing.md +8 -5
  182. package/doc/ai/extensions.md +12 -3
  183. package/doc/ai/language-support.md +2 -1
  184. package/doc/ai/troubleshooting.md +14 -0
  185. package/doc/ai/zh-CN/contributing.md +6 -3
  186. package/doc/ai/zh-CN/extensions.md +10 -2
  187. package/doc/ai/zh-CN/language-support.md +2 -1
  188. package/doc/ai/zh-CN/troubleshooting.md +12 -0
  189. package/doc/gui/api.md +35 -4
  190. package/doc/gui/dom.md +8 -0
  191. package/doc/gui/input.md +8 -0
  192. package/doc/gui/known-issues.md +43 -6
  193. package/doc/gui/runtime.md +16 -1
  194. package/doc/gui/webgl.md +97 -26
  195. package/doc/gui-scripts.md +2 -1
  196. package/doc/gui.md +8 -5
  197. package/doc/implemented/binder.md +1 -1
  198. package/doc/implemented/checker.md +9 -0
  199. package/doc/implemented/codegen.md +7 -0
  200. package/doc/implemented/parser.md +2 -1
  201. package/doc/implemented/runtime-core.md +9 -2
  202. package/doc/implemented/stdlib.md +10 -2
  203. package/doc/implemented/typed-arrays.md +18 -2
  204. package/doc/zh-CN/gui/api.md +27 -5
  205. package/doc/zh-CN/gui/dom.md +6 -0
  206. package/doc/zh-CN/gui/input.md +7 -0
  207. package/doc/zh-CN/gui/known-issues.md +30 -5
  208. package/doc/zh-CN/gui/runtime.md +13 -1
  209. package/doc/zh-CN/gui/webgl.md +20 -7
  210. package/doc/zh-CN/gui-scripts.md +2 -1
  211. package/doc/zh-CN/gui.md +4 -1
  212. package/doc/zh-CN/implemented/binder.md +1 -1
  213. package/doc/zh-CN/implemented/checker.md +7 -0
  214. package/doc/zh-CN/implemented/codegen.md +7 -0
  215. package/doc/zh-CN/implemented/parser.md +2 -1
  216. package/doc/zh-CN/implemented/runtime-core.md +9 -2
  217. package/doc/zh-CN/implemented/stdlib.md +6 -2
  218. package/doc/zh-CN/implemented/typed-arrays.md +14 -2
  219. package/package.json +7 -7
  220. package/runtime/ext_gui/audio.cpp +39 -3
  221. package/runtime/ext_gui/audio_extra.cpp +353 -0
  222. package/runtime/ext_gui/audio_extra.h +47 -0
  223. package/runtime/ext_gui/audio_fft.h +76 -0
  224. package/runtime/ext_gui/audio_internal.h +21 -0
  225. package/runtime/ext_gui/audio_mixer.cpp +46 -1
  226. package/runtime/ext_gui/audio_mixer.h +89 -1
  227. package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
  228. package/runtime/ext_gui/audio_nodes.cpp +242 -0
  229. package/runtime/ext_gui/audio_nodes_internal.h +81 -0
  230. package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
  231. package/runtime/ext_gui/browser.cpp +11 -0
  232. package/runtime/ext_gui/browser_screen.cpp +73 -0
  233. package/runtime/ext_gui/dom_api.cpp +4 -0
  234. package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
  235. package/runtime/ext_gui/dom_api_events.cpp +2 -1
  236. package/runtime/ext_gui/dom_api_internal.h +11 -0
  237. package/runtime/ext_gui/dom_api_mutation.cpp +49 -0
  238. package/runtime/ext_gui/dom_api_node.cpp +21 -0
  239. package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
  240. package/runtime/ext_gui/dom_api_proto.cpp +6 -0
  241. package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
  242. package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
  243. package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
  244. package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
  245. package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
  246. package/runtime/ext_gui/dom_api_webgl_state.cpp +11 -2
  247. package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
  248. package/runtime/ext_gui/gui.cpp +8 -1
  249. package/runtime/ext_gui/gui_engine.h +20 -2
  250. package/runtime/ext_gui/gui_events.cpp +31 -126
  251. package/runtime/ext_gui/gui_input.cpp +148 -0
  252. package/runtime/ext_gui/gui_webgl.cpp +3 -2
  253. package/runtime/ext_gui/pointer_lock.cpp +137 -0
  254. package/runtime/ext_gui/style_ua.cpp +4 -0
  255. package/runtime/ext_gui/warnings.cpp +1 -1
  256. package/runtime/ext_gui/webgl.h +102 -7
  257. package/runtime/ext_gui/webgl_api.h +3 -2
  258. package/runtime/ext_gui/webgl_blit.cpp +109 -15
  259. package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
  260. package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
  261. package/runtime/ext_gui/webgl_buffer.cpp +26 -170
  262. package/runtime/ext_gui/webgl_context.cpp +119 -169
  263. package/runtime/ext_gui/webgl_draw.cpp +116 -5
  264. package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
  265. package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
  266. package/runtime/ext_gui/webgl_draw_state.h +2 -0
  267. package/runtime/ext_gui/webgl_feature.cpp +2 -2
  268. package/runtime/ext_gui/webgl_feature.h +4 -3
  269. package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
  270. package/runtime/ext_gui/webgl_glsl.h +4 -0
  271. package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
  272. package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
  273. package/runtime/ext_gui/webgl_objects.h +18 -2
  274. package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
  275. package/runtime/ext_gui/webgl_shader.cpp +1 -1
  276. package/runtime/ext_gui/webgl_state.cpp +45 -36
  277. package/runtime/ext_gui/webgl_targets.cpp +440 -0
  278. package/runtime/ext_gui/webgl_texture.cpp +81 -25
  279. package/runtime/ext_gui/window.cpp +11 -83
  280. package/runtime/ext_gui/window_diagnostics.cpp +94 -1
  281. package/runtime/rt.h +27 -27
  282. package/runtime/rt_binary.h +44 -0
  283. package/runtime/rt_internal.h +52 -60
  284. package/runtime/rt_object.h +83 -0
  285. package/runtime/rt_profile.h +45 -0
  286. package/runtime/xt_alloc.c +88 -133
  287. package/runtime/xt_array_buffer.c +99 -71
  288. package/runtime/xt_builtins.c +3 -1
  289. package/runtime/xt_constructors.c +1 -0
  290. package/runtime/xt_containers/access.inc +96 -11
  291. package/runtime/xt_containers/arrays.inc +2 -1
  292. package/runtime/xt_containers/cstr_cache.inc +56 -0
  293. package/runtime/xt_containers/method_cache.inc +121 -0
  294. package/runtime/xt_containers/object_keys.inc +58 -0
  295. package/runtime/xt_containers/objects.inc +47 -79
  296. package/runtime/xt_containers/shapes.inc +153 -8
  297. package/runtime/xt_containers.c +4 -0
  298. package/runtime/xt_gc_release.c +70 -0
  299. package/runtime/xt_gc_stack.c +83 -0
  300. package/runtime/xt_gc_verify.c +1 -0
  301. package/runtime/xt_io/console.inc +66 -0
  302. package/runtime/xt_io/exception.inc +32 -6
  303. package/runtime/xt_io/watchdog.inc +101 -0
  304. package/runtime/xt_io.c +1 -0
  305. package/runtime/xt_loop.c +23 -3
  306. package/runtime/xt_pool.c +151 -0
  307. package/runtime/xt_profile.c +126 -0
  308. package/runtime/xt_stdlib/dispatch.inc +7 -1
  309. package/runtime/xt_stdlib/math.inc +272 -57
  310. package/runtime/xt_stdlib2/json_stringify.inc +1 -2
  311. package/runtime/xt_stdlib2/regexp-match.inc +17 -0
  312. package/runtime/xt_storage/indexed_db.c +4 -1
  313. package/runtime/xt_structured_clone.c +2 -1
  314. package/runtime/xt_typed_array/construction.inc +10 -0
  315. package/runtime/xt_typed_array/elements.inc +43 -23
  316. package/runtime/xt_url.c +50 -0
  317. package/runtime/xt_values/constructors.inc +4 -1
  318. package/runtime/xt_values/strings.inc +3 -1
  319. package/src/ast/common.ts +10 -0
  320. package/src/binder/references.ts +13 -7
  321. package/src/checker/source.ts +3 -0
  322. package/src/cli/main.ts +14 -3
  323. package/src/codegen/generator/calls/access.ts +5 -10
  324. package/src/codegen/generator/calls/element-inline.ts +433 -0
  325. package/src/codegen/generator/calls/invocation.ts +87 -1
  326. package/src/codegen/generator/calls.ts +5 -0
  327. package/src/codegen/generator/debug.ts +21 -3
  328. package/src/codegen/generator/expressions/assignment.ts +11 -2
  329. package/src/codegen/generator/expressions/global-values.ts +57 -0
  330. package/src/codegen/generator/expressions/primary.ts +4 -27
  331. package/src/codegen/generator/expressions.ts +3 -0
  332. package/src/codegen/generator/layout.ts +54 -0
  333. package/src/codegen/generator/state.ts +5 -0
  334. package/src/diagnostics/diagnostic.ts +1 -1
  335. package/src/diagnostics/source-text.ts +118 -22
  336. package/src/diagnostics/source.ts +29 -7
  337. package/src/driver/build-key.ts +21 -1
  338. package/src/driver/bundler/concatenate.ts +12 -5
  339. package/src/driver/bundler/graph.ts +2 -2
  340. package/src/driver/bundler/merge.ts +11 -4
  341. package/src/driver/bundler/reexport-resolution.ts +2 -0
  342. package/src/driver/compiler.ts +14 -3
  343. package/src/driver/frontend.ts +3 -4
  344. package/src/driver/runtime-objects.ts +4 -0
  345. package/src/driver/toolchain.ts +28 -5
  346. package/src/driver/version.ts +1 -1
  347. package/src/extensions/gui/html.ts +41 -11
  348. package/src/extensions/gui/index.ts +55 -1
  349. package/src/extensions/registry.ts +20 -0
  350. package/src/parser/expressions.ts +2 -2
  351. package/src/parser/helpers.ts +22 -0
@@ -61,10 +61,14 @@
61
61
  #define XT_OBJECT_KIND_WEAK_MAP 17
62
62
  #define XT_OBJECT_KIND_WEAK_SET 18
63
63
  #define XT_OBJECT_KIND_WEAK_REF 19
64
+ /* An ArrayBuffer: an ordinary object whose *bytes* live in a plain `uint8_t`
65
+ * block instead of boxed values. Typed arrays and DataViews index that block
66
+ * directly, which is the difference between a geometry loop running at memory
67
+ * speed and one paying a runtime call per byte. */
68
+ #define XT_OBJECT_KIND_ARRAY_BUFFER 20
64
69
 
65
70
  /* Common header for every heap object. `flags` bit 0 is the collector's mark
66
- * bit; it is cleared on every surviving object at the end of a sweep. */
67
- typedef struct xt_header {
71
+ * bit; it is cleared on every surviving object at the end of a sweep. */typedef struct xt_header {
68
72
  uint8_t kind;
69
73
  uint8_t flags;
70
74
  uint16_t reserved;
@@ -73,6 +77,22 @@ typedef struct xt_header {
73
77
  } xt_header;
74
78
 
75
79
  #define XT_GC_MARK 0x01u
80
+ /** Block came from the small-block pool (see `xt_alloc.c`); the collector
81
+ * returns it to its size class instead of `free`. */
82
+ #define XT_GC_POOLED 0x02u
83
+
84
+ /**
85
+ * Whether an allocation kind is an ordinary object with a property bag — the
86
+ * kinds the generic `xt_object_get`/`xt_set`/`keys`/inspect paths accept.
87
+ *
88
+ * An ArrayBuffer is one of them: it is an object that *also* owns a byte block,
89
+ * so its `byteLength`/`slice` stay ordinary properties and `Object.keys`
90
+ * behaves like it does for any other object.
91
+ */
92
+ static inline int xt_kind_is_object(int kind) {
93
+ return kind == XT_OBJECT_KIND_OBJECT || kind == XT_OBJECT_KIND_ERROR ||
94
+ kind == XT_OBJECT_KIND_ARRAY_BUFFER;
95
+ }
76
96
 
77
97
  /* A string is either *flat* (`flat` points at `capacity` bytes, the last one
78
98
  * NUL) or a *cons* node (`flat == NULL`, `left`/`right` name the operands).
@@ -103,61 +123,7 @@ typedef struct {
103
123
  uint32_t *limbs;
104
124
  } xt_bigint;
105
125
 
106
- typedef struct {
107
- /* String or Symbol value (see `xt_to_property_key`). */
108
- xt_value key;
109
- xt_value value;
110
- /* Accessor properties (`get x()` / `set x(v)`) store the functions here;
111
- * when set, `value` is ignored and property access invokes the getter. */
112
- xt_value getter;
113
- xt_value setter;
114
- } xt_property;
115
-
116
- /* Hidden-class descriptor for ordinary objects. Shapes are interned by their
117
- * (parent, key) transition and never freed, so an object's shape pointer is a
118
- * stable layout identity. Shape keys are rooted by a collector provider in
119
- * xt_containers/shapes.inc. */
120
- typedef struct xt_shape {
121
- xt_value key;
122
- uint32_t count;
123
- struct xt_shape *parent;
124
- struct xt_shape *next; /* hash-bucket chain */
125
- struct xt_shape *all_next; /* every shape, for the GC root provider */
126
- } xt_shape;
127
-
128
- typedef struct {
129
- xt_header header;
130
- uint32_t count;
131
- uint32_t capacity;
132
- xt_property *properties;
133
- xt_shape *shape;
134
- xt_value prototype;
135
- uint8_t frozen;
136
- uint8_t is_array_base;
137
- uint16_t reserved2;
138
- /* Captured `Error.stack` for XT_OBJECT_KIND_ERROR, XT_UNDEFINED otherwise.
139
- * Deliberately not a property: `Object.keys`, `for...in` and JSON.stringify
140
- * must not see it, while `error.stack` returns it through `xt_get`. */
141
- xt_value error_stack;
142
- /* Optional dynamic-property view (host objects such as `element.style`); see
143
- * `xt_object_hooks` in `rt.h`. NULL for ordinary objects. */
144
- const xt_object_hooks *hooks;
145
- void *hook_data;
146
- } xt_object;
147
-
148
- typedef struct {
149
- xt_header header;
150
- uint32_t length;
151
- uint32_t capacity;
152
- xt_value *items;
153
- /* Named (non-index) properties such as `raw` on template strings or
154
- * `index`/`input` on RegExp match results, stored in an `xt_object`. */
155
- xt_value extra;
156
- /* The array's [[Prototype]] (`Array.prototype` for ordinary arrays). Arrays
157
- * are a distinct allocation kind, so this field is what lets
158
- * `Object.getPrototypeOf([])` and `x instanceof <Array alias>` work. */
159
- xt_value prototype;
160
- } xt_array;
126
+ #include "rt_object.h"
161
127
 
162
128
  typedef struct {
163
129
  xt_header header;
@@ -208,8 +174,18 @@ void xt_gc_set_stack_base(void *base);
208
174
  void xt_gc_arm(void);
209
175
  /* Run a full collection now. Re-entrant calls are ignored. */
210
176
  void xt_gc_collect(void);
177
+ /* Release the payload and the block of a swept object (xt_gc_release.c). */
178
+ void xt_gc_release(xt_header *header);
211
179
  /* Override the automatic trigger threshold (bytes of live heap). */
212
180
  void xt_gc_set_threshold(size_t bytes);
181
+
182
+ /* Small-block buffers allocated outside the collector (an object's property
183
+ * table, an array's items). `xt_raw_realloc` copies through a new block. */
184
+ void *xt_pool_alloc(size_t size);
185
+ void xt_pool_free_block(void *block, size_t size);
186
+ void *xt_raw_alloc(size_t size);
187
+ void xt_raw_free(void *pointer);
188
+ void *xt_raw_realloc(void *pointer, size_t new_size);
213
189
  extern _Thread_local int xt_gc_worker_thread;
214
190
  void xt_gc_verify_payloads(void); /* XT_GC_VERIFY=1 */
215
191
  void xt_gc_debug_record_free(uintptr_t address, size_t size, int kind);
@@ -228,11 +204,11 @@ void xt_gc_register_root_provider(void (*provider)(void));
228
204
  * region the caller records where its stack was suspended, so every active
229
205
  * region is scanned and suspended callers stay reachable. */
230
206
  void xt_gc_push_stack(uintptr_t low, uintptr_t high);
231
- /* Mark the currently-executing region as suspended at `sp` (its frames above
232
- * `sp` stay live while a deeper generator region runs). */
207
+ void xt_gc_init_main_stack(uintptr_t high);
233
208
  void xt_gc_suspend(uintptr_t sp);
234
209
  void xt_gc_pop_stack(void);
235
-
210
+ size_t xt_gc_stack_region_count(void);
211
+ void xt_gc_stack_region_bounds(size_t index, uintptr_t current, uintptr_t *low, uintptr_t *high);
236
212
  /* Marking primitives used by root providers and per-kind trace hooks. */
237
213
  void xt_gc_mark_value(xt_value value);
238
214
  void xt_gc_mark_header(xt_header *header);
@@ -413,6 +389,12 @@ xt_value xt_iter_open(xt_value value);
413
389
 
414
390
  /* xbintsc clock helpers (xt_loop.c): monotonic milliseconds for
415
391
  * `performance.now`, wall-clock milliseconds for `Date`. */
392
+ /** Snapshot the `performance.now()` time origin (the generated `main` calls
393
+ * this at startup through `xt_gc_init`). */
394
+ void xt_time_init(void);
395
+
396
+ /* Opt-in runtime call counters (`XT_PROFILE=1`, see xt_profile.c). */
397
+ #include "rt_profile.h"
416
398
  double xt_monotonic_ms(void);
417
399
  double xt_wallclock_ms(void);
418
400
 
@@ -592,9 +574,19 @@ const char *xt_typed_array_name_of(int kind);
592
574
  /* ArrayBuffer helpers (xt_array_buffer.c). */
593
575
  int xt_is_array_buffer(xt_value value);
594
576
  uint32_t xt_array_buffer_byte_length(xt_value value);
577
+ /* The backing bytes, or NULL for a detached/zero-length/unrelated value.
578
+ * `byte_length` receives the buffer's length. Valid until the buffer is
579
+ * detached or resized — callers use it within one operation. */
580
+ uint8_t *xt_array_buffer_bytes(xt_value buffer, uint32_t *byte_length);
595
581
  uint8_t xt_array_buffer_get_byte(xt_value buffer, uint32_t index);
596
582
  void xt_array_buffer_set_byte(xt_value buffer, uint32_t index, uint8_t value);
597
583
  xt_value xt_array_buffer_ctor(int32_t argc, xt_value *argv);
584
+ /** The `ArrayBuffer.prototype.slice` method value `xt_get` serves. */
585
+ xt_value xt_array_buffer_slice_value(void);
586
+ /* `byteLength`/`slice` as served from the buffer's kind (XT_UNDEFINED for any
587
+ * other key); shared by `xt_get` and `xt_object_get`. */
588
+ xt_value xt_array_buffer_served_property(xt_value buffer, xt_value key);
598
589
  #include "xt_web.h"
599
590
  #include "xt_async_io.h"
600
591
  #endif /* XT_RT_INTERNAL_H */
592
+
@@ -0,0 +1,83 @@
1
+ /*
2
+ * xbintsc runtime — object layout.
3
+ *
4
+ * Included by `rt_internal.h`, after the common `xt_header` and the value tags,
5
+ * because every container kind below starts with that header. Keeping the
6
+ * layouts in one small file makes it obvious what an "object" is in this runtime:
7
+ * a header, a property bag with an interned hidden-class shape, a prototype, and
8
+ * the per-kind side slots (an ArrayBuffer's bytes, a typed-array view's resolved
9
+ * base, an Error's captured stack, a host view's hooks).
10
+ */
11
+
12
+ #ifndef XT_RT_OBJECT_H
13
+ #define XT_RT_OBJECT_H
14
+
15
+ typedef struct {
16
+ /* String or Symbol value (see `xt_to_property_key`). */
17
+ xt_value key;
18
+ xt_value value;
19
+ /* Accessor properties (`get x()` / `set x(v)`) store the functions here;
20
+ * when set, `value` is ignored and property access invokes the getter. */
21
+ xt_value getter;
22
+ xt_value setter;
23
+ } xt_property;
24
+
25
+ /* Hidden-class descriptor for ordinary objects. Shapes are interned by their
26
+ * (parent, key) transition and never freed, so an object's shape pointer is a
27
+ * stable layout identity. Shape keys are rooted by a collector provider in
28
+ * xt_containers/shapes.inc. */
29
+ typedef struct xt_shape {
30
+ xt_value key;
31
+ uint32_t count;
32
+ struct xt_shape *parent;
33
+ struct xt_shape *next; /* hash-bucket chain */
34
+ struct xt_shape *all_next; /* every shape, for the GC root provider */
35
+ } xt_shape;
36
+
37
+ typedef struct {
38
+ xt_header header;
39
+ uint32_t count;
40
+ uint32_t capacity;
41
+ xt_property *properties;
42
+ xt_shape *shape;
43
+ xt_value prototype;
44
+ uint8_t frozen;
45
+ uint8_t is_array_base;
46
+ uint16_t reserved2;
47
+ /* Captured `Error.stack` for XT_OBJECT_KIND_ERROR, XT_UNDEFINED otherwise.
48
+ * Deliberately not a property: `Object.keys`, `for...in` and JSON.stringify
49
+ * must not see it, while `error.stack` returns it through `xt_get`. */
50
+ xt_value error_stack;
51
+ /* Optional dynamic-property view (host objects such as `element.style`); see
52
+ * `xt_object_hooks` in `rt.h`. NULL for ordinary objects. */
53
+ const xt_object_hooks *hooks;
54
+ void *hook_data;
55
+ /* XT_OBJECT_KIND_ARRAY_BUFFER only: the backing bytes, owned by this object
56
+ * and freed by the collector when it is swept. Views resolve them through
57
+ * `xt_array_buffer_bytes` and index them directly. */
58
+ uint8_t *buffer_bytes;
59
+ uint32_t buffer_length;
60
+ /* Typed-array views only: the bytes this view indexes (the buffer's block at
61
+ * the view's byte offset) and how many are available from there, set once in
62
+ * `xt_ta_view` and read on the per-element path. A buffer's block never moves
63
+ * while it is alive, and the view keeps its buffer alive as a property, so no
64
+ * invalidation is needed. NULL for every other object. */
65
+ uint8_t *view_bytes;
66
+ uint32_t view_length;
67
+ } xt_object;
68
+
69
+ typedef struct {
70
+ xt_header header;
71
+ uint32_t length;
72
+ uint32_t capacity;
73
+ xt_value *items;
74
+ /* Named (non-index) properties such as `raw` on template strings or
75
+ * `index`/`input` on RegExp match results, stored in an `xt_object`. */
76
+ xt_value extra;
77
+ /* The array's [[Prototype]] (`Array.prototype` for ordinary arrays). Arrays
78
+ * are a distinct allocation kind, so this field is what lets
79
+ * `Object.getPrototypeOf([])` and `x instanceof <Array alias>` work. */
80
+ xt_value prototype;
81
+ } xt_array;
82
+
83
+ #endif /* XT_RT_OBJECT_H */
@@ -0,0 +1,45 @@
1
+ /*
2
+ * xbintsc runtime — opt-in call counters.
3
+ *
4
+ * Included by `rt_internal.h` so every runtime unit can bump a counter with
5
+ * `XT_PROFILE_TICK`; `xt_profile.c` owns the storage and the exit dump. Kept in
6
+ * its own header so the shared runtime header stays within the size budget.
7
+ */
8
+
9
+ #ifndef XT_RT_PROFILE_H
10
+ #define XT_RT_PROFILE_H
11
+
12
+ enum {
13
+ XT_PROFILE_ALLOC,
14
+ XT_PROFILE_GC,
15
+ XT_PROFILE_MATH,
16
+ XT_PROFILE_SET,
17
+ XT_PROFILE_GET_IC,
18
+ XT_PROFILE_METHOD_IC,
19
+ XT_PROFILE_OBJECT_SET,
20
+ XT_PROFILE_OBJECT_INSERT,
21
+ XT_PROFILE_OBJECT_FIND,
22
+ XT_PROFILE_OBJECT_RESERVE,
23
+ XT_PROFILE_CLOSURE_CALL,
24
+ XT_PROFILE_ARRAY_GET,
25
+ XT_PROFILE_STRING_CSTR,
26
+ XT_PROFILE_TYPED_READ,
27
+ XT_PROFILE_TYPED_WRITE,
28
+ XT_PROFILE_COUNT
29
+ };
30
+
31
+ extern int xt_profile_on;
32
+ extern unsigned long long xt_profile_calls[XT_PROFILE_COUNT];
33
+ void xt_profile_init(void);
34
+ /* Diagnostics for allocation pressure: how many blocks of each object kind are
35
+ * allocated, and which C-string property names are looked up most (the string
36
+ * created by `xt_object_get_cstr` is one allocation per lookup). */
37
+ void xt_profile_note_alloc(int kind);
38
+ void xt_profile_note_cstr(const char *key);
39
+
40
+ #define XT_PROFILE_TICK(slot) \
41
+ do { \
42
+ if (xt_profile_on) xt_profile_calls[slot]++; \
43
+ } while (0)
44
+
45
+ #endif /* XT_RT_PROFILE_H */
@@ -54,21 +54,11 @@ static size_t g_root_provider_capacity = 0;
54
54
 
55
55
  /* ------------------------------------------------------------------------- */
56
56
  /* Active stack regions */
57
+ /* */
58
+ /* The region table lives in `xt_gc_stack.c`; it grows on demand because an */
59
+ /* async call chain can be deeper than any fixed limit. */
57
60
  /* ------------------------------------------------------------------------- */
58
61
 
59
- #define XT_GC_MAX_STACKS 64
60
- typedef struct {
61
- uintptr_t low;
62
- uintptr_t high;
63
- /* Lower bound captured from the stack below this region when a deeper region
64
- * was entered on top of it. `UINTPTR_MAX` means "this is the top region"; the
65
- * collector then scans from the current stack pointer. */
66
- uintptr_t scan_low;
67
- } xt_stack_region;
68
-
69
- static xt_stack_region g_stack_regions[XT_GC_MAX_STACKS];
70
- static int g_stack_depth = 0;
71
-
72
62
  /* ------------------------------------------------------------------------- */
73
63
  /* Mark stack and address set */
74
64
  /* ------------------------------------------------------------------------- */
@@ -144,6 +134,8 @@ static void xt_heap_link(xt_header *header) {
144
134
  }
145
135
 
146
136
  void *xt_alloc(size_t size, int kind) {
137
+ XT_PROFILE_TICK(XT_PROFILE_ALLOC);
138
+ if (xt_profile_on) xt_profile_note_alloc(kind);
147
139
  if (!g_gc_initialised) xt_gc_init();
148
140
  if (xt_gc_worker_thread) {
149
141
  void *block = calloc(1, size);
@@ -162,7 +154,15 @@ void *xt_alloc(size_t size, int kind) {
162
154
  * the conservative stack scan. */
163
155
  if (g_gc_armed && !g_gc_running && g_heap_bytes >= g_gc_threshold) xt_gc_collect();
164
156
 
165
- xt_header *header = (xt_header *)calloc(1, size);
157
+ xt_header *header = (xt_header *)xt_pool_alloc(size);
158
+ if (header != NULL) {
159
+ header->kind = (uint8_t)kind;
160
+ header->flags = XT_GC_POOLED;
161
+ header->size = (uint32_t)size;
162
+ xt_heap_link(header);
163
+ return header;
164
+ }
165
+ header = (xt_header *)calloc(1, size);
166
166
  if (!header) {
167
167
  fprintf(stderr, "xbintsc: out of memory allocating %zu bytes\n", size);
168
168
  abort();
@@ -170,7 +170,6 @@ void *xt_alloc(size_t size, int kind) {
170
170
  header->kind = (uint8_t)kind;
171
171
  header->flags = 0;
172
172
  header->size = (uint32_t)size;
173
- header->size = (uint32_t)size;
174
173
  xt_heap_link(header);
175
174
  return header;
176
175
  }
@@ -185,30 +184,20 @@ size_t xt_heap_allocations(void) { return g_heap_allocations; }
185
184
  void xt_gc_set_stack_base(void *base) {
186
185
  uintptr_t high = (uintptr_t)base;
187
186
  if (high == 0) return;
188
- if (g_stack_depth == 0) {
189
- g_stack_regions[0].low = 0;
190
- g_stack_regions[0].high = high;
191
- g_stack_regions[0].scan_low = UINTPTR_MAX;
192
- g_stack_depth = 1;
193
- } else if (high > g_stack_regions[0].high) {
194
- g_stack_regions[0].high = high;
195
- }
187
+ xt_gc_init_main_stack(high);
196
188
  }
197
189
 
198
190
  void xt_gc_init(void) {
199
191
  if (g_gc_initialised) return;
200
192
  g_gc_initialised = 1;
193
+ /* The generated `main` calls this first, before any module code, so the
194
+ * `performance.now()` origin is the start of the program. */
195
+ xt_time_init();
196
+ xt_profile_init();
201
197
  uintptr_t high = (uintptr_t)&high;
202
- if (g_stack_depth == 0) {
203
- g_stack_regions[0].low = 0;
204
- g_stack_regions[0].high = high;
205
- g_stack_regions[0].scan_low = UINTPTR_MAX;
206
- g_stack_depth = 1;
207
- } else if (high > g_stack_regions[0].high) {
208
- /* `xt_gc_set_stack_base` normally installed a bound above the caller's
209
- * frame already; keep the higher of the two. */
210
- g_stack_regions[0].high = high;
211
- }
198
+ /* `xt_gc_set_stack_base` normally installed a bound above the caller's frame
199
+ * already; the helper keeps the higher of the two. */
200
+ xt_gc_init_main_stack(high);
212
201
  const char *env = getenv("XT_GC_THRESHOLD");
213
202
  if (env && *env) {
214
203
  long long value = atoll(env);
@@ -269,24 +258,6 @@ void xt_gc_register_root_provider(void (*provider)(void)) {
269
258
  }
270
259
  g_root_providers[g_root_provider_count++] = provider;
271
260
  }
272
- void xt_gc_push_stack(uintptr_t low, uintptr_t high) {
273
- if (g_stack_depth >= XT_GC_MAX_STACKS) return;
274
- g_stack_regions[g_stack_depth].low = low;
275
- g_stack_regions[g_stack_depth].high = high;
276
- g_stack_regions[g_stack_depth].scan_low = low;
277
- g_stack_depth++;
278
- }
279
- void xt_gc_suspend(uintptr_t sp) {
280
- if (g_stack_depth <= 0) return;
281
- uintptr_t *scan = &g_stack_regions[g_stack_depth - 1].scan_low;
282
- if (*scan == UINTPTR_MAX || sp < *scan) *scan = sp;
283
- }
284
- void xt_gc_pop_stack(void) {
285
- if (g_stack_depth <= 1) return;
286
- g_stack_depth--;
287
- /* Back on the underlying stack: resume scanning it from the current frame. */
288
- if (g_stack_depth > 0) g_stack_regions[g_stack_depth - 1].scan_low = UINTPTR_MAX;
289
- }
290
261
  /* ------------------------------------------------------------------------- */
291
262
  /* Marking */
292
263
  /* ------------------------------------------------------------------------- */
@@ -319,10 +290,12 @@ static void xt_gc_gray_push_checked(xt_header *header) {
319
290
  void xt_gc_mark_header(xt_header *header) { xt_gc_gray_push_checked(header); }
320
291
 
321
292
  void xt_gc_mark_value(xt_value value) {
322
- if (XT_IS_STRING(value) || XT_IS_OBJECT(value) || XT_IS_ARRAY(value) || XT_IS_FUNCTION(value) ||
323
- XT_IS_BIGINT(value)) {
324
- xt_gc_gray_push((xt_header *)XT_GET_PTR(value));
325
- }
293
+ /* One tag compare rejects every number (and undefined/null/booleans), which
294
+ * is most of a scene's property slots; the five individual `XT_IS_*` tests
295
+ * made marking a large live set spend most of its time in predictable
296
+ * branches. */
297
+ if ((value & XT_TAG_MASK) < XT_TAG_BIGINT) return;
298
+ xt_gc_gray_push((xt_header *)XT_GET_PTR(value));
326
299
  }
327
300
  int xt_gc_value_is_marked(xt_value value) {
328
301
  if (!(XT_IS_STRING(value) || XT_IS_OBJECT(value) || XT_IS_ARRAY(value) ||
@@ -377,41 +350,59 @@ static void xt_gc_process(xt_header *header) {
377
350
  /* Numbers/bytes only: no references to follow. */
378
351
  return;
379
352
  case XT_OBJECT_KIND_OBJECT:
380
- case XT_OBJECT_KIND_ERROR: {
353
+ case XT_OBJECT_KIND_ERROR:
354
+ case XT_OBJECT_KIND_ARRAY_BUFFER: {
355
+ /* Precise trace: every reference in an ordinary object is an `xt_value`
356
+ * (a property key/value/accessor, the prototype and the captured error
357
+ * stack). The old conservative payload scan also looked up the raw
358
+ * `properties`/`shape`/`hooks` pointers and every number in the property
359
+ * table, which made marking a large scene spend most of its time in the
360
+ * heap address table. */
381
361
  xt_object *object = (xt_object *)header;
382
- xt_gc_scan_region(base, payload);
383
- if (object->properties && object->count) {
384
- xt_gc_scan_region(object->properties, sizeof(xt_property) * (size_t)object->count);
362
+ xt_gc_mark_value(object->prototype);
363
+ xt_gc_mark_value(object->error_stack);
364
+ for (uint32_t i = 0; i < object->count; i++) {
365
+ xt_gc_mark_value(object->properties[i].key);
366
+ xt_gc_mark_value(object->properties[i].value);
367
+ xt_gc_mark_value(object->properties[i].getter);
368
+ xt_gc_mark_value(object->properties[i].setter);
385
369
  }
386
370
  return;
387
371
  }
388
372
  case XT_OBJECT_KIND_ARRAY: {
389
373
  xt_array *array = (xt_array *)header;
390
- xt_gc_scan_region(base, payload);
391
- if (array->items && array->length) {
392
- xt_gc_scan_region(array->items, sizeof(xt_value) * (size_t)array->length);
393
- }
374
+ xt_gc_mark_value(array->prototype);
375
+ xt_gc_mark_value(array->extra);
376
+ for (uint32_t i = 0; i < array->length; i++) xt_gc_mark_value(array->items[i]);
394
377
  return;
395
378
  }
396
379
  case XT_OBJECT_KIND_FUNCTION: {
397
380
  xt_function *function = (xt_function *)header;
398
- xt_gc_scan_region(base, payload);
399
- if (function->environment && function->environment_count > 0) {
400
- xt_gc_scan_region(function->environment, sizeof(xt_value) * (size_t)function->environment_count);
381
+ if (function->name != NULL) xt_gc_gray_push_checked(&function->name->header);
382
+ if (function->properties != NULL) xt_gc_gray_push_checked(&function->properties->header);
383
+ xt_gc_mark_value(function->prototype);
384
+ for (int32_t i = 0; i < function->environment_count; i++) {
385
+ xt_gc_mark_value(function->environment[i]);
401
386
  }
402
387
  return;
403
388
  }
404
389
  case XT_OBJECT_KIND_MAP: {
405
390
  xt_map *map = (xt_map *)header;
406
- xt_gc_scan_region(base, payload);
407
- if (map->keys && map->count) xt_gc_scan_region(map->keys, sizeof(xt_value) * (size_t)map->count);
408
- if (map->values && map->count) xt_gc_scan_region(map->values, sizeof(xt_value) * (size_t)map->count);
391
+ for (uint32_t i = 0; i < map->count; i++) {
392
+ xt_gc_mark_value(map->keys[i]);
393
+ xt_gc_mark_value(map->values[i]);
394
+ }
409
395
  return;
410
396
  }
411
397
  case XT_OBJECT_KIND_SET: {
412
398
  xt_set_object *set = (xt_set_object *)header;
413
- xt_gc_scan_region(base, payload);
414
- if (set->values && set->count) xt_gc_scan_region(set->values, sizeof(xt_value) * (size_t)set->count);
399
+ for (uint32_t i = 0; i < set->count; i++) xt_gc_mark_value(set->values[i]);
400
+ return;
401
+ }
402
+ case XT_OBJECT_KIND_REGEXP: {
403
+ xt_regexp *regexp = (xt_regexp *)header;
404
+ xt_gc_mark_value(regexp->source);
405
+ xt_gc_mark_value(regexp->flags);
415
406
  return;
416
407
  }
417
408
  case XT_OBJECT_KIND_PROMISE:
@@ -442,52 +433,6 @@ static void xt_gc_process(xt_header *header) {
442
433
  /* ------------------------------------------------------------------------- */
443
434
  /* Release */
444
435
  /* ------------------------------------------------------------------------- */
445
- static void xt_gc_release(xt_header *header) {
446
- switch (header->kind) {
447
- case XT_OBJECT_KIND_STRING:
448
- free(((xt_string *)header)->flat);
449
- break;
450
- case XT_OBJECT_KIND_BIGINT:
451
- free(((xt_bigint *)header)->limbs);
452
- break;
453
- case XT_OBJECT_KIND_OBJECT:
454
- case XT_OBJECT_KIND_ERROR:
455
- free(((xt_object *)header)->properties);
456
- break;
457
- case XT_OBJECT_KIND_ARRAY:
458
- free(((xt_array *)header)->items);
459
- break;
460
- case XT_OBJECT_KIND_FUNCTION:
461
- free(((xt_function *)header)->environment);
462
- break;
463
- case XT_OBJECT_KIND_MAP:
464
- free(((xt_map *)header)->keys);
465
- free(((xt_map *)header)->values);
466
- break;
467
- case XT_OBJECT_KIND_SET:
468
- free(((xt_set_object *)header)->values);
469
- break;
470
- case XT_OBJECT_KIND_WEAK_MAP:
471
- free(((xt_weak_map *)header)->keys);
472
- free(((xt_weak_map *)header)->values);
473
- break;
474
- case XT_OBJECT_KIND_WEAK_SET:
475
- free(((xt_weak_set *)header)->values);
476
- break;
477
- case XT_OBJECT_KIND_PROMISE:
478
- xt_promise_gc_release(header);
479
- break;
480
- case XT_OBJECT_KIND_GENERATOR:
481
- xt_generator_gc_release(header);
482
- break;
483
- case XT_OBJECT_KIND_ASYNC:
484
- xt_async_gc_release(header);
485
- break;
486
- default:
487
- break;
488
- }
489
- free(header);
490
- }
491
436
  /* ------------------------------------------------------------------------- */
492
437
  /* Collection */
493
438
  /* ------------------------------------------------------------------------- */
@@ -504,22 +449,29 @@ static void xt_gc_mark_roots(void) {
504
449
  _setjmp(registers);
505
450
  xt_gc_scan_region(&registers, sizeof(registers));
506
451
  uintptr_t stack_pointer = (uintptr_t)&registers;
507
- for (int i = 0; i < g_stack_depth; i++) {
508
- uintptr_t high = g_stack_regions[i].high;
509
- uintptr_t low = (i == g_stack_depth - 1) ? stack_pointer : g_stack_regions[i].scan_low;
452
+ size_t regionCount = xt_gc_stack_region_count();
453
+ for (size_t i = 0; i < regionCount; i++) {
454
+ uintptr_t high = 0;
455
+ uintptr_t low = 0;
456
+ xt_gc_stack_region_bounds(i, stack_pointer, &low, &high);
510
457
  if (high > low) xt_gc_scan_region((const void *)low, high - low);
511
458
  }
512
459
  }
513
460
  void xt_gc_collect(void) {
461
+ XT_PROFILE_TICK(XT_PROFILE_GC);
514
462
  if (g_gc_running) return;
515
463
  if (!g_gc_initialised) xt_gc_init();
516
464
  g_gc_running = 1;
465
+ const double gc_started_ms = xt_monotonic_ms();
517
466
  const int trace = xt_gc_trace_enabled();
518
467
  const int leak = getenv("XT_GC_LEAK") != NULL;
519
468
  const size_t heap_before = g_heap_bytes;
520
469
  const size_t allocations_before = g_heap_allocations;
521
470
 
471
+ const double phase_started = xt_monotonic_ms();
522
472
  xt_gc_table_build();
473
+ const double phase_table = xt_monotonic_ms() - phase_started;
474
+ const double mark_started = xt_monotonic_ms();
523
475
  xt_gc_mark_roots();
524
476
  /* Ephemeron fixed point: a WeakMap value is reachable only when its key is
525
477
  * reachable. Marking a value can reach further keys, so repeat until a pass
@@ -535,6 +487,8 @@ void xt_gc_collect(void) {
535
487
  xt_weak_gc_clear();
536
488
  xt_weak_gc_compact();
537
489
  if (getenv("XT_GC_VERIFY") != NULL) xt_gc_verify_payloads();
490
+ const double phase_mark = xt_monotonic_ms() - mark_started;
491
+ const double sweep_started = xt_monotonic_ms();
538
492
 
539
493
  xt_header **link = &g_heap_head;
540
494
  xt_header *header = g_heap_head;
@@ -565,20 +519,19 @@ void xt_gc_collect(void) {
565
519
  }
566
520
 
567
521
  xt_gc_table_free();
522
+ const double phase_sweep = xt_monotonic_ms() - sweep_started;
568
523
  g_gc_running = 0;
569
524
 
570
525
  if (!g_gc_threshold_pinned) {
571
- /* Follow the live set: twice the surviving heap is the headroom a
572
- * mark-sweep wants between collections, and the floor keeps a tiny heap
573
- * from collecting on nearly every allocation.
574
- *
575
- * The threshold must *shrink* again, not just ratchet upwards. A doubling
576
- * threshold with a monotonic floor turns any transient growth of the live
577
- * set into exponentially rarer collections: each sweep only reclaims the
578
- * newly dead part of a larger heap, so the heap (and with it the resident
579
- * set) grows without bound. A GUI program that keeps a few extra nodes
580
- * alive for one frame is enough to start that spiral. */
581
- size_t next = g_heap_bytes * 2;
526
+ /* Follow the live set: four times the surviving heap is the headroom a
527
+ * mark-sweep wants between collections for an interactive program. Two
528
+ * times collected too often: a three.js scene that keeps ~380k objects live
529
+ * spent a ~300 ms pause every ~1.2 s, and half of the frame budget went to
530
+ * collections. Four times halves that overhead at a bounded memory cost
531
+ * (the threshold still shrinks with the live set, so it cannot ratchet
532
+ * upwards). The floor keeps a tiny heap from collecting on nearly every
533
+ * allocation. */
534
+ size_t next = g_heap_bytes * 4;
582
535
  if (next < XT_GC_MIN_THRESHOLD) next = XT_GC_MIN_THRESHOLD;
583
536
  g_gc_threshold = next;
584
537
  }
@@ -586,9 +539,11 @@ void xt_gc_collect(void) {
586
539
  g_gc_collections++;
587
540
  if (trace) {
588
541
  fprintf(stderr,
589
- "xt_gc: #%zu heap %zu -> %zu bytes, allocations %zu -> %zu, next trigger %zu\n",
542
+ "xt_gc: #%zu heap %zu -> %zu bytes, allocations %zu -> %zu, next trigger %zu, took %.1fms"
543
+ " (table %.1f, mark %.1f, sweep %.1f)\n",
590
544
  g_gc_collections, heap_before, g_heap_bytes, allocations_before, g_heap_allocations,
591
- g_gc_threshold);
545
+ g_gc_threshold, xt_monotonic_ms() - gc_started_ms, phase_table, phase_mark,
546
+ phase_sweep);
592
547
  fprintf(stderr, "xt_gc: live kinds");
593
548
  for (int i = 1; i < 16; i++) {
594
549
  if (live_by_kind[i] != 0) {