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,769 @@
1
+ import assert from 'node:assert/strict';
2
+ import {readFile, writeFile, mkdir, symlink,lstat} from 'node:fs/promises';
3
+ import {resolve, join,relative,isAbsolute,sep} from 'node:path';
4
+ import {pathToFileURL,fileURLToPath} from 'node:url';
5
+ import {spawn} from 'node:child_process';
6
+ import {createHash} from 'node:crypto';
7
+ import {Console} from 'node:console';
8
+ import {Writable} from 'node:stream';
9
+ import {instantiateManagedRuntime,instantiateManagedRuntimeWithHostModules} from './managed-runtime.mjs';
10
+ import {independentCompilerResources,buildIndependentCompiler} from './compiler-build.mjs';
11
+ import {openCompilerArtifact,archiveCompilerArtifact,normalizeCompilerHost,saveCompilerMetadata} from './compiler-bootstrap.mjs';
12
+ import {prepareOriginalCompilerGenerations} from './compiler-corpus-generations.mjs';
13
+ import {prepareOriginalReferenceArtifact} from './compiler-corpus-reference.mjs';
14
+ import {encodeCompilerIR,encodeCompilerMetadata} from './compiler-session.mjs';
15
+
16
+ function valueRecord(value) {
17
+ if (value === undefined) return {$eliscriptObservation: 'undefined'};
18
+ if (typeof value === 'bigint') return {$eliscriptObservation:'bigint',decimal:String(value)};
19
+ if (typeof value === 'number') {
20
+ if (Object.is(value, -0)) return {$eliscriptObservation: '-0'};
21
+ if (!Number.isFinite(value)) return {$eliscriptObservation: String(value)};
22
+ }
23
+ if (Array.isArray(value)) return value.map(valueRecord);
24
+ if (value !== null && typeof value === 'object') {
25
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, valueRecord(item)]));
26
+ }
27
+ return value;
28
+ }
29
+
30
+ function managedValue(a, value) {
31
+ if (value === null || typeof value !== 'object') return value;
32
+ if (value.kind === 4) return a.readNumber(value);
33
+ if (value.kind === 5) return a.readString(value);
34
+ if (value.kind === 34) return a.readBigInt(value);
35
+ if(value.kind===13){
36
+ const result={},keys=a.objectKeys(value);
37
+ try{for(let index=0;index<a.length(keys);index++){
38
+ const key=a.get(keys,index),child=a.objectGet(value,key);
39
+ try{Object.defineProperty(result,a.readString(key),{value:managedValue(a,child),enumerable:true,writable:true,configurable:true});}
40
+ finally{a.release(child);a.release(key);}
41
+ }}finally{a.release(keys);}
42
+ return result;
43
+ }
44
+ if (value.kind !== 14) throw new TypeError('original corpus observation has an unsupported source value kind');
45
+ return Array.from({length: a.length(value)}, (_, index) => {
46
+ const child = a.get(value, index);
47
+ try {return managedValue(a, child);} finally {a.release(child);}
48
+ });
49
+ }
50
+
51
+ function fromRecipe(value, results) {
52
+ if(Array.isArray(value))return value.map(item=>fromRecipe(item,results));
53
+ if(value===null||typeof value!=='object')return value;
54
+ if(Object.keys(value).length===1&&Object.hasOwn(value,'$compilerCorpusRef')){
55
+ const [step,...path]=value.$compilerCorpusRef.split('.');
56
+ if(!results.has(step))throw new Error('original request sequence references an unavailable step');
57
+ let result=results.get(step);for(const part of path){if(result===null||!Object.hasOwn(result,part))throw new Error('original request sequence references an unavailable result');result=result[part];}
58
+ return structuredClone(result);
59
+ }
60
+ if(Object.keys(value).length===1&&Object.hasOwn(value,'$compilerCorpusConcat'))return fromRecipe(value.$compilerCorpusConcat,results).join('');
61
+ if(Object.keys(value).length===1&&Object.hasOwn(value,'$compilerCorpusReplace')){const [source,before,after]=fromRecipe(value.$compilerCorpusReplace,results);return source.replace(before,after);}
62
+ if(Object.keys(value).length===1&&Object.hasOwn(value,'$compilerCorpusJsonPatch')){
63
+ const [source,patches]=fromRecipe(value.$compilerCorpusJsonPatch,results),document=JSON.parse(source);
64
+ for(const patch of patches){
65
+ let owner=document;for(const part of patch.path.slice(0,-1))owner=owner[part];
66
+ const key=patch.path.at(-1);
67
+ if(Object.hasOwn(patch,'duplicateIndex')){
68
+ const array=owner[key],index=patch.duplicateIndex;
69
+ if(!Array.isArray(array)||!Number.isSafeInteger(index)||index<0||index>=array.length||!Object.hasOwn(array,index)||
70
+ Object.hasOwn(patch,'append')||Object.hasOwn(patch,'value')||Object.hasOwn(patch,'negativeZero'))
71
+ throw new TypeError('original corpus duplicateIndex must select one existing own array element');
72
+ array.push(structuredClone(array[index]));
73
+ }
74
+ else if(Object.hasOwn(patch,'append'))owner[key].push(patch.append);
75
+ else owner[key]=patch.negativeZero?-0:patch.value;
76
+ }
77
+ const wire=item=>{
78
+ if(typeof item==='number'&&Object.is(item,-0))return '-0';
79
+ if(Array.isArray(item))return '['+item.map(wire).join(',')+']';
80
+ if(item!==null&&typeof item==='object')return '{'+Object.keys(item).map(key=>JSON.stringify(key)+':'+wire(item[key])).join(',')+'}';
81
+ return JSON.stringify(item);
82
+ };
83
+ return wire(document);
84
+ }
85
+ return Object.fromEntries(Object.entries(value).map(([key,item])=>[key,fromRecipe(item,results)]));
86
+ }
87
+ export {fromRecipe as resolveOriginalCorpusRequest};
88
+
89
+ async function childOutput(command,args,{cwd,signal,env,timeoutMs}={}){
90
+ if(timeoutMs!==undefined&&(!Number.isSafeInteger(timeoutMs)||timeoutMs<=0))throw new TypeError('original host deadline must retain its positive integer timeout');
91
+ return new Promise((accept,reject)=>{
92
+ const child=spawn(command,args,{cwd,signal,env:env?{...process.env,...env}:process.env,stdio:['ignore','pipe','pipe']}),stdout=[],stderr=[];
93
+ let timer,termination,expired=false;
94
+ if(timeoutMs!==undefined)timer=setTimeout(()=>{
95
+ expired=true;child.kill('SIGTERM');
96
+ termination=setTimeout(()=>child.kill('SIGKILL'),1000);termination.unref();
97
+ },timeoutMs);
98
+ const clear=()=>{clearTimeout(timer);clearTimeout(termination);};
99
+ child.stdout.on('data',chunk=>stdout.push(chunk));child.stderr.on('data',chunk=>stderr.push(chunk));child.once('error',error=>{clear();reject(error);});
100
+ child.once('close',code=>{
101
+ clear();
102
+ if(expired){const error=new Error('original corpus host exceeded its '+timeoutMs+' ms timeout');error.code='ELISCRIPT_ORIGINAL_HOST_TIMEOUT';error.timeoutMs=timeoutMs;reject(error);}
103
+ else if(code===0)accept(Buffer.concat(stdout).toString('utf8'));
104
+ else reject(new Error(Buffer.concat(stderr).toString('utf8').trim()||'corpus host exited with '+code));
105
+ });
106
+ });
107
+ }
108
+
109
+ function box(a,value){
110
+ if(typeof value==='bigint')return a.bigint(value);
111
+ if(typeof value==='number')return a.number(value);if(typeof value==='string')return a.string(value);
112
+ if(value===null||typeof value!=='object')return value;
113
+ const children=[];
114
+ try{
115
+ if(Array.isArray(value)){const items=value.map(item=>{const child=box(a,item);children.push(child);return child;});return a.sourceArray(items);}
116
+ const items=Object.fromEntries(Object.entries(value).map(([key,item])=>{const child=box(a,item);children.push(child);return[key,child];}));return a.sourceObject(items);
117
+ }finally{children.forEach(child=>a.release(child));}
118
+ }
119
+
120
+ async function originalProgramAliases(artifact,record){
121
+ const directory=artifact.directory??resolve(artifact.path,'..');
122
+ const modules=artifact.target==='javascript'?artifact.modules:artifact.descriptor?.project?.modules;
123
+ if(!Array.isArray(modules))throw new Error('original host oracle requires actual phased module exports');
124
+ for(const module of modules){
125
+ if(typeof module.id!=='string'||!module.id.endsWith('.mjs'))throw new TypeError('original program module identity must end in .mjs');
126
+ const alias=module.id.slice(0,-4)+'.eli',file=resolve(directory,alias);
127
+ if(module.id.startsWith('/')||module.id.split('/').some(part=>!part||part==='.'||part==='..')||/[\\:\u0000]/.test(module.id))throw new TypeError('original program alias escapes the product');
128
+ await mkdir(resolve(file,'..'),{recursive:true});
129
+ const base='./'+module.id.split('/').at(-1);
130
+ const hasDefault=module.exports?.some(item=>item.name==='default');
131
+ await writeFile(file,'export * from '+JSON.stringify(base)+';\n'+(hasDefault?'export {default} from '+JSON.stringify(base)+';\n':''));
132
+ }
133
+ await javascriptEnvironment(artifact,record.sourceRoot);
134
+ try{await symlink(resolve(record.sourceRoot,'runtime'),resolve(directory,'runtime'),'dir');}catch(error){if(error.code!=='EEXIST')throw error;}
135
+ }
136
+
137
+ async function originalProgramSidecars(artifact,record){
138
+ const directory=resolve(artifact.directory??resolve(artifact.path,'..'));
139
+ async function put(id,source){
140
+ if(typeof id!=='string'||!id||/[\\:\u0000]/.test(id)||id.split('/').some(part=>!part||part==='.'||part==='..')||typeof source!=='string')throw new TypeError('invalid original provider sidecar');
141
+ const path=resolve(directory,id),part=relative(directory,path);
142
+ if(isAbsolute(part)||part==='..'||part.startsWith('..'+sep))throw new TypeError('original provider sidecar escapes its artifact');
143
+ let parent=directory;
144
+ for(const segment of id.split('/').slice(0,-1)){
145
+ parent=join(parent,segment);await mkdir(parent,{recursive:true});
146
+ const details=await lstat(parent);if(details.isSymbolicLink()||!details.isDirectory())throw new TypeError('original provider sidecar traverses an alias');
147
+ }
148
+ try{await writeFile(path,source,{flag:'wx'});}catch(error){
149
+ if(error.code!=='EEXIST')throw error;
150
+ const details=await lstat(path);if(details.isSymbolicLink()||!details.isFile()||!(await readFile(path)).equals(Buffer.from(source)))throw new Error('original provider sidecar conflicts with emitted source');
151
+ }
152
+ return path;
153
+ }
154
+ for(const source of record.request.hostSources??[])await put(source.id,source.source);
155
+ if(record.execution.hostSource!==null&&record.execution.hostSource!==undefined)return put(record.execution.host,record.execution.hostSource);
156
+ return record.execution.host?resolve(record.sourceRoot,record.execution.host):null;
157
+ }
158
+
159
+ export function originalProgramArguments(contract,entry,base){
160
+ const records=contract.arguments??(contract.argumentModules??[entry]).map(module=>({module}));
161
+ if(!Array.isArray(records))throw new TypeError('original program arguments must be an array');
162
+ return records.map(record=>{
163
+ if(record===null||typeof record!=='object'||Array.isArray(record)||Object.keys(record).length!==1)
164
+ throw new TypeError('original program requires an explicit argument recipe');
165
+ if(Object.hasOwn(record,'literal')){
166
+ if(typeof record.literal!=='string')throw new TypeError('original program literal argument must be text');
167
+ return record.literal;
168
+ }
169
+ if(Object.hasOwn(record,'directory')){
170
+ if(record.directory!==true)throw new TypeError('original program directory argument must select its artifact');
171
+ return fileURLToPath(new URL('./',base));
172
+ }
173
+ const id=record.module;
174
+ if(typeof id!=='string'||!id||/[\\:\u0000]/.test(id)||id.split('/').some(part=>!part||part==='.'||part==='..'))
175
+ throw new TypeError('original program module argument must stay inside its artifact');
176
+ const url=new URL(id.split('/').map(encodeURIComponent).join('/'),base);
177
+ return contract.argument==='url'?url.href:fileURLToPath(url);
178
+ });
179
+ }
180
+
181
+ async function originalCompilerSourceMaps(context) {
182
+ const {record, artifact, session, signal, target} = context;
183
+ if (!record.execution.compilerSourceMaps || target === 'javascript') return [];
184
+ const modules = record.modules ?? record.request.modules;
185
+ if (!Array.isArray(modules) || modules.length === 0) throw new TypeError('original compiler source maps require the entire original source graph');
186
+ const request = {...record.request, operation: 'project', modules, entry: record.entry ?? record.request.entry,
187
+ target: 'javascript', sourceMap: true, debug: false, phased: false};
188
+ const response = await session.request(request, {signal});
189
+ const support = await context.archiveProduct(response, 'original-compiler-javascript-maps', 'javascript');
190
+ assert.equal(support.target, 'javascript');
191
+ assert.deepEqual(support.modules.map(module => module.id).sort(), modules.map(module => module.id).sort());
192
+ const maps = [];
193
+ for (const module of support.modules) {
194
+ if (typeof module.sourceMapPath !== 'string') throw new Error('original compiler JavaScript source map was not emitted');
195
+ const source = await readFile(module.sourceMapPath, 'utf8');
196
+ assert.equal(createHash('sha256').update(source).digest('hex'), module.sourceMapSha256);
197
+ maps.push({id: module.id + '.map', source});
198
+ }
199
+ // Only the separately produced map bytes are placed beside the binary ESM
200
+ // facades. The companion JavaScript implementation remains in its separately
201
+ // identified archive and is never imported as the selected target program.
202
+ await originalProgramSidecars(artifact, {request: {hostSources: maps}, execution: {}});
203
+ return [{role: 'original-compiler-javascript-source-maps', target: 'javascript',
204
+ directory: relative(context.directory, support.directory).split(sep).join('/'), identitySha256: support.identitySha256}];
205
+ }
206
+
207
+ async function executeOriginalProgram(context){
208
+ const {artifact,record,target,sourceRoot,signal}=context;
209
+ const supplied=context.options??{},resources=record.execution.runtimeProfile==='compiler'?independentCompilerResources(supplied):null;
210
+ const configured=resources?{...supplied,profile:resources.profile,budget:resources.budget,memory:resources.memory,auto:resources.auto,runtimeOptions:{...resources.budget,auto:resources.auto,...supplied.runtimeOptions}}:supplied;
211
+ const options={...configured,...(record.memory?{memory:structuredClone(record.memory)}:{}),
212
+ runtimeOptions:{...configured.runtimeOptions,...record.execution.runtimeOptions}};
213
+ context={...context,options};
214
+ const supportingProducts=await originalCompilerSourceMaps(context);
215
+ if(record.execution.zeroImports===true&&target==='wasm'){
216
+ const module=new WebAssembly.Module(new Uint8Array(await readFile(artifact.path)));
217
+ assert.deepEqual(WebAssembly.Module.imports(module),[],'original source graph must remain a zero-import WASM product');
218
+ }
219
+ const reference=await prepareOriginalReferenceArtifact(context);
220
+ if(reference)supportingProducts.push(...reference.supportingProducts);
221
+ const generations=await prepareOriginalCompilerGenerations(context);
222
+ if(generations)supportingProducts.push(...generations.supportingProducts);
223
+ const generationEnvironment=generations?{ELISCRIPT_ORIGINAL_COMPILER_GENERATIONS:generations.manifestPath}:{};
224
+ if(reference)generationEnvironment.ELISCRIPT_ORIGINAL_REFERENCE_PRODUCT_ROOT=reference.directory;
225
+ const javascriptCompanion=supportingProducts.find(item=>item.role==='original-compiler-javascript-source-maps');
226
+ const javascriptDirectory=target==='javascript'?artifact.directory:javascriptCompanion?resolve(context.directory,javascriptCompanion.directory):undefined;
227
+ if(javascriptDirectory!==undefined)generationEnvironment.ELISCRIPT_ORIGINAL_JAVASCRIPT_PRODUCT_ROOT=javascriptDirectory;
228
+ const hostFile=await originalProgramSidecars(artifact,{...record,sourceRoot});
229
+ await originalProgramAliases(artifact,{sourceRoot});
230
+ const directory=artifact.directory??resolve(artifact.path,'..'),entry=resolve(directory,artifact.entry),contract=record.execution;
231
+ const timeoutMs=contract.timeoutByTarget?.[target]??contract.timeoutMs;
232
+ const loader=resolve(sourceRoot,'tests/fixtures/compiled-eli-node-loader.mjs');
233
+ if(contract.hostRuntime!==undefined&&!['node','bun'].includes(contract.hostRuntime))throw new TypeError('original host runtime must be node or bun');
234
+ const bunHost=contract.hostRuntime!==undefined?contract.hostRuntime==='bun':options.programHost==='bun'||contract.requiresBun;
235
+ const command=bunHost?(options.bun??process.env.BUN??'bun'):(options.node??process.env.NODE??'node');
236
+ const preload=bunHost?['--preload',resolve(sourceRoot,'tests/fixtures/compiled-eli-bun-preload.mjs')]:['--experimental-loader',loader];
237
+ if(target==='javascript'){
238
+ let args,env={ELISCRIPT_ORIGINAL_TARGET:target,ELISCRIPT_ORIGINAL_SOURCE_ROOT:sourceRoot,...generationEnvironment};
239
+ if(contract.hostEval){
240
+ const script=resolve(directory,'__eliscript_original_inline.mjs');await writeFile(script,contract.hostEval);
241
+ args=[...preload,script];env[contract.environment]=entry;
242
+ }else args=hostFile?[...preload,hostFile,...originalProgramArguments(contract,artifact.entry,pathToFileURL(directory+'/').href)]:[...preload,entry];
243
+ return{kind:'original-program',stdout:await childOutput(command,args,{cwd:directory,signal,env,timeoutMs}),...(supportingProducts.length?{supportingProducts}:{})};
244
+ }
245
+ // The original host script runs unchanged in the same process as its actual
246
+ // managed runtime. Install prepared cells before loading the script; let its
247
+ // own import evaluate the facade at the original point in its execution.
248
+ const driver=resolve(directory,'__eliscript_original_program.mjs'),configuration=resolve(directory,'__eliscript_original_program.json');
249
+ await saveCompilerMetadata(configuration,{target,path:artifact.path,descriptor:artifact.descriptor,typed:artifact.typed,
250
+ nativeTarget:artifact.nativeTarget??options.nativeTarget??(process.platform==='linux'?'arm64-linux':'arm64-macos'),entry:artifact.entry,host:hostFile,
251
+ argument:contract.argument,arguments:contract.arguments,argumentModules:contract.argumentModules??[artifact.entry],hostEval:contract.hostEval,environment:contract.environment,base:pathToFileURL(directory+'/').href,sourceRoot,childProcesses:contract.childProcesses,runtimeLaunchers:contract.runtimeLaunchers===true,memory:options.memory,runtimeOptions:{...options.runtimeOptions,...(record.auto===undefined?{}:{auto:record.auto}),...(artifact.debug?{debug:artifact.debug}:{})}});
252
+ const contextURL=pathToFileURL(resolve(sourceRoot,'tools/backends/compiler-corpus-host-context.mjs')).href;
253
+ const source=`import {readFile} from 'node:fs/promises';
254
+ import {pathToFileURL,fileURLToPath} from 'node:url';
255
+ import {openOriginalProgramContext,inheritOriginalProgramContext,originalProgramBunLauncher} from ${JSON.stringify(contextURL)};
256
+ import {readCompilerMetadata} from ${JSON.stringify(pathToFileURL(resolve(sourceRoot,'tools/backends/compiler-metadata.mjs')).href)};
257
+ const configuration=${JSON.stringify(configuration)};
258
+ const input=await readCompilerMetadata(configuration);
259
+ const originalProgramArguments=${originalProgramArguments.toString()};
260
+ process.env.ELISCRIPT_ORIGINAL_TARGET=input.target;
261
+ process.env.ELISCRIPT_ORIGINAL_SOURCE_ROOT=input.sourceRoot;
262
+ const context=await openOriginalProgramContext(input,{identity:configuration});
263
+ if(input.childProcesses==='inherit-selected-artifact')inheritOriginalProgramContext({configuration,sourceRoot:input.sourceRoot});
264
+ if(input.runtimeLaunchers){
265
+ const launcher=await originalProgramBunLauncher({directory:fileURLToPath(input.base),bun:process.execPath,configuration,sourceRoot:input.sourceRoot});
266
+ process.env.ELISCRIPT_ORIGINAL_BUN=launcher;
267
+ process.env.ELISCRIPT_JS_RUNTIME=launcher;
268
+ }
269
+
270
+ let failed=false;
271
+ try{
272
+ const entry=new URL(input.entry,input.base);
273
+ if(input.hostEval){process.env[input.environment]=fileURLToPath(entry);await import('data:text/javascript;charset=utf-8,'+encodeURIComponent(input.hostEval));}
274
+ else if(input.host){process.argv=[process.execPath,input.host,...originalProgramArguments(input,input.entry,input.base)];await import(pathToFileURL(input.host));}
275
+ else await import(new URL(context.facades.loadEntry,input.base));
276
+ }catch(error){failed=true;throw error;}finally{
277
+ try{await context.close();}catch(error){if(!failed)throw error;}
278
+ }
279
+ `;
280
+ await writeFile(driver,source);
281
+ return{kind:'original-program',stdout:await childOutput(command,[...preload,driver],{cwd:directory,signal,timeoutMs,env:{ELISCRIPT_ORIGINAL_SOURCE_ROOT:sourceRoot,ELISCRIPT_ORIGINAL_TARGET:target,...generationEnvironment}}),...(supportingProducts.length?{supportingProducts}:{})};
282
+ }
283
+
284
+ // A public compiler-tools corpus runs the emitted complete compiler itself.
285
+ // It must not import its functions as a phased program facade or substitute a
286
+ // JavaScript compiler for a requested binary compiler.
287
+ async function executeCompilerSessionProgram(context){
288
+ const {artifact,record,target,sourceRoot,signal}=context,contract=record.execution;
289
+ const resources=independentCompilerResources(contract.compilerProfile===undefined?context.options??{}:{profile:contract.compilerProfile}),options={...context.options,
290
+ memory:record.memory??resources.memory,runtimeOptions:{...resources.budget,auto:resources.auto,
291
+ ...context.options?.runtimeOptions,...contract.runtimeOptions}};
292
+ if(!['javascript','wasm','native'].includes(target))throw new TypeError('original compiler tools require a real selected compiler target');
293
+ if(!['node','bun'].includes(contract.hostRuntime))throw new TypeError('original compiler tools require their explicit host runtime');
294
+ const directory=artifact.directory??resolve(artifact.path,'..');
295
+ await javascriptEnvironment(artifact,sourceRoot);
296
+ const host=await originalProgramSidecars(artifact,{...record,sourceRoot});
297
+ if(!host)throw new TypeError('original compiler tools require their retained original host source');
298
+ const configuration=resolve(directory,'__eliscript_original_compiler_session.json');
299
+ const supportingDirectory=resolve(context.directory,'original-tool-products');
300
+ const supportingManifest=resolve(context.directory,'original-tool-products.json');
301
+ if(contract.preparationTimeoutMs!==undefined&&(!Number.isSafeInteger(contract.preparationTimeoutMs)||contract.preparationTimeoutMs<=0))
302
+ throw new TypeError('original compiler preparation requires its positive original beforeAll timeout');
303
+ const timeoutMs=contract.preparationTimeoutMs===undefined?contract.timeoutMs:contract.preparationTimeoutMs+contract.timeoutMs;
304
+ await saveCompilerMetadata(configuration,{target,path:artifact.path,sourceRoot,entry:artifact.entry,
305
+ descriptor:artifact.descriptor,typed:artifact.typed,memory:options.memory,
306
+ ...(contract.preparationTimeoutMs===undefined?{}:{preparationTimeoutMs:contract.preparationTimeoutMs}),
307
+ ...(contract.supportingCompilerProducts===true?{supportingDirectory,supportingManifest}:{}),
308
+ runtimeOptions:{...options.runtimeOptions,nativeTarget:artifact.nativeTarget??options.nativeTarget??
309
+ (process.platform==='linux'?'arm64-linux':'arm64-macos'),...(artifact.debug?{debug:artifact.debug}:{})}});
310
+ const command=contract.hostRuntime==='bun'?(options.bun??process.env.BUN??'bun'):(options.node??process.env.NODE??'node');
311
+ const stdout=await childOutput(command,[host],{cwd:sourceRoot,signal,timeoutMs,
312
+ env:{ELISCRIPT_ORIGINAL_SOURCE_ROOT:sourceRoot,ELISCRIPT_ORIGINAL_TARGET:target,
313
+ ELISCRIPT_ORIGINAL_COMPILER_SESSION:configuration}});
314
+ const supportingProducts=[];
315
+ if(contract.supportingCompilerProducts===true){
316
+ const manifest=JSON.parse(await readFile(supportingManifest,'utf8'));
317
+ if(manifest?.format!=='eliscript-original-compiler-supporting-products'||manifest.version!==1||
318
+ !Array.isArray(manifest.products)||!manifest.products.length)throw new TypeError('original compiler tools did not retain their real supporting products');
319
+ const roles=new Set();
320
+ for(const[index,product]of manifest.products.entries()){
321
+ if(typeof product?.role!=='string'||!product.role||roles.has(product.role))throw new TypeError('original compiler supporting product role is missing or duplicate');
322
+ roles.add(product.role);
323
+ const built=product.artifact;
324
+ for(const path of [built?.directory,built?.path]){
325
+ if(typeof path!=='string')throw new TypeError('original compiler supporting product requires actual local files');
326
+ const inside=relative(supportingDirectory,resolve(path));
327
+ if(!inside||isAbsolute(inside)||inside==='..'||inside.startsWith('..'+sep))throw new TypeError('original compiler supporting product escapes its case archive');
328
+ }
329
+ if(built.provenance?.mode!=='session'||normalizeCompilerHost(built.provenance.producerHost)!==target||
330
+ built.provenance.runtimeCompiled!==true||!Array.isArray(built.provenance.compiledModuleIds)||
331
+ !Array.isArray(built.sourceIdentity?.modules)||
332
+ JSON.stringify([...built.provenance.compiledModuleIds].sort())!==JSON.stringify(built.sourceIdentity.modules.map(item=>item.id).sort()))
333
+ throw new Error('original compiler supporting product was not built completely by the selected real compiler');
334
+ const archived=await archiveCompilerArtifact(built,resolve(context.directory,'original-tool-product-'+index+'-metadata'));
335
+ if(!archived.productIdentity?.sha256)throw new Error('original compiler supporting product has no authenticated emitted file identity');
336
+ supportingProducts.push({role:product.role,target:normalizeCompilerHost(built.host),producerHost:target,
337
+ directory:relative(context.directory,built.directory).split(sep).join('/'),identitySha256:archived.productIdentity.sha256});
338
+ }
339
+ }
340
+ return{kind:'original-program',stdout,...(supportingProducts.length?{supportingProducts}:{})};
341
+ }
342
+
343
+ async function executeExports(context, contract){
344
+ const {artifact,target,sourceRoot,options}=context,observations=[];
345
+ if(target==='javascript'){
346
+ if(contract.isolated){
347
+ const url=await javascriptEnvironment(artifact,sourceRoot);
348
+ const script=`import assert from 'node:assert/strict';const m=await import(process.argv[1]),c=JSON.parse(process.argv[2]),out=[];
349
+ const valueRecord=${valueRecord.toString()};
350
+ for(const[name,expected]of Object.entries(c.values??{})){assert.deepEqual(m[name],expected);out.push({name,value:valueRecord(m[name])});}
351
+ for(const call of c.calls??[]){let value,error,failed=false;try{value=await m[call.javascriptName??call.name](...call.args);}catch(e){failed=true;error=e;}
352
+ if(call.error!==undefined){assert(failed);assert.equal(error?.message,call.error);out.push({name:call.name,error:call.error});}
353
+ else{if(failed)throw error;assert.deepEqual(value,call.expected);out.push({name:call.name,value:valueRecord(value)});}}
354
+ process.stdout.write(JSON.stringify(out));`;
355
+ const stdout=await childOutput(options.node??process.env.NODE??'node',['--input-type=module','--eval',script,url,encodeCompilerIR(contract)],{cwd:context.directory,signal:context.signal});
356
+ return JSON.parse(stdout);
357
+ }
358
+ const module=await javascriptModule(artifact,sourceRoot);
359
+ for(const [name,expected]of Object.entries(contract.values??{})){assert.deepEqual(module[name],expected);observations.push({name,value:valueRecord(module[name])});}
360
+ for(const call of contract.calls??[]){
361
+ let value,error,failed=false;try{value=await module[call.javascriptName??call.name](...call.args);}catch(failure){failed=true;error=failure;}
362
+ if(call.error!==undefined){assert(failed,'original exported call must throw');assert.equal(error?.message,call.error);observations.push({name:call.name,error:call.error});}
363
+ else{if(failed)throw error;assert.deepEqual(value,call.expected);observations.push({name:call.name,value:valueRecord(value)});}
364
+ }
365
+ return observations;
366
+ }
367
+ const a=await managedRuntime(artifact,target,{...options,allowHostCapabilities:true});let failed=false;
368
+ try{
369
+ a.auto(contract.auto??65536);
370
+ for(const [name,expected]of Object.entries(contract.values??{})){
371
+ const value=a.getExport(name);try{assert.deepEqual(managedValue(a,value),expected);observations.push({name,value:valueRecord(managedValue(a,value))});}finally{a.release(value);}
372
+ }
373
+ for(const call of contract.calls??[]){
374
+ const args=[];let value,error,callFailed=false;
375
+ try{
376
+ for(const arg of call.args)args.push(box(a,arg));
377
+ try{value=a.invoke(call.name,args);}catch(caught){callFailed=true;error=caught;}
378
+ if(call.error!==undefined){assert(callFailed,'original exported call must throw');assert.equal(error?.message,call.error);observations.push({name:call.name,error:call.error});}
379
+ else{if(callFailed)throw error;const actual=managedValue(a,value);assert.deepEqual(actual,call.expected);observations.push({name:call.name,value:valueRecord(actual)});}
380
+ }finally{a.release(value);args.forEach(arg=>a.release(arg));}
381
+ }
382
+ return observations;
383
+ }catch(error){failed=true;throw error;}
384
+ finally{
385
+ let cleanup,cleanupFailed=false;
386
+ for(const action of[()=>a.closeModule(),()=>a.collect(),()=>assert.equal(a.live(),0),()=>assert.equal(a.stats().frameDepth,0),()=>a.close?.()]){
387
+ try{action();}catch(error){if(!cleanupFailed){cleanupFailed=true;cleanup=error;}}
388
+ }
389
+ if(!failed&&cleanupFailed)throw cleanup;
390
+ }
391
+ }
392
+
393
+ async function executeSequence(context){
394
+ const {record,session,target,options,directory,signal}=context,results=new Map(),products=new Map(),observations=[];let expectedSatisfied=true;
395
+ for(const step of record.steps){
396
+ try{
397
+ const request=fromRecipe(step.request,results);
398
+ if(step.backendTarget!==undefined&&!['wasm','native','javascript'].includes(step.backendTarget))throw new TypeError('original backend diagnostic target is invalid');
399
+ const emission=['project','project-ir','emit-ir','emit-memory-ir','emit-typed-memory'].includes(request.operation);
400
+ if(emission)Object.assign(request,{target:step.backendTarget??request.target??target,
401
+ memory:request.memory??record.memory??options.memory,
402
+ nativeTarget:request.nativeTarget??record.nativeTarget??options.nativeTarget??(process.platform==='linux'?'arm64-linux':'arm64-macos'),
403
+ nativeFormat:request.nativeFormat??'library'});
404
+ let response,error,requestFailed=false;
405
+ try{response=await session.request(request,{signal});}catch(failure){requestFailed=true;error=failure;}
406
+ if(step.error){
407
+ assert(requestFailed,'original request must fail: '+step.id);
408
+ if(step.error.message!==undefined)assert.equal(error?.message,step.error.message);
409
+ if(step.error.contains!==undefined)assert(String(error?.message??error).includes(step.error.contains));
410
+ if(step.error.code!==undefined)assert.equal(error?.eliscriptDiagnostic?.code,step.error.code);
411
+ if(step.error.phase!==undefined)assert.equal(error?.eliscriptDiagnostic?.phase,step.error.phase);
412
+ for(const expected of step.error.expectFields??[]){
413
+ let value=error?.eliscriptDiagnostic;
414
+ for(const key of expected.path)value=value?.[key];
415
+ assert.deepEqual(value,expected.value);
416
+ }
417
+ observations.push({id:step.id,error:diagnostic(error)});continue;
418
+ }
419
+ if(requestFailed)throw error;
420
+ results.set(step.id,response);
421
+ if(Object.hasOwn(step,'expected'))assert.deepEqual(response,step.expected);
422
+ for(const expectation of step.expectFields??[]){let actual=response;for(const key of expectation.path)actual=actual[key];assert.deepEqual(actual,expectation.value);}
423
+ if(step.containsData!==undefined)assert(JSON.parse(response.data).includes(step.containsData));
424
+ for(const text of step.includesJavascript??[])assert(response.javascript.includes(text));
425
+ for(const text of step.excludesJavascript??[])assert(!response.javascript.includes(text));
426
+ if(step.containsField)assert(response[step.containsField.field].includes(step.containsField.text));
427
+ if(step.negativeZeroAt){let value=JSON.parse(response.ir);for(const key of step.negativeZeroAt)value=value[key];assert(Object.is(value,-0));}
428
+ if(step.canonicalEnvelope){assert(response.canonicalIR.startsWith('{"format":"eliscript-ir","program":{"body":'));assert(response.canonicalIR.endsWith('},"version":1}'));}
429
+ if(step.sameFieldsAs){for(const field of step.sameFieldsAs.fields){
430
+ const previous=results.get(step.sameFieldsAs.step)?.[field];
431
+ if(field==='ir')assert.deepEqual(JSON.parse(response[field]),JSON.parse(previous));
432
+ else assert.deepEqual(response[field],previous);
433
+ }}
434
+ let observation=response;
435
+ if(emission){
436
+ const product=response?.target===undefined&&typeof response?.javascript==='string'
437
+ ?{target:'javascript',entry:step.entry??'ir.mjs',modules:[{id:step.entry??'ir.mjs',javascript:response.javascript,
438
+ ...(response.sourceMap===undefined?{}:{sourceMap:response.sourceMap})}]}:response;
439
+ const artifact=await context.archiveProduct(product,'sequence-'+step.id,product.target);products.set(step.id,artifact);
440
+ if(step.sameProductAs)assert.equal(artifact.identitySha256,products.get(step.sameProductAs)?.identitySha256);
441
+ for(const sidecar of step.sidecars??[]){
442
+ if(typeof sidecar.file!=='string'||sidecar.file.split('/').some(part=>!part||part==='.'||part==='..')||/[\\:\u0000]/.test(sidecar.file))throw new Error('original sidecar path is not relative');
443
+ const path=join(resolve(artifact.path,'..'),sidecar.file);await mkdir(resolve(path,'..'),{recursive:true});await writeFile(path,sidecar.source,{flag:'wx'});
444
+ }
445
+ if(step.artifact?.kind==='exports')observation=await executeExports({...context,artifact,target:artifact.target},step.artifact);
446
+ else if(step.artifact?.kind==='original-program') {
447
+ observation=await executeOriginalProgram({...context,artifact,target:artifact.target,
448
+ record:{...record,entry:artifact.entry,request,execution:{...step.artifact}}});
449
+ }
450
+ else if(step.artifact?.kind==='stdout'){
451
+ let stdout;
452
+ if(artifact.target==='javascript'){
453
+ await javascriptEnvironment(artifact,context.sourceRoot);
454
+ stdout=await childOutput(options.node??process.env.NODE??'node',[artifact.path],{cwd:directory,signal});
455
+ }else{
456
+ const chunks=[],output=new Writable({write(chunk,encoding,complete){chunks.push(Buffer.from(chunk));complete();}});
457
+ const logger=new Console({stdout:output,stderr:output,colorMode:false});
458
+ const a=await managedRuntime(artifact,artifact.target,{...options,allowHostCapabilities:true,runtimeOptions:{...options.runtimeOptions,console:logger}});
459
+ let cleanup;
460
+ for(const action of[()=>a.closeModule(),()=>a.collect(),()=>assert.equal(a.live(),0),()=>assert.equal(a.stats().frameDepth,0),()=>a.close?.(),()=>output.end()]){
461
+ try{action();}catch(error){cleanup??=error;}
462
+ }
463
+ if(cleanup)throw cleanup;
464
+ stdout=Buffer.concat(chunks).toString('utf8');
465
+ }
466
+ assert.equal(stdout,step.artifact.expected);observation={stdout};
467
+ }else observation={productIdentitySha256:artifact.identitySha256};
468
+ }
469
+ observations.push({id:step.id,result:valueRecord(observation)});
470
+ }catch(error){if(signal?.aborted)throw signal.reason===undefined?error:signal.reason;expectedSatisfied=false;observations.push({id:step.id,status:'failed',error:diagnostic(error)});}
471
+ }
472
+ return{kind:'sequence',expectedSatisfied,identity:observations};
473
+ }
474
+
475
+ function diagnostic(error) {
476
+ return {kind: 'diagnostic', name: error?.name ?? 'Error', message: error?.message ?? String(error),
477
+ ...(error?.eliscriptDiagnostic !== undefined ? {diagnostic: structuredClone(error.eliscriptDiagnostic)} : {})};
478
+ }
479
+
480
+ // These are the original independent acceptance oracles, not a compilation
481
+ // fallback. Each full fixture is evaluated once and its cases retain order.
482
+ export function createOriginalSeedOracle({sourceRoot, emacs = process.env.EMACS ?? 'emacs', signal,directory,node,bun,programHost,profile,budget,memory,auto,nativeTarget,sessionOptions} = {}) {
483
+ const suites = new Map();
484
+ return async ({record,target}) => {
485
+ if(record.expected?.kind==='seed-program'){
486
+ if(typeof directory!=='string')throw new TypeError('original program Seed oracle requires an explicit evidence directory');
487
+ const originalHost=record.execution?.hostRuntime??(programHost==='bun'||record.execution?.requiresBun?'bun':'node');
488
+ const key='program:'+record.id+':'+originalHost;
489
+ if(!suites.has(key))suites.set(key,(async()=>{
490
+ const output=resolve(directory,createHash('sha256').update(key).digest('hex')),product=resolve(output,'product'),modules=[];
491
+ await mkdir(product,{recursive:true});
492
+ for(const item of record.modules){
493
+ const input=resolve(output,'sources',item.filename),path=resolve(product,item.id);
494
+ await mkdir(resolve(input,'..'),{recursive:true});await writeFile(input,item.source);
495
+ await mkdir(resolve(path,'..'),{recursive:true});
496
+ await childOutput(resolve(sourceRoot,'bin/eliscript-seed'),['--source-map','--output',path,input],{cwd:sourceRoot,signal});
497
+ modules.push({id:item.id,path});
498
+ }
499
+ const artifact={target:'javascript',entry:record.entry,path:resolve(product,record.entry),directory:product,modules};
500
+ const options={programHost:originalHost,node,bun,profile,budget,memory,auto,nativeTarget,sessionOptions};
501
+ const {archiveProduct}=await import('./compiler-matrix.mjs');
502
+ const programContext={artifact,record,target:'javascript',sourceRoot,signal,options,directory:output,
503
+ archiveProduct:async(value,name='product',productTarget='javascript')=>archiveProduct(value,productTarget,resolve(output,name))};
504
+ if(record.execution?.kind==='compiler-session-program')return executeCompilerSessionProgram(programContext);
505
+ if(!record.execution?.compilerGenerations)return executeOriginalProgram(programContext);
506
+ // This is the separate independent oracle, never a replacement for a
507
+ // selected producer that failed. Build its actual seed driver before
508
+ // reconstructing all three JavaScript successor generations.
509
+ const seed=await buildIndependentCompiler({host:'javascript',sourceRoot,outputRoot:resolve(output,'independent-seed-compiler'),
510
+ profile:profile??'small',budget,memory,auto,nativeTarget,retainIR:true,debug:true,signal});
511
+ const session=await openCompilerArtifact(seed,sessionOptions);let failed=false;
512
+ try{
513
+ return await executeOriginalProgram({...programContext,session});
514
+ }catch(error){failed=true;throw error;}
515
+ finally{try{await session.close();}catch(error){if(!failed)throw error;}}
516
+ })());
517
+ return suites.get(key);
518
+ }
519
+ if (record.kind !== 'stage' || record.original?.manifest !== 'compiler-parity' && !record.original?.oracleCase) return undefined;
520
+ const stage = record.request.stage;
521
+ const inline=record.original.oracleCase;
522
+ if(inline){
523
+ if(stage!=='emitter'||typeof directory!=='string'||typeof inline.name!=='string'||typeof inline.filename!=='string'||
524
+ inline.source!==record.request.source||inline.filename!==record.request.filename||typeof inline.source!=='string'||
525
+ typeof record.original.suite!=='string'||typeof record.original.sourceSha256!=='string')throw new TypeError('inline original Seed case requires its exact source and bound original suite');
526
+ const path=resolve(sourceRoot,record.original.suite),part=relative(resolve(sourceRoot),path);
527
+ if(isAbsolute(part)||part==='..'||part.startsWith('..'+sep)||
528
+ createHash('sha256').update(await readFile(path)).digest('hex')!==record.original.sourceSha256)
529
+ throw new Error('inline original Seed suite bytes changed');
530
+ }
531
+ const key = stage + ':' + (inline?createHash('sha256').update(JSON.stringify({inline,suite:record.original.suite,sha256:record.original.sourceSha256})).digest('hex'):record.original.fixture);
532
+ if (!suites.has(key)) suites.set(key, (async()=>{
533
+ let fixture=inline?resolve(directory,'inline-'+key.slice(stage.length+1)+'.json'):resolve(sourceRoot,record.original.fixture);
534
+ if(inline){await mkdir(directory,{recursive:true});await writeFile(fixture,encodeCompilerMetadata({valid:[inline],invalid:[]})+'\n',{flag:'wx'});}
535
+ return new Promise((accept, reject) => {
536
+ const script = 'tests/bootstrap-' + stage + '-oracle.el';
537
+ const child = spawn(emacs, ['--batch', '-Q', '-L', 'compiler', '-L', 'tests', '--script', script], {
538
+ cwd: sourceRoot, signal,
539
+ env: {...process.env, ['ELISCRIPT_' + stage.toUpperCase() + '_FIXTURE']: fixture},
540
+ stdio: ['ignore', 'pipe', 'pipe'],
541
+ });
542
+ const stdout = [], stderr = [];
543
+ child.stdout.on('data', chunk => stdout.push(chunk));
544
+ child.stderr.on('data', chunk => stderr.push(chunk));
545
+ child.once('error', reject);
546
+ child.once('close', code => {
547
+ if (code !== 0) {reject(new Error(Buffer.concat(stderr).toString('utf8').trim() || 'original Seed oracle exited with ' + code));return;}
548
+ try {const values = JSON.parse(Buffer.concat(stdout).toString('utf8'));assert(Array.isArray(values));accept(values);} catch (error) {reject(error);}
549
+ });
550
+ });})());
551
+ const values = await suites.get(key);
552
+ const originalName = inline?.name??record.original.case.name;
553
+ const found = values.filter(value => value.name === originalName);
554
+ if (found.length !== 1) throw new Error('original Seed oracle case identity differs: ' + originalName);
555
+ return {kind: 'original-seed', stage, result: found[0]};
556
+ };
557
+ }
558
+
559
+ async function javascriptEnvironment(artifact, sourceRoot) {
560
+ // Supply the package's real runtime exports; compiler algorithms still come
561
+ // exclusively from the selected session and its emitted artifact.
562
+ const modules = join(resolve(artifact.path, '..'), 'node_modules');
563
+ await mkdir(modules, {recursive: true});
564
+ try {await symlink(resolve(sourceRoot), join(modules, 'eliscript'), 'dir');}
565
+ catch (error) {if (error.code !== 'EEXIST') throw error;}
566
+ return pathToFileURL(artifact.path).href;
567
+ }
568
+
569
+ async function javascriptModule(artifact,sourceRoot){return import(await javascriptEnvironment(artifact,sourceRoot));}
570
+
571
+ async function managedRuntime(artifact, target, options) {
572
+ if(!options.allowHostCapabilities)assert.equal(artifact.descriptor?.hostCapabilities?.length??0,0,'original pure corpus declares no host capabilities');
573
+ const runtimeOptions={...options.runtimeOptions,
574
+ ...(artifact.debug?{debug:artifact.debug}:{}),
575
+ moduleBaseURL:options.moduleBaseURL??pathToFileURL(artifact.path).href,
576
+ projectModuleBaseURL:options.projectModuleBaseURL??pathToFileURL(resolve(artifact.path,'..')+'/').href,
577
+ projectEntry:artifact.entry,
578
+ importModule:options.importModule??options.runtimeOptions?.importModule,
579
+ hostModules:options.hostModules??options.runtimeOptions?.hostModules};
580
+ if (target === 'wasm') {
581
+ const bytes = new Uint8Array(await readFile(artifact.path));
582
+ const module = new WebAssembly.Module(bytes);
583
+ if(!options.allowHostCapabilities)assert.deepEqual(WebAssembly.Module.imports(module), [], 'original pure corpus requires zero imports');
584
+ return options.allowHostCapabilities?instantiateManagedRuntimeWithHostModules(bytes,runtimeOptions):instantiateManagedRuntime(bytes,runtimeOptions);
585
+ }
586
+ const {instantiateNativeManagedRuntime} = await import('./native-managed-runtime.mjs');
587
+ return instantiateNativeManagedRuntime(artifact.path, {typed: artifact.typed, descriptor: artifact.descriptor},
588
+ {...options.memory, ...runtimeOptions, nativeTarget: artifact.nativeTarget ?? options.nativeTarget ?? (process.platform === 'linux' ? 'arm64-linux' : 'arm64-macos')});
589
+ }
590
+
591
+ async function executeBehavior({record, artifact, target, sourceRoot, options}) {
592
+ const scenario = record.execution.scenario;
593
+ if (target === 'javascript') {
594
+ const module = await javascriptModule(artifact, sourceRoot);
595
+ if (scenario.runtimeError) {
596
+ let thrown;
597
+ try {module.run();} catch (error) {thrown = error;}
598
+ assert(thrown, 'original scenario must throw');
599
+ assert.equal(thrown.name, scenario.jsError);
600
+ if (scenario.runtimeError === 'ELI-RT0009') assert.equal(thrown.eliscriptDiagnostic?.code, scenario.runtimeError);
601
+ if (Object.hasOwn(scenario, 'recover')) assert.deepEqual(module.recover(), scenario.recover);
602
+ return {kind: 'managed-bdd', expectedSatisfied: true, error: diagnostic(thrown),
603
+ ...(Object.hasOwn(scenario, 'recover') ? {recovery: valueRecord(scenario.recover)} : {})};
604
+ }
605
+ const result = module.run();
606
+ assert.deepEqual(result, scenario.expected);
607
+ return {kind: 'managed-bdd', expectedSatisfied: true, value: valueRecord(result)};
608
+ }
609
+ const a = await managedRuntime(artifact, target, options);
610
+ let failure;
611
+ try {
612
+ a.auto(record.auto);
613
+ if (scenario.runtimeError) {
614
+ let thrown;
615
+ try {const value = a.invoke('run');a.release(value);} catch (error) {thrown = error;}
616
+ assert(thrown, 'original scenario must throw');
617
+ assert.equal(thrown.eliscriptDiagnostic?.code, scenario.runtimeError);
618
+ if (scenario.wasmError) assert.equal(thrown.name, scenario.wasmError);
619
+ assert.equal(a.stats().frameDepth, 0);
620
+ if (Object.hasOwn(scenario, 'recover')) {
621
+ const value = a.invoke('recover');
622
+ try {assert.deepEqual(managedValue(a, value), scenario.recover);} finally {a.release(value);}
623
+ }
624
+ return {kind: 'managed-bdd', expectedSatisfied: true, error: diagnostic(thrown),
625
+ ...(Object.hasOwn(scenario, 'recover') ? {recovery: valueRecord(scenario.recover)} : {})};
626
+ }
627
+ const value = a.invoke('run');
628
+ let result;
629
+ try {result = managedValue(a, value);assert.deepEqual(result, scenario.expected);} finally {a.release(value);}
630
+ return {kind: 'managed-bdd', expectedSatisfied: true, value: valueRecord(result)};
631
+ } catch (error) {failure = error; throw error;}
632
+ finally {
633
+ let cleanupError;
634
+ for (const action of [() => a.closeModule(), () => a.collect(), () => assert.equal(a.live(), 0),
635
+ () => assert.equal(a.stats().frameDepth, 0), () => a.close?.()]) {
636
+ try {action();} catch (error) {cleanupError ??= error;}
637
+ }
638
+ if (!failure && cleanupError) throw cleanupError;
639
+ }
640
+ }
641
+
642
+ async function executeUnicodeProfile(context){
643
+ const {record,artifact,target,sourceRoot,options}=context,profile=record.execution.profile;
644
+ const a=target==='javascript'?null:await managedRuntime(artifact,target,{...options,runtimeOptions:{...options.runtimeOptions,unicodeVersion:profile.version}});
645
+ let module,failure;
646
+ try{
647
+ if(a)a.auto(record.auto);else module=await javascriptModule(artifact,sourceRoot);
648
+ const convert=(name,text)=>{
649
+ if(!a)return module[name](text);
650
+ const input=a.string(text);let output;
651
+ try{output=a.invoke(name,[input]);return a.readString(output);}finally{a.release(output);a.release(input);}
652
+ };
653
+ const hashes={upper:createHash('sha256'),lower:createHash('sha256')};let checked=0;
654
+ for(let start=0;start<0x110000;start+=512){
655
+ const points=[];for(let point=start;point<Math.min(start+512,0x110000);point++)if(point<0xd800||point>0xdfff)points.push(point);
656
+ checked+=points.length;const input=String.fromCodePoint(...points);
657
+ for(const name of['upper','lower'])hashes[name].update(convert(name,input),'utf16le');
658
+ }
659
+ assert.equal(checked,0x110000-0x800);
660
+ const actual={};for(const name of['upper','lower']){actual[name]=hashes[name].digest('hex');assert.equal(actual[name],profile[name]);}
661
+ for(const [text,expected]of profile.sigma)assert.equal(convert('lower',text),expected);
662
+ return{kind:'unicode-profile',expectedSatisfied:true,version:profile.version,checked,sigmaCases:profile.sigma.length,hashes:actual};
663
+ }catch(error){failure=error;throw error;}
664
+ finally{
665
+ if(a){let cleanup;for(const action of[()=>a.closeModule(),()=>a.collect(),()=>assert.equal(a.live(),0),()=>assert.equal(a.stats().frameDepth,0),()=>a.close?.()]){
666
+ try{action();}catch(error){cleanup??=error;}
667
+ }if(!failure&&cleanup)throw cleanup;}
668
+ }
669
+ }
670
+
671
+ // Called only by the production matrix driver. Defining this module never
672
+ // executes a fixture or loads a compiler artifact.
673
+ export async function executeCompilerCorpusRecord(context) {
674
+ const {record, response, failure, target, options = {}} = context;
675
+ if (Object.hasOwn(context,'failure')) return diagnostic(failure);
676
+ if (record.kind === 'stage') {
677
+ if (response?.stage !== record.request.stage || response?.filename !== record.request.filename || typeof response.data !== 'string') {
678
+ throw new TypeError('compiler stage did not return its lossless data envelope');
679
+ }
680
+ JSON.parse(response.data);
681
+ return {kind: 'stage', stage: response.stage, filename: response.filename, data: response.data};
682
+ }
683
+ if(record.kind==='sequence')return executeSequence(context);
684
+ if (record.kind === 'original-suite') {
685
+ if (typeof options.executeOriginalFixture !== 'function') {
686
+ return {kind: 'original-suite', status: 'executor-required', requiredLocatorIds: record.expected.requiredLocatorIds};
687
+ }
688
+ const observation = await options.executeOriginalFixture(context);
689
+ if (observation?.status !== 'executed' || !Array.isArray(observation.executedLocatorIds)) {
690
+ throw new TypeError('original-suite executor must report actual executed locator identities');
691
+ }
692
+ assert.deepEqual([...observation.executedLocatorIds].sort(), [...record.expected.requiredLocatorIds].sort());
693
+ return observation;
694
+ }
695
+ if (record.execution?.kind === 'managed-bdd') return executeBehavior({...context, target, options});
696
+ if(record.execution?.kind==='unicode-profile')return executeUnicodeProfile({...context,options});
697
+ if(record.execution?.kind==='original-program')return executeOriginalProgram({...context,options});
698
+ if(record.execution?.kind==='compiler-session-program')return executeCompilerSessionProgram({...context,options});
699
+ return {kind: 'unsupported-execution', status: 'executor-required'};
700
+ }
701
+
702
+ export async function compareCompilerCorpusObservation({record, observation, target, options = {}}) {
703
+ const expected = record.expected;
704
+ if(expected?.kind==='seed-program'){
705
+ if(observation?.kind!=='original-program')return{status:'different',reason:'original complete program did not execute'};
706
+ if(Object.hasOwn(expected,'stdout')&&observation.stdout!==expected.stdout)return{status:'different',reason:'original frozen stdout differs'};
707
+ if(Object.hasOwn(expected,'stdoutJSON')){
708
+ try{assert.deepEqual(JSON.parse(observation.stdout),expected.stdoutJSON);}catch{return{status:'different',reason:'original inline host data assertion differs'};}
709
+ }
710
+ if(typeof options.originalOracle!=='function')return{status:'unverified',reason:'original program Seed oracle is required'};
711
+ try{
712
+ const oracle=await options.originalOracle({record:structuredClone(record),target});
713
+ return oracle?.kind==='original-program'&&oracle.stdout===observation.stdout?{status:'equivalent',oracle:record.original.host??record.original.fixture}:{status:'different',reason:'original complete program or host observation differs'};
714
+ }catch(error){return{status:'unverified',reason:'original complete program Seed oracle did not finish',failure:diagnostic(error)};}
715
+ }
716
+ if(expected?.kind==='unicode-profile')return observation?.kind==='unicode-profile'&&observation.expectedSatisfied===true
717
+ ?{status:'equivalent',oracle:record.original.fixture}:{status:'different',reason:'original complete Unicode profile observation differs'};
718
+ if(expected?.kind==='sequence')return observation?.kind==='sequence'&&observation.expectedSatisfied===true
719
+ ?{status:'equivalent',oracle:record.original.suite}:{status:'different',reason:'original request sequence did not complete'};
720
+ if (expected?.kind === 'diagnostic') {
721
+ if (observation?.kind !== 'diagnostic' || observation.message !== expected.message) return {status: 'different', reason: 'original diagnostic message differs'};
722
+ if (expected.diagnostic !== undefined) {
723
+ try {assert.deepEqual(observation.diagnostic, expected.diagnostic);} catch {return {status: 'different', reason: 'original structured diagnostic differs'};}
724
+ }
725
+ return {status: 'equivalent', oracle: record.original.fixture};
726
+ }
727
+ if (expected?.kind === 'managed-bdd') {
728
+ const scenario = expected.scenario;
729
+ if (scenario.compileError && target !== 'javascript') {
730
+ return observation?.kind === 'diagnostic' && observation.diagnostic?.code === scenario.compileError &&
731
+ observation.diagnostic?.location?.file === record.modules[0].filename && observation.diagnostic?.location?.start?.line >= 2
732
+ ? {status: 'equivalent', oracle: record.original.fixture}
733
+ : {status: 'different', reason: 'original managed compile refusal differs'};
734
+ }
735
+ return observation?.kind === 'managed-bdd' && observation.expectedSatisfied === true
736
+ ? {status: 'equivalent', oracle: record.original.fixture}
737
+ : {status: 'different', reason: 'original behavior scenario did not complete'};
738
+ }
739
+ if (expected?.kind === 'original-suite') {
740
+ if(observation?.kind === 'diagnostic') return {status: 'different', reason: 'original suite execution failed'};
741
+ return observation?.status === 'executed' && observation.verification === 'equivalent'
742
+ ? {status: 'equivalent', oracle: 'original-suite-executor'}
743
+ : {status: 'unverified', reason: 'original suite execution and comparison are still required'};
744
+ }
745
+ if (expected?.oracleRequired) {
746
+ if(observation?.kind !== 'stage') return {status: 'different', reason: 'original accepted stage failed'};
747
+ if (typeof options.originalOracle !== 'function') return {status: 'unverified', reason: 'original Seed observation is required'};
748
+ let oracle;
749
+ try {oracle = await options.originalOracle({record: structuredClone(record), target});}
750
+ catch (error) {return {status: 'unverified', reason: 'original Seed oracle could not complete', failure: diagnostic(error)};}
751
+ if (oracle === undefined) return {status: 'unverified', reason: 'original oracle did not supply this case'};
752
+ try {
753
+ if (oracle.kind === 'original-seed') {
754
+ assert.equal(oracle.stage, record.request.stage);
755
+ assert.equal(oracle.result.status, 'ok');
756
+ assert.equal(observation.kind, 'stage');
757
+ const data = JSON.parse(observation.data);
758
+ if (oracle.stage === 'reader' || oracle.stage === 'expander') assert.deepEqual(data, oracle.result.forms);
759
+ else if (oracle.stage === 'ir') assert.deepEqual(data, oracle.result.program);
760
+ else if (oracle.stage === 'emitter') assert.deepEqual(data, {javascript: oracle.result.javascript, sourceMap: oracle.result.sourceMap});
761
+ else if (oracle.stage !== 'analyzer') throw new Error('unrepresented original Seed stage');
762
+ // The original analyzer fixture compares acceptance and diagnostics;
763
+ // cross-host stage identity separately covers its actual analysis data.
764
+ } else assert.deepEqual(observation, oracle);
765
+ return {status: 'equivalent', oracle: 'original-seed'};
766
+ } catch {return {status: 'different', reason: 'original Seed observation differs'};}
767
+ }
768
+ return {status: 'unverified', reason: 'no original observation contract was supplied'};
769
+ }