eliscript 0.0.1 → 0.0.3

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 (417) hide show
  1. package/README.md +61 -0
  2. package/bootstrap/README.md +26 -0
  3. package/bootstrap/backends/README.md +515 -0
  4. package/bootstrap/backends/async.eli +230 -0
  5. package/bootstrap/backends/binary.eli +173 -0
  6. package/bootstrap/backends/capabilities.eli +74 -0
  7. package/bootstrap/backends/elf.eli +246 -0
  8. package/bootstrap/backends/managed.eli +5976 -0
  9. package/bootstrap/backends/memory.eli +100 -0
  10. package/bootstrap/backends/native.eli +2000 -0
  11. package/bootstrap/backends/numeric.eli +1362 -0
  12. package/bootstrap/backends/optimize.eli +79 -0
  13. package/bootstrap/backends/regexp.eli +2263 -0
  14. package/bootstrap/backends/sha256.eli +138 -0
  15. package/bootstrap/backends/wasm.eli +1161 -0
  16. package/bootstrap/compiler/analyzer.eli +165 -77
  17. package/bootstrap/compiler/compiler.eli +43 -19
  18. package/bootstrap/compiler/emitter.eli +780 -170
  19. package/bootstrap/compiler/expander.eli +136 -45
  20. package/bootstrap/compiler/formatter.eli +8 -1
  21. package/bootstrap/compiler/ir.eli +148 -45
  22. package/bootstrap/compiler/lower.eli +29 -2
  23. package/bootstrap/compiler/project.eli +51 -21
  24. package/bootstrap/compiler/reader.eli +128 -36
  25. package/bootstrap/compiler/source-map.eli +46 -4
  26. package/bootstrap/compiler/symbol.eli +2 -1
  27. package/bootstrap/compiler/syntax.eli +47 -12
  28. package/bootstrap/compiler/transient-analysis.eli +40 -4
  29. package/bootstrap/host/check-cli-legacy.mjs +163 -0
  30. package/bootstrap/host/check-cli.mjs +59 -158
  31. package/bootstrap/host/check-cli.mjs.map +1 -0
  32. package/bootstrap/host/compiler-session.eli +1579 -0
  33. package/bootstrap/host/compiler-tools.eli +513 -0
  34. package/bootstrap/host/eliscript-cli.mjs +53 -33
  35. package/bootstrap/host/eliscript-cli.mjs.map +1 -0
  36. package/bootstrap/host/project-cli-legacy.mjs +295 -0
  37. package/bootstrap/host/project-cli.mjs +74 -289
  38. package/bootstrap/host/project-cli.mjs.map +1 -0
  39. package/bootstrap/host/project-legacy.mjs +1080 -0
  40. package/bootstrap/host/project.mjs +210 -1060
  41. package/bootstrap/host/project.mjs.map +1 -0
  42. package/bootstrap/runtime/UNICODE-LICENSE.txt +39 -0
  43. package/bootstrap/runtime/memory.eli +30379 -0
  44. package/browser/host.mjs +732 -11
  45. package/browser/worker.mjs +6 -3
  46. package/compiler/eliscript-analyzer.el +371 -4
  47. package/compiler/eliscript-cli.el +84 -1
  48. package/compiler/eliscript-emitter.el +1189 -256
  49. package/compiler/eliscript-expander.el +147 -10
  50. package/compiler/eliscript-ir-emitter.el +725 -208
  51. package/compiler/eliscript-lower.el +127 -1
  52. package/compiler/eliscript-portable.el +177 -51
  53. package/compiler/eliscript-project.el +20 -2
  54. package/compiler/eliscript-reader.el +141 -57
  55. package/compiler/eliscript-source-map.el +26 -12
  56. package/compiler/eliscript-transient-analysis.el +382 -19
  57. package/dist/backends/async.mjs +561 -0
  58. package/dist/backends/async.mjs.macro-origins.json +1 -0
  59. package/dist/backends/async.mjs.map +1 -0
  60. package/dist/backends/binary.mjs +381 -0
  61. package/dist/backends/binary.mjs.macro-origins.json +1 -0
  62. package/dist/backends/binary.mjs.map +1 -0
  63. package/dist/backends/capabilities.mjs +237 -0
  64. package/dist/backends/capabilities.mjs.macro-origins.json +1 -0
  65. package/dist/backends/capabilities.mjs.map +1 -0
  66. package/dist/backends/elf.mjs +540 -0
  67. package/dist/backends/elf.mjs.macro-origins.json +1 -0
  68. package/dist/backends/elf.mjs.map +1 -0
  69. package/dist/backends/managed.mjs +10616 -0
  70. package/dist/backends/managed.mjs.macro-origins.json +1 -0
  71. package/dist/backends/managed.mjs.map +1 -0
  72. package/dist/backends/memory.mjs +278 -0
  73. package/dist/backends/memory.mjs.macro-origins.json +1 -0
  74. package/dist/backends/memory.mjs.map +1 -0
  75. package/dist/backends/native.mjs +4099 -0
  76. package/dist/backends/native.mjs.macro-origins.json +1 -0
  77. package/dist/backends/native.mjs.map +1 -0
  78. package/dist/backends/numeric.mjs +2458 -0
  79. package/dist/backends/numeric.mjs.macro-origins.json +1 -0
  80. package/dist/backends/numeric.mjs.map +1 -0
  81. package/dist/backends/optimize.mjs +204 -0
  82. package/dist/backends/optimize.mjs.macro-origins.json +1 -0
  83. package/dist/backends/optimize.mjs.map +1 -0
  84. package/dist/backends/regexp.mjs +2033 -0
  85. package/dist/backends/regexp.mjs.macro-origins.json +1 -0
  86. package/dist/backends/regexp.mjs.map +1 -0
  87. package/dist/backends/sha256.mjs +310 -0
  88. package/dist/backends/sha256.mjs.macro-origins.json +1 -0
  89. package/dist/backends/sha256.mjs.map +1 -0
  90. package/dist/backends/wasm.mjs +2258 -0
  91. package/dist/backends/wasm.mjs.macro-origins.json +1 -0
  92. package/dist/backends/wasm.mjs.map +1 -0
  93. package/dist/bootstrap/analyzer.mjs +1908 -776
  94. package/dist/bootstrap/analyzer.mjs.macro-origins.json +1 -0
  95. package/dist/bootstrap/analyzer.mjs.map +1 -1
  96. package/dist/bootstrap/compiler.mjs +450 -142
  97. package/dist/bootstrap/compiler.mjs.macro-origins.json +1 -0
  98. package/dist/bootstrap/compiler.mjs.map +1 -1
  99. package/dist/bootstrap/emitter.mjs +3083 -909
  100. package/dist/bootstrap/emitter.mjs.macro-origins.json +1 -0
  101. package/dist/bootstrap/emitter.mjs.map +1 -1
  102. package/dist/bootstrap/expander.mjs +2887 -1233
  103. package/dist/bootstrap/expander.mjs.macro-origins.json +1 -0
  104. package/dist/bootstrap/expander.mjs.map +1 -1
  105. package/dist/bootstrap/formatter.mjs +582 -218
  106. package/dist/bootstrap/formatter.mjs.macro-origins.json +1 -0
  107. package/dist/bootstrap/formatter.mjs.map +1 -1
  108. package/dist/bootstrap/ir.mjs +670 -116
  109. package/dist/bootstrap/ir.mjs.macro-origins.json +1 -0
  110. package/dist/bootstrap/ir.mjs.map +1 -1
  111. package/dist/bootstrap/lower.mjs +866 -257
  112. package/dist/bootstrap/lower.mjs.macro-origins.json +1 -0
  113. package/dist/bootstrap/lower.mjs.map +1 -1
  114. package/dist/bootstrap/package.json +1 -0
  115. package/dist/bootstrap/project.mjs +1168 -498
  116. package/dist/bootstrap/project.mjs.macro-origins.json +1 -0
  117. package/dist/bootstrap/project.mjs.map +1 -1
  118. package/dist/bootstrap/reader.mjs +674 -175
  119. package/dist/bootstrap/reader.mjs.macro-origins.json +1 -0
  120. package/dist/bootstrap/reader.mjs.map +1 -1
  121. package/dist/bootstrap/runtime/math.mjs +1117 -0
  122. package/dist/bootstrap/runtime/math.mjs.map +1 -0
  123. package/dist/bootstrap/runtime/unicode-case-data.mjs +10125 -0
  124. package/dist/bootstrap/runtime/unicode-case-data.mjs.map +1 -0
  125. package/dist/bootstrap/runtime/unicode-case.mjs +281 -0
  126. package/dist/bootstrap/runtime/unicode-case.mjs.map +1 -0
  127. package/dist/bootstrap/source-map.mjs +430 -119
  128. package/dist/bootstrap/source-map.mjs.macro-origins.json +1 -0
  129. package/dist/bootstrap/source-map.mjs.map +1 -1
  130. package/dist/bootstrap/symbol.mjs +229 -53
  131. package/dist/bootstrap/symbol.mjs.macro-origins.json +1 -0
  132. package/dist/bootstrap/symbol.mjs.map +1 -1
  133. package/dist/bootstrap/syntax.mjs +205 -7
  134. package/dist/bootstrap/syntax.mjs.macro-origins.json +1 -0
  135. package/dist/bootstrap/syntax.mjs.map +1 -1
  136. package/dist/bootstrap/transient-analysis.mjs +1185 -489
  137. package/dist/bootstrap/transient-analysis.mjs.macro-origins.json +1 -0
  138. package/dist/bootstrap/transient-analysis.mjs.map +1 -1
  139. package/dist/browser/compiler.js +199 -6478
  140. package/dist/browser/host.mjs +1078 -0
  141. package/dist/browser/loader.js +1 -0
  142. package/dist/browser/loader.mjs +231 -0
  143. package/dist/browser/worker.mjs +63 -0
  144. package/dist/compiler-artifact.json +1 -0
  145. package/dist/host/compiler-session.mjs +2980 -0
  146. package/dist/host/compiler-session.mjs.macro-origins.json +1 -0
  147. package/dist/host/compiler-session.mjs.map +1 -0
  148. package/dist/host/compiler-tools.mjs +1084 -0
  149. package/dist/host/compiler-tools.mjs.macro-origins.json +1 -0
  150. package/dist/host/compiler-tools.mjs.map +1 -0
  151. package/dist/literal-sources/runtime/core/collection-internals.eli +60 -0
  152. package/dist/literal-sources/runtime/core/collection.eli +639 -0
  153. package/dist/literal-sources/runtime/core/data-text.eli +290 -0
  154. package/dist/literal-sources/runtime/core/data.eli +22 -0
  155. package/dist/literal-sources/runtime/core/identifier.eli +44 -0
  156. package/dist/literal-sources/runtime/core/lazy-sequence.eli +131 -0
  157. package/dist/literal-sources/runtime/core/list.eli +19 -0
  158. package/dist/literal-sources/runtime/core/map.eli +9 -0
  159. package/dist/literal-sources/runtime/core/metadata-internals.eli +6 -0
  160. package/dist/literal-sources/runtime/core/metadata.eli +40 -0
  161. package/dist/literal-sources/runtime/core/object.eli +8 -0
  162. package/dist/literal-sources/runtime/core/order.eli +123 -0
  163. package/dist/literal-sources/runtime/core/persistent-kind.eli +28 -0
  164. package/dist/literal-sources/runtime/core/protocol-error.eli +32 -0
  165. package/dist/literal-sources/runtime/core/protocol.eli +28 -0
  166. package/dist/literal-sources/runtime/core/queue.eli +9 -0
  167. package/dist/literal-sources/runtime/core/record.eli +191 -0
  168. package/dist/literal-sources/runtime/core/regex.eli +158 -0
  169. package/dist/literal-sources/runtime/core/sequence.eli +305 -0
  170. package/dist/literal-sources/runtime/core/set-algebra.eli +28 -0
  171. package/dist/literal-sources/runtime/core/set.eli +9 -0
  172. package/dist/literal-sources/runtime/core/sorted.eli +408 -0
  173. package/dist/literal-sources/runtime/core/text.eli +14 -0
  174. package/dist/literal-sources/runtime/core/transducer.eli +268 -0
  175. package/dist/literal-sources/runtime/core/transient.eli +17 -0
  176. package/dist/literal-sources/runtime/core/truth.eli +4 -0
  177. package/dist/literal-sources/runtime/core/type.eli +232 -0
  178. package/dist/literal-sources/runtime/core/value-internals.eli +13 -0
  179. package/dist/literal-sources/runtime/core/value.eli +19 -0
  180. package/dist/literal-sources/runtime/core/vector.eli +25 -0
  181. package/dist/literal-sources/runtime/literals.eli +23 -0
  182. package/dist/literal-sources/runtime/testing/value.eli +6 -0
  183. package/dist/literal-sources/runtime/wire/http-rpc.eli +362 -0
  184. package/dist/literal-sources/runtime/wire/markdown.eli +275 -0
  185. package/dist/literal-sources/runtime/wire/schema.eli +193 -0
  186. package/dist/literal-sources/stdlib/bit.eli +36 -0
  187. package/dist/literal-sources/stdlib/core/data.eli +306 -0
  188. package/dist/literal-sources/stdlib/core/object.eli +89 -0
  189. package/dist/literal-sources/stdlib/core/protocol.eli +451 -0
  190. package/dist/literal-sources/stdlib/core/set.eli +312 -0
  191. package/dist/literal-sources/stdlib/core/text.eli +103 -0
  192. package/dist/literal-sources/stdlib/managed-literal-protocols.eli +494 -0
  193. package/dist/literal-sources/stdlib/managed-literals.eli +1469 -0
  194. package/dist/literal-sources/stdlib/managed-queue-state.eli +65 -0
  195. package/dist/literal-sources/stdlib/managed-sorted-state.eli +233 -0
  196. package/dist/literal-sources/stdlib/managed-transient-state.eli +348 -0
  197. package/dist/literal-sources/stdlib/managed-value-state.eli +153 -0
  198. package/dist/literal-sources/stdlib/managed-vector-view-state.eli +102 -0
  199. package/dist/literal-sources/stdlib/persistent-list.eli +145 -0
  200. package/dist/literal-sources/stdlib/persistent-map.eli +724 -0
  201. package/dist/literal-sources/stdlib/persistent-set.eli +236 -0
  202. package/dist/literal-sources/stdlib/persistent-vector.eli +359 -0
  203. package/dist/literal-sources/stdlib/value.eli +325 -0
  204. package/dist/package.json +10 -0
  205. package/dist/runtime/math.mjs +1116 -0
  206. package/dist/runtime/math.mjs.macro-origins.json +1 -0
  207. package/dist/runtime/math.mjs.map +1 -0
  208. package/dist/runtime/unicode-case-data.mjs +10124 -0
  209. package/dist/runtime/unicode-case-data.mjs.macro-origins.json +1 -0
  210. package/dist/runtime/unicode-case-data.mjs.map +1 -0
  211. package/dist/runtime/unicode-case.mjs +280 -0
  212. package/dist/runtime/unicode-case.mjs.macro-origins.json +1 -0
  213. package/dist/runtime/unicode-case.mjs.map +1 -0
  214. package/dist/runtime.eli +30379 -0
  215. package/dist/stage3-release.json +1 -0
  216. package/editor/README.md +1 -1
  217. package/editor/eliscript-mode.el +1 -1
  218. package/editor/eliscript-repl.el +1 -1
  219. package/package.json +106 -11
  220. package/platform/http.mjs +20 -0
  221. package/runtime/array-text.mjs +159 -0
  222. package/runtime/core/map-internals.mjs +27 -9
  223. package/runtime/core/object-impl.mjs +26 -17
  224. package/runtime/core/object-impl.mjs.map +1 -1
  225. package/runtime/core/protocol-impl.mjs +682 -255
  226. package/runtime/core/protocol-impl.mjs.map +1 -1
  227. package/runtime/core/protocol.mjs +4 -0
  228. package/runtime/core/record.mjs +23 -2
  229. package/runtime/core/regex.mjs +4 -0
  230. package/runtime/core/sorted.mjs +53 -0
  231. package/runtime/core/text-impl.mjs +167 -48
  232. package/runtime/core/text-impl.mjs.map +1 -1
  233. package/runtime/core/type.mjs +75 -3
  234. package/runtime/core/vector.mjs +6 -0
  235. package/runtime/math.eli +429 -0
  236. package/runtime/math.mjs +1116 -0
  237. package/runtime/math.mjs.map +1 -0
  238. package/runtime/number-radix.mjs +105 -0
  239. package/runtime/unicode-case-data.eli +29 -0
  240. package/runtime/unicode-case-data.mjs +10124 -0
  241. package/runtime/unicode-case-data.mjs.map +1 -0
  242. package/runtime/unicode-case.eli +100 -0
  243. package/runtime/unicode-case.mjs +280 -0
  244. package/runtime/unicode-case.mjs.map +1 -0
  245. package/runtime/wire/http-rpc.mjs +168 -0
  246. package/runtime/wire/markdown.mjs +196 -0
  247. package/runtime/wire/schema.mjs +109 -0
  248. package/stdlib/README.md +54 -0
  249. package/stdlib/core/protocol.eli +81 -17
  250. package/stdlib/core/seq.eli +1 -1
  251. package/stdlib/core/zipper.eli +172 -72
  252. package/stdlib/gepo.eli +12 -0
  253. package/stdlib/interop/js.eli +56 -15
  254. package/stdlib/managed-literal-protocols.eli +494 -0
  255. package/stdlib/managed-literals.eli +1469 -0
  256. package/stdlib/managed-protocol-error.eli +32 -0
  257. package/stdlib/managed-queue-state.eli +65 -0
  258. package/stdlib/managed-runtime-collection-internals.eli +60 -0
  259. package/stdlib/managed-runtime-collection.eli +639 -0
  260. package/stdlib/managed-runtime-data-text.eli +290 -0
  261. package/stdlib/managed-runtime-data.eli +22 -0
  262. package/stdlib/managed-runtime-identifier.eli +44 -0
  263. package/stdlib/managed-runtime-lazy-sequence.eli +131 -0
  264. package/stdlib/managed-runtime-list.eli +19 -0
  265. package/stdlib/managed-runtime-literals.eli +23 -0
  266. package/stdlib/managed-runtime-map.eli +9 -0
  267. package/stdlib/managed-runtime-metadata-internals.eli +6 -0
  268. package/stdlib/managed-runtime-metadata.eli +40 -0
  269. package/stdlib/managed-runtime-object.eli +8 -0
  270. package/stdlib/managed-runtime-order.eli +123 -0
  271. package/stdlib/managed-runtime-persistent-kind.eli +28 -0
  272. package/stdlib/managed-runtime-protocol.eli +28 -0
  273. package/stdlib/managed-runtime-queue.eli +9 -0
  274. package/stdlib/managed-runtime-record.eli +191 -0
  275. package/stdlib/managed-runtime-regex.eli +158 -0
  276. package/stdlib/managed-runtime-sequence.eli +305 -0
  277. package/stdlib/managed-runtime-set-algebra.eli +28 -0
  278. package/stdlib/managed-runtime-set.eli +9 -0
  279. package/stdlib/managed-runtime-sorted.eli +408 -0
  280. package/stdlib/managed-runtime-text.eli +14 -0
  281. package/stdlib/managed-runtime-transducer.eli +268 -0
  282. package/stdlib/managed-runtime-transient.eli +17 -0
  283. package/stdlib/managed-runtime-truth.eli +4 -0
  284. package/stdlib/managed-runtime-type.eli +232 -0
  285. package/stdlib/managed-runtime-value-internals.eli +13 -0
  286. package/stdlib/managed-runtime-value.eli +19 -0
  287. package/stdlib/managed-runtime-vector.eli +25 -0
  288. package/stdlib/managed-sorted-state.eli +233 -0
  289. package/stdlib/managed-testing-value.eli +6 -0
  290. package/stdlib/managed-transient-state.eli +348 -0
  291. package/stdlib/managed-value-state.eli +153 -0
  292. package/stdlib/managed-vector-view-state.eli +102 -0
  293. package/stdlib/managed-wire-http-rpc.eli +362 -0
  294. package/stdlib/managed-wire-markdown.eli +275 -0
  295. package/stdlib/managed-wire-schema.eli +193 -0
  296. package/stdlib/mdp.eli +7 -0
  297. package/stdlib/mds.eli +4 -0
  298. package/stdlib/persistent-vector.eli +23 -6
  299. package/tools/acceptance/check-legacy.mjs +687 -0
  300. package/tools/acceptance/check.eli +431 -0
  301. package/tools/acceptance/compile-evidence.el +49 -0
  302. package/tools/acceptance/finalize-legacy.mjs +498 -0
  303. package/tools/acceptance/finalize.eli +270 -0
  304. package/tools/backends/benchmark.mjs +175 -0
  305. package/tools/backends/build.mjs +135 -0
  306. package/tools/backends/compile.mjs +94 -0
  307. package/tools/backends/compiler-bootstrap.mjs +1001 -0
  308. package/tools/backends/compiler-browser.mjs +361 -0
  309. package/tools/backends/compiler-build.mjs +1628 -0
  310. package/tools/backends/compiler-cli-legacy.mjs +334 -0
  311. package/tools/backends/compiler-cli.mjs +29 -0
  312. package/tools/backends/compiler-corpus-bit.mjs +234 -0
  313. package/tools/backends/compiler-corpus-cli-adapters-legacy.mjs +362 -0
  314. package/tools/backends/compiler-corpus-cli-adapters.mjs +247 -0
  315. package/tools/backends/compiler-corpus-debugging.mjs +221 -0
  316. package/tools/backends/compiler-corpus-emitter.mjs +324 -0
  317. package/tools/backends/compiler-corpus-evaluation-adapters.mjs +65 -0
  318. package/tools/backends/compiler-corpus-execution-legacy.mjs +769 -0
  319. package/tools/backends/compiler-corpus-execution.mjs +3324 -0
  320. package/tools/backends/compiler-corpus-fuzz.mjs +229 -0
  321. package/tools/backends/compiler-corpus-generations.mjs +208 -0
  322. package/tools/backends/compiler-corpus-host-context-legacy.mjs +114 -0
  323. package/tools/backends/compiler-corpus-host-context.mjs +550 -0
  324. package/tools/backends/compiler-corpus-identity-host.mjs +553 -0
  325. package/tools/backends/compiler-corpus-identity-value-adapters-legacy.mjs +298 -0
  326. package/tools/backends/compiler-corpus-identity-value-adapters.mjs +69 -0
  327. package/tools/backends/compiler-corpus-isolated-exports.mjs +21 -0
  328. package/tools/backends/compiler-corpus-legacy.mjs +1155 -0
  329. package/tools/backends/compiler-corpus-literal-provider.mjs +282 -0
  330. package/tools/backends/compiler-corpus-managed-adapters-legacy.mjs +334 -0
  331. package/tools/backends/compiler-corpus-managed-adapters.mjs +937 -0
  332. package/tools/backends/compiler-corpus-managed-cases.mjs +179 -0
  333. package/tools/backends/compiler-corpus-managed-fixtures-legacy.mjs +879 -0
  334. package/tools/backends/compiler-corpus-managed-fixtures.mjs +1287 -0
  335. package/tools/backends/compiler-corpus-matchers.mjs +173 -0
  336. package/tools/backends/compiler-corpus-original-program.mjs +612 -0
  337. package/tools/backends/compiler-corpus-process.mjs +765 -0
  338. package/tools/backends/compiler-corpus-program-driver.mjs +306 -0
  339. package/tools/backends/compiler-corpus-project-adapters-legacy.mjs +497 -0
  340. package/tools/backends/compiler-corpus-project-adapters.mjs +340 -0
  341. package/tools/backends/compiler-corpus-project-entry-host.mjs +511 -0
  342. package/tools/backends/compiler-corpus-project-transport.mjs +151 -0
  343. package/tools/backends/compiler-corpus-raw-fixture-observer.mjs +1438 -0
  344. package/tools/backends/compiler-corpus-raw-language-fixtures.mjs +1456 -0
  345. package/tools/backends/compiler-corpus-raw-math-fixture.mjs +346 -0
  346. package/tools/backends/compiler-corpus-raw-special-fixtures.mjs +523 -0
  347. package/tools/backends/compiler-corpus-reference-legacy.mjs +263 -0
  348. package/tools/backends/compiler-corpus-reference.mjs +241 -0
  349. package/tools/backends/compiler-corpus-runtime-adapters-legacy.mjs +843 -0
  350. package/tools/backends/compiler-corpus-runtime-adapters.mjs +663 -0
  351. package/tools/backends/compiler-corpus-source-archive.mjs +206 -0
  352. package/tools/backends/compiler-corpus-tools-artifact-adapters.mjs +410 -0
  353. package/tools/backends/compiler-corpus-tools-cli.mjs +363 -0
  354. package/tools/backends/compiler-corpus-tools-reference.mjs +264 -0
  355. package/tools/backends/compiler-corpus.mjs +2054 -0
  356. package/tools/backends/compiler-debug.mjs +142 -0
  357. package/tools/backends/compiler-matrix.mjs +1955 -0
  358. package/tools/backends/compiler-metadata.mjs +203 -0
  359. package/tools/backends/compiler-package-browser.mjs +120 -0
  360. package/tools/backends/compiler-package-legacy.mjs +654 -0
  361. package/tools/backends/compiler-package.mjs +464 -0
  362. package/tools/backends/compiler-project.mjs +126 -0
  363. package/tools/backends/compiler-session.mjs +843 -0
  364. package/tools/backends/compiler-sha256.mjs +152 -0
  365. package/tools/backends/compiler-unicode-profile-host.mjs +196 -0
  366. package/tools/backends/compiler-worker.mjs +573 -0
  367. package/tools/backends/dist/bootstrap-js-stages.mjs +919 -0
  368. package/tools/backends/dist/bootstrap-js-stages.mjs.map +1 -0
  369. package/tools/backends/dist/managed-ir-inventory.mjs +488 -0
  370. package/tools/backends/dist/managed-ir-inventory.mjs.map +1 -0
  371. package/tools/backends/dist/record-grid.mjs +1256 -0
  372. package/tools/backends/dist/record-grid.mjs.map +1 -0
  373. package/tools/backends/dist/release-cli.mjs +462 -0
  374. package/tools/backends/dist/release-cli.mjs.map +1 -0
  375. package/tools/backends/dist/run-artifact.mjs +517 -0
  376. package/tools/backends/dist/run-artifact.mjs.map +1 -0
  377. package/tools/backends/eliscript/compiler-corpus-bit.eli +77 -0
  378. package/tools/backends/eliscript/compiler-corpus-debugging.eli +70 -0
  379. package/tools/backends/eliscript/compiler-corpus-project-entry-host.eli +256 -0
  380. package/tools/backends/managed-foreign-binding.mjs +497 -0
  381. package/tools/backends/managed-host-legacy.mjs +1181 -0
  382. package/tools/backends/managed-host-lifecycle.mjs +310 -0
  383. package/tools/backends/managed-host-object-provider.mjs +155 -0
  384. package/tools/backends/managed-host-object-realm.mjs +797 -0
  385. package/tools/backends/managed-host-proxy.mjs +71 -0
  386. package/tools/backends/managed-host-runtime.mjs +5868 -0
  387. package/tools/backends/managed-host.mjs +716 -0
  388. package/tools/backends/managed-module-graph-legacy.mjs +308 -0
  389. package/tools/backends/managed-module-graph.mjs +694 -0
  390. package/tools/backends/managed-runtime-host-legacy.mjs +195 -0
  391. package/tools/backends/managed-runtime.mjs +939 -0
  392. package/tools/backends/managed-source-view-legacy.mjs +332 -0
  393. package/tools/backends/managed-source-view.mjs +959 -0
  394. package/tools/backends/memory-runtime.mjs +100 -0
  395. package/tools/backends/native-benchmark.mjs +88 -0
  396. package/tools/backends/native-managed-runtime.mjs +677 -0
  397. package/tools/backends/native-memory.mjs +768 -0
  398. package/tools/backends/native-node-memory.mjs +142 -0
  399. package/tools/backends/native-node-runner.mjs +99 -0
  400. package/tools/backends/native-node-watchdog.mjs +19 -0
  401. package/tools/backends/native-node-worker.mjs +75 -0
  402. package/tools/backends/stage3-targets.mjs +493 -0
  403. package/tools/bootstrap-command.el +13 -0
  404. package/tools/bootstrap-runtime.el +101 -0
  405. package/tools/bootstrap-seed.el +55 -0
  406. package/tools/project/check-cli.eli +31 -0
  407. package/tools/project/project-cli.eli +42 -0
  408. package/tools/project/project.eli +122 -0
  409. package/tools/runtime/unicode-case-profiles.mjs +13 -0
  410. package/tools/runtime/unicode-case-runtime.el +57 -0
  411. package/tools/testing/source-debugging-corpus-host.eli +16 -0
  412. package/tools/testing/source-debugging.eli +139 -0
  413. package/tools/testing/stdlib-bit-corpus-host.eli +21 -0
  414. package/tools/testing/stdlib-bit-corpus-host.mjs +118 -0
  415. package/tools/testing/stdlib-bit.eli +104 -0
  416. package/tools/testing/stdlib-bit.mjs +255 -0
  417. package/bin/eliscript-bootstrap +0 -15
@@ -0,0 +1,206 @@
1
+ import {createHash} from 'node:crypto';
2
+ import {mkdir,lstat,open} from 'node:fs/promises';
3
+ import {writeSync} from 'node:fs';
4
+ import {resolve,dirname} from 'node:path';
5
+ import {encodeCompilerIR,forEachCompilerIRChunk,compilerSourceAssetEncoding} from './compiler-session.mjs';
6
+ import {createCompilerMetadataDecoder} from './compiler-metadata.mjs';
7
+ import {cloneCompilerCorpusData} from './compiler-corpus.mjs';
8
+
9
+ function utf16Identity(source) {
10
+ const hash=createHash('sha256');
11
+ // UTF16 hashes code units, so splitting a surrogate pair is lossless here.
12
+ for(let at=0;at<source.length;at+=32768)hash.update(source.slice(at,at+32768),'utf16le');
13
+ return {encoding:'utf16le',bytes:source.length*2,sha256:hash.digest('hex')};
14
+ }
15
+
16
+ function jsonChunks(value,consume) {forEachCompilerIRChunk(value,consume);consume('\n');}
17
+ function sourceChunks(source,encoding,consume) {
18
+ if(encoding==='json-utf16'){forEachCompilerIRChunk(source,consume);return;}
19
+ for(let start=0;start<source.length;) {
20
+ let end=Math.min(start+32768,source.length);
21
+ if(end<source.length&&source.charCodeAt(end-1)>=0xd800&&source.charCodeAt(end-1)<=0xdbff&&
22
+ source.charCodeAt(end)>=0xdc00&&source.charCodeAt(end)<=0xdfff)end--;
23
+ consume(source.slice(start,end));start=end;
24
+ }
25
+ }
26
+ function chunkIdentity(visit) {
27
+ const hash=createHash('sha256');let bytes=0;
28
+ visit(chunk=>{bytes+=Buffer.byteLength(chunk,'utf8');hash.update(chunk,'utf8');});
29
+ return {bytes,sha256:hash.digest('hex')};
30
+ }
31
+ function normalizeIR(value) {
32
+ const decoder=createCompilerMetadataDecoder();
33
+ forEachCompilerIRChunk(value,chunk=>decoder.write(chunk));return decoder.finish();
34
+ }
35
+ async function writeOwnedChunks(path,visit) {
36
+ // The caller already owns a complete snapshot and checked it before I/O.
37
+ // Never retain its full escaped text or buffers for other pending assets.
38
+ const file=await open(path,'wx');let failed=false;
39
+ try {
40
+ visit(chunk=>{
41
+ const bytes=Buffer.from(chunk,'utf8');let offset=0;
42
+ while(offset<bytes.length) {
43
+ const count=writeSync(file.fd,bytes,offset,bytes.length-offset);
44
+ if(!Number.isInteger(count)||count<1||count>bytes.length-offset)
45
+ throw new Error('original source archive write did not advance');
46
+ offset+=count;
47
+ }
48
+ });
49
+ } catch(error){failed=true;throw error;}
50
+ finally{try{await file.close();}catch(error){if(!failed)throw error;}}
51
+ }
52
+
53
+ function localFile(directory,path) {
54
+ if(typeof path!=='string'||!path||/[\\:\u0000]/.test(path)||
55
+ path.split('/').some(part=>!part||part==='.'||part==='..')) {
56
+ throw new TypeError('original source archive requires a relative asset path');
57
+ }
58
+ return resolve(directory,...path.split('/'));
59
+ }
60
+
61
+ async function readAsset(directory,path,encoding='json',identity,mismatch) {
62
+ const file=localFile(directory,path);
63
+ let parent=resolve(directory);
64
+ const root=await lstat(parent);
65
+ if(root.isSymbolicLink()||!root.isDirectory())throw new TypeError('original source archive directory must be a real directory');
66
+ for(const part of path.split('/')) {
67
+ parent=resolve(parent,part);
68
+ const info=await lstat(parent);
69
+ if(info.isSymbolicLink())throw new TypeError('original source archive traverses a filesystem alias');
70
+ if(parent===file ? !info.isFile() : !info.isDirectory())throw new TypeError('original source archive asset has the wrong file type');
71
+ }
72
+ const input=await open(file,'r'),buffer=new Uint8Array(65536),hash=createHash('sha256');
73
+ const decoder=new TextDecoder('utf-8',{fatal:true,ignoreBOM:true});
74
+ let parser=encoding==='json'||encoding==='json-utf16'?createCompilerMetadataDecoder():undefined;
75
+ let parts=encoding==='utf8'?[]:undefined,bytes=0,decodeError,decodeFailed=false,result,failed=false;
76
+ if(!['json','json-utf16','utf8'].includes(encoding)) {
77
+ decodeError=new TypeError('unsupported compiler source asset encoding');decodeFailed=true;
78
+ }
79
+ const accept=text=>{if(parser)parser.write(text);else parts.push(text);};
80
+ try {
81
+ for(;;) {
82
+ const {bytesRead}=await input.read(buffer,0,buffer.length,null);
83
+ if(!Number.isInteger(bytesRead)||bytesRead<0||bytesRead>buffer.length)
84
+ throw new Error('original source archive read returned an invalid byte count');
85
+ if(bytesRead===0)break;
86
+ const chunk=buffer.subarray(0,bytesRead);bytes+=bytesRead;hash.update(chunk);
87
+ if(!decodeFailed) {
88
+ try{accept(decoder.decode(chunk,{stream:true}));}
89
+ catch(error){decodeError=error;decodeFailed=true;parser=undefined;parts=undefined;}
90
+ }
91
+ }
92
+ if(!decodeFailed) {
93
+ try {
94
+ accept(decoder.decode());result=parser?parser.finish():parts.join('');
95
+ if(encoding==='json-utf16'&&typeof result!=='string')
96
+ throw new TypeError('encoded compiler source asset must contain a JSON string');
97
+ }catch(error){decodeError=error;decodeFailed=true;}
98
+ }
99
+ const sha256=hash.digest('hex');
100
+ // The original boundary checks complete file identity BEFORE decoding.
101
+ // Defer any streaming parse/UTF8 failure until that same check succeeds.
102
+ if(identity&&(bytes!==identity.bytes||sha256!==identity.sha256))throw new Error(mismatch);
103
+ if(decodeFailed)throw decodeError;
104
+ return result;
105
+ }catch(error){failed=true;throw error;}
106
+ finally{try{await input.close();}catch(error){if(!failed)throw error;}}
107
+ }
108
+
109
+ function sourceRecord(value,label) {
110
+ if(value===null||typeof value!=='object'||typeof value.source!=='string'||
111
+ typeof value.filename!=='string')throw new TypeError(label+' requires its exact source and filename');
112
+ return value;
113
+ }
114
+
115
+ // A case archive is replay input, not only a display copy. Keep the entire
116
+ // request/expected/execution recipe and its IEEE values, and store source text
117
+ // without UTF-8 replacement of lone UTF-16 surrogates. Ordinal disk paths avoid
118
+ // making virtual module identities depend on the host filesystem's encoding.
119
+ export async function archiveCompilerCorpusSources(record,directory) {
120
+ const snapshot=cloneCompilerCorpusData(record);
121
+ if(snapshot===null||typeof snapshot!=='object'||Array.isArray(snapshot)||typeof snapshot.id!=='string') {
122
+ throw new TypeError('original source archive requires a corpus case');
123
+ }
124
+ if(snapshot.modules!==undefined&&!Array.isArray(snapshot.modules))throw new TypeError('original source modules must be an array');
125
+ const modules=snapshot.modules??[],ids=new Set();
126
+ for(const module of modules) {
127
+ sourceRecord(module,'original source module');
128
+ if(typeof module.id!=='string'||ids.has(module.id))throw new TypeError('original source module identities must be unique strings');
129
+ ids.add(module.id);
130
+ }
131
+ if(snapshot.kind==='stage')sourceRecord(snapshot.request,'original stage request');
132
+ // Finish the immutable in-memory snapshot before the first asynchronous I/O.
133
+ const recordIdentity=chunkIdentity(consume=>jsonChunks(snapshot,consume)),assets=[];
134
+ function prepare(source,name) {
135
+ const encoding=compilerSourceAssetEncoding(source),path=name+(encoding==='utf8'?'.eli':'.eli.json');
136
+ const asset={path,encoding,...chunkIdentity(consume=>sourceChunks(source,encoding,consume))};
137
+ assets.push({asset,source});
138
+ return {...utf16Identity(source),asset};
139
+ }
140
+ const archivedModules=modules.map((module,index)=>({id:module.id,filename:module.filename,
141
+ ...prepare(module.source,'modules/'+String(index).padStart(6,'0'))}));
142
+ const stage=snapshot.kind==='stage'?{filename:snapshot.request.filename,
143
+ ...prepare(snapshot.request.source,'stage-input'),macroContext:snapshot.request.macroContext}:undefined;
144
+ const identity={format:'eliscript-original-case-sources',version:1,id:snapshot.id,
145
+ kind:snapshot.kind,entry:snapshot.entry,modules:archivedModules,stage,
146
+ coverage:snapshot.coverage,original:snapshot.original,suite:snapshot.suite,steps:snapshot.steps,
147
+ record:{path:'record.json',encoding:'json',...recordIdentity}};
148
+ // Normalize optional fields exactly as they appear in the retained JSON.
149
+ const body=normalizeIR(identity);
150
+ const result={...body,sha256:chunkIdentity(consume=>jsonChunks(body,consume)).sha256};
151
+ await mkdir(directory,{recursive:true});
152
+ const root=await lstat(directory);
153
+ if(root.isSymbolicLink()||!root.isDirectory())throw new TypeError('original source archive directory must be a real directory');
154
+ for(const {asset,source} of assets) {
155
+ const path=localFile(directory,asset.path);await mkdir(dirname(path),{recursive:true});
156
+ const parent=await lstat(dirname(path));
157
+ if(parent.isSymbolicLink()||!parent.isDirectory())throw new TypeError('original source archive traverses a filesystem alias');
158
+ await writeOwnedChunks(path,consume=>sourceChunks(source,asset.encoding,consume));
159
+ }
160
+ await writeOwnedChunks(localFile(directory,'record.json'),consume=>jsonChunks(snapshot,consume));
161
+ await writeOwnedChunks(localFile(directory,'source-identity.json'),consume=>jsonChunks(result,consume));
162
+ return result;
163
+ }
164
+
165
+ export async function readArchivedCompilerCorpusSources(directory,{expectedIdentity}={}) {
166
+ const identity=await readAsset(directory,'source-identity.json');
167
+ const {sha256,...body}=identity;
168
+ if(identity.format!=='eliscript-original-case-sources'||identity.version!==1||
169
+ sha256!==chunkIdentity(consume=>jsonChunks(body,consume)).sha256||expectedIdentity!==undefined&&sha256!==expectedIdentity) {
170
+ throw new Error('original source archive identity differs');
171
+ }
172
+ const recordAsset=identity.record;
173
+ if(recordAsset?.path!=='record.json'||recordAsset.encoding!=='json')throw new TypeError('original source archive has no complete case recipe');
174
+ const record=await readAsset(directory,recordAsset.path,'json',recordAsset,'original source case recipe bytes changed');
175
+ if(record.id!==identity.id||record.kind!==identity.kind||record.entry!==identity.entry||
176
+ !Array.isArray(identity.modules)||(record.modules??[]).length!==identity.modules.length) {
177
+ throw new Error('original source archive case inventory differs');
178
+ }
179
+ const paths=new Set(['record.json','source-identity.json']);
180
+ async function check(archived,source) {
181
+ if(archived?.encoding!=='utf16le'||archived.filename!==source.filename||
182
+ archived.bytes!==source.source.length*2||archived.sha256!==utf16Identity(source.source).sha256) {
183
+ throw new Error('original source archive does not bind the exact UTF16 source');
184
+ }
185
+ const asset=archived.asset;
186
+ if(!asset||paths.has(asset.path))throw new Error('original source archive repeats an asset');
187
+ paths.add(asset.path);
188
+ const text=await readAsset(directory,asset.path,asset.encoding===undefined?'utf8':asset.encoding,
189
+ asset,'original source archive asset bytes changed');
190
+ if(text!==source.source)throw new Error('original source archive text differs from its case recipe');
191
+ }
192
+ for(let index=0;index<identity.modules.length;index++) {
193
+ const archived=identity.modules[index],module=sourceRecord(record.modules[index],'archived source module');
194
+ if(archived.id!==module.id)throw new Error('original source module order or identity changed');
195
+ await check(archived,module);
196
+ }
197
+ if(record.kind==='stage') {
198
+ await check(identity.stage,sourceRecord(record.request,'archived stage request'));
199
+ if(encodeCompilerIR({value:identity.stage.macroContext})!==encodeCompilerIR({value:record.request.macroContext}))throw new Error('original stage archive changed its macro context');
200
+ }
201
+ else if(identity.stage!==undefined)throw new Error('original source archive added a stage request');
202
+ for(const field of ['coverage','original','suite','steps']) {
203
+ if(encodeCompilerIR({value:identity[field]})!==encodeCompilerIR({value:record[field]}))throw new Error('original source archive recipe metadata differs');
204
+ }
205
+ return record;
206
+ }
@@ -0,0 +1,410 @@
1
+ import {createHash} from 'node:crypto';
2
+ import {resolve} from 'node:path';
3
+ import {pathToFileURL} from 'node:url';
4
+ import {loadCompilerSources} from './compiler-build.mjs';
5
+ import {compilerSourceIdentity} from './compiler-bootstrap.mjs';
6
+ import {originalSourceCaseLocators} from './compiler-corpus-managed-cases.mjs';
7
+ import {addOriginalWorkerProgram} from './compiler-corpus-cli-adapters.mjs';
8
+
9
+ const suite = 'tests/compiler-session-tools.test.mjs';
10
+ const digest = source => createHash('sha256').update(source).digest('hex');
11
+ const caseTitles = [
12
+ 'a complete real managed compiler driver transports AggregateError graphs with shared errors and cause identity',
13
+ 'the real compiler CLI emits structured source failures and preserves successful output with the same built artifact',
14
+ 'real CLI streaming UTF8 preserves split astral scalars BOM diagnostics and strict malformed-tail failures',
15
+ ];
16
+ const semanticFixtures = [
17
+ 'tests/fixtures/core-expression-forms.eli', 'tests/fixtures/core-language-api-usage.eli',
18
+ 'tests/fixtures/core-stdlib-usage.eli', 'tests/fixtures/wasm-managed-source-collections.eli',
19
+ 'tests/fixtures/managed-stdlib-value-json.eli',
20
+ ];
21
+
22
+ // These cases exercise the original host implementation or its retained
23
+ // reports. They remain mandatory original gates, not selected-compiler runs.
24
+ const hostGatePlans = new Map([
25
+ ['tests/collection-layout-benchmark.test.mjs', {
26
+ imports: ['./helpers/performance-acceptance.mjs', 'bun:test', 'node:fs/promises', 'node:url',
27
+ '../tools/collections/layout-benchmark.mjs', '../tools/collections/benchmark.mjs'],
28
+ dependencies: ['tools/collections/layout-host.mjs', 'benchmarks/hamt-layout-macos-arm64.json'],
29
+ cases: new Map([
30
+ ['HAMT layout core validates equivalent real node operations', 'original-host-runtime-case'],
31
+ ['HAMT layout host adapters agree under Bun and Node', 'original-host-runtime-case'],
32
+ ['HAMT browser benchmark uses copied native ESM without a bundler', 'original-source-inventory-case'],
33
+ ['committed HAMT layout baseline proves the 32/24 threshold decision', 'original-retained-report-case'],
34
+ ]),
35
+ }],
36
+ ['tests/transient-builder-benchmark.test.mjs', {
37
+ imports: ['./helpers/performance-acceptance.mjs', 'bun:test', 'node:fs/promises', 'node:path',
38
+ '../tools/collections/transient-builder-benchmark.mjs'],
39
+ dependencies: ['benchmarks/transient-builder-macos-arm64.json'],
40
+ cases: new Map([
41
+ ['committed transient builder report matches core runtime sources', 'original-current-source-report-case'],
42
+ ['transient builder report validator rejects incomplete evidence', 'original-retained-report-case'],
43
+ ]),
44
+ }],
45
+ ['tests/public-surface.test.mjs', {
46
+ imports: ['bun:test', 'node:fs/promises', 'node:path', 'node:url', '../tools/surface/check.mjs'],
47
+ dependencies: ['contracts/public-surface.json'],
48
+ cases: new Map([
49
+ ['repository public surface matches every tracked implementation', 'original-source-inventory-case'],
50
+ ['public surface checker follows aliased runtime re-exports', 'original-source-inventory-case'],
51
+ ]),
52
+ }],
53
+ ['tests/worker-value-codec.test.mjs', {
54
+ imports: ['bun:test', '../runtime/core/identifier.mjs', '../runtime/core/list.mjs', '../runtime/core/map.mjs',
55
+ '../runtime/core/metadata.mjs', '../runtime/core/protocol.mjs', '../runtime/core/set.mjs',
56
+ '../runtime/core/transient.mjs', '../runtime/core/value.mjs', '../runtime/core/vector.mjs',
57
+ '../runtime/worker-value-codec.mjs'],
58
+ dependencies: [],
59
+ cases: new Map([
60
+ ['worker value codec transports protocol definitions without runtime identity', 'original-host-runtime-case'],
61
+ ]),
62
+ }],
63
+ ]);
64
+
65
+ function sourceImports(source) {
66
+ return [...source.matchAll(/^import\s+[\s\S]*?\sfrom\s+["']([^"']+)["'];/gm)].map(match => match[1]);
67
+ }
68
+
69
+ export async function originalToolsHostGateCase({locator, source, file}) {
70
+ const plan = hostGatePlans.get(locator?.file);
71
+ if (!plan || !plan.cases.has(locator.contains)) return null;
72
+ if (typeof source !== 'string' || typeof file !== 'function') throw new TypeError('original tools gate requires source services');
73
+ const imports = sourceImports(source);
74
+ if (imports.length !== plan.imports.length || imports.some((name, index) => name !== plan.imports[index])) {
75
+ throw new TypeError('original tools gate dependencies changed: ' + locator.file);
76
+ }
77
+ if (/\b(?:compile_string|compile_ir_string|compileFile|buildIndependentCompiler|createCompilerSession|import)\s*\(|bin\/eliscript|ELISCRIPT_[A-Z_]*COMPILER/.test(source)) {
78
+ throw new TypeError('original tools gate acquired a compiler path: ' + locator.file);
79
+ }
80
+ let selected = originalSourceCaseLocators(locator.file, source).find(item => item.contains === locator.contains)?.originalCase;
81
+ if (!selected && locator.file === 'tests/transient-builder-benchmark.test.mjs') {
82
+ const prefix = 'currentPerformanceTest(test)(' + JSON.stringify(locator.contains) + ', async () => {';
83
+ const start = source.indexOf(prefix);
84
+ if (start < 0 || source.indexOf(prefix, start + prefix.length) >= 0 || !source.slice(start).trimEnd().endsWith('});')) {
85
+ throw new TypeError('original current-source report gate boundary changed');
86
+ }
87
+ selected = {title: locator.contains, span: {start, end: source.length},
88
+ byteStart: Buffer.byteLength(source.slice(0, start)), byteEnd: Buffer.byteLength(source),
89
+ sha256: digest(source.slice(start)), registration: 'currentPerformanceTest(test)', timeoutMs: 5000};
90
+ }
91
+ if (!selected) throw new TypeError('original tools gate case boundary changed: ' + locator.contains);
92
+ const dependencies = [];
93
+ const paths = new Set(plan.dependencies);
94
+ for (const specifier of imports) if (specifier.startsWith('.')) {
95
+ const path = new URL(specifier, 'file:///' + locator.file).pathname.slice(1);
96
+ paths.add(path);
97
+ }
98
+ for (const path of paths) dependencies.push({file: path, sourceSha256: (await file(path)).sha256});
99
+ return {kind: plan.cases.get(locator.contains), originalAssertion: locator.contains,
100
+ region: {start: selected.span.start, end: selected.span.end, byteStart: selected.byteStart,
101
+ byteEnd: selected.byteEnd, sha256: selected.sha256}, dependencies,
102
+ registration: selected.registration, timeoutMs: selected.timeoutMs,
103
+ reason: 'unchanged complete original gate; this case has no language compiler or selected-product injection'};
104
+ }
105
+
106
+ function semanticDependencies(source) {
107
+ // These are the existing suite's complete header dependencies. The replay
108
+ // supplies its test collector and selected-session setup explicitly; a new
109
+ // import must be wired deliberately instead of failing deep in a VM run.
110
+ const expected = [
111
+ "import {beforeAll, afterAll, test, spyOn} from 'bun:test';",
112
+ "import assert from 'node:assert/strict';",
113
+ "import {mkdtemp, readFile, writeFile, rm} from 'node:fs/promises';",
114
+ "import {resolve} from 'node:path';",
115
+ "import {tmpdir} from 'node:os';",
116
+ "import {pathToFileURL} from 'node:url';",
117
+ "import {spawnSync} from 'node:child_process';",
118
+ "import {createHash} from 'node:crypto';",
119
+ "import {buildIndependentCompiler,loadCompilerSources,independentCompilerResources} from '../tools/backends/compiler-build.mjs';",
120
+ "import {createCompilerSession} from '../tools/backends/compiler-session.mjs';",
121
+ ];
122
+ const headerEnd = source.indexOf('\nlet directory, owned, driver;');
123
+ const imports = headerEnd < 0 ? [] : source.slice(0, headerEnd).split('\n').map(line => line.trim()).filter(Boolean);
124
+ if (imports.length !== expected.length || imports.some((line, index) => line !== expected[index])) {
125
+ throw new TypeError('original compiler semantic dependencies changed');
126
+ }
127
+ const session = region(source, 'async function withSession(run) {', '\nconst analyze =');
128
+ if (session.source !== "async function withSession(run) {\n const session = await createCompilerSession({host: 'javascript', compiler: driver});\n try {await run(session);} finally {session.close();}\n}") {
129
+ throw new TypeError('original compiler semantic session lifecycle changed');
130
+ }
131
+ const {source: retained, ...sessionRange} = session;
132
+ return {imports, header: {start: 0, end: headerEnd, byteStart: 0, byteEnd: Buffer.byteLength(source.slice(0, headerEnd)),
133
+ sha256: digest(source.slice(0, headerEnd))}, session: sessionRange};
134
+ }
135
+
136
+ function semanticRegions(source) {
137
+ const first = region(source, 'const analyze =', '\nasync function withBackendPhaseTrace');
138
+ const start = source.indexOf("test('optional parameter defaults resolve");
139
+ if (start < 0) throw new TypeError('original compiler semantic case boundary changed');
140
+ const tail = source.slice(start);
141
+ return [first, {source: tail, start, end: source.length, byteStart: Buffer.byteLength(source.slice(0, start)),
142
+ byteEnd: Buffer.byteLength(source), sha256: digest(tail)}];
143
+ }
144
+
145
+ function semanticTitles(regions) {
146
+ const names = [];
147
+ for (const selected of regions) {
148
+ for (const match of selected.source.matchAll(/^[ \t]*test\('([^']+)'([^\n]*)/gm)) {
149
+ if (match[1] === 'production tools analyze complete existing fixture ') {
150
+ if (!match[2].startsWith(' + filename,')) throw new TypeError('original compiler semantic fixture registration changed');
151
+ names.push(...semanticFixtures.map(filename => match[1] + filename));
152
+ } else {
153
+ if (!match[2].startsWith(',')) throw new TypeError('original compiler semantic test registration changed');
154
+ names.push(match[1]);
155
+ }
156
+ }
157
+ }
158
+ if (names.length === 0 || new Set(names).size !== names.length) throw new TypeError('invalid original compiler semantic case names');
159
+ return names;
160
+ }
161
+
162
+ function semanticHostSource(sourceRoot, sourceIdentity, fixtureIdentities, body, titles) {
163
+ return `import assert from 'node:assert/strict';
164
+ import {readFile} from 'node:fs/promises';
165
+ import {createHash} from 'node:crypto';
166
+ import {pathToFileURL} from 'node:url';
167
+ import {createCompilerSession} from ${JSON.stringify(pathToFileURL(resolve(sourceRoot, 'tools/backends/compiler-session.mjs')).href)};
168
+ import {loadCompilerSources} from ${JSON.stringify(pathToFileURL(resolve(sourceRoot, 'tools/backends/compiler-build.mjs')).href)};
169
+ import {compilerSourceIdentity} from ${JSON.stringify(pathToFileURL(resolve(sourceRoot, 'tools/backends/compiler-bootstrap.mjs')).href)};
170
+ import {readCompilerMetadata} from ${JSON.stringify(pathToFileURL(resolve(sourceRoot, 'tools/backends/compiler-metadata.mjs')).href)};
171
+ const configuration=await readCompilerMetadata(process.env.ELISCRIPT_ORIGINAL_COMPILER_SESSION);
172
+ process.chdir(configuration.sourceRoot);
173
+ assert.deepEqual(compilerSourceIdentity(await loadCompilerSources({sourceRoot:configuration.sourceRoot})),${JSON.stringify(sourceIdentity)});
174
+ for(const identity of ${JSON.stringify(fixtureIdentities)}){
175
+ const bytes=await readFile(identity.filename);
176
+ assert.equal(createHash('sha256').update(bytes).digest('hex'),identity.sha256,identity.filename);
177
+ }
178
+ const selectedDriver=configuration.target==='javascript'?await import(pathToFileURL(configuration.path).href):undefined;
179
+ const selectedBytes=configuration.target==='wasm'?new Uint8Array(await readFile(configuration.path)):undefined;
180
+ async function openSelected(){
181
+ const session=await createCompilerSession({host:configuration.target,compiler:selectedDriver,
182
+ ...(configuration.target==='wasm'?{bytes:selectedBytes}:{}),
183
+ ...(configuration.target==='native'?{path:configuration.path,descriptor:{typed:configuration.typed,descriptor:configuration.descriptor}}:{}),
184
+ memory:configuration.memory,options:configuration.runtimeOptions});
185
+ assert.equal(session.host,configuration.target);return session;
186
+ }
187
+ async function withSession(run){const session=await openSelected();try{await run(session);}finally{session.close();}}
188
+ const cases=[];
189
+ function test(name,run,timeout=5000){cases.push({name,run,timeout});}
190
+ async function timed(name,run,timeout){
191
+ let timer;const start=performance.now();
192
+ try{
193
+ await Promise.race([Promise.resolve().then(run),new Promise((_,reject)=>{timer=setTimeout(()=>reject(new Error(name+' exceeded its original '+timeout+' ms timeout')),timeout);})]);
194
+ assert(performance.now()-start<=timeout,name+' exceeded its original '+timeout+' ms timeout');
195
+ }finally{clearTimeout(timer);}
196
+ }
197
+ ` + body + `
198
+ assert.deepEqual(cases.map(record=>record.name),${JSON.stringify(titles)});
199
+ for(const record of cases)await timed(record.name,record.run,record.timeout);
200
+ console.log(JSON.stringify(cases.map(record=>record.name)));
201
+ `;
202
+ }
203
+
204
+ function region(source, begin, end, from = 0) {
205
+ const start = source.indexOf(begin, from);
206
+ const finish = start < 0 ? -1 : source.indexOf(end, start + begin.length);
207
+ if (start < 0 || finish < 0) throw new TypeError('original compiler artifact case boundary changed: ' + begin);
208
+ const selected = source.slice(start, finish);
209
+ return {source: selected, start, end: finish, byteStart: Buffer.byteLength(source.slice(0, start)),
210
+ byteEnd: Buffer.byteLength(source.slice(0, finish)), sha256: digest(selected)};
211
+ }
212
+
213
+ function replaceSetup(source, before, after, changes) {
214
+ const at = source.indexOf(before);
215
+ if (at < 0 || source.indexOf(before, at + before.length) >= 0) {
216
+ throw new TypeError('original compiler artifact setup changed: ' + before);
217
+ }
218
+ changes.push({role: 'selected-complete-compiler-transport', beforeSha256: digest(before), afterSha256: digest(after)});
219
+ return source.slice(0, at) + after + source.slice(at + before.length);
220
+ }
221
+
222
+ // These are the original artifact and CLI assertion bodies, rather than a
223
+ // replacement compiler or a reduced request corpus. Only artifact construction,
224
+ // target transport, and the independent JavaScript reference setup change.
225
+ export async function addOriginalToolsArtifactPrograms({add, locators, text, file, sourceRoot}) {
226
+ if (typeof add !== 'function' || !Array.isArray(locators) || typeof text !== 'function' ||
227
+ typeof file !== 'function' || typeof sourceRoot !== 'string') {
228
+ throw new TypeError('original compiler artifact adapter requires its source manifest and services');
229
+ }
230
+ const workerPrograms = await addOriginalWorkerProgram({add, locators, text, file, sourceRoot});
231
+ const candidates = locators.filter(locator => locator.file === suite);
232
+ if (candidates.length === 0) return workerPrograms;
233
+ const source = await text(suite), identity = await file(suite);
234
+ const selected = region(source, 'const aggregateSource=', "\ntest('optional parameter defaults resolve");
235
+ const coverage = candidates.filter(locator => typeof locator.contains === 'string' &&
236
+ selected.source.includes(locator.contains)).map(locator => locator.id);
237
+ const semantics = semanticRegions(source);
238
+ const semanticNames = semanticTitles(semantics);
239
+ const semanticCoverage = candidates.filter(locator => typeof locator.contains === 'string' &&
240
+ (semanticNames.includes(locator.contains) || semantics.some(selected => selected.source.includes(locator.contains)))).map(locator => locator.id);
241
+ if (coverage.length === 0 && semanticCoverage.length === 0) return workerPrograms;
242
+ const dependencies = semanticCoverage.length ? semanticDependencies(source) : null;
243
+
244
+ const sources = await loadCompilerSources({sourceRoot});
245
+ for (const record of [...sources.modules, sources.runtime, ...(sources.literalSources ?? [])]) await file(record.filename);
246
+ const completeSourceIdentity = compilerSourceIdentity(sources);
247
+ const changes = [];
248
+ let body = selected.source;
249
+ body = replaceSetup(body,
250
+ "const producer=await createCompilerSession({host:'javascript',compiler:driver});",
251
+ 'const producer=await openSelected();', changes);
252
+ body = replaceSetup(body, 'const sources=await loadCompilerSources();',
253
+ 'const sources=structuredClone(completeSources);', changes);
254
+ body = replaceSetup(body,
255
+ "const oracleSource=aggregateSource(pathToFileURL(resolve(directory,'host/compiler-session.mjs')).href);",
256
+ `const oracleArtifact=await buildSelectedArtifact(producer,'aggregate-reference','javascript',structuredClone(completeSources));
257
+ const oracleSource=aggregateSource(pathToFileURL(oracleArtifact.path).href);`, changes);
258
+ body = replaceSetup(body,
259
+ "const artifact=await withBackendPhaseTrace(()=>buildIndependentCompiler({host:'wasm',outputRoot:temporary,session:producer,sources}));",
260
+ "const artifact=await buildSelectedArtifact(producer,'aggregate-selected',configuration.target,sources);", changes);
261
+ body = replaceSetup(body,
262
+ 'assert.deepEqual(WebAssembly.Module.imports(new WebAssembly.Module(artifact.bytes)),[]);',
263
+ "assert.equal(artifact.host,configuration.target);\n if(configuration.target==='wasm')assert.deepEqual(WebAssembly.Module.imports(new WebAssembly.Module(artifact.bytes)),[]);", changes);
264
+ body = replaceSetup(body,
265
+ "managed=await createCompilerSession({host:'wasm',bytes:artifact.bytes,memory:resources.memory,options:{...resources.budget,auto:resources.auto}});",
266
+ 'managed=await openArtifact(artifact,resources);assert.equal(managed.host,configuration.target);', changes);
267
+
268
+ const sessionURL = pathToFileURL(resolve(sourceRoot, 'tools/backends/compiler-session.mjs')).href;
269
+ const buildURL = pathToFileURL(resolve(sourceRoot, 'tools/backends/compiler-build.mjs')).href;
270
+ const bootstrapURL = pathToFileURL(resolve(sourceRoot, 'tools/backends/compiler-bootstrap.mjs')).href;
271
+ const hostSource = `import assert from 'node:assert/strict';
272
+ import {mkdtemp,readFile,writeFile,rm,mkdir} from 'node:fs/promises';
273
+ import {resolve} from 'node:path';
274
+ import {tmpdir} from 'node:os';
275
+ import {pathToFileURL} from 'node:url';
276
+ import {spawnSync} from 'node:child_process';
277
+ import {createCompilerSession} from ${JSON.stringify(sessionURL)};
278
+ import {buildIndependentCompiler,loadCompilerSources,independentCompilerResources} from ${JSON.stringify(buildURL)};
279
+ import {compilerSourceIdentity} from ${JSON.stringify(bootstrapURL)};
280
+ import {readCompilerMetadata} from ${JSON.stringify(pathToFileURL(resolve(sourceRoot,'tools/backends/compiler-metadata.mjs')).href)};
281
+ const configuration=await readCompilerMetadata(process.env.ELISCRIPT_ORIGINAL_COMPILER_SESSION);
282
+ process.chdir(configuration.sourceRoot);
283
+ if(!configuration.supportingDirectory||!configuration.supportingManifest)throw new TypeError('original compiler artifact cases require their actual product archive');
284
+ const completeSources=await loadCompilerSources({sourceRoot:configuration.sourceRoot});
285
+ assert.deepEqual(compilerSourceIdentity(completeSources),${JSON.stringify(completeSourceIdentity)});
286
+ const cliPath=${JSON.stringify(resolve(sourceRoot, 'tools/backends/compiler-cli.mjs'))};
287
+ const resources=independentCompilerResources({profile:'small'});
288
+ assert.deepEqual(configuration.memory,resources.memory);
289
+ for(const[key,value]of Object.entries({...resources.budget,auto:resources.auto}))assert.equal(configuration.runtimeOptions[key],value,key);
290
+ const selectedDriver=configuration.target==='javascript'?await import(pathToFileURL(configuration.path).href):undefined;
291
+ async function openSelected(){
292
+ const session=await createCompilerSession({host:configuration.target,compiler:selectedDriver,
293
+ ...(configuration.target==='wasm'?{bytes:new Uint8Array(await readFile(configuration.path))}:{}),
294
+ ...(configuration.target==='native'?{path:configuration.path,descriptor:{typed:configuration.typed,descriptor:configuration.descriptor}}:{}),
295
+ memory:configuration.memory,options:configuration.runtimeOptions});
296
+ assert.equal(session.host,configuration.target);return session;
297
+ }
298
+ async function openArtifact(artifact,limits=resources){
299
+ const session=await createCompilerSession({host:artifact.host,
300
+ ...(artifact.host==='javascript'?{compiler:await import(pathToFileURL(artifact.path).href)}:{}),
301
+ ...(artifact.host==='wasm'?{bytes:artifact.bytes}:{}),
302
+ ...(artifact.host==='native'?{path:artifact.path,descriptor:artifact.lowered??{typed:artifact.typed,descriptor:artifact.descriptor}}:{}),
303
+ memory:limits.memory,options:{...limits.budget,auto:limits.auto,nativeTarget:artifact.nativeTarget??configuration.runtimeOptions.nativeTarget}});
304
+ assert.equal(session.host,artifact.host);return session;
305
+ }
306
+ const supportingProducts=[];
307
+ async function saveSupportingProducts(){
308
+ await mkdir(configuration.supportingDirectory,{recursive:true});
309
+ await writeFile(configuration.supportingManifest,JSON.stringify({format:'eliscript-original-compiler-supporting-products',version:1,products:supportingProducts}));
310
+ }
311
+ async function buildSelectedArtifact(producer,role,target,sources){
312
+ const artifact=await buildIndependentCompiler({host:target,outputRoot:resolve(configuration.supportingDirectory,role),
313
+ sourceRoot:configuration.sourceRoot,session:producer,sources,profile:'small',budget:resources.budget,
314
+ memory:resources.memory,auto:resources.auto,nativeTarget:configuration.runtimeOptions.nativeTarget});
315
+ assert.equal(artifact.host,target);assert.equal(artifact.provenance.mode,'session');
316
+ assert.equal(artifact.provenance.producerHost,producer.host);
317
+ assert.deepEqual(artifact.provenance.compiledModuleIds,sources.modules.map(module=>module.id));
318
+ assert.equal(artifact.provenance.runtimeCompiled,true);
319
+ supportingProducts.push({role,artifact});await saveSupportingProducts();return artifact;
320
+ }
321
+ let directory,standard;
322
+ async function withSession(run){const session=await openArtifact(standard);try{return await run(session);}finally{session.close();}}
323
+ const cases=[];
324
+ function test(name,run,timeout=5000){cases.push({name,run,timeout});}
325
+ async function timed(name,run,timeout){
326
+ let timer;
327
+ const start=performance.now();
328
+ try{
329
+ await Promise.race([Promise.resolve().then(run),new Promise((_,reject)=>{timer=setTimeout(()=>reject(new Error(name+' exceeded its original '+timeout+' ms timeout')),timeout);})]);
330
+ assert(performance.now()-start<=timeout,name+' exceeded its original '+timeout+' ms timeout');
331
+ }finally{clearTimeout(timer);}
332
+ }
333
+ ` + body + `
334
+ assert.deepEqual(cases.map(record=>record.name),${JSON.stringify(caseTitles)});
335
+ let failed=false;
336
+ try{
337
+ await timed('original compiler artifact beforeAll',async()=>{
338
+ const producer=await openSelected();
339
+ try{standard=await buildSelectedArtifact(producer,'standard-selected',configuration.target,structuredClone(completeSources));directory=standard.directory;}
340
+ finally{producer.close();}
341
+ },120000);
342
+ for(const record of cases)await timed(record.name,record.run,record.timeout);
343
+ console.log(JSON.stringify(cases.map(record=>record.name)));
344
+ }catch(error){failed=true;throw error;}
345
+ finally{
346
+ try{await saveSupportingProducts();}catch(error){if(!failed)throw error;}
347
+ }
348
+ `;
349
+
350
+ const regions = [{start: selected.start, end: selected.end, byteStart: selected.byteStart,
351
+ byteEnd: selected.byteEnd, sha256: selected.sha256}];
352
+ const recordIds = [];
353
+ for (const hostRuntime of coverage.length ? ['node', 'bun'] : []) {
354
+ const id = 'original-tools-artifact:compiler-session-tools:' + hostRuntime;
355
+ recordIds.push(id);
356
+ add({id, kind: 'project', coverage: [...coverage], entry: sources.entry,
357
+ modules: structuredClone(sources.modules), memory: {initialPages: 128, maximumPages: 4096},
358
+ request: {operation: 'project', resolveImports: true, phased: false, sourceMap: true},
359
+ execution: {kind: 'compiler-session-program', host: 'tests/__eliscript_original_tools_artifact_' + hostRuntime + '.mjs',
360
+ hostRuntime, hostSource, runtimeProfile: 'compiler', compilerProfile: 'small',
361
+ runtimeOptions: {maxSlots: 131072, initialBytes: 8388608, maxBytes: 67108864, auto: 65536},
362
+ supportingCompilerProducts: true, timeoutMs: 300000,
363
+ setupReplacement: {kind: 'selected-complete-compiler-artifacts', producer: 'selected-session',
364
+ reference: 'independent-javascript-product-assertions-only', sourceIdentity: completeSourceIdentity, changes,
365
+ beforeAllTimeoutMs: 120000, originalCaseTimeouts: [120000, 30000, 30000]}},
366
+ expected: {kind: 'seed-program', oracleRequired: true},
367
+ original: {suite, host: suite, sourceSha256: identity.sha256, regions,
368
+ originalAssertions: [...caseTitles], completeSourceIdentity,
369
+ setupReplacement: {kind: 'selected-complete-compiler-artifacts', changes},
370
+ coverageScope: 'aggregate-entry-and-three-artifact-cli-cases-only'},
371
+ });
372
+ }
373
+ const summaries = [...workerPrograms, ...(coverage.length ? [{suite, coverage: [...coverage], regions, recordIds}] : [])];
374
+ if (semanticCoverage.length) {
375
+ const fixtureIdentities = [];
376
+ for (const filename of semanticFixtures) fixtureIdentities.push({filename, sha256: (await file(filename)).sha256});
377
+ const semanticChanges = [];
378
+ const semanticBody = replaceSetup(semantics.map(selected => selected.source).join('\n'),
379
+ "const session = await createCompilerSession({host: 'javascript', compiler: driver});",
380
+ 'const session = await openSelected();', semanticChanges);
381
+ const titles = semanticNames;
382
+ const semanticRanges = semantics.map(({source, ...range}) => range);
383
+ const semanticIds = [];
384
+ const semanticHost = semanticHostSource(sourceRoot, completeSourceIdentity, fixtureIdentities, semanticBody, titles);
385
+ for (const hostRuntime of ['node', 'bun']) {
386
+ const id = 'original-managed:compiler-session-tools:' + hostRuntime;
387
+ semanticIds.push(id);
388
+ add({id, kind: 'project', coverage: [...semanticCoverage], entry: sources.entry,
389
+ modules: structuredClone(sources.modules), memory: {initialPages: 128, maximumPages: 4096},
390
+ request: {operation: 'project', resolveImports: true, phased: false, sourceMap: true},
391
+ execution: {kind: 'compiler-session-program', host: 'tests/__eliscript_compiler_session_tools_' + hostRuntime + '.mjs',
392
+ hostRuntime, hostSource: semanticHost, runtimeProfile: 'compiler', compilerProfile: 'small',
393
+ runtimeOptions: {maxSlots: 131072, initialBytes: 8388608, maxBytes: 67108864, auto: 65536}, timeoutMs: 120000,
394
+ setupReplacement: {kind: 'selected-complete-compiler-semantic-tools', producer: 'selected-session',
395
+ reference: 'retained-original-semantic-assertions-and-generated-javascript', sourceIdentity: completeSourceIdentity,
396
+ dependencies, changes: semanticChanges, defaultCaseTimeoutMs: 5000, deadlines: 'retained-test-registration-arguments'}},
397
+ expected: {kind: 'seed-program', oracleRequired: true},
398
+ original: {suite, host: suite, sourceSha256: identity.sha256, regions: semanticRanges,
399
+ cases: candidates.filter(locator => semanticCoverage.includes(locator.id) && locator.originalCase)
400
+ .map(locator => ({id: locator.id, ...structuredClone(locator.originalCase)})),
401
+ originalAssertions: titles, completeSourceIdentity, fixtureIdentities,
402
+ originalAssertion: 'all original public semantic tools cases including the original trailing parameter-default query corpus; aggregate/CLI artifact cases are separate',
403
+ setupReplacement: {kind: 'selected-complete-compiler-semantic-tools', dependencies, changes: semanticChanges},
404
+ coverageScope: 'retained-semantic-tools-regions-only'},
405
+ });
406
+ }
407
+ summaries.push({suite, coverage: [...semanticCoverage], regions: semanticRanges, recordIds: semanticIds});
408
+ }
409
+ return summaries;
410
+ }