@scriptc/compiler 0.1.7 → 0.2.0

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 (1032) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +73 -24
  2. package/ambient/scriptc-overrides.d.ts +10 -6
  3. package/ambient/scriptc.d.ts +15 -0
  4. package/dist/backend/build-cache.d.ts +1 -3
  5. package/dist/backend/build-cache.js +3 -22
  6. package/dist/backend/build-cache.js.map +1 -1
  7. package/dist/backend/cache-root.d.ts +3 -0
  8. package/dist/backend/cache-root.js +23 -0
  9. package/dist/backend/cache-root.js.map +1 -0
  10. package/dist/backend/cycle-analysis.d.ts +15 -0
  11. package/dist/backend/cycle-analysis.js +107 -0
  12. package/dist/backend/cycle-analysis.js.map +1 -0
  13. package/dist/backend/cycle-analysis.test.js +124 -0
  14. package/dist/backend/cycle-analysis.test.js.map +1 -0
  15. package/dist/backend/executable-features.d.ts +4 -0
  16. package/dist/backend/executable-features.js +42 -0
  17. package/dist/backend/executable-features.js.map +1 -0
  18. package/dist/backend/external-c.d.ts +5 -27
  19. package/dist/backend/external-c.js +5 -40
  20. package/dist/backend/external-c.js.map +1 -1
  21. package/dist/backend/ffi-callbacks.d.ts +2 -3
  22. package/dist/backend/ffi-callbacks.js +2 -3
  23. package/dist/backend/ffi-callbacks.js.map +1 -1
  24. package/dist/backend/library-identity-markers.d.ts +4 -9
  25. package/dist/backend/library-identity-markers.js +11 -49
  26. package/dist/backend/library-identity-markers.js.map +1 -1
  27. package/dist/backend/library-pack.d.ts +5 -0
  28. package/dist/backend/library-pack.js +123 -0
  29. package/dist/backend/library-pack.js.map +1 -0
  30. package/dist/backend/link-plan-core.d.ts +20 -0
  31. package/dist/backend/link-plan-core.js +18 -0
  32. package/dist/backend/link-plan-core.js.map +1 -0
  33. package/dist/backend/link-plan.d.ts +1 -1
  34. package/dist/backend/link-plan.js +16 -17
  35. package/dist/backend/link-plan.js.map +1 -1
  36. package/dist/backend/link-trace.d.ts +2 -0
  37. package/dist/backend/link-trace.js +24 -0
  38. package/dist/backend/link-trace.js.map +1 -0
  39. package/dist/backend/linker.js +1 -1
  40. package/dist/backend/linker.js.map +1 -1
  41. package/dist/backend/literals.d.ts +9 -0
  42. package/dist/backend/literals.js +35 -0
  43. package/dist/backend/literals.js.map +1 -0
  44. package/dist/backend/literals.test.d.ts +1 -0
  45. package/dist/backend/literals.test.js +53 -0
  46. package/dist/backend/literals.test.js.map +1 -0
  47. package/dist/backend/llvm/blocks.d.ts +2 -0
  48. package/dist/backend/llvm/blocks.js +9 -4
  49. package/dist/backend/llvm/blocks.js.map +1 -1
  50. package/dist/backend/llvm/blocks.test.d.ts +1 -0
  51. package/dist/backend/llvm/blocks.test.js +91 -0
  52. package/dist/backend/llvm/blocks.test.js.map +1 -0
  53. package/dist/backend/llvm/classes.d.ts +14 -8
  54. package/dist/backend/llvm/classes.js +70 -28
  55. package/dist/backend/llvm/classes.js.map +1 -1
  56. package/dist/backend/llvm/common.d.ts +5 -1
  57. package/dist/backend/llvm/common.js +45 -4
  58. package/dist/backend/llvm/common.js.map +1 -1
  59. package/dist/backend/llvm/debug-info.js +2 -7
  60. package/dist/backend/llvm/debug-info.js.map +1 -1
  61. package/dist/backend/llvm/debug-info.test.d.ts +1 -0
  62. package/dist/backend/llvm/debug-info.test.js +110 -0
  63. package/dist/backend/llvm/debug-info.test.js.map +1 -0
  64. package/dist/backend/llvm/dyn.d.ts +16 -2
  65. package/dist/backend/llvm/dyn.js +494 -165
  66. package/dist/backend/llvm/dyn.js.map +1 -1
  67. package/dist/backend/llvm/emitter.d.ts +596 -1
  68. package/dist/backend/llvm/emitter.js +695 -410
  69. package/dist/backend/llvm/emitter.js.map +1 -1
  70. package/dist/backend/llvm/emitter.test.d.ts +1 -0
  71. package/dist/backend/llvm/emitter.test.js +179 -0
  72. package/dist/backend/llvm/emitter.test.js.map +1 -0
  73. package/dist/backend/llvm/expr-async.js +23 -14
  74. package/dist/backend/llvm/expr-async.js.map +1 -1
  75. package/dist/backend/llvm/expr-bytes.d.ts +1 -1
  76. package/dist/backend/llvm/expr-bytes.js +32 -14
  77. package/dist/backend/llvm/expr-bytes.js.map +1 -1
  78. package/dist/backend/llvm/expr-callbacks.d.ts +1 -1
  79. package/dist/backend/llvm/expr-callbacks.js +25 -22
  80. package/dist/backend/llvm/expr-callbacks.js.map +1 -1
  81. package/dist/backend/llvm/expr-calls.js +136 -35
  82. package/dist/backend/llvm/expr-calls.js.map +1 -1
  83. package/dist/backend/llvm/expr-containers.d.ts +1 -1
  84. package/dist/backend/llvm/expr-containers.js +43 -14
  85. package/dist/backend/llvm/expr-containers.js.map +1 -1
  86. package/dist/backend/llvm/expr-context.d.ts +5 -260
  87. package/dist/backend/llvm/expr-control.js +9 -5
  88. package/dist/backend/llvm/expr-control.js.map +1 -1
  89. package/dist/backend/llvm/expr-dispatch.d.ts +1 -1
  90. package/dist/backend/llvm/expr-dispatch.js +2 -0
  91. package/dist/backend/llvm/expr-dispatch.js.map +1 -1
  92. package/dist/backend/llvm/expr-dynamic.js +62 -74
  93. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  94. package/dist/backend/llvm/expr-island.d.ts +1 -1
  95. package/dist/backend/llvm/expr-island.js +11 -7
  96. package/dist/backend/llvm/expr-island.js.map +1 -1
  97. package/dist/backend/llvm/expr-primitives.d.ts +1 -1
  98. package/dist/backend/llvm/expr-primitives.js +51 -30
  99. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  100. package/dist/backend/llvm/expr-primitives.test.js +1 -1
  101. package/dist/backend/llvm/expr-records.d.ts +5 -1
  102. package/dist/backend/llvm/expr-records.js +43 -4
  103. package/dist/backend/llvm/expr-records.js.map +1 -1
  104. package/dist/backend/llvm/expr-stream-bridges.d.ts +4 -4
  105. package/dist/backend/llvm/expr-stream-bridges.js +102 -121
  106. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  107. package/dist/backend/llvm/expr-stream-bridges.test.d.ts +1 -0
  108. package/dist/backend/llvm/expr-stream-bridges.test.js +55 -0
  109. package/dist/backend/llvm/expr-stream-bridges.test.js.map +1 -0
  110. package/dist/backend/llvm/expr-stream-callbacks.d.ts +1 -1
  111. package/dist/backend/llvm/expr-stream-callbacks.js +12 -12
  112. package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
  113. package/dist/backend/llvm/layouts.d.ts +19 -0
  114. package/dist/backend/llvm/layouts.js +12 -0
  115. package/dist/backend/llvm/layouts.js.map +1 -0
  116. package/dist/backend/llvm/lib-abi.d.ts +19 -0
  117. package/dist/backend/llvm/lib-abi.js +82 -0
  118. package/dist/backend/llvm/lib-abi.js.map +1 -0
  119. package/dist/backend/llvm/lib-connect.d.ts +2 -0
  120. package/dist/backend/llvm/lib-connect.js +51 -0
  121. package/dist/backend/llvm/lib-connect.js.map +1 -0
  122. package/dist/backend/llvm/lib-datagram.d.ts +2 -0
  123. package/dist/backend/llvm/lib-datagram.js +135 -0
  124. package/dist/backend/llvm/lib-datagram.js.map +1 -0
  125. package/dist/backend/llvm/lib-dispatch.js +50 -6
  126. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  127. package/dist/backend/llvm/lib-filesystem.js +30 -18
  128. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  129. package/dist/backend/llvm/lib-http2.d.ts +2 -0
  130. package/dist/backend/llvm/lib-http2.js +215 -0
  131. package/dist/backend/llvm/lib-http2.js.map +1 -0
  132. package/dist/backend/llvm/lib-lookup.d.ts +2 -0
  133. package/dist/backend/llvm/lib-lookup.js +39 -0
  134. package/dist/backend/llvm/lib-lookup.js.map +1 -0
  135. package/dist/backend/llvm/lib-network.js +25 -2
  136. package/dist/backend/llvm/lib-network.js.map +1 -1
  137. package/dist/backend/llvm/lib-process.js +21 -16
  138. package/dist/backend/llvm/lib-process.js.map +1 -1
  139. package/dist/backend/llvm/lib-shared.js +117 -1
  140. package/dist/backend/llvm/lib-shared.js.map +1 -1
  141. package/dist/backend/llvm/lib-stream.js +3 -2
  142. package/dist/backend/llvm/lib-stream.js.map +1 -1
  143. package/dist/backend/llvm/lib-test.d.ts +2 -0
  144. package/dist/backend/llvm/lib-test.js +34 -0
  145. package/dist/backend/llvm/lib-test.js.map +1 -0
  146. package/dist/backend/llvm/lib-tls.d.ts +2 -0
  147. package/dist/backend/llvm/lib-tls.js +82 -0
  148. package/dist/backend/llvm/lib-tls.js.map +1 -0
  149. package/dist/backend/llvm/shapes.d.ts +10 -9
  150. package/dist/backend/llvm/shapes.js +35 -130
  151. package/dist/backend/llvm/shapes.js.map +1 -1
  152. package/dist/backend/llvm/unsupported.d.ts +1 -0
  153. package/dist/backend/llvm/unsupported.js +1 -2
  154. package/dist/backend/llvm/unsupported.js.map +1 -1
  155. package/dist/backend/llvm/walkers.js +1 -7
  156. package/dist/backend/llvm/walkers.js.map +1 -1
  157. package/dist/backend/mangle.d.ts +2 -2
  158. package/dist/backend/mangle.js +16 -5
  159. package/dist/backend/mangle.js.map +1 -1
  160. package/dist/backend/{c/may-throw.d.ts → may-throw.d.ts} +1 -1
  161. package/dist/backend/{c/may-throw.js → may-throw.js} +51 -46
  162. package/dist/backend/may-throw.js.map +1 -0
  163. package/dist/backend/may-throw.test.d.ts +1 -0
  164. package/dist/backend/may-throw.test.js +58 -0
  165. package/dist/backend/may-throw.test.js.map +1 -0
  166. package/dist/backend/native-codegen-core.d.ts +22 -0
  167. package/dist/backend/native-codegen-core.js +44 -0
  168. package/dist/backend/native-codegen-core.js.map +1 -0
  169. package/dist/backend/native-codegen.d.ts +3 -19
  170. package/dist/backend/native-codegen.js +5 -44
  171. package/dist/backend/native-codegen.js.map +1 -1
  172. package/dist/backend/native-codegen.test.js +2 -2
  173. package/dist/backend/native-codegen.test.js.map +1 -1
  174. package/dist/backend/native-link-info-core.d.ts +94 -0
  175. package/dist/backend/native-link-info-core.js +62 -0
  176. package/dist/backend/native-link-info-core.js.map +1 -0
  177. package/dist/backend/native-link-info.d.ts +3 -88
  178. package/dist/backend/native-link-info.js +12 -243
  179. package/dist/backend/native-link-info.js.map +1 -1
  180. package/dist/backend/native-link-info.test.js +41 -146
  181. package/dist/backend/native-link-info.test.js.map +1 -1
  182. package/dist/backend/native-toolchain.d.ts +10 -25
  183. package/dist/backend/native-toolchain.js +31 -211
  184. package/dist/backend/native-toolchain.js.map +1 -1
  185. package/dist/backend/native-toolchain.test.js +5 -5
  186. package/dist/backend/native-toolchain.test.js.map +1 -1
  187. package/dist/backend/native-tools.d.ts +24 -0
  188. package/dist/backend/native-tools.js +33 -0
  189. package/dist/backend/native-tools.js.map +1 -0
  190. package/dist/backend/object-localize.js +19 -8
  191. package/dist/backend/object-localize.js.map +1 -1
  192. package/dist/backend/object-localize.test.js +22 -0
  193. package/dist/backend/object-localize.test.js.map +1 -1
  194. package/dist/backend/runtime-abi.d.ts +2 -2
  195. package/dist/backend/runtime-abi.js +2 -2
  196. package/dist/backend/runtime-pack-core.d.ts +101 -0
  197. package/dist/backend/runtime-pack-core.js +172 -0
  198. package/dist/backend/runtime-pack-core.js.map +1 -0
  199. package/dist/backend/runtime-pack-native.d.ts +21 -0
  200. package/dist/backend/runtime-pack-native.js +70 -0
  201. package/dist/backend/runtime-pack-native.js.map +1 -0
  202. package/dist/backend/runtime-pack-targets.test.js +1 -1
  203. package/dist/backend/runtime-pack.d.ts +3 -83
  204. package/dist/backend/runtime-pack.js +8 -151
  205. package/dist/backend/runtime-pack.js.map +1 -1
  206. package/dist/backend/runtime-pack.test.js +24 -1
  207. package/dist/backend/runtime-pack.test.js.map +1 -1
  208. package/dist/backend/target-diagnostics.d.ts +22 -0
  209. package/dist/backend/target-diagnostics.js +108 -0
  210. package/dist/backend/target-diagnostics.js.map +1 -0
  211. package/dist/backend/target-platform.d.ts +15 -0
  212. package/dist/backend/target-platform.js +72 -0
  213. package/dist/backend/target-platform.js.map +1 -0
  214. package/dist/backend/targets.d.ts +13 -4
  215. package/dist/backend/targets.js +95 -30
  216. package/dist/backend/targets.js.map +1 -1
  217. package/dist/backend/targets.test.js +65 -4
  218. package/dist/backend/targets.test.js.map +1 -1
  219. package/dist/backend/toolchain-environment.d.ts +6 -0
  220. package/dist/backend/toolchain-environment.js +99 -0
  221. package/dist/backend/toolchain-environment.js.map +1 -0
  222. package/dist/backend/vendor-archives.d.ts +1 -9
  223. package/dist/backend/vendor-archives.js +2 -9
  224. package/dist/backend/vendor-archives.js.map +1 -1
  225. package/dist/backend/vendor-inputs.d.ts +9 -0
  226. package/dist/backend/vendor-inputs.js +10 -0
  227. package/dist/backend/vendor-inputs.js.map +1 -0
  228. package/dist/backend/warm-cache.d.ts +3 -0
  229. package/dist/backend/warm-cache.js +41 -0
  230. package/dist/backend/warm-cache.js.map +1 -0
  231. package/dist/cli/command.d.ts +3 -0
  232. package/dist/cli/command.js +328 -0
  233. package/dist/cli/command.js.map +1 -0
  234. package/dist/cli/host.d.ts +24 -0
  235. package/dist/cli/host.js +2 -0
  236. package/dist/cli/host.js.map +1 -0
  237. package/dist/cli/output-options.d.ts +26 -0
  238. package/dist/cli/output-options.js +60 -0
  239. package/dist/cli/output-options.js.map +1 -0
  240. package/dist/cli/paths.d.ts +12 -0
  241. package/dist/cli/paths.js +42 -0
  242. package/dist/cli/paths.js.map +1 -0
  243. package/dist/cli/usage.d.ts +74 -0
  244. package/dist/cli/usage.js +86 -0
  245. package/dist/cli/usage.js.map +1 -0
  246. package/dist/cli/wasi-paths.d.ts +8 -0
  247. package/dist/cli/wasi-paths.js +41 -0
  248. package/dist/cli/wasi-paths.js.map +1 -0
  249. package/dist/cli/wasi-runner.d.ts +2 -0
  250. package/dist/cli/wasi-runner.js +28 -0
  251. package/dist/cli/wasi-runner.js.map +1 -0
  252. package/dist/compat/fetch-profile.js +3 -3
  253. package/dist/compat/fetch-profile.js.map +1 -1
  254. package/dist/compile-types.d.ts +162 -0
  255. package/dist/compile-types.js +2 -0
  256. package/dist/compile-types.js.map +1 -0
  257. package/dist/coverage/report.js +11 -5
  258. package/dist/coverage/report.js.map +1 -1
  259. package/dist/coverage/surface-manifest.js +5 -2
  260. package/dist/coverage/surface-manifest.js.map +1 -1
  261. package/dist/diagnostics/diagnostic.js +3 -3
  262. package/dist/diagnostics/diagnostic.js.map +1 -1
  263. package/dist/executable/executable-cache.d.ts +3 -4
  264. package/dist/executable/executable-cache.js +5 -6
  265. package/dist/executable/executable-cache.js.map +1 -1
  266. package/dist/executable/executable-cache.test.js +16 -17
  267. package/dist/executable/executable-cache.test.js.map +1 -1
  268. package/dist/executable/prepare.d.ts +14 -0
  269. package/dist/executable/prepare.js +66 -0
  270. package/dist/executable/prepare.js.map +1 -0
  271. package/dist/ffi/ffi-manifest.d.ts +11 -4
  272. package/dist/ffi/ffi-manifest.js +170 -58
  273. package/dist/ffi/ffi-manifest.js.map +1 -1
  274. package/dist/ffi/ffi-manifest.test.d.ts +1 -0
  275. package/dist/ffi/ffi-manifest.test.js +111 -0
  276. package/dist/ffi/ffi-manifest.test.js.map +1 -0
  277. package/dist/format-integer.d.ts +3 -0
  278. package/dist/format-integer.js +14 -0
  279. package/dist/format-integer.js.map +1 -0
  280. package/dist/frontend/analysis.d.ts +5 -0
  281. package/dist/frontend/analysis.js +88 -0
  282. package/dist/frontend/analysis.js.map +1 -0
  283. package/dist/frontend/arguments-usage.d.ts +1 -3
  284. package/dist/frontend/arguments-usage.js.map +1 -1
  285. package/dist/frontend/builtin-modules.d.ts +1 -1
  286. package/dist/frontend/builtin-modules.js +1 -1
  287. package/dist/frontend/builtin-modules.js.map +1 -1
  288. package/dist/frontend/cjs-lexer.d.ts +4 -25
  289. package/dist/frontend/cjs-lexer.js +6 -806
  290. package/dist/frontend/cjs-lexer.js.map +1 -1
  291. package/dist/frontend/cjs-resolve.d.ts +5 -0
  292. package/dist/frontend/cjs-resolve.js +429 -0
  293. package/dist/frontend/cjs-resolve.js.map +1 -0
  294. package/dist/frontend/cjs-syntax.d.ts +26 -0
  295. package/dist/frontend/cjs-syntax.js +806 -0
  296. package/dist/frontend/cjs-syntax.js.map +1 -0
  297. package/dist/frontend/comptime-node.d.ts +4 -0
  298. package/dist/frontend/comptime-node.js +16 -0
  299. package/dist/frontend/comptime-node.js.map +1 -0
  300. package/dist/frontend/comptime-node.test.d.ts +1 -0
  301. package/dist/frontend/comptime-node.test.js +37 -0
  302. package/dist/frontend/comptime-node.test.js.map +1 -0
  303. package/dist/frontend/dts-paths.d.ts +3 -4
  304. package/dist/frontend/dts-paths.js +15 -8
  305. package/dist/frontend/dts-paths.js.map +1 -1
  306. package/dist/frontend/fork-target.js +2 -2
  307. package/dist/frontend/fork-target.js.map +1 -1
  308. package/dist/frontend/helper-tokens.d.ts +1 -0
  309. package/dist/frontend/helper-tokens.js +147 -0
  310. package/dist/frontend/helper-tokens.js.map +1 -0
  311. package/dist/frontend/helper-tokens.test.d.ts +1 -0
  312. package/dist/frontend/helper-tokens.test.js +35 -0
  313. package/dist/frontend/helper-tokens.test.js.map +1 -0
  314. package/dist/frontend/inferred-js-diagnostics.d.ts +5 -0
  315. package/dist/frontend/inferred-js-diagnostics.js +69 -0
  316. package/dist/frontend/inferred-js-diagnostics.js.map +1 -0
  317. package/dist/frontend/inferred-js-diagnostics.test.d.ts +1 -0
  318. package/dist/frontend/inferred-js-diagnostics.test.js +58 -0
  319. package/dist/frontend/inferred-js-diagnostics.test.js.map +1 -0
  320. package/dist/frontend/input-tracker.d.ts +5 -2
  321. package/dist/frontend/input-tracker.js +24 -3
  322. package/dist/frontend/input-tracker.js.map +1 -1
  323. package/dist/frontend/input-tracker.test.js +23 -0
  324. package/dist/frontend/input-tracker.test.js.map +1 -1
  325. package/dist/frontend/lib-contract.js +32 -24
  326. package/dist/frontend/lib-contract.js.map +1 -1
  327. package/dist/frontend/literal-values.d.ts +4 -0
  328. package/dist/frontend/literal-values.js +21 -0
  329. package/dist/frontend/literal-values.js.map +1 -0
  330. package/dist/frontend/literal-values.test.d.ts +1 -0
  331. package/dist/frontend/literal-values.test.js +91 -0
  332. package/dist/frontend/literal-values.test.js.map +1 -0
  333. package/dist/frontend/lowering/abstract-equality.d.ts +1 -1
  334. package/dist/frontend/lowering/abstract-equality.js +3 -0
  335. package/dist/frontend/lowering/abstract-equality.js.map +1 -1
  336. package/dist/frontend/lowering/array-indexed-mutation.js +11 -6
  337. package/dist/frontend/lowering/array-indexed-mutation.js.map +1 -1
  338. package/dist/frontend/lowering/array-values.d.ts +4 -1
  339. package/dist/frontend/lowering/array-values.js +43 -1
  340. package/dist/frontend/lowering/array-values.js.map +1 -1
  341. package/dist/frontend/lowering/callback-arg.js +1 -0
  342. package/dist/frontend/lowering/callback-arg.js.map +1 -1
  343. package/dist/frontend/lowering/class-callbacks.d.ts +12 -0
  344. package/dist/frontend/lowering/class-callbacks.js +63 -0
  345. package/dist/frontend/lowering/class-callbacks.js.map +1 -0
  346. package/dist/frontend/lowering/class-descriptors.d.ts +9 -0
  347. package/dist/frontend/lowering/class-descriptors.js +73 -0
  348. package/dist/frontend/lowering/class-descriptors.js.map +1 -0
  349. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +41 -0
  350. package/dist/frontend/lowering/class-dynamic-dispatch.js +803 -0
  351. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -0
  352. package/dist/frontend/lowering/class-dynamic-dispatch.test.d.ts +1 -0
  353. package/dist/frontend/lowering/class-dynamic-dispatch.test.js +92 -0
  354. package/dist/frontend/lowering/class-dynamic-dispatch.test.js.map +1 -0
  355. package/dist/frontend/lowering/class-instance-constructor.d.ts +7 -0
  356. package/dist/frontend/lowering/class-instance-constructor.js +64 -0
  357. package/dist/frontend/lowering/class-instance-constructor.js.map +1 -0
  358. package/dist/frontend/lowering/class-method-values.d.ts +10 -0
  359. package/dist/frontend/lowering/class-method-values.js +170 -0
  360. package/dist/frontend/lowering/class-method-values.js.map +1 -0
  361. package/dist/frontend/lowering/class-prototypes.d.ts +16 -0
  362. package/dist/frontend/lowering/class-prototypes.js +134 -0
  363. package/dist/frontend/lowering/class-prototypes.js.map +1 -0
  364. package/dist/frontend/lowering/class-static-data.d.ts +6 -0
  365. package/dist/frontend/lowering/class-static-data.js +56 -0
  366. package/dist/frontend/lowering/class-static-data.js.map +1 -0
  367. package/dist/frontend/lowering/containers/buffer-numeric-methods.d.ts +4 -0
  368. package/dist/frontend/lowering/containers/buffer-numeric-methods.js +26 -0
  369. package/dist/frontend/lowering/containers/buffer-numeric-methods.js.map +1 -0
  370. package/dist/frontend/lowering/containers/bytes.d.ts +11 -7
  371. package/dist/frontend/lowering/containers/bytes.js +164 -155
  372. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  373. package/dist/frontend/lowering/containers/string-and-regexp.d.ts +2 -2
  374. package/dist/frontend/lowering/containers/string-and-regexp.js +39 -16
  375. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  376. package/dist/frontend/lowering/containers/string-replacement.d.ts +7 -0
  377. package/dist/frontend/lowering/containers/string-replacement.js +217 -0
  378. package/dist/frontend/lowering/containers/string-replacement.js.map +1 -0
  379. package/dist/frontend/lowering/error-methods.d.ts +11 -0
  380. package/dist/frontend/lowering/error-methods.js +78 -0
  381. package/dist/frontend/lowering/error-methods.js.map +1 -0
  382. package/dist/frontend/lowering/expressions/global-symbols.d.ts +6 -0
  383. package/dist/frontend/lowering/expressions/global-symbols.js +11 -0
  384. package/dist/frontend/lowering/expressions/global-symbols.js.map +1 -0
  385. package/dist/frontend/lowering/expressions/native-proxy.d.ts +7 -0
  386. package/dist/frontend/lowering/expressions/native-proxy.js +49 -0
  387. package/dist/frontend/lowering/expressions/native-proxy.js.map +1 -0
  388. package/dist/frontend/lowering/expressions/nullish-assignment.d.ts +6 -0
  389. package/dist/frontend/lowering/expressions/nullish-assignment.js +124 -0
  390. package/dist/frontend/lowering/expressions/nullish-assignment.js.map +1 -0
  391. package/dist/frontend/lowering/expressions/object-literals.d.ts +8 -8
  392. package/dist/frontend/lowering/expressions/object-literals.js +473 -178
  393. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  394. package/dist/frontend/lowering/expressions/optional-chains.js +20 -8
  395. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
  396. package/dist/frontend/lowering/expressions/try-lower-expression.js +1 -0
  397. package/dist/frontend/lowering/expressions/try-lower-expression.js.map +1 -1
  398. package/dist/frontend/lowering/expressions/union-field-write.d.ts +8 -0
  399. package/dist/frontend/lowering/expressions/union-field-write.js +71 -0
  400. package/dist/frontend/lowering/expressions/union-field-write.js.map +1 -0
  401. package/dist/frontend/lowering/function-context.d.ts +93 -0
  402. package/dist/frontend/lowering/function-context.js +103 -0
  403. package/dist/frontend/lowering/function-context.js.map +1 -0
  404. package/dist/frontend/lowering/generator-delegation.d.ts +7 -0
  405. package/dist/frontend/lowering/generator-delegation.js +85 -0
  406. package/dist/frontend/lowering/generator-delegation.js.map +1 -0
  407. package/dist/frontend/lowering/generator-dynamic-dispatch.d.ts +10 -0
  408. package/dist/frontend/lowering/generator-dynamic-dispatch.js +105 -0
  409. package/dist/frontend/lowering/generator-dynamic-dispatch.js.map +1 -0
  410. package/dist/frontend/lowering/lib-boundary.d.ts +2 -1
  411. package/dist/frontend/lowering/lib-boundary.js +59 -20
  412. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  413. package/dist/frontend/lowering/lib-boundary.test.d.ts +1 -0
  414. package/dist/frontend/lowering/lib-boundary.test.js +45 -0
  415. package/dist/frontend/lowering/lib-boundary.test.js.map +1 -0
  416. package/dist/frontend/lowering/lower-array-sort.d.ts +1 -1
  417. package/dist/frontend/lowering/lower-assert.d.ts +1 -1
  418. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  419. package/dist/frontend/lowering/lower-async-iteration.d.ts +1 -1
  420. package/dist/frontend/lowering/lower-async-iteration.js.map +1 -1
  421. package/dist/frontend/lowering/lower-builtin-values.d.ts +12 -0
  422. package/dist/frontend/lowering/lower-builtin-values.js +139 -0
  423. package/dist/frontend/lowering/lower-builtin-values.js.map +1 -0
  424. package/dist/frontend/lowering/lower-builtins.d.ts +27 -41
  425. package/dist/frontend/lowering/lower-builtins.js +539 -343
  426. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  427. package/dist/frontend/lowering/lower-calls.d.ts +20 -17
  428. package/dist/frontend/lowering/lower-calls.js +1236 -353
  429. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  430. package/dist/frontend/lowering/lower-classes.d.ts +83 -45
  431. package/dist/frontend/lowering/lower-classes.js +952 -339
  432. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  433. package/dist/frontend/lowering/lower-comptime.d.ts +1 -1
  434. package/dist/frontend/lowering/lower-comptime.js +23 -32
  435. package/dist/frontend/lowering/lower-comptime.js.map +1 -1
  436. package/dist/frontend/lowering/lower-containers.d.ts +27 -32
  437. package/dist/frontend/lowering/lower-containers.js +796 -151
  438. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  439. package/dist/frontend/lowering/lower-dgram.d.ts +1 -1
  440. package/dist/frontend/lowering/lower-dgram.js.map +1 -1
  441. package/dist/frontend/lowering/lower-enums.d.ts +1 -1
  442. package/dist/frontend/lowering/lower-enums.js.map +1 -1
  443. package/dist/frontend/lowering/lower-event-emitter.d.ts +30 -1
  444. package/dist/frontend/lowering/lower-event-emitter.js +58 -26
  445. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  446. package/dist/frontend/lowering/lower-expando.d.ts +7 -1
  447. package/dist/frontend/lowering/lower-expando.js +14 -6
  448. package/dist/frontend/lowering/lower-expando.js.map +1 -1
  449. package/dist/frontend/lowering/lower-exprs.d.ts +35 -11
  450. package/dist/frontend/lowering/lower-exprs.js +1674 -779
  451. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  452. package/dist/frontend/lowering/lower-generators.d.ts +2 -5
  453. package/dist/frontend/lowering/lower-generators.js +77 -46
  454. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  455. package/dist/frontend/lowering/lower-global-value.d.ts +7 -0
  456. package/dist/frontend/lowering/lower-global-value.js +17 -0
  457. package/dist/frontend/lowering/lower-global-value.js.map +1 -0
  458. package/dist/frontend/lowering/lower-inspect.d.ts +1 -1
  459. package/dist/frontend/lowering/lower-inspect.js +17 -8
  460. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  461. package/dist/frontend/lowering/lower-island.d.ts +5 -8
  462. package/dist/frontend/lowering/lower-island.js +34 -23
  463. package/dist/frontend/lowering/lower-island.js.map +1 -1
  464. package/dist/frontend/lowering/lower-mixins.d.ts +2 -2
  465. package/dist/frontend/lowering/lower-mixins.js +5 -3
  466. package/dist/frontend/lowering/lower-mixins.js.map +1 -1
  467. package/dist/frontend/lowering/lower-modules.d.ts +1 -1
  468. package/dist/frontend/lowering/lower-modules.js +233 -30
  469. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  470. package/dist/frontend/lowering/lower-namespaces.d.ts +1 -1
  471. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  472. package/dist/frontend/lowering/lower-node-module.d.ts +1 -1
  473. package/dist/frontend/lowering/lower-node-module.js +13 -10
  474. package/dist/frontend/lowering/lower-node-module.js.map +1 -1
  475. package/dist/frontend/lowering/lower-server.d.ts +1 -1
  476. package/dist/frontend/lowering/lower-server.js +6 -10
  477. package/dist/frontend/lowering/lower-server.js.map +1 -1
  478. package/dist/frontend/lowering/lower-stmts.d.ts +10 -14
  479. package/dist/frontend/lowering/lower-stmts.js +728 -496
  480. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  481. package/dist/frontend/lowering/lower-stream.d.ts +1 -1
  482. package/dist/frontend/lowering/lower-stream.js +19 -10
  483. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  484. package/dist/frontend/lowering/lower-test.d.ts +1 -1
  485. package/dist/frontend/lowering/lower-test.js.map +1 -1
  486. package/dist/frontend/lowering/lower-url.d.ts +6 -0
  487. package/dist/frontend/lowering/lower-url.js +77 -0
  488. package/dist/frontend/lowering/lower-url.js.map +1 -0
  489. package/dist/frontend/lowering/lowerer.d.ts +113 -189
  490. package/dist/frontend/lowering/lowerer.js +1031 -672
  491. package/dist/frontend/lowering/lowerer.js.map +1 -1
  492. package/dist/frontend/lowering/lowerer.test.d.ts +1 -0
  493. package/dist/frontend/lowering/lowerer.test.js +26 -0
  494. package/dist/frontend/lowering/lowerer.test.js.map +1 -0
  495. package/dist/frontend/lowering/native-ffi.d.ts +5 -0
  496. package/dist/frontend/lowering/native-ffi.js +40 -0
  497. package/dist/frontend/lowering/native-ffi.js.map +1 -0
  498. package/dist/frontend/lowering/object-enumeration-receiver.d.ts +7 -0
  499. package/dist/frontend/lowering/object-enumeration-receiver.js +33 -0
  500. package/dist/frontend/lowering/object-enumeration-receiver.js.map +1 -0
  501. package/dist/frontend/lowering/object-factory-new.d.ts +8 -0
  502. package/dist/frontend/lowering/object-factory-new.js +68 -0
  503. package/dist/frontend/lowering/object-factory-new.js.map +1 -0
  504. package/dist/frontend/lowering/optional-arguments.js +6 -1
  505. package/dist/frontend/lowering/optional-arguments.js.map +1 -1
  506. package/dist/frontend/lowering/pairs-snapshot.js +2 -1
  507. package/dist/frontend/lowering/pairs-snapshot.js.map +1 -1
  508. package/dist/frontend/lowering/runtime-optional-locals.d.ts +14 -0
  509. package/dist/frontend/lowering/runtime-optional-locals.js +41 -0
  510. package/dist/frontend/lowering/runtime-optional-locals.js.map +1 -0
  511. package/dist/frontend/lowering/runtime-optional-locals.test.d.ts +1 -0
  512. package/dist/frontend/lowering/runtime-optional-locals.test.js +85 -0
  513. package/dist/frontend/lowering/runtime-optional-locals.test.js.map +1 -0
  514. package/dist/frontend/lowering/sanitize-class-types.d.ts +8 -0
  515. package/dist/frontend/lowering/sanitize-class-types.js +79 -0
  516. package/dist/frontend/lowering/sanitize-class-types.js.map +1 -0
  517. package/dist/frontend/lowering/sanitize-class-types.test.d.ts +1 -0
  518. package/dist/frontend/lowering/sanitize-class-types.test.js +60 -0
  519. package/dist/frontend/lowering/sanitize-class-types.test.js.map +1 -0
  520. package/dist/frontend/lowering/static-this.d.ts +5 -1
  521. package/dist/frontend/lowering/static-this.js +28 -2
  522. package/dist/frontend/lowering/static-this.js.map +1 -1
  523. package/dist/frontend/lowering/string-index.d.ts +7 -0
  524. package/dist/frontend/lowering/string-index.js +39 -0
  525. package/dist/frontend/lowering/string-index.js.map +1 -0
  526. package/dist/frontend/lowering/surfaces.d.ts +8 -3
  527. package/dist/frontend/lowering/surfaces.js +61 -29
  528. package/dist/frontend/lowering/surfaces.js.map +1 -1
  529. package/dist/frontend/lowering/symbol-fields.d.ts +22 -0
  530. package/dist/frontend/lowering/symbol-fields.js +183 -0
  531. package/dist/frontend/lowering/symbol-fields.js.map +1 -0
  532. package/dist/frontend/lowering/symbol-methods.d.ts +7 -0
  533. package/dist/frontend/lowering/symbol-methods.js +30 -0
  534. package/dist/frontend/lowering/symbol-methods.js.map +1 -0
  535. package/dist/frontend/lowering/text-decoder-encoding.d.ts +10 -0
  536. package/dist/frontend/lowering/text-decoder-encoding.js +77 -0
  537. package/dist/frontend/lowering/text-decoder-encoding.js.map +1 -0
  538. package/dist/frontend/lowering/text-decoder-encoding.test.d.ts +1 -0
  539. package/dist/frontend/lowering/text-decoder-encoding.test.js +38 -0
  540. package/dist/frontend/lowering/text-decoder-encoding.test.js.map +1 -0
  541. package/dist/frontend/lowering/union-narrow.d.ts +9 -0
  542. package/dist/frontend/lowering/union-narrow.js +59 -0
  543. package/dist/frontend/lowering/union-narrow.js.map +1 -0
  544. package/dist/frontend/lowering/union-narrow.test.d.ts +1 -0
  545. package/dist/frontend/lowering/union-narrow.test.js +72 -0
  546. package/dist/frontend/lowering/union-narrow.test.js.map +1 -0
  547. package/dist/frontend/lowering/union-retag.d.ts +43 -0
  548. package/dist/frontend/lowering/union-retag.js +259 -0
  549. package/dist/frontend/lowering/union-retag.js.map +1 -0
  550. package/dist/frontend/lowering/union-retag.test.d.ts +1 -0
  551. package/dist/frontend/lowering/union-retag.test.js +405 -0
  552. package/dist/frontend/lowering/union-retag.test.js.map +1 -0
  553. package/dist/frontend/lowering/unregistered-class-types.d.ts +14 -0
  554. package/dist/frontend/lowering/unregistered-class-types.js +94 -0
  555. package/dist/frontend/lowering/unregistered-class-types.js.map +1 -0
  556. package/dist/frontend/lowering/unregistered-class-types.test.d.ts +1 -0
  557. package/dist/frontend/lowering/unregistered-class-types.test.js +65 -0
  558. package/dist/frontend/lowering/unregistered-class-types.test.js.map +1 -0
  559. package/dist/frontend/lowering/width-lift.d.ts +40 -0
  560. package/dist/frontend/lowering/width-lift.js +2 -0
  561. package/dist/frontend/lowering/width-lift.js.map +1 -0
  562. package/dist/frontend/module-syntax.d.ts +58 -0
  563. package/dist/frontend/module-syntax.js +123 -0
  564. package/dist/frontend/module-syntax.js.map +1 -0
  565. package/dist/frontend/module-syntax.test.d.ts +1 -0
  566. package/dist/frontend/module-syntax.test.js +78 -0
  567. package/dist/frontend/module-syntax.test.js.map +1 -0
  568. package/dist/frontend/npm-fetch-analysis.d.ts +17 -0
  569. package/dist/frontend/npm-fetch-analysis.js +100 -0
  570. package/dist/frontend/npm-fetch-analysis.js.map +1 -0
  571. package/dist/frontend/npm-fetch-analysis.test.d.ts +1 -0
  572. package/dist/frontend/npm-fetch-analysis.test.js +107 -0
  573. package/dist/frontend/npm-fetch-analysis.test.js.map +1 -0
  574. package/dist/frontend/npm-fetch-node.d.ts +2 -0
  575. package/dist/frontend/npm-fetch-node.js +12 -0
  576. package/dist/frontend/npm-fetch-node.js.map +1 -0
  577. package/dist/frontend/npm-fetch-syntax.d.ts +6 -0
  578. package/dist/frontend/npm-fetch-syntax.js +207 -0
  579. package/dist/frontend/npm-fetch-syntax.js.map +1 -0
  580. package/dist/frontend/npm-node.d.ts +10 -0
  581. package/dist/frontend/npm-node.js +14 -0
  582. package/dist/frontend/npm-node.js.map +1 -0
  583. package/dist/frontend/npm-static-bundled-cjs.d.ts +8 -0
  584. package/dist/frontend/npm-static-bundled-cjs.js +236 -0
  585. package/dist/frontend/npm-static-bundled-cjs.js.map +1 -0
  586. package/dist/frontend/npm-static-bundled-cjs.test.d.ts +1 -0
  587. package/dist/frontend/npm-static-bundled-cjs.test.js +69 -0
  588. package/dist/frontend/npm-static-bundled-cjs.test.js.map +1 -0
  589. package/dist/frontend/npm-static-declaration-syntax.d.ts +57 -0
  590. package/dist/frontend/npm-static-declaration-syntax.js +944 -0
  591. package/dist/frontend/npm-static-declaration-syntax.js.map +1 -0
  592. package/dist/frontend/npm-static-declarations.d.ts +11 -39
  593. package/dist/frontend/npm-static-declarations.js +22 -561
  594. package/dist/frontend/npm-static-declarations.js.map +1 -1
  595. package/dist/frontend/npm-static-declarations.test.js +245 -6
  596. package/dist/frontend/npm-static-declarations.test.js.map +1 -1
  597. package/dist/frontend/npm-static-prune.d.ts +1 -1
  598. package/dist/frontend/npm-static-prune.js +5 -4
  599. package/dist/frontend/npm-static-prune.js.map +1 -1
  600. package/dist/frontend/npm-static-prune.test.js +1 -1
  601. package/dist/frontend/npm-static-prune.test.js.map +1 -1
  602. package/dist/frontend/npm-static-rewrite-host.d.ts +4 -0
  603. package/dist/frontend/npm-static-rewrite-host.js +179 -0
  604. package/dist/frontend/npm-static-rewrite-host.js.map +1 -0
  605. package/dist/frontend/npm-static-rewrite-syntax.d.ts +16 -0
  606. package/dist/frontend/npm-static-rewrite-syntax.js +905 -0
  607. package/dist/frontend/npm-static-rewrite-syntax.js.map +1 -0
  608. package/dist/frontend/npm-static-rewrite.d.ts +0 -5
  609. package/dist/frontend/npm-static-rewrite.js +2 -1079
  610. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  611. package/dist/frontend/npm-static-subtyping.d.ts +5 -0
  612. package/dist/frontend/npm-static-subtyping.js +55 -0
  613. package/dist/frontend/npm-static-subtyping.js.map +1 -0
  614. package/dist/frontend/npm-static-subtyping.test.d.ts +1 -0
  615. package/dist/frontend/npm-static-subtyping.test.js +58 -0
  616. package/dist/frontend/npm-static-subtyping.test.js.map +1 -0
  617. package/dist/frontend/npm-static.d.ts +7 -15
  618. package/dist/frontend/npm-static.js +19 -28
  619. package/dist/frontend/npm-static.js.map +1 -1
  620. package/dist/frontend/npm.d.ts +8 -69
  621. package/dist/frontend/npm.js +21 -361
  622. package/dist/frontend/npm.js.map +1 -1
  623. package/dist/frontend/npm.test.js +2 -2
  624. package/dist/frontend/npm.test.js.map +1 -1
  625. package/dist/frontend/pipeline-native.d.ts +6 -0
  626. package/dist/frontend/pipeline-native.js +32 -0
  627. package/dist/frontend/pipeline-native.js.map +1 -0
  628. package/dist/frontend/pipeline.d.ts +54 -0
  629. package/dist/frontend/pipeline.js +382 -0
  630. package/dist/frontend/pipeline.js.map +1 -0
  631. package/dist/frontend/pipeline.test.d.ts +1 -0
  632. package/dist/frontend/pipeline.test.js +77 -0
  633. package/dist/frontend/pipeline.test.js.map +1 -0
  634. package/dist/frontend/program-analysis.d.ts +10 -0
  635. package/dist/frontend/program-analysis.js +14 -0
  636. package/dist/frontend/program-analysis.js.map +1 -0
  637. package/dist/frontend/program-node.d.ts +9 -0
  638. package/dist/frontend/program-node.js +48 -0
  639. package/dist/frontend/program-node.js.map +1 -0
  640. package/dist/frontend/program.d.ts +38 -19
  641. package/dist/frontend/program.js +344 -169
  642. package/dist/frontend/program.js.map +1 -1
  643. package/dist/frontend/program.test.js +87 -2
  644. package/dist/frontend/program.test.js.map +1 -1
  645. package/dist/frontend/provenance-core.d.ts +9 -0
  646. package/dist/frontend/provenance-core.js +435 -0
  647. package/dist/frontend/provenance-core.js.map +1 -0
  648. package/dist/frontend/provenance.d.ts +0 -4
  649. package/dist/frontend/provenance.js +4 -459
  650. package/dist/frontend/provenance.js.map +1 -1
  651. package/dist/frontend/resolve.d.ts +3 -1
  652. package/dist/frontend/resolve.js +6 -3
  653. package/dist/frontend/resolve.js.map +1 -1
  654. package/dist/frontend/runtime-resolve.d.ts +4 -3
  655. package/dist/frontend/runtime-resolve.js +22 -18
  656. package/dist/frontend/runtime-resolve.js.map +1 -1
  657. package/dist/frontend/runtime-resolve.test.js +53 -0
  658. package/dist/frontend/runtime-resolve.test.js.map +1 -1
  659. package/dist/frontend/services-node.d.ts +5 -0
  660. package/dist/frontend/services-node.js +19 -0
  661. package/dist/frontend/services-node.js.map +1 -0
  662. package/dist/frontend/services-node.test.d.ts +1 -0
  663. package/dist/frontend/services-node.test.js +70 -0
  664. package/dist/frontend/services-node.test.js.map +1 -0
  665. package/dist/frontend/services.d.ts +44 -0
  666. package/dist/frontend/services.js +90 -0
  667. package/dist/frontend/services.js.map +1 -0
  668. package/dist/frontend/services.test.d.ts +1 -0
  669. package/dist/frontend/services.test.js +174 -0
  670. package/dist/frontend/services.test.js.map +1 -0
  671. package/dist/frontend/ts7/adapter.d.ts +3 -3
  672. package/dist/frontend/ts7/adapter.js +14 -31
  673. package/dist/frontend/ts7/adapter.js.map +1 -1
  674. package/dist/frontend/ts7/api.d.ts +16 -0
  675. package/dist/frontend/ts7/api.js +24 -0
  676. package/dist/frontend/ts7/api.js.map +1 -0
  677. package/dist/frontend/ts7/ast-bytes.d.ts +31 -0
  678. package/dist/frontend/ts7/ast-bytes.js +137 -0
  679. package/dist/frontend/ts7/ast-bytes.js.map +1 -0
  680. package/dist/frontend/ts7/ast-bytes.test.d.ts +1 -0
  681. package/dist/frontend/ts7/ast-bytes.test.js +73 -0
  682. package/dist/frontend/ts7/ast-bytes.test.js.map +1 -0
  683. package/dist/frontend/ts7/ast-guards.generated.d.ts +353 -0
  684. package/dist/frontend/ts7/ast-guards.generated.js +1951 -0
  685. package/dist/frontend/ts7/ast-guards.generated.js.map +1 -0
  686. package/dist/frontend/ts7/ast-guards.test.d.ts +1 -0
  687. package/dist/frontend/ts7/ast-guards.test.js +43 -0
  688. package/dist/frontend/ts7/ast-guards.test.js.map +1 -0
  689. package/dist/frontend/ts7/ast-node.d.ts +194 -0
  690. package/dist/frontend/ts7/ast-node.js +448 -0
  691. package/dist/frontend/ts7/ast-node.js.map +1 -0
  692. package/dist/frontend/ts7/ast-node.test.d.ts +1 -0
  693. package/dist/frontend/ts7/ast-node.test.js +266 -0
  694. package/dist/frontend/ts7/ast-node.test.js.map +1 -0
  695. package/dist/frontend/ts7/ast-schema.generated.d.ts +503 -0
  696. package/dist/frontend/ts7/ast-schema.generated.js +1446 -0
  697. package/dist/frontend/ts7/ast-schema.generated.js.map +1 -0
  698. package/dist/frontend/ts7/ast-text.d.ts +6 -0
  699. package/dist/frontend/ts7/ast-text.js +124 -0
  700. package/dist/frontend/ts7/ast-text.js.map +1 -0
  701. package/dist/frontend/ts7/ast-text.test.d.ts +1 -0
  702. package/dist/frontend/ts7/ast-text.test.js +38 -0
  703. package/dist/frontend/ts7/ast-text.test.js.map +1 -0
  704. package/dist/frontend/ts7/ast-tokens.generated.d.ts +2 -0
  705. package/dist/frontend/ts7/ast-tokens.generated.js +155 -0
  706. package/dist/frontend/ts7/ast-tokens.generated.js.map +1 -0
  707. package/dist/frontend/ts7/ast-types.d.ts +42 -0
  708. package/dist/frontend/ts7/ast-types.generated.d.ts +1615 -0
  709. package/dist/frontend/ts7/ast-types.generated.js +5 -0
  710. package/dist/frontend/ts7/ast-types.generated.js.map +1 -0
  711. package/dist/frontend/ts7/ast-types.js +3 -0
  712. package/dist/frontend/ts7/ast-types.js.map +1 -0
  713. package/dist/frontend/ts7/ast-wire.d.ts +58 -0
  714. package/dist/frontend/ts7/ast-wire.js +267 -0
  715. package/dist/frontend/ts7/ast-wire.js.map +1 -0
  716. package/dist/frontend/ts7/ast-wire.test.d.ts +1 -0
  717. package/dist/frontend/ts7/ast-wire.test.js +151 -0
  718. package/dist/frontend/ts7/ast-wire.test.js.map +1 -0
  719. package/dist/frontend/ts7/ast.d.ts +14 -14
  720. package/dist/frontend/ts7/ast.js +21 -15
  721. package/dist/frontend/ts7/ast.js.map +1 -1
  722. package/dist/frontend/ts7/census-check.js +1 -0
  723. package/dist/frontend/ts7/census-check.js.map +1 -1
  724. package/dist/frontend/ts7/checker-cache.d.ts +48 -0
  725. package/dist/frontend/ts7/checker-cache.js +92 -0
  726. package/dist/frontend/ts7/checker-cache.js.map +1 -0
  727. package/dist/frontend/ts7/checker.d.ts +19 -46
  728. package/dist/frontend/ts7/checker.js +231 -161
  729. package/dist/frontend/ts7/checker.js.map +1 -1
  730. package/dist/frontend/ts7/checker.test.d.ts +1 -0
  731. package/dist/frontend/ts7/checker.test.js +335 -0
  732. package/dist/frontend/ts7/checker.test.js.map +1 -0
  733. package/dist/frontend/ts7/enums.d.ts +4 -27
  734. package/dist/frontend/ts7/enums.generated.d.ts +878 -0
  735. package/dist/frontend/ts7/enums.generated.js +1313 -0
  736. package/dist/frontend/ts7/enums.generated.js.map +1 -0
  737. package/dist/frontend/ts7/enums.js +4 -45
  738. package/dist/frontend/ts7/enums.js.map +1 -1
  739. package/dist/frontend/ts7/enums.test.d.ts +1 -0
  740. package/dist/frontend/ts7/enums.test.js +48 -0
  741. package/dist/frontend/ts7/enums.test.js.map +1 -0
  742. package/dist/frontend/ts7/native-api.d.ts +10 -0
  743. package/dist/frontend/ts7/native-api.js +10 -0
  744. package/dist/frontend/ts7/native-api.js.map +1 -0
  745. package/dist/frontend/ts7/native-host.d.ts +2 -0
  746. package/dist/frontend/ts7/native-host.js +11 -0
  747. package/dist/frontend/ts7/native-host.js.map +1 -0
  748. package/dist/frontend/ts7/native-process.d.ts +14 -0
  749. package/dist/frontend/ts7/native-process.js +62 -0
  750. package/dist/frontend/ts7/native-process.js.map +1 -0
  751. package/dist/frontend/ts7/program-adapter.d.ts +10 -98
  752. package/dist/frontend/ts7/program-adapter.js +16 -310
  753. package/dist/frontend/ts7/program-adapter.js.map +1 -1
  754. package/dist/frontend/ts7/program-host.d.ts +115 -0
  755. package/dist/frontend/ts7/program-host.js +347 -0
  756. package/dist/frontend/ts7/program-host.js.map +1 -0
  757. package/dist/frontend/ts7/program-host.test.d.ts +1 -0
  758. package/dist/frontend/ts7/program-host.test.js +207 -0
  759. package/dist/frontend/ts7/program-host.test.js.map +1 -0
  760. package/dist/frontend/ts7/rpc-api.d.ts +12 -0
  761. package/dist/frontend/ts7/rpc-api.js +23 -0
  762. package/dist/frontend/ts7/rpc-api.js.map +1 -0
  763. package/dist/frontend/ts7/rpc-client.d.ts +27 -0
  764. package/dist/frontend/ts7/rpc-client.js +102 -0
  765. package/dist/frontend/ts7/rpc-client.js.map +1 -0
  766. package/dist/frontend/ts7/rpc-client.test.d.ts +1 -0
  767. package/dist/frontend/ts7/rpc-client.test.js +133 -0
  768. package/dist/frontend/ts7/rpc-client.test.js.map +1 -0
  769. package/dist/frontend/ts7/rpc-filesystem.d.ts +16 -0
  770. package/dist/frontend/ts7/rpc-filesystem.js +42 -0
  771. package/dist/frontend/ts7/rpc-filesystem.js.map +1 -0
  772. package/dist/frontend/ts7/rpc-filesystem.test.d.ts +1 -0
  773. package/dist/frontend/ts7/rpc-filesystem.test.js +89 -0
  774. package/dist/frontend/ts7/rpc-filesystem.test.js.map +1 -0
  775. package/dist/frontend/ts7/rpc-process.d.ts +2 -0
  776. package/dist/frontend/ts7/rpc-process.js +148 -0
  777. package/dist/frontend/ts7/rpc-process.js.map +1 -0
  778. package/dist/frontend/ts7/rpc-process.test.d.ts +1 -0
  779. package/dist/frontend/ts7/rpc-process.test.js +29 -0
  780. package/dist/frontend/ts7/rpc-process.test.js.map +1 -0
  781. package/dist/frontend/ts7/rpc-wire.d.ts +46 -0
  782. package/dist/frontend/ts7/rpc-wire.js +195 -0
  783. package/dist/frontend/ts7/rpc-wire.js.map +1 -0
  784. package/dist/frontend/ts7/rpc-wire.test.d.ts +1 -0
  785. package/dist/frontend/ts7/rpc-wire.test.js +168 -0
  786. package/dist/frontend/ts7/rpc-wire.test.js.map +1 -0
  787. package/dist/frontend/ts7/semantic-checker.d.ts +137 -0
  788. package/dist/frontend/ts7/semantic-checker.js +221 -0
  789. package/dist/frontend/ts7/semantic-checker.js.map +1 -0
  790. package/dist/frontend/ts7/semantic-checker.test.d.ts +1 -0
  791. package/dist/frontend/ts7/semantic-checker.test.js +119 -0
  792. package/dist/frontend/ts7/semantic-checker.test.js.map +1 -0
  793. package/dist/frontend/ts7/semantic-json.d.ts +5 -0
  794. package/dist/frontend/ts7/semantic-json.js +52 -0
  795. package/dist/frontend/ts7/semantic-json.js.map +1 -0
  796. package/dist/frontend/ts7/semantic-json.test.d.ts +1 -0
  797. package/dist/frontend/ts7/semantic-json.test.js +42 -0
  798. package/dist/frontend/ts7/semantic-json.test.js.map +1 -0
  799. package/dist/frontend/ts7/semantic-model.d.ts +222 -0
  800. package/dist/frontend/ts7/semantic-model.js +423 -0
  801. package/dist/frontend/ts7/semantic-model.js.map +1 -0
  802. package/dist/frontend/ts7/semantic-model.test.d.ts +1 -0
  803. package/dist/frontend/ts7/semantic-model.test.js +322 -0
  804. package/dist/frontend/ts7/semantic-model.test.js.map +1 -0
  805. package/dist/frontend/ts7/semantic-schema.generated.d.ts +283 -0
  806. package/dist/frontend/ts7/semantic-schema.generated.js +222 -0
  807. package/dist/frontend/ts7/semantic-schema.generated.js.map +1 -0
  808. package/dist/frontend/ts7/semantic-types.d.ts +5 -0
  809. package/dist/frontend/ts7/semantic-types.js +2 -0
  810. package/dist/frontend/ts7/semantic-types.js.map +1 -0
  811. package/dist/frontend/ts7/session-cache.d.ts +17 -0
  812. package/dist/frontend/ts7/session-cache.js +97 -0
  813. package/dist/frontend/ts7/session-cache.js.map +1 -0
  814. package/dist/frontend/ts7/session-cache.test.d.ts +1 -0
  815. package/dist/frontend/ts7/session-cache.test.js +87 -0
  816. package/dist/frontend/ts7/session-cache.test.js.map +1 -0
  817. package/dist/frontend/ts7/session-path.d.ts +18 -0
  818. package/dist/frontend/ts7/session-path.js +203 -0
  819. package/dist/frontend/ts7/session-path.js.map +1 -0
  820. package/dist/frontend/ts7/session-path.test.d.ts +1 -0
  821. package/dist/frontend/ts7/session-path.test.js +34 -0
  822. package/dist/frontend/ts7/session-path.test.js.map +1 -0
  823. package/dist/frontend/ts7/session-schema.generated.d.ts +167 -0
  824. package/dist/frontend/ts7/session-schema.generated.js +5 -0
  825. package/dist/frontend/ts7/session-schema.generated.js.map +1 -0
  826. package/dist/frontend/ts7/session-timing.d.ts +50 -0
  827. package/dist/frontend/ts7/session-timing.js +61 -0
  828. package/dist/frontend/ts7/session-timing.js.map +1 -0
  829. package/dist/frontend/ts7/session-timing.test.d.ts +1 -0
  830. package/dist/frontend/ts7/session-timing.test.js +52 -0
  831. package/dist/frontend/ts7/session-timing.test.js.map +1 -0
  832. package/dist/frontend/ts7/session.d.ts +105 -0
  833. package/dist/frontend/ts7/session.js +233 -0
  834. package/dist/frontend/ts7/session.js.map +1 -0
  835. package/dist/frontend/ts7/session.test.d.ts +1 -0
  836. package/dist/frontend/ts7/session.test.js +215 -0
  837. package/dist/frontend/ts7/session.test.js.map +1 -0
  838. package/dist/frontend/ts7/source-parser-node.d.ts +6 -0
  839. package/dist/frontend/ts7/source-parser-node.js +15 -0
  840. package/dist/frontend/ts7/source-parser-node.js.map +1 -0
  841. package/dist/frontend/ts7/source-parser.d.ts +25 -0
  842. package/dist/frontend/ts7/source-parser.js +96 -0
  843. package/dist/frontend/ts7/source-parser.js.map +1 -0
  844. package/dist/frontend/ts7/source-parser.test.d.ts +1 -0
  845. package/dist/frontend/ts7/source-parser.test.js +151 -0
  846. package/dist/frontend/ts7/source-parser.test.js.map +1 -0
  847. package/dist/frontend/ts7/syntax.d.ts +3 -0
  848. package/dist/frontend/ts7/syntax.js +4 -0
  849. package/dist/frontend/ts7/syntax.js.map +1 -0
  850. package/dist/frontend/tsc-codes.js +3 -0
  851. package/dist/frontend/tsc-codes.js.map +1 -1
  852. package/dist/frontend/type-mapper.d.ts +25 -17
  853. package/dist/frontend/type-mapper.js +465 -121
  854. package/dist/frontend/type-mapper.js.map +1 -1
  855. package/dist/frontend/type-mapper.test.js +123 -2
  856. package/dist/frontend/type-mapper.test.js.map +1 -1
  857. package/dist/frontend/union-discriminants.d.ts +16 -0
  858. package/dist/frontend/union-discriminants.js +98 -0
  859. package/dist/frontend/union-discriminants.js.map +1 -0
  860. package/dist/frontend/union-discriminants.test.d.ts +1 -0
  861. package/dist/frontend/union-discriminants.test.js +182 -0
  862. package/dist/frontend/union-discriminants.test.js.map +1 -0
  863. package/dist/index.d.ts +7 -198
  864. package/dist/index.js +369 -1572
  865. package/dist/index.js.map +1 -1
  866. package/dist/ir/analysis.d.ts +16 -4
  867. package/dist/ir/analysis.js +21 -4
  868. package/dist/ir/analysis.js.map +1 -1
  869. package/dist/ir/analysis.test.js +15 -2
  870. package/dist/ir/analysis.test.js.map +1 -1
  871. package/dist/ir/constant-tables.js +67 -49
  872. package/dist/ir/constant-tables.js.map +1 -1
  873. package/dist/ir/constant-tables.test.js +1 -1
  874. package/dist/ir/control-flow.d.ts +6 -0
  875. package/dist/ir/control-flow.js +142 -0
  876. package/dist/ir/control-flow.js.map +1 -0
  877. package/dist/ir/control-flow.test.d.ts +1 -0
  878. package/dist/ir/control-flow.test.js +113 -0
  879. package/dist/ir/control-flow.test.js.map +1 -0
  880. package/dist/ir/integer-loops.js +7 -18
  881. package/dist/ir/integer-loops.js.map +1 -1
  882. package/dist/ir/integer-ranges.js +53 -27
  883. package/dist/ir/integer-ranges.js.map +1 -1
  884. package/dist/ir/ir.d.ts +291 -152
  885. package/dist/ir/ir.js +588 -881
  886. package/dist/ir/ir.js.map +1 -1
  887. package/dist/ir/ir.test.js +127 -1
  888. package/dist/ir/ir.test.js.map +1 -1
  889. package/dist/ir/scalar-records.js +165 -134
  890. package/dist/ir/scalar-records.js.map +1 -1
  891. package/dist/ir/scalar-records.test.js +1 -1
  892. package/dist/ir/serialize.d.ts +4 -2
  893. package/dist/ir/serialize.js +19 -12
  894. package/dist/ir/serialize.js.map +1 -1
  895. package/dist/ir/serialize.test.d.ts +1 -0
  896. package/dist/ir/serialize.test.js +53 -0
  897. package/dist/ir/serialize.test.js.map +1 -0
  898. package/dist/ir/traverse.d.ts +41 -0
  899. package/dist/ir/traverse.js +660 -0
  900. package/dist/ir/traverse.js.map +1 -0
  901. package/dist/ir/traverse.test.d.ts +1 -0
  902. package/dist/ir/traverse.test.js +242 -0
  903. package/dist/ir/traverse.test.js.map +1 -0
  904. package/dist/ir/validate.js +1942 -1491
  905. package/dist/ir/validate.js.map +1 -1
  906. package/dist/ir/validate.test.js +476 -2
  907. package/dist/ir/validate.test.js.map +1 -1
  908. package/dist/library/cache-primitives.d.ts +2 -3
  909. package/dist/library/cache-primitives.js +4 -6
  910. package/dist/library/cache-primitives.js.map +1 -1
  911. package/dist/library/fence-eval.js +2 -2
  912. package/dist/library/fence-eval.js.map +1 -1
  913. package/dist/library/int-infer.js +7 -6
  914. package/dist/library/int-infer.js.map +1 -1
  915. package/dist/library/int-infer.test.js +4 -4
  916. package/dist/library/library-cache.d.ts +3 -2
  917. package/dist/library/library-cache.js +5 -17
  918. package/dist/library/library-cache.js.map +1 -1
  919. package/dist/library/library-cache.test.js +54 -41
  920. package/dist/library/library-cache.test.js.map +1 -1
  921. package/dist/library/library-profile.d.ts +3 -1
  922. package/dist/library/library-profile.js +15 -6
  923. package/dist/library/library-profile.js.map +1 -1
  924. package/dist/library/prepare.d.ts +15 -0
  925. package/dist/library/prepare.js +584 -0
  926. package/dist/library/prepare.js.map +1 -0
  927. package/dist/library/semantic-source.d.ts +1 -1
  928. package/dist/library/semantic-source.js +8 -6
  929. package/dist/library/semantic-source.js.map +1 -1
  930. package/dist/library/sidecar-validate.js +4 -4
  931. package/dist/library/sidecar-validate.js.map +1 -1
  932. package/dist/library/sidecar.d.ts +2 -0
  933. package/dist/library/sidecar.js +10 -3
  934. package/dist/library/sidecar.js.map +1 -1
  935. package/dist/native/cache.d.ts +11 -0
  936. package/dist/native/cache.js +113 -0
  937. package/dist/native/cache.js.map +1 -0
  938. package/dist/native/cache.test.d.ts +1 -0
  939. package/dist/native/cache.test.js +66 -0
  940. package/dist/native/cache.test.js.map +1 -0
  941. package/dist/native/cli.d.ts +1 -0
  942. package/dist/native/cli.js +112 -0
  943. package/dist/native/cli.js.map +1 -0
  944. package/dist/native/compiler.d.ts +15 -0
  945. package/dist/native/compiler.js +336 -0
  946. package/dist/native/compiler.js.map +1 -0
  947. package/dist/native/compiler.test.d.ts +1 -0
  948. package/dist/native/compiler.test.js +174 -0
  949. package/dist/native/compiler.test.js.map +1 -0
  950. package/dist/native/comptime.d.ts +5 -0
  951. package/dist/native/comptime.js +73 -0
  952. package/dist/native/comptime.js.map +1 -0
  953. package/dist/native/comptime.test.d.ts +1 -0
  954. package/dist/native/comptime.test.js +65 -0
  955. package/dist/native/comptime.test.js.map +1 -0
  956. package/dist/native/executable-cache.d.ts +26 -0
  957. package/dist/native/executable-cache.js +228 -0
  958. package/dist/native/executable-cache.js.map +1 -0
  959. package/dist/native/executable-cache.test.d.ts +1 -0
  960. package/dist/native/executable-cache.test.js +151 -0
  961. package/dist/native/executable-cache.test.js.map +1 -0
  962. package/dist/native/file-identity.d.ts +4 -0
  963. package/dist/native/file-identity.js +14 -0
  964. package/dist/native/file-identity.js.map +1 -0
  965. package/dist/native/file-identity.test.d.ts +1 -0
  966. package/dist/native/file-identity.test.js +43 -0
  967. package/dist/native/file-identity.test.js.map +1 -0
  968. package/dist/native/library.d.ts +22 -0
  969. package/dist/native/library.js +83 -0
  970. package/dist/native/library.js.map +1 -0
  971. package/dist/native/prepare.d.ts +21 -0
  972. package/dist/native/prepare.js +174 -0
  973. package/dist/native/prepare.js.map +1 -0
  974. package/dist/native/prepare.test.d.ts +1 -0
  975. package/dist/native/prepare.test.js +70 -0
  976. package/dist/native/prepare.test.js.map +1 -0
  977. package/dist/native/sanitizer.d.ts +11 -0
  978. package/dist/native/sanitizer.js +135 -0
  979. package/dist/native/sanitizer.js.map +1 -0
  980. package/dist/native/sanitizer.test.d.ts +1 -0
  981. package/dist/native/sanitizer.test.js +58 -0
  982. package/dist/native/sanitizer.test.js.map +1 -0
  983. package/dist/native/task.d.ts +4 -0
  984. package/dist/native/task.js +16 -0
  985. package/dist/native/task.js.map +1 -0
  986. package/dist/native/task.test.d.ts +1 -0
  987. package/dist/native/task.test.js +17 -0
  988. package/dist/native/task.test.js.map +1 -0
  989. package/dist/native/toolchain.d.ts +45 -0
  990. package/dist/native/toolchain.js +74 -0
  991. package/dist/native/toolchain.js.map +1 -0
  992. package/dist/native/toolchain.test.d.ts +1 -0
  993. package/dist/native/toolchain.test.js +33 -0
  994. package/dist/native/toolchain.test.js.map +1 -0
  995. package/dist/startup-cache.d.ts +1 -1
  996. package/dist/startup-cache.js +2 -5
  997. package/dist/startup-cache.js.map +1 -1
  998. package/dist/timing.d.ts +4 -0
  999. package/dist/timing.js +19 -0
  1000. package/dist/timing.js.map +1 -0
  1001. package/dist/wasi-paths.js +10 -7
  1002. package/dist/wasi-paths.js.map +1 -1
  1003. package/package.json +28 -19
  1004. package/surface-manifest.json +52 -18
  1005. package/dist/backend/c/async.d.ts +0 -171
  1006. package/dist/backend/c/async.js +0 -1317
  1007. package/dist/backend/c/async.js.map +0 -1
  1008. package/dist/backend/c/c-emitter.d.ts +0 -536
  1009. package/dist/backend/c/c-emitter.js +0 -1932
  1010. package/dist/backend/c/c-emitter.js.map +0 -1
  1011. package/dist/backend/c/exprs.d.ts +0 -15
  1012. package/dist/backend/c/exprs.js +0 -8847
  1013. package/dist/backend/c/exprs.js.map +0 -1
  1014. package/dist/backend/c/island.d.ts +0 -45
  1015. package/dist/backend/c/island.js +0 -281
  1016. package/dist/backend/c/island.js.map +0 -1
  1017. package/dist/backend/c/may-throw.js.map +0 -1
  1018. package/dist/backend/c/shapes.d.ts +0 -142
  1019. package/dist/backend/c/shapes.js +0 -603
  1020. package/dist/backend/c/shapes.js.map +0 -1
  1021. package/dist/backend/c/stmts.d.ts +0 -76
  1022. package/dist/backend/c/stmts.js +0 -1108
  1023. package/dist/backend/c/stmts.js.map +0 -1
  1024. package/dist/backend/c/types.d.ts +0 -71
  1025. package/dist/backend/c/types.js +0 -459
  1026. package/dist/backend/c/types.js.map +0 -1
  1027. package/dist/backend/c/types.test.js +0 -32
  1028. package/dist/backend/c/types.test.js.map +0 -1
  1029. package/dist/backend/c/walkers.d.ts +0 -134
  1030. package/dist/backend/c/walkers.js +0 -1772
  1031. package/dist/backend/c/walkers.js.map +0 -1
  1032. /package/dist/backend/{c/types.test.d.ts → cycle-analysis.test.d.ts} +0 -0
@@ -1,1932 +0,0 @@
1
- import { InternalCompilerError } from "../../errors.js";
2
- import { SourceLocations } from "../source-locations.js";
3
- import { ffiCallbackType, funcOf, isFfiCallbackParam, isFfiContextParam, isFfiReleaseParam, isRefCounted, isUnitType, mapOf, moduleEmbedsCompressedNpm, moduleUsesChildProcess, moduleUsesDgram, moduleUsesDynInvoke, moduleEmbedsBuiltin, moduleUsesFetch, moduleUsesFsWatch, moduleUsesHttp2, moduleUsesHttpServer, moduleUsesNet, moduleUsesNodeTest, moduleUsesProcessEvents, moduleUsesStream, moduleUsesTls, moduleUsesTlsCa, POINTER_KINDS, RUNTIME_EMITTER_CLASS, STRING, VOID } from "../../ir/ir.js";
4
- import { undefinedArmTag } from "../../ir/analysis.js";
5
- import { scalarizeNumericRecords } from "../../ir/scalar-records.js";
6
- import { findConstantNumericTables } from "../../ir/constant-tables.js";
7
- import { allocateFfiCallbackAdapters, hasForeignFfiCallback, hasRetainedFfiCallback } from "../ffi-callbacks.js";
8
- import { mangleAsyncSpawn, mangleGenSpawn, mangleClassObj, mangleField, mangleGlobal, mangleFnClosure, mangleFunction, mangleLocal, mangleRawParam, mangleVtSlot, mangleWrapper, } from "../mangle.js";
9
- import { cCommentText, cFnPtrCast, cType, releaseCallC, cStringLiteral, cDecl, cNumberLiteral } from "./types.js";
10
- import { computeMayThrow } from "./may-throw.js";
11
- import { unionTruthyHelper, unionEqHelper, unionToStrHelper, unionJoinHelper, jsonWriteHelper, jsonIndentHelper, dynMatchHelper, dynCheckHelper, dynFuncBoxHelper, dynToStrHelper, caughtToDynHelper, toDynHelper, recordKeyGetHelper, recordKeySetHelper } from "./walkers.js";
12
- import { emitStructDefs, vtEntriesFor, vtSlotParams, emitVtableDecls, emitVtableInstances, emitVtAdapterDefs, emitHierarchyClassHelpers, emitClassObjs, emitCtorThunkDefs, errorVtStampLines, emitterVtStampLines, streamVtStampLines, traceAdapterC, traceArgC, boxNewC, arrNewC } from "./shapes.js";
13
- import { emitAsyncScaffolding, childDataThunkFor, childExitThunkFor, childExitSignalThunkFor, execFileThunkFor, ipcMessageThunkFor, ipcSendThunkFor, closeBindThunkFor, connectResThunkFor, connectSockThunkFor, closeOverrideWrapFor, cryptoBytesThunkFor, dgramMsgThunkFor, dnsLookupThunkFor, fsRenameThunkFor, genResultThunkFor, netLookupAnswerThunkFor, emitterInvokeThunkFor, streamCbThunkFor, streamDataThunkFor, raceAdapterFor, resolveThunkFor, sniAnswerThunkFor, zlibBytesThunkFor } from "./async.js";
14
- import { emitNpmEmbedding, islandAdapter, islandTypedAdapter } from "./island.js";
15
- import { emitFunction, emitBlock, emitStmts, emitStmt, emitTryCatch, emitSwitch, mergeBrace, emitBranchInto, emitCondition } from "./stmts.js";
16
- import { emitExpr, liveDynRefAdapter as buildLiveDynRefAdapter } from "./exprs.js";
17
- import { emitLibraryIdentityLines } from "../library-identity-markers.js";
18
- export function emitCModule(mod, sourceText, options = {}) {
19
- return new CEmitter(scalarizeNumericRecords(mod), sourceText, options).emit();
20
- }
21
- function ffiNativeTypeC(cls) {
22
- switch (cls) {
23
- case "f64":
24
- return "double";
25
- case "bool":
26
- case "u8":
27
- return "uint8_t";
28
- case "u32":
29
- return "uint32_t";
30
- case "i32":
31
- return "int32_t";
32
- case "cstring":
33
- return "const char *";
34
- case "string":
35
- case "bytes":
36
- throw new InternalCompilerError(`emitter bug: span class '${cls}' has no scalar C type`);
37
- case "void":
38
- return "void";
39
- }
40
- }
41
- function ffiCallbackNativeParamsC(callback, named) {
42
- return callback.params.flatMap((param, i) => {
43
- if (isFfiContextParam(param))
44
- return [`void *${named ? "sc_ctx" : ""}`.trim()];
45
- if (param === "string" || param === "bytes") {
46
- return [
47
- `const uint8_t *${named ? `sc_a${i}` : ""}`.trim(),
48
- `size_t${named ? ` sc_a${i}_len` : ""}`,
49
- ];
50
- }
51
- return [`${ffiNativeTypeC(param)}${named ? ` sc_a${i}` : ""}`];
52
- });
53
- }
54
- function ffiCallbackPointerTypeC(callback) {
55
- const ret = ffiNativeTypeC(callback.returns);
56
- const params = ffiCallbackNativeParamsC(callback, false);
57
- return `${ret} (*)(${params.length > 0 ? params.join(", ") : "void"})`;
58
- }
59
- function ffiCallbackDummyC(callback) {
60
- return callback.returns === "void" ? "" : "0";
61
- }
62
- export class CEmitter {
63
- mod;
64
- options;
65
- debug;
66
- sourceLoc = null;
67
- lines = [];
68
- indent = 0;
69
- tempCounter = 0;
70
- /** Interned string literals: UTF-8 text → static symbol name. */
71
- literals = new Map();
72
- /** Kind-specialized typed-array access helpers actually used by this
73
- * program. Keeping these in the generated TU means unrelated binaries do
74
- * not pay even debug/link metadata for byte-loop fast paths. */
75
- bytesElementHelpers = new Set();
76
- /** Interned unit-armed union instances: "unionId:tag" → static symbol.
77
- * A unit arm (undefined/null) has no payload, so every instance of one
78
- * (union, tag) pair is identical — ONE immortal (rc == SIZE_MAX) static
79
- * serves them all. Immortals are skipped by retain/release and by the
80
- * cycle collector's child filter (SCR_CYC_SKIP), so the missing cycle
81
- * header is fine even when a traced container points at one. */
82
- unitInstances = new Map();
83
- /** Interned regex literals: "<flags>/<pattern>" → static symbol. One
84
- * immortal (rc == SIZE_MAX) ScrRegex per distinct (pattern, flags) pair —
85
- * the bytecode slot starts NULL and the runtime compiles it lazily on
86
- * first use. The source/flags strings ride the ordinary literal table. */
87
- regexInstances = new Map();
88
- /** Interned tagged-template strings objects: per-site key → symbol +
89
- * cooked spans. One immortal (rc == SIZE_MAX) ScrArr of interned string
90
- * literals per template-literal SITE — the spec's per-occurrence
91
- * identity: the same site evaluated twice hands the tag the same array,
92
- * two sites never share even with identical text. */
93
- templateStringsInstances = new Map();
94
- /** Class objects (classes as first-class values): className → static
95
- * symbol. One immortal ScrClassObj per class some classRef names —
96
- * preorder interval baked as constants, the .name string in the literal
97
- * table, and a per-class construct thunk (void *sc_ct_*) newValue
98
- * dispatches through. Registered during body emission (the regex
99
- * pattern); the statics and thunks are assembled around the bodies. */
100
- classObjs = new Map();
101
- /** Stack of statement frames: refcounted temps not yet released or moved. */
102
- frames = [];
103
- /** Stack of scopes: refcounted locals (with types) declared in each. */
104
- scopes = [];
105
- /** The function being emitted: local table (for boxedness) and whether
106
- * each local arrived through the closure environment (env captures are
107
- * borrowed — never declared, never released here). */
108
- currentLocals = new Map();
109
- captureIds = new Set();
110
- /** Canonical byte-loop induction locals currently represented by an
111
- * unsigned integer shadow. Ordinary number reads widen the shadow back to
112
- * f64; direct byte indices consume it without a conversion round trip. */
113
- integerLoopBindings = new Map();
114
- integerRanges = new Map();
115
- /** Declared functions referenced as values: each needs an env-signature
116
- * wrapper + an interned immortal closure (so `f === f` holds). */
117
- fnValues = new Set();
118
- /** Emitted ref-kind resolve thunks for new Promise, interned per inner
119
- * typeKey → thunk symbol. */
120
- resolveThunks = new Map();
121
- genResThunks = new Map();
122
- /** Emitted child exit adapters, interned per union id (childExitThunkFor). */
123
- childExitThunks = new Map();
124
- /** Emitted child-stream data adapters, interned per union id
125
- * (childDataThunkFor). */
126
- childDataThunks = new Map();
127
- /** Emitted bound-close adapters, interned per union id
128
- * (closeBindThunkFor). */
129
- closeBindThunks = new Map();
130
- /** Emitted close-override wrappers, interned per (union id, ret kind)
131
- * (closeOverrideWrapFor). */
132
- closeOverrideWraps = new Map();
133
- /** Emitted dgram message adapters, interned per rinfo shape id
134
- * (dgramMsgThunkFor). */
135
- dgramMsgThunks = new Map();
136
- /** Emitted dns.lookup callback adapters, interned per union id + param
137
- * count (dnsLookupThunkFor). */
138
- dnsLookupThunks = new Map();
139
- /** Emitted fs.rename callback adapters, interned per callback type. */
140
- fsRenameThunks = new Map();
141
- /** Emitted SNI answer-closure thunks, interned per cb func-type key
142
- * (sniAnswerThunkFor). */
143
- sniAnswerThunks = new Map();
144
- /** Emitted net.connect lookup answer thunks, interned per cb func-type
145
- * key (netLookupAnswerThunkFor). */
146
- netLookupAnswerThunks = new Map();
147
- /** Emitted EventEmitter listener invoke adapters, interned per listener
148
- * func-type key (emitterInvokeThunkFor). */
149
- emitterInvokeThunks = new Map();
150
- /** Emitted stream option-callback invoke adapters (read/write/final/
151
- * destroy/transform/flush — the leading-`this` closures), interned per
152
- * (kind, callback func-type) key (streamCbThunkFor). */
153
- streamCbThunks = new Map();
154
- /** Emitted stream completion-callback closure fns (the `callback` a
155
- * user's write/final/destroy/transform/flush receives and calls),
156
- * interned per (kind, done func-type) key (streamDoneFnFor). */
157
- streamDoneFns = new Map();
158
- /** Emitted CONNECT-listener union-socket adapters, interned per cb
159
- * func-type key (connectSockThunkFor). */
160
- connectSockThunks = new Map();
161
- /** Emitted Promise.race fulfillment adapters, interned per
162
- * `entryInner=>resultInner` typeKey pair (raceAdapterFor). */
163
- raceThunks = new Map();
164
- /** setTimeout appeared somewhere: main must run the event loop even in
165
- * programs with no async functions. */
166
- usesTimers = false;
167
- fnByName = new Map();
168
- /** Manifest-bound native imports, used by ffiCall emission. */
169
- ffiByName = new Map();
170
- /** One C-ABI trampoline per manifest callback entry. Raw function
171
- * pointers additionally get a distinct TLS context slot, so two
172
- * callbacks with the same signature never alias each other's closure. */
173
- ffiCallbackAdapters;
174
- /** Module-level constant consulted per ffiCall: with a retained
175
- * descriptor anywhere in the manifest, every native call is a
176
- * pending-exception checkpoint (may-throw derives the same fact from
177
- * the same helper). */
178
- ffiHasRetainedCallback;
179
- ffiHasForeignCallback;
180
- globalsById = new Map();
181
- constantNumericTables;
182
- unionsById = new Map();
183
- /** Active optional-chain bind temps, by chain id (chainRecv reads). */
184
- chainTemps = new Map();
185
- recordsById = new Map();
186
- /** Record shapes whose bodies emitted recordClone. Filled while function
187
- * bodies emit, before emitStructDefs assembles per-shape helpers. */
188
- recordCloneShapes = new Set();
189
- /** Type-directed JSON walkers, interned per typeKey — one serializer per
190
- * type used in jsonStringify position (sc_jw_*), one match predicate
191
- * (sc_dm_*) and one checked builder (sc_dc_*) per type used in dynCheck
192
- * position. Emitted as prototypes + definitions after the struct block
193
- * (they reference struct types, per-shape RC helpers, and each other, so
194
- * the prototypes make definition order irrelevant). */
195
- jsonWriters = new Map();
196
- /** The pretty-print re-indenter (type-independent, interned once):
197
- * emitted on the first `JSON.stringify(v, null, space)` site. */
198
- jsonIndentFn = null;
199
- /** The dyn ToString pair (type-independent, interned once): emitted on
200
- * the first String(unknown) / `${unknown}` site. */
201
- dynToStrFn = null;
202
- /** The caught→dyn converter (type-independent, interned once): emitted
203
- * on the first catch binding flowing into an `unknown` slot. */
204
- caughtToDynFn = null;
205
- /** Interned per-union helpers: unionId → emitted function name. */
206
- unionTruthyFns = new Map();
207
- unionEqFns = new Map();
208
- unionToStrFns = new Map();
209
- unionJoinFns = new Map();
210
- dynMatchers = new Map();
211
- dynBuilders = new Map();
212
- /** Static→dyn converters (sc_td_*), per typeKey; dynamic-keyed record
213
- * read helpers (sc_rkg_*), per shapeId|result typeKey; dynamic-keyed
214
- * write helpers (sc_rks_*), per shapeId. */
215
- toDynFns = new Map();
216
- /** ReadableStream.from typed-array element adapters, per element
217
- * typeKey. The runtime retains the original array and calls one of these
218
- * for each pull, preserving iterator-time reads without teaching the
219
- * runtime the compiler's program-specific record/union layouts. */
220
- streamFromArrayAdapters = new Map();
221
- /** Identity-preserving static→dyn capsules for program classes and Web
222
- * APIs whose values remain directly observable. */
223
- liveDynRefAdapters = new Map();
224
- /** Runtime-arm dispatchers for live references whose static type is a
225
- * union. Mutable arms become typed capsules; scalar/unit arms retain the
226
- * ordinary static-to-dyn conversion. */
227
- liveDynUnionRefAdapters = new Map();
228
- dynPromiseAdapters = new Map();
229
- /** The checked-dynamic function boundary's per-signature helpers (see
230
- * walkers.ts): call thunks (sc_dfk_*), box builders (sc_dfb_*),
231
- * and dynCheck adapters (sc_dfa_*), each per func typeKey. */
232
- dynFuncThunks = new Map();
233
- dynFuncBoxes = new Map();
234
- dynFuncAdapters = new Map();
235
- /** dyn-promise settle adapters (sc_pda_*), per INNER typeKey: convert a
236
- * typed fulfillment payload into the boxed destination's dyn payload
237
- * (scr_dyn_new_promise_adapting's callback — toDynHelper's promise arm). */
238
- promiseDynAdapters = new Map();
239
- recordKeyGetFns = new Map();
240
- recordKeySetFns = new Map();
241
- walkerProtos = [];
242
- walkerDefs = [];
243
- /** Island host-call adapters, interned per (arity, void-ness): the one
244
- * uniform shape scr_jsval_from_closure calls — unpack the cell array,
245
- * call the closure through its real ABI (which CONSUMES its params, so
246
- * each cell is retained in), return the +1 result cell or NULL for void.
247
- * Definitions ride walkerDefs (self-contained over the closure ABI). */
248
- islandAdapters = new Map();
249
- /** TYPED island host-call adapters, interned per full signature (param
250
- * typeKeys + return classification): each incoming engine argument
251
- * converts to the param's static type through the exit machinery before
252
- * the closure runs — see islandTypedAdapter (island.ts). */
253
- islandTypedAdapters = new Map();
254
- /** Enclosing break/continue targets. An unlabeled `break` binds to the
255
- * innermost loop-or-switch entry (labeled BLOCK entries are skipped); an
256
- * unlabeled `continue` searches inward-out for the innermost LOOP,
257
- * skipping switches and blocks. A LABELED jump binds to the entry whose
258
- * `labels` contains its label: `break lbl` jumps to the target's
259
- * endLabel (loops allocate one lazily via `usedEnd` — a C `break` only
260
- * exits the innermost loop), `continue lbl` to the target loop's
261
- * continueLabel. Loops: `continueLabel` is null when C `continue` is
262
- * correct (unlabeled while/forOf); for/do-while loops need a goto label
263
- * so `continue` still runs the update/condition, and LABELED loops of
264
- * every shape allocate one up front (a labeled continue from a nested
265
- * loop needs a goto). Switches are emitted as goto chains — never as C
266
- * `switch` — so a C `break`/`continue` inside an emitted switch region
267
- * still binds to the enclosing C loop; a break targeting the switch
268
- * itself jumps to `endLabel` instead. Labeled blocks carry only an
269
- * endLabel (`break lbl` is the only jump that can target them).
270
- * `scopeDepth` = scopes.length at entry — a break/continue releases
271
- * every scope pushed after that before jumping. `frameDepth` =
272
- * frames.length at entry: statements the jump exits may still hold
273
- * pending refcounted temps in their frames (a switch's discriminant,
274
- * most notably), whose normal end-of-statement releases sit on the
275
- * fall-through path the jump bypasses — the jump releases every frame
276
- * pushed after the target's own before jumping. */
277
- jumpTargets = [];
278
- labelCounter = 0;
279
- returnTypeByFn = new Map();
280
- lineStarts = null;
281
- /** May-throw analysis results (computeMayThrow): pending-exception checks
282
- * are emitted only after calls that can actually raise. */
283
- mayThrow;
284
- indirectMayThrow;
285
- /** Enclosing try contexts, innermost last — the compile-time analogue of
286
- * the jump-target stack for UNWINDING: a pending check (or `throw`) inside
287
- * a try releases frames/scopes down to the recorded depths and jumps to
288
- * `label` (the catch, or the exception-path finally) instead of returning
289
- * out of the function. Purely compile-time: entering a try emits no code. */
290
- tryStack = [];
291
- /** Enclosing try-with-finally regions, innermost last. Returns use the
292
- * central pending-return copies; break/continue inline the crossed bodies
293
- * with the same truncated ownership and exception context as LLVM. */
294
- finallyStack = [];
295
- /** Scope entry protecting sc_pret while a pending-return finally copy
296
- * runs. A return in that copy replaces the old completion: it evaluates
297
- * first, releases the old slot, then removes this protection from its
298
- * own unwind path before dispatching. */
299
- pendingReturnScopeIndex = null;
300
- /** Return type of the function being emitted — the unwind path returns a
301
- * dummy of this type (never read: callers check the pending flag first). */
302
- currentReturnType = VOID;
303
- /** The generator channels of the function being emitted (null outside
304
- * generator bodies): yieldExpr emission reads them, and emitTryCatch's
305
- * catch prologue emits the GENRET sentinel re-unwind exactly here. */
306
- currentGenerator = null;
307
- /** Cycle-capable shapes ("object:<name>" / "record:<id>") and unions
308
- * (unionId): instances get a cycle header + emitted trace/teardown, and
309
- * fields/payloads of these types are visited by container traces.
310
- * Computed as a greatest fixpoint in the constructor — see there. */
311
- tracedShapes = new Set();
312
- tracedUnions = new Set();
313
- /** The class graph (single inheritance): base/children links, hierarchy
314
- * membership (extends anywhere ⇒ vtable word + dynamic release), the
315
- * whole-program preorder numbering behind O(1) instanceof, and the
316
- * per-hierarchy virtual slot lists (root classes only). Computed once in
317
- * the constructor. */
318
- classMeta = new Map();
319
- /** Method names with at least one may-throw implementation: a
320
- * virtualCall's pending check keys on this (same over-approximation as
321
- * computeMayThrow's callee cover). */
322
- mayThrowMethods = new Set();
323
- /** Vtable slot adapters to define after the function signatures (they
324
- * call sc_f_* bodies): dedupe key "implClass.method". */
325
- vtAdapters = new Map();
326
- constructor(mod, sourceText, options = {}) {
327
- this.mod = mod;
328
- this.options = options;
329
- this.debug = options.debugSources === undefined ? null : new SourceLocations(options.debugSources);
330
- this.constantNumericTables = findConstantNumericTables(mod);
331
- this.ffiCallbackAdapters = allocateFfiCallbackAdapters(mod.ffiImports ?? []);
332
- this.ffiHasRetainedCallback = hasRetainedFfiCallback(mod.ffiImports ?? []);
333
- this.ffiHasForeignCallback = hasForeignFfiCallback(mod.ffiImports ?? []);
334
- for (const fn of mod.functions) {
335
- this.returnTypeByFn.set(fn.name, fn.returnType);
336
- this.fnByName.set(fn.name, fn);
337
- }
338
- for (const entry of mod.ffiImports ?? []) {
339
- this.ffiByName.set(entry.name, entry);
340
- }
341
- const mt = computeMayThrow(mod);
342
- this.mayThrow = mt.fns;
343
- this.indirectMayThrow = mt.indirect;
344
- for (const g of mod.globals ?? [])
345
- this.globalsById.set(g.id, g);
346
- for (const u of mod.unions ?? [])
347
- this.unionsById.set(u.id, u);
348
- for (const r of mod.records ?? [])
349
- this.recordsById.set(r.id, r);
350
- // The class graph. Link base/children, number the forest in preorder
351
- // (roots and children in module class order — deterministic), and
352
- // compute each hierarchy's virtual slots: a class's method gets a slot
353
- // iff no ancestor declares it (root-most) AND some strict descendant
354
- // redeclares it — never-overridden methods stay direct calls
355
- // everywhere (whole-program devirtualization).
356
- for (const cls of mod.classes ?? []) {
357
- const meta = {
358
- def: cls,
359
- base: null,
360
- children: [],
361
- root: undefined,
362
- pre: 0,
363
- post: 0,
364
- hierarchy: false,
365
- slots: [],
366
- };
367
- this.classMeta.set(cls.name, meta);
368
- }
369
- for (const meta of this.classMeta.values()) {
370
- if (meta.def.base === undefined)
371
- continue;
372
- const base = this.classMeta.get(meta.def.base);
373
- if (!base)
374
- throw new InternalCompilerError(`emitter bug: undeclared base class ${meta.def.base}`);
375
- meta.base = base;
376
- base.children.push(meta);
377
- }
378
- let preCounter = 0;
379
- const number = (meta, root) => {
380
- meta.root = root;
381
- meta.pre = preCounter++;
382
- for (const c of meta.children)
383
- number(c, root);
384
- meta.post = preCounter - 1; // max pre in the subtree (inclusive)
385
- };
386
- for (const meta of this.classMeta.values()) {
387
- if (meta.base === null)
388
- number(meta, meta);
389
- // The runtime emitter class is ALWAYS a hierarchy member: ScrEmitter
390
- // carries its vtable word whether or not the program subclasses it.
391
- meta.hierarchy = meta.base !== null || meta.children.length > 0 ||
392
- meta.def.name === RUNTIME_EMITTER_CLASS;
393
- }
394
- const declares = (m, method) => m.def.methods?.includes(method) ?? false;
395
- const declaredBelow = (m, method) => m.children.some((c) => declares(c, method) || declaredBelow(c, method));
396
- const collectSlots = (m, root, seen) => {
397
- for (const method of m.def.methods ?? []) {
398
- let inherited = false;
399
- for (let a = m.base; a; a = a.base)
400
- inherited ||= declares(a, method);
401
- if (!inherited && declaredBelow(m, method)) {
402
- let fn = this.fnByName.get(`%${m.def.name}.${method}`);
403
- if (!fn && m.def.abstractMethods?.includes(method)) {
404
- // An ABSTRACT declarer has no function; the slot's ABI
405
- // signature comes from any concrete descendant implementation
406
- // (the frontend's override exactness makes them identical).
407
- // No concrete implementation anywhere in the subtree means no
408
- // instance can dispatch the slot (only abstract classes
409
- // declare it, and abstract classes never instantiate) — skip.
410
- const findImpl = (c) => {
411
- for (const child of c.children) {
412
- const f = declares(child, method) && !child.def.abstractMethods?.includes(method)
413
- ? this.fnByName.get(`%${child.def.name}.${method}`)
414
- : undefined;
415
- const found = f ?? findImpl(child);
416
- if (found)
417
- return found;
418
- }
419
- return undefined;
420
- };
421
- fn = findImpl(m);
422
- if (!fn)
423
- continue;
424
- }
425
- if (!fn)
426
- throw new InternalCompilerError(`emitter bug: missing method function %${m.def.name}.${method}`);
427
- // Sibling branches can each own a slot for the same method name
428
- // (each root-most in its own subtree — mixin layers make this
429
- // routine): the member name disambiguates by occurrence.
430
- const occurrence = seen.get(method) ?? 0;
431
- seen.set(method, occurrence + 1);
432
- root.slots.push({ method, declarer: m, fn, member: mangleVtSlot(method, occurrence) });
433
- }
434
- }
435
- for (const c of m.children)
436
- collectSlots(c, root, seen);
437
- };
438
- for (const meta of this.classMeta.values()) {
439
- if (meta.base === null && meta.hierarchy)
440
- collectSlots(meta, meta, new Map());
441
- }
442
- for (const cls of mod.classes ?? []) {
443
- for (const m of cls.methods ?? []) {
444
- if (this.mayThrow.has(`%${cls.name}.${m}`))
445
- this.mayThrowMethods.add(m);
446
- }
447
- }
448
- // Cycle capability, as a greatest fixpoint over shapes and unions:
449
- // start optimistic (everything cycle-capable), then repeatedly drop
450
- // shapes with no cycle-capable field and unions with no cycle-capable
451
- // arm until stable. Closures and promises are always cycle-capable
452
- // (a captured box can hold anything; a rejection payload is an
453
- // arbitrary thrown value); strings never are, and arrays/maps inherit
454
- // their element/value type's capability (a record element can point
455
- // back at the array holding it). The optimistic start is what keeps
456
- // self- and mutually-recursive classes traced (`class A { next: A }`).
457
- const shapeDefs = [
458
- // The emitter class carries a synthetic closure-typed pseudo-field:
459
- // its runtime registry OWNS listener closures, so the emitter
460
- // hierarchy is unconditionally cycle-capable — the fixpoint must
461
- // never drop it (the pseudo-field never reaches struct emission;
462
- // runtime classes emit no structs).
463
- ...(mod.classes ?? []).map((c) => ({
464
- key: `object:${c.name}`,
465
- fields: c.name === RUNTIME_EMITTER_CLASS
466
- ? [...c.fields, { name: "<listeners>", type: funcOf([], VOID) }]
467
- : c.fields,
468
- })),
469
- // An index-signature shape's overflow map participates like a field
470
- // of map type: the shape is cycle-capable when the overflow VALUE
471
- // type is (a record/object/union value in the map can point back at
472
- // the record embedding it) — cycleCapable's map rule answers that.
473
- ...(mod.records ?? []).map((r) => ({
474
- key: `record:${r.id}`,
475
- fields: r.indexValue
476
- ? [...r.fields, { name: "<overflow>", type: mapOf(STRING, r.indexValue) }]
477
- : r.fields,
478
- })),
479
- ];
480
- for (const s of shapeDefs)
481
- this.tracedShapes.add(s.key);
482
- // A hierarchy is ONE unit of cycle capability: a base-typed slot can
483
- // hold any subclass and retain touches the cycle header, so header
484
- // presence must be uniform across an extends-hierarchy — it is
485
- // cycle-capable iff ANY member is. Standalone classes and records are
486
- // singleton units (today's behavior exactly).
487
- const unitKeyOf = (key) => {
488
- if (!key.startsWith("object:"))
489
- return key;
490
- const meta = this.classMeta.get(key.slice("object:".length));
491
- return meta && meta.hierarchy ? `object:${meta.root.def.name}` : key;
492
- };
493
- const units = new Map();
494
- for (const s of shapeDefs) {
495
- const unit = unitKeyOf(s.key);
496
- let members = units.get(unit);
497
- if (!members)
498
- units.set(unit, (members = []));
499
- members.push(s);
500
- }
501
- for (const u of mod.unions ?? [])
502
- this.tracedUnions.add(u.id);
503
- const cycleCapable = (t) => {
504
- switch (t.kind) {
505
- case "func":
506
- case "promise":
507
- return true;
508
- case "object":
509
- return this.tracedShapes.has(`object:${t.className}`);
510
- case "record":
511
- return this.tracedShapes.has(`record:${t.shapeId}`);
512
- case "union":
513
- return this.tracedUnions.has(t.unionId);
514
- // A map is cycle-capable exactly when its VALUE type is: a record/
515
- // object/union value can hold the map that owns it, while string/
516
- // array/scalar values cannot point back. Map-valued maps (an
517
- // index-signature overflow over `Map<K, V>` values) recurse on the
518
- // inner value. Terminates: IrTypes are finite trees, and the
519
- // record/union cases read the fixpoint sets.
520
- case "map":
521
- return cycleCapable(t.value);
522
- // An array is cycle-capable exactly when its ELEMENT type is —
523
- // record/object/union elements (and cycle-capable inner arrays)
524
- // can point back at the array. Terminates: element types are
525
- // finite trees, and the record/union cases read the fixpoint sets.
526
- case "array":
527
- return cycleCapable(t.elem);
528
- default:
529
- return false;
530
- }
531
- };
532
- let shrunk = true;
533
- while (shrunk) {
534
- shrunk = false;
535
- for (const members of units.values()) {
536
- if (this.tracedShapes.has(members[0].key) &&
537
- !members.some((s) => s.fields.some((f) => cycleCapable(f.type)))) {
538
- for (const s of members)
539
- this.tracedShapes.delete(s.key);
540
- shrunk = true;
541
- }
542
- }
543
- for (const u of mod.unions ?? []) {
544
- if (this.tracedUnions.has(u.id) && !u.arms.some(cycleCapable)) {
545
- this.tracedUnions.delete(u.id);
546
- shrunk = true;
547
- }
548
- }
549
- }
550
- if (sourceText !== undefined) {
551
- this.lineStarts = [0];
552
- for (let i = 0; i < sourceText.length; i++) {
553
- if (sourceText[i] === "\n")
554
- this.lineStarts.push(i + 1);
555
- }
556
- }
557
- }
558
- emit() {
559
- const body = [];
560
- // Async-generator spawn wrappers need their type-directed result
561
- // builders even when user code only creates and drops the iterator.
562
- // Register them before the unit-instance table flushes below.
563
- for (const fn of this.mod.functions) {
564
- if (!fn.async || fn.generator === undefined)
565
- continue;
566
- genResultThunkFor(this, {
567
- kind: "generator",
568
- async: true,
569
- yieldT: fn.generator.yieldT,
570
- retT: fn.returnType,
571
- nextT: fn.generator.nextT,
572
- }, fn.generator.resultType);
573
- }
574
- // Function bodies are emitted first (into this.lines) so the literal
575
- // table is complete; the file is then assembled around them.
576
- for (const fn of this.mod.functions) {
577
- this.emitFunction(fn);
578
- body.push(...this.lines);
579
- this.lines.length = 0;
580
- }
581
- const out = [
582
- `/* Generated by scriptc from ${this.mod.sourceFile}. Do not edit. */`,
583
- `#include "scr_runtime.h"`,
584
- `#include <math.h>`,
585
- `#include <stdio.h>`,
586
- `#include <stdlib.h>`,
587
- ``,
588
- ];
589
- out.push(...this.emitBytesElementHelpers());
590
- for (const table of this.constantNumericTables.values()) {
591
- out.push(`static const double ${table.symbol}[] = { ${table.values.map(cNumberLiteral).join(", ")} };`, `static inline double ${table.symbol}_get(const ScrArr *a, double i) {`,
592
- // Range checks precede the conversion: NaN, infinities and large
593
- // numbers must never reach a C float-to-integer conversion.
594
- ` if (a != NULL && i >= 0.0 && i < ${table.values.length}.0) {`, ` size_t index = (size_t)i;`, ` if ((double)index == i) return ${table.symbol}[index];`, ` }`, ` return scr_arr_get_number(a, i);`, `}`, ``);
595
- }
596
- // Struct defs render into their own buffer BEFORE the unit-instance
597
- // table flushes: class newFns point undefined-armed union fields at
598
- // interned unit instances (fields start as JS's undefined, not NULL),
599
- // so the instances they intern must both exist in the map by flush
600
- // time and be DEFINED earlier in the file than the newFn bodies.
601
- const structDefs = [];
602
- this.emitStructDefs(structDefs);
603
- for (const [text, sym] of this.literals) {
604
- const bytes = Buffer.from(text, "utf8");
605
- out.push(`static struct { size_t rc; size_t len; size_t cap; char data[${bytes.length + 1}]; } ${sym} =`, ` { SIZE_MAX, ${bytes.length}, ${bytes.length}, ${cStringLiteral(bytes)} };`);
606
- }
607
- if (this.literals.size > 0)
608
- out.push("");
609
- for (const [key, sym] of this.unitInstances) {
610
- // One immortal instance per unit-armed (union, tag): tag set, payload
611
- // slot and RC entry points zero — retain/release/collector all skip
612
- // rc == SIZE_MAX, so these never join the RC audit or a trace walk.
613
- const [unionId, tag] = key.split(":");
614
- out.push(`static ScrUnion ${sym} = { .rc = SIZE_MAX, .tag = ${tag} }; /* ${unionId} unit arm */`);
615
- }
616
- if (this.unitInstances.size > 0)
617
- out.push("");
618
- for (const line of structDefs)
619
- out.push(line); // program-sized: never spread
620
- for (const [key, sym] of this.regexInstances) {
621
- // One immortal ScrRegex per (pattern, flags) literal, pointing at the
622
- // interned source/flags strings. `.bc` starts NULL: the runtime
623
- // compiles the pattern lazily on first use and caches it here (and
624
- // frees it at exit), so unexecuted regexes cost nothing. NOT const —
625
- // the bc slot mutates.
626
- const sep = key.indexOf("/");
627
- const flags = key.slice(0, sep);
628
- const pattern = key.slice(sep + 1);
629
- const src = this.internLiteral(pattern);
630
- const fl = this.internLiteral(flags);
631
- const safe = cCommentText(`/${pattern}/${flags}`);
632
- out.push(`static ${this.mod.lib?.threadInstances === true ? "_Thread_local " : ""}ScrRegex ${sym} = { .rc = SIZE_MAX, .source = (ScrStr *)&${src}, ` +
633
- `.flags = (ScrStr *)&${fl}, .bc = NULL }; /* ${safe} */`);
634
- }
635
- if (this.regexInstances.size > 0)
636
- out.push("");
637
- for (const [, { sym, cooked }] of this.templateStringsInstances) {
638
- // One immortal ScrArr per tagged-template site: the data slots point
639
- // at the interned cooked-string literals (address constants — fully
640
- // static, no lazy init; reads retain immortal strings, a no-op).
641
- // len == cap and nothing ever mutates it (TemplateStringsArray is
642
- // ReadonlyArray, tsc rejects the mutating spellings).
643
- const slots = cooked.map((s) => `(void *)&${this.internLiteral(s)}`).join(", ");
644
- out.push(`static void *${sym}_data[${cooked.length}] = { ${slots} };`, `static ScrArr ${sym} = { .rc = SIZE_MAX, .len = ${cooked.length}, .cap = ${cooked.length}, ` +
645
- `.elem = SCR_ELEM_STR, .elem_retain = NULL, .elem_release = NULL, .elem_trace = NULL, ` +
646
- `.data = (uint64_t *)${sym}_data };`);
647
- }
648
- if (this.templateStringsInstances.size > 0)
649
- out.push("");
650
- const embedded = this.mod.embedded;
651
- emitNpmEmbedding(this, out);
652
- const globals = this.mod.globals ?? [];
653
- // Thread-instanced library state (abi.instance_per_thread): module
654
- // globals, run-once guards, and the regex literal caches below live in
655
- // thread-local storage — one full instance per embedder thread,
656
- // matching the runtime objects compiled with -DSCR_THREAD_INSTANCES.
657
- // Immutable interned data (string literals, unit arms, template
658
- // arrays, vtables) stays shared.
659
- const tl = this.mod.lib?.threadInstances === true ? "_Thread_local " : "";
660
- for (const g of globals) {
661
- // File-scope statics: zero/NULL-initialized, assigned by %init
662
- // functions, released (refcounted ones) before the RC audit runs.
663
- out.push(`static ${tl}${cDecl(g.type, mangleGlobal(g.id))}; /* ${g.name} */`);
664
- }
665
- if (globals.length > 0)
666
- out.push("");
667
- // Outbound native FFI declarations. string/bytes each expand from one
668
- // scriptc value to a borrowed pointer+length pair. Format-2 callbacks
669
- // and their independently positioned contexts are exact pointer slots.
670
- // Library callback channels reuse ffiCall IR but are NOT direct symbol
671
- // imports: their profile names are registration keys and TypeScript
672
- // bindings only, and call sites dispatch through the runtime slot. Do
673
- // not emit extern declarations for them (besides inventing undefined
674
- // symbols, a valid TS channel name such as `int` is a C keyword).
675
- const libraryCallbackNames = new Set(this.mod.lib?.callbacks?.map((cb) => cb.name) ?? []);
676
- const directFfiImports = (this.mod.ffiImports ?? []).filter((entry) => !libraryCallbackNames.has(entry.name));
677
- for (const entry of directFfiImports) {
678
- const params = entry.params.flatMap((param) => {
679
- if (isFfiCallbackParam(param) || isFfiReleaseParam(param)) {
680
- return [ffiCallbackPointerTypeC(param.callback)];
681
- }
682
- if (isFfiContextParam(param))
683
- return ["void *"];
684
- switch (param) {
685
- case "f64":
686
- return ["double"];
687
- case "bool":
688
- case "u8":
689
- return ["uint8_t"];
690
- case "u32":
691
- return ["uint32_t"];
692
- case "i32":
693
- return ["int32_t"];
694
- case "string":
695
- case "bytes":
696
- return ["const uint8_t *", "size_t"];
697
- }
698
- });
699
- const ret = ffiNativeTypeC(entry.returns);
700
- out.push(`extern ${ret} ${entry.symbol}(${params.length > 0 ? params.join(", ") : "void"});`);
701
- }
702
- if (directFfiImports.length > 0)
703
- out.push("");
704
- for (const fn of this.mod.functions)
705
- out.push(this.signature(fn) + ";");
706
- this.emitFfiCallbackDefs(out);
707
- // Class objects (classes as values): construct-thunk prototypes plus
708
- // the immortal statics that take their addresses — after the function
709
- // signatures (the thunks call sc_new_*/the constructors), before
710
- // anything that references &sc_co_*.
711
- emitClassObjs(this, out);
712
- // Vtable slot adapters: prototyped with the vtables (emitStructDefs),
713
- // defined here where the method bodies they call are declared.
714
- this.emitVtAdapterDefs(out);
715
- // Wrappers + interned closures for declared functions used as values.
716
- // Placed after the forward declarations (they call sc_f_*) and before
717
- // the bodies (which reference &sc_fc_*).
718
- this.emitAsyncScaffolding(out);
719
- for (const name of this.fnValues) {
720
- const fn = this.fnByName.get(name);
721
- const params = ["ScrClosure *sc_env", ...fn.params.map((p) => cDecl(p.type, mangleLocal(p.localId)))];
722
- const call = `${this.callTargetC(name)}(${fn.params.map((p) => mangleLocal(p.localId)).join(", ")})`;
723
- const retType = fn.generator ? "ScrGen *" : fn.async ? "ScrPromise *" : cType(fn.returnType);
724
- out.push(``, `static ${retType}${retType.endsWith("*") ? "" : " "}${mangleWrapper(name)}(${params.join(", ")}) {`, ` (void)sc_env;`, fn.returnType.kind === "void" && !fn.async && !fn.generator ? ` ${call};` : ` return ${call};`, `}`, `static struct { size_t rc; void *fn; size_t ncaps; ScrBox *props; } ${mangleFnClosure(name)} =`, ` { SIZE_MAX, (void *)&${mangleWrapper(name)}, 0, NULL };`);
725
- }
726
- // Construct-thunk definitions (prototyped with the class objects
727
- // above): they call sc_new_* and the constructors, both declared.
728
- emitCtorThunkDefs(this, out);
729
- // Type-directed JSON walkers (jsonStringify serializers, dynCheck
730
- // matchers/builders), interned per type during body emission above.
731
- if (this.walkerProtos.length > 0) {
732
- out.push("");
733
- for (const line of this.walkerProtos)
734
- out.push(line);
735
- out.push("");
736
- for (const line of this.walkerDefs)
737
- out.push(line);
738
- }
739
- // Loop-appended, never spread: `body` scales with the PROGRAM (a large
740
- // embedded graph emits hundreds of thousands of lines), and a spread
741
- // push passes every line as a call argument — the engine's stack
742
- // overflows long before memory matters.
743
- out.push("");
744
- for (const line of body)
745
- out.push(line);
746
- if (this.mod.lib !== undefined) {
747
- // LIBRARY mode: no main(), no scr_init/scr_lib_init, no event
748
- // loop — the profile-declared external symbols instead. Everything
749
- // above is unchanged (still all internal linkage).
750
- this.emitLibEntries(out, globals);
751
- return out.join("\n");
752
- }
753
- const refGlobals = globals.filter((g) => isRefCounted(g.type));
754
- // Interned function-value closures are IMMORTAL (rc == SIZE_MAX), so
755
- // an own-property table Object.defineProperties hung on one would
756
- // outlive the RC audit — release it with the globals. Only emitted
757
- // when the dispatch unit is even linked (defineProps is the only
758
- // writer).
759
- const fnValueProps = moduleUsesDynInvoke(this.mod) ? [...this.fnValues] : [];
760
- if (refGlobals.length > 0 || fnValueProps.length > 0) {
761
- out.push(`static void sc_release_globals(void) {`);
762
- for (const g of refGlobals) {
763
- out.push(` ${releaseCallC(g.type, mangleGlobal(g.id))};`);
764
- }
765
- for (const name of fnValueProps) {
766
- out.push(` if (${mangleFnClosure(name)}.props) { scr_box_release(${mangleFnClosure(name)}.props); ${mangleFnClosure(name)}.props = NULL; }`);
767
- }
768
- out.push(`}`, ``);
769
- }
770
- const asyncEntry = this.fnByName.get(this.mod.entry)?.async === true;
771
- const hasAsync = this.mod.functions.some((f) => f.async);
772
- // Generator programs run the loop too (an empty pass when nothing is
773
- // pending): its exit accounting notes still-suspended generator
774
- // fibers as abandoned, so the RC audit downgrades exactly like the
775
- // async loop-exhaustion story.
776
- const hasGenerators = this.mod.functions.some((f) => f.generator !== undefined);
777
- // Embedded npm code can leave island promise chains pending when %main
778
- // returns (a package function's async work) — the loop's io hook
779
- // drains the engine's job queue at quiescence, so npm-importing
780
- // programs always run the loop, like Node always runs its own.
781
- const usesIsland = embedded !== undefined && embedded.modules.length > 0;
782
- const snapshotsTlsCa = moduleUsesTls(this.mod) ||
783
- moduleUsesTlsCa(this.mod) ||
784
- moduleEmbedsBuiltin(this.mod, "node:https") ||
785
- moduleEmbedsBuiltin(this.mod, "node:tls");
786
- // A pending module root normally selects Node's exit status 13, but
787
- // an already-failed node:test run or an embedded process.exitCode has
788
- // higher precedence. Keep this expression shared with the ordinary
789
- // successful epilogue so both paths consult the same program verdict.
790
- const usesNodeTest = moduleUsesNodeTest(this.mod);
791
- const programExitUsesIsland = !usesNodeTest && usesIsland;
792
- const programExitCode = usesNodeTest
793
- ? "scr_test_exit_code()"
794
- : usesIsland
795
- ? "scr_island_exit_code()"
796
- : "scr_exit_code_hint_get()";
797
- // Exit listeners can read MODULE GLOBALS directly (test/common's
798
- // runCallChecks over its mustCallChecks ledger — an interned top-level
799
- // closure, no capture boxes keeping anything alive), so they must run
800
- // BEFORE sc_release_globals — the atexit half alone would fire after
801
- // main freed them (observed use-after-free). scr_run_exit_listeners
802
- // is idempotent (scr_exit_ran), so the atexit becomes a no-op; the
803
- // code argument is the hint the failure reporters maintain — exactly
804
- // what the atexit path would have passed. With a retained FFI
805
- // descriptor the inline call is required even with nothing to
806
- // release: listeners must beat the atexit FFI ledger sweep (a
807
- // listener may legitimately release or pump a registration), and
808
- // only the inline call orders ahead of every atexit handler. Plain
809
- // event programs with neither keep the atexit path, so their
810
- // listener timing is unchanged.
811
- const needsRelease = refGlobals.length > 0 || fnValueProps.length > 0;
812
- const runExitListeners = moduleUsesProcessEvents(this.mod) && (needsRelease || this.ffiHasRetainedCallback)
813
- ? "scr_run_exit_listeners((double)scr_exit_code_hint_get()); "
814
- : "";
815
- const exitCleanup = `${runExitListeners}${needsRelease ? "sc_release_globals(); " : ""}`;
816
- const releaseGlobals = needsRelease
817
- ? ` ${runExitListeners}sc_release_globals();`
818
- : runExitListeners !== ""
819
- ? ` ${runExitListeners.trim()}`
820
- : ` /* no refcounted globals */`;
821
- const uncaught = (indent, releaseTop = false) => [
822
- `${indent}if (scr_exc_pending()) {`,
823
- `${indent} scr_exc_print_uncaught();`,
824
- `${indent} ${releaseTop ? "scr_promise_release(sc_top); " : ""}` +
825
- `${exitCleanup}return 1;`,
826
- `${indent}}`,
827
- ];
828
- out.push(
829
- // Real argc/argv feed the library's interned process.argv (see
830
- // scr_lib_init — lazy, so argv-free programs allocate nothing).
831
- `int main(int argc, char **argv) {`, ` scr_init();`,
832
- // The builtin error classes' preorder intervals are program-dependent
833
- // (they share this module's class-forest numbering, so instanceof and
834
- // the uncaught printer's Error-range test agree between runtime-made
835
- // and compiled error objects) — stamp them before any code runs.
836
- ...this.errorVtStampLines(),
837
- // The runtime emitter vtable's interval, when the program touches
838
- // node:events (the class def rides the module exactly then).
839
- ...emitterVtStampLines(this),
840
- // The runtime stream vtables' intervals, when the program touches
841
- // node:stream (the emitter story — instanceof and dynamic teardown
842
- // both dispatch through them).
843
- ...streamVtStampLines(this),
844
- // Node reads NODE_EXTRA_CA_CERTS and the referenced file during
845
- // process initialization. Native fetch performs the same idempotent
846
- // install from scr_fetch_install.
847
- ...(snapshotsTlsCa ? [` scr_tls_ca_install();`] : []), ` scr_lib_init(argc, argv);`,
848
- // Fetch-referencing programs register the native fetch bridge before any
849
- // island entry (the engine's lazy boot consults it): the ONLY
850
- // reference to scr_fetch.c, so fetch-free builds never compile or
851
- // link it (native-toolchain.ts gates on the same predicate). moduleUsesFetch is
852
- // true only for fetch-referencing embedded graphs and for USER-code
853
- // fetch (the island-backed ambient's globalGet) — both boot the
854
- // engine before the global is read.
855
- ...(moduleUsesFetch(this.mod) ? [` scr_fetch_install();`] : []),
856
- // Embedded graphs that import node:zlib register the island's zlib
857
- // bridge before any island entry — the ONLY reference to
858
- // scr_zlib_island.c (native-toolchain.ts compiles it on the same predicate), so
859
- // zlib-free dynamic builds keep the island's clear refusal.
860
- ...(moduleEmbedsBuiltin(this.mod, "node:zlib") ? [` scr_zlib_island_install();`] : []),
861
- // Embedded graphs that import node:http/https register the island's
862
- // http client bridge (scr_net_island.c — native-toolchain.ts compiles it and the
863
- // socket units on the same predicate; native-fetch builds also
864
- // register it from scr_fetch_install, idempotently).
865
- ...(moduleEmbedsBuiltin(this.mod, "node:http") || moduleEmbedsBuiltin(this.mod, "node:https")
866
- ? [` scr_net_island_install();`]
867
- : []),
868
- // Event-surface programs (signal/exit listeners, stdin events) fill
869
- // the loop's nullable event hooks before %main — the events unit
870
- // (scr_events.c) links only when this line is emitted (native-toolchain.ts gates
871
- // on the same predicate, like fetch).
872
- ...(moduleUsesProcessEvents(this.mod) ? [` scr_events_install();`] : []), ...(moduleUsesChildProcess(this.mod) ? [` scr_child_dyn_install();`] : []),
873
- // Net-surface programs fill the loop's net hooks before %main — the
874
- // net unit (scr_net.c) links only when this line is emitted (native-toolchain.ts
875
- // gates on the same predicate, like events). The dyn-install twin
876
- // stamps the netSocket handle-dispatch ops into the dyn core so
877
- // sockets can cross the checked-dynamic boundary (SCR_DYN_HANDLE).
878
- ...(moduleUsesNet(this.mod) ? [` scr_net_install();`, ` scr_net_dyn_install();`] : []),
879
- // Http-surface programs additionally stamp the httpReq/httpRes
880
- // handle-dispatch ops (scr_http.c links exactly when this line is
881
- // emitted — native-toolchain.ts's http gate).
882
- ...(moduleUsesHttpServer(this.mod) ? [` scr_http_dyn_install();`] : []),
883
- // http2-surface programs stamp the h2 session/stream handle-dispatch
884
- // ops (scr_http2.c links exactly when this line is emitted — native-toolchain.ts's
885
- // http2 gate).
886
- ...(moduleUsesHttp2(this.mod) ? [` scr_http2_dyn_install();`] : []),
887
- // Stream-surface programs fill the loop's stream hook (the deferred
888
- // next-tick emissions) before %main — scr_stream.c links only when
889
- // this line is emitted (native-toolchain.ts gates on the same predicate).
890
- ...(moduleUsesStream(this.mod) ? [` scr_stream_install();`] : []),
891
- // Dgram/dns-surface programs fill the loop's dgram hooks the same
892
- // way — scr_dgram.c links only when this line is emitted.
893
- ...(moduleUsesDgram(this.mod) ? [` scr_dgram_install();`] : []),
894
- // fs.watch programs fill the loop's watch hooks the same way —
895
- // scr_watch.c links only when this line is emitted.
896
- ...(moduleUsesFsWatch(this.mod) ? [` scr_watch_install();`] : []), ...(this.ffiHasForeignCallback ? [` scr_ffi_install();`] : []),
897
- // The embedded npm tables must be registered before %main: the %init
898
- // functions it calls import from them. Static data only — the engine
899
- // still boots lazily, on the first island entry. Compressed module
900
- // text (island.ts stores big sources as raw DEFLATE) needs the
901
- // inflater installed first — scr_zlib.c joins the link on the same
902
- // moduleEmbedsCompressedNpm predicate (index.ts's zlib switch), so
903
- // compression-free dynamic builds keep their exact link line.
904
- ...(embedded && embedded.modules.length > 0
905
- ? [
906
- ...(moduleEmbedsCompressedNpm(this.mod)
907
- ? [` scr_island_set_inflate(scr_zlib_inflate_exact);`]
908
- : []),
909
- ` scr_island_modules(sc_npm_modules, ${embedded.modules.length}, ` +
910
- `${embedded.edges.length > 0 ? "sc_npm_edges" : "NULL"}, ${embedded.edges.length});`,
911
- ]
912
- : []), ...(asyncEntry
913
- ? [` ScrPromise *sc_top = ${mangleAsyncSpawn(this.mod.entry)}();`]
914
- : [` ${mangleFunction(this.mod.entry)}();`]),
915
- // Uncaught exception from top-level code: Node exits 1.
916
- ...(this.mayThrow.has(this.mod.entry) && !asyncEntry ? uncaught(" ") : []),
917
- // The event loop runs to exhaustion (microtasks before timers). A
918
- // throw escaping a timer callback and unhandled promise rejections
919
- // both exit 1, like Node.
920
- ...(hasAsync || hasGenerators || this.usesTimers || usesIsland || this.ffiHasForeignCallback
921
- ? [
922
- ` bool sc_loop_rejection = scr_loop_run(${asyncEntry ? "sc_top" : "NULL"});`,
923
- ...uncaught(" ", asyncEntry),
924
- ` if (sc_loop_rejection) {`,
925
- ` scr_discard_unhandled_rejections();`,
926
- ...(asyncEntry ? [` scr_promise_release(sc_top);`] : []),
927
- ` ${exitCleanup}return 1;`,
928
- ` }`,
929
- ...(asyncEntry
930
- ? [
931
- ` int sc_top_status = scr_promise_finish_top_level(sc_top);`,
932
- ` if (sc_top_status == 1) {`,
933
- // Earlier-checkpoint rejections were decided inside the
934
- // loop. The fatal module verdict suppresses unrelated
935
- // rejections from THIS checkpoint, exactly Node's order.
936
- ` scr_discard_unhandled_rejections();`,
937
- ` scr_promise_rethrow_top_level(sc_top);`,
938
- ` scr_promise_release(sc_top);`,
939
- ` scr_exc_print_uncaught();`,
940
- ` ${exitCleanup}return 1;`,
941
- ` }`,
942
- ` scr_promise_release(sc_top);`,
943
- ]
944
- : []),
945
- ` if (scr_report_unhandled_rejections()) {`,
946
- ` ${exitCleanup}return 1;`,
947
- ` }`,
948
- ...(asyncEntry
949
- ? [
950
- ` if (sc_top_status == 13) {`,
951
- ` int sc_exit_status = ${programExitCode};`,
952
- ` if (sc_exit_status == 0) sc_exit_status = sc_top_status;`,
953
- ...(programExitUsesIsland && runExitListeners !== ""
954
- ? [` size_t sc_exit_code_version = scr_island_exit_code_version();`]
955
- : []),
956
- // finish_top_level initially notes 13; replace that hint
957
- // before exit listeners run when a higher-priority
958
- // verdict has already selected the process status.
959
- ` scr_exit_code_note(sc_exit_status);`,
960
- ...(runExitListeners !== "" ? [` ${runExitListeners.trim()}`] : []),
961
- ...(programExitUsesIsland && runExitListeners !== ""
962
- ? [
963
- ` if (scr_island_exit_code_version() != sc_exit_code_version) {`,
964
- ` sc_exit_status = scr_island_exit_code();`,
965
- ` scr_exit_code_note(sc_exit_status);`,
966
- ` }`,
967
- ]
968
- : []),
969
- ...(needsRelease ? [` sc_release_globals();`] : []),
970
- ` return sc_exit_status;`,
971
- ` }`,
972
- ]
973
- : []),
974
- ]
975
- : []), releaseGlobals,
976
- // node:test programs exit through the runner's verdict (Node's
977
- // contract: 1 when any non-todo test failed). The loop-run above is
978
- // guaranteed for these programs — every registration libCall sets
979
- // usesTimers, so the runner fiber always drains before this line.
980
- // Island programs exit with process.exitCode when the embedded
981
- // graph set it (Node's implicit exit status: set it, return
982
- // normally, exit with it) — 0 when never set.
983
- ` return ${programExitCode};`, `}`, ``);
984
- return out.join("\n");
985
- }
986
- /* ── library mode ─────────────────────────────────────────────────────
987
- * The program TU's ONLY external-linkage definitions: the export-map
988
- * wrappers plus the mode-provided init / sink-registration / reset /
989
- * collect entries, all delegating their runtime halves to scr_library.c so
990
- * both backends' emitted bodies are trivially identical. The init entry
991
- * IS module-graph evaluation: full deterministic reset (program globals
992
- * released and zeroed — run-once guards included — then the runtime's
993
- * session reset), the error-vt interval stamps verbatim from today's
994
- * main, then %main, then the escaped-exception check. */
995
- emitLibEntries(out, globals) {
996
- const lib = this.mod.lib;
997
- const autoReset = lib.resultResetSymbol === null;
998
- out.push(``, `/* ── library-mode entries (profile: ${lib.profileName}) ── */`, ``);
999
- // Session reset of PROGRAM state: release every refcounted global and
1000
- // zero everything (the run-once module guards included), putting the
1001
- // program back at the not-yet-evaluated state.
1002
- out.push(`static void sc_lib_release_globals(void) {`);
1003
- for (const g of globals) {
1004
- const name = mangleGlobal(g.id);
1005
- if (isRefCounted(g.type)) {
1006
- out.push(` ${releaseCallC(g.type, name)}; ${name} = NULL; /* ${g.name} */`);
1007
- }
1008
- else if (g.type.kind === "bool") {
1009
- out.push(` ${name} = false; /* ${g.name} */`);
1010
- }
1011
- else {
1012
- out.push(` ${name} = 0; /* ${g.name} */`);
1013
- }
1014
- }
1015
- if (globals.length === 0)
1016
- out.push(` /* no globals */`);
1017
- out.push(`}`, ``);
1018
- // The runtime detected-trap overlay table (scr_runtime.h declares it,
1019
- // the library trap funnel consults it): flat code/teaching/remediation
1020
- // triples, one per runtime trap code (SC4013–SC4019) the profile
1021
- // declares text for. NULL keeps the funnel's default for that cell;
1022
- // the empty table still defines the symbols the funnel links against.
1023
- if (lib.trapOverlays.length === 0) {
1024
- out.push(`const char *const scr_library_trap_overlays[] = { NULL };`);
1025
- }
1026
- else {
1027
- const cells = lib.trapOverlays.flatMap((o) => [
1028
- cStringLiteral(Buffer.from(o.code, "utf8")),
1029
- o.teaching !== undefined ? cStringLiteral(Buffer.from(o.teaching, "utf8")) : "NULL",
1030
- o.remediation !== undefined ? cStringLiteral(Buffer.from(o.remediation, "utf8")) : "NULL",
1031
- ]);
1032
- out.push(`const char *const scr_library_trap_overlays[] = { ${cells.join(", ")} };`);
1033
- }
1034
- out.push(`const size_t scr_library_trap_overlays_len = ${lib.trapOverlays.length};`, ``);
1035
- out.push(`void ${lib.initSymbol}(void) {`, ` scr_library_entry(true, "${lib.initSymbol}"); /* init always resets the result arena */`, ` sc_lib_release_globals();`, ` scr_library_reset();`, ...this.errorVtStampLines(), ...emitterVtStampLines(this), ` ${mangleFunction(this.mod.entry)}();`, ` scr_library_check_exc();`, `}`, ``, `void ${lib.sinkRegisterSymbol}(void (*fn)(void *ctx, const uint8_t *msg, size_t msg_len, uint64_t address), void *ctx) {`, ` scr_library_callback_entry_guard("${lib.sinkRegisterSymbol}");`, ` scr_library_set_sink(fn, ctx);`, `}`, ``);
1036
- if (lib.callbacks !== undefined && lib.callbacks.length > 0) {
1037
- // Host-callback registration: a pure store dispatch (the sink
1038
- // registration's rule — no entry prologue, no poison guard, legal
1039
- // before init) except the first operation rejects callback-time
1040
- // re-entry (SC4026). The channel name selects the slot; an unknown or
1041
- // NULL name is a defined -1, never a store. Latest registration
1042
- // wins; a NULL fn clears the channel.
1043
- out.push(`int32_t ${lib.callbackRegisterSymbol}(const char *name, void (*fn)(void), void *ctx) {`, ` scr_library_callback_entry_guard("${lib.callbackRegisterSymbol}");`, ` if (name == NULL) return -1;`);
1044
- for (const cb of lib.callbacks) {
1045
- out.push(` if (strcmp(name, ${cStringLiteral(Buffer.from(cb.name, "utf8"))}) == 0) {`, ` scr_library_cb_set(${cb.slot}, fn, ctx); /* channel '${cb.name}' */`, ` return 0;`, ` }`);
1046
- }
1047
- out.push(` return -1;`, `}`, ``);
1048
- }
1049
- if (lib.identity !== undefined && this.options.emitLibraryIdentity !== false) {
1050
- // Profile-declared identity getters (the ask-2 sidecar's boot-time
1051
- // pairing fence): pure data returns with NO entry prologue — exempt
1052
- // from the poisoned guard and every runtime touch (ratified), so a
1053
- // host can read them before init and after a trap.
1054
- out.push(...emitLibraryIdentityLines("c", lib.identity));
1055
- }
1056
- if (lib.resultResetSymbol !== null) {
1057
- out.push(`void ${lib.resultResetSymbol}(void) {`, ` scr_library_entry(false, "${lib.resultResetSymbol}");`, ` scr_library_arena_reset();`, `}`, ``);
1058
- }
1059
- if (lib.collectSymbol !== null) {
1060
- out.push(`void ${lib.collectSymbol}(void) {`, ` scr_library_entry(false, "${lib.collectSymbol}");`, ` scr_library_collect(); /* arena reset + a full cycle collection */`, `}`, ``);
1061
- }
1062
- for (const e of lib.exports) {
1063
- const params = [];
1064
- const args = [];
1065
- e.params.forEach((cls, i) => {
1066
- switch (cls) {
1067
- case "f64":
1068
- params.push(`double a${i}`);
1069
- args.push(`a${i}`);
1070
- break;
1071
- case "bool":
1072
- params.push(`uint8_t a${i}`);
1073
- args.push(`(a${i} != 0)`);
1074
- break;
1075
- case "u8":
1076
- params.push(`uint8_t a${i}`);
1077
- args.push(`(double)a${i}`);
1078
- break;
1079
- case "u32":
1080
- params.push(`uint32_t a${i}`);
1081
- args.push(`(double)a${i}`);
1082
- break;
1083
- case "i32":
1084
- params.push(`int32_t a${i}`);
1085
- args.push(`(double)a${i}`);
1086
- break;
1087
- case "i64":
1088
- // The inbound declared-integer edge (ask 4): the helper
1089
- // converts exactly or delivers the host-contract trap — a
1090
- // value past ±(2^53−1) cannot ride f64 without silent
1091
- // rounding, which is a coercion the author never wrote.
1092
- params.push(`int64_t a${i}`);
1093
- args.push(`scr_library_i64_in(a${i}, ${cStringLiteral(Buffer.from(e.inboundIntTrap, "utf8"))})`);
1094
- break;
1095
- case "u64":
1096
- params.push(`uint64_t a${i}`);
1097
- args.push(`scr_library_u64_in(a${i}, ${cStringLiteral(Buffer.from(e.inboundIntTrap, "utf8"))})`);
1098
- break;
1099
- case "string":
1100
- params.push(`const uint8_t *a${i}_ptr`, `size_t a${i}_len`);
1101
- args.push(`scr_library_str_in(a${i}_ptr, a${i}_len)`);
1102
- break;
1103
- case "bytes":
1104
- params.push(`const uint8_t *a${i}_ptr`, `size_t a${i}_len`);
1105
- // The helper's trap message is the compiler-assembled
1106
- // structured trap-teaching form (0x01 text 0x1F SC4012 0x1F
1107
- // symbol [0x1F remediation]) — assembled once at export
1108
- // resolution, identical across both backends.
1109
- args.push(`scr_library_bytes_in(a${i}_ptr, a${i}_len, ${cStringLiteral(Buffer.from(e.inboundBytesTrap, "utf8"))})`);
1110
- break;
1111
- }
1112
- });
1113
- if (e.returns === "string" || e.returns === "bytes") {
1114
- params.push(`const uint8_t **out`, `size_t *out_len`);
1115
- }
1116
- const retType = e.returns === "f64" ? "double"
1117
- : e.returns === "bool" ? "uint8_t"
1118
- : e.returns === "i64" ? "int64_t"
1119
- : e.returns === "u64" ? "uint64_t"
1120
- : "void";
1121
- const call = `${mangleFunction(e.fnName)}(${args.join(", ")})`;
1122
- out.push(`${retType} ${e.symbol}(${params.length > 0 ? params.join(", ") : "void"}) {`);
1123
- // The prologue records this entry's symbol in the funnel's
1124
- // current-entry slot: a detected trap anywhere below names the
1125
- // entry the host called (structured trap-teaching field 2).
1126
- out.push(` scr_library_entry(${autoReset ? "true" : "false"}, "${e.symbol}");`);
1127
- switch (e.returns) {
1128
- case "void":
1129
- out.push(` ${call};`, ` scr_library_check_exc();`);
1130
- break;
1131
- case "f64":
1132
- out.push(` double sc_r = ${call};`, ` scr_library_check_exc();`, ` return sc_r;`);
1133
- break;
1134
- case "i64":
1135
- case "u64":
1136
- // The outbound declared-integer edge (ask 4): every value
1137
- // reaching this return was PROVEN whole and inside the class's
1138
- // range at compile time, so the cast is exact by construction
1139
- // (and the unwind path's 0.0 converts cleanly).
1140
- out.push(` double sc_r = ${call};`, ` scr_library_check_exc();`, ` return (${retType})sc_r;`);
1141
- break;
1142
- case "bool":
1143
- out.push(` bool sc_r = ${call};`, ` scr_library_check_exc();`, ` return (uint8_t)(sc_r ? 1 : 0);`);
1144
- break;
1145
- case "string":
1146
- out.push(` ScrStr *sc_r = ${call};`, ` scr_library_check_exc();`, ` scr_library_str_out(sc_r, out, out_len);`);
1147
- break;
1148
- case "bytes":
1149
- out.push(` ScrBytes *sc_r = ${call};`, ` scr_library_check_exc();`, ` scr_library_bytes_out(sc_r, out, out_len);`);
1150
- break;
1151
- }
1152
- out.push(`}`, ``);
1153
- }
1154
- }
1155
- emitAsyncScaffolding(out) {
1156
- return emitAsyncScaffolding(this, out);
1157
- }
1158
- emitStructDefs(out) {
1159
- return emitStructDefs(this, out);
1160
- }
1161
- /* ── vtables (class hierarchies) ──────────────────────────────────────
1162
- * One vtable struct type per hierarchy (named after the root): a ScrVt
1163
- * head — the class's preorder interval for instanceof and its DIRECT
1164
- * release for dynamic teardown — plus one member per virtual slot. Only
1165
- * methods actually overridden somewhere have slots; the slot's signature
1166
- * is the root-most declaring class's, and overriding implementations sit
1167
- * behind reinterpreting adapters (prefix layout makes the `this` cast
1168
- * sound). Each class gets one static const vtable instance stamped into
1169
- * every object it allocates. */
1170
- vtEntriesFor(meta) {
1171
- return vtEntriesFor(this, meta);
1172
- }
1173
- vtSlotParams(slot, named) {
1174
- return vtSlotParams(this, slot, named);
1175
- }
1176
- emitVtableDecls(out, hierarchyClasses) {
1177
- return emitVtableDecls(this, out, hierarchyClasses);
1178
- }
1179
- emitVtableInstances(out, hierarchyClasses) {
1180
- return emitVtableInstances(this, out, hierarchyClasses);
1181
- }
1182
- emitVtAdapterDefs(out) {
1183
- return emitVtAdapterDefs(this, out);
1184
- }
1185
- emitHierarchyClassHelpers(out, meta, s) {
1186
- return emitHierarchyClassHelpers(this, out, meta, s);
1187
- }
1188
- /* ── type-directed JSON walkers (jsonStringify / dynCheck) ────────────
1189
- * No dyn is built for stringify and no tags are consulted: the STATIC IR
1190
- * type drives everything, one emitted helper per typeKey (interned, like
1191
- * the array-HOF desugars). dynCheck helpers walk the runtime dyn (ScrDyn)
1192
- * against the target type: match predicates (sc_dm_*) answer "does this
1193
- * dyn fit?" without throwing (union arms are tried in canonical order —
1194
- * first FULL match wins), and builders (sc_dc_*) construct the typed
1195
- * value (+1) or throw a path-annotated TypeError through the exception
1196
- * cell. Recursion terminates because recursive shapes/unions are rejected
1197
- * by the frontend. */
1198
- islandAdapter(arity, retKind) {
1199
- return islandAdapter(this, arity, retKind);
1200
- }
1201
- islandTypedAdapter(fn) {
1202
- return islandTypedAdapter(this, fn);
1203
- }
1204
- unionTruthyHelper(unionId) {
1205
- return unionTruthyHelper(this, unionId);
1206
- }
1207
- unionEqHelper(unionId, sameValue) {
1208
- return unionEqHelper(this, unionId, sameValue);
1209
- }
1210
- unionToStrHelper(unionId) {
1211
- return unionToStrHelper(this, unionId);
1212
- }
1213
- unionJoinHelper(unionId) {
1214
- return unionJoinHelper(this, unionId);
1215
- }
1216
- jsonWriteHelper(t) {
1217
- return jsonWriteHelper(this, t);
1218
- }
1219
- jsonIndentHelper() {
1220
- return jsonIndentHelper(this);
1221
- }
1222
- dynMatchHelper(t) {
1223
- return dynMatchHelper(this, t);
1224
- }
1225
- dynCheckHelper(t) {
1226
- return dynCheckHelper(this, t);
1227
- }
1228
- toDynHelper(t) {
1229
- return toDynHelper(this, t);
1230
- }
1231
- liveDynRefAdapter(t) {
1232
- return buildLiveDynRefAdapter(this, t);
1233
- }
1234
- dynFuncBoxHelper(t) {
1235
- return dynFuncBoxHelper(this, t);
1236
- }
1237
- recordKeyGetHelper(shapeId, t, overflowOnly = false) {
1238
- return recordKeyGetHelper(this, shapeId, t, overflowOnly);
1239
- }
1240
- recordKeySetHelper(shapeId) {
1241
- return recordKeySetHelper(this, shapeId);
1242
- }
1243
- dynToStrHelper() {
1244
- return dynToStrHelper(this);
1245
- }
1246
- caughtToDynHelper() {
1247
- return caughtToDynHelper(this);
1248
- }
1249
- /* ── cycle-collection wiring ──────────────────────────────────────────
1250
- * Containers that store a payload's RC entry points as function pointers
1251
- * (obj-kind boxes, union ref arms, promise payloads, the exception cell)
1252
- * also store the payload type's TRACE entry point — non-NULL exactly when
1253
- * the payload type carries a cycle header, which is what the container's
1254
- * own trace keys on (visit when present, release at teardown when not).
1255
- * Closures/unions/promises always carry one (runtime-provided traces);
1256
- * classes/records carry one iff their shape can participate in a cycle
1257
- * (emitted trace); strings/arrays/dyn never can. */
1258
- traceAdapterC(t) {
1259
- return traceAdapterC(this, t);
1260
- }
1261
- traceArgC(t) {
1262
- return traceArgC(this, t);
1263
- }
1264
- boxNewC(t) {
1265
- return boxNewC(this, t);
1266
- }
1267
- arrNewC(elem, capExpr) {
1268
- return arrNewC(this, elem, capExpr);
1269
- }
1270
- /* ── plumbing ─────────────────────────────────────────────────────── */
1271
- integerLoopIndex(expr) {
1272
- return expr.kind === "varRef" ? this.integerLoopBindings.get(expr.localId) ?? null : null;
1273
- }
1274
- bytesElementHelper(op, elem, integerIndex = false) {
1275
- const mode = integerIndex ? "u64" : "f64";
1276
- this.bytesElementHelpers.add(`${op}:${elem}:${mode}`);
1277
- return `sc_bytes_${op}_${elem}${integerIndex ? "_u64" : ""}`;
1278
- }
1279
- emitBytesElementHelpers() {
1280
- if (this.bytesElementHelpers.size === 0)
1281
- return [];
1282
- const hasF64 = [...this.bytesElementHelpers].some((key) => key.endsWith(":f64"));
1283
- const hasU64 = [...this.bytesElementHelpers].some((key) => key.endsWith(":u64"));
1284
- const out = [`/* Typed-array hot paths specialized from the IR element kind. */`];
1285
- if (hasF64) {
1286
- out.push(`static inline size_t sc_bytes_index_checked(const ScrBytes *b, double i) {`, ` if (!(i >= 0.0 && i < (double)b->len)) { (void)scr_bytes_get(b, i); return 0; }`, ` size_t idx = (size_t)i;`, ` if ((double)idx != i) { (void)scr_bytes_get(b, i); return 0; }`, ` return idx;`, `}`);
1287
- }
1288
- if (hasU64) {
1289
- out.push(`static inline size_t sc_bytes_index_u64_checked(const ScrBytes *b, uint64_t i) {`, ` if (i >= b->len) { (void)scr_bytes_get(b, (double)i); return 0; }`, ` return (size_t)i;`, `}`);
1290
- }
1291
- if ([...this.bytesElementHelpers].some((key) => key.startsWith("set:") && !key.startsWith("set:f32:") && !key.startsWith("set:f64:"))) {
1292
- out.push(`static inline uint32_t sc_bytes_coerce_u32(double v) {`, ` if (v >= -9007199254740992.0 && v <= 9007199254740992.0) return (uint32_t)(int64_t)v;`, ` if (v != v || isinf(v)) return 0;`, ` double t = fmod(trunc(v), 4294967296.0);`, ` if (t < 0) t += 4294967296.0;`, ` return (uint32_t)t;`, `}`);
1293
- }
1294
- for (const elem of ["u8", "u32", "i32", "f32", "f64"]) {
1295
- for (const mode of ["f64", "u64"]) {
1296
- const suffix = mode === "u64" ? "_u64" : "";
1297
- const indexType = mode === "u64" ? "uint64_t" : "double";
1298
- const checked = mode === "u64" ? "sc_bytes_index_u64_checked" : "sc_bytes_index_checked";
1299
- if (this.bytesElementHelpers.has(`get:${elem}:${mode}`)) {
1300
- if (elem === "u8") {
1301
- out.push(`static inline double sc_bytes_get_u8${suffix}(const ScrBytes *b, ${indexType} i) {`, ` return (double)b->data[${checked}(b, i)];`, `}`);
1302
- }
1303
- else {
1304
- const valueType = elem === "f32" ? "float" : elem === "f64" ? "double" : elem === "i32" ? "int32_t" : "uint32_t";
1305
- const size = elem === "f64" ? 8 : 4;
1306
- out.push(`static inline double sc_bytes_get_${elem}${suffix}(const ScrBytes *b, ${indexType} i) {`, ` ${valueType} v;`, ` memcpy(&v, b->data + ${checked}(b, i) * ${size}, ${size});`, ` return (double)v;`, `}`);
1307
- }
1308
- }
1309
- if (this.bytesElementHelpers.has(`set:${elem}:${mode}`)) {
1310
- if (elem === "u8") {
1311
- out.push(`static inline void sc_bytes_set_u8${suffix}(ScrBytes *b, ${indexType} i, double v) {`, ` b->data[${checked}(b, i)] = (uint8_t)sc_bytes_coerce_u32(v);`, `}`);
1312
- }
1313
- else {
1314
- const valueType = elem === "f32" ? "float" : elem === "f64" ? "double" : "uint32_t";
1315
- const init = elem === "f32" ? `(float)v` : elem === "f64" ? "v" : `sc_bytes_coerce_u32(v)`;
1316
- const size = elem === "f64" ? 8 : 4;
1317
- out.push(`static inline void sc_bytes_set_${elem}${suffix}(ScrBytes *b, ${indexType} i, double v) {`, ` size_t idx = ${checked}(b, i);`, ` ${valueType} stored = ${init};`, ` memcpy(b->data + idx * ${size}, &stored, ${size});`, `}`);
1318
- }
1319
- }
1320
- }
1321
- }
1322
- out.push("");
1323
- return out;
1324
- }
1325
- line(text) {
1326
- const pos = this.sourceLoc === null ? null : this.debug?.position(this.sourceLoc);
1327
- if (pos !== null && pos !== undefined && text.trim() !== "") {
1328
- // Repeat the directive for every generated line: one TS statement can
1329
- // expand into many native instructions, all belonging to that line.
1330
- this.lines.push(`#line ${pos.line} ${JSON.stringify(pos.file)}`);
1331
- }
1332
- this.lines.push(" ".repeat(this.indent) + text);
1333
- }
1334
- endSourceFunction() {
1335
- this.sourceLoc = null;
1336
- if (this.debug !== null)
1337
- this.lines.push('#line 1 "<scriptc>"');
1338
- }
1339
- srcComment(loc) {
1340
- if (!this.lineStarts)
1341
- return "";
1342
- let lo = 0, hi = this.lineStarts.length - 1;
1343
- while (lo < hi) {
1344
- const mid = (lo + hi + 1) >> 1;
1345
- if (this.lineStarts[mid] <= loc.start)
1346
- lo = mid;
1347
- else
1348
- hi = mid - 1;
1349
- }
1350
- return ` /* ${this.mod.sourceFile}:${lo + 1} */`;
1351
- }
1352
- newTemp(type, init) {
1353
- const name = `sc_t${this.tempCounter++}`;
1354
- this.line(`${cDecl(type, name)} = ${init};`);
1355
- if (isRefCounted(type))
1356
- this.currentFrame().push({ name, type });
1357
- return { name, type };
1358
- }
1359
- /** A borrowed compiler temp. Used only when a surrounding operation has
1360
- * proved that evaluation cannot overwrite the owning binding before the
1361
- * temp's last use. Unlike newTemp, this does not join the release frame. */
1362
- newBorrowedTemp(type, init) {
1363
- const name = `sc_t${this.tempCounter++}`;
1364
- this.line(`${cDecl(type, name)} = ${init};`);
1365
- return { name, type };
1366
- }
1367
- /** newTemp for a MAY-THROW runtime call: the result joins its frame
1368
- * BEFORE the standard pending check, so an unwind releases the dummy
1369
- * (NULL for refcounted kinds) harmlessly and the value is only read past
1370
- * the check. The shared shape of every fallible boundary call — jsOp,
1371
- * jsExit, composite jsMarshal, dynCheck, await reads. */
1372
- fallibleTemp(type, call) {
1373
- const t = this.newTemp(type, call);
1374
- this.emitPendingCheck();
1375
- return t;
1376
- }
1377
- currentFrame() {
1378
- const frame = this.frames[this.frames.length - 1];
1379
- if (!frame)
1380
- throw new InternalCompilerError("emitter bug: no active statement frame");
1381
- return frame;
1382
- }
1383
- /** Strike a refcounted temp from its frame: ownership is being moved. */
1384
- moveTemp(t) {
1385
- if (!isRefCounted(t.type))
1386
- return;
1387
- for (let i = this.frames.length - 1; i >= 0; i--) {
1388
- const idx = this.frames[i].findIndex((e) => e.name === t.name);
1389
- if (idx >= 0) {
1390
- this.frames[i].splice(idx, 1);
1391
- return;
1392
- }
1393
- }
1394
- throw new InternalCompilerError(`emitter bug: moved temp ${t.name} not found in any frame`);
1395
- }
1396
- /** The release call for one owned refcounted value. */
1397
- releaseValue(name, type) {
1398
- this.line(`${releaseCallC(type, name)};`);
1399
- }
1400
- releaseFrame(frame) {
1401
- for (const t of frame) {
1402
- if (t.boxed)
1403
- this.line(`scr_box_release(${t.name});`);
1404
- else
1405
- this.releaseValue(t.name, t.type);
1406
- }
1407
- }
1408
- /** THE release-on-jump path (break/continue/return): pending statement
1409
- * frames and entered scopes down to (and excluding nothing above) the
1410
- * given depths, innermost first — everything whose normal fall-through
1411
- * releases the jump bypasses. The jump target's own frame/scope stay
1412
- * live: a loop's releases after the loop and a switch's after its end
1413
- * label are still on the jump's path (return passes 0/0 — it leaves the
1414
- * whole function). */
1415
- releaseForJump(frameDepth, scopeDepth) {
1416
- for (let i = this.frames.length - 1; i >= frameDepth; i--)
1417
- this.releaseFrame(this.frames[i]);
1418
- for (let i = this.scopes.length - 1; i >= scopeDepth; i--)
1419
- this.releaseFrame(this.scopes[i]);
1420
- }
1421
- /** Run the finally regions a break/continue exits, then release to its
1422
- * resolved target. Every body sees compile-time frame/scope/finally/try
1423
- * stacks truncated to the region boundary: a throw propagates outside
1424
- * the completing try, and a jump inside the finally replaces the pending
1425
- * jump without re-entering the same cleanup. */
1426
- emitFinallysForJump(finallyDepth, frameDepth, scopeDepth) {
1427
- if (this.finallyStack.length <= finallyDepth) {
1428
- this.releaseForJump(frameDepth, scopeDepth);
1429
- return;
1430
- }
1431
- const savedFrames = this.frames;
1432
- const savedScopes = this.scopes;
1433
- const savedFinally = this.finallyStack;
1434
- const savedTry = this.tryStack;
1435
- for (let i = savedFinally.length - 1; i >= finallyDepth; i--) {
1436
- const fin = savedFinally[i];
1437
- this.releaseForJump(fin.frameDepth, fin.scopeDepth);
1438
- this.frames = this.frames.slice(0, fin.frameDepth);
1439
- this.scopes = this.scopes.slice(0, fin.scopeDepth);
1440
- this.finallyStack = savedFinally.slice(0, i);
1441
- this.tryStack = savedTry.slice(0, fin.tryDepth);
1442
- this.emitBlock(fin.body);
1443
- }
1444
- this.releaseForJump(frameDepth, scopeDepth);
1445
- this.frames = savedFrames;
1446
- this.scopes = savedScopes;
1447
- this.finallyStack = savedFinally;
1448
- this.tryStack = savedTry;
1449
- }
1450
- /** THE unwind path at a point where an exception is pending: release
1451
- * everything between here and the innermost try handler — or the whole
1452
- * function — via releaseForJump, then jump to the handler / return a
1453
- * dummy value (never read: callers of a may-throw function test the
1454
- * pending flag before using the result). Callers own the surrounding
1455
- * `if (scr_exc_pending())`; a `throw` unwinds unconditionally. */
1456
- emitUnwind() {
1457
- const target = this.tryStack[this.tryStack.length - 1];
1458
- if (target) {
1459
- this.releaseForJump(target.frameDepth, target.scopeDepth);
1460
- target.used = true;
1461
- this.line(`goto ${target.label};`);
1462
- return;
1463
- }
1464
- this.releaseForJump(0, 0);
1465
- const t = this.currentReturnType;
1466
- if (t.kind === "void")
1467
- this.line(`return;`);
1468
- else if (t.kind === "f64" || t.kind === "date")
1469
- this.line(`return 0;`);
1470
- else if (t.kind === "bool")
1471
- this.line(`return false;`);
1472
- else
1473
- this.line(`return NULL;`);
1474
- }
1475
- errorVtStampLines() {
1476
- return errorVtStampLines(this);
1477
- }
1478
- /** The C symbol a direct call or closure enters a function through:
1479
- * async bodies are entered via their emitted spawn wrapper (which runs
1480
- * the fiber eagerly to its first suspension and returns the promise);
1481
- * generator bodies via theirs (which only ALLOCATES the suspended
1482
- * fiber and returns the generator object). */
1483
- callTargetC(fnName) {
1484
- const fn = this.fnByName.get(fnName);
1485
- if (fn?.generator !== undefined)
1486
- return mangleGenSpawn(fnName);
1487
- if (fn?.async === true)
1488
- return mangleAsyncSpawn(fnName);
1489
- return mangleFunction(fnName);
1490
- }
1491
- /** The emitter contract for exceptions: after EVERY call that can throw
1492
- * (per the may-throw analysis), test the pending flag and unwind. */
1493
- emitPendingCheck() {
1494
- this.line(`if (scr_exc_pending()) {`);
1495
- this.indent++;
1496
- this.emitUnwind();
1497
- this.indent--;
1498
- this.line(`}`);
1499
- }
1500
- internLiteral(text) {
1501
- let sym = this.literals.get(text);
1502
- if (!sym) {
1503
- sym = `sc_lit_${this.literals.size}`;
1504
- this.literals.set(text, sym);
1505
- }
1506
- return sym;
1507
- }
1508
- /** The class object's static symbol (classes as values), registering it
1509
- * for assembly on first use and interning the .name literal while the
1510
- * literal table is still open (bodies emit before the file assembles —
1511
- * the regex-literal discipline). */
1512
- classObjSym(className) {
1513
- let sym = this.classObjs.get(className);
1514
- if (!sym) {
1515
- const meta = this.classMeta.get(className);
1516
- if (!meta)
1517
- throw new InternalCompilerError(`emitter bug: classRef to unknown class ${className}`);
1518
- this.internLiteral(meta.def.jsName ?? "");
1519
- sym = mangleClassObj(className);
1520
- this.classObjs.set(className, sym);
1521
- }
1522
- return sym;
1523
- }
1524
- /** The interned immortal instance for a UNIT arm of a union — asserts the
1525
- * arm really is payload-less (undefined/null). */
1526
- internUnitInstance(unionId, tag) {
1527
- const arm = this.unionsById.get(unionId)?.arms[tag];
1528
- if (!arm || !isUnitType(arm)) {
1529
- throw new InternalCompilerError(`emitter bug: unit instance for non-unit arm ${tag} of ${unionId}`);
1530
- }
1531
- const key = `${unionId}:${tag}`;
1532
- let sym = this.unitInstances.get(key);
1533
- if (!sym) {
1534
- sym = `sc_unit_${this.unitInstances.size}`;
1535
- this.unitInstances.set(key, sym);
1536
- }
1537
- return sym;
1538
- }
1539
- /** The C expression for that instance — the one pointer every unit-arm
1540
- * value of this (union, tag) is: rc == SIZE_MAX, so RC entry points and
1541
- * the collector both skip it and no retain is ever owed. */
1542
- unitInstanceRef(unionId, tag) {
1543
- return `(ScrUnion *)&${this.internUnitInstance(unionId, tag)}`;
1544
- }
1545
- /** The class-newFn initialization line for a field whose type ADMITS
1546
- * undefined — such fields start as JS's `undefined`, never the calloc
1547
- * NULL: tsc's strictPropertyInitialization accepts them with no
1548
- * initializer and no constructor assignment (undefined is in the type),
1549
- * so a fresh instance is readable before any assignment runs — a method
1550
- * assigns later, a constructor branch skips it, a base constructor's
1551
- * virtual call reads a derived field before super() returns. Node reads
1552
- * `undefined` there; a NULL payload pointer would be a segfault (union
1553
- * fields) or a silent nothing (jsval fields). Undefined-armed unions get
1554
- * the interned immortal unit instance (free; releases skip it); jsval
1555
- * (`any`) fields get an engine undefined cell — such classes exist only
1556
- * in --dynamic builds, and the field's release balances it. Empty for
1557
- * every type that cannot hold undefined (tsc's SPI guards those) and for
1558
- * record shapes' construction paths, which write every field. */
1559
- undefFieldInitLineC(name, t) {
1560
- if (t.kind === "jsval") {
1561
- return [` o->${mangleField(name)} = scr_jsval_undefined(); /* ${cCommentText(name)} starts undefined */`];
1562
- }
1563
- const tag = undefinedArmTag(t, this.unionsById);
1564
- if (tag < 0 || t.kind !== "union")
1565
- return [];
1566
- return [` o->${mangleField(name)} = ${this.unitInstanceRef(t.unionId, tag)}; /* ${cCommentText(name)} starts undefined */`];
1567
- }
1568
- /* ── functions ────────────────────────────────────────────────────── */
1569
- ffiCallbackAdapter(binding, id) {
1570
- const adapter = this.ffiCallbackAdapters.get(`${binding}:${id}`);
1571
- if (!adapter)
1572
- throw new InternalCompilerError(`emitter bug: no callback adapter for ${binding}:${id}`);
1573
- return adapter;
1574
- }
1575
- /** C-callable trampolines for format-2/3/4 callbacks. The external callback
1576
- * ABI is scalar C, format-3 copy-in string/byte slots, plus an optional
1577
- * exact-position context pointer; the internal side is scriptc's
1578
- * (ScrClosure *env, params...) convention. A raw callback borrows its
1579
- * closure through a distinct TLS slot for the dynamic extent of the outer
1580
- * call, or a process-global slot for retained replace semantics. */
1581
- emitFfiCallbackDefs(out) {
1582
- if (this.ffiCallbackAdapters.size === 0)
1583
- return;
1584
- for (const adapter of this.ffiCallbackAdapters.values()) {
1585
- const cb = adapter.callback;
1586
- if (adapter.tls !== null) {
1587
- out.push(`static _Thread_local ScrClosure *${adapter.tls};`);
1588
- }
1589
- if (adapter.global !== null) {
1590
- out.push(`static ScrClosure *${adapter.global};`);
1591
- }
1592
- if (adapter.table !== null) {
1593
- out.push(`static ScrFfiTable ${adapter.table};`);
1594
- }
1595
- const nativeParams = ffiCallbackNativeParamsC(cb, true);
1596
- const ret = ffiNativeTypeC(cb.returns);
1597
- const contextParam = cb.params.findIndex(isFfiContextParam);
1598
- if (cb.invoke === "foreign") {
1599
- if (adapter.table === null || contextParam < 0 || cb.returns !== "void") {
1600
- throw new InternalCompilerError("emitter bug: invalid foreign FFI callback descriptor");
1601
- }
1602
- const dispatch = `${adapter.symbol}_dispatch`;
1603
- const ft = ffiCallbackType(cb);
1604
- const scriptArgs = cb.params.flatMap((param, i) => {
1605
- if (isFfiContextParam(param))
1606
- return [];
1607
- switch (param) {
1608
- case "f64":
1609
- return [`scr_ffi_call_get_f64(sc_call, ${i})`];
1610
- case "bool":
1611
- return [`scr_ffi_call_get_bool(sc_call, ${i})`];
1612
- case "u8":
1613
- return [`scr_ffi_call_get_u8(sc_call, ${i})`];
1614
- case "u32":
1615
- return [`scr_ffi_call_get_u32(sc_call, ${i})`];
1616
- case "i32":
1617
- return [`scr_ffi_call_get_i32(sc_call, ${i})`];
1618
- case "cstring":
1619
- case "string":
1620
- return [`scr_str_from_utf8_lossy(scr_ffi_call_get_data(sc_call, ${i}), scr_ffi_call_get_len(sc_call, ${i}))`];
1621
- case "bytes":
1622
- return [`scr_bytes_from_data(scr_ffi_call_get_data(sc_call, ${i}), scr_ffi_call_get_len(sc_call, ${i}))`];
1623
- }
1624
- });
1625
- out.push(`static void ${dispatch}(ScrClosure *sc_cb, ScrFfiCall *sc_call) {`, ` (${cFnPtrCast(ft)}sc_cb->fn)(sc_cb${scriptArgs.length ? `, ${scriptArgs.join(", ")}` : ""});`, `}`, `static void ${adapter.symbol}(${nativeParams.join(", ")}) {`, ` ScrClosure *sc_cb = (ScrClosure *)sc_ctx;`, ` ScrFfiCall *sc_call = scr_ffi_call_new(&${adapter.table}, sc_cb, &${dispatch}, ${cb.params.length});`);
1626
- cb.params.forEach((param, i) => {
1627
- if (isFfiContextParam(param))
1628
- return;
1629
- switch (param) {
1630
- case "f64":
1631
- out.push(` scr_ffi_call_set_f64(sc_call, ${i}, sc_a${i});`);
1632
- break;
1633
- case "bool":
1634
- out.push(` scr_ffi_call_set_bool(sc_call, ${i}, sc_a${i});`);
1635
- break;
1636
- case "u8":
1637
- out.push(` scr_ffi_call_set_u8(sc_call, ${i}, sc_a${i});`);
1638
- break;
1639
- case "u32":
1640
- out.push(` scr_ffi_call_set_u32(sc_call, ${i}, sc_a${i});`);
1641
- break;
1642
- case "i32":
1643
- out.push(` scr_ffi_call_set_i32(sc_call, ${i}, sc_a${i});`);
1644
- break;
1645
- case "cstring":
1646
- out.push(` scr_ffi_call_copy_cstring(sc_call, ${i}, sc_a${i});`);
1647
- break;
1648
- case "string":
1649
- case "bytes":
1650
- out.push(` scr_ffi_call_copy_${param}(sc_call, ${i}, sc_a${i}, sc_a${i}_len);`);
1651
- break;
1652
- }
1653
- });
1654
- out.push(` scr_ffi_post(sc_call);`, `}`, ``);
1655
- continue;
1656
- }
1657
- out.push(`static ${ret} ${adapter.symbol}(${nativeParams.length > 0 ? nativeParams.join(", ") : "void"}) {`, ` ScrClosure *sc_cb = ${contextParam >= 0 ? `(ScrClosure *)sc_ctx` : adapter.tls ?? adapter.global};`, ` if (sc_cb == NULL) scr_trap("scriptc: native callback invoked outside its ${adapter.callback.lifetime === "call" ? "call-scoped" : "retained"} lifetime\\n");`);
1658
- const dummy = ffiCallbackDummyC(cb);
1659
- out.push(` if (scr_exc_pending()) ${cb.returns === "void" ? "return;" : `return ${dummy};`}`);
1660
- // Reject every invalid native pointer before materializing any owned
1661
- // callback arguments, so the trap path cannot strand an earlier copy.
1662
- for (let i = 0; i < cb.params.length; i++) {
1663
- const param = cb.params[i];
1664
- if (param === "cstring") {
1665
- out.push(` if (sc_a${i} == NULL) scr_trap("scriptc: native callback passed a NULL cstring\\n");`);
1666
- }
1667
- else if (param === "string" || param === "bytes") {
1668
- out.push(` if (sc_a${i} == NULL && sc_a${i}_len != 0) scr_trap("scriptc: native callback passed a NULL ${param} span with nonzero length\\n");`);
1669
- }
1670
- }
1671
- const ft = ffiCallbackType(cb);
1672
- const materialized = new Map();
1673
- for (let i = 0; i < cb.params.length; i++) {
1674
- const param = cb.params[i];
1675
- if (isFfiContextParam(param))
1676
- continue;
1677
- if (param === "cstring") {
1678
- const local = `sc_s${i}`;
1679
- out.push(` ScrStr *${local} = scr_str_from_utf8_lossy((const uint8_t *)sc_a${i}, strlen(sc_a${i}));`);
1680
- materialized.set(i, local);
1681
- }
1682
- else if (param === "string") {
1683
- const local = `sc_s${i}`;
1684
- out.push(` ScrStr *${local} = scr_str_from_utf8_lossy(sc_a${i}, sc_a${i}_len);`);
1685
- materialized.set(i, local);
1686
- }
1687
- else if (param === "bytes") {
1688
- const local = `sc_s${i}`;
1689
- out.push(` ScrBytes *${local} = scr_bytes_from_data(sc_a${i}, sc_a${i}_len);`);
1690
- materialized.set(i, local);
1691
- }
1692
- }
1693
- const scriptArgs = cb.params.flatMap((param, i) => {
1694
- if (isFfiContextParam(param))
1695
- return [];
1696
- switch (param) {
1697
- case "f64":
1698
- return [`sc_a${i}`];
1699
- case "bool":
1700
- return [`(sc_a${i} != 0)`];
1701
- case "u8":
1702
- case "u32":
1703
- case "i32":
1704
- return [`(double)sc_a${i}`];
1705
- case "cstring":
1706
- case "string":
1707
- case "bytes":
1708
- return [materialized.get(i)];
1709
- }
1710
- });
1711
- const call = `(${cFnPtrCast(ft)}sc_cb->fn)(sc_cb${scriptArgs.length ? `, ${scriptArgs.join(", ")}` : ""})`;
1712
- if (cb.lifetime === "retained") {
1713
- // The callback may unregister or replace its own descriptor. Hold
1714
- // one invocation reference so that dropping the table's last pin
1715
- // cannot free the executing closure or its captures mid-call.
1716
- out.push(` scr_closure_retain(sc_cb);`);
1717
- }
1718
- if (cb.returns === "void") {
1719
- out.push(` ${call};`, ...(cb.lifetime === "retained" ? [` scr_closure_release(sc_cb);`] : []), ` return;`, `}`, ``);
1720
- continue;
1721
- }
1722
- out.push(` ${cDecl(ft.ret, "sc_result")} = ${call};`);
1723
- if (cb.lifetime === "retained")
1724
- out.push(` scr_closure_release(sc_cb);`);
1725
- switch (cb.returns) {
1726
- case "f64":
1727
- out.push(` return sc_result;`);
1728
- break;
1729
- case "bool":
1730
- out.push(` return (uint8_t)(sc_result ? 1 : 0);`);
1731
- break;
1732
- case "u8":
1733
- out.push(` return (uint8_t)(uint32_t)scr_bit_ushr(sc_result, 0.0);`);
1734
- break;
1735
- case "u32":
1736
- out.push(` return (uint32_t)scr_bit_ushr(sc_result, 0.0);`);
1737
- break;
1738
- case "i32":
1739
- out.push(` return (int32_t)scr_bit_or(sc_result, 0.0);`);
1740
- break;
1741
- }
1742
- out.push(`}`, ``);
1743
- }
1744
- }
1745
- signature(fn) {
1746
- const boxedIds = new Set(fn.locals.filter((l) => l.boxed).map((l) => l.id));
1747
- const parts = fn.params.map((p) =>
1748
- // A boxed param's sc_l_ name is its box; the raw value arrives under
1749
- // a sc_p_ name and is moved into the box in the prologue.
1750
- cDecl(p.type, boxedIds.has(p.localId) ? mangleRawParam(p.localId) : mangleLocal(p.localId)));
1751
- // Lifted functions receive their closure first.
1752
- if (fn.captures !== undefined)
1753
- parts.unshift("ScrClosure *sc_env");
1754
- const params = parts.length ? parts.join(", ") : "void";
1755
- return `static ${cType(fn.returnType)} ${mangleFunction(fn.name)}(${params})`;
1756
- }
1757
- emitFunction(fn) {
1758
- return emitFunction(this, fn);
1759
- }
1760
- /* ── statements ───────────────────────────────────────────────────── */
1761
- emitBlock(stmts, setup) {
1762
- return emitBlock(this, stmts, setup);
1763
- }
1764
- emitStmts(stmts) {
1765
- return emitStmts(this, stmts);
1766
- }
1767
- emitStmt(s) {
1768
- return emitStmt(this, s);
1769
- }
1770
- /** A fresh loop jump-target entry. `continueLabel` null means "C
1771
- * continue is correct" (while/forOf) — but a LABELED loop always
1772
- * allocates one (a labeled continue arriving from a nested loop needs a
1773
- * goto), and every labeled loop gets a lazy end label for labeled break
1774
- * (a C break only exits the innermost loop). */
1775
- loopTarget(continueLabel, labels) {
1776
- return {
1777
- kind: "loop",
1778
- continueLabel: continueLabel === null && labels !== undefined ? `sc_cont_${this.labelCounter++}` : continueLabel,
1779
- usedContinue: false,
1780
- endLabel: labels !== undefined ? `sc_end_${this.labelCounter++}` : null,
1781
- usedEnd: false,
1782
- ...(labels !== undefined && { labels }),
1783
- scopeDepth: this.scopes.length,
1784
- frameDepth: this.frames.length,
1785
- finallyDepth: this.finallyStack.length,
1786
- };
1787
- }
1788
- emitTryCatch(s) {
1789
- return emitTryCatch(this, s);
1790
- }
1791
- emitSwitch(s) {
1792
- return emitSwitch(this, s);
1793
- }
1794
- mergeBrace(emitBlockFn) {
1795
- return mergeBrace(this, emitBlockFn);
1796
- }
1797
- emitBranchInto(target, expr) {
1798
- return emitBranchInto(this, target, expr);
1799
- }
1800
- emitCondition(cond) {
1801
- return emitCondition(this, cond);
1802
- }
1803
- /** C expression testing JS truthiness of a temp (falsy: 0, -0, NaN, "").
1804
- * `x == x` rejects NaN, `x != 0` rejects both zeros; strings only need
1805
- * their length — no runtime call, no ownership change. */
1806
- truthyC(t) {
1807
- if (POINTER_KINDS.has(t.type.kind) &&
1808
- t.type.kind !== "string" && t.type.kind !== "bigint" && t.type.kind !== "union" &&
1809
- t.type.kind !== "dyn" && t.type.kind !== "jsval" &&
1810
- t.type.kind !== "caught") {
1811
- // JS objects are ALWAYS truthy ([] and {} included). These are
1812
- // non-NULL pointers, so the honest constant reads as a pointer
1813
- // test (no unused-value warnings, operand still evaluated).
1814
- return `${t.name} != NULL`;
1815
- }
1816
- switch (t.type.kind) {
1817
- case "bool":
1818
- return t.name;
1819
- case "f64":
1820
- return `${t.name} == ${t.name} && ${t.name} != 0`;
1821
- case "string":
1822
- return `${t.name}->len != 0`;
1823
- case "bigint":
1824
- return `scr_bigint_truthy(${t.name})`;
1825
- case "date":
1826
- // The scalar payload may be 0 or NaN, but the source Date object
1827
- // is always truthy.
1828
- return "true";
1829
- case "jsval":
1830
- // Island truthiness: the engine's ToBoolean (never throws, no
1831
- // ownership change) — jsval operands are legal in `logical`.
1832
- return `(scr_jsval_truthy(${t.name}) != 0)`;
1833
- case "union":
1834
- // The ARM value's ToBoolean, answered by a per-union interned
1835
- // helper (switch on tag: unit arms false, scalar/string arms by
1836
- // value, ref arms true, jsval arms ask the engine).
1837
- return `${this.unionTruthyHelper(t.type.unionId)}(${t.name})`;
1838
- case "procStream":
1839
- // A stream value is a JS object (always truthy); the scalar fd
1840
- // representation is 1 or 2, so the honest constant reads as its
1841
- // own non-zero test.
1842
- return `${t.name} != 0`;
1843
- case "dyn":
1844
- // ToBoolean over the dyn kind (scr_dyn_truthy — JS-exact for
1845
- // every kind; borrowed, never throws): `v || dflt` and condition
1846
- // descent on checked-dynamic values.
1847
- return `scr_dyn_truthy(${t.name})`;
1848
- case "undefinedT":
1849
- case "nullT":
1850
- case "caught":
1851
- throw new InternalCompilerError(`emitter bug: truthiness of ${t.type.kind}`);
1852
- case "void":
1853
- throw new InternalCompilerError("emitter bug: truthiness of void");
1854
- default: {
1855
- const _exhaustive = t.type;
1856
- void _exhaustive;
1857
- throw new InternalCompilerError("unreachable");
1858
- }
1859
- }
1860
- }
1861
- /* ── expressions ──────────────────────────────────────────────────── */
1862
- emitExpr(e) {
1863
- return emitExpr(this, e);
1864
- }
1865
- childExitThunkFor(param) {
1866
- return childExitThunkFor(this, param);
1867
- }
1868
- execFileThunkFor(cbT) {
1869
- return execFileThunkFor(this, cbT);
1870
- }
1871
- ipcMessageThunkFor(cbT) {
1872
- return ipcMessageThunkFor(this, cbT);
1873
- }
1874
- ipcSendThunkFor(cbT) {
1875
- return ipcSendThunkFor(this, cbT);
1876
- }
1877
- childDataThunkFor(param) {
1878
- return childDataThunkFor(this, param);
1879
- }
1880
- closeBindThunkFor(cbUnion, retServer) {
1881
- return closeBindThunkFor(this, cbUnion, retServer);
1882
- }
1883
- closeOverrideWrapFor(cbUnion, retServer) {
1884
- return closeOverrideWrapFor(this, cbUnion, retServer);
1885
- }
1886
- childExitSignalThunkFor(codeParam, sigParam) {
1887
- return childExitSignalThunkFor(this, codeParam, sigParam);
1888
- }
1889
- dgramMsgThunkFor(param) {
1890
- return dgramMsgThunkFor(this, param);
1891
- }
1892
- dnsLookupThunkFor(cbT) {
1893
- return dnsLookupThunkFor(this, cbT);
1894
- }
1895
- fsRenameThunkFor(cbT) {
1896
- return fsRenameThunkFor(this, cbT);
1897
- }
1898
- cryptoBytesThunkFor(cbT) {
1899
- return cryptoBytesThunkFor(this, cbT);
1900
- }
1901
- zlibBytesThunkFor(cbT) {
1902
- return zlibBytesThunkFor(this, cbT);
1903
- }
1904
- sniAnswerThunkFor(cbT) {
1905
- return sniAnswerThunkFor(this, cbT);
1906
- }
1907
- netLookupAnswerThunkFor(cbT) {
1908
- return netLookupAnswerThunkFor(this, cbT);
1909
- }
1910
- emitterInvokeThunkFor(cbT) {
1911
- return emitterInvokeThunkFor(this, cbT);
1912
- }
1913
- streamDataThunkFor(cbT) {
1914
- return streamDataThunkFor(this, cbT);
1915
- }
1916
- streamCbThunkFor(kind, cbT) {
1917
- return streamCbThunkFor(this, kind, cbT);
1918
- }
1919
- connectSockThunkFor(cbT) {
1920
- return connectSockThunkFor(this, cbT);
1921
- }
1922
- connectResThunkFor(cbT) {
1923
- return connectResThunkFor(this, cbT);
1924
- }
1925
- raceAdapterFor(from, to) {
1926
- return raceAdapterFor(this, from, to);
1927
- }
1928
- resolveThunkFor(inner) {
1929
- return resolveThunkFor(this, inner);
1930
- }
1931
- }
1932
- //# sourceMappingURL=c-emitter.js.map