@scriptc/compiler 0.0.35 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +14 -11
  2. package/ambient/scriptc-overrides.d.ts +0 -7
  3. package/ambient/scriptc.d.ts +1 -1
  4. package/dist/backend/build-cache.d.ts +44 -0
  5. package/dist/backend/build-cache.js +241 -0
  6. package/dist/backend/build-cache.js.map +1 -0
  7. package/dist/backend/{emission/emit-async.d.ts → c/async.d.ts} +21 -30
  8. package/dist/backend/{emission/emit-async.js → c/async.js} +270 -286
  9. package/dist/backend/c/async.js.map +1 -0
  10. package/dist/backend/{emission/emitter.d.ts → c/c-emitter.d.ts} +6 -23
  11. package/dist/backend/{emission/emitter.js → c/c-emitter.js} +53 -107
  12. package/dist/backend/c/c-emitter.js.map +1 -0
  13. package/dist/backend/c/exprs.d.ts +8 -0
  14. package/dist/backend/c/exprs.js +7937 -0
  15. package/dist/backend/c/exprs.js.map +1 -0
  16. package/dist/backend/{emission/emit-island.d.ts → c/island.d.ts} +5 -5
  17. package/dist/backend/{emission/emit-island.js → c/island.js} +24 -22
  18. package/dist/backend/c/island.js.map +1 -0
  19. package/dist/backend/{emission → c}/may-throw.d.ts +1 -1
  20. package/dist/backend/{emission → c}/may-throw.js +4 -1
  21. package/dist/backend/c/may-throw.js.map +1 -0
  22. package/dist/backend/{emission/emit-shapes.d.ts → c/shapes.d.ts} +19 -19
  23. package/dist/backend/{emission/emit-shapes.js → c/shapes.js} +78 -87
  24. package/dist/backend/c/shapes.js.map +1 -0
  25. package/dist/backend/{emission/emit-stmts.d.ts → c/stmts.d.ts} +12 -12
  26. package/dist/backend/{emission/emit-stmts.js → c/stmts.js} +395 -343
  27. package/dist/backend/c/stmts.js.map +1 -0
  28. package/dist/backend/{emission/emit-types.d.ts → c/types.d.ts} +1 -1
  29. package/dist/backend/{emission/emit-types.js → c/types.js} +42 -286
  30. package/dist/backend/c/types.js.map +1 -0
  31. package/dist/backend/c/types.test.js +25 -0
  32. package/dist/backend/c/types.test.js.map +1 -0
  33. package/dist/backend/{emission/emit-walkers.d.ts → c/walkers.d.ts} +19 -41
  34. package/dist/backend/{emission/emit-walkers.js → c/walkers.js} +242 -304
  35. package/dist/backend/c/walkers.js.map +1 -0
  36. package/dist/backend/external-c.d.ts +33 -0
  37. package/dist/backend/external-c.js +51 -0
  38. package/dist/backend/external-c.js.map +1 -0
  39. package/dist/backend/ffi-callbacks.d.ts +1 -1
  40. package/dist/backend/ffi-callbacks.js +4 -3
  41. package/dist/backend/ffi-callbacks.js.map +1 -1
  42. package/dist/backend/{library-identity.d.ts → library-identity-markers.d.ts} +0 -4
  43. package/dist/backend/{library-identity.js → library-identity-markers.js} +10 -9
  44. package/dist/backend/library-identity-markers.js.map +1 -0
  45. package/dist/backend/link-plan.d.ts +37 -0
  46. package/dist/backend/link-plan.js +26 -0
  47. package/dist/backend/link-plan.js.map +1 -0
  48. package/dist/backend/linker.d.ts +22 -0
  49. package/dist/backend/linker.js +236 -0
  50. package/dist/backend/linker.js.map +1 -0
  51. package/dist/backend/llvm/blocks.d.ts +4 -0
  52. package/dist/backend/llvm/blocks.js +29 -0
  53. package/dist/backend/llvm/blocks.js.map +1 -1
  54. package/dist/backend/llvm/classes.d.ts +2 -19
  55. package/dist/backend/llvm/classes.js +20 -52
  56. package/dist/backend/llvm/classes.js.map +1 -1
  57. package/dist/backend/llvm/common.d.ts +4 -0
  58. package/dist/backend/llvm/common.js +27 -0
  59. package/dist/backend/llvm/common.js.map +1 -0
  60. package/dist/backend/llvm/dyn.d.ts +3 -8
  61. package/dist/backend/llvm/dyn.js +159 -224
  62. package/dist/backend/llvm/dyn.js.map +1 -1
  63. package/dist/backend/llvm/emitter.d.ts +4 -1
  64. package/dist/backend/llvm/emitter.js +548 -9988
  65. package/dist/backend/llvm/emitter.js.map +1 -1
  66. package/dist/backend/llvm/expr-async.d.ts +4 -0
  67. package/dist/backend/llvm/expr-async.js +726 -0
  68. package/dist/backend/llvm/expr-async.js.map +1 -0
  69. package/dist/backend/llvm/expr-bytes.d.ts +13 -0
  70. package/dist/backend/llvm/expr-bytes.js +456 -0
  71. package/dist/backend/llvm/expr-bytes.js.map +1 -0
  72. package/dist/backend/llvm/expr-callbacks.d.ts +22 -0
  73. package/dist/backend/llvm/expr-callbacks.js +520 -0
  74. package/dist/backend/llvm/expr-callbacks.js.map +1 -0
  75. package/dist/backend/llvm/expr-calls.d.ts +2 -0
  76. package/dist/backend/llvm/expr-calls.js +618 -0
  77. package/dist/backend/llvm/expr-calls.js.map +1 -0
  78. package/dist/backend/llvm/expr-containers.d.ts +25 -0
  79. package/dist/backend/llvm/expr-containers.js +637 -0
  80. package/dist/backend/llvm/expr-containers.js.map +1 -0
  81. package/dist/backend/llvm/expr-context.d.ts +255 -0
  82. package/dist/backend/llvm/expr-context.js +2 -0
  83. package/dist/backend/llvm/expr-context.js.map +1 -0
  84. package/dist/backend/llvm/expr-control.d.ts +2 -0
  85. package/dist/backend/llvm/expr-control.js +473 -0
  86. package/dist/backend/llvm/expr-control.js.map +1 -0
  87. package/dist/backend/llvm/expr-dispatch.d.ts +4 -0
  88. package/dist/backend/llvm/expr-dispatch.js +153 -0
  89. package/dist/backend/llvm/expr-dispatch.js.map +1 -0
  90. package/dist/backend/llvm/expr-dynamic.d.ts +2 -0
  91. package/dist/backend/llvm/expr-dynamic.js +810 -0
  92. package/dist/backend/llvm/expr-dynamic.js.map +1 -0
  93. package/dist/backend/llvm/expr-island.d.ts +15 -0
  94. package/dist/backend/llvm/expr-island.js +690 -0
  95. package/dist/backend/llvm/expr-island.js.map +1 -0
  96. package/dist/backend/llvm/expr-primitives.d.ts +6 -0
  97. package/dist/backend/llvm/expr-primitives.js +642 -0
  98. package/dist/backend/llvm/expr-primitives.js.map +1 -0
  99. package/dist/backend/llvm/expr-records.d.ts +9 -0
  100. package/dist/backend/llvm/expr-records.js +299 -0
  101. package/dist/backend/llvm/expr-records.js.map +1 -0
  102. package/dist/backend/llvm/expr-stream-bridges.d.ts +13 -0
  103. package/dist/backend/llvm/expr-stream-bridges.js +420 -0
  104. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -0
  105. package/dist/backend/llvm/expr-stream-callbacks.d.ts +12 -0
  106. package/dist/backend/llvm/expr-stream-callbacks.js +360 -0
  107. package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -0
  108. package/dist/backend/llvm/lib-dispatch.d.ts +5 -0
  109. package/dist/backend/llvm/lib-dispatch.js +267 -0
  110. package/dist/backend/llvm/lib-dispatch.js.map +1 -0
  111. package/dist/backend/llvm/lib-filesystem.d.ts +6 -0
  112. package/dist/backend/llvm/lib-filesystem.js +594 -0
  113. package/dist/backend/llvm/lib-filesystem.js.map +1 -0
  114. package/dist/backend/llvm/lib-network.d.ts +2 -0
  115. package/dist/backend/llvm/lib-network.js +429 -0
  116. package/dist/backend/llvm/lib-network.js.map +1 -0
  117. package/dist/backend/llvm/lib-process.d.ts +5 -0
  118. package/dist/backend/llvm/lib-process.js +585 -0
  119. package/dist/backend/llvm/lib-process.js.map +1 -0
  120. package/dist/backend/llvm/lib-shared.d.ts +6 -0
  121. package/dist/backend/llvm/lib-shared.js +687 -0
  122. package/dist/backend/llvm/lib-shared.js.map +1 -0
  123. package/dist/backend/llvm/lib-stream.d.ts +2 -0
  124. package/dist/backend/llvm/lib-stream.js +470 -0
  125. package/dist/backend/llvm/lib-stream.js.map +1 -0
  126. package/dist/backend/llvm/shapes.d.ts +12 -2
  127. package/dist/backend/llvm/shapes.js +66 -307
  128. package/dist/backend/llvm/shapes.js.map +1 -1
  129. package/dist/backend/llvm/shapes.test.js +52 -0
  130. package/dist/backend/llvm/shapes.test.js.map +1 -0
  131. package/dist/backend/llvm/unsupported.d.ts +1 -1
  132. package/dist/backend/llvm/walkers.d.ts +2 -3
  133. package/dist/backend/llvm/walkers.js +195 -222
  134. package/dist/backend/llvm/walkers.js.map +1 -1
  135. package/dist/backend/native-codegen.d.ts +45 -0
  136. package/dist/backend/native-codegen.js +275 -0
  137. package/dist/backend/native-codegen.js.map +1 -0
  138. package/dist/backend/native-codegen.test.js +226 -0
  139. package/dist/backend/native-codegen.test.js.map +1 -0
  140. package/dist/backend/native-link-info.d.ts +96 -0
  141. package/dist/backend/native-link-info.js +243 -0
  142. package/dist/backend/native-link-info.js.map +1 -0
  143. package/dist/backend/native-link-info.test.d.ts +1 -0
  144. package/dist/backend/native-link-info.test.js +134 -0
  145. package/dist/backend/native-link-info.test.js.map +1 -0
  146. package/dist/backend/{cc.d.ts → native-toolchain.d.ts} +54 -34
  147. package/dist/backend/{cc.js → native-toolchain.js} +231 -810
  148. package/dist/backend/native-toolchain.js.map +1 -0
  149. package/dist/backend/native-toolchain.test.d.ts +1 -0
  150. package/dist/backend/{cc-cache.test.js → native-toolchain.test.js} +219 -7
  151. package/dist/backend/native-toolchain.test.js.map +1 -0
  152. package/dist/backend/object-localize.js +1 -1
  153. package/dist/backend/runtime-abi.d.ts +10 -0
  154. package/dist/backend/runtime-abi.js +11 -0
  155. package/dist/backend/runtime-abi.js.map +1 -0
  156. package/dist/backend/runtime-pack-targets.test.d.ts +1 -0
  157. package/dist/backend/runtime-pack-targets.test.js +54 -0
  158. package/dist/backend/runtime-pack-targets.test.js.map +1 -0
  159. package/dist/backend/runtime-pack.d.ts +112 -0
  160. package/dist/backend/runtime-pack.js +305 -0
  161. package/dist/backend/runtime-pack.js.map +1 -0
  162. package/dist/backend/runtime-pack.test.d.ts +1 -0
  163. package/dist/backend/runtime-pack.test.js +473 -0
  164. package/dist/backend/runtime-pack.test.js.map +1 -0
  165. package/dist/backend/targets.d.ts +76 -0
  166. package/dist/backend/targets.js +262 -0
  167. package/dist/backend/targets.js.map +1 -0
  168. package/dist/backend/targets.test.d.ts +1 -0
  169. package/dist/backend/targets.test.js +41 -0
  170. package/dist/backend/targets.test.js.map +1 -0
  171. package/dist/backend/vendor-archives.d.ts +41 -0
  172. package/dist/backend/vendor-archives.js +462 -0
  173. package/dist/backend/vendor-archives.js.map +1 -0
  174. package/dist/compat/fetch-profile.d.ts +0 -1
  175. package/dist/compat/fetch-profile.js +0 -1
  176. package/dist/compat/fetch-profile.js.map +1 -1
  177. package/dist/coverage/report.js +3 -3
  178. package/dist/coverage/report.js.map +1 -1
  179. package/dist/coverage/surface-manifest.js +35 -33
  180. package/dist/coverage/surface-manifest.js.map +1 -1
  181. package/dist/diagnostics/diagnostic.d.ts +11 -12
  182. package/dist/diagnostics/diagnostic.js +19 -17
  183. package/dist/diagnostics/diagnostic.js.map +1 -1
  184. package/dist/diagnostics/render.d.ts +1 -1
  185. package/dist/diagnostics/render.js +1 -1
  186. package/dist/diagnostics/render.js.map +1 -1
  187. package/dist/errors.d.ts +5 -0
  188. package/dist/errors.js +9 -0
  189. package/dist/errors.js.map +1 -0
  190. package/dist/executable/{early-cache.d.ts → executable-cache.d.ts} +2 -2
  191. package/dist/executable/{early-cache.js → executable-cache.js} +36 -98
  192. package/dist/executable/executable-cache.js.map +1 -0
  193. package/dist/executable/executable-cache.test.d.ts +1 -0
  194. package/dist/executable/{early-cache.test.js → executable-cache.test.js} +3 -3
  195. package/dist/executable/executable-cache.test.js.map +1 -0
  196. package/dist/ffi/{profile.js → ffi-manifest.js} +1 -1
  197. package/dist/ffi/ffi-manifest.js.map +1 -0
  198. package/dist/frontend/builtin-modules.d.ts +21 -0
  199. package/dist/frontend/builtin-modules.js +82 -0
  200. package/dist/frontend/builtin-modules.js.map +1 -0
  201. package/dist/frontend/cjs-lexer.d.ts +7 -0
  202. package/dist/frontend/cjs-lexer.js +15 -17
  203. package/dist/frontend/cjs-lexer.js.map +1 -1
  204. package/dist/frontend/dts-paths.d.ts +26 -0
  205. package/dist/frontend/dts-paths.js +41 -0
  206. package/dist/frontend/dts-paths.js.map +1 -0
  207. package/dist/frontend/input-tracker.d.ts +0 -2
  208. package/dist/frontend/input-tracker.js +1 -4
  209. package/dist/frontend/input-tracker.js.map +1 -1
  210. package/dist/frontend/lib-contract.d.ts +1 -5
  211. package/dist/frontend/lib-contract.js +1 -1
  212. package/dist/frontend/lib-contract.js.map +1 -1
  213. package/dist/frontend/lib-exports.d.ts +1 -1
  214. package/dist/frontend/lowering/array-values.d.ts +8 -0
  215. package/dist/frontend/lowering/array-values.js +60 -0
  216. package/dist/frontend/lowering/array-values.js.map +1 -0
  217. package/dist/frontend/lowering/call-position.d.ts +4 -0
  218. package/dist/frontend/lowering/call-position.js +7 -0
  219. package/dist/frontend/lowering/call-position.js.map +1 -0
  220. package/dist/frontend/lowering/callback-arg.d.ts +20 -0
  221. package/dist/frontend/lowering/callback-arg.js +44 -0
  222. package/dist/frontend/lowering/callback-arg.js.map +1 -0
  223. package/dist/frontend/lowering/lib-boundary.d.ts +1 -1
  224. package/dist/frontend/lowering/lib-boundary.js +34 -34
  225. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  226. package/dist/frontend/lowering/lower-array-sort.d.ts +22 -0
  227. package/dist/frontend/lowering/lower-array-sort.js +619 -0
  228. package/dist/frontend/lowering/lower-array-sort.js.map +1 -0
  229. package/dist/frontend/lowering/lower-assert.d.ts +3 -3
  230. package/dist/frontend/lowering/lower-assert.js +214 -241
  231. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  232. package/dist/frontend/lowering/lower-builtins.d.ts +74 -146
  233. package/dist/frontend/lowering/lower-builtins.js +1285 -1233
  234. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  235. package/dist/frontend/lowering/lower-calls.d.ts +59 -192
  236. package/dist/frontend/lowering/lower-calls.js +1644 -1506
  237. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  238. package/dist/frontend/lowering/lower-classes.d.ts +62 -125
  239. package/dist/frontend/lowering/lower-classes.js +832 -866
  240. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  241. package/dist/frontend/lowering/lower-comptime.d.ts +5 -12
  242. package/dist/frontend/lowering/lower-comptime.js +32 -31
  243. package/dist/frontend/lowering/lower-comptime.js.map +1 -1
  244. package/dist/frontend/lowering/lower-containers.d.ts +35 -135
  245. package/dist/frontend/lowering/lower-containers.js +1984 -2227
  246. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  247. package/dist/frontend/lowering/lower-dgram.d.ts +3 -7
  248. package/dist/frontend/lowering/lower-dgram.js +97 -111
  249. package/dist/frontend/lowering/lower-dgram.js.map +1 -1
  250. package/dist/frontend/lowering/lower-enums.d.ts +4 -4
  251. package/dist/frontend/lowering/lower-enums.js +30 -30
  252. package/dist/frontend/lowering/lower-enums.js.map +1 -1
  253. package/dist/frontend/lowering/{lower-emitter.d.ts → lower-event-emitter.d.ts} +7 -18
  254. package/dist/frontend/lowering/{lower-emitter.js → lower-event-emitter.js} +172 -174
  255. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -0
  256. package/dist/frontend/lowering/lower-expando.d.ts +5 -5
  257. package/dist/frontend/lowering/lower-expando.js +40 -40
  258. package/dist/frontend/lowering/lower-expando.js.map +1 -1
  259. package/dist/frontend/lowering/lower-exprs.d.ts +60 -264
  260. package/dist/frontend/lowering/lower-exprs.js +2361 -1765
  261. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  262. package/dist/frontend/lowering/lower-generators.d.ts +6 -6
  263. package/dist/frontend/lowering/lower-generators.js +73 -72
  264. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  265. package/dist/frontend/lowering/lower-inspect.d.ts +5 -17
  266. package/dist/frontend/lowering/lower-inspect.js +273 -261
  267. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  268. package/dist/frontend/lowering/lower-island.d.ts +39 -49
  269. package/dist/frontend/lowering/lower-island.js +447 -513
  270. package/dist/frontend/lowering/lower-island.js.map +1 -1
  271. package/dist/frontend/lowering/lower-mixins.d.ts +7 -10
  272. package/dist/frontend/lowering/lower-mixins.js +85 -85
  273. package/dist/frontend/lowering/lower-mixins.js.map +1 -1
  274. package/dist/frontend/lowering/lower-modules.d.ts +12 -18
  275. package/dist/frontend/lowering/lower-modules.js +284 -283
  276. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  277. package/dist/frontend/lowering/lower-namespaces.d.ts +23 -49
  278. package/dist/frontend/lowering/lower-namespaces.js +123 -115
  279. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  280. package/dist/frontend/lowering/lower-server.d.ts +18 -25
  281. package/dist/frontend/lowering/lower-server.js +909 -899
  282. package/dist/frontend/lowering/lower-server.js.map +1 -1
  283. package/dist/frontend/lowering/lower-stmts.d.ts +30 -149
  284. package/dist/frontend/lowering/lower-stmts.js +1463 -1285
  285. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  286. package/dist/frontend/lowering/lower-stream.d.ts +12 -12
  287. package/dist/frontend/lowering/lower-stream.js +300 -301
  288. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  289. package/dist/frontend/lowering/lower-test.d.ts +5 -5
  290. package/dist/frontend/lowering/lower-test.js +82 -82
  291. package/dist/frontend/lowering/lower-test.js.map +1 -1
  292. package/dist/frontend/lowering/lowerer.d.ts +134 -22
  293. package/dist/frontend/lowering/lowerer.js +1277 -126
  294. package/dist/frontend/lowering/lowerer.js.map +1 -1
  295. package/dist/frontend/lowering/pairs-snapshot.d.ts +11 -0
  296. package/dist/frontend/lowering/pairs-snapshot.js +85 -0
  297. package/dist/frontend/lowering/pairs-snapshot.js.map +1 -0
  298. package/dist/frontend/lowering/static-this.d.ts +6 -0
  299. package/dist/frontend/lowering/static-this.js +24 -0
  300. package/dist/frontend/lowering/static-this.js.map +1 -0
  301. package/dist/frontend/lowering/surfaces.d.ts +24 -35
  302. package/dist/frontend/lowering/surfaces.js +78 -66
  303. package/dist/frontend/lowering/surfaces.js.map +1 -1
  304. package/dist/frontend/npm-static-rewrite.js +6 -28
  305. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  306. package/dist/frontend/npm-static.d.ts +0 -10
  307. package/dist/frontend/npm-static.js +4 -7
  308. package/dist/frontend/npm-static.js.map +1 -1
  309. package/dist/frontend/npm.d.ts +0 -24
  310. package/dist/frontend/npm.js +11 -85
  311. package/dist/frontend/npm.js.map +1 -1
  312. package/dist/frontend/program.d.ts +3 -1
  313. package/dist/frontend/program.js +9 -4
  314. package/dist/frontend/program.js.map +1 -1
  315. package/dist/frontend/provenance-registry.d.ts +0 -2
  316. package/dist/frontend/provenance-registry.js +0 -10
  317. package/dist/frontend/provenance-registry.js.map +1 -1
  318. package/dist/frontend/provenance.js +4 -7
  319. package/dist/frontend/provenance.js.map +1 -1
  320. package/dist/frontend/resolve.d.ts +7 -2
  321. package/dist/frontend/resolve.js +12 -17
  322. package/dist/frontend/resolve.js.map +1 -1
  323. package/dist/frontend/resolve.test.d.ts +1 -0
  324. package/dist/frontend/resolve.test.js +29 -0
  325. package/dist/frontend/resolve.test.js.map +1 -0
  326. package/dist/frontend/ts7/adapter.d.ts +2 -2
  327. package/dist/frontend/ts7/adapter.js +1 -1
  328. package/dist/frontend/ts7/adapter.js.map +1 -1
  329. package/dist/frontend/ts7/checker.js +2 -36
  330. package/dist/frontend/ts7/checker.js.map +1 -1
  331. package/dist/frontend/ts7/enums.js +2 -1
  332. package/dist/frontend/ts7/enums.js.map +1 -1
  333. package/dist/frontend/ts7/{program.js → program-adapter.js} +7 -6
  334. package/dist/frontend/ts7/program-adapter.js.map +1 -0
  335. package/dist/frontend/ts7/world-check.d.ts +1 -3
  336. package/dist/frontend/ts7/world-check.js +3 -1
  337. package/dist/frontend/ts7/world-check.js.map +1 -1
  338. package/dist/frontend/tsc-codes.d.ts +8 -0
  339. package/dist/frontend/tsc-codes.js +109 -0
  340. package/dist/frontend/tsc-codes.js.map +1 -0
  341. package/dist/frontend/{types.d.ts → type-mapper.d.ts} +2 -25
  342. package/dist/frontend/{types.js → type-mapper.js} +12 -11
  343. package/dist/frontend/type-mapper.js.map +1 -0
  344. package/dist/frontend/workspace-registry.d.ts +26 -0
  345. package/dist/frontend/workspace-registry.js +71 -0
  346. package/dist/frontend/workspace-registry.js.map +1 -0
  347. package/dist/index.d.ts +113 -31
  348. package/dist/index.js +536 -128
  349. package/dist/index.js.map +1 -1
  350. package/dist/ir/analysis.d.ts +37 -0
  351. package/dist/ir/analysis.js +118 -0
  352. package/dist/ir/analysis.js.map +1 -0
  353. package/dist/ir/analysis.test.d.ts +1 -0
  354. package/dist/ir/analysis.test.js +21 -0
  355. package/dist/ir/analysis.test.js.map +1 -0
  356. package/dist/ir/build.d.ts +9 -0
  357. package/dist/ir/build.js +33 -0
  358. package/dist/ir/build.js.map +1 -0
  359. package/dist/ir/integer-loops.d.ts +1 -1
  360. package/dist/ir/{nodes.d.ts → ir.d.ts} +119 -37
  361. package/dist/ir/{nodes.js → ir.js} +170 -166
  362. package/dist/ir/ir.js.map +1 -0
  363. package/dist/ir/ir.test.d.ts +1 -0
  364. package/dist/ir/ir.test.js +17 -0
  365. package/dist/ir/ir.test.js.map +1 -0
  366. package/dist/ir/serialize.d.ts +2 -2
  367. package/dist/ir/serialize.js +3 -2
  368. package/dist/ir/serialize.js.map +1 -1
  369. package/dist/ir/validate.d.ts +1 -1
  370. package/dist/ir/validate.js +93 -41
  371. package/dist/ir/validate.js.map +1 -1
  372. package/dist/library/cache-primitives.d.ts +24 -0
  373. package/dist/library/cache-primitives.js +83 -0
  374. package/dist/library/cache-primitives.js.map +1 -0
  375. package/dist/library/cache-reset.test.d.ts +1 -0
  376. package/dist/library/cache-reset.test.js +47 -0
  377. package/dist/library/cache-reset.test.js.map +1 -0
  378. package/dist/library/{implementation-identity.js → compiler-self-identity.js} +1 -1
  379. package/dist/library/compiler-self-identity.js.map +1 -0
  380. package/dist/library/fence-eval.d.ts +3 -1
  381. package/dist/library/fence-eval.js +8 -2
  382. package/dist/library/fence-eval.js.map +1 -1
  383. package/dist/library/int-infer.d.ts +1 -36
  384. package/dist/library/int-infer.js +29 -18
  385. package/dist/library/int-infer.js.map +1 -1
  386. package/dist/library/int-infer.test.js +4 -4
  387. package/dist/library/{early-cache.d.ts → library-cache.d.ts} +1 -1
  388. package/dist/library/{early-cache.js → library-cache.js} +34 -89
  389. package/dist/library/library-cache.js.map +1 -0
  390. package/dist/library/library-cache.test.d.ts +1 -0
  391. package/dist/library/{early-cache.test.js → library-cache.test.js} +7 -7
  392. package/dist/library/library-cache.test.js.map +1 -0
  393. package/dist/library/{profile.d.ts → library-profile.d.ts} +4 -7
  394. package/dist/library/{profile.js → library-profile.js} +18 -11
  395. package/dist/library/library-profile.js.map +1 -0
  396. package/dist/library/semantic-source.js +2 -1
  397. package/dist/library/semantic-source.js.map +1 -1
  398. package/dist/library/sidecar.d.ts +5 -2
  399. package/dist/library/sidecar.js +11 -5
  400. package/dist/library/sidecar.js.map +1 -1
  401. package/dist/startup-cache.d.ts +11 -3
  402. package/dist/startup-cache.js +17 -2
  403. package/dist/startup-cache.js.map +1 -1
  404. package/package.json +19 -2
  405. package/surface-manifest.json +5 -5
  406. package/dist/backend/cc-cache.test.js.map +0 -1
  407. package/dist/backend/cc.js.map +0 -1
  408. package/dist/backend/emission/emit-async.js.map +0 -1
  409. package/dist/backend/emission/emit-exprs.d.ts +0 -13
  410. package/dist/backend/emission/emit-exprs.js +0 -7407
  411. package/dist/backend/emission/emit-exprs.js.map +0 -1
  412. package/dist/backend/emission/emit-island.js.map +0 -1
  413. package/dist/backend/emission/emit-shapes.js.map +0 -1
  414. package/dist/backend/emission/emit-stmts.js.map +0 -1
  415. package/dist/backend/emission/emit-types.js.map +0 -1
  416. package/dist/backend/emission/emit-walkers.js.map +0 -1
  417. package/dist/backend/emission/emitter.js.map +0 -1
  418. package/dist/backend/emission/may-throw.js.map +0 -1
  419. package/dist/backend/library-identity.js.map +0 -1
  420. package/dist/executable/early-cache.js.map +0 -1
  421. package/dist/executable/early-cache.test.js.map +0 -1
  422. package/dist/ffi/profile.js.map +0 -1
  423. package/dist/frontend/lowering/lower-emitter.js.map +0 -1
  424. package/dist/frontend/shared.d.ts +0 -82
  425. package/dist/frontend/shared.js +0 -308
  426. package/dist/frontend/shared.js.map +0 -1
  427. package/dist/frontend/ts7/program.js.map +0 -1
  428. package/dist/frontend/types.js.map +0 -1
  429. package/dist/ir/nodes.js.map +0 -1
  430. package/dist/library/early-cache.js.map +0 -1
  431. package/dist/library/early-cache.test.js.map +0 -1
  432. package/dist/library/implementation-identity.js.map +0 -1
  433. package/dist/library/profile.js.map +0 -1
  434. /package/dist/backend/{cc-cache.test.d.ts → c/types.test.d.ts} +0 -0
  435. /package/dist/{executable/early-cache.test.d.ts → backend/llvm/shapes.test.d.ts} +0 -0
  436. /package/dist/{library/early-cache.test.d.ts → backend/native-codegen.test.d.ts} +0 -0
  437. /package/dist/ffi/{profile.d.ts → ffi-manifest.d.ts} +0 -0
  438. /package/dist/frontend/ts7/{program.d.ts → program-adapter.d.ts} +0 -0
  439. /package/dist/library/{implementation-identity.d.ts → compiler-self-identity.d.ts} +0 -0
@@ -0,0 +1,642 @@
1
+ /* Focused LLVM expression emission extracted from emitter.ts. */
2
+ import { InternalCompilerError } from "../../errors.js";
3
+ import { matchStringSelfConcat, undefinedArmTag } from "../../ir/analysis.js";
4
+ import { isRefCounted } from "../../ir/ir.js";
5
+ import { mangleRecordClone, mangleRecordNew } from "../mangle.js";
6
+ import { arrNewCall, elemAccess } from "./shapes.js";
7
+ import { LlvmUnsupportedError } from "./unsupported.js";
8
+ /** ScrBytesElem (scr_runtime.h): U8, U32, F32, I32. */
9
+ const BYTES_ELEM_NUM = {
10
+ u8: 0,
11
+ u32: 1,
12
+ f32: 2,
13
+ i32: 3,
14
+ };
15
+ import { f64Lit } from "./common.js";
16
+ export function emitLiteralExpr(host, e) {
17
+ const B = host.B;
18
+ switch (e.kind) {
19
+ case "numLit":
20
+ return { name: f64Lit(e.value), type: e.type };
21
+ case "boolLit":
22
+ return { name: e.value ? "true" : "false", type: e.type };
23
+ case "strLit": {
24
+ const sym = host.internLiteral(e.value);
25
+ return host.own({ name: host.retainValue(sym, e.type), type: e.type });
26
+ }
27
+ case "unitLit":
28
+ // unitLits are consumed inline by the unionWrap case (a unit arm is
29
+ // tag-only); one reaching the generic dispatch escaped its wrap.
30
+ throw new InternalCompilerError(`llvm emitter bug: bare unitLit '${e.unit}'`);
31
+ case "varRef": {
32
+ const integerSlot = host.integerLoopBindings.get(e.localId);
33
+ if (integerSlot !== undefined) {
34
+ const integer = B.tmp();
35
+ const number = B.tmp();
36
+ B.line(`${integer} = load ${host.sizeType}, ptr ${integerSlot}`);
37
+ B.line(`${number} = uitofp ${host.sizeType} ${integer} to double`);
38
+ return { name: number, type: e.type };
39
+ }
40
+ const b = host.binding(e.localId);
41
+ if (b.kind === "boxed") {
42
+ // Reads go through the shared binding; ref kinds come out +1.
43
+ // Forward-captured consts (tdz) test the box's payload slot
44
+ // first: empty is the temporal dead zone (catchable
45
+ // ReferenceError, Node's message).
46
+ const box = host.loadBox(b.slot);
47
+ if (b.local.tdz === true) {
48
+ const v = host.tdzBoxRead(box, e.type, b.local.name);
49
+ return host.own({ name: v, type: e.type });
50
+ }
51
+ const v = host.boxGet(box, e.type);
52
+ return host.own({ name: v, type: e.type });
53
+ }
54
+ const t = B.tmp();
55
+ B.line(`${t} = load ${host.llType(b.type)}, ptr ${b.slot}`);
56
+ if (isRefCounted(e.type))
57
+ return host.own({ name: host.retainValue(t, e.type), type: e.type });
58
+ return { name: t, type: e.type };
59
+ }
60
+ default: {
61
+ const _exhaustive = e;
62
+ void _exhaustive;
63
+ throw new InternalCompilerError("unreachable");
64
+ }
65
+ }
66
+ }
67
+ export function emitOperatorExpr(host, e) {
68
+ const B = host.B;
69
+ switch (e.kind) {
70
+ case "bin": {
71
+ const l = host.emitExpr(e.left);
72
+ const r = host.emitExpr(e.right);
73
+ const t = B.tmp();
74
+ const arith = { "+": "fadd", "-": "fsub", "*": "fmul", "/": "fdiv" };
75
+ const cmp = { "<": "olt", "<=": "ole", ">": "ogt", ">=": "oge", "===": "oeq", "!==": "une" };
76
+ const libm = { "%": "fmod", "**": "pow" };
77
+ const bit = {
78
+ "&": "scr_bit_and",
79
+ "|": "scr_bit_or",
80
+ "^": "scr_bit_xor",
81
+ "<<": "scr_bit_shl",
82
+ ">>": "scr_bit_shr",
83
+ ">>>": "scr_bit_ushr",
84
+ };
85
+ if ((e.op === "===" || e.op === "!==") && e.left.type.kind === "bool") {
86
+ B.line(`${t} = icmp ${e.op === "===" ? "eq" : "ne"} i1 ${l.name}, ${r.name}`);
87
+ }
88
+ else if ((e.op === "===" || e.op === "!==") && host.llType(e.left.type) === "ptr") {
89
+ // Reference identity (JS object equality) — closures, arrays,
90
+ // records compared as pointers, exactly the C `==`.
91
+ B.line(`${t} = icmp ${e.op === "===" ? "eq" : "ne"} ptr ${l.name}, ${r.name}`);
92
+ }
93
+ else if (arith[e.op] !== undefined || cmp[e.op] !== undefined) {
94
+ if (e.left.type.kind !== "f64")
95
+ throw new LlvmUnsupportedError(`bin:${e.op}:${e.left.type.kind}`, e.loc);
96
+ if (arith[e.op] !== undefined)
97
+ B.line(`${t} = ${arith[e.op]} double ${l.name}, ${r.name}`);
98
+ else
99
+ B.line(`${t} = fcmp ${cmp[e.op]} double ${l.name}, ${r.name}`);
100
+ }
101
+ else {
102
+ const fn = libm[e.op] ?? bit[e.op];
103
+ if (fn === undefined)
104
+ throw new LlvmUnsupportedError(`bin:${e.op}`, e.loc);
105
+ host.declare(`declare double @${fn}(double, double)`);
106
+ B.line(`${t} = call double @${fn}(double ${l.name}, double ${r.name})`);
107
+ }
108
+ return { name: t, type: e.type };
109
+ }
110
+ case "unary": {
111
+ const v = host.emitExpr(e.operand);
112
+ const t = B.tmp();
113
+ if (e.op === "-")
114
+ B.line(`${t} = fneg double ${v.name}`);
115
+ else if (e.op === "!")
116
+ B.line(`${t} = xor i1 ${v.name}, true`);
117
+ else {
118
+ host.declare(`declare double @scr_bit_not(double)`);
119
+ B.line(`${t} = call double @scr_bit_not(double ${v.name})`);
120
+ }
121
+ return { name: t, type: e.type };
122
+ }
123
+ case "incDec": {
124
+ // Expression-position ++/-- over an f64 binding (locals, module
125
+ // globals, capture boxes): read, write ±1, yield old (postfix) or
126
+ // new (prefix).
127
+ const b = host.binding(e.localId);
128
+ if (b.kind === "boxed") {
129
+ const box = host.loadBox(b.slot);
130
+ const old = host.boxGet(box, e.type);
131
+ const next = B.tmp();
132
+ B.line(`${next} = ${e.op === "+" ? "fadd" : "fsub"} double ${old}, ${f64Lit(1)}`);
133
+ host.boxSet(box, e.type, next);
134
+ return { name: e.prefix ? next : old, type: e.type };
135
+ }
136
+ const old = B.tmp();
137
+ const next = B.tmp();
138
+ B.line(`${old} = load double, ptr ${b.slot}`);
139
+ B.line(`${next} = ${e.op === "+" ? "fadd" : "fsub"} double ${old}, ${f64Lit(1)}`);
140
+ B.line(`store double ${next}, ptr ${b.slot}`);
141
+ return { name: e.prefix ? next : old, type: e.type };
142
+ }
143
+ case "fieldIncDec": {
144
+ // ++/-- over a class FIELD in expression position: one receiver
145
+ // evaluation, read-modify-write, old/new snapshotted — the local
146
+ // form over a field slot. CHECKED-DYNAMIC fields validate the
147
+ // number OUT (dynCheck — the catchable TypeError on non-numbers),
148
+ // compute, and box the result back into the slot; unlink-then-
149
+ // release like fieldSet (exprs.ts's shape).
150
+ const obj = host.emitExpr(e.obj);
151
+ const { ptr } = host.classFieldPtr(obj.name, e.className, e.field);
152
+ if (e.fieldDyn) {
153
+ const box = B.tmp();
154
+ B.line(`${box} = load ptr, ptr ${ptr}`);
155
+ const helper = host.dyn.dynCheckHelper(e.type);
156
+ const old = B.tmp();
157
+ B.line(`${old} = call double @${helper}(ptr ${box}, ptr null)`);
158
+ host.emitPendingCheck();
159
+ const next = B.tmp();
160
+ B.line(`${next} = ${e.op === "+" ? "fadd" : "fsub"} double ${old}, ${f64Lit(1)}`);
161
+ host.declare(`declare ptr @scr_dyn_new_num(double)`);
162
+ host.declare(`declare void @scr_dyn_release(ptr)`);
163
+ const boxed = B.tmp();
164
+ B.line(`${boxed} = call ptr @scr_dyn_new_num(double ${next})`);
165
+ B.line(`store ptr ${boxed}, ptr ${ptr}`);
166
+ B.line(`call void @scr_dyn_release(ptr ${box})`);
167
+ return { name: e.prefix ? next : old, type: e.type };
168
+ }
169
+ const old = B.tmp();
170
+ const next = B.tmp();
171
+ B.line(`${old} = load double, ptr ${ptr}`);
172
+ B.line(`${next} = ${e.op === "+" ? "fadd" : "fsub"} double ${old}, ${f64Lit(1)}`);
173
+ B.line(`store double ${next}, ptr ${ptr}`);
174
+ return { name: e.prefix ? next : old, type: e.type };
175
+ }
176
+ case "assignExpr": {
177
+ // `x = e` in expression position: the binding takes its OWN
178
+ // reference (retain for ref kinds), the temp stays the yielded
179
+ // value — CEmitter's order exactly (release old, store retained).
180
+ const concat = e.value;
181
+ const suffix = matchStringSelfConcat(e.localId, concat);
182
+ if (suffix && concat.kind === "strConcat") {
183
+ return host.emitStringSelfConcatAssign(e.localId, concat.left, suffix, true);
184
+ }
185
+ const b = host.binding(e.localId);
186
+ const v = host.emitExpr(e.value);
187
+ if (b.kind === "boxed") {
188
+ // box_set takes ownership of the passed reference, so hand it a
189
+ // retained copy and keep the temp's own reference for the yield.
190
+ const stored = isRefCounted(v.type) ? host.retainValue(v.name, v.type) : v.name;
191
+ host.boxSet(host.loadBox(b.slot), b.type, stored);
192
+ return v;
193
+ }
194
+ if (isRefCounted(b.type)) {
195
+ const old = B.tmp();
196
+ B.line(`${old} = load ptr, ptr ${b.slot}`);
197
+ host.releaseValue(old, b.type);
198
+ B.line(`store ptr ${host.retainValue(v.name, v.type)}, ptr ${b.slot}`);
199
+ }
200
+ else {
201
+ B.line(`store ${host.llType(b.type)} ${v.name}, ptr ${b.slot}`);
202
+ }
203
+ return v;
204
+ }
205
+ case "seqExpr": {
206
+ // Statements mid-expression: each emits in place (its own frame,
207
+ // exactly statement position); the result is an ordinary temp of
208
+ // the current frame. The validator restricted stmts to straight-
209
+ // line writes — no jump can leave the region.
210
+ for (const s of e.stmts)
211
+ host.emitStmt(s);
212
+ return host.emitExpr(e.result);
213
+ }
214
+ default: {
215
+ const _exhaustive = e;
216
+ void _exhaustive;
217
+ throw new InternalCompilerError("unreachable");
218
+ }
219
+ }
220
+ }
221
+ export function emitStringExpr(host, e) {
222
+ const B = host.B;
223
+ switch (e.kind) {
224
+ case "strConcat": {
225
+ const l = host.emitExpr(e.left);
226
+ const r = host.emitExpr(e.right);
227
+ host.declare(`declare ptr @scr_str_concat(ptr, ptr)`);
228
+ const t = B.tmp();
229
+ B.line(`${t} = call ptr @scr_str_concat(ptr ${l.name}, ptr ${r.name})`);
230
+ return host.own({ name: t, type: e.type });
231
+ }
232
+ case "strEq": {
233
+ const l = host.emitExpr(e.left);
234
+ const r = host.emitExpr(e.right);
235
+ host.declare(`declare zeroext i1 @scr_str_eq(ptr, ptr)`);
236
+ const eq = B.tmp();
237
+ B.line(`${eq} = call zeroext i1 @scr_str_eq(ptr ${l.name}, ptr ${r.name})`);
238
+ if (!e.negated)
239
+ return { name: eq, type: e.type };
240
+ const t = B.tmp();
241
+ B.line(`${t} = xor i1 ${eq}, true`);
242
+ return { name: t, type: e.type };
243
+ }
244
+ case "strCmp": {
245
+ const l = host.emitExpr(e.left);
246
+ const r = host.emitExpr(e.right);
247
+ const fn = e.utf16 === true ? "scr_str_cmp_u16" : "scr_str_cmp";
248
+ host.declare(`declare i32 @${fn}(ptr, ptr)`);
249
+ const c = B.tmp();
250
+ const t = B.tmp();
251
+ const pred = { "<": "slt", "<=": "sle", ">": "sgt", ">=": "sge" }[e.op];
252
+ B.line(`${c} = call i32 @${fn}(ptr ${l.name}, ptr ${r.name})`);
253
+ B.line(`${t} = icmp ${pred} i32 ${c}, 0`);
254
+ return { name: t, type: e.type };
255
+ }
256
+ case "toString": {
257
+ const v = host.emitExpr(e.operand);
258
+ if (v.type.kind === "union") {
259
+ // The ARM value's ToString: an inline tag switch (unit arms are
260
+ // interned literals, string arms retain the payload, f64/bool
261
+ // arms format — the C per-union helper at the use site). Ref
262
+ // arms never arrive (the frontend fences those).
263
+ const def = host.unionsById.get(v.type.unionId);
264
+ if (!def)
265
+ throw new InternalCompilerError(`llvm emitter bug: ToString of unknown union ${v.type.unionId}`);
266
+ const slot = B.slot();
267
+ B.entryAllocas.push(`${slot} = alloca ptr`);
268
+ const join = B.newLabel("us.j");
269
+ host.unionTagSwitch(v.name, def, (arm) => {
270
+ switch (arm.kind) {
271
+ case "undefinedT":
272
+ case "nullT": {
273
+ const lit = host.internLiteral(arm.kind === "undefinedT" ? "undefined" : "null");
274
+ B.line(`store ptr ${host.retainValue(lit, e.type)}, ptr ${slot}`);
275
+ break;
276
+ }
277
+ case "string":
278
+ B.line(`store ptr ${host.retainValue(host.unionPeek(v.name), e.type)}, ptr ${slot}`);
279
+ break;
280
+ case "f64": {
281
+ const x = B.tmp();
282
+ const r = B.tmp();
283
+ host.declare(`declare double @scr_union_get_f64(ptr)`);
284
+ host.declare(`declare ptr @scr_f64_to_scrstr(double)`);
285
+ B.line(`${x} = call double @scr_union_get_f64(ptr ${v.name})`);
286
+ B.line(`${r} = call ptr @scr_f64_to_scrstr(double ${x})`);
287
+ B.line(`store ptr ${r}, ptr ${slot}`);
288
+ break;
289
+ }
290
+ case "bool": {
291
+ const x = B.tmp();
292
+ const r = B.tmp();
293
+ host.declare(`declare zeroext i1 @scr_union_get_bool(ptr)`);
294
+ host.declare(`declare ptr @scr_bool_to_scrstr(i1 zeroext)`);
295
+ B.line(`${x} = call zeroext i1 @scr_union_get_bool(ptr ${v.name})`);
296
+ B.line(`${r} = call ptr @scr_bool_to_scrstr(i1 zeroext ${x})`);
297
+ B.line(`store ptr ${r}, ptr ${slot}`);
298
+ break;
299
+ }
300
+ case "bytes": {
301
+ // Buffer.toString() IS the utf8 decode (Node's default
302
+ // encoding) — the `Buffer | string` chunk idiom.
303
+ const enc = host.internLiteral("utf8");
304
+ const p = host.unionPeek(v.name);
305
+ const r = B.tmp();
306
+ host.declare(`declare ptr @scr_bytes_to_str(ptr, ptr)`);
307
+ B.line(`${r} = call ptr @scr_bytes_to_str(ptr ${p}, ptr ${enc})`);
308
+ B.line(`store ptr ${r}, ptr ${slot}`);
309
+ break;
310
+ }
311
+ default:
312
+ throw new LlvmUnsupportedError(`toString:union:${arm.kind}`, e.loc);
313
+ }
314
+ B.br(join);
315
+ });
316
+ B.startBlock(join);
317
+ const t = B.tmp();
318
+ B.line(`${t} = load ptr, ptr ${slot}`);
319
+ return host.own({ name: t, type: e.type });
320
+ }
321
+ if (v.type.kind === "record") {
322
+ // String(record) / `${record}`: Object.prototype.toString's
323
+ // constant — the interned literal, retained like a strLit.
324
+ const sym = host.internLiteral("[object Object]");
325
+ return host.own({ name: host.retainValue(sym, e.type), type: e.type });
326
+ }
327
+ if (v.type.kind === "caught") {
328
+ // String(e) / `${e}` on a catch binding: JS's String() over the
329
+ // snapshot (scr_caught_to_string — borrows the box, +1 result).
330
+ host.declare(`declare ptr @scr_caught_to_string(ptr)`);
331
+ const t = B.tmp();
332
+ B.line(`${t} = call ptr @scr_caught_to_string(ptr ${v.name})`);
333
+ return host.own({ name: t, type: e.type });
334
+ }
335
+ if (v.type.kind === "dyn") {
336
+ // String(unknown): dispatch over the dyn kind (dyn.ts's sc_ds —
337
+ // Node's String() incl. arrays-join and "[object Object]").
338
+ const helper = host.dyn.dynToStrHelper();
339
+ const t = B.tmp();
340
+ B.line(`${t} = call ptr @${helper}(ptr ${v.name})`);
341
+ return host.own({ name: t, type: e.type });
342
+ }
343
+ const t = B.tmp();
344
+ if (v.type.kind === "f64") {
345
+ host.declare(`declare ptr @scr_f64_to_scrstr(double)`);
346
+ B.line(`${t} = call ptr @scr_f64_to_scrstr(double ${v.name})`);
347
+ }
348
+ else if (v.type.kind === "bool") {
349
+ host.declare(`declare ptr @scr_bool_to_scrstr(i1 zeroext)`);
350
+ B.line(`${t} = call ptr @scr_bool_to_scrstr(i1 zeroext ${v.name})`);
351
+ }
352
+ else {
353
+ throw new LlvmUnsupportedError(`toString:${v.type.kind}`, e.loc);
354
+ }
355
+ return host.own({ name: t, type: e.type });
356
+ }
357
+ case "strIntrinsic":
358
+ return host.emitStrIntrinsic(e);
359
+ case "regexLit": {
360
+ // One immortal static per (pattern, flags) pair; the +1 retain is
361
+ // a no-op on immortals but keeps the owned-temps discipline
362
+ // uniform. Pattern/flags strings intern NOW (the literal table is
363
+ // still open — the C emitter's regex-literal discipline).
364
+ const key = `${e.flags}/${e.pattern}`;
365
+ let re = host.regexInstances.get(key);
366
+ if (!re) {
367
+ re = {
368
+ sym: `sc_re_${host.regexInstances.size}`,
369
+ src: host.internLiteral(e.pattern),
370
+ fl: host.internLiteral(e.flags),
371
+ };
372
+ host.regexInstances.set(key, re);
373
+ }
374
+ return host.own({ name: host.retainValue(`@${re.sym}`, e.type), type: e.type });
375
+ }
376
+ case "templateStrings": {
377
+ // One immortal static string array per template SITE (the key);
378
+ // the +1 retain is a no-op on immortals. Cooked strings intern
379
+ // NOW (the literal table is still open).
380
+ let inst = host.templateStringsInstances.get(e.key);
381
+ if (!inst) {
382
+ inst = {
383
+ sym: `sc_tsa_${host.templateStringsInstances.size}`,
384
+ slots: e.cooked.map((s) => host.internLiteral(s)),
385
+ };
386
+ host.templateStringsInstances.set(e.key, inst);
387
+ }
388
+ return host.own({ name: host.retainValue(`@${inst.sym}`, e.type), type: e.type });
389
+ }
390
+ case "regexIntrinsic":
391
+ return host.emitRegexIntrinsic(e);
392
+ default: {
393
+ const _exhaustive = e;
394
+ void _exhaustive;
395
+ throw new InternalCompilerError("unreachable");
396
+ }
397
+ }
398
+ }
399
+ export function emitContainerExpr(host, e) {
400
+ const B = host.B;
401
+ switch (e.kind) {
402
+ case "arrayLit": {
403
+ // Allocate, then push each element in order. Ownership of refcounted
404
+ // plain elements moves into the array; SPREAD positions hold a
405
+ // same-typed source array (borrowed): its elements copy in —
406
+ // _get_ref returns +1 and _push_ref takes ownership, RC-balanced;
407
+ // the length is snapshotted before the loop.
408
+ if (e.type.kind !== "array")
409
+ throw new InternalCompilerError("llvm emitter bug: arrayLit of non-array type");
410
+ const elem = e.type.elem;
411
+ const arr = B.tmp();
412
+ B.line(`${arr} = ${arrNewCall(host, elem, String(e.elems.length))}`);
413
+ const out = host.own({ name: arr, type: e.type });
414
+ const acc = elemAccess(elem);
415
+ const spreadSet = new Set(e.spreads ?? []);
416
+ e.elems.forEach((el, i) => {
417
+ const v = host.emitExpr(el);
418
+ if (spreadSet.has(i)) {
419
+ host.emitArrayCopyLoop(arr, v.name, acc);
420
+ return;
421
+ }
422
+ if (acc === "ref")
423
+ host.moveTemp(v);
424
+ host.arrPush(arr, acc, v.name);
425
+ });
426
+ return out;
427
+ }
428
+ case "arrayNewLen": {
429
+ // Mapper-less Array.from({ length: n }): a length-n array of
430
+ // ABSENT slots — the interned undefined arm for unions carrying
431
+ // one (immortal: pushing owes no retain), NULL for every other ref
432
+ // element kind. The `i <= n - 1` bound is ToLength for the lengths
433
+ // that terminate: fractions truncate, negative/NaN → empty.
434
+ if (e.type.kind !== "array")
435
+ throw new InternalCompilerError("llvm emitter bug: arrayNewLen of non-array type");
436
+ const elem = e.type.elem;
437
+ const n = host.emitExpr(e.length);
438
+ const arr = B.tmp();
439
+ B.line(`${arr} = ${arrNewCall(host, elem, "0")}`);
440
+ const out = host.own({ name: arr, type: e.type });
441
+ const acc = elemAccess(elem);
442
+ let fill = acc === "f64" ? f64Lit(0) : acc === "bool" ? "false" : "null";
443
+ if (elem.kind === "union") {
444
+ const tag = undefinedArmTag(elem, host.unionsById);
445
+ if (tag >= 0)
446
+ fill = host.unitInstanceRef(elem.unionId, tag);
447
+ }
448
+ const bound = B.tmp();
449
+ B.line(`${bound} = fsub double ${n.name}, ${f64Lit(1)}`);
450
+ B.countedLoop(bound, () => host.arrPush(arr, acc, fill), "ole");
451
+ return out;
452
+ }
453
+ case "arrayGet": {
454
+ const arr = host.emitExpr(e.arr);
455
+ const idx = host.emitExpr(e.index);
456
+ if (e.arr.type.kind !== "array")
457
+ throw new InternalCompilerError("llvm emitter bug: arrayGet on non-array");
458
+ // Ref-element reads return +1 (the runtime retains); own registers
459
+ // the owned temp in the frame like any other.
460
+ const acc = elemAccess(e.arr.type.elem);
461
+ const accTy = acc === "f64" ? "double" : acc === "bool" ? "i1" : "ptr";
462
+ host.declare(`declare ${acc === "bool" ? "zeroext i1" : accTy} @scr_arr_get_${acc}(ptr, double)`);
463
+ const t = B.tmp();
464
+ B.line(`${t} = call ${accTy} @scr_arr_get_${acc}(ptr ${arr.name}, double ${idx.name})`);
465
+ return host.own({ name: t, type: e.type });
466
+ }
467
+ case "arrayHas": {
468
+ const arr = host.emitExpr(e.arr);
469
+ const idx = host.emitExpr(e.index);
470
+ if (e.arr.type.kind !== "array")
471
+ throw new InternalCompilerError("llvm emitter bug: arrayHas on non-array");
472
+ host.declare(`declare zeroext i1 @scr_arr_has(ptr, double)`);
473
+ const t = B.tmp();
474
+ B.line(`${t} = call zeroext i1 @scr_arr_has(ptr ${arr.name}, double ${idx.name})`);
475
+ return { name: t, type: e.type };
476
+ }
477
+ case "arrayState": {
478
+ const arr = host.emitExpr(e.arr);
479
+ const idx = host.emitExpr(e.index);
480
+ if (e.arr.type.kind !== "array")
481
+ throw new InternalCompilerError("llvm emitter bug: arrayState on non-array");
482
+ host.declare(`declare double @scr_arr_state(ptr, double)`);
483
+ const t = B.tmp();
484
+ B.line(`${t} = call double @scr_arr_state(ptr ${arr.name}, double ${idx.name})`);
485
+ return { name: t, type: e.type };
486
+ }
487
+ case "arrIntrinsic":
488
+ return host.emitArrIntrinsic(e);
489
+ case "bytesNew": {
490
+ // Typed-array/Buffer construction; the SOURCE's static type picks
491
+ // the runtime entry. The source is borrowed; every form hands
492
+ // back +1. Only the f64 (length) form can throw (Node's "Invalid
493
+ // typed array length" RangeError) — pending check after the temp
494
+ // joins its frame.
495
+ if (e.type.kind !== "bytes")
496
+ throw new InternalCompilerError("llvm emitter bug: bytesNew of non-bytes type");
497
+ const kind = BYTES_ELEM_NUM[e.type.elem];
498
+ if (!e.source) {
499
+ host.declare(`declare ptr @scr_bytes_new(i32, double)`);
500
+ const t = B.tmp();
501
+ B.line(`${t} = call ptr @scr_bytes_new(i32 ${kind}, double ${f64Lit(0)})`);
502
+ return host.own({ name: t, type: e.type });
503
+ }
504
+ const src = host.emitExpr(e.source);
505
+ const t = B.tmp();
506
+ if (e.source.type.kind === "f64") {
507
+ host.declare(`declare ptr @scr_bytes_new(i32, double)`);
508
+ B.line(`${t} = call ptr @scr_bytes_new(i32 ${kind}, double ${src.name})`);
509
+ const out = host.own({ name: t, type: e.type });
510
+ host.emitPendingCheck();
511
+ return out;
512
+ }
513
+ if (e.source.type.kind === "bytes") {
514
+ host.declare(`declare ptr @scr_bytes_copy(ptr)`);
515
+ B.line(`${t} = call ptr @scr_bytes_copy(ptr ${src.name})`);
516
+ return host.own({ name: t, type: e.type });
517
+ }
518
+ if (e.source.type.kind === "array") {
519
+ host.declare(`declare ptr @scr_bytes_from_arr(i32, ptr)`);
520
+ B.line(`${t} = call ptr @scr_bytes_from_arr(i32 ${kind}, ptr ${src.name})`);
521
+ return host.own({ name: t, type: e.type });
522
+ }
523
+ throw new InternalCompilerError(`llvm emitter bug: bytesNew source of kind ${e.source.type.kind}`);
524
+ }
525
+ case "bytesIntrinsic":
526
+ return host.emitBytesIntrinsic(e);
527
+ case "mapNew":
528
+ return host.emitMapNew(e);
529
+ case "mapIntrinsic":
530
+ case "setIntrinsic":
531
+ return host.emitMapLikeIntrinsic(e);
532
+ case "setNew":
533
+ return host.emitSetNew(e);
534
+ default: {
535
+ const _exhaustive = e;
536
+ void _exhaustive;
537
+ throw new InternalCompilerError("unreachable");
538
+ }
539
+ }
540
+ }
541
+ export function emitRecordExpr(host, e) {
542
+ const B = host.B;
543
+ switch (e.kind) {
544
+ case "fieldGet": {
545
+ const obj = host.emitExpr(e.obj);
546
+ const { ptr, type } = host.classFieldPtr(obj.name, e.className, e.field);
547
+ const v = host.loadField(ptr, type);
548
+ if (isRefCounted(e.type))
549
+ return host.own({ name: host.retainValue(v, e.type), type: e.type });
550
+ return { name: v, type: e.type };
551
+ }
552
+ case "recordGet": {
553
+ const obj = host.emitExpr(e.obj);
554
+ const { ptr, type } = host.recordFieldPtr(obj.name, e.shapeId, e.field);
555
+ const v = host.loadField(ptr, type);
556
+ if (isRefCounted(e.type))
557
+ return host.own({ name: host.retainValue(v, e.type), type: e.type });
558
+ return { name: v, type: e.type };
559
+ }
560
+ case "recordLit": {
561
+ // Allocate (fields zeroed), then write each field IN SOURCE ORDER —
562
+ // JS evaluates property values in source order. Ownership of
563
+ // refcounted values moves in; the struct is fresh, so there is
564
+ // never an old value to release. OVERFLOW entries insert into the
565
+ // shape's overflow map in the same interleaved order.
566
+ if (e.type.kind !== "record")
567
+ throw new InternalCompilerError("llvm emitter bug: recordLit of non-record type");
568
+ const shapeId = e.type.shapeId;
569
+ const rec = B.tmp();
570
+ B.line(`${rec} = call ptr @${mangleRecordNew(shapeId)}()`);
571
+ const out = host.own({ name: rec, type: e.type });
572
+ for (const f of e.fields) {
573
+ if (f.drop) {
574
+ // A mapping-dropped field: the initializer runs in its source-
575
+ // order slot — effects included — and the result (if any)
576
+ // releases with the statement frame instead of storing.
577
+ host.emitExpr(f.value);
578
+ continue;
579
+ }
580
+ const v = host.emitExpr(f.value);
581
+ if (f.overflow) {
582
+ const lit = host.internLiteral(f.name);
583
+ const acc = v.type.kind === "f64" ? "f64" : v.type.kind === "bool" ? "bool" : "ref";
584
+ if (acc === "ref")
585
+ host.moveTemp(v);
586
+ const ovf = host.recordOvfPtr(rec, shapeId);
587
+ const argTy = acc === "f64" ? "double" : acc === "bool" ? "i1 zeroext" : "ptr";
588
+ host.declare(`declare void @scr_map_set_str_${acc}(ptr, ptr, ${argTy})`);
589
+ B.line(`call void @scr_map_set_str_${acc}(ptr ${ovf}, ptr ${lit}, ${argTy === "i1 zeroext" ? "i1" : argTy} ${v.name})`);
590
+ continue;
591
+ }
592
+ if (isRefCounted(v.type))
593
+ host.moveTemp(v);
594
+ const { ptr, type } = host.recordFieldPtr(rec, shapeId, f.name);
595
+ host.storeField(ptr, type, v.name);
596
+ }
597
+ return out;
598
+ }
599
+ case "recordClone": {
600
+ if (e.type.kind !== "record")
601
+ throw new InternalCompilerError("llvm emitter bug: recordClone of non-record type");
602
+ host.recordCloneShapes.add(e.type.shapeId);
603
+ const source = host.emitExpr(e.source);
604
+ const rec = B.tmp();
605
+ B.line(`${rec} = call ptr @${mangleRecordClone(e.type.shapeId)}(ptr ${source.name})`);
606
+ const out = host.own({ name: rec, type: e.type });
607
+ for (const f of e.overrides) {
608
+ const v = host.emitExpr(f.value);
609
+ const { ptr, type } = host.recordFieldPtr(rec, e.type.shapeId, f.name);
610
+ if (isRefCounted(type)) {
611
+ host.moveTemp(v);
612
+ const old = B.tmp();
613
+ B.line(`${old} = load ptr, ptr ${ptr}`);
614
+ host.storeField(ptr, type, v.name);
615
+ host.releaseValue(old, type);
616
+ }
617
+ else {
618
+ host.storeField(ptr, type, v.name);
619
+ }
620
+ }
621
+ return out;
622
+ }
623
+ case "recordKeyGet":
624
+ return host.emitRecordKeyGet(e);
625
+ case "recordOvfKeys": {
626
+ // The overflow map's live keys in JS own-key order — a fresh
627
+ // string[] snapshot (+1); the record is borrowed.
628
+ const obj = host.emitExpr(e.obj);
629
+ const ovf = host.recordOvfPtr(obj.name, e.shapeId);
630
+ host.declare(`declare ptr @scr_map_keys_js_order(ptr)`);
631
+ const t = B.tmp();
632
+ B.line(`${t} = call ptr @scr_map_keys_js_order(ptr ${ovf})`);
633
+ return host.own({ name: t, type: e.type });
634
+ }
635
+ default: {
636
+ const _exhaustive = e;
637
+ void _exhaustive;
638
+ throw new InternalCompilerError("unreachable");
639
+ }
640
+ }
641
+ }
642
+ //# sourceMappingURL=expr-primitives.js.map