@scriptc/cli-darwin-x64 0.0.0 → 0.2.1

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 (963) hide show
  1. package/dist/LICENSE +202 -0
  2. package/dist/THIRD_PARTY_NOTICES +4 -0
  3. package/dist/bin/scriptc +0 -0
  4. package/dist/bin/scriptc.json +21 -0
  5. package/dist/lib/declarations/scriptc-node-fallback.d.ts +3857 -0
  6. package/dist/lib/declarations/scriptc-overrides.d.ts +92 -0
  7. package/dist/lib/declarations/scriptc.d.ts +98 -0
  8. package/dist/lib/llvm/LICENSE +1 -0
  9. package/dist/lib/llvm/SCRIPTC_LICENSE +1 -0
  10. package/dist/lib/llvm/THIRD_PARTY_NOTICES +1 -0
  11. package/dist/lib/llvm/bin/scriptc-llvm-codegen +0 -0
  12. package/dist/lib/llvm/package.json +35 -0
  13. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_array.o +0 -0
  14. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_assert.o +0 -0
  15. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_async.o +0 -0
  16. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_async_dyn.o +0 -0
  17. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bigint.o +0 -0
  18. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bigint_assert.o +0 -0
  19. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bytes.o +0 -0
  20. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bytes_io.o +0 -0
  21. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_child.o +0 -0
  22. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_closure.o +0 -0
  23. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_console.o +0 -0
  24. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_console_native.o +0 -0
  25. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_copying.o +0 -0
  26. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_crypto_async.o +0 -0
  27. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_cycle.o +0 -0
  28. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_dc.o +0 -0
  29. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_dgram.o +0 -0
  30. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_dyn_handle.o +0 -0
  31. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_dyn_invoke.o +0 -0
  32. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_error.o +0 -0
  33. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_events.o +0 -0
  34. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_events_emitter.o +0 -0
  35. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_exception.o +0 -0
  36. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_fetch.o +0 -0
  37. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_ffi.o +0 -0
  38. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_ffi_queue.o +0 -0
  39. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_file_handle.o +0 -0
  40. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_grapheme.o +0 -0
  41. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_http.o +0 -0
  42. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_http2.o +0 -0
  43. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_inspect.o +0 -0
  44. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_json.o +0 -0
  45. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_lib.o +0 -0
  46. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_loop_epoll.o +0 -0
  47. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_loop_kqueue.o +0 -0
  48. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_loop_wsapoll.o +0 -0
  49. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_map.o +0 -0
  50. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_net.o +0 -0
  51. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_node_builtin.o +0 -0
  52. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_number.o +0 -0
  53. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_object.o +0 -0
  54. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_path.o +0 -0
  55. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_qs.o +0 -0
  56. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_readline.o +0 -0
  57. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_regex.o +0 -0
  58. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_stream.o +0 -0
  59. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_string.o +0 -0
  60. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_symbol.o +0 -0
  61. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_test.o +0 -0
  62. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_tls.o +0 -0
  63. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_tls_ca.o +0 -0
  64. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_union.o +0 -0
  65. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_url.o +0 -0
  66. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_url_params.o +0 -0
  67. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_util.o +0 -0
  68. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_watch.o +0 -0
  69. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_zlib.o +0 -0
  70. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_array.o +0 -0
  71. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_assert.o +0 -0
  72. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_async.o +0 -0
  73. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_async_dyn.o +0 -0
  74. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bigint.o +0 -0
  75. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bigint_assert.o +0 -0
  76. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bytes.o +0 -0
  77. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bytes_io.o +0 -0
  78. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_child.o +0 -0
  79. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_closure.o +0 -0
  80. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_console.o +0 -0
  81. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_console_native.o +0 -0
  82. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_copying.o +0 -0
  83. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_crypto_async.o +0 -0
  84. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_cycle.o +0 -0
  85. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_dc.o +0 -0
  86. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_dgram.o +0 -0
  87. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_dyn_handle.o +0 -0
  88. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_dyn_invoke.o +0 -0
  89. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_error.o +0 -0
  90. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_events.o +0 -0
  91. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_events_emitter.o +0 -0
  92. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_exception.o +0 -0
  93. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_fetch.o +0 -0
  94. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_ffi.o +0 -0
  95. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_ffi_queue.o +0 -0
  96. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_file_handle.o +0 -0
  97. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_grapheme.o +0 -0
  98. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_http.o +0 -0
  99. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_http2.o +0 -0
  100. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_inspect.o +0 -0
  101. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_inspect_island.o +0 -0
  102. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_island.o +0 -0
  103. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_json.o +0 -0
  104. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_lib.o +0 -0
  105. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_loop_epoll.o +0 -0
  106. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_loop_kqueue.o +0 -0
  107. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_loop_wsapoll.o +0 -0
  108. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_map.o +0 -0
  109. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_net.o +0 -0
  110. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_net_island.o +0 -0
  111. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_node_builtin.o +0 -0
  112. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_number.o +0 -0
  113. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_object.o +0 -0
  114. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_path.o +0 -0
  115. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_qs.o +0 -0
  116. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_readline.o +0 -0
  117. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_regex.o +0 -0
  118. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_stream.o +0 -0
  119. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_string.o +0 -0
  120. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_symbol.o +0 -0
  121. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_test.o +0 -0
  122. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_tls.o +0 -0
  123. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_tls_ca.o +0 -0
  124. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_union.o +0 -0
  125. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_url.o +0 -0
  126. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_url_params.o +0 -0
  127. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_util.o +0 -0
  128. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_watch.o +0 -0
  129. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_web.o +0 -0
  130. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_zlib.o +0 -0
  131. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_zlib_island.o +0 -0
  132. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
  133. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  134. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_array.o +0 -0
  135. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_assert.o +0 -0
  136. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bigint.o +0 -0
  137. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bigint_assert.o +0 -0
  138. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bytes.o +0 -0
  139. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bytes_io.o +0 -0
  140. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_closure.o +0 -0
  141. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_console.o +0 -0
  142. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_console_native.o +0 -0
  143. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_copying.o +0 -0
  144. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_cycle.o +0 -0
  145. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_dyn_handle.o +0 -0
  146. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_dyn_invoke.o +0 -0
  147. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_error.o +0 -0
  148. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_events_emitter.o +0 -0
  149. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_exception.o +0 -0
  150. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_grapheme.o +0 -0
  151. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_inspect.o +0 -0
  152. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_json.o +0 -0
  153. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_lib.o +0 -0
  154. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_library.o +0 -0
  155. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_map.o +0 -0
  156. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_node_builtin.o +0 -0
  157. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_number.o +0 -0
  158. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_object.o +0 -0
  159. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_path.o +0 -0
  160. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_regex.o +0 -0
  161. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_string.o +0 -0
  162. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_symbol.o +0 -0
  163. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_union.o +0 -0
  164. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_url.o +0 -0
  165. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_url_params.o +0 -0
  166. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_zlib.o +0 -0
  167. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  168. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_array.o +0 -0
  169. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_assert.o +0 -0
  170. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bigint.o +0 -0
  171. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bigint_assert.o +0 -0
  172. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bytes.o +0 -0
  173. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bytes_io.o +0 -0
  174. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_closure.o +0 -0
  175. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_console.o +0 -0
  176. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_console_native.o +0 -0
  177. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_copying.o +0 -0
  178. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_cycle.o +0 -0
  179. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_dyn_handle.o +0 -0
  180. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_dyn_invoke.o +0 -0
  181. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_error.o +0 -0
  182. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_events_emitter.o +0 -0
  183. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_exception.o +0 -0
  184. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_grapheme.o +0 -0
  185. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_inspect.o +0 -0
  186. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_json.o +0 -0
  187. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_lib.o +0 -0
  188. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_library.o +0 -0
  189. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_map.o +0 -0
  190. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_node_builtin.o +0 -0
  191. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_number.o +0 -0
  192. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_object.o +0 -0
  193. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_path.o +0 -0
  194. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_regex.o +0 -0
  195. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_string.o +0 -0
  196. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_symbol.o +0 -0
  197. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_union.o +0 -0
  198. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_url.o +0 -0
  199. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_url_params.o +0 -0
  200. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_zlib.o +0 -0
  201. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  202. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_array.o +0 -0
  203. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_assert.o +0 -0
  204. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bigint.o +0 -0
  205. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bigint_assert.o +0 -0
  206. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bytes.o +0 -0
  207. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bytes_io.o +0 -0
  208. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_closure.o +0 -0
  209. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_console.o +0 -0
  210. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_console_native.o +0 -0
  211. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_copying.o +0 -0
  212. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_cycle.o +0 -0
  213. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_dyn_handle.o +0 -0
  214. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_dyn_invoke.o +0 -0
  215. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_error.o +0 -0
  216. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_events_emitter.o +0 -0
  217. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_exception.o +0 -0
  218. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_grapheme.o +0 -0
  219. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_inspect.o +0 -0
  220. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_json.o +0 -0
  221. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_lib.o +0 -0
  222. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_library.o +0 -0
  223. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_map.o +0 -0
  224. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_node_builtin.o +0 -0
  225. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_number.o +0 -0
  226. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_object.o +0 -0
  227. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_path.o +0 -0
  228. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_regex.o +0 -0
  229. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_string.o +0 -0
  230. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_symbol.o +0 -0
  231. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_union.o +0 -0
  232. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_url.o +0 -0
  233. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_url_params.o +0 -0
  234. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_zlib.o +0 -0
  235. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  236. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_array.o +0 -0
  237. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_assert.o +0 -0
  238. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bigint.o +0 -0
  239. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bigint_assert.o +0 -0
  240. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bytes.o +0 -0
  241. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bytes_io.o +0 -0
  242. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_closure.o +0 -0
  243. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_console.o +0 -0
  244. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_console_native.o +0 -0
  245. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_copying.o +0 -0
  246. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_cycle.o +0 -0
  247. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_dyn_handle.o +0 -0
  248. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_dyn_invoke.o +0 -0
  249. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_error.o +0 -0
  250. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_events_emitter.o +0 -0
  251. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_exception.o +0 -0
  252. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_grapheme.o +0 -0
  253. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_inspect.o +0 -0
  254. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_json.o +0 -0
  255. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_lib.o +0 -0
  256. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_library.o +0 -0
  257. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_map.o +0 -0
  258. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_node_builtin.o +0 -0
  259. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_number.o +0 -0
  260. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_object.o +0 -0
  261. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_path.o +0 -0
  262. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_regex.o +0 -0
  263. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_string.o +0 -0
  264. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_symbol.o +0 -0
  265. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_union.o +0 -0
  266. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_url.o +0 -0
  267. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_url_params.o +0 -0
  268. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_zlib.o +0 -0
  269. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  270. package/dist/lib/runtime-darwin-x64/artifacts/licenses/mbedtls.txt +553 -0
  271. package/dist/lib/runtime-darwin-x64/artifacts/licenses/quickjs-ng.txt +24 -0
  272. package/dist/lib/runtime-darwin-x64/artifacts/licenses/ryu.txt +23 -0
  273. package/dist/lib/runtime-darwin-x64/artifacts/licenses/scriptc-runtime.txt +202 -0
  274. package/dist/lib/runtime-darwin-x64/artifacts/licenses/unicode.txt +39 -0
  275. package/dist/lib/runtime-darwin-x64/artifacts/licenses/v8-number-radix.txt +61 -0
  276. package/dist/lib/runtime-darwin-x64/artifacts/licenses/zlib.txt +22 -0
  277. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_array.o +0 -0
  278. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_assert.o +0 -0
  279. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_async.o +0 -0
  280. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_async_dyn.o +0 -0
  281. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bigint.o +0 -0
  282. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bigint_assert.o +0 -0
  283. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bytes.o +0 -0
  284. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bytes_io.o +0 -0
  285. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_child.o +0 -0
  286. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_closure.o +0 -0
  287. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_console.o +0 -0
  288. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_console_native.o +0 -0
  289. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_copying.o +0 -0
  290. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_crypto_async.o +0 -0
  291. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_cycle.o +0 -0
  292. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_dc.o +0 -0
  293. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_dgram.o +0 -0
  294. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_dyn_handle.o +0 -0
  295. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_dyn_invoke.o +0 -0
  296. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_error.o +0 -0
  297. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_events.o +0 -0
  298. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_events_emitter.o +0 -0
  299. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_exception.o +0 -0
  300. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_fetch.o +0 -0
  301. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_ffi.o +0 -0
  302. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_ffi_queue.o +0 -0
  303. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_file_handle.o +0 -0
  304. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_grapheme.o +0 -0
  305. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_http.o +0 -0
  306. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_http2.o +0 -0
  307. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_inspect.o +0 -0
  308. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_json.o +0 -0
  309. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_lib.o +0 -0
  310. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_loop_epoll.o +0 -0
  311. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_loop_kqueue.o +0 -0
  312. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_loop_wsapoll.o +0 -0
  313. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_map.o +0 -0
  314. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_net.o +0 -0
  315. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_node_builtin.o +0 -0
  316. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_number.o +0 -0
  317. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_object.o +0 -0
  318. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_path.o +0 -0
  319. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_qs.o +0 -0
  320. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_readline.o +0 -0
  321. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_regex.o +0 -0
  322. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_stream.o +0 -0
  323. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_string.o +0 -0
  324. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_symbol.o +0 -0
  325. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_test.o +0 -0
  326. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_tls.o +0 -0
  327. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_tls_ca.o +0 -0
  328. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_union.o +0 -0
  329. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_url.o +0 -0
  330. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_url_params.o +0 -0
  331. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_util.o +0 -0
  332. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_watch.o +0 -0
  333. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_zlib.o +0 -0
  334. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_array.o +0 -0
  335. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_assert.o +0 -0
  336. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_async.o +0 -0
  337. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_async_dyn.o +0 -0
  338. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bigint.o +0 -0
  339. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bigint_assert.o +0 -0
  340. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bytes.o +0 -0
  341. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bytes_io.o +0 -0
  342. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_child.o +0 -0
  343. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_closure.o +0 -0
  344. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_console.o +0 -0
  345. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_console_native.o +0 -0
  346. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_copying.o +0 -0
  347. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_crypto_async.o +0 -0
  348. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_cycle.o +0 -0
  349. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_dc.o +0 -0
  350. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_dgram.o +0 -0
  351. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_dyn_handle.o +0 -0
  352. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_dyn_invoke.o +0 -0
  353. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_error.o +0 -0
  354. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_events.o +0 -0
  355. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_events_emitter.o +0 -0
  356. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_exception.o +0 -0
  357. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_fetch.o +0 -0
  358. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_ffi.o +0 -0
  359. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_ffi_queue.o +0 -0
  360. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_file_handle.o +0 -0
  361. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_grapheme.o +0 -0
  362. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_http.o +0 -0
  363. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_http2.o +0 -0
  364. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_inspect.o +0 -0
  365. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_inspect_island.o +0 -0
  366. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_island.o +0 -0
  367. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_json.o +0 -0
  368. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_lib.o +0 -0
  369. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_loop_epoll.o +0 -0
  370. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_loop_kqueue.o +0 -0
  371. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_loop_wsapoll.o +0 -0
  372. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_map.o +0 -0
  373. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_net.o +0 -0
  374. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_net_island.o +0 -0
  375. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_node_builtin.o +0 -0
  376. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_number.o +0 -0
  377. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_object.o +0 -0
  378. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_path.o +0 -0
  379. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_qs.o +0 -0
  380. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_readline.o +0 -0
  381. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_regex.o +0 -0
  382. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_stream.o +0 -0
  383. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_string.o +0 -0
  384. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_symbol.o +0 -0
  385. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_test.o +0 -0
  386. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_tls.o +0 -0
  387. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_tls_ca.o +0 -0
  388. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_union.o +0 -0
  389. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_url.o +0 -0
  390. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_url_params.o +0 -0
  391. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_util.o +0 -0
  392. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_watch.o +0 -0
  393. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_web.o +0 -0
  394. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_zlib.o +0 -0
  395. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_zlib_island.o +0 -0
  396. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
  397. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  398. package/dist/lib/runtime-darwin-x64/artifacts/vendor/libregexp/libscriptc-libregexp.a +0 -0
  399. package/dist/lib/runtime-darwin-x64/artifacts/vendor/mbedtls/libscriptc-mbedtls.a +0 -0
  400. package/dist/lib/runtime-darwin-x64/artifacts/vendor/quickjs/libscriptc-quickjs.a +0 -0
  401. package/dist/lib/runtime-darwin-x64/artifacts/vendor/zlib/libscriptc-zlib.a +0 -0
  402. package/dist/lib/runtime-darwin-x64/package.json +24 -0
  403. package/dist/lib/runtime-darwin-x64/runtime-pack.json +5762 -0
  404. package/dist/lib/runtime-sources/LICENSE +202 -0
  405. package/dist/lib/runtime-sources/package.json +22 -0
  406. package/dist/lib/runtime-sources/src/scr_array.c +1460 -0
  407. package/dist/lib/runtime-sources/src/scr_assert.c +1538 -0
  408. package/dist/lib/runtime-sources/src/scr_async.c +3945 -0
  409. package/dist/lib/runtime-sources/src/scr_async.test.c +134 -0
  410. package/dist/lib/runtime-sources/src/scr_async.test.ts +34 -0
  411. package/dist/lib/runtime-sources/src/scr_async_dyn.c +877 -0
  412. package/dist/lib/runtime-sources/src/scr_bigint.c +898 -0
  413. package/dist/lib/runtime-sources/src/scr_bigint_assert.c +22 -0
  414. package/dist/lib/runtime-sources/src/scr_bytes.c +2682 -0
  415. package/dist/lib/runtime-sources/src/scr_bytes_io.c +1324 -0
  416. package/dist/lib/runtime-sources/src/scr_child.c +6335 -0
  417. package/dist/lib/runtime-sources/src/scr_closure.c +213 -0
  418. package/dist/lib/runtime-sources/src/scr_console.c +259 -0
  419. package/dist/lib/runtime-sources/src/scr_console_native.c +95 -0
  420. package/dist/lib/runtime-sources/src/scr_copying.c +146 -0
  421. package/dist/lib/runtime-sources/src/scr_crypto_async.c +24 -0
  422. package/dist/lib/runtime-sources/src/scr_cycle.c +565 -0
  423. package/dist/lib/runtime-sources/src/scr_dc.c +814 -0
  424. package/dist/lib/runtime-sources/src/scr_dgram.c +1182 -0
  425. package/dist/lib/runtime-sources/src/scr_dyn_handle.c +96 -0
  426. package/dist/lib/runtime-sources/src/scr_dyn_invoke.c +1759 -0
  427. package/dist/lib/runtime-sources/src/scr_error.c +419 -0
  428. package/dist/lib/runtime-sources/src/scr_events.c +1222 -0
  429. package/dist/lib/runtime-sources/src/scr_events_emitter.c +842 -0
  430. package/dist/lib/runtime-sources/src/scr_exception.c +484 -0
  431. package/dist/lib/runtime-sources/src/scr_fetch.c +7479 -0
  432. package/dist/lib/runtime-sources/src/scr_fetch_curl.c +666 -0
  433. package/dist/lib/runtime-sources/src/scr_ffi.c +143 -0
  434. package/dist/lib/runtime-sources/src/scr_ffi_queue.c +379 -0
  435. package/dist/lib/runtime-sources/src/scr_file_handle.c +562 -0
  436. package/dist/lib/runtime-sources/src/scr_grapheme.c +203 -0
  437. package/dist/lib/runtime-sources/src/scr_grapheme_data.h +842 -0
  438. package/dist/lib/runtime-sources/src/scr_http.c +5811 -0
  439. package/dist/lib/runtime-sources/src/scr_http2.c +3243 -0
  440. package/dist/lib/runtime-sources/src/scr_inspect.c +923 -0
  441. package/dist/lib/runtime-sources/src/scr_inspect_island.c +51 -0
  442. package/dist/lib/runtime-sources/src/scr_island.c +10012 -0
  443. package/dist/lib/runtime-sources/src/scr_island_manifest.h +153 -0
  444. package/dist/lib/runtime-sources/src/scr_json.c +8986 -0
  445. package/dist/lib/runtime-sources/src/scr_json.test.c +182 -0
  446. package/dist/lib/runtime-sources/src/scr_json.test.ts +33 -0
  447. package/dist/lib/runtime-sources/src/scr_lib.c +6304 -0
  448. package/dist/lib/runtime-sources/src/scr_library.c +444 -0
  449. package/dist/lib/runtime-sources/src/scr_loop_epoll.c +241 -0
  450. package/dist/lib/runtime-sources/src/scr_loop_kqueue.c +121 -0
  451. package/dist/lib/runtime-sources/src/scr_loop_wsapoll.c +208 -0
  452. package/dist/lib/runtime-sources/src/scr_map.c +752 -0
  453. package/dist/lib/runtime-sources/src/scr_musl.c +438 -0
  454. package/dist/lib/runtime-sources/src/scr_net.c +3708 -0
  455. package/dist/lib/runtime-sources/src/scr_net_island.c +458 -0
  456. package/dist/lib/runtime-sources/src/scr_node_builtin.c +291 -0
  457. package/dist/lib/runtime-sources/src/scr_number.c +192 -0
  458. package/dist/lib/runtime-sources/src/scr_object.c +91 -0
  459. package/dist/lib/runtime-sources/src/scr_path.c +1281 -0
  460. package/dist/lib/runtime-sources/src/scr_platform.h +119 -0
  461. package/dist/lib/runtime-sources/src/scr_qs.c +496 -0
  462. package/dist/lib/runtime-sources/src/scr_readline.c +288 -0
  463. package/dist/lib/runtime-sources/src/scr_regex.c +1313 -0
  464. package/dist/lib/runtime-sources/src/scr_runtime.h +7364 -0
  465. package/dist/lib/runtime-sources/src/scr_stream.c +3346 -0
  466. package/dist/lib/runtime-sources/src/scr_string.c +1864 -0
  467. package/dist/lib/runtime-sources/src/scr_symbol.c +239 -0
  468. package/dist/lib/runtime-sources/src/scr_test.c +662 -0
  469. package/dist/lib/runtime-sources/src/scr_text_decoder_data.h +7389 -0
  470. package/dist/lib/runtime-sources/src/scr_text_decoder_labels.h +225 -0
  471. package/dist/lib/runtime-sources/src/scr_tls.c +1806 -0
  472. package/dist/lib/runtime-sources/src/scr_tls_ca.c +433 -0
  473. package/dist/lib/runtime-sources/src/scr_union.c +105 -0
  474. package/dist/lib/runtime-sources/src/scr_url.c +1400 -0
  475. package/dist/lib/runtime-sources/src/scr_url_internal.h +29 -0
  476. package/dist/lib/runtime-sources/src/scr_url_params.c +526 -0
  477. package/dist/lib/runtime-sources/src/scr_util.c +984 -0
  478. package/dist/lib/runtime-sources/src/scr_watch.c +568 -0
  479. package/dist/lib/runtime-sources/src/scr_web.c +1854 -0
  480. package/dist/lib/runtime-sources/src/scr_win.c +231 -0
  481. package/dist/lib/runtime-sources/src/scr_win_stats.h +23 -0
  482. package/dist/lib/runtime-sources/src/scr_zlib.c +358 -0
  483. package/dist/lib/runtime-sources/src/scr_zlib_island.c +15 -0
  484. package/dist/lib/runtime-sources/vendor/README.md +60 -0
  485. package/dist/lib/runtime-sources/vendor/curl/COPYRIGHT +534 -0
  486. package/dist/lib/runtime-sources/vendor/curl/include/curl/curl.h +3214 -0
  487. package/dist/lib/runtime-sources/vendor/curl/include/curl/curlver.h +79 -0
  488. package/dist/lib/runtime-sources/vendor/curl/include/curl/easy.h +125 -0
  489. package/dist/lib/runtime-sources/vendor/curl/include/curl/header.h +74 -0
  490. package/dist/lib/runtime-sources/vendor/curl/include/curl/mprintf.h +52 -0
  491. package/dist/lib/runtime-sources/vendor/curl/include/curl/multi.h +460 -0
  492. package/dist/lib/runtime-sources/vendor/curl/include/curl/options.h +70 -0
  493. package/dist/lib/runtime-sources/vendor/curl/include/curl/stdcheaders.h +35 -0
  494. package/dist/lib/runtime-sources/vendor/curl/include/curl/system.h +508 -0
  495. package/dist/lib/runtime-sources/vendor/curl/include/curl/typecheck-gcc.h +716 -0
  496. package/dist/lib/runtime-sources/vendor/curl/include/curl/urlapi.h +149 -0
  497. package/dist/lib/runtime-sources/vendor/curl/include/curl/websockets.h +84 -0
  498. package/dist/lib/runtime-sources/vendor/mbedtls/LICENSE +553 -0
  499. package/dist/lib/runtime-sources/vendor/mbedtls/include/CMakeLists.txt +22 -0
  500. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/aes.h +631 -0
  501. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/aria.h +343 -0
  502. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/asn1.h +642 -0
  503. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/asn1write.h +390 -0
  504. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/base64.h +82 -0
  505. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/bignum.h +1088 -0
  506. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/block_cipher.h +76 -0
  507. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/build_info.h +194 -0
  508. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/camellia.h +305 -0
  509. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ccm.h +526 -0
  510. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/chacha20.h +209 -0
  511. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/chachapoly.h +351 -0
  512. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/check_config.h +1149 -0
  513. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/cipher.h +1250 -0
  514. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/cmac.h +246 -0
  515. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/compat-2.x.h +46 -0
  516. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_legacy_crypto.h +578 -0
  517. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_legacy_from_psa.h +873 -0
  518. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_psa_from_legacy.h +359 -0
  519. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_psa_superset_legacy.h +145 -0
  520. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_ssl.h +91 -0
  521. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_x509.h +35 -0
  522. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_psa.h +61 -0
  523. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/constant_time.h +36 -0
  524. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ctr_drbg.h +596 -0
  525. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/debug.h +156 -0
  526. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/des.h +385 -0
  527. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/dhm.h +972 -0
  528. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ecdh.h +455 -0
  529. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ecdsa.h +674 -0
  530. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ecjpake.h +298 -0
  531. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ecp.h +1517 -0
  532. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/entropy.h +274 -0
  533. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/error.h +201 -0
  534. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/gcm.h +387 -0
  535. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/hkdf.h +124 -0
  536. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/hmac_drbg.h +434 -0
  537. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/lms.h +440 -0
  538. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/mbedtls_config.h +4446 -0
  539. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/md.h +526 -0
  540. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/md5.h +190 -0
  541. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/memory_buffer_alloc.h +142 -0
  542. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/net_sockets.h +299 -0
  543. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/nist_kw.h +166 -0
  544. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/oid.h +727 -0
  545. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/pem.h +160 -0
  546. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/pk.h +1303 -0
  547. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/pkcs12.h +186 -0
  548. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/pkcs5.h +198 -0
  549. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/pkcs7.h +252 -0
  550. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/platform.h +516 -0
  551. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/platform_time.h +79 -0
  552. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/platform_util.h +247 -0
  553. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/poly1305.h +168 -0
  554. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/private_access.h +20 -0
  555. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/psa_util.h +207 -0
  556. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ripemd160.h +136 -0
  557. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/rsa.h +1170 -0
  558. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/sha1.h +219 -0
  559. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/sha256.h +200 -0
  560. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/sha3.h +172 -0
  561. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/sha512.h +208 -0
  562. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ssl.h +5887 -0
  563. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ssl_cache.h +187 -0
  564. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ssl_ciphersuites.h +482 -0
  565. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ssl_cookie.h +106 -0
  566. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ssl_ticket.h +199 -0
  567. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/threading.h +167 -0
  568. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/timing.h +94 -0
  569. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/version.h +78 -0
  570. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/x509.h +500 -0
  571. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/x509_crl.h +184 -0
  572. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/x509_crt.h +1208 -0
  573. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/x509_csr.h +382 -0
  574. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/build_info.h +20 -0
  575. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto.h +4998 -0
  576. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_adjust_auto_enabled.h +31 -0
  577. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_adjust_config_dependencies.h +51 -0
  578. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_adjust_config_key_pair_types.h +101 -0
  579. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_adjust_config_synonyms.h +49 -0
  580. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_builtin_composites.h +214 -0
  581. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_builtin_key_derivation.h +118 -0
  582. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_builtin_primitives.h +114 -0
  583. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_compat.h +230 -0
  584. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_config.h +145 -0
  585. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_driver_common.h +44 -0
  586. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_driver_contexts_composites.h +151 -0
  587. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_driver_contexts_key_derivation.h +52 -0
  588. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_driver_contexts_primitives.h +105 -0
  589. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_extra.h +2145 -0
  590. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_legacy.h +88 -0
  591. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_platform.h +102 -0
  592. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_se_driver.h +1383 -0
  593. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_sizes.h +1319 -0
  594. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_struct.h +527 -0
  595. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_types.h +508 -0
  596. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_values.h +2782 -0
  597. package/dist/lib/runtime-sources/vendor/mbedtls/library/aes.c +2294 -0
  598. package/dist/lib/runtime-sources/vendor/mbedtls/library/aesce.c +624 -0
  599. package/dist/lib/runtime-sources/vendor/mbedtls/library/aesce.h +136 -0
  600. package/dist/lib/runtime-sources/vendor/mbedtls/library/aesni.c +846 -0
  601. package/dist/lib/runtime-sources/vendor/mbedtls/library/aesni.h +162 -0
  602. package/dist/lib/runtime-sources/vendor/mbedtls/library/alignment.h +704 -0
  603. package/dist/lib/runtime-sources/vendor/mbedtls/library/aria.c +969 -0
  604. package/dist/lib/runtime-sources/vendor/mbedtls/library/asn1parse.c +468 -0
  605. package/dist/lib/runtime-sources/vendor/mbedtls/library/asn1write.c +440 -0
  606. package/dist/lib/runtime-sources/vendor/mbedtls/library/base64.c +322 -0
  607. package/dist/lib/runtime-sources/vendor/mbedtls/library/base64_internal.h +45 -0
  608. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum.c +2583 -0
  609. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_core.c +1240 -0
  610. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_core.h +872 -0
  611. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_core_invasive.h +38 -0
  612. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_internal.h +122 -0
  613. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_mod.c +394 -0
  614. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_mod.h +452 -0
  615. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_mod_raw.c +276 -0
  616. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_mod_raw.h +416 -0
  617. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_mod_raw_invasive.h +34 -0
  618. package/dist/lib/runtime-sources/vendor/mbedtls/library/block_cipher.c +207 -0
  619. package/dist/lib/runtime-sources/vendor/mbedtls/library/block_cipher_internal.h +99 -0
  620. package/dist/lib/runtime-sources/vendor/mbedtls/library/bn_mul.h +1094 -0
  621. package/dist/lib/runtime-sources/vendor/mbedtls/library/camellia.c +1058 -0
  622. package/dist/lib/runtime-sources/vendor/mbedtls/library/ccm.c +777 -0
  623. package/dist/lib/runtime-sources/vendor/mbedtls/library/chacha20.c +563 -0
  624. package/dist/lib/runtime-sources/vendor/mbedtls/library/chacha20_internal.h +23 -0
  625. package/dist/lib/runtime-sources/vendor/mbedtls/library/chachapoly.c +487 -0
  626. package/dist/lib/runtime-sources/vendor/mbedtls/library/check_crypto_config.h +136 -0
  627. package/dist/lib/runtime-sources/vendor/mbedtls/library/cipher.c +1712 -0
  628. package/dist/lib/runtime-sources/vendor/mbedtls/library/cipher_invasive.h +28 -0
  629. package/dist/lib/runtime-sources/vendor/mbedtls/library/cipher_wrap.c +2482 -0
  630. package/dist/lib/runtime-sources/vendor/mbedtls/library/cipher_wrap.h +178 -0
  631. package/dist/lib/runtime-sources/vendor/mbedtls/library/cmac.c +1067 -0
  632. package/dist/lib/runtime-sources/vendor/mbedtls/library/common.h +487 -0
  633. package/dist/lib/runtime-sources/vendor/mbedtls/library/constant_time.c +247 -0
  634. package/dist/lib/runtime-sources/vendor/mbedtls/library/constant_time_impl.h +541 -0
  635. package/dist/lib/runtime-sources/vendor/mbedtls/library/constant_time_internal.h +579 -0
  636. package/dist/lib/runtime-sources/vendor/mbedtls/library/ctr.h +35 -0
  637. package/dist/lib/runtime-sources/vendor/mbedtls/library/ctr_drbg.c +1016 -0
  638. package/dist/lib/runtime-sources/vendor/mbedtls/library/debug.c +475 -0
  639. package/dist/lib/runtime-sources/vendor/mbedtls/library/debug_internal.h +185 -0
  640. package/dist/lib/runtime-sources/vendor/mbedtls/library/des.c +1042 -0
  641. package/dist/lib/runtime-sources/vendor/mbedtls/library/dhm.c +700 -0
  642. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecdh.c +696 -0
  643. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecdsa.c +858 -0
  644. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecjpake.c +1216 -0
  645. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecp.c +3674 -0
  646. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecp_curves.c +6125 -0
  647. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecp_curves_new.c +9 -0
  648. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecp_internal_alt.h +287 -0
  649. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecp_invasive.h +305 -0
  650. package/dist/lib/runtime-sources/vendor/mbedtls/library/entropy.c +680 -0
  651. package/dist/lib/runtime-sources/vendor/mbedtls/library/entropy_poll.c +233 -0
  652. package/dist/lib/runtime-sources/vendor/mbedtls/library/entropy_poll.h +64 -0
  653. package/dist/lib/runtime-sources/vendor/mbedtls/library/error.c +878 -0
  654. package/dist/lib/runtime-sources/vendor/mbedtls/library/gcm.c +1330 -0
  655. package/dist/lib/runtime-sources/vendor/mbedtls/library/hkdf.c +161 -0
  656. package/dist/lib/runtime-sources/vendor/mbedtls/library/hmac_drbg.c +633 -0
  657. package/dist/lib/runtime-sources/vendor/mbedtls/library/lmots.c +789 -0
  658. package/dist/lib/runtime-sources/vendor/mbedtls/library/lmots.h +288 -0
  659. package/dist/lib/runtime-sources/vendor/mbedtls/library/lms.c +778 -0
  660. package/dist/lib/runtime-sources/vendor/mbedtls/library/md.c +1108 -0
  661. package/dist/lib/runtime-sources/vendor/mbedtls/library/md5.c +426 -0
  662. package/dist/lib/runtime-sources/vendor/mbedtls/library/md_psa.h +26 -0
  663. package/dist/lib/runtime-sources/vendor/mbedtls/library/md_wrap.h +46 -0
  664. package/dist/lib/runtime-sources/vendor/mbedtls/library/memory_buffer_alloc.c +751 -0
  665. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_common.h +181 -0
  666. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_error.h +89 -0
  667. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_reader.c +538 -0
  668. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_reader.h +366 -0
  669. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_trace.c +112 -0
  670. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_trace.h +154 -0
  671. package/dist/lib/runtime-sources/vendor/mbedtls/library/net_sockets.c +694 -0
  672. package/dist/lib/runtime-sources/vendor/mbedtls/library/nist_kw.c +729 -0
  673. package/dist/lib/runtime-sources/vendor/mbedtls/library/oid.c +1166 -0
  674. package/dist/lib/runtime-sources/vendor/mbedtls/library/padlock.c +157 -0
  675. package/dist/lib/runtime-sources/vendor/mbedtls/library/padlock.h +111 -0
  676. package/dist/lib/runtime-sources/vendor/mbedtls/library/pem.c +554 -0
  677. package/dist/lib/runtime-sources/vendor/mbedtls/library/pk.c +1602 -0
  678. package/dist/lib/runtime-sources/vendor/mbedtls/library/pk_ecc.c +261 -0
  679. package/dist/lib/runtime-sources/vendor/mbedtls/library/pk_internal.h +241 -0
  680. package/dist/lib/runtime-sources/vendor/mbedtls/library/pk_wrap.c +1618 -0
  681. package/dist/lib/runtime-sources/vendor/mbedtls/library/pk_wrap.h +138 -0
  682. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkcs12.c +437 -0
  683. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkcs5.c +500 -0
  684. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkcs7.c +787 -0
  685. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkparse.c +1392 -0
  686. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkwrite.c +631 -0
  687. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkwrite.h +121 -0
  688. package/dist/lib/runtime-sources/vendor/mbedtls/library/platform.c +402 -0
  689. package/dist/lib/runtime-sources/vendor/mbedtls/library/platform_util.c +258 -0
  690. package/dist/lib/runtime-sources/vendor/mbedtls/library/poly1305.c +492 -0
  691. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto.c +9532 -0
  692. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_aead.c +646 -0
  693. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_aead.h +499 -0
  694. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_cipher.c +747 -0
  695. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_cipher.h +316 -0
  696. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_client.c +22 -0
  697. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_core.h +983 -0
  698. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_core_common.h +52 -0
  699. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_driver_wrappers.h +2896 -0
  700. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.c +256 -0
  701. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.h +31 -0
  702. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_ecp.c +594 -0
  703. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_ecp.h +267 -0
  704. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_ffdh.c +361 -0
  705. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_ffdh.h +131 -0
  706. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_hash.c +470 -0
  707. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_hash.h +211 -0
  708. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_invasive.h +92 -0
  709. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_its.h +131 -0
  710. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_mac.c +505 -0
  711. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_mac.h +264 -0
  712. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_pake.c +571 -0
  713. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_pake.h +159 -0
  714. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_random.c +181 -0
  715. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_random.h +72 -0
  716. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_random_impl.h +200 -0
  717. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_rsa.c +714 -0
  718. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_rsa.h +321 -0
  719. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_se.c +373 -0
  720. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_se.h +192 -0
  721. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_slot_management.c +1137 -0
  722. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_slot_management.h +344 -0
  723. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_storage.c +481 -0
  724. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_storage.h +392 -0
  725. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_its_file.c +254 -0
  726. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_util.c +614 -0
  727. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_util_internal.h +100 -0
  728. package/dist/lib/runtime-sources/vendor/mbedtls/library/ripemd160.c +490 -0
  729. package/dist/lib/runtime-sources/vendor/mbedtls/library/rsa.c +3121 -0
  730. package/dist/lib/runtime-sources/vendor/mbedtls/library/rsa_alt_helpers.c +455 -0
  731. package/dist/lib/runtime-sources/vendor/mbedtls/library/rsa_alt_helpers.h +209 -0
  732. package/dist/lib/runtime-sources/vendor/mbedtls/library/rsa_internal.h +188 -0
  733. package/dist/lib/runtime-sources/vendor/mbedtls/library/sha1.c +480 -0
  734. package/dist/lib/runtime-sources/vendor/mbedtls/library/sha256.c +983 -0
  735. package/dist/lib/runtime-sources/vendor/mbedtls/library/sha3.c +721 -0
  736. package/dist/lib/runtime-sources/vendor/mbedtls/library/sha512.c +1115 -0
  737. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_cache.c +410 -0
  738. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_ciphersuites.c +2050 -0
  739. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_ciphersuites_internal.h +154 -0
  740. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_client.c +1023 -0
  741. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_client.h +22 -0
  742. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_cookie.c +384 -0
  743. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_debug_helpers.h +85 -0
  744. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_debug_helpers_generated.c +251 -0
  745. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_misc.h +3198 -0
  746. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_msg.c +6619 -0
  747. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_ticket.c +556 -0
  748. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls.c +10234 -0
  749. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls12_client.c +3688 -0
  750. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls12_server.c +4311 -0
  751. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_client.c +3208 -0
  752. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_generic.c +1793 -0
  753. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_invasive.h +23 -0
  754. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_keys.c +1918 -0
  755. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_keys.h +668 -0
  756. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_server.c +3624 -0
  757. package/dist/lib/runtime-sources/vendor/mbedtls/library/threading.c +193 -0
  758. package/dist/lib/runtime-sources/vendor/mbedtls/library/threading_internal.h +28 -0
  759. package/dist/lib/runtime-sources/vendor/mbedtls/library/timing.c +152 -0
  760. package/dist/lib/runtime-sources/vendor/mbedtls/library/version.c +32 -0
  761. package/dist/lib/runtime-sources/vendor/mbedtls/library/version_features.c +856 -0
  762. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509.c +1776 -0
  763. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509_create.c +570 -0
  764. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509_crl.c +708 -0
  765. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509_crt.c +3311 -0
  766. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509_csr.c +648 -0
  767. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509_internal.h +101 -0
  768. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509write.c +174 -0
  769. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509write_crt.c +688 -0
  770. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509write_csr.c +336 -0
  771. package/dist/lib/runtime-sources/vendor/quickjs-ng/CMakeLists.txt +566 -0
  772. package/dist/lib/runtime-sources/vendor/quickjs-ng/LICENSE +24 -0
  773. package/dist/lib/runtime-sources/vendor/quickjs-ng/README.md +24 -0
  774. package/dist/lib/runtime-sources/vendor/quickjs-ng/api-test.c +1195 -0
  775. package/dist/lib/runtime-sources/vendor/quickjs-ng/builtin-array-fromasync.h +119 -0
  776. package/dist/lib/runtime-sources/vendor/quickjs-ng/builtin-iterator-zip-keyed.h +332 -0
  777. package/dist/lib/runtime-sources/vendor/quickjs-ng/builtin-iterator-zip.h +337 -0
  778. package/dist/lib/runtime-sources/vendor/quickjs-ng/cutils.h +1998 -0
  779. package/dist/lib/runtime-sources/vendor/quickjs-ng/dtoa.c +1619 -0
  780. package/dist/lib/runtime-sources/vendor/quickjs-ng/dtoa.h +87 -0
  781. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/function_source.c +81 -0
  782. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/hello.c +53 -0
  783. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/hello_module.c +106 -0
  784. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/repl.c +3036 -0
  785. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/standalone.c +323 -0
  786. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/test_fib.c +81 -0
  787. package/dist/lib/runtime-sources/vendor/quickjs-ng/libregexp-opcode.h +73 -0
  788. package/dist/lib/runtime-sources/vendor/quickjs-ng/libregexp.c +3474 -0
  789. package/dist/lib/runtime-sources/vendor/quickjs-ng/libregexp.h +101 -0
  790. package/dist/lib/runtime-sources/vendor/quickjs-ng/libunicode-table.h +5173 -0
  791. package/dist/lib/runtime-sources/vendor/quickjs-ng/libunicode.c +2069 -0
  792. package/dist/lib/runtime-sources/vendor/quickjs-ng/libunicode.h +172 -0
  793. package/dist/lib/runtime-sources/vendor/quickjs-ng/list.h +107 -0
  794. package/dist/lib/runtime-sources/vendor/quickjs-ng/lre-test.c +52 -0
  795. package/dist/lib/runtime-sources/vendor/quickjs-ng/qjs.c +762 -0
  796. package/dist/lib/runtime-sources/vendor/quickjs-ng/qjsc.c +673 -0
  797. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs-atom.h +280 -0
  798. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs-c-atomics.h +54 -0
  799. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs-libc.c +5037 -0
  800. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs-libc.h +87 -0
  801. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs-opcode.h +377 -0
  802. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs.c +64041 -0
  803. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs.h +1447 -0
  804. package/dist/lib/runtime-sources/vendor/quickjs-ng/run-test262.c +2374 -0
  805. package/dist/lib/runtime-sources/vendor/quickjs-ng/unicode_gen.c +3121 -0
  806. package/dist/lib/runtime-sources/vendor/quickjs-ng/unicode_gen_def.h +310 -0
  807. package/dist/lib/runtime-sources/vendor/ryu/LICENSE-Boost +23 -0
  808. package/dist/lib/runtime-sources/vendor/ryu/common.h +114 -0
  809. package/dist/lib/runtime-sources/vendor/ryu/d2s.c +509 -0
  810. package/dist/lib/runtime-sources/vendor/ryu/d2s_full_table.h +367 -0
  811. package/dist/lib/runtime-sources/vendor/ryu/d2s_intrinsics.h +357 -0
  812. package/dist/lib/runtime-sources/vendor/ryu/d2s_small_table.h +186 -0
  813. package/dist/lib/runtime-sources/vendor/ryu/digit_table.h +35 -0
  814. package/dist/lib/runtime-sources/vendor/ryu/ryu.h +46 -0
  815. package/dist/lib/runtime-sources/vendor/unicode/LICENSE +39 -0
  816. package/dist/lib/runtime-sources/vendor/v8-number-radix/LICENSE +61 -0
  817. package/dist/lib/runtime-sources/vendor/zlib/LICENSE +22 -0
  818. package/dist/lib/runtime-sources/vendor/zlib/adler32.c +164 -0
  819. package/dist/lib/runtime-sources/vendor/zlib/compress.c +75 -0
  820. package/dist/lib/runtime-sources/vendor/zlib/crc32.c +1049 -0
  821. package/dist/lib/runtime-sources/vendor/zlib/crc32.h +9446 -0
  822. package/dist/lib/runtime-sources/vendor/zlib/deflate.c +2139 -0
  823. package/dist/lib/runtime-sources/vendor/zlib/deflate.h +377 -0
  824. package/dist/lib/runtime-sources/vendor/zlib/gzclose.c +23 -0
  825. package/dist/lib/runtime-sources/vendor/zlib/gzguts.h +214 -0
  826. package/dist/lib/runtime-sources/vendor/zlib/gzlib.c +582 -0
  827. package/dist/lib/runtime-sources/vendor/zlib/gzread.c +602 -0
  828. package/dist/lib/runtime-sources/vendor/zlib/gzwrite.c +631 -0
  829. package/dist/lib/runtime-sources/vendor/zlib/infback.c +628 -0
  830. package/dist/lib/runtime-sources/vendor/zlib/inffast.c +320 -0
  831. package/dist/lib/runtime-sources/vendor/zlib/inffast.h +11 -0
  832. package/dist/lib/runtime-sources/vendor/zlib/inffixed.h +94 -0
  833. package/dist/lib/runtime-sources/vendor/zlib/inflate.c +1526 -0
  834. package/dist/lib/runtime-sources/vendor/zlib/inflate.h +126 -0
  835. package/dist/lib/runtime-sources/vendor/zlib/inftrees.c +299 -0
  836. package/dist/lib/runtime-sources/vendor/zlib/inftrees.h +62 -0
  837. package/dist/lib/runtime-sources/vendor/zlib/trees.c +1117 -0
  838. package/dist/lib/runtime-sources/vendor/zlib/trees.h +128 -0
  839. package/dist/lib/runtime-sources/vendor/zlib/uncompr.c +85 -0
  840. package/dist/lib/runtime-sources/vendor/zlib/zconf.h +543 -0
  841. package/dist/lib/runtime-sources/vendor/zlib/zlib.h +1938 -0
  842. package/dist/lib/runtime-sources/vendor/zlib/zutil.c +299 -0
  843. package/dist/lib/runtime-sources/vendor/zlib/zutil.h +254 -0
  844. package/dist/lib/scriptc-comptime +0 -0
  845. package/dist/lib/typescript/LICENSE +55 -0
  846. package/dist/lib/typescript/NOTICE.txt +436 -0
  847. package/dist/lib/typescript/lib/lib.d.ts +20 -0
  848. package/dist/lib/typescript/lib/lib.decorators.d.ts +382 -0
  849. package/dist/lib/typescript/lib/lib.decorators.legacy.d.ts +20 -0
  850. package/dist/lib/typescript/lib/lib.dom.asynciterable.d.ts +18 -0
  851. package/dist/lib/typescript/lib/lib.dom.d.ts +45125 -0
  852. package/dist/lib/typescript/lib/lib.dom.iterable.d.ts +18 -0
  853. package/dist/lib/typescript/lib/lib.es2015.collection.d.ts +159 -0
  854. package/dist/lib/typescript/lib/lib.es2015.core.d.ts +595 -0
  855. package/dist/lib/typescript/lib/lib.es2015.d.ts +26 -0
  856. package/dist/lib/typescript/lib/lib.es2015.generator.d.ts +75 -0
  857. package/dist/lib/typescript/lib/lib.es2015.iterable.d.ts +603 -0
  858. package/dist/lib/typescript/lib/lib.es2015.promise.d.ts +79 -0
  859. package/dist/lib/typescript/lib/lib.es2015.proxy.d.ts +126 -0
  860. package/dist/lib/typescript/lib/lib.es2015.reflect.d.ts +142 -0
  861. package/dist/lib/typescript/lib/lib.es2015.symbol.d.ts +44 -0
  862. package/dist/lib/typescript/lib/lib.es2015.symbol.wellknown.d.ts +324 -0
  863. package/dist/lib/typescript/lib/lib.es2016.array.include.d.ts +114 -0
  864. package/dist/lib/typescript/lib/lib.es2016.d.ts +19 -0
  865. package/dist/lib/typescript/lib/lib.es2016.full.d.ts +21 -0
  866. package/dist/lib/typescript/lib/lib.es2016.intl.d.ts +29 -0
  867. package/dist/lib/typescript/lib/lib.es2017.arraybuffer.d.ts +19 -0
  868. package/dist/lib/typescript/lib/lib.es2017.d.ts +24 -0
  869. package/dist/lib/typescript/lib/lib.es2017.date.d.ts +29 -0
  870. package/dist/lib/typescript/lib/lib.es2017.full.d.ts +21 -0
  871. package/dist/lib/typescript/lib/lib.es2017.intl.d.ts +42 -0
  872. package/dist/lib/typescript/lib/lib.es2017.object.d.ts +47 -0
  873. package/dist/lib/typescript/lib/lib.es2017.sharedmemory.d.ts +133 -0
  874. package/dist/lib/typescript/lib/lib.es2017.string.d.ts +47 -0
  875. package/dist/lib/typescript/lib/lib.es2017.typedarrays.d.ts +51 -0
  876. package/dist/lib/typescript/lib/lib.es2018.asyncgenerator.d.ts +75 -0
  877. package/dist/lib/typescript/lib/lib.es2018.asynciterable.d.ts +51 -0
  878. package/dist/lib/typescript/lib/lib.es2018.d.ts +22 -0
  879. package/dist/lib/typescript/lib/lib.es2018.full.d.ts +22 -0
  880. package/dist/lib/typescript/lib/lib.es2018.intl.d.ts +81 -0
  881. package/dist/lib/typescript/lib/lib.es2018.promise.d.ts +28 -0
  882. package/dist/lib/typescript/lib/lib.es2018.regexp.d.ts +35 -0
  883. package/dist/lib/typescript/lib/lib.es2019.array.d.ts +77 -0
  884. package/dist/lib/typescript/lib/lib.es2019.d.ts +22 -0
  885. package/dist/lib/typescript/lib/lib.es2019.full.d.ts +22 -0
  886. package/dist/lib/typescript/lib/lib.es2019.intl.d.ts +21 -0
  887. package/dist/lib/typescript/lib/lib.es2019.object.d.ts +31 -0
  888. package/dist/lib/typescript/lib/lib.es2019.string.d.ts +35 -0
  889. package/dist/lib/typescript/lib/lib.es2019.symbol.d.ts +22 -0
  890. package/dist/lib/typescript/lib/lib.es2020.bigint.d.ts +763 -0
  891. package/dist/lib/typescript/lib/lib.es2020.d.ts +25 -0
  892. package/dist/lib/typescript/lib/lib.es2020.date.d.ts +40 -0
  893. package/dist/lib/typescript/lib/lib.es2020.full.d.ts +22 -0
  894. package/dist/lib/typescript/lib/lib.es2020.intl.d.ts +472 -0
  895. package/dist/lib/typescript/lib/lib.es2020.number.d.ts +26 -0
  896. package/dist/lib/typescript/lib/lib.es2020.promise.d.ts +45 -0
  897. package/dist/lib/typescript/lib/lib.es2020.sharedmemory.d.ts +97 -0
  898. package/dist/lib/typescript/lib/lib.es2020.string.d.ts +42 -0
  899. package/dist/lib/typescript/lib/lib.es2020.symbol.wellknown.d.ts +39 -0
  900. package/dist/lib/typescript/lib/lib.es2021.d.ts +21 -0
  901. package/dist/lib/typescript/lib/lib.es2021.full.d.ts +22 -0
  902. package/dist/lib/typescript/lib/lib.es2021.intl.d.ts +164 -0
  903. package/dist/lib/typescript/lib/lib.es2021.promise.d.ts +46 -0
  904. package/dist/lib/typescript/lib/lib.es2021.string.d.ts +31 -0
  905. package/dist/lib/typescript/lib/lib.es2021.weakref.d.ts +76 -0
  906. package/dist/lib/typescript/lib/lib.es2022.array.d.ts +119 -0
  907. package/dist/lib/typescript/lib/lib.es2022.d.ts +23 -0
  908. package/dist/lib/typescript/lib/lib.es2022.error.d.ts +73 -0
  909. package/dist/lib/typescript/lib/lib.es2022.full.d.ts +22 -0
  910. package/dist/lib/typescript/lib/lib.es2022.intl.d.ts +143 -0
  911. package/dist/lib/typescript/lib/lib.es2022.object.d.ts +24 -0
  912. package/dist/lib/typescript/lib/lib.es2022.regexp.d.ts +37 -0
  913. package/dist/lib/typescript/lib/lib.es2022.string.d.ts +23 -0
  914. package/dist/lib/typescript/lib/lib.es2023.array.d.ts +922 -0
  915. package/dist/lib/typescript/lib/lib.es2023.collection.d.ts +19 -0
  916. package/dist/lib/typescript/lib/lib.es2023.d.ts +20 -0
  917. package/dist/lib/typescript/lib/lib.es2023.full.d.ts +22 -0
  918. package/dist/lib/typescript/lib/lib.es2023.intl.d.ts +62 -0
  919. package/dist/lib/typescript/lib/lib.es2024.arraybuffer.d.ts +63 -0
  920. package/dist/lib/typescript/lib/lib.es2024.collection.d.ts +27 -0
  921. package/dist/lib/typescript/lib/lib.es2024.d.ts +24 -0
  922. package/dist/lib/typescript/lib/lib.es2024.full.d.ts +22 -0
  923. package/dist/lib/typescript/lib/lib.es2024.object.d.ts +27 -0
  924. package/dist/lib/typescript/lib/lib.es2024.promise.d.ts +33 -0
  925. package/dist/lib/typescript/lib/lib.es2024.regexp.d.ts +23 -0
  926. package/dist/lib/typescript/lib/lib.es2024.sharedmemory.d.ts +66 -0
  927. package/dist/lib/typescript/lib/lib.es2024.string.d.ts +27 -0
  928. package/dist/lib/typescript/lib/lib.es2025.collection.d.ts +94 -0
  929. package/dist/lib/typescript/lib/lib.es2025.d.ts +23 -0
  930. package/dist/lib/typescript/lib/lib.es2025.float16.d.ts +443 -0
  931. package/dist/lib/typescript/lib/lib.es2025.full.d.ts +22 -0
  932. package/dist/lib/typescript/lib/lib.es2025.intl.d.ts +200 -0
  933. package/dist/lib/typescript/lib/lib.es2025.iterator.d.ts +146 -0
  934. package/dist/lib/typescript/lib/lib.es2025.promise.d.ts +32 -0
  935. package/dist/lib/typescript/lib/lib.es2025.regexp.d.ts +30 -0
  936. package/dist/lib/typescript/lib/lib.es5.d.ts +4599 -0
  937. package/dist/lib/typescript/lib/lib.es6.d.ts +21 -0
  938. package/dist/lib/typescript/lib/lib.esnext.array.d.ts +33 -0
  939. package/dist/lib/typescript/lib/lib.esnext.collection.d.ts +47 -0
  940. package/dist/lib/typescript/lib/lib.esnext.d.ts +27 -0
  941. package/dist/lib/typescript/lib/lib.esnext.date.d.ts +21 -0
  942. package/dist/lib/typescript/lib/lib.esnext.decorators.d.ts +26 -0
  943. package/dist/lib/typescript/lib/lib.esnext.disposable.d.ts +191 -0
  944. package/dist/lib/typescript/lib/lib.esnext.error.d.ts +22 -0
  945. package/dist/lib/typescript/lib/lib.esnext.full.d.ts +22 -0
  946. package/dist/lib/typescript/lib/lib.esnext.intl.d.ts +107 -0
  947. package/dist/lib/typescript/lib/lib.esnext.sharedmemory.d.ts +23 -0
  948. package/dist/lib/typescript/lib/lib.esnext.temporal.d.ts +485 -0
  949. package/dist/lib/typescript/lib/lib.esnext.typedarrays.d.ts +90 -0
  950. package/dist/lib/typescript/lib/lib.scripthost.d.ts +320 -0
  951. package/dist/lib/typescript/lib/lib.webworker.asynciterable.d.ts +18 -0
  952. package/dist/lib/typescript/lib/lib.webworker.d.ts +15606 -0
  953. package/dist/lib/typescript/lib/lib.webworker.importscripts.d.ts +21 -0
  954. package/dist/lib/typescript/lib/lib.webworker.iterable.d.ts +18 -0
  955. package/dist/lib/typescript/lib/tsc +0 -0
  956. package/dist/lib/typescript/package.json +45 -0
  957. package/dist/lib/wasi/cli/wasi-paths.js +41 -0
  958. package/dist/lib/wasi/cli/wasi-runner.js +28 -0
  959. package/dist/lib/wasi/package.json +1 -0
  960. package/dist/lib/wasi/wasi-paths.js +25 -0
  961. package/package.json +22 -6
  962. package/README.md +0 -3
  963. package/index.js +0 -2
@@ -0,0 +1,3945 @@
1
+ /* Async runtime: stackful fibers, promises, and a dependency-free event
2
+ * loop (microtask queue + timer min-heap).
3
+ *
4
+ * Model (see docs/ir.md):
5
+ * - An async function's body is ordinary compiled C, run on its own fiber
6
+ * (dedicated ucontext stack). Calling it runs the body EAGERLY until
7
+ * the first suspension (JS's synchronous-prefix rule), then control
8
+ * returns to the spawner with a +1 promise.
9
+ * - `await` on a pending promise parks the fiber on the promise's waiter
10
+ * list and switches back to whoever resumed it. Fulfillment moves waiters
11
+ * to the microtask queue (microtasks run before timers, like Node).
12
+ * - Each fiber carries its own exception cell (scr_exc_swap_cell) so a
13
+ * pending exception can't leak across concurrent execution contexts. A
14
+ * throw escaping an async body rejects its promise; awaiting a rejected
15
+ * promise re-throws into the awaiter.
16
+ * - Loop exhaustion with still-suspended fibers exits normally (Node's
17
+ * behavior); those stacks are deliberately not unwound, and the RC audit
18
+ * downgrades to a note in that case.
19
+ */
20
+ #define _XOPEN_SOURCE 700
21
+ /* Anonymous mappings alongside the XSI ucontext API on Darwin and glibc. */
22
+ #ifndef _DARWIN_C_SOURCE
23
+ #define _DARWIN_C_SOURCE 1
24
+ #endif
25
+ #ifndef _DEFAULT_SOURCE
26
+ #define _DEFAULT_SOURCE 1
27
+ #endif
28
+ #include "scr_runtime.h"
29
+
30
+ #include <errno.h>
31
+ #include <fcntl.h>
32
+ #include <stdio.h>
33
+ #include <stdlib.h>
34
+ #include <string.h>
35
+ #include <time.h>
36
+ #ifdef _WIN32
37
+ /* Windows arm: fibers come from the Win32 Fibers API (CreateFiberEx /
38
+ * SwitchToFiber — the direct ucontext analog: cooperatively scheduled,
39
+ * same thread, own stack); the idle sleep is nanosleep (mingw-w64 ships
40
+ * it, over Sleep). poll(2) has no Windows arm — see the sleep seam in
41
+ * scr_loop_run: the poller-backed units (net/dgram/watch) are not built
42
+ * for win32 targets (native-toolchain.ts gates them), so their fds never appear; the
43
+ * events unit DOES cross-compile (scr_events.c's win32 arm) and is
44
+ * served by a capped nanosleep — dispatch at the next turn's top, the
45
+ * cap bounding signal/stdin latency instead of a pollable wake fd. */
46
+ #include <windows.h>
47
+ #elif defined(__wasi__)
48
+ #include <poll.h>
49
+ #else
50
+ #include <poll.h>
51
+ #include <pthread.h>
52
+ #include <signal.h>
53
+ #include <sys/mman.h>
54
+ #include <ucontext.h>
55
+ #include <unistd.h>
56
+ #endif
57
+
58
+ #ifdef __wasi__
59
+ /* WASI Preview 1 has no process-spawn capability. The child unit is not
60
+ * linked for this target, but the generic loop keeps its quiescence hooks;
61
+ * their empty implementation makes the absence explicit at link time
62
+ * without weakening async/timer support. */
63
+ bool scr_children_pending(void) { return false; }
64
+ bool scr_children_ready(void) { return false; }
65
+ bool scr_children_reffed_pending(void) { return false; }
66
+ bool scr_children_failed_pending(void) { return false; }
67
+ void scr_children_poll(void) {}
68
+ int scr_children_wake_fd(void) { return -1; }
69
+ bool scr_children_wait(double max_wait_ms) {
70
+ (void)max_wait_ms;
71
+ return false;
72
+ }
73
+ void scr_children_teardown(void) {}
74
+ #endif
75
+
76
+ #if defined(__has_feature)
77
+ #if __has_feature(address_sanitizer)
78
+ #define SCR_ASAN_FIBERS 1
79
+ void __sanitizer_start_switch_fiber(void **fake_stack_save, const void *bottom, size_t size);
80
+ void __sanitizer_finish_switch_fiber(void *fake_stack_save, const void **bottom_old, size_t *size_old);
81
+ #endif
82
+ #endif
83
+
84
+ /* ASan inflates stack frames severalfold (unoptimized locals + redzones),
85
+ * so the sanitized lane gets proportionally bigger fiber stacks — same
86
+ * headroom DISCIPLINE, instrumented scale. Keep the island's stack budget
87
+ * (scr_island.c) at half of whichever size is active. 8MB under ASan is
88
+ * the measured need: an engine call costs 64–96KB there, and a real
89
+ * embedded graph entered FROM A FIBER (a commander action awaiting
90
+ * generateText — zod parses inside promise chains) nests dozens of engine
91
+ * frames; native POSIX stacks are mapped and committed lazily, so idle
92
+ * fibers pay address space, not RSS. */
93
+ #ifdef SCR_ASAN_FIBERS
94
+ #define SCR_FIBER_STACK (8 * 1024 * 1024)
95
+ #else
96
+ #define SCR_FIBER_STACK (256 * 1024)
97
+ #endif
98
+
99
+ #if !defined(_WIN32) && !defined(__wasi__)
100
+ /* Keep stacks out of malloc's size classes. Reuse a bounded number during
101
+ * a burst of promise/generator work, then unmap the spares before the loop
102
+ * sleeps. This avoids both heap fragmentation and per-call mmap overhead.
103
+ * The sanitizer lane unmaps every finished stack immediately. */
104
+ #ifndef SCR_ASAN_FIBERS
105
+ #define SCR_FIBER_SPARES 4
106
+ static SCR_TL void *scr_fiber_spares[SCR_FIBER_SPARES];
107
+ static SCR_TL size_t scr_fiber_nspares;
108
+ static SCR_TL bool scr_fiber_cleanup_registered;
109
+ #endif
110
+
111
+ static void scr_fiber_stacks_clear(void) {
112
+ #ifndef SCR_ASAN_FIBERS
113
+ while (scr_fiber_nspares > 0) {
114
+ (void)munmap(scr_fiber_spares[--scr_fiber_nspares], SCR_FIBER_STACK);
115
+ scr_fiber_spares[scr_fiber_nspares] = NULL;
116
+ }
117
+ #endif
118
+ }
119
+
120
+ static void *scr_fiber_stack_new(void) {
121
+ #ifndef SCR_ASAN_FIBERS
122
+ if (scr_fiber_nspares > 0) {
123
+ void *stack = scr_fiber_spares[--scr_fiber_nspares];
124
+ scr_fiber_spares[scr_fiber_nspares] = NULL;
125
+ return stack;
126
+ }
127
+ if (!scr_fiber_cleanup_registered) {
128
+ scr_fiber_cleanup_registered = true;
129
+ scr_atexit(scr_fiber_stacks_clear);
130
+ }
131
+ #endif
132
+ void *stack = mmap(NULL, SCR_FIBER_STACK, PROT_READ | PROT_WRITE,
133
+ MAP_PRIVATE | MAP_ANON, -1, 0);
134
+ if (stack == MAP_FAILED) scr_trap("scriptc: out of memory\n");
135
+ return stack;
136
+ }
137
+
138
+ static void scr_fiber_stack_free(void *stack) {
139
+ if (!stack) return;
140
+ #ifndef SCR_ASAN_FIBERS
141
+ if (scr_fiber_nspares < SCR_FIBER_SPARES) {
142
+ scr_fiber_spares[scr_fiber_nspares++] = stack;
143
+ return;
144
+ }
145
+ #endif
146
+ (void)munmap(stack, SCR_FIBER_STACK);
147
+ }
148
+ #endif
149
+
150
+ /* ── promises ─────────────────────────────────────────────────────────── */
151
+
152
+ enum { SCR_PROM_PENDING = 0, SCR_PROM_FULFILLED = 1, SCR_PROM_REJECTED = 2 };
153
+
154
+ typedef struct ScrFiber ScrFiber;
155
+
156
+ typedef struct { size_t rc; } ScrPromiseIdentity;
157
+
158
+ struct ScrPromise {
159
+ size_t rc; /* The cycle collector reads the reference count at offset zero. */
160
+ ScrPromiseIdentity *identity;
161
+ int state;
162
+ bool top_level_handled; /* uncaughtException handled entry evaluation */
163
+ /* Payload (fulfillment value or rejection reason), ScrExcCell-style.
164
+ * trace_fn is non-NULL iff the REF payload type carries a cycle header
165
+ * (a promise settled with a cycle-capable value can be a cycle member —
166
+ * e.g. a closure that captures a box holding this very promise). */
167
+ ScrExcKind payload_kind; /* NONE = void fulfillment */
168
+ double f64;
169
+ bool b;
170
+ void *payload;
171
+ void *(*retain_fn)(void *);
172
+ void (*release_fn)(void *);
173
+ ScrTraceFn trace_fn;
174
+ /* Fibers parked on this promise. */
175
+ ScrFiber **waiters;
176
+ size_t nwaiters, waiters_cap;
177
+ /* Combinator callbacks (Promise.race / Promise.all): at settle,
178
+ * fulfilled promises run adapt(dst, this) — an emitted adapter
179
+ * converting the payload into the destination's inner type — and
180
+ * rejections copy raw (reasons are dynamically tagged). Each entry owns
181
+ * a reference on its dst. Promise.all entries carry the shared
182
+ * countdown state (`all` non-NULL, `all_idx` the entry's INPUT index);
183
+ * race entries leave both zeroed and keep the adapt dispatch. */
184
+ struct ScrPromiseCbWaiter {
185
+ void (*adapt)(ScrPromise *dst, ScrPromise *src);
186
+ ScrPromise *dst;
187
+ struct ScrAllState *all;
188
+ size_t all_idx;
189
+ } *cbs;
190
+ size_t ncbs, cbs_cap;
191
+ /* Unhandled-rejection tracking: set when rejected, cleared on await. */
192
+ bool rejection_observed;
193
+ /* Set when the checkpoint report delivered THIS promise to
194
+ * 'unhandledRejection' listeners — a handler attached after that is
195
+ * Node's 'rejectionHandled' moment (scr_prom_observe below). */
196
+ bool reported_unhandled;
197
+ };
198
+
199
+ #ifdef SCR_RC_AUDIT
200
+ static long scr_live_promises = 0;
201
+ long scr_promise_live_count(void) { return scr_live_promises; }
202
+ #endif
203
+
204
+ /* ── Promise.all shared state ─────────────────────────────────────────
205
+ * One per Promise.all call: the values array filled per INPUT index as
206
+ * entries fulfill, the countdown of fulfillments still missing, and the
207
+ * per-element-kind store helper. The state holds +1 on `values` (NULL for
208
+ * void-element all) and is itself refcounted by the entries that still
209
+ * point at it (parked cb waiters plus the builder while it subscribes);
210
+ * the RESULT promise is NOT held here — each parked entry's cb.dst is the
211
+ * retained result, so promise teardown paths need no all-specific
212
+ * destination handling. */
213
+ typedef struct ScrAllState {
214
+ size_t rc;
215
+ size_t remaining;
216
+ ScrArr *values;
217
+ void (*store)(ScrArr *a, double i, ScrPromise *src);
218
+ } ScrAllState;
219
+
220
+ static void scr_promise_all_state_release(ScrAllState *st) {
221
+ if (--st->rc == 0) {
222
+ if (st->values) scr_arr_release(st->values);
223
+ free(st);
224
+ }
225
+ }
226
+
227
+ static void scr_oom(void) {
228
+ fputs("scriptc: out of memory\n", stderr);
229
+ abort();
230
+ }
231
+
232
+ static void scr_promise_trace(void *o, ScrTraceVisit visit, void *ctx) {
233
+ ScrPromise *p = (ScrPromise *)o;
234
+ /* Waiters are fibers (not refcounted objects) — the settled payload and
235
+ * the combinator destinations are the strong references this promise
236
+ * owns (destination promises are cycle-headered). */
237
+ if ((p->payload_kind == SCR_EXC_REF || p->payload_kind == SCR_EXC_OBJ ||
238
+ p->payload_kind == SCR_EXC_PRIMITIVE_REF) &&
239
+ p->trace_fn) {
240
+ visit(p->payload, ctx);
241
+ }
242
+ for (size_t i = 0; i < p->ncbs; i++) visit(p->cbs[i].dst, ctx);
243
+ }
244
+
245
+ /* Teardown for the collector: release the payload only when the trace does
246
+ * NOT visit it (the complement — see the contract in scr_runtime.h). The
247
+ * cb destinations are always visited, so only the array frees here. */
248
+ static void scr_promise_gcfree(void *o) {
249
+ ScrPromise *p = (ScrPromise *)o;
250
+ if (p->payload_kind == SCR_EXC_STR) {
251
+ scr_str_release((ScrStr *)p->payload);
252
+ } else if ((p->payload_kind == SCR_EXC_REF || p->payload_kind == SCR_EXC_OBJ ||
253
+ p->payload_kind == SCR_EXC_PRIMITIVE_REF) &&
254
+ p->payload && !p->trace_fn) {
255
+ p->release_fn(p->payload);
256
+ }
257
+ /* Parked Promise.all states are NOT traced children (their values array
258
+ * is reachable only through them) — release like the untraced payload
259
+ * above; the cb destinations stay untouched (trace visits them). */
260
+ for (size_t i = 0; i < p->ncbs; i++) {
261
+ if (p->cbs[i].all) scr_promise_all_state_release(p->cbs[i].all);
262
+ }
263
+ if (--p->identity->rc == 0) free(p->identity);
264
+ free(p->waiters);
265
+ free(p->cbs);
266
+ #ifdef SCR_RC_AUDIT
267
+ scr_live_promises--;
268
+ #endif
269
+ scr_cyc_free(p);
270
+ }
271
+
272
+ ScrPromise *scr_promise_new(void) {
273
+ ScrPromise *p = scr_cyc_alloc(sizeof *p, &scr_promise_trace, &scr_promise_gcfree);
274
+ p->rc = 1;
275
+ p->identity = malloc(sizeof *p->identity);
276
+ if (!p->identity) scr_oom();
277
+ p->identity->rc = 1;
278
+ #ifdef SCR_RC_AUDIT
279
+ scr_live_promises++;
280
+ #endif
281
+ return p;
282
+ }
283
+
284
+ void scr_promise_share_identity(ScrPromise *dst, ScrPromise *src) {
285
+ if (dst->identity == src->identity) return;
286
+ if (--dst->identity->rc == 0) free(dst->identity);
287
+ dst->identity = src->identity;
288
+ dst->identity->rc++;
289
+ }
290
+
291
+ bool scr_promise_identity_equal(ScrPromise *a, ScrPromise *b) {
292
+ return a->identity == b->identity;
293
+ }
294
+
295
+ /* The 'rejectionHandled' hook (scr_async_dyn.c installs it at listener
296
+ * registration — the scr_urj_deliver_fn pattern, so listener-free
297
+ * binaries keep their size class): called when a promise the checkpoint
298
+ * report already delivered as unhandled gains a handler. */
299
+ void (*scr_rjh_notify_fn)(ScrPromise *p) = NULL;
300
+
301
+ /* Every handler attach funnels here: mark the rejection observed, and
302
+ * fire Node's 'rejectionHandled' when the attach arrived AFTER the
303
+ * report delivered this promise to 'unhandledRejection' listeners (the
304
+ * model's one late-handling window — earlier handling keeps the promise
305
+ * out of the report entirely). The flag clears on the first attach, so
306
+ * one report fires at most one 'rejectionHandled' — Node's pairing. */
307
+ static void scr_prom_observe(ScrPromise *p) {
308
+ p->rejection_observed = true;
309
+ if (p->reported_unhandled) {
310
+ p->reported_unhandled = false;
311
+ if (scr_rjh_notify_fn != NULL) scr_rjh_notify_fn(p);
312
+ }
313
+ }
314
+
315
+ /* The attach-time handled mark (scr_async_dyn.c's dyn then/catch with a
316
+ * rejection handler, plus the module loader's ownership of every module
317
+ * evaluation promise): Node marks a promise handled at ATTACH, including
318
+ * while it is still pending, not when a later reaction runs. The pending
319
+ * mark is essential for a module dependency whose importer aborts while
320
+ * evaluating a later sibling — the loader still owns that dependency's
321
+ * eventual rejection, so it must never surface as an unrelated unhandled
322
+ * rejection. */
323
+ void scr_promise_mark_handled(ScrPromise *p) {
324
+ scr_prom_observe(p);
325
+ }
326
+
327
+ ScrPromise *scr_promise_retain(ScrPromise *p) {
328
+ if (p && p->rc != SIZE_MAX) {
329
+ p->rc++;
330
+ scr_cyc_mark_live(p);
331
+ }
332
+ return p;
333
+ }
334
+
335
+ static void scr_promise_release_payload(ScrPromise *p) {
336
+ if (p->payload_kind == SCR_EXC_STR) scr_str_release((ScrStr *)p->payload);
337
+ else if ((p->payload_kind == SCR_EXC_REF || p->payload_kind == SCR_EXC_OBJ ||
338
+ p->payload_kind == SCR_EXC_PRIMITIVE_REF) &&
339
+ p->payload) p->release_fn(p->payload);
340
+ p->payload_kind = SCR_EXC_NONE;
341
+ p->payload = NULL;
342
+ }
343
+
344
+ void scr_promise_release(ScrPromise *p) {
345
+ if (!p || p->rc == SIZE_MAX) return;
346
+ if (--p->rc == 0) {
347
+ scr_cyc_on_dead(p);
348
+ scr_promise_release_payload(p);
349
+ if (--p->identity->rc == 0) free(p->identity);
350
+ free(p->waiters);
351
+ for (size_t i = 0; i < p->ncbs; i++) {
352
+ scr_promise_release(p->cbs[i].dst);
353
+ if (p->cbs[i].all) scr_promise_all_state_release(p->cbs[i].all);
354
+ }
355
+ free(p->cbs);
356
+ #ifdef SCR_RC_AUDIT
357
+ scr_live_promises--;
358
+ #endif
359
+ scr_cyc_free(p);
360
+ } else {
361
+ scr_cyc_on_release(p); /* possible cycle root; may collect — p is done */
362
+ }
363
+ }
364
+
365
+ void *scr_promise_retain_v(void *p) { return scr_promise_retain((ScrPromise *)p); }
366
+ void scr_promise_release_v(void *p) { scr_promise_release((ScrPromise *)p); }
367
+ void scr_promise_trace_v(void *p, ScrTraceVisit visit, void *ctx) {
368
+ scr_promise_trace(p, visit, ctx);
369
+ }
370
+
371
+ /* ── fibers and the scheduler ─────────────────────────────────────────── */
372
+
373
+ /* One saved execution context. POSIX: a ucontext_t (swapcontext saves the
374
+ * outgoing context INTO the `from` slot). Windows: the fiber HANDLE —
375
+ * SwitchToFiber saves the outgoing state inside the fiber object itself,
376
+ * so the slot only needs to name the destination; `from` is unused. */
377
+ #ifdef _WIN32
378
+ typedef void *ScrCtx;
379
+ #elif defined(__wasi__)
380
+ typedef unsigned char ScrCtx;
381
+ #else
382
+ typedef ucontext_t ScrCtx;
383
+ #endif
384
+
385
+ struct ScrFiber {
386
+ ScrCtx ctx;
387
+ /* wasm32 uses LLVM's stackless switched-coroutine frame instead of a
388
+ * native saved stack. The compiler emits these two generic wrappers in
389
+ * every WASI module. */
390
+ void *coro;
391
+ ScrCtx *return_to; /* whoever resumed us last (spawner or the loop) */
392
+ char *stack; /* POSIX only; Windows fibers own their stack (NULL) */
393
+ ScrPromise *promise; /* the promise this fiber settles (owned +1); NULL
394
+ * for generator fibers (gen non-NULL instead) */
395
+ ScrGen *gen; /* the generator this fiber runs (borrowed — the
396
+ * ScrGen owns the fiber, never the reverse) */
397
+ ScrExcCell exc;
398
+ /* AsyncLocalStorage context (owned; NULL = empty). Inherited from the
399
+ * SPAWNER at spawn (Node's init-time capture), swapped active with the
400
+ * fiber (the exc-cell pattern) so run()'s window rides awaits. */
401
+ ScrAlsCtx *als;
402
+ bool done;
403
+ /* Trampoline args: the spawn wrapper stores a pointer to a stack-local
404
+ * argpack; the trampoline copies it out before the spawner resumes. */
405
+ void *argpack;
406
+ void (*entry)(ScrFiber *self, void *argpack);
407
+ /* queueMicrotask entries: a stackless pseudo-fiber — the READY queue's
408
+ * FIFO IS the microtask queue, so a closure rides it as a fiber-shaped
409
+ * envelope and scr_resume_fiber runs it on the main stack (a throw is
410
+ * an UNCAUGHT exception, like Node's queueMicrotask, never a
411
+ * rejection). Owned; NULL on real fibers. */
412
+ ScrClosure *micro_cb;
413
+ /* Async-generator settlement jobs: stackless READY-queue envelopes.
414
+ * The retained generator is pumped on the main stack. */
415
+ ScrGen *gen_job;
416
+ #ifdef SCR_ASAN_FIBERS
417
+ void *fake_stack;
418
+ #endif
419
+ };
420
+
421
+ /* ── AsyncLocalStorage (node:async_hooks) ─────────────────────────────
422
+ * Stores are process-lived ids; the CONTEXT is an immutable refcounted
423
+ * snapshot of (store id → dyn value) entries. One ACTIVE SLOT pointer
424
+ * (the exc-cell pattern): main owns a static slot, every fiber owns its
425
+ * own field, scr_switch repoints the active slot — so run()'s window
426
+ * rides the fiber across awaits, and a spawned fiber INHERITS the
427
+ * spawner's snapshot (Node's init-time capture through AsyncResource).
428
+ * Snapshots are immutable: enter builds a fresh one (entries retained),
429
+ * restore swaps the previous back — timer capture retains pointers. */
430
+
431
+ /* The ScrAlsCtx layout and the API over it live in scr_runtime.h /
432
+ * scr_async_dyn.c (gated — the size-class stance); this always-linked
433
+ * core keeps only what the fiber machinery itself touches: the active
434
+ * slot, the snapshot RC pair, and the switch/spawn/destroy wiring. */
435
+ static ScrAlsCtx *scr_als_main_slot = NULL;
436
+ ScrAlsCtx **scr_als_active = &scr_als_main_slot;
437
+
438
+ ScrAlsCtx *scr_als_ctx_retain(ScrAlsCtx *c) {
439
+ if (c) c->rc++;
440
+ return c;
441
+ }
442
+
443
+ void scr_als_ctx_release(ScrAlsCtx *c) {
444
+ if (!c || --c->rc != 0) return;
445
+ for (size_t i = 0; i < c->len; i++) scr_dyn_release(c->entries[i].value);
446
+ free(c);
447
+ }
448
+
449
+
450
+
451
+ static ScrCtx scr_loop_ctx; /* the main stack (scheduler home) */
452
+ static ScrFiber *scr_current = NULL;
453
+ static long scr_fibers_live = 0;
454
+ static long scr_fibers_abandoned = 0;
455
+
456
+ long scr_abandoned_fiber_count(void) { return scr_fibers_abandoned; }
457
+
458
+ /* True while executing on an async fiber (vs the main stack). The island
459
+ * sizes its engine stack budget per stack: fibers are small and fixed,
460
+ * the main stack is the process's megabytes (scr_island.c isl_entry). */
461
+ bool scr_on_fiber(void) { return scr_current != NULL; }
462
+ void *scr_fiber_self(void) { return scr_current; }
463
+
464
+ #ifdef __wasi__
465
+ extern void scr_wasi_coro_resume(void *handle);
466
+ extern void scr_wasi_coro_destroy(void *handle);
467
+
468
+ void scr_wasi_coro_started(void *handle) {
469
+ if (scr_current == NULL) {
470
+ fputs("scriptc: internal error: coroutine started outside a fiber\n", stderr);
471
+ abort();
472
+ }
473
+ scr_current->coro = handle;
474
+ }
475
+ #endif
476
+
477
+ /* Microtask queue: ready fibers, FIFO. */
478
+ static ScrFiber **scr_ready = NULL;
479
+ static size_t scr_ready_head = 0, scr_ready_len = 0, scr_ready_cap = 0;
480
+
481
+ static void scr_ready_push(ScrFiber *f) {
482
+ if (scr_ready_head + scr_ready_len == scr_ready_cap) {
483
+ if (scr_ready_len > 0) {
484
+ memmove(scr_ready, scr_ready + scr_ready_head, scr_ready_len * sizeof *scr_ready);
485
+ }
486
+ scr_ready_head = 0;
487
+ if (scr_ready_len == scr_ready_cap) {
488
+ scr_ready_cap = scr_ready_cap ? scr_ready_cap * 2 : 16;
489
+ scr_ready = realloc(scr_ready, scr_ready_cap * sizeof *scr_ready);
490
+ if (!scr_ready) scr_oom();
491
+ }
492
+ }
493
+ scr_ready[scr_ready_head + scr_ready_len++] = f;
494
+ }
495
+
496
+ static void scr_async_gen_job(ScrGen *g);
497
+ static void scr_async_gen_resume_ready(ScrGen *g);
498
+
499
+ /* Timer min-heap, FIFO tiebreak via sequence numbers. `id` is nonzero only
500
+ * for setInterval entries (the clearInterval handle; setTimeout has no
501
+ * clear surface, so plain timeouts never need one) and `repeat_ms` is the
502
+ * interval's period — a fired interval re-enters the heap with a fresh
503
+ * deadline and seq, so ties against later timers stay FIFO like Node's. */
504
+ typedef struct {
505
+ double deadline_ms;
506
+ unsigned long seq;
507
+ ScrClosure *cb; /* owned */
508
+ double repeat_ms;
509
+ unsigned long id;
510
+ bool reffed; /* keeps the loop alive; unref() clears it (Node semantics) */
511
+ double delay_ms; /* the original delay — refresh() re-arms to now + this */
512
+ } ScrTimer;
513
+
514
+ static ScrTimer *scr_timers = NULL;
515
+ static size_t scr_ntimers = 0, scr_timers_cap = 0;
516
+ static unsigned long scr_timer_seq = 0;
517
+ /* REF'd armed timers — the loop's timer-liveness count (an unref'd timer
518
+ * sits in the heap and still FIRES if the loop runs for other reasons, but
519
+ * does not by itself keep the loop alive). Kept in sync by push/pop/remove
520
+ * and by ref/unref. */
521
+ static size_t scr_reffed_timers = 0;
522
+
523
+ /* Exported: the island's timer machinery (scr_web.c) shares this clock so
524
+ * its deadlines are comparable with the loop's. */
525
+ double scr_now_ms(void) {
526
+ struct timespec ts;
527
+ clock_gettime(CLOCK_MONOTONIC, &ts);
528
+ return (double)ts.tv_sec * 1000.0 + (double)ts.tv_nsec / 1e6;
529
+ }
530
+
531
+ static bool scr_timer_before(const ScrTimer *a, const ScrTimer *b) {
532
+ if (a->deadline_ms != b->deadline_ms) return a->deadline_ms < b->deadline_ms;
533
+ return a->seq < b->seq;
534
+ }
535
+
536
+ static void scr_timer_push(ScrTimer t) {
537
+ if (scr_ntimers == scr_timers_cap) {
538
+ scr_timers_cap = scr_timers_cap ? scr_timers_cap * 2 : 16;
539
+ scr_timers = realloc(scr_timers, scr_timers_cap * sizeof *scr_timers);
540
+ if (!scr_timers) scr_oom();
541
+ }
542
+ if (t.reffed) scr_reffed_timers++;
543
+ size_t i = scr_ntimers++;
544
+ scr_timers[i] = t;
545
+ while (i > 0) {
546
+ size_t parent = (i - 1) / 2;
547
+ if (!scr_timer_before(&scr_timers[i], &scr_timers[parent])) break;
548
+ ScrTimer tmp = scr_timers[i];
549
+ scr_timers[i] = scr_timers[parent];
550
+ scr_timers[parent] = tmp;
551
+ i = parent;
552
+ }
553
+ }
554
+
555
+ static ScrTimer scr_timer_pop(void) {
556
+ ScrTimer top = scr_timers[0];
557
+ if (top.reffed && scr_reffed_timers > 0) scr_reffed_timers--;
558
+ scr_timers[0] = scr_timers[--scr_ntimers];
559
+ size_t i = 0;
560
+ for (;;) {
561
+ size_t l = 2 * i + 1, r = 2 * i + 2, min = i;
562
+ if (l < scr_ntimers && scr_timer_before(&scr_timers[l], &scr_timers[min])) min = l;
563
+ if (r < scr_ntimers && scr_timer_before(&scr_timers[r], &scr_timers[min])) min = r;
564
+ if (min == i) break;
565
+ ScrTimer tmp = scr_timers[i];
566
+ scr_timers[i] = scr_timers[min];
567
+ scr_timers[min] = tmp;
568
+ i = min;
569
+ }
570
+ return top;
571
+ }
572
+
573
+ /* Node's delay coercion (lib/internal/timers.js): NaN/negative/sub-ms
574
+ * clamp to 1, the delay TRUNCATES to integer milliseconds (setTimeout(cb,
575
+ * 1.8) and setTimeout(cb, 1.1) both land in the 1ms bucket, so a batch of
576
+ * fractional delays fires in REGISTRATION order — test-timers-non-integer-
577
+ * delay's contract), and anything past TIMEOUT_MAX (2^31-1) becomes 1. */
578
+ static double scr_timer_coerce_ms(double ms) {
579
+ if (!(ms >= 1)) return 1;
580
+ if (ms > 2147483647.0) return 1; /* past TIMEOUT_MAX (also +Infinity) */
581
+ return (double)(unsigned long long)ms; /* trunc: positive, finite, in range */
582
+ }
583
+
584
+ void scr_set_timeout(ScrClosure *cb, double ms) {
585
+ ms = scr_timer_coerce_ms(ms);
586
+ ScrTimer t = {scr_now_ms() + ms, scr_timer_seq++, cb /* ownership moves in */, 0, 0, true, ms};
587
+ scr_timer_push(t);
588
+ }
589
+
590
+ /* ── setInterval / clearInterval ─────────────────────────────────────
591
+ * Intervals ride the same heap: the entry carries its period and a
592
+ * nonzero id (the compiled handle — Node's Timeout object reduced to the
593
+ * number the fallback declarations promise). A live interval keeps the
594
+ * loop alive exactly because it sits in the heap; clearInterval removes
595
+ * the entry EAGERLY (a lazily-cancelled entry would hold the loop open
596
+ * until its deadline — an interval cleared at t=0 with a one-hour period
597
+ * must let the program exit NOW, like Node). Clearing the interval whose
598
+ * callback is currently running (the self-clearing spinner pattern) is
599
+ * handled by the firing pair below: the entry is out of the heap while
600
+ * its callback runs, so the run loop re-pushes it only if the callback
601
+ * did not clear it. */
602
+
603
+ static unsigned long scr_interval_next_id = 1;
604
+ static unsigned long scr_firing_id = 0; /* interval currently running */
605
+ static bool scr_firing_cleared = false;
606
+ static bool scr_firing_reffed = true; /* the running interval's ref state */
607
+ static bool scr_firing_refresh = false; /* refresh() called mid-callback */
608
+
609
+ /* Removes heap entry i (swap-with-last, then sift whichever way the moved
610
+ * entry needs). */
611
+ static void scr_timer_remove_at(size_t i) {
612
+ if (scr_timers[i].reffed && scr_reffed_timers > 0) scr_reffed_timers--;
613
+ scr_timers[i] = scr_timers[--scr_ntimers];
614
+ if (i >= scr_ntimers) return;
615
+ /* Sift up if the moved entry beats its parent, else sift down. */
616
+ while (i > 0) {
617
+ size_t parent = (i - 1) / 2;
618
+ if (!scr_timer_before(&scr_timers[i], &scr_timers[parent])) break;
619
+ ScrTimer tmp = scr_timers[i];
620
+ scr_timers[i] = scr_timers[parent];
621
+ scr_timers[parent] = tmp;
622
+ i = parent;
623
+ }
624
+ for (;;) {
625
+ size_t l = 2 * i + 1, r = 2 * i + 2, min = i;
626
+ if (l < scr_ntimers && scr_timer_before(&scr_timers[l], &scr_timers[min])) min = l;
627
+ if (r < scr_ntimers && scr_timer_before(&scr_timers[r], &scr_timers[min])) min = r;
628
+ if (min == i) break;
629
+ ScrTimer tmp = scr_timers[i];
630
+ scr_timers[i] = scr_timers[min];
631
+ scr_timers[min] = tmp;
632
+ i = min;
633
+ }
634
+ }
635
+
636
+ double scr_set_interval(ScrClosure *cb, double ms) {
637
+ ms = scr_timer_coerce_ms(ms); /* Node's clamp-and-trunc, like setTimeout */
638
+ unsigned long id = scr_interval_next_id++;
639
+ ScrTimer t = {scr_now_ms() + ms, scr_timer_seq++, cb /* ownership moves in */, ms, id, true, ms};
640
+ scr_timer_push(t);
641
+ return (double)id;
642
+ }
643
+
644
+ /* A one-shot timer WITH a clear handle — the island's setTimeout (its
645
+ * clearTimeout must cancel, unlike the static surface's clear-less
646
+ * setTimeout). Rides the interval id space so scr_clear_interval serves
647
+ * both; repeat_ms 0 keeps it one-shot at the firing site. */
648
+ double scr_set_timeout_handle(ScrClosure *cb, double ms) {
649
+ ms = scr_timer_coerce_ms(ms);
650
+ unsigned long id = scr_interval_next_id++;
651
+ ScrTimer t = {scr_now_ms() + ms, scr_timer_seq++, cb /* ownership moves in */, 0, id, true, ms};
652
+ scr_timer_push(t);
653
+ return (double)id;
654
+ }
655
+
656
+ /* process.env-style timer ref bookkeeping: unref() drops a timer from the
657
+ * loop's liveness count (it still fires if the loop runs on), ref() puts
658
+ * it back. Node-exact for the static timer surface; NaN/0/absent handles
659
+ * are tolerated (never a handle). The one-shot setTimeout with NO clear
660
+ * handle (id 0) cannot be unref'd by id — the compiler routes .unref()
661
+ * only over handle-returning timers, so id 0 never reaches here. */
662
+ static ScrTimer *scr_timer_find(unsigned long id) {
663
+ for (size_t i = 0; i < scr_ntimers; i++) {
664
+ if (scr_timers[i].id == id) return &scr_timers[i];
665
+ }
666
+ return NULL;
667
+ }
668
+
669
+ void scr_timer_unref(double handle) {
670
+ if (!(handle >= 1)) return;
671
+ unsigned long id = (unsigned long)handle;
672
+ if (id == scr_firing_id) {
673
+ /* Firing interval unref'ing itself: the re-arm carries the flag. */
674
+ scr_firing_reffed = false;
675
+ return;
676
+ }
677
+ ScrTimer *t = scr_timer_find(id);
678
+ if (t && t->reffed) {
679
+ t->reffed = false;
680
+ if (scr_reffed_timers > 0) scr_reffed_timers--;
681
+ }
682
+ }
683
+
684
+ void scr_timer_ref(double handle) {
685
+ if (!(handle >= 1)) return;
686
+ unsigned long id = (unsigned long)handle;
687
+ if (id == scr_firing_id) {
688
+ scr_firing_reffed = true;
689
+ return;
690
+ }
691
+ ScrTimer *t = scr_timer_find(id);
692
+ if (t && !t->reffed) {
693
+ t->reffed = true;
694
+ scr_reffed_timers++;
695
+ }
696
+ }
697
+
698
+ /* refresh(): re-arm to now + the original delay — Node's Timeout.refresh.
699
+ * A HEAP entry (armed timeout or interval between ticks) re-enters the
700
+ * heap with a fresh deadline and seq (FIFO against later same-deadline
701
+ * timers, like a brand-new timer); the timer whose callback is RUNNING
702
+ * sets the firing flag and the loop re-arms the one-shot after the
703
+ * callback returns (the interval re-arm already does). A one-shot that
704
+ * fired on an earlier turn is gone — its closure released — so refresh
705
+ * of a dead handle is a tolerated no-op (SEMANTICS: Node re-activates
706
+ * even a fired Timeout; the compiled handle cannot). */
707
+ void scr_timer_refresh(double handle) {
708
+ if (!(handle >= 1)) return;
709
+ unsigned long id = (unsigned long)handle;
710
+ if (id == scr_firing_id) {
711
+ scr_firing_refresh = true;
712
+ return;
713
+ }
714
+ for (size_t i = 0; i < scr_ntimers; i++) {
715
+ if (scr_timers[i].id == id) {
716
+ ScrTimer t = scr_timers[i];
717
+ scr_timer_remove_at(i);
718
+ t.deadline_ms = scr_now_ms() + t.delay_ms;
719
+ t.seq = scr_timer_seq++;
720
+ scr_timer_push(t);
721
+ return;
722
+ }
723
+ }
724
+ }
725
+
726
+ /* hasRef(): true iff the handle names a live, still-reffed timer. */
727
+ bool scr_timer_has_ref(double handle) {
728
+ if (!(handle >= 1)) return false;
729
+ unsigned long id = (unsigned long)handle;
730
+ if (id == scr_firing_id) return scr_firing_reffed;
731
+ ScrTimer *t = scr_timer_find(id);
732
+ return t != NULL && t->reffed;
733
+ }
734
+
735
+ /* ── process.getActiveResourcesInfo (the loop's own bookkeeping) ──────
736
+ * 'Timeout' per armed heap timer — plus the firing, uncleared one (Node
737
+ * counts a Timeout as active while its callback runs, until clearTimeout
738
+ * drops it) — and 'Immediate' per queued, unfired immediate (a FIRED
739
+ * immediate no longer counts, Node's current answer inside the
740
+ * callback). Resource kinds this runtime does not model as loop handles
741
+ * (TCP wraps, FS requests, ...) are absent — SEMANTICS.md names the
742
+ * divergence. Result +1. */
743
+ static size_t scr_pending_immediates; /* defined below with the queue */
744
+ ScrArr *scr_active_resources(void) {
745
+ ScrArr *arr = scr_arr_new(SCR_ELEM_STR, 8);
746
+ size_t timeouts = scr_ntimers + ((scr_firing_id != 0 && !scr_firing_cleared) ? 1 : 0);
747
+ for (size_t i = 0; i < timeouts; i++) scr_arr_push_ref(arr, scr_str_new("Timeout", 7));
748
+ for (size_t i = 0; i < scr_pending_immediates; i++) scr_arr_push_ref(arr, scr_str_new("Immediate", 9));
749
+ return arr;
750
+ }
751
+
752
+ /* ── process.nextTick (the user tick queue) ───────────────────────────
753
+ * A FIFO of user callbacks drained BEFORE promise jobs at every loop
754
+ * checkpoint, to joint exhaustion with them — Node's tick-then-microtask
755
+ * order. Pending ticks are always-ready work: the loop neither sleeps
756
+ * nor exits while any exist. Ticks scheduled from 'exit' listeners (or
757
+ * left queued on the uncaught paths) never run — the teardown releases
758
+ * them, like Node dropping the queue at exit. */
759
+ typedef struct ScrNtick {
760
+ ScrClosure *cb; /* owned; NULL for a raw C-hook entry */
761
+ ScrFsRenameFn error_cb; /* process-write success adapter, or NULL */
762
+ void (*raw)(void); /* hook when cb == NULL (stream markers) */
763
+ struct ScrNtick *next;
764
+ } ScrNtick;
765
+
766
+ static ScrNtick *scr_nt_head = NULL;
767
+ static ScrNtick *scr_nt_tail = NULL;
768
+
769
+ /* Public: releases every queued tick without running it — the loop-exit
770
+ * teardown below AND the exit-listener runner (scr_events.c) both call
771
+ * it, because 'exit' listeners run AFTER the loop's teardown and may
772
+ * enqueue ticks that must never run (Node) yet must not leak. */
773
+
774
+ void scr_next_tick(ScrClosure *cb /*moves*/) {
775
+ ScrNtick *t = calloc(1, sizeof *t);
776
+ if (!t) scr_oom();
777
+ t->cb = cb;
778
+ if (scr_nt_tail) scr_nt_tail->next = t;
779
+ else scr_nt_head = t;
780
+ scr_nt_tail = t;
781
+ }
782
+
783
+ /* stdout/stderr write completions are Node nextTicks too, but their
784
+ * callback receives the success `null` argument. Reuse the error-first
785
+ * adapter ABI also used by fs.rename: emitted adapters construct the
786
+ * program's Error | null union, and NULL selects its null arm. */
787
+ void scr_process_write_callback(ScrClosure *cb /*moves*/, ScrFsRenameFn fn) {
788
+ ScrNtick *t = calloc(1, sizeof *t);
789
+ if (!t) scr_oom();
790
+ t->cb = cb;
791
+ t->error_cb = fn;
792
+ if (scr_nt_tail) scr_nt_tail->next = t;
793
+ else scr_nt_head = t;
794
+ scr_nt_tail = t;
795
+ }
796
+
797
+ /* A RAW C-hook tick: the stream unit enqueues one marker per deferred
798
+ * stream emission so those emissions interleave with user nextTicks in
799
+ * true FIFO order — in Node they ARE nextTicks (resume_, emitReadable_,
800
+ * endReadableNT, ...). The hook dispatches exactly one stream tick;
801
+ * teardown just drops markers (the stream queue owns its entries). */
802
+ void scr_next_tick_raw(void (*fn)(void)) {
803
+ ScrNtick *t = calloc(1, sizeof *t);
804
+ if (!t) scr_oom();
805
+ t->raw = fn;
806
+ if (scr_nt_tail) scr_nt_tail->next = t;
807
+ else scr_nt_head = t;
808
+ scr_nt_tail = t;
809
+ }
810
+
811
+ void scr_nticks_teardown(void) {
812
+ while (scr_nt_head != NULL) {
813
+ ScrNtick *t = scr_nt_head;
814
+ scr_nt_head = t->next;
815
+ if (t->cb) scr_closure_release(t->cb);
816
+ free(t);
817
+ }
818
+ scr_nt_tail = NULL;
819
+ }
820
+
821
+ /* Releases every armed timer — the island teardown calls this before the
822
+ * engine dies so closures holding engine callbacks free first and the
823
+ * counting allocator's zero-live audit holds (the loop only exits with
824
+ * entries still armed on the uncaught/unhandled paths). */
825
+ static void scr_immediates_teardown(void);
826
+ void scr_timers_teardown(void) {
827
+ for (size_t i = 0; i < scr_ntimers; i++) scr_closure_release(scr_timers[i].cb);
828
+ scr_ntimers = 0;
829
+ scr_reffed_timers = 0;
830
+ scr_immediates_teardown();
831
+ scr_nticks_teardown();
832
+ }
833
+
834
+ void scr_clear_interval(double handle) {
835
+ if (!(handle >= 1)) return; /* NaN/0/negative: never a handle; Node tolerates */
836
+ unsigned long id = (unsigned long)handle;
837
+ if (id == scr_firing_id) {
838
+ scr_firing_cleared = true; /* the run loop drops the callback */
839
+ return;
840
+ }
841
+ for (size_t i = 0; i < scr_ntimers; i++) {
842
+ if (scr_timers[i].id == id) {
843
+ scr_closure_release(scr_timers[i].cb);
844
+ scr_timer_remove_at(i);
845
+ return;
846
+ }
847
+ }
848
+ }
849
+
850
+ /* ── immediates (Node's check phase) ──────────────────────────────────
851
+ * setImmediate callbacks run once per loop turn, AFTER due timers, in
852
+ * FIFO order — and immediates queued while the phase runs wait for the
853
+ * NEXT turn (the phase snapshots its end index). The queue is an
854
+ * append-only array with a head cursor; clearImmediate NULLs the slot in
855
+ * place (order and indices stay stable mid-phase). Ids ride their own
856
+ * space — clearTimeout of an Immediate is a no-op, like Node. */
857
+ typedef struct {
858
+ unsigned long id;
859
+ ScrClosure *cb; /* owned; NULL once fired or cleared */
860
+ bool reffed; /* keeps the loop alive; unref() clears it (Node semantics) */
861
+ } ScrImmediate;
862
+
863
+ static ScrImmediate *scr_immediates = NULL;
864
+ static size_t scr_nimmediates = 0, scr_immediates_head = 0, scr_immediates_cap = 0;
865
+ static unsigned long scr_immediate_seq = 0;
866
+ /* Pending (queued, uncleared) immediates and the reffed subset — the
867
+ * loop's no-sleep signal and liveness count respectively. */
868
+ static size_t scr_pending_immediates = 0;
869
+ static size_t scr_reffed_immediates = 0;
870
+
871
+ double scr_set_immediate(ScrClosure *cb) {
872
+ if (scr_nimmediates == scr_immediates_cap) {
873
+ scr_immediates_cap = scr_immediates_cap ? scr_immediates_cap * 2 : 16;
874
+ scr_immediates = realloc(scr_immediates, scr_immediates_cap * sizeof *scr_immediates);
875
+ if (!scr_immediates) scr_oom();
876
+ }
877
+ unsigned long id = ++scr_immediate_seq;
878
+ scr_immediates[scr_nimmediates].id = id;
879
+ scr_immediates[scr_nimmediates].cb = cb; /* ownership moves in */
880
+ scr_immediates[scr_nimmediates].reffed = true;
881
+ scr_nimmediates++;
882
+ scr_pending_immediates++;
883
+ scr_reffed_immediates++;
884
+ return (double)id;
885
+ }
886
+
887
+ static ScrImmediate *scr_immediate_find(unsigned long id) {
888
+ for (size_t i = scr_immediates_head; i < scr_nimmediates; i++) {
889
+ if (scr_immediates[i].id == id && scr_immediates[i].cb != NULL) return &scr_immediates[i];
890
+ }
891
+ return NULL;
892
+ }
893
+
894
+ void scr_clear_immediate(double handle) {
895
+ if (!(handle >= 1)) return; /* NaN/0/negative: never a handle; Node tolerates */
896
+ ScrImmediate *im = scr_immediate_find((unsigned long)handle);
897
+ if (im == NULL) return; /* already fired/cleared: no-op, like Node */
898
+ scr_closure_release(im->cb);
899
+ im->cb = NULL;
900
+ if (scr_pending_immediates > 0) scr_pending_immediates--;
901
+ if (im->reffed) {
902
+ im->reffed = false;
903
+ if (scr_reffed_immediates > 0) scr_reffed_immediates--;
904
+ }
905
+ }
906
+
907
+ /* Immediate.unref()/ref()/hasRef(): the Timeout trio's exact story over
908
+ * the immediate queue. A fired or cleared handle is a tolerated no-op
909
+ * (Node's Immediate methods on a dead handle do nothing). */
910
+ void scr_immediate_unref(double handle) {
911
+ if (!(handle >= 1)) return;
912
+ ScrImmediate *im = scr_immediate_find((unsigned long)handle);
913
+ if (im && im->reffed) {
914
+ im->reffed = false;
915
+ if (scr_reffed_immediates > 0) scr_reffed_immediates--;
916
+ }
917
+ }
918
+
919
+ void scr_immediate_ref(double handle) {
920
+ if (!(handle >= 1)) return;
921
+ ScrImmediate *im = scr_immediate_find((unsigned long)handle);
922
+ if (im && !im->reffed) {
923
+ im->reffed = true;
924
+ scr_reffed_immediates++;
925
+ }
926
+ }
927
+
928
+ bool scr_immediate_has_ref(double handle) {
929
+ if (!(handle >= 1)) return false;
930
+ ScrImmediate *im = scr_immediate_find((unsigned long)handle);
931
+ return im != NULL && im->reffed;
932
+ }
933
+
934
+ /* The teardown sweep's immediate arm (called from scr_timers_teardown):
935
+ * unref'd immediates left queued at normal loop exit never fire (Node),
936
+ * so their closures release here or the RC audit counts them as leaks. */
937
+ static void scr_immediates_teardown(void) {
938
+ for (size_t i = scr_immediates_head; i < scr_nimmediates; i++) {
939
+ if (scr_immediates[i].cb != NULL) scr_closure_release(scr_immediates[i].cb);
940
+ }
941
+ scr_nimmediates = 0;
942
+ scr_immediates_head = 0;
943
+ scr_pending_immediates = 0;
944
+ scr_reffed_immediates = 0;
945
+ }
946
+
947
+ /* Unhandled rejections: rejected promises retained here until observed. */
948
+ static ScrPromise **scr_maybe_unhandled = NULL;
949
+ static size_t scr_nunhandled = 0, scr_unhandled_cap = 0;
950
+
951
+ static void scr_track_rejection(ScrPromise *p) {
952
+ if (scr_nunhandled == scr_unhandled_cap) {
953
+ scr_unhandled_cap = scr_unhandled_cap ? scr_unhandled_cap * 2 : 8;
954
+ scr_maybe_unhandled = realloc(scr_maybe_unhandled, scr_unhandled_cap * sizeof *scr_maybe_unhandled);
955
+ if (!scr_maybe_unhandled) scr_oom();
956
+ }
957
+ scr_maybe_unhandled[scr_nunhandled++] = scr_promise_retain(p);
958
+ }
959
+
960
+ /* ── context switching (ASan-annotated) ───────────────────────────────── */
961
+
962
+ #ifdef SCR_ASAN_FIBERS
963
+ static void *scr_main_fake_stack; /* fake-stack slot for the main context */
964
+ #endif
965
+
966
+ #ifdef _WIN32
967
+ /* The current context's handle, converting the main thread to a fiber on
968
+ * first need (SwitchToFiber requires the caller BE a fiber; the runtime is
969
+ * single-threaded, so one lazy conversion covers the process). Also the
970
+ * loop-home keeper: whenever main is the caller this IS scr_loop_ctx's
971
+ * value — assigned at the conversion so parked fibers can always switch
972
+ * back to it. */
973
+ static void *scr_win_self(void) {
974
+ static bool converted = false;
975
+ if (!converted) {
976
+ scr_loop_ctx = ConvertThreadToFiber(NULL);
977
+ if (scr_loop_ctx == NULL) {
978
+ fputs("scriptc: ConvertThreadToFiber failed\n", stderr);
979
+ abort();
980
+ }
981
+ converted = true;
982
+ }
983
+ return GetCurrentFiber();
984
+ }
985
+ #endif
986
+
987
+ static void scr_switch(ScrCtx *from, ScrCtx *to, ScrFiber *to_fiber) {
988
+ #ifdef SCR_ASAN_FIBERS
989
+ ScrFiber *from_fiber = scr_current;
990
+ #endif
991
+ scr_current = to_fiber;
992
+ scr_exc_swap_cell(to_fiber ? &to_fiber->exc : NULL);
993
+ scr_als_active = to_fiber ? &to_fiber->als : &scr_als_main_slot;
994
+ #ifdef _WIN32
995
+ /* SwitchToFiber snapshots the outgoing fiber's state inside its own
996
+ * fiber object — `from` has nothing to record. */
997
+ (void)from;
998
+ SwitchToFiber(*to);
999
+ #elif defined(__wasi__)
1000
+ (void)from;
1001
+ (void)to;
1002
+ scr_trap("scriptc: internal error: native stack switch reached on WASI\n");
1003
+ #elif defined(SCR_ASAN_FIBERS)
1004
+ void **save = from_fiber ? &from_fiber->fake_stack : &scr_main_fake_stack;
1005
+ const void *bottom = to_fiber ? to_fiber->stack : NULL;
1006
+ size_t size = to_fiber ? SCR_FIBER_STACK : 0;
1007
+ __sanitizer_start_switch_fiber(save, bottom, size);
1008
+ swapcontext(from, to);
1009
+ const void *old_bottom;
1010
+ size_t old_size;
1011
+ __sanitizer_finish_switch_fiber(
1012
+ scr_current ? scr_current->fake_stack : scr_main_fake_stack, &old_bottom, &old_size);
1013
+ #else
1014
+ swapcontext(from, to);
1015
+ #endif
1016
+ }
1017
+
1018
+ static void scr_promise_settle_wake(ScrPromise *p);
1019
+
1020
+ /* Copies src's settlement into a still-pending dst (payload RETAINED —
1021
+ * src can settle other destinations and still be awaited) and wakes dst's
1022
+ * waiters. A rejection consumed this way counts as HANDLED on src (a
1023
+ * combinator attached a handler, like Node's race). The Promise.race
1024
+ * same-inner-type adapter and the rejection path both land here. */
1025
+ static void scr_promise_settle_from(ScrPromise *dst, ScrPromise *src) {
1026
+ if (dst->state == SCR_PROM_PENDING) {
1027
+ dst->state = src->state;
1028
+ dst->payload_kind = src->payload_kind;
1029
+ dst->f64 = src->f64;
1030
+ dst->b = src->b;
1031
+ dst->retain_fn = src->retain_fn;
1032
+ dst->release_fn = src->release_fn;
1033
+ dst->trace_fn = src->trace_fn;
1034
+ dst->payload = NULL;
1035
+ if (src->payload_kind == SCR_EXC_STR && src->payload) {
1036
+ dst->payload = scr_str_retain((ScrStr *)src->payload);
1037
+ } else if ((src->payload_kind == SCR_EXC_REF || src->payload_kind == SCR_EXC_OBJ ||
1038
+ src->payload_kind == SCR_EXC_PRIMITIVE_REF) &&
1039
+ src->payload) {
1040
+ dst->payload = src->retain_fn(src->payload);
1041
+ }
1042
+ scr_promise_settle_wake(dst);
1043
+ }
1044
+ if (src->state == SCR_PROM_REJECTED) scr_prom_observe(src);
1045
+ }
1046
+
1047
+ /* The emitted same-type Promise.race adapter (see raceAdapterFor). */
1048
+ void scr_promise_adapt_copy(ScrPromise *dst, ScrPromise *src) {
1049
+ scr_promise_settle_from(dst, src);
1050
+ }
1051
+
1052
+ /* One Promise.all entry settling: a fulfillment stores its payload into
1053
+ * the values array at the entry's INPUT index (input order regardless of
1054
+ * settlement order) and the LAST missing fulfillment fulfills the result
1055
+ * with the array (void-element all fulfills void); a rejection copies raw
1056
+ * into the result — the first one in SETTLEMENT order wins through the
1057
+ * destination's own pending check, and later ones still count as HANDLED
1058
+ * on their entries (settle_from marks them observed), exactly Node's
1059
+ * subscribe-to-everything behavior. */
1060
+ static void scr_promise_all_settle(ScrAllState *st, ScrPromise *result, size_t idx,
1061
+ ScrPromise *src) {
1062
+ if (src->state == SCR_PROM_FULFILLED) {
1063
+ if (st->store) st->store(st->values, (double)idx, src);
1064
+ if (--st->remaining == 0 && result->state == SCR_PROM_PENDING) {
1065
+ if (st->values) {
1066
+ scr_promise_fulfill_ref(result, scr_arr_retain(st->values), scr_arr_retain_v,
1067
+ scr_arr_release_v,
1068
+ st->values->elem_trace ? scr_arr_trace_v : NULL);
1069
+ } else {
1070
+ scr_promise_fulfill_void(result);
1071
+ }
1072
+ }
1073
+ } else {
1074
+ scr_promise_settle_from(result, src);
1075
+ }
1076
+ }
1077
+
1078
+ /* Settle helpers wake waiters into the microtask queue and run the
1079
+ * combinator callbacks: adapters for fulfillments (they convert the
1080
+ * payload to the destination's inner type), the raw copy for rejections
1081
+ * (reasons are dynamically tagged). first-settle-wins rides the
1082
+ * destination's own pending check. Promise.all entries dispatch through
1083
+ * their shared countdown state instead of the adapt pair. */
1084
+ static void scr_promise_settle_wake(ScrPromise *p) {
1085
+ for (size_t i = 0; i < p->nwaiters; i++) scr_ready_push(p->waiters[i]);
1086
+ p->nwaiters = 0;
1087
+ for (size_t i = 0; i < p->ncbs; i++) {
1088
+ if (p->cbs[i].all) {
1089
+ scr_promise_all_settle(p->cbs[i].all, p->cbs[i].dst, p->cbs[i].all_idx, p);
1090
+ scr_promise_all_state_release(p->cbs[i].all);
1091
+ } else if (p->state == SCR_PROM_FULFILLED) {
1092
+ p->cbs[i].adapt(p->cbs[i].dst, p);
1093
+ } else {
1094
+ scr_promise_settle_from(p->cbs[i].dst, p);
1095
+ }
1096
+ scr_promise_release(p->cbs[i].dst);
1097
+ }
1098
+ p->ncbs = 0;
1099
+ if (p->state == SCR_PROM_REJECTED) scr_track_rejection(p);
1100
+ }
1101
+
1102
+ /* ── Promise.race ─────────────────────────────────────────────────────
1103
+ * The compiler emits: a fresh result promise, then one race_add per
1104
+ * entry. A settled entry settles the result immediately (first add
1105
+ * wins); pending entries park a callback waiter that fires inside the
1106
+ * entry's settle. Fibers awaiting the result still wake through the
1107
+ * microtask queue. Losing entries keep their own settlements (payloads
1108
+ * are retained, not moved). */
1109
+
1110
+ void scr_promise_race_add(ScrPromise *race, ScrPromise *in,
1111
+ void (*adapt)(ScrPromise *dst, ScrPromise *src)) {
1112
+ if (in->state != SCR_PROM_PENDING) {
1113
+ if (in->state == SCR_PROM_FULFILLED) adapt(race, in);
1114
+ else scr_promise_settle_from(race, in);
1115
+ return;
1116
+ }
1117
+ if (in->ncbs == in->cbs_cap) {
1118
+ in->cbs_cap = in->cbs_cap ? in->cbs_cap * 2 : 4;
1119
+ in->cbs = realloc(in->cbs, in->cbs_cap * sizeof *in->cbs);
1120
+ if (!in->cbs) scr_oom();
1121
+ }
1122
+ in->cbs[in->ncbs].adapt = adapt;
1123
+ in->cbs[in->ncbs].dst = scr_promise_retain(race);
1124
+ in->cbs[in->ncbs].all = NULL;
1125
+ in->cbs[in->ncbs].all_idx = 0;
1126
+ in->ncbs++;
1127
+ }
1128
+
1129
+ /* ── Promise.all ──────────────────────────────────────────────────────
1130
+ * BORROWS the entries array `ps` and the pre-capacity values array
1131
+ * `values` (NULL for void elements), retains what it keeps, and returns
1132
+ * the result promise +1. `values` arrives EMPTY with cap >= ps->len (the
1133
+ * emitted construction passes the length) and is pre-sized here: every
1134
+ * slot's zero bits are the per-kind placeholder (0.0 / false / NULL),
1135
+ * legal to overwrite through the store helpers and to release. Entries
1136
+ * already settled settle inline (a rejection settles the result NOW —
1137
+ * first rejection in settlement order — and later rejected entries are
1138
+ * still marked handled); pending entries park a countdown waiter. The
1139
+ * empty array fulfills immediately (awaiters take the settled-await
1140
+ * microtask hop, like Node's one-tick resolve). */
1141
+ ScrPromise *scr_promise_all(ScrArr *ps, ScrArr *values,
1142
+ void (*store)(ScrArr *a, double i, ScrPromise *src)) {
1143
+ size_t n = ps->len;
1144
+ ScrPromise *result = scr_promise_new();
1145
+ if (values && n > 0) {
1146
+ /* Pre-size as holes. Promise settlement writes the present slots through
1147
+ * the normal setters; this also remains safe when n is sparse-sized and
1148
+ * the array intentionally has no dense allocation. */
1149
+ scr_arr_set_len(values, (double)n);
1150
+ }
1151
+ ScrAllState *st = malloc(sizeof *st);
1152
+ if (!st) scr_oom();
1153
+ st->rc = 1; /* the builder's reference, dropped at the end */
1154
+ st->remaining = n;
1155
+ st->values = values ? scr_arr_retain(values) : NULL;
1156
+ st->store = store;
1157
+ for (size_t i = 0; i < n; i++) {
1158
+ ScrPromise *in = (ScrPromise *)scr_arr_get_ref(ps, (double)i); /* +1 */
1159
+ if (in->state != SCR_PROM_PENDING) {
1160
+ scr_promise_all_settle(st, result, i, in);
1161
+ } else {
1162
+ if (in->ncbs == in->cbs_cap) {
1163
+ in->cbs_cap = in->cbs_cap ? in->cbs_cap * 2 : 4;
1164
+ in->cbs = realloc(in->cbs, in->cbs_cap * sizeof *in->cbs);
1165
+ if (!in->cbs) scr_oom();
1166
+ }
1167
+ in->cbs[in->ncbs].adapt = NULL;
1168
+ in->cbs[in->ncbs].dst = scr_promise_retain(result);
1169
+ in->cbs[in->ncbs].all = st;
1170
+ in->cbs[in->ncbs].all_idx = i;
1171
+ in->ncbs++;
1172
+ st->rc++;
1173
+ }
1174
+ scr_promise_release(in);
1175
+ }
1176
+ /* n == 0, or every entry was already fulfilled inline. */
1177
+ if (st->remaining == 0 && result->state == SCR_PROM_PENDING) {
1178
+ if (st->values) {
1179
+ scr_promise_fulfill_ref(result, scr_arr_retain(st->values), scr_arr_retain_v,
1180
+ scr_arr_release_v,
1181
+ st->values->elem_trace ? scr_arr_trace_v : NULL);
1182
+ } else {
1183
+ scr_promise_fulfill_void(result);
1184
+ }
1185
+ }
1186
+ scr_promise_all_state_release(st);
1187
+ return result;
1188
+ }
1189
+
1190
+ /* Per-element-kind store helpers for the emitted Promise.all: write the
1191
+ * entry's fulfillment payload into the values array at its input index.
1192
+ * The payload accessors return retained/by-value (losing a reference is
1193
+ * impossible: set_* takes ownership and releases the zero placeholder). */
1194
+ void scr_promise_all_store_f64(ScrArr *a, double i, ScrPromise *src) {
1195
+ scr_arr_set_f64(a, i, scr_promise_payload_f64(src));
1196
+ }
1197
+ void scr_promise_all_store_bool(ScrArr *a, double i, ScrPromise *src) {
1198
+ scr_arr_set_bool(a, i, scr_promise_payload_bool(src));
1199
+ }
1200
+ void scr_promise_all_store_str(ScrArr *a, double i, ScrPromise *src) {
1201
+ scr_arr_set_ref(a, i, scr_promise_payload_str(src));
1202
+ }
1203
+ void scr_promise_all_store_ref(ScrArr *a, double i, ScrPromise *src) {
1204
+ scr_arr_set_ref(a, i, scr_promise_payload_ref(src));
1205
+ }
1206
+
1207
+ /* Fulfillment payload accessors for the emitted race adapters — all
1208
+ * retained/by-value (the source keeps its settlement). */
1209
+ double scr_promise_payload_f64(ScrPromise *p) { return p->f64; }
1210
+ bool scr_promise_payload_bool(ScrPromise *p) { return p->b; }
1211
+ ScrStr *scr_promise_payload_str(ScrPromise *p) {
1212
+ return scr_str_retain((ScrStr *)p->payload);
1213
+ }
1214
+ /* Thin views for the gated dyn-async TU (scr_async_dyn.c): the payload
1215
+ * KIND, whether a REF payload is a dyn value (the dyn adapters), and the
1216
+ * settled-await primitive (park/hop + rejection re-throw; true =
1217
+ * fulfilled). */
1218
+ static bool scr_await_settled(ScrPromise *p); /* defined with the await family */
1219
+ int scr_promise_payload_kind(const ScrPromise *p) { return (int)p->payload_kind; }
1220
+ bool scr_promise_payload_is_dyn(const ScrPromise *p) { return p->retain_fn == scr_dyn_retain_v; }
1221
+ double scr_promise_payload_num(const ScrPromise *p) { return p->f64; }
1222
+ bool scr_promise_payload_flag(const ScrPromise *p) { return p->b; }
1223
+ bool scr_promise_await_settled(ScrPromise *p) { return scr_await_settled(p); }
1224
+ void scr_promise_payload_release(const ScrPromise *p, void *v) { p->release_fn(v); }
1225
+
1226
+ void *scr_promise_payload_ref(ScrPromise *p) {
1227
+ return p->payload ? p->retain_fn(p->payload) : NULL;
1228
+ }
1229
+
1230
+ /* MOVES a pending exception out of `cell` into `p` as its rejection payload
1231
+ * (the cell resets to NONE). Shared by fiber completion and the new-Promise
1232
+ * executor runners; callers wake waiters themselves. */
1233
+ static void scr_promise_reject_from_cell(ScrPromise *p, ScrExcCell *cell) {
1234
+ p->state = SCR_PROM_REJECTED;
1235
+ p->payload_kind = cell->kind;
1236
+ p->f64 = cell->f64;
1237
+ p->b = cell->b;
1238
+ p->payload = cell->payload;
1239
+ p->retain_fn = cell->retain_fn;
1240
+ p->release_fn = cell->release_fn;
1241
+ p->trace_fn = cell->trace_fn;
1242
+ cell->kind = SCR_EXC_NONE;
1243
+ cell->payload = NULL;
1244
+ cell->trace_fn = NULL;
1245
+ }
1246
+
1247
+ static void scr_fiber_finish(ScrFiber *self) {
1248
+ if (self->gen != NULL) {
1249
+ /* Generator completion: the emitted trampoline already stored the
1250
+ * completion value (or consumed the GENRET sentinel); a real body
1251
+ * exception stays pending in this fiber's cell — the consumer-side
1252
+ * resume moves it into the resumer's cell. No promise to settle. */
1253
+ self->done = true;
1254
+ return;
1255
+ }
1256
+ ScrPromise *p = self->promise;
1257
+ if (scr_exc_pending()) {
1258
+ /* The body's exception escaped: the promise rejects with the payload
1259
+ * (moved from the fiber's cell into the promise). */
1260
+ scr_promise_reject_from_cell(p, &self->exc);
1261
+ }
1262
+ /* Fulfillment payload was stored by the trampoline before finishing. */
1263
+ scr_promise_settle_wake(p);
1264
+ self->done = true;
1265
+ }
1266
+
1267
+ #ifdef _WIN32
1268
+ static void CALLBACK scr_trampoline(void *param) {
1269
+ (void)param;
1270
+ #else
1271
+ static void scr_trampoline(void) {
1272
+ #endif
1273
+ #ifdef SCR_ASAN_FIBERS
1274
+ const void *ob;
1275
+ size_t os;
1276
+ __sanitizer_finish_switch_fiber(scr_current->fake_stack, &ob, &os);
1277
+ #endif
1278
+ ScrFiber *self = scr_current;
1279
+ self->entry(self, self->argpack);
1280
+ scr_fiber_finish(self);
1281
+ /* Dead fiber: hop back to whoever resumed us. The loop frees us. */
1282
+ scr_switch(&self->ctx, self->return_to, NULL);
1283
+ /* unreachable */
1284
+ }
1285
+
1286
+ #if !defined(_WIN32) && !defined(__wasi__)
1287
+ /* Apple Silicon's makecontext clears all of uc_stack before installing the
1288
+ * initial registers. Passing the whole mapping eagerly commits 256 KiB
1289
+ * (8 MiB under ASan) per call, defeating the lazy allocation above. Its
1290
+ * zero-argument startup frame only needs the top of the downward-growing
1291
+ * stack. Initialize that window, then publish the FULL stack bounds before
1292
+ * any execution or sanitizer switch. The stack top and saved SP are the
1293
+ * same as when initializing the full mapping; ordinary calls can still
1294
+ * use all of SCR_FIBER_STACK.
1295
+ * See libplatform/src/ucontext/generic/makecontext.c's arm64 implementation. */
1296
+ static void scr_fiber_context_init(ScrFiber *f) {
1297
+ f->stack = scr_fiber_stack_new();
1298
+ if (getcontext(&f->ctx) != 0) scr_trap("scriptc: getcontext failed\n");
1299
+ f->ctx.uc_stack.ss_sp = f->stack;
1300
+ f->ctx.uc_stack.ss_size = SCR_FIBER_STACK;
1301
+ f->ctx.uc_stack.ss_flags = 0;
1302
+ f->ctx.uc_link = NULL;
1303
+ #if defined(__APPLE__) && defined(__aarch64__)
1304
+ const size_t bootstrap = 16 * 1024;
1305
+ f->ctx.uc_stack.ss_sp = f->stack + SCR_FIBER_STACK - bootstrap;
1306
+ f->ctx.uc_stack.ss_size = bootstrap;
1307
+ #endif
1308
+ makecontext(&f->ctx, scr_trampoline, 0);
1309
+ f->ctx.uc_stack.ss_sp = f->stack;
1310
+ f->ctx.uc_stack.ss_size = SCR_FIBER_STACK;
1311
+ }
1312
+ #endif
1313
+
1314
+ /* Frees a finished fiber's execution resources (the promise release and
1315
+ * bookkeeping stay at the call sites). Windows: DeleteFiber tears down the
1316
+ * fiber object and its stack — legal here because a finished fiber has
1317
+ * switched away and can never be current again. */
1318
+ static void scr_fiber_destroy(ScrFiber *f) {
1319
+ #ifdef _WIN32
1320
+ DeleteFiber(f->ctx);
1321
+ #elif defined(__wasi__)
1322
+ if (f->coro != NULL) scr_wasi_coro_destroy(f->coro);
1323
+ #endif
1324
+ scr_als_ctx_release(f->als);
1325
+ #if !defined(_WIN32) && !defined(__wasi__)
1326
+ scr_fiber_stack_free(f->stack);
1327
+ #else
1328
+ free(f->stack);
1329
+ #endif
1330
+ free(f);
1331
+ }
1332
+
1333
+ /* Spawns and EAGERLY runs an async body until its first suspension (JS's
1334
+ * synchronous-prefix rule). Returns the fiber's promise, +1. */
1335
+ ScrPromise *scr_async_spawn(void (*entry)(ScrFiber *, void *), void *argpack) {
1336
+ ScrFiber *f = calloc(1, sizeof *f);
1337
+ if (!f) scr_oom();
1338
+ f->promise = scr_promise_new();
1339
+ f->entry = entry;
1340
+ f->argpack = argpack;
1341
+ /* AsyncLocalStorage: the child runs in the SPAWNER's context (Node's
1342
+ * init-time capture); snapshots are immutable, so a retain suffices. */
1343
+ f->als = scr_als_ctx_retain(*scr_als_active);
1344
+ scr_fibers_live++;
1345
+
1346
+ #ifdef _WIN32
1347
+ /* Commit one page initially; Windows commits further pages as the stack
1348
+ * grows. Keep the executable's stack reserve, as with CreateFiber,
1349
+ * without committing SCR_FIBER_STACK for every idle fiber. */
1350
+ ScrCtx here = scr_win_self();
1351
+ f->ctx = CreateFiberEx(4096, 0, 0, scr_trampoline, NULL);
1352
+ if (f->ctx == NULL) scr_oom();
1353
+ #elif defined(__wasi__)
1354
+ ScrFiber *spawner = scr_current;
1355
+ scr_current = f;
1356
+ scr_exc_swap_cell(&f->exc);
1357
+ scr_als_active = &f->als;
1358
+ entry(f, argpack); /* eager prefix; returns at suspend/final suspend */
1359
+ scr_current = spawner;
1360
+ scr_exc_swap_cell(spawner ? &spawner->exc : NULL);
1361
+ scr_als_active = spawner ? &spawner->als : &scr_als_main_slot;
1362
+ ScrPromise *result = scr_promise_retain(f->promise);
1363
+ if (f->done) {
1364
+ scr_promise_release(f->promise);
1365
+ scr_fiber_destroy(f);
1366
+ scr_fibers_live--;
1367
+ }
1368
+ return result;
1369
+ #else
1370
+ scr_fiber_context_init(f);
1371
+
1372
+ ucontext_t here;
1373
+ #endif
1374
+ #ifndef __wasi__
1375
+ f->return_to = &here;
1376
+ ScrFiber *spawner = scr_current;
1377
+ scr_switch(&here, &f->ctx, f);
1378
+ /* back: the fiber suspended or finished. The switch back targeted NULL
1379
+ * (the child doesn't know who spawned it), which pointed both the current
1380
+ * fiber AND the exception machinery at main — restore the spawner's cell
1381
+ * too, or a fiber that eagerly spawned another keeps throwing/catching
1382
+ * against main's cell and completes with its own cell empty (a phantom
1383
+ * `undefined` rejection while the real payload leaks). */
1384
+ scr_current = spawner;
1385
+ scr_exc_swap_cell(spawner ? &spawner->exc : NULL);
1386
+ scr_als_active = spawner ? &spawner->als : &scr_als_main_slot;
1387
+ ScrPromise *result = scr_promise_retain(f->promise);
1388
+ if (f->done) {
1389
+ scr_promise_release(f->promise);
1390
+ scr_fiber_destroy(f);
1391
+ scr_fibers_live--;
1392
+ }
1393
+ return result;
1394
+ #endif
1395
+ }
1396
+
1397
+ /* A runtime-authored C continuation whose first operation awaits one known
1398
+ * dependency. Native fibers can park normally. wasm32 has no resumable C
1399
+ * stack, so queue the fiber only after the dependency settles; the entry's
1400
+ * await then extracts the result without attempting a stack switch. The
1401
+ * READY queue supplies the settled-await microtask hop in both cases. */
1402
+ ScrPromise *scr_async_spawn_after(ScrPromise *dependency,
1403
+ void (*entry)(ScrFiber *, void *),
1404
+ void *argpack) {
1405
+ #ifndef __wasi__
1406
+ (void)dependency;
1407
+ return scr_async_spawn(entry, argpack);
1408
+ #else
1409
+ ScrFiber *f = calloc(1, sizeof *f);
1410
+ if (!f) scr_oom();
1411
+ f->promise = scr_promise_new();
1412
+ f->entry = entry;
1413
+ f->argpack = argpack;
1414
+ f->als = scr_als_ctx_retain(*scr_als_active);
1415
+ scr_fibers_live++;
1416
+
1417
+ if (dependency->state == SCR_PROM_PENDING) {
1418
+ if (dependency->nwaiters == dependency->waiters_cap) {
1419
+ dependency->waiters_cap = dependency->waiters_cap ? dependency->waiters_cap * 2 : 4;
1420
+ dependency->waiters = realloc(
1421
+ dependency->waiters, dependency->waiters_cap * sizeof *dependency->waiters);
1422
+ if (!dependency->waiters) scr_oom();
1423
+ }
1424
+ dependency->waiters[dependency->nwaiters++] = f;
1425
+ } else {
1426
+ scr_ready_push(f);
1427
+ }
1428
+ return scr_promise_retain(f->promise);
1429
+ #endif
1430
+ }
1431
+
1432
+ /* Parks the current fiber on `p` until it settles. Only fibers await. */
1433
+ static void scr_await_park(ScrPromise *p) {
1434
+ ScrFiber *self = scr_current;
1435
+ if (!self) {
1436
+ fputs("scriptc: internal error: await outside an async function\n", stderr);
1437
+ abort();
1438
+ }
1439
+ if (p->nwaiters == p->waiters_cap) {
1440
+ p->waiters_cap = p->waiters_cap ? p->waiters_cap * 2 : 4;
1441
+ p->waiters = realloc(p->waiters, p->waiters_cap * sizeof *p->waiters);
1442
+ if (!p->waiters) scr_oom();
1443
+ }
1444
+ p->waiters[p->nwaiters++] = self;
1445
+ scr_switch(&self->ctx, self->return_to, NULL);
1446
+ /* Resumed by the loop: return_to must now point at the loop's context. */
1447
+ }
1448
+
1449
+ #ifdef __wasi__
1450
+ /* The emitted coroutine suspends immediately after these preparation
1451
+ * calls. Settled promises still queue one ready turn; pending promises own
1452
+ * the continuation through their waiter list. */
1453
+ void scr_wasi_await_prepare(ScrFiber *self, ScrPromise *p) {
1454
+ if (p->state == SCR_PROM_PENDING) {
1455
+ if (p->nwaiters == p->waiters_cap) {
1456
+ p->waiters_cap = p->waiters_cap ? p->waiters_cap * 2 : 4;
1457
+ p->waiters = realloc(p->waiters, p->waiters_cap * sizeof *p->waiters);
1458
+ if (!p->waiters) scr_oom();
1459
+ }
1460
+ p->waiters[p->nwaiters++] = self;
1461
+ } else {
1462
+ scr_ready_push(self);
1463
+ }
1464
+ }
1465
+
1466
+ void scr_wasi_await_hop_prepare(ScrFiber *self) { scr_ready_push(self); }
1467
+
1468
+ bool scr_wasi_module_await_prepare(ScrFiber *self, ScrPromise *p) {
1469
+ if (p->state != SCR_PROM_PENDING) return false;
1470
+ scr_wasi_await_prepare(self, p);
1471
+ return true;
1472
+ }
1473
+
1474
+ void scr_wasi_async_finish(ScrFiber *self) { scr_fiber_finish(self); }
1475
+
1476
+ void scr_wasi_gen_finish(ScrFiber *self) {
1477
+ if (scr_exc_genret_pending()) {
1478
+ scr_exc_clear();
1479
+ scr_gen_ret_to_out(self->gen);
1480
+ }
1481
+ scr_fiber_finish(self);
1482
+ }
1483
+ #endif
1484
+
1485
+ /* One microtask hop: park the current fiber on the READY queue itself and
1486
+ * yield. JS's `await` ALWAYS suspends — even on an already-settled promise
1487
+ * the continuation runs as a microtask — so without this hop an awaiter of
1488
+ * a settled promise would continue synchronously inside the spawner,
1489
+ * observably earlier than Node (corpus 1428 pins the ordering). */
1490
+ static void scr_await_yield(void) {
1491
+ ScrFiber *self = scr_current;
1492
+ if (!self) {
1493
+ fputs("scriptc: internal error: await outside an async function\n", stderr);
1494
+ abort();
1495
+ }
1496
+ scr_ready_push(self);
1497
+ scr_switch(&self->ctx, self->return_to, NULL);
1498
+ }
1499
+
1500
+ /* The emitted promise-or-absent await's unit arm (`await u` where u holds
1501
+ * undefined/null): JS awaits non-thenables through exactly one microtask
1502
+ * turn — the same hop a settled promise takes. */
1503
+ void scr_await_hop(void) { scr_await_yield(); }
1504
+
1505
+ /* Copies a rejection into the active execution context's exception cell.
1506
+ * The payload is RETAINED, not moved — a promise can be awaited more than
1507
+ * once, and the executable's top-level completion probe consumes the same
1508
+ * settlement from the main stack after the loop drains. */
1509
+ static void scr_promise_rethrow(ScrPromise *p) {
1510
+ switch (p->payload_kind) {
1511
+ case SCR_EXC_F64: scr_throw_f64(p->f64); break;
1512
+ case SCR_EXC_BOOL: scr_throw_bool(p->b); break;
1513
+ case SCR_EXC_STR: scr_throw_str(scr_str_retain((ScrStr *)p->payload)); break;
1514
+ case SCR_EXC_REF: scr_throw_ref(p->retain_fn(p->payload), p->retain_fn, p->release_fn, p->trace_fn); break;
1515
+ case SCR_EXC_PRIMITIVE_REF: scr_throw_primitive_ref(p->retain_fn(p->payload), p->retain_fn, p->release_fn, p->trace_fn); break;
1516
+ case SCR_EXC_OBJ: scr_throw_obj(p->retain_fn(p->payload), p->retain_fn, p->release_fn, p->trace_fn); break;
1517
+ case SCR_EXC_NONE:
1518
+ case SCR_EXC_GENRET: /* unreachable: the sentinel never settles a promise */
1519
+ scr_throw_str(scr_str_new("undefined", 9));
1520
+ break;
1521
+ }
1522
+ }
1523
+
1524
+ /* Await result extraction. Rejection re-throws into the awaiter. */
1525
+ static bool scr_await_settled(ScrPromise *p) {
1526
+ #ifdef __wasi__
1527
+ if (p->state == SCR_PROM_PENDING) {
1528
+ fputs("scriptc: internal error: resumed before awaited promise settled\n", stderr);
1529
+ abort();
1530
+ }
1531
+ #else
1532
+ if (p->state != SCR_PROM_PENDING) scr_await_yield();
1533
+ while (p->state == SCR_PROM_PENDING) scr_await_park(p);
1534
+ #endif
1535
+ scr_prom_observe(p);
1536
+ if (p->state == SCR_PROM_REJECTED) {
1537
+ scr_promise_rethrow(p);
1538
+ return false;
1539
+ }
1540
+ return true;
1541
+ }
1542
+
1543
+ double scr_await_f64(ScrPromise *p) {
1544
+ return scr_await_settled(p) ? p->f64 : 0;
1545
+ }
1546
+ bool scr_await_bool(ScrPromise *p) {
1547
+ return scr_await_settled(p) ? p->b : false;
1548
+ }
1549
+ void *scr_await_ref(ScrPromise *p) {
1550
+ return scr_await_settled(p) && p->payload ? p->retain_fn(p->payload) : NULL;
1551
+ }
1552
+ void scr_await_void(ScrPromise *p) { scr_await_settled(p); }
1553
+
1554
+ /* ECMAScript's INTERNAL module-dependency wait. Unlike a user-authored
1555
+ * await, an already-completed dependency does not introduce a promise-job
1556
+ * hop: the evaluator continues synchronously into the importer. A pending
1557
+ * dependency still parks this module fiber, and rejection propagates into
1558
+ * it exactly like an ordinary await. */
1559
+ void scr_module_await(ScrPromise *p) {
1560
+ #ifndef __wasi__
1561
+ while (p->state == SCR_PROM_PENDING) scr_await_park(p);
1562
+ #endif
1563
+ scr_prom_observe(p);
1564
+ if (p->state == SCR_PROM_REJECTED) scr_promise_rethrow(p);
1565
+ }
1566
+
1567
+ int scr_promise_finish_top_level(ScrPromise *p) {
1568
+ if (p->state == SCR_PROM_PENDING) {
1569
+ /* ECMAScript module evaluation is still pending, but Node's ref'd
1570
+ * event-loop work is exhausted. Node exits with its dedicated
1571
+ * unsettled-top-level-await status. */
1572
+ scr_exit_code_note(13);
1573
+ return 13;
1574
+ }
1575
+ scr_prom_observe(p);
1576
+ return p->state == SCR_PROM_REJECTED && !p->top_level_handled ? 1 : 0;
1577
+ }
1578
+
1579
+ void scr_promise_rethrow_top_level(ScrPromise *p) {
1580
+ if (p->state == SCR_PROM_REJECTED) scr_promise_rethrow(p);
1581
+ }
1582
+
1583
+
1584
+
1585
+
1586
+
1587
+ /* Fulfillment storers, called by the compiled trampolines / resolve thunks. */
1588
+ void scr_promise_fulfill_f64(ScrPromise *p, double v) {
1589
+ if (p->state != SCR_PROM_PENDING) return; /* first settle wins */
1590
+ p->state = SCR_PROM_FULFILLED;
1591
+ p->payload_kind = SCR_EXC_F64;
1592
+ p->f64 = v;
1593
+ scr_promise_settle_wake(p);
1594
+ }
1595
+ void scr_promise_fulfill_bool(ScrPromise *p, bool v) {
1596
+ if (p->state != SCR_PROM_PENDING) return;
1597
+ p->state = SCR_PROM_FULFILLED;
1598
+ p->payload_kind = SCR_EXC_BOOL;
1599
+ p->b = v;
1600
+ scr_promise_settle_wake(p);
1601
+ }
1602
+ void scr_promise_fulfill_ref(ScrPromise *p, void *v, void *(*retain)(void *), void (*release)(void *), ScrTraceFn trace) {
1603
+ if (p->state != SCR_PROM_PENDING) {
1604
+ if (release) release(v); /* value was +1 for us; drop it */
1605
+ return;
1606
+ }
1607
+ p->state = SCR_PROM_FULFILLED;
1608
+ p->payload_kind = v ? SCR_EXC_REF : SCR_EXC_NONE;
1609
+ p->payload = v;
1610
+ p->retain_fn = retain;
1611
+ p->release_fn = release;
1612
+ p->trace_fn = trace;
1613
+ scr_promise_settle_wake(p);
1614
+ }
1615
+ void scr_promise_fulfill_void(ScrPromise *p) {
1616
+ if (p->state != SCR_PROM_PENDING) return;
1617
+ p->state = SCR_PROM_FULFILLED;
1618
+ p->payload_kind = SCR_EXC_NONE;
1619
+ scr_promise_settle_wake(p);
1620
+ }
1621
+
1622
+ /* String payloads ride the STR kind so awaits type them precisely. */
1623
+ void scr_promise_fulfill_str(ScrPromise *p, ScrStr *v) {
1624
+ if (p->state != SCR_PROM_PENDING) {
1625
+ scr_str_release(v);
1626
+ return;
1627
+ }
1628
+ p->state = SCR_PROM_FULFILLED;
1629
+ p->payload_kind = SCR_EXC_STR;
1630
+ p->payload = v; /* ownership moves in */
1631
+ p->retain_fn = (void *(*)(void *))scr_str_retain;
1632
+ p->release_fn = (void (*)(void *))scr_str_release;
1633
+ scr_promise_settle_wake(p);
1634
+ }
1635
+ ScrStr *scr_await_str(ScrPromise *p) {
1636
+ return scr_await_settled(p) && p->payload ? scr_str_retain((ScrStr *)p->payload) : NULL;
1637
+ }
1638
+
1639
+ /* REJECTS `p` with the exception pending in the ACTIVE cell (moved out —
1640
+ * the cell resets, so the caller returns to the engine/loop with a clean
1641
+ * cell) and wakes waiters; the rejection enters the unhandled ledger like
1642
+ * any other. The island → static promise bridge's rejection half: its
1643
+ * settle callback converts the engine reason into a pending exception
1644
+ * (the exception bridge's one conversion), then lands it here. A no-op
1645
+ * with nothing pending; an already-settled `p` just clears the cell
1646
+ * (first settle wins, like resolve-then-throw). */
1647
+ void scr_promise_reject_pending(ScrPromise *p) {
1648
+ if (!scr_exc_pending()) return;
1649
+ if (p->state == SCR_PROM_PENDING) {
1650
+ scr_promise_reject_from_cell(p, scr_exc_current_cell());
1651
+ scr_promise_settle_wake(p);
1652
+ } else {
1653
+ scr_exc_clear();
1654
+ }
1655
+ }
1656
+
1657
+ /* ── settled-promise minting (the fs/promises bridge) ─────────────────
1658
+ * The promise-returning stdlib functions run their syscall SYNCHRONOUSLY
1659
+ * (the documented non-interleaving divergence, SEMANTICS.md) and wrap the
1660
+ * outcome here: a pending exception in the active cell becomes the
1661
+ * promise's REJECTION (moved out of the cell — the caller's pending check
1662
+ * then sees a clean cell, exactly like Node where fs/promises failures
1663
+ * reject instead of throwing), anything else fulfills with the payload.
1664
+ * The rejected case still enters the unhandled-rejection ledger, so a
1665
+ * never-awaited failure reports at exit like any other rejection. */
1666
+
1667
+ static ScrPromise *scr_promise_settled_common(void) {
1668
+ if (!scr_exc_pending()) return NULL;
1669
+ ScrPromise *p = scr_promise_new();
1670
+ scr_promise_reject_from_cell(p, scr_exc_current_cell());
1671
+ scr_promise_settle_wake(p); /* no waiters yet; enters the ledger */
1672
+ return p;
1673
+ }
1674
+
1675
+ ScrPromise *scr_promise_settled_str(ScrStr *v) {
1676
+ ScrPromise *rejected = scr_promise_settled_common();
1677
+ if (rejected) {
1678
+ scr_str_release(v); /* NULL-tolerant; the op returned a dummy */
1679
+ return rejected;
1680
+ }
1681
+ ScrPromise *p = scr_promise_new();
1682
+ scr_promise_fulfill_str(p, v); /* moves in */
1683
+ return p;
1684
+ }
1685
+
1686
+ ScrPromise *scr_promise_settled_void(void) {
1687
+ ScrPromise *rejected = scr_promise_settled_common();
1688
+ if (rejected) return rejected;
1689
+ ScrPromise *p = scr_promise_new();
1690
+ scr_promise_fulfill_void(p);
1691
+ return p;
1692
+ }
1693
+
1694
+ ScrPromise *scr_promise_settled_ref(void *v, void *(*retain)(void *), void (*release)(void *),
1695
+ ScrTraceFn trace) {
1696
+ ScrPromise *rejected = scr_promise_settled_common();
1697
+ if (rejected) {
1698
+ if (v && release) release(v);
1699
+ return rejected;
1700
+ }
1701
+ ScrPromise *p = scr_promise_new();
1702
+ scr_promise_fulfill_ref(p, v, retain, release, trace); /* moves in */
1703
+ return p;
1704
+ }
1705
+
1706
+ /* ── fs/promises ─────────────────────────────────────────────────────
1707
+ * The promise forms run the SAME sync operations and mint an already-
1708
+ * settled promise (scr_promise_settled_*): success fulfills, a pending
1709
+ * exception moves in as the rejection — catchable at the await, like
1710
+ * Node. DOCUMENTED DIVERGENCE (SEMANTICS.md): the syscall blocks the
1711
+ * event loop, so I/O never interleaves with timers or other fibers —
1712
+ * observable only in concurrent code, not in the sequential await
1713
+ * chains CLIs are made of. */
1714
+
1715
+ ScrPromise *scr_fsp_read_file(ScrStr *path) {
1716
+ return scr_promise_settled_str(scr_fs_read_file(path));
1717
+ }
1718
+
1719
+ ScrPromise *scr_fsp_write_file(ScrStr *path, ScrStr *data) {
1720
+ scr_fs_write_file(path, data);
1721
+ return scr_promise_settled_void();
1722
+ }
1723
+
1724
+ ScrPromise *scr_fsp_write_file_mode(ScrStr *path, ScrStr *data, double mode) {
1725
+ scr_fs_write_file_mode(path, data, mode);
1726
+ return scr_promise_settled_void();
1727
+ }
1728
+
1729
+ ScrPromise *scr_fsp_mkdir(ScrStr *path) {
1730
+ scr_fs_mkdir(path);
1731
+ return scr_promise_settled_void();
1732
+ }
1733
+
1734
+ ScrPromise *scr_fsp_mkdir_mode(ScrStr *path, double mode) {
1735
+ scr_fs_mkdir_mode(path, mode);
1736
+ return scr_promise_settled_void();
1737
+ }
1738
+
1739
+ ScrPromise *scr_fsp_mkdir_recursive(ScrStr *path) {
1740
+ scr_fs_mkdir_recursive(path);
1741
+ return scr_promise_settled_void();
1742
+ }
1743
+
1744
+ ScrPromise *scr_fsp_mkdir_recursive_mode(ScrStr *path, double mode) {
1745
+ scr_fs_mkdir_recursive_mode(path, mode);
1746
+ return scr_promise_settled_void();
1747
+ }
1748
+
1749
+ ScrPromise *scr_fsp_unlink(ScrStr *path) {
1750
+ scr_fs_unlink(path);
1751
+ return scr_promise_settled_void();
1752
+ }
1753
+
1754
+ ScrPromise *scr_fsp_chmod(ScrStr *path, double mode) {
1755
+ scr_fs_chmod(path, mode);
1756
+ return scr_promise_settled_void();
1757
+ }
1758
+
1759
+ ScrPromise *scr_fsp_readdir(ScrStr *path) {
1760
+ ScrArr *names = scr_fs_readdir(path);
1761
+ return scr_promise_settled_ref(names, &scr_arr_retain_v, &scr_arr_release_v, NULL);
1762
+ }
1763
+
1764
+ ScrPromise *scr_fsp_rm(ScrStr *path) {
1765
+ scr_fs_rm(path);
1766
+ return scr_promise_settled_void();
1767
+ }
1768
+
1769
+ ScrPromise *scr_fsp_stat(ScrStr *path) {
1770
+ ScrStats *st = scr_fs_stat(path);
1771
+ return scr_promise_settled_ref(st, &scr_stats_retain_v, &scr_stats_release_v, NULL);
1772
+ }
1773
+
1774
+ ScrPromise *scr_fsp_realpath(ScrStr *path) {
1775
+ return scr_promise_settled_str(scr_fs_realpath_promise(path));
1776
+ }
1777
+
1778
+ ScrPromise *scr_fsp_lstat(ScrStr *path) {
1779
+ ScrStats *st = scr_fs_lstat(path);
1780
+ return scr_promise_settled_ref(st, &scr_stats_retain_v, &scr_stats_release_v, NULL);
1781
+ }
1782
+
1783
+ ScrPromise *scr_fsp_rename(ScrStr *oldpath, ScrStr *newpath) {
1784
+ scr_fs_rename(oldpath, newpath);
1785
+ return scr_promise_settled_void();
1786
+ }
1787
+
1788
+ /* Shared native work queue, initially introduced by fs.rename and also used
1789
+ * by node:zlib's callback codecs. Work starts immediately on a native worker,
1790
+ * matching libuv's key contract while JS/main is synchronously occupied.
1791
+ * Error/Buffer construction, callback invocation, and every RC mutation stay
1792
+ * on the main runtime thread when a later loop turn observes completion.
1793
+ *
1794
+ * A compact operation queue is also the liveness handle: an outstanding
1795
+ * callback-style request keeps the loop alive. Four persistent workers mirror
1796
+ * libuv's default pool size without creating one OS thread per request. A
1797
+ * platform mutex publishes each result before the loop removes it from the
1798
+ * completion queue. */
1799
+ #if !defined(SCR_LIB) && !defined(__wasi__)
1800
+ typedef struct ScrFsRenameOp {
1801
+ bool generic;
1802
+ bool ran;
1803
+ void *payload;
1804
+ ScrWorkFn work;
1805
+ ScrWorkFn after;
1806
+ ScrWorkFn destroy;
1807
+ ScrStr *oldpath;
1808
+ ScrStr *newpath;
1809
+ ScrClosure *cb;
1810
+ ScrFsRenameFn fn;
1811
+ int error;
1812
+ struct ScrFsRenameOp *next;
1813
+ } ScrFsRenameOp;
1814
+
1815
+ static ScrFsRenameOp *scr_fs_rename_work = NULL;
1816
+ static ScrFsRenameOp **scr_fs_rename_work_tail = &scr_fs_rename_work;
1817
+ static ScrFsRenameOp *scr_fs_rename_done = NULL;
1818
+ static ScrFsRenameOp **scr_fs_rename_done_tail = &scr_fs_rename_done;
1819
+ static size_t scr_fs_rename_pending_count = 0;
1820
+ static size_t scr_fs_rename_worker_count = 0;
1821
+ static bool scr_fs_rename_stopping = false;
1822
+ static bool scr_fs_rename_shutdown_registered = false;
1823
+
1824
+ #ifdef _WIN32
1825
+ static HANDLE scr_fs_rename_workers[4];
1826
+ static SRWLOCK scr_fs_rename_lock = SRWLOCK_INIT;
1827
+ static CONDITION_VARIABLE scr_fs_rename_cond = CONDITION_VARIABLE_INIT;
1828
+ static void scr_fs_rename_lock_enter(void) { AcquireSRWLockExclusive(&scr_fs_rename_lock); }
1829
+ static void scr_fs_rename_lock_leave(void) { ReleaseSRWLockExclusive(&scr_fs_rename_lock); }
1830
+ static void scr_fs_rename_wait(void) {
1831
+ (void)SleepConditionVariableSRW(&scr_fs_rename_cond, &scr_fs_rename_lock, INFINITE, 0);
1832
+ }
1833
+ static void scr_fs_rename_signal(void) { WakeConditionVariable(&scr_fs_rename_cond); }
1834
+ static void scr_fs_rename_broadcast(void) { WakeAllConditionVariable(&scr_fs_rename_cond); }
1835
+ #else
1836
+ static pthread_t scr_fs_rename_workers[4];
1837
+ static pthread_mutex_t scr_fs_rename_lock = PTHREAD_MUTEX_INITIALIZER;
1838
+ static pthread_cond_t scr_fs_rename_cond = PTHREAD_COND_INITIALIZER;
1839
+ static void scr_fs_rename_lock_enter(void) { (void)pthread_mutex_lock(&scr_fs_rename_lock); }
1840
+ static void scr_fs_rename_lock_leave(void) { (void)pthread_mutex_unlock(&scr_fs_rename_lock); }
1841
+ static void scr_fs_rename_wait(void) {
1842
+ (void)pthread_cond_wait(&scr_fs_rename_cond, &scr_fs_rename_lock);
1843
+ }
1844
+ static void scr_fs_rename_signal(void) { (void)pthread_cond_signal(&scr_fs_rename_cond); }
1845
+ static void scr_fs_rename_broadcast(void) { (void)pthread_cond_broadcast(&scr_fs_rename_cond); }
1846
+ #endif
1847
+
1848
+ static void scr_fs_rename_op_release(ScrFsRenameOp *op) {
1849
+ if (op->generic) {
1850
+ op->destroy(op->payload);
1851
+ free(op);
1852
+ return;
1853
+ }
1854
+ scr_str_release(op->oldpath);
1855
+ scr_str_release(op->newpath);
1856
+ scr_closure_release(op->cb);
1857
+ free(op);
1858
+ }
1859
+
1860
+ static void scr_fs_rename_worker_loop(void) {
1861
+ for (;;) {
1862
+ scr_fs_rename_lock_enter();
1863
+ while (scr_fs_rename_work == NULL && !scr_fs_rename_stopping) scr_fs_rename_wait();
1864
+ if (scr_fs_rename_stopping) {
1865
+ scr_fs_rename_lock_leave();
1866
+ return;
1867
+ }
1868
+ ScrFsRenameOp *op = scr_fs_rename_work;
1869
+ scr_fs_rename_work = op->next;
1870
+ if (scr_fs_rename_work == NULL) scr_fs_rename_work_tail = &scr_fs_rename_work;
1871
+ scr_fs_rename_lock_leave();
1872
+
1873
+ if (op->generic) op->work(op->payload);
1874
+ else op->error = scr_fs_rename_raw(op->oldpath, op->newpath);
1875
+ op->ran = true;
1876
+
1877
+ scr_fs_rename_lock_enter();
1878
+ op->next = NULL;
1879
+ *scr_fs_rename_done_tail = op;
1880
+ scr_fs_rename_done_tail = &op->next;
1881
+ scr_fs_rename_lock_leave();
1882
+ }
1883
+ }
1884
+
1885
+ #ifdef _WIN32
1886
+ static DWORD WINAPI scr_fs_rename_worker(LPVOID payload) {
1887
+ (void)payload;
1888
+ scr_fs_rename_worker_loop();
1889
+ return 0;
1890
+ }
1891
+ #else
1892
+ static void *scr_fs_rename_worker(void *payload) {
1893
+ (void)payload;
1894
+ scr_fs_rename_worker_loop();
1895
+ return NULL;
1896
+ }
1897
+ #endif
1898
+
1899
+ /* Runs before the ordinary runtime atexit cleanup/audit (it is registered
1900
+ * lazily by the first rename request, after scr_init/scr_lib_init). Fatal
1901
+ * top-level or callback exceptions can stop the loop with requests still in
1902
+ * flight; join the workers before releasing their retained path/callback
1903
+ * payloads so sanitized builds keep the program's real exit verdict. */
1904
+ static void scr_fs_renames_shutdown(void) {
1905
+ scr_fs_rename_lock_enter();
1906
+ scr_fs_rename_stopping = true;
1907
+ scr_fs_rename_broadcast();
1908
+ scr_fs_rename_lock_leave();
1909
+
1910
+ for (size_t i = 0; i < scr_fs_rename_worker_count; i++) {
1911
+ #ifdef _WIN32
1912
+ (void)WaitForSingleObject(scr_fs_rename_workers[i], INFINITE);
1913
+ CloseHandle(scr_fs_rename_workers[i]);
1914
+ #else
1915
+ (void)pthread_join(scr_fs_rename_workers[i], NULL);
1916
+ #endif
1917
+ }
1918
+
1919
+ scr_fs_rename_lock_enter();
1920
+ ScrFsRenameOp *work = scr_fs_rename_work;
1921
+ ScrFsRenameOp *done = scr_fs_rename_done;
1922
+ scr_fs_rename_work = NULL;
1923
+ scr_fs_rename_work_tail = &scr_fs_rename_work;
1924
+ scr_fs_rename_done = NULL;
1925
+ scr_fs_rename_done_tail = &scr_fs_rename_done;
1926
+ scr_fs_rename_pending_count = 0;
1927
+ scr_fs_rename_lock_leave();
1928
+ while (work != NULL) {
1929
+ ScrFsRenameOp *next = work->next;
1930
+ scr_fs_rename_op_release(work);
1931
+ work = next;
1932
+ }
1933
+ while (done != NULL) {
1934
+ ScrFsRenameOp *next = done->next;
1935
+ scr_fs_rename_op_release(done);
1936
+ done = next;
1937
+ }
1938
+ }
1939
+
1940
+ static bool scr_fs_renames_pending(void) { return scr_fs_rename_pending_count != 0; }
1941
+
1942
+ static bool scr_fs_renames_dispatch(void) {
1943
+ scr_fs_rename_lock_enter();
1944
+ ScrFsRenameOp *op = scr_fs_rename_done;
1945
+ if (op != NULL) {
1946
+ scr_fs_rename_done = op->next;
1947
+ if (scr_fs_rename_done == NULL) scr_fs_rename_done_tail = &scr_fs_rename_done;
1948
+ }
1949
+ scr_fs_rename_lock_leave();
1950
+ if (op == NULL) return false;
1951
+ scr_fs_rename_pending_count--;
1952
+ if (op->generic) {
1953
+ if (!op->ran) op->work(op->payload);
1954
+ op->after(op->payload);
1955
+ scr_fs_rename_op_release(op);
1956
+ return true;
1957
+ }
1958
+ ScrCaught *caught = NULL;
1959
+ ScrError *err = NULL;
1960
+ if (op->error != 0) {
1961
+ scr_fs_rename_error(op->error, op->oldpath, op->newpath);
1962
+ caught = scr_exc_take();
1963
+ if (caught && caught->kind == SCR_EXC_OBJ && scr_error_is(caught->payload)) {
1964
+ err = (ScrError *)caught->payload;
1965
+ }
1966
+ }
1967
+ op->fn(op->cb, err);
1968
+ scr_caught_release(caught);
1969
+ scr_fs_rename_op_release(op);
1970
+ return true;
1971
+ }
1972
+
1973
+ static void scr_work_submit_op(ScrFsRenameOp *op) {
1974
+ if (!scr_fs_rename_shutdown_registered) {
1975
+ if (atexit(scr_fs_renames_shutdown) != 0) {
1976
+ scr_trap("scriptc: could not register worker cleanup\n");
1977
+ }
1978
+ scr_fs_rename_shutdown_registered = true;
1979
+ }
1980
+ scr_fs_rename_pending_count++;
1981
+ scr_fs_rename_lock_enter();
1982
+ *scr_fs_rename_work_tail = op;
1983
+ scr_fs_rename_work_tail = &op->next;
1984
+ int create_error = 0;
1985
+ if (scr_fs_rename_worker_count < 4) {
1986
+ #ifdef _WIN32
1987
+ HANDLE worker = CreateThread(NULL, 0, scr_fs_rename_worker, NULL, 0, NULL);
1988
+ if (worker != NULL) {
1989
+ scr_fs_rename_workers[scr_fs_rename_worker_count] = worker;
1990
+ scr_fs_rename_worker_count++;
1991
+ } else {
1992
+ create_error = EAGAIN;
1993
+ }
1994
+ #else
1995
+ pthread_t worker;
1996
+ create_error = pthread_create(&worker, NULL, scr_fs_rename_worker, NULL);
1997
+ if (create_error == 0) {
1998
+ scr_fs_rename_workers[scr_fs_rename_worker_count] = worker;
1999
+ scr_fs_rename_worker_count++;
2000
+ }
2001
+ #endif
2002
+ }
2003
+ if (create_error != 0 && scr_fs_rename_worker_count == 0) {
2004
+ /* Submission failure remains asynchronous. Rename preserves its
2005
+ * resource error; generic work falls back to the main loop turn. */
2006
+ while (scr_fs_rename_work != NULL) {
2007
+ ScrFsRenameOp *failed = scr_fs_rename_work;
2008
+ scr_fs_rename_work = failed->next;
2009
+ failed->error = create_error;
2010
+ failed->ran = !failed->generic;
2011
+ failed->next = NULL;
2012
+ *scr_fs_rename_done_tail = failed;
2013
+ scr_fs_rename_done_tail = &failed->next;
2014
+ }
2015
+ scr_fs_rename_work_tail = &scr_fs_rename_work;
2016
+ } else {
2017
+ scr_fs_rename_signal();
2018
+ }
2019
+ scr_fs_rename_lock_leave();
2020
+ }
2021
+ #elif defined(__wasi__)
2022
+ /* WASI Preview 1 has no threads, but rename itself is available. Queue the
2023
+ * request and perform it on the next loop turn so callback timing remains
2024
+ * asynchronous and the request remains a liveness handle. */
2025
+ typedef struct ScrFsRenameOp {
2026
+ bool generic;
2027
+ void *payload;
2028
+ ScrWorkFn work;
2029
+ ScrWorkFn after;
2030
+ ScrWorkFn destroy;
2031
+ ScrStr *oldpath;
2032
+ ScrStr *newpath;
2033
+ ScrClosure *cb;
2034
+ ScrFsRenameFn fn;
2035
+ struct ScrFsRenameOp *next;
2036
+ } ScrFsRenameOp;
2037
+
2038
+ static ScrFsRenameOp *scr_fs_rename_done = NULL;
2039
+ static ScrFsRenameOp **scr_fs_rename_done_tail = &scr_fs_rename_done;
2040
+ static size_t scr_fs_rename_pending_count = 0;
2041
+
2042
+ static bool scr_fs_renames_pending(void) { return scr_fs_rename_pending_count != 0; }
2043
+
2044
+ static bool scr_fs_renames_dispatch(void) {
2045
+ ScrFsRenameOp *op = scr_fs_rename_done;
2046
+ if (op == NULL) return false;
2047
+ scr_fs_rename_done = op->next;
2048
+ if (scr_fs_rename_done == NULL) scr_fs_rename_done_tail = &scr_fs_rename_done;
2049
+ scr_fs_rename_pending_count--;
2050
+
2051
+ if (op->generic) {
2052
+ op->work(op->payload);
2053
+ op->after(op->payload);
2054
+ op->destroy(op->payload);
2055
+ free(op);
2056
+ return true;
2057
+ }
2058
+
2059
+ int error = scr_fs_rename_raw(op->oldpath, op->newpath);
2060
+ ScrCaught *caught = NULL;
2061
+ ScrError *err = NULL;
2062
+ if (error != 0) {
2063
+ scr_fs_rename_error(error, op->oldpath, op->newpath);
2064
+ caught = scr_exc_take();
2065
+ if (caught && caught->kind == SCR_EXC_OBJ && scr_error_is(caught->payload)) {
2066
+ err = (ScrError *)caught->payload;
2067
+ }
2068
+ }
2069
+ op->fn(op->cb, err);
2070
+ scr_caught_release(caught);
2071
+ scr_str_release(op->oldpath);
2072
+ scr_str_release(op->newpath);
2073
+ scr_closure_release(op->cb);
2074
+ free(op);
2075
+ return true;
2076
+ }
2077
+ #else
2078
+ static bool scr_fs_renames_pending(void) { return false; }
2079
+ static bool scr_fs_renames_dispatch(void) { return false; }
2080
+ #endif
2081
+
2082
+ void scr_fs_rename_async(ScrStr *oldpath, ScrStr *newpath,
2083
+ ScrClosure *cb, ScrFsRenameFn fn) {
2084
+ #if defined(SCR_LIB)
2085
+ (void)oldpath; (void)newpath; (void)fn;
2086
+ scr_closure_release(cb);
2087
+ scr_trap("scriptc: callback-style fs.rename is not supported by this target\n");
2088
+ #elif defined(__wasi__)
2089
+ ScrFsRenameOp *op = calloc(1, sizeof *op);
2090
+ if (!op) scr_trap("scriptc: out of memory\n");
2091
+ op->oldpath = scr_str_retain(oldpath);
2092
+ op->newpath = scr_str_retain(newpath);
2093
+ op->cb = cb;
2094
+ op->fn = fn;
2095
+ *scr_fs_rename_done_tail = op;
2096
+ scr_fs_rename_done_tail = &op->next;
2097
+ scr_fs_rename_pending_count++;
2098
+ #else
2099
+ ScrFsRenameOp *op = calloc(1, sizeof *op);
2100
+ if (!op) scr_trap("scriptc: out of memory\n");
2101
+ op->oldpath = scr_str_retain(oldpath);
2102
+ op->newpath = scr_str_retain(newpath);
2103
+ op->cb = cb;
2104
+ op->fn = fn;
2105
+ scr_work_submit_op(op);
2106
+ #endif
2107
+ }
2108
+
2109
+ void scr_work_submit(void *payload, ScrWorkFn work, ScrWorkFn after,
2110
+ ScrWorkFn destroy) {
2111
+ #if defined(SCR_LIB)
2112
+ (void)work; (void)after;
2113
+ destroy(payload);
2114
+ scr_trap("scriptc: native worker jobs are not supported by this target\n");
2115
+ #elif defined(__wasi__)
2116
+ ScrFsRenameOp *op = calloc(1, sizeof *op);
2117
+ if (!op) scr_trap("scriptc: out of memory\n");
2118
+ op->generic = true;
2119
+ op->payload = payload;
2120
+ op->work = work;
2121
+ op->after = after;
2122
+ op->destroy = destroy;
2123
+ *scr_fs_rename_done_tail = op;
2124
+ scr_fs_rename_done_tail = &op->next;
2125
+ scr_fs_rename_pending_count++;
2126
+ #else
2127
+ ScrFsRenameOp *op = calloc(1, sizeof *op);
2128
+ if (!op) scr_trap("scriptc: out of memory\n");
2129
+ op->generic = true;
2130
+ op->payload = payload;
2131
+ op->work = work;
2132
+ op->after = after;
2133
+ op->destroy = destroy;
2134
+ scr_work_submit_op(op);
2135
+ #endif
2136
+ }
2137
+
2138
+ void scr_fs_rename_thunk0(ScrClosure *cb, ScrError *err) {
2139
+ (void)err;
2140
+ ((void (*)(ScrClosure *))cb->fn)(cb);
2141
+ }
2142
+
2143
+ /* Callback-style crypto completions. The operation validates and computes
2144
+ * before enqueueing; delivery is a later macrotask, never synchronous with
2145
+ * the API call. The queue owns both references and transfers the Buffer to
2146
+ * the emitted callback adapter. */
2147
+ typedef struct ScrCryptoBytesOp {
2148
+ ScrBytes *value;
2149
+ ScrClosure *cb;
2150
+ ScrCryptoBytesFn fn;
2151
+ struct ScrCryptoBytesOp *next;
2152
+ } ScrCryptoBytesOp;
2153
+
2154
+ static ScrCryptoBytesOp *scr_crypto_bytes_head = NULL;
2155
+ static ScrCryptoBytesOp **scr_crypto_bytes_tail = &scr_crypto_bytes_head;
2156
+ static size_t scr_crypto_bytes_pending_count = 0;
2157
+ static bool scr_crypto_bytes_cleanup_registered = false;
2158
+
2159
+ static void scr_crypto_bytes_shutdown(void) {
2160
+ while (scr_crypto_bytes_head != NULL) {
2161
+ ScrCryptoBytesOp *op = scr_crypto_bytes_head;
2162
+ scr_crypto_bytes_head = op->next;
2163
+ scr_bytes_release(op->value);
2164
+ scr_closure_release(op->cb);
2165
+ free(op);
2166
+ }
2167
+ scr_crypto_bytes_tail = &scr_crypto_bytes_head;
2168
+ scr_crypto_bytes_pending_count = 0;
2169
+ }
2170
+
2171
+ static bool scr_crypto_bytes_pending(void) {
2172
+ return scr_crypto_bytes_pending_count != 0;
2173
+ }
2174
+
2175
+ static bool scr_crypto_bytes_dispatch(void) {
2176
+ ScrCryptoBytesOp *op = scr_crypto_bytes_head;
2177
+ if (op == NULL) return false;
2178
+ scr_crypto_bytes_head = op->next;
2179
+ if (scr_crypto_bytes_head == NULL) scr_crypto_bytes_tail = &scr_crypto_bytes_head;
2180
+ scr_crypto_bytes_pending_count--;
2181
+ op->fn(op->cb, op->value); /* adapter consumes value */
2182
+ scr_closure_release(op->cb);
2183
+ free(op);
2184
+ return true;
2185
+ }
2186
+
2187
+ void scr_crypto_defer_bytes(ScrBytes *value, ScrClosure *cb, ScrCryptoBytesFn fn) {
2188
+ if (!scr_crypto_bytes_cleanup_registered) {
2189
+ if (atexit(scr_crypto_bytes_shutdown) != 0) {
2190
+ scr_bytes_release(value);
2191
+ scr_closure_release(cb);
2192
+ scr_trap("scriptc: could not register crypto callback cleanup\n");
2193
+ }
2194
+ scr_crypto_bytes_cleanup_registered = true;
2195
+ }
2196
+ ScrCryptoBytesOp *op = malloc(sizeof *op);
2197
+ if (!op) {
2198
+ scr_bytes_release(value);
2199
+ scr_closure_release(cb);
2200
+ scr_trap("scriptc: out of memory\n");
2201
+ }
2202
+ op->value = value;
2203
+ op->cb = cb;
2204
+ op->fn = fn;
2205
+ op->next = NULL;
2206
+ *scr_crypto_bytes_tail = op;
2207
+ scr_crypto_bytes_tail = &op->next;
2208
+ scr_crypto_bytes_pending_count++;
2209
+ }
2210
+
2211
+ /* ── node:timers/promises ────────────────────────────────────────────
2212
+ * The promisified pair: a PENDING void promise a one-shot heap timer
2213
+ * (setTimeout) or the immediate queue (setImmediate) fulfills — the
2214
+ * resolve closure is scr_make_resolve's void thunk, so settlement wakes
2215
+ * awaiting fibers exactly like every other promise, and the armed
2216
+ * timer/immediate keeps the loop alive until it fires (Node: an awaited
2217
+ * timers/promises sleep holds the process open). Neither throws; the
2218
+ * delay rides scr_set_timeout's own Node-exact coercion (clamp to 1,
2219
+ * truncate). */
2220
+
2221
+ ScrPromise *scr_tp_set_timeout(double ms) {
2222
+ ScrPromise *p = scr_promise_new();
2223
+ scr_set_timeout(scr_make_resolve(p, 3 /* void */), ms);
2224
+ return p;
2225
+ }
2226
+
2227
+ ScrPromise *scr_tp_set_immediate(void) {
2228
+ ScrPromise *p = scr_promise_new();
2229
+ scr_set_immediate(scr_make_resolve(p, 3 /* void */));
2230
+ return p;
2231
+ }
2232
+
2233
+ /* ── setImmediate as a first-class dyn value ─────────────────────────
2234
+ * The global passed AS A FUNCTION VALUE into untyped code (the Node-suite
2235
+ * traceCallback shape: `channel.traceCallback(setImmediate, 0, ctx, null,
2236
+ * cb)`). The minted dyn callable schedules its own immediate that calls
2237
+ * args[0] with the remaining arguments (Node's setImmediate(cb, ...args)
2238
+ * contract) and answers undefined (the Immediate handle object has no dyn
2239
+ * story — clearImmediate over this value is not modeled). A non-function
2240
+ * first argument throws Node's ERR_INVALID_ARG_TYPE synchronously. */
2241
+
2242
+ static void scr_imm_dyn_fire(ScrClosure *c) {
2243
+ ScrDyn *fn = (ScrDyn *)scr_box_get_ref(c->caps[0]);
2244
+ ScrDyn *args = (ScrDyn *)scr_box_get_ref(c->caps[1]);
2245
+ ScrDyn *r = scr_dyn_call(fn, args->v.arr.items, args->v.arr.len, "immediate callback");
2246
+ if (r != NULL) scr_dyn_release(r);
2247
+ scr_dyn_release(fn);
2248
+ scr_dyn_release(args);
2249
+ }
2250
+
2251
+ static ScrDyn *scr_imm_dyn_thunk(ScrClosure *clo, ScrDyn *const *args, size_t argc) {
2252
+ (void)clo;
2253
+ if (argc == 0 || args[0]->kind != SCR_DYN_FUNC) {
2254
+ static const char msg[] = "The \"callback\" argument must be of type function.";
2255
+ scr_throw_error_msg_code(SCR_ERR_TYPE, msg, sizeof msg - 1, "ERR_INVALID_ARG_TYPE");
2256
+ return NULL;
2257
+ }
2258
+ ScrDyn *rest = scr_dyn_new_arr();
2259
+ for (size_t i = 1; i < argc; i++) scr_dyn_arr_push(rest, scr_dyn_retain(args[i]));
2260
+ ScrClosure *c = scr_closure_new((void *)scr_imm_dyn_fire, 2);
2261
+ c->caps[0] = scr_box_new_obj(scr_dyn_retain_v, scr_dyn_release_v, NULL);
2262
+ scr_box_set_ref(c->caps[0], scr_dyn_retain(args[0]));
2263
+ c->caps[1] = scr_box_new_obj(scr_dyn_retain_v, scr_dyn_release_v, NULL);
2264
+ scr_box_set_ref(c->caps[1], rest); /* moves */
2265
+ scr_set_immediate(c);
2266
+ return scr_dyn_retain(scr_dyn_undefined());
2267
+ }
2268
+
2269
+ ScrDyn *scr_set_immediate_dyn_value(void) {
2270
+ return scr_dyn_new_func(scr_closure_new((void *)scr_imm_dyn_thunk, 0), scr_imm_dyn_thunk,
2271
+ 1, "(cb,...)", "setImmediate");
2272
+ }
2273
+
2274
+ /* ── queueMicrotask ──────────────────────────────────────────────────
2275
+ * The READY queue's FIFO is the microtask queue (promise continuations
2276
+ * ride it as parked fibers), so a queueMicrotask callback enters the SAME
2277
+ * queue as a stackless envelope — one order across both producers, like
2278
+ * V8's single microtask queue. scr_resume_fiber runs the closure on the
2279
+ * main stack; a throw is an uncaught exception (Node's queueMicrotask),
2280
+ * never a rejection. */
2281
+ void scr_queue_microtask(ScrClosure *cb) {
2282
+ ScrFiber *f = calloc(1, sizeof *f);
2283
+ if (!f) scr_oom();
2284
+ f->micro_cb = cb; /* ownership moves in */
2285
+ scr_ready_push(f);
2286
+ }
2287
+
2288
+ /* The checked-dynamic argument form (JS files — common.mustCall wrappers
2289
+ * and the suite's invalid-input probes): a non-function throws Node's
2290
+ * ERR_INVALID_ARG_TYPE synchronously; a function value is called with
2291
+ * zero arguments (Node passes none — extra queueMicrotask arguments are
2292
+ * ignored). */
2293
+ static void scr_micro_dyn_fire(ScrClosure *c) {
2294
+ ScrDyn *fn = (ScrDyn *)scr_box_get_ref(c->caps[0]);
2295
+ ScrDyn *r = scr_dyn_call(fn, NULL, 0, "queueMicrotask callback");
2296
+ if (r != NULL) scr_dyn_release(r);
2297
+ scr_dyn_release(fn);
2298
+ }
2299
+
2300
+ void scr_queue_microtask_dyn(const ScrDyn *cb) {
2301
+ if (cb->kind != SCR_DYN_FUNC) {
2302
+ static const char msg[] = "The \"callback\" argument must be of type function.";
2303
+ scr_throw_error_msg_code(SCR_ERR_TYPE, msg, sizeof msg - 1, "ERR_INVALID_ARG_TYPE");
2304
+ return;
2305
+ }
2306
+ ScrClosure *c = scr_closure_new((void *)scr_micro_dyn_fire, 1);
2307
+ c->caps[0] = scr_box_new_obj(scr_dyn_retain_v, scr_dyn_release_v, NULL);
2308
+ scr_box_set_ref(c->caps[0], scr_dyn_retain((ScrDyn *)cb));
2309
+ scr_queue_microtask(c);
2310
+ }
2311
+
2312
+ /* ── the event hooks (scr_events.c) ──────────────────────────────────
2313
+ * Process signal/exit events and the piped-stdin surface live in
2314
+ * scr_events.c, which links ONLY into binaries whose IR uses those
2315
+ * surfaces (the io-hook precedent, gated like scr_regex/scr_fetch):
2316
+ * scr_events_install() fills these slots before %main. Event-free
2317
+ * builds keep every slot NULL and the loop is byte-identical in
2318
+ * behavior. The scr_lib.c hooks live in scr_lib.c and the abnormal-exit
2319
+ * code hint in scr_exception.c, so each unit stays self-contained (the
2320
+ * runtime C tests link them separately). */
2321
+
2322
+ static bool (*scr_events_pending_fn)(void) = NULL; /* keeps the loop alive */
2323
+ static bool (*scr_events_watching_fn)(void) = NULL; /* wants the poll sleep */
2324
+ static void (*scr_events_dispatch_fn)(void) = NULL; /* fire due listeners */
2325
+ static int (*scr_events_pollfds_fn)(int out[2]) = NULL;
2326
+
2327
+ void scr_loop_set_events(bool (*pending)(void), bool (*watching)(void),
2328
+ void (*dispatch)(void), int (*pollfds)(int out[2])) {
2329
+ scr_events_pending_fn = pending;
2330
+ scr_events_watching_fn = watching;
2331
+ scr_events_dispatch_fn = dispatch;
2332
+ scr_events_pollfds_fn = pollfds;
2333
+ }
2334
+
2335
+ /* ── the event loop ───────────────────────────────────────────────────── */
2336
+
2337
+ static void scr_resume_fiber(ScrFiber *f) {
2338
+ if (f->gen_job != NULL) {
2339
+ ScrGen *g = f->gen_job;
2340
+ free(f);
2341
+ scr_async_gen_job(g);
2342
+ scr_gen_release(g);
2343
+ return;
2344
+ }
2345
+ /* A queueMicrotask envelope: run the closure on the main stack, no
2346
+ * context switch. A throw leaves the exception cell pending — every
2347
+ * drain site returns to main's uncaught report, Node's queueMicrotask
2348
+ * semantics (uncaughtException, never an unhandled rejection). */
2349
+ if (f->micro_cb != NULL) {
2350
+ ScrClosure *cb = f->micro_cb;
2351
+ free(f);
2352
+ ((void (*)(ScrClosure *))cb->fn)(cb);
2353
+ scr_closure_release(cb);
2354
+ return;
2355
+ }
2356
+ if (f->gen != NULL) {
2357
+ scr_async_gen_resume_ready(f->gen);
2358
+ return;
2359
+ }
2360
+ #ifdef _WIN32
2361
+ /* The loop runs on the main stack; make sure scr_loop_ctx names its
2362
+ * fiber handle (a no-op after the first conversion). */
2363
+ (void)scr_win_self();
2364
+ #endif
2365
+ f->return_to = &scr_loop_ctx;
2366
+ #ifdef __wasi__
2367
+ scr_current = f;
2368
+ scr_exc_swap_cell(&f->exc);
2369
+ scr_als_active = &f->als;
2370
+ if (f->coro != NULL) {
2371
+ scr_wasi_coro_resume(f->coro);
2372
+ } else {
2373
+ /* scr_async_spawn_after's runtime C continuation. Its dependency is
2374
+ * settled, so the entry can extract through scr_await_* without a
2375
+ * stack switch and then completes in this turn. */
2376
+ f->entry(f, f->argpack);
2377
+ scr_fiber_finish(f);
2378
+ }
2379
+ scr_current = NULL;
2380
+ scr_exc_swap_cell(NULL);
2381
+ scr_als_active = &scr_als_main_slot;
2382
+ #else
2383
+ scr_switch(&scr_loop_ctx, &f->ctx, f);
2384
+ #endif
2385
+ if (f->done) {
2386
+ scr_promise_release(f->promise);
2387
+ scr_fiber_destroy(f);
2388
+ scr_fibers_live--;
2389
+ }
2390
+ }
2391
+
2392
+ /* Reap granularity while children are pending on the POLLING fallback:
2393
+ * the loop polls waitpid(WNOHANG) at least this often instead of sleeping
2394
+ * to the next timer deadline. The primary path has no cap — the sleep
2395
+ * waits on the child watch (scr_children_wait — kqueue NOTE_EXIT on BSD,
2396
+ * pidfd epoll on Linux, the timer deadline riding the wait timeout) and a
2397
+ * child's exit wakes it immediately. The fallback covers platforms with
2398
+ * neither backend, children whose exit watch could not be armed, and
2399
+ * turns where the io poll takes the sleep (curl's fds can't join it). */
2400
+ #define SCR_CHILD_POLL_MS 1.0
2401
+
2402
+ /* Sleep cap while only external io is pending (no timer models its
2403
+ * wakeup): the io poll sleeps on REAL fds inside this window (a fetch
2404
+ * transfer's sockets wake it early), so a generous cap costs nothing. */
2405
+ #define SCR_IO_POLL_MS 1000.0
2406
+
2407
+ /* Sleep cap while signal handlers or stdin consumers are pending AND the
2408
+ * io poll owns the sleep (curl's fd wait retries on EINTR and can't watch
2409
+ * the wake pipe): bounded signal/stdin latency during a fetch at 20
2410
+ * wakeups/second. The dedicated poll(2) sleep needs no cap — it waits on
2411
+ * the wake pipe and fd 0 directly. */
2412
+ #define SCR_SIGNAL_POLL_MS 50.0
2413
+
2414
+ /* The external io hook (scr_runtime.h): the dynamic island registers
2415
+ * engine-job draining + fetch transfer polling here. Static builds never
2416
+ * set it — both slots stay NULL and the loop is byte-identical in
2417
+ * behavior. */
2418
+ static bool (*scr_io_pending_fn)(void) = NULL;
2419
+ static void (*scr_io_poll_fn)(double max_wait_ms) = NULL;
2420
+
2421
+ void scr_loop_set_io(bool (*pending)(void), void (*poll)(double)) {
2422
+ scr_io_pending_fn = pending;
2423
+ scr_io_poll_fn = poll;
2424
+ }
2425
+
2426
+ /* The island's earliest armed timer deadline (HUGE_VAL when none): caps
2427
+ * the sleep below so an armed AbortSignal.timeout fires on time while
2428
+ * the loop waits on socket readiness — without keeping the loop alive by
2429
+ * itself (the liveness test never consults it, Node's unref'd timer). */
2430
+ static double (*scr_island_deadline_fn)(void) = NULL;
2431
+
2432
+ void scr_loop_set_island_deadline(double (*fn)(void)) { scr_island_deadline_fn = fn; }
2433
+
2434
+ /* The net hook (scr_net.c, when linked — the events-hook shape):
2435
+ * `pending` keeps the loop alive while servers/sockets are live,
2436
+ * `dispatch` fires at every turn top, and `pollfd` is the unit's poller
2437
+ * fd for the idle poll(2) sleep (readable while events are pending —
2438
+ * kqueue and epoll fds both behave this way).
2439
+ * Net-free builds keep every slot NULL and the loop is byte-identical. */
2440
+ static bool (*scr_net_pending_fn)(void) = NULL;
2441
+ static void (*scr_net_dispatch_fn)(void) = NULL;
2442
+ static int (*scr_net_pollfd_fn)(void) = NULL;
2443
+
2444
+ void scr_loop_set_net(bool (*pending)(void), void (*dispatch)(void), int (*pollfd)(void)) {
2445
+ scr_net_pending_fn = pending;
2446
+ scr_net_dispatch_fn = dispatch;
2447
+ scr_net_pollfd_fn = pollfd;
2448
+ }
2449
+
2450
+ /* The dgram hook (scr_dgram.c, when linked) — the net hook's exact shape:
2451
+ * one more set of nullable slots, byte-identical loop behavior when
2452
+ * unset. */
2453
+ static bool (*scr_dgram_pending_fn)(void) = NULL;
2454
+ static void (*scr_dgram_dispatch_fn)(void) = NULL;
2455
+ static int (*scr_dgram_pollfd_fn)(void) = NULL;
2456
+
2457
+ void scr_loop_set_dgram(bool (*pending)(void), void (*dispatch)(void), int (*pollfd)(void)) {
2458
+ scr_dgram_pending_fn = pending;
2459
+ scr_dgram_dispatch_fn = dispatch;
2460
+ scr_dgram_pollfd_fn = pollfd;
2461
+ }
2462
+
2463
+ /* The fs.watch hook (scr_watch.c, when linked) — the net hook's exact
2464
+ * shape: one more set of nullable slots, byte-identical loop behavior
2465
+ * when unset. */
2466
+ static bool (*scr_watch_pending_fn)(void) = NULL;
2467
+ static void (*scr_watch_dispatch_fn)(void) = NULL;
2468
+ static int (*scr_watch_pollfd_fn)(void) = NULL;
2469
+
2470
+ void scr_loop_set_watch(bool (*pending)(void), void (*dispatch)(void), int (*pollfd)(void)) {
2471
+ scr_watch_pending_fn = pending;
2472
+ scr_watch_dispatch_fn = dispatch;
2473
+ scr_watch_pollfd_fn = pollfd;
2474
+ }
2475
+
2476
+ /* The foreign-FFI queue hook (scr_ffi.c when a format-5 descriptor exists).
2477
+ * Its pending count includes live registrations (reffed by default) and
2478
+ * queued deliveries; dispatch runs exactly one callback per loop turn. */
2479
+ static bool (*scr_ffi_pending_fn)(void) = NULL;
2480
+ static bool (*scr_ffi_dispatch_fn)(void) = NULL;
2481
+ static int (*scr_ffi_pollfd_fn)(void) = NULL;
2482
+ static void (*scr_ffi_stop_fn)(void) = NULL;
2483
+
2484
+ void scr_loop_set_ffi(bool (*pending)(void), bool (*dispatch)(void),
2485
+ int (*pollfd)(void), void (*stop)(void)) {
2486
+ scr_ffi_pending_fn = pending;
2487
+ scr_ffi_dispatch_fn = dispatch;
2488
+ scr_ffi_pollfd_fn = pollfd;
2489
+ scr_ffi_stop_fn = stop;
2490
+ }
2491
+
2492
+ /* The stream hook (scr_stream.c, when linked): `pending` keeps the loop
2493
+ * alive while deferred stream ticks exist, `dispatch` drains them at the
2494
+ * TOP of every turn — before the events/net stations, the closest
2495
+ * placement to Node's process.nextTick (whose stream emissions these
2496
+ * are). No poller fd: ticks are pure CPU work, always ready. */
2497
+ static bool (*scr_stream_pending_fn)(void) = NULL;
2498
+ static void (*scr_stream_dispatch_fn)(void) = NULL;
2499
+
2500
+ void scr_loop_set_stream(bool (*pending)(void), void (*dispatch)(void)) {
2501
+ scr_stream_pending_fn = pending;
2502
+ scr_stream_dispatch_fn = dispatch;
2503
+ }
2504
+
2505
+ /* Dispatch hooks yield between event batches when fibers are already
2506
+ * queued, so promise jobs interleave with event delivery (Node's
2507
+ * microtask checkpoints between macrotasks). */
2508
+ bool scr_loop_has_ready(void) { return scr_ready_len > 0; }
2509
+
2510
+ static bool scr_loop_run_pass(ScrPromise *top_level, bool first_checkpoint) {
2511
+ /* The FIRST checkpoint after the synchronous main body runs promise
2512
+ * jobs BEFORE the first tick drain: Node's main-module evaluation is
2513
+ * itself awaited (the runMain continuation is a microtask queued after
2514
+ * the body's own), so microtasks scheduled during the body beat ticks
2515
+ * scheduled during the body exactly once, at startup — differentially
2516
+ * pinned. Every later checkpoint drains ticks first. */
2517
+ bool rejection_failed = false;
2518
+ for (;;) {
2519
+ if (top_level != NULL && top_level->state == SCR_PROM_REJECTED) break;
2520
+ /* process.nextTick callbacks BEFORE promise jobs (Node's checkpoint
2521
+ * order): the tick queue to exhaustion, then the microtask queue to
2522
+ * exhaustion, and back while either has work — a microtask's
2523
+ * nextTick runs before the turn proceeds, but never preempts the
2524
+ * microtask queue mid-drain (V8 drains it fully). A tick's uncaught
2525
+ * throw ends the loop like any listener's (main reports it). */
2526
+ if (!first_checkpoint) {
2527
+ while (scr_nt_head != NULL) {
2528
+ ScrNtick *t = scr_nt_head;
2529
+ scr_nt_head = t->next;
2530
+ if (scr_nt_head == NULL) scr_nt_tail = NULL;
2531
+ ScrClosure *cb = t->cb;
2532
+ ScrFsRenameFn error_cb = t->error_cb;
2533
+ void (*raw)(void) = t->raw;
2534
+ free(t);
2535
+ if (cb) {
2536
+ if (error_cb) error_cb(cb, NULL);
2537
+ else ((void (*)(ScrClosure *))cb->fn)(cb);
2538
+ scr_closure_release(cb);
2539
+ } else {
2540
+ raw(); /* one stream tick, FIFO with the user ticks around it */
2541
+ }
2542
+ if (scr_exc_pending()) return false;
2543
+ }
2544
+ }
2545
+ /* Microtasks to exhaustion (Node: promise jobs before timers). */
2546
+ while (scr_ready_len > 0) {
2547
+ ScrFiber *f = scr_ready[scr_ready_head++];
2548
+ scr_ready_len--;
2549
+ scr_resume_fiber(f);
2550
+ }
2551
+ first_checkpoint = false;
2552
+ /* The ESM loader observes a rejected entry evaluation at a promise-job
2553
+ * checkpoint and terminates before later ref'd timers or I/O can run.
2554
+ * Wait until this checkpoint's ready queue is drained — the root's
2555
+ * rejection handler is itself promise-job ordered — then leave through
2556
+ * the normal teardown below. A fulfilled root deliberately does not
2557
+ * stop the loop. */
2558
+ if (top_level != NULL && top_level->state == SCR_PROM_REJECTED) break;
2559
+ if (scr_nt_head != NULL) continue;
2560
+ /* Node decides unhandled rejections at the END of each complete
2561
+ * nextTick/microtask checkpoint, before advancing to timers or I/O.
2562
+ * A rejected executable module root wins over OTHER rejections from
2563
+ * this same checkpoint (the root check above); rejections from an
2564
+ * earlier checkpoint have already delivered here. Handled listeners
2565
+ * may enqueue more jobs or ref'd work, so return to the checkpoint
2566
+ * head instead of declaring the loop exhausted underneath them. */
2567
+ if (scr_report_unhandled_rejections()) {
2568
+ rejection_failed = true;
2569
+ break;
2570
+ }
2571
+ if (scr_ready_len > 0 || scr_nt_head != NULL || scr_nunhandled > 0) continue;
2572
+ /* Quiescent between turns (microtasks drained, nothing running):
2573
+ * collect any cycles the turn left behind. One SCHEDULED pass — almost
2574
+ * always a nursery one, sized to the turn's own garbage. A full sweep
2575
+ * here would walk the whole live heap every turn, which is precisely
2576
+ * what the generations exist to avoid. No-op on an empty buffer. */
2577
+ scr_cyc_collect_scheduled();
2578
+ /* Completed callback-style worker jobs are delivered on the main
2579
+ * runtime thread. A worker may have finished while synchronous user code
2580
+ * occupied that thread. Deliver exactly one completion per checkpoint:
2581
+ * Node drains nextTicks and microtasks after each native callback before
2582
+ * invoking the next ready callback. */
2583
+ if (scr_fs_renames_pending()) {
2584
+ bool dispatched = scr_fs_renames_dispatch();
2585
+ if (scr_exc_pending()) return false;
2586
+ if (dispatched) continue;
2587
+ }
2588
+ if (scr_crypto_bytes_pending()) {
2589
+ bool dispatched = scr_crypto_bytes_dispatch();
2590
+ if (scr_exc_pending()) return false;
2591
+ if (dispatched) continue;
2592
+ }
2593
+ /* Foreign native callbacks are macrotasks. Deliver one, then restart at
2594
+ * the microtask checkpoint before considering the next queued post. */
2595
+ if (scr_ffi_dispatch_fn != NULL && scr_ffi_dispatch_fn()) {
2596
+ if (scr_exc_pending()) return false;
2597
+ if (scr_ready_len > 0 || scr_nt_head != NULL || scr_nunhandled > 0) continue;
2598
+ }
2599
+ /* Stream tick dispatch (scr_stream.c, when linked): the deferred
2600
+ * next-tick emissions ('data' flow kicks, 'readable'/'end'/'finish'/
2601
+ * 'drain'/'error'/'close') fire now, FIRST — the nextTick station.
2602
+ * Listeners may enqueue microtasks or more ticks — restart the turn
2603
+ * so those drain first. */
2604
+ if (scr_stream_dispatch_fn != NULL) {
2605
+ scr_stream_dispatch_fn();
2606
+ if (scr_exc_pending()) return false; /* uncaught throw in a listener */
2607
+ if (scr_ready_len > 0) continue;
2608
+ if (scr_stream_pending_fn != NULL && scr_stream_pending_fn()) continue;
2609
+ }
2610
+ /* Event dispatch (scr_events.c, when linked): watched signals
2611
+ * delivered since the last turn fire their listeners now (macrotasks,
2612
+ * like timers), then stdin — while a consumer exists, probe fd 0 and
2613
+ * deliver one arrived chunk / the EOF events. Both may enqueue
2614
+ * microtasks — restart the turn so those drain first. */
2615
+ if (scr_events_dispatch_fn != NULL) {
2616
+ scr_events_dispatch_fn();
2617
+ if (scr_exc_pending()) return false; /* uncaught throw in a listener */
2618
+ if (scr_ready_len > 0) continue;
2619
+ }
2620
+ /* Net dispatch (scr_net.c, when linked): accepts, arrived data,
2621
+ * connect completions, and the deferred listening/error/close emits
2622
+ * fire now (macrotasks, like the events hook). Callbacks may enqueue
2623
+ * microtasks — restart the turn so those drain first. */
2624
+ if (scr_net_dispatch_fn != NULL) {
2625
+ scr_net_dispatch_fn();
2626
+ if (scr_exc_pending()) return false; /* uncaught throw in a listener */
2627
+ if (scr_ready_len > 0) continue;
2628
+ }
2629
+ /* Dgram dispatch (scr_dgram.c, when linked): arrived datagrams and
2630
+ * the deferred listening/connect/error/close emits (plus pending
2631
+ * dns.lookup callbacks) fire now — the net hook's exact station. */
2632
+ if (scr_dgram_dispatch_fn != NULL) {
2633
+ scr_dgram_dispatch_fn();
2634
+ if (scr_exc_pending()) return false; /* uncaught throw in a listener */
2635
+ if (scr_ready_len > 0) continue;
2636
+ }
2637
+ /* Watch dispatch (scr_watch.c, when linked): file events queued on
2638
+ * the unit's event backend fire their FSWatcher listeners now — the
2639
+ * net hook's exact station. */
2640
+ if (scr_watch_dispatch_fn != NULL) {
2641
+ scr_watch_dispatch_fn();
2642
+ if (scr_exc_pending()) return false; /* uncaught throw in a listener */
2643
+ if (scr_ready_len > 0) continue;
2644
+ }
2645
+ /* Reap spawned children and fire their listeners (before timers,
2646
+ * like Node's nextTick-ish spawn-failure "error"). A callback may
2647
+ * enqueue microtasks or spawn again — restart the turn if so.
2648
+ * EXCEPT when ONLY unref'd children remain: Node's liveness check
2649
+ * precedes any further poll/reap, so once nothing reffed holds the
2650
+ * loop their pending exits are DROPPED at loop exit — never
2651
+ * delivered. Without this gate the kill-then-exit shape (a timer's
2652
+ * last act kills an unref'd child) would race machine timing: a
2653
+ * death landing before this sweep fired its 'exit' where Node
2654
+ * deterministically never does. The teardown below releases the
2655
+ * undelivered listeners, so the RC audit stays clean. */
2656
+ if (scr_children_pending()) {
2657
+ bool held =
2658
+ scr_reffed_timers > 0 || scr_reffed_immediates > 0 || scr_children_reffed_pending() ||
2659
+ /* spawn failures settle regardless: their 'error' is a
2660
+ * next-tick event, delivered even on an unref'd child */
2661
+ scr_children_failed_pending() ||
2662
+ (scr_io_pending_fn != NULL && scr_io_pending_fn()) ||
2663
+ (scr_events_pending_fn != NULL && scr_events_pending_fn()) ||
2664
+ (scr_net_pending_fn != NULL && scr_net_pending_fn()) ||
2665
+ (scr_dgram_pending_fn != NULL && scr_dgram_pending_fn()) ||
2666
+ (scr_watch_pending_fn != NULL && scr_watch_pending_fn()) ||
2667
+ (scr_ffi_pending_fn != NULL && scr_ffi_pending_fn()) ||
2668
+ scr_fs_renames_pending() || scr_crypto_bytes_pending();
2669
+ if (held) {
2670
+ scr_children_poll();
2671
+ if (scr_exc_pending()) return false; /* uncaught throw in a listener */
2672
+ if (scr_ready_len > 0) continue;
2673
+ }
2674
+ }
2675
+ /* Deferred stream ticks are always-ready work: never sleep or exit
2676
+ * while any exist (the dispatch above drains them, so reaching here
2677
+ * with ticks pending means a dispatch station enqueued more). User
2678
+ * nextTicks enqueued by a station listener are the same story. */
2679
+ if (scr_stream_pending_fn != NULL && scr_stream_pending_fn()) continue;
2680
+ if (scr_nt_head != NULL) continue;
2681
+ bool kids = scr_children_pending();
2682
+ bool io = scr_io_pending_fn != NULL && scr_io_pending_fn();
2683
+ bool events = scr_events_pending_fn != NULL && scr_events_pending_fn();
2684
+ bool net = scr_net_pending_fn != NULL && scr_net_pending_fn();
2685
+ bool dgram = scr_dgram_pending_fn != NULL && scr_dgram_pending_fn();
2686
+ bool watch = scr_watch_pending_fn != NULL && scr_watch_pending_fn();
2687
+ bool ffi = scr_ffi_pending_fn != NULL && scr_ffi_pending_fn();
2688
+ bool renames = scr_fs_renames_pending();
2689
+ bool crypto = scr_crypto_bytes_pending();
2690
+ /* Timer liveness counts only REF'd timers: an unref'd timer stays in
2691
+ * the heap (and fires if the loop runs on for other reasons) but does
2692
+ * not by itself keep the process alive — Node's unref semantics.
2693
+ * Children follow the same rule: an unref'd child is still REAPED
2694
+ * while the loop runs (kids drives the sweeps and sleeps above) but
2695
+ * only reffed ones keep the process alive. */
2696
+ if (scr_reffed_timers == 0 && scr_reffed_immediates == 0 && !scr_children_reffed_pending() && !io && !events && !net && !dgram && !watch && !ffi && !renames && !crypto) break;
2697
+ /* Sleep to the earliest deadline, then run every due timer (each may
2698
+ * enqueue microtasks, which the next iteration drains first). Who
2699
+ * sleeps depends on what is pending:
2700
+ * - external io: the io POLL takes the sleep — it waits on real fds
2701
+ * up to the deadline (socket readiness wakes it early) and makes
2702
+ * progress (engine jobs, arrived response data) before timers run.
2703
+ * A child's exit can't wake curl's fds, so children re-impose the
2704
+ * reap-granularity cap on this path.
2705
+ * - signals watched or stdin consumed: poll(2) takes the sleep — the
2706
+ * wake pipe, fd 0, and the child watch's fd together, so any of
2707
+ * them ends it immediately (details at the branch).
2708
+ * - children only: the sleep waits on the child watch — the exit
2709
+ * wakeup and the timer deadline together via the wait timeout — so a
2710
+ * child's exit ends the sleep immediately and the next turn's reap
2711
+ * pass fires its listeners. scr_children_wait declines when it
2712
+ * can't wake for every pending child; the ~1ms polling cap is the
2713
+ * fallback.
2714
+ * - timers only: plain nanosleep to the deadline. */
2715
+ double now = scr_now_ms();
2716
+ double due = scr_ntimers > 0 ? scr_timers[0].deadline_ms : now + SCR_IO_POLL_MS;
2717
+ /* The worker pool has no platform poll handle yet. Bound the idle
2718
+ * wait exactly like the portable child fallback so completion is noticed
2719
+ * promptly even when another poller owns the sleep. */
2720
+ if (renames && due > now + SCR_CHILD_POLL_MS) due = now + SCR_CHILD_POLL_MS;
2721
+ /* An armed island timer (AbortSignal.timeout) caps the sleep: it must
2722
+ * fire on time even while the poller waits on socket readiness. */
2723
+ if (scr_island_deadline_fn != NULL) {
2724
+ double isl_due = scr_island_deadline_fn();
2725
+ if (isl_due < due) due = isl_due;
2726
+ }
2727
+ /* Pending immediates are always-ready work: no sleep — run due timers
2728
+ * (Node's timers phase precedes check), then the check phase below. */
2729
+ if (scr_pending_immediates > 0) due = now;
2730
+ /* Child polling can drain a pipe into the IPC queue after its dispatch
2731
+ * station has run. Completed sends and disconnects can also become ready
2732
+ * during that turn. No fd will wake us for this userspace work: return to
2733
+ * dispatch without sleeping, still allowing due timers and immediates. */
2734
+ if (scr_children_ready()) due = now;
2735
+ #if !defined(_WIN32) && !defined(__wasi__)
2736
+ if (due > now) scr_fiber_stacks_clear();
2737
+ #endif
2738
+ bool evw = scr_events_watching_fn != NULL && scr_events_watching_fn();
2739
+ if (io) {
2740
+ if (kids && due > now + SCR_CHILD_POLL_MS) due = now + SCR_CHILD_POLL_MS;
2741
+ /* Signals/stdin/net can't wake curl's fd wait (and its poll retries
2742
+ * on EINTR), so they re-impose a coarser cap — bounded Ctrl-C and
2743
+ * socket latency during a fetch, without the reap-granularity
2744
+ * cost. */
2745
+ else if ((evw || net || dgram || watch || ffi) && due > now + SCR_SIGNAL_POLL_MS) due = now + SCR_SIGNAL_POLL_MS;
2746
+ scr_io_poll_fn(due > now ? due - now : 0);
2747
+ now = scr_now_ms();
2748
+ if (scr_ready_len > 0) continue; /* io callbacks woke fibers */
2749
+ } else if (evw || net || dgram || watch || ffi) {
2750
+ #if defined(_WIN32) || defined(__wasi__)
2751
+ /* The win32 arm, and WASI hosts whose poll_oneoff adapters do not
2752
+ * reliably wake for a closed inherited stdin pipe: the sleep is a capped nanosleep and
2753
+ * the next turn's dispatch does the work — signal flags (set by the
2754
+ * CRT handler on msvcrt's console-ctrl thread) and the stdin probe
2755
+ * at SCR_SIGNAL_POLL_MS granularity (scr_events.c), socket/dgram
2756
+ * readiness at the child-reap cap (scr_loop_wsapoll.c's zero-timeout
2757
+ * WSAPoll drains at dispatch; ~1ms keeps loopback exchanges inside
2758
+ * the granularity Node's IOCP-woken loop delivers, where 50ms could
2759
+ * reorder a socket emit past a short timer). When the caps ever
2760
+ * show up in a profile, the upgrade is a real waitable arm —
2761
+ * WaitForMultipleObjects over WSAEVENTs, or IOCP. */
2762
+ if (evw && due > now + SCR_SIGNAL_POLL_MS) due = now + SCR_SIGNAL_POLL_MS;
2763
+ if ((net || dgram || watch) && due > now + SCR_CHILD_POLL_MS) due = now + SCR_CHILD_POLL_MS;
2764
+ if (ffi && due > now + SCR_CHILD_POLL_MS) due = now + SCR_CHILD_POLL_MS;
2765
+ if (kids && due > now + SCR_CHILD_POLL_MS) due = now + SCR_CHILD_POLL_MS;
2766
+ if (due > now) {
2767
+ double wait = due - now;
2768
+ struct timespec ts = {(time_t)(wait / 1000.0), (long)((wait - (double)((time_t)(wait / 1000.0)) * 1000.0) * 1e6)};
2769
+ nanosleep(&ts, NULL);
2770
+ }
2771
+ now = scr_now_ms();
2772
+ #else
2773
+ /* poll(2) takes the sleep: the events unit's fds — the signal wake
2774
+ * pipe (a signal delivered BEFORE the poll entered still has its
2775
+ * byte in the pipe — no lost-wakeup race) and fd 0 while stdin has
2776
+ * a consumer — plus the child watch's fd when it can represent
2777
+ * every pending child (kqueue and epoll fds poll readable when
2778
+ * events are pending); unrepresentable children keep the ~1ms reap cap
2779
+ * instead. Dispatch happens at the next turn's top — the poll only
2780
+ * decides how long to sleep. */
2781
+ struct pollfd fds[7];
2782
+ int nfds = 0;
2783
+ int evfds[2];
2784
+ int nev = evw && scr_events_pollfds_fn != NULL ? scr_events_pollfds_fn(evfds) : 0;
2785
+ for (int i = 0; i < nev; i++) {
2786
+ fds[nfds].fd = evfds[i];
2787
+ fds[nfds].events = POLLIN;
2788
+ fds[nfds++].revents = 0;
2789
+ }
2790
+ if (net) {
2791
+ /* The net unit's poller fd: readable while socket events are
2792
+ * pending, so arrived data/accepts end the sleep immediately.
2793
+ * Dispatch (which also DRAINS the poller) happens at the next
2794
+ * turn's top — the poll only decides how long to sleep. */
2795
+ int nfd = scr_net_pollfd_fn != NULL ? scr_net_pollfd_fn() : -1;
2796
+ if (nfd >= 0) {
2797
+ fds[nfds].fd = nfd;
2798
+ fds[nfds].events = POLLIN;
2799
+ fds[nfds++].revents = 0;
2800
+ } else if (due > now + SCR_SIGNAL_POLL_MS) {
2801
+ due = now + SCR_SIGNAL_POLL_MS;
2802
+ }
2803
+ }
2804
+ if (dgram) {
2805
+ /* The dgram unit's poller fd — the net slot's exact story. */
2806
+ int dfd = scr_dgram_pollfd_fn != NULL ? scr_dgram_pollfd_fn() : -1;
2807
+ if (dfd >= 0) {
2808
+ fds[nfds].fd = dfd;
2809
+ fds[nfds].events = POLLIN;
2810
+ fds[nfds++].revents = 0;
2811
+ } else if (due > now + SCR_SIGNAL_POLL_MS) {
2812
+ due = now + SCR_SIGNAL_POLL_MS;
2813
+ }
2814
+ }
2815
+ if (watch) {
2816
+ /* The watch unit's event fd — the net slot's exact story. */
2817
+ int wfd = scr_watch_pollfd_fn != NULL ? scr_watch_pollfd_fn() : -1;
2818
+ if (wfd >= 0) {
2819
+ fds[nfds].fd = wfd;
2820
+ fds[nfds].events = POLLIN;
2821
+ fds[nfds++].revents = 0;
2822
+ } else if (due > now + SCR_SIGNAL_POLL_MS) {
2823
+ due = now + SCR_SIGNAL_POLL_MS;
2824
+ }
2825
+ }
2826
+ if (ffi) {
2827
+ int ffd = scr_ffi_pollfd_fn != NULL ? scr_ffi_pollfd_fn() : -1;
2828
+ if (ffd >= 0) {
2829
+ fds[nfds].fd = ffd;
2830
+ fds[nfds].events = POLLIN;
2831
+ fds[nfds++].revents = 0;
2832
+ } else if (due > now + SCR_CHILD_POLL_MS) {
2833
+ due = now + SCR_CHILD_POLL_MS;
2834
+ }
2835
+ }
2836
+ if (kids) {
2837
+ int cfd = scr_children_wake_fd();
2838
+ if (cfd >= 0) {
2839
+ fds[nfds].fd = cfd;
2840
+ fds[nfds].events = POLLIN;
2841
+ fds[nfds++].revents = 0;
2842
+ } else if (due > now + SCR_CHILD_POLL_MS) {
2843
+ due = now + SCR_CHILD_POLL_MS;
2844
+ }
2845
+ }
2846
+ double wait = due > now ? due - now : 0;
2847
+ if (wait > 1e9) wait = 1e9; /* poll takes int ms */
2848
+ (void)poll(fds, (nfds_t)nfds, (int)(wait + 0.999));
2849
+ /* Consume queued child-exit events NOW (zero-timeout drain) — an
2850
+ * unconsumed event keeps the kqueue fd readable and would turn the
2851
+ * next poll into a busy spin while other children still run. The
2852
+ * WNOHANG sweep at the next turn's top stays the reaper. */
2853
+ if (kids) (void)scr_children_wait(0);
2854
+ now = scr_now_ms();
2855
+ #endif /* !_WIN32 && !__wasi__ */
2856
+ } else if (kids && scr_children_wait(due > now ? due - now : 0)) {
2857
+ now = scr_now_ms(); /* woke early on an exit, or hit the deadline */
2858
+ } else {
2859
+ if (kids && due > now + SCR_CHILD_POLL_MS) due = now + SCR_CHILD_POLL_MS;
2860
+ if (due > now) {
2861
+ double wait = due - now;
2862
+ struct timespec ts = {(time_t)(wait / 1000.0), (long)((wait - (double)((time_t)(wait / 1000.0)) * 1000.0) * 1e6)};
2863
+ nanosleep(&ts, NULL);
2864
+ now = due;
2865
+ }
2866
+ }
2867
+ while (scr_ntimers > 0 && scr_timers[0].deadline_ms <= now) {
2868
+ ScrTimer t = scr_timer_pop();
2869
+ /* Timer callbacks are plain sync closures, run on the main stack.
2870
+ * An interval entry is OUT of the heap while its callback runs;
2871
+ * clearInterval(its own id) from inside sets the firing flag and
2872
+ * the re-arm below drops it instead. A throw kills the interval
2873
+ * with the program (Node: the uncaught exception ends the process
2874
+ * before any rescheduled tick could run). */
2875
+ if (t.id != 0) {
2876
+ scr_firing_id = t.id;
2877
+ scr_firing_cleared = false;
2878
+ scr_firing_reffed = t.reffed; /* unref/ref during the callback lands here */
2879
+ scr_firing_refresh = false;
2880
+ }
2881
+ ((void (*)(ScrClosure *))t.cb->fn)(t.cb);
2882
+ if (t.id != 0 && t.repeat_ms > 0 && !scr_firing_cleared) {
2883
+ /* Re-arm relative to the post-callback clock (libuv's uv_timer
2884
+ * repeat behavior: no catch-up bursts after a slow callback). The
2885
+ * ref state carries across ticks (a self-unref'd interval stays
2886
+ * unref'd). */
2887
+ ScrTimer again = {scr_now_ms() + t.repeat_ms, scr_timer_seq++, t.cb, t.repeat_ms, t.id, scr_firing_reffed, t.delay_ms};
2888
+ scr_timer_push(again);
2889
+ } else if (t.id != 0 && scr_firing_refresh && !scr_firing_cleared) {
2890
+ /* refresh() from inside the one-shot's own callback: re-arm to
2891
+ * now + the original delay, ref state carried (Node's
2892
+ * Timeout.refresh — the timer fires again). */
2893
+ ScrTimer again = {scr_now_ms() + t.delay_ms, scr_timer_seq++, t.cb, 0, t.id, scr_firing_reffed, t.delay_ms};
2894
+ scr_timer_push(again);
2895
+ } else {
2896
+ scr_closure_release(t.cb);
2897
+ }
2898
+ scr_firing_id = 0;
2899
+ if (scr_exc_pending()) return false; /* uncaught throw in a callback: main handles it */
2900
+ if (scr_ready_len > 0) break; /* drain microtasks before more timers */
2901
+ }
2902
+ /* The check phase: immediates queued BEFORE this phase started run
2903
+ * now, FIFO; ones a callback queues wait for the next turn (the end
2904
+ * snapshot — Node's once-per-turn rule, so a setImmediate chain can't
2905
+ * starve the loop). Cleared slots (cb NULL) skip. Microtasks drain
2906
+ * between callbacks, like Node's inter-macrotask checkpoints; a woken
2907
+ * fiber restarts the turn first (the timer loop's break above), so the
2908
+ * phase only runs on a drained queue. */
2909
+ if (scr_ready_len == 0 && scr_pending_immediates > 0) {
2910
+ size_t end = scr_nimmediates;
2911
+ while (scr_immediates_head < end) {
2912
+ size_t i = scr_immediates_head++;
2913
+ ScrClosure *cb = scr_immediates[i].cb;
2914
+ if (cb == NULL) continue; /* cleared */
2915
+ scr_immediates[i].cb = NULL; /* fired: clear/ref/unref on this id no-op now */
2916
+ if (scr_pending_immediates > 0) scr_pending_immediates--;
2917
+ if (scr_immediates[i].reffed) {
2918
+ scr_immediates[i].reffed = false;
2919
+ if (scr_reffed_immediates > 0) scr_reffed_immediates--;
2920
+ }
2921
+ ((void (*)(ScrClosure *))cb->fn)(cb);
2922
+ scr_closure_release(cb);
2923
+ if (scr_exc_pending()) return false; /* uncaught throw: main handles it */
2924
+ while (scr_ready_len > 0) {
2925
+ ScrFiber *f = scr_ready[scr_ready_head++];
2926
+ scr_ready_len--;
2927
+ scr_resume_fiber(f);
2928
+ }
2929
+ if (top_level != NULL && top_level->state == SCR_PROM_REJECTED) break;
2930
+ }
2931
+ /* Fully drained: reset the cursor so the array reuses its slots. */
2932
+ if (scr_immediates_head == scr_nimmediates) {
2933
+ scr_immediates_head = 0;
2934
+ scr_nimmediates = 0;
2935
+ }
2936
+ }
2937
+ }
2938
+ return rejection_failed;
2939
+ }
2940
+
2941
+ bool scr_loop_run(ScrPromise *top_level) {
2942
+ bool first_checkpoint = true;
2943
+ bool rejection_failed;
2944
+ for (;;) {
2945
+ rejection_failed = scr_loop_run_pass(top_level && !top_level->top_level_handled ? top_level : NULL, first_checkpoint);
2946
+ first_checkpoint = false;
2947
+ if (scr_exc_pending()) {
2948
+ if (scr_exc_handle_uncaught(false)) continue;
2949
+ break; /* main reports the original or handler-thrown exception */
2950
+ }
2951
+ if (rejection_failed) break;
2952
+ if (top_level && top_level->state == SCR_PROM_REJECTED && !top_level->top_level_handled) {
2953
+ scr_promise_rethrow(top_level);
2954
+ if (scr_exc_handle_uncaught(true)) {
2955
+ top_level->top_level_handled = true;
2956
+ scr_prom_observe(top_level);
2957
+ continue;
2958
+ }
2959
+ scr_discard_unhandled_rejections();
2960
+ break;
2961
+ }
2962
+ break;
2963
+ }
2964
+ /* Exit can now leave UNREF'd timers armed in the heap (ordinary
2965
+ * exhaustion, a fatal module root, or an unhandled rejection). They
2966
+ * never fire, so release their closures here or the RC audit counts
2967
+ * them as leaks. Uncaught callback throws still return above for main
2968
+ * to report through the existing exceptional teardown path. */
2969
+ scr_timers_teardown();
2970
+ /* No reffed foreign registration or queued invocation remains at ordinary
2971
+ * exhaustion. Disarm posting before exit listeners/global teardown so a
2972
+ * straggling native thread becomes a safe silent drop. */
2973
+ if (scr_ffi_stop_fn != NULL) scr_ffi_stop_fn();
2974
+ /* Retained native FFI registrations are deliberately NOT torn down
2975
+ * here: process 'exit' listeners run after the loop returns (inline in
2976
+ * main, before any atexit handler) and may legitimately release a
2977
+ * registration or pump a native library one last time — exactly like
2978
+ * the process.exit() path, where the ledger is also still intact. On
2979
+ * returns that reach atexit, the sweep scr_ffi_retain registered (LIFO
2980
+ * before the RC audit) then drops the ledger's references. It does NOT
2981
+ * run on process.exit(): scr_process_exit ends in _Exit, skipping every
2982
+ * atexit handler — the sweep and the RC audit alike — and leaves the
2983
+ * ledger to the OS. */
2984
+ /* Unref'd children the loop never reaped: release the
2985
+ * registry's references (their listeners never fire — the process is
2986
+ * exiting, Node's behavior; the OS reparents the children). */
2987
+ scr_children_teardown();
2988
+ scr_fibers_abandoned = scr_fibers_live;
2989
+ scr_note_abandoned_fibers(scr_fibers_abandoned);
2990
+ return rejection_failed;
2991
+ }
2992
+
2993
+ /* The island's half of the unhandled-rejection report (scr_island.c
2994
+ * registers it at engine boot): called with print=true when the static
2995
+ * ledger below reported nothing — one report, one voice, like Node's
2996
+ * first-unhandled-rejection death. Returns whether the island had any.
2997
+ * Static builds never set it. */
2998
+ static bool (*scr_island_rejections_fn)(bool print) = NULL;
2999
+ static int (*scr_island_jobs_drain_fn)(void) = NULL;
3000
+
3001
+ void scr_loop_set_island_rejections(bool (*fn)(bool print),
3002
+ int (*drain_jobs)(void)) {
3003
+ scr_island_rejections_fn = fn;
3004
+ scr_island_jobs_drain_fn = drain_jobs;
3005
+ }
3006
+
3007
+ /* ── process.on('unhandledRejection') ─────────────────────────────────
3008
+ * Dyn listeners are called per never-observed rejection at the completed
3009
+ * nextTick/microtask checkpoint. A registered listener suppresses the
3010
+ * default report and exit 1, exactly Node's handled-event contract. */
3011
+
3012
+ /* The unhandled-rejection LISTENER hook (scr_async_dyn.c installs it at
3013
+ * registration — the loop-hook pattern, so listener-free binaries keep
3014
+ * their size class): called per never-observed rejection; false = a
3015
+ * listener threw (the uncaught crash path). */
3016
+ bool (*scr_urj_deliver_fn)(ScrPromise *p) = NULL;
3017
+
3018
+ /* Unhandled rejections at a completed nextTick/microtask checkpoint:
3019
+ * Node prints an error and exits 1 when no listener handles the event.
3020
+ * Snapshot the ledger: a listener can reject another promise, but that
3021
+ * new rejection belongs to the NEXT checkpoint rather than this report. */
3022
+ bool scr_report_unhandled_rejections(void) {
3023
+ /* Static fibers drain before engine jobs in this runtime's documented
3024
+ * island ordering. Complete BOTH halves of that microtask checkpoint
3025
+ * before deciding either rejection ledger; engine reactions can attach
3026
+ * a handler to a rejection that would otherwise look unhandled here.
3027
+ * A host callback can wake a static fiber/tick, in which case the loop
3028
+ * must drain that work before reporting too. */
3029
+ if (scr_island_jobs_drain_fn != NULL) {
3030
+ scr_island_jobs_drain_fn();
3031
+ if (scr_ready_len > 0 || scr_nt_head != NULL) return false;
3032
+ }
3033
+ bool any = false;
3034
+ bool crashed = false;
3035
+ size_t report_count = scr_nunhandled;
3036
+ for (size_t i = 0; i < report_count; i++) {
3037
+ ScrPromise *p = scr_maybe_unhandled[i];
3038
+ if (p->state == SCR_PROM_REJECTED && !p->rejection_observed && !crashed) {
3039
+ if (scr_urj_deliver_fn != NULL) {
3040
+ /* Listener dispatch (scr_async_dyn.c installed the hook at
3041
+ * registration): the event handles it, like Node — per entry,
3042
+ * no report, exit 0. A listener throw is the uncaught crash.
3043
+ * reported_unhandled arms the 'rejectionHandled' window: a
3044
+ * handler the listener itself attaches fires the sibling event
3045
+ * (scr_prom_observe). */
3046
+ p->rejection_observed = true;
3047
+ p->reported_unhandled = true;
3048
+ if (!scr_urj_deliver_fn(p) && !scr_exc_handle_uncaught(false)) crashed = true;
3049
+ } else if (scr_uncaught_exception_hook != NULL) {
3050
+ scr_promise_rethrow(p);
3051
+ if (scr_exc_handle_uncaught(true)) {
3052
+ p->rejection_observed = true;
3053
+ p->reported_unhandled = true;
3054
+ } else {
3055
+ crashed = true;
3056
+ }
3057
+ } else if (!any) {
3058
+ any = true;
3059
+ fflush(stdout);
3060
+ fputs("Unhandled promise rejection: ", stderr);
3061
+ switch (p->payload_kind) {
3062
+ case SCR_EXC_F64: {
3063
+ char buf[32];
3064
+ scr_f64_to_str(p->f64, buf);
3065
+ fputs(buf, stderr);
3066
+ break;
3067
+ }
3068
+ case SCR_EXC_BOOL: fputs(p->b ? "true" : "false", stderr); break;
3069
+ case SCR_EXC_STR: fputs(((ScrStr *)p->payload)->data, stderr); break;
3070
+ case SCR_EXC_OBJ:
3071
+ /* Error rejections render "name: message", like the uncaught path. */
3072
+ if (scr_error_is(p->payload)) {
3073
+ ScrStr *s = scr_error_to_string((ScrError *)p->payload);
3074
+ fwrite(s->data, 1, s->len, stderr);
3075
+ scr_str_release(s);
3076
+ break;
3077
+ }
3078
+ /* fall through */
3079
+ default: fputs("[object]", stderr); break;
3080
+ }
3081
+ fputc('\n', stderr);
3082
+ }
3083
+ }
3084
+ scr_promise_release(p);
3085
+ }
3086
+ size_t remaining = scr_nunhandled - report_count;
3087
+ if (remaining > 0) {
3088
+ memmove(scr_maybe_unhandled, scr_maybe_unhandled + report_count,
3089
+ remaining * sizeof *scr_maybe_unhandled);
3090
+ }
3091
+ scr_nunhandled = remaining;
3092
+ if (crashed) {
3093
+ scr_exc_print_uncaught();
3094
+ return true;
3095
+ }
3096
+ if (scr_island_rejections_fn != NULL) {
3097
+ bool island = scr_island_rejections_fn(!any);
3098
+ any = any || island;
3099
+ }
3100
+ /* main returns 1 on a reported rejection — the 'exit' listeners (atexit)
3101
+ * must see that code, like Node's. */
3102
+ if (any) scr_exit_code_note(1);
3103
+ return any;
3104
+ }
3105
+
3106
+ /* A fatal executable-module rejection suppresses unrelated rejections
3107
+ * created in the SAME checkpoint. Drop their retained ledger references
3108
+ * without delivering process events or a competing default report. */
3109
+ void scr_discard_unhandled_rejections(void) {
3110
+ for (size_t i = 0; i < scr_nunhandled; i++) {
3111
+ scr_promise_release(scr_maybe_unhandled[i]);
3112
+ }
3113
+ scr_nunhandled = 0;
3114
+ }
3115
+
3116
+ /* ── new Promise(executor) ────────────────────────────────────────────── */
3117
+
3118
+ /* resolve closures: caps[0] is a box whose slot holds the promise (+1). */
3119
+ static ScrPromise *scr_resolve_target(ScrClosure *self) {
3120
+ return (ScrPromise *)scr_box_get_ref(self->caps[0]);
3121
+ }
3122
+ static void scr_resolve_thunk_f64(ScrClosure *self, double v) {
3123
+ ScrPromise *p = scr_resolve_target(self);
3124
+ scr_promise_fulfill_f64(p, v);
3125
+ scr_promise_release(p);
3126
+ }
3127
+ static void scr_resolve_thunk_bool(ScrClosure *self, bool v) {
3128
+ ScrPromise *p = scr_resolve_target(self);
3129
+ scr_promise_fulfill_bool(p, v);
3130
+ scr_promise_release(p);
3131
+ }
3132
+ static void scr_resolve_thunk_str(ScrClosure *self, ScrStr *v) {
3133
+ ScrPromise *p = scr_resolve_target(self);
3134
+ scr_promise_fulfill_str(p, v); /* callee owns its params: moves in */
3135
+ scr_promise_release(p);
3136
+ }
3137
+ static void scr_resolve_thunk_void(ScrClosure *self) {
3138
+ ScrPromise *p = scr_resolve_target(self);
3139
+ scr_promise_fulfill_void(p);
3140
+ scr_promise_release(p);
3141
+ }
3142
+ /* Ref payloads: emitted code passes the concrete retain/release via a
3143
+ * second box slot? Keep simple: ref resolve thunks are monomorphized by the
3144
+ * EMITTER (it knows the arm type) — it emits a tiny static thunk calling
3145
+ * scr_promise_fulfill_ref with the concrete helpers, wrapped over caps[0].
3146
+ * The runtime provides only the scalar/str/void thunks. */
3147
+
3148
+ ScrClosure *scr_make_resolve(ScrPromise *p, int kind /*0 f64,1 bool,2 str,3 void*/) {
3149
+ void *fns[4] = {(void *)&scr_resolve_thunk_f64, (void *)&scr_resolve_thunk_bool,
3150
+ (void *)&scr_resolve_thunk_str, (void *)&scr_resolve_thunk_void};
3151
+ ScrClosure *c = scr_closure_new(fns[kind], 1);
3152
+ ScrBox *b = scr_box_new_obj(scr_promise_retain_v, scr_promise_release_v,
3153
+ scr_promise_trace_v);
3154
+ scr_box_set_ref(b, scr_promise_retain(p));
3155
+ c->caps[0] = b;
3156
+ return c;
3157
+ }
3158
+
3159
+ /* Emitted ref-kind resolve thunks call this. */
3160
+ void scr_resolve_ref_impl(ScrClosure *self, void *v, void *(*retain)(void *), void (*release)(void *), ScrTraceFn trace) {
3161
+ ScrPromise *p = scr_resolve_target(self);
3162
+ scr_promise_fulfill_ref(p, v, retain, release, trace);
3163
+ scr_promise_release(p);
3164
+ }
3165
+
3166
+ /* ── emitter support ──────────────────────────────────────────────────── */
3167
+
3168
+ ScrPromise *scr_fiber_promise(ScrFiber *f) { return f->promise; }
3169
+
3170
+ /* Generalized resolve construction: `fn` is an emitted thunk with closure
3171
+ * calling convention (self, value) that forwards to scr_resolve_ref_impl
3172
+ * with the concrete RC helpers. */
3173
+ ScrClosure *scr_make_resolve_fn(ScrPromise *p, void *fn) {
3174
+ ScrClosure *c = scr_closure_new(fn, 1);
3175
+ ScrBox *b = scr_box_new_obj(scr_promise_retain_v, scr_promise_release_v,
3176
+ scr_promise_trace_v);
3177
+ scr_box_set_ref(b, scr_promise_retain(p));
3178
+ c->caps[0] = b;
3179
+ return c;
3180
+ }
3181
+
3182
+ /* ── reject closures (new Promise((resolve, reject) => ...)) ──────────
3183
+ * Mirror of the resolve closures: caps[0] is a box whose slot holds the
3184
+ * promise (+1). The reason is always an Error-hierarchy instance (the
3185
+ * frontend pins the reject parameter to `(reason: Error) => void`), and it
3186
+ * stores as SCR_EXC_OBJ — exactly the thrown-Error representation — so an
3187
+ * await rethrows it, catch-side instanceof answers, and the uncaught
3188
+ * printer prints "name: message". First settle wins, exactly JS: reject
3189
+ * after any settle (resolve-then-reject, double reject) releases the
3190
+ * reason and does nothing. The closure calling convention makes the thunk
3191
+ * own its param, like every compiled callee. */
3192
+ static void scr_reject_thunk(ScrClosure *self, ScrError *reason) {
3193
+ ScrPromise *p = scr_resolve_target(self);
3194
+ if (p->state != SCR_PROM_PENDING) {
3195
+ scr_error_release(reason);
3196
+ } else {
3197
+ p->state = SCR_PROM_REJECTED;
3198
+ p->payload_kind = SCR_EXC_OBJ;
3199
+ p->payload = reason; /* ownership moves in */
3200
+ p->retain_fn = scr_error_retain_v;
3201
+ p->release_fn = scr_error_release_v;
3202
+ p->trace_fn = scr_error_trace_arg();
3203
+ scr_promise_settle_wake(p);
3204
+ }
3205
+ scr_promise_release(p);
3206
+ }
3207
+
3208
+ ScrClosure *scr_make_reject(ScrPromise *p) {
3209
+ ScrClosure *c = scr_closure_new((void *)&scr_reject_thunk, 1);
3210
+ ScrBox *b = scr_box_new_obj(scr_promise_retain_v, scr_promise_release_v,
3211
+ scr_promise_trace_v);
3212
+ scr_box_set_ref(b, scr_promise_retain(p));
3213
+ c->caps[0] = b;
3214
+ return c;
3215
+ }
3216
+
3217
+ /* Shared executor epilogue: an escaping throw rejects a still-pending
3218
+ * promise (payload moved out of the active exception cell); a throw after
3219
+ * the promise settled is swallowed, like resolve-then-throw in JS. */
3220
+ static void scr_executor_check_throw(ScrPromise *p) {
3221
+ if (!scr_exc_pending()) return;
3222
+ if (p->state == SCR_PROM_PENDING) {
3223
+ scr_promise_reject_from_cell(p, scr_exc_current_cell());
3224
+ scr_promise_settle_wake(p);
3225
+ } else {
3226
+ scr_exc_clear();
3227
+ }
3228
+ }
3229
+
3230
+ /* Runs a `new Promise(executor)` executor synchronously; an escaping throw
3231
+ * rejects the promise (JS-exact). Borrows `p` and `exec`; `resolve`
3232
+ * ownership moves INTO the executor call (compiled callees own and finally
3233
+ * release their params). */
3234
+ void scr_promise_run_executor(ScrPromise *p, ScrClosure *exec, ScrClosure *resolve) {
3235
+ ((void (*)(ScrClosure *, ScrClosure *))exec->fn)(exec, resolve);
3236
+ scr_executor_check_throw(p);
3237
+ }
3238
+
3239
+ /* Zero-param executor (`new Promise(() => {})`): nothing can ever resolve —
3240
+ * a deliberately-forever-pending promise. Borrows both. */
3241
+ void scr_promise_run_executor0(ScrPromise *p, ScrClosure *exec) {
3242
+ ((void (*)(ScrClosure *))exec->fn)(exec);
3243
+ scr_executor_check_throw(p);
3244
+ }
3245
+
3246
+ /* Two-param executor (`new Promise((resolve, reject) => ...)`): same as
3247
+ * scr_promise_run_executor with the reject closure's +1 also moving into
3248
+ * the call. */
3249
+ void scr_promise_run_executor2(ScrPromise *p, ScrClosure *exec, ScrClosure *resolve,
3250
+ ScrClosure *reject) {
3251
+ ((void (*)(ScrClosure *, ScrClosure *, ScrClosure *))exec->fn)(exec, resolve, reject);
3252
+ scr_executor_check_throw(p);
3253
+ }
3254
+
3255
+ /* ── sync generators (function*) ──────────────────────────────────────
3256
+ * Contract in scr_runtime.h. The fiber machinery above is the engine:
3257
+ * scr_switch is a synchronous coroutine hop, so generators need no event
3258
+ * loop — .next() from the main stack (or any fiber) blocks until the
3259
+ * yield. */
3260
+
3261
+ enum {
3262
+ SCR_GEN_UNSTARTED = 0,
3263
+ SCR_GEN_SUSPENDED,
3264
+ SCR_GEN_AWAITING,
3265
+ SCR_GEN_RUNNING,
3266
+ SCR_GEN_DONE
3267
+ };
3268
+
3269
+ /* One type-erased value slot: the exception cell's payload technique,
3270
+ * with only the release entry point (takes MOVE — nothing here retains). */
3271
+ typedef struct {
3272
+ ScrExcKind kind; /* NONE / F64 / BOOL / REF (strings ride REF) */
3273
+ double f64;
3274
+ bool b;
3275
+ void *payload;
3276
+ void (*release_fn)(void *);
3277
+ } ScrGenSlot;
3278
+
3279
+ enum { SCR_AG_NEXT = 0, SCR_AG_RETURN, SCR_AG_THROW };
3280
+
3281
+ typedef struct ScrAsyncGenRequest {
3282
+ int mode;
3283
+ ScrGenSlot arg;
3284
+ ScrExcCell thrown;
3285
+ ScrPromise *promise; /* owned until this request settles */
3286
+ struct ScrAsyncGenRequest *next;
3287
+ } ScrAsyncGenRequest;
3288
+
3289
+ static void scr_gen_slot_reset(ScrGenSlot *s) {
3290
+ if (s->kind == SCR_EXC_REF && s->payload != NULL) s->release_fn(s->payload);
3291
+ s->kind = SCR_EXC_NONE;
3292
+ s->payload = NULL;
3293
+ s->release_fn = NULL;
3294
+ }
3295
+
3296
+ static void scr_gen_exc_reset(ScrExcCell *cell) {
3297
+ if (cell->kind == SCR_EXC_STR) {
3298
+ scr_str_release((ScrStr *)cell->payload);
3299
+ } else if (cell->kind == SCR_EXC_REF || cell->kind == SCR_EXC_OBJ ||
3300
+ cell->kind == SCR_EXC_PRIMITIVE_REF) {
3301
+ cell->release_fn(cell->payload);
3302
+ }
3303
+ ScrStackFrame *stack = cell->stack;
3304
+ memset(cell, 0, sizeof *cell);
3305
+ cell->stack = stack;
3306
+ }
3307
+
3308
+ static void scr_gen_exc_move(ScrExcCell *dst, ScrExcCell *src) {
3309
+ scr_gen_exc_reset(dst);
3310
+ ScrStackFrame *dst_stack = dst->stack;
3311
+ ScrStackFrame *src_stack = src->stack;
3312
+ *dst = *src;
3313
+ dst->stack = dst_stack;
3314
+ memset(src, 0, sizeof *src);
3315
+ src->stack = src_stack;
3316
+ }
3317
+
3318
+ struct ScrGen {
3319
+ size_t rc;
3320
+ ScrDyn *receiver;
3321
+ ScrFiber *fiber; /* NULL once torn down (done, or unstarted release) */
3322
+ int state;
3323
+ ScrGenSlot out; /* yielded value / completion value */
3324
+ ScrGenSlot in; /* the .next(v) argument */
3325
+ ScrGenSlot ret; /* a parked .return(v) value */
3326
+ /* The never-started teardown: drops the packed (already-retained)
3327
+ * arguments the spawn wrapper built. Emitted per generator function. */
3328
+ void (*drop_args)(void *);
3329
+ bool is_async;
3330
+ void (*settle_async)(ScrGen *, ScrPromise *);
3331
+ ScrAsyncGenRequest *requests_head;
3332
+ ScrAsyncGenRequest *requests_tail;
3333
+ ScrPromise *active_request;
3334
+ ScrExcCell async_error;
3335
+ bool settle_queued;
3336
+ bool success_hop_done;
3337
+ };
3338
+
3339
+ static ScrGen *scr_gen_new_common(void (*entry)(ScrFiber *, void *), void *argpack,
3340
+ void (*drop_args)(void *),
3341
+ void (*settle_async)(ScrGen *, ScrPromise *)) {
3342
+ ScrGen *g = calloc(1, sizeof *g);
3343
+ if (!g) scr_oom();
3344
+ g->rc = 1;
3345
+ g->receiver = scr_dyn_this_get();
3346
+ g->state = SCR_GEN_UNSTARTED;
3347
+ g->drop_args = drop_args;
3348
+ g->is_async = settle_async != NULL;
3349
+ g->settle_async = settle_async;
3350
+ scr_obj_alloc_note();
3351
+
3352
+ ScrFiber *f = calloc(1, sizeof *f);
3353
+ if (!f) scr_oom();
3354
+ f->gen = g;
3355
+ f->entry = entry;
3356
+ f->argpack = argpack; /* owned by the fiber start; drop_args if never started */
3357
+ /* AsyncLocalStorage: generator bodies run in their CREATOR's context
3358
+ * (the spawn-inheritance stance; resumes swap it active like any
3359
+ * fiber switch). */
3360
+ f->als = scr_als_ctx_retain(*scr_als_active);
3361
+ scr_fibers_live++;
3362
+ #ifdef _WIN32
3363
+ f->ctx = CreateFiberEx(4096, 0, 0, scr_trampoline, NULL);
3364
+ if (f->ctx == NULL) scr_oom();
3365
+ #elif defined(__wasi__)
3366
+ f->ctx = 0;
3367
+ #else
3368
+ scr_fiber_context_init(f);
3369
+ #endif
3370
+ g->fiber = f;
3371
+ return g;
3372
+ }
3373
+
3374
+ ScrGen *scr_gen_new(void (*entry)(ScrFiber *, void *), void *argpack,
3375
+ void (*drop_args)(void *)) {
3376
+ return scr_gen_new_common(entry, argpack, drop_args, NULL);
3377
+ }
3378
+
3379
+ ScrGen *scr_async_gen_new(void (*entry)(ScrFiber *, void *), void *argpack,
3380
+ void (*drop_args)(void *),
3381
+ void (*settle)(ScrGen *, ScrPromise *)) {
3382
+ return scr_gen_new_common(entry, argpack, drop_args, settle);
3383
+ }
3384
+
3385
+ ScrGen *scr_gen_retain(ScrGen *g) {
3386
+ if (g) g->rc++;
3387
+ return g;
3388
+ }
3389
+
3390
+ void scr_gen_release(ScrGen *g) {
3391
+ if (!g || --g->rc != 0) return;
3392
+ scr_dyn_release(g->receiver);
3393
+ scr_gen_slot_reset(&g->out);
3394
+ scr_gen_slot_reset(&g->in);
3395
+ scr_gen_slot_reset(&g->ret);
3396
+ scr_gen_exc_reset(&g->async_error);
3397
+ if (g->fiber != NULL) {
3398
+ if (g->state == SCR_GEN_UNSTARTED) {
3399
+ /* Never ran: nothing on the stack owns anything — clean teardown.
3400
+ * The packed arguments (+1 each) drop through the emitted helper. */
3401
+ if (g->drop_args != NULL) g->drop_args(g->fiber->argpack);
3402
+ else free(g->fiber->argpack);
3403
+ scr_fiber_destroy(g->fiber);
3404
+ scr_fibers_live--;
3405
+ } else {
3406
+ /* Suspended: the stack holds live locals — unwinding would run user
3407
+ * finally blocks Node's GC never runs, so the fiber is deliberately
3408
+ * ABANDONED (it stays in the live count; a program that drops a
3409
+ * suspended generator gets the abandoned-fiber audit note, the
3410
+ * loop-exhaustion story). The fiber's back-pointer clears so a
3411
+ * dangling resume can never reach the freed ScrGen. */
3412
+ g->fiber->gen = NULL;
3413
+ }
3414
+ }
3415
+ scr_obj_free_note();
3416
+ free(g);
3417
+ }
3418
+
3419
+ void *scr_gen_retain_v(void *g) { return scr_gen_retain((ScrGen *)g); }
3420
+ void scr_gen_release_v(void *g) { scr_gen_release((ScrGen *)g); }
3421
+
3422
+ bool scr_gen_done(ScrGen *g) { return g->state == SCR_GEN_DONE; }
3423
+ ScrGen *scr_gen_of_fiber(ScrFiber *f) { return f->gen; }
3424
+ ScrDyn *scr_gen_receiver(void) {
3425
+ return scr_dyn_retain(scr_current && scr_current->gen ? scr_current->gen->receiver : scr_dyn_undefined());
3426
+ }
3427
+
3428
+ /* Slot setters (release the previous occupant; payloads MOVE in). */
3429
+ static void scr_gen_slot_f64(ScrGenSlot *s, double v) {
3430
+ scr_gen_slot_reset(s);
3431
+ s->kind = SCR_EXC_F64;
3432
+ s->f64 = v;
3433
+ }
3434
+ static void scr_gen_slot_bool(ScrGenSlot *s, bool v) {
3435
+ scr_gen_slot_reset(s);
3436
+ s->kind = SCR_EXC_BOOL;
3437
+ s->b = v;
3438
+ }
3439
+ static void scr_gen_slot_ref(ScrGenSlot *s, void *v, void (*release)(void *)) {
3440
+ scr_gen_slot_reset(s);
3441
+ s->kind = SCR_EXC_REF;
3442
+ s->payload = v;
3443
+ s->release_fn = release;
3444
+ }
3445
+
3446
+ void scr_gen_in_f64(ScrGen *g, double v) { scr_gen_slot_f64(&g->in, v); }
3447
+ void scr_gen_in_bool(ScrGen *g, bool v) { scr_gen_slot_bool(&g->in, v); }
3448
+ void scr_gen_in_ref(ScrGen *g, void *v, void (*release)(void *)) {
3449
+ scr_gen_slot_ref(&g->in, v, release);
3450
+ }
3451
+ void scr_gen_in_none(ScrGen *g) { scr_gen_slot_reset(&g->in); }
3452
+
3453
+ void scr_gen_ret_f64(ScrGen *g, double v) { scr_gen_slot_f64(&g->ret, v); }
3454
+ void scr_gen_ret_bool(ScrGen *g, bool v) { scr_gen_slot_bool(&g->ret, v); }
3455
+ void scr_gen_ret_ref(ScrGen *g, void *v, void (*release)(void *)) {
3456
+ scr_gen_slot_ref(&g->ret, v, release);
3457
+ }
3458
+ void scr_gen_ret_none(ScrGen *g) { scr_gen_slot_reset(&g->ret); }
3459
+
3460
+ void scr_gen_out_f64(ScrGen *g, double v) { scr_gen_slot_f64(&g->out, v); }
3461
+ void scr_gen_out_bool(ScrGen *g, bool v) { scr_gen_slot_bool(&g->out, v); }
3462
+ void scr_gen_out_ref(ScrGen *g, void *v, void (*release)(void *)) {
3463
+ scr_gen_slot_ref(&g->out, v, release);
3464
+ }
3465
+
3466
+ /* Takes MOVE the slot's value out (the slot resets — a done generator's
3467
+ * later resumes answer NONE, JS's undefined). */
3468
+ static double scr_gen_slot_take_f64(ScrGenSlot *s) {
3469
+ double v = s->kind == SCR_EXC_F64 ? s->f64 : 0;
3470
+ s->kind = SCR_EXC_NONE;
3471
+ return v;
3472
+ }
3473
+ static bool scr_gen_slot_take_bool(ScrGenSlot *s) {
3474
+ bool v = s->kind == SCR_EXC_BOOL ? s->b : false;
3475
+ s->kind = SCR_EXC_NONE;
3476
+ return v;
3477
+ }
3478
+ static void *scr_gen_slot_take_ref(ScrGenSlot *s) {
3479
+ void *v = s->kind == SCR_EXC_REF ? s->payload : NULL;
3480
+ s->kind = SCR_EXC_NONE;
3481
+ s->payload = NULL;
3482
+ s->release_fn = NULL;
3483
+ return v;
3484
+ }
3485
+
3486
+ bool scr_gen_out_has(ScrGen *g) { return g->out.kind != SCR_EXC_NONE; }
3487
+ double scr_gen_take_out_f64(ScrGen *g) { return scr_gen_slot_take_f64(&g->out); }
3488
+ bool scr_gen_take_out_bool(ScrGen *g) { return scr_gen_slot_take_bool(&g->out); }
3489
+ void *scr_gen_take_out_ref(ScrGen *g) { return scr_gen_slot_take_ref(&g->out); }
3490
+
3491
+ /* The running fiber's generator — the body-side helpers' anchor. */
3492
+ static ScrGen *scr_gen_self(void) {
3493
+ ScrGen *g = scr_current != NULL ? scr_current->gen : NULL;
3494
+ if (g == NULL) {
3495
+ fputs("scriptc: internal error: yield outside a generator\n", stderr);
3496
+ abort();
3497
+ }
3498
+ return g;
3499
+ }
3500
+
3501
+ double scr_gen_take_in_f64(void) { return scr_gen_slot_take_f64(&scr_gen_self()->in); }
3502
+ bool scr_gen_take_in_bool(void) { return scr_gen_slot_take_bool(&scr_gen_self()->in); }
3503
+ void *scr_gen_take_in_ref(void) { return scr_gen_slot_take_ref(&scr_gen_self()->in); }
3504
+
3505
+ ScrDyn *scr_gen_delegate_resume(ScrDyn *(*next_ref)(void *),
3506
+ ScrDyn *(*return_ref)(void *),
3507
+ ScrDyn *(*caught_ref)(const ScrCaught *)) {
3508
+ ScrGen *g = scr_gen_self();
3509
+ ScrExcCell *cell = scr_exc_current_cell();
3510
+ int mode = cell->kind == SCR_EXC_GENRET ? 1 : cell->kind != SCR_EXC_NONE ? 2 : 0;
3511
+ ScrDyn *value;
3512
+ if (mode == 2) {
3513
+ ScrCaught *caught = scr_exc_take();
3514
+ value = caught_ref(caught);
3515
+ scr_caught_release(caught);
3516
+ } else {
3517
+ if (mode == 1) scr_exc_clear();
3518
+ ScrGenSlot *slot = mode == 1 ? &g->ret : &g->in;
3519
+ ScrDyn *(*convert)(void *) = mode == 1 ? return_ref : next_ref;
3520
+ switch (slot->kind) {
3521
+ case SCR_EXC_F64: value = scr_dyn_new_num(slot->f64); break;
3522
+ case SCR_EXC_BOOL: value = scr_dyn_new_bool(slot->b); break;
3523
+ case SCR_EXC_REF: value = convert(slot->payload); break;
3524
+ default: value = scr_dyn_retain(scr_dyn_undefined()); break;
3525
+ }
3526
+ scr_gen_slot_reset(slot);
3527
+ }
3528
+ if (scr_exc_pending()) {
3529
+ scr_dyn_release(value);
3530
+ return NULL;
3531
+ }
3532
+ ScrDyn *result = scr_dyn_new_obj();
3533
+ ScrDyn *kind = scr_dyn_new_num(mode);
3534
+ scr_dyn_obj_set(result, "kind", 4, kind);
3535
+ scr_dyn_obj_set(result, "value", 5, value);
3536
+ /* Object insertion takes ownership of both completion fields. */
3537
+ return result;
3538
+ }
3539
+
3540
+ /* yield: park the value in OUT and hop back to the resumer. Control
3541
+ * returns here at the next resume — possibly with an injected .throw
3542
+ * payload or the GENRET sentinel pending (the emitted check handles it). */
3543
+ static void scr_gen_yield_switch(void) {
3544
+ ScrFiber *self = scr_current;
3545
+ scr_switch(&self->ctx, self->return_to, NULL);
3546
+ }
3547
+ void scr_gen_yield_f64(double v) {
3548
+ scr_gen_slot_f64(&scr_gen_self()->out, v);
3549
+ scr_gen_yield_switch();
3550
+ }
3551
+ void scr_gen_yield_bool(bool v) {
3552
+ scr_gen_slot_bool(&scr_gen_self()->out, v);
3553
+ scr_gen_yield_switch();
3554
+ }
3555
+ void scr_gen_yield_ref(void *v, void (*release)(void *)) {
3556
+ scr_gen_slot_ref(&scr_gen_self()->out, v, release);
3557
+ scr_gen_yield_switch();
3558
+ }
3559
+
3560
+ void scr_async_gen_hop_done(void) {
3561
+ ScrGen *g = scr_gen_self();
3562
+ if (!g->is_async) {
3563
+ fputs("scriptc: internal error: async-generator hop on sync generator\n", stderr);
3564
+ abort();
3565
+ }
3566
+ g->success_hop_done = true;
3567
+ }
3568
+
3569
+ bool scr_exc_genret_pending(void) {
3570
+ return scr_exc_current_cell()->kind == SCR_EXC_GENRET;
3571
+ }
3572
+
3573
+ void scr_gen_ret_to_out(ScrGen *g) {
3574
+ scr_gen_slot_reset(&g->out);
3575
+ g->out = g->ret;
3576
+ g->ret.kind = SCR_EXC_NONE;
3577
+ g->ret.payload = NULL;
3578
+ g->ret.release_fn = NULL;
3579
+ }
3580
+
3581
+ /* The consumer→fiber hop shared by every resume mode: switches in, and on
3582
+ * the way back moves a pending body exception into the RESUMER's cell
3583
+ * (synchronous propagation — the await-rethrow analog) and tears down a
3584
+ * finished fiber. The gen is retained across the hop so a body that
3585
+ * releases the consumer's last reference cannot free it mid-run. */
3586
+ static void scr_gen_switch_in(ScrGen *g) {
3587
+ ScrFiber *f = g->fiber;
3588
+ scr_gen_retain(g);
3589
+ g->state = SCR_GEN_RUNNING;
3590
+ #ifdef _WIN32
3591
+ ScrCtx here = scr_win_self();
3592
+ #elif defined(__wasi__)
3593
+ ScrCtx here = 0;
3594
+ #else
3595
+ ucontext_t here;
3596
+ #endif
3597
+ f->return_to = &here;
3598
+ ScrFiber *me = scr_current;
3599
+ #ifdef __wasi__
3600
+ scr_current = f;
3601
+ scr_exc_swap_cell(&f->exc);
3602
+ scr_als_active = &f->als;
3603
+ if (f->coro == NULL) f->entry(f, f->argpack);
3604
+ else scr_wasi_coro_resume(f->coro);
3605
+ scr_current = me;
3606
+ scr_exc_swap_cell(me != NULL ? &me->exc : NULL);
3607
+ scr_als_active = me != NULL ? &me->als : &scr_als_main_slot;
3608
+ #else
3609
+ scr_switch(&here, &f->ctx, f);
3610
+ /* Back on the consumer: restore identity + the consumer's cell (the
3611
+ * yield/finish switch targeted NULL — main's cell). */
3612
+ scr_current = me;
3613
+ scr_exc_swap_cell(me != NULL ? &me->exc : NULL);
3614
+ #endif
3615
+ if (f->done) {
3616
+ g->state = SCR_GEN_DONE;
3617
+ if (f->exc.kind != SCR_EXC_NONE) {
3618
+ if (g->is_async) {
3619
+ /* Async-generator failures reject the active request; they never
3620
+ * throw synchronously from next/return/throw. */
3621
+ scr_gen_exc_move(&g->async_error, &f->exc);
3622
+ } else {
3623
+ /* The sync body's exception escapes at the resume site. */
3624
+ ScrExcCell *mine = scr_exc_current_cell();
3625
+ scr_gen_exc_move(mine, &f->exc);
3626
+ }
3627
+ }
3628
+ scr_fiber_destroy(f);
3629
+ g->fiber = NULL;
3630
+ scr_fibers_live--;
3631
+ } else {
3632
+ /* An async generator can return to its resumer because it yielded OR
3633
+ * because await parked it. OUT distinguishes the two. */
3634
+ g->state = g->is_async && !scr_gen_out_has(g)
3635
+ ? SCR_GEN_AWAITING
3636
+ : SCR_GEN_SUSPENDED;
3637
+ }
3638
+ scr_gen_release(g);
3639
+ }
3640
+
3641
+ void scr_gen_resume(ScrGen *g) {
3642
+ switch (g->state) {
3643
+ case SCR_GEN_RUNNING: {
3644
+ static const char sc_m[] = "Generator is already running";
3645
+ scr_throw_error_msg(SCR_ERR_TYPE, sc_m, sizeof sc_m - 1);
3646
+ return;
3647
+ }
3648
+ case SCR_GEN_DONE:
3649
+ /* next() on a done generator: { value: undefined, done: true } —
3650
+ * OUT is NONE (the completing resume took it). */
3651
+ return;
3652
+ default:
3653
+ scr_gen_switch_in(g);
3654
+ }
3655
+ }
3656
+
3657
+ void scr_gen_resume_return(ScrGen *g) {
3658
+ switch (g->state) {
3659
+ case SCR_GEN_RUNNING: {
3660
+ static const char sc_m[] = "Generator is already running";
3661
+ scr_throw_error_msg(SCR_ERR_TYPE, sc_m, sizeof sc_m - 1);
3662
+ return;
3663
+ }
3664
+ case SCR_GEN_DONE:
3665
+ scr_gen_ret_to_out(g);
3666
+ return;
3667
+ case SCR_GEN_UNSTARTED:
3668
+ /* The body never runs: tear the fiber down cleanly (drop the packed
3669
+ * arguments) and complete with the parked value. */
3670
+ if (g->drop_args != NULL) g->drop_args(g->fiber->argpack);
3671
+ else free(g->fiber->argpack);
3672
+ scr_fiber_destroy(g->fiber);
3673
+ g->fiber = NULL;
3674
+ scr_fibers_live--;
3675
+ g->state = SCR_GEN_DONE;
3676
+ scr_gen_ret_to_out(g);
3677
+ return;
3678
+ default:
3679
+ /* Suspended at a yield: inject the sentinel (an earlier .return whose
3680
+ * unwind a finally-yield parked leaves it already set) and resume. */
3681
+ if (g->fiber->exc.kind == SCR_EXC_NONE) g->fiber->exc.kind = SCR_EXC_GENRET;
3682
+ scr_gen_switch_in(g);
3683
+ }
3684
+ }
3685
+
3686
+ void scr_gen_resume_throw(ScrGen *g) {
3687
+ switch (g->state) {
3688
+ case SCR_GEN_RUNNING: {
3689
+ /* Replace the parked payload with Node's reentrancy TypeError. */
3690
+ static const char sc_m[] = "Generator is already running";
3691
+ scr_throw_error_msg(SCR_ERR_TYPE, sc_m, sizeof sc_m - 1);
3692
+ return;
3693
+ }
3694
+ case SCR_GEN_DONE:
3695
+ /* .throw on a done generator: it stays done; the payload stays
3696
+ * pending in the caller — the call site's check rethrows it. */
3697
+ return;
3698
+ case SCR_GEN_UNSTARTED:
3699
+ /* The body never runs; the generator becomes done and the payload
3700
+ * stays pending in the caller (probed Node behavior). */
3701
+ if (g->drop_args != NULL) g->drop_args(g->fiber->argpack);
3702
+ else free(g->fiber->argpack);
3703
+ scr_fiber_destroy(g->fiber);
3704
+ g->fiber = NULL;
3705
+ scr_fibers_live--;
3706
+ g->state = SCR_GEN_DONE;
3707
+ return;
3708
+ default: {
3709
+ /* Move the caller's pending payload into the fiber's cell (an
3710
+ * earlier sentinel parked by a finally-yield is replaced — the
3711
+ * injected throw wins, like a throw inside that finally). */
3712
+ ScrExcCell *mine = scr_exc_current_cell();
3713
+ ScrExcCell *dst = &g->fiber->exc;
3714
+ dst->kind = mine->kind;
3715
+ dst->f64 = mine->f64;
3716
+ dst->b = mine->b;
3717
+ dst->payload = mine->payload;
3718
+ dst->retain_fn = mine->retain_fn;
3719
+ dst->release_fn = mine->release_fn;
3720
+ dst->trace_fn = mine->trace_fn;
3721
+ mine->kind = SCR_EXC_NONE;
3722
+ mine->payload = NULL;
3723
+ mine->trace_fn = NULL;
3724
+ scr_gen_switch_in(g);
3725
+ }
3726
+ }
3727
+ }
3728
+
3729
+ /* ── async generators ────────────────────────────────────────────────
3730
+ * The body is the same suspended generator fiber, now allowed to await.
3731
+ * Each resume request owns a promise and a retained generator. The first
3732
+ * idle request starts synchronously; successful yield/return settlement
3733
+ * takes AsyncGeneratorYield's Await hop (the emitter marks a yielded
3734
+ * promise whose await already supplied it), while thrown completions reject
3735
+ * immediately. Requests queued behind an active one begin in that
3736
+ * settlement continuation, preserving Node's ordering. */
3737
+
3738
+ static void scr_async_gen_start_queued(ScrGen *g);
3739
+
3740
+ static void scr_async_gen_schedule_settle(ScrGen *g) {
3741
+ if (g->settle_queued) return;
3742
+ ScrFiber *job = calloc(1, sizeof *job);
3743
+ if (!job) scr_oom();
3744
+ job->gen_job = scr_gen_retain(g);
3745
+ g->settle_queued = true;
3746
+ scr_ready_push(job);
3747
+ }
3748
+
3749
+ static void scr_async_gen_finish_active(ScrGen *g, bool rejected) {
3750
+ ScrPromise *p = g->active_request;
3751
+ if (p == NULL) {
3752
+ fputs("scriptc: internal error: async generator settled without a request\n", stderr);
3753
+ abort();
3754
+ }
3755
+ g->active_request = NULL;
3756
+ if (rejected) {
3757
+ scr_promise_reject_from_cell(p, &g->async_error);
3758
+ scr_promise_settle_wake(p);
3759
+ } else {
3760
+ g->settle_async(g, p);
3761
+ }
3762
+ scr_promise_release(p);
3763
+ /* Every queued request retains its generator until settlement. */
3764
+ scr_gen_release(g);
3765
+ }
3766
+
3767
+ static void scr_async_gen_capture_caller_error(ScrGen *g) {
3768
+ ScrExcCell *cell = scr_exc_current_cell();
3769
+ if (cell->kind != SCR_EXC_NONE) scr_gen_exc_move(&g->async_error, cell);
3770
+ }
3771
+
3772
+ static void scr_async_gen_run_active(ScrGen *g, ScrAsyncGenRequest *req) {
3773
+ const bool was_done = g->state == SCR_GEN_DONE;
3774
+ if (req->mode == SCR_AG_NEXT) {
3775
+ scr_gen_slot_reset(&g->in);
3776
+ g->in = req->arg;
3777
+ memset(&req->arg, 0, sizeof req->arg);
3778
+ scr_gen_resume(g);
3779
+ } else if (req->mode == SCR_AG_RETURN) {
3780
+ scr_gen_slot_reset(&g->ret);
3781
+ g->ret = req->arg;
3782
+ memset(&req->arg, 0, sizeof req->arg);
3783
+ scr_gen_resume_return(g);
3784
+ } else {
3785
+ scr_gen_exc_move(scr_exc_current_cell(), &req->thrown);
3786
+ scr_gen_resume_throw(g);
3787
+ }
3788
+ scr_async_gen_capture_caller_error(g);
3789
+
3790
+ if (g->async_error.kind != SCR_EXC_NONE) {
3791
+ scr_async_gen_finish_active(g, true);
3792
+ return;
3793
+ }
3794
+ if (g->state == SCR_GEN_AWAITING) return;
3795
+
3796
+ /* next() on an already-completed generator produces its undefined done
3797
+ * result immediately. Yield, body return, and return(value) all pass
3798
+ * through AsyncGeneratorYield's successful Await step. */
3799
+ if (was_done && req->mode == SCR_AG_NEXT) {
3800
+ scr_async_gen_finish_active(g, false);
3801
+ } else if (g->success_hop_done) {
3802
+ g->success_hop_done = false;
3803
+ scr_async_gen_finish_active(g, false);
3804
+ } else {
3805
+ scr_async_gen_schedule_settle(g);
3806
+ }
3807
+ }
3808
+
3809
+ static void scr_async_gen_start_queued(ScrGen *g) {
3810
+ /* Keep the object alive while an immediately-settled request releases
3811
+ * its own retain and the loop inspects the next queue node. */
3812
+ scr_gen_retain(g);
3813
+ while (g->active_request == NULL && g->requests_head != NULL) {
3814
+ ScrAsyncGenRequest *req = g->requests_head;
3815
+ g->requests_head = req->next;
3816
+ if (g->requests_head == NULL) g->requests_tail = NULL;
3817
+ g->active_request = req->promise; /* request ownership transfers */
3818
+ scr_async_gen_run_active(g, req);
3819
+ scr_gen_slot_reset(&req->arg);
3820
+ scr_gen_exc_reset(&req->thrown);
3821
+ free(req);
3822
+ /* Awaiting or deferred successful settlement keeps this request
3823
+ * active. Immediate done/error settlement cleared it and can consume
3824
+ * the next queued request in this same turn. */
3825
+ if (g->active_request != NULL) break;
3826
+ }
3827
+ scr_gen_release(g);
3828
+ }
3829
+
3830
+ static ScrPromise *scr_async_gen_enqueue(ScrGen *g, int mode,
3831
+ ScrGenSlot *arg,
3832
+ ScrExcCell *thrown) {
3833
+ if (!g->is_async || g->settle_async == NULL) {
3834
+ fputs("scriptc: internal error: async resume of a sync generator\n", stderr);
3835
+ abort();
3836
+ }
3837
+ ScrAsyncGenRequest *req = calloc(1, sizeof *req);
3838
+ if (!req) scr_oom();
3839
+ req->mode = mode;
3840
+ if (arg != NULL) {
3841
+ req->arg = *arg;
3842
+ memset(arg, 0, sizeof *arg);
3843
+ }
3844
+ if (thrown != NULL) scr_gen_exc_move(&req->thrown, thrown);
3845
+ req->promise = scr_promise_new();
3846
+ /* The request owns the original promise reference and one generator
3847
+ * reference; the caller receives a second promise reference. */
3848
+ ScrPromise *result = scr_promise_retain(req->promise);
3849
+ scr_gen_retain(g);
3850
+ if (g->requests_tail != NULL) g->requests_tail->next = req;
3851
+ else g->requests_head = req;
3852
+ g->requests_tail = req;
3853
+ if (g->active_request == NULL && !g->settle_queued) {
3854
+ scr_async_gen_start_queued(g);
3855
+ }
3856
+ return result;
3857
+ }
3858
+
3859
+ ScrPromise *scr_async_gen_next_none(ScrGen *g) {
3860
+ ScrGenSlot arg = {0};
3861
+ return scr_async_gen_enqueue(g, SCR_AG_NEXT, &arg, NULL);
3862
+ }
3863
+
3864
+ ScrPromise *scr_async_gen_next_f64(ScrGen *g, double value) {
3865
+ ScrGenSlot arg = {0};
3866
+ scr_gen_slot_f64(&arg, value);
3867
+ return scr_async_gen_enqueue(g, SCR_AG_NEXT, &arg, NULL);
3868
+ }
3869
+
3870
+ ScrPromise *scr_async_gen_next_bool(ScrGen *g, bool value) {
3871
+ ScrGenSlot arg = {0};
3872
+ scr_gen_slot_bool(&arg, value);
3873
+ return scr_async_gen_enqueue(g, SCR_AG_NEXT, &arg, NULL);
3874
+ }
3875
+
3876
+ ScrPromise *scr_async_gen_next_ref(ScrGen *g, void *value,
3877
+ void (*release)(void *)) {
3878
+ ScrGenSlot arg = {0};
3879
+ scr_gen_slot_ref(&arg, value, release);
3880
+ return scr_async_gen_enqueue(g, SCR_AG_NEXT, &arg, NULL);
3881
+ }
3882
+
3883
+ ScrPromise *scr_async_gen_return_none(ScrGen *g) {
3884
+ ScrGenSlot arg = {0};
3885
+ return scr_async_gen_enqueue(g, SCR_AG_RETURN, &arg, NULL);
3886
+ }
3887
+
3888
+ ScrPromise *scr_async_gen_return_f64(ScrGen *g, double value) {
3889
+ ScrGenSlot arg = {0};
3890
+ scr_gen_slot_f64(&arg, value);
3891
+ return scr_async_gen_enqueue(g, SCR_AG_RETURN, &arg, NULL);
3892
+ }
3893
+
3894
+ ScrPromise *scr_async_gen_return_bool(ScrGen *g, bool value) {
3895
+ ScrGenSlot arg = {0};
3896
+ scr_gen_slot_bool(&arg, value);
3897
+ return scr_async_gen_enqueue(g, SCR_AG_RETURN, &arg, NULL);
3898
+ }
3899
+
3900
+ ScrPromise *scr_async_gen_return_ref(ScrGen *g, void *value,
3901
+ void (*release)(void *)) {
3902
+ ScrGenSlot arg = {0};
3903
+ scr_gen_slot_ref(&arg, value, release);
3904
+ return scr_async_gen_enqueue(g, SCR_AG_RETURN, &arg, NULL);
3905
+ }
3906
+
3907
+ ScrPromise *scr_async_gen_throw(ScrGen *g) {
3908
+ ScrExcCell thrown = {0};
3909
+ scr_gen_exc_move(&thrown, scr_exc_current_cell());
3910
+ return scr_async_gen_enqueue(g, SCR_AG_THROW, NULL, &thrown);
3911
+ }
3912
+
3913
+ static void scr_async_gen_job(ScrGen *g) {
3914
+ g->settle_queued = false;
3915
+ if (g->active_request == NULL || g->async_error.kind != SCR_EXC_NONE) {
3916
+ fputs("scriptc: internal error: invalid async generator settlement job\n", stderr);
3917
+ abort();
3918
+ }
3919
+ scr_async_gen_finish_active(g, false);
3920
+ scr_async_gen_start_queued(g);
3921
+ }
3922
+
3923
+ static void scr_async_gen_resume_ready(ScrGen *g) {
3924
+ if (!g->is_async || g->active_request == NULL) {
3925
+ fputs("scriptc: internal error: async generator resumed without a request\n", stderr);
3926
+ abort();
3927
+ }
3928
+ /* The active request normally owns the generator. Keep an independent
3929
+ * reference across settlement, which releases that request ownership. */
3930
+ scr_gen_retain(g);
3931
+ scr_gen_switch_in(g);
3932
+ if (g->async_error.kind != SCR_EXC_NONE) {
3933
+ scr_async_gen_finish_active(g, true);
3934
+ scr_async_gen_start_queued(g);
3935
+ } else if (g->state != SCR_GEN_AWAITING) {
3936
+ if (g->success_hop_done) {
3937
+ g->success_hop_done = false;
3938
+ scr_async_gen_finish_active(g, false);
3939
+ scr_async_gen_start_queued(g);
3940
+ } else {
3941
+ scr_async_gen_schedule_settle(g);
3942
+ }
3943
+ }
3944
+ scr_gen_release(g);
3945
+ }