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,654 @@
1
+ #!/usr/bin/env node
2
+ import {copyFile, mkdir, open, readFile, readdir, rename, rm, writeFile} from 'node:fs/promises';
3
+ import {resolve, dirname, isAbsolute, relative, sep} from 'node:path';
4
+ import {fileURLToPath} from 'node:url';
5
+ import {createHash, randomUUID} from 'node:crypto';
6
+ import {createReadStream} from 'node:fs';
7
+ import {parseArgs} from 'node:util';
8
+ import {root} from './build.mjs';
9
+ import {writeCompilerMetadata} from './compiler-build.mjs';
10
+ import {readCompilerMetadata} from './compiler-metadata.mjs';
11
+
12
+ const packageLoader = String.raw`import {createCompilerSession} from './transport/backends/compiler-session.mjs';
13
+ import {createCompilerMetadataDecoder} from './transport/backends/compiler-metadata.mjs';
14
+ import {createCompilerSha256} from './transport/backends/compiler-sha256.mjs';
15
+ import {ownCompilerDebugDocument} from './transport/backends/compiler-debug.mjs';
16
+
17
+ function checkIdentity(identity, label) {
18
+ if (!identity || !Number.isSafeInteger(identity.bytes) || identity.bytes < 0 ||
19
+ typeof identity.sha256 !== 'string' || !/^[0-9a-f]{64}$/.test(identity.sha256)) {
20
+ throw new TypeError('compiler package has an invalid file identity: ' + label);
21
+ }
22
+ return identity;
23
+ }
24
+ function relativeResource(path, base) {
25
+ if (typeof path !== 'string' || !path || /[\\%?#\u0000]/.test(path) ||
26
+ /^[a-z][a-z0-9+.-]*:/i.test(path) || path.startsWith('/') ||
27
+ path.split('/').some(part => !part || part === '.' || part === '..')) {
28
+ throw new TypeError('compiler package resource must have a relative path');
29
+ }
30
+ const url = new URL(path, base), directory = new URL('.', base);
31
+ if (url.protocol !== directory.protocol || url.origin !== directory.origin ||
32
+ !url.href.startsWith(directory.href)) throw new TypeError('compiler package resource escapes its directory');
33
+ return url;
34
+ }
35
+ async function resourceHash() {
36
+ if (typeof process !== 'undefined' && (process.versions?.node || process.versions?.bun)) {
37
+ const {createHash} = await import('node:crypto');
38
+ const hash = createHash('sha256');
39
+ return {update: bytes => hash.update(bytes), digestHex: () => hash.digest('hex')};
40
+ }
41
+ return createCompilerSha256();
42
+ }
43
+ async function sha256(bytes) {
44
+ const hash = await resourceHash();hash.update(bytes);return hash.digestHex();
45
+ }
46
+ // The consumer owns only its bounded chunk or final decoded value. Successful
47
+ // native verification must not leave a complete, otherwise unused image in a
48
+ // package cache beside the platform loader's image.
49
+ async function streamResource(url, fetchResource, consume, finish) {
50
+ if (url.protocol === 'file:') {
51
+ const {open} = await import('node:fs/promises');
52
+ const file = await open(url, 'r');let failed = false;
53
+ try {
54
+ const buffer = new Uint8Array(65536);
55
+ for (;;) {
56
+ const {bytesRead} = await file.read(buffer, 0, buffer.length, null);
57
+ if (!bytesRead) break;
58
+ consume(buffer.subarray(0, bytesRead));
59
+ }
60
+ return finish();
61
+ } catch (error) {failed = true;throw error;}
62
+ finally {try {await file.close();} catch (error) {if (!failed) throw error;}}
63
+ }
64
+ if (!['http:', 'https:'].includes(url.protocol)) throw new TypeError('unsupported compiler package resource protocol');
65
+ if (typeof fetchResource !== 'function') throw new TypeError('compiler package requires fetch');
66
+ const response = await fetchResource(url);
67
+ if (!response.ok) throw new Error('compiler resource failed: ' + response.status);
68
+ // Preserve legacy fetch adapters; actual streaming responses never enter
69
+ // this full-buffer fallback.
70
+ if (response.body == null) {consume(new Uint8Array(await response.arrayBuffer()));return finish();}
71
+ const reader = response.body.getReader();let failed = false;
72
+ try {
73
+ for (;;) {
74
+ const part = await reader.read();
75
+ if (part.done) break;
76
+ consume(part.value);
77
+ }
78
+ return finish();
79
+ } catch (error) {
80
+ failed = true;
81
+ try {await reader.cancel(error);} catch {}
82
+ throw error;
83
+ } finally {try {reader.releaseLock();} catch (error) {if (!failed) throw error;}}
84
+ }
85
+ async function resourceVerifier(identity, url) {
86
+ const hash = await resourceHash();let bytes = 0;
87
+ return {
88
+ consume(chunk) {
89
+ if (!(chunk instanceof Uint8Array)) throw new TypeError('compiler package stream requires Uint8Array chunks');
90
+ hash.update(chunk);bytes += chunk.byteLength;
91
+ if (!Number.isSafeInteger(bytes)) throw new RangeError('compiler package resource byte count exceeds safe integer range');
92
+ },
93
+ finish() {
94
+ const digest = hash.digestHex();
95
+ if (identity !== undefined) {
96
+ checkIdentity(identity, url.href);
97
+ if (bytes !== identity.bytes) throw new Error('compiler package resource byte count mismatch: ' + url.href);
98
+ if (digest !== identity.sha256) throw new Error('compiler package resource SHA-256 mismatch: ' + url.href);
99
+ }
100
+ },
101
+ };
102
+ }
103
+ async function verifyResource(url, fetchResource, identity) {
104
+ const verifier = await resourceVerifier(identity, url);
105
+ await streamResource(url, fetchResource, chunk => verifier.consume(chunk), () => verifier.finish());
106
+ }
107
+ async function readSourceResource(url, fetchResource, identity, resources, formats, encoding = 'utf8') {
108
+ const key = 'source:' + url.href;
109
+ let pending = resources.get(key);
110
+ if (!pending) {
111
+ pending = (async () => {
112
+ const verifier = await resourceVerifier(identity, url);
113
+ const variants = new Map();
114
+ let decoder, failed = false, failure;
115
+ if (formats.has('utf8') || formats.has('json-utf16')) {
116
+ try {decoder = new TextDecoder('utf-8', {fatal: true, ignoreBOM: true});}
117
+ catch (error) {failed = true;failure = error;}
118
+ }
119
+ for (const format of formats) {
120
+ let variant;
121
+ if (format === 'utf8') variant = {blocks: []};
122
+ else if (format === 'json-utf16') {
123
+ try {variant = {parser: createCompilerMetadataDecoder()};}
124
+ catch (error) {variant = {failed: true, error};}
125
+ } else variant = {failed: true, error: new TypeError('unsupported compiler source asset encoding')};
126
+ variants.set(format, variant);
127
+ }
128
+ const text = value => {
129
+ for (const variant of variants.values()) if (!variant.failed) {
130
+ if (variant.blocks) variant.blocks.push(value);
131
+ else try {variant.parser.write(value);} catch (error) {variant.failed = true;variant.error = error;variant.parser = undefined;}
132
+ }
133
+ };
134
+ const consume = chunk => {
135
+ verifier.consume(chunk);
136
+ if (decoder && !failed) try {
137
+ for (let offset = 0; offset < chunk.length; offset += 65536)
138
+ text(decoder.decode(chunk.subarray(offset, offset + 65536), {stream: true}));
139
+ } catch (error) {failed = true;failure = error;}
140
+ };
141
+ const finish = () => {
142
+ // Hash/length failures retain priority over every decode failure.
143
+ verifier.finish();
144
+ if (decoder && !failed) try {text(decoder.decode());} catch (error) {failed = true;failure = error;}
145
+ for (const [format, variant] of variants) {
146
+ // An unsupported encoding failed before UTF8 decoding in the public
147
+ // asset codec. Keep that order even for malformed bytes.
148
+ if (failed && (format === 'utf8' || format === 'json-utf16')) {variant.failed = true;variant.error = failure;}
149
+ if (!variant.failed) try {
150
+ variant.value = format === 'utf8' ? variant.blocks.join('') : variant.parser.finish();
151
+ if (typeof variant.value !== 'string') throw new TypeError('encoded compiler source asset must contain a JSON string');
152
+ } catch (error) {variant.failed = true;variant.error = error;}
153
+ variant.blocks = undefined;variant.parser = undefined;
154
+ }
155
+ return variants;
156
+ };
157
+ // A binary also declared as source still consumes its already verified
158
+ // bytes once. Ordinary source assets never allocate a complete byte view.
159
+ if (resources.has(url.href)) {
160
+ const bytes = await readResource(url, fetchResource, identity, resources);
161
+ consume(bytes);const result = finish();resources.delete(url.href);return result;
162
+ }
163
+ return streamResource(url, fetchResource, consume, finish);
164
+ })();
165
+ resources.set(key, pending);
166
+ }
167
+ let variants;
168
+ try {variants = await pending;}
169
+ catch (error) {if (resources.get(key) === pending) resources.delete(key);throw error;}
170
+ const result = variants.get(encoding);
171
+ if (!result) throw new TypeError('unsupported compiler source asset encoding');
172
+ if (result.failed) throw result.error;
173
+ return result.value;
174
+ }
175
+ async function readResource(url, fetchResource, identity, resources) {
176
+ const key = url.href;
177
+ let pending = resources.get(key);
178
+ if (!pending) {
179
+ pending = (async () => {
180
+ let bytes;
181
+ if (url.protocol === 'file:') {
182
+ const {readFile} = await import('node:fs/promises');
183
+ const data = await readFile(url);
184
+ // This read owns its buffer; verification and consumption share the
185
+ // exact view instead of copying an entire binary or metadata file.
186
+ bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
187
+ } else {
188
+ if (!['http:', 'https:'].includes(url.protocol)) throw new TypeError('unsupported compiler package resource protocol');
189
+ if (typeof fetchResource !== 'function') throw new TypeError('compiler package requires fetch');
190
+ const response = await fetchResource(url);
191
+ if (!response.ok) throw new Error('compiler resource failed: ' + response.status);
192
+ bytes = new Uint8Array(await response.arrayBuffer());
193
+ }
194
+ return {bytes, digest: undefined};
195
+ })();
196
+ resources.set(key, pending);
197
+ }
198
+ try {
199
+ const resource = await pending;
200
+ if (identity !== undefined) {
201
+ checkIdentity(identity, key);
202
+ if (resource.bytes.byteLength !== identity.bytes) throw new Error('compiler package resource byte count mismatch: ' + key);
203
+ resource.digest ??= sha256(resource.bytes);
204
+ if (await resource.digest !== identity.sha256) throw new Error('compiler package resource SHA-256 mismatch: ' + key);
205
+ }
206
+ return resource.bytes;
207
+ } catch (error) {
208
+ if (resources.get(key) === pending) resources.delete(key);
209
+ throw error;
210
+ }
211
+ }
212
+ async function readMetadataResource(url, fetchResource, identity, resources) {
213
+ const key = 'metadata:' + url.href;
214
+ let pending = resources.get(key);
215
+ if (!pending) {
216
+ pending = (async () => {
217
+ const hash = await resourceHash(), utf8 = new TextDecoder('utf-8', {fatal: true});
218
+ const parser = createCompilerMetadataDecoder();
219
+ let bytes = 0, decodeFailed = false, decodeError;
220
+ function consume(chunk) {
221
+ if (!(chunk instanceof Uint8Array)) throw new TypeError('compiler package stream requires Uint8Array chunks');
222
+ hash.update(chunk);bytes += chunk.byteLength;
223
+ if (!Number.isSafeInteger(bytes)) throw new RangeError('compiler package resource byte count exceeds safe integer range');
224
+ // Verify the complete original byte stream even after malformed JSON.
225
+ // A corrupt resource must still report its identity failure first.
226
+ if (!decodeFailed) try {
227
+ for (let offset = 0; offset < chunk.length; offset += 65536) {
228
+ parser.write(utf8.decode(chunk.subarray(offset, offset + 65536), {stream: true}));
229
+ }
230
+ } catch (error) {decodeFailed = true;decodeError = error;}
231
+ }
232
+ function finish() {
233
+ const digest = hash.digestHex();
234
+ if (identity !== undefined) {
235
+ checkIdentity(identity, url.href);
236
+ if (bytes !== identity.bytes) throw new Error('compiler package resource byte count mismatch: ' + url.href);
237
+ if (digest !== identity.sha256) throw new Error('compiler package resource SHA-256 mismatch: ' + url.href);
238
+ }
239
+ if (decodeFailed) throw decodeError;
240
+ parser.write(utf8.decode());
241
+ return parser.finish();
242
+ }
243
+ return streamResource(url, fetchResource, consume, finish);
244
+ })();
245
+ resources.set(key, pending);
246
+ }
247
+ try {return await pending;}
248
+ catch (error) {if (resources.get(key) === pending) resources.delete(key);throw error;}
249
+ }
250
+
251
+ export async function openCompilerPackage({manifestURL = new URL('./compiler-package.json', import.meta.url),
252
+ manifestIdentity, fetch: fetchResource = globalThis.fetch, options, memory} = {}) {
253
+ const url = new URL(manifestURL, import.meta.url), resources = new Map();
254
+ // Without an externally pinned identity the package manifest is the trust
255
+ // anchor, not a signature or proof of authenticity for the whole package.
256
+ if (manifestIdentity !== undefined) checkIdentity(manifestIdentity, url.href);
257
+ const manifest = await readMetadataResource(url, fetchResource, manifestIdentity, resources);
258
+ if (manifest.format !== 'eliscript-compiler-package' || manifest.version !== 1 || !Array.isArray(manifest.files)) {
259
+ throw new TypeError('unsupported compiler package');
260
+ }
261
+ const declared = new Map();
262
+ for (const record of manifest.files) {
263
+ const resourceURL = relativeResource(record?.path, url), identity = checkIdentity(record, record.path);
264
+ const previous = declared.get(resourceURL.href);
265
+ if (previous && (previous.bytes !== identity.bytes || previous.sha256 !== identity.sha256)) {
266
+ throw new TypeError('compiler package contains conflicting file identities: ' + record.path);
267
+ }
268
+ declared.set(resourceURL.href, Object.freeze({bytes: identity.bytes, sha256: identity.sha256}));
269
+ }
270
+ async function checkedResource(resourceURL) {
271
+ const identity = declared.get(resourceURL.href);
272
+ if (!identity) throw new Error('compiler package resource has no declared identity: ' + resourceURL.href);
273
+ return readResource(resourceURL, fetchResource, identity, resources);
274
+ }
275
+ async function checkedMetadata(resourceURL) {
276
+ const identity = declared.get(resourceURL.href);
277
+ if (!identity) throw new Error('compiler package resource has no declared identity: ' + resourceURL.href);
278
+ return readMetadataResource(resourceURL, fetchResource, identity, resources);
279
+ }
280
+ const artifactURL = relativeResource(manifest.artifact, url);
281
+ const artifact = await checkedMetadata(artifactURL);
282
+ const host = artifact.host;
283
+ if (!['javascript', 'wasm', 'native'].includes(host) || host !== manifest.host) throw new TypeError('compiler package host mismatch');
284
+ const binaryURL = relativeResource(artifact.path, artifactURL);
285
+ const runtimeURL = relativeResource(artifact.runtimePath, artifactURL);
286
+ const runtimeAsset = {url: runtimeURL, encoding: artifact.runtimeEncoding};
287
+ const debugURL = artifact.debugPath ? relativeResource(artifact.debugPath, artifactURL) : undefined;
288
+ if (artifact.literalSources !== undefined && !Array.isArray(artifact.literalSources)) throw new TypeError('compiler literalSources must be an array');
289
+ const literalAssets = (artifact.literalSources ?? []).map(item => {
290
+ if (typeof item?.id !== 'string' || typeof item.filename !== 'string') throw new TypeError('invalid compiler literal source asset');
291
+ return {...item, url: relativeResource(item.path, artifactURL)};
292
+ });
293
+ // Plan all declared source interpretations before the first lazy read. If
294
+ // aliases use both encodings, decode both from one verified stream; cache
295
+ // only the required final strings, never an extra encoded byte image.
296
+ const sourceFormats = new Map();
297
+ for (const item of [runtimeAsset, ...literalAssets]) {
298
+ let formats = sourceFormats.get(item.url.href);
299
+ if (!formats) sourceFormats.set(item.url.href, formats = new Set());
300
+ formats.add(item.encoding === undefined ? 'utf8' : item.encoding);
301
+ }
302
+ async function checkedSource(item) {
303
+ const identity = declared.get(item.url.href);
304
+ if (!identity) throw new Error('compiler package resource has no declared identity: ' + item.url.href);
305
+ return readSourceResource(item.url, fetchResource, identity, resources, sourceFormats.get(item.url.href), item.encoding);
306
+ }
307
+ // Metadata references must be present even when a resource is loaded lazily.
308
+ for (const resourceURL of [binaryURL, runtimeURL, ...(debugURL ? [debugURL] : []), ...literalAssets.map(item => item.url)]) {
309
+ if (!declared.has(resourceURL.href)) throw new Error('compiler package metadata references an undeclared file: ' + resourceURL.href);
310
+ }
311
+ const config = {host, options: {...artifact.budget, auto: artifact.auto, nativeTarget: artifact.nativeTarget, ...options}, memory: {...artifact.memory, ...memory}};
312
+ if (options?.debug === undefined && debugURL) config.options.debug = ownCompilerDebugDocument(await checkedMetadata(debugURL));
313
+ if (host === 'javascript') {
314
+ // Native ESM import owns its entry/dependency reads. Fetching them here
315
+ // cannot bind the later import to those bytes and would download them twice.
316
+ // These imports, including this loader's static transport import above,
317
+ // are deliberately not reported as verified resource consumption.
318
+ config.compiler = await import(binaryURL.href);
319
+ } else if (host === 'wasm') config.bytes = await checkedResource(binaryURL);
320
+ else {
321
+ const operatingSystem = artifact.nativeTarget === 'arm64-linux' ? 'linux' : artifact.nativeTarget === 'arm64-macos' ? 'darwin' : null;
322
+ if (operatingSystem === null || artifactURL.protocol !== 'file:' ||
323
+ typeof process === 'undefined' || process.platform !== operatingSystem || process.arch !== 'arm64' ||
324
+ !(process.versions?.bun || process.versions?.node)) throw new Error('native compiler package requires Node or Bun on its declared arm64 platform');
325
+ await verifyResource(binaryURL, fetchResource, declared.get(binaryURL.href));
326
+ const {fileURLToPath} = await import('node:url');
327
+ // The platform loader subsequently opens this verified path itself; it
328
+ // does not consume a JavaScript implementation or a WASM substitute.
329
+ config.path = fileURLToPath(binaryURL);
330
+ config.descriptor = {typed: artifact.typed, descriptor: artifact.descriptor};
331
+ }
332
+ const session = await createCompilerSession(config);
333
+ // Instantiation has consumed the WASM image. Only an unusual source alias
334
+ // still needs that exact byte view; its source decoder releases it later.
335
+ config.bytes = undefined;
336
+ if (!sourceFormats.has(binaryURL.href)) resources.delete(binaryURL.href);
337
+ let runtimeReady = false, runtimeLoading, literalSourcesLoading, closed = false, closeResult, closeFailed = false, closeError;
338
+ function active() {
339
+ if (closed) {
340
+ const error = new Error('compiler package is closed');error.code = 'closed';throw error;
341
+ }
342
+ }
343
+ async function runtimeRequest(record) {
344
+ if (Object.hasOwn(record, 'literalSources') || artifact.literalSources === undefined) return record;
345
+ if (!literalSourcesLoading) literalSourcesLoading = Promise.all(literalAssets.map(async item => ({
346
+ id: item.id, filename: item.filename, source: await checkedSource(item),
347
+ }))).catch(error => {literalSourcesLoading = undefined;throw error;});
348
+ const literalSources = await literalSourcesLoading;active();
349
+ return {...record, literalSources};
350
+ }
351
+ async function loadRuntime(requestOptions) {
352
+ active();
353
+ if (runtimeReady) return;
354
+ if (!runtimeLoading) runtimeLoading = (async () => {
355
+ const source = await checkedSource(runtimeAsset);
356
+ active();
357
+ // An explicit runtime request may have completed while the package
358
+ // resource was downloading. Do not overwrite its successful state.
359
+ if (runtimeReady) return;
360
+ const request = await runtimeRequest({operation: 'runtime', source, filename: 'bootstrap/runtime/memory.eli'});
361
+ active();
362
+ if (runtimeReady) return;
363
+ await session.request(request, requestOptions);
364
+ active();runtimeReady = true;
365
+ })();
366
+ const pending = runtimeLoading;
367
+ try {await pending;active();}
368
+ finally {if (runtimeLoading === pending) runtimeLoading = undefined;}
369
+ }
370
+ function close() {
371
+ if (closed) {
372
+ if (closeFailed) throw closeError;
373
+ return closeResult;
374
+ }
375
+ closed = true;runtimeReady = false;literalSourcesLoading = undefined;resources.clear();
376
+ try {closeResult = session.close();return closeResult;}
377
+ catch (error) {closeFailed = true;closeError = error;throw error;}
378
+ }
379
+ return Object.freeze({
380
+ host, manifest, artifact,
381
+ integrity: Object.freeze({manifest: manifestIdentity === undefined ? 'package-trust-anchor' : 'pinned-sha256-and-bytes',
382
+ controlledResources: 'sha256-and-bytes-before-consumption',
383
+ javascriptImports: 'native-esm-loader-not-intercepted',
384
+ nativeLibrary: host === 'native' ? 'file-verified-before-platform-loader' : null}),
385
+ async request(request, requestOptions) {
386
+ active();
387
+ const record = typeof request === 'string' ? JSON.parse(request) : request;
388
+ if (['project','project-ir','emit-ir'].includes(record?.operation) && (record.target === 'wasm' || record.target === 'native')) await loadRuntime(requestOptions);
389
+ active();
390
+ const prepared = record?.operation === 'runtime' ? await runtimeRequest(record) : request;
391
+ active();
392
+ const result = await session.request(prepared, requestOptions);
393
+ active();
394
+ if (record?.operation === 'runtime') runtimeReady = true;
395
+ return result;
396
+ },
397
+ loadRuntime,
398
+ close,
399
+ });
400
+ }
401
+ `;
402
+
403
+ function portablePath(path) {
404
+ if (typeof path !== 'string' || !path || isAbsolute(path) || /^[a-z][a-z0-9+.-]*:/i.test(path) || path.includes('\\') || path.split('/').some(part => part === '..')) {
405
+ throw new TypeError('compiler package paths must be relative');
406
+ }
407
+ return path;
408
+ }
409
+
410
+ function localPath(directory, path) {
411
+ return isAbsolute(path) ? path : resolve(directory, path);
412
+ }
413
+
414
+ export async function packageIndependentCompiler({artifact, outputRoot, sourceRoot = root, name = 'eliscript-independent-compiler'} = {}) {
415
+ if (!artifact || !outputRoot) throw new TypeError('compiler packaging requires artifact and outputRoot');
416
+ let input, inputDirectory;
417
+ if (typeof artifact === 'string') {
418
+ const path = resolve(artifact);
419
+ input = await readCompilerMetadata(path);
420
+ inputDirectory = dirname(path);
421
+ } else {
422
+ input = artifact;
423
+ inputDirectory = artifact.directory ?? (artifact.metadataPath ? dirname(artifact.metadataPath) : undefined);
424
+ if (!inputDirectory) throw new TypeError('in-memory compiler artifact requires its directory');
425
+ }
426
+ if (!['javascript', 'wasm', 'native'].includes(input.host)) throw new TypeError('unsupported compiler package host');
427
+ if (input.host === 'native' && !['arm64-macos', 'arm64-linux'].includes(input.nativeTarget)) throw new TypeError('native compiler package requires real arm64-macos or arm64-linux code');
428
+ if (!input.sourceIdentity || !input.artifactIdentity) throw new TypeError('compiler package requires preserved source and artifact identities');
429
+ for (const record of input.sourceIdentity.modules ?? []) {
430
+ if (record.filename !== undefined) portablePath(record.filename);
431
+ }
432
+ for(const record of input.sourceIdentity.hostSources??[]){portablePath(record.id);if(record.filename!==undefined)portablePath(record.filename);}
433
+ if (input.sourceIdentity.runtime?.filename !== undefined) portablePath(input.sourceIdentity.runtime.filename);
434
+ const directory = resolve(outputRoot), artifactDirectory = resolve(directory, 'artifact');
435
+ const declaredFiles = new Map(input.artifactIdentity.files.map(record => [portablePath(record.path), record]));
436
+ const files = [];
437
+ async function fileIdentity(path) {
438
+ const hash = createHash('sha256');let bytes = 0;
439
+ for await (const chunk of createReadStream(path, {highWaterMark: 65536})) {hash.update(chunk);bytes += chunk.length;}
440
+ return {bytes, sha256: hash.digest('hex')};
441
+ }
442
+ async function put(path, data) {
443
+ portablePath(path);
444
+ const target = resolve(directory, path);
445
+ await mkdir(dirname(target), {recursive: true});
446
+ await writeFile(target, data);
447
+ const bytes = typeof data === 'string' ? Buffer.from(data) : data;
448
+ files.push({path, bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex')});
449
+ }
450
+ async function putMetadata(path, value) {
451
+ portablePath(path);
452
+ const target = resolve(directory, path);
453
+ await mkdir(dirname(target), {recursive: true});
454
+ await writeCompilerMetadata(target, value);
455
+ files.push({path, ...await fileIdentity(target)});
456
+ }
457
+ async function putFile(path, source) {
458
+ portablePath(path);
459
+ const target = resolve(directory, path);
460
+ await mkdir(dirname(target), {recursive: true});
461
+ await copyFile(source, target);
462
+ files.push({path, ...await fileIdentity(target)});
463
+ }
464
+ async function copyArtifact(source, destination) {
465
+ portablePath(destination);
466
+ const identity = declaredFiles.get(destination);
467
+ const target = resolve(directory, 'artifact', destination);
468
+ await mkdir(dirname(target), {recursive: true});
469
+ const temporary = target + '.copy-' + randomUUID();
470
+ let inputFile, outputFile, failed = false;
471
+ try {
472
+ inputFile = await open(localPath(inputDirectory, source), 'r');
473
+ outputFile = await open(temporary, 'wx');
474
+ const buffer = new Uint8Array(65536), hash = createHash('sha256');let bytes = 0;
475
+ for (;;) {
476
+ const {bytesRead} = await inputFile.read(buffer, 0, buffer.length, null);
477
+ if (!bytesRead) break;
478
+ const chunk = buffer.subarray(0, bytesRead);
479
+ await outputFile.writeFile(chunk);hash.update(chunk);bytes += bytesRead;
480
+ }
481
+ const digest = hash.digest('hex');
482
+ if (!identity || identity.sha256 !== digest || identity.bytes !== bytes) {
483
+ throw new Error('compiler artifact changed after emission: ' + destination);
484
+ }
485
+ await outputFile.close();outputFile = undefined;
486
+ await inputFile.close();inputFile = undefined;
487
+ // Only the exact bytes checked above may replace an existing package
488
+ // resource. A failed copy leaves its destination and identity untouched.
489
+ await rename(temporary, target);
490
+ files.push({path: 'artifact/' + destination, bytes, sha256: digest});
491
+ } catch (error) {failed = true;throw error;}
492
+ finally {
493
+ const cleanup = await Promise.allSettled([inputFile?.close(), outputFile?.close()]);
494
+ cleanup.push(...await Promise.allSettled([rm(temporary, {force: true})]));
495
+ if (!failed) for (const result of cleanup) if (result.status === 'rejected') throw result.reason;
496
+ }
497
+ }
498
+ const {bytes, lowered, load, directory: localDirectory, url, metadataPath, ...metadata} = input;
499
+ if (input.host === 'javascript') {
500
+ if (!Array.isArray(input.modules) || !input.modules.length) throw new TypeError('JavaScript compiler package requires the complete module graph');
501
+ metadata.modules = [];
502
+ for (const module of input.modules) {
503
+ const destination = portablePath(module.id);
504
+ await copyArtifact(module.path, destination);
505
+ const record = {id: module.id, path: destination};
506
+ if (module.sourceMapPath) {
507
+ record.sourceMapPath = destination + '.map';
508
+ await copyArtifact(module.sourceMapPath, record.sourceMapPath);
509
+ }
510
+ if (module.macroOriginsPath) {
511
+ record.macroOriginsPath = destination + '.macro-origins.json';
512
+ await copyArtifact(module.macroOriginsPath, record.macroOriginsPath);
513
+ }
514
+ metadata.modules.push(record);
515
+ }
516
+ metadata.path = portablePath(input.entry);
517
+ } else {
518
+ metadata.path = input.host === 'wasm' ? 'compiler.wasm' : input.nativeTarget === 'arm64-linux' ? 'compiler.so' : 'compiler.dylib';
519
+ await copyArtifact(input.path, metadata.path);
520
+ }
521
+ const artifactPath = path => portablePath(isAbsolute(path) ? relative(inputDirectory, path).split(sep).join('/') : path);
522
+ if (input.literalSources !== undefined) {
523
+ if (!Array.isArray(input.literalSources)) throw new TypeError('compiler literalSources must be an array');
524
+ metadata.literalSources = [];
525
+ for (const record of input.literalSources) {
526
+ if (typeof record?.id !== 'string' || typeof record.filename !== 'string') throw new TypeError('invalid compiler literal source asset');
527
+ portablePath(record.id);portablePath(record.filename);
528
+ const destination = artifactPath(record.path);
529
+ await copyArtifact(record.path, destination);
530
+ metadata.literalSources.push({id: record.id, filename: record.filename, path: destination,
531
+ ...(record.encoding === undefined ? {} : {encoding: record.encoding})});
532
+ }
533
+ }
534
+ if(input.project){
535
+ metadata.project={...input.project,files:[]};
536
+ for(const path of input.project.files??[]){
537
+ const destination=artifactPath(path);await copyArtifact(path,destination);metadata.project.files.push(destination);
538
+ }
539
+ }
540
+ if(input.hostSources){
541
+ metadata.hostSources=[];
542
+ for(const record of input.hostSources){
543
+ const destination=artifactPath(record.path);await copyArtifact(record.path,destination);
544
+ metadata.hostSources.push({id:record.id,path:destination});
545
+ }
546
+ }
547
+ if (input.debugPath) {
548
+ metadata.debugPath = artifactPath(input.debugPath);
549
+ await copyArtifact(input.debugPath, metadata.debugPath);
550
+ }
551
+ if (input.frontendIR) {
552
+ metadata.frontendIR = [];
553
+ for (const record of input.frontendIR) {
554
+ const path = artifactPath(record.path), canonicalPath = artifactPath(record.canonicalPath);
555
+ await copyArtifact(record.path, path);await copyArtifact(record.canonicalPath, canonicalPath);
556
+ metadata.frontendIR.push({id: record.id, stage: record.stage, path, canonicalPath});
557
+ }
558
+ }
559
+ metadata.runtimePath = input.runtimeEncoding === undefined ? 'runtime.eli' : 'runtime.eli.json';
560
+ await copyArtifact(input.runtimePath, metadata.runtimePath);
561
+ await putMetadata('artifact/compiler-artifact.json', metadata);
562
+ const transport = [
563
+ 'tools/backends/compiler-session.mjs',
564
+ 'tools/backends/compiler-metadata.mjs',
565
+ 'tools/backends/compiler-sha256.mjs',
566
+ 'tools/backends/compiler-worker.mjs',
567
+ 'tools/backends/compiler-browser.mjs',
568
+ 'tools/backends/compiler-debug.mjs',
569
+ 'tools/backends/managed-runtime.mjs',
570
+ 'tools/backends/managed-host.mjs',
571
+ 'tools/backends/managed-source-view.mjs',
572
+ 'tools/backends/managed-module-graph.mjs',
573
+ 'tools/runtime/unicode-case-profiles.mjs',
574
+ ];
575
+ if (input.host === 'native') transport.push('tools/backends/native-managed-runtime.mjs', 'tools/backends/native-memory.mjs',
576
+ 'tools/backends/native-node-memory.mjs','tools/backends/native-node-worker.mjs','tools/backends/native-node-runner.mjs',
577
+ 'tools/backends/native-node-watchdog.mjs');
578
+ for (const path of transport) await putFile('transport/' + path.slice('tools/'.length), resolve(sourceRoot, path));
579
+ // Keep the boundary provider at its canonical package-relative location so
580
+ // consumers and the transport import the same class/protocol module instance.
581
+ await putFile('runtime/literals.mjs', resolve(sourceRoot, 'runtime/literals.mjs'));
582
+ async function copyCore(directoryPath) {
583
+ for (const entry of await readdir(resolve(sourceRoot, directoryPath), {withFileTypes: true})) {
584
+ const path = directoryPath + '/' + entry.name;
585
+ if (entry.isDirectory()) await copyCore(path);
586
+ else if (entry.isFile() && entry.name.endsWith('.mjs')) await putFile(path, resolve(sourceRoot, path));
587
+ }
588
+ }
589
+ await copyCore('runtime/core');
590
+ await copyCore('runtime/wire');
591
+ await putFile('platform/http.mjs', resolve(sourceRoot, 'platform/http.mjs'));
592
+ await put('compiler-loader.mjs', packageLoader);
593
+ const packageSource = JSON.parse(await readFile(resolve(sourceRoot, 'package.json'), 'utf8'));
594
+ const manifest = {
595
+ format: 'eliscript-compiler-package', version: 1,
596
+ host: input.host, target: input.target,
597
+ artifact: 'artifact/compiler-artifact.json',
598
+ loader: 'compiler-loader.mjs',
599
+ worker: 'transport/backends/compiler-worker.mjs',
600
+ browser: input.host === 'native' ? null : 'transport/backends/compiler-browser.mjs',
601
+ runtime: 'artifact/' + metadata.runtimePath,
602
+ capabilities: {
603
+ compilerHost: input.host,
604
+ productTargets: ['javascript', 'wasm', 'native'],
605
+ environments: input.host === 'native' ? ['node', 'bun'] : ['node', 'bun', 'browser'],
606
+ ...(input.host === 'native' ? {nativeTarget: input.nativeTarget, operatingSystem: input.nativeTarget === 'arm64-linux' ? 'linux' : 'darwin', architecture: 'arm64',
607
+ nativeLibraryLoader:{bun:'ffi',node:'bun-subprocess',compilerBackend:'native'}} : {}),
608
+ nativeProductTargets: input.capabilities?.nativeProductTargets ?? [input.nativeTarget ?? 'arm64-macos'],
609
+ seedRuntimeDependency: false,
610
+ externalCompilerBackend: false,
611
+ },
612
+ sourceIdentity: input.sourceIdentity,
613
+ artifactIdentity: input.artifactIdentity,
614
+ provenance: input.provenance,
615
+ acceptance: input.acceptance ?? {status: 'not-recorded'},
616
+ files,
617
+ };
618
+ await put('package.json', JSON.stringify({
619
+ name, version: packageSource.version, type: 'module',
620
+ exports: {
621
+ '.': './compiler-loader.mjs',
622
+ './manifest': './compiler-package.json',
623
+ './artifact': './artifact/compiler-artifact.json',
624
+ './worker': './transport/backends/compiler-worker.mjs',
625
+ './debug': './transport/backends/compiler-debug.mjs',
626
+ './runtime/*': './runtime/*',
627
+ './platform/http': './platform/http.mjs',
628
+ './platform/http.mjs': './platform/http.mjs',
629
+ ...(input.host === 'native' ? {} : {'./browser': './transport/backends/compiler-browser.mjs'}),
630
+ },
631
+ files: ['compiler-loader.mjs', 'compiler-package.json', 'artifact', 'transport', 'runtime', 'platform'],
632
+ license: packageSource.license,
633
+ }, null, 2) + '\n');
634
+ const manifestPath = resolve(directory, 'compiler-package.json');
635
+ await writeCompilerMetadata(manifestPath, manifest);
636
+ return {directory, artifactDirectory, manifestPath, manifest};
637
+ }
638
+
639
+ export async function main(args = process.argv.slice(2)) {
640
+ const {values} = parseArgs({args, strict: true, options: {
641
+ artifact: {type: 'string'}, output: {type: 'string', short: 'o'},
642
+ name: {type: 'string'}, help: {type: 'boolean', short: 'h'},
643
+ }});
644
+ if (values.help) {
645
+ process.stdout.write('Usage: compiler-package.mjs --artifact compiler-artifact.json --output DIRECTORY [--name PACKAGE]\n');
646
+ return;
647
+ }
648
+ const result = await packageIndependentCompiler({artifact: values.artifact, outputRoot: values.output, name: values.name});
649
+ process.stdout.write(result.manifestPath + '\n');
650
+ }
651
+
652
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
653
+ main().catch(error => {process.stderr.write((error?.stack ?? String(error)) + '\n'); process.exitCode = 1;});
654
+ }