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
@@ -129,3 +129,69 @@ xt_value xt_console_time_end(int32_t argc, xt_value *argv) {
129
129
  }
130
130
  return XT_UNDEFINED;
131
131
  }
132
+
133
+ /* ------------------------------------------------------------------------- */
134
+ /* The global `console` object */
135
+ /* ------------------------------------------------------------------------- */
136
+
137
+ /*
138
+ * `console` is a global *value* as well as a namespace: code writes
139
+ * `const log = console.log`, `console.error.bind(console)` and
140
+ * `const { warn } = console`, so the binding has to be a real object whose
141
+ * methods are ordinary first-class functions. The object is built once and
142
+ * rooted; each method is a closure over the raw `(argc, argv)` runtime symbol,
143
+ * so a method keeps its behaviour when detached from the object.
144
+ */
145
+
146
+ typedef void (*xt_console_void_method)(int32_t, xt_value *);
147
+ typedef xt_value (*xt_console_value_method)(int32_t, xt_value *);
148
+
149
+ static xt_value xt_console_void_bridge(xt_value thisValue, xt_value env, int32_t argc,
150
+ xt_value *argv) {
151
+ (void)thisValue;
152
+ ((xt_console_void_method)(uintptr_t)xt_closure_env(env, 0))(argc, argv);
153
+ return XT_UNDEFINED;
154
+ }
155
+
156
+ static xt_value xt_console_value_bridge(xt_value thisValue, xt_value env, int32_t argc,
157
+ xt_value *argv) {
158
+ (void)thisValue;
159
+ return ((xt_console_value_method)(uintptr_t)xt_closure_env(env, 0))(argc, argv);
160
+ }
161
+
162
+ static void xt_console_add(xt_value object, const char *name, void *method, int returnsValue) {
163
+ xt_value env[1];
164
+ env[0] = (xt_value)(uintptr_t)method;
165
+ xt_value closure = xt_closure_new(
166
+ returnsValue ? (void *)xt_console_value_bridge : (void *)xt_console_void_bridge, 1, env);
167
+ xt_value key = xt_string_from_cstr(name);
168
+ xt_function_set_metadata(closure, key, returnsValue ? 1 : 0);
169
+ xt_object_set(object, key, closure);
170
+ }
171
+
172
+ xt_value xt_console_object(int32_t argc, xt_value *argv) {
173
+ (void)argc;
174
+ (void)argv;
175
+ static xt_value cached = 0;
176
+ if (cached != 0) return cached;
177
+ xt_value object = xt_object_new();
178
+ xt_console_add(object, "log", (void *)xt_console_log, 0);
179
+ xt_console_add(object, "info", (void *)xt_console_info, 0);
180
+ xt_console_add(object, "warn", (void *)xt_console_warn, 0);
181
+ xt_console_add(object, "error", (void *)xt_console_error, 0);
182
+ xt_console_add(object, "debug", (void *)xt_console_log, 0);
183
+ xt_console_add(object, "dir", (void *)xt_console_dir, 1);
184
+ xt_console_add(object, "trace", (void *)xt_console_trace, 1);
185
+ xt_console_add(object, "assert", (void *)xt_console_assert, 1);
186
+ xt_console_add(object, "count", (void *)xt_console_count, 1);
187
+ xt_console_add(object, "countReset", (void *)xt_console_count_reset, 1);
188
+ xt_console_add(object, "group", (void *)xt_console_group, 1);
189
+ xt_console_add(object, "groupEnd", (void *)xt_console_group_end, 1);
190
+ xt_console_add(object, "table", (void *)xt_console_table, 1);
191
+ xt_console_add(object, "time", (void *)xt_console_time, 1);
192
+ xt_console_add(object, "timeEnd", (void *)xt_console_time_end, 1);
193
+ xt_console_add(object, "timeLog", (void *)xt_console_time_log, 1);
194
+ cached = object;
195
+ xt_gc_add_root(&cached);
196
+ return object;
197
+ }
@@ -38,8 +38,39 @@ typedef struct {
38
38
 
39
39
  static xt_stack_entry g_stack[XT_STACK_MAX_DEPTH];
40
40
  static int32_t g_stack_depth = 0;
41
+ /* Bumped on every push/pop so the hang watchdog (`watchdog.inc`) can tell a
42
+ * program that is working from one that is spinning without calling anything. */
43
+ static volatile unsigned long long g_stack_ticks = 0;
44
+
45
+ /* The module whose top-level code is running. Every module of a bundle shares
46
+ * one generated function, so a crash inside a module body would otherwise be
47
+ * reported at the entry file's offsets. Codegen emits one call per module
48
+ * boundary. */
49
+ static const char *g_current_module = NULL;
50
+
51
+ /* Defined in `watchdog.inc`, which is included after this file. */
52
+ static void xt_stack_watchdog_start_once(void);
53
+
54
+ /** Print the shadow stack, innermost frame first (used by the hang watchdog
55
+ * and by hosts that want the JavaScript frames on a fatal signal). */
56
+ static void xt_stack_dump_frames(void) {
57
+ int32_t depth = g_stack_depth;
58
+ if (depth < 0) depth = 0;
59
+ if (depth > XT_STACK_MAX_DEPTH) depth = XT_STACK_MAX_DEPTH;
60
+ for (int32_t index = depth - 1; index >= 0; index--) {
61
+ const xt_stack_entry *entry = &g_stack[index];
62
+ fprintf(stderr, " at %s (%s:%d)\n",
63
+ entry->name && entry->name[0] ? entry->name : "anonymous",
64
+ entry->file && entry->file[0] ? entry->file : "<anonymous>", entry->line);
65
+ }
66
+ if (depth == 0 && g_current_module != NULL) {
67
+ fprintf(stderr, " (no JavaScript frame; module %s)\n", g_current_module);
68
+ }
69
+ }
41
70
 
42
71
  void xt_stack_push(const char *name, const char *file, int32_t line) {
72
+ g_stack_ticks++;
73
+ xt_stack_watchdog_start_once();
43
74
  if (g_stack_depth >= XT_STACK_MAX_DEPTH) return;
44
75
  xt_stack_entry *entry = &g_stack[g_stack_depth++];
45
76
  entry->name = name;
@@ -48,6 +79,7 @@ void xt_stack_push(const char *name, const char *file, int32_t line) {
48
79
  }
49
80
 
50
81
  void xt_stack_pop(void) {
82
+ g_stack_ticks++;
51
83
  if (g_stack_depth > 0) g_stack_depth--;
52
84
  }
53
85
 
@@ -64,12 +96,6 @@ void xt_stack_trim(int32_t depth) {
64
96
  if (depth < g_stack_depth) g_stack_depth = depth;
65
97
  }
66
98
 
67
- /* The module whose top-level code is running. Every module of a bundle shares
68
- * one generated function, so a crash inside a module body would otherwise be
69
- * reported at the entry file's offsets. Codegen emits one call per module
70
- * boundary. */
71
- static const char *g_current_module = NULL;
72
-
73
99
  void xt_stack_set_module(const char *name) { g_current_module = name; }
74
100
 
75
101
 
@@ -0,0 +1,101 @@
1
+ /* ------------------------------------------------------------------------- */
2
+ /* Hang watchdog */
3
+ /* ------------------------------------------------------------------------- */
4
+
5
+ /*
6
+ * A compiled program that spins — an unexpected infinite loop in user code, a
7
+ * blocking host call, a pathological input — prints nothing at all, and a GUI
8
+ * program merely stops painting. There is no debugger attached and no V8 to
9
+ * request a profile from, so "it hangs" is all the user can report.
10
+ *
11
+ * Setting `XT_STACK_WATCHDOG_MS=<n>` starts a sampler thread that watches the
12
+ * shadow call stack: when no function has been entered or left for `n`
13
+ * milliseconds, it prints the innermost frames (name, file, line). That turns a
14
+ * silent hang into the source location that is spinning.
15
+ *
16
+ * Cost when the variable is unset: one relaxed counter increment per compiled
17
+ * call and nothing else — the thread is not started. The frame array is read
18
+ * from another thread without a lock, which can tear a frame in the middle of
19
+ * an update; that is acceptable for a diagnostic that only runs when asked for.
20
+ * The stack data itself lives in `exception.inc`.
21
+ */
22
+
23
+ #if !defined(_WIN32)
24
+ #include <pthread.h>
25
+ #endif
26
+
27
+ static volatile int g_watchdog_started = 0;
28
+ static volatile int g_watchdog_stop = 0;
29
+
30
+ /** Monotonic milliseconds. */
31
+ static unsigned long long xt_watchdog_now_ms(void) {
32
+ #if defined(_WIN32)
33
+ return (unsigned long long)GetTickCount64();
34
+ #else
35
+ struct timespec ts;
36
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) return 0;
37
+ return (unsigned long long)ts.tv_sec * 1000ull + (unsigned long long)(ts.tv_nsec / 1000000);
38
+ #endif
39
+ }
40
+
41
+ #if defined(_WIN32)
42
+ static unsigned __stdcall xt_watchdog_entry(void *argument) {
43
+ #else
44
+ static void *xt_watchdog_entry(void *argument) {
45
+ #endif
46
+ unsigned long long threshold = (unsigned long long)(uintptr_t)argument;
47
+ unsigned long long interval = threshold / 4;
48
+ if (interval < 20) interval = 20;
49
+ unsigned long long last_ticks = g_stack_ticks;
50
+ unsigned long long idle_since = xt_watchdog_now_ms();
51
+ int sample_all = getenv("XT_STACK_SAMPLE_ALL") != NULL;
52
+ while (!g_watchdog_stop) {
53
+ unsigned long long now;
54
+ #if defined(_WIN32)
55
+ Sleep((DWORD)interval);
56
+ #else
57
+ struct timespec sleep_for;
58
+ sleep_for.tv_sec = (time_t)(interval / 1000);
59
+ sleep_for.tv_nsec = (long)((interval % 1000) * 1000000);
60
+ nanosleep(&sleep_for, NULL);
61
+ #endif
62
+ if (g_watchdog_stop) break;
63
+ now = xt_watchdog_now_ms();
64
+ if (!sample_all && g_stack_ticks != last_ticks) {
65
+ last_ticks = g_stack_ticks;
66
+ idle_since = now;
67
+ continue;
68
+ }
69
+ if (!sample_all && now - idle_since < threshold) continue;
70
+ if (sample_all) last_ticks = g_stack_ticks;
71
+ fprintf(stderr, "xt: no JavaScript call for %llu ms, shadow stack:\n", now - idle_since);
72
+ xt_stack_dump_frames();
73
+ fflush(stderr);
74
+ /* Report once per idle period, not once per interval. */
75
+ idle_since = now;
76
+ }
77
+ #if defined(_WIN32)
78
+ return 0;
79
+ #else
80
+ return NULL;
81
+ #endif
82
+ }
83
+
84
+ /** Start the sampler once, if `XT_STACK_WATCHDOG_MS` asks for it. */
85
+ static void xt_stack_watchdog_start_once(void) {
86
+ if (g_watchdog_started) return;
87
+ g_watchdog_started = 1;
88
+ const char *configured = getenv("XT_STACK_WATCHDOG_MS");
89
+ if (configured == NULL || configured[0] == 0) return;
90
+ long ms = strtol(configured, NULL, 10);
91
+ if (ms <= 0) return;
92
+ #if defined(_WIN32)
93
+ uintptr_t handle = _beginthreadex(NULL, 0, xt_watchdog_entry, (void *)(uintptr_t)ms, 0, NULL);
94
+ if (handle != 0) CloseHandle((HANDLE)handle);
95
+ #else
96
+ pthread_t thread;
97
+ if (pthread_create(&thread, NULL, xt_watchdog_entry, (void *)(uintptr_t)ms) == 0) {
98
+ pthread_detach(thread);
99
+ }
100
+ #endif
101
+ }
package/runtime/xt_io.c CHANGED
@@ -46,6 +46,7 @@
46
46
  #endif
47
47
 
48
48
  #include "xt_io/exception.inc"
49
+ #include "xt_io/watchdog.inc"
49
50
  #include "xt_io/inspect.inc"
50
51
  #include "xt_io/console.inc"
51
52
  #include "xt_io/base64.inc"
package/runtime/xt_loop.c CHANGED
@@ -92,9 +92,9 @@ static int64_t xt_loop_now_ms(void) {
92
92
  #endif
93
93
  }
94
94
 
95
- /* Fractional monotonic milliseconds for `performance.now()`. Kept separate from
96
- * xt_loop_now_ms(), which only needs whole milliseconds for timer deadlines. */
97
- double xt_monotonic_ms(void) {
95
+ /* Raw fractional monotonic milliseconds: on Windows this is the QPC counter,
96
+ * which counts from machine boot, not from process start. */
97
+ static double xt_raw_monotonic_ms(void) {
98
98
  #if defined(_WIN32)
99
99
  static LARGE_INTEGER frequency;
100
100
  if (frequency.QuadPart == 0) QueryPerformanceFrequency(&frequency);
@@ -108,6 +108,26 @@ double xt_monotonic_ms(void) {
108
108
  #endif
109
109
  }
110
110
 
111
+ /* `performance.now()` is relative to the program's own time origin, like a
112
+ * browser's (navigation start) or Node's (process start) — not to machine boot.
113
+ * Before the origin existed, a process started six days into an uptime reported
114
+ * `performance.now() == 521,000,000` on its first call: deltas were still right,
115
+ * so three.js kept working, but every absolute reading was nonsense and any
116
+ * `now() / 1000` (three.js's `clock.elapsedTime`) started at six days. */
117
+ static double g_time_origin_ms = -1.0;
118
+
119
+ void xt_time_init(void) {
120
+ if (g_time_origin_ms < 0.0) g_time_origin_ms = xt_raw_monotonic_ms();
121
+ }
122
+
123
+ /* Fractional monotonic milliseconds for `performance.now()`. Kept separate from
124
+ * xt_loop_now_ms(), which only needs whole milliseconds for timer deadlines. */
125
+ double xt_monotonic_ms(void) {
126
+ if (g_time_origin_ms < 0.0) g_time_origin_ms = xt_raw_monotonic_ms();
127
+ double elapsed = xt_raw_monotonic_ms() - g_time_origin_ms;
128
+ return elapsed < 0.0 ? 0.0 : elapsed;
129
+ }
130
+
111
131
  /* Wall-clock milliseconds since the Unix epoch, for `Date.now()` and
112
132
  * `new Date()`. `time(NULL)` only has second resolution, which silently broke
113
133
  * elapsed-time math; this keeps the milliseconds the language exposes. */
@@ -0,0 +1,151 @@
1
+ /*
2
+ * xbintsc runtime — the small-block allocator.
3
+ *
4
+ * The collector in `xt_alloc.c` owns reachability; this unit owns the bytes.
5
+ * Keeping the two apart keeps each file within the repository's size budget and
6
+ * makes the ownership rule explicit: every block either comes from a size-class
7
+ * free list or from `malloc`, and the collector asks this unit to release it.
8
+ */
9
+
10
+ #include "rt_internal.h"
11
+
12
+ #include <stdio.h>
13
+ #include <stdlib.h>
14
+ #include <string.h>
15
+ /* ------------------------------------------------------------------------- */
16
+ /* Small-block pool */
17
+ /* ------------------------------------------------------------------------- */
18
+
19
+ /*
20
+ * Most runtime objects are small — an `xt_object` is ~120 bytes and a closure
21
+ * ~100 — and a scene build creates millions of them. The C allocator charges a
22
+ * lock, a free-list search and zeroing per block, which made object creation
23
+ * the dominant cost of three.js's geometry and level construction. Blocks up
24
+ * to `XT_POOL_SMALL_MAX` are carved out of 1 MiB slabs and recycled through
25
+ * per-class free lists instead; the collector returns a block to its class, so
26
+ * a steady state reuses the same memory.
27
+ *
28
+ * The pool is main-thread only: an I/O worker allocates result values with
29
+ * `calloc` (see `xt_alloc`), and the collector — the only thing that releases
30
+ * blocks — runs on the main thread. Slabs are never returned to the OS; the
31
+ * pool is bounded by the process's peak live set, the same bound the
32
+ * collector's threshold follows.
33
+ */
34
+ #define XT_POOL_SMALL_MAX 2048
35
+ static const uint16_t xt_pool_sizes[] = {
36
+ 16, 32, 48, 64, 80, 96, 112, 128, 160, 192, 224, 256,
37
+ 320, 384, 448, 512, 640, 768, 896, 1024, 1280, 1536, 1792, 2048,
38
+ };
39
+ #define XT_POOL_CLASS_COUNT ((int)(sizeof(xt_pool_sizes) / sizeof(xt_pool_sizes[0])))
40
+ static void *g_pool_free[XT_POOL_CLASS_COUNT];
41
+ static unsigned char *g_pool_cursor = NULL;
42
+ static size_t g_pool_left = 0;
43
+
44
+ static int xt_pool_class_of(size_t size) {
45
+ for (int index = 0; index < XT_POOL_CLASS_COUNT; index++) {
46
+ if (size <= (size_t)xt_pool_sizes[index]) return index;
47
+ }
48
+ return -1;
49
+ }
50
+
51
+ /** A zeroed block of at least `size` bytes, or NULL when the size is large. */
52
+ void *xt_pool_alloc(size_t size) {
53
+ int cls = xt_pool_class_of(size);
54
+ if (cls < 0) return NULL;
55
+ void *block = g_pool_free[cls];
56
+ if (block != NULL) {
57
+ g_pool_free[cls] = *(void **)block;
58
+ } else {
59
+ size_t need = (size_t)xt_pool_sizes[cls];
60
+ if (g_pool_left < need) {
61
+ size_t chunk = (size_t)1 << 20;
62
+ if (chunk < need) chunk = need;
63
+ g_pool_cursor = (unsigned char *)malloc(chunk);
64
+ if (g_pool_cursor == NULL) return NULL;
65
+ g_pool_left = chunk;
66
+ }
67
+ block = g_pool_cursor;
68
+ g_pool_cursor += need;
69
+ g_pool_left -= need;
70
+ }
71
+ memset(block, 0, size);
72
+ return block;
73
+ }
74
+
75
+ /** Return a block from `xt_pool_alloc` to its class. */
76
+ void xt_pool_free_block(void *block, size_t size) {
77
+ /* Only the main thread owns the pool. A worker never allocates from it, so
78
+ * reaching here on a worker would mean a main-thread block was re-grown
79
+ * there; leaking it is safer than corrupting the free list. */
80
+ if (xt_gc_worker_thread) return;
81
+ int cls = xt_pool_class_of(size);
82
+ if (cls < 0 || block == NULL) return;
83
+ *(void **)block = g_pool_free[cls];
84
+ g_pool_free[cls] = block;
85
+ }
86
+
87
+ /* ------------------------------------------------------------------------- */
88
+ /* Small-block buffers (property tables, array items) */
89
+ /* ------------------------------------------------------------------------- */
90
+
91
+ /*
92
+ * The buffers behind an object's property table and an array's items grow by
93
+ * doubling, so they are allocated outside the collector. They get the same
94
+ * pool treatment through a small private header, which also records where the
95
+ * block came from: a buffer allocated on an I/O worker comes from `malloc` and
96
+ * is released with `free`, while a main-thread buffer is pooled. The 16-byte
97
+ * header keeps the payload 16-byte aligned.
98
+ */
99
+ typedef struct {
100
+ uint32_t cls;
101
+ uint32_t size;
102
+ uint64_t padding;
103
+ } xt_raw_header;
104
+
105
+ #define XT_RAW_HEADER_SIZE ((size_t)16)
106
+
107
+ void *xt_raw_alloc(size_t size) {
108
+ if (size == 0) size = 1;
109
+ unsigned char *block = NULL;
110
+ if (!xt_gc_worker_thread && size <= XT_POOL_SMALL_MAX) block = (unsigned char *)xt_pool_alloc(size + XT_RAW_HEADER_SIZE);
111
+ if (block == NULL) {
112
+ block = (unsigned char *)malloc(size + XT_RAW_HEADER_SIZE);
113
+ if (block == NULL) {
114
+ fprintf(stderr, "xbintsc: out of memory allocating %zu bytes\n", size);
115
+ abort();
116
+ }
117
+ xt_raw_header *header = (xt_raw_header *)block;
118
+ header->cls = 0xffffffffu;
119
+ header->size = (uint32_t)size;
120
+ header->padding = 0;
121
+ } else {
122
+ xt_raw_header *header = (xt_raw_header *)block;
123
+ header->cls = (uint32_t)xt_pool_class_of(size + XT_RAW_HEADER_SIZE);
124
+ header->size = (uint32_t)size;
125
+ header->padding = 0;
126
+ }
127
+ return block + XT_RAW_HEADER_SIZE;
128
+ }
129
+
130
+ void xt_raw_free(void *pointer) {
131
+ if (pointer == NULL) return;
132
+ unsigned char *block = (unsigned char *)pointer - XT_RAW_HEADER_SIZE;
133
+ xt_raw_header *header = (xt_raw_header *)block;
134
+ if (header->cls == 0xffffffffu) {
135
+ free(block);
136
+ return;
137
+ }
138
+ xt_pool_free_block(block, (size_t)header->size + XT_RAW_HEADER_SIZE);
139
+ }
140
+
141
+ void *xt_raw_realloc(void *pointer, size_t new_size) {
142
+ if (pointer == NULL) return xt_raw_alloc(new_size);
143
+ unsigned char *block = (unsigned char *)pointer - XT_RAW_HEADER_SIZE;
144
+ xt_raw_header *header = (xt_raw_header *)block;
145
+ size_t old_size = (size_t)header->size;
146
+ void *grown = xt_raw_alloc(new_size);
147
+ memcpy(grown, pointer, old_size < new_size ? old_size : new_size);
148
+ xt_raw_free(pointer);
149
+ return grown;
150
+ }
151
+
@@ -0,0 +1,126 @@
1
+ /*
2
+ * xbintsc runtime — opt-in call counters for performance work.
3
+ *
4
+ * `XT_PROFILE=1` increments one counter per entry of the runtime's hottest
5
+ * helpers and prints the totals at exit. A counter is one branch and one
6
+ * increment, so a profiled run keeps the shape of the workload; pair the counts
7
+ * with a microbenchmark of the same helper to attribute time.
8
+ *
9
+ * This is diagnostics, not a feature: the counters are off unless the variable
10
+ * is set, and the dump goes to stderr.
11
+ */
12
+
13
+ #include "rt_internal.h"
14
+
15
+ #include <stdio.h>
16
+ #include <stdlib.h>
17
+ #include <string.h>
18
+
19
+ #define XT_PROFILE_KEY_SLOTS 512
20
+ #define XT_PROFILE_KEY_PROBES 8
21
+
22
+ typedef struct {
23
+ char *key;
24
+ unsigned long long count;
25
+ } xt_profile_key;
26
+
27
+ static xt_profile_key g_keys[XT_PROFILE_KEY_SLOTS];
28
+ static unsigned long long g_alloc_kinds[32];
29
+
30
+ int xt_profile_on = 0;
31
+ unsigned long long xt_profile_calls[XT_PROFILE_COUNT];
32
+
33
+ void xt_profile_note_alloc(int kind) {
34
+ if (!xt_profile_on) return;
35
+ if (kind >= 0 && kind < 32) g_alloc_kinds[kind]++;
36
+ }
37
+
38
+ void xt_profile_note_cstr(const char *key) {
39
+ if (!xt_profile_on || key == NULL) return;
40
+ uint64_t hash = 1469598103934665603ull;
41
+ for (const char *p = key; *p != '\0'; p++) {
42
+ hash ^= (unsigned char)*p;
43
+ hash *= 1099511628211ull;
44
+ }
45
+ const size_t start = (size_t)(hash & (XT_PROFILE_KEY_SLOTS - 1));
46
+ for (size_t probe = 0; probe < XT_PROFILE_KEY_PROBES; probe++) {
47
+ xt_profile_key *slot = &g_keys[(start + probe) & (XT_PROFILE_KEY_SLOTS - 1)];
48
+ if (slot->key == NULL) {
49
+ const size_t length = strlen(key) + 1;
50
+ char *copy = (char *)malloc(length);
51
+ if (copy == NULL) return;
52
+ memcpy(copy, key, length);
53
+ slot->key = copy;
54
+ slot->count = 1;
55
+ return;
56
+ }
57
+ if (strcmp(slot->key, key) == 0) {
58
+ slot->count++;
59
+ return;
60
+ }
61
+ }
62
+ }
63
+
64
+ static const char *const xt_profile_kind_names[32] = {
65
+ "none", "string", "object", "array", "function",
66
+ "promise", "map", "set", "date", "regexp",
67
+ "symbol", "bigint", "error", "generator", "iterator",
68
+ "async", "async-iter", "weak-map", "weak-set", "weak-ref",
69
+ "array-buffer",
70
+ };
71
+
72
+ static const char *const xt_profile_names[XT_PROFILE_COUNT] = {
73
+ "alloc",
74
+ "gc",
75
+ "math",
76
+ "set",
77
+ "get-ic",
78
+ "method-ic",
79
+ "object-set",
80
+ "object-insert",
81
+ "object-find",
82
+ "object-reserve",
83
+ "closure-call",
84
+ "array-get",
85
+ "string-cstr",
86
+ "typed-read",
87
+ "typed-write",
88
+ };
89
+
90
+ static void xt_profile_dump(void) {
91
+ if (!xt_profile_on) return;
92
+ for (int i = 0; i < XT_PROFILE_COUNT; i++) {
93
+ if (xt_profile_calls[i] == 0) continue;
94
+ fprintf(stderr, "xt_profile: %-14s %llu\n", xt_profile_names[i], xt_profile_calls[i]);
95
+ }
96
+ for (int kind = 0; kind < 32; kind++) {
97
+ if (g_alloc_kinds[kind] == 0) continue;
98
+ const char *name = kind < (int)(sizeof(xt_profile_kind_names) / sizeof(char *))
99
+ ? xt_profile_kind_names[kind]
100
+ : "other";
101
+ fprintf(stderr, "xt_profile: alloc %-12s %llu\n", name, g_alloc_kinds[kind]);
102
+ }
103
+ /* The twenty most frequent C-string property names: each was an allocated
104
+ * xt_string unless the runtime interns it. */
105
+ for (int rank = 0; rank < 20; rank++) {
106
+ long best = -1;
107
+ unsigned long long best_count = 0;
108
+ for (int i = 0; i < XT_PROFILE_KEY_SLOTS; i++) {
109
+ if (g_keys[i].key == NULL || g_keys[i].count == 0) continue;
110
+ if (g_keys[i].count > best_count) {
111
+ best_count = g_keys[i].count;
112
+ best = i;
113
+ }
114
+ }
115
+ if (best < 0) break;
116
+ fprintf(stderr, "xt_profile: key %-24s %llu\n", g_keys[best].key, g_keys[best].count);
117
+ g_keys[best].count = 0;
118
+ }
119
+ }
120
+
121
+ void xt_profile_init(void) {
122
+ const char *env = getenv("XT_PROFILE");
123
+ if (env == NULL || env[0] == '\0' || env[0] == '0') return;
124
+ xt_profile_on = 1;
125
+ atexit(xt_profile_dump);
126
+ }
@@ -335,9 +335,14 @@ static xt_value xt_function_has_instance(xt_value thisValue, xt_value env, int32
335
335
  xt_value xt_function_has_instance_method(void) {
336
336
  static xt_value cached = 0;
337
337
  if (cached == 0) {
338
+ /* Root the slot before the first allocation. A lazy getter that stores into
339
+ * a static and only registers it afterwards loses the value to a collection
340
+ * that runs while building it: the static is not on the stack, so the
341
+ * collector never sees the new method. Building it allocates its name
342
+ * string, which is exactly such a collection point. */
343
+ xt_gc_add_root(&cached);
338
344
  cached = xt_closure_new((void *)xt_function_has_instance, 0, NULL);
339
345
  xt_function_set_metadata(cached, xt_string_from_cstr("[Symbol.hasInstance]"), 1);
340
- xt_gc_add_root(&cached);
341
346
  }
342
347
  return cached;
343
348
  }
@@ -515,3 +520,4 @@ xt_value xt_call_method(xt_value target, xt_value name, int32_t argc, xt_value *
515
520
  }
516
521
  xt_throw_no_method("value", method);
517
522
  }
523
+