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,362 @@
1
+ (module eliscript.managed-wire-http-rpc
2
+ (import "../../platform/http.mjs" :as Host)
3
+ (import "../../stdlib/managed-literals.eli" literal-each)
4
+
5
+ (defconst media-type "text/markdown; charset=utf-8")
6
+ (defun truth (value) (funcall globalThis/Boolean value))
7
+ (defun coalesce (value fallback) (if (or (nil? value) (undefined? value)) fallback value))
8
+ (defun option (object key fallback)
9
+ (let ((value (get object key))) (if (undefined? value) (funcall fallback) value)))
10
+ (defun fail (message) (throw (new globalThis/TypeError message)))
11
+ (defun instance? (value constructor)
12
+ (unless (or (= (js* "typeof constructor") "function")
13
+ (and (not (nil? constructor)) (= (js* "typeof constructor") "object")))
14
+ (fail "Right-hand side of instanceof is not an object"))
15
+ (let ((method (get constructor (get globalThis/Symbol :hasInstance))))
16
+ (when (nullish? method)
17
+ (unless (= (js* "typeof constructor") "function")
18
+ (fail "Right-hand side of instanceof is not callable"))
19
+ (setq method (get (get globalThis/Function :prototype) (get globalThis/Symbol :hasInstance))))
20
+ (funcall globalThis/Boolean (Reflect/apply method constructor (js-array value)))))
21
+ (defun line (value)
22
+ (js-call (funcall globalThis/String value) :replace (new globalThis/RegExp "[\\r\\n]" "gu") " "))
23
+ (defun public-path (value)
24
+ (when (or (not (= (js* "typeof value") "string"))
25
+ (not (js-call value :startsWith "/"))
26
+ (js-call (new globalThis/RegExp "[\\s?#`\\\\]" "u") :test value)
27
+ (js-call value :includes "//")
28
+ (and (not (= value "/")) (js-call value :endsWith "/"))
29
+ (js-call (js-call value :split "/") :some (lambda (part) (or (= part ".") (= part ".."))))
30
+ (js-call (js-array "/.well-known/gepo" "/.gepo") :some
31
+ (lambda (prefix) (or (= value prefix) (js-call value :startsWith (str prefix "/")))))
32
+ (not (= (get (new (get Host/globals :URL) value "https://local.invalid") :pathname) value)))
33
+ (fail "Expected a canonical public operation path"))
34
+ value)
35
+ (defun abort-reason (signal)
36
+ (let ((reason (get signal :reason)))
37
+ (if (or (nil? reason) (undefined? reason)) (new globalThis/Error "HTTP request aborted") reason)))
38
+ (defun target (value)
39
+ (let ((url (new (get Host/globals :URL) value)))
40
+ (when (or (not (js-call (js-array "http:" "https:") :includes (get url :protocol)))
41
+ (truth (get url :username)) (truth (get url :password)))
42
+ (fail "Expected an HTTP URL without credentials"))
43
+ (put url :hash "") url))
44
+ (defun parent (value)
45
+ (if (= value "/") nil
46
+ (let ((part (js-call value :slice 0 (js-call value :lastIndexOf "/"))))
47
+ (if (= part "") "/" part))))
48
+
49
+ ;; Object spread creates own data fields, including a literal __proto__ key.
50
+ (defun spread-into (result source)
51
+ (unless (or (nil? source) (undefined? source))
52
+ (let ((boxed (funcall globalThis/Object source)))
53
+ (literal-each (Reflect/ownKeys boxed)
54
+ (lambda (key)
55
+ (let ((descriptor (Object/getOwnPropertyDescriptor boxed key)))
56
+ (when (and (not (undefined? descriptor)) (truth (get descriptor :enumerable)))
57
+ (Object/defineProperty result key
58
+ (js-object :value (get boxed key) :writable t :enumerable t :configurable t))))))))
59
+ result)
60
+ (defun defineOperation (options)
61
+ (public-path (get options :path))
62
+ (let ((execute (get options :execute)))
63
+ (unless (= (js* "typeof execute") "function")
64
+ (fail "Operation requires an execute function")))
65
+ (Object/freeze (spread-into
66
+ (js-object :title (get options :path) :summary "Invoke this operation."
67
+ :contentType "application/json" :request "Body is service-defined."
68
+ :success "Use HTTP status and response representation." :failures (js-array)
69
+ :effect "Service-defined." :retry "No automatic POST retry.") options)))
70
+ (defun usageMarkdown (operation)
71
+ (public-path (get operation :path))
72
+ (str "# " (line (let ((title (get operation :title)))
73
+ (if (or (nil? title) (undefined? title)) (get operation :path) title)))
74
+ "\n\nPOST `" (get operation :path) "` with Content-Type: "
75
+ (line (coalesce (get operation :contentType) "application/json")) ".\n\nPurpose: "
76
+ (line (coalesce (get operation :summary) "")) "\nRequest: "
77
+ (line (coalesce (get operation :request) "Body is service-defined.")) "\nSuccess: "
78
+ (line (coalesce (get operation :success) "Use HTTP status and response representation.")) "\nFailures: "
79
+ (let ((failures (js-call (let ((value (get operation :failures)))
80
+ (if (or (nil? value) (undefined? value)) (js-array) value)) :join "; ")))
81
+ (line (if (truth failures) failures "Use applicable HTTP error statuses.")))
82
+ "\nEffect: " (line (coalesce (get operation :effect) "Service-defined."))
83
+ "\nRetry: " (line (coalesce (get operation :retry) "No automatic POST retry.")) "\n"))
84
+ (defun directory-node () (js-object :operation nil :children (new globalThis/Set)))
85
+ (defun tree (operations)
86
+ (let ((nodes (new globalThis/Map (js-array (js-array "/" (directory-node))))))
87
+ (literal-each operations
88
+ (lambda (operation)
89
+ (public-path (get operation :path))
90
+ (let ((existing (js-call nodes :get (get operation :path))))
91
+ (when (and (not (undefined? existing)) (truth (get existing :operation)))
92
+ (fail "Duplicate operation path")))
93
+ (unless (js-call nodes :has (get operation :path))
94
+ (js-call nodes :set (get operation :path) (directory-node)))
95
+ (put (js-call nodes :get (get operation :path)) :operation operation)
96
+ (let ((child (get operation :path)))
97
+ (while (not (nil? (parent child)))
98
+ (let ((directory (parent child)))
99
+ (unless (js-call nodes :has directory) (js-call nodes :set directory (directory-node)))
100
+ (js-call (get (js-call nodes :get directory) :children) :add child)
101
+ (setq child directory))))))
102
+ nodes))
103
+ (defun pathIndexMarkdown (title operations &rest optional-arguments)
104
+ (let ((location (aref optional-arguments 0)))
105
+ (when (undefined? location) (setq location "/"))
106
+ (public-path location)
107
+ (let* ((nodes (tree operations)) (node (js-call nodes :get location)))
108
+ (if (undefined? node) nil
109
+ (let* ((children (js-call (Array/from (get node :children)) :sort))
110
+ (kind (if (truth (get node :operation))
111
+ (if (> (js-length children) 0) "operation and directory" "operation") "directory"))
112
+ (result (str "# " (line (coalesce title "Service")) "\n\nGEPO 0.2\nPath: `" location
113
+ "`\nParent: " (if (nil? (parent location)) "none" (str "`" (parent location) "`"))
114
+ "\nKind: " kind "\n")))
115
+ (when (truth (get node :operation))
116
+ (setq result (str result "\n## Usage\n\n" (usageMarkdown (get node :operation)))))
117
+ (setq result (str result "\n## Children\n\n"))
118
+ (if (= (js-length children) 0)
119
+ (setq result (str result (if (truth (get node :operation))
120
+ "No immediate child paths.\n" "The visible capability set is empty.\n")))
121
+ (literal-each children
122
+ (lambda (child)
123
+ (let ((operation (get (js-call nodes :get child) :operation)))
124
+ (setq result (str result "- `" child "` — "
125
+ (line (if (or (nil? operation) (undefined? operation)) "Directory"
126
+ (coalesce (get operation :summary) "Directory"))) "\n"))))))
127
+ result)))))
128
+ (defun discoveryCandidates (value)
129
+ (let ((url (target value)))
130
+ (put url :search "")
131
+ (let* ((root (get url :origin)) (candidates (js-array)))
132
+ (unless (= (get url :pathname) "/") (js-call candidates :push (str (get url :href) "?.gepo")))
133
+ (js-call candidates :push (str root "/?.gepo") (str root "/.gepo") (str root "/.well-known/gepo"))
134
+ (Array/from (new globalThis/Set candidates)))))
135
+ (defun classifyDiscovery (response)
136
+ (if (or (< (get response :status) 200) (>= (get response :status) 300)
137
+ (not (truth (get response :contentType))))
138
+ (js-object :accepted false :paths (js-array) :empty false)
139
+ (let ((type (js-call (js-call (get (js-call (get response :contentType) :split ";") 0) :trim) :toLowerCase)))
140
+ (if (or (not (js-call (js-array "text/markdown" "text/plain") :includes type))
141
+ (not (js-call (new globalThis/RegExp "\\bGEPO\\b" "u") :test (get response :body))))
142
+ (js-object :accepted false :paths (js-array) :empty false)
143
+ (let* ((children (js-call (js-call (get response :body) :split
144
+ (new globalThis/RegExp "^## Children\\s*$" "mu")) :at -1))
145
+ (matches (Array/from (js-call children :matchAll
146
+ (new globalThis/RegExp "^\\s*-\\s+`(/[^`\\s]*)`" "gmu"))))
147
+ (paths (Array/from (new globalThis/Set (js-call matches :map (lambda (match) (get match 1)))))))
148
+ (when (and (= (js-length paths) 0)
149
+ (js-call (new globalThis/RegExp "^Path: `/`$" "mu") :test (get response :body))
150
+ (js-call (new globalThis/RegExp "^Kind: operation$" "mu") :test (get response :body)))
151
+ (js-call paths :push "/"))
152
+ (let ((empty (js-call (new globalThis/RegExp "visible capability set is empty|no visible (?:operations|capabilities)" "iu")
153
+ :test children)))
154
+ (js-object :accepted (or (> (js-length paths) 0) empty) :paths paths :empty empty)))))))
155
+
156
+ (defun object? (value)
157
+ (or (and (not (nil? value)) (= (js* "typeof value") "object"))
158
+ (= (js* "typeof value") "function")))
159
+ (defun iterator-close (iterator)
160
+ (let ((close (get iterator :return)))
161
+ (unless (or (nil? close) (undefined? close))
162
+ (let ((result (Reflect/apply close iterator (js-array))))
163
+ (unless (object? result) (fail "Iterator result is not an object"))))))
164
+ (defun iteration (iterable)
165
+ (let* ((method (get iterable (get globalThis/Symbol :iterator)))
166
+ (iterator (Reflect/apply method iterable (js-array))))
167
+ (unless (object? iterator) (fail "Iterator result is not an object"))
168
+ (js-object :iterator iterator :next (get iterator :next))))
169
+ (defun iteration-step (cursor)
170
+ (let ((step (Reflect/apply (get cursor :next) (get cursor :iterator) (js-array))))
171
+ (unless (object? step) (fail "Iterator result is not an object")) step))
172
+ (defun close-abrupt (cursor error)
173
+ (try (iterator-close (get cursor :iterator)) (catch ignored nil))
174
+ (throw error))
175
+
176
+ (defun markdown-response (body &rest optional-arguments)
177
+ (let ((status (aref optional-arguments 0)) (headers (aref optional-arguments 1)))
178
+ (when (undefined? status) (setq status 200))
179
+ (when (undefined? headers) (setq headers (js-object)))
180
+ (new (get Host/globals :Response) body
181
+ (js-object :status status :headers (spread-into
182
+ (js-object "Content-Type" media-type "Cache-Control" "private, no-store") headers)))))
183
+ (defun createService (&rest optional-arguments)
184
+ (let ((options (aref optional-arguments 0)))
185
+ (when (undefined? options) (setq options (js-object)))
186
+ (let* ((title (option options "title" (lambda () "Service")))
187
+ (operations (option options "operations" (lambda () (js-array))))
188
+ (authorize (option options "authorize" (lambda () (lambda () t))))
189
+ (visible (option options "visible" (lambda () (lambda () t))))
190
+ (entries (js-call operations :map defineOperation)))
191
+ (tree entries)
192
+ (async (request)
193
+ (let* ((url (new (get Host/globals :URL) (get request :url)))
194
+ (fixed-entry (js-call (js-array "/.gepo" "/.well-known/gepo") :includes (get url :pathname)))
195
+ (discovery (and (js-call (js-array "GET" "HEAD") :includes (get request :method))
196
+ (or (js-call (get url :searchParams) :has ".gepo") fixed-entry)))
197
+ (location (if fixed-entry "/" (get url :pathname)))
198
+ (available (js-array)))
199
+ (let ((cursor (iteration entries)) (done false))
200
+ (while (not done)
201
+ (let ((step (iteration-step cursor)))
202
+ (if (truth (get step :done)) (setq done t)
203
+ (let ((operation (get step :value)))
204
+ (try
205
+ (when (truth (await (funcall visible request operation)))
206
+ (js-call available :push operation))
207
+ (catch error (close-abrupt cursor error))))))))
208
+ (let* ((nodes (tree available)) (node (js-call nodes :get location)))
209
+ (if (undefined? node) (markdown-response "Unknown path" 404)
210
+ (let ((permission (await (funcall authorize request (get node :operation)
211
+ (if discovery "index" (if (= (get request :method) "POST") "invoke" "usage"))))))
212
+ (cond
213
+ ((instance? permission (get Host/globals :Response)) permission)
214
+ ((not (eq permission t)) (markdown-response "Forbidden" 403))
215
+ (t
216
+ (let ((allow (if (and (truth (get node :operation)) (not fixed-entry))
217
+ "GET, HEAD, OPTIONS, POST" "GET, HEAD, OPTIONS")))
218
+ (cond
219
+ ((= (get request :method) "OPTIONS")
220
+ (new (get Host/globals :Response) nil (js-object :status 204 :headers (js-object :Allow allow))))
221
+ ((or (= (get request :method) "GET") (= (get request :method) "HEAD"))
222
+ (let ((body (if (or discovery (not (truth (get node :operation))))
223
+ (pathIndexMarkdown title available location) (usageMarkdown (get node :operation)))))
224
+ (markdown-response (if (= (get request :method) "HEAD") nil body))))
225
+ ((or (not (= (get request :method) "POST")) (not (truth (get node :operation)))
226
+ (js-call (js-array "/.gepo" "/.well-known/gepo") :includes (get url :pathname)))
227
+ (markdown-response "Method not allowed" 405 (js-object :Allow allow)))
228
+ (t (let ((result (await (js-call (get node :operation) :execute request))))
229
+ (unless (instance? result (get Host/globals :Response)) (fail "Operation must return a Response"))
230
+ result))))))))))))))
231
+
232
+ (defun cancel-after-failure (stream reason)
233
+ ;; Stream cancellation may itself remain pending indefinitely. Once the
234
+ ;; business operation has failed, cleanup cannot own its completion or
235
+ ;; replace its first exception. Observe a cancellation rejection without
236
+ ;; waiting for it; ReadableStream cancellation closes pending reads now.
237
+ (try
238
+ (js-call (Promise/resolve (js-call stream :cancel reason)) :catch (lambda () undefined))
239
+ (catch ignored undefined))
240
+ undefined)
241
+ (defun createClient (&rest optional-arguments)
242
+ (let ((configuration (aref optional-arguments 0)))
243
+ (when (undefined? configuration) (setq configuration (js-object)))
244
+ (let* ((transport (option configuration "fetch" (lambda () (get Host/globals :fetch))))
245
+ (defaults (option configuration "headers" (lambda () (js-object))))
246
+ (maxBytes (option configuration "maxBytes" (lambda () 2097152)))
247
+ (timeoutMs (option configuration "timeoutMs" (lambda () 30000)))
248
+ (classify (option configuration "classify" (lambda () classifyDiscovery))))
249
+ (unless (and (= (js* "typeof transport") "function") (= (js* "typeof classify") "function")
250
+ (Number/isSafeInteger maxBytes) (>= maxBytes 1)
251
+ (Number/isSafeInteger timeoutMs) (>= timeoutMs 1))
252
+ (fail "Invalid client options"))
253
+ (let ((default-headers (new (get Host/globals :Headers) defaults))
254
+ (send nil) (usage nil) (index nil))
255
+ (setq send (async (url method body &rest optional-arguments)
256
+ (let ((options (aref optional-arguments 0)))
257
+ (when (undefined? options) (setq options (js-object)))
258
+ (let ((headers (new (get Host/globals :Headers) default-headers)))
259
+ (js-call (new (get Host/globals :Headers) (get options :headers)) :forEach
260
+ (lambda (value key) (js-call headers :set key value)))
261
+ (unless (js-call headers :has "Accept")
262
+ (js-call headers :set "Accept" "text/markdown, text/plain;q=0.8, */*;q=0.1"))
263
+ (when (truth (get options :contentType)) (js-call headers :set "Content-Type" (get options :contentType)))
264
+ (let* ((controller (new (get Host/globals :AbortController)))
265
+ (signal (if (truth (get options :signal))
266
+ (js-call (get Host/globals :AbortSignal) :any (js-array (get controller :signal) (get options :signal)))
267
+ (get controller :signal))))
268
+ (when (truth (get signal :aborted))
269
+ (throw (abort-reason signal)))
270
+ (let* ((timer (funcall (get Host/globals :setTimeout)
271
+ (lambda () (js-call controller :abort (new globalThis/Error "HTTP timeout"))) timeoutMs))
272
+ (on-abort undefined)
273
+ (aborted (new globalThis/Promise
274
+ (lambda (resolve reject)
275
+ (setq on-abort (lambda ()
276
+ (funcall reject (abort-reason signal))))
277
+ (js-call signal :addEventListener "abort" on-abort (js-object :once t))))))
278
+ (try
279
+ (let ((reply (await (Promise/race (js-array aborted
280
+ (funcall transport (get url :href)
281
+ (js-object :method method :body body :headers headers :redirect "manual" :signal signal)))))))
282
+ (when (and (>= (get reply :status) 300) (< (get reply :status) 400))
283
+ (let ((stream (get reply :body))
284
+ (error (new globalThis/Error "Redirect requires explicit caller handling")))
285
+ (unless (nullish? stream) (cancel-after-failure stream error))
286
+ (throw error)))
287
+ (let ((chunks (js-array)) (size 0))
288
+ (when (truth (get reply :body))
289
+ (let ((reader (js-call (get reply :body) :getReader)) (failed false))
290
+ (try
291
+ (let ((done false))
292
+ (while (not done)
293
+ (let* ((item (await (Promise/race (js-array aborted (js-call reader :read)))))
294
+ (finished (get item :done)) (value (get item :value)))
295
+ (if (truth finished) (setq done t)
296
+ (progn
297
+ (setq size (+ size (get value :byteLength)))
298
+ (when (> size maxBytes)
299
+ (throw (new globalThis/RangeError "HTTP response byte limit")))
300
+ (js-call chunks :push value))))))
301
+ (catch error
302
+ (setq failed t)
303
+ (cancel-after-failure reader error)
304
+ (throw error))
305
+ (finally
306
+ (try (js-call reader :releaseLock)
307
+ (catch cleanup-error (unless failed (throw cleanup-error))))))))
308
+ (let ((bytes (new (get Host/globals :Uint8Array) size)) (offset 0))
309
+ (literal-each chunks (lambda (chunk)
310
+ (js-call bytes :set chunk offset)
311
+ (setq offset (+ offset (get chunk :byteLength)))))
312
+ (js-object :url (get url :href) :status (get reply :status)
313
+ :contentType (js-call (get reply :headers) :get "Content-Type")
314
+ :headers (get reply :headers)
315
+ :body (js-call (new (get Host/globals :TextDecoder)) :decode bytes)))))
316
+ (finally
317
+ (funcall (get Host/globals :clearTimeout) timer)
318
+ (js-call signal :removeEventListener "abort" on-abort)))))))))
319
+ (setq usage (async (value &rest optional-arguments)
320
+ (let ((options (aref optional-arguments 0)))
321
+ (when (undefined? options) (setq options (js-object)))
322
+ (let ((url (target value)))
323
+ (js-call (get url :searchParams) :delete ".gepo")
324
+ (funcall send url "GET" undefined options)))))
325
+ (setq index (async (value &rest optional-arguments)
326
+ (let ((options (aref optional-arguments 0)))
327
+ (when (undefined? options) (setq options (js-object)))
328
+ (let ((url (target value))) (put url :search ".gepo") (funcall send url "GET" undefined options)))))
329
+ (Object/freeze (js-object :usage usage :index index
330
+ :discover (async (value &rest optional-arguments)
331
+ (let ((options (aref optional-arguments 0)))
332
+ (when (undefined? options) (setq options (js-object)))
333
+ (let ((attempts (js-array)) (candidates (discoveryCandidates value)) (found nil))
334
+ (let ((cursor (iteration candidates)) (done false))
335
+ (while (not done)
336
+ (let ((step (iteration-step cursor)))
337
+ (if (truth (get step :done)) (setq done t)
338
+ (let ((candidate (get step :value)))
339
+ (try
340
+ (let* ((reply (await (funcall send (target candidate) "GET" undefined options)))
341
+ (result (await (funcall classify reply))))
342
+ (js-call attempts :push (js-object :url (get reply :url) :status (get reply :status) :accepted (get result :accepted)))
343
+ (when (truth (get result :accepted))
344
+ (setq found (spread-into (spread-into (js-object) reply)
345
+ (js-object :paths (get result :paths) :state (if (truth (get result :empty)) "empty" "found") :attempts attempts)))
346
+ (setq done t)))
347
+ (catch error (close-abrupt cursor error)))
348
+ (when done (iterator-close (get cursor :iterator))))))))
349
+ (if (nil? found) (js-object :state "not-found" :attempts attempts) found))))
350
+ :invoke (async (value body &rest optional-arguments)
351
+ (let ((options (aref optional-arguments 0)))
352
+ (when (undefined? options) (setq options (js-object)))
353
+ (unless (eq (get options :allowPost) t) (fail "Invocation requires allowPost: true"))
354
+ (when (undefined? body) (fail "Invocation requires an explicit body"))
355
+ (let ((url (target value)))
356
+ (when (js-call (get url :searchParams) :has ".gepo") (fail "Discovery parameter is reserved"))
357
+ (let ((description (await (funcall usage url options))))
358
+ (when (or (< (get description :status) 200) (>= (get description :status) 300))
359
+ (throw (new globalThis/Error (str "Usage request failed: " (get description :status)))))
360
+ (funcall send url "POST" body options)))))))))))
361
+
362
+ (export defineOperation usageMarkdown pathIndexMarkdown discoveryCandidates classifyDiscovery createService createClient))
@@ -0,0 +1,275 @@
1
+ (module eliscript.managed-wire-markdown
2
+ (import "../../stdlib/managed-literals.eli" literal-each)
3
+ (defconst number-pattern (js* "/^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$/u"))
4
+ (defun object? (value) (and (not (nil? value)) (= (js* "typeof value") "object") (not (Array/isArray value))))
5
+ (defun truth (value) (js* "!!value"))
6
+ (defun own (value key) (Object/hasOwn value key))
7
+ (defun put-data (target key value)
8
+ (Object/defineProperty target key (js-object :value value :writable t :enumerable t :configurable t)))
9
+ (defconst MarkdownError (funcall
10
+ (js* "(implementation, name) => { if (typeof name !== \"string\") throw new TypeError(\"class name must be a string\"); return ({ [name]: class { constructor(...args) { return implementation(this, ...args); } } })[name]; }")
11
+ (lambda (self code line message)
12
+ (let ((error (new globalThis/Error (str code " at line " line ": " message))))
13
+ (Object/setPrototypeOf error (Object/getPrototypeOf self))
14
+ (put error :name "MarkdownError") (put error :code code) (put error :line line) error)) "MarkdownError"))
15
+ (Object/setPrototypeOf MarkdownError globalThis/Error)
16
+ (Object/setPrototypeOf (get MarkdownError :prototype) (get globalThis/Error :prototype))
17
+ (Object/defineProperty MarkdownError "length" (js-object :value 3 :configurable t))
18
+ (defun fail (code line message) (throw (new MarkdownError code line message)))
19
+ (defun scalar (text)
20
+ (cond
21
+ ((and (js-call text :startsWith "\"") (js-call text :endsWith "\"") (>= (js-length text) 2))
22
+ (js-call (js-call text :slice 1 -1) :replace (js* "/\\\\([\"\\\\ntr])/gu")
23
+ (lambda (matched character)
24
+ (let ((value (get (js-object :n "\n" :t "\t" :r "\r") character)))
25
+ (if (nullish? value) character value)))))
26
+ ((js-call number-pattern :test text)
27
+ (let ((value (funcall globalThis/Number text)))
28
+ (unless (Number/isFinite value) (throw (new globalThis/RangeError "Number exceeds finite IEEE 754 range"))) value))
29
+ ((= text "true") t) ((= text "false") false) ((or (= text "null") (= text "")) nil)
30
+ ((= text "{}") (js-object)) ((= text "[]") (js-array)) (t text)))
31
+ (defun cells (text)
32
+ (let ((result (js-array)) (cell "") (index 1))
33
+ (while (< index (1- (js-length text)))
34
+ (let ((character (aref text index)))
35
+ (cond ((and (= character "\\") (= (aref text (1+ index)) "|")) (setq cell (str cell "|") index (1+ index)))
36
+ ((= character "|") (js-call result :push (js-call cell :trim)) (setq cell ""))
37
+ (t (setq cell (str cell character)))))
38
+ (setq index (1+ index))) (js-call result :push (js-call cell :trim)) result))
39
+ (defun leading (raw) (get (js-call raw :match (js* "/^\\s*/u")) 0))
40
+ (defun table-token (lines index text level line)
41
+ (if (or (>= (1+ index) (js-length lines))
42
+ (not (js-call (js-call (aref lines (1+ index)) :trim) :startsWith "|"))
43
+ (not (js-call (js-call (aref lines (1+ index)) :trim) :endsWith "|"))) nil
44
+ (let ((separator (cells (js-call (aref lines (1+ index)) :trim))))
45
+ (if (not (js-call separator :every (lambda (cell) (js-call (js* "/^:?-+:?$/u") :test cell)))) nil
46
+ (progn
47
+ (when (js-call (leading (aref lines (1+ index))) :includes "\t") (fail "MDP-E009" (1+ line) "Tab indentation"))
48
+ (let ((headers (cells text)) (rows (js-array)))
49
+ (when (or (js-call headers :some (lambda (header) (not (truth header))))
50
+ (/= (get (new globalThis/Set headers) :size) (js-length headers))) (fail "MDP-E005" line "Invalid table header"))
51
+ (unless (= (js-length separator) (js-length headers)) (fail "MDP-E004" (1+ line) "Separator width"))
52
+ (setq index (1+ index))
53
+ (while (and (< (1+ index) (js-length lines))
54
+ (js-call (js* "/^\\s*\\|.*\\|\\s*$/u") :test (aref lines (1+ index))))
55
+ (when (js-call (leading (aref lines (1+ index))) :includes "\t") (fail "MDP-E009" (+ index 2) "Tab indentation"))
56
+ (setq index (1+ index))
57
+ (let ((row (cells (js-call (aref lines index) :trim))))
58
+ (unless (= (js-length row) (js-length headers)) (fail "MDP-E004" (1+ index) "Row width"))
59
+ (if (= (js-length headers) 1) (js-call rows :push (scalar (aref row 0)))
60
+ (let ((value (js-object)))
61
+ (js-call row :forEach (lambda (cell at)
62
+ (unless (= cell "") (put-data value (aref headers at) (scalar cell)))))
63
+ (js-call rows :push value)))))
64
+ (js-object :index index :token (js-object :kind "table" :value rows :level level :line line))))))))
65
+ (defun tokenize (source)
66
+ (let ((lines (js-call (js-call source :replace (js* "/^\\uFEFF/u") "") :split (js* "/\\r\\n?|\\n/u")))
67
+ (tokens (js-array)) (fence nil) (html nil) (index 0))
68
+ (while (< index (js-length lines))
69
+ (let* ((raw (aref lines index)) (text (js-call raw :trim)) (line (1+ index)) (handled false))
70
+ (unless (nil? fence)
71
+ (when (js-call (new globalThis/RegExp (str "^ {0,3}" (get fence :char) "{" (get fence :size) ",}\\s*$") "u") :test raw)
72
+ (setq fence nil))
73
+ (setq handled t))
74
+ (when (and (not handled) (not (nil? html)))
75
+ (when (if (= html "blank") (= text "") (js-call html :test raw)) (setq html nil))
76
+ (setq handled t))
77
+ (unless handled
78
+ (let ((fenced (js-call raw :match (js* "/^ {0,3}(`{3,}|~{3,})/u"))))
79
+ (when (truth fenced)
80
+ (setq fence (js-object :char (aref (aref fenced 1) 0) :size (js-length (aref fenced 1))) handled t))))
81
+ (unless handled
82
+ (when (js-call (js* "/^ {0,3}<!--/u") :test raw)
83
+ (unless (js-call raw :includes "-->") (setq html (js* "/-->/u"))) (setq handled t)))
84
+ (unless handled
85
+ (let ((special (js-call raw :match (js* "/^ {0,3}<(script|pre|style|textarea)(?:\\s|>)/iu"))))
86
+ (when (truth special)
87
+ (let ((end (new globalThis/RegExp (str "</" (aref special 1) ">") "iu")))
88
+ (unless (js-call end :test raw) (setq html end))) (setq handled t))))
89
+ (unless handled
90
+ (when (js-call (js* "/^ {0,3}<\\?/u") :test raw)
91
+ (unless (js-call raw :includes "?>") (setq html (js* "/\\?>/u"))) (setq handled t)))
92
+ (unless handled
93
+ (when (js-call (js* "/^ {0,3}<!\\[CDATA\\[/u") :test raw)
94
+ (unless (js-call raw :includes "]]>") (setq html (js* "/\\]\\]>/u"))) (setq handled t)))
95
+ (unless handled
96
+ (when (js-call (js* "/^ {0,3}<![A-Z]/u") :test raw)
97
+ (unless (js-call raw :includes ">") (setq html (js* "/>/u"))) (setq handled t)))
98
+ (unless handled
99
+ (let ((block-tag (js* "/^ {0,3}<\\/?(?:address|article|aside|base|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\\s|\\/?>)/iu")))
100
+ (when (or (js-call block-tag :test raw)
101
+ (js-call (js* "/^ {0,3}<\\/?[A-Za-z][\\w-]*(?:\\s[^>]*|\\/?)>\\s*$/u") :test raw))
102
+ (setq html "blank" handled t))))
103
+ (unless handled
104
+ (let ((heading (js-call raw :match (js* "/^ {0,3}(#{1,2})(?:[ \\t]+(.*)|$)/u"))))
105
+ (when (truth heading)
106
+ (let ((title (js-call (js-call (if (nullish? (aref heading 2)) "" (aref heading 2)) :replace
107
+ (js* "/(?:^|\\s+)#+\\s*$/u") "") :trim)))
108
+ (unless (truth title) (fail "MDP-E007" line "Empty heading"))
109
+ (js-call tokens :push (js-object :kind "heading" :level (js-length (aref heading 1)) :title title :line line)))
110
+ (setq handled t))))
111
+ (unless handled
112
+ (let* ((field (js-call text :match (js* "/^-\\s+([^]*?):(?: (.*)|\\s*)$/u")))
113
+ (pipe (and (js-call text :startsWith "|") (js-call text :endsWith "|") (> (js-length text) 1))))
114
+ (when (or (truth field) pipe)
115
+ (let ((indent (leading raw)))
116
+ (when (js-call indent :includes "\t") (fail "MDP-E009" line "Tab indentation"))
117
+ (let ((level (Math/floor (/ (js-length indent) 2))))
118
+ (if (truth field)
119
+ (js-call tokens :push (js-object :kind "field" :key (js-call (aref field 1) :trim)
120
+ :text (js-call (if (nullish? (aref field 2)) "" (aref field 2)) :trim) :level level :line line))
121
+ (let ((table (table-token lines index text level line)))
122
+ (unless (nil? table)
123
+ (setq index (get table :index)) (js-call tokens :push (get table :token)))))))))))
124
+ (setq index (1+ index))) tokens))
125
+ (defun option (options key fallback)
126
+ (let ((value (aref options key))) (if (undefined? value) fallback value)))
127
+ (defun parse (source &rest optional-options)
128
+ (let* ((options (if (or (= (js-length optional-options) 0) (undefined? (aref optional-options 0))) (js-object) (aref optional-options 0)))
129
+ (max-length (option options "maxLength" 16777216)) (max-depth (option options "maxDepth" 256)))
130
+ (unless (= (js* "typeof source") "string") (throw (new globalThis/TypeError "Markdown source must be a string")))
131
+ (unless (and (Number/isSafeInteger max-length) (>= max-length 1) (Number/isSafeInteger max-depth) (>= max-depth 0) (<= max-depth 512))
132
+ (throw (new globalThis/RangeError "Invalid parser limits")))
133
+ (when (> (js-length source) max-length) (throw (new globalThis/RangeError "Markdown length limit")))
134
+ (let ((tokens (tokenize source)) (cursor 0) (block nil))
135
+ (setq block (lambda (level root)
136
+ (when (> level max-depth) (throw (new globalThis/RangeError "Markdown depth limit")))
137
+ (let ((value (js-object)) (mode "object") (populated false) (done false))
138
+ (while (and (not done) (< cursor (js-length tokens)))
139
+ (let ((token (aref tokens cursor)))
140
+ (if (or (= (get token :kind) "heading") (< (get token :level) level)) (setq done t)
141
+ (progn
142
+ (when (and (> (get token :level) level) (not (and (= (get token :kind) "table") (= level 0) (<= (get token :level) 1))))
143
+ (fail (if (or (= (get token :kind) "table") (= (get token :key) "")) "MDP-E006" "MDP-E009") (get token :line) "Unattached indentation"))
144
+ (setq cursor (1+ cursor))
145
+ (if (= (get token :kind) "table")
146
+ (progn
147
+ (when root (fail "MDP-E006" (get token :line) "Root table"))
148
+ (when populated (fail "MDP-E002" (get token :line) "Mixed contents"))
149
+ (setq value (get token :value) mode "table" populated t))
150
+ (let ((element (= (get token :key) "")))
151
+ (when (and element root) (fail "MDP-E006" (get token :line) "Root element"))
152
+ (when (or (= mode "table") (and populated (not (eq element (= mode "elements")))))
153
+ (fail "MDP-E002" (get token :line) "Mixed contents"))
154
+ (when (and element (not populated)) (setq value (js-array) mode "elements"))
155
+ (when (and (not element) (own value (get token :key))) (fail "MDP-E003" (get token :line) "Duplicate key"))
156
+ (let* ((child (scalar (get token :text))) (next (aref tokens cursor)))
157
+ (when (and (truth next) (not (= (get next :kind) "heading")) (> (get next :level) level))
158
+ (when (or (/= (get next :level) (1+ level)) (not (= (get token :text) "")))
159
+ (fail (if (= (get next :kind) "table") "MDP-E006" "MDP-E009") (get next :line) "Child requires a container"))
160
+ (setq child (funcall block (1+ level) false)))
161
+ (if element (js-call value :push child) (put-data value (get token :key) child)))
162
+ (setq populated t))))))) value)))
163
+ (let ((result (funcall block 0 t)) (current nil))
164
+ (while (< cursor (js-length tokens))
165
+ (let ((token (aref tokens cursor)))
166
+ (setq cursor (1+ cursor))
167
+ (if (= (get token :level) 1)
168
+ (progn
169
+ (when (own result (get token :title)) (fail "MDP-E003" (get token :line) "Duplicate section"))
170
+ (setq current (funcall block 0 false)) (put-data result (get token :title) current))
171
+ (progn
172
+ (when (nil? current) (fail "MDP-E001" (get token :line) "Orphan heading"))
173
+ (when (Array/isArray current) (fail "MDP-E002" (get token :line) "Table with subsection"))
174
+ (when (own current (get token :title)) (fail "MDP-E003" (get token :line) "Duplicate subsection"))
175
+ (put-data current (get token :title) (funcall block 0 false))))) ) result))))
176
+
177
+ (defun atom (value)
178
+ (cond ((nil? value) "null")
179
+ ((= (js* "typeof value") "string")
180
+ (if (or (= value "") (not (= (js-call value :trim) value)) (js-call (js* "/[\\n\\r\\t]/u") :test value)
181
+ (js-call number-pattern :test value) (js-call (js-array "true" "false" "null" "{}" "[]") :includes value)
182
+ (and (js-call value :startsWith "\"") (js-call value :endsWith "\"")))
183
+ (str "\"" (js-call value :replace (js* "/[\"\\\\\\n\\r\\t]/gu")
184
+ (lambda (character) (get (js-object "\"" "\\\"" "\\" "\\\\" "\n" "\\n" "\r" "\\r" "\t" "\\t") character))) "\"") value))
185
+ ((or (= (js* "typeof value") "boolean") (and (= (js* "typeof value") "number") (Number/isFinite value))) (funcall globalThis/String value))
186
+ ((and (Array/isArray value) (= (js-length value) 0)) "[]")
187
+ ((and (object? value) (js-call (js-array (get globalThis/Object :prototype) nil) :includes (Object/getPrototypeOf value))
188
+ (= (js-length (Object/keys value)) 0)) "{}")
189
+ (t (throw (new globalThis/TypeError "Expected a finite JSON scalar")))))
190
+ (defun leaf (value)
191
+ (or (nil? value) (not (= (js* "typeof value") "object"))
192
+ (if (Array/isArray value) (= (js-length value) 0) (= (js-length (Object/keys value)) 0))))
193
+ (defun key-text (key &optional heading)
194
+ (when (or (not (truth key)) (not (= (js-call key :trim) key)) (js-call (js* "/[\\r\\n\\t]/u") :test key)
195
+ (if heading (js-call (js* "/\\s#+$/u") :test key) (js-call (js* "/: /u") :test key)))
196
+ (throw (new globalThis/TypeError "Unrepresentable Markdown key"))) key)
197
+ (defun append-child (lines prefix child depth body)
198
+ (let* ((push (get lines :push)) (first (funcall prefix)) (tail (funcall body child depth)) (arguments (js-array first)))
199
+ (literal-each tail (lambda (line) (put arguments (js-length arguments) line)))
200
+ (Reflect/apply push lines arguments)))
201
+ (defun flat-object-keys (data)
202
+ ;; Collect one mapped level before Set construction, keeping the original
203
+ ;; index order, length snapshots and HasProperty/Get order for holes.
204
+ (let ((result (js-array)) (length (js-length data)) (index 0))
205
+ (while (< index length)
206
+ (when (Reflect/has data index)
207
+ (let* ((item (aref data index)) (keys (if (object? item) (Object/keys item) (js-array))))
208
+ (if (Array/isArray keys)
209
+ (let ((key-length (js-length keys)) (key-index 0))
210
+ (while (< key-index key-length)
211
+ (when (Reflect/has keys key-index)
212
+ (put result (js-length result) (aref keys key-index)))
213
+ (setq key-index (1+ key-index))))
214
+ (put result (js-length result) keys))))
215
+ (setq index (1+ index))) result))
216
+ (defun encode (value &rest optional-options)
217
+ (let* ((options (if (or (= (js-length optional-options) 0) (undefined? (aref optional-options 0))) (js-object) (aref optional-options 0)))
218
+ (max-depth (option options "maxDepth" 256)) (max-length (option options "maxLength" 16777216)))
219
+ (unless (and (object? value) (js-call (js-array (get globalThis/Object :prototype) nil) :includes (Object/getPrototypeOf value)))
220
+ (throw (new globalThis/TypeError "Markdown document must be a plain object")))
221
+ (unless (and (Number/isSafeInteger max-depth) (>= max-depth 0) (<= max-depth 512) (Number/isSafeInteger max-length) (>= max-length 1))
222
+ (throw (new globalThis/RangeError "Invalid encoder limits")))
223
+ (let ((active (new globalThis/Set)) (body nil))
224
+ (setq body (lambda (data depth)
225
+ (when (> depth max-depth) (throw (new globalThis/RangeError "Markdown depth limit")))
226
+ (when (js-call active :has data) (throw (new globalThis/TypeError "Cyclic Markdown value")))
227
+ (js-call active :add data)
228
+ (let ((pad (js-call " " :repeat depth)) (lines (js-array)))
229
+ (cond
230
+ ((Array/isArray data)
231
+ (let ((index 0))
232
+ (while (< index (js-length data))
233
+ (unless (own data index) (throw (new globalThis/TypeError "Sparse arrays are not JSON values")))
234
+ (setq index (1+ index))))
235
+ (if (js-call data :every leaf)
236
+ (progn
237
+ (setq lines (js-array (str pad "| value |") (str pad "| --- |")))
238
+ (literal-each (js-call data :map (lambda (item) (str pad "| " (js-call (atom item) :replaceAll "|" "\\|") " |")))
239
+ (lambda (line) (put lines (js-length lines) line))))
240
+ (let ((keys (js-array)))
241
+ (literal-each (new globalThis/Set (flat-object-keys data))
242
+ (lambda (key) (put keys (js-length keys) key)))
243
+ (if (and (> (js-length keys) 1) (js-call data :every (lambda (item) (and (object? item) (js-call (Object/values item) :every leaf)))))
244
+ (let ((row (lambda (values) (str pad "| " (js-call values :join " | ") " |")))
245
+ (cell (lambda (item) (js-call (atom item) :replaceAll "|" "\\|"))))
246
+ (setq lines (js-array
247
+ (funcall row (js-call keys :map (lambda (key) (js-call (key-text key) :replaceAll "|" "\\|"))))
248
+ (funcall row (js-call keys :map (lambda () "---")))))
249
+ (literal-each (js-call data :map (lambda (item)
250
+ (funcall row (js-call keys :map (lambda (key) (if (own item key) (funcall cell (aref item key)) ""))))))
251
+ (lambda (line) (put lines (js-length lines) line))))
252
+ (literal-each data (lambda (child)
253
+ (if (leaf child) (js-call lines :push (str pad "- : " (atom child)))
254
+ (append-child lines (lambda () (str pad "- :")) child (1+ depth) body))))))))
255
+ ((object? data)
256
+ (unless (and (eq (Object/getPrototypeOf data) (get globalThis/Object :prototype))
257
+ (not (nil? data)))
258
+ (unless (nil? (Object/getPrototypeOf data)) (throw (new globalThis/TypeError "Expected plain JSON object"))))
259
+ (literal-each (Object/entries data) (lambda (entry)
260
+ (let ((key (aref entry 0)) (child (aref entry 1)))
261
+ (if (leaf child) (js-call lines :push (str pad "- " (key-text key) ": " (atom child)))
262
+ (append-child lines (lambda () (str pad "- " (key-text key) ":")) child (1+ depth) body))))))
263
+ (t (throw (new globalThis/TypeError "Expected JSON container"))))
264
+ (js-call active :delete data) lines)))
265
+ (js-call active :add value)
266
+ (let ((preamble (js-array)) (sections (js-array)))
267
+ (literal-each (Object/entries value) (lambda (entry)
268
+ (let ((key (aref entry 0)) (child (aref entry 1)))
269
+ (if (leaf child) (js-call preamble :push (str "- " (key-text key) ": " (atom child)))
270
+ (js-call sections :push (str "# " (key-text key t) "\n\n" (js-call (funcall body child 0) :join "\n")))))))
271
+ (let ((parts (if (> (js-length preamble) 0) (js-array (js-call preamble :join "\n")) (js-array))))
272
+ (literal-each sections (lambda (section) (put parts (js-length parts) section)))
273
+ (let ((output (str (js-call parts :join "\n\n") "\n")))
274
+ (when (> (js-length output) max-length) (throw (new globalThis/RangeError "Markdown length limit"))) output))))))
275
+ (export MarkdownError parse encode))