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
@@ -1 +1 @@
1
- {"version":3,"file":"protocol-impl.mjs","sources":["../../stdlib/core/protocol.eli"],"sourcesContent":["(module eliscript.core.protocol\n (import \"../../runtime/core/protocol-error.mjs\" ProtocolDispatchError)\n\n (defconst protocol-states (js* \"new WeakMap()\"))\n (defconst protocol-missing (js* \"Symbol(\\\"eliscript.protocol.missing\\\")\"))\n (defconst protocol-host-categories\n (js-array \"null\" \"undefined\" \"boolean\" \"number\" \"bigint\" \"string\"\n \"symbol\" \"function\" \"object\"))\n (defconst protocol-definition-format \"eliscript-protocol-definition\")\n (defconst protocol-definition-version 1)\n (defconst protocol-max-operations 1024)\n\n ;; These capabilities isolate host reflection from dispatch policy. They are\n ;; deliberately private and contain no protocol-specific decisions.\n (defconst protocol-symbol (js* \"(description) => Symbol(description)\"))\n (defconst protocol-array? (js* \"Array.isArray\"))\n (defconst protocol-map (js* \"() => new Map()\"))\n (defconst protocol-null-object (js* \"() => Object.create(null)\"))\n (defconst protocol-own-descriptors\n (js* \"Object.getOwnPropertyDescriptors\"))\n (defconst protocol-own-keys (js* \"Reflect.ownKeys\"))\n (defconst protocol-has-own\n (js* \"(value, key) => Object.prototype.hasOwnProperty.call(value, key)\"))\n (defconst protocol-property-present\n (js* \"(value, key) => { if (value === null || value === undefined) return false; return Reflect.has(Object(value), key); }\"))\n (defconst protocol-property-value\n (js* \"(value, key) => Object(value)[key]\"))\n (defconst protocol-host-type (js* \"(value) => typeof value\"))\n (defconst protocol-exact-prototype\n (js* \"(value, missing) => ((typeof value === \\\"object\\\" && value !== null) || typeof value === \\\"function\\\") ? Object.getPrototypeOf(value) : missing\"))\n (defconst protocol-object-prototype (js* \"Object.prototype\"))\n (defconst protocol-get-prototype (js* \"Object.getPrototypeOf\"))\n (defconst protocol-freeze (js* \"Object.freeze\"))\n (defconst protocol-define-enumerable\n (js* \"(target, key, value) => { Object.defineProperty(target, key, { value, enumerable: true }); return target; }\"))\n (defconst protocol-define-metadata\n (js* \"(target, protocol, operation, slot) => { Object.defineProperties(target, { protocol: { value: protocol }, operation: { value: operation }, slot: { value: slot } }); return target; }\"))\n\n (defun protocol-fail (message)\n (throw (new globalThis/TypeError message)))\n\n (defun protocol-state (protocol)\n (let ((state (js-call protocol-states :get protocol)))\n (if (undefined? state)\n (protocol-fail \"expected an Eliscript protocol\")\n state)))\n\n (defun normalize-name (value label)\n (if (or (not (= (value-type value) \"string\"))\n (= (js-length value) 0))\n (protocol-fail (str label \" must be a non-empty string\"))\n value))\n\n (defun normalize-protocol-operations (operations)\n (when (not (funcall protocol-array? operations))\n (protocol-fail \"protocol operations must be a non-empty dense array\"))\n (let ((length (js-length operations)))\n (when (= length 0)\n (protocol-fail \"protocol operations must be a non-empty dense array\"))\n (when (> length protocol-max-operations)\n (protocol-fail\n (str \"protocol operations exceed \" protocol-max-operations)))\n (let* ((descriptors (funcall protocol-own-descriptors operations))\n (keys (funcall protocol-own-keys descriptors))\n (normalized (js-array))\n (index 0))\n ;; A dense Array has one own descriptor per item plus \"length\". This\n ;; also rejects Symbol keys and named side-channel properties.\n (when (/= (js-length keys) (1+ length))\n (protocol-fail\n \"protocol operations must be a dense array with no extra properties\"))\n (while (< index length)\n (let ((descriptor (get descriptors (str index) undefined)))\n (when (or (undefined? descriptor)\n (not (funcall protocol-has-own descriptor \"value\"))\n (not (get descriptor :enumerable false)))\n (protocol-fail\n \"protocol operations must contain enumerable data values\"))\n (js-call normalized :push\n (normalize-name (get descriptor :value)\n \"protocol operation\")))\n (setq index (1+ index)))\n normalized)))\n\n (defun protocol-definition-field (descriptors name)\n (let ((descriptor (get descriptors name undefined)))\n (when (or (undefined? descriptor)\n (not (funcall protocol-has-own descriptor \"value\"))\n (not (get descriptor :enumerable false)))\n (protocol-fail\n (str \"protocol definition field \" name\n \" must be an enumerable data property\")))\n (get descriptor :value)))\n\n (defun normalize-protocol-definition (definition)\n (when (or (nil? definition)\n (not (= (value-type definition) \"object\"))\n (funcall protocol-array? definition))\n (protocol-fail \"protocol definition must be a plain object\"))\n (let ((prototype (funcall protocol-get-prototype definition)))\n (when (and (/= prototype protocol-object-prototype)\n (not (nil? prototype)))\n (protocol-fail \"protocol definition must be a plain object\")))\n (let* ((descriptors (funcall protocol-own-descriptors definition))\n (keys (funcall protocol-own-keys descriptors)))\n (when (/= (js-length keys) 4)\n (protocol-fail\n \"protocol definition must contain exactly format, version, name, and operations\"))\n (let ((format (protocol-definition-field descriptors \"format\"))\n (version (protocol-definition-field descriptors \"version\"))\n (name (protocol-definition-field descriptors \"name\"))\n (operations (protocol-definition-field descriptors \"operations\")))\n (when (/= format protocol-definition-format)\n (protocol-fail (str \"unsupported protocol definition format \" format)))\n (when (/= version protocol-definition-version)\n (protocol-fail (str \"unsupported protocol definition version \" version)))\n (js-object :name (normalize-name name \"protocol name\")\n :operations (normalize-protocol-operations operations)))))\n\n (defun operation-record (protocol operation)\n (let* ((state (protocol-state protocol))\n (record (js-call (get state :operations) :get operation)))\n (if (undefined? record)\n (protocol-fail\n (str \"protocol \" (get protocol :name) \" has no operation \" operation))\n record)))\n\n (defun protocol-host-category (value)\n (if (nil? value) \"null\" (funcall protocol-host-type value)))\n\n (defun known-host-category? (category)\n (let ((index 0)\n (found false))\n (while (and (< index (js-length protocol-host-categories)) (not found))\n (when (= category (js-nth index protocol-host-categories))\n (setq found t))\n (setq index (1+ index)))\n found))\n\n (defun normalize-implementations (protocol implementations)\n (when (or (nil? implementations)\n (not (= (value-type implementations) \"object\")))\n (protocol-fail\n (str \"protocol \" (get protocol :name)\n \" implementations must be an object\")))\n (let* ((descriptors (funcall protocol-own-descriptors implementations))\n (keys (funcall protocol-own-keys descriptors))\n (normalized (funcall protocol-null-object))\n (index 0))\n (when (= (js-length keys) 0)\n (protocol-fail\n (str \"protocol \" (get protocol :name)\n \" extension must implement at least one operation\")))\n (while (< index (js-length keys))\n (let* ((key (js-nth index keys))\n (descriptor (get descriptors key)))\n (when (not (= (value-type key) \"string\"))\n (protocol-fail\n (str \"protocol \" (get protocol :name)\n \" implementation names must be strings\")))\n (operation-record protocol key)\n (when (or (not (funcall protocol-has-own descriptor \"value\"))\n (not (= (value-type (get descriptor :value)) \"function\")))\n (protocol-fail\n (str \"protocol \" (get protocol :name) \"/\" key\n \" implementation must be a function\")))\n (funcall protocol-define-enumerable\n normalized key (get descriptor :value)))\n (setq index (1+ index)))\n (funcall protocol-freeze normalized)))\n\n (defun merge-implementations (current incoming)\n (let ((merged (funcall protocol-null-object))\n (copy nil))\n (setq copy\n (lambda (source)\n (unless (nullish? source)\n (let ((keys (object-keys source))\n (index 0))\n (while (< index (js-length keys))\n (let ((key (js-nth index keys)))\n (funcall protocol-define-enumerable\n merged key (get source key)))\n (setq index (1+ index)))))))\n (funcall copy current)\n (funcall copy incoming)\n (funcall protocol-freeze merged)))\n\n (defun direct-method (record receiver)\n (if (or (nil? receiver) (undefined? receiver))\n protocol-missing\n (let ((slot (get record :slot)))\n (if (not (funcall protocol-property-present receiver slot))\n protocol-missing\n (let ((method (funcall protocol-property-value receiver slot)))\n (if (= (value-type method) \"function\") method nil))))))\n\n (defun external-method (state record receiver)\n (let* ((prototype\n (funcall protocol-exact-prototype receiver protocol-missing))\n (exact-implementations\n (if (= prototype protocol-missing)\n undefined\n (js-call (get state :types) :get prototype)))\n (exact\n (if (undefined? exact-implementations)\n undefined\n (get exact-implementations (get record :name) undefined))))\n (if (not (undefined? exact))\n exact\n (let* ((category-implementations\n (js-call (get state :categories) :get\n (protocol-host-category receiver)))\n (category\n (if (undefined? category-implementations)\n undefined\n (get category-implementations\n (get record :name) undefined))))\n (if (not (undefined? category))\n category\n (get (get state :defaults)\n (get record :name) protocol-missing))))))\n\n (defun dispatch (protocol record receiver arguments)\n (let ((direct (direct-method record receiver)))\n (when (nil? direct)\n (throw\n (new ProtocolDispatchError\n protocol (get record :name) receiver \"invalid-direct-slot\")))\n (if (/= direct protocol-missing)\n (js-call direct :apply receiver arguments)\n (let ((external\n (external-method (protocol-state protocol) record receiver)))\n (if (= external protocol-missing)\n (throw\n (new ProtocolDispatchError protocol (get record :name) receiver))\n (apply external (js-cons receiver arguments)))))))\n\n (defun define-protocol (name operations)\n (let ((protocol-name (normalize-name name \"protocol name\"))\n (protocol-operations (normalize-protocol-operations operations)))\n (let ((records (funcall protocol-map))\n (operation-table (funcall protocol-null-object))\n (protocol nil)\n (index 0))\n (while (< index (js-length protocol-operations))\n (let ((operation\n (js-nth index protocol-operations)))\n (when (js-call records :has operation)\n (protocol-fail\n (str \"protocol \" protocol-name\n \" declares duplicate operation \" operation)))\n (let* ((slot\n (funcall protocol-symbol\n (str \"eliscript.protocol.\"\n protocol-name \"/\" operation)))\n (method\n (lambda (&rest invocation)\n (when (= (js-length invocation) 0)\n (protocol-fail\n (str \"protocol \" protocol-name \"/\" operation\n \" requires a dispatch value\")))\n (dispatch protocol\n (js-call records :get operation)\n (aref invocation 0)\n (js-call invocation :slice 1))))\n (record\n (js-object :name operation :slot slot :method method)))\n (js-call records :set operation record)\n (funcall protocol-define-enumerable\n operation-table operation method)))\n (setq index (1+ index)))\n\n (setq protocol\n (funcall protocol-freeze\n (js-object :name protocol-name\n :operations\n (funcall protocol-freeze operation-table))))\n (setq index 0)\n (while (< index (js-length protocol-operations))\n (let* ((operation (js-nth index protocol-operations))\n (record (js-call records :get operation))\n (method (get record :method)))\n (funcall protocol-define-metadata\n method protocol operation (get record :slot))\n (funcall protocol-freeze method)\n (funcall protocol-freeze record))\n (setq index (1+ index)))\n\n (js-call protocol-states :set protocol\n (js-object :operations records\n :types (funcall protocol-map)\n :categories (funcall protocol-map)\n :defaults\n (funcall protocol-freeze\n (funcall protocol-null-object))))\n protocol)))\n\n (defun protocol-definition (protocol)\n (protocol-state protocol)\n (let ((operations\n (js-call (object-keys (get protocol :operations)) :slice)))\n (funcall protocol-freeze operations)\n (funcall protocol-freeze\n (js-object :format protocol-definition-format\n :version protocol-definition-version\n :name (get protocol :name)\n :operations operations))))\n\n (defun define-protocol-from-definition (definition)\n (let ((normalized (normalize-protocol-definition definition)))\n (define-protocol (get normalized :name)\n (get normalized :operations))))\n\n (defun protocol-method (protocol operation)\n (get (operation-record protocol operation) :method))\n\n (defun protocol-slot (protocol operation)\n (get (operation-record protocol operation) :slot))\n\n (defun extend-protocol-type (protocol constructor implementations)\n (let ((state (protocol-state protocol)))\n (when (not (= (value-type constructor) \"function\"))\n (protocol-fail\n (str \"protocol \" (get protocol :name)\n \" exact type must be a constructor with a prototype\")))\n (let ((prototype (get constructor :prototype nil)))\n (when (or (nil? prototype)\n (not (= (value-type prototype) \"object\")))\n (protocol-fail\n (str \"protocol \" (get protocol :name)\n \" exact type must be a constructor with a prototype\")))\n (let* ((normalized\n (normalize-implementations protocol implementations))\n (current (js-call (get state :types) :get prototype)))\n (js-call (get state :types) :set prototype\n (merge-implementations current normalized)))\n protocol)))\n\n (defun extend-protocol-category (protocol category implementations)\n (let ((state (protocol-state protocol)))\n (when (not (known-host-category? category))\n (protocol-fail (str \"unknown protocol host category \" category)))\n (let* ((normalized\n (normalize-implementations protocol implementations))\n (current (js-call (get state :categories) :get category)))\n (js-call (get state :categories) :set category\n (merge-implementations current normalized)))\n protocol))\n\n (defun extend-protocol-default (protocol implementations)\n (let* ((state (protocol-state protocol))\n (normalized (normalize-implementations protocol implementations)))\n (put state :defaults\n (merge-implementations (get state :defaults) normalized))\n protocol))\n\n (defun implements-protocol-operation? (protocol operation value)\n (let* ((record (operation-record protocol operation))\n (direct (direct-method record value)))\n (and (not (nil? direct))\n (or (/= direct protocol-missing)\n (/= (external-method (protocol-state protocol) record value)\n protocol-missing)))))\n\n (defun implements-protocol? (protocol value)\n (let* ((state (protocol-state protocol))\n (operations (object-keys (get protocol :operations)))\n (index 0)\n (implemented t))\n (while (and (< index (js-length operations)) implemented)\n (let* ((record\n (js-call (get state :operations) :get (js-nth index operations)))\n (direct (direct-method record value)))\n (when (or (nil? direct)\n (and (= direct protocol-missing)\n (= (external-method state record value)\n protocol-missing)))\n (setq implemented false)))\n (setq index (1+ index)))\n implemented))\n\n (export define-protocol define-protocol-from-definition\n extend-protocol-category extend-protocol-default\n extend-protocol-type implements-protocol-operation?\n implements-protocol? protocol-definition protocol-host-category\n protocol-method protocol-slot))\n"],"names":[],"mappings":";;;AACE,QAAgD;AAEhD,wBAA0B;AAC1B,yBAA2B;AAC3B,iCACE,CAAU,QAAO,aAAY,WAAU,UAAS,UAAS,UACxD,UAAS,YAAW;A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iC,UAAS,UAAS;SACjD,EAAM;IACJ,oBAAM,qBAAM,2BAAqB,eAC9B,cAAc,QAAK,4CAAkC;IACxD,EAAO;eAEA;eACL,CAAS,CAAK,OAAM,eAAa,OAAK,UAC5B,sBAAsB,SAAQ;SAF1B,CAAS,CAAK,OAAM,eAAa,OAAK;OAD7C,0BAA0B,UAAS;WAI5C;KARY,eAAe;;AAU/B,iCAAgC,UAAS;SACvC,EAAO;aACA;;QACL,EAAK,OAAM,cACL,sBAAsB,CAAK,OAAM,aAAW;eAClD;;OAHkB,0BAA0B,UAAS;KADxC,eAAe;;AAMhC,8CAAuC,UAAS,WAAU;SACxD,EAAO;aACA;aACL,uEACK,8FACI,kGAAK,gBAAiB,eAAe,WAAU,QAAO,QAClD,oBAFJ,kGAAI,QAAO,4CADf,qBAAK,CAAM;OADF,cAAc,QAAO;KADrB,iBAAiB,UAAS;;AAO5C,oCAA6B,UAAS;SACpC,EAAO;aACA;eACA;iBACA;;YACL;wCAAO,uEAAsC,qCAAjC,CAAG,QAAM,EAAW;gBAC9B,EAAO;2BAEA;2BACL,oBAAM,8FACI,uEACK,CAAI,gBAAgB,OAAM,QAAO,WAC9B,2CAFH,CAAG,WAAO,qBADf,CAAM,qBAId,CAAM,CAAA,cAAY;qBALN,cAAc,QAAO;mBAD7B,CAAS,CAAK,OAAM,eAAa,OAAK,IAAc,mBAAN;gBAOtD,CAAM,CAAA,QAAM,CAAI;;;;mBAClB;;WAXkB;SADN;OADK,aAAa,CAAK,UAAS;KAD/B,eAAe;;AAgBhC,QAAQ,iBAAgB,iCAChB,0BAAyB,yBACzB,sBAAqB,sCACrB,4BAAqB,qBAAoB,wBACzC,iBAAgB"}
1
+ {"version":3,"file":"protocol-impl.mjs","sources":["../../stdlib/core/protocol.eli"],"sourcesContent":["(module eliscript.core.protocol\n (import \"../../runtime/core/protocol-error.mjs\" ProtocolDispatchError)\n\n (defconst protocol-states (new globalThis/WeakMap))\n (defconst protocol-operation-owners (new globalThis/WeakMap))\n (defconst protocol-method-owners (new globalThis/WeakMap))\n (defconst protocol-missing\n (funcall globalThis/Symbol \"eliscript.protocol.missing\"))\n (defconst protocol-host-categories\n (js-array \"null\" \"undefined\" \"boolean\" \"number\" \"bigint\" \"string\"\n \"symbol\" \"function\" \"object\"))\n (defconst protocol-definition-format \"eliscript-protocol-definition\")\n (defconst protocol-definition-version 1)\n (defconst protocol-max-operations 1024)\n\n ;; These capabilities isolate host reflection from dispatch policy. They are\n ;; deliberately private and contain no protocol-specific decisions.\n (defconst protocol-symbol\n (lambda (description) (funcall globalThis/Symbol description)))\n (defconst protocol-array? (js* \"Array.isArray\"))\n (defconst protocol-map (lambda () (new globalThis/Map)))\n (defconst protocol-null-object\n (lambda () (js-call globalThis/Object :create nil)))\n (defconst protocol-own-descriptors\n (js* \"Object.getOwnPropertyDescriptors\"))\n (defconst protocol-own-keys (js* \"Reflect.ownKeys\"))\n (defconst protocol-has-own\n (lambda (value key)\n (js-call (aref (aref globalThis/Object \"prototype\") \"hasOwnProperty\")\n :call value key)))\n (defconst protocol-property-present\n (lambda (value key)\n (if (or (nil? value) (undefined? value))\n false\n (js-call globalThis/Reflect :has (funcall globalThis/Object value) key))))\n (defconst protocol-property-value\n (lambda (value key) (aref (funcall globalThis/Object value) key)))\n (defconst protocol-host-type (lambda (value) (js* \"typeof value\")))\n (defconst protocol-exact-prototype\n (lambda (value missing)\n (if (or (and (= (js* \"typeof value\") \"object\") (not (nil? value)))\n (= (js* \"typeof value\") \"function\"))\n (js-call globalThis/Object :getPrototypeOf value)\n missing)))\n (defconst protocol-object-prototype (js* \"Object.prototype\"))\n (defconst protocol-get-prototype (js* \"Object.getPrototypeOf\"))\n (defconst protocol-freeze (js* \"Object.freeze\"))\n (defconst protocol-define-enumerable\n (lambda (target key value)\n (js-call globalThis/Object :defineProperty target key\n (js-object :value value :enumerable t))\n target))\n (defconst protocol-define-metadata\n (lambda (target protocol operation slot)\n (js-call globalThis/Object :defineProperties target\n (js-object :protocol (js-object :value protocol)\n :operation (js-object :value operation)\n :slot (js-object :value slot)))\n target))\n\n (defun protocol-fail (message)\n (throw (new globalThis/TypeError message)))\n\n (defun protocol-state (protocol)\n (let ((state (js-call protocol-states :get protocol)))\n (if (undefined? state)\n (protocol-fail \"expected an Eliscript protocol\")\n state)))\n\n (defun normalize-name (value label)\n (if (or (not (= (value-type value) \"string\"))\n (= (js-length value) 0))\n (protocol-fail (str label \" must be a non-empty string\"))\n value))\n\n (defun normalize-protocol-operations (operations)\n (when (not (funcall protocol-array? operations))\n (protocol-fail \"protocol operations must be a non-empty dense array\"))\n (let ((length (js-length operations)))\n (when (= length 0)\n (protocol-fail \"protocol operations must be a non-empty dense array\"))\n (when (> length protocol-max-operations)\n (protocol-fail\n (str \"protocol operations exceed \" protocol-max-operations)))\n (let* ((descriptors (funcall protocol-own-descriptors operations))\n (keys (funcall protocol-own-keys descriptors))\n (normalized (js-array))\n (index 0))\n ;; A dense Array has one own descriptor per item plus \"length\". This\n ;; also rejects Symbol keys and named side-channel properties.\n (when (/= (js-length keys) (1+ length))\n (protocol-fail\n \"protocol operations must be a dense array with no extra properties\"))\n (while (< index length)\n (let ((descriptor (get descriptors (str index) undefined)))\n (when (or (undefined? descriptor)\n (not (funcall protocol-has-own descriptor \"value\"))\n (not (get descriptor :enumerable false)))\n (protocol-fail\n \"protocol operations must contain enumerable data values\"))\n (js-call normalized :push\n (normalize-name (get descriptor :value)\n \"protocol operation\")))\n (setq index (1+ index)))\n normalized)))\n\n (defun protocol-definition-field (descriptors name)\n (let ((descriptor (get descriptors name undefined)))\n (when (or (undefined? descriptor)\n (not (funcall protocol-has-own descriptor \"value\"))\n (not (get descriptor :enumerable false)))\n (protocol-fail\n (str \"protocol definition field \" name\n \" must be an enumerable data property\")))\n (get descriptor :value)))\n\n (defun normalize-protocol-definition (definition)\n (when (or (nil? definition)\n (not (= (value-type definition) \"object\"))\n (funcall protocol-array? definition))\n (protocol-fail \"protocol definition must be a plain object\"))\n (let ((prototype (funcall protocol-get-prototype definition)))\n (when (and (/= prototype protocol-object-prototype)\n (not (nil? prototype)))\n (protocol-fail \"protocol definition must be a plain object\")))\n (let* ((descriptors (funcall protocol-own-descriptors definition))\n (keys (funcall protocol-own-keys descriptors)))\n (when (/= (js-length keys) 4)\n (protocol-fail\n \"protocol definition must contain exactly format, version, name, and operations\"))\n (let ((format (protocol-definition-field descriptors \"format\"))\n (version (protocol-definition-field descriptors \"version\"))\n (name (protocol-definition-field descriptors \"name\"))\n (operations (protocol-definition-field descriptors \"operations\")))\n (when (/= format protocol-definition-format)\n (protocol-fail (str \"unsupported protocol definition format \" format)))\n (when (/= version protocol-definition-version)\n (protocol-fail (str \"unsupported protocol definition version \" version)))\n (js-object :name (normalize-name name \"protocol name\")\n :operations (normalize-protocol-operations operations)))))\n\n (defun operation-record (protocol operation)\n (let* ((state (protocol-state protocol))\n (record (js-call (get state :operations) :get operation)))\n (if (undefined? record)\n (protocol-fail\n (str \"protocol \" (get protocol :name) \" has no operation \" operation))\n record)))\n\n (defun protocol-host-category (value)\n (if (nil? value) \"null\" (funcall protocol-host-type value)))\n\n (defun known-host-category? (category)\n (let ((index 0)\n (found false))\n (while (and (< index (js-length protocol-host-categories)) (not found))\n (when (= category (js-nth index protocol-host-categories))\n (setq found t))\n (setq index (1+ index)))\n found))\n\n (defun normalize-implementations (protocol implementations)\n (when (or (nil? implementations)\n (not (= (value-type implementations) \"object\")))\n (protocol-fail\n (str \"protocol \" (get protocol :name)\n \" implementations must be an object\")))\n (let* ((descriptors (funcall protocol-own-descriptors implementations))\n (keys (funcall protocol-own-keys descriptors))\n (normalized (funcall protocol-null-object))\n (index 0))\n (when (= (js-length keys) 0)\n (protocol-fail\n (str \"protocol \" (get protocol :name)\n \" extension must implement at least one operation\")))\n (while (< index (js-length keys))\n (let* ((key (js-nth index keys))\n (descriptor (get descriptors key)))\n (when (not (= (value-type key) \"string\"))\n (protocol-fail\n (str \"protocol \" (get protocol :name)\n \" implementation names must be strings\")))\n (operation-record protocol key)\n (when (or (not (funcall protocol-has-own descriptor \"value\"))\n (not (= (value-type (get descriptor :value)) \"function\")))\n (protocol-fail\n (str \"protocol \" (get protocol :name) \"/\" key\n \" implementation must be a function\")))\n (funcall protocol-define-enumerable\n normalized key (get descriptor :value)))\n (setq index (1+ index)))\n (funcall protocol-freeze normalized)))\n\n (defun merge-implementations (current incoming)\n (let ((merged (funcall protocol-null-object))\n (copy nil))\n (setq copy\n (lambda (source)\n (unless (nullish? source)\n (let ((keys (object-keys source))\n (index 0))\n (while (< index (js-length keys))\n (let ((key (js-nth index keys)))\n (funcall protocol-define-enumerable\n merged key (get source key)))\n (setq index (1+ index)))))))\n (funcall copy current)\n (funcall copy incoming)\n (funcall protocol-freeze merged)))\n\n (defun direct-method (record receiver)\n (if (or (nil? receiver) (undefined? receiver))\n protocol-missing\n (let ((slot (get record :slot)))\n (if (not (funcall protocol-property-present receiver slot))\n protocol-missing\n (let ((method (funcall protocol-property-value receiver slot)))\n (if (= (value-type method) \"function\") method nil))))))\n\n (defun external-method (state record receiver)\n (let* ((prototype\n (funcall protocol-exact-prototype receiver protocol-missing))\n (exact-implementations\n (if (= prototype protocol-missing)\n undefined\n (js-call (get state :types) :get prototype)))\n (exact\n (if (undefined? exact-implementations)\n undefined\n (get exact-implementations (get record :name) undefined))))\n (if (not (undefined? exact))\n exact\n (let* ((category-implementations\n (js-call (get state :categories) :get\n (protocol-host-category receiver)))\n (category\n (if (undefined? category-implementations)\n undefined\n (get category-implementations\n (get record :name) undefined))))\n (if (not (undefined? category))\n category\n (get (get state :defaults)\n (get record :name) protocol-missing))))))\n\n (defun dispatch (protocol record receiver arguments)\n (let ((direct (direct-method record receiver)))\n (when (nil? direct)\n (throw\n (new ProtocolDispatchError\n protocol (get record :name) receiver \"invalid-direct-slot\")))\n (if (/= direct protocol-missing)\n (js-call direct :apply receiver arguments)\n (let ((external\n (external-method (protocol-state protocol) record receiver)))\n (if (= external protocol-missing)\n (throw\n (new ProtocolDispatchError protocol (get record :name) receiver))\n (apply external (js-cons receiver arguments)))))))\n\n (defun make-protocol-with-slots (name operations slots)\n (let ((protocol-name (normalize-name name \"protocol name\"))\n (protocol-operations (normalize-protocol-operations operations)))\n (let ((records (funcall protocol-map))\n (operation-table (funcall protocol-null-object))\n (protocol nil)\n (index 0))\n (while (< index (js-length protocol-operations))\n (let ((operation\n (js-nth index protocol-operations)))\n (when (js-call records :has operation)\n (protocol-fail\n (str \"protocol \" protocol-name\n \" declares duplicate operation \" operation)))\n (let* ((slot\n (if (nil? slots)\n (funcall protocol-symbol\n (str \"eliscript.protocol.\" protocol-name \"/\" operation))\n (get slots index)))\n (method\n (lambda (&rest invocation)\n (when (= (js-length invocation) 0)\n (protocol-fail\n (str \"protocol \" protocol-name \"/\" operation\n \" requires a dispatch value\")))\n (dispatch protocol\n (js-call records :get operation)\n (aref invocation 0)\n (js-call invocation :slice 1))))\n (record\n (js-object :name operation :slot slot :method method)))\n (js-call records :set operation record)\n (funcall protocol-define-enumerable\n operation-table operation method)))\n (setq index (1+ index)))\n\n (setq protocol\n (funcall protocol-freeze\n (js-object :name protocol-name\n :operations\n (funcall protocol-freeze operation-table))))\n (js-call protocol-operation-owners :set operation-table protocol)\n (setq index 0)\n (while (< index (js-length protocol-operations))\n (let* ((operation (js-nth index protocol-operations))\n (record (js-call records :get operation))\n (method (get record :method)))\n (funcall protocol-define-metadata\n method protocol operation (get record :slot))\n (js-call protocol-method-owners :set method\n (funcall protocol-freeze\n (js-object :protocol protocol :operation operation)))\n (funcall protocol-freeze method)\n (funcall protocol-freeze record))\n (setq index (1+ index)))\n\n (js-call protocol-states :set protocol\n (js-object :operations records\n :types (funcall protocol-map)\n :categories (funcall protocol-map)\n :defaults\n (funcall protocol-freeze\n (funcall protocol-null-object))))\n protocol)))\n\n (defun define-protocol (name operations)\n (make-protocol-with-slots name operations nil))\n\n (defun protocol-definition (protocol)\n (protocol-state protocol)\n (let ((operations\n (js-call (object-keys (get protocol :operations)) :slice)))\n (funcall protocol-freeze operations)\n (funcall protocol-freeze\n (js-object :format protocol-definition-format\n :version protocol-definition-version\n :name (get protocol :name)\n :operations operations))))\n\n (defun define-protocol-from-definition (definition)\n (let ((normalized (normalize-protocol-definition definition)))\n (define-protocol (get normalized :name)\n (get normalized :operations))))\n\n ;; Bulk materialization reuses already transported Symbols, so observing a\n ;; slot before its protocol does not create two identities for one slot.\n (defun materialize-protocol-from-definition (definition slots)\n (let* ((normalized (normalize-protocol-definition definition))\n (operations (get normalized :operations)))\n (unless (and (funcall protocol-array? slots) (= (js-length slots) (js-length operations)))\n (protocol-fail \"protocol slots must be a dense array matching its operations\"))\n (let* ((descriptors (funcall protocol-own-descriptors slots))\n (keys (funcall protocol-own-keys descriptors))\n (seen (new globalThis/Set)) (symbols (js-array)) (index 0))\n (unless (= (js-length keys) (1+ (js-length slots)))\n (protocol-fail \"protocol slots must be a dense array with no extra properties\"))\n (while (< index (js-length slots))\n (let* ((descriptor (get descriptors (str index) undefined))\n (value (if (undefined? descriptor) undefined (get descriptor :value))))\n (unless (and (not (undefined? descriptor))\n (funcall protocol-has-own descriptor \"value\")\n (get descriptor :enumerable false)\n (= (funcall protocol-host-type value) \"symbol\"))\n (protocol-fail \"protocol slots must contain enumerable Symbol data values\"))\n (when (js-call seen :has value) (protocol-fail \"protocol slots must be distinct Symbols\"))\n (js-call seen :add value) (js-call symbols :push value))\n (setq index (1+ index)))\n (make-protocol-with-slots (get normalized :name) operations symbols))))\n\n (defun protocol-method (protocol operation)\n (get (operation-record protocol operation) :method))\n\n (defun protocol-slot (protocol operation)\n (get (operation-record protocol operation) :slot))\n\n (defun extend-protocol-type (protocol constructor implementations)\n (let ((state (protocol-state protocol)))\n (when (not (= (value-type constructor) \"function\"))\n (protocol-fail\n (str \"protocol \" (get protocol :name)\n \" exact type must be a constructor with a prototype\")))\n (let ((prototype (get constructor :prototype nil)))\n (when (or (nil? prototype)\n (not (= (value-type prototype) \"object\")))\n (protocol-fail\n (str \"protocol \" (get protocol :name)\n \" exact type must be a constructor with a prototype\")))\n (let* ((normalized\n (normalize-implementations protocol implementations))\n (current (js-call (get state :types) :get prototype)))\n (js-call (get state :types) :set prototype\n (merge-implementations current normalized)))\n protocol)))\n\n (defun extend-protocol-category (protocol category implementations)\n (let ((state (protocol-state protocol)))\n (when (not (known-host-category? category))\n (protocol-fail (str \"unknown protocol host category \" category)))\n (let* ((normalized\n (normalize-implementations protocol implementations))\n (current (js-call (get state :categories) :get category)))\n (js-call (get state :categories) :set category\n (merge-implementations current normalized)))\n protocol))\n\n (defun extend-protocol-default (protocol implementations)\n (let* ((state (protocol-state protocol))\n (normalized (normalize-implementations protocol implementations)))\n (put state :defaults\n (merge-implementations (get state :defaults) normalized))\n protocol))\n\n (defun implements-protocol-operation? (protocol operation value)\n (let* ((record (operation-record protocol operation))\n (direct (direct-method record value)))\n (and (not (nil? direct))\n (or (/= direct protocol-missing)\n (/= (external-method (protocol-state protocol) record value)\n protocol-missing)))))\n\n (defun implements-protocol? (protocol value)\n (let* ((state (protocol-state protocol))\n (operations (object-keys (get protocol :operations)))\n (index 0)\n (implemented t))\n (while (and (< index (js-length operations)) implemented)\n (let* ((record\n (js-call (get state :operations) :get (js-nth index operations)))\n (direct (direct-method record value)))\n (when (or (nil? direct)\n (and (= direct protocol-missing)\n (= (external-method state record value)\n protocol-missing)))\n (setq implemented false)))\n (setq index (1+ index)))\n implemented))\n\n (defun protocol? (value) (js-call protocol-states :has value))\n\n (defun read-protocol-operations-owner (value)\n (js-call protocol-operation-owners :get value))\n\n (defun read-protocol-method-owner (value)\n (js-call protocol-method-owners :get value))\n\n (export protocol? define-protocol define-protocol-from-definition materialize-protocol-from-definition\n read-protocol-operations-owner read-protocol-method-owner\n extend-protocol-category extend-protocol-default\n extend-protocol-type implements-protocol-operation?\n implements-protocol? protocol-definition protocol-host-category\n protocol-method protocol-slot))\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AA;;;;AAEJ,iCAAgC,UAAS;EACvC;QAAO,QAAQ,eAAe;QACvB,aAAa,0BAA0B,UAAS;IACrD,EAAK,OAAM,cACL,sBAAsB,CAAK,OAAM,aAAW;IAClD,OAAA;;;AAEJ,8CAAuC,UAAS,WAAU;EACxD;QAAO,SAAS,iBAAiB,UAAS;QACnC,SAAS,cAAc,QAAO;IACnC,OAAA,CAAK,EAAK,CAAM,qBACX,CAAI,kGAAI,QAAO,+BACX,kGAAK,gBAAiB,eAAe,WAAU,QAAO,QAClD;;;AAEjB,oCAA6B,UAAS;EACpC;QAAO,QAAQ,eAAe;QACvB,aAAY,aAAa,CAAK,UAAS;QACvC,QAAO;QACP,cAAa;IAClB,0BAAO,uEAAsC,qCAAjC,kCAAG,OAAM,EAAW;MAC9B;YAAO,SACC,CAAS,CAAK,OAAM,eAAa,OAAK,IAAc,mBAAN;YAC/C,SAAS,cAAc,QAAO;QACnC,IAAM,CAAI,CAAM,oBACN,CAAK,CAAG,WAAO,+BACV,CAAI,gBAAgB,OAAM,QAAO,WAC9B;UAChB,CAAM,CAAA,cAAY;;;MACtB,CAAM,CAAA,QAAM,CAAI;;IAClB,OAAA;;;AAEJ,yBAAkB;EAAO,OAAA,CAAS,4BAAgB,OAAK;;AAEvD,wCAAuC;EACrC,OAAA,CAAS,4BAA0B,OAAK;;AAE1C,oCAAmC;EACjC,OAAA,CAAS,4BAAuB,OAAK;;AAEvC,QAAQ,iBAAU,iBAAgB,iCAAgC,sCAC1D,gCAA+B,4BAC/B,0BAAyB,yBACzB,sBAAqB,sCACrB,4BAAqB,qBAAoB,wBACzC,iBAAgB"}
@@ -10,5 +10,9 @@ export {
10
10
  protocol_definition as protocolDefinition,
11
11
  protocol_host_category as protocolHostCategory,
12
12
  protocol_method as protocolMethod,
13
+ protocol_QMARK_ as isProtocol,
14
+ materialize_protocol_from_definition as materializeProtocolFromDefinition,
15
+ read_protocol_operations_owner as readProtocolOperationsOwner,
16
+ read_protocol_method_owner as readProtocolMethodOwner,
13
17
  protocol_slot as protocolSlot,
14
18
  } from "./protocol-impl.mjs";
@@ -124,9 +124,13 @@ function normalizeSourceMap(typeState, source) {
124
124
  return map;
125
125
  }
126
126
 
127
- export function defineRecordType(name, fields) {
127
+ function makeRecordType(name, fields, reuseFields) {
128
128
  const typeName = normalizeTypeName(name);
129
- const fieldNames = normalizeFieldNames(fields);
129
+ const normalizedFields = normalizeFieldNames(fields);
130
+ if (reuseFields && !Object.isFrozen(fields)) {
131
+ fail("materialized record fields must be a frozen array");
132
+ }
133
+ const fieldNames = reuseFields ? fields : normalizedFields;
130
134
  const fieldKeys = Object.freeze(fieldNames.map((field) => keyword(field)));
131
135
  const fieldIndexes = new Map(
132
136
  fieldNames.map((field, index) => [field, index]),
@@ -321,6 +325,14 @@ export function defineRecordType(name, fields) {
321
325
  return RecordValue;
322
326
  }
323
327
 
328
+ export function defineRecordType(name, fields) {
329
+ return makeRecordType(name, fields, false);
330
+ }
331
+
332
+ export function materializeRecordType(name, fields) {
333
+ return makeRecordType(name, fields, true);
334
+ }
335
+
324
336
  export function isRecordType(value) {
325
337
  return typeof value === "function" && recordTypes.has(value);
326
338
  }
@@ -344,3 +356,12 @@ export function recordFieldNames(value) {
344
356
  const type = isRecordType(value) ? value : recordType(value);
345
357
  return type.recordFields;
346
358
  }
359
+
360
+ // The bulk transport reads the constructor's actual immutable payload without
361
+ // guessing a private Symbol from its description or invoking a state getter.
362
+ export function readRecordState(value) {
363
+ if (value === null || typeof value !== "object") return undefined;
364
+ const descriptor = Object.getOwnPropertyDescriptor(value, RECORD_STATE);
365
+ return descriptor !== undefined && "value" in descriptor
366
+ ? descriptor.value : undefined;
367
+ }
@@ -41,6 +41,10 @@ function stateOf(pattern) {
41
41
  return state;
42
42
  }
43
43
 
44
+ export function readRegexState(value) {
45
+ return patternStates.get(value);
46
+ }
47
+
44
48
  function nativePattern(pattern, global = false) {
45
49
  const state = stateOf(pattern);
46
50
  return new RegExp(state.source, global ? `${state.flags}g` : state.flags);
@@ -31,6 +31,7 @@ import {
31
31
  import {
32
32
  SORTED_MAP_STATE,
33
33
  SORTED_SET_STATE,
34
+ SortedNode,
34
35
  sortedAssoc,
35
36
  sortedDissoc,
36
37
  sortedEntries,
@@ -55,6 +56,14 @@ const SET_HASH_TAG = 0x51e7_b32d;
55
56
  const BOUND_TESTS = new Set(["<", "<=", ">", ">="]);
56
57
  const DEFAULT_COMPARATOR = comparator(compareValues);
57
58
 
59
+ export function isDefaultSortedComparator(value) {
60
+ return value === DEFAULT_COMPARATOR;
61
+ }
62
+
63
+ export function defaultSortedComparator() {
64
+ return DEFAULT_COMPARATOR;
65
+ }
66
+
58
67
  function normalizeComparator(comparison) {
59
68
  return comparison === compareValues || comparison === DEFAULT_COMPARATOR
60
69
  ? DEFAULT_COMPARATOR
@@ -74,6 +83,50 @@ function makeSet(map, metadata = null) {
74
83
  return new PersistentSortedSet(SORTED_SET_TOKEN, map, metadata);
75
84
  }
76
85
 
86
+ export function readSortedMapState(value) {
87
+ if (!(value instanceof PersistentSortedMap)) return undefined;
88
+ const descriptor = Object.getOwnPropertyDescriptor(value, SORTED_MAP_STATE);
89
+ return descriptor !== undefined && "value" in descriptor ? descriptor.value : undefined;
90
+ }
91
+
92
+ export function readSortedSetState(value) {
93
+ if (!(value instanceof PersistentSortedSet)) return undefined;
94
+ const descriptor = Object.getOwnPropertyDescriptor(value, SORTED_SET_STATE);
95
+ return descriptor !== undefined && "value" in descriptor ? descriptor.value : undefined;
96
+ }
97
+
98
+ // Transport already supplies ordered, unique data. Rebuild only its physical
99
+ // host representation; normalizing or comparing again would invoke user code
100
+ // a second time and change the comparator's observable identity.
101
+ function materializeSortedRoot(values, set, start, end) {
102
+ if (start === end) return null;
103
+ const middle = start + Math.floor((end - start) / 2);
104
+ const item = values[middle];
105
+ if (!set && (!Array.isArray(item) || item.length !== 2)) {
106
+ throw new TypeError("invalid sorted map transport entry");
107
+ }
108
+ return new SortedNode(
109
+ set ? item : item[0],
110
+ set ? PRESENT : item[1],
111
+ materializeSortedRoot(values, set, start, middle),
112
+ materializeSortedRoot(values, set, middle + 1, end),
113
+ );
114
+ }
115
+
116
+ export function materializeSortedMap(entries, comparison, metadata = null) {
117
+ if (!Array.isArray(entries) || typeof comparison !== "function") {
118
+ throw new TypeError("invalid sorted map transport record");
119
+ }
120
+ return makeMap(materializeSortedRoot(entries, false, 0, entries.length), comparison, metadata);
121
+ }
122
+
123
+ export function materializeSortedSet(values, comparison, metadata = null) {
124
+ if (!Array.isArray(values) || typeof comparison !== "function") {
125
+ throw new TypeError("invalid sorted set transport record");
126
+ }
127
+ return makeSet(makeMap(materializeSortedRoot(values, true, 0, values.length), comparison), metadata);
128
+ }
129
+
77
130
  function mapPairHash(entry, hash) {
78
131
  return finishHash(
79
132
  mixHash(mixHash(MAP_ENTRY_HASH_TAG, hash(entry[0])), hash(entry[1])),
@@ -1,95 +1,214 @@
1
1
  // Generated by Eliscript. Do not edit.
2
+ import "eliscript/runtime/unicode-case.mjs";
2
3
  const __eliscript_truthy = (value) => value !== false && value != null;
4
+ const __eliscript_number_intrinsic = globalThis.Number;
5
+ const __eliscript_bigint_intrinsic = globalThis.BigInt;
6
+ const __eliscript_numeric_apply = globalThis.Reflect.apply;
7
+ const __eliscript_numeric_symbol = globalThis.Symbol.toPrimitive;
8
+ const __eliscript_numeric_error = globalThis.TypeError;
9
+ const __eliscript_numeric_trim = globalThis.String.prototype.trim;
10
+ const __eliscript_numeric_slice = globalThis.String.prototype.slice;
11
+ const __eliscript_numeric_exec = globalThis.RegExp.prototype.exec;
12
+ const __eliscript_numeric_radix = /^(?:0[xX][0-9a-fA-F]+|0[oO][0-7]+|0[bB][01]+)$/;
13
+ const __eliscript_numeric_object = (value) => value !== null && (typeof value === "object" || typeof value === "function" || (typeof value === "undefined" && value !== void 0));
14
+ const __eliscript_numeric_primitive = (value) => {
15
+ if (!__eliscript_numeric_object(value)) return value;
16
+ const exotic = value[__eliscript_numeric_symbol];
17
+ if (exotic !== void 0 && exotic !== null) {
18
+ const result = __eliscript_numeric_apply(exotic, value, ["number"]);
19
+ if (!__eliscript_numeric_object(result)) return result;
20
+ throw new __eliscript_numeric_error("Cannot convert object to primitive value");
21
+ }
22
+ for (let index = 0; index < 2; index++) {
23
+ const method = value[index === 0 ? "valueOf" : "toString"];
24
+ if (typeof method === "function" || (typeof method === "undefined" && method !== void 0)) {
25
+ const result = __eliscript_numeric_apply(method, value, []);
26
+ if (!__eliscript_numeric_object(result)) return result;
27
+ }
28
+ }
29
+ throw new __eliscript_numeric_error("Cannot convert object to primitive value");
30
+ };
31
+ const __eliscript_to_number = (value) => {
32
+ const primitive = __eliscript_numeric_primitive(value);
33
+ if (typeof primitive === "string") {
34
+ const text = __eliscript_numeric_apply(__eliscript_numeric_trim, primitive, []);
35
+ if (__eliscript_numeric_apply(__eliscript_numeric_exec, __eliscript_numeric_radix, [text]) !== null) {
36
+ let first = 2;
37
+ while (first < text.length && text[first] === "0") first++;
38
+ if (first === text.length) return 0;
39
+ const prefix = text[1];
40
+ const limit = prefix === "x" || prefix === "X" ? 256 : prefix === "b" || prefix === "B" ? 1024 : 342;
41
+ if (text.length - first > limit) return 1 / 0;
42
+ const token = __eliscript_numeric_apply(__eliscript_numeric_slice, text, [0, 2]) + __eliscript_numeric_apply(__eliscript_numeric_slice, text, [first]);
43
+ return __eliscript_number_intrinsic(__eliscript_bigint_intrinsic(token));
44
+ }
45
+ }
46
+ return __eliscript_number_intrinsic(primitive);
47
+ };
48
+ const __eliscript_numeric = (value) => {
49
+ if (typeof value === "number" || typeof value === "bigint") return value;
50
+ const primitive = __eliscript_numeric_primitive(value);
51
+ if (typeof primitive === "number" || typeof primitive === "bigint") return primitive;
52
+ return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
53
+ };
54
+ const __eliscript_implicit_number = (value) => {
55
+ if (typeof value === "number") return value;
56
+ const primitive = __eliscript_numeric_primitive(value);
57
+ if (typeof primitive === "bigint") throw new __eliscript_numeric_error("Cannot convert a BigInt value to a number");
58
+ return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
59
+ };
60
+ const __eliscript_numeric_decrement = (value) => __eliscript_implicit_number(value) - 1;
61
+ const __eliscript_numeric_sub = (a, b) => { if (typeof a === "number" && typeof b === "number") return a - b; return __eliscript_numeric(a) - __eliscript_numeric(b); };
62
+ const __eliscript_numeric_mul = (a, b) => { if (typeof a === "number" && typeof b === "number") return a * b; return __eliscript_numeric(a) * __eliscript_numeric(b); };
63
+ const __eliscript_numeric_div = (a, b) => { if (typeof a === "number" && typeof b === "number") return a / b; return __eliscript_numeric(a) / __eliscript_numeric(b); };
64
+ const __eliscript_numeric_rem = (a, b) => { if (typeof a === "number" && typeof b === "number") return a % b; return __eliscript_numeric(a) % __eliscript_numeric(b); };
65
+ const __eliscript_numeric_and = (a, b) => { if (typeof a === "number" && typeof b === "number") return a & b; return __eliscript_numeric(a) & __eliscript_numeric(b); };
66
+ const __eliscript_numeric_or = (a, b) => { if (typeof a === "number" && typeof b === "number") return a | b; return __eliscript_numeric(a) | __eliscript_numeric(b); };
67
+ const __eliscript_numeric_xor = (a, b) => { if (typeof a === "number" && typeof b === "number") return a ^ b; return __eliscript_numeric(a) ^ __eliscript_numeric(b); };
68
+ const __eliscript_numeric_shl = (a, b) => { if (typeof a === "number" && typeof b === "number") return a << b; return __eliscript_numeric(a) << __eliscript_numeric(b); };
69
+ const __eliscript_numeric_shr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >> b; return __eliscript_numeric(a) >> __eliscript_numeric(b); };
70
+ const __eliscript_numeric_ushr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >>> b; return __eliscript_numeric(a) >>> __eliscript_numeric(b); };
71
+ const __eliscript_numeric_neg = (a) => typeof a === "number" ? -a : -__eliscript_numeric(a);
72
+ const __eliscript_numeric_int32 = (a) => typeof a === "number" ? a | 0 : __eliscript_numeric(a) | 0;
73
+ const __eliscript_numeric_uint32 = (a) => typeof a === "number" ? a >>> 0 : __eliscript_numeric(a) >>> 0;
74
+ const __eliscript_numeric_not = (a) => typeof a === "number" ? ~a : ~__eliscript_numeric(a);
75
+ const __eliscript_numeric_relation = (operator, left, right) => {
76
+ if (typeof left === "number" && typeof right === "number") {
77
+ if (operator === "<") return left < right;
78
+ if (operator === "<=") return left <= right;
79
+ if (operator === ">") return left > right;
80
+ return left >= right;
81
+ }
82
+ let a = __eliscript_numeric_primitive(left);
83
+ let b = __eliscript_numeric_primitive(right);
84
+ const x = typeof a, y = typeof b;
85
+ if (!((x === "string" && y === "string") || (x === "bigint" && y === "string") || (x === "string" && y === "bigint"))) {
86
+ a = __eliscript_numeric(a);
87
+ b = __eliscript_numeric(b);
88
+ }
89
+ if (operator === "<") return a < b;
90
+ if (operator === "<=") return a <= b;
91
+ if (operator === ">") return a > b;
92
+ return a >= b;
93
+ };
3
94
 
4
95
  import * as Collection from "../../runtime/core/collection.mjs";
5
96
  function empty_QMARK_(text) {
6
97
  return (Collection.count(text) === 0);
7
98
  }
8
99
  function slice(start, end, text) {
9
- return ((result, index, limit) => {
10
- (() => {
11
- while (__eliscript_truthy((index < limit))) {
100
+ {
101
+ const __eliscript_value_1 = "";
102
+ const __eliscript_value_2 = (__eliscript_numeric_relation("<", start, 0) ? 0 : start);
103
+ const __eliscript_value_3 = (__eliscript_numeric_relation(">", end, Collection.count(text)) ? Collection.count(text) : end);
104
+ {
105
+ let result = __eliscript_value_1;
106
+ let index = __eliscript_value_2;
107
+ let limit = __eliscript_value_3;
108
+ while (__eliscript_numeric_relation("<", index, limit)) {
12
109
  ((result = (String(result) + String(Collection.nth(text, index)))), (index = (index + 1)));
13
110
  }
14
- return null;
15
- })();
16
- return result;
17
- })("", (__eliscript_truthy((start < 0)) ? 0 : start), (__eliscript_truthy((end > Collection.count(text))) ? Collection.count(text) : end));
111
+ return result;
112
+ }
113
+ }
18
114
  }
19
115
  function starts_at_QMARK_(prefix, offset, text) {
20
- return ((matched, index) => {
21
- (() => {
22
- while (__eliscript_truthy(((__eliscript_value_2) => (__eliscript_truthy(__eliscript_value_2) ? (index < Collection.count(prefix)) : __eliscript_value_2))(matched))) {
23
- (__eliscript_truthy((!__eliscript_truthy((Collection.nth(prefix, index) === Collection.nth(text, (offset + index)))))) ? ((matched = false)) : null);
116
+ {
117
+ const __eliscript_value_4 = (__eliscript_numeric_relation(">=", offset, 0) && __eliscript_numeric_relation("<=", (offset + Collection.count(prefix)), Collection.count(text)));
118
+ const __eliscript_value_5 = 0;
119
+ {
120
+ let matched = __eliscript_value_4;
121
+ let index = __eliscript_value_5;
122
+ while (__eliscript_truthy(((__eliscript_value_6) => (__eliscript_truthy(__eliscript_value_6) ? __eliscript_numeric_relation("<", index, Collection.count(prefix)) : __eliscript_value_6))(matched))) {
123
+ if ((!(Collection.nth(prefix, index) === Collection.nth(text, (offset + index))))) {
124
+ ((matched = false));
125
+ }
24
126
  ((index = (index + 1)));
25
127
  }
26
- return null;
27
- })();
28
- return matched;
29
- })(((__eliscript_value_1) => (__eliscript_truthy(__eliscript_value_1) ? ((offset + Collection.count(prefix)) <= Collection.count(text)) : __eliscript_value_1))((offset >= 0)), 0);
128
+ return matched;
129
+ }
130
+ }
30
131
  }
31
132
  function starts_with_QMARK_(prefix, text) {
32
133
  return starts_at_QMARK_(prefix, 0, text);
33
134
  }
34
135
  function ends_with_QMARK_(suffix, text) {
35
- return starts_at_QMARK_(suffix, (Collection.count(text) - Collection.count(suffix)), text);
136
+ return starts_at_QMARK_(suffix, __eliscript_numeric_sub(Collection.count(text), Collection.count(suffix)), text);
36
137
  }
37
138
  function contains_QMARK_(needle, text) {
38
- return ((found, offset, last_offset) => {
39
- (() => {
40
- while (__eliscript_truthy(((__eliscript_value_3) => (__eliscript_truthy(__eliscript_value_3) ? (offset <= last_offset) : __eliscript_value_3))((!__eliscript_truthy(found))))) {
41
- (__eliscript_truthy(starts_at_QMARK_(needle, offset, text)) ? ((found = true)) : null);
139
+ {
140
+ const __eliscript_value_7 = false;
141
+ const __eliscript_value_8 = 0;
142
+ const __eliscript_value_9 = __eliscript_numeric_sub(Collection.count(text), Collection.count(needle));
143
+ {
144
+ let found = __eliscript_value_7;
145
+ let offset = __eliscript_value_8;
146
+ let last_offset = __eliscript_value_9;
147
+ while (((!__eliscript_truthy(found)) && __eliscript_numeric_relation("<=", offset, last_offset))) {
148
+ if (__eliscript_truthy(starts_at_QMARK_(needle, offset, text))) {
149
+ ((found = true));
150
+ }
42
151
  ((offset = (offset + 1)));
43
152
  }
44
- return null;
45
- })();
46
- return found;
47
- })(false, 0, (Collection.count(text) - Collection.count(needle)));
153
+ return found;
154
+ }
155
+ }
48
156
  }
49
157
  function strip_prefix(prefix, text) {
50
- return (__eliscript_truthy(starts_with_QMARK_(prefix, text)) ? slice(Collection.count(prefix), Collection.count(text), text) : text);
158
+ if (__eliscript_truthy(starts_with_QMARK_(prefix, text))) {
159
+ return slice(Collection.count(prefix), Collection.count(text), text);
160
+ } else {
161
+ return text;
162
+ }
51
163
  }
52
164
  function strip_suffix(suffix, text) {
53
- return (__eliscript_truthy(ends_with_QMARK_(suffix, text)) ? slice(0, (Collection.count(text) - Collection.count(suffix)), text) : text);
165
+ if (__eliscript_truthy(ends_with_QMARK_(suffix, text))) {
166
+ return slice(0, __eliscript_numeric_sub(Collection.count(text), Collection.count(suffix)), text);
167
+ } else {
168
+ return text;
169
+ }
54
170
  }
55
171
  function whitespace_QMARK_(character) {
56
- return ((__eliscript_value_4) => (__eliscript_truthy(__eliscript_value_4) ? __eliscript_value_4 : ((__eliscript_value_5) => (__eliscript_truthy(__eliscript_value_5) ? __eliscript_value_5 : ((__eliscript_value_6) => (__eliscript_truthy(__eliscript_value_6) ? __eliscript_value_6 : (character === "\r")))((character === "\n"))))((character === "\t"))))((character === " "));
172
+ return ((character === " ") || (character === "\t") || (character === "\n") || (character === "\r"));
57
173
  }
58
174
  function trim(text) {
59
- return ((start, end) => {
60
- (() => {
61
- while (__eliscript_truthy(((__eliscript_value_7) => (__eliscript_truthy(__eliscript_value_7) ? whitespace_QMARK_(Collection.nth(text, start)) : __eliscript_value_7))((start <= end)))) {
175
+ {
176
+ const __eliscript_value_10 = 0;
177
+ const __eliscript_value_11 = __eliscript_numeric_decrement(Collection.count(text));
178
+ {
179
+ let start = __eliscript_value_10;
180
+ let end = __eliscript_value_11;
181
+ while (__eliscript_truthy(((__eliscript_value_12) => (__eliscript_truthy(__eliscript_value_12) ? whitespace_QMARK_(Collection.nth(text, start)) : __eliscript_value_12))(__eliscript_numeric_relation("<=", start, end)))) {
62
182
  ((start = (start + 1)));
63
183
  }
64
- return null;
65
- })();
66
- (() => {
67
- while (__eliscript_truthy(((__eliscript_value_8) => (__eliscript_truthy(__eliscript_value_8) ? whitespace_QMARK_(Collection.nth(text, end)) : __eliscript_value_8))((end >= start)))) {
68
- ((end = (end - 1)));
184
+ while (__eliscript_truthy(((__eliscript_value_13) => (__eliscript_truthy(__eliscript_value_13) ? whitespace_QMARK_(Collection.nth(text, end)) : __eliscript_value_13))(__eliscript_numeric_relation(">=", end, start)))) {
185
+ ((end = __eliscript_numeric_decrement(end)));
69
186
  }
70
- return null;
71
- })();
72
- return slice(start, (end + 1), text);
73
- })(0, (Collection.count(text) - 1));
187
+ return slice(start, (end + 1), text);
188
+ }
189
+ }
74
190
  }
75
191
  function blank_QMARK_(text) {
76
192
  return empty_QMARK_(trim(text));
77
193
  }
78
194
  function join(separator, values) {
79
- return (Collection.reduce(values, (state, value) => {
195
+ return (Collection.reduce(values, ((state, value) => {
80
196
  return ({"first": false, "text": (String((state)["text"]) + String((__eliscript_truthy((state)["first"]) ? "" : separator)) + String(value))});
81
- }, ({"first": true, "text": ""})))["text"];
197
+ }), ({"first": true, "text": ""})))["text"];
82
198
  }
83
199
  function repeat(count, text) {
84
- return ((result, index) => {
85
- (() => {
86
- while (__eliscript_truthy((index < count))) {
200
+ {
201
+ const __eliscript_value_14 = "";
202
+ const __eliscript_value_15 = 0;
203
+ {
204
+ let result = __eliscript_value_14;
205
+ let index = __eliscript_value_15;
206
+ while (__eliscript_numeric_relation("<", index, count)) {
87
207
  ((result = (String(result) + String(text))), (index = (index + 1)));
88
208
  }
89
- return null;
90
- })();
91
- return result;
92
- })("", 0);
209
+ return result;
210
+ }
211
+ }
93
212
  }
94
213
  export {blank_QMARK_, contains_QMARK_, empty_QMARK_, ends_with_QMARK_, join, repeat, slice, starts_at_QMARK_, starts_with_QMARK_, strip_prefix, strip_suffix, trim, whitespace_QMARK_};
95
214
  //# sourceMappingURL=text-impl.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"text-impl.mjs","sources":["../../stdlib/core/text.eli"],"sourcesContent":["(module eliscript.core.text\n (import \"../../runtime/core/collection.mjs\" :as Collection)\n\n (defun empty? (text)\n (= (Collection/count text) 0))\n\n (defun slice (start end text)\n (let ((result \"\")\n (index (if (< start 0) 0 start))\n (limit\n (if (> end (Collection/count text))\n (Collection/count text)\n end)))\n (while (< index limit)\n (setq result (str result (Collection/nth text index))\n index (1+ index)))\n result))\n\n (defun starts-at? (prefix offset text)\n (let ((matched\n (and (>= offset 0)\n (<= (+ offset (Collection/count prefix))\n (Collection/count text))))\n (index 0))\n (while (and matched (< index (Collection/count prefix)))\n (unless (= (Collection/nth prefix index)\n (Collection/nth text (+ offset index)))\n (setq matched false))\n (setq index (1+ index)))\n matched))\n\n (defun starts-with? (prefix text)\n (starts-at? prefix 0 text))\n\n (defun ends-with? (suffix text)\n (starts-at? suffix\n (- (Collection/count text) (Collection/count suffix))\n text))\n\n (defun contains? (needle text)\n (let ((found false)\n (offset 0)\n (last-offset\n (- (Collection/count text) (Collection/count needle))))\n (while (and (not found) (<= offset last-offset))\n (when (starts-at? needle offset text)\n (setq found t))\n (setq offset (1+ offset)))\n found))\n\n (defun strip-prefix (prefix text)\n (if (starts-with? prefix text)\n (slice (Collection/count prefix) (Collection/count text) text)\n text))\n\n (defun strip-suffix (suffix text)\n (if (ends-with? suffix text)\n (slice 0 (- (Collection/count text) (Collection/count suffix)) text)\n text))\n\n (defun whitespace? (character)\n (or (= character \" \")\n (= character \"\\t\")\n (= character \"\\n\")\n (= character \"\\r\")))\n\n (defun trim (text)\n (let ((start 0)\n (end (1- (Collection/count text))))\n (while (and (<= start end)\n (whitespace? (Collection/nth text start)))\n (setq start (1+ start)))\n (while (and (>= end start)\n (whitespace? (Collection/nth text end)))\n (setq end (1- end)))\n (slice start (1+ end) text)))\n\n (defun blank? (text)\n (empty? (trim text)))\n\n (defun join (separator values)\n (get\n (Collection/reduce\n values\n (lambda (state value)\n (js-object\n :first false\n :text (str (get state :text)\n (if (get state :first) \"\" separator)\n value)))\n (js-object :first t :text \"\"))\n :text))\n\n (defun repeat (count text)\n (let ((result \"\")\n (index 0))\n (while (< index count)\n (setq result (str result text)\n index (1+ index)))\n result))\n\n (export blank? contains? empty? ends-with? join repeat slice starts-at?\n starts-with? strip-prefix strip-suffix trim whitespace?))\n"],"names":[],"mappings":";;;AACE,YAAgD;AAEhD,sBAAe;SACb,CAAI,iBAAiB,UAAM;;AAE7B,eAAc,OAAM,KAAI;SACtB,EAAM,QACA,OACA;IAIJ;gCAAO,CAAG,QAAM;QACd,CAAM,CAAA,SAAO,QAAK,iBAAQ,eAAe,MAAK,WACxC,CAAA,QAAM,CAAI;;;;WAClB;KATY,IACD,oBAAI,CAAG,QAAM,MAAG,IAAE,QAExB,oBAAI,CAAG,MAAK,iBAAiB,UACxB,iBAAiB,QACpB;;AAMX,0BAAmB,QAAO,QAAO;SAC/B,EAAM,SAIA;IACJ;gCAAO,qEAAa,CAAG,QAAO,iBAAiB,iCAAnC;QACV,yCAAQ,CAAI,eAAe,QAAO,WACtB,eAAe,MAAK,CAAG,SAAO,cACxC,CAAM,CAAA,UAAQ;QAChB,CAAM,CAAA,QAAM,CAAI;;;;WAClB;KATK,qEACK,CAAI,CAAG,SAAQ,iBAAiB,YAC3B,iBAAiB,+BAFtB,CAAI,UAAO,KAGV;;AAQf,4BAAqB,QAAO;SACzB,iBAAW,QAAO,GAAE;;AAEvB,0BAAmB,QAAO;SACvB,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AU,cAAO,kBAAW,MAAK,QAAO,OAAM,kBACrD,oBAAa,cAAa,cAAa,MAAK"}
1
+ {"version":3,"file":"text-impl.mjs","sources":["../../stdlib/core/text.eli"],"sourcesContent":["(module eliscript.core.text\n (import \"../../runtime/core/collection.mjs\" :as Collection)\n\n (defun empty? (text)\n (= (Collection/count text) 0))\n\n (defun slice (start end text)\n (let ((result \"\")\n (index (if (< start 0) 0 start))\n (limit\n (if (> end (Collection/count text))\n (Collection/count text)\n end)))\n (while (< index limit)\n (setq result (str result (Collection/nth text index))\n index (1+ index)))\n result))\n\n (defun starts-at? (prefix offset text)\n (let ((matched\n (and (>= offset 0)\n (<= (+ offset (Collection/count prefix))\n (Collection/count text))))\n (index 0))\n (while (and matched (< index (Collection/count prefix)))\n (unless (= (Collection/nth prefix index)\n (Collection/nth text (+ offset index)))\n (setq matched false))\n (setq index (1+ index)))\n matched))\n\n (defun starts-with? (prefix text)\n (starts-at? prefix 0 text))\n\n (defun ends-with? (suffix text)\n (starts-at? suffix\n (- (Collection/count text) (Collection/count suffix))\n text))\n\n (defun contains? (needle text)\n (let ((found false)\n (offset 0)\n (last-offset\n (- (Collection/count text) (Collection/count needle))))\n (while (and (not found) (<= offset last-offset))\n (when (starts-at? needle offset text)\n (setq found t))\n (setq offset (1+ offset)))\n found))\n\n (defun strip-prefix (prefix text)\n (if (starts-with? prefix text)\n (slice (Collection/count prefix) (Collection/count text) text)\n text))\n\n (defun strip-suffix (suffix text)\n (if (ends-with? suffix text)\n (slice 0 (- (Collection/count text) (Collection/count suffix)) text)\n text))\n\n (defun whitespace? (character)\n (or (= character \" \")\n (= character \"\\t\")\n (= character \"\\n\")\n (= character \"\\r\")))\n\n (defun trim (text)\n (let ((start 0)\n (end (1- (Collection/count text))))\n (while (and (<= start end)\n (whitespace? (Collection/nth text start)))\n (setq start (1+ start)))\n (while (and (>= end start)\n (whitespace? (Collection/nth text end)))\n (setq end (1- end)))\n (slice start (1+ end) text)))\n\n (defun blank? (text)\n (empty? (trim text)))\n\n (defun join (separator values)\n (get\n (Collection/reduce\n values\n (lambda (state value)\n (js-object\n :first false\n :text (str (get state :text)\n (if (get state :first) \"\" separator)\n value)))\n (js-object :first t :text \"\"))\n :text))\n\n (defun repeat (count text)\n (let ((result \"\")\n (index 0))\n (while (< index count)\n (setq result (str result text)\n index (1+ index)))\n result))\n\n (export blank? contains? empty? ends-with? join repeat slice starts-at?\n starts-with? strip-prefix strip-suffix trim whitespace?))\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACE,YAAgD;AAEhD,sBAAe;EACb,OAAA,CAAI,iBAAiB,UAAM;;AAE7B,eAAc,OAAM,KAAI;EACtB;gCAAc;gCACD,CAAI,kCAAG,OAAM,KAAG,IAAE;gCAExB,CAAI,kCAAG,KAAK,iBAAiB,SACxB,iBAAiB,QACpB;;UALH;UACA;UACA;MAIJ,OAAO,kCAAG,OAAM;QACd,CAAM,CAAA,SAAO,QAAK,iBAAQ,eAAe,MAAK,WACxC,CAAA,QAAM,CAAI;;MAClB,OAAA;;;;AAEJ,0BAAmB,QAAO,QAAO;EAC/B;gCACO,CAAK,mCAAI,QAAO,MACX,mCAAI,CAAG,SAAQ,iBAAiB,UAC3B,iBAAiB;gCACrB;;UAJP;UAIA;MACJ,0BAAO,qEAAa,kCAAG,OAAO,iBAAiB,iCAAnC;QACV,MAAQ,CAAI,eAAe,QAAO,WACtB,eAAe,MAAK,CAAG,SAAO;UACxC,CAAM,CAAA,UAAQ;;QAChB,CAAM,CAAA,QAAM,CAAI;;MAClB,OAAA;;;;AAEJ,4BAAqB,QAAO;EAC1B,OAAC,iBAAW,QAAO,GAAE;;AAEvB,0BAAmB,QAAO;EACxB,OAAC,iBAAW,QACA,wBAAI,iBAAiB,OAAO,iBAAiB,UAC7C;;AAEd,yBAAkB,QAAO;EACvB;gCAAa;gCACC;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