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.
- package/README.md +61 -0
- package/bootstrap/README.md +26 -0
- package/bootstrap/backends/README.md +515 -0
- package/bootstrap/backends/async.eli +230 -0
- package/bootstrap/backends/binary.eli +173 -0
- package/bootstrap/backends/capabilities.eli +74 -0
- package/bootstrap/backends/elf.eli +246 -0
- package/bootstrap/backends/managed.eli +5976 -0
- package/bootstrap/backends/memory.eli +100 -0
- package/bootstrap/backends/native.eli +2000 -0
- package/bootstrap/backends/numeric.eli +1362 -0
- package/bootstrap/backends/optimize.eli +79 -0
- package/bootstrap/backends/regexp.eli +2263 -0
- package/bootstrap/backends/sha256.eli +138 -0
- package/bootstrap/backends/wasm.eli +1161 -0
- package/bootstrap/compiler/analyzer.eli +165 -77
- package/bootstrap/compiler/compiler.eli +43 -19
- package/bootstrap/compiler/emitter.eli +780 -170
- package/bootstrap/compiler/expander.eli +136 -45
- package/bootstrap/compiler/formatter.eli +8 -1
- package/bootstrap/compiler/ir.eli +148 -45
- package/bootstrap/compiler/lower.eli +29 -2
- package/bootstrap/compiler/project.eli +51 -21
- package/bootstrap/compiler/reader.eli +128 -36
- package/bootstrap/compiler/source-map.eli +46 -4
- package/bootstrap/compiler/symbol.eli +2 -1
- package/bootstrap/compiler/syntax.eli +47 -12
- package/bootstrap/compiler/transient-analysis.eli +40 -4
- package/bootstrap/host/check-cli-legacy.mjs +163 -0
- package/bootstrap/host/check-cli.mjs +59 -158
- package/bootstrap/host/check-cli.mjs.map +1 -0
- package/bootstrap/host/compiler-session.eli +1579 -0
- package/bootstrap/host/compiler-tools.eli +513 -0
- package/bootstrap/host/eliscript-cli.mjs +53 -33
- package/bootstrap/host/eliscript-cli.mjs.map +1 -0
- package/bootstrap/host/project-cli-legacy.mjs +295 -0
- package/bootstrap/host/project-cli.mjs +74 -289
- package/bootstrap/host/project-cli.mjs.map +1 -0
- package/bootstrap/host/project-legacy.mjs +1080 -0
- package/bootstrap/host/project.mjs +210 -1060
- package/bootstrap/host/project.mjs.map +1 -0
- package/bootstrap/runtime/UNICODE-LICENSE.txt +39 -0
- package/bootstrap/runtime/memory.eli +30379 -0
- package/browser/host.mjs +732 -11
- package/browser/worker.mjs +6 -3
- package/compiler/eliscript-analyzer.el +371 -4
- package/compiler/eliscript-cli.el +84 -1
- package/compiler/eliscript-emitter.el +1189 -256
- package/compiler/eliscript-expander.el +147 -10
- package/compiler/eliscript-ir-emitter.el +725 -208
- package/compiler/eliscript-lower.el +127 -1
- package/compiler/eliscript-portable.el +177 -51
- package/compiler/eliscript-project.el +20 -2
- package/compiler/eliscript-reader.el +141 -57
- package/compiler/eliscript-source-map.el +26 -12
- package/compiler/eliscript-transient-analysis.el +382 -19
- package/dist/backends/async.mjs +561 -0
- package/dist/backends/async.mjs.macro-origins.json +1 -0
- package/dist/backends/async.mjs.map +1 -0
- package/dist/backends/binary.mjs +381 -0
- package/dist/backends/binary.mjs.macro-origins.json +1 -0
- package/dist/backends/binary.mjs.map +1 -0
- package/dist/backends/capabilities.mjs +237 -0
- package/dist/backends/capabilities.mjs.macro-origins.json +1 -0
- package/dist/backends/capabilities.mjs.map +1 -0
- package/dist/backends/elf.mjs +540 -0
- package/dist/backends/elf.mjs.macro-origins.json +1 -0
- package/dist/backends/elf.mjs.map +1 -0
- package/dist/backends/managed.mjs +10616 -0
- package/dist/backends/managed.mjs.macro-origins.json +1 -0
- package/dist/backends/managed.mjs.map +1 -0
- package/dist/backends/memory.mjs +278 -0
- package/dist/backends/memory.mjs.macro-origins.json +1 -0
- package/dist/backends/memory.mjs.map +1 -0
- package/dist/backends/native.mjs +4099 -0
- package/dist/backends/native.mjs.macro-origins.json +1 -0
- package/dist/backends/native.mjs.map +1 -0
- package/dist/backends/numeric.mjs +2458 -0
- package/dist/backends/numeric.mjs.macro-origins.json +1 -0
- package/dist/backends/numeric.mjs.map +1 -0
- package/dist/backends/optimize.mjs +204 -0
- package/dist/backends/optimize.mjs.macro-origins.json +1 -0
- package/dist/backends/optimize.mjs.map +1 -0
- package/dist/backends/regexp.mjs +2033 -0
- package/dist/backends/regexp.mjs.macro-origins.json +1 -0
- package/dist/backends/regexp.mjs.map +1 -0
- package/dist/backends/sha256.mjs +310 -0
- package/dist/backends/sha256.mjs.macro-origins.json +1 -0
- package/dist/backends/sha256.mjs.map +1 -0
- package/dist/backends/wasm.mjs +2258 -0
- package/dist/backends/wasm.mjs.macro-origins.json +1 -0
- package/dist/backends/wasm.mjs.map +1 -0
- package/dist/bootstrap/analyzer.mjs +1908 -776
- package/dist/bootstrap/analyzer.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -1
- package/dist/bootstrap/compiler.mjs +450 -142
- package/dist/bootstrap/compiler.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/compiler.mjs.map +1 -1
- package/dist/bootstrap/emitter.mjs +3083 -909
- package/dist/bootstrap/emitter.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/emitter.mjs.map +1 -1
- package/dist/bootstrap/expander.mjs +2887 -1233
- package/dist/bootstrap/expander.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/expander.mjs.map +1 -1
- package/dist/bootstrap/formatter.mjs +582 -218
- package/dist/bootstrap/formatter.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/formatter.mjs.map +1 -1
- package/dist/bootstrap/ir.mjs +670 -116
- package/dist/bootstrap/ir.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/ir.mjs.map +1 -1
- package/dist/bootstrap/lower.mjs +866 -257
- package/dist/bootstrap/lower.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/lower.mjs.map +1 -1
- package/dist/bootstrap/package.json +1 -0
- package/dist/bootstrap/project.mjs +1168 -498
- package/dist/bootstrap/project.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/project.mjs.map +1 -1
- package/dist/bootstrap/reader.mjs +674 -175
- package/dist/bootstrap/reader.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/reader.mjs.map +1 -1
- package/dist/bootstrap/runtime/math.mjs +1117 -0
- package/dist/bootstrap/runtime/math.mjs.map +1 -0
- package/dist/bootstrap/runtime/unicode-case-data.mjs +10125 -0
- package/dist/bootstrap/runtime/unicode-case-data.mjs.map +1 -0
- package/dist/bootstrap/runtime/unicode-case.mjs +281 -0
- package/dist/bootstrap/runtime/unicode-case.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +430 -119
- package/dist/bootstrap/source-map.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/source-map.mjs.map +1 -1
- package/dist/bootstrap/symbol.mjs +229 -53
- package/dist/bootstrap/symbol.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/symbol.mjs.map +1 -1
- package/dist/bootstrap/syntax.mjs +205 -7
- package/dist/bootstrap/syntax.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/syntax.mjs.map +1 -1
- package/dist/bootstrap/transient-analysis.mjs +1185 -489
- package/dist/bootstrap/transient-analysis.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -1
- package/dist/browser/compiler.js +199 -6478
- package/dist/browser/host.mjs +1078 -0
- package/dist/browser/loader.js +1 -0
- package/dist/browser/loader.mjs +231 -0
- package/dist/browser/worker.mjs +63 -0
- package/dist/compiler-artifact.json +1 -0
- package/dist/host/compiler-session.mjs +2980 -0
- package/dist/host/compiler-session.mjs.macro-origins.json +1 -0
- package/dist/host/compiler-session.mjs.map +1 -0
- package/dist/host/compiler-tools.mjs +1084 -0
- package/dist/host/compiler-tools.mjs.macro-origins.json +1 -0
- package/dist/host/compiler-tools.mjs.map +1 -0
- package/dist/literal-sources/runtime/core/collection-internals.eli +60 -0
- package/dist/literal-sources/runtime/core/collection.eli +639 -0
- package/dist/literal-sources/runtime/core/data-text.eli +290 -0
- package/dist/literal-sources/runtime/core/data.eli +22 -0
- package/dist/literal-sources/runtime/core/identifier.eli +44 -0
- package/dist/literal-sources/runtime/core/lazy-sequence.eli +131 -0
- package/dist/literal-sources/runtime/core/list.eli +19 -0
- package/dist/literal-sources/runtime/core/map.eli +9 -0
- package/dist/literal-sources/runtime/core/metadata-internals.eli +6 -0
- package/dist/literal-sources/runtime/core/metadata.eli +40 -0
- package/dist/literal-sources/runtime/core/object.eli +8 -0
- package/dist/literal-sources/runtime/core/order.eli +123 -0
- package/dist/literal-sources/runtime/core/persistent-kind.eli +28 -0
- package/dist/literal-sources/runtime/core/protocol-error.eli +32 -0
- package/dist/literal-sources/runtime/core/protocol.eli +28 -0
- package/dist/literal-sources/runtime/core/queue.eli +9 -0
- package/dist/literal-sources/runtime/core/record.eli +191 -0
- package/dist/literal-sources/runtime/core/regex.eli +158 -0
- package/dist/literal-sources/runtime/core/sequence.eli +305 -0
- package/dist/literal-sources/runtime/core/set-algebra.eli +28 -0
- package/dist/literal-sources/runtime/core/set.eli +9 -0
- package/dist/literal-sources/runtime/core/sorted.eli +408 -0
- package/dist/literal-sources/runtime/core/text.eli +14 -0
- package/dist/literal-sources/runtime/core/transducer.eli +268 -0
- package/dist/literal-sources/runtime/core/transient.eli +17 -0
- package/dist/literal-sources/runtime/core/truth.eli +4 -0
- package/dist/literal-sources/runtime/core/type.eli +232 -0
- package/dist/literal-sources/runtime/core/value-internals.eli +13 -0
- package/dist/literal-sources/runtime/core/value.eli +19 -0
- package/dist/literal-sources/runtime/core/vector.eli +25 -0
- package/dist/literal-sources/runtime/literals.eli +23 -0
- package/dist/literal-sources/runtime/testing/value.eli +6 -0
- package/dist/literal-sources/runtime/wire/http-rpc.eli +362 -0
- package/dist/literal-sources/runtime/wire/markdown.eli +275 -0
- package/dist/literal-sources/runtime/wire/schema.eli +193 -0
- package/dist/literal-sources/stdlib/bit.eli +36 -0
- package/dist/literal-sources/stdlib/core/data.eli +306 -0
- package/dist/literal-sources/stdlib/core/object.eli +89 -0
- package/dist/literal-sources/stdlib/core/protocol.eli +451 -0
- package/dist/literal-sources/stdlib/core/set.eli +312 -0
- package/dist/literal-sources/stdlib/core/text.eli +103 -0
- package/dist/literal-sources/stdlib/managed-literal-protocols.eli +494 -0
- package/dist/literal-sources/stdlib/managed-literals.eli +1469 -0
- package/dist/literal-sources/stdlib/managed-queue-state.eli +65 -0
- package/dist/literal-sources/stdlib/managed-sorted-state.eli +233 -0
- package/dist/literal-sources/stdlib/managed-transient-state.eli +348 -0
- package/dist/literal-sources/stdlib/managed-value-state.eli +153 -0
- package/dist/literal-sources/stdlib/managed-vector-view-state.eli +102 -0
- package/dist/literal-sources/stdlib/persistent-list.eli +145 -0
- package/dist/literal-sources/stdlib/persistent-map.eli +724 -0
- package/dist/literal-sources/stdlib/persistent-set.eli +236 -0
- package/dist/literal-sources/stdlib/persistent-vector.eli +359 -0
- package/dist/literal-sources/stdlib/value.eli +325 -0
- package/dist/package.json +10 -0
- package/dist/runtime/math.mjs +1116 -0
- package/dist/runtime/math.mjs.macro-origins.json +1 -0
- package/dist/runtime/math.mjs.map +1 -0
- package/dist/runtime/unicode-case-data.mjs +10124 -0
- package/dist/runtime/unicode-case-data.mjs.macro-origins.json +1 -0
- package/dist/runtime/unicode-case-data.mjs.map +1 -0
- package/dist/runtime/unicode-case.mjs +280 -0
- package/dist/runtime/unicode-case.mjs.macro-origins.json +1 -0
- package/dist/runtime/unicode-case.mjs.map +1 -0
- package/dist/runtime.eli +30379 -0
- package/dist/stage3-release.json +1 -0
- package/editor/README.md +1 -1
- package/editor/eliscript-mode.el +1 -1
- package/editor/eliscript-repl.el +1 -1
- package/package.json +106 -11
- package/platform/http.mjs +20 -0
- package/runtime/array-text.mjs +159 -0
- package/runtime/core/map-internals.mjs +27 -9
- package/runtime/core/object-impl.mjs +26 -17
- package/runtime/core/object-impl.mjs.map +1 -1
- package/runtime/core/protocol-impl.mjs +682 -255
- package/runtime/core/protocol-impl.mjs.map +1 -1
- package/runtime/core/protocol.mjs +4 -0
- package/runtime/core/record.mjs +23 -2
- package/runtime/core/regex.mjs +4 -0
- package/runtime/core/sorted.mjs +53 -0
- package/runtime/core/text-impl.mjs +167 -48
- package/runtime/core/text-impl.mjs.map +1 -1
- package/runtime/core/type.mjs +75 -3
- package/runtime/core/vector.mjs +6 -0
- package/runtime/math.eli +429 -0
- package/runtime/math.mjs +1116 -0
- package/runtime/math.mjs.map +1 -0
- package/runtime/number-radix.mjs +105 -0
- package/runtime/unicode-case-data.eli +29 -0
- package/runtime/unicode-case-data.mjs +10124 -0
- package/runtime/unicode-case-data.mjs.map +1 -0
- package/runtime/unicode-case.eli +100 -0
- package/runtime/unicode-case.mjs +280 -0
- package/runtime/unicode-case.mjs.map +1 -0
- package/runtime/wire/http-rpc.mjs +168 -0
- package/runtime/wire/markdown.mjs +196 -0
- package/runtime/wire/schema.mjs +109 -0
- package/stdlib/README.md +54 -0
- package/stdlib/core/protocol.eli +81 -17
- package/stdlib/core/seq.eli +1 -1
- package/stdlib/core/zipper.eli +172 -72
- package/stdlib/gepo.eli +12 -0
- package/stdlib/interop/js.eli +56 -15
- package/stdlib/managed-literal-protocols.eli +494 -0
- package/stdlib/managed-literals.eli +1469 -0
- package/stdlib/managed-protocol-error.eli +32 -0
- package/stdlib/managed-queue-state.eli +65 -0
- package/stdlib/managed-runtime-collection-internals.eli +60 -0
- package/stdlib/managed-runtime-collection.eli +639 -0
- package/stdlib/managed-runtime-data-text.eli +290 -0
- package/stdlib/managed-runtime-data.eli +22 -0
- package/stdlib/managed-runtime-identifier.eli +44 -0
- package/stdlib/managed-runtime-lazy-sequence.eli +131 -0
- package/stdlib/managed-runtime-list.eli +19 -0
- package/stdlib/managed-runtime-literals.eli +23 -0
- package/stdlib/managed-runtime-map.eli +9 -0
- package/stdlib/managed-runtime-metadata-internals.eli +6 -0
- package/stdlib/managed-runtime-metadata.eli +40 -0
- package/stdlib/managed-runtime-object.eli +8 -0
- package/stdlib/managed-runtime-order.eli +123 -0
- package/stdlib/managed-runtime-persistent-kind.eli +28 -0
- package/stdlib/managed-runtime-protocol.eli +28 -0
- package/stdlib/managed-runtime-queue.eli +9 -0
- package/stdlib/managed-runtime-record.eli +191 -0
- package/stdlib/managed-runtime-regex.eli +158 -0
- package/stdlib/managed-runtime-sequence.eli +305 -0
- package/stdlib/managed-runtime-set-algebra.eli +28 -0
- package/stdlib/managed-runtime-set.eli +9 -0
- package/stdlib/managed-runtime-sorted.eli +408 -0
- package/stdlib/managed-runtime-text.eli +14 -0
- package/stdlib/managed-runtime-transducer.eli +268 -0
- package/stdlib/managed-runtime-transient.eli +17 -0
- package/stdlib/managed-runtime-truth.eli +4 -0
- package/stdlib/managed-runtime-type.eli +232 -0
- package/stdlib/managed-runtime-value-internals.eli +13 -0
- package/stdlib/managed-runtime-value.eli +19 -0
- package/stdlib/managed-runtime-vector.eli +25 -0
- package/stdlib/managed-sorted-state.eli +233 -0
- package/stdlib/managed-testing-value.eli +6 -0
- package/stdlib/managed-transient-state.eli +348 -0
- package/stdlib/managed-value-state.eli +153 -0
- package/stdlib/managed-vector-view-state.eli +102 -0
- package/stdlib/managed-wire-http-rpc.eli +362 -0
- package/stdlib/managed-wire-markdown.eli +275 -0
- package/stdlib/managed-wire-schema.eli +193 -0
- package/stdlib/mdp.eli +7 -0
- package/stdlib/mds.eli +4 -0
- package/stdlib/persistent-vector.eli +23 -6
- package/tools/acceptance/check-legacy.mjs +687 -0
- package/tools/acceptance/check.eli +431 -0
- package/tools/acceptance/compile-evidence.el +49 -0
- package/tools/acceptance/finalize-legacy.mjs +498 -0
- package/tools/acceptance/finalize.eli +270 -0
- package/tools/backends/benchmark.mjs +175 -0
- package/tools/backends/build.mjs +135 -0
- package/tools/backends/compile.mjs +94 -0
- package/tools/backends/compiler-bootstrap.mjs +1001 -0
- package/tools/backends/compiler-browser.mjs +361 -0
- package/tools/backends/compiler-build.mjs +1628 -0
- package/tools/backends/compiler-cli-legacy.mjs +334 -0
- package/tools/backends/compiler-cli.mjs +29 -0
- package/tools/backends/compiler-corpus-bit.mjs +234 -0
- package/tools/backends/compiler-corpus-cli-adapters-legacy.mjs +362 -0
- package/tools/backends/compiler-corpus-cli-adapters.mjs +247 -0
- package/tools/backends/compiler-corpus-debugging.mjs +221 -0
- package/tools/backends/compiler-corpus-emitter.mjs +324 -0
- package/tools/backends/compiler-corpus-evaluation-adapters.mjs +65 -0
- package/tools/backends/compiler-corpus-execution-legacy.mjs +769 -0
- package/tools/backends/compiler-corpus-execution.mjs +3324 -0
- package/tools/backends/compiler-corpus-fuzz.mjs +229 -0
- package/tools/backends/compiler-corpus-generations.mjs +208 -0
- package/tools/backends/compiler-corpus-host-context-legacy.mjs +114 -0
- package/tools/backends/compiler-corpus-host-context.mjs +550 -0
- package/tools/backends/compiler-corpus-identity-host.mjs +553 -0
- package/tools/backends/compiler-corpus-identity-value-adapters-legacy.mjs +298 -0
- package/tools/backends/compiler-corpus-identity-value-adapters.mjs +69 -0
- package/tools/backends/compiler-corpus-isolated-exports.mjs +21 -0
- package/tools/backends/compiler-corpus-legacy.mjs +1155 -0
- package/tools/backends/compiler-corpus-literal-provider.mjs +282 -0
- package/tools/backends/compiler-corpus-managed-adapters-legacy.mjs +334 -0
- package/tools/backends/compiler-corpus-managed-adapters.mjs +937 -0
- package/tools/backends/compiler-corpus-managed-cases.mjs +179 -0
- package/tools/backends/compiler-corpus-managed-fixtures-legacy.mjs +879 -0
- package/tools/backends/compiler-corpus-managed-fixtures.mjs +1287 -0
- package/tools/backends/compiler-corpus-matchers.mjs +173 -0
- package/tools/backends/compiler-corpus-original-program.mjs +612 -0
- package/tools/backends/compiler-corpus-process.mjs +765 -0
- package/tools/backends/compiler-corpus-program-driver.mjs +306 -0
- package/tools/backends/compiler-corpus-project-adapters-legacy.mjs +497 -0
- package/tools/backends/compiler-corpus-project-adapters.mjs +340 -0
- package/tools/backends/compiler-corpus-project-entry-host.mjs +511 -0
- package/tools/backends/compiler-corpus-project-transport.mjs +151 -0
- package/tools/backends/compiler-corpus-raw-fixture-observer.mjs +1438 -0
- package/tools/backends/compiler-corpus-raw-language-fixtures.mjs +1456 -0
- package/tools/backends/compiler-corpus-raw-math-fixture.mjs +346 -0
- package/tools/backends/compiler-corpus-raw-special-fixtures.mjs +523 -0
- package/tools/backends/compiler-corpus-reference-legacy.mjs +263 -0
- package/tools/backends/compiler-corpus-reference.mjs +241 -0
- package/tools/backends/compiler-corpus-runtime-adapters-legacy.mjs +843 -0
- package/tools/backends/compiler-corpus-runtime-adapters.mjs +663 -0
- package/tools/backends/compiler-corpus-source-archive.mjs +206 -0
- package/tools/backends/compiler-corpus-tools-artifact-adapters.mjs +410 -0
- package/tools/backends/compiler-corpus-tools-cli.mjs +363 -0
- package/tools/backends/compiler-corpus-tools-reference.mjs +264 -0
- package/tools/backends/compiler-corpus.mjs +2054 -0
- package/tools/backends/compiler-debug.mjs +142 -0
- package/tools/backends/compiler-matrix.mjs +1955 -0
- package/tools/backends/compiler-metadata.mjs +203 -0
- package/tools/backends/compiler-package-browser.mjs +120 -0
- package/tools/backends/compiler-package-legacy.mjs +654 -0
- package/tools/backends/compiler-package.mjs +464 -0
- package/tools/backends/compiler-project.mjs +126 -0
- package/tools/backends/compiler-session.mjs +843 -0
- package/tools/backends/compiler-sha256.mjs +152 -0
- package/tools/backends/compiler-unicode-profile-host.mjs +196 -0
- package/tools/backends/compiler-worker.mjs +573 -0
- package/tools/backends/dist/bootstrap-js-stages.mjs +919 -0
- package/tools/backends/dist/bootstrap-js-stages.mjs.map +1 -0
- package/tools/backends/dist/managed-ir-inventory.mjs +488 -0
- package/tools/backends/dist/managed-ir-inventory.mjs.map +1 -0
- package/tools/backends/dist/record-grid.mjs +1256 -0
- package/tools/backends/dist/record-grid.mjs.map +1 -0
- package/tools/backends/dist/release-cli.mjs +462 -0
- package/tools/backends/dist/release-cli.mjs.map +1 -0
- package/tools/backends/dist/run-artifact.mjs +517 -0
- package/tools/backends/dist/run-artifact.mjs.map +1 -0
- package/tools/backends/eliscript/compiler-corpus-bit.eli +77 -0
- package/tools/backends/eliscript/compiler-corpus-debugging.eli +70 -0
- package/tools/backends/eliscript/compiler-corpus-project-entry-host.eli +256 -0
- package/tools/backends/managed-foreign-binding.mjs +497 -0
- package/tools/backends/managed-host-legacy.mjs +1181 -0
- package/tools/backends/managed-host-lifecycle.mjs +310 -0
- package/tools/backends/managed-host-object-provider.mjs +155 -0
- package/tools/backends/managed-host-object-realm.mjs +797 -0
- package/tools/backends/managed-host-proxy.mjs +71 -0
- package/tools/backends/managed-host-runtime.mjs +5868 -0
- package/tools/backends/managed-host.mjs +716 -0
- package/tools/backends/managed-module-graph-legacy.mjs +308 -0
- package/tools/backends/managed-module-graph.mjs +694 -0
- package/tools/backends/managed-runtime-host-legacy.mjs +195 -0
- package/tools/backends/managed-runtime.mjs +939 -0
- package/tools/backends/managed-source-view-legacy.mjs +332 -0
- package/tools/backends/managed-source-view.mjs +959 -0
- package/tools/backends/memory-runtime.mjs +100 -0
- package/tools/backends/native-benchmark.mjs +88 -0
- package/tools/backends/native-managed-runtime.mjs +677 -0
- package/tools/backends/native-memory.mjs +768 -0
- package/tools/backends/native-node-memory.mjs +142 -0
- package/tools/backends/native-node-runner.mjs +99 -0
- package/tools/backends/native-node-watchdog.mjs +19 -0
- package/tools/backends/native-node-worker.mjs +75 -0
- package/tools/backends/stage3-targets.mjs +493 -0
- package/tools/bootstrap-command.el +13 -0
- package/tools/bootstrap-runtime.el +101 -0
- package/tools/bootstrap-seed.el +55 -0
- package/tools/project/check-cli.eli +31 -0
- package/tools/project/project-cli.eli +42 -0
- package/tools/project/project.eli +122 -0
- package/tools/runtime/unicode-case-profiles.mjs +13 -0
- package/tools/runtime/unicode-case-runtime.el +57 -0
- package/tools/testing/source-debugging-corpus-host.eli +16 -0
- package/tools/testing/source-debugging.eli +139 -0
- package/tools/testing/stdlib-bit-corpus-host.eli +21 -0
- package/tools/testing/stdlib-bit-corpus-host.mjs +118 -0
- package/tools/testing/stdlib-bit.eli +104 -0
- package/tools/testing/stdlib-bit.mjs +255 -0
- package/bin/eliscript-bootstrap +0 -15
|
@@ -0,0 +1,1469 @@
|
|
|
1
|
+
(module eliscript.managed-literals
|
|
2
|
+
(import-portable "./bit.eli" rotate-left)
|
|
3
|
+
(import-portable "./persistent-list.eli"
|
|
4
|
+
empty-persistent-list persistent-list-count persistent-list-empty? persistent-list-cons
|
|
5
|
+
persistent-list-first persistent-list-rest persistent-list-pop persistent-list-nth
|
|
6
|
+
persistent-list-meta persistent-list-with-meta persistent-list-to-array persistent-list-from-array)
|
|
7
|
+
(import-portable "./persistent-vector.eli"
|
|
8
|
+
empty-persistent-vector persistent-vector-count persistent-vector-nth persistent-vector-assoc
|
|
9
|
+
persistent-vector-conj persistent-vector-pop persistent-vector-meta persistent-vector-with-meta
|
|
10
|
+
persistent-vector-reduce persistent-vector-to-array persistent-vector-from-array)
|
|
11
|
+
(import-portable "./persistent-map.eli"
|
|
12
|
+
empty-persistent-map persistent-map-count persistent-map-has? persistent-map-get
|
|
13
|
+
persistent-map-assoc persistent-map-dissoc persistent-map-reduce persistent-map-to-entries
|
|
14
|
+
persistent-map-meta persistent-map-with-meta persistent-map-from-entries)
|
|
15
|
+
(import-portable "./persistent-set.eli"
|
|
16
|
+
empty-persistent-set persistent-set-count persistent-set-has? persistent-set-conj
|
|
17
|
+
persistent-set-disj persistent-set-reduce persistent-set-meta persistent-set-with-meta
|
|
18
|
+
persistent-set-to-array persistent-set-from-array)
|
|
19
|
+
(import-portable "./value.eli" value-hash)
|
|
20
|
+
(import "./managed-literal-protocols.eli" managed-literal-register-protocols managed-literal-hash-value
|
|
21
|
+
managed-literal-protocol-role managed-literal-protocol-for-role)
|
|
22
|
+
(import "./managed-value-state.eli" hashPrimitiveValue)
|
|
23
|
+
(import "./core/protocol.eli" protocol? protocol-definition materialize-protocol-from-definition
|
|
24
|
+
read-protocol-operations-owner read-protocol-method-owner protocol-method)
|
|
25
|
+
(import "./managed-transient-state.eli"
|
|
26
|
+
managed-transient-vector-new managed-transient-vector-conj managed-transient-vector-assoc managed-transient-vector-persistent
|
|
27
|
+
managed-transient-map-new managed-transient-map-assoc managed-transient-map-dissoc managed-transient-map-persistent
|
|
28
|
+
managed-transient-set-new managed-transient-set-conj managed-transient-set-disj managed-transient-set-persistent)
|
|
29
|
+
(import-portable "./managed-vector-view-state.eli"
|
|
30
|
+
managed-vector-view-state? managed-vector-view-state-make managed-vector-view-state-vector
|
|
31
|
+
managed-vector-view-state-start managed-vector-view-state-end managed-vector-view-state-count
|
|
32
|
+
managed-vector-view-state-meta managed-vector-view-state-subvec managed-vector-view-state-with-meta
|
|
33
|
+
managed-vector-view-state-nth managed-vector-view-state-assoc managed-vector-view-state-conj
|
|
34
|
+
managed-vector-view-state-peek managed-vector-view-state-empty managed-vector-view-state-pop
|
|
35
|
+
managed-vector-view-state-to-array)
|
|
36
|
+
(import-portable "./managed-queue-state.eli"
|
|
37
|
+
managed-queue-state-empty managed-queue-state-count managed-queue-state-meta
|
|
38
|
+
managed-queue-state-with-meta managed-queue-state-conj managed-queue-state-peek
|
|
39
|
+
managed-queue-state-pop managed-queue-state-to-array managed-queue-state-from-array)
|
|
40
|
+
|
|
41
|
+
;; The portable tries remain private. Public values are frozen class-shaped
|
|
42
|
+
;; objects with Symbol state, rather than the portable records' public kind.
|
|
43
|
+
(defconst literal-records (new globalThis/WeakMap))
|
|
44
|
+
(defconst literal-wrappers (new globalThis/WeakMap))
|
|
45
|
+
(defconst literal-node-views (new globalThis/WeakMap))
|
|
46
|
+
(defconst literal-map-root-views (new globalThis/WeakMap))
|
|
47
|
+
(defconst literal-queue-views (new globalThis/WeakMap))
|
|
48
|
+
(defconst literal-subvector-sources (new globalThis/WeakMap))
|
|
49
|
+
(defconst literal-view-states (new globalThis/WeakMap))
|
|
50
|
+
(defconst literal-hashes (new globalThis/WeakMap))
|
|
51
|
+
(defconst literal-iterators (new globalThis/WeakMap))
|
|
52
|
+
(defconst literal-transient-records (new globalThis/WeakMap))
|
|
53
|
+
(defconst literal-editable-results (new globalThis/WeakSet))
|
|
54
|
+
(defconst literal-transient-vector-state (funcall globalThis/Symbol "eliscript.transient-vector.state"))
|
|
55
|
+
(defconst literal-transient-map-state (funcall globalThis/Symbol "eliscript.transient-map.state"))
|
|
56
|
+
(defconst literal-transient-set-state (funcall globalThis/Symbol "eliscript.transient-set.state"))
|
|
57
|
+
(defconst literal-prototypes-ready (js-object))
|
|
58
|
+
(defconst literal-keywords (new globalThis/Map))
|
|
59
|
+
(defconst literal-transports (new globalThis/Map))
|
|
60
|
+
(defconst literal-object-freeze Object/freeze)
|
|
61
|
+
(defconst literal-object-is-frozen Object/isFrozen)
|
|
62
|
+
(defconst literal-object-has-own Object/hasOwn)
|
|
63
|
+
(defconst literal-object-create Object/create)
|
|
64
|
+
(defconst literal-object-get-prototype-of Object/getPrototypeOf)
|
|
65
|
+
(defconst literal-object-get-own-property-descriptor Object/getOwnPropertyDescriptor)
|
|
66
|
+
(defconst literal-object-prototype (get globalThis/Object :prototype))
|
|
67
|
+
(defconst literal-array-is-array Array/isArray)
|
|
68
|
+
(defconst literal-symbol-iterator (get globalThis/Symbol :iterator))
|
|
69
|
+
(defconst literal-symbol-has-instance (get globalThis/Symbol :hasInstance))
|
|
70
|
+
(defconst literal-symbol-to-string-tag (get globalThis/Symbol :toStringTag))
|
|
71
|
+
(defconst literal-data-descriptor
|
|
72
|
+
(let ((descriptor (funcall literal-object-create nil)))
|
|
73
|
+
(put descriptor :value undefined)
|
|
74
|
+
(put descriptor :writable t)
|
|
75
|
+
(put descriptor :enumerable t)
|
|
76
|
+
(put descriptor :configurable t)
|
|
77
|
+
descriptor))
|
|
78
|
+
(defvar literal-has-transients false)
|
|
79
|
+
(defun literal-node-owner (node)
|
|
80
|
+
(if literal-has-transients (get node :owner nil) nil))
|
|
81
|
+
(defconst literal-token (funcall literal-object-freeze (js-object)))
|
|
82
|
+
(defconst literal-missing (funcall globalThis/Symbol "eliscript.collection.missing"))
|
|
83
|
+
(defconst literal-value-type (js-call globalThis/Symbol :for "eliscript.value.type"))
|
|
84
|
+
(defconst literal-list-state (funcall globalThis/Symbol "eliscript.list.state"))
|
|
85
|
+
(defconst literal-vector-state (funcall globalThis/Symbol "eliscript.vector.state"))
|
|
86
|
+
(defconst literal-map-state (funcall globalThis/Symbol "eliscript.map.state"))
|
|
87
|
+
(defconst literal-set-state (funcall globalThis/Symbol "eliscript.set.state"))
|
|
88
|
+
(defconst literal-queue-state (funcall globalThis/Symbol "eliscript.queue.state"))
|
|
89
|
+
(defun literal-make-method (function name)
|
|
90
|
+
(funcall (js* "(fn, name) => { if (typeof name !== \"string\") throw new TypeError(\"method name must be a string\"); return ({ [name](...args) { return Reflect.apply(fn, this, args); } })[name]; }") function name))
|
|
91
|
+
|
|
92
|
+
(defun literal-fail (message) (throw (new globalThis/TypeError message)))
|
|
93
|
+
(defun literal-range (message) (throw (new globalThis/RangeError message)))
|
|
94
|
+
(defun literal-own-data (target key value)
|
|
95
|
+
(put literal-data-descriptor :value value)
|
|
96
|
+
(Reflect/defineProperty target key literal-data-descriptor)
|
|
97
|
+
(put literal-data-descriptor :value undefined)
|
|
98
|
+
target)
|
|
99
|
+
(defun literal-install-method (prototype key name arity implementation)
|
|
100
|
+
(let ((method (literal-make-method implementation name)))
|
|
101
|
+
(Object/defineProperty method "length" (js-object :value arity :configurable t))
|
|
102
|
+
(Object/defineProperty prototype key (js-object :value method :writable t :configurable t)) method))
|
|
103
|
+
(defun literal-install-getter (prototype key name implementation)
|
|
104
|
+
(let ((method (literal-make-method implementation name)))
|
|
105
|
+
(Object/defineProperty prototype key (js-object :get method :configurable t)) method))
|
|
106
|
+
(defun literal-state-key (type)
|
|
107
|
+
(cond ((= type 1) literal-list-state) ((= type 2) literal-vector-state)
|
|
108
|
+
((= type 3) literal-map-state) ((= type 4) literal-set-state) (t literal-queue-state)))
|
|
109
|
+
(defun literal-data (receiver type)
|
|
110
|
+
(let* ((view (aref receiver (literal-state-key type)))
|
|
111
|
+
(data (js-call literal-view-states :get view)))
|
|
112
|
+
(if (undefined? data) (literal-fail "incompatible persistent collection receiver") data)))
|
|
113
|
+
(defun literal-record (value) (js-call literal-records :get value))
|
|
114
|
+
(defun literal-type (value)
|
|
115
|
+
(let ((record (literal-record value))) (if (undefined? record) 0 (get record :type))))
|
|
116
|
+
(defun literal-storage-type (value)
|
|
117
|
+
(let ((record (literal-record value))) (if (undefined? record) 0 (get record :type))))
|
|
118
|
+
(defun literal-prototype (type)
|
|
119
|
+
(get (cond ((= type 1) PersistentList) ((= type 2) PersistentVector)
|
|
120
|
+
((= type 3) PersistentHashMap) ((= type 4) PersistentHashSet) ((= type 5) PersistentQueue)
|
|
121
|
+
((= type 6) Keyword) (t EliscriptSymbol)) :prototype))
|
|
122
|
+
(defun literal-register (object type data)
|
|
123
|
+
(js-call literal-records :set object (js-object :type type :data data))
|
|
124
|
+
(when (or (<= type 5) (= type 8))
|
|
125
|
+
(js-call literal-wrappers :set data object)
|
|
126
|
+
(js-call literal-view-states :set (aref object (literal-state-key (if (= type 8) 2 type)))
|
|
127
|
+
(if (= type 8) (persistent-vector-with-meta (managed-vector-view-state-vector data)
|
|
128
|
+
(managed-vector-view-state-meta data)) data))) object)
|
|
129
|
+
|
|
130
|
+
(defun PersistentList (token count empty value rest &optional metadata)
|
|
131
|
+
(when (not (eq token literal-token))
|
|
132
|
+
(literal-fail "PersistentList values must be created with persistentList or PersistentList.from"))
|
|
133
|
+
(let ((receiver (js* "this")))
|
|
134
|
+
(literal-own-data receiver literal-list-state
|
|
135
|
+
(funcall literal-object-freeze (js-object :count count :empty empty :value value :rest rest :metadata metadata)))
|
|
136
|
+
(funcall literal-object-freeze receiver)))
|
|
137
|
+
(defun PersistentVector (token count shift root tail &optional metadata)
|
|
138
|
+
(when (not (eq token literal-token))
|
|
139
|
+
(literal-fail "PersistentVector values must be created with persistentVector or PersistentVector.from"))
|
|
140
|
+
(let ((receiver (js* "this")))
|
|
141
|
+
(literal-own-data receiver literal-vector-state
|
|
142
|
+
(funcall literal-object-freeze (js-object :count count :shift shift :root root :tail tail :metadata metadata)))
|
|
143
|
+
(funcall literal-object-freeze receiver)))
|
|
144
|
+
(defun PersistentHashMap (token count root &optional metadata)
|
|
145
|
+
(when (not (eq token literal-token))
|
|
146
|
+
(literal-fail "PersistentHashMap values must be created with persistentHashMap or PersistentHashMap.from"))
|
|
147
|
+
(let ((receiver (js* "this")))
|
|
148
|
+
(literal-own-data receiver literal-map-state (funcall literal-object-freeze (js-object :count count :root root :metadata metadata)))
|
|
149
|
+
(funcall literal-object-freeze receiver)))
|
|
150
|
+
(defun PersistentHashSet (token map &optional metadata)
|
|
151
|
+
(when (or (not (eq token literal-token)) (not (= (literal-type map) 3)))
|
|
152
|
+
(literal-fail "PersistentHashSet values must be created with persistentHashSet or PersistentHashSet.from"))
|
|
153
|
+
(let ((receiver (js* "this")))
|
|
154
|
+
(literal-own-data receiver literal-set-state (funcall literal-object-freeze (js-object :map map :metadata metadata)))
|
|
155
|
+
(funcall literal-object-freeze receiver)))
|
|
156
|
+
(defun PersistentQueue (token count front rear &optional metadata)
|
|
157
|
+
(when (not (eq token literal-token))
|
|
158
|
+
(literal-fail "PersistentQueue values must be created with persistentQueue or PersistentQueue.from"))
|
|
159
|
+
(when (or (not (Number/isSafeInteger count)) (< count 0) (> count 2147483647)
|
|
160
|
+
(not (or (= (literal-type front) 2) (= (literal-type front) 8)))
|
|
161
|
+
(not (or (= (literal-type rear) 2) (= (literal-type rear) 8)))
|
|
162
|
+
(not (= (+ (get front :count) (get rear :count)) count))
|
|
163
|
+
(and (> count 0) (= (get front :count) 0)))
|
|
164
|
+
(literal-fail "invalid persistent queue state"))
|
|
165
|
+
(let ((receiver (js* "this")))
|
|
166
|
+
(literal-own-data receiver literal-queue-state
|
|
167
|
+
(funcall literal-object-freeze (js-object :count count :front front :rear rear :metadata metadata)))
|
|
168
|
+
(funcall literal-object-freeze receiver)))
|
|
169
|
+
(defun VectorNode (&optional slots owner)
|
|
170
|
+
(let ((receiver (js* "this")))
|
|
171
|
+
(put receiver :owner owner) (put receiver :slots (if (nil? slots) (js-array) slots))
|
|
172
|
+
(when (nil? owner) (funcall literal-object-freeze (get receiver :slots)) (funcall literal-object-freeze receiver)) receiver))
|
|
173
|
+
(defun MapEntry (key value hash)
|
|
174
|
+
(let ((receiver (js* "this")))
|
|
175
|
+
(put receiver :key key) (put receiver :value value) (put receiver :hash (uint32 hash)) (funcall literal-object-freeze receiver)))
|
|
176
|
+
(defun BitmapIndexedNode (&optional bitmap items owner)
|
|
177
|
+
(let ((receiver (js* "this")))
|
|
178
|
+
(put receiver :bitmap (uint32 (if (nil? bitmap) 0 bitmap))) (put receiver :owner owner)
|
|
179
|
+
(put receiver :items (if (nil? items) (js-array) items))
|
|
180
|
+
(when (nil? owner) (funcall literal-object-freeze (get receiver :items)) (funcall literal-object-freeze receiver)) receiver))
|
|
181
|
+
(defun ArrayNode (count children &optional owner)
|
|
182
|
+
(let ((receiver (js* "this")))
|
|
183
|
+
(put receiver :count count) (put receiver :owner owner) (put receiver :children children)
|
|
184
|
+
(when (nil? owner) (funcall literal-object-freeze children) (funcall literal-object-freeze receiver)) receiver))
|
|
185
|
+
(defun HashCollisionNode (hash entries &optional owner)
|
|
186
|
+
(let ((receiver (js* "this")))
|
|
187
|
+
(put receiver :hash (uint32 hash)) (put receiver :owner owner) (put receiver :entries entries)
|
|
188
|
+
(when (nil? owner) (funcall literal-object-freeze entries) (funcall literal-object-freeze receiver)) receiver))
|
|
189
|
+
(defun literal-vector-node-view (node level)
|
|
190
|
+
(let ((cached (js-call literal-node-views :get node)))
|
|
191
|
+
(if (not (undefined? cached))
|
|
192
|
+
(progn
|
|
193
|
+
(unless (nil? (literal-node-owner node))
|
|
194
|
+
(let ((source (get node :slots)) (slots (get cached :slots)) (index 0))
|
|
195
|
+
(put slots :length (js-length source))
|
|
196
|
+
(while (< index (js-length source))
|
|
197
|
+
(let ((item (get source index)))
|
|
198
|
+
(if (funcall literal-object-has-own source index)
|
|
199
|
+
(put slots index (if (and (> level 0) (not (nullish? item)))
|
|
200
|
+
(literal-vector-node-view item (- level 5)) item))
|
|
201
|
+
(Reflect/deleteProperty slots index)))
|
|
202
|
+
(setq index (1+ index))))) cached)
|
|
203
|
+
(let* ((slots (get node :slots)) (values (new globalThis/Array (js-length slots))) (index 0))
|
|
204
|
+
(while (< index (js-length slots))
|
|
205
|
+
(let ((value (get slots index)))
|
|
206
|
+
(unless (undefined? value)
|
|
207
|
+
(put values index (if (and (> level 0) (not (nil? value)))
|
|
208
|
+
(literal-vector-node-view value (- level 5)) value))))
|
|
209
|
+
(setq index (1+ index)))
|
|
210
|
+
(let ((view (new VectorNode values (literal-node-owner node))))
|
|
211
|
+
(js-call literal-node-views :set node view) view)))))
|
|
212
|
+
(defun literal-map-node-view (node)
|
|
213
|
+
(if (nil? node) literal-empty-bitmap
|
|
214
|
+
(let ((cached (js-call literal-node-views :get node)))
|
|
215
|
+
(if (not (undefined? cached))
|
|
216
|
+
(progn
|
|
217
|
+
(unless (or (= (get node :kind) "entry") (nil? (literal-node-owner node)))
|
|
218
|
+
(let* ((kind (get node :kind)) (field (if (= kind "bitmap") "items" (if (= kind "array") "children" "entries")))
|
|
219
|
+
(source (get node field)) (items (get cached field)) (index 0))
|
|
220
|
+
(put items :length (js-length source))
|
|
221
|
+
(while (< index (js-length source))
|
|
222
|
+
(let ((child (get source index)))
|
|
223
|
+
(put items index (if (nullish? child) undefined (literal-map-node-view child))))
|
|
224
|
+
(setq index (1+ index)))
|
|
225
|
+
(put cached (if (= kind "bitmap") "bitmap" (if (= kind "array") "count" "hash"))
|
|
226
|
+
(get node (if (= kind "bitmap") "bitmap" (if (= kind "array") "count" "hash")))))) cached)
|
|
227
|
+
(let* ((kind (get node :kind))
|
|
228
|
+
(view (if (= kind "entry") (new MapEntry (get node :key) (get node :value) (get node :hash))
|
|
229
|
+
(let* ((source (get node (if (= kind "bitmap") "items" (if (= kind "array") "children" "entries"))))
|
|
230
|
+
(items (new globalThis/Array (js-length source))) (index 0))
|
|
231
|
+
(while (< index (js-length source))
|
|
232
|
+
(let ((child (get source index)))
|
|
233
|
+
(put items index (if (nil? child) undefined (literal-map-node-view child))))
|
|
234
|
+
(setq index (1+ index)))
|
|
235
|
+
(cond ((= kind "bitmap") (new BitmapIndexedNode (get node :bitmap) items (literal-node-owner node)))
|
|
236
|
+
((= kind "array") (new ArrayNode (get node :count) items (literal-node-owner node)))
|
|
237
|
+
(t (new HashCollisionNode (get node :hash) items (literal-node-owner node))))))))
|
|
238
|
+
(js-call literal-node-views :set node view) view)))))
|
|
239
|
+
(defun literal-map-root-view (root)
|
|
240
|
+
(if (nil? root) literal-empty-bitmap
|
|
241
|
+
(if (or (= (get root :kind) "entry") (= (get root :kind) "collision"))
|
|
242
|
+
(let ((child (literal-map-node-view root)) (cached (js-call literal-map-root-views :get root)))
|
|
243
|
+
(if (not (undefined? cached)) cached
|
|
244
|
+
(let ((view (new BitmapIndexedNode (uint32 (bit-shift-left 1 (bit-and (get root :hash) 31)))
|
|
245
|
+
(js-array child) (literal-node-owner root))))
|
|
246
|
+
(js-call literal-map-root-views :set root view) view)))
|
|
247
|
+
(literal-map-node-view root))))
|
|
248
|
+
|
|
249
|
+
(defconst literal-empty-bitmap (new BitmapIndexedNode))
|
|
250
|
+
(defconst literal-empty-list-data (empty-persistent-list))
|
|
251
|
+
(defconst literal-empty-vector-data (empty-persistent-vector))
|
|
252
|
+
(defconst literal-empty-map-data (empty-persistent-map literal-hash literal-equal literal-equal))
|
|
253
|
+
(defconst literal-empty-set-data (empty-persistent-set literal-hash literal-equal))
|
|
254
|
+
(defconst literal-empty-queue-data (managed-queue-state-empty))
|
|
255
|
+
(defun literal-data-count (type data)
|
|
256
|
+
(if (= type 4) (persistent-set-count data) (get data :count)))
|
|
257
|
+
(defun literal-canonical-data (type data)
|
|
258
|
+
(if (and (= (literal-data-count type data) 0) (nil? (get data :metadata)))
|
|
259
|
+
(cond ((= type 1) literal-empty-list-data) ((= type 2) literal-empty-vector-data)
|
|
260
|
+
((= type 3) literal-empty-map-data) ((= type 4) literal-empty-set-data) (t literal-empty-queue-data)) data))
|
|
261
|
+
(defun literal-wrap-list (data)
|
|
262
|
+
(let ((pending (js-array)) (current data) (result undefined))
|
|
263
|
+
(while (undefined? result)
|
|
264
|
+
(setq current (literal-canonical-data 1 current) result (js-call literal-wrappers :get current))
|
|
265
|
+
(when (undefined? result)
|
|
266
|
+
(if (persistent-list-empty? current)
|
|
267
|
+
(setq result (literal-register (new PersistentList literal-token 0 t undefined nil
|
|
268
|
+
(persistent-list-meta current)) 1 current))
|
|
269
|
+
(progn (js-call pending :push current) (setq current (persistent-list-rest current nil))))))
|
|
270
|
+
(while (> (js-length pending) 0)
|
|
271
|
+
(setq current (js-call pending :pop)
|
|
272
|
+
result (literal-register (new PersistentList literal-token (persistent-list-count current) false
|
|
273
|
+
(persistent-list-first current nil) result (persistent-list-meta current)) 1 current))) result))
|
|
274
|
+
(defun literal-wrap (type raw-data)
|
|
275
|
+
(literal-initialize-prototype type)
|
|
276
|
+
(let* ((data (literal-canonical-data type raw-data)) (cached (js-call literal-wrappers :get data)))
|
|
277
|
+
(if (not (undefined? cached)) cached
|
|
278
|
+
(if (= type 1) (literal-wrap-list data)
|
|
279
|
+
(literal-register
|
|
280
|
+
(cond
|
|
281
|
+
((= type 2) (new PersistentVector literal-token (persistent-vector-count data) (get data :shift)
|
|
282
|
+
(literal-vector-node-view (get data :root) (get data :shift))
|
|
283
|
+
(let ((tail (get data :tail)))
|
|
284
|
+
(if (js-call literal-editable-results :has data)
|
|
285
|
+
tail
|
|
286
|
+
(funcall literal-object-freeze tail))) (persistent-vector-meta data)))
|
|
287
|
+
((= type 3) (new PersistentHashMap literal-token (persistent-map-count data)
|
|
288
|
+
(literal-map-root-view (get data :root)) (persistent-map-meta data)))
|
|
289
|
+
((= type 4) (new PersistentHashSet literal-token (literal-wrap 3 (get data :map)) (persistent-set-meta data)))
|
|
290
|
+
(t (let ((view (literal-queue-view data)))
|
|
291
|
+
(new PersistentQueue literal-token (managed-queue-state-count data)
|
|
292
|
+
(get view :front) (get view :rear) (managed-queue-state-meta data)))))
|
|
293
|
+
type data)))))
|
|
294
|
+
(defun literal-list-to-array-data (data)
|
|
295
|
+
(let ((out (js-array)) (index 0) (current data))
|
|
296
|
+
(while (not (persistent-list-empty? current))
|
|
297
|
+
(put out index (persistent-list-first current nil))
|
|
298
|
+
(setq index (1+ index) current (persistent-list-rest current nil)))
|
|
299
|
+
out))
|
|
300
|
+
(defun literal-queue-view (data)
|
|
301
|
+
(let ((cached (js-call literal-queue-views :get data)))
|
|
302
|
+
(if (not (undefined? cached)) cached
|
|
303
|
+
(let ((view (js-object
|
|
304
|
+
:front (literal-vector-from-array-values (literal-list-to-array-data (get data :front)))
|
|
305
|
+
:rear (literal-vector-from-array-values (js-call (literal-list-to-array-data (get data :rear)) :reverse)))))
|
|
306
|
+
(js-call literal-queue-views :set data view) view))))
|
|
307
|
+
(defun literal-list (&rest values)
|
|
308
|
+
(literal-initialize-prototype 1) (js-call PersistentList :from values))
|
|
309
|
+
(defun literal-vector (&rest values)
|
|
310
|
+
(literal-initialize-prototype 2)
|
|
311
|
+
(when (<= (js-length values) 32) (funcall literal-object-freeze values))
|
|
312
|
+
(literal-vector-from-array-values values))
|
|
313
|
+
(defun literal-map (&rest values)
|
|
314
|
+
(when (/= (% (js-length values) 2) 0) (literal-fail "hash-map expects complete key/value pairs"))
|
|
315
|
+
(let ((entries (js-array)) (index 0) (pair 0))
|
|
316
|
+
(while (< index (js-length values))
|
|
317
|
+
(put entries pair (js-array (get values index) (get values (1+ index))))
|
|
318
|
+
(setq index (+ index 2) pair (1+ pair)))
|
|
319
|
+
(literal-initialize-prototype 3) (js-call PersistentHashMap :from entries)))
|
|
320
|
+
(defun literal-set (&rest values)
|
|
321
|
+
(literal-initialize-prototype 4) (js-call PersistentHashSet :from values))
|
|
322
|
+
(defun literal-queue (&rest values)
|
|
323
|
+
(literal-initialize-prototype 5) (js-call PersistentQueue :from values))
|
|
324
|
+
|
|
325
|
+
(defun literal-count (collection)
|
|
326
|
+
(let ((type (literal-type collection)))
|
|
327
|
+
(cond ((or (and (>= type 1) (<= type 5)) (= type 8)) (get collection :count))
|
|
328
|
+
((nullish? collection) 0)
|
|
329
|
+
((or (funcall literal-array-is-array collection) (= (js* "typeof collection") "string")) (js-length collection))
|
|
330
|
+
((or (literal-instance? collection globalThis/Map) (literal-instance? collection globalThis/Set)) (get collection :size))
|
|
331
|
+
((= (funcall literal-object-get-prototype-of collection) literal-object-prototype) (js-length (Object/keys collection)))
|
|
332
|
+
(t (literal-fail "value does not implement ICounted/count")))))
|
|
333
|
+
(defun literal-instance? (value constructor)
|
|
334
|
+
(cond
|
|
335
|
+
((or (eq constructor PersistentVector) (eq constructor PersistentList)
|
|
336
|
+
(eq constructor PersistentHashMap) (eq constructor PersistentHashSet)
|
|
337
|
+
(eq constructor PersistentQueue))
|
|
338
|
+
(if (or (nullish? value) (and (/= (js* "typeof value") "object") (/= (js* "typeof value") "function")))
|
|
339
|
+
false
|
|
340
|
+
(let ((type (literal-type value)))
|
|
341
|
+
(if (> type 0)
|
|
342
|
+
(if (eq constructor PersistentVector)
|
|
343
|
+
(or (= type 2) (= type 8))
|
|
344
|
+
(= type (cond ((eq constructor PersistentList) 1) ((eq constructor PersistentHashMap) 3)
|
|
345
|
+
((eq constructor PersistentHashSet) 4) (t 5))))
|
|
346
|
+
(if (funcall literal-array-is-array value)
|
|
347
|
+
false
|
|
348
|
+
(js-call (get constructor literal-symbol-has-instance) :call constructor value))))))
|
|
349
|
+
(t (js-call (get constructor literal-symbol-has-instance) :call constructor value))))
|
|
350
|
+
(defun literal-nth (collection index &rest not-found)
|
|
351
|
+
(let ((type (literal-type collection)) (fallback (if (and (> (js-length not-found) 0) (not (undefined? (get not-found 0))))
|
|
352
|
+
(get not-found 0) literal-missing)))
|
|
353
|
+
(if (or (= type 1) (= type 2) (= type 8))
|
|
354
|
+
(if (eq fallback literal-missing) (js-call collection :nth index) (js-call collection :nth index fallback))
|
|
355
|
+
(if (or (Array/isArray collection) (= (js* "typeof collection") "string"))
|
|
356
|
+
(if (and (Number/isInteger index) (>= index 0) (< index (js-length collection))) (get collection index)
|
|
357
|
+
(if (eq fallback literal-missing) (literal-range "nth index is outside collection bounds") fallback))
|
|
358
|
+
(literal-fail "value does not implement IIndexed/nth")))))
|
|
359
|
+
(defun literal-get (collection key &optional not-found)
|
|
360
|
+
(let ((type (literal-type collection)))
|
|
361
|
+
(cond ((= type 3) (js-call collection :get key not-found))
|
|
362
|
+
((= type 4) (if (js-call collection :has key) key not-found))
|
|
363
|
+
((or (= type 2) (= type 8)) (js-call collection :nth key not-found))
|
|
364
|
+
((nullish? collection) not-found)
|
|
365
|
+
((Array/isArray collection) (if (and (Number/isInteger key) (>= key 0) (< key (js-length collection)))
|
|
366
|
+
(get collection key) not-found))
|
|
367
|
+
(t (let ((result (aref collection key))) (if (undefined? result) not-found result))))))
|
|
368
|
+
;; A binding's raw key tag is not a property-key coercion. Only values in
|
|
369
|
+
;; this actual adapter's private registry enter its canonical ILookup; other
|
|
370
|
+
;; source/foreign values retain the memory runtime's existing lookup path.
|
|
371
|
+
(defun literal-binding-lookup (source key tagged)
|
|
372
|
+
(if (= (literal-type source) 0) nil
|
|
373
|
+
(let* ((actual-key (cond ((= tagged 1) (literal-keyword key))
|
|
374
|
+
((= tagged 2) (literal-symbol key)) (t key)))
|
|
375
|
+
(lookup (protocol-method (managed-literal-protocol-for-role "collection.ILookup") "get"))
|
|
376
|
+
(value (funcall lookup source actual-key literal-missing)))
|
|
377
|
+
(js-array value (not (eq value literal-missing))))))
|
|
378
|
+
(defun literal-first (collection &optional not-found)
|
|
379
|
+
(if (nullish? collection) not-found
|
|
380
|
+
(if (= (literal-type collection) 1) (js-call collection :first not-found)
|
|
381
|
+
(literal-fail "first expects a persistent List or nil"))))
|
|
382
|
+
(defun literal-rest (collection)
|
|
383
|
+
(if (nullish? collection) (literal-list-empty)
|
|
384
|
+
(if (= (literal-type collection) 1)
|
|
385
|
+
(js-call collection :rest)
|
|
386
|
+
(literal-fail "rest expects a persistent List or nil"))))
|
|
387
|
+
(defun literal-cons (head tail)
|
|
388
|
+
(let ((list (if (nullish? tail) (literal-list-empty)
|
|
389
|
+
(if (= (literal-type tail) 1) tail (literal-fail "cons expects a persistent List or nil")))))
|
|
390
|
+
(js-call list :cons head)))
|
|
391
|
+
(defun literal-to-array (collection)
|
|
392
|
+
(if (= (literal-storage-type collection) 8)
|
|
393
|
+
(let* ((data (get (literal-record collection) :data)) (source (literal-subvector-source data))
|
|
394
|
+
(index (managed-vector-view-state-start data)) (end (managed-vector-view-state-end data))
|
|
395
|
+
(values (js-array)) (out-index 0))
|
|
396
|
+
(while (< index end)
|
|
397
|
+
(put values out-index (js-call source :nth index))
|
|
398
|
+
(setq index (1+ index) out-index (1+ out-index))) values)
|
|
399
|
+
(let* ((type (literal-type collection)) (data (literal-data collection type)))
|
|
400
|
+
(literal-to-array-data type data))))
|
|
401
|
+
(defun literal-to-array-data (type data)
|
|
402
|
+
(cond ((= type 1) (literal-list-to-array-data data))
|
|
403
|
+
((= type 2)
|
|
404
|
+
(let ((out (js-array)) (index 0))
|
|
405
|
+
(persistent-vector-reduce (lambda (_ item) (put out index item) (setq index (1+ index)) nil) nil data)
|
|
406
|
+
out))
|
|
407
|
+
((= type 3)
|
|
408
|
+
(let ((out (js-array)) (index 0))
|
|
409
|
+
(persistent-map-reduce
|
|
410
|
+
(lambda (_ key value) (put out index (Object/freeze (js-array key value))) (setq index (1+ index)) nil) nil data)
|
|
411
|
+
out))
|
|
412
|
+
((= type 4)
|
|
413
|
+
(let ((out (js-array)) (index 0))
|
|
414
|
+
(persistent-set-reduce (lambda (_ item) (put out index item) (setq index (1+ index)) nil) nil data)
|
|
415
|
+
out))
|
|
416
|
+
(t (let* ((out (literal-list-to-array-data (get data :front)))
|
|
417
|
+
(rear (literal-list-to-array-data (get data :rear)))
|
|
418
|
+
(out-index (js-length out))
|
|
419
|
+
(index (1- (js-length rear))))
|
|
420
|
+
(while (>= index 0)
|
|
421
|
+
(put out out-index (get rear index))
|
|
422
|
+
(setq out-index (1+ out-index) index (1- index))) out))))
|
|
423
|
+
(defun literal-conj (collection value)
|
|
424
|
+
(if (or (= (literal-storage-type collection) 8) (= (literal-storage-type collection) 5)) (js-call collection :conj value)
|
|
425
|
+
(let* ((type (literal-type collection)) (data (literal-data collection type))
|
|
426
|
+
(next (cond ((= type 1) (persistent-list-cons data value)) ((= type 2) (persistent-vector-conj data value))
|
|
427
|
+
((= type 4) (persistent-set-conj data value)) ((= type 5) (managed-queue-state-conj data value))
|
|
428
|
+
(t (let ((entry (literal-entry value))) (persistent-map-assoc data (get entry 0) (get entry 1)))))))
|
|
429
|
+
(if (nil? next) (literal-range "persistent collection cannot exceed 2147483647 values")
|
|
430
|
+
(if (eq next data) collection (literal-wrap type next))))))
|
|
431
|
+
(defun literal-assoc (collection key value)
|
|
432
|
+
(if (= (literal-storage-type collection) 8) (js-call collection :assoc key value)
|
|
433
|
+
(let* ((type (literal-type collection)) (data (literal-data collection type)))
|
|
434
|
+
(when (and (= type 2) (not (and (Number/isInteger key) (>= key 0) (<= key (persistent-vector-count data)))))
|
|
435
|
+
(literal-range (str "assoc index " key " is outside [0, " (persistent-vector-count data) ")")))
|
|
436
|
+
(let ((next (cond ((= type 2) (persistent-vector-assoc data key value))
|
|
437
|
+
((= type 3) (persistent-map-assoc data key value)) (t (literal-fail "value is not associative")))))
|
|
438
|
+
(if (nil? next) (literal-range "persistent collection cannot exceed 2147483647 values")
|
|
439
|
+
(if (eq next data) collection (literal-wrap type next)))))))
|
|
440
|
+
(defun literal-dissoc (collection key)
|
|
441
|
+
(let* ((data (literal-data collection 3)) (next (persistent-map-dissoc data key)))
|
|
442
|
+
(if (eq data next) collection (literal-wrap 3 next))))
|
|
443
|
+
(defun literal-disj (collection value)
|
|
444
|
+
(let* ((data (literal-data collection 4)) (next (persistent-set-disj data value)))
|
|
445
|
+
(if (eq data next) collection (literal-wrap 4 next))))
|
|
446
|
+
(defun literal-peek (collection &optional not-found)
|
|
447
|
+
(if (= (literal-storage-type collection) 8) (js-call collection :peek not-found)
|
|
448
|
+
(let* ((type (literal-type collection)) (data (literal-data collection type)))
|
|
449
|
+
(cond ((= type 1) (persistent-list-first data not-found))
|
|
450
|
+
((= type 2) (persistent-vector-nth data (1- (persistent-vector-count data)) not-found))
|
|
451
|
+
((= type 5) (managed-queue-state-peek data not-found)) (t (literal-fail "value is not a persistent stack"))))))
|
|
452
|
+
(defun literal-pop (collection)
|
|
453
|
+
(if (or (= (literal-storage-type collection) 8) (= (literal-storage-type collection) 5)) (js-call collection :pop)
|
|
454
|
+
(let* ((type (literal-type collection)) (data (literal-data collection type)))
|
|
455
|
+
(when (= (literal-data-count type data) 0)
|
|
456
|
+
(literal-range (cond ((= type 1) "cannot pop an empty persistent list")
|
|
457
|
+
((= type 2) "cannot pop an empty persistent vector") (t "cannot pop an empty persistent queue"))))
|
|
458
|
+
(literal-wrap type (cond ((= type 1) (persistent-list-pop data)) ((= type 2) (persistent-vector-pop data))
|
|
459
|
+
((= type 5) (managed-queue-state-pop data)) (t (literal-fail "value is not a persistent stack")))))))
|
|
460
|
+
(defun literal-meta (collection)
|
|
461
|
+
(let ((record (literal-record collection)))
|
|
462
|
+
(if (undefined? record) nil (get (get record :data) :metadata nil))))
|
|
463
|
+
(defun literal-with-meta (collection metadata)
|
|
464
|
+
(unless (or (nil? metadata) (= (literal-type metadata) 3))
|
|
465
|
+
(literal-fail "metadata must be null or a persistent hash map"))
|
|
466
|
+
(if (= (literal-storage-type collection) 8)
|
|
467
|
+
(let* ((data (get (literal-record collection) :data)) (next (managed-vector-view-state-with-meta data metadata)))
|
|
468
|
+
(if (eq data next) collection
|
|
469
|
+
(progn (js-call literal-subvector-sources :set next (literal-subvector-source data)) (literal-wrap-subvector next))))
|
|
470
|
+
(let* ((type (literal-type collection)) (record (literal-record collection)))
|
|
471
|
+
(when (or (= type 0) (= type 6)) (literal-fail "value does not support metadata"))
|
|
472
|
+
(let* ((data (get record :data))
|
|
473
|
+
(next (cond ((= type 1) (persistent-list-with-meta data metadata))
|
|
474
|
+
((= type 2) (persistent-vector-with-meta data metadata)) ((= type 3) (persistent-map-with-meta data metadata))
|
|
475
|
+
((= type 4) (persistent-set-with-meta data metadata)) ((= type 5) (managed-queue-state-with-meta data metadata))
|
|
476
|
+
(t (if (eq metadata (get data :metadata)) data
|
|
477
|
+
(js-object :namespace (get data :namespace) :name (get data :name) :metadata metadata))))))
|
|
478
|
+
(if (eq next data) collection
|
|
479
|
+
(progn
|
|
480
|
+
(when (= type 5) (js-call literal-queue-views :set next (literal-queue-view data)))
|
|
481
|
+
(if (= type 7) (literal-new-identifier 7 next) (literal-wrap type next))))))))
|
|
482
|
+
|
|
483
|
+
(defun literal-valid-identifier-part? (value)
|
|
484
|
+
(and (= (js* "typeof value") "string") (> (js-length value) 0) (not (js-call value :includes "/"))))
|
|
485
|
+
(defun literal-identifier? (value type)
|
|
486
|
+
(and (not (nullish? value))
|
|
487
|
+
(or (= (js* "typeof value") "object") (= (js* "typeof value") "function"))
|
|
488
|
+
(let ((descriptor (Object/getOwnPropertyDescriptor value literal-value-type)))
|
|
489
|
+
(and (not (undefined? descriptor)) (Object/hasOwn descriptor "value") (= (get descriptor :value) type)))))
|
|
490
|
+
(defun literal-identifier-arguments (values type)
|
|
491
|
+
(cond
|
|
492
|
+
((= (js-length values) 1)
|
|
493
|
+
(let ((value (get values 0)))
|
|
494
|
+
(if (literal-identifier? value type)
|
|
495
|
+
(let ((namespace (get value :namespace)) (name (get value :name)))
|
|
496
|
+
(unless (and (or (nil? namespace) (literal-valid-identifier-part? namespace)) (literal-valid-identifier-part? name))
|
|
497
|
+
(literal-fail "expected an Eliscript keyword or symbol"))
|
|
498
|
+
(js-object :existing value :namespace namespace :name name))
|
|
499
|
+
(progn
|
|
500
|
+
(unless (and (= (js* "typeof value") "string") (> (js-length value) 0))
|
|
501
|
+
(literal-fail (str type " name must be a non-empty string")))
|
|
502
|
+
(let ((slash (js-call value :indexOf "/")))
|
|
503
|
+
(if (= slash -1) (js-object :existing nil :namespace nil :name value)
|
|
504
|
+
(if (or (= slash 0) (= slash (1- (js-length value)))
|
|
505
|
+
(/= (js-call value :indexOf "/" (1+ slash)) -1))
|
|
506
|
+
(literal-fail (str type " name must be name or namespace/name"))
|
|
507
|
+
(js-object :existing nil :namespace (js-call value :slice 0 slash) :name (js-call value :slice (1+ slash))))))))))
|
|
508
|
+
((= (js-length values) 2)
|
|
509
|
+
(let ((namespace (get values 0)) (name (get values 1)))
|
|
510
|
+
(unless (or (nil? namespace) (literal-valid-identifier-part? namespace))
|
|
511
|
+
(literal-fail (str type " namespace must be a non-empty string without /")))
|
|
512
|
+
(unless (literal-valid-identifier-part? name) (literal-fail (str type " name must be a non-empty string without /")))
|
|
513
|
+
(js-object :existing nil :namespace namespace :name name)))
|
|
514
|
+
(t (literal-fail (str type " expects a name or namespace and name")))))
|
|
515
|
+
(defun Keyword (token namespace name)
|
|
516
|
+
(unless (eq token literal-token) (literal-fail "Keyword values must be created with keyword()"))
|
|
517
|
+
(let ((receiver (js* "this")))
|
|
518
|
+
(Object/defineProperty receiver literal-value-type (js-object :value "keyword"))
|
|
519
|
+
(Object/freeze receiver)))
|
|
520
|
+
(defun EliscriptSymbol (token namespace name &optional metadata)
|
|
521
|
+
(unless (eq token literal-token) (literal-fail "EliscriptSymbol values must be created with eliscriptSymbol()"))
|
|
522
|
+
(let ((receiver (js* "this")))
|
|
523
|
+
(Object/defineProperty receiver literal-value-type (js-object :value "symbol")) (Object/freeze receiver)))
|
|
524
|
+
(defun literal-new-identifier (type normalized)
|
|
525
|
+
(literal-initialize-prototype type)
|
|
526
|
+
(literal-register (if (= type 6) (new Keyword literal-token (get normalized :namespace) (get normalized :name))
|
|
527
|
+
(new EliscriptSymbol literal-token (get normalized :namespace) (get normalized :name) (get normalized :metadata nil))) type normalized))
|
|
528
|
+
(defun literal-keyword (&rest values)
|
|
529
|
+
(let* ((normalized (literal-identifier-arguments values "keyword")) (existing (get normalized :existing)))
|
|
530
|
+
(if (not (nil? existing)) existing
|
|
531
|
+
(let* ((namespace (get normalized :namespace)) (name (get normalized :name))
|
|
532
|
+
(key (if (nil? namespace) name (str namespace "/" name))) (cached (js-call literal-keywords :get key)))
|
|
533
|
+
(if (not (undefined? cached)) cached
|
|
534
|
+
(let ((value (literal-new-identifier 6 normalized))) (js-call literal-keywords :set key value) value))))))
|
|
535
|
+
(defun literal-symbol (&rest values)
|
|
536
|
+
(let* ((normalized (literal-identifier-arguments values "symbol")) (existing (get normalized :existing)))
|
|
537
|
+
(if (not (nil? existing)) existing (literal-new-identifier 7 normalized))))
|
|
538
|
+
(defun literal-equal (left right)
|
|
539
|
+
(if (and (not (nil? literal-protocol-runtime))
|
|
540
|
+
(= (value-type (get literal-protocol-runtime :equalValues)) "function"))
|
|
541
|
+
(funcall (get literal-protocol-runtime :equalValues) left right)
|
|
542
|
+
(literal-structural-equal left right)))
|
|
543
|
+
(defun literal-structural-equal (left right &rest comparators)
|
|
544
|
+
(let ((recurse (if (> (js-length comparators) 0) (get comparators 0) literal-equal)))
|
|
545
|
+
(if (= left right) t
|
|
546
|
+
(if (and (= (js* "typeof left") "number") (= (js* "typeof right") "number"))
|
|
547
|
+
(and (not (= left left)) (not (= right right)))
|
|
548
|
+
(let ((type (literal-type left)))
|
|
549
|
+
(cond
|
|
550
|
+
((or (literal-identifier? left "keyword") (literal-identifier? left "symbol"))
|
|
551
|
+
(try (and (literal-identifier? right (if (literal-identifier? left "keyword") "keyword" "symbol"))
|
|
552
|
+
(= (get left :namespace) (get right :namespace)) (= (get left :name) (get right :name))) (catch error false)))
|
|
553
|
+
((or (= type 0) (and (/= type (literal-type right))
|
|
554
|
+
(not (and (or (= type 2) (= type 8)) (or (= (literal-type right) 2) (= (literal-type right) 8)))))) false)
|
|
555
|
+
((= type 3) (let ((a (literal-data left 3)) (b (literal-data right 3)))
|
|
556
|
+
(and (= (persistent-map-count a) (persistent-map-count b))
|
|
557
|
+
(persistent-map-reduce (lambda (out key item)
|
|
558
|
+
(and out (persistent-map-has? b key) (funcall recurse item (persistent-map-get b key nil)))) t a))))
|
|
559
|
+
((= type 4) (let ((a (literal-data left 4)) (b (literal-data right 4)))
|
|
560
|
+
(and (= (persistent-set-count a) (persistent-set-count b))
|
|
561
|
+
(persistent-set-reduce (lambda (out item) (and out (persistent-set-has? b item))) t a))))
|
|
562
|
+
(t (let ((a (literal-to-array left)) (b (literal-to-array right)) (index 0) (same t))
|
|
563
|
+
(if (/= (js-length a) (js-length b)) false
|
|
564
|
+
(progn (while (and same (< index (js-length a)))
|
|
565
|
+
(setq same (funcall recurse (get a index) (get b index)) index (1+ index))) same))))))))))
|
|
566
|
+
(defun literal-mix (hash value)
|
|
567
|
+
(let ((mixed (imul32 (bit-xor hash value) 1540483477)))
|
|
568
|
+
(uint32 (bit-xor mixed (unsigned-bit-shift-right mixed 15)))))
|
|
569
|
+
(defun literal-finish (hash count)
|
|
570
|
+
(let ((mixed (literal-mix hash count)))
|
|
571
|
+
(setq mixed (imul32 (bit-xor mixed (unsigned-bit-shift-right mixed 16)) 2246822507))
|
|
572
|
+
(setq mixed (imul32 (bit-xor mixed (unsigned-bit-shift-right mixed 13)) 3266489909))
|
|
573
|
+
(uint32 (bit-xor mixed (unsigned-bit-shift-right mixed 16)))))
|
|
574
|
+
(defun literal-string-hash (text tag)
|
|
575
|
+
(let ((hash (literal-mix tag (js-length text))) (index 0))
|
|
576
|
+
(while (< index (js-length text)) (setq hash (literal-mix hash (string-code-unit-at text index)) index (1+ index)))
|
|
577
|
+
(literal-finish hash (js-length text))))
|
|
578
|
+
(defun literal-ordered-hash (values tag hasher)
|
|
579
|
+
(let ((hash tag) (index 0))
|
|
580
|
+
(while (< index (js-length values)) (setq hash (literal-mix hash (funcall hasher (get values index))) index (1+ index)))
|
|
581
|
+
(literal-finish hash index)))
|
|
582
|
+
(defun literal-hash (value)
|
|
583
|
+
(managed-literal-hash-value value))
|
|
584
|
+
(defun literal-structural-hash (value &rest hashers)
|
|
585
|
+
(let ((type (literal-type value)) (host-type (js* "typeof value"))
|
|
586
|
+
(hasher (if (> (js-length hashers) 0) (get hashers 0) literal-hash)))
|
|
587
|
+
(cond
|
|
588
|
+
((or (= host-type "bigint") (= host-type "symbol")) (hashPrimitiveValue value))
|
|
589
|
+
((or (literal-identifier? value "keyword") (literal-identifier? value "symbol"))
|
|
590
|
+
(literal-finish (literal-mix (literal-mix
|
|
591
|
+
(if (literal-identifier? value "keyword") 795685287 1908952723)
|
|
592
|
+
(if (nil? (get value :namespace)) 1251063421 (literal-string-hash (get value :namespace) 1831565813)))
|
|
593
|
+
(literal-string-hash (get value :name) 1831565813)) 2))
|
|
594
|
+
((or (and (>= type 1) (<= type 5)) (= type 8))
|
|
595
|
+
(let ((cached (if (> (js-length hashers) 0) undefined (js-call literal-hashes :get value))))
|
|
596
|
+
(if (not (undefined? cached)) cached
|
|
597
|
+
(let ((hash
|
|
598
|
+
(if (or (= type 3) (= type 4))
|
|
599
|
+
(let ((sum 0) (xor 0) (product 1) (count 0))
|
|
600
|
+
(let ((visit (lambda (item-hash)
|
|
601
|
+
(setq sum (uint32 (+ sum item-hash))
|
|
602
|
+
xor (uint32 (bit-xor xor (rotate-left item-hash (bit-and item-hash 31))))
|
|
603
|
+
product (uint32 (imul32 product (bit-or item-hash 1))) count (1+ count)))))
|
|
604
|
+
(if (= type 3)
|
|
605
|
+
(persistent-map-reduce (lambda (_ key item)
|
|
606
|
+
(funcall visit (literal-finish (literal-mix (literal-mix 982610667 (funcall hasher key)) (funcall hasher item)) 2)))
|
|
607
|
+
nil (literal-data value 3))
|
|
608
|
+
(persistent-set-reduce (lambda (_ item) (funcall visit (funcall hasher item))) nil (literal-data value 4))))
|
|
609
|
+
(literal-finish (literal-mix (literal-mix (literal-mix (if (= type 3) 1821285621 1374139181) sum) xor) product) count))
|
|
610
|
+
(literal-ordered-hash (literal-to-array value)
|
|
611
|
+
(if (= type 1) 793406745 (if (or (= type 2) (= type 8)) 1327180861 1799167783)) hasher))))
|
|
612
|
+
(when (= (js-length hashers) 0) (js-call literal-hashes :set value hash)) hash))))
|
|
613
|
+
(t (hashPrimitiveValue value)))))
|
|
614
|
+
|
|
615
|
+
;; Iterator positions and callback arguments are ordinary source values. No
|
|
616
|
+
;; host iterator or per-element compiler import participates in this path.
|
|
617
|
+
(defun literal-iterator-state (iterator)
|
|
618
|
+
(let ((state (js-call literal-iterators :get iterator)))
|
|
619
|
+
(if (undefined? state) (literal-fail "incompatible generator receiver") state)))
|
|
620
|
+
(defun literal-map-iterator-entry (state)
|
|
621
|
+
(let ((stack (get state :stack)) (entry nil))
|
|
622
|
+
(while (and (nil? entry) (> (js-length stack) 0))
|
|
623
|
+
(let* ((frame (get stack (1- (js-length stack)))) (node (get frame :node)) (kind (get node :kind)))
|
|
624
|
+
(if (= kind "entry") (progn (js-call stack :pop) (setq entry node))
|
|
625
|
+
(let* ((children (get node (if (= kind "bitmap") "items" (if (= kind "array") "children" "entries"))))
|
|
626
|
+
(index (get frame :index)))
|
|
627
|
+
(if (>= index (js-length children)) (js-call stack :pop)
|
|
628
|
+
(progn (put frame :index (1+ index))
|
|
629
|
+
(let ((child (get children index)))
|
|
630
|
+
(unless (nullish? child) (js-call stack :push (js-object :node child :index 0)))))))))) entry))
|
|
631
|
+
(defun literal-iterator-next (&rest arguments)
|
|
632
|
+
(let* ((state (literal-iterator-state (js* "this"))) (type (get state :type))
|
|
633
|
+
(data (get state :data)) (index (get state :index)) (out literal-missing))
|
|
634
|
+
(unless (get state :closed)
|
|
635
|
+
(cond
|
|
636
|
+
((= type 0) (when (< index (js-length data)) (setq out (get data index))))
|
|
637
|
+
((= type 1) (unless (persistent-list-empty? data)
|
|
638
|
+
(setq out (persistent-list-first data nil)) (put state :data (persistent-list-rest data nil))))
|
|
639
|
+
((= type 2) (when (< index (persistent-vector-count data)) (setq out (persistent-vector-nth data index nil))))
|
|
640
|
+
((= type 8) (when (< index (managed-vector-view-state-count data))
|
|
641
|
+
(setq out (js-call (literal-subvector-source data) :nth (+ (managed-vector-view-state-start data) index)))))
|
|
642
|
+
((= type 5) (when (< index (managed-queue-state-count data))
|
|
643
|
+
(let* ((front (get data :front)) (front-count (persistent-list-count front)))
|
|
644
|
+
(setq out (if (< index front-count) (persistent-list-nth front index nil)
|
|
645
|
+
(let ((rear (get data :rear)))
|
|
646
|
+
(persistent-list-nth rear (- (1- (persistent-list-count rear)) (- index front-count)) nil)))))))
|
|
647
|
+
(t (let ((entry (literal-map-iterator-entry state)) (mode (get state :mode)))
|
|
648
|
+
(unless (nil? entry)
|
|
649
|
+
(let ((key (get entry :key)))
|
|
650
|
+
(setq out (if (= type 4)
|
|
651
|
+
(if (= mode 3) (Object/freeze (js-array key key)) key)
|
|
652
|
+
(cond ((= mode 1) key) ((= mode 2) (get entry :value))
|
|
653
|
+
(t (Object/freeze (js-array key (get entry :value))))))))))))
|
|
654
|
+
(put state :index (1+ index)))
|
|
655
|
+
(if (eq out literal-missing)
|
|
656
|
+
(progn (put state :closed t) (put state :data nil) (put state :stack nil) (js-object :value undefined :done t))
|
|
657
|
+
(js-object :value out :done false))))
|
|
658
|
+
(defun literal-iterator-return (&rest arguments)
|
|
659
|
+
(let ((state (literal-iterator-state (js* "this")))
|
|
660
|
+
(value (if (> (js-length arguments) 0) (get arguments 0) undefined)))
|
|
661
|
+
(put state :closed t) (put state :data nil) (put state :stack nil)
|
|
662
|
+
(js-object :value value :done t)))
|
|
663
|
+
(defun literal-iterator-throw (value)
|
|
664
|
+
(let ((state (literal-iterator-state (js* "this"))))
|
|
665
|
+
(put state :closed t) (put state :data nil) (put state :stack nil) (throw value)))
|
|
666
|
+
(defun literal-iterator-self () (js* "this"))
|
|
667
|
+
(defun literal-make-iterator (values)
|
|
668
|
+
(literal-new-iterator 0 values 0))
|
|
669
|
+
(defvar literal-iterator-prototype nil)
|
|
670
|
+
(defun literal-new-iterator (type data mode)
|
|
671
|
+
(when (nil? literal-iterator-prototype)
|
|
672
|
+
(setq literal-iterator-prototype (js-object))
|
|
673
|
+
(literal-install-method literal-iterator-prototype "next" "next" 1 literal-iterator-next)
|
|
674
|
+
(literal-install-method literal-iterator-prototype "return" "return" 1 literal-iterator-return)
|
|
675
|
+
(literal-install-method literal-iterator-prototype "throw" "throw" 1 literal-iterator-throw)
|
|
676
|
+
(literal-install-method literal-iterator-prototype (get globalThis/Symbol :iterator) "[Symbol.iterator]" 0 literal-iterator-self)
|
|
677
|
+
(Object/defineProperty literal-iterator-prototype (get globalThis/Symbol :toStringTag)
|
|
678
|
+
(js-object :value "Generator" :configurable t)))
|
|
679
|
+
(let ((iterator (Object/create literal-iterator-prototype))
|
|
680
|
+
(state (js-object :type type :data data :index 0 :mode mode :closed false :stack nil)))
|
|
681
|
+
(when (or (= type 3) (= type 4))
|
|
682
|
+
(let* ((map (if (= type 4) (get data :map) data)) (root (get map :root)))
|
|
683
|
+
(put state :stack (if (nil? root) (js-array) (js-array (js-object :node root :index 0))))))
|
|
684
|
+
(js-call literal-iterators :set iterator state) iterator))
|
|
685
|
+
(defun literal-iterate-method () (literal-make-iterator (literal-to-array (js* "this"))))
|
|
686
|
+
(defun literal-to-array-method () (literal-to-array (js* "this")))
|
|
687
|
+
(defun literal-count-method () (get (aref (js* "this") (literal-state-key (literal-type (js* "this")))) :count))
|
|
688
|
+
(defun literal-list-count-method () (get (aref (js* "this") literal-list-state) :count))
|
|
689
|
+
(defun literal-vector-count-method () (get (aref (js* "this") literal-vector-state) :count))
|
|
690
|
+
(defun literal-map-count-method () (get (aref (js* "this") literal-map-state) :count))
|
|
691
|
+
(defun literal-queue-count-method () (get (aref (js* "this") literal-queue-state) :count))
|
|
692
|
+
(defun literal-set-count-method () (get (get (aref (js* "this") literal-set-state) :map) :count))
|
|
693
|
+
(defun literal-empty-method () (= (literal-count (js* "this")) 0))
|
|
694
|
+
(defun literal-first-method (&rest args) (literal-first (js* "this") (if (> (js-length args) 0) (get args 0) nil)))
|
|
695
|
+
(defun literal-rest-method () (literal-rest (js* "this")))
|
|
696
|
+
(defun literal-nth-method (index &rest not-found)
|
|
697
|
+
(apply literal-nth (js-call (js-array (js* "this") index) :concat not-found)))
|
|
698
|
+
(defun literal-conj-method (value) (literal-conj (js* "this") value))
|
|
699
|
+
(defun literal-assoc-method (key value) (literal-assoc (js* "this") key value))
|
|
700
|
+
(defun literal-dissoc-method (key) (literal-dissoc (js* "this") key))
|
|
701
|
+
(defun literal-disj-method (value) (literal-disj (js* "this") value))
|
|
702
|
+
(defun literal-get-method (key &optional not-found) (literal-get (js* "this") key not-found))
|
|
703
|
+
(defun literal-has-method (key)
|
|
704
|
+
(let* ((receiver (js* "this")) (type (literal-type receiver)))
|
|
705
|
+
(if (= type 3) (persistent-map-has? (literal-data receiver 3) key)
|
|
706
|
+
(persistent-set-has? (literal-data receiver 4) key))))
|
|
707
|
+
(defun literal-peek-method (&rest args) (literal-peek (js* "this") (if (> (js-length args) 0) (get args 0) nil)))
|
|
708
|
+
(defun literal-pop-method () (literal-pop (js* "this")))
|
|
709
|
+
(defun literal-entry (entry)
|
|
710
|
+
(when (or (nullish? entry) (not (= (value-type (get entry (get globalThis/Symbol :iterator))) "function")))
|
|
711
|
+
(literal-fail "persistent hash map entries must be iterable key/value pairs"))
|
|
712
|
+
(let* ((iterator (js-call entry (get globalThis/Symbol :iterator))) (complete false))
|
|
713
|
+
(try
|
|
714
|
+
(let* ((first (js-call iterator :next)) (second nil) (third nil))
|
|
715
|
+
(let ((done (get first :done)))
|
|
716
|
+
(when (js* "!!done") (literal-fail "persistent hash map entries must contain exactly two values")))
|
|
717
|
+
(setq second (js-call iterator :next))
|
|
718
|
+
(let ((done (get second :done)))
|
|
719
|
+
(when (js* "!!done") (literal-fail "persistent hash map entries must contain exactly two values")))
|
|
720
|
+
(setq third (js-call iterator :next))
|
|
721
|
+
(let ((done (get third :done)))
|
|
722
|
+
(unless (js* "!!done") (literal-fail "persistent hash map entries must contain exactly two values")))
|
|
723
|
+
(setq complete t) (js-array (get first :value) (get second :value)))
|
|
724
|
+
(finally (when (and (not complete) (= (value-type (get iterator :return)) "function")) (js-call iterator :return))))))
|
|
725
|
+
(defun literal-reduce-method (reducer &rest initial)
|
|
726
|
+
(unless (= (value-type reducer) "function") (literal-fail "collection reducer must be a function"))
|
|
727
|
+
(let* ((receiver (js* "this")) (type (literal-type receiver)) (values (literal-to-array receiver))
|
|
728
|
+
(count (js-length values)) (index 0) (result nil))
|
|
729
|
+
(when (and (or (= type 3) (= type 4)) (= (js-length initial) 0))
|
|
730
|
+
(literal-fail "persistent hash collection reduce requires an initial value"))
|
|
731
|
+
(if (> (js-length initial) 0) (setq result (get initial 0))
|
|
732
|
+
(if (= count 0) (literal-fail "cannot reduce an empty collection without an initial value")
|
|
733
|
+
(setq result (get values 0) index 1)))
|
|
734
|
+
(while (< index count)
|
|
735
|
+
(setq result (if (= type 3)
|
|
736
|
+
(funcall reducer result (get (get values index) 1) (get (get values index) 0) receiver)
|
|
737
|
+
(if (= type 4) (funcall reducer result (get values index) receiver)
|
|
738
|
+
(funcall reducer result (get values index)))) index (1+ index))) result))
|
|
739
|
+
(defun literal-map-keys-method ()
|
|
740
|
+
(literal-new-iterator 3 (literal-data (js* "this") 3) 1))
|
|
741
|
+
(defun literal-map-values-method ()
|
|
742
|
+
(literal-new-iterator 3 (literal-data (js* "this") 3) 2))
|
|
743
|
+
(defun literal-set-entries-method ()
|
|
744
|
+
(literal-new-iterator 4 (literal-data (js* "this") 4) 3))
|
|
745
|
+
(defun literal-name-method () (get (get (literal-record (js* "this")) :data) :name))
|
|
746
|
+
(defun literal-namespace-method () (get (get (literal-record (js* "this")) :data) :namespace))
|
|
747
|
+
(defun literal-qualified-name-method ()
|
|
748
|
+
(let* ((receiver (js* "this")) (namespace (get receiver :namespace)) (name (get receiver :name)))
|
|
749
|
+
(if (nil? namespace) name (str namespace "/" name))))
|
|
750
|
+
(defun literal-identifier-string-method ()
|
|
751
|
+
(let ((receiver (js* "this")))
|
|
752
|
+
(str (if (= (literal-type receiver) 6) ":" "") (get receiver :qualifiedName))))
|
|
753
|
+
(defun literal-identifier-json-method ()
|
|
754
|
+
(literal-fail (if (= (literal-type (js* "this")) 6)
|
|
755
|
+
"Keyword values require an explicit serialization codec" "EliscriptSymbol values require an explicit serialization codec")))
|
|
756
|
+
(defun literal-tag-method ()
|
|
757
|
+
(let ((type (literal-type (js* "this"))))
|
|
758
|
+
(cond ((= type 1) "EliscriptPersistentList") ((= type 2) "EliscriptPersistentVector")
|
|
759
|
+
((= type 3) "EliscriptPersistentHashMap") ((= type 4) "EliscriptPersistentHashSet")
|
|
760
|
+
((= type 5) "EliscriptPersistentQueue") ((= type 6) "EliscriptKeyword") (t "EliscriptSymbol"))))
|
|
761
|
+
|
|
762
|
+
;; Each prototype method reads its own class's state key. In particular a
|
|
763
|
+
;; borrowed vector method must never dispatch as a list method on its receiver.
|
|
764
|
+
(defun literal-list-tag () "EliscriptPersistentList")
|
|
765
|
+
(defun literal-vector-tag () "EliscriptPersistentVector")
|
|
766
|
+
(defun literal-map-tag () "EliscriptPersistentHashMap")
|
|
767
|
+
(defun literal-set-tag () "EliscriptPersistentHashSet")
|
|
768
|
+
(defun literal-queue-tag () "EliscriptPersistentQueue")
|
|
769
|
+
(defun literal-keyword-tag () "EliscriptKeyword")
|
|
770
|
+
(defun literal-symbol-tag () "EliscriptSymbol")
|
|
771
|
+
(defun literal-object? (value)
|
|
772
|
+
(or (and (not (nil? value)) (= (js* "typeof value") "object")) (= (js* "typeof value") "function")))
|
|
773
|
+
(defun literal-close-iterator (iterator abrupt)
|
|
774
|
+
(try
|
|
775
|
+
(let ((close (get iterator :return)))
|
|
776
|
+
(unless (nullish? close)
|
|
777
|
+
(unless (= (js* "typeof close") "function") (literal-fail "iterator return must be callable"))
|
|
778
|
+
(let ((closed (js-call close :call iterator)))
|
|
779
|
+
(unless (literal-object? closed) (literal-fail "iterator return must be an object")))))
|
|
780
|
+
(catch error (unless abrupt (throw error)))))
|
|
781
|
+
(defun literal-while-each (iterable visit)
|
|
782
|
+
(let ((method (aref iterable (get globalThis/Symbol :iterator))))
|
|
783
|
+
(unless (= (js* "typeof method") "function") (literal-fail "value is not iterable"))
|
|
784
|
+
(let ((iterator (js-call method :call iterable)))
|
|
785
|
+
(unless (literal-object? iterator) (literal-fail "iterator must be an object"))
|
|
786
|
+
(let ((next (get iterator :next)) (done false) (complete t))
|
|
787
|
+
(while (not done)
|
|
788
|
+
;; IteratorNext/done/value failures precede entry into the body.
|
|
789
|
+
(let ((step (js-call next :call iterator)))
|
|
790
|
+
(unless (literal-object? step) (literal-fail "iterator result must be an object"))
|
|
791
|
+
(let ((finished (get step :done)))
|
|
792
|
+
(if (js* "!!finished") (setq done t)
|
|
793
|
+
(let ((item (get step :value)) (continuing t))
|
|
794
|
+
(try (setq continuing (funcall visit item))
|
|
795
|
+
(catch error (literal-close-iterator iterator t) (throw error)))
|
|
796
|
+
(unless (js* "!!continuing")
|
|
797
|
+
(literal-close-iterator iterator false) (setq complete false done t))))))) complete))))
|
|
798
|
+
(defvar literal-protocol-runtime nil)
|
|
799
|
+
(defun literal-protocols ()
|
|
800
|
+
(when (nil? literal-protocol-runtime)
|
|
801
|
+
(setq literal-protocol-runtime (managed-literal-register-protocols (js-object) (literal-protocol-callbacks))))
|
|
802
|
+
literal-protocol-runtime)
|
|
803
|
+
(defun literal-protocol-runtime-get () (literal-protocols))
|
|
804
|
+
(defun literal-protocol-callbacks ()
|
|
805
|
+
(js-object :type literal-type :count literal-count :equal literal-structural-equal :hash literal-structural-hash
|
|
806
|
+
:meta literal-meta :withMeta literal-with-meta :conj literal-conj :assoc literal-assoc :dissoc literal-dissoc
|
|
807
|
+
:disj literal-disj :peek literal-peek :pop literal-pop :nth literal-nth :get literal-get :toArray literal-to-array
|
|
808
|
+
:transient literal-transient :transientType literal-transient-type :transientConj literal-transient-conj
|
|
809
|
+
:transientAssoc literal-transient-assoc :transientDissoc literal-transient-dissoc :transientPersistent literal-transient-persistent))
|
|
810
|
+
(defun literal-register-protocol-type (type constructor)
|
|
811
|
+
(let ((constructors (js-object))
|
|
812
|
+
(name (cond ((= type 1) "list") ((= type 2) "vector") ((= type 3) "map") ((= type 4) "set")
|
|
813
|
+
((= type 5) "queue") ((= type 6) "keyword") ((= type 7) "symbol") (t "subvector"))))
|
|
814
|
+
(put constructors name constructor)
|
|
815
|
+
(when (= type 8) (put constructors :vector PersistentVector))
|
|
816
|
+
(setq literal-protocol-runtime (managed-literal-register-protocols constructors (literal-protocol-callbacks)))))
|
|
817
|
+
(defun literal-reduced-result? (value)
|
|
818
|
+
(and (not (nil? literal-protocol-runtime))
|
|
819
|
+
(funcall (get literal-protocol-runtime :isReduced) value)))
|
|
820
|
+
(defun literal-unreduced-result (value)
|
|
821
|
+
(funcall (get literal-protocol-runtime :unreduced) value))
|
|
822
|
+
(defun literal-sequence-reduce-method (reducer &rest initial)
|
|
823
|
+
(unless (= (value-type reducer) "function") (literal-fail "collection reducer must be a function"))
|
|
824
|
+
(let ((result (if (= (js-length initial) 0) literal-missing (get initial 0))))
|
|
825
|
+
(literal-while-each (js* "this") (lambda (item)
|
|
826
|
+
(if (eq result literal-missing) (progn (setq result item) t)
|
|
827
|
+
(progn (setq result (funcall reducer result item))
|
|
828
|
+
(if (literal-reduced-result? result) (progn (setq result (literal-unreduced-result result)) false) t)))))
|
|
829
|
+
(when (eq result literal-missing) (literal-fail "cannot reduce an empty collection without an initial value")) result))
|
|
830
|
+
(defun literal-map-reduce-method (reducer &rest initial)
|
|
831
|
+
(unless (= (value-type reducer) "function") (literal-fail "persistent hash map reducer must be a function"))
|
|
832
|
+
(when (= (js-length initial) 0) (literal-fail "persistent hash map reduce requires an initial value"))
|
|
833
|
+
(let* ((receiver (js* "this")) (data (literal-data receiver 3)) (result (get initial 0))
|
|
834
|
+
(iterator (literal-new-iterator 3 data 0)))
|
|
835
|
+
(literal-while-each iterator (lambda (entry)
|
|
836
|
+
(setq result (funcall reducer result (get entry 1) (get entry 0) receiver))
|
|
837
|
+
(if (literal-reduced-result? result) (progn (setq result (literal-unreduced-result result)) false) t))) result))
|
|
838
|
+
(defun literal-set-reduce-method (reducer &rest initial)
|
|
839
|
+
(unless (= (value-type reducer) "function") (literal-fail "persistent hash set reducer must be a function"))
|
|
840
|
+
(when (= (js-length initial) 0) (literal-fail "persistent hash set reduce requires an initial value"))
|
|
841
|
+
(let ((receiver (js* "this")) (result (get initial 0)))
|
|
842
|
+
(literal-while-each receiver (lambda (item)
|
|
843
|
+
(setq result (funcall reducer result item receiver))
|
|
844
|
+
(if (literal-reduced-result? result) (progn (setq result (literal-unreduced-result result)) false) t))) result))
|
|
845
|
+
(defun literal-to-map-method ()
|
|
846
|
+
(let ((out (new globalThis/Map)))
|
|
847
|
+
(literal-each (js* "this") (lambda (entry) (js-call out :set (get entry 0) (get entry 1)))) out))
|
|
848
|
+
(defun literal-to-set-method ()
|
|
849
|
+
(let ((out (new globalThis/Set)))
|
|
850
|
+
(literal-each (js* "this") (lambda (value) (js-call out :add value))) out))
|
|
851
|
+
(defun literal-set-union-method (&rest collections)
|
|
852
|
+
(let ((result (js* "this")) (index 0))
|
|
853
|
+
(while (< index (js-length collections))
|
|
854
|
+
(literal-each (get collections index) (lambda (value) (setq result (js-call result :conj value))))
|
|
855
|
+
(setq index (1+ index))) result))
|
|
856
|
+
(defun literal-set-intersection-method (&rest collections)
|
|
857
|
+
(let ((receiver (js* "this")) (result (js* "this")) (index 0) (finished false))
|
|
858
|
+
(while (and (not finished) (< index (js-length collections)))
|
|
859
|
+
(let ((other (literal-set-from (get collections index))))
|
|
860
|
+
(if (= (get result :count) 0) (setq finished t)
|
|
861
|
+
(let* ((candidates (if (<= (get result :count) (get other :count)) result other))
|
|
862
|
+
(membership (if (eq candidates result) other result))
|
|
863
|
+
(retained (literal-with-meta (literal-set-empty) (get (aref receiver literal-set-state) :metadata))))
|
|
864
|
+
(literal-each candidates (lambda (value)
|
|
865
|
+
(when (js-call membership :has value) (setq retained (js-call retained :conj value)))))
|
|
866
|
+
(unless (= (get retained :count) (get result :count)) (setq result retained)))))
|
|
867
|
+
(setq index (1+ index))) result))
|
|
868
|
+
(defun literal-set-difference-method (&rest collections)
|
|
869
|
+
(let ((result (js* "this")) (index 0) (finished false))
|
|
870
|
+
(while (and (not finished) (< index (js-length collections)))
|
|
871
|
+
(literal-each (get collections index) (lambda (value) (setq result (js-call result :disj value))))
|
|
872
|
+
(when (= (get result :count) 0) (setq finished t)) (setq index (1+ index))) result))
|
|
873
|
+
(defun literal-set-subset-method (collection)
|
|
874
|
+
(let ((receiver (js* "this")) (other (literal-set-from collection)))
|
|
875
|
+
(if (> (get receiver :count) (get other :count)) false
|
|
876
|
+
(literal-while-each receiver (lambda (value) (js-call other :has value))))))
|
|
877
|
+
(defun literal-set-superset-method (collection)
|
|
878
|
+
(js-call (literal-set-from collection) :isSubsetOf (js* "this")))
|
|
879
|
+
(defun literal-set-disjoint-method (collection)
|
|
880
|
+
(let* ((receiver (js* "this")) (other (literal-set-from collection))
|
|
881
|
+
(candidates (if (<= (get receiver :count) (get other :count)) receiver other))
|
|
882
|
+
(membership (if (eq candidates receiver) other receiver)))
|
|
883
|
+
(literal-while-each candidates (lambda (value) (not (js-call membership :has value))))))
|
|
884
|
+
|
|
885
|
+
(defun literal-finish-change (type data next receiver)
|
|
886
|
+
(if (nil? next) (literal-range "persistent collection cannot exceed 2147483647 values")
|
|
887
|
+
(if (eq data next) receiver (literal-wrap type next))))
|
|
888
|
+
(defun literal-list-conj-method (value)
|
|
889
|
+
(let* ((receiver (js* "this")) (data (literal-data receiver 1)))
|
|
890
|
+
(literal-finish-change 1 data (persistent-list-cons data value) receiver)))
|
|
891
|
+
(defun literal-vector-conj-method (value)
|
|
892
|
+
(let* ((receiver (js* "this")) (data (literal-data receiver 2)))
|
|
893
|
+
(literal-finish-change 2 data (persistent-vector-conj data value) receiver)))
|
|
894
|
+
(defun literal-map-conj-method (value)
|
|
895
|
+
(let* ((receiver (js* "this")) (data (literal-data receiver 3)) (entry (literal-entry value)))
|
|
896
|
+
(literal-finish-change 3 data (persistent-map-assoc data (get entry 0) (get entry 1)) receiver)))
|
|
897
|
+
(defun literal-set-conj-method (value)
|
|
898
|
+
(let* ((receiver (js* "this")) (data (literal-data receiver 4)))
|
|
899
|
+
(literal-finish-change 4 data (persistent-set-conj data value) receiver)))
|
|
900
|
+
(defun literal-queue-conj-method (value)
|
|
901
|
+
(let* ((receiver (js* "this")) (data (literal-data receiver 5)) (state (aref receiver literal-queue-state))
|
|
902
|
+
(next (managed-queue-state-conj data value)))
|
|
903
|
+
(when (nil? next) (literal-range "persistent queue cannot exceed 2147483647 values"))
|
|
904
|
+
(js-call literal-queue-views :set next
|
|
905
|
+
(if (= (get state :count) 0) (js-object :front (literal-vector value) :rear (literal-vector-empty))
|
|
906
|
+
(js-object :front (get state :front) :rear (js-call (get state :rear) :conj value))))
|
|
907
|
+
(literal-wrap 5 next)))
|
|
908
|
+
(defun literal-vector-assoc-method (index value)
|
|
909
|
+
(let* ((receiver (js* "this")) (data (literal-data receiver 2)))
|
|
910
|
+
(unless (and (Number/isInteger index) (>= index 0) (<= index (persistent-vector-count data)))
|
|
911
|
+
(literal-range (str "assoc index " (funcall globalThis/String index) " is outside [0, " (persistent-vector-count data) ")")))
|
|
912
|
+
(literal-finish-change 2 data (persistent-vector-assoc data index value) receiver)))
|
|
913
|
+
(defun literal-map-assoc-method (key value)
|
|
914
|
+
(let* ((receiver (js* "this")) (data (literal-data receiver 3)))
|
|
915
|
+
(literal-finish-change 3 data (persistent-map-assoc data key value) receiver)))
|
|
916
|
+
(defun literal-map-get-method (key &optional not-found)
|
|
917
|
+
(persistent-map-get (literal-data (js* "this") 3) key not-found))
|
|
918
|
+
(defun literal-map-has-method (key) (persistent-map-has? (literal-data (js* "this") 3) key))
|
|
919
|
+
(defun literal-set-has-method (key) (persistent-set-has? (literal-data (js* "this") 4) key))
|
|
920
|
+
(defun literal-nth-data (type data index not-found)
|
|
921
|
+
(let ((out (if (= type 1) (persistent-list-nth data index not-found) (persistent-vector-nth data index not-found))))
|
|
922
|
+
(if (eq out literal-missing)
|
|
923
|
+
(literal-range (str "nth index " (funcall globalThis/String index) " is outside [0, " (literal-data-count type data) ")")) out)))
|
|
924
|
+
(defun literal-list-nth-method (index &optional not-found)
|
|
925
|
+
(literal-nth-data 1 (literal-data (js* "this") 1) index
|
|
926
|
+
(if (undefined? not-found) literal-missing not-found)))
|
|
927
|
+
(defun literal-vector-nth-method (index &optional not-found)
|
|
928
|
+
(literal-nth-data 2 (literal-data (js* "this") 2) index
|
|
929
|
+
(if (undefined? not-found) literal-missing not-found)))
|
|
930
|
+
(defun literal-list-first-method (&optional not-found)
|
|
931
|
+
(let ((state (aref (js* "this") literal-list-state))) (if (get state :empty) not-found (get state :value))))
|
|
932
|
+
(defun literal-list-rest-method ()
|
|
933
|
+
(let* ((receiver (js* "this")) (state (aref receiver literal-list-state)))
|
|
934
|
+
(if (get state :empty) receiver (get state :rest))))
|
|
935
|
+
(defun literal-list-peek-method (&optional not-found) (js-call (js* "this") :first not-found))
|
|
936
|
+
(defun literal-vector-peek-method (&optional not-found)
|
|
937
|
+
(let ((receiver (js* "this")))
|
|
938
|
+
(if (= (get receiver :count) 0) not-found (js-call receiver :nth (1- (get receiver :count))))))
|
|
939
|
+
(defun literal-queue-peek-method (&optional not-found)
|
|
940
|
+
(let ((state (aref (js* "this") literal-queue-state)))
|
|
941
|
+
(if (= (get state :count) 0) not-found (js-call (get state :front) :nth 0))))
|
|
942
|
+
(defun literal-pop-data (type data)
|
|
943
|
+
(when (= (literal-data-count type data) 0)
|
|
944
|
+
(literal-range (cond ((= type 1) "cannot pop an empty persistent list")
|
|
945
|
+
((= type 2) "cannot pop an empty persistent vector") (t "cannot pop an empty persistent queue"))))
|
|
946
|
+
(literal-wrap type (cond ((= type 1) (persistent-list-pop data)) ((= type 2) (persistent-vector-pop data))
|
|
947
|
+
(t (managed-queue-state-pop data)))))
|
|
948
|
+
(defun literal-list-pop-method () (literal-pop-data 1 (literal-data (js* "this") 1)))
|
|
949
|
+
(defun literal-vector-pop-method () (literal-pop-data 2 (literal-data (js* "this") 2)))
|
|
950
|
+
(defun literal-queue-pop-method ()
|
|
951
|
+
(let* ((receiver (js* "this")) (data (literal-data receiver 5)) (state (aref receiver literal-queue-state)))
|
|
952
|
+
(when (= (get state :count) 0) (literal-range "cannot pop an empty persistent queue"))
|
|
953
|
+
(let ((next (managed-queue-state-pop data)))
|
|
954
|
+
(js-call literal-queue-views :set next
|
|
955
|
+
(if (> (get (get state :front) :count) 1)
|
|
956
|
+
(js-object :front (literal-subvec (get state :front) 1) :rear (get state :rear))
|
|
957
|
+
(js-object :front (get state :rear) :rear (literal-vector-empty))))
|
|
958
|
+
(literal-wrap 5 next))))
|
|
959
|
+
(defun literal-list-array-method ()
|
|
960
|
+
(let ((out (js-array)) (index 0))
|
|
961
|
+
(literal-each (js* "this") (lambda (item) (put out index item) (setq index (1+ index)))) out))
|
|
962
|
+
(defun literal-vector-array-method ()
|
|
963
|
+
(let ((out (js-array)) (index 0))
|
|
964
|
+
(js-call (js* "this") :reduce (lambda (_ item) (put out index item) (setq index (1+ index)) out) out)))
|
|
965
|
+
(defun literal-queue-array-method ()
|
|
966
|
+
(let ((out (js-array)) (index 0))
|
|
967
|
+
(literal-each (js* "this") (lambda (item) (put out index item) (setq index (1+ index)))) out))
|
|
968
|
+
(defun literal-list-iterate-method () (literal-new-iterator 1 (literal-data (js* "this") 1) 0))
|
|
969
|
+
(defun literal-vector-iterate-method () (literal-new-iterator 2 (literal-data (js* "this") 2) 0))
|
|
970
|
+
(defun literal-map-iterate-method () (literal-new-iterator 3 (literal-data (js* "this") 3) 0))
|
|
971
|
+
(defun literal-set-iterate-method () (literal-new-iterator 4 (literal-data (js* "this") 4) 1))
|
|
972
|
+
(defun literal-queue-iterate-method () (literal-new-iterator 5 (literal-data (js* "this") 5) 0))
|
|
973
|
+
(defun literal-each (iterable visit)
|
|
974
|
+
(funcall (js* "(iterable, visit) => { for (const item of iterable) visit(item); }") iterable visit))
|
|
975
|
+
(defun literal-list-empty () (literal-wrap 1 literal-empty-list-data))
|
|
976
|
+
(defun literal-vector-empty () (literal-wrap 2 literal-empty-vector-data))
|
|
977
|
+
(defun literal-map-empty () (literal-wrap 3 literal-empty-map-data))
|
|
978
|
+
(defun literal-set-empty () (literal-wrap 4 literal-empty-set-data))
|
|
979
|
+
(defun literal-queue-empty () (literal-wrap 5 literal-empty-queue-data))
|
|
980
|
+
(defun literal-list-from (iterable)
|
|
981
|
+
(if (= (literal-type iterable) 1) iterable
|
|
982
|
+
(let* ((values (Array/from iterable)) (index (1- (js-length values))) (data literal-empty-list-data))
|
|
983
|
+
(when (> (js-length values) 2147483647) (literal-range "persistent list cannot exceed 2147483647 values"))
|
|
984
|
+
(while (>= index 0)
|
|
985
|
+
(setq data (persistent-list-cons data (get values index))
|
|
986
|
+
index (1- index)))
|
|
987
|
+
(literal-wrap 1 data))))
|
|
988
|
+
(defun literal-vector-new-path (level node)
|
|
989
|
+
(if (= level 0) node
|
|
990
|
+
(js-object :slots (js-array (literal-vector-new-path (- level 5) node)))))
|
|
991
|
+
(defun literal-vector-push-tail-mutable (level parent tail-node count)
|
|
992
|
+
(let* ((slots (get parent :slots))
|
|
993
|
+
(subindex (bit-and (unsigned-bit-shift-right (1- count) level) 31)))
|
|
994
|
+
(if (= level 5)
|
|
995
|
+
(put slots subindex tail-node)
|
|
996
|
+
(let ((existing (get slots subindex)))
|
|
997
|
+
(if (not (nullish? existing))
|
|
998
|
+
(literal-vector-push-tail-mutable (- level 5) existing tail-node count)
|
|
999
|
+
(put slots subindex (literal-vector-new-path (- level 5) tail-node)))))
|
|
1000
|
+
parent))
|
|
1001
|
+
(defun literal-vector-from-array-values (values)
|
|
1002
|
+
(let ((length (js-length values)))
|
|
1003
|
+
(when (> length 2147483647)
|
|
1004
|
+
(literal-range "persistent collection cannot exceed 2147483647 values"))
|
|
1005
|
+
(cond
|
|
1006
|
+
((= length 0) (literal-vector-empty))
|
|
1007
|
+
((<= length 32)
|
|
1008
|
+
(literal-wrap 2 (js-object :kind "eliscript/persistent-vector"
|
|
1009
|
+
:count length :shift 5 :root (get literal-empty-vector-data :root)
|
|
1010
|
+
:tail (if (funcall literal-object-is-frozen values) values (funcall literal-object-freeze (js-call values :slice)))
|
|
1011
|
+
:metadata nil)))
|
|
1012
|
+
(t
|
|
1013
|
+
(let ((count 0) (shift 5) (root (js-object :slots (js-array))) (tail (js-array)) (tail-len 0))
|
|
1014
|
+
(while (< count length)
|
|
1015
|
+
(let ((value (get values count)))
|
|
1016
|
+
(if (< tail-len 32)
|
|
1017
|
+
(progn (put tail tail-len value) (setq tail-len (1+ tail-len)))
|
|
1018
|
+
(let ((tail-node (js-object :slots tail)))
|
|
1019
|
+
(if (> (unsigned-bit-shift-right count 5) (bit-shift-left 1 shift))
|
|
1020
|
+
(setq root (js-object :slots (js-array root (literal-vector-new-path shift tail-node)))
|
|
1021
|
+
shift (+ shift 5))
|
|
1022
|
+
(literal-vector-push-tail-mutable shift root tail-node count))
|
|
1023
|
+
(setq tail (js-array value) tail-len 1))))
|
|
1024
|
+
(setq count (1+ count)))
|
|
1025
|
+
(literal-wrap 2 (js-object :kind "eliscript/persistent-vector"
|
|
1026
|
+
:count count :shift shift :root root :tail (funcall literal-object-freeze tail) :metadata nil)))))))
|
|
1027
|
+
(defun literal-vector-from (iterable)
|
|
1028
|
+
(if (or (= (literal-type iterable) 2) (= (literal-type iterable) 8)) iterable
|
|
1029
|
+
(if (and (funcall literal-array-is-array iterable) (not (funcall literal-object-has-own iterable literal-symbol-iterator)))
|
|
1030
|
+
(literal-vector-from-array-values iterable)
|
|
1031
|
+
(let ((count 0) (shift 5) (root (get literal-empty-vector-data :root)) (tail (js-array)) (tail-len 0))
|
|
1032
|
+
(literal-each iterable (lambda (value)
|
|
1033
|
+
(when (= count 2147483647)
|
|
1034
|
+
(literal-range "persistent collection cannot exceed 2147483647 values"))
|
|
1035
|
+
(if (< tail-len 32)
|
|
1036
|
+
(progn (put tail tail-len value) (setq tail-len (1+ tail-len)))
|
|
1037
|
+
(let ((tail-node (js-object :slots tail)))
|
|
1038
|
+
(when (eq root (get literal-empty-vector-data :root))
|
|
1039
|
+
(setq root (js-object :slots (js-array))))
|
|
1040
|
+
(if (> (unsigned-bit-shift-right count 5) (bit-shift-left 1 shift))
|
|
1041
|
+
(setq root (js-object :slots (js-array root (literal-vector-new-path shift tail-node)))
|
|
1042
|
+
shift (+ shift 5))
|
|
1043
|
+
(literal-vector-push-tail-mutable shift root tail-node count))
|
|
1044
|
+
(setq tail (js-array value) tail-len 1)))
|
|
1045
|
+
(setq count (1+ count))))
|
|
1046
|
+
(if (= count 0) (literal-vector-empty)
|
|
1047
|
+
(literal-wrap 2 (js-object :kind "eliscript/persistent-vector"
|
|
1048
|
+
:count count :shift shift :root root :tail (funcall literal-object-freeze tail) :metadata nil)))))))
|
|
1049
|
+
(defun literal-map-from (iterable)
|
|
1050
|
+
(if (= (literal-type iterable) 3) iterable
|
|
1051
|
+
(let ((data literal-empty-map-data))
|
|
1052
|
+
(literal-each iterable (lambda (entry)
|
|
1053
|
+
(let ((pair (literal-entry entry)))
|
|
1054
|
+
(setq data (persistent-map-assoc data (get pair 0) (get pair 1)))
|
|
1055
|
+
(when (nil? data) (literal-range "persistent collection cannot exceed 2147483647 values")))))
|
|
1056
|
+
(literal-wrap 3 data))))
|
|
1057
|
+
(defun literal-set-from (iterable)
|
|
1058
|
+
(if (= (literal-type iterable) 4) iterable
|
|
1059
|
+
(let ((data literal-empty-set-data))
|
|
1060
|
+
(literal-each iterable (lambda (value)
|
|
1061
|
+
(setq data (persistent-set-conj data value))
|
|
1062
|
+
(when (nil? data) (literal-range "persistent collection cannot exceed 2147483647 values"))))
|
|
1063
|
+
(literal-wrap 4 data))))
|
|
1064
|
+
(defun literal-queue-from (iterable)
|
|
1065
|
+
(if (= (literal-type iterable) 5) iterable
|
|
1066
|
+
(let ((result (literal-queue-empty)))
|
|
1067
|
+
(literal-each iterable (lambda (value) (setq result (js-call result :conj value)))) result)))
|
|
1068
|
+
|
|
1069
|
+
(defun PersistentSubVector (vector start end &optional metadata)
|
|
1070
|
+
(unless (= (literal-type vector) 2) (literal-fail "invalid persistent subvector source"))
|
|
1071
|
+
(literal-initialize-subvector-prototype)
|
|
1072
|
+
(let* ((source (aref vector literal-vector-state))
|
|
1073
|
+
(receiver (Reflect/construct PersistentVector
|
|
1074
|
+
(js-array literal-token (get source :count) (get source :shift) (get source :root) (get source :tail) metadata)
|
|
1075
|
+
PersistentSubVector))
|
|
1076
|
+
(data (managed-vector-view-state-make (literal-data vector 2) start end metadata)))
|
|
1077
|
+
(js-call literal-subvector-sources :set data vector)
|
|
1078
|
+
(literal-register receiver 8 data)))
|
|
1079
|
+
(defun literal-subvector-source (data)
|
|
1080
|
+
(let ((source (js-call literal-subvector-sources :get data)))
|
|
1081
|
+
(if (undefined? source) (literal-wrap 2 (managed-vector-view-state-vector data)) source)))
|
|
1082
|
+
(defun literal-wrap-subvector (data)
|
|
1083
|
+
(let ((cached (js-call literal-wrappers :get data)))
|
|
1084
|
+
(if (not (undefined? cached)) cached
|
|
1085
|
+
(let ((value (new PersistentSubVector (literal-wrap 2 (managed-vector-view-state-vector data))
|
|
1086
|
+
(managed-vector-view-state-start data) (managed-vector-view-state-end data) (managed-vector-view-state-meta data))))
|
|
1087
|
+
(js-call literal-subvector-sources :set data (literal-subvector-source data))
|
|
1088
|
+
(literal-register value 8 data)))))
|
|
1089
|
+
(defun literal-subvector-data (value)
|
|
1090
|
+
(let ((record (literal-record value)))
|
|
1091
|
+
(if (or (undefined? record) (/= (get record :type) 8)) (literal-fail "incompatible persistent subvector receiver")
|
|
1092
|
+
(get record :data))))
|
|
1093
|
+
(defun literal-subvec (vector start &optional end)
|
|
1094
|
+
(unless (or (= (literal-type vector) 2) (= (literal-type vector) 8))
|
|
1095
|
+
(literal-fail "subvec expects a persistent vector"))
|
|
1096
|
+
(let* ((data (if (= (literal-type vector) 8) (literal-subvector-data vector) (literal-data vector 2)))
|
|
1097
|
+
(next (managed-vector-view-state-subvec data start end)))
|
|
1098
|
+
(if (nil? next)
|
|
1099
|
+
(literal-range (str "subvec range [" (funcall globalThis/String start) ", "
|
|
1100
|
+
(funcall globalThis/String (if (nullish? end) (get vector :count) end)) ") is outside [0, " (get vector :count) "]"))
|
|
1101
|
+
(progn
|
|
1102
|
+
(js-call literal-subvector-sources :set next
|
|
1103
|
+
(if (= (literal-type vector) 8) (literal-subvector-source data) vector))
|
|
1104
|
+
(literal-wrap-subvector next)))))
|
|
1105
|
+
(defun literal-subvector-count () (managed-vector-view-state-count (literal-subvector-data (js* "this"))))
|
|
1106
|
+
(defun literal-subvector-size () (get (js* "this") :count))
|
|
1107
|
+
(defun literal-subvector-nth (index &rest not-found)
|
|
1108
|
+
(let* ((data (literal-subvector-data (js* "this")))
|
|
1109
|
+
(fallback (if (or (= (js-length not-found) 0) (undefined? (get not-found 0))) literal-missing (get not-found 0)))
|
|
1110
|
+
(value (if (and (Number/isInteger index) (>= index 0) (< index (managed-vector-view-state-count data)))
|
|
1111
|
+
(js-call (literal-subvector-source data) :nth (+ (managed-vector-view-state-start data) index)) fallback)))
|
|
1112
|
+
(if (eq value literal-missing)
|
|
1113
|
+
(literal-range (str "subvec nth index " (funcall globalThis/String index) " is outside [0, "
|
|
1114
|
+
(managed-vector-view-state-count data) ")")) value)))
|
|
1115
|
+
(defun literal-subvector-assoc (index value)
|
|
1116
|
+
(let* ((data (literal-subvector-data (js* "this"))) (count (managed-vector-view-state-count data)))
|
|
1117
|
+
(unless (and (Number/isInteger index) (>= index 0) (<= index count))
|
|
1118
|
+
(literal-range (str "subvec assoc index " (funcall globalThis/String index) " is outside [0, " count "]")))
|
|
1119
|
+
(let* ((source (literal-subvector-source data)) (absolute (+ (managed-vector-view-state-start data) index))
|
|
1120
|
+
(vector (if (= absolute (get source :count)) (js-call source :conj value) (js-call source :assoc absolute value)))
|
|
1121
|
+
(next (managed-vector-view-state-make (literal-data vector 2)
|
|
1122
|
+
(managed-vector-view-state-start data) (if (> (1+ absolute) (managed-vector-view-state-end data))
|
|
1123
|
+
(1+ absolute) (managed-vector-view-state-end data)) (managed-vector-view-state-meta data))))
|
|
1124
|
+
(js-call literal-subvector-sources :set next vector) (literal-wrap-subvector next))))
|
|
1125
|
+
(defun literal-subvector-conj (value) (js-call (js* "this") :assoc (get (js* "this") :count) value))
|
|
1126
|
+
(defun literal-subvector-peek (&optional not-found)
|
|
1127
|
+
(let ((data (literal-subvector-data (js* "this"))))
|
|
1128
|
+
(if (= (managed-vector-view-state-count data) 0) not-found
|
|
1129
|
+
(js-call (literal-subvector-source data) :nth (1- (managed-vector-view-state-end data))))))
|
|
1130
|
+
(defun literal-subvector-pop ()
|
|
1131
|
+
(let* ((data (literal-subvector-data (js* "this"))) (next (managed-vector-view-state-pop data)))
|
|
1132
|
+
(if (nil? next) (literal-range "cannot pop an empty persistent subvector")
|
|
1133
|
+
(if (managed-vector-view-state? next)
|
|
1134
|
+
(progn (js-call literal-subvector-sources :set next (literal-subvector-source data)) (literal-wrap-subvector next))
|
|
1135
|
+
(literal-wrap 2 next)))))
|
|
1136
|
+
(defun literal-subvector-reduce (reducer &rest initial)
|
|
1137
|
+
(unless (= (value-type reducer) "function") (literal-fail "persistent subvector reducer must be a function"))
|
|
1138
|
+
(let* ((data (literal-subvector-data (js* "this"))) (index 0) (count (managed-vector-view-state-count data)) (result nil))
|
|
1139
|
+
(if (> (js-length initial) 0) (setq result (get initial 0))
|
|
1140
|
+
(if (= count 0) (literal-fail "cannot reduce an empty persistent subvector without an initial value")
|
|
1141
|
+
(setq result (js-call (literal-subvector-source data) :nth (managed-vector-view-state-start data)) index 1)))
|
|
1142
|
+
(while (< index count)
|
|
1143
|
+
(setq result (funcall reducer result
|
|
1144
|
+
(js-call (literal-subvector-source data) :nth (+ (managed-vector-view-state-start data) index)) index) index (1+ index))) result))
|
|
1145
|
+
(defun literal-subvector-iterate ()
|
|
1146
|
+
(literal-new-iterator 8 (literal-subvector-data (js* "this")) 0))
|
|
1147
|
+
(defun literal-subvector-tag () "EliscriptPersistentSubVector")
|
|
1148
|
+
(defun literal-transient-key (type)
|
|
1149
|
+
(cond ((= type 2) literal-transient-vector-state) ((= type 3) literal-transient-map-state) (t literal-transient-set-state)))
|
|
1150
|
+
(defun literal-transient-type (value)
|
|
1151
|
+
(let ((record (js-call literal-transient-records :get value)))
|
|
1152
|
+
(if (undefined? record) 0 (get record :type))))
|
|
1153
|
+
(defun literal-transient-record (value)
|
|
1154
|
+
(let ((record (js-call literal-transient-records :get value)))
|
|
1155
|
+
(if (undefined? record) (literal-fail "incompatible transient collection receiver") record)))
|
|
1156
|
+
(defun literal-transient-json-error ()
|
|
1157
|
+
(let ((type (literal-transient-type (js* "this"))))
|
|
1158
|
+
(literal-fail (cond ((= type 2) "transient vectors cannot be serialized")
|
|
1159
|
+
((= type 3) "transient hash maps cannot be serialized") (t "transient hash sets cannot be serialized")))))
|
|
1160
|
+
(defun literal-transient-vector-json-error () (literal-fail "transient vectors cannot be serialized"))
|
|
1161
|
+
(defun literal-transient-map-json-error () (literal-fail "transient hash maps cannot be serialized"))
|
|
1162
|
+
(defun literal-transient-set-json-error () (literal-fail "transient hash sets cannot be serialized"))
|
|
1163
|
+
(defun literal-transient-vector-tag () "EliscriptTransientVector")
|
|
1164
|
+
(defun literal-transient-map-tag () "EliscriptTransientHashMap")
|
|
1165
|
+
(defun literal-transient-set-tag () "EliscriptTransientHashSet")
|
|
1166
|
+
(defun literal-transient-refresh (receiver)
|
|
1167
|
+
(let* ((record (literal-transient-record receiver)) (type (get record :type))
|
|
1168
|
+
(state (get record :state)) (view (aref receiver (literal-transient-key type))))
|
|
1169
|
+
(put view :active (get state :active))
|
|
1170
|
+
(if (= type 4)
|
|
1171
|
+
(progn
|
|
1172
|
+
(put view :metadata (get state :metadata))
|
|
1173
|
+
(literal-transient-refresh (get view :map)))
|
|
1174
|
+
(progn
|
|
1175
|
+
(put view :changed (get state :changed)) (put view :owner (get state :owner))
|
|
1176
|
+
(put view :count (get state :count)) (put view :metadata (get state :metadata))
|
|
1177
|
+
(if (= type 2)
|
|
1178
|
+
(progn
|
|
1179
|
+
(put view :shift (get state :shift)) (put view :tailOwned (get state :tailOwned))
|
|
1180
|
+
(put view :root (literal-vector-node-view (get state :root) (get state :shift)))
|
|
1181
|
+
(put view :tail (get state :tail)))
|
|
1182
|
+
(put view :root (literal-map-root-view (get state :root)))))) receiver))
|
|
1183
|
+
(defun literal-transient-build (receiver type source state)
|
|
1184
|
+
(setq literal-has-transients t)
|
|
1185
|
+
(literal-initialize-transient-prototype type)
|
|
1186
|
+
(let ((view (if (= type 4)
|
|
1187
|
+
(js-object :active t :source source :sourceMap (get (aref source literal-set-state) :map)
|
|
1188
|
+
:map (literal-transient-map-from-state (get (aref source literal-set-state) :map) (get state :map))
|
|
1189
|
+
:metadata (get state :metadata))
|
|
1190
|
+
(if (= type 2)
|
|
1191
|
+
(js-object :active t :changed false :owner (get state :owner) :source source :count (get state :count)
|
|
1192
|
+
:shift (get state :shift) :root (get (aref source literal-vector-state) :root)
|
|
1193
|
+
:tail (get state :tail) :tailOwned false :metadata (get state :metadata))
|
|
1194
|
+
(js-object :active t :changed false :owner (get state :owner) :source source :count (get state :count)
|
|
1195
|
+
:root (get (aref source literal-map-state) :root) :metadata (get state :metadata))))))
|
|
1196
|
+
(literal-own-data receiver (literal-transient-key type) view)
|
|
1197
|
+
(js-call literal-transient-records :set receiver (js-object :type type :state state :source source))
|
|
1198
|
+
(Object/defineProperty receiver "__eliscript_transient__"
|
|
1199
|
+
(js-object :get (literal-make-method
|
|
1200
|
+
(cond ((= type 2) literal-transient-vector-json-error) ((= type 3) literal-transient-map-json-error)
|
|
1201
|
+
(t literal-transient-set-json-error)) "get __eliscript_transient__") :enumerable t))
|
|
1202
|
+
(Object/freeze receiver)))
|
|
1203
|
+
(defun TransientVector (token vector)
|
|
1204
|
+
(unless (and (eq token literal-token) (or (= (literal-type vector) 2) (= (literal-type vector) 8)))
|
|
1205
|
+
(literal-fail "transient vectors must be created from a persistent vector"))
|
|
1206
|
+
(let ((source (if (= (literal-type vector) 8)
|
|
1207
|
+
(literal-with-meta (apply literal-vector (literal-to-array vector)) (literal-meta vector)) vector)))
|
|
1208
|
+
(literal-transient-build (js* "this") 2 source (managed-transient-vector-new (literal-data source 2)))))
|
|
1209
|
+
(defun TransientHashMap (token map)
|
|
1210
|
+
(unless (and (eq token literal-token) (= (literal-type map) 3))
|
|
1211
|
+
(literal-fail "transient hash maps must be created from a persistent hash map"))
|
|
1212
|
+
(literal-transient-build (js* "this") 3 map (managed-transient-map-new (literal-data map 3))))
|
|
1213
|
+
(defun TransientHashSet (token set)
|
|
1214
|
+
(unless (and (eq token literal-token) (= (literal-type set) 4))
|
|
1215
|
+
(literal-fail "transient hash sets must be created from a persistent hash set"))
|
|
1216
|
+
(literal-transient-build (js* "this") 4 set (managed-transient-set-new (literal-data set 4))))
|
|
1217
|
+
(defun literal-transient-map-from-state (source state)
|
|
1218
|
+
(let ((receiver (Object/create (get TransientHashMap :prototype))))
|
|
1219
|
+
(literal-transient-build receiver 3 source state)))
|
|
1220
|
+
(defun literal-transient (receiver)
|
|
1221
|
+
(let ((type (literal-type receiver)))
|
|
1222
|
+
(cond ((= type 2) (new TransientVector literal-token receiver))
|
|
1223
|
+
((= type 8) (let ((out (literal-with-meta (literal-vector-empty) (literal-meta receiver))))
|
|
1224
|
+
(literal-each receiver (lambda (item) (setq out (literal-conj out item))))
|
|
1225
|
+
(new TransientVector literal-token out)))
|
|
1226
|
+
((= type 3) (new TransientHashMap literal-token receiver))
|
|
1227
|
+
((= type 4) (new TransientHashSet literal-token receiver))
|
|
1228
|
+
(t (literal-fail "collection is not editable")))))
|
|
1229
|
+
(defun literal-transient-conj (receiver value)
|
|
1230
|
+
;; Map entry evaluation occurs before the active-state check.
|
|
1231
|
+
(let ((record (literal-transient-record receiver)))
|
|
1232
|
+
(if (= (get record :type) 3)
|
|
1233
|
+
(let ((entry (literal-entry value))) (literal-transient-assoc receiver (get entry 0) (get entry 1)))
|
|
1234
|
+
(progn
|
|
1235
|
+
(try
|
|
1236
|
+
(if (= (get record :type) 2) (managed-transient-vector-conj (get record :state) value)
|
|
1237
|
+
(managed-transient-set-conj (get record :state) value))
|
|
1238
|
+
(finally (literal-transient-refresh receiver))) receiver))))
|
|
1239
|
+
(defun literal-transient-assoc (receiver key value)
|
|
1240
|
+
(let* ((record (literal-transient-record receiver)) (type (get record :type)))
|
|
1241
|
+
(try
|
|
1242
|
+
(cond ((= type 2) (managed-transient-vector-assoc (get record :state) key value))
|
|
1243
|
+
((= type 3) (managed-transient-map-assoc (get record :state) key value))
|
|
1244
|
+
(t (literal-fail "transient collection does not support assoc!")))
|
|
1245
|
+
(finally (literal-transient-refresh receiver))) receiver))
|
|
1246
|
+
(defun literal-transient-dissoc (receiver key)
|
|
1247
|
+
(let* ((record (literal-transient-record receiver)) (type (get record :type)))
|
|
1248
|
+
(try
|
|
1249
|
+
(cond ((= type 3) (managed-transient-map-dissoc (get record :state) key))
|
|
1250
|
+
((= type 4) (managed-transient-set-disj (get record :state) key))
|
|
1251
|
+
(t (literal-fail "transient collection does not support dissoc!")))
|
|
1252
|
+
(finally (literal-transient-refresh receiver))) receiver))
|
|
1253
|
+
(defun literal-transient-persistent (receiver)
|
|
1254
|
+
(let* ((record (literal-transient-record receiver)) (type (get record :type)) (state (get record :state)) (data nil))
|
|
1255
|
+
(try
|
|
1256
|
+
(setq data (cond ((= type 2) (managed-transient-vector-persistent state))
|
|
1257
|
+
((= type 3) (managed-transient-map-persistent state)) (t (managed-transient-set-persistent state))))
|
|
1258
|
+
(finally (literal-transient-refresh receiver)))
|
|
1259
|
+
(let ((source (get record :source)))
|
|
1260
|
+
(if (eq data (literal-data source type)) source
|
|
1261
|
+
(progn (js-call literal-editable-results :add data) (literal-wrap type data))))))
|
|
1262
|
+
(defun literal-initialize-transient-prototype (type)
|
|
1263
|
+
(let ((key (+ type 10)))
|
|
1264
|
+
(unless (Object/hasOwn literal-prototypes-ready key)
|
|
1265
|
+
(let* ((constructor (cond ((= type 2) TransientVector) ((= type 3) TransientHashMap) (t TransientHashSet)))
|
|
1266
|
+
(prototype (get constructor :prototype)) (constructors (js-object)))
|
|
1267
|
+
(Object/defineProperty constructor "prototype" (js-object :writable false))
|
|
1268
|
+
(literal-install-method prototype "toJSON" "toJSON" 0
|
|
1269
|
+
(cond ((= type 2) literal-transient-vector-json-error) ((= type 3) literal-transient-map-json-error)
|
|
1270
|
+
(t literal-transient-set-json-error)))
|
|
1271
|
+
(literal-install-getter prototype (get globalThis/Symbol :toStringTag) "get [Symbol.toStringTag]"
|
|
1272
|
+
(cond ((= type 2) literal-transient-vector-tag) ((= type 3) literal-transient-map-tag) (t literal-transient-set-tag)))
|
|
1273
|
+
(put constructors (cond ((= type 2) "transientVector") ((= type 3) "transientMap") (t "transientSet")) constructor)
|
|
1274
|
+
(setq literal-protocol-runtime (managed-literal-register-protocols constructors (literal-protocol-callbacks)))
|
|
1275
|
+
(put literal-prototypes-ready key t)))))
|
|
1276
|
+
(defun literal-initialize-subvector-prototype ()
|
|
1277
|
+
(unless (Object/hasOwn literal-prototypes-ready 8)
|
|
1278
|
+
(literal-initialize-prototype 2)
|
|
1279
|
+
(let ((prototype (get PersistentSubVector :prototype)))
|
|
1280
|
+
(Object/setPrototypeOf prototype (get PersistentVector :prototype))
|
|
1281
|
+
(Object/setPrototypeOf PersistentSubVector PersistentVector)
|
|
1282
|
+
(Object/defineProperty PersistentSubVector "prototype" (js-object :writable false))
|
|
1283
|
+
(literal-install-getter prototype "count" "get count" literal-subvector-count)
|
|
1284
|
+
(literal-install-getter prototype "size" "get size" literal-subvector-size)
|
|
1285
|
+
(literal-install-getter prototype (get globalThis/Symbol :toStringTag) "get [Symbol.toStringTag]" literal-subvector-tag)
|
|
1286
|
+
(literal-install-method prototype "nth" "nth" 1 literal-subvector-nth)
|
|
1287
|
+
(literal-install-method prototype "assoc" "assoc" 2 literal-subvector-assoc)
|
|
1288
|
+
(literal-install-method prototype "conj" "conj" 1 literal-subvector-conj)
|
|
1289
|
+
(literal-install-method prototype "peek" "peek" 0 literal-subvector-peek)
|
|
1290
|
+
(literal-install-method prototype "pop" "pop" 0 literal-subvector-pop)
|
|
1291
|
+
(literal-install-method prototype "reduce" "reduce" 1 literal-subvector-reduce)
|
|
1292
|
+
(literal-install-method prototype (get globalThis/Symbol :iterator) "[Symbol.iterator]" 0 literal-subvector-iterate)
|
|
1293
|
+
(literal-register-protocol-type 8 PersistentSubVector)
|
|
1294
|
+
(put literal-prototypes-ready 8 t))))
|
|
1295
|
+
|
|
1296
|
+
(defun literal-initialize-prototype (type)
|
|
1297
|
+
(unless (Object/hasOwn literal-prototypes-ready type)
|
|
1298
|
+
(let* ((constructor (cond ((= type 1) PersistentList) ((= type 2) PersistentVector) ((= type 3) PersistentHashMap)
|
|
1299
|
+
((= type 4) PersistentHashSet) ((= type 5) PersistentQueue) ((= type 6) Keyword) (t EliscriptSymbol)))
|
|
1300
|
+
(prototype (literal-prototype type)))
|
|
1301
|
+
(Object/defineProperty constructor "prototype" (js-object :writable false))
|
|
1302
|
+
(literal-install-getter prototype (get globalThis/Symbol :toStringTag) "get [Symbol.toStringTag]"
|
|
1303
|
+
(cond ((= type 1) literal-list-tag) ((= type 2) literal-vector-tag) ((= type 3) literal-map-tag)
|
|
1304
|
+
((= type 4) literal-set-tag) ((= type 5) literal-queue-tag) ((= type 6) literal-keyword-tag) (t literal-symbol-tag)))
|
|
1305
|
+
(if (<= type 5)
|
|
1306
|
+
(progn
|
|
1307
|
+
(let ((counter (cond ((= type 1) literal-list-count-method) ((= type 2) literal-vector-count-method)
|
|
1308
|
+
((= type 3) literal-map-count-method) ((= type 4) literal-set-count-method) (t literal-queue-count-method))))
|
|
1309
|
+
(literal-install-getter prototype "count" "get count" counter)
|
|
1310
|
+
(literal-install-getter prototype "size" "get size" counter))
|
|
1311
|
+
(when (or (= type 1) (= type 5)) (literal-install-getter prototype "isEmpty" "get isEmpty" literal-empty-method))
|
|
1312
|
+
(literal-install-method constructor "empty" "empty" 0
|
|
1313
|
+
(cond ((= type 1) literal-list-empty) ((= type 2) literal-vector-empty) ((= type 3) literal-map-empty)
|
|
1314
|
+
((= type 4) literal-set-empty) (t literal-queue-empty)))
|
|
1315
|
+
(literal-install-method constructor "from" "from" 1
|
|
1316
|
+
(cond ((= type 1) literal-list-from) ((= type 2) literal-vector-from) ((= type 3) literal-map-from)
|
|
1317
|
+
((= type 4) literal-set-from) (t literal-queue-from)))
|
|
1318
|
+
(literal-install-method prototype "conj" "conj" 1
|
|
1319
|
+
(cond ((= type 1) literal-list-conj-method) ((= type 2) literal-vector-conj-method) ((= type 3) literal-map-conj-method)
|
|
1320
|
+
((= type 4) literal-set-conj-method) (t literal-queue-conj-method)))
|
|
1321
|
+
(literal-install-method prototype "reduce" "reduce" (if (or (= type 3) (= type 4)) 2 1)
|
|
1322
|
+
(cond ((= type 3) literal-map-reduce-method) ((= type 4) literal-set-reduce-method) (t literal-sequence-reduce-method)))
|
|
1323
|
+
(literal-install-method prototype (get globalThis/Symbol :iterator) "[Symbol.iterator]" 0
|
|
1324
|
+
(cond ((= type 1) literal-list-iterate-method) ((= type 2) literal-vector-iterate-method)
|
|
1325
|
+
((= type 3) literal-map-iterate-method) ((= type 4) literal-set-iterate-method) (t literal-queue-iterate-method)))
|
|
1326
|
+
(when (or (= type 1) (= type 2) (= type 5))
|
|
1327
|
+
(literal-install-method prototype "peek" "peek" 0 (if (= type 1) literal-list-peek-method (if (= type 2) literal-vector-peek-method literal-queue-peek-method)))
|
|
1328
|
+
(literal-install-method prototype "pop" "pop" 0 (if (= type 1) literal-list-pop-method (if (= type 2) literal-vector-pop-method literal-queue-pop-method)))
|
|
1329
|
+
(literal-install-method prototype "toArray" "toArray" 0 (if (= type 1) literal-list-array-method (if (= type 2) literal-vector-array-method literal-queue-array-method))))
|
|
1330
|
+
(when (or (= type 1) (= type 2))
|
|
1331
|
+
(literal-install-method prototype "nth" "nth" 1 (if (= type 1) literal-list-nth-method literal-vector-nth-method)))
|
|
1332
|
+
(when (= type 1)
|
|
1333
|
+
(literal-install-method prototype "first" "first" 0 literal-list-first-method)
|
|
1334
|
+
(literal-install-method prototype "rest" "rest" 0 literal-list-rest-method)
|
|
1335
|
+
(literal-install-method prototype "cons" "cons" 1 literal-list-conj-method))
|
|
1336
|
+
(when (or (= type 2) (= type 3))
|
|
1337
|
+
(literal-install-method prototype "assoc" "assoc" 2 (if (= type 2) literal-vector-assoc-method literal-map-assoc-method)))
|
|
1338
|
+
(when (or (= type 3) (= type 4))
|
|
1339
|
+
(literal-install-method prototype "has" "has" 1 (if (= type 3) literal-map-has-method literal-set-has-method))
|
|
1340
|
+
(literal-install-method prototype "entries" "entries" 0 (if (= type 3) literal-map-iterate-method literal-set-entries-method))
|
|
1341
|
+
(literal-install-method prototype "keys" "keys" 0 (if (= type 3) literal-map-keys-method literal-set-iterate-method))
|
|
1342
|
+
(literal-install-method prototype "values" "values" 0 (if (= type 3) literal-map-values-method literal-set-iterate-method)))
|
|
1343
|
+
(when (= type 3)
|
|
1344
|
+
(literal-install-method prototype "get" "get" 1 literal-map-get-method)
|
|
1345
|
+
(literal-install-method prototype "dissoc" "dissoc" 1 literal-dissoc-method)
|
|
1346
|
+
(literal-install-method prototype "toMap" "toMap" 0 literal-to-map-method))
|
|
1347
|
+
(when (= type 4)
|
|
1348
|
+
(literal-install-method prototype "disj" "disj" 1 literal-disj-method)
|
|
1349
|
+
(literal-install-method prototype "toSet" "toSet" 0 literal-to-set-method)
|
|
1350
|
+
(literal-install-method prototype "union" "union" 0 literal-set-union-method)
|
|
1351
|
+
(literal-install-method prototype "intersection" "intersection" 0 literal-set-intersection-method)
|
|
1352
|
+
(literal-install-method prototype "difference" "difference" 0 literal-set-difference-method)
|
|
1353
|
+
(literal-install-method prototype "isSubsetOf" "isSubsetOf" 1 literal-set-subset-method)
|
|
1354
|
+
(literal-install-method prototype "isSupersetOf" "isSupersetOf" 1 literal-set-superset-method)
|
|
1355
|
+
(literal-install-method prototype "isDisjointFrom" "isDisjointFrom" 1 literal-set-disjoint-method)))
|
|
1356
|
+
(progn
|
|
1357
|
+
(literal-install-getter prototype "name" "get name" literal-name-method)
|
|
1358
|
+
(literal-install-getter prototype "namespace" "get namespace" literal-namespace-method)
|
|
1359
|
+
(literal-install-getter prototype "qualifiedName" "get qualifiedName" literal-qualified-name-method)
|
|
1360
|
+
(literal-install-method prototype "toString" "toString" 0 literal-identifier-string-method)
|
|
1361
|
+
(literal-install-method prototype "toJSON" "toJSON" 0 literal-identifier-json-method)))
|
|
1362
|
+
(literal-register-protocol-type type constructor)
|
|
1363
|
+
(put literal-prototypes-ready type t))))
|
|
1364
|
+
(defun literal-ensure-type (type)
|
|
1365
|
+
(cond ((= type 8) (literal-initialize-subvector-prototype))
|
|
1366
|
+
((and (>= type 1) (<= type 7)) (literal-initialize-prototype type))
|
|
1367
|
+
(t (literal-fail "unknown persistent value type")))
|
|
1368
|
+
(cond ((= type 8) PersistentSubVector) (t (get (literal-prototype type) :constructor))))
|
|
1369
|
+
(defun literal-kind (value)
|
|
1370
|
+
(let ((type (literal-type value)))
|
|
1371
|
+
(cond ((= type 1) "list") ((= type 2) "vector") ((= type 3) "map") ((= type 4) "set")
|
|
1372
|
+
((= type 5) "queue") ((= type 6) "keyword") ((= type 7) "symbol") ((= type 8) "subvector")
|
|
1373
|
+
((funcall (get (literal-protocols) :isReduced) value) "reduced")
|
|
1374
|
+
(t (literal-transport-kind value)))))
|
|
1375
|
+
(defun literal-register-transport (kind predicate exporter importer)
|
|
1376
|
+
(unless (and (= (js* "typeof kind") "string") (> (js-length kind) 0)
|
|
1377
|
+
(= (js* "typeof predicate") "function") (= (js* "typeof exporter") "function")
|
|
1378
|
+
(= (js* "typeof importer") "function")) (literal-fail "persistent transport requires a kind and callable adapters"))
|
|
1379
|
+
(when (or (js-call literal-transports :has kind)
|
|
1380
|
+
(js-call (js-array "list" "vector" "map" "set" "queue" "keyword" "symbol" "subvector" "reduced") :includes kind))
|
|
1381
|
+
(literal-fail "persistent transport kind is already registered"))
|
|
1382
|
+
(js-call literal-transports :set kind (Object/freeze (js-object :predicate predicate :exporter exporter :importer importer)))
|
|
1383
|
+
undefined)
|
|
1384
|
+
(defun literal-transport-kind (value)
|
|
1385
|
+
(let ((found nil))
|
|
1386
|
+
(literal-while-each literal-transports (lambda (entry)
|
|
1387
|
+
(let ((matches (funcall (get (get entry 1) :predicate) value)))
|
|
1388
|
+
(if (js* "!!matches") (progn (setq found (get entry 0)) false) t)))) found))
|
|
1389
|
+
(defun literal-export-transport (kind value)
|
|
1390
|
+
(let ((adapter (js-call literal-transports :get kind)))
|
|
1391
|
+
(if (undefined? adapter) (literal-fail "unknown persistent transport kind")
|
|
1392
|
+
(funcall (get adapter :exporter) value))))
|
|
1393
|
+
(defun literal-import-transport (kind record)
|
|
1394
|
+
(let ((adapter (js-call literal-transports :get kind)))
|
|
1395
|
+
(if (undefined? adapter) (literal-fail "unknown persistent value kind")
|
|
1396
|
+
(funcall (get adapter :importer) record))))
|
|
1397
|
+
(defun literal-export-value (value)
|
|
1398
|
+
(let ((kind (literal-kind value)))
|
|
1399
|
+
(if (nil? kind) nil
|
|
1400
|
+
(if (js-call literal-transports :has kind) (literal-export-transport kind value)
|
|
1401
|
+
(if (= kind "reduced")
|
|
1402
|
+
(js-object :kind kind :value (funcall (get (literal-protocols) :unreduced) value))
|
|
1403
|
+
(if (= kind "subvector")
|
|
1404
|
+
(let ((data (literal-subvector-data value)))
|
|
1405
|
+
(js-object :kind kind :source (literal-subvector-source data)
|
|
1406
|
+
:start (managed-vector-view-state-start data) :end (managed-vector-view-state-end data)
|
|
1407
|
+
:metadata (managed-vector-view-state-meta data)))
|
|
1408
|
+
(if (or (= kind "keyword") (= kind "symbol"))
|
|
1409
|
+
(let ((data (get (literal-record value) :data)))
|
|
1410
|
+
(js-object :kind kind :namespace (get data :namespace) :name (get data :name)
|
|
1411
|
+
:metadata (literal-meta value)))
|
|
1412
|
+
(let ((values (literal-to-array value)))
|
|
1413
|
+
(when (= kind "map")
|
|
1414
|
+
(let ((flat (js-array)) (index 0))
|
|
1415
|
+
(while (< index (js-length values))
|
|
1416
|
+
(let ((entry (get values index))) (js-call flat :push (get entry 0) (get entry 1)))
|
|
1417
|
+
(setq index (1+ index))) (setq values flat)))
|
|
1418
|
+
(js-object :kind kind :values values :metadata (literal-meta value))))))))))
|
|
1419
|
+
(defun literal-import-value (record)
|
|
1420
|
+
(let* ((kind (get record :kind)) (values (get record :values))
|
|
1421
|
+
(value (cond ((= kind "list") (progn (literal-initialize-prototype 1) (js-call PersistentList :from values)))
|
|
1422
|
+
((= kind "vector") (progn (literal-initialize-prototype 2) (literal-vector-from-array-values values)))
|
|
1423
|
+
((= kind "map")
|
|
1424
|
+
(let ((entries (js-array)) (index 0) (pair 0))
|
|
1425
|
+
(while (< index (js-length values))
|
|
1426
|
+
(put entries pair (js-array (get values index) (get values (1+ index))))
|
|
1427
|
+
(setq index (+ index 2) pair (1+ pair)))
|
|
1428
|
+
(literal-initialize-prototype 3) (js-call PersistentHashMap :from entries)))
|
|
1429
|
+
((= kind "set") (progn (literal-initialize-prototype 4) (js-call PersistentHashSet :from values)))
|
|
1430
|
+
((= kind "queue") (progn (literal-initialize-prototype 5) (js-call PersistentQueue :from values)))
|
|
1431
|
+
((= kind "reduced") (funcall (get (literal-protocols) :reduced) (get record :value)))
|
|
1432
|
+
((= kind "subvector") (literal-subvec (get record :source) (get record :start) (get record :end)))
|
|
1433
|
+
((= kind "keyword") (literal-keyword (get record :namespace) (get record :name)))
|
|
1434
|
+
((= kind "symbol") (literal-symbol (get record :namespace) (get record :name)))
|
|
1435
|
+
(t (literal-import-transport kind record))))
|
|
1436
|
+
(metadata (get record :metadata nil)))
|
|
1437
|
+
(if (or (= kind "keyword") (= kind "reduced") (js-call literal-transports :has kind) (nil? metadata))
|
|
1438
|
+
value (literal-with-meta value metadata))))
|
|
1439
|
+
(literal-register-transport "protocol" protocol?
|
|
1440
|
+
(lambda (protocol)
|
|
1441
|
+
(let* ((definition (protocol-definition protocol)) (operations (get protocol :operations))
|
|
1442
|
+
(names (get definition :operations)) (slots (js-array)) (index 0))
|
|
1443
|
+
(while (< index (js-length names))
|
|
1444
|
+
(js-call slots :push (get (get operations (get names index)) :slot))
|
|
1445
|
+
(setq index (1+ index)))
|
|
1446
|
+
(js-object :kind "protocol" :definition definition :slots slots :operations operations
|
|
1447
|
+
:role (managed-literal-protocol-role protocol))))
|
|
1448
|
+
(lambda (record)
|
|
1449
|
+
(materialize-protocol-from-definition (get record :definition) (get record :slots))))
|
|
1450
|
+
(literal-register-transport "protocol-operations"
|
|
1451
|
+
(lambda (value) (not (undefined? (read-protocol-operations-owner value))))
|
|
1452
|
+
(lambda (value) (js-object :kind "protocol-operations" :protocol (read-protocol-operations-owner value)))
|
|
1453
|
+
(lambda (record) (get (get record :protocol) :operations)))
|
|
1454
|
+
(literal-register-transport "protocol-method"
|
|
1455
|
+
(lambda (value) (not (undefined? (read-protocol-method-owner value))))
|
|
1456
|
+
(lambda (value) (let ((owner (read-protocol-method-owner value)))
|
|
1457
|
+
(js-object :kind "protocol-method" :protocol (get owner :protocol) :operation (get owner :operation))))
|
|
1458
|
+
(lambda (record) (get (get (get record :protocol) :operations) (get record :operation))))
|
|
1459
|
+
(defun literal-protocol-for-role (role) (managed-literal-protocol-for-role role))
|
|
1460
|
+
(export literal-list literal-vector literal-vector-from-array-values literal-map literal-set literal-queue literal-keyword literal-symbol literal-binding-lookup
|
|
1461
|
+
literal-count literal-nth literal-get literal-first literal-rest literal-cons literal-equal literal-hash
|
|
1462
|
+
literal-mix literal-finish literal-string-hash literal-entry literal-each
|
|
1463
|
+
literal-conj literal-assoc literal-dissoc literal-disj literal-peek literal-pop literal-meta literal-with-meta
|
|
1464
|
+
literal-to-array literal-type literal-kind literal-export-value literal-import-value literal-subvec literal-protocols
|
|
1465
|
+
literal-protocol-runtime-get literal-ensure-type literal-instance? literal-transient literal-transient-type literal-transient-conj
|
|
1466
|
+
literal-register-transport literal-protocol-for-role
|
|
1467
|
+
literal-transient-assoc literal-transient-dissoc literal-transient-persistent
|
|
1468
|
+
PersistentList PersistentVector PersistentHashMap PersistentHashSet PersistentQueue PersistentSubVector
|
|
1469
|
+
TransientVector TransientHashMap TransientHashSet Keyword EliscriptSymbol))
|