eliscript 0.0.1 → 0.0.2

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 +59 -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-legacy.mjs +37 -0
  35. package/bootstrap/host/eliscript-cli.mjs +53 -33
  36. package/bootstrap/host/eliscript-cli.mjs.map +1 -0
  37. package/bootstrap/host/project-cli-legacy.mjs +295 -0
  38. package/bootstrap/host/project-cli.mjs +74 -289
  39. package/bootstrap/host/project-cli.mjs.map +1 -0
  40. package/bootstrap/host/project-legacy.mjs +1080 -0
  41. package/bootstrap/host/project.mjs +210 -1060
  42. package/bootstrap/host/project.mjs.map +1 -0
  43. package/bootstrap/runtime/UNICODE-LICENSE.txt +39 -0
  44. package/bootstrap/runtime/memory.eli +30379 -0
  45. package/browser/host.mjs +89 -0
  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 +446 -0
  141. package/dist/browser/loader.js +1 -0
  142. package/dist/browser/loader.mjs +231 -0
  143. package/dist/browser/worker.mjs +60 -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 +579 -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 +23 -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 +20 -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 +483 -0
  193. package/dist/literal-sources/stdlib/managed-literals.eli +1414 -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 +97 -10
  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 +114 -47
  252. package/stdlib/gepo.eli +12 -0
  253. package/stdlib/interop/js.eli +56 -15
  254. package/stdlib/managed-literal-protocols.eli +483 -0
  255. package/stdlib/managed-literals.eli +1414 -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 +579 -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 +23 -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 +20 -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 +460 -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 +486 -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,843 @@
1
+ import {instantiateManagedRuntime} from './managed-runtime.mjs';
2
+
3
+ const names = Object.freeze({
4
+ create: 'compiler_session_new',
5
+ request: 'compiler_session_request',
6
+ close: 'compiler_session_close',
7
+ });
8
+ const compilerHeap = Object.freeze({
9
+ maxSlots: 131072, initialBytes: 8388608, maxBytes: 67108864,
10
+ });
11
+ const compilerMemory = Object.freeze({initialPages: 128, maximumPages: 4096});
12
+ const ownedCompilerBuildRequests = new WeakMap();
13
+ const ownedCompilerBuildProducts = new WeakSet();
14
+ const compilerBuildConsumptionRequests = new WeakMap();
15
+
16
+ // Ownership is recorded by the successful private handoff, never by a field
17
+ // on a caller-provided producer or response. Only these products may stream
18
+ // their private debug values without the public writer's eager snapshot.
19
+ export function isOwnedCompilerBuildProduct(value) {
20
+ return ownedCompilerBuildProducts.has(value);
21
+ }
22
+
23
+ // Only the concrete JavaScript session below can own a freshly emitted binary
24
+ // product. Public requests and arbitrary producer wrappers keep their wire
25
+ // snapshot contract; no caller-provided property enables this internal path.
26
+ export function requestCompilerBuildProduct(session, request, options) {
27
+ const owned = ownedCompilerBuildRequests.get(session);
28
+ return owned ? owned(request, options) : session.request(request, options);
29
+ }
30
+
31
+ // A driver's private handoff can retain canonical subtrees. Its public wire
32
+ // response instead creates a complete new data graph, including debug/typed
33
+ // records. A verified artifact loader may register its existing fresh-product
34
+ // handoff instead. Public producers cannot transfer either right through
35
+ // fields on a response or an old ownership token.
36
+ export async function requestCompilerBuildConsumption(session, request, options) {
37
+ const consume = compilerBuildConsumptionRequests.get(session);
38
+ return {product: await (consume ? consume(request, options) : session.request(request, options)),
39
+ owned: consume !== undefined};
40
+ }
41
+
42
+ export async function registerVerifiedCompilerBuildConsumption(session) {
43
+ const loader = './compiler-bootstrap.mjs';
44
+ const {isVerifiedCompilerBuildSession} = await import(loader);
45
+ const owned = ownedCompilerBuildRequests.get(session);
46
+ if (!owned || !isVerifiedCompilerBuildSession(session)) {
47
+ throw new TypeError('exclusive compiler consumption requires a verified JavaScript artifact session');
48
+ }
49
+ compilerBuildConsumptionRequests.set(session, owned);
50
+ return session;
51
+ }
52
+
53
+ // The authenticated artifact adapter injects runtime assets in its public
54
+ // request method. Only its project dispatch forwards ownership unchanged;
55
+ // wrapping that adapter again does not inherit this private registration.
56
+ export function registerCompilerBuildProductForwarder(adapter, session) {
57
+ const owned = ownedCompilerBuildRequests.get(session);
58
+ if (owned) ownedCompilerBuildRequests.set(adapter, (request, options) => {
59
+ const record = typeof request === 'string' ? JSON.parse(request) : request;
60
+ return record?.operation === 'project' ? owned(request, options) : adapter.request(request, options);
61
+ });
62
+ const consume = compilerBuildConsumptionRequests.get(session);
63
+ if (consume) compilerBuildConsumptionRequests.set(adapter, (request, options) => {
64
+ const record = typeof request === 'string' ? JSON.parse(request) : request;
65
+ return record?.operation === 'project' ? consume(request, options) : adapter.request(request, options);
66
+ });
67
+ return adapter;
68
+ }
69
+
70
+ // UTF-8 files cannot represent an unpaired UTF-16 surrogate. Such virtual
71
+ // source text crosses the file/download boundary as a JSON string instead of
72
+ // silently becoming U+FFFD; ordinary source files keep their existing format.
73
+ export function compilerSourceAssetEncoding(source) {
74
+ if (typeof source !== 'string') throw new TypeError('compiler source asset must contain a string');
75
+ for (let index = 0; index < source.length; index++) {
76
+ const unit = source.charCodeAt(index);
77
+ if (unit >= 0xd800 && unit <= 0xdbff) {
78
+ const next = source.charCodeAt(index + 1);
79
+ if (next >= 0xdc00 && next <= 0xdfff) index++;
80
+ else return 'json-utf16';
81
+ } else if (unit >= 0xdc00 && unit <= 0xdfff) return 'json-utf16';
82
+ }
83
+ return 'utf8';
84
+ }
85
+
86
+ export function encodeCompilerSourceAsset(source) {
87
+ const encoding = compilerSourceAssetEncoding(source);
88
+ return {encoding, text: encoding === 'utf8' ? source : JSON.stringify(source)};
89
+ }
90
+
91
+ export function decodeCompilerSourceAsset(bytes, encoding = 'utf8') {
92
+ if (encoding !== 'utf8' && encoding !== 'json-utf16') throw new TypeError('unsupported compiler source asset encoding');
93
+ const text = new TextDecoder('utf-8', {fatal: true, ignoreBOM: true}).decode(bytes);
94
+ if (encoding === 'utf8') return text;
95
+ const source = JSON.parse(text);
96
+ if (typeof source !== 'string') throw new TypeError('encoded compiler source asset must contain a JSON string');
97
+ return source;
98
+ }
99
+
100
+ function checkSignal(signal) {
101
+ if (signal === undefined) return;
102
+ if (signal === null || typeof signal !== 'object' || typeof signal.aborted !== 'boolean') {
103
+ throw new TypeError('compiler request requires an AbortSignal');
104
+ }
105
+ if (typeof signal.throwIfAborted === 'function') signal.throwIfAborted();
106
+ else if (signal.aborted) {
107
+ if (signal.reason !== undefined) throw signal.reason;
108
+ const error = new Error('compiler request aborted');error.name = 'AbortError';throw error;
109
+ }
110
+ }
111
+
112
+ function compilerResponseEvents(graph = false, stringChunks = false) {
113
+ let root, hasRoot = false;
114
+ const frames = [], references = [], activeReferences = new Set();
115
+ const invalid = () => {throw new TypeError('compiler returned invalid response events');};
116
+ const attach = value => {
117
+ if (!frames.length) {
118
+ if (hasRoot) invalid();
119
+ root = value;hasRoot = true;return;
120
+ }
121
+ const frame = frames[frames.length - 1];
122
+ if (frame.array) frame.value.push(value);
123
+ else {
124
+ if (!frame.hasKey) invalid();
125
+ Object.defineProperty(frame.value, frame.key, {value, writable: true, enumerable: true, configurable: true});
126
+ frame.hasKey = false;frame.key = undefined;
127
+ }
128
+ };
129
+ return {
130
+ append(events) {
131
+ if (!Array.isArray(events) || !events.length || events.length > 256) invalid();
132
+ for (const event of events) {
133
+ if (!Array.isArray(event)) invalid();
134
+ const [kind, value] = event;
135
+ const active = frames[frames.length - 1];
136
+ if (active?.string) {
137
+ if (kind === 'string-chunk' && event.length === 2 && typeof value === 'string' &&
138
+ value.length > 0 && value.length <= 8192 && active.units + value.length <= active.length) {
139
+ active.parts.push(value);active.units += value.length;
140
+ } else if (kind === 'end' && event.length === 1 && active.units === active.length) {
141
+ frames.pop();
142
+ const text = active.parts.join('');active.parts = undefined;
143
+ attach(text);
144
+ } else invalid();
145
+ } else if (stringChunks && kind === 'string' && event.length === 2 &&
146
+ Number.isSafeInteger(value) && value > 0) {
147
+ // Complete only after the announced UTF16 length is received. The
148
+ // parent key remains pending until this single scalar is attached.
149
+ frames.push({string: true, length: value, units: 0, parts: []});
150
+ } else if ((kind === 'object' || kind === 'array') &&
151
+ (graph ? event.length === 2 && Number.isSafeInteger(value) && value === references.length + 1
152
+ : event.length === 1)) {
153
+ const container = kind === 'array' ? [] : {};
154
+ if (graph) {references.push(container);activeReferences.add(value);}
155
+ attach(container);frames.push({value: container, array: kind === 'array', hasKey: false, reference: graph ? value : undefined});
156
+ } else if (graph && kind === 'reference' && event.length === 2) {
157
+ if (!Number.isSafeInteger(value) || value < 1 || value > references.length || activeReferences.has(value)) invalid();
158
+ attach(references[value - 1]);
159
+ } else if (kind === 'key' && event.length === 2 && typeof value === 'string') {
160
+ const frame = frames[frames.length - 1];
161
+ if (!frame || frame.array || frame.hasKey) invalid();
162
+ frame.key = value;frame.hasKey = true;
163
+ } else if (kind === 'value' && event.length === 2 &&
164
+ (value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')) {
165
+ attach(value);
166
+ } else if (kind === 'array-values' && event.length === 2) {
167
+ const frame = frames[frames.length - 1];
168
+ if (!frame?.array || !Array.isArray(value) || value.length < 1 || value.length > 256 ||
169
+ value.some(item => item !== null && (typeof item !== 'number' || !Number.isFinite(item)))) invalid();
170
+ // Bounded scalar runs preserve every element, including IEEE -0.
171
+ // Validate the whole run before appending any of its values.
172
+ for (const item of value) frame.value.push(item);
173
+ } else if (kind === 'end' && event.length === 1) {
174
+ const frame = frames.pop();
175
+ if (!frame || frame.hasKey) invalid();
176
+ if (graph) activeReferences.delete(frame.reference);
177
+ } else invalid();
178
+ }
179
+ },
180
+ get complete() {return hasRoot && frames.length === 0;},
181
+ get value() {if (!this.complete) invalid();return root;},
182
+ release() {
183
+ // Neither a failed/cancelled response nor a completed handoff keeps its
184
+ // temporary string pieces or graph identity index beside later replies.
185
+ for (const frame of frames) if (frame.string) frame.parts = undefined;
186
+ frames.length = 0;references.length = 0;activeReferences.clear();
187
+ root = undefined;hasRoot = false;
188
+ },
189
+ };
190
+ }
191
+
192
+ function encodeRequest(request) {
193
+ if (typeof request === 'string') return request;
194
+ const text = JSON.stringify(request);
195
+ if (typeof text !== 'string') throw new TypeError('compiler request must contain JSON data');
196
+ return text;
197
+ }
198
+
199
+ // A data codec for the already produced IR. It performs no compilation or IR
200
+ // reconstruction, and preserves the IEEE negative zero in JSON number text.
201
+ export function encodeCompilerIR(program) {
202
+ return encodeCompilerData(program,false);
203
+ }
204
+
205
+ // Retained compiler data uses the same IEEE-preserving, non-recursive wire
206
+ // format. Diagnostic BigInts keep the metadata boundary's decimal-string form;
207
+ // executable IR continues to reject them rather than silently changing types.
208
+ export function encodeCompilerMetadata(value) {
209
+ return encodeCompilerData(value,true);
210
+ }
211
+
212
+ // Packaging can hash the exact metadata wire without first materializing one
213
+ // giant string. Consumption is synchronous, so getters and shared subtrees
214
+ // have the same visit order as encodeCompilerMetadata.
215
+ export function forEachCompilerMetadataChunk(value, consume) {
216
+ if (typeof consume !== 'function') throw new TypeError('compiler metadata chunk consumer must be a function');
217
+ encodeCompilerData(value, true, consume);
218
+ }
219
+
220
+ // The IR wire differs from metadata only in rejecting BigInt. Archive writers
221
+ // use this exact codec without materializing an additional complete document.
222
+ export function forEachCompilerIRChunk(value, consume) {
223
+ if (typeof consume !== 'function') throw new TypeError('compiler IR chunk consumer must be a function');
224
+ encodeCompilerData(value, false, consume);
225
+ }
226
+
227
+ function encodeCompilerData(program,metadata,consume) {
228
+ // Bound the number of live token strings while retaining exact wire bytes.
229
+ // Large binaries/typed IR otherwise keep millions of tiny strings and an
230
+ // equally large pointer array until the final join.
231
+ const chunks = consume ? undefined : [], ancestors = new Set(), frames = [], quotedStrings = new Map();
232
+ const emit = consume ?? (text => chunks.push(text));
233
+ const largeTokenUnits = 1024;
234
+ // Quoting is a discardable primitive-value cache, not an identity table.
235
+ // Getters can produce arbitrarily many distinct long strings during a
236
+ // streaming hash. Bound both key and quoted text retained by this call.
237
+ const quotedStringUnitsLimit = 4194304, quotedStringEntriesLimit = 1024;
238
+ const quotedStringBlockUnits = 8192, quotedStringWholeUnits = 32768;
239
+ let quotedStringUnits = 0, pending = [], pendingUnits = 0;
240
+ const flush = () => {
241
+ if (!pending.length) return;
242
+ emit(pending.join(''));pending = [];pendingUnits = 0;
243
+ };
244
+ const push = text => {
245
+ // A repeated source token already owns its exact quoted bytes. Joining it
246
+ // with punctuation here would create another large copy for every edge,
247
+ // defeating sharing until the final output is assembled.
248
+ if (text.length >= largeTokenUnits) {flush();emit(text);return;}
249
+ pending.push(text);pendingUnits += text.length;
250
+ if (pending.length >= 2048 || pendingUnits >= 32768) flush();
251
+ };
252
+ const rememberQuote = (value, text, units) => {
253
+ if (quotedStrings.size >= quotedStringEntriesLimit || quotedStringUnits + units > quotedStringUnitsLimit) {
254
+ quotedStrings.clear();quotedStringUnits = 0;
255
+ }
256
+ quotedStrings.set(value, text);quotedStringUnits += units;
257
+ };
258
+ const quote = value => {
259
+ if (value.length < largeTokenUnits) return JSON.stringify(value);
260
+ let text = quotedStrings.get(value);
261
+ if (text === undefined) {
262
+ text = JSON.stringify(value);
263
+ const units = value.length + text.length;
264
+ if (units <= quotedStringUnitsLimit) rememberQuote(value, text, units);
265
+ }
266
+ return text;
267
+ };
268
+ const pushQuoted = value => {
269
+ if (value.length <= quotedStringWholeUnits) {push(quote(value));return;}
270
+ // A bounded output writer must also bound quoting its largest primitive.
271
+ // Never form a second complete escaped source string before streaming it.
272
+ const cached = quotedStrings.get(value);
273
+ if (cached !== undefined) {
274
+ push('"');for (const part of cached) push(part);push('"');return;
275
+ }
276
+ let parts = value.length * 2 + 2 <= quotedStringUnitsLimit ? [] : undefined;
277
+ let units = value.length + 2;
278
+ push('"');
279
+ for (let start = 0; start < value.length;) {
280
+ let end = Math.min(start + quotedStringBlockUnits, value.length);
281
+ if (end < value.length) {
282
+ const high = value.charCodeAt(end - 1), low = value.charCodeAt(end);
283
+ if (high >= 0xd800 && high <= 0xdbff && low >= 0xdc00 && low <= 0xdfff) end--;
284
+ }
285
+ // JSON's escaping is local to code points. Keeping a surrogate pair in
286
+ // one block preserves both well-formed JSON spelling and UTF8 hashing.
287
+ const part = JSON.stringify(value.slice(start, end)).slice(1, -1);
288
+ push(part);units += part.length;
289
+ if (parts !== undefined) {
290
+ if (units > quotedStringUnitsLimit) parts = undefined;
291
+ else parts.push(part);
292
+ }
293
+ start = end;
294
+ }
295
+ push('"');
296
+ if (parts !== undefined) rememberQuote(value, parts, units);
297
+ };
298
+ function append(value, arrayElement = false) {
299
+ if (value === null) {push('null');return true;}
300
+ const kind = typeof value;
301
+ if (kind === 'bigint') {
302
+ if (!metadata) throw new TypeError('compiler IR cannot contain BigInt values');
303
+ pushQuoted(String(value));return true;
304
+ }
305
+ if (kind === 'number') {push(Object.is(value, -0) ? '-0' : JSON.stringify(value));return true;}
306
+ if (kind === 'string') {pushQuoted(value);return true;}
307
+ if (kind === 'boolean') {push(JSON.stringify(value));return true;}
308
+ if (kind !== 'object') {if (arrayElement) push('null');return false;}
309
+ if (ancestors.has(value)) throw new TypeError('compiler IR cannot contain cycles');
310
+ ancestors.add(value);
311
+ if (Array.isArray(value)) {
312
+ push('[');
313
+ frames.push({value, array: true, index: 0});
314
+ } else {
315
+ push('{');
316
+ frames.push({value, array: false, keys: Object.keys(value), index: 0, first: true});
317
+ }
318
+ return true;
319
+ }
320
+ if (!append(program)) throw new TypeError('compiler IR must be JSON data');
321
+ // Keep traversal state on the data stack. Complete compiler IR can exceed
322
+ // the host call-stack depth, and shared subtrees must remain legal once
323
+ // their previous traversal has completed.
324
+ while (frames.length) {
325
+ const frame = frames[frames.length - 1];
326
+ if (frame.array) {
327
+ if (frame.index < frame.value.length) {
328
+ const index = frame.index++;
329
+ if (index) push(',');
330
+ append(frame.value[index], true);
331
+ continue;
332
+ }
333
+ } else if (frame.index < frame.keys.length) {
334
+ const key = frame.keys[frame.index++], item = frame.value[key];
335
+ if (item === undefined || typeof item === 'function' || typeof item === 'symbol') continue;
336
+ if (!frame.first) push(',');
337
+ frame.first = false;
338
+ pushQuoted(key);push(':');
339
+ append(item);
340
+ continue;
341
+ }
342
+ push(frame.array ? ']' : '}');
343
+ ancestors.delete(frame.value);
344
+ frames.pop();
345
+ }
346
+ flush();return chunks?.join('');
347
+ }
348
+
349
+ // Like the response identity index, necessary object identities are split
350
+ // across finite host tables. The index lives only for one private handoff;
351
+ // its keys are already owned by that handoff or the compiler's source cache.
352
+ function compilerOwnedDataMemo(segmentSize = 1048576) {
353
+ if (!Number.isSafeInteger(segmentSize) || segmentSize < 1 || segmentSize > 1048576)
354
+ throw new TypeError('invalid owned compiler memo segment size');
355
+ const segments = [new Map()];
356
+ const find = key => {
357
+ for (let index = segments.length - 1; index >= 0; index--)
358
+ if (segments[index].has(key)) return segments[index];
359
+ };
360
+ return {segments,
361
+ has(key) {return find(key) !== undefined;},
362
+ get(key) {return find(key)?.get(key);},
363
+ set(key, value) {
364
+ let segment = find(key);
365
+ if (!segment) {
366
+ segment = segments[segments.length - 1];
367
+ if (segment.size >= segmentSize) {segment = new Map();segments.push(segment);}
368
+ }
369
+ segment.set(key, value);
370
+ },
371
+ };
372
+ }
373
+
374
+ // The private producer hands over data records, not caller objects. Preserve
375
+ // the public wire's values without serializing and parsing the entire graph.
376
+ // Canonical subgraphs keep their storage; only changed nodes and their parent
377
+ // paths are copied. In particular, shared source spans are never mutated.
378
+ function ownedCompilerDataNormalizer({segmentSize = 1048576, completeLimit = 65536} = {}) {
379
+ if (!Number.isSafeInteger(completeLimit) || completeLimit < 1 || completeLimit > 65536)
380
+ throw new TypeError('invalid owned compiler completion cache size');
381
+ const omitted = Symbol('omitted compiler field'), active = new Set(), complete = new Set();
382
+ const replacements = compilerOwnedDataMemo(segmentSize), borrowedCopies = compilerOwnedDataMemo(segmentSize), frames = [];
383
+ const remember = value => {
384
+ // This only avoids walking unchanged subgraphs again; forgetting a hit is
385
+ // safe. Changed results and detached borrowed edges have persistent memos.
386
+ if (complete.size >= completeLimit) complete.clear();
387
+ complete.add(value);
388
+ };
389
+ const resolved = (value, borrowed) => borrowed ? borrowedCopies.get(value)
390
+ : replacements.has(value) ? replacements.get(value) : value;
391
+ function begin(value, borrowed = false) {
392
+ const array = Array.isArray(value);
393
+ active.add(value);
394
+ const keys = Object.keys(value), ownKeys = Reflect.ownKeys(value);
395
+ frames.push({value, array, borrowed, keys: array ? undefined : keys, index: 0, changes: undefined,
396
+ copy: borrowed || ownKeys.length !== (array ? value.length + 1 : keys.length) ||
397
+ Object.getPrototypeOf(value) !== (array ? Array.prototype : Object.prototype)});
398
+ }
399
+ function change(frame, key, before, after) {
400
+ if (!Object.is(before, after)) {
401
+ (frame.changes ??= new Map()).set(key, after);frame.copy = true;
402
+ }
403
+ }
404
+ const scalar = (value, array) => {
405
+ const kind = typeof value;
406
+ if (kind === 'bigint') throw new TypeError('compiler IR cannot contain BigInt values');
407
+ if (kind === 'number') return Number.isFinite(value) ? value : null;
408
+ if (value === undefined || kind === 'function' || kind === 'symbol') return array ? null : omitted;
409
+ return value;
410
+ };
411
+ return function normalize(root) {
412
+ if (root === null || typeof root !== 'object') {
413
+ const result = scalar(root, false);
414
+ if (result === omitted) throw new TypeError('compiler IR must be JSON data');
415
+ return result;
416
+ }
417
+ begin(root);
418
+ while (frames.length) {
419
+ const frame = frames[frames.length - 1], count = frame.array ? frame.value.length : frame.keys.length;
420
+ if (frame.child) {
421
+ const {key, value, borrowed} = frame.child;frame.child = undefined;
422
+ const result = resolved(value, borrowed);
423
+ // lower-scalar-program creates fresh function/body/local containers,
424
+ // but function.source and expression.span borrow cached frontend IR.
425
+ // Debug also borrows span and macroOrigins. Replace only those edges
426
+ // on fresh records; copying their entire typed parent paths would
427
+ // duplicate almost the whole runtime for no isolation benefit.
428
+ if (borrowed && !frame.borrowed && Object.getOwnPropertyDescriptor(frame.value, key)?.writable) {
429
+ Object.defineProperty(frame.value, key, {value: result});
430
+ frame.detached = true;
431
+ } else change(frame, key, value, result);
432
+ continue;
433
+ }
434
+ if (frame.index < count) {
435
+ const key = frame.array ? frame.index++ : frame.keys[frame.index++];
436
+ const property = Object.getOwnPropertyDescriptor(frame.value, key);
437
+ // Fresh compiler records contain data properties. Do not reinterpret an
438
+ // accessor or execute it a second time while making a partial copy. Its
439
+ // original thrown value still wins over this malformed-payload error.
440
+ if (property && !Object.hasOwn(property, 'value')) {
441
+ Reflect.get(frame.value, key);
442
+ throw new TypeError('owned compiler data must contain data properties');
443
+ }
444
+ const value = Reflect.get(frame.value, key), normalized = scalar(value, frame.array);
445
+ change(frame, key, value, normalized);
446
+ if (!property) {(frame.changes ??= new Map()).set(key, normalized);frame.copy = true;}
447
+ if (normalized === null || typeof normalized !== 'object') continue;
448
+ if (active.has(value)) throw new TypeError('compiler IR cannot contain cycles');
449
+ const borrowed = frame.borrowed || key === 'source' || key === 'span' || key === 'macroOrigins' || key === 'hostCapabilities';
450
+ frame.child = {key, value, borrowed};
451
+ if (borrowed ? borrowedCopies.has(value) : replacements.has(value) || complete.has(value)) continue;
452
+ begin(value, borrowed);continue;
453
+ }
454
+ if (frame.copy) {
455
+ const copy = frame.array ? new Array(count) : {};
456
+ for (let index = 0; index < count; index++) {
457
+ const key = frame.array ? index : frame.keys[index];
458
+ const value = frame.changes?.has(key) ? frame.changes.get(key)
459
+ : Object.getOwnPropertyDescriptor(frame.value, key)?.value;
460
+ if (value !== omitted) Object.defineProperty(copy, key, {value, writable: true, enumerable: true, configurable: true});
461
+ }
462
+ (frame.borrowed ? borrowedCopies : replacements).set(frame.value, copy);
463
+ } else if (frame.detached) {
464
+ // A cache miss must not revisit an edge now pointing at its private
465
+ // copy and detach it a second time. Preserve that identity independently
466
+ // of the optional, bounded completion cache.
467
+ replacements.set(frame.value, frame.value);
468
+ }
469
+ active.delete(frame.value);if (!frame.borrowed) remember(frame.value);frames.pop();
470
+ }
471
+ return resolved(root, false);
472
+ };
473
+ }
474
+
475
+ function withRoots(runtime, operation) {
476
+ const roots = [];let result, failed = false, failure;
477
+ try {result = operation(value => {roots.push(value);return value;});}
478
+ catch (error) {failed = true;failure = error;}
479
+ for (let i = roots.length - 1; i >= 0; i--) {
480
+ try {runtime.release(roots[i]);}
481
+ catch (error) {if (!failed) {failed = true;failure = error;}}
482
+ }
483
+ if (failed) throw failure;
484
+ return result;
485
+ }
486
+
487
+ function property(runtime, object, name, read, {optionalEngineStack = false} = {}) {
488
+ return withRoots(runtime, own => {
489
+ const key = own(runtime.string(name));
490
+ // An independent runtime may represent explicit stack fields without
491
+ // generating an execution stack. Never demand that missing capability
492
+ // while transporting the source exception; represented getters still run.
493
+ if (optionalEngineStack && runtime.errorStackAvailable?.(object, key) === false) return read(undefined);
494
+ return read(own(runtime.objectGet(object, key)));
495
+ });
496
+ }
497
+
498
+ // This copies diagnostic data across the ownership boundary, never compiler IR
499
+ // or executable source algorithms. All visited values remain rooted by callers.
500
+ function completedException(runtime, value, result, memo) {
501
+ if (memo) {
502
+ runtime.pin(value);
503
+ memo.own(value);
504
+ memo.entries.push({source: value, result});
505
+ }
506
+ return result;
507
+ }
508
+
509
+ function diagnosticData(runtime, value, ancestors = [], memo) {
510
+ if (value === null || value === undefined || typeof value === 'boolean') return value;
511
+ if (value.kind === 4) return runtime.readNumber(value);
512
+ if (value.kind === 5) return runtime.readString(value);
513
+ if (value.kind === 34) return runtime.readBigInt(value);
514
+ if (ancestors.length >= 64 || ancestors.some(parent => runtime.keyEqual(parent, value))) {
515
+ throw new TypeError('compiler diagnostic is cyclic or exceeds its nesting limit');
516
+ }
517
+ const completed = memo?.entries.find(entry => runtime.keyEqual(entry.source, value));
518
+ if (completed) return completed.result;
519
+ const path = [...ancestors, value];
520
+ if (value.kind === 7 || value.kind === 8 || value.kind === 14) {
521
+ const result = [];
522
+ for (let i = 0; i < runtime.length(value); i++) {
523
+ result.push(withRoots(runtime, own => diagnosticData(runtime, own(runtime.get(value, i)), path, memo)));
524
+ }
525
+ return completedException(runtime, value, result, memo);
526
+ }
527
+ if (value.kind !== 13) throw new TypeError('compiler diagnostic contains an opaque value');
528
+ return withRoots(runtime, own => {
529
+ const keys = own(runtime.objectKeys(value)), result = {};
530
+ for (let i = 0; i < runtime.length(keys); i++) {
531
+ withRoots(runtime, keep => {
532
+ const key = keep(runtime.get(keys, i)), name = runtime.readString(key);
533
+ const item = keep(runtime.objectGet(value, key));
534
+ Object.defineProperty(result, name, {
535
+ value: diagnosticData(runtime, item, path, memo), enumerable: true, writable: true, configurable: true,
536
+ });
537
+ });
538
+ }
539
+ return completedException(runtime, value, result, memo);
540
+ });
541
+ }
542
+
543
+ function exceptionEntries(runtime, value, ancestors, memo) {
544
+ if (value === null || value === undefined || typeof value === 'boolean' ||
545
+ ![7, 8, 14].includes(value.kind)) {
546
+ return sourceException(runtime, value, ancestors, memo);
547
+ }
548
+ if (ancestors.length >= 64 || ancestors.some(parent => runtime.keyEqual(parent, value))) {
549
+ throw new TypeError('compiler exception errors are cyclic or exceed their nesting limit');
550
+ }
551
+ const completed = memo.entries.find(entry => runtime.keyEqual(entry.source, value));
552
+ if (completed) return completed.result;
553
+ const path = [...ancestors, value], result = [];
554
+ for (let index = 0; index < runtime.length(value); index++) {
555
+ result.push(withRoots(runtime, own =>
556
+ exceptionEntries(runtime, own(runtime.get(value, index)), path, memo)));
557
+ }
558
+ return completedException(runtime, value, result, memo);
559
+ }
560
+
561
+ function sourceException(runtime, value, ancestors = [], memo) {
562
+ if (!memo) return withRoots(runtime, own => sourceException(runtime, value, ancestors, {entries: [], own}));
563
+ if (value === null || value === undefined || typeof value === 'boolean') return value;
564
+ if (value.kind === 4) return runtime.readNumber(value);
565
+ if (value.kind === 5) return runtime.readString(value);
566
+ if (value.kind === 34) return runtime.readBigInt(value);
567
+ if ([7, 8, 14].includes(value.kind)) return exceptionEntries(runtime, value, ancestors, memo);
568
+ if (value.kind !== 13) return diagnosticData(runtime, value, ancestors, memo);
569
+ if (ancestors.length >= 64 || ancestors.some(parent => runtime.keyEqual(parent, value))) {
570
+ throw new TypeError('compiler exception cause is cyclic or exceeds its nesting limit');
571
+ }
572
+ const completed = memo.entries.find(entry => runtime.keyEqual(entry.source, value));
573
+ if (completed) return completed.result;
574
+ const path = [...ancestors, value];
575
+ const name = property(runtime, value, 'name', field => field?.kind === 5 ? runtime.readString(field) : undefined);
576
+ const message = property(runtime, value, 'message', field => field?.kind === 5 ? runtime.readString(field) : undefined);
577
+ if (name === undefined && message === undefined) return diagnosticData(runtime, value, ancestors, memo);
578
+ const constructors = {Error, TypeError, RangeError, SyntaxError, ReferenceError, URIError, EvalError, AggregateError};
579
+ const Constructor = Object.hasOwn(constructors, name) ? constructors[name] : Error;
580
+ const error = Constructor === AggregateError ? new AggregateError([], message ?? '') : new Constructor(message ?? '');
581
+ if (name !== undefined) error.name = name;
582
+ if (Constructor === AggregateError) {
583
+ withRoots(runtime, own => {
584
+ const key = own(runtime.string('errors'));
585
+ const present = runtime.objectHas(value, key);
586
+ const field = own(runtime.objectGet(value, key));
587
+ if (present || field !== undefined) {
588
+ Object.defineProperty(error, 'errors', {
589
+ value: exceptionEntries(runtime, field, path, memo), configurable: true, writable: true,
590
+ });
591
+ } else delete error.errors;
592
+ });
593
+ }
594
+ property(runtime, value, 'stack', field => {
595
+ if (field?.kind === 5) Object.defineProperty(error, 'stack', {
596
+ value: runtime.readString(field), configurable: true, writable: true,
597
+ });
598
+ }, {optionalEngineStack: true});
599
+ property(runtime, value, 'eliscriptDiagnostic', field => {
600
+ if (field !== undefined && field !== null) error.eliscriptDiagnostic = diagnosticData(runtime, field, [], memo);
601
+ });
602
+ for (const key of ['code', 'diagnostics', 'macroOrigins','eliscriptFrames','eliscriptSourceFrames']) {
603
+ property(runtime, value, key, field => {
604
+ if (field !== undefined) Object.defineProperty(error, key, {
605
+ value: diagnosticData(runtime, field, [], memo), enumerable: true, configurable: true, writable: true,
606
+ });
607
+ });
608
+ }
609
+ withRoots(runtime, own => {
610
+ const key = own(runtime.string('cause'));
611
+ const present = runtime.objectHas(value, key);
612
+ const field = own(runtime.objectGet(value, key));
613
+ if (present || field !== undefined) Object.defineProperty(error, 'cause', {
614
+ value: sourceException(runtime, field, path, memo), configurable: true, writable: true,
615
+ });
616
+ });
617
+ return completedException(runtime, value, error, memo);
618
+ }
619
+
620
+ function transferError(runtime, error) {
621
+ if (!runtime || error === null || typeof error !== 'object' || typeof error.kind !== 'number' || error instanceof Error) {
622
+ return error;
623
+ }
624
+ let result,release=true;
625
+ try {result = sourceException(runtime, error);}
626
+ catch (conversionError) {
627
+ // Even if an exhausted heap cannot copy a diagnostic, preserve the first
628
+ // thrown value rather than replacing it with a transport/cleanup failure.
629
+ try{result=runtime.toHostValue(error);}catch{result=error;release=false;}
630
+ if (conversionError !== error && conversionError?.kind !== undefined) {
631
+ try {runtime.release(conversionError);} catch {}
632
+ }
633
+ } finally {
634
+ try {if(release)runtime.release(error);} catch (releaseError) {
635
+ if (result instanceof Error) result.releaseError = releaseError;
636
+ }
637
+ }
638
+ return result;
639
+ }
640
+
641
+ // A session owns one long-lived driver state. Requests cross as one JSON
642
+ // string; target selection, compilation and runtime caching stay in the driver.
643
+ // Only the private JS build handoff consumes a fresh result without a JSON copy.
644
+ export async function createCompilerSession({host, compiler, bytes, descriptor, path, memory = {}, options = {}} = {}) {
645
+ if (!['javascript', 'wasm', 'native'].includes(host)) throw new TypeError('unknown compiler session host');
646
+ if (options === null || typeof options !== 'object' || Array.isArray(options) ||
647
+ memory === null || typeof memory !== 'object' || Array.isArray(memory)) {
648
+ throw new TypeError('compiler session memory and options must be objects');
649
+ }
650
+ let runtime, driver, state, hasState = false, closed = false, busy = false;
651
+ const {auto = 65536, ...heapOptions} = options;
652
+ if (!Number.isInteger(auto) || auto < 0 || auto > 0xffffffff) throw new RangeError('invalid compiler collection threshold');
653
+
654
+ function closeOwned() {
655
+ let failed = false, failure;
656
+ const attempt = operation => {
657
+ try {operation();}
658
+ catch (error) {const transferred = transferError(runtime, error);if (!failed) {failed = true;failure = transferred;}}
659
+ };
660
+ if (hasState) {
661
+ if (runtime) {
662
+ attempt(() => {const result = runtime.invoke(names.close, [state]);runtime.release(result);});
663
+ attempt(() => runtime.release(state));
664
+ } else attempt(() => Reflect.apply(driver.close, driver.module, [state]));
665
+ }
666
+ hasState = false;state = undefined;
667
+ if (runtime) {
668
+ attempt(() => runtime.closeModule());
669
+ attempt(() => runtime.collect());
670
+ attempt(() => runtime.close?.());
671
+ }
672
+ driver = undefined;runtime = undefined;
673
+ if (failed) throw failure;
674
+ }
675
+
676
+ try {
677
+ if (host === 'javascript') {
678
+ if (!compiler || typeof compiler !== 'object') throw new TypeError('JavaScript compiler session requires a driver module');
679
+ driver = {module: compiler, create: compiler[names.create], request: compiler[names.request], close: compiler[names.close]};
680
+ if ([driver.create, driver.request, driver.close].some(value => typeof value !== 'function')) {
681
+ throw new TypeError('compiler driver is missing its session exports');
682
+ }
683
+ state = Reflect.apply(driver.create, driver.module, []);hasState = true;
684
+ } else {
685
+ const settings = {...compilerHeap, ...heapOptions, initializeModule: false};
686
+ if (host === 'wasm') {
687
+ if (bytes === undefined) throw new TypeError('WASM compiler session requires an artifact');
688
+ runtime = instantiateManagedRuntime(bytes, settings);
689
+ } else {
690
+ if (typeof path !== 'string' || !path || descriptor?.typed?.abi !== 'memory-u32' || !descriptor.descriptor) {
691
+ throw new TypeError('native compiler session requires its library path and complete lowering descriptor');
692
+ }
693
+ const nativeModule = './native-managed-runtime.mjs';
694
+ const {instantiateNativeManagedRuntime} = await import(nativeModule);
695
+ runtime = await instantiateNativeManagedRuntime(path, descriptor, {...compilerMemory, ...memory, ...settings});
696
+ }
697
+ runtime.auto(auto);runtime.initializeModule();
698
+ state = runtime.invoke(names.create);hasState = true;
699
+ }
700
+ } catch (error) {
701
+ const primary = transferError(runtime, error);
702
+ try {closeOwned();} catch {} // Setup failure remains the primary exception.
703
+ throw primary;
704
+ }
705
+
706
+ function exchange(text) {
707
+ let input, output, result, failed = false, failure;
708
+ try {
709
+ if (runtime) {
710
+ input = runtime.string(text);output = runtime.invoke(names.request, [state, input]);
711
+ result = runtime.readString(output);
712
+ } else result = Reflect.apply(driver.request, driver.module, [state, text]);
713
+ if (typeof result !== 'string') throw new TypeError('compiler driver returned a non-JSON response');
714
+ result = JSON.parse(result);
715
+ } catch (error) {failed = true;failure = transferError(runtime, error);}
716
+ finally {
717
+ for (const value of [output, input]) if (runtime && value !== undefined) {
718
+ try {runtime.release(value);}
719
+ catch (error) {if (!failed) {failed = true;failure = transferError(runtime, error);}}
720
+ }
721
+ }
722
+ if (failed) throw failure;
723
+ return result;
724
+ }
725
+
726
+ function requestData(request, {signal, responseMode, responseStringChunks} = {}, allowOwned = false) {
727
+ if (closed) throw new Error('compiler session is closed');
728
+ if (busy) throw new Error('compiler session is busy');
729
+ if (responseMode !== undefined && responseMode !== 'events-v1' && responseMode !== 'graph-events-v1')
730
+ throw new TypeError('unsupported compiler response mode');
731
+ if (responseStringChunks !== undefined && typeof responseStringChunks !== 'boolean')
732
+ throw new TypeError('compiler response string chunks must be a boolean');
733
+ if (responseStringChunks === true && responseMode === undefined)
734
+ throw new TypeError('compiler response string chunks require an event response mode');
735
+ checkSignal(signal);busy = true;
736
+ let failed = false, failure, result, token, pending = false, transferred = false;
737
+ const receive = text => {
738
+ try {return exchange(text);}
739
+ catch (error) {transferred = true;throw error;}
740
+ };
741
+ try {
742
+ let text = encodeRequest(request);checkSignal(signal);
743
+ if (responseStringChunks === true) {
744
+ // This extension is opt-in and declared by the concrete driver.
745
+ // An opaque/older driver keeps its original request protocol and
746
+ // never receives an unadvertised chunking field or a silent retry.
747
+ const capabilities = receive(JSON.stringify({operation: 'capabilities'}));
748
+ checkSignal(signal);
749
+ if (capabilities?.responseStringChunks !== true)
750
+ throw new TypeError('compiler driver does not support response string chunks');
751
+ }
752
+ let owned = false;
753
+ if (allowOwned && !runtime) {
754
+ const entry = driver.module.compiler_session_project_owned;
755
+ if (typeof entry === 'function') {
756
+ let input = JSON.parse(text);
757
+ const target = input?.target;
758
+ const nativeTarget = input?.nativeTarget, nativeFormat = input?.nativeFormat ?? 'library';
759
+ const eligible = input !== null && typeof input === 'object' && !Array.isArray(input) &&
760
+ input.operation === 'project' && (target === 'wasm' || target === 'native') && !Object.hasOwn(input, 'responseMode');
761
+ input = undefined;
762
+ // Pass the captured wire export itself. The actual driver refuses
763
+ // ownership when a caller wrapped or substituted that function.
764
+ const envelope = eligible ? Reflect.apply(entry, driver.module, [driver.request, state, text]) : null;
765
+ if (envelope !== null) {
766
+ if (!envelope || typeof envelope !== 'object' || Array.isArray(envelope) ||
767
+ !Object.hasOwn(envelope, 'format') || !Object.hasOwn(envelope, 'version') ||
768
+ envelope.format !== 'eliscript-compiler-owned-project' || envelope.version !== 1 ||
769
+ !Object.hasOwn(envelope, 'value')) throw new TypeError('compiler returned an invalid owned project envelope');
770
+ const product = envelope.value;
771
+ if (!product || typeof product !== 'object' || Array.isArray(product) || product.target !== target ||
772
+ (target === 'wasm' ? product.typed !== undefined
773
+ : !product.typed || typeof product.typed !== 'object' || Array.isArray(product.typed) ||
774
+ product.typed.abi !== 'memory-u32' || !Array.isArray(product.typed.functions) || !Array.isArray(product.typed.exports) ||
775
+ typeof product.nativeTarget !== 'string' || product.nativeTarget !== nativeTarget ||
776
+ !['library', 'object'].includes(product.nativeFormat) || product.nativeFormat !== nativeFormat) ||
777
+ !product.descriptor || typeof product.descriptor !== 'object' ||
778
+ Array.isArray(product.descriptor) || product.bytes === undefined)
779
+ throw new TypeError('compiler returned an invalid owned ' + target + ' project');
780
+ // The small lowering descriptor retains the exact public JSON
781
+ // data contract. The fresh binary and complete debug graph have
782
+ // a single build owner and require no second serialized graph.
783
+ // The descriptor remains a small, independent public snapshot.
784
+ // Native typed data is also public artifact metadata: use the
785
+ // exact wire normalization, retaining canonical DAG nodes.
786
+ result = {...product, descriptor: JSON.parse(encodeCompilerIR(product.descriptor))};
787
+ const normalize = ownedCompilerDataNormalizer();
788
+ if (target === 'native') result.typed = normalize(product.typed);
789
+ if (product.debug !== undefined) result.debug = normalize(product.debug);
790
+ ownedCompilerBuildProducts.add(result);
791
+ owned = true;
792
+ }
793
+ }
794
+ }
795
+ if (!owned && responseMode !== undefined) {
796
+ const input = JSON.parse(text);
797
+ if (input === null || typeof input !== 'object' || Array.isArray(input))
798
+ throw new TypeError('compiler event request must be an object');
799
+ text = JSON.stringify({...input, responseMode,
800
+ ...(responseStringChunks === true ? {responseStringChunks: true} : {})});
801
+ }
802
+ if (!owned) result = receive(text);
803
+ if (!owned && responseMode !== undefined) {
804
+ const graph = responseMode === 'graph-events-v1', decoder = compilerResponseEvents(graph, responseStringChunks === true);
805
+ try {
806
+ for (;;) {
807
+ if (!result || result.format !== 'eliscript-compiler-response-events' || result.version !== (graph ? 2 : 1) ||
808
+ !Number.isSafeInteger(result.token) || result.token < 1 || typeof result.done !== 'boolean' ||
809
+ (token !== undefined && token !== result.token))
810
+ throw new TypeError('compiler returned an invalid response envelope');
811
+ token = result.token;pending = !result.done;
812
+ decoder.append(result.events);checkSignal(signal);
813
+ if (result.done) {result = decoder.value;break;}
814
+ if (decoder.complete) throw new TypeError('compiler response completed before its final envelope');
815
+ result = receive(JSON.stringify({operation: 'response-next', token}));
816
+ }
817
+ } finally {decoder.release();}
818
+ }
819
+ // Synchronous WASM/native execution cannot be preempted by AbortSignal.
820
+ // Observe cancellation at the completed request boundary only.
821
+ checkSignal(signal);
822
+ } catch (error) {failed = true;failure = transferred ? error : transferError(runtime, error);}
823
+ finally {
824
+ if (pending) try {exchange(JSON.stringify({operation: 'response-close', token}));} catch {}
825
+ busy = false;
826
+ }
827
+ if (failed) throw failure;
828
+ return result;
829
+ }
830
+ const session = Object.freeze({
831
+ host,
832
+ get closed() {return closed;},
833
+ request(request, options) {return requestData(request, options);},
834
+ close() {
835
+ if (closed) return;
836
+ if (busy) throw new Error('cannot close a compiler session during a request');
837
+ closed = true;closeOwned();
838
+ },
839
+ });
840
+ if (host === 'javascript') ownedCompilerBuildRequests.set(session, (request, options) => requestData(request, options, true));
841
+ compilerBuildConsumptionRequests.set(session, (request, options) => requestData(request, options));
842
+ return session;
843
+ }