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,1080 @@
1
+ import { createHash } from "node:crypto";
2
+ import {
3
+ lstatSync,
4
+ mkdirSync,
5
+ readFileSync,
6
+ readdirSync,
7
+ realpathSync,
8
+ statSync,
9
+ writeFileSync,
10
+ } from "node:fs";
11
+ import {
12
+ basename,
13
+ dirname,
14
+ isAbsolute,
15
+ relative,
16
+ resolve,
17
+ sep,
18
+ } from "node:path";
19
+ import { fileURLToPath } from "node:url";
20
+
21
+ import { loadCompiler } from "./bun.mjs";
22
+
23
+ const manifestFilename = "eliscript-project.json";
24
+ const cacheFormat = "eliscript-project-cache";
25
+ const cacheVersion = 2;
26
+ const hostDirectory = dirname(fileURLToPath(import.meta.url));
27
+
28
+ function projectError(message, filename) {
29
+ const error = new Error(message);
30
+ error.eliscriptDiagnostic = {
31
+ format: "eliscript-diagnostic",
32
+ version: 1,
33
+ code: "ELI-B0001",
34
+ severity: "error",
35
+ phase: "project-build",
36
+ message,
37
+ ...(filename ? { location: { file: filename } } : {}),
38
+ };
39
+ throw error;
40
+ }
41
+
42
+ function canonicalDirectory(path, label) {
43
+ const expanded = resolve(path);
44
+ let attributes;
45
+ try {
46
+ attributes = statSync(expanded);
47
+ } catch {
48
+ projectError(`${label} is not a directory`, expanded);
49
+ }
50
+ if (!attributes.isDirectory()) {
51
+ projectError(`${label} is not a directory`, expanded);
52
+ }
53
+ return realpathSync(expanded);
54
+ }
55
+
56
+ function pathOption(value, label) {
57
+ if (typeof value !== "string" || value.length === 0) {
58
+ projectError(`${label} must be a non-empty path`);
59
+ }
60
+ return value;
61
+ }
62
+
63
+ function insideRoot(root, candidate) {
64
+ const path = relative(root, candidate);
65
+ return path === "" || (!isAbsolute(path) && path !== ".." &&
66
+ !path.startsWith(`..${sep}`));
67
+ }
68
+
69
+ function canonicalSource(path, root, importer) {
70
+ const expanded = resolve(path);
71
+ let attributes;
72
+ try {
73
+ attributes = statSync(expanded);
74
+ } catch {
75
+ projectError(`local Eliscript module does not exist: ${path}`, importer);
76
+ }
77
+ if (!attributes.isFile()) {
78
+ projectError(`local Eliscript module does not exist: ${path}`, importer);
79
+ }
80
+ const canonical = realpathSync(expanded);
81
+ if (!insideRoot(root, canonical)) {
82
+ projectError(`local Eliscript module escapes project root: ${path}`, importer);
83
+ }
84
+ return canonical;
85
+ }
86
+
87
+ function macroDependency(specifier, root, importer) {
88
+ const expanded = resolve(root, specifier);
89
+ let attributes;
90
+ try {
91
+ attributes = statSync(expanded);
92
+ } catch {
93
+ projectError(`macro file dependency does not exist: ${specifier}`, importer);
94
+ }
95
+ if (!attributes.isFile()) {
96
+ projectError(`macro file dependency does not exist: ${specifier}`, importer);
97
+ }
98
+ const source = realpathSync(expanded);
99
+ if (!insideRoot(root, source)) {
100
+ projectError(
101
+ `macro file dependency escapes project root: ${specifier}`,
102
+ importer,
103
+ );
104
+ }
105
+ const bytes = readFileSync(source);
106
+ return {
107
+ specifier,
108
+ source,
109
+ digest: createHash("sha256").update(bytes).digest("hex"),
110
+ content: (() => {
111
+ try {
112
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
113
+ } catch {
114
+ projectError(
115
+ `macro file dependency is not valid UTF-8: ${specifier}`,
116
+ importer,
117
+ );
118
+ }
119
+ })(),
120
+ };
121
+ }
122
+
123
+ function macroInputs(request, root, importer) {
124
+ const dependencies = [...request.macroFileDependencies]
125
+ .map((specifier) => macroDependency(specifier, root, importer));
126
+ const canonical = new Set(dependencies.map(({ source }) => source));
127
+ if (canonical.size !== dependencies.length) {
128
+ projectError("macro file dependencies resolve to duplicates", importer);
129
+ }
130
+ return {
131
+ dependencies,
132
+ context: {
133
+ capabilities: new Set(request.macroCapabilities),
134
+ files: new Map(dependencies.map(({ specifier, content }) =>
135
+ [specifier, content])),
136
+ },
137
+ };
138
+ }
139
+
140
+ function macroDependencyRecords(dependencies, root) {
141
+ return dependencies.map(({ source, digest }) => ({
142
+ path: relative(root, source),
143
+ digest,
144
+ }));
145
+ }
146
+
147
+ function outputFor(source, root, outDir) {
148
+ const sourcePath = relative(root, source);
149
+ return resolve(outDir, `${sourcePath.slice(0, -4)}.mjs`);
150
+ }
151
+
152
+ function physicalWritePath(path) {
153
+ const expanded = resolve(path);
154
+ const suffix = [];
155
+ let cursor = expanded;
156
+ while (true) {
157
+ try {
158
+ lstatSync(cursor);
159
+ let canonical;
160
+ try {
161
+ canonical = realpathSync(cursor);
162
+ } catch {
163
+ projectError(`generated artifact contains an unresolved symlink: ${expanded}`);
164
+ }
165
+ return resolve(canonical, ...suffix.reverse());
166
+ } catch (error) {
167
+ if (error?.eliscriptDiagnostic) throw error;
168
+ if (error?.code !== "ENOENT") {
169
+ projectError(`generated artifact path cannot be resolved: ${expanded}`);
170
+ }
171
+ const parent = dirname(cursor);
172
+ if (parent === cursor) {
173
+ projectError(`generated artifact path cannot be resolved: ${expanded}`);
174
+ }
175
+ suffix.push(basename(cursor));
176
+ cursor = parent;
177
+ }
178
+ }
179
+ }
180
+
181
+ function existingFileIdentity(path) {
182
+ try {
183
+ const attributes = statSync(path);
184
+ return attributes.isFile() ? `${attributes.dev}:${attributes.ino}` : null;
185
+ } catch {
186
+ return null;
187
+ }
188
+ }
189
+
190
+ function validateOutputIsolation({ sources, macroDependencies, root, outDir }) {
191
+ const protectedPaths = [
192
+ ...sources,
193
+ ...macroDependencies.map(({ source }) => source),
194
+ ];
195
+ const protectedCanonical = new Set(protectedPaths.map((path) =>
196
+ realpathSync(path)));
197
+ const protectedIdentities = new Set(protectedPaths
198
+ .map(existingFileIdentity)
199
+ .filter((identity) => identity !== null));
200
+ const artifacts = [
201
+ ...sources.flatMap((source) => {
202
+ const output = outputFor(source, root, outDir);
203
+ return [output, `${output}.map`];
204
+ }),
205
+ resolve(outDir, manifestFilename),
206
+ ];
207
+ const artifactCanonical = new Set();
208
+ const artifactIdentities = new Set();
209
+ for (const artifact of artifacts) {
210
+ const physical = physicalWritePath(artifact);
211
+ const identity = existingFileIdentity(artifact);
212
+ if (!insideRoot(outDir, physical)) {
213
+ projectError(`generated artifact escapes output directory: ${artifact}`);
214
+ }
215
+ if (protectedCanonical.has(physical) ||
216
+ (identity !== null && protectedIdentities.has(identity))) {
217
+ projectError(`generated artifact would overwrite an input: ${artifact}`);
218
+ }
219
+ if (artifactCanonical.has(physical) ||
220
+ (identity !== null && artifactIdentities.has(identity))) {
221
+ projectError(`generated artifacts resolve to the same file: ${artifact}`);
222
+ }
223
+ artifactCanonical.add(physical);
224
+ if (identity !== null) artifactIdentities.add(identity);
225
+ }
226
+ }
227
+
228
+ function localSourceImport(specifier) {
229
+ return specifier.endsWith(".eli") &&
230
+ (specifier.startsWith("./") || specifier.startsWith("../"));
231
+ }
232
+
233
+ function relativeImport(target, importer) {
234
+ const path = relative(dirname(importer), target);
235
+ return path.startsWith("./") || path.startsWith("../") ? path : `./${path}`;
236
+ }
237
+
238
+ function walkProgram(program, visit) {
239
+ const pending = [...program.body];
240
+ while (pending.length > 0) {
241
+ const node = pending.pop();
242
+ visit(node);
243
+ for (let index = node.children.length - 1; index >= 0; index -= 1) {
244
+ pending.push(node.children[index]);
245
+ }
246
+ }
247
+ }
248
+
249
+ function projectImports(program, source, root, portable) {
250
+ const imports = [];
251
+ walkProgram(program, (node) => {
252
+ if (node.kind !== "import-declaration") return;
253
+ const specifier = node.value;
254
+ if (portable && node.properties?.portable !== true) {
255
+ projectError("portable project contains a non-portable import", source);
256
+ }
257
+ if (!localSourceImport(specifier)) {
258
+ if (portable || specifier.endsWith(".eli")) {
259
+ const kind = portable ? "portable import" : "Eliscript source import";
260
+ projectError(`${kind} must be a relative .eli module: ${specifier}`, source);
261
+ }
262
+ return;
263
+ }
264
+ const dependency = canonicalSource(
265
+ resolve(dirname(source), specifier),
266
+ root,
267
+ source,
268
+ );
269
+ imports.push({
270
+ dependency,
271
+ entries: node.children
272
+ .filter((child) => child.kind === "import-named")
273
+ .map((child) => child.value),
274
+ node,
275
+ });
276
+ });
277
+ return imports;
278
+ }
279
+
280
+ function rewriteLocalImports(program, source, root, outDir) {
281
+ const outputPath = outputFor(source, root, outDir);
282
+ walkProgram(program, (node) => {
283
+ if (node.kind !== "import-declaration" || !localSourceImport(node.value)) {
284
+ return;
285
+ }
286
+ const dependency = canonicalSource(
287
+ resolve(dirname(source), node.value),
288
+ root,
289
+ source,
290
+ );
291
+ node.value = relativeImport(outputFor(dependency, root, outDir), outputPath);
292
+ });
293
+ }
294
+
295
+ function digestBytes(bytes) {
296
+ return createHash("sha256").update(bytes).digest("hex");
297
+ }
298
+
299
+ function digestFile(filename) {
300
+ return digestBytes(readFileSync(filename));
301
+ }
302
+
303
+ function regularFile(filename) {
304
+ try {
305
+ return statSync(filename).isFile();
306
+ } catch (error) {
307
+ if (error?.code === "ENOENT") return false;
308
+ throw error;
309
+ }
310
+ }
311
+
312
+ function compilerModuleDirectory(moduleDirectory) {
313
+ return resolve(
314
+ moduleDirectory ??
315
+ process.env.ELISCRIPT_BOOTSTRAP_MODULE_DIR ??
316
+ resolve(hostDirectory, "../../dist/bootstrap"),
317
+ );
318
+ }
319
+
320
+ function compilerDirectoryDigest(directory) {
321
+ const filenames = readdirSync(directory, { withFileTypes: true })
322
+ .filter((entry) => entry.isFile() &&
323
+ (entry.name.endsWith(".mjs") || entry.name.endsWith(".mjs.map")))
324
+ .map((entry) => entry.name)
325
+ .sort();
326
+ if (!filenames.includes("compiler.mjs")) {
327
+ projectError("generated compiler directory is incomplete", directory);
328
+ }
329
+ const hash = createHash("sha256");
330
+ for (const filename of filenames) {
331
+ hash.update(filename);
332
+ hash.update("\0");
333
+ hash.update(readFileSync(resolve(directory, filename)));
334
+ hash.update("\0");
335
+ }
336
+ return hash.digest("hex");
337
+ }
338
+
339
+ function compilerDigestOption(value) {
340
+ if (typeof value !== "string" || !/^[0-9a-f]{64}$/u.test(value)) {
341
+ projectError("injected compiler requires a lowercase SHA-256 compilerDigest");
342
+ }
343
+ return value;
344
+ }
345
+
346
+ function writeModule({
347
+ compiler,
348
+ program,
349
+ source,
350
+ sourceText,
351
+ root,
352
+ outDir,
353
+ dependencies,
354
+ macroDependencies,
355
+ portableEntries,
356
+ reason,
357
+ sourceMapReference,
358
+ }) {
359
+ const output = outputFor(source, root, outDir);
360
+ const sourceMap = `${output}.map`;
361
+ rewriteLocalImports(program, source, root, outDir);
362
+ const emission = compiler.emit_ir_string_with_source_map(
363
+ program,
364
+ sourceText,
365
+ basename(output),
366
+ relative(dirname(sourceMap), source),
367
+ );
368
+ const javascript = sourceMapReference
369
+ ? `${emission.javascript}//# sourceMappingURL=${basename(sourceMap)}\n`
370
+ : emission.javascript;
371
+ mkdirSync(dirname(output), { recursive: true });
372
+ writeFileSync(sourceMap, emission.sourceMap);
373
+ writeFileSync(output, javascript);
374
+ return {
375
+ source,
376
+ output,
377
+ sourceMap,
378
+ sourceDigest: digestBytes(sourceText),
379
+ outputDigest: digestFile(output),
380
+ sourceMapDigest: digestFile(sourceMap),
381
+ dependencies,
382
+ macroDependencies,
383
+ portableEntries,
384
+ reused: false,
385
+ reason,
386
+ };
387
+ }
388
+
389
+ function reportModule(module, root, outDir) {
390
+ return {
391
+ source: relative(root, module.source),
392
+ output: relative(outDir, module.output),
393
+ sourceMap: relative(outDir, module.sourceMap),
394
+ status: module.reused ? "reused" : "compiled",
395
+ reason: module.reason,
396
+ dependencies: module.dependencies.map((dependency) => relative(root, dependency)),
397
+ ...(module.macroDependencies.length > 0
398
+ ? { macroDependencies: macroDependencyRecords(module.macroDependencies, root) }
399
+ : {}),
400
+ portableEntries: [...module.portableEntries],
401
+ };
402
+ }
403
+
404
+ function manifestRecord(module, root, outDir) {
405
+ return {
406
+ source: relative(root, module.source),
407
+ output: relative(outDir, module.output),
408
+ sourceMap: relative(outDir, module.sourceMap),
409
+ sourceDigest: module.sourceDigest,
410
+ outputDigest: module.outputDigest,
411
+ sourceMapDigest: module.sourceMapDigest,
412
+ ...(module.macroDependencies.length > 0
413
+ ? { macroDependencies: macroDependencyRecords(module.macroDependencies, root) }
414
+ : {}),
415
+ };
416
+ }
417
+
418
+ function cacheMetadataRecord(module, root) {
419
+ return {
420
+ source: relative(root, module.source),
421
+ dependencies: module.dependencies.map((dependency) => relative(root, dependency)),
422
+ ...(module.macroDependencies.length > 0
423
+ ? { macroDependencies: macroDependencyRecords(module.macroDependencies, root) }
424
+ : {}),
425
+ portableEntries: [...module.portableEntries],
426
+ };
427
+ }
428
+
429
+ function cacheIdentityModule(record) {
430
+ return {
431
+ source: record.source,
432
+ dependencies: record.dependencies,
433
+ ...(record.macroDependencies === undefined
434
+ ? {}
435
+ : { macroDependencies: record.macroDependencies }),
436
+ portableEntries: record.portableEntries,
437
+ };
438
+ }
439
+
440
+ function cacheIdentity(value) {
441
+ if (!value || !Array.isArray(value.modules)) return undefined;
442
+ const modules = value.modules.map(cacheIdentityModule);
443
+ if (value.format === undefined && value.version === 1) {
444
+ return {
445
+ version: 1,
446
+ compilerDigest: value.compilerDigest,
447
+ mode: value.mode,
448
+ portableEntries: value.portableEntries,
449
+ modules,
450
+ };
451
+ }
452
+ return {
453
+ format: value.format,
454
+ version: value.version,
455
+ compilerDigest: value.compilerDigest,
456
+ mode: value.mode,
457
+ portableEntries: value.portableEntries,
458
+ modules,
459
+ };
460
+ }
461
+
462
+ function writeManifest(
463
+ entryOutputs,
464
+ modules,
465
+ root,
466
+ outDir,
467
+ mode,
468
+ portableEntries,
469
+ compilerDigest,
470
+ ) {
471
+ const outputEntries = entryOutputs.map((entryOutput) =>
472
+ relative(outDir, entryOutput));
473
+ const identity = outputEntries.length === 1
474
+ ? {
475
+ format: "eliscript-project",
476
+ version: 1,
477
+ entry: outputEntries[0],
478
+ modules: modules.map((module) => manifestRecord(module, root, outDir)),
479
+ }
480
+ : {
481
+ format: "eliscript-project",
482
+ version: 2,
483
+ entries: outputEntries,
484
+ modules: modules.map((module) => manifestRecord(module, root, outDir)),
485
+ };
486
+ const digest = digestBytes(JSON.stringify(identity));
487
+ const cache = {
488
+ format: cacheFormat,
489
+ version: cacheVersion,
490
+ compilerDigest,
491
+ mode,
492
+ portableEntries,
493
+ modules: modules.map((module) => cacheMetadataRecord(module, root)),
494
+ };
495
+ const cacheDigest = digestBytes(JSON.stringify(cache));
496
+ const manifest = resolve(outDir, manifestFilename);
497
+ mkdirSync(outDir, { recursive: true });
498
+ writeFileSync(manifest, `${JSON.stringify({
499
+ ...identity,
500
+ digest,
501
+ cache: { ...cache, digest: cacheDigest },
502
+ })}\n`);
503
+ return { manifest: realpathSync(manifest), digest };
504
+ }
505
+
506
+ function readCache({
507
+ compiler,
508
+ enabled,
509
+ outDir,
510
+ entryOutputs,
511
+ mode,
512
+ portableEntries,
513
+ compilerDigest,
514
+ }) {
515
+ const manifestPath = resolve(outDir, manifestFilename);
516
+ if (!enabled) {
517
+ return compiler.project_cache_lookup({
518
+ enabled: false,
519
+ manifestStatus: "missing",
520
+ });
521
+ }
522
+ if (!regularFile(manifestPath)) {
523
+ return compiler.project_cache_lookup({
524
+ enabled: true,
525
+ manifestStatus: "missing",
526
+ });
527
+ }
528
+ try {
529
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
530
+ const graphIdentity = manifest?.version === 2
531
+ ? {
532
+ format: manifest?.format,
533
+ version: manifest?.version,
534
+ entries: manifest?.entries,
535
+ modules: manifest?.modules,
536
+ }
537
+ : {
538
+ format: manifest?.format,
539
+ version: manifest?.version,
540
+ entry: manifest?.entry,
541
+ modules: manifest?.modules,
542
+ };
543
+ const privateIdentity = cacheIdentity(manifest?.cache);
544
+ return compiler.project_cache_lookup({
545
+ enabled: true,
546
+ manifestStatus: "readable",
547
+ manifest,
548
+ expectedEntry: entryOutputs.length === 1
549
+ ? relative(outDir, entryOutputs[0])
550
+ : undefined,
551
+ expectedEntries: entryOutputs.map((entryOutput) =>
552
+ relative(outDir, entryOutput)),
553
+ graphDigestValid: manifest?.digest ===
554
+ digestBytes(JSON.stringify(graphIdentity)),
555
+ cacheDigestValid: privateIdentity !== undefined &&
556
+ manifest.cache?.digest === digestBytes(JSON.stringify(privateIdentity)),
557
+ compilerDigest,
558
+ mode,
559
+ portableEntries,
560
+ });
561
+ } catch {
562
+ return compiler.project_cache_lookup({
563
+ enabled: true,
564
+ manifestStatus: "unreadable",
565
+ });
566
+ }
567
+ }
568
+
569
+ function cachedRecords(lookup) {
570
+ return new Map((lookup.cache?.records ?? []).map((record) =>
571
+ [record.source, record]));
572
+ }
573
+
574
+ function cachedModule({
575
+ compiler,
576
+ source,
577
+ root,
578
+ outDir,
579
+ record,
580
+ expectedPortableEntries,
581
+ expectedMacroDependencies = [],
582
+ }) {
583
+ const output = outputFor(source, root, outDir);
584
+ const sourceMap = `${output}.map`;
585
+ let sourceDigest;
586
+ let outputDigest;
587
+ let sourceMapDigest;
588
+ let outputExists = false;
589
+ let sourceMapExists = false;
590
+ let artifactFailure;
591
+ try {
592
+ sourceDigest = digestFile(source);
593
+ outputExists = regularFile(output);
594
+ sourceMapExists = regularFile(sourceMap);
595
+ if (outputExists) outputDigest = digestFile(output);
596
+ if (sourceMapExists) sourceMapDigest = digestFile(sourceMap);
597
+ } catch {
598
+ artifactFailure = "artifact-unreadable";
599
+ }
600
+ let dependencies = [];
601
+ let dependenciesValid = true;
602
+ const expectedMacroRecords = macroDependencyRecords(
603
+ expectedMacroDependencies,
604
+ root,
605
+ );
606
+ let macroDependenciesMatch = false;
607
+ try {
608
+ if (!Array.isArray(record?.metadata?.dependencies) ||
609
+ !Array.isArray(record?.metadata?.portableEntries)) {
610
+ throw new TypeError("cache module metadata is invalid");
611
+ }
612
+ dependencies = record.metadata.dependencies.map((dependency) =>
613
+ canonicalSource(resolve(root, dependency), root, source));
614
+ const recordedMacroDependencies = record.metadata.macroDependencies ?? [];
615
+ macroDependenciesMatch =
616
+ JSON.stringify(recordedMacroDependencies) ===
617
+ JSON.stringify(expectedMacroRecords);
618
+ } catch {
619
+ dependenciesValid = false;
620
+ }
621
+ const decision = compiler.project_cache_decision({
622
+ record,
623
+ output: relative(outDir, output),
624
+ sourceMap: relative(outDir, sourceMap),
625
+ expectedPortableEntries,
626
+ macroDependenciesMatch,
627
+ sourceDigest,
628
+ outputExists,
629
+ sourceMapExists,
630
+ outputDigest,
631
+ sourceMapDigest,
632
+ dependenciesValid,
633
+ artifactFailure,
634
+ });
635
+ return {
636
+ decision,
637
+ module: decision.reused
638
+ ? {
639
+ source,
640
+ output,
641
+ sourceMap,
642
+ sourceDigest,
643
+ outputDigest,
644
+ sourceMapDigest,
645
+ dependencies,
646
+ macroDependencies: expectedMacroDependencies,
647
+ portableEntries: [...record.metadata.portableEntries],
648
+ reused: true,
649
+ reason: "verified",
650
+ }
651
+ : undefined,
652
+ };
653
+ }
654
+
655
+ function standardPlan(
656
+ compiler,
657
+ entries,
658
+ root,
659
+ outDir,
660
+ sourceCache,
661
+ programCache,
662
+ records,
663
+ decisions,
664
+ sourceOverrides,
665
+ macroContext,
666
+ macroDependencies,
667
+ ) {
668
+ return compiler.project_plan(entries, (source) => {
669
+ const cached = cachedModule({
670
+ compiler,
671
+ source,
672
+ root,
673
+ outDir,
674
+ record: records.get(relative(root, source)),
675
+ expectedPortableEntries: [],
676
+ expectedMacroDependencies: macroDependencies,
677
+ });
678
+ decisions.set(source, cached);
679
+ if (cached.module !== undefined) return cached.module.dependencies;
680
+ const sourceText = sourceOverrides.get(source) ?? readFileSync(source, "utf8");
681
+ const program = compiler.compile_ir_string(sourceText, source, macroContext);
682
+ sourceCache.set(source, sourceText);
683
+ programCache.set(source, program);
684
+ return projectImports(program, source, root, false)
685
+ .map(({ dependency }) => dependency);
686
+ });
687
+ }
688
+
689
+ function portablePlan(
690
+ compiler,
691
+ entry,
692
+ entries,
693
+ root,
694
+ sourceCache,
695
+ programCache,
696
+ sourceOverrides,
697
+ macroContext,
698
+ ) {
699
+ return compiler.portable_project_plan([{ id: entry, entries }],
700
+ (source, requestedEntries) => {
701
+ const sourceText = sourceOverrides.get(source) ?? readFileSync(source, "utf8");
702
+ const program = compiler.compile_project_portable_ir_string(
703
+ sourceText,
704
+ requestedEntries,
705
+ source,
706
+ macroContext,
707
+ );
708
+ sourceCache.set(source, sourceText);
709
+ programCache.set(source, program);
710
+ return projectImports(program, source, root, true).map((dependency) => ({
711
+ id: dependency.dependency,
712
+ entries: dependency.entries,
713
+ }));
714
+ });
715
+ }
716
+
717
+ function sourceOverridesOption(values, root) {
718
+ if (values === undefined) return new Map();
719
+ const entries = values instanceof Map
720
+ ? [...values.entries()]
721
+ : Object.entries(values);
722
+ const overrides = new Map();
723
+ for (const [filename, sourceText] of entries) {
724
+ if (typeof sourceText !== "string") {
725
+ projectError("project source override must be a string", filename);
726
+ }
727
+ const source = canonicalSource(
728
+ pathOption(filename, "project source override"),
729
+ root,
730
+ filename,
731
+ );
732
+ if (overrides.has(source)) {
733
+ projectError("project source overrides resolve to duplicates", source);
734
+ }
735
+ overrides.set(source, sourceText);
736
+ }
737
+ return overrides;
738
+ }
739
+
740
+ function validateSourceOverrides(sourceOverrides, plan) {
741
+ const plannedSources = new Set(plan.modules.map((record) => record.id));
742
+ for (const source of sourceOverrides.keys()) {
743
+ if (!plannedSources.has(source)) {
744
+ projectError("project source override is outside the project graph", source);
745
+ }
746
+ }
747
+ }
748
+
749
+ function checkStandardPlan(
750
+ compiler,
751
+ entries,
752
+ root,
753
+ sourceOverrides,
754
+ macroContext,
755
+ ) {
756
+ return compiler.project_plan(entries, (source) => {
757
+ const sourceText = sourceOverrides.get(source) ?? readFileSync(source, "utf8");
758
+ const program = compiler.compile_ir_string(sourceText, source, macroContext);
759
+ return projectImports(program, source, root, false)
760
+ .map(({ dependency }) => dependency);
761
+ });
762
+ }
763
+
764
+ function checkPortablePlan(
765
+ compiler,
766
+ entry,
767
+ entries,
768
+ root,
769
+ sourceOverrides,
770
+ macroContext,
771
+ ) {
772
+ return compiler.portable_project_plan([{ id: entry, entries }],
773
+ (source, requestedEntries) => {
774
+ const sourceText = sourceOverrides.get(source) ?? readFileSync(source, "utf8");
775
+ const program = compiler.compile_project_portable_ir_string(
776
+ sourceText,
777
+ requestedEntries,
778
+ source,
779
+ macroContext,
780
+ );
781
+ return projectImports(program, source, root, true).map((dependency) => ({
782
+ id: dependency.dependency,
783
+ entries: dependency.entries,
784
+ }));
785
+ });
786
+ }
787
+
788
+ export async function checkProject(options) {
789
+ if (!options || typeof options !== "object") {
790
+ projectError("project check options must be an object");
791
+ }
792
+ if (options.entry === undefined && options.entries === undefined) {
793
+ projectError("project check requires entry or entries");
794
+ }
795
+ const moduleDirectory = compilerModuleDirectory(options.moduleDirectory);
796
+ const compiler = options.compiler ?? await loadCompiler(moduleDirectory);
797
+ const request = compiler.check_operation_request({
798
+ entry: options.entry,
799
+ entries: options.entries,
800
+ root: options.root ?? null,
801
+ portableEntries: options.portableEntries ?? [],
802
+ macroCapabilities: options.macroCapabilities ?? [],
803
+ macroFileDependencies: options.macroFileDependencies ?? [],
804
+ });
805
+ const entryPaths = request.entries.map((entry) =>
806
+ resolve(pathOption(entry, "entry")));
807
+ if (entryPaths.length > 1 && request.root === null) {
808
+ projectError("multi-entry project checks require an explicit project root");
809
+ }
810
+ const root = canonicalDirectory(
811
+ request.root === null
812
+ ? dirname(entryPaths[0])
813
+ : pathOption(request.root, "project root"),
814
+ "project root",
815
+ );
816
+ const entries = entryPaths.map((entryPath) => {
817
+ const entry = canonicalSource(entryPath, root, entryPath);
818
+ if (!entry.endsWith(".eli")) {
819
+ projectError("entry file must use the .eli extension", entry);
820
+ }
821
+ return entry;
822
+ }).sort();
823
+ if (new Set(entries).size !== entries.length) {
824
+ projectError("project entries resolve to duplicate sources");
825
+ }
826
+ const macro = macroInputs(request, root, entries[0]);
827
+ const sourceOverrides = sourceOverridesOption(options.sourceOverrides, root);
828
+ const portableEntries = [...request.portableEntries];
829
+ const plan = portableEntries.length > 0
830
+ ? checkPortablePlan(
831
+ compiler,
832
+ entries[0],
833
+ portableEntries,
834
+ root,
835
+ sourceOverrides,
836
+ macro.context,
837
+ )
838
+ : checkStandardPlan(
839
+ compiler,
840
+ entries,
841
+ root,
842
+ sourceOverrides,
843
+ macro.context,
844
+ );
845
+ validateSourceOverrides(sourceOverrides, plan);
846
+ const mode = plan.mode;
847
+ const modules = plan.modules.map((record) => ({
848
+ source: relative(root, record.id),
849
+ dependencies: record.dependencies.map((dependency) =>
850
+ relative(root, typeof dependency === "string" ? dependency : dependency.id)),
851
+ portableEntries: record.entries === undefined ? [] : [...record.entries],
852
+ }));
853
+ const report = compiler.project_check_report({
854
+ mode,
855
+ root,
856
+ entries: entries.map((entry) => relative(root, entry)),
857
+ portableEntries,
858
+ modules,
859
+ });
860
+ return Object.freeze({
861
+ format: "eliscript-project-check",
862
+ version: 1,
863
+ root,
864
+ entries: Object.freeze(entries),
865
+ mode,
866
+ portableEntries: Object.freeze(portableEntries),
867
+ macroCapabilities: request.macroCapabilities,
868
+ macroFileDependencies: Object.freeze(macro.dependencies),
869
+ report,
870
+ plan,
871
+ });
872
+ }
873
+
874
+ export async function buildProject(options) {
875
+ const startedAt = performance.now();
876
+ if (!options || typeof options !== "object") {
877
+ projectError("project build options must be an object");
878
+ }
879
+ if ((options.entry === undefined && options.entries === undefined) ||
880
+ options.outDir === undefined) {
881
+ projectError("project build requires entry or entries and outDir");
882
+ }
883
+ const moduleDirectory = compilerModuleDirectory(options.moduleDirectory);
884
+ const compiler = options.compiler ?? await loadCompiler(moduleDirectory);
885
+ const request = compiler.build_operation_request({
886
+ mode: "project",
887
+ entry: options.entry,
888
+ entries: options.entries,
889
+ outDir: options.outDir,
890
+ root: options.root ?? null,
891
+ portableEntries: options.portableEntries ?? [],
892
+ macroCapabilities: options.macroCapabilities ?? [],
893
+ macroFileDependencies: options.macroFileDependencies ?? [],
894
+ useCache: options.useCache === undefined ? true : options.useCache,
895
+ });
896
+ const requestedEntries = request.version === 2
897
+ ? [...request.entries]
898
+ : [request.entry];
899
+ if (requestedEntries.length > 1 && request.root === null) {
900
+ projectError("multi-entry project builds require an explicit project root");
901
+ }
902
+ const entryPaths = requestedEntries.map((entry) =>
903
+ resolve(pathOption(entry, "entry")));
904
+ const root = canonicalDirectory(
905
+ request.root === null
906
+ ? dirname(entryPaths[0])
907
+ : pathOption(request.root, "project root"),
908
+ "project root",
909
+ );
910
+ const entries = entryPaths.map((entryPath) => {
911
+ const entry = canonicalSource(entryPath, root, entryPath);
912
+ if (!entry.endsWith(".eli")) {
913
+ projectError("entry file must use the .eli extension", entry);
914
+ }
915
+ return entry;
916
+ }).sort();
917
+ if (new Set(entries).size !== entries.length) {
918
+ projectError("project entries resolve to duplicate sources");
919
+ }
920
+ const macro = macroInputs(request, root, entries[0]);
921
+ const sourceOverrides = sourceOverridesOption(options.sourceOverrides, root);
922
+ const requestedOutDir = resolve(pathOption(request.outDir, "output"));
923
+ try {
924
+ const attributes = statSync(requestedOutDir);
925
+ if (!attributes.isDirectory()) {
926
+ projectError("output path is not a directory", requestedOutDir);
927
+ }
928
+ } catch (error) {
929
+ if (error?.eliscriptDiagnostic) throw error;
930
+ mkdirSync(requestedOutDir, { recursive: true });
931
+ }
932
+ const outDir = realpathSync(requestedOutDir);
933
+ const sourceMapReference = options.sourceMapReference !== false;
934
+ const useCache = request.useCache && sourceOverrides.size === 0 &&
935
+ sourceMapReference;
936
+ const compilerDigest = options.compiler === undefined
937
+ ? compilerDirectoryDigest(moduleDirectory)
938
+ : compilerDigestOption(options.compilerDigest);
939
+ const requestedPortableEntries = [...request.portableEntries];
940
+ const mode = requestedPortableEntries.length > 0 ? "portable" : "standard";
941
+ const entryOutputs = entries.map((entry) => outputFor(entry, root, outDir));
942
+ const cacheStartedAt = performance.now();
943
+ const cacheLookup = readCache({
944
+ compiler,
945
+ enabled: useCache,
946
+ outDir,
947
+ entryOutputs,
948
+ mode,
949
+ portableEntries: requestedPortableEntries,
950
+ compilerDigest,
951
+ });
952
+ const cacheReadMs = performance.now() - cacheStartedAt;
953
+ const records = cachedRecords(cacheLookup);
954
+ const sourceCache = new Map();
955
+ const programCache = new Map();
956
+ const decisions = new Map();
957
+ const plan = mode === "portable"
958
+ ? portablePlan(
959
+ compiler,
960
+ entries[0],
961
+ requestedPortableEntries,
962
+ root,
963
+ sourceCache,
964
+ programCache,
965
+ sourceOverrides,
966
+ macro.context,
967
+ )
968
+ : standardPlan(
969
+ compiler,
970
+ entries,
971
+ root,
972
+ outDir,
973
+ sourceCache,
974
+ programCache,
975
+ records,
976
+ decisions,
977
+ sourceOverrides,
978
+ macro.context,
979
+ macro.dependencies,
980
+ );
981
+ validateSourceOverrides(sourceOverrides, plan);
982
+ validateOutputIsolation({
983
+ sources: plan.modules.map(({ id }) => id),
984
+ macroDependencies: macro.dependencies,
985
+ root,
986
+ outDir,
987
+ });
988
+ const normalizedPortableEntries = plan.mode === "portable"
989
+ ? [...plan.entries[0].entries]
990
+ : [];
991
+ const modules = plan.modules.map((record) => {
992
+ const dependencies = record.dependencies.map((dependency) =>
993
+ typeof dependency === "string" ? dependency : dependency.id);
994
+ const modulePortableEntries = record.entries === undefined
995
+ ? []
996
+ : [...record.entries];
997
+ const cached = plan.mode === "standard"
998
+ ? decisions.get(record.id)
999
+ : cachedModule({
1000
+ compiler,
1001
+ source: record.id,
1002
+ root,
1003
+ outDir,
1004
+ record: records.get(relative(root, record.id)),
1005
+ expectedPortableEntries: modulePortableEntries,
1006
+ expectedMacroDependencies: macro.dependencies,
1007
+ });
1008
+ if (cached?.module !== undefined) return cached.module;
1009
+ return writeModule({
1010
+ compiler,
1011
+ program: programCache.get(record.id),
1012
+ source: record.id,
1013
+ sourceText: sourceCache.get(record.id),
1014
+ root,
1015
+ outDir,
1016
+ dependencies,
1017
+ macroDependencies: macro.dependencies,
1018
+ portableEntries: modulePortableEntries,
1019
+ reason: cacheLookup.cache === null
1020
+ ? cacheLookup.reason
1021
+ : cached.decision.reason,
1022
+ sourceMapReference,
1023
+ });
1024
+ });
1025
+ const workFinishedAt = performance.now();
1026
+ const manifestData = writeManifest(
1027
+ entryOutputs,
1028
+ modules,
1029
+ root,
1030
+ outDir,
1031
+ plan.mode,
1032
+ normalizedPortableEntries,
1033
+ compilerDigest,
1034
+ );
1035
+ const manifestFinishedAt = performance.now();
1036
+ const reportInput = {
1037
+ mode: plan.mode,
1038
+ root,
1039
+ outDir,
1040
+ manifest: relative(outDir, manifestData.manifest),
1041
+ digest: manifestData.digest,
1042
+ portableEntries: normalizedPortableEntries,
1043
+ cache: { enabled: useCache, reason: cacheLookup.reason },
1044
+ timings: {
1045
+ cacheReadMs,
1046
+ workMs: Math.max(0, workFinishedAt - startedAt - cacheReadMs),
1047
+ manifestWriteMs: manifestFinishedAt - workFinishedAt,
1048
+ totalMs: manifestFinishedAt - startedAt,
1049
+ },
1050
+ modules: modules.map((module) => reportModule(module, root, outDir)),
1051
+ };
1052
+ if (entries.length === 1) {
1053
+ reportInput.entry = relative(root, entries[0]);
1054
+ reportInput.entryOutput = relative(outDir, entryOutputs[0]);
1055
+ } else {
1056
+ reportInput.entries = entries.map((entry) => relative(root, entry));
1057
+ reportInput.entryOutputs = entryOutputs.map((entryOutput) =>
1058
+ relative(outDir, entryOutput));
1059
+ }
1060
+ const report = compiler.project_build_report(reportInput);
1061
+ return Object.freeze({
1062
+ format: "eliscript-project-build",
1063
+ version: entries.length === 1 ? 1 : 2,
1064
+ root,
1065
+ outDir,
1066
+ entry: entries.length === 1 ? entries[0] : undefined,
1067
+ entryOutput: entries.length === 1 ? entryOutputs[0] : undefined,
1068
+ entries: Object.freeze(entries),
1069
+ entryOutputs: Object.freeze(entryOutputs),
1070
+ mode: plan.mode,
1071
+ portableEntries: Object.freeze(normalizedPortableEntries),
1072
+ macroCapabilities: request.macroCapabilities,
1073
+ macroFileDependencies: Object.freeze(macro.dependencies),
1074
+ modules: Object.freeze(modules.map((module) => Object.freeze(module))),
1075
+ manifest: manifestData.manifest,
1076
+ digest: manifestData.digest,
1077
+ report,
1078
+ plan,
1079
+ });
1080
+ }