eliscript 0.1.3 → 0.1.4
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/COPYING.RUNTIME +93 -0
- package/README.md +15 -3
- package/bin/eliscript-test +29 -0
- package/bootstrap/backends/README.md +5 -4
- package/bootstrap/backends/binary.eli +89 -22
- package/bootstrap/backends/capabilities.eli +9 -4
- package/bootstrap/backends/managed-layout.eli +93 -81
- package/bootstrap/backends/managed.eli +651 -125
- package/bootstrap/backends/native.eli +1791 -324
- package/bootstrap/backends/numeric.eli +71 -7
- package/bootstrap/backends/sha256.eli +165 -68
- package/bootstrap/backends/wasm.eli +461 -52
- package/bootstrap/compiler/analyzer.eli +692 -2
- package/bootstrap/compiler/compiler.eli +16 -3
- package/bootstrap/compiler/emitter.eli +80 -35
- package/bootstrap/compiler/project.eli +175 -1
- package/bootstrap/compiler/transient-analysis.eli +2 -2
- package/bootstrap/host/build.eli +1 -0
- package/bootstrap/host/build.mjs +1 -1
- package/bootstrap/host/build.mjs.map +1 -1
- package/bootstrap/host/bun.mjs +7 -9
- package/bootstrap/host/bun.mjs.map +1 -1
- package/bootstrap/host/check-cli-ground.eli +47 -5
- package/bootstrap/host/check-cli-ground.mjs +60 -19
- package/bootstrap/host/check-cli-ground.mjs.map +1 -1
- package/bootstrap/host/check-cli.mjs +41 -1
- package/bootstrap/host/check-cli.mjs.map +1 -1
- package/bootstrap/host/compiler-session.eli +136 -22
- package/bootstrap/host/eliscript-cli.mjs +1 -1
- package/bootstrap/host/eliscript-cli.mjs.map +1 -1
- package/bootstrap/host/evaluation-cli.eli +33 -1
- package/bootstrap/host/evaluation-cli.mjs +65 -28
- package/bootstrap/host/evaluation-cli.mjs.map +1 -1
- package/bootstrap/host/evaluation.eli +651 -42
- package/bootstrap/host/evaluation.mjs +884 -72
- package/bootstrap/host/evaluation.mjs.map +1 -1
- package/bootstrap/host/project-cli-ground.eli +6 -1
- package/bootstrap/host/project-cli-ground.mjs +33 -32
- package/bootstrap/host/project-cli-ground.mjs.map +1 -1
- package/bootstrap/host/project-cli.mjs +1 -1
- package/bootstrap/host/project-cli.mjs.map +1 -1
- package/bootstrap/host/project-ground.eli +266 -45
- package/bootstrap/host/project-ground.mjs +429 -159
- package/bootstrap/host/project-ground.mjs.map +1 -1
- package/bootstrap/host/project.mjs +30 -40
- package/bootstrap/host/project.mjs.map +1 -1
- package/bootstrap/host/test-cli.eli +379 -0
- package/bootstrap/host/test-cli.mjs +494 -0
- package/bootstrap/host/test-cli.mjs.map +1 -0
- package/browser/README.md +7 -0
- package/browser/host.mjs +21 -29
- package/browser/host.mjs.map +1 -1
- package/browser/worker.mjs +7 -9
- package/browser/worker.mjs.map +1 -1
- package/compiler/eliscript-analyzer.el +694 -0
- package/compiler/eliscript-cli.el +66 -22
- package/compiler/eliscript-emitter.el +67 -43
- package/compiler/eliscript-ir-emitter.el +71 -36
- package/compiler/eliscript-project.el +360 -80
- package/compiler/eliscript-transient-analysis.el +5 -5
- package/compiler/eliscript.el +6 -0
- package/dist/backends/binary.mjs +148 -26
- package/dist/backends/binary.mjs.map +1 -1
- package/dist/backends/capabilities.mjs +11 -4
- package/dist/backends/capabilities.mjs.map +1 -1
- package/dist/backends/elf.mjs +4 -4
- package/dist/backends/elf.mjs.map +1 -1
- package/dist/backends/managed-layout.mjs +53 -56
- package/dist/backends/managed-layout.mjs.map +1 -1
- package/dist/backends/managed.mjs +1116 -375
- package/dist/backends/managed.mjs.map +1 -1
- package/dist/backends/memory.mjs +24 -26
- package/dist/backends/memory.mjs.map +1 -1
- package/dist/backends/native.mjs +2529 -434
- package/dist/backends/native.mjs.map +1 -1
- package/dist/backends/numeric.mjs +140 -33
- package/dist/backends/numeric.mjs.map +1 -1
- package/dist/backends/optimize.mjs +2 -2
- package/dist/backends/optimize.mjs.map +1 -1
- package/dist/backends/regexp.mjs +33 -35
- package/dist/backends/regexp.mjs.map +1 -1
- package/dist/backends/sha256.mjs +159 -59
- package/dist/backends/sha256.mjs.map +1 -1
- package/dist/backends/wasm.mjs +609 -73
- package/dist/backends/wasm.mjs.map +1 -1
- package/dist/bootstrap/analyzer.mjs +1018 -2
- package/dist/bootstrap/analyzer.mjs.map +1 -1
- package/dist/bootstrap/compiler.mjs +30 -23
- package/dist/bootstrap/compiler.mjs.map +1 -1
- package/dist/bootstrap/emitter.mjs +206 -161
- package/dist/bootstrap/emitter.mjs.macro-origins.json +16 -16
- package/dist/bootstrap/emitter.mjs.map +1 -1
- package/dist/bootstrap/expander.mjs +27 -31
- package/dist/bootstrap/expander.mjs.map +1 -1
- package/dist/bootstrap/ir.mjs +22 -24
- package/dist/bootstrap/ir.mjs.map +1 -1
- package/dist/bootstrap/project.mjs +246 -1
- package/dist/bootstrap/project.mjs.map +1 -1
- package/dist/bootstrap/reader.mjs +2 -2
- package/dist/bootstrap/reader.mjs.map +1 -1
- package/dist/bootstrap/source-map.mjs +34 -48
- package/dist/bootstrap/source-map.mjs.map +1 -1
- package/dist/bootstrap/transient-analysis.mjs +2 -2
- package/dist/bootstrap/transient-analysis.mjs.map +1 -1
- package/dist/browser/compiler.js +106 -106
- package/dist/browser/host.mjs +21 -29
- package/dist/browser/loader.js +1 -1
- package/dist/browser/worker.mjs +95 -95
- package/dist/compiler-artifact.json +1 -1
- package/dist/host/compiler-session.mjs +405 -228
- package/dist/host/compiler-session.mjs.map +1 -1
- package/dist/host/compiler-tools.mjs +44 -46
- package/dist/host/compiler-tools.mjs.map +1 -1
- package/dist/literal-sources/runtime/core/array-map.eli +45 -0
- package/dist/literal-sources/runtime/core/collection-internals.eli +22 -2
- package/dist/literal-sources/runtime/core/collection.eli +282 -23
- package/dist/literal-sources/runtime/core/data-text.eli +196 -13
- package/dist/literal-sources/runtime/core/data.eli +1 -1
- package/dist/literal-sources/runtime/core/identifier.eli +1 -1
- package/dist/literal-sources/runtime/core/lazy-sequence.eli +822 -44
- package/dist/literal-sources/runtime/core/list.eli +1 -1
- package/dist/literal-sources/runtime/core/map.eli +1 -1
- package/dist/literal-sources/runtime/core/metadata-internals.eli +2 -2
- package/dist/literal-sources/runtime/core/metadata.eli +2 -2
- package/dist/literal-sources/{stdlib/core/object.eli → runtime/core/object-impl.eli} +6 -6
- package/dist/literal-sources/runtime/core/object.eli +1 -1
- package/dist/literal-sources/runtime/core/order.eli +3 -3
- package/dist/literal-sources/runtime/core/persistent-kind.eli +1 -1
- package/dist/literal-sources/{stdlib/core/protocol.eli → runtime/core/protocol-impl.eli} +2 -2
- package/dist/literal-sources/runtime/core/protocol.eli +5 -3
- package/dist/literal-sources/runtime/core/queue.eli +1 -1
- package/dist/literal-sources/runtime/core/record.eli +3 -3
- package/dist/literal-sources/runtime/core/regex.eli +2 -2
- package/dist/literal-sources/runtime/core/sequence.eli +1 -1
- package/dist/literal-sources/runtime/core/set-algebra.eli +1 -1
- package/dist/literal-sources/runtime/core/set.eli +1 -1
- package/dist/literal-sources/runtime/core/sorted.eli +4 -4
- package/dist/literal-sources/{stdlib/core/text.eli → runtime/core/text-impl.eli} +2 -2
- package/dist/literal-sources/runtime/core/text.eli +1 -1
- package/dist/literal-sources/runtime/core/transducer.eli +24 -2
- package/dist/literal-sources/runtime/core/transient.eli +7 -5
- package/dist/literal-sources/runtime/core/type.eli +1 -1
- package/dist/literal-sources/runtime/core/value-internals.eli +3 -3
- package/dist/literal-sources/runtime/core/value.eli +2 -2
- package/dist/literal-sources/runtime/core/vector.eli +5 -2
- package/dist/literal-sources/{stdlib → runtime/managed}/managed-literal-protocols.eli +100 -34
- package/dist/literal-sources/{stdlib → runtime/managed}/managed-literals.eli +406 -81
- package/{stdlib → dist/literal-sources/runtime/managed}/managed-queue-state.eli +1 -1
- package/{stdlib → dist/literal-sources/runtime/managed}/managed-sorted-state.eli +1 -1
- package/dist/literal-sources/runtime/managed/managed-transient-state.eli +1206 -0
- package/{stdlib → dist/literal-sources/runtime/managed}/managed-value-state.eli +30 -6
- package/dist/literal-sources/{stdlib → runtime/managed}/managed-vector-view-state.eli +1 -1
- package/dist/literal-sources/runtime/wire/http-rpc.eli +1 -1
- package/dist/literal-sources/runtime/wire/markdown.eli +1 -1
- package/dist/literal-sources/runtime/wire/schema.eli +1 -1
- package/dist/literal-sources/stdlib/bit.eli +89 -1
- package/dist/literal-sources/stdlib/data.eli +522 -0
- package/dist/literal-sources/stdlib/interop/object.eli +39 -0
- package/dist/literal-sources/stdlib/persistent-list.eli +60 -21
- package/dist/literal-sources/stdlib/persistent-map.eli +335 -324
- package/dist/literal-sources/stdlib/persistent-set.eli +8 -6
- package/dist/literal-sources/stdlib/persistent-vector.eli +18 -18
- package/dist/literal-sources/stdlib/protocol.eli +63 -0
- package/{stdlib/core → dist/literal-sources/stdlib}/set.eli +8 -8
- package/dist/literal-sources/stdlib/string.eli +362 -0
- package/dist/runtime/lisp/async-runtime.mjs +55 -59
- package/dist/runtime/lisp/async-runtime.mjs.map +1 -1
- package/dist/runtime/lisp/builtins.mjs +232 -280
- package/dist/runtime/lisp/builtins.mjs.map +1 -1
- package/dist/runtime/lisp/cli.mjs +159 -167
- package/dist/runtime/lisp/cli.mjs.map +1 -1
- package/dist/runtime/lisp/compiler.mjs +359 -419
- package/dist/runtime/lisp/compiler.mjs.map +1 -1
- package/dist/runtime/lisp/core.mjs +24 -24
- package/dist/runtime/lisp/core.mjs.map +1 -1
- package/dist/runtime/lisp/evaluator.mjs +315 -385
- package/dist/runtime/lisp/evaluator.mjs.map +1 -1
- package/dist/runtime/lisp/extensions.mjs +85 -103
- package/dist/runtime/lisp/extensions.mjs.map +1 -1
- package/dist/runtime/lisp/host-io.mjs +106 -122
- package/dist/runtime/lisp/host-io.mjs.map +1 -1
- package/dist/runtime/lisp/io-worker.mjs +117 -135
- package/dist/runtime/lisp/io-worker.mjs.map +1 -1
- package/dist/runtime/lisp/keymap.mjs +5 -5
- package/dist/runtime/lisp/keymap.mjs.map +1 -1
- package/dist/runtime/lisp/macros-forms.mjs +49 -51
- package/dist/runtime/lisp/macros-forms.mjs.map +1 -1
- package/dist/runtime/lisp/reader-format.mjs +31 -31
- package/dist/runtime/lisp/reader-format.mjs.map +1 -1
- package/dist/runtime/lisp/regexp-buffer.mjs +9 -9
- package/dist/runtime/lisp/regexp-buffer.mjs.map +1 -1
- package/dist/runtime/math.mjs +32 -38
- package/dist/runtime/math.mjs.map +1 -1
- package/dist/runtime/number-radix.mjs +5 -7
- package/dist/runtime/number-radix.mjs.map +1 -1
- package/dist/runtime/primitives.mjs +81 -46
- package/dist/runtime/primitives.mjs.macro-origins.json +294 -44
- package/dist/runtime/primitives.mjs.map +1 -1
- package/dist/runtime/unicode-case.mjs +6 -6
- package/dist/runtime/unicode-case.mjs.map +1 -1
- package/dist/runtime.eli +3068 -1882
- package/dist/stage3-release.json +1 -1
- package/dist/stdlib/async.mjs +1838 -0
- package/dist/stdlib/bit.mjs +116 -0
- package/dist/stdlib/collection.mjs +193 -0
- package/dist/stdlib/core.mjs +28 -0
- package/dist/stdlib/data-text.mjs +54 -0
- package/dist/stdlib/data.mjs +601 -0
- package/dist/stdlib/devtools.mjs +565 -0
- package/dist/stdlib/diff.mjs +180 -0
- package/dist/stdlib/fn.mjs +164 -0
- package/dist/stdlib/hierarchy.mjs +189 -0
- package/dist/stdlib/identifier.mjs +33 -0
- package/dist/stdlib/interop/js.mjs +706 -0
- package/dist/stdlib/interop/object.mjs +40 -0
- package/dist/stdlib/json.mjs +843 -0
- package/dist/stdlib/lazy-sequence.mjs +117 -0
- package/dist/stdlib/math.mjs +386 -0
- package/dist/stdlib/meta.mjs +21 -0
- package/dist/stdlib/multimethod.mjs +345 -0
- package/dist/stdlib/numeric.mjs +327 -0
- package/dist/stdlib/order.mjs +194 -0
- package/dist/stdlib/persistent-list.mjs +171 -0
- package/dist/stdlib/persistent-map.mjs +781 -0
- package/dist/stdlib/persistent-queue.mjs +44 -0
- package/dist/stdlib/persistent-set.mjs +225 -0
- package/dist/stdlib/persistent-vector.mjs +316 -0
- package/dist/stdlib/portable/data-text.mjs +1094 -0
- package/dist/stdlib/portable/data.mjs +62 -0
- package/dist/stdlib/portable/identifier.mjs +179 -0
- package/dist/stdlib/portable/metadata.mjs +63 -0
- package/dist/stdlib/portable/object.mjs +140 -0
- package/dist/stdlib/portable/sequence.mjs +142 -0
- package/dist/stdlib/portable/text.mjs +111 -0
- package/dist/stdlib/pprint.mjs +807 -0
- package/dist/stdlib/protocol.mjs +61 -0
- package/dist/stdlib/record.mjs +25 -0
- package/dist/stdlib/regex.mjs +115 -0
- package/dist/stdlib/result.mjs +198 -0
- package/dist/stdlib/schema.mjs +2828 -0
- package/dist/stdlib/seq.mjs +913 -0
- package/dist/stdlib/set.mjs +317 -0
- package/dist/stdlib/sorted.mjs +56 -0
- package/dist/stdlib/state.mjs +451 -0
- package/dist/stdlib/string.mjs +494 -0
- package/dist/stdlib/tap.mjs +187 -0
- package/dist/stdlib/test.mjs +669 -0
- package/dist/stdlib/time.mjs +522 -0
- package/dist/stdlib/transducer.mjs +85 -0
- package/dist/stdlib/transient.mjs +32 -0
- package/dist/stdlib/type.mjs +28 -0
- package/dist/stdlib/uuid.mjs +377 -0
- package/dist/stdlib/value.mjs +334 -0
- package/dist/stdlib/walk.mjs +243 -0
- package/dist/stdlib/wire/gepo.mjs +28 -0
- package/dist/stdlib/wire/mdp.mjs +13 -0
- package/dist/stdlib/wire/mds.mjs +10 -0
- package/dist/stdlib/zipper.mjs +1025 -0
- package/editor/README.md +15 -0
- package/editor/eliscript-data.el +221 -8
- package/editor/eliscript-mode.el +207 -48
- package/editor/eliscript-runtime.el +6 -3
- package/package.json +49 -15
- package/platform/README.md +6 -0
- package/platform/browser.mjs +10 -12
- package/platform/browser.mjs.map +1 -1
- package/runtime/README.md +12 -5
- package/runtime/core/array-map.eli +538 -0
- package/runtime/core/array-map.mjs +651 -0
- package/runtime/core/array-map.mjs.map +1 -0
- package/runtime/core/collection-internals.eli +85 -33
- package/runtime/core/collection-internals.mjs +245 -193
- package/runtime/core/collection-internals.mjs.map +1 -1
- package/runtime/core/collection.eli +105 -3
- package/runtime/core/collection.mjs +190 -53
- package/runtime/core/collection.mjs.map +1 -1
- package/runtime/core/data-text.eli +224 -16
- package/runtime/core/data-text.mjs +345 -83
- package/runtime/core/data-text.mjs.map +1 -1
- package/runtime/core/data.eli +50 -33
- package/runtime/core/data.mjs +72 -36
- package/runtime/core/data.mjs.map +1 -1
- package/runtime/core/identifier.mjs +15 -19
- package/runtime/core/identifier.mjs.map +1 -1
- package/runtime/core/lazy-sequence.eli +885 -15
- package/runtime/core/lazy-sequence.mjs +1265 -38
- package/runtime/core/lazy-sequence.mjs.map +1 -1
- package/runtime/core/map-internals.eli +209 -1
- package/runtime/core/map-internals.mjs +359 -71
- package/runtime/core/map-internals.mjs.map +1 -1
- package/runtime/core/map.eli +75 -7
- package/runtime/core/map.mjs +122 -47
- package/runtime/core/map.mjs.map +1 -1
- package/{stdlib/core/object.eli → runtime/core/object-impl.eli} +6 -6
- package/runtime/core/object-impl.mjs +5 -5
- package/runtime/core/object-impl.mjs.map +1 -1
- package/runtime/core/order.eli +15 -3
- package/runtime/core/order.mjs +23 -8
- package/runtime/core/order.mjs.map +1 -1
- package/runtime/core/persistent-kind.mjs +9 -13
- package/runtime/core/persistent-kind.mjs.map +1 -1
- package/runtime/core/protocol-error.mjs +9 -11
- package/runtime/core/protocol-error.mjs.map +1 -1
- package/{stdlib/core/protocol.eli → runtime/core/protocol-impl.eli} +2 -2
- package/runtime/core/protocol-impl.mjs +10 -10
- package/runtime/core/protocol-impl.mjs.map +1 -1
- package/runtime/core/queue.mjs +14 -16
- package/runtime/core/queue.mjs.map +1 -1
- package/runtime/core/record.eli +2 -2
- package/runtime/core/record.mjs +13 -17
- package/runtime/core/record.mjs.map +1 -1
- package/runtime/core/regex.mjs +18 -22
- package/runtime/core/regex.mjs.map +1 -1
- package/runtime/core/sequence.eli +33 -31
- package/runtime/core/sequence.mjs +60 -93
- package/runtime/core/sequence.mjs.map +1 -1
- package/runtime/core/set.eli +53 -27
- package/runtime/core/set.mjs +113 -82
- package/runtime/core/set.mjs.map +1 -1
- package/runtime/core/sorted.mjs +91 -108
- package/runtime/core/sorted.mjs.map +1 -1
- package/{stdlib/core/text.eli → runtime/core/text-impl.eli} +2 -2
- package/runtime/core/text-impl.mjs +1 -1
- package/runtime/core/text-impl.mjs.map +1 -1
- package/runtime/core/transducer.eli +24 -0
- package/runtime/core/transducer.mjs +27 -1
- package/runtime/core/transducer.mjs.map +1 -1
- package/runtime/core/transient-internals.eli +12 -4
- package/runtime/core/transient-internals.mjs +19 -6
- package/runtime/core/transient-internals.mjs.map +1 -1
- package/runtime/core/transient.eli +31 -0
- package/runtime/core/transient.mjs +33 -2
- package/runtime/core/transient.mjs.map +1 -1
- package/runtime/core/value-internals.mjs +29 -35
- package/runtime/core/value-internals.mjs.map +1 -1
- package/runtime/core/vector.eli +73 -20
- package/runtime/core/vector.mjs +159 -156
- package/runtime/core/vector.mjs.map +1 -1
- package/runtime/literals.eli +16 -9
- package/runtime/literals.mjs +25 -9
- package/runtime/literals.mjs.map +1 -1
- package/{stdlib → runtime/managed}/managed-literal-protocols.eli +100 -34
- package/{stdlib → runtime/managed}/managed-literals.eli +406 -81
- package/{dist/literal-sources/stdlib → runtime/managed}/managed-queue-state.eli +1 -1
- package/runtime/managed/managed-runtime-array-map.eli +45 -0
- package/{stdlib → runtime/managed}/managed-runtime-collection-internals.eli +22 -2
- package/{stdlib → runtime/managed}/managed-runtime-collection.eli +282 -23
- package/{stdlib → runtime/managed}/managed-runtime-data-text.eli +196 -13
- package/{stdlib → runtime/managed}/managed-runtime-data.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-identifier.eli +1 -1
- package/runtime/managed/managed-runtime-lazy-sequence.eli +935 -0
- package/{stdlib → runtime/managed}/managed-runtime-list.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-map.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-metadata-internals.eli +2 -2
- package/{stdlib → runtime/managed}/managed-runtime-metadata.eli +2 -2
- package/{stdlib → runtime/managed}/managed-runtime-object.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-order.eli +3 -3
- package/{stdlib → runtime/managed}/managed-runtime-persistent-kind.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-protocol.eli +5 -3
- package/{stdlib → runtime/managed}/managed-runtime-queue.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-record.eli +3 -3
- package/{stdlib → runtime/managed}/managed-runtime-regex.eli +2 -2
- package/{stdlib → runtime/managed}/managed-runtime-sequence.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-set-algebra.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-set.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-sorted.eli +4 -4
- package/{stdlib → runtime/managed}/managed-runtime-text.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-transducer.eli +24 -2
- package/{stdlib → runtime/managed}/managed-runtime-transient.eli +7 -5
- package/{stdlib → runtime/managed}/managed-runtime-type.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-value-internals.eli +3 -3
- package/{stdlib → runtime/managed}/managed-runtime-value.eli +2 -2
- package/{stdlib → runtime/managed}/managed-runtime-vector.eli +5 -2
- package/{dist/literal-sources/stdlib → runtime/managed}/managed-sorted-state.eli +1 -1
- package/runtime/managed/managed-transient-state.eli +1206 -0
- package/{dist/literal-sources/stdlib → runtime/managed}/managed-value-state.eli +30 -6
- package/{stdlib → runtime/managed}/managed-vector-view-state.eli +1 -1
- package/{stdlib → runtime/managed}/managed-wire-http-rpc.eli +1 -1
- package/{stdlib → runtime/managed}/managed-wire-markdown.eli +1 -1
- package/{stdlib → runtime/managed}/managed-wire-schema.eli +1 -1
- package/runtime/math.mjs +32 -38
- package/runtime/math.mjs.map +1 -1
- package/runtime/number-radix.mjs +5 -7
- package/runtime/number-radix.mjs.map +1 -1
- package/runtime/primitives.eli +19 -6
- package/runtime/primitives.mjs +81 -46
- package/runtime/primitives.mjs.map +1 -1
- package/runtime/source-mapping.mjs +17 -23
- package/runtime/source-mapping.mjs.map +1 -1
- package/runtime/testing/map.eli +70 -41
- package/runtime/testing/map.mjs +57 -34
- package/runtime/testing/map.mjs.map +1 -1
- package/runtime/unicode-case.mjs +6 -6
- package/runtime/unicode-case.mjs.map +1 -1
- package/runtime/wire/http-rpc.mjs +12 -18
- package/runtime/wire/http-rpc.mjs.map +1 -1
- package/runtime/wire/markdown.mjs +42 -42
- package/runtime/wire/markdown.mjs.map +1 -1
- package/runtime/wire/schema.mjs +13 -13
- package/runtime/wire/schema.mjs.map +1 -1
- package/runtime/worker-value-codec.mjs +5 -7
- package/runtime/worker-value-codec.mjs.map +1 -1
- package/runtime/worker-value-stream.mjs +128 -135
- package/runtime/worker-value-stream.mjs.map +1 -1
- package/runtime/worker.mjs +75 -89
- package/runtime/worker.mjs.map +1 -1
- package/stdlib/README.md +25 -18
- package/stdlib/async.eli +1245 -0
- package/stdlib/bit.eli +89 -1
- package/stdlib/bit.mjs +89 -2
- package/stdlib/bit.mjs.map +1 -1
- package/stdlib/{core/collection.eli → collection.eli} +39 -4
- package/stdlib/core.eli +956 -0
- package/stdlib/data-text.eli +62 -1091
- package/stdlib/data.eli +517 -37
- package/stdlib/devtools.eli +399 -0
- package/stdlib/diff.eli +134 -0
- package/stdlib/{function.eli → fn.eli} +1 -1
- package/stdlib/identifier.eli +21 -136
- package/stdlib/interop/object.eli +39 -0
- package/stdlib/{core/lazy-sequence.eli → lazy-sequence.eli} +28 -2
- package/stdlib/math.eli +267 -0
- package/stdlib/{core/metadata.eli → meta.eli} +2 -2
- package/stdlib/{core/order.eli → order.eli} +6 -6
- package/stdlib/persistent-list.eli +60 -21
- package/stdlib/persistent-map.eli +335 -324
- package/stdlib/persistent-set.eli +8 -6
- package/stdlib/persistent-vector.eli +18 -18
- package/stdlib/portable/data-text.eli +1092 -0
- package/stdlib/portable/data.eli +42 -0
- package/stdlib/portable/identifier.eli +147 -0
- package/stdlib/{metadata.eli → portable/metadata.eli} +5 -5
- package/stdlib/{object.eli → portable/object.eli} +1 -1
- package/stdlib/{sequence.eli → portable/sequence.eli} +1 -1
- package/stdlib/{text.eli → portable/text.eli} +1 -1
- package/stdlib/pprint.eli +588 -0
- package/stdlib/protocol.eli +63 -0
- package/stdlib/{core/record.eli → record.eli} +2 -2
- package/stdlib/regex.eli +70 -0
- package/stdlib/result.eli +53 -44
- package/stdlib/schema.eli +1886 -0
- package/stdlib/{core/seq.eli → seq.eli} +97 -90
- package/{dist/literal-sources/stdlib/core → stdlib}/set.eli +8 -8
- package/stdlib/{core/sorted.eli → sorted.eli} +2 -2
- package/stdlib/{state/atom.eli → state.eli} +137 -7
- package/stdlib/string.eli +362 -0
- package/stdlib/tap.eli +135 -0
- package/stdlib/test.eli +566 -0
- package/stdlib/time.eli +419 -0
- package/stdlib/{core/transducer.eli → transducer.eli} +4 -2
- package/stdlib/{core/transient.eli → transient.eli} +11 -5
- package/stdlib/{core/type.eli → type.eli} +2 -2
- package/stdlib/uuid.eli +288 -0
- package/stdlib/{core/walk.eli → walk.eli} +6 -6
- package/stdlib/{gepo.eli → wire/gepo.eli} +2 -2
- package/stdlib/{mdp.eli → wire/mdp.eli} +2 -2
- package/stdlib/{mds.eli → wire/mds.eli} +2 -2
- package/stdlib/{core/zipper.eli → zipper.eli} +179 -138
- package/tests/helpers/wasm-managed-math-node.mjs +495 -582
- package/tools/acceptance/check-ground.mjs +106 -132
- package/tools/acceptance/check.mjs +16 -16
- package/tools/acceptance/retained-performance-snapshot.mjs +265 -149
- package/tools/acceptance/retained-soak.mjs +5 -7
- package/tools/acceptance/retained-transient.mjs +5 -7
- package/tools/backends/build.mjs +373 -95
- package/tools/backends/compiler-bootstrap.mjs +271 -317
- package/tools/backends/compiler-browser.mjs +7 -9
- package/tools/backends/compiler-build.mjs +77 -97
- package/tools/backends/compiler-cli-ground.mjs +47 -47
- package/tools/backends/compiler-data-transport.mjs +27 -31
- package/tools/backends/compiler-host-iteration.mjs +13 -21
- package/tools/backends/compiler-host-record.mjs +28 -34
- package/tools/backends/compiler-metadata.mjs +145 -53
- package/tools/backends/compiler-package-ground.mjs +39 -47
- package/tools/backends/compiler-package-loader.mjs +164 -206
- package/tools/backends/compiler-session.mjs +432 -324
- package/tools/backends/compiler-worker.mjs +79 -89
- package/tools/backends/dist/bootstrap-js-stages.mjs +17 -19
- package/tools/backends/dist/bootstrap-js-stages.mjs.map +1 -1
- package/tools/backends/dist/managed-ir-inventory.mjs +1 -1
- package/tools/backends/dist/managed-ir-inventory.mjs.map +1 -1
- package/tools/backends/dist/release-cli.mjs +151 -22
- package/tools/backends/dist/release-cli.mjs.map +1 -1
- package/tools/backends/dist/run-artifact.mjs +54 -76
- package/tools/backends/dist/run-artifact.mjs.map +1 -1
- package/tools/backends/managed-foreign-binding.mjs +370 -114
- package/tools/backends/managed-host-ground.mjs +14 -17
- package/tools/backends/managed-host-lifecycle.mjs +42 -53
- package/tools/backends/managed-host-object-realm.mjs +121 -111
- package/tools/backends/managed-host-proxy.mjs +5 -7
- package/tools/backends/managed-host-runtime.mjs +6295 -4350
- package/tools/backends/managed-host.mjs +234 -188
- package/tools/backends/managed-layout.mjs +53 -56
- package/tools/backends/managed-module-graph-ground.mjs +488 -568
- package/tools/backends/managed-module-graph.mjs +62 -76
- package/tools/backends/managed-runtime-host-ground.mjs +352 -400
- package/tools/backends/managed-runtime.mjs +227 -266
- package/tools/backends/managed-source-view-ground.mjs +165 -161
- package/tools/backends/managed-source-view.mjs +415 -154
- package/tools/backends/native-managed-runtime.mjs +96 -138
- package/tools/backends/native-memory.mjs +1122 -742
- package/tools/backends/native-node-ffi.mjs +2439 -0
- package/tools/backends/native-node-memory.mjs +793 -383
- package/tools/backends/native-node-runner.mjs +1458 -579
- package/tools/backends/native-node-watchdog.mjs +12 -14
- package/tools/backends/native-node-worker.mjs +46 -50
- package/tools/backends/stage3-targets.mjs +2 -2
- package/tools/bootstrap-runtime.el +4 -4
- package/tools/collections/transient-builder-benchmark.mjs +17 -17
- package/tools/project/check-cli.eli +27 -3
- package/tools/project/project-cli.eli +1 -1
- package/tools/testing/maintained-suite-source.mjs +5 -7
- package/tools/testing/maintained-suite-source.mjs.map +1 -1
- package/dist/literal-sources/stdlib/core/data.eli +0 -306
- package/dist/literal-sources/stdlib/managed-transient-state.eli +0 -353
- package/stdlib/core/data-text.eli +0 -16
- package/stdlib/core/data.eli +0 -306
- package/stdlib/core/identifier.eli +0 -32
- package/stdlib/core/regex.eli +0 -17
- package/stdlib/deferred.eli +0 -70
- package/stdlib/managed-runtime-lazy-sequence.eli +0 -157
- package/stdlib/managed-transient-state.eli +0 -353
- /package/{stdlib → runtime/managed}/managed-protocol-error.eli +0 -0
- /package/{stdlib → runtime/managed}/managed-runtime-literals.eli +0 -0
- /package/{stdlib → runtime/managed}/managed-runtime-truth.eli +0 -0
- /package/{stdlib → runtime/managed}/managed-testing-value.eli +0 -0
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
(module eliscript.runtime.core.lazy-sequence
|
|
2
|
-
(import "./collection.mjs"
|
|
3
|
-
|
|
2
|
+
(import "./collection.mjs"
|
|
3
|
+
IChunk
|
|
4
|
+
IChunkedSeq
|
|
5
|
+
MemoizedSequenceView
|
|
6
|
+
isChunkedSeq
|
|
7
|
+
memoizedSequenceView
|
|
8
|
+
seq)
|
|
9
|
+
(import "./collection-internals.mjs"
|
|
10
|
+
CHUNKED_FIRST
|
|
11
|
+
CHUNKED_MORE
|
|
12
|
+
CHUNKED_NEXT
|
|
13
|
+
CHUNK_COUNT
|
|
14
|
+
CHUNK_DROP_FIRST
|
|
15
|
+
CHUNK_NTH
|
|
16
|
+
COLLECTION_COUNT
|
|
17
|
+
COLLECTION_NTH
|
|
18
|
+
COLLECTION_REDUCE
|
|
19
|
+
COLLECTION_SEQ
|
|
20
|
+
UNBOUNDED_SEQUENCE
|
|
21
|
+
dispatchChunkCount
|
|
22
|
+
dispatchChunkDropFirst
|
|
23
|
+
dispatchChunkNth
|
|
24
|
+
dispatchChunkedFirst
|
|
25
|
+
dispatchChunkedNext
|
|
26
|
+
isReducedValue
|
|
27
|
+
memoizedSequenceStatus
|
|
28
|
+
registerChunkedPrependHandler
|
|
29
|
+
registerChunkedSliceHandler
|
|
30
|
+
unreducedValue
|
|
31
|
+
validateCollectionCount)
|
|
32
|
+
(import "./list.mjs" EMPTY_LIST)
|
|
33
|
+
(import "./protocol.mjs" implementsProtocol)
|
|
4
34
|
(import "./transducer.mjs"
|
|
5
35
|
deduping
|
|
6
36
|
distincting
|
|
@@ -20,15 +50,36 @@
|
|
|
20
50
|
taking
|
|
21
51
|
takingNth
|
|
22
52
|
takingWhile)
|
|
53
|
+
(import "./truth.mjs" isTruthy)
|
|
23
54
|
|
|
55
|
+
(defconst CHUNK_SIZE 32)
|
|
24
56
|
(defconst typeof-value (js* "(value) => typeof value"))
|
|
25
57
|
(defconst instance-of? (js* "(value, Constructor) => value instanceof Constructor"))
|
|
58
|
+
(defconst host-apply Reflect/apply)
|
|
59
|
+
(defconst no-arguments (Object/freeze (js-array)))
|
|
60
|
+
(defconst iterator-symbol (get globalThis/Symbol :iterator))
|
|
61
|
+
|
|
26
62
|
(defconst lazy-cons-states (new globalThis/WeakMap))
|
|
63
|
+
(defconst array-chunk-states (new globalThis/WeakMap))
|
|
64
|
+
(defconst chunk-buffer-states (new globalThis/WeakMap))
|
|
65
|
+
(defconst chunked-cons-states (new globalThis/WeakMap))
|
|
66
|
+
(defconst lazy-chunked-states (new globalThis/WeakMap))
|
|
67
|
+
|
|
27
68
|
(defconst no-failure (funcall globalThis/Symbol "eliscript.lazy-cons.no-failure"))
|
|
69
|
+
(defconst NO_INITIAL (funcall globalThis/Symbol "eliscript.lazy-chunk.no-initial"))
|
|
70
|
+
(defconst ARRAY_CHUNK_TOKEN (funcall globalThis/Symbol "eliscript.array-chunk.constructor"))
|
|
71
|
+
(defconst ARRAY_CHUNK_MISSING (funcall globalThis/Symbol "eliscript.array-chunk.missing"))
|
|
72
|
+
(defconst CHUNK_BUFFER_TOKEN (funcall globalThis/Symbol "eliscript.chunk-buffer.constructor"))
|
|
73
|
+
(defconst CHUNKED_CONS_TOKEN (funcall globalThis/Symbol "eliscript.chunked-cons.constructor"))
|
|
74
|
+
(defconst LAZY_CHUNKED_TOKEN (funcall globalThis/Symbol "eliscript.lazy-chunked.constructor"))
|
|
75
|
+
(defconst UNKNOWN_COUNT (funcall globalThis/Symbol "eliscript.chunked.unknown-count"))
|
|
28
76
|
|
|
29
77
|
(defun fail (message)
|
|
30
78
|
(throw (new globalThis/TypeError message)))
|
|
31
79
|
|
|
80
|
+
(defun range-fail (message)
|
|
81
|
+
(throw (new globalThis/RangeError message)))
|
|
82
|
+
|
|
32
83
|
(defun callable? (value)
|
|
33
84
|
(= (funcall typeof-value value) "function"))
|
|
34
85
|
|
|
@@ -44,6 +95,16 @@
|
|
|
44
95
|
(unless (= actual expected)
|
|
45
96
|
(fail (str name " requires exactly " expected (if (= expected 1) " argument" " arguments")))))
|
|
46
97
|
|
|
98
|
+
(defun require-nonnegative (value label)
|
|
99
|
+
(unless (and (Number/isSafeInteger value) (>= value 0))
|
|
100
|
+
(fail (str label " must be a non-negative safe integer")))
|
|
101
|
+
value)
|
|
102
|
+
|
|
103
|
+
(defun require-finite (value label)
|
|
104
|
+
(unless (Number/isFinite value)
|
|
105
|
+
(fail (str label " must be a finite number")))
|
|
106
|
+
value)
|
|
107
|
+
|
|
47
108
|
(defun method (implementation name arity)
|
|
48
109
|
(let ((function (funcall
|
|
49
110
|
(js* "(fn, name) => ({ [name](...args) { return fn(this, ...args); } })[name]")
|
|
@@ -52,11 +113,25 @@
|
|
|
52
113
|
(Object/defineProperty function "length" (js-object :value arity :configurable t))
|
|
53
114
|
function))
|
|
54
115
|
|
|
116
|
+
(defun getter (implementation name)
|
|
117
|
+
(funcall
|
|
118
|
+
(js* "(fn, name) => Object.getOwnPropertyDescriptor({ get [name]() { return fn(this); } }, name).get")
|
|
119
|
+
implementation
|
|
120
|
+
name))
|
|
121
|
+
|
|
122
|
+
(defun install-method (target key name arity implementation)
|
|
123
|
+
(Object/defineProperty target key
|
|
124
|
+
(js-object :value (method implementation name arity) :writable t :configurable t)))
|
|
125
|
+
|
|
126
|
+
(defun install-getter (target key name implementation)
|
|
127
|
+
(Object/defineProperty target key
|
|
128
|
+
(js-object :get (getter implementation (str "get " name)) :configurable t)))
|
|
129
|
+
|
|
55
130
|
(defun sequence-iterator (value)
|
|
56
131
|
(let ((source (seq value)))
|
|
57
132
|
(if (nil? source)
|
|
58
|
-
(js-call (aref (js-array)
|
|
59
|
-
(js-call (aref source
|
|
133
|
+
(js-call (aref (js-array) iterator-symbol) :call (js-array))
|
|
134
|
+
(js-call (aref source iterator-symbol) :call source))))
|
|
60
135
|
|
|
61
136
|
(defun realize-tail (state)
|
|
62
137
|
(unless (eq (get state :failure) no-failure)
|
|
@@ -111,10 +186,739 @@
|
|
|
111
186
|
(js-object :value value :done t))
|
|
112
187
|
"return"
|
|
113
188
|
1))))
|
|
114
|
-
(put iterator
|
|
189
|
+
(put iterator iterator-symbol
|
|
115
190
|
(method (lambda (self) self) "[Symbol.iterator]" 0))
|
|
116
191
|
iterator)))
|
|
117
192
|
|
|
193
|
+
;; 32-element chunked sequence infrastructure
|
|
194
|
+
(defconst ArrayChunk
|
|
195
|
+
(funcall
|
|
196
|
+
(js* "(init) => class ArrayChunk { constructor(token, array, off, end) { init(this, token, array, off, end); } }")
|
|
197
|
+
(lambda (self token array off end)
|
|
198
|
+
(unless (eq token ARRAY_CHUNK_TOKEN)
|
|
199
|
+
(fail "ArrayChunk values must be created with arrayChunk"))
|
|
200
|
+
(js-call array-chunk-states :set self
|
|
201
|
+
(Object/freeze (js-object :array array :off off :end end :count (- end off))))
|
|
202
|
+
(Object/freeze self))))
|
|
203
|
+
|
|
204
|
+
(defun chunk-state (chunk)
|
|
205
|
+
(js-call array-chunk-states :get chunk))
|
|
206
|
+
|
|
207
|
+
(defun arrayChunk (array &optional off end)
|
|
208
|
+
(unless (Array/isArray array)
|
|
209
|
+
(fail "arrayChunk expects a JavaScript Array"))
|
|
210
|
+
(let* ((total (js-length array))
|
|
211
|
+
(start (if (nullish? off) 0 (validateCollectionCount off)))
|
|
212
|
+
(finish (if (nullish? end) total (validateCollectionCount end))))
|
|
213
|
+
(when (or (> start finish) (> finish total))
|
|
214
|
+
(range-fail "arrayChunk bounds are outside array length"))
|
|
215
|
+
(let ((frozen-items (Object/freeze (js-call array :slice))))
|
|
216
|
+
(new ArrayChunk ARRAY_CHUNK_TOKEN frozen-items start finish))))
|
|
217
|
+
|
|
218
|
+
(defun array-chunk-owned (frozen-array off end)
|
|
219
|
+
(new ArrayChunk ARRAY_CHUNK_TOKEN frozen-array off end))
|
|
220
|
+
|
|
221
|
+
(let ((cproto (get ArrayChunk :prototype)))
|
|
222
|
+
(install-getter cproto "count" "count"
|
|
223
|
+
(lambda (self) (get (chunk-state self) :count)))
|
|
224
|
+
(install-getter cproto "size" "size"
|
|
225
|
+
(lambda (self) (get (chunk-state self) :count)))
|
|
226
|
+
(install-method cproto "chunkCount" "chunkCount" 0
|
|
227
|
+
(lambda (self) (get (chunk-state self) :count)))
|
|
228
|
+
(install-method cproto "chunkNth" "chunkNth" 1
|
|
229
|
+
(lambda (self index &rest args)
|
|
230
|
+
(let* ((state (chunk-state self))
|
|
231
|
+
(count (get state :count))
|
|
232
|
+
(not-found (if (= (js-length args) 0) ARRAY_CHUNK_MISSING (aref args 0))))
|
|
233
|
+
(if (and (Number/isInteger index) (>= index 0) (< index count))
|
|
234
|
+
(aref (get state :array) (+ (get state :off) index))
|
|
235
|
+
(if (not (eq not-found ARRAY_CHUNK_MISSING))
|
|
236
|
+
not-found
|
|
237
|
+
(range-fail (str "chunk index " (funcall globalThis/String index) " is outside [0, " count ")")))))))
|
|
238
|
+
(install-method cproto "dropFirst" "dropFirst" 0
|
|
239
|
+
(lambda (self)
|
|
240
|
+
(let ((state (chunk-state self)))
|
|
241
|
+
(when (= (get state :count) 0)
|
|
242
|
+
(range-fail "cannot dropFirst on empty chunk"))
|
|
243
|
+
(array-chunk-owned (get state :array) (+ (get state :off) 1) (get state :end)))))
|
|
244
|
+
(install-method cproto CHUNK_COUNT "[eliscript.chunk.count]" 0
|
|
245
|
+
(lambda (self) (get (chunk-state self) :count)))
|
|
246
|
+
(install-method cproto CHUNK_NTH "[eliscript.chunk.nth]" 1
|
|
247
|
+
(lambda (self index &rest args)
|
|
248
|
+
(funcall host-apply (get cproto :chunkNth) self (js-call (js-array index) :concat args))))
|
|
249
|
+
(install-method cproto CHUNK_DROP_FIRST "[eliscript.chunk.dropFirst]" 0
|
|
250
|
+
(lambda (self) (js-call self :dropFirst)))
|
|
251
|
+
(install-method cproto COLLECTION_COUNT "[eliscript.collection.count]" 0
|
|
252
|
+
(lambda (self) (get (chunk-state self) :count)))
|
|
253
|
+
(install-method cproto COLLECTION_NTH "[eliscript.collection.nth]" 1
|
|
254
|
+
(lambda (self index &rest args)
|
|
255
|
+
(funcall host-apply (get cproto :chunkNth) self (js-call (js-array index) :concat args))))
|
|
256
|
+
(install-method cproto iterator-symbol "[Symbol.iterator]" 0
|
|
257
|
+
(lambda (self)
|
|
258
|
+
(let* ((state (chunk-state self))
|
|
259
|
+
(array (get state :array))
|
|
260
|
+
(end (get state :end))
|
|
261
|
+
(cursor (get state :off)))
|
|
262
|
+
(let ((iter (js-object
|
|
263
|
+
:next (method
|
|
264
|
+
(lambda (_self)
|
|
265
|
+
(if (< cursor end)
|
|
266
|
+
(let ((value (aref array cursor)))
|
|
267
|
+
(setq cursor (1+ cursor))
|
|
268
|
+
(js-object :value value :done false))
|
|
269
|
+
(js-object :value undefined :done t)))
|
|
270
|
+
"next"
|
|
271
|
+
0))))
|
|
272
|
+
(put iter iterator-symbol (method (lambda (s) s) "[Symbol.iterator]" 0))
|
|
273
|
+
iter))))
|
|
274
|
+
(install-getter cproto (get globalThis/Symbol :toStringTag) "[Symbol.toStringTag]"
|
|
275
|
+
(lambda (_self) "EliscriptArrayChunk")))
|
|
276
|
+
|
|
277
|
+
(defconst ChunkBuffer
|
|
278
|
+
(funcall
|
|
279
|
+
(js* "(init) => class ChunkBuffer { constructor(token, capacity) { init(this, token, capacity); } }")
|
|
280
|
+
(lambda (self token capacity)
|
|
281
|
+
(unless (eq token CHUNK_BUFFER_TOKEN)
|
|
282
|
+
(fail "ChunkBuffer values must be created with chunkBuffer"))
|
|
283
|
+
(js-call chunk-buffer-states :set self
|
|
284
|
+
(js-object :items (js-array) :capacity capacity :consumed false))
|
|
285
|
+
(Object/freeze self))))
|
|
286
|
+
|
|
287
|
+
(defun chunk-buffer-state (buffer)
|
|
288
|
+
(let ((state (js-call chunk-buffer-states :get buffer)))
|
|
289
|
+
(when (undefined? state)
|
|
290
|
+
(fail "expected an Eliscript ChunkBuffer"))
|
|
291
|
+
state))
|
|
292
|
+
|
|
293
|
+
(defun active-buffer-state (buffer)
|
|
294
|
+
(let ((state (chunk-buffer-state buffer)))
|
|
295
|
+
(when (get state :consumed)
|
|
296
|
+
(fail "ChunkBuffer has already been converted to an immutable chunk"))
|
|
297
|
+
state))
|
|
298
|
+
|
|
299
|
+
(defun chunkBuffer (&optional capacity)
|
|
300
|
+
(let ((limit (if (nullish? capacity) CHUNK_SIZE (require-nonnegative capacity "chunkBuffer capacity"))))
|
|
301
|
+
(new ChunkBuffer CHUNK_BUFFER_TOKEN limit)))
|
|
302
|
+
|
|
303
|
+
(defun chunkAppend (buffer value)
|
|
304
|
+
(let ((state (active-buffer-state buffer)))
|
|
305
|
+
(when (>= (js-length (get state :items)) (get state :capacity))
|
|
306
|
+
(range-fail "ChunkBuffer capacity exceeded"))
|
|
307
|
+
(js-call (get state :items) :push value)
|
|
308
|
+
buffer))
|
|
309
|
+
|
|
310
|
+
(defun chunkFromBuffer (buffer)
|
|
311
|
+
(let* ((state (active-buffer-state buffer))
|
|
312
|
+
(items (get state :items))
|
|
313
|
+
(len (js-length items)))
|
|
314
|
+
(put state "consumed" t)
|
|
315
|
+
(put state "items" nil)
|
|
316
|
+
(Object/freeze items)
|
|
317
|
+
(array-chunk-owned items 0 len)))
|
|
318
|
+
|
|
319
|
+
(let ((bproto (get ChunkBuffer :prototype)))
|
|
320
|
+
(install-getter bproto "count" "count"
|
|
321
|
+
(lambda (self)
|
|
322
|
+
(let ((state (chunk-buffer-state self)))
|
|
323
|
+
(if (get state :consumed) 0 (js-length (get state :items))))))
|
|
324
|
+
(install-getter bproto "size" "size"
|
|
325
|
+
(lambda (self) (get self :count)))
|
|
326
|
+
(install-method bproto "add" "add" 1
|
|
327
|
+
(lambda (self value) (chunkAppend self value)))
|
|
328
|
+
(install-method bproto "chunk" "chunk" 0
|
|
329
|
+
(lambda (self) (chunkFromBuffer self)))
|
|
330
|
+
(install-getter bproto (get globalThis/Symbol :toStringTag) "[Symbol.toStringTag]"
|
|
331
|
+
(lambda (_self) "EliscriptChunkBuffer")))
|
|
332
|
+
|
|
333
|
+
(defun chunk-count-of (chunk)
|
|
334
|
+
(let ((direct (aref chunk CHUNK_COUNT)))
|
|
335
|
+
(if (callable? direct)
|
|
336
|
+
(funcall host-apply direct chunk no-arguments)
|
|
337
|
+
(dispatchChunkCount chunk))))
|
|
338
|
+
|
|
339
|
+
(defun chunk-nth-of (chunk index)
|
|
340
|
+
(let ((direct (aref chunk CHUNK_NTH)))
|
|
341
|
+
(if (callable? direct)
|
|
342
|
+
(funcall host-apply direct chunk (js-array index))
|
|
343
|
+
(dispatchChunkNth chunk index))))
|
|
344
|
+
|
|
345
|
+
(defun chunk-drop-first-of (chunk)
|
|
346
|
+
(let ((direct (aref chunk CHUNK_DROP_FIRST)))
|
|
347
|
+
(if (callable? direct)
|
|
348
|
+
(funcall host-apply direct chunk no-arguments)
|
|
349
|
+
(dispatchChunkDropFirst chunk))))
|
|
350
|
+
|
|
351
|
+
(defun resolve-lazy-chunk (lazy-seq)
|
|
352
|
+
(let ((state (js-call lazy-chunked-states :get lazy-seq)))
|
|
353
|
+
(unless (eq (get state :failure) no-failure)
|
|
354
|
+
(throw (get state :failure)))
|
|
355
|
+
(unless (get state :started)
|
|
356
|
+
(put state "started" t)
|
|
357
|
+
(try
|
|
358
|
+
(let ((resolved (funcall (get state :thunk))))
|
|
359
|
+
(put state "thunk" nil)
|
|
360
|
+
(while (funcall instance-of? resolved LazyChunkedSeq)
|
|
361
|
+
(setq resolved (resolve-lazy-chunk resolved)))
|
|
362
|
+
(put state "value" resolved))
|
|
363
|
+
(catch error
|
|
364
|
+
(put state "thunk" nil)
|
|
365
|
+
(put state "failure" error)
|
|
366
|
+
(throw error))))
|
|
367
|
+
(get state :value)))
|
|
368
|
+
|
|
369
|
+
(defun resolve-more-seq (state)
|
|
370
|
+
(unless (eq (get state :failure) no-failure)
|
|
371
|
+
(throw (get state :failure)))
|
|
372
|
+
(unless (get state :moreRealized)
|
|
373
|
+
(put state "moreRealized" t)
|
|
374
|
+
(try
|
|
375
|
+
(let ((raw (get state :more)))
|
|
376
|
+
(put state "more" nil)
|
|
377
|
+
(let ((next-val (if (callable? raw) (funcall raw) raw)))
|
|
378
|
+
(while (funcall instance-of? next-val LazyChunkedSeq)
|
|
379
|
+
(setq next-val (resolve-lazy-chunk next-val)))
|
|
380
|
+
(put state "cachedMore" (if (nil? next-val) nil next-val))))
|
|
381
|
+
(catch error
|
|
382
|
+
(put state "more" nil)
|
|
383
|
+
(put state "failure" error)
|
|
384
|
+
(throw error))))
|
|
385
|
+
(get state :cachedMore))
|
|
386
|
+
|
|
387
|
+
(defun normalize-chunk-head (chunked-seq)
|
|
388
|
+
(if (funcall instance-of? chunked-seq LazyChunkedSeq)
|
|
389
|
+
(resolve-lazy-chunk chunked-seq)
|
|
390
|
+
chunked-seq))
|
|
391
|
+
|
|
392
|
+
(defun chunked-first-of (chunked-seq)
|
|
393
|
+
(let ((curr (normalize-chunk-head chunked-seq)))
|
|
394
|
+
(if (nil? curr)
|
|
395
|
+
nil
|
|
396
|
+
(let ((direct (aref curr CHUNKED_FIRST)))
|
|
397
|
+
(if (callable? direct)
|
|
398
|
+
(funcall host-apply direct curr no-arguments)
|
|
399
|
+
(dispatchChunkedFirst curr))))))
|
|
400
|
+
|
|
401
|
+
(defun chunked-next-of (chunked-seq)
|
|
402
|
+
(let ((curr (normalize-chunk-head chunked-seq)))
|
|
403
|
+
(if (nil? curr)
|
|
404
|
+
nil
|
|
405
|
+
(let ((direct (aref curr CHUNKED_NEXT)))
|
|
406
|
+
(if (callable? direct)
|
|
407
|
+
(funcall host-apply direct curr no-arguments)
|
|
408
|
+
(dispatchChunkedNext curr))))))
|
|
409
|
+
|
|
410
|
+
(defun chunked-seq-iterator (initial-seq)
|
|
411
|
+
(let* ((current initial-seq)
|
|
412
|
+
(current-array nil)
|
|
413
|
+
(cursor 0)
|
|
414
|
+
(limit 0)
|
|
415
|
+
(current-chunk nil)
|
|
416
|
+
(tail-iterator nil)
|
|
417
|
+
(closed false)
|
|
418
|
+
(close-fn (lambda ()
|
|
419
|
+
(setq closed t current nil current-array nil current-chunk nil)
|
|
420
|
+
(when (and (not (nil? tail-iterator))
|
|
421
|
+
(callable? (get tail-iterator :return)))
|
|
422
|
+
(js-call tail-iterator :return))
|
|
423
|
+
(setq tail-iterator nil)))
|
|
424
|
+
(iter (js-object
|
|
425
|
+
:next (lambda ()
|
|
426
|
+
(if closed
|
|
427
|
+
(js-object :value undefined :done t)
|
|
428
|
+
(progn
|
|
429
|
+
(while (and (>= cursor limit) (nil? tail-iterator) (not (nil? current)))
|
|
430
|
+
(let ((resolved (normalize-chunk-head current)))
|
|
431
|
+
(if (nil? resolved)
|
|
432
|
+
(setq current nil)
|
|
433
|
+
(if (isChunkedSeq resolved)
|
|
434
|
+
(let ((chunk (chunked-first-of resolved)))
|
|
435
|
+
(if (or (nil? chunk) (= (chunk-count-of chunk) 0))
|
|
436
|
+
(setq current (chunked-next-of resolved))
|
|
437
|
+
(let ((cstate (chunk-state chunk)))
|
|
438
|
+
(if (not (undefined? cstate))
|
|
439
|
+
(setq current-array (get cstate :array)
|
|
440
|
+
cursor (get cstate :off)
|
|
441
|
+
limit (get cstate :end)
|
|
442
|
+
current-chunk nil
|
|
443
|
+
current (chunked-next-of resolved))
|
|
444
|
+
(setq current-array nil
|
|
445
|
+
cursor 0
|
|
446
|
+
limit (chunk-count-of chunk)
|
|
447
|
+
current-chunk chunk
|
|
448
|
+
current (chunked-next-of resolved))))))
|
|
449
|
+
(setq tail-iterator (sequence-iterator resolved)
|
|
450
|
+
current nil)))))
|
|
451
|
+
(cond
|
|
452
|
+
((< cursor limit)
|
|
453
|
+
(let ((val (if (not (nil? current-array))
|
|
454
|
+
(aref current-array cursor)
|
|
455
|
+
(chunk-nth-of current-chunk cursor))))
|
|
456
|
+
(setq cursor (1+ cursor))
|
|
457
|
+
(js-object :value val :done false)))
|
|
458
|
+
((not (nil? tail-iterator))
|
|
459
|
+
(let ((step (js-call tail-iterator :next)))
|
|
460
|
+
(when (truth (get step :done))
|
|
461
|
+
(setq closed t tail-iterator nil))
|
|
462
|
+
step))
|
|
463
|
+
(t
|
|
464
|
+
(setq closed t)
|
|
465
|
+
(js-object :value undefined :done t))))))
|
|
466
|
+
:return (lambda (&rest optional)
|
|
467
|
+
(let ((value (if (= (js-length optional) 0) undefined (get optional 0))))
|
|
468
|
+
(funcall close-fn)
|
|
469
|
+
(js-object :value value :done t)))
|
|
470
|
+
:throw (lambda (&rest optional)
|
|
471
|
+
(let ((error (if (= (js-length optional) 0) undefined (get optional 0))))
|
|
472
|
+
(funcall close-fn)
|
|
473
|
+
(throw error))))))
|
|
474
|
+
(Object/defineProperty iter iterator-symbol
|
|
475
|
+
(js-object :value (lambda () iter) :writable t :configurable t))
|
|
476
|
+
iter))
|
|
477
|
+
|
|
478
|
+
(defun chunked-seq-count (start-seq)
|
|
479
|
+
(let ((total 0)
|
|
480
|
+
(curr (normalize-chunk-head start-seq)))
|
|
481
|
+
(while (not (nil? curr))
|
|
482
|
+
(if (isChunkedSeq curr)
|
|
483
|
+
(let ((chunk (chunked-first-of curr)))
|
|
484
|
+
(when (not (nil? chunk))
|
|
485
|
+
(setq total (+ total (chunk-count-of chunk))))
|
|
486
|
+
(setq curr (chunked-next-of curr)))
|
|
487
|
+
(let ((iter (sequence-iterator curr))
|
|
488
|
+
(done false))
|
|
489
|
+
(while (not done)
|
|
490
|
+
(let ((step (js-call iter :next)))
|
|
491
|
+
(if (truth (get step :done))
|
|
492
|
+
(setq done t)
|
|
493
|
+
(setq total (1+ total)))))
|
|
494
|
+
(setq curr nil))))
|
|
495
|
+
total))
|
|
496
|
+
|
|
497
|
+
(defun reduce-chunked-seq (start-seq reducer initial-args)
|
|
498
|
+
(unless (callable? reducer)
|
|
499
|
+
(fail "collection reducer must be a function"))
|
|
500
|
+
(let ((acc (if (= (js-length initial-args) 0) NO_INITIAL (aref initial-args 0)))
|
|
501
|
+
(curr (normalize-chunk-head start-seq))
|
|
502
|
+
(early false))
|
|
503
|
+
(while (and (not (nil? curr)) (not early))
|
|
504
|
+
(if (isChunkedSeq curr)
|
|
505
|
+
(let ((chunk (chunked-first-of curr)))
|
|
506
|
+
(when (not (nil? chunk))
|
|
507
|
+
(let ((cstate (chunk-state chunk)))
|
|
508
|
+
(if (not (undefined? cstate))
|
|
509
|
+
(let* ((arr (get cstate :array))
|
|
510
|
+
(idx (get cstate :off))
|
|
511
|
+
(end (get cstate :end)))
|
|
512
|
+
(when (and (< idx end) (eq acc NO_INITIAL))
|
|
513
|
+
(setq acc (aref arr idx) idx (1+ idx)))
|
|
514
|
+
(while (and (< idx end) (not early))
|
|
515
|
+
(setq acc (funcall reducer acc (aref arr idx)))
|
|
516
|
+
(if (isReducedValue acc)
|
|
517
|
+
(setq acc (unreducedValue acc) early t)
|
|
518
|
+
(setq idx (1+ idx)))))
|
|
519
|
+
(let ((cnt (chunk-count-of chunk))
|
|
520
|
+
(idx 0))
|
|
521
|
+
(when (and (< idx cnt) (eq acc NO_INITIAL))
|
|
522
|
+
(setq acc (chunk-nth-of chunk 0) idx 1))
|
|
523
|
+
(while (and (< idx cnt) (not early))
|
|
524
|
+
(setq acc (funcall reducer acc (chunk-nth-of chunk idx)))
|
|
525
|
+
(if (isReducedValue acc)
|
|
526
|
+
(setq acc (unreducedValue acc) early t)
|
|
527
|
+
(setq idx (1+ idx))))))))
|
|
528
|
+
(unless early
|
|
529
|
+
(setq curr (chunked-next-of curr))))
|
|
530
|
+
(let ((iter (sequence-iterator curr))
|
|
531
|
+
(done false))
|
|
532
|
+
(while (and (not done) (not early))
|
|
533
|
+
(let ((step (js-call iter :next)))
|
|
534
|
+
(if (truth (get step :done))
|
|
535
|
+
(setq done t)
|
|
536
|
+
(if (eq acc NO_INITIAL)
|
|
537
|
+
(setq acc (get step :value))
|
|
538
|
+
(progn
|
|
539
|
+
(setq acc (funcall reducer acc (get step :value)))
|
|
540
|
+
(when (isReducedValue acc)
|
|
541
|
+
(setq acc (unreducedValue acc) early t)))))))
|
|
542
|
+
(setq curr nil))))
|
|
543
|
+
(when (eq acc NO_INITIAL)
|
|
544
|
+
(fail "cannot reduce an empty collection without an initial value"))
|
|
545
|
+
acc))
|
|
546
|
+
|
|
547
|
+
(defconst ChunkedCons
|
|
548
|
+
(funcall
|
|
549
|
+
(js* "(init) => class ChunkedCons { constructor(token, chunk, more, countHint) { init(this, token, chunk, more, countHint); } }")
|
|
550
|
+
(lambda (self token chunk more count-hint)
|
|
551
|
+
(unless (eq token CHUNKED_CONS_TOKEN)
|
|
552
|
+
(fail "ChunkedCons values must be created with chunkedCons"))
|
|
553
|
+
(js-call chunked-cons-states :set self
|
|
554
|
+
(js-object
|
|
555
|
+
:chunk chunk
|
|
556
|
+
:more more
|
|
557
|
+
:countHint count-hint
|
|
558
|
+
:moreRealized false
|
|
559
|
+
:cachedMore nil
|
|
560
|
+
:failure no-failure))
|
|
561
|
+
(Object/freeze self))))
|
|
562
|
+
|
|
563
|
+
(defun make-chunked-cons (chunk more &optional count-hint)
|
|
564
|
+
(let ((resolved-hint (if (nullish? count-hint) UNKNOWN_COUNT count-hint)))
|
|
565
|
+
(new ChunkedCons CHUNKED_CONS_TOKEN chunk more resolved-hint)))
|
|
566
|
+
|
|
567
|
+
(defun chunkedCons (chunk more)
|
|
568
|
+
(unless (or (funcall instance-of? chunk ArrayChunk) (implementsProtocol IChunk chunk))
|
|
569
|
+
(fail "chunkedCons expects an IChunk as its first argument"))
|
|
570
|
+
(if (= (chunk-count-of chunk) 0)
|
|
571
|
+
(if (callable? more) (funcall more) (if (nil? more) nil (seq more)))
|
|
572
|
+
(make-chunked-cons chunk more UNKNOWN_COUNT)))
|
|
573
|
+
|
|
574
|
+
(let ((ccproto (get ChunkedCons :prototype)))
|
|
575
|
+
(install-method ccproto CHUNKED_FIRST "[eliscript.chunked-seq.chunkedFirst]" 0
|
|
576
|
+
(lambda (self) (get (js-call chunked-cons-states :get self) :chunk)))
|
|
577
|
+
(install-method ccproto CHUNKED_NEXT "[eliscript.chunked-seq.chunkedNext]" 0
|
|
578
|
+
(lambda (self)
|
|
579
|
+
(let ((next-val (resolve-more-seq (js-call chunked-cons-states :get self))))
|
|
580
|
+
(if (nil? next-val)
|
|
581
|
+
nil
|
|
582
|
+
(if (or (funcall instance-of? next-val ChunkedCons)
|
|
583
|
+
(funcall instance-of? next-val LazyChunkedSeq))
|
|
584
|
+
next-val
|
|
585
|
+
(seq next-val))))))
|
|
586
|
+
(install-method ccproto CHUNKED_MORE "[eliscript.chunked-seq.chunkedMore]" 0
|
|
587
|
+
(lambda (self)
|
|
588
|
+
(let ((next-val (js-call (aref self CHUNKED_NEXT) :call self)))
|
|
589
|
+
(if (nil? next-val) EMPTY_LIST next-val))))
|
|
590
|
+
(install-method ccproto COLLECTION_SEQ "[eliscript.collection.seq]" 0
|
|
591
|
+
(lambda (self) self))
|
|
592
|
+
(install-method ccproto COLLECTION_COUNT "[eliscript.collection.count]" 0
|
|
593
|
+
(lambda (self)
|
|
594
|
+
(let* ((state (js-call chunked-cons-states :get self))
|
|
595
|
+
(hint (get state :countHint)))
|
|
596
|
+
(cond
|
|
597
|
+
((eq hint UNBOUNDED_SEQUENCE)
|
|
598
|
+
(range-fail "unbounded sequence does not have a finite count"))
|
|
599
|
+
((not (eq hint UNKNOWN_COUNT)) hint)
|
|
600
|
+
(t
|
|
601
|
+
(let ((computed (chunked-seq-count self)))
|
|
602
|
+
(put state "countHint" computed)
|
|
603
|
+
computed))))))
|
|
604
|
+
(install-method ccproto COLLECTION_REDUCE "[eliscript.collection.reduce]" 1
|
|
605
|
+
(lambda (self reducer &rest initial)
|
|
606
|
+
(reduce-chunked-seq self reducer initial)))
|
|
607
|
+
(install-method ccproto iterator-symbol "[Symbol.iterator]" 0
|
|
608
|
+
(lambda (self) (chunked-seq-iterator self)))
|
|
609
|
+
(install-getter ccproto (get globalThis/Symbol :toStringTag) "[Symbol.toStringTag]"
|
|
610
|
+
(lambda (_self) "EliscriptChunkedCons")))
|
|
611
|
+
|
|
612
|
+
(defconst LazyChunkedSeq
|
|
613
|
+
(funcall
|
|
614
|
+
(js* "(init) => class LazyChunkedSeq { constructor(token, thunk, countHint) { init(this, token, thunk, countHint); } }")
|
|
615
|
+
(lambda (self token thunk count-hint)
|
|
616
|
+
(unless (eq token LAZY_CHUNKED_TOKEN)
|
|
617
|
+
(fail "LazyChunkedSeq values must be created with lazyChunkedSeq"))
|
|
618
|
+
(js-call lazy-chunked-states :set self
|
|
619
|
+
(js-object
|
|
620
|
+
:thunk thunk
|
|
621
|
+
:countHint count-hint
|
|
622
|
+
:started false
|
|
623
|
+
:value nil
|
|
624
|
+
:failure no-failure))
|
|
625
|
+
(Object/freeze self))))
|
|
626
|
+
|
|
627
|
+
(defun make-lazy-chunked (thunk &optional count-hint)
|
|
628
|
+
(new LazyChunkedSeq LAZY_CHUNKED_TOKEN thunk
|
|
629
|
+
(if (nullish? count-hint) UNKNOWN_COUNT count-hint)))
|
|
630
|
+
|
|
631
|
+
(let ((lcproto (get LazyChunkedSeq :prototype)))
|
|
632
|
+
(install-method lcproto CHUNKED_FIRST "[eliscript.chunked-seq.chunkedFirst]" 0
|
|
633
|
+
(lambda (self)
|
|
634
|
+
(let ((resolved (resolve-lazy-chunk self)))
|
|
635
|
+
(if (nil? resolved) nil (chunked-first-of resolved)))))
|
|
636
|
+
(install-method lcproto CHUNKED_NEXT "[eliscript.chunked-seq.chunkedNext]" 0
|
|
637
|
+
(lambda (self)
|
|
638
|
+
(let ((resolved (resolve-lazy-chunk self)))
|
|
639
|
+
(if (nil? resolved) nil (chunked-next-of resolved)))))
|
|
640
|
+
(install-method lcproto CHUNKED_MORE "[eliscript.chunked-seq.chunkedMore]" 0
|
|
641
|
+
(lambda (self)
|
|
642
|
+
(let ((next-val (js-call (aref self CHUNKED_NEXT) :call self)))
|
|
643
|
+
(if (nil? next-val) EMPTY_LIST next-val))))
|
|
644
|
+
(install-method lcproto COLLECTION_SEQ "[eliscript.collection.seq]" 0
|
|
645
|
+
(lambda (self)
|
|
646
|
+
(let ((state (js-call lazy-chunked-states :get self)))
|
|
647
|
+
(if (eq (get state :countHint) UNBOUNDED_SEQUENCE)
|
|
648
|
+
self
|
|
649
|
+
(let ((resolved (resolve-lazy-chunk self)))
|
|
650
|
+
(if (nil? resolved) nil self))))))
|
|
651
|
+
(install-method lcproto COLLECTION_COUNT "[eliscript.collection.count]" 0
|
|
652
|
+
(lambda (self)
|
|
653
|
+
(let* ((state (js-call lazy-chunked-states :get self))
|
|
654
|
+
(hint (get state :countHint)))
|
|
655
|
+
(cond
|
|
656
|
+
((eq hint UNBOUNDED_SEQUENCE)
|
|
657
|
+
(range-fail "unbounded sequence does not have a finite count"))
|
|
658
|
+
((not (eq hint UNKNOWN_COUNT)) hint)
|
|
659
|
+
(t
|
|
660
|
+
(let ((computed (chunked-seq-count self)))
|
|
661
|
+
(put state "countHint" computed)
|
|
662
|
+
computed))))))
|
|
663
|
+
(install-method lcproto COLLECTION_REDUCE "[eliscript.collection.reduce]" 1
|
|
664
|
+
(lambda (self reducer &rest initial)
|
|
665
|
+
(reduce-chunked-seq self reducer initial)))
|
|
666
|
+
(install-method lcproto iterator-symbol "[Symbol.iterator]" 0
|
|
667
|
+
(lambda (self) (chunked-seq-iterator self)))
|
|
668
|
+
(install-getter lcproto (get globalThis/Symbol :toStringTag) "[Symbol.toStringTag]"
|
|
669
|
+
(lambda (_self) "EliscriptLazyChunkedSeq")))
|
|
670
|
+
|
|
671
|
+
(defun build-range-cons (start step total offset)
|
|
672
|
+
(if (and (not (eq total UNBOUNDED_SEQUENCE)) (>= offset total))
|
|
673
|
+
nil
|
|
674
|
+
(let* ((remaining (if (eq total UNBOUNDED_SEQUENCE) CHUNK_SIZE (Math/min CHUNK_SIZE (- total offset))))
|
|
675
|
+
(items (new globalThis/Array remaining))
|
|
676
|
+
(i 0))
|
|
677
|
+
(while (< i remaining)
|
|
678
|
+
(put items i (+ start (* (+ offset i) step)))
|
|
679
|
+
(setq i (1+ i)))
|
|
680
|
+
(Object/freeze items)
|
|
681
|
+
(let ((next-offset (+ offset remaining))
|
|
682
|
+
(hint (if (eq total UNBOUNDED_SEQUENCE) UNBOUNDED_SEQUENCE (- total offset))))
|
|
683
|
+
(make-chunked-cons
|
|
684
|
+
(array-chunk-owned items 0 remaining)
|
|
685
|
+
(if (or (eq total UNBOUNDED_SEQUENCE) (< next-offset total))
|
|
686
|
+
(lambda () (build-range-cons start step total next-offset))
|
|
687
|
+
nil)
|
|
688
|
+
hint)))))
|
|
689
|
+
|
|
690
|
+
(defun chunkedRange (&rest bounds)
|
|
691
|
+
(when (> (js-length bounds) 3)
|
|
692
|
+
(fail "range expects zero to three arguments"))
|
|
693
|
+
(if (= (js-length bounds) 0)
|
|
694
|
+
(make-lazy-chunked (lambda () (build-range-cons 0 1 UNBOUNDED_SEQUENCE 0)) UNBOUNDED_SEQUENCE)
|
|
695
|
+
(let* ((start (require-finite (if (= (js-length bounds) 1) 0 (aref bounds 0)) "range start"))
|
|
696
|
+
(end (require-finite (if (= (js-length bounds) 1) (aref bounds 0) (aref bounds 1)) "range end"))
|
|
697
|
+
(step (require-finite (if (= (js-length bounds) 3) (aref bounds 2) 1) "range step")))
|
|
698
|
+
(when (= step 0)
|
|
699
|
+
(fail "range step must be non-zero"))
|
|
700
|
+
(let* ((distance (/ (- end start) step))
|
|
701
|
+
(length (if (> distance 0)
|
|
702
|
+
(require-nonnegative (Math/ceil distance) "range count")
|
|
703
|
+
0)))
|
|
704
|
+
(if (= length 0)
|
|
705
|
+
nil
|
|
706
|
+
(make-lazy-chunked (lambda () (build-range-cons start step length 0)) length))))))
|
|
707
|
+
|
|
708
|
+
(defun build-repeat-cons (value remaining)
|
|
709
|
+
(if (and (not (eq remaining UNBOUNDED_SEQUENCE)) (<= remaining 0))
|
|
710
|
+
nil
|
|
711
|
+
(let* ((batch (if (eq remaining UNBOUNDED_SEQUENCE) CHUNK_SIZE (Math/min CHUNK_SIZE remaining)))
|
|
712
|
+
(items (new globalThis/Array batch))
|
|
713
|
+
(i 0))
|
|
714
|
+
(while (< i batch)
|
|
715
|
+
(put items i value)
|
|
716
|
+
(setq i (1+ i)))
|
|
717
|
+
(Object/freeze items)
|
|
718
|
+
(let ((next-rem (if (eq remaining UNBOUNDED_SEQUENCE) UNBOUNDED_SEQUENCE (- remaining batch))))
|
|
719
|
+
(make-chunked-cons
|
|
720
|
+
(array-chunk-owned items 0 batch)
|
|
721
|
+
(if (or (eq next-rem UNBOUNDED_SEQUENCE) (> next-rem 0))
|
|
722
|
+
(lambda () (build-repeat-cons value next-rem))
|
|
723
|
+
nil)
|
|
724
|
+
remaining)))))
|
|
725
|
+
|
|
726
|
+
(defun chunkedRepeat (&rest arguments)
|
|
727
|
+
(cond
|
|
728
|
+
((= (js-length arguments) 1)
|
|
729
|
+
(let ((value (aref arguments 0)))
|
|
730
|
+
(make-lazy-chunked (lambda () (build-repeat-cons value UNBOUNDED_SEQUENCE)) UNBOUNDED_SEQUENCE)))
|
|
731
|
+
((= (js-length arguments) 2)
|
|
732
|
+
(let ((length (require-nonnegative (aref arguments 0) "repeat count"))
|
|
733
|
+
(value (aref arguments 1)))
|
|
734
|
+
(if (= length 0)
|
|
735
|
+
nil
|
|
736
|
+
(make-lazy-chunked (lambda () (build-repeat-cons value length)) length))))
|
|
737
|
+
(t (fail "repeat expects a value or a count and value"))))
|
|
738
|
+
|
|
739
|
+
(defun chunked-map-seq (transform source)
|
|
740
|
+
(let ((unbounded (and (funcall instance-of? source LazyChunkedSeq)
|
|
741
|
+
(eq (get (js-call lazy-chunked-states :get source) :countHint) UNBOUNDED_SEQUENCE))))
|
|
742
|
+
(make-lazy-chunked
|
|
743
|
+
(lambda ()
|
|
744
|
+
(let ((resolved (normalize-chunk-head source)))
|
|
745
|
+
(if (nil? resolved)
|
|
746
|
+
nil
|
|
747
|
+
(if (isChunkedSeq resolved)
|
|
748
|
+
(let* ((chunk (chunked-first-of resolved))
|
|
749
|
+
(cnt (chunk-count-of chunk))
|
|
750
|
+
(buf (chunkBuffer cnt))
|
|
751
|
+
(cstate (chunk-state chunk)))
|
|
752
|
+
(if (not (undefined? cstate))
|
|
753
|
+
(let ((arr (get cstate :array))
|
|
754
|
+
(i (get cstate :off))
|
|
755
|
+
(end (get cstate :end)))
|
|
756
|
+
(while (< i end)
|
|
757
|
+
(chunkAppend buf (funcall transform (aref arr i)))
|
|
758
|
+
(setq i (1+ i))))
|
|
759
|
+
(let ((i 0))
|
|
760
|
+
(while (< i cnt)
|
|
761
|
+
(chunkAppend buf (funcall transform (chunk-nth-of chunk i)))
|
|
762
|
+
(setq i (1+ i)))))
|
|
763
|
+
(let ((rest-seq (chunked-next-of resolved)))
|
|
764
|
+
(make-chunked-cons
|
|
765
|
+
(chunkFromBuffer buf)
|
|
766
|
+
(if (nil? rest-seq) nil (lambda () (chunked-map-seq transform rest-seq)))
|
|
767
|
+
(if unbounded UNBOUNDED_SEQUENCE UNKNOWN_COUNT))))
|
|
768
|
+
(sequence (mapping transform) resolved)))))
|
|
769
|
+
(if unbounded UNBOUNDED_SEQUENCE UNKNOWN_COUNT))))
|
|
770
|
+
|
|
771
|
+
(defun chunked-filter-seq (predicate source)
|
|
772
|
+
(make-lazy-chunked
|
|
773
|
+
(lambda ()
|
|
774
|
+
(let ((curr (normalize-chunk-head source))
|
|
775
|
+
(result nil)
|
|
776
|
+
(done false))
|
|
777
|
+
(while (and (not (nil? curr)) (not done))
|
|
778
|
+
(if (isChunkedSeq curr)
|
|
779
|
+
(let* ((chunk (chunked-first-of curr))
|
|
780
|
+
(cnt (chunk-count-of chunk))
|
|
781
|
+
(buf (chunkBuffer cnt))
|
|
782
|
+
(cstate (chunk-state chunk)))
|
|
783
|
+
(if (not (undefined? cstate))
|
|
784
|
+
(let ((arr (get cstate :array))
|
|
785
|
+
(i (get cstate :off))
|
|
786
|
+
(end (get cstate :end)))
|
|
787
|
+
(while (< i end)
|
|
788
|
+
(let ((item (aref arr i)))
|
|
789
|
+
(when (truth (isTruthy (funcall predicate item)))
|
|
790
|
+
(chunkAppend buf item)))
|
|
791
|
+
(setq i (1+ i))))
|
|
792
|
+
(let ((i 0))
|
|
793
|
+
(while (< i cnt)
|
|
794
|
+
(let ((item (chunk-nth-of chunk i)))
|
|
795
|
+
(when (truth (isTruthy (funcall predicate item)))
|
|
796
|
+
(chunkAppend buf item)))
|
|
797
|
+
(setq i (1+ i)))))
|
|
798
|
+
(let ((next-curr (chunked-next-of curr)))
|
|
799
|
+
(if (> (get buf :count) 0)
|
|
800
|
+
(setq result (make-chunked-cons
|
|
801
|
+
(chunkFromBuffer buf)
|
|
802
|
+
(if (nil? next-curr) nil (lambda () (chunked-filter-seq predicate next-curr))))
|
|
803
|
+
done t)
|
|
804
|
+
(setq curr next-curr))))
|
|
805
|
+
(setq result (sequence (filtering predicate) curr)
|
|
806
|
+
done t)))
|
|
807
|
+
result))))
|
|
808
|
+
|
|
809
|
+
(defun chunked-keep-seq (transform source)
|
|
810
|
+
(make-lazy-chunked
|
|
811
|
+
(lambda ()
|
|
812
|
+
(let ((curr (normalize-chunk-head source))
|
|
813
|
+
(result nil)
|
|
814
|
+
(done false))
|
|
815
|
+
(while (and (not (nil? curr)) (not done))
|
|
816
|
+
(if (isChunkedSeq curr)
|
|
817
|
+
(let* ((chunk (chunked-first-of curr))
|
|
818
|
+
(cnt (chunk-count-of chunk))
|
|
819
|
+
(buf (chunkBuffer cnt))
|
|
820
|
+
(cstate (chunk-state chunk)))
|
|
821
|
+
(if (not (undefined? cstate))
|
|
822
|
+
(let ((arr (get cstate :array))
|
|
823
|
+
(i (get cstate :off))
|
|
824
|
+
(end (get cstate :end)))
|
|
825
|
+
(while (< i end)
|
|
826
|
+
(let ((kept (funcall transform (aref arr i))))
|
|
827
|
+
(unless (nil? kept)
|
|
828
|
+
(chunkAppend buf kept)))
|
|
829
|
+
(setq i (1+ i))))
|
|
830
|
+
(let ((i 0))
|
|
831
|
+
(while (< i cnt)
|
|
832
|
+
(let ((kept (funcall transform (chunk-nth-of chunk i))))
|
|
833
|
+
(unless (nil? kept)
|
|
834
|
+
(chunkAppend buf kept)))
|
|
835
|
+
(setq i (1+ i)))))
|
|
836
|
+
(let ((next-curr (chunked-next-of curr)))
|
|
837
|
+
(if (> (get buf :count) 0)
|
|
838
|
+
(setq result (make-chunked-cons
|
|
839
|
+
(chunkFromBuffer buf)
|
|
840
|
+
(if (nil? next-curr) nil (lambda () (chunked-keep-seq transform next-curr))))
|
|
841
|
+
done t)
|
|
842
|
+
(setq curr next-curr))))
|
|
843
|
+
(setq result (sequence (keeping transform) curr)
|
|
844
|
+
done t)))
|
|
845
|
+
result))))
|
|
846
|
+
|
|
847
|
+
(defun chunked-take-seq (limit source)
|
|
848
|
+
(if (= limit 0)
|
|
849
|
+
(make-lazy-chunked (lambda () nil) 0)
|
|
850
|
+
(make-lazy-chunked
|
|
851
|
+
(lambda ()
|
|
852
|
+
(let ((resolved (normalize-chunk-head source)))
|
|
853
|
+
(if (nil? resolved)
|
|
854
|
+
nil
|
|
855
|
+
(if (isChunkedSeq resolved)
|
|
856
|
+
(let* ((chunk (chunked-first-of resolved))
|
|
857
|
+
(cnt (chunk-count-of chunk))
|
|
858
|
+
(take-cnt (Math/min limit cnt))
|
|
859
|
+
(buf (chunkBuffer take-cnt))
|
|
860
|
+
(cstate (chunk-state chunk)))
|
|
861
|
+
(if (not (undefined? cstate))
|
|
862
|
+
(let ((arr (get cstate :array))
|
|
863
|
+
(off (get cstate :off))
|
|
864
|
+
(i 0))
|
|
865
|
+
(while (< i take-cnt)
|
|
866
|
+
(chunkAppend buf (aref arr (+ off i)))
|
|
867
|
+
(setq i (1+ i))))
|
|
868
|
+
(let ((i 0))
|
|
869
|
+
(while (< i take-cnt)
|
|
870
|
+
(chunkAppend buf (chunk-nth-of chunk i))
|
|
871
|
+
(setq i (1+ i)))))
|
|
872
|
+
(let ((rem (- limit take-cnt))
|
|
873
|
+
(next-src (chunked-next-of resolved)))
|
|
874
|
+
(make-chunked-cons
|
|
875
|
+
(chunkFromBuffer buf)
|
|
876
|
+
(if (or (= rem 0) (nil? next-src)) nil (lambda () (chunked-take-seq rem next-src))))))
|
|
877
|
+
(sequence (taking limit) resolved))))))))
|
|
878
|
+
|
|
879
|
+
(defun chunked-drop-seq (limit source)
|
|
880
|
+
(if (= limit 0)
|
|
881
|
+
source
|
|
882
|
+
(let ((unbounded (and (funcall instance-of? source LazyChunkedSeq)
|
|
883
|
+
(eq (get (js-call lazy-chunked-states :get source) :countHint) UNBOUNDED_SEQUENCE))))
|
|
884
|
+
(make-lazy-chunked
|
|
885
|
+
(lambda ()
|
|
886
|
+
(let ((rem limit)
|
|
887
|
+
(curr (normalize-chunk-head source))
|
|
888
|
+
(result nil)
|
|
889
|
+
(done false))
|
|
890
|
+
(while (and (> rem 0) (not (nil? curr)) (not done))
|
|
891
|
+
(if (isChunkedSeq curr)
|
|
892
|
+
(let* ((chunk (chunked-first-of curr))
|
|
893
|
+
(cnt (chunk-count-of chunk)))
|
|
894
|
+
(if (<= cnt rem)
|
|
895
|
+
(setq rem (- rem cnt)
|
|
896
|
+
curr (chunked-next-of curr))
|
|
897
|
+
(let ((trimmed chunk))
|
|
898
|
+
(while (> rem 0)
|
|
899
|
+
(setq trimmed (chunk-drop-first-of trimmed)
|
|
900
|
+
rem (1- rem)))
|
|
901
|
+
(setq result (make-chunked-cons trimmed (chunked-next-of curr)
|
|
902
|
+
(if unbounded UNBOUNDED_SEQUENCE UNKNOWN_COUNT))
|
|
903
|
+
done t))))
|
|
904
|
+
(setq result (sequence (dropping rem) curr)
|
|
905
|
+
done t)))
|
|
906
|
+
(if done result curr)))
|
|
907
|
+
(if unbounded UNBOUNDED_SEQUENCE UNKNOWN_COUNT)))))
|
|
908
|
+
|
|
909
|
+
(registerChunkedSliceHandler
|
|
910
|
+
(lambda (source offset)
|
|
911
|
+
(chunked-drop-seq offset source)))
|
|
912
|
+
|
|
913
|
+
(registerChunkedPrependHandler
|
|
914
|
+
(lambda (value source)
|
|
915
|
+
(let* ((items (Object/freeze (js-array value)))
|
|
916
|
+
(single (array-chunk-owned items 0 1))
|
|
917
|
+
(unbounded (and (funcall instance-of? source LazyChunkedSeq)
|
|
918
|
+
(eq (get (js-call lazy-chunked-states :get source) :countHint) UNBOUNDED_SEQUENCE))))
|
|
919
|
+
(make-chunked-cons single source (if unbounded UNBOUNDED_SEQUENCE UNKNOWN_COUNT)))))
|
|
920
|
+
|
|
921
|
+
;; Existing non-chunked lazy sequence & lazyCons path
|
|
118
922
|
(defun lazySequence (&rest arguments)
|
|
119
923
|
(unless (= (js-length arguments) 1)
|
|
120
924
|
(fail "lazySequence requires exactly one thunk"))
|
|
@@ -140,7 +944,13 @@
|
|
|
140
944
|
|
|
141
945
|
(defun lazyMap (&rest arguments)
|
|
142
946
|
(require-arity (js-length arguments) 2 "lazyMap")
|
|
143
|
-
(
|
|
947
|
+
(let ((transform (get arguments 0))
|
|
948
|
+
(collection (get arguments 1)))
|
|
949
|
+
(if (isChunkedSeq collection)
|
|
950
|
+
(progn
|
|
951
|
+
(unless (callable? transform) (mapping transform))
|
|
952
|
+
(chunked-map-seq transform collection))
|
|
953
|
+
(sequence (mapping transform) collection))))
|
|
144
954
|
|
|
145
955
|
(defun lazyMapIndexed (&rest arguments)
|
|
146
956
|
(require-arity (js-length arguments) 2 "lazyMapIndexed")
|
|
@@ -148,7 +958,13 @@
|
|
|
148
958
|
|
|
149
959
|
(defun lazyKeep (&rest arguments)
|
|
150
960
|
(require-arity (js-length arguments) 2 "lazyKeep")
|
|
151
|
-
(
|
|
961
|
+
(let ((transform (get arguments 0))
|
|
962
|
+
(collection (get arguments 1)))
|
|
963
|
+
(if (isChunkedSeq collection)
|
|
964
|
+
(progn
|
|
965
|
+
(unless (callable? transform) (keeping transform))
|
|
966
|
+
(chunked-keep-seq transform collection))
|
|
967
|
+
(sequence (keeping transform) collection))))
|
|
152
968
|
|
|
153
969
|
(defun lazyKeepIndexed (&rest arguments)
|
|
154
970
|
(require-arity (js-length arguments) 2 "lazyKeepIndexed")
|
|
@@ -156,7 +972,13 @@
|
|
|
156
972
|
|
|
157
973
|
(defun lazyFilter (&rest arguments)
|
|
158
974
|
(require-arity (js-length arguments) 2 "lazyFilter")
|
|
159
|
-
(
|
|
975
|
+
(let ((predicate (get arguments 0))
|
|
976
|
+
(collection (get arguments 1)))
|
|
977
|
+
(if (isChunkedSeq collection)
|
|
978
|
+
(progn
|
|
979
|
+
(unless (callable? predicate) (filtering predicate))
|
|
980
|
+
(chunked-filter-seq predicate collection))
|
|
981
|
+
(sequence (filtering predicate) collection))))
|
|
160
982
|
|
|
161
983
|
(defun lazyRemove (&rest arguments)
|
|
162
984
|
(require-arity (js-length arguments) 2 "lazyRemove")
|
|
@@ -164,11 +986,25 @@
|
|
|
164
986
|
|
|
165
987
|
(defun lazyTake (&rest arguments)
|
|
166
988
|
(require-arity (js-length arguments) 2 "lazyTake")
|
|
167
|
-
(
|
|
989
|
+
(let ((limit (get arguments 0))
|
|
990
|
+
(collection (get arguments 1)))
|
|
991
|
+
(if (isChunkedSeq collection)
|
|
992
|
+
(progn
|
|
993
|
+
(unless (and (Number/isSafeInteger limit) (>= limit 0))
|
|
994
|
+
(taking limit))
|
|
995
|
+
(chunked-take-seq limit collection))
|
|
996
|
+
(sequence (taking limit) collection))))
|
|
168
997
|
|
|
169
998
|
(defun lazyDrop (&rest arguments)
|
|
170
999
|
(require-arity (js-length arguments) 2 "lazyDrop")
|
|
171
|
-
(
|
|
1000
|
+
(let ((limit (get arguments 0))
|
|
1001
|
+
(collection (get arguments 1)))
|
|
1002
|
+
(if (isChunkedSeq collection)
|
|
1003
|
+
(progn
|
|
1004
|
+
(unless (and (Number/isSafeInteger limit) (>= limit 0))
|
|
1005
|
+
(dropping limit))
|
|
1006
|
+
(chunked-drop-seq limit collection))
|
|
1007
|
+
(sequence (dropping limit) collection))))
|
|
172
1008
|
|
|
173
1009
|
(defun lazyTakeWhile (&rest arguments)
|
|
174
1010
|
(require-arity (js-length arguments) 2 "lazyTakeWhile")
|
|
@@ -207,12 +1043,34 @@
|
|
|
207
1043
|
(sequence (partitioningBy (get arguments 0)) (get arguments 1)))
|
|
208
1044
|
|
|
209
1045
|
(defun isLazySequence (value)
|
|
210
|
-
(funcall instance-of? value MemoizedSequenceView)
|
|
1046
|
+
(or (funcall instance-of? value MemoizedSequenceView)
|
|
1047
|
+
(funcall instance-of? value LazyChunkedSeq)
|
|
1048
|
+
(funcall instance-of? value ChunkedCons)))
|
|
211
1049
|
|
|
212
1050
|
(defun status (value)
|
|
213
|
-
(
|
|
214
|
-
(
|
|
215
|
-
|
|
1051
|
+
(cond
|
|
1052
|
+
((funcall instance-of? value MemoizedSequenceView)
|
|
1053
|
+
(memoizedSequenceStatus value))
|
|
1054
|
+
((funcall instance-of? value LazyChunkedSeq)
|
|
1055
|
+
(let ((state (js-call lazy-chunked-states :get value)))
|
|
1056
|
+
(Object/freeze
|
|
1057
|
+
(js-object
|
|
1058
|
+
:started (get state :started)
|
|
1059
|
+
:complete (and (get state :started) (nil? (get state :value)))
|
|
1060
|
+
:failed (not (eq (get state :failure) no-failure))
|
|
1061
|
+
:realizedCount (if (and (get state :started) (not (nil? (get state :value))))
|
|
1062
|
+
(let ((chunk (chunked-first-of (get state :value))))
|
|
1063
|
+
(if (nil? chunk) 0 (chunk-count-of chunk)))
|
|
1064
|
+
0)))))
|
|
1065
|
+
((funcall instance-of? value ChunkedCons)
|
|
1066
|
+
(let ((state (js-call chunked-cons-states :get value)))
|
|
1067
|
+
(Object/freeze
|
|
1068
|
+
(js-object
|
|
1069
|
+
:started t
|
|
1070
|
+
:complete (and (get state :moreRealized) (nil? (get state :cachedMore)))
|
|
1071
|
+
:failed (not (eq (get state :failure) no-failure))
|
|
1072
|
+
:realizedCount (chunk-count-of (get state :chunk))))))
|
|
1073
|
+
(t (fail "operation requires a lazy sequence"))))
|
|
216
1074
|
|
|
217
1075
|
(defun isLazySequenceRealized (value)
|
|
218
1076
|
(get (status value) :started))
|
|
@@ -222,7 +1080,7 @@
|
|
|
222
1080
|
|
|
223
1081
|
(defun realizeLazySequence (value)
|
|
224
1082
|
(status value)
|
|
225
|
-
(let ((iterator (js-call (aref value
|
|
1083
|
+
(let ((iterator (js-call (aref value iterator-symbol) :call value))
|
|
226
1084
|
(done false))
|
|
227
1085
|
(while (not done)
|
|
228
1086
|
(let ((step (js-call iterator :next)))
|
|
@@ -251,6 +1109,18 @@
|
|
|
251
1109
|
(Object/defineProperty lazyPartitionBy "length" (js-object :value 2 :configurable t))
|
|
252
1110
|
|
|
253
1111
|
(export
|
|
1112
|
+
CHUNK_SIZE
|
|
1113
|
+
ArrayChunk
|
|
1114
|
+
ChunkBuffer
|
|
1115
|
+
ChunkedCons
|
|
1116
|
+
LazyChunkedSeq
|
|
1117
|
+
arrayChunk
|
|
1118
|
+
chunkBuffer
|
|
1119
|
+
chunkAppend
|
|
1120
|
+
chunkFromBuffer
|
|
1121
|
+
chunkedCons
|
|
1122
|
+
chunkedRange
|
|
1123
|
+
chunkedRepeat
|
|
254
1124
|
lazySequence
|
|
255
1125
|
lazyCons
|
|
256
1126
|
lazyMap
|