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
@@ -0,0 +1,58 @@
1
+ xt_value xt_object_keys(xt_value value) {
2
+ xt_value result = xt_array_new(0, NULL);
3
+ /* A typed array's enumerable own keys are its indices; `length` and the
4
+ * buffer metadata are observable but not enumerable. */
5
+ int typed = xt_typed_array_kind_of(value);
6
+ if (typed >= 0) {
7
+ uint32_t length = (uint32_t)xt_to_number(xt_object_get_cstr(value, "length"));
8
+ for (uint32_t i = 0; i < length; i++) {
9
+ char buffer[32];
10
+ snprintf(buffer, sizeof(buffer), "%u", i);
11
+ xt_array_push(result, xt_string_from_cstr(buffer));
12
+ }
13
+ return result;
14
+ }
15
+ if (XT_IS_OBJECT(value)) {
16
+ xt_object *obj = (xt_object *)XT_GET_PTR(value);
17
+ /* Map/Set/Date/RegExp/Promise/Symbol use their own layout and have no
18
+ * property bag; reading `obj->count` there walked off the end of the
19
+ * allocation (`Object.getOwnPropertyNames(new Map())` crashed). */
20
+ if (!xt_kind_is_object(obj->header.kind)) {
21
+ return result;
22
+ }
23
+ for (uint32_t i = 0; i < obj->count; i++) {
24
+ if (XT_IS_STRING(obj->properties[i].key)) xt_array_push(result, obj->properties[i].key);
25
+ }
26
+ /* Dynamic keys of a host view (`element.dataset`, ...), appended without
27
+ * repeating a real property that was just pushed. */
28
+ xt_object_append_dynamic_keys(obj, value, result);
29
+ return result;
30
+ }
31
+ if (XT_IS_ARRAY(value)) {
32
+ xt_array *array = (xt_array *)XT_GET_PTR(value);
33
+ for (uint32_t i = 0; i < array->length; i++) {
34
+ char buffer[32];
35
+ snprintf(buffer, sizeof(buffer), "%u", i);
36
+ xt_array_push(result, xt_string_from_cstr(buffer));
37
+ }
38
+ if (XT_IS_OBJECT(array->extra)) {
39
+ xt_object *extra = (xt_object *)XT_GET_PTR(array->extra);
40
+ for (uint32_t i = 0; i < extra->count; i++) {
41
+ if (XT_IS_STRING(extra->properties[i].key)) xt_array_push(result, extra->properties[i].key);
42
+ }
43
+ }
44
+ return result;
45
+ }
46
+ if (XT_IS_STRING(value)) {
47
+ xt_string *s = xt_as_string(value);
48
+ uint32_t units = xt_string_utf16_length(s);
49
+ for (uint32_t i = 0; i < units; i++) {
50
+ char buffer[32];
51
+ snprintf(buffer, sizeof(buffer), "%u", i);
52
+ xt_array_push(result, xt_string_from_cstr(buffer));
53
+ }
54
+ return result;
55
+ }
56
+ return result;
57
+ }
58
+
@@ -3,10 +3,12 @@
3
3
  /* ------------------------------------------------------------------------- */
4
4
 
5
5
  static void xt_object_reserve(xt_object *obj, uint32_t needed) {
6
+ XT_PROFILE_TICK(XT_PROFILE_OBJECT_RESERVE);
6
7
  if (needed <= obj->capacity) return;
7
8
  uint32_t capacity = obj->capacity ? obj->capacity * 2 : 8;
8
9
  while (capacity < needed) capacity *= 2;
9
- obj->properties = (xt_property *)realloc(obj->properties, sizeof(xt_property) * capacity);
10
+ obj->properties =
11
+ (xt_property *)xt_raw_realloc(obj->properties, sizeof(xt_property) * capacity);
10
12
  if (!obj->properties) {
11
13
  fprintf(stderr, "xbintsc: out of memory growing object\n");
12
14
  abort();
@@ -195,6 +197,7 @@ xt_object *xt_as_object(xt_value value) {
195
197
  }
196
198
 
197
199
  static xt_property *xt_object_find(xt_object *obj, xt_value key) {
200
+ XT_PROFILE_TICK(XT_PROFILE_OBJECT_FIND);
198
201
  for (uint32_t i = 0; i < obj->count; i++) {
199
202
  if (xt_property_key_equals(obj->properties[i].key, key)) return &obj->properties[i];
200
203
  }
@@ -230,6 +233,7 @@ static int xt_key_is_array_index(xt_string *key, uint32_t *out) {
230
233
  /* Insert a new property for `key`, preserving JavaScript key order. Symbols
231
234
  * are not array indices and simply append in insertion order. */
232
235
  static xt_property *xt_object_insert_property(xt_object *obj, xt_value key) {
236
+ XT_PROFILE_TICK(XT_PROFILE_OBJECT_INSERT);
233
237
  uint32_t index = 0;
234
238
  uint32_t position = obj->count;
235
239
  if (XT_IS_STRING(key) && xt_key_is_array_index(xt_as_string(key), &index)) {
@@ -302,8 +306,11 @@ xt_value xt_object_get(xt_value value, xt_value key) {
302
306
  layout. Containers such as Map/Set/Date/RegExp/Promise/Array must not be
303
307
  interpreted as property tables, or property lookup reads past the end of
304
308
  their real representation. */
305
- if (obj->header.kind != XT_OBJECT_KIND_OBJECT && obj->header.kind != XT_OBJECT_KIND_ERROR)
306
- return XT_UNDEFINED;
309
+ if (!xt_kind_is_object(obj->header.kind)) return XT_UNDEFINED;
310
+ if (obj->header.kind == XT_OBJECT_KIND_ARRAY_BUFFER) {
311
+ xt_value served = xt_array_buffer_served_property(value, key);
312
+ if (served != XT_UNDEFINED) return served; /* `byteLength` / `slice` */
313
+ }
307
314
  xt_value k = xt_to_property_key(key);
308
315
  /* Walk the prototype chain like JavaScript property lookup. */
309
316
  xt_object *cur = obj;
@@ -328,7 +335,15 @@ xt_value xt_object_get(xt_value value, xt_value key) {
328
335
  continue;
329
336
  }
330
337
  if (!XT_IS_OBJECT(cur->prototype)) break;
331
- cur = (xt_object *)XT_GET_PTR(cur->prototype);
338
+ xt_object *next = (xt_object *)XT_GET_PTR(cur->prototype);
339
+ if (next == cur) break;
340
+ /* A prototype may be any object value (`Object.setPrototypeOf(o, new Map())`
341
+ * is legal). Only plain objects and errors share the property-table layout;
342
+ * walking into a Map/Set/Date would read `count`/`properties` at the wrong
343
+ * offsets. Stop the chain instead, which is what the lookup would find
344
+ * anyway: those containers keep their state outside their property bag. */
345
+ if (!xt_kind_is_object(next->header.kind)) break;
346
+ cur = next;
332
347
  }
333
348
  /* A host view (`element.style`, `element.dataset`, computed style) answers the
334
349
  * keys it owns dynamically. Only a miss reaches this point, so prototype
@@ -346,18 +361,19 @@ xt_value xt_object_get(xt_value value, xt_value key) {
346
361
  static xt_object *xt_object_prototype_of(xt_value prototype, xt_object *current) {
347
362
  xt_object *next = xt_as_object(prototype);
348
363
  if (!next || next == current) return NULL;
349
- if (next->header.kind != XT_OBJECT_KIND_OBJECT && next->header.kind != XT_OBJECT_KIND_ERROR)
364
+ if (!xt_kind_is_object(next->header.kind))
350
365
  return NULL;
351
366
  return next;
352
367
  }
353
368
 
354
369
  xt_value xt_object_set(xt_value value, xt_value key, xt_value newValue) {
370
+ XT_PROFILE_TICK(XT_PROFILE_OBJECT_SET);
355
371
  if (XT_IS_FUNCTION(value) && xt_key_is_prototype(key)) {
356
372
  return xt_function_set_prototype(value, newValue);
357
373
  }
358
374
  xt_object *obj = xt_as_object(value);
359
375
  if (!obj) return newValue;
360
- if (obj->header.kind != XT_OBJECT_KIND_OBJECT && obj->header.kind != XT_OBJECT_KIND_ERROR)
376
+ if (!xt_kind_is_object(obj->header.kind))
361
377
  return newValue;
362
378
  if (obj->frozen) return newValue;
363
379
  xt_value k = xt_to_property_key(key);
@@ -436,6 +452,7 @@ xt_value xt_object_get_prototype(xt_value value) {
436
452
  switch (obj->header.kind) {
437
453
  case XT_OBJECT_KIND_OBJECT:
438
454
  case XT_OBJECT_KIND_ERROR:
455
+ case XT_OBJECT_KIND_ARRAY_BUFFER:
439
456
  return obj->prototype;
440
457
  case XT_OBJECT_KIND_SYMBOL:
441
458
  case XT_OBJECT_KIND_MAP:
@@ -460,7 +477,12 @@ xt_value xt_object_set_prototype(xt_value value, xt_value proto) {
460
477
  return value;
461
478
  }
462
479
  xt_object *obj = xt_as_object(value);
463
- if (obj && !obj->frozen) obj->prototype = proto;
480
+ if (obj && !obj->frozen) {
481
+ obj->prototype = proto;
482
+ /* `reserved2` memoizes a typed array's element kind from its prototype
483
+ * (`xt_typed_array_kind_of`); a re-prototyped view is no longer that kind. */
484
+ obj->reserved2 = 0;
485
+ }
464
486
  return value;
465
487
  }
466
488
 
@@ -478,12 +500,22 @@ int xt_object_is_frozen(xt_value value) {
478
500
 
479
501
  xt_value xt_object_from_entries(xt_value entries) {
480
502
  xt_value result = xt_object_new();
481
- xt_array *array = xt_as_array(entries);
482
- if (!array) return result;
483
- for (uint32_t i = 0; i < array->length; i++) {
484
- xt_array *pair = xt_as_array(array->items[i]);
485
- if (!pair || pair->length < 2) continue;
486
- xt_object_set(result, pair->items[0], pair->items[1]);
503
+ /* `fromEntries` consumes *any* iterable (a `Map`, a `URLSearchParams`, a
504
+ * generator), not only an array: the shell-usage scan the Saltline page does
505
+ * with `Object.fromEntries(new URLSearchParams(location.search))` silently
506
+ * produced `{}` and the page fell back to its default boot path. */
507
+ xt_value iterator = xt_iter_open(entries);
508
+ xt_value index = xt_number(0);
509
+ while (xt_truthy(xt_iter_has(iterator, index))) {
510
+ xt_value item = xt_iter_value(iterator, index);
511
+ /* An entry is any object with `0`/`1` properties; arrays are a separate
512
+ * value tag, not `XT_IS_OBJECT` values. */
513
+ if (XT_IS_OBJECT(item) || XT_IS_ARRAY(item)) {
514
+ xt_value key = xt_get(item, xt_number(0));
515
+ xt_value value = xt_get(item, xt_number(1));
516
+ xt_object_set(result, key, value);
517
+ }
518
+ index = xt_number(xt_to_number(index) + 1.0);
487
519
  }
488
520
  return result;
489
521
  }
@@ -491,7 +523,7 @@ xt_value xt_object_from_entries(xt_value entries) {
491
523
  xt_value xt_object_has(xt_value value, xt_value key) {
492
524
  if (!XT_IS_OBJECT(value)) return XT_FALSE;
493
525
  xt_object *obj = (xt_object *)XT_GET_PTR(value);
494
- if (obj->header.kind != XT_OBJECT_KIND_OBJECT && obj->header.kind != XT_OBJECT_KIND_ERROR) {
526
+ if (!xt_kind_is_object(obj->header.kind)) {
495
527
  return XT_FALSE;
496
528
  }
497
529
  xt_value propertyKey = xt_to_property_key(key);
@@ -509,74 +541,10 @@ xt_value xt_object_own_property_symbols(xt_value value) {
509
541
  xt_value result = xt_array_new(0, NULL);
510
542
  if (!XT_IS_OBJECT(value)) return result;
511
543
  xt_object *obj = (xt_object *)XT_GET_PTR(value);
512
- if (obj->header.kind != XT_OBJECT_KIND_OBJECT && obj->header.kind != XT_OBJECT_KIND_ERROR)
544
+ if (!xt_kind_is_object(obj->header.kind))
513
545
  return result;
514
546
  for (uint32_t i = 0; i < obj->count; i++) {
515
547
  if (xt_is_symbol(obj->properties[i].key)) xt_array_push(result, obj->properties[i].key);
516
548
  }
517
549
  return result;
518
550
  }
519
-
520
- xt_value xt_object_keys(xt_value value) {
521
- xt_value result = xt_array_new(0, NULL);
522
- /* A typed array's enumerable own keys are its indices; `length` and the
523
- * buffer metadata are observable but not enumerable. */
524
- int typed = xt_typed_array_kind_of(value);
525
- if (typed >= 0) {
526
- uint32_t length = (uint32_t)xt_to_number(xt_object_get_cstr(value, "length"));
527
- for (uint32_t i = 0; i < length; i++) {
528
- char buffer[32];
529
- snprintf(buffer, sizeof(buffer), "%u", i);
530
- xt_array_push(result, xt_string_from_cstr(buffer));
531
- }
532
- return result;
533
- }
534
- if (XT_IS_OBJECT(value)) {
535
- xt_object *obj = (xt_object *)XT_GET_PTR(value);
536
- /* Map/Set/Date/RegExp/Promise/Symbol use their own layout and have no
537
- * property bag; reading `obj->count` there walked off the end of the
538
- * allocation (`Object.getOwnPropertyNames(new Map())` crashed). */
539
- if (obj->header.kind != XT_OBJECT_KIND_OBJECT && obj->header.kind != XT_OBJECT_KIND_ERROR) {
540
- return result;
541
- }
542
- for (uint32_t i = 0; i < obj->count; i++) {
543
- if (XT_IS_STRING(obj->properties[i].key)) xt_array_push(result, obj->properties[i].key);
544
- }
545
- /* Dynamic keys of a host view (`element.dataset`, ...), appended without
546
- * repeating a real property that was just pushed. */
547
- xt_object_append_dynamic_keys(obj, value, result);
548
- return result;
549
- }
550
- if (XT_IS_ARRAY(value)) {
551
- xt_array *array = (xt_array *)XT_GET_PTR(value);
552
- for (uint32_t i = 0; i < array->length; i++) {
553
- char buffer[32];
554
- snprintf(buffer, sizeof(buffer), "%u", i);
555
- xt_array_push(result, xt_string_from_cstr(buffer));
556
- }
557
- if (XT_IS_OBJECT(array->extra)) {
558
- xt_object *extra = (xt_object *)XT_GET_PTR(array->extra);
559
- for (uint32_t i = 0; i < extra->count; i++) {
560
- if (XT_IS_STRING(extra->properties[i].key)) xt_array_push(result, extra->properties[i].key);
561
- }
562
- }
563
- return result;
564
- }
565
- if (XT_IS_STRING(value)) {
566
- xt_string *s = xt_as_string(value);
567
- uint32_t units = xt_string_utf16_length(s);
568
- for (uint32_t i = 0; i < units; i++) {
569
- char buffer[32];
570
- snprintf(buffer, sizeof(buffer), "%u", i);
571
- xt_array_push(result, xt_string_from_cstr(buffer));
572
- }
573
- return result;
574
- }
575
- return result;
576
- }
577
-
578
- /* Convenience used by codegen for `obj.prop`. */
579
- xt_value xt_object_get_cstr(xt_value value, const char *key) {
580
- xt_value k = xt_string_from_cstr(key);
581
- return xt_object_get(value, k);
582
- }
@@ -4,23 +4,57 @@
4
4
 
5
5
  /* Shapes are interned by their (parent, property key) transition. They are
6
6
  * immortal metadata, but their keys are ordinary strings/symbols, so a root
7
- * provider keeps those keys alive. Pointer identity is enough to share a
8
- * transition between the same interned literal; dynamically built keys simply
9
- * get their own shape, which is still a correct layout identity for the IC. */
10
- #define XT_SHAPE_BUCKETS 256
7
+ * provider keeps those keys alive. A key is matched by *text* (see
8
+ * `xt_shape_bucket`), so an interned literal and a string built at run time with
9
+ * the same bytes share one transition.
10
+ *
11
+ * The bucket count and the intern limit are performance parameters, not
12
+ * semantics: a saturated table (or a NULL shape) disables the shape/method
13
+ * inline caches for every object created afterwards, so the next lookup is a
14
+ * linear scan of the receiver and its prototype chain. A GUI page built on a
15
+ * large JS bundle interns tens of thousands of transitions, so the old 256
16
+ * buckets / 16K shapes pair walked long chains and then silently degraded the
17
+ * hot paths; both are sized for a large application now.
18
+ */
19
+ #define XT_SHAPE_BUCKETS 4096
11
20
  /* Interned shapes are immortal metadata. A program that creates property names
12
21
  * dynamically would otherwise leak one shape per name forever, so stop
13
22
  * interning after a bounded number; those objects simply fall back to the
14
23
  * uncached lookup (a NULL shape). */
15
- #define XT_SHAPE_LIMIT 16384
24
+ #define XT_SHAPE_LIMIT 262144
16
25
  static xt_shape *g_shapes[XT_SHAPE_BUCKETS];
17
26
  static xt_shape *g_shape_all = NULL;
18
27
  static xt_shape *g_shape_root = NULL;
19
28
  static uint32_t g_shape_count = 0;
20
29
 
30
+ /* A key's *content* decides its bucket, not the address of the string that
31
+ * holds it. Property keys built at run time (a typed array's `byteLength`, a
32
+ * DOM handle's `length`, any `obj["k" + i]`) are fresh string objects with the
33
+ * same bytes; hashing the pointer would put each of them in its own bucket, so
34
+ * the value comparison in the chain below could never find the existing
35
+ * transition and *every insert* would intern a new shape. Hashing the bytes is
36
+ * what makes value interning work, and therefore what keeps the shape table
37
+ * (and the inline caches that depend on it) usable in a large program. */
38
+ static uint64_t xt_shape_key_hash(xt_value key) {
39
+ if (XT_IS_STRING(key)) {
40
+ xt_string *string = xt_as_string(key);
41
+ const char *bytes = xt_string_bytes(string);
42
+ uint64_t hash = 1469598103934665603ULL; /* FNV-1a */
43
+ for (uint32_t i = 0; i < string->length; i++) {
44
+ hash ^= (unsigned char)bytes[i];
45
+ hash *= 1099511628211ULL;
46
+ }
47
+ return hash;
48
+ }
49
+ return (uint64_t)(uintptr_t)XT_GET_PTR(key);
50
+ }
51
+
21
52
  static size_t xt_shape_bucket(xt_shape *parent, xt_value key) {
22
- uintptr_t mixed = ((uintptr_t)parent >> 4) ^ ((uintptr_t)XT_GET_PTR(key) >> 4);
23
- return (size_t)mixed & (XT_SHAPE_BUCKETS - 1);
53
+ uintptr_t mixed = ((uintptr_t)parent >> 4) ^ (uintptr_t)xt_shape_key_hash(key);
54
+ /* The low bits are alignment, not entropy: mix them before masking. */
55
+ mixed ^= mixed >> 17;
56
+ mixed *= 0x9e3779b97f4a7c15ULL;
57
+ return (size_t)(mixed >> 32) & (XT_SHAPE_BUCKETS - 1);
24
58
  }
25
59
 
26
60
  static void xt_shape_gc_roots(void) {
@@ -38,11 +72,111 @@ static xt_shape *xt_shape_empty(void) {
38
72
  return shape;
39
73
  }
40
74
 
75
+ static int xt_shape_trace_enabled(void) {
76
+ static int enabled = -1;
77
+ if (enabled < 0) {
78
+ const char *env = getenv("XT_SHAPE_TRACE");
79
+ enabled = (env != NULL && env[0] != '\0' && env[0] != '0') ? 1 : 0;
80
+ }
81
+ return enabled;
82
+ }
83
+
84
+ static uint64_t g_shape_rebuilds = 0;
85
+
86
+ /* Trace-only histogram over the property names that create transitions. */
87
+ typedef struct {
88
+ char text[24];
89
+ uint32_t count;
90
+ } xt_shape_key_stat;
91
+ #define XT_SHAPE_TRACE_KEYS 64
92
+ static xt_shape_key_stat g_shape_key_stats[XT_SHAPE_TRACE_KEYS];
93
+ static uint32_t g_shape_key_stat_count = 0;
94
+
95
+ static void xt_shape_trace_record(xt_value key) {
96
+ char text[24];
97
+ if (XT_IS_STRING(key)) {
98
+ xt_string *string = xt_as_string(key);
99
+ const char *bytes = xt_string_bytes(string);
100
+ uint32_t length = string->length;
101
+ if (length > 20) length = 20;
102
+ if (bytes) {
103
+ memcpy(text, bytes, length);
104
+ text[length] = '\0';
105
+ } else {
106
+ text[0] = '\0';
107
+ }
108
+ } else if (xt_is_symbol(key)) {
109
+ xt_value description = xt_symbol_description(key);
110
+ const char *name = XT_IS_STRING(description) ? xt_string_bytes(xt_as_string(description)) : "";
111
+ snprintf(text, sizeof(text), "@%s", name != NULL ? name : "");
112
+ } else {
113
+ snprintf(text, sizeof(text), "<other>");
114
+ }
115
+ for (uint32_t i = 0; i < g_shape_key_stat_count; i++) {
116
+ if (strcmp(g_shape_key_stats[i].text, text) == 0) {
117
+ g_shape_key_stats[i].count++;
118
+ return;
119
+ }
120
+ }
121
+ if (g_shape_key_stat_count < XT_SHAPE_TRACE_KEYS) {
122
+ snprintf(g_shape_key_stats[g_shape_key_stat_count].text, sizeof(g_shape_key_stats[0].text), "%s", text);
123
+ g_shape_key_stats[g_shape_key_stat_count].count = 1;
124
+ g_shape_key_stat_count++;
125
+ }
126
+ }
127
+
128
+ static void xt_shape_trace_report(void) {
129
+ fprintf(stderr, "xt_shape: %u transitions, %llu rebuilds; top property names:", (unsigned)g_shape_count,
130
+ (unsigned long long)g_shape_rebuilds);
131
+ for (int rank = 0; rank < 8; rank++) {
132
+ int best = -1;
133
+ for (uint32_t i = 0; i < g_shape_key_stat_count; i++) {
134
+ if (g_shape_key_stats[i].count == 0) continue;
135
+ if (best < 0 || g_shape_key_stats[i].count > g_shape_key_stats[best].count) best = (int)i;
136
+ }
137
+ if (best < 0) break;
138
+ fprintf(stderr, " %s=%u", g_shape_key_stats[best].text, g_shape_key_stats[best].count);
139
+ g_shape_key_stats[best].count = 0;
140
+ }
141
+ fprintf(stderr, "\n");
142
+ }
143
+
144
+ /* Print the full property layout of a newly interned shape (root first). */
145
+ static void xt_shape_trace_chain(xt_shape *shape) {
146
+ const xt_shape *chain[64];
147
+ int depth = 0;
148
+ for (const xt_shape *s = shape; s != NULL && s->parent != NULL && depth < 64; s = s->parent) chain[depth++] = s;
149
+ fprintf(stderr, "xt_shape: latest layout:");
150
+ for (int i = depth - 1; i >= 0; i--) {
151
+ xt_value key = chain[i]->key;
152
+ if (XT_IS_STRING(key)) {
153
+ xt_string *string = xt_as_string(key);
154
+ const char *bytes = xt_string_bytes(string);
155
+ uint32_t length = string->length;
156
+ if (length > 16) length = 16;
157
+ fprintf(stderr, " %.*s", (int)length, bytes != NULL ? bytes : "");
158
+ } else if (xt_is_symbol(key)) {
159
+ xt_value description = xt_symbol_description(key);
160
+ const char *name = XT_IS_STRING(description) ? xt_string_bytes(xt_as_string(description)) : "?";
161
+ fprintf(stderr, " @%s", name != NULL ? name : "?");
162
+ } else {
163
+ fprintf(stderr, " <other>");
164
+ }
165
+ }
166
+ fprintf(stderr, "\n");
167
+ }
168
+
41
169
  xt_shape *xt_shape_transition(xt_shape *parent, xt_value key) {
42
170
  if (!parent) parent = xt_shape_empty();
43
171
  size_t bucket = xt_shape_bucket(parent, key);
44
172
  for (xt_shape *shape = g_shapes[bucket]; shape; shape = shape->next) {
45
- if (shape->parent == parent && shape->key == key) return shape;
173
+ if (shape->parent != parent) continue;
174
+ /* Property keys are interned for literals, but a key built at run time
175
+ * (`obj[name]`, a number converted to a string, a symbol-less parser) is a
176
+ * fresh value every time. Interning by value, not by pointer, is what keeps
177
+ * a page from creating one shape per *insert* instead of one per distinct
178
+ * layout. */
179
+ if (shape->key == key || xt_property_key_equals(shape->key, key)) return shape;
46
180
  }
47
181
  if (g_shape_count >= XT_SHAPE_LIMIT) return NULL;
48
182
  xt_shape *shape = (xt_shape *)calloc(1, sizeof(xt_shape));
@@ -55,10 +189,21 @@ xt_shape *xt_shape_transition(xt_shape *parent, xt_value key) {
55
189
  shape->all_next = g_shape_all;
56
190
  g_shape_all = shape;
57
191
  g_shape_count++;
192
+ /* Diagnostics: `XT_SHAPE_TRACE=1` reports the interned-transition count so a
193
+ * page that needs a larger table is visible instead of silently degrading.
194
+ * The per-key histogram shows *which* property names are multiplying. */
195
+ if (xt_shape_trace_enabled()) {
196
+ xt_shape_trace_record(key);
197
+ if ((g_shape_count & 32767u) == 0) {
198
+ xt_shape_trace_report();
199
+ xt_shape_trace_chain(shape);
200
+ }
201
+ }
58
202
  return shape;
59
203
  }
60
204
 
61
205
  void xt_object_shape_changed(xt_object *obj) {
206
+ g_shape_rebuilds++;
62
207
  xt_shape *shape = xt_shape_empty();
63
208
  for (uint32_t i = 0; i < obj->count; i++) {
64
209
  shape = xt_shape_transition(shape, obj->properties[i].key);
@@ -19,6 +19,10 @@
19
19
  #include "xt_containers/shapes.inc"
20
20
  #include "xt_containers/function_prototypes.inc"
21
21
  #include "xt_containers/objects.inc"
22
+ #include "xt_containers/cstr_cache.inc"
23
+ #include "xt_containers/object_keys.inc"
22
24
  #include "xt_containers/arrays.inc"
23
25
  #include "xt_containers/access.inc"
26
+ #include "xt_containers/method_cache.inc"
24
27
  #include "xt_containers/boxes.inc"
28
+
@@ -0,0 +1,70 @@
1
+ /*
2
+ * xbintsc runtime — release the backing storage of one collected block.
3
+ *
4
+ * Split out of xt_alloc.c to keep the collector within the file-size budget;
5
+ * called from the sweep with the block already unlinked from the heap list.
6
+ */
7
+
8
+ #include "rt_internal.h"
9
+
10
+ #include <stdlib.h>
11
+
12
+ void xt_gc_release(xt_header *header) {
13
+ const size_t block_size = (size_t)header->size;
14
+ const int pooled = (header->flags & XT_GC_POOLED) != 0;
15
+ switch (header->kind) {
16
+ case XT_OBJECT_KIND_STRING:
17
+ free(((xt_string *)header)->flat);
18
+ break;
19
+ case XT_OBJECT_KIND_BIGINT:
20
+ free(((xt_bigint *)header)->limbs);
21
+ break;
22
+ case XT_OBJECT_KIND_OBJECT:
23
+ case XT_OBJECT_KIND_ERROR:
24
+ xt_raw_free(((xt_object *)header)->properties);
25
+ break;
26
+ case XT_OBJECT_KIND_ARRAY_BUFFER: {
27
+ xt_object *object = (xt_object *)header;
28
+ free(object->buffer_bytes);
29
+ xt_raw_free(object->properties);
30
+ break;
31
+ }
32
+ case XT_OBJECT_KIND_ARRAY:
33
+ xt_raw_free(((xt_array *)header)->items);
34
+ break;
35
+ case XT_OBJECT_KIND_FUNCTION:
36
+ free(((xt_function *)header)->environment);
37
+ break;
38
+ case XT_OBJECT_KIND_MAP:
39
+ free(((xt_map *)header)->keys);
40
+ free(((xt_map *)header)->values);
41
+ break;
42
+ case XT_OBJECT_KIND_SET:
43
+ free(((xt_set_object *)header)->values);
44
+ break;
45
+ case XT_OBJECT_KIND_WEAK_MAP:
46
+ free(((xt_weak_map *)header)->keys);
47
+ free(((xt_weak_map *)header)->values);
48
+ break;
49
+ case XT_OBJECT_KIND_WEAK_SET:
50
+ free(((xt_weak_set *)header)->values);
51
+ break;
52
+ case XT_OBJECT_KIND_PROMISE:
53
+ xt_promise_gc_release(header);
54
+ break;
55
+ case XT_OBJECT_KIND_GENERATOR:
56
+ xt_generator_gc_release(header);
57
+ break;
58
+ case XT_OBJECT_KIND_ASYNC:
59
+ xt_async_gc_release(header);
60
+ break;
61
+ default:
62
+ break;
63
+ }
64
+ if (pooled) {
65
+ xt_pool_free_block(header, block_size);
66
+ } else {
67
+ free(header);
68
+ }
69
+ }
70
+
@@ -0,0 +1,83 @@
1
+ /*
2
+ * xbintsc runtime — GC stack-region table.
3
+ *
4
+ * A coroutine has a private C stack; while it runs (or while it is suspended
5
+ * under a deeper coroutine) the conservative collector must scan that region.
6
+ * The table grows on demand: an `async` call chain can be deeper than any fixed
7
+ * limit, and silently dropping a push would desynchronise push/pop, so a later
8
+ * pop evicted a still-live parent region and the collector stopped scanning it.
9
+ */
10
+
11
+ #include "rt_internal.h"
12
+
13
+ #include <stddef.h>
14
+ #include <stdio.h>
15
+ #include <stdlib.h>
16
+
17
+ typedef struct {
18
+ uintptr_t low;
19
+ uintptr_t high;
20
+ /* Lower bound captured from the stack below this region when a deeper region
21
+ * was entered on top of it. `UINTPTR_MAX` means "this is the top region"; the
22
+ * collector then scans from the current stack pointer. */
23
+ uintptr_t scan_low;
24
+ } xt_stack_region;
25
+
26
+ static xt_stack_region *g_stack_regions = NULL;
27
+ static size_t g_stack_depth = 0;
28
+ static size_t g_stack_capacity = 0;
29
+
30
+ /** Ensure room for one more region; aborts when the process is out of memory. */
31
+ static void xt_gc_reserve_stack_region(void) {
32
+ if (g_stack_depth < g_stack_capacity) return;
33
+ size_t capacity = g_stack_capacity == 0 ? 16 : g_stack_capacity * 2;
34
+ xt_stack_region *grown = (xt_stack_region *)realloc(g_stack_regions, sizeof(xt_stack_region) * capacity);
35
+ if (!grown) {
36
+ fprintf(stderr, "xbintsc: out of memory growing the GC stack-region table\n");
37
+ abort();
38
+ }
39
+ g_stack_regions = grown;
40
+ g_stack_capacity = capacity;
41
+ }
42
+
43
+ void xt_gc_init_main_stack(uintptr_t high) {
44
+ xt_gc_reserve_stack_region();
45
+ if (g_stack_depth == 0) {
46
+ g_stack_regions[0].low = 0;
47
+ g_stack_regions[0].high = high;
48
+ g_stack_regions[0].scan_low = UINTPTR_MAX;
49
+ g_stack_depth = 1;
50
+ } else if (high > g_stack_regions[0].high) {
51
+ g_stack_regions[0].high = high;
52
+ }
53
+ }
54
+
55
+ void xt_gc_push_stack(uintptr_t low, uintptr_t high) {
56
+ xt_gc_reserve_stack_region();
57
+ g_stack_regions[g_stack_depth].low = low;
58
+ g_stack_regions[g_stack_depth].high = high;
59
+ g_stack_regions[g_stack_depth].scan_low = low;
60
+ g_stack_depth++;
61
+ }
62
+
63
+ void xt_gc_suspend(uintptr_t sp) {
64
+ if (g_stack_depth == 0) return;
65
+ uintptr_t *scan = &g_stack_regions[g_stack_depth - 1].scan_low;
66
+ if (*scan == UINTPTR_MAX || sp < *scan) *scan = sp;
67
+ }
68
+
69
+ void xt_gc_pop_stack(void) {
70
+ if (g_stack_depth <= 1) return;
71
+ g_stack_depth--;
72
+ /* Back on the underlying stack: resume scanning it from the current frame. */
73
+ if (g_stack_depth > 0) g_stack_regions[g_stack_depth - 1].scan_low = UINTPTR_MAX;
74
+ }
75
+
76
+ size_t xt_gc_stack_region_count(void) {
77
+ return g_stack_depth;
78
+ }
79
+
80
+ void xt_gc_stack_region_bounds(size_t index, uintptr_t current, uintptr_t *low, uintptr_t *high) {
81
+ *high = g_stack_regions[index].high;
82
+ *low = index + 1 == g_stack_depth ? current : g_stack_regions[index].scan_low;
83
+ }
@@ -42,6 +42,7 @@ static const char *xt_gc_kind_name(uint8_t kind) {
42
42
  case XT_OBJECT_KIND_WEAK_MAP: return "weakmap";
43
43
  case XT_OBJECT_KIND_WEAK_SET: return "weakset";
44
44
  case XT_OBJECT_KIND_WEAK_REF: return "weakref";
45
+ case XT_OBJECT_KIND_ARRAY_BUFFER: return "array-buffer";
45
46
  default: return "?";
46
47
  }
47
48
  }