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