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
|
@@ -0,0 +1,2828 @@
|
|
|
1
|
+
// Generated by Eliscript. Do not edit.
|
|
2
|
+
import { tdz as __eliscript_tdz_error, immutable as __eliscript_const_error } from "eliscript/runtime/errors.mjs";
|
|
3
|
+
var __eliscript_tdz_ready_0;
|
|
4
|
+
var __eliscript_tdz_ready_1;
|
|
5
|
+
var __eliscript_tdz_ready_2;
|
|
6
|
+
var __eliscript_tdz_ready_3;
|
|
7
|
+
var __eliscript_tdz_ready_4;
|
|
8
|
+
var __eliscript_tdz_ready_5;
|
|
9
|
+
var __eliscript_tdz_ready_6;
|
|
10
|
+
var __eliscript_tdz_ready_7;
|
|
11
|
+
var __eliscript_tdz_ready_8;
|
|
12
|
+
var __eliscript_tdz_ready_9;
|
|
13
|
+
var __eliscript_tdz_ready_10;
|
|
14
|
+
var __eliscript_tdz_ready_11;
|
|
15
|
+
var __eliscript_tdz_ready_12;
|
|
16
|
+
var __eliscript_tdz_ready_13;
|
|
17
|
+
var __eliscript_tdz_ready_14;
|
|
18
|
+
var __eliscript_tdz_ready_15;
|
|
19
|
+
var __eliscript_tdz_ready_16;
|
|
20
|
+
var __eliscript_tdz_ready_17;
|
|
21
|
+
var __eliscript_tdz_ready_18;
|
|
22
|
+
var __eliscript_tdz_ready_19;
|
|
23
|
+
var __eliscript_tdz_ready_20;
|
|
24
|
+
var __eliscript_tdz_ready_21;
|
|
25
|
+
var __eliscript_tdz_ready_22;
|
|
26
|
+
var __eliscript_tdz_ready_24;
|
|
27
|
+
import "eliscript/runtime/unicode-case.mjs";
|
|
28
|
+
import "eliscript/runtime/math.mjs";
|
|
29
|
+
import { __eliscript_at, __eliscript_at_direct, __eliscript_to_number, __eliscript_numeric_decrement, __eliscript_numeric_relation, __eliscript_numeric_sub, __eliscript_numeric_mul, __eliscript_numeric_div, __eliscript_numeric_rem, __eliscript_numeric_and, __eliscript_numeric_or, __eliscript_numeric_xor, __eliscript_numeric_shl, __eliscript_numeric_shr, __eliscript_numeric_ushr, __eliscript_numeric_neg, __eliscript_numeric_int32, __eliscript_numeric_uint32, __eliscript_numeric_not, __eliscript_numeric_imul } from "eliscript/runtime/prelude.mjs";
|
|
30
|
+
import { valueType as __eliscript_value_type } from "eliscript/runtime/primitives.mjs";
|
|
31
|
+
const __eliscript_truthy = (value) => value !== false && value != null;
|
|
32
|
+
|
|
33
|
+
import * as Collection from "../../runtime/core/collection.mjs";
|
|
34
|
+
import {printValue} from "../../runtime/core/data-text.mjs";
|
|
35
|
+
import {eliscriptSymbol, isEliscriptSymbol, isIdentifier, isKeyword, keyword, qualifiedIdentifierName} from "../../runtime/core/identifier.mjs";
|
|
36
|
+
import {persistentList} from "../../runtime/core/list.mjs";
|
|
37
|
+
import {EMPTY_MAP} from "../../runtime/core/map.mjs";
|
|
38
|
+
import {persistentHashSet} from "../../runtime/core/set.mjs";
|
|
39
|
+
import {equalValues} from "../../runtime/core/value.mjs";
|
|
40
|
+
import {EMPTY_VECTOR, PersistentVector, persistentVector} from "../../runtime/core/vector.mjs";
|
|
41
|
+
const INVALID = keyword("eliscript.schema", "invalid");
|
|
42
|
+
__eliscript_tdz_ready_0 = true;
|
|
43
|
+
const KW_SCHEMA = keyword("eliscript.schema", "schema");
|
|
44
|
+
__eliscript_tdz_ready_1 = true;
|
|
45
|
+
const KW_VALUE = keyword("eliscript.schema", "value");
|
|
46
|
+
__eliscript_tdz_ready_2 = true;
|
|
47
|
+
const KW_PROBLEMS = keyword("eliscript.schema", "problems");
|
|
48
|
+
__eliscript_tdz_ready_3 = true;
|
|
49
|
+
const KW_PATH = keyword("eliscript.schema", "path");
|
|
50
|
+
__eliscript_tdz_ready_4 = true;
|
|
51
|
+
const KW_PRED = keyword("eliscript.schema", "pred");
|
|
52
|
+
__eliscript_tdz_ready_5 = true;
|
|
53
|
+
const KW_VAL = keyword("eliscript.schema", "val");
|
|
54
|
+
__eliscript_tdz_ready_6 = true;
|
|
55
|
+
const KW_VIA = keyword("eliscript.schema", "via");
|
|
56
|
+
__eliscript_tdz_ready_7 = true;
|
|
57
|
+
const KW_IN = keyword("eliscript.schema", "in");
|
|
58
|
+
__eliscript_tdz_ready_8 = true;
|
|
59
|
+
const KW_REASON = keyword("eliscript.schema", "reason");
|
|
60
|
+
__eliscript_tdz_ready_9 = true;
|
|
61
|
+
const KW_OK = keyword("ok?");
|
|
62
|
+
__eliscript_tdz_ready_10 = true;
|
|
63
|
+
const KW_SEED = keyword("seed");
|
|
64
|
+
__eliscript_tdz_ready_11 = true;
|
|
65
|
+
const KW_NUM_TESTS = keyword("num-tests");
|
|
66
|
+
__eliscript_tdz_ready_12 = true;
|
|
67
|
+
const KW_FAIL = keyword("fail");
|
|
68
|
+
__eliscript_tdz_ready_13 = true;
|
|
69
|
+
const KW_SHRUNK = keyword("shrunk");
|
|
70
|
+
__eliscript_tdz_ready_14 = true;
|
|
71
|
+
const KW_SMALLEST = keyword("smallest");
|
|
72
|
+
__eliscript_tdz_ready_15 = true;
|
|
73
|
+
const KW_STEPS = keyword("steps");
|
|
74
|
+
__eliscript_tdz_ready_16 = true;
|
|
75
|
+
const KW_DEPTH = keyword("depth");
|
|
76
|
+
__eliscript_tdz_ready_17 = true;
|
|
77
|
+
const KW_ERROR = keyword("error");
|
|
78
|
+
__eliscript_tdz_ready_18 = true;
|
|
79
|
+
const MISSING = ({});
|
|
80
|
+
__eliscript_tdz_ready_19 = true;
|
|
81
|
+
const REGISTRY = new (globalThis.Map)();
|
|
82
|
+
__eliscript_tdz_ready_20 = true;
|
|
83
|
+
const Schema = (class Schema { constructor(kind, name, config, customGen, meta) { this.kind = kind; this.name = name; this.config = config; this.customGen = customGen || null; this.meta = meta || null; Object.freeze(this); } });
|
|
84
|
+
__eliscript_tdz_ready_21 = true;
|
|
85
|
+
const SchemaGen = (class SchemaGen { constructor(name, sampleFn) { this.name = name; this.sampleFn = sampleFn; Object.freeze(this); } });
|
|
86
|
+
__eliscript_tdz_ready_22 = true;
|
|
87
|
+
function schema_QMARK_(value) {
|
|
88
|
+
return value instanceof Schema;
|
|
89
|
+
}
|
|
90
|
+
function gen_QMARK_(value) {
|
|
91
|
+
return value instanceof SchemaGen;
|
|
92
|
+
}
|
|
93
|
+
function invalid_QMARK_(value) {
|
|
94
|
+
return equalValues(value, (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID")));
|
|
95
|
+
}
|
|
96
|
+
function kv_map(...kvs) {
|
|
97
|
+
{
|
|
98
|
+
let out = EMPTY_MAP;
|
|
99
|
+
let i = 0;
|
|
100
|
+
let len = ((kvs) ?? []).length;
|
|
101
|
+
while (__eliscript_numeric_relation("<", (i + 1), len)) {
|
|
102
|
+
((out = Collection.assoc(out, (kvs)[i], (kvs)[(i + 1)])));
|
|
103
|
+
((i = (i + 2)));
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function truthy_QMARK_(value) {
|
|
109
|
+
return (!((value === null) || (value === undefined) || (value === false)));
|
|
110
|
+
}
|
|
111
|
+
function make_schema(kind, name, config, custom_gen = null, meta = null) {
|
|
112
|
+
return new ((__eliscript_tdz_ready_21 === true ? Schema : __eliscript_tdz_error("Schema")))(kind, name, config, ((custom_gen == null) ? null : custom_gen), ((meta == null) ? null : meta));
|
|
113
|
+
}
|
|
114
|
+
function make_gen(name, sample_fn) {
|
|
115
|
+
return new ((__eliscript_tdz_ready_22 === true ? SchemaGen : __eliscript_tdz_error("SchemaGen")))(name, sample_fn);
|
|
116
|
+
}
|
|
117
|
+
function read_opt(options, k1, k2 = null, k3 = null, fallback = null) {
|
|
118
|
+
if ((options == null)) {
|
|
119
|
+
return fallback;
|
|
120
|
+
} else {
|
|
121
|
+
if (__eliscript_truthy(Collection.isMap(options))) {
|
|
122
|
+
{
|
|
123
|
+
let v1 = Collection.get(options, keyword(k1), (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")));
|
|
124
|
+
if (!((v1 === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING"))))) {
|
|
125
|
+
return v1;
|
|
126
|
+
} else {
|
|
127
|
+
{
|
|
128
|
+
let s1 = Collection.get(options, k1, (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")));
|
|
129
|
+
if (!((s1 === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING"))))) {
|
|
130
|
+
return s1;
|
|
131
|
+
} else {
|
|
132
|
+
if (!((k2 == null))) {
|
|
133
|
+
{
|
|
134
|
+
let v2 = Collection.get(options, keyword(k2), (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")));
|
|
135
|
+
if (!((v2 === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING"))))) {
|
|
136
|
+
return v2;
|
|
137
|
+
} else {
|
|
138
|
+
{
|
|
139
|
+
let s2 = Collection.get(options, k2, (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")));
|
|
140
|
+
if (!((s2 === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING"))))) {
|
|
141
|
+
return s2;
|
|
142
|
+
} else {
|
|
143
|
+
if (!((k3 == null))) {
|
|
144
|
+
{
|
|
145
|
+
let v3 = Collection.get(options, keyword(k3), (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")));
|
|
146
|
+
if (!((v3 === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING"))))) {
|
|
147
|
+
return v3;
|
|
148
|
+
} else {
|
|
149
|
+
return Collection.get(options, k3, fallback);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
return fallback;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
return fallback;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
if ((__eliscript_value_type(options) === "object")) {
|
|
168
|
+
if (__eliscript_truthy(Object.hasOwn(options, k1))) {
|
|
169
|
+
return (options)[k1];
|
|
170
|
+
} else {
|
|
171
|
+
if ((!((k2 == null)) && __eliscript_truthy(Object.hasOwn(options, k2)))) {
|
|
172
|
+
return (options)[k2];
|
|
173
|
+
} else {
|
|
174
|
+
if ((!((k3 == null)) && __eliscript_truthy(Object.hasOwn(options, k3)))) {
|
|
175
|
+
return (options)[k3];
|
|
176
|
+
} else {
|
|
177
|
+
return fallback;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
return fallback;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function def_spec(key, schema) {
|
|
188
|
+
if ((!(__eliscript_truthy(isKeyword(key)) || __eliscript_truthy(isEliscriptSymbol(key))))) {
|
|
189
|
+
((__eliscript_value_1) => { throw __eliscript_value_1; })(new (globalThis.TypeError)("def-spec expects a keyword or symbol key"));
|
|
190
|
+
}
|
|
191
|
+
{
|
|
192
|
+
let resolved = resolve_spec(schema);
|
|
193
|
+
((__eliscript_tdz_ready_20 === true ? REGISTRY : __eliscript_tdz_error("REGISTRY")))["set"](hash_key_for_id(key), resolved);
|
|
194
|
+
return resolved;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function hash_key_for_id(id) {
|
|
198
|
+
return (String((__eliscript_truthy(isKeyword(id)) ? "k:" : "s:")) + String(qualifiedIdentifierName(id)));
|
|
199
|
+
}
|
|
200
|
+
function get_spec(key) {
|
|
201
|
+
if ((__eliscript_truthy(isKeyword(key)) || __eliscript_truthy(isEliscriptSymbol(key)))) {
|
|
202
|
+
{
|
|
203
|
+
let found = ((__eliscript_tdz_ready_20 === true ? REGISTRY : __eliscript_tdz_error("REGISTRY")))["get"](hash_key_for_id(key));
|
|
204
|
+
if ((found === undefined)) {
|
|
205
|
+
return null;
|
|
206
|
+
} else {
|
|
207
|
+
return found;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function resolve_spec(spec) {
|
|
215
|
+
if (__eliscript_truthy(schema_QMARK_(spec))) {
|
|
216
|
+
return spec;
|
|
217
|
+
} else {
|
|
218
|
+
if ((__eliscript_value_type(spec) === "function")) {
|
|
219
|
+
return spec_pred(spec, ({"name": ((n) => {
|
|
220
|
+
if ((__eliscript_truthy(n) && __eliscript_numeric_relation(">", ((n) ?? []).length, 0))) {
|
|
221
|
+
return n;
|
|
222
|
+
} else {
|
|
223
|
+
return "predicate";
|
|
224
|
+
}
|
|
225
|
+
})((spec)["name"])}));
|
|
226
|
+
} else {
|
|
227
|
+
if (__eliscript_truthy(Collection.isSet(spec))) {
|
|
228
|
+
return spec_enum(spec);
|
|
229
|
+
} else {
|
|
230
|
+
if ((__eliscript_truthy(isKeyword(spec)) || __eliscript_truthy(isEliscriptSymbol(spec)))) {
|
|
231
|
+
{
|
|
232
|
+
let found = get_spec(spec);
|
|
233
|
+
if ((found === null)) {
|
|
234
|
+
((__eliscript_value_2) => { throw __eliscript_value_2; })(new (globalThis.Error)((String("unknown registered schema: ") + String(qualifiedIdentifierName(spec)))));
|
|
235
|
+
}
|
|
236
|
+
return found;
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
return ((__eliscript_value_3) => { throw __eliscript_value_3; })(new (globalThis.TypeError)((String("expected schema or predicate, got ") + String(printValue(spec)))));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function make_rng(seed) {
|
|
246
|
+
{
|
|
247
|
+
let normalized = ((seed == null) ? 42 : __eliscript_numeric_uint32(seed));
|
|
248
|
+
return ({"state": normalized});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function rng_next_u32(rng) {
|
|
252
|
+
{
|
|
253
|
+
let s = __eliscript_numeric_uint32(((rng)["state"] + 1831565813));
|
|
254
|
+
let _w = ((rng)["state"] = s);
|
|
255
|
+
let t1 = __eliscript_numeric_imul(__eliscript_numeric_xor(s, __eliscript_numeric_ushr(s, 15)), __eliscript_numeric_or(s, 1));
|
|
256
|
+
let t2 = __eliscript_numeric_uint32((t1 + __eliscript_numeric_imul(__eliscript_numeric_xor(t1, __eliscript_numeric_ushr(t1, 7)), __eliscript_numeric_or(t1, 61))));
|
|
257
|
+
return __eliscript_numeric_uint32(__eliscript_numeric_xor(t2, __eliscript_numeric_ushr(t2, 14)));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function rng_next_float(rng) {
|
|
261
|
+
return __eliscript_numeric_div(rng_next_u32(rng), 4294967296);
|
|
262
|
+
}
|
|
263
|
+
function rng_next_int(rng, min_val, max_val) {
|
|
264
|
+
{
|
|
265
|
+
let lo = Math.ceil(min_val);
|
|
266
|
+
let hi = Math.floor(max_val);
|
|
267
|
+
if (__eliscript_numeric_relation(">", lo, hi)) {
|
|
268
|
+
((__eliscript_value_4) => { throw __eliscript_value_4; })(new (globalThis.RangeError)((String("invalid integer range [") + String(min_val) + String(", ") + String(max_val) + String("]"))));
|
|
269
|
+
}
|
|
270
|
+
if ((lo === hi)) {
|
|
271
|
+
return lo;
|
|
272
|
+
} else {
|
|
273
|
+
{
|
|
274
|
+
let span = (__eliscript_numeric_sub(hi, lo) + 1);
|
|
275
|
+
return (lo + Math.floor(__eliscript_numeric_mul(rng_next_float(rng), span)));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function gen_return(value) {
|
|
281
|
+
return make_gen("return", ((_rng, _size) => {
|
|
282
|
+
return value;
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
function gen_fmap(f, gen) {
|
|
286
|
+
if ((!(__eliscript_value_type(f) === "function"))) {
|
|
287
|
+
((__eliscript_value_5) => { throw __eliscript_value_5; })(new (globalThis.TypeError)("gen-fmap expects a function"));
|
|
288
|
+
}
|
|
289
|
+
{
|
|
290
|
+
let g = ensure_gen(gen);
|
|
291
|
+
return make_gen((String("fmap:") + String((g)["name"])), ((rng, size) => {
|
|
292
|
+
return f((g)["sampleFn"](rng, size));
|
|
293
|
+
}));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function gen_bind(gen, f) {
|
|
297
|
+
if ((!(__eliscript_value_type(f) === "function"))) {
|
|
298
|
+
((__eliscript_value_6) => { throw __eliscript_value_6; })(new (globalThis.TypeError)("gen-bind expects a function"));
|
|
299
|
+
}
|
|
300
|
+
{
|
|
301
|
+
let g = ensure_gen(gen);
|
|
302
|
+
return make_gen((String("bind:") + String((g)["name"])), ((rng, size) => {
|
|
303
|
+
{
|
|
304
|
+
let inner = ensure_gen(f((g)["sampleFn"](rng, size)));
|
|
305
|
+
return (inner)["sampleFn"](rng, size);
|
|
306
|
+
}
|
|
307
|
+
}));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function gen_one_of(gens) {
|
|
311
|
+
{
|
|
312
|
+
let arr = to_js_array(gens);
|
|
313
|
+
if ((((arr) ?? []).length === 0)) {
|
|
314
|
+
((__eliscript_value_7) => { throw __eliscript_value_7; })(new (globalThis.RangeError)("gen-one-of requires at least one generator"));
|
|
315
|
+
}
|
|
316
|
+
{
|
|
317
|
+
let resolved = (arr)["map"](ensure_gen);
|
|
318
|
+
return make_gen("one-of", ((rng, size) => {
|
|
319
|
+
{
|
|
320
|
+
let idx = rng_next_int(rng, 0, __eliscript_numeric_decrement(((resolved) ?? []).length));
|
|
321
|
+
return ((resolved)[idx])["sampleFn"](rng, size);
|
|
322
|
+
}
|
|
323
|
+
}));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function gen_elements(values) {
|
|
328
|
+
{
|
|
329
|
+
let arr = to_js_array(values);
|
|
330
|
+
if ((((arr) ?? []).length === 0)) {
|
|
331
|
+
((__eliscript_value_8) => { throw __eliscript_value_8; })(new (globalThis.RangeError)("gen-elements requires at least one value"));
|
|
332
|
+
}
|
|
333
|
+
return make_gen("elements", ((rng, _size) => {
|
|
334
|
+
return (arr)[rng_next_int(rng, 0, __eliscript_numeric_decrement(((arr) ?? []).length))];
|
|
335
|
+
}));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function gen_such_that(pred, gen, max_tries = null) {
|
|
339
|
+
{
|
|
340
|
+
let g = ensure_gen(gen);
|
|
341
|
+
let tries_limit = ((max_tries == null) ? 200 : max_tries);
|
|
342
|
+
return make_gen((String("such-that:") + String((g)["name"])), ((rng, size) => {
|
|
343
|
+
{
|
|
344
|
+
let attempt = 0;
|
|
345
|
+
let found = (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING"));
|
|
346
|
+
while (((found === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING"))) && __eliscript_numeric_relation("<", attempt, tries_limit))) {
|
|
347
|
+
{
|
|
348
|
+
let candidate = (g)["sampleFn"](rng, (size + Math.floor(__eliscript_numeric_div(attempt, 4))));
|
|
349
|
+
if (__eliscript_truthy(truthy_QMARK_(pred(candidate)))) {
|
|
350
|
+
((found = candidate));
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
((attempt = (attempt + 1)));
|
|
354
|
+
}
|
|
355
|
+
if ((found === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")))) {
|
|
356
|
+
((__eliscript_value_9) => { throw __eliscript_value_9; })(new (globalThis.Error)((String("gen-such-that exhausted after ") + String(tries_limit) + String(" attempts"))));
|
|
357
|
+
}
|
|
358
|
+
return found;
|
|
359
|
+
}
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const gen_boolean = make_gen("boolean", ((rng, _size) => {
|
|
364
|
+
return (rng_next_int(rng, 0, 1) === 1);
|
|
365
|
+
}));
|
|
366
|
+
function gen_int(min_val = null, max_val = null) {
|
|
367
|
+
if ((!((min_val == null)) && !((max_val == null)))) {
|
|
368
|
+
return make_gen("int-range", ((rng, _size) => {
|
|
369
|
+
return rng_next_int(rng, min_val, max_val);
|
|
370
|
+
}));
|
|
371
|
+
} else {
|
|
372
|
+
return make_gen("int", ((rng, size) => {
|
|
373
|
+
{
|
|
374
|
+
let bound = Math.max(1, Math.floor(size));
|
|
375
|
+
let r = rng_next_int(rng, __eliscript_numeric_neg(bound), bound);
|
|
376
|
+
return r;
|
|
377
|
+
}
|
|
378
|
+
}));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
function gen_double(options = null) {
|
|
382
|
+
{
|
|
383
|
+
let min_v = read_opt(options, "min", null, null, -1000);
|
|
384
|
+
let max_v = read_opt(options, "max", null, null, 1000);
|
|
385
|
+
let allow_nan = truthy_QMARK_(read_opt(options, "NaN?", "nan?", null, false));
|
|
386
|
+
let allow_inf = truthy_QMARK_(read_opt(options, "infinite?", "infinite", null, false));
|
|
387
|
+
return make_gen("double", ((rng, size) => {
|
|
388
|
+
{
|
|
389
|
+
let tag = rng_next_int(rng, 0, 19);
|
|
390
|
+
if ((__eliscript_truthy(allow_nan) && (tag === 0))) {
|
|
391
|
+
return (globalThis.Number)["NaN"];
|
|
392
|
+
} else {
|
|
393
|
+
if ((__eliscript_truthy(allow_inf) && (tag === 1))) {
|
|
394
|
+
return (globalThis.Number)["POSITIVE_INFINITY"];
|
|
395
|
+
} else {
|
|
396
|
+
if ((__eliscript_truthy(allow_inf) && (tag === 2))) {
|
|
397
|
+
return (globalThis.Number)["NEGATIVE_INFINITY"];
|
|
398
|
+
} else {
|
|
399
|
+
{
|
|
400
|
+
let span = __eliscript_numeric_sub(max_v, min_v);
|
|
401
|
+
let scaled = (min_v + __eliscript_numeric_mul(rng_next_float(rng), (__eliscript_truthy(Number.isFinite(span)) ? span : Math.max(1, size))));
|
|
402
|
+
return __eliscript_numeric_div(Math.round(__eliscript_numeric_mul(scaled, 10000)), 10000);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
const PRINTABLE_ASCII = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_- ";
|
|
412
|
+
__eliscript_tdz_ready_24 = true;
|
|
413
|
+
function gen_string(min_len = null, max_len = null) {
|
|
414
|
+
{
|
|
415
|
+
let lo = ((min_len == null) ? 0 : min_len);
|
|
416
|
+
let hi = ((max_len == null) ? null : max_len);
|
|
417
|
+
return make_gen("string", ((rng, size) => {
|
|
418
|
+
{
|
|
419
|
+
let cap = ((hi == null) ? Math.max(lo, Math.min(32, Math.floor(size))) : hi);
|
|
420
|
+
let len = rng_next_int(rng, lo, cap);
|
|
421
|
+
let chars = [];
|
|
422
|
+
let i = 0;
|
|
423
|
+
while (__eliscript_numeric_relation("<", i, len)) {
|
|
424
|
+
{
|
|
425
|
+
let cidx = rng_next_int(rng, 0, __eliscript_numeric_decrement((((__eliscript_tdz_ready_24 === true ? PRINTABLE_ASCII : __eliscript_tdz_error("PRINTABLE_ASCII"))) ?? []).length));
|
|
426
|
+
(chars)["push"](((__eliscript_tdz_ready_24 === true ? PRINTABLE_ASCII : __eliscript_tdz_error("PRINTABLE_ASCII")))[cidx]);
|
|
427
|
+
}
|
|
428
|
+
((i = (i + 1)));
|
|
429
|
+
}
|
|
430
|
+
return __eliscript_at_direct(chars, "join", "");
|
|
431
|
+
}
|
|
432
|
+
}));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
const gen_keyword = make_gen("keyword", ((rng, size) => {
|
|
436
|
+
{
|
|
437
|
+
let len = rng_next_int(rng, 1, Math.max(1, Math.min(12, Math.floor((size + 1)))));
|
|
438
|
+
let chars = [];
|
|
439
|
+
let i = 0;
|
|
440
|
+
while (__eliscript_numeric_relation("<", i, len)) {
|
|
441
|
+
(chars)["push"](("abcdefghijkmnopqrstuvwxyz")[rng_next_int(rng, 0, 24)]);
|
|
442
|
+
((i = (i + 1)));
|
|
443
|
+
}
|
|
444
|
+
return keyword(__eliscript_at_direct(chars, "join", ""));
|
|
445
|
+
}
|
|
446
|
+
}));
|
|
447
|
+
const gen_symbol = make_gen("symbol", ((rng, size) => {
|
|
448
|
+
{
|
|
449
|
+
let kw = (gen_keyword)["sampleFn"](rng, size);
|
|
450
|
+
return eliscriptSymbol(qualifiedIdentifierName(kw));
|
|
451
|
+
}
|
|
452
|
+
}));
|
|
453
|
+
function gen_tuple(...gens) {
|
|
454
|
+
{
|
|
455
|
+
let resolved = (Array.from(gens))["map"](ensure_gen);
|
|
456
|
+
return make_gen("tuple", ((rng, size) => {
|
|
457
|
+
{
|
|
458
|
+
let items = [];
|
|
459
|
+
let i = 0;
|
|
460
|
+
while (__eliscript_numeric_relation("<", i, ((resolved) ?? []).length)) {
|
|
461
|
+
(items)["push"](((resolved)[i])["sampleFn"](rng, size));
|
|
462
|
+
((i = (i + 1)));
|
|
463
|
+
}
|
|
464
|
+
return (PersistentVector)["from"](items);
|
|
465
|
+
}
|
|
466
|
+
}));
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
function gen_vector(item_gen, min_count = null, max_count = null, distinct_QMARK_ = null) {
|
|
470
|
+
{
|
|
471
|
+
let g = ensure_gen(item_gen);
|
|
472
|
+
let lo = ((min_count == null) ? 0 : min_count);
|
|
473
|
+
let hi = ((max_count == null) ? null : max_count);
|
|
474
|
+
let uniq = truthy_QMARK_(distinct_QMARK_);
|
|
475
|
+
return make_gen("vector", ((rng, size) => {
|
|
476
|
+
{
|
|
477
|
+
let cap = ((hi == null) ? Math.max(lo, Math.min(16, Math.floor(size))) : hi);
|
|
478
|
+
let target_len = rng_next_int(rng, lo, cap);
|
|
479
|
+
let items = [];
|
|
480
|
+
let attempts = 0;
|
|
481
|
+
let limit = __eliscript_numeric_mul(Math.max(1, target_len), 20);
|
|
482
|
+
while ((__eliscript_numeric_relation("<", ((items) ?? []).length, target_len) && __eliscript_numeric_relation("<", attempts, limit))) {
|
|
483
|
+
{
|
|
484
|
+
let candidate = (g)["sampleFn"](rng, Math.max(1, Math.floor(__eliscript_numeric_div(size, 2))));
|
|
485
|
+
if ((!(__eliscript_truthy(uniq)) || !(__eliscript_truthy(array_contains_equal_QMARK_(items, candidate))))) {
|
|
486
|
+
(items)["push"](candidate);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
((attempts = (attempts + 1)));
|
|
490
|
+
}
|
|
491
|
+
if (__eliscript_numeric_relation("<", ((items) ?? []).length, lo)) {
|
|
492
|
+
((__eliscript_value_10) => { throw __eliscript_value_10; })(new (globalThis.Error)("gen-vector failed to produce minimum distinct elements"));
|
|
493
|
+
}
|
|
494
|
+
return (PersistentVector)["from"](items);
|
|
495
|
+
}
|
|
496
|
+
}));
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
function gen_map(key_gen, val_gen, min_count = null, max_count = null) {
|
|
500
|
+
{
|
|
501
|
+
let kg = ensure_gen(key_gen);
|
|
502
|
+
let vg = ensure_gen(val_gen);
|
|
503
|
+
let lo = ((min_count == null) ? 0 : min_count);
|
|
504
|
+
let hi = ((max_count == null) ? null : max_count);
|
|
505
|
+
return make_gen("map", ((rng, size) => {
|
|
506
|
+
{
|
|
507
|
+
let cap = ((hi == null) ? Math.max(lo, Math.min(12, Math.floor(size))) : hi);
|
|
508
|
+
let target_len = rng_next_int(rng, lo, cap);
|
|
509
|
+
let pairs = [];
|
|
510
|
+
let seen_keys = [];
|
|
511
|
+
let attempts = 0;
|
|
512
|
+
let limit = __eliscript_numeric_mul(Math.max(1, target_len), 20);
|
|
513
|
+
while ((__eliscript_numeric_relation("<", ((seen_keys) ?? []).length, target_len) && __eliscript_numeric_relation("<", attempts, limit))) {
|
|
514
|
+
{
|
|
515
|
+
let k = (kg)["sampleFn"](rng, Math.max(1, Math.floor(__eliscript_numeric_div(size, 2))));
|
|
516
|
+
if ((!__eliscript_truthy(array_contains_equal_QMARK_(seen_keys, k)))) {
|
|
517
|
+
{
|
|
518
|
+
let v = (vg)["sampleFn"](rng, Math.max(1, Math.floor(__eliscript_numeric_div(size, 2))));
|
|
519
|
+
(seen_keys)["push"](k);
|
|
520
|
+
(pairs)["push"](k);
|
|
521
|
+
(pairs)["push"](v);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
((attempts = (attempts + 1)));
|
|
526
|
+
}
|
|
527
|
+
if (__eliscript_numeric_relation("<", ((seen_keys) ?? []).length, lo)) {
|
|
528
|
+
((__eliscript_value_11) => { throw __eliscript_value_11; })(new (globalThis.Error)("gen-map failed to produce minimum distinct keys"));
|
|
529
|
+
}
|
|
530
|
+
return kv_map(...(pairs ?? []));
|
|
531
|
+
}
|
|
532
|
+
}));
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
function ensure_gen(value) {
|
|
536
|
+
if (__eliscript_truthy(gen_QMARK_(value))) {
|
|
537
|
+
return value;
|
|
538
|
+
} else {
|
|
539
|
+
if (__eliscript_truthy(schema_QMARK_(value))) {
|
|
540
|
+
return gen_from_spec(value);
|
|
541
|
+
} else {
|
|
542
|
+
return ((__eliscript_value_12) => { throw __eliscript_value_12; })(new (globalThis.TypeError)("expected a generator or schema"));
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function with_gen(schema, gen) {
|
|
547
|
+
{
|
|
548
|
+
let s = resolve_spec(schema);
|
|
549
|
+
let g = ((__eliscript_value_type(gen) === "function") ? gen() : ensure_gen(gen));
|
|
550
|
+
return make_schema((s)["kind"], (s)["name"], (s)["config"], ensure_gen(g), (s)["meta"]);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function spec_pred(pred, options = null) {
|
|
554
|
+
if ((!(__eliscript_value_type(pred) === "function"))) {
|
|
555
|
+
((__eliscript_value_13) => { throw __eliscript_value_13; })(new (globalThis.TypeError)("spec-pred expects a predicate function"));
|
|
556
|
+
}
|
|
557
|
+
{
|
|
558
|
+
let name = read_opt(options, "name", null, null, ((pn) => {
|
|
559
|
+
if ((__eliscript_truthy(pn) && __eliscript_numeric_relation(">", ((pn) ?? []).length, 0))) {
|
|
560
|
+
return pn;
|
|
561
|
+
} else {
|
|
562
|
+
return "predicate";
|
|
563
|
+
}
|
|
564
|
+
})((pred)["name"]));
|
|
565
|
+
let gen = read_opt(options, "gen", null, null, null);
|
|
566
|
+
return make_schema("pred", name, ({"pred": pred}), ((gen == null) ? null : ensure_gen(gen)));
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
const spec_any = make_schema("any", "any?", ({}), gen_one_of([gen_int(), gen_boolean, gen_string(), gen_keyword, gen_return(null)]));
|
|
570
|
+
const spec_nil = make_schema("pred", "nil?", ({"pred": ((x) => {
|
|
571
|
+
return (x === null);
|
|
572
|
+
})}), gen_return(null));
|
|
573
|
+
const spec_boolean = make_schema("pred", "boolean?", ({"pred": ((x) => {
|
|
574
|
+
return (__eliscript_value_type(x) === "boolean");
|
|
575
|
+
})}), gen_boolean);
|
|
576
|
+
const spec_number = make_schema("pred", "number?", ({"pred": ((x) => {
|
|
577
|
+
return ((__eliscript_value_type(x) === "number") && (!__eliscript_truthy(Number.isNaN(x))));
|
|
578
|
+
})}), gen_double(({"min": -100, "max": 100})));
|
|
579
|
+
const spec_int = make_schema("pred", "int?", ({"pred": ((x) => {
|
|
580
|
+
return Number.isSafeInteger(x);
|
|
581
|
+
})}), gen_int());
|
|
582
|
+
const spec_double = make_schema("pred", "double?", ({"pred": ((x) => {
|
|
583
|
+
return (__eliscript_value_type(x) === "number");
|
|
584
|
+
})}), gen_double());
|
|
585
|
+
const spec_string = make_schema("pred", "string?", ({"pred": ((x) => {
|
|
586
|
+
return (__eliscript_value_type(x) === "string");
|
|
587
|
+
})}), gen_string());
|
|
588
|
+
const spec_keyword = make_schema("pred", "keyword?", ({"pred": isKeyword}), gen_keyword);
|
|
589
|
+
const spec_symbol = make_schema("pred", "symbol?", ({"pred": isEliscriptSymbol}), gen_symbol);
|
|
590
|
+
const spec_vector = make_schema("pred", "vector?", ({"pred": Collection.isVector}), gen_vector(spec_any, 0, 8));
|
|
591
|
+
const spec_map = make_schema("pred", "map?", ({"pred": Collection.isMap}), gen_map(gen_keyword, spec_any, 0, 8));
|
|
592
|
+
const spec_set = make_schema("pred", "set?", ({"pred": Collection.isSet}), gen_fmap(((v) => {
|
|
593
|
+
return persistentHashSet(...(to_js_array(v) ?? []));
|
|
594
|
+
}), gen_vector(spec_any, 0, 6)));
|
|
595
|
+
const spec_list = make_schema("pred", "list?", ({"pred": Collection.isList}), gen_fmap(((v) => {
|
|
596
|
+
return persistentList(...(to_js_array(v) ?? []));
|
|
597
|
+
}), gen_vector(spec_any, 0, 8)));
|
|
598
|
+
function spec_int_in(min_val, max_val) {
|
|
599
|
+
if ((!(__eliscript_truthy(Number.isSafeInteger(min_val)) && __eliscript_truthy(Number.isSafeInteger(max_val)) && __eliscript_numeric_relation("<=", min_val, max_val)))) {
|
|
600
|
+
((__eliscript_value_14) => { throw __eliscript_value_14; })(new (globalThis.RangeError)("spec-int-in requires safe integers min <= max"));
|
|
601
|
+
}
|
|
602
|
+
return make_schema("int-in", (String("(int-in ") + String(min_val) + String(" ") + String(max_val) + String(")")), ({"min": min_val, "max": max_val}), gen_int(min_val, max_val));
|
|
603
|
+
}
|
|
604
|
+
function spec_double_in(options = null) {
|
|
605
|
+
{
|
|
606
|
+
let min_v = read_opt(options, "min", null, null, (globalThis.Number)["NEGATIVE_INFINITY"]);
|
|
607
|
+
let max_v = read_opt(options, "max", null, null, (globalThis.Number)["POSITIVE_INFINITY"]);
|
|
608
|
+
let allow_inf = truthy_QMARK_(read_opt(options, "infinite?", "infinite", null, false));
|
|
609
|
+
let allow_nan = truthy_QMARK_(read_opt(options, "NaN?", "nan?", null, false));
|
|
610
|
+
return make_schema("double-in", "double-in", ({"min": min_v, "max": max_v, "infinite?": allow_inf, "NaN?": allow_nan}), gen_double(({"min": (__eliscript_truthy(Number.isFinite(min_v)) ? min_v : -1000), "max": (__eliscript_truthy(Number.isFinite(max_v)) ? max_v : 1000), "infinite?": allow_inf, "NaN?": allow_nan})));
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function spec_string_len(min_len, max_len = null) {
|
|
614
|
+
{
|
|
615
|
+
let lo = ((min_len == null) ? 0 : min_len);
|
|
616
|
+
let hi = ((max_len == null) ? null : max_len);
|
|
617
|
+
if ((!(__eliscript_truthy(Number.isSafeInteger(lo)) && __eliscript_numeric_relation(">=", lo, 0) && ((hi == null) || (__eliscript_truthy(Number.isSafeInteger(hi)) && __eliscript_numeric_relation(">=", hi, lo)))))) {
|
|
618
|
+
((__eliscript_value_15) => { throw __eliscript_value_15; })(new (globalThis.RangeError)("spec-string-len requires non-negative safe integers min <= max"));
|
|
619
|
+
}
|
|
620
|
+
return make_schema("string-len", (String("(string-len ") + String(lo) + String(((hi == null) ? ")" : (String(" ") + String(hi) + String(")"))))), ({"min": lo, "max": hi}), gen_string(lo, hi));
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function spec_nilable(spec) {
|
|
624
|
+
{
|
|
625
|
+
let inner = resolve_spec(spec);
|
|
626
|
+
return make_schema("nilable", (String("(nilable ") + String((inner)["name"]) + String(")")), ({"inner": inner}));
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
function spec_enum(values) {
|
|
630
|
+
{
|
|
631
|
+
let arr = to_js_array(values);
|
|
632
|
+
if ((((arr) ?? []).length === 0)) {
|
|
633
|
+
((__eliscript_value_16) => { throw __eliscript_value_16; })(new (globalThis.RangeError)("spec-enum requires a non-empty collection or array"));
|
|
634
|
+
}
|
|
635
|
+
return make_schema("enum", "enum", ({"values": arr}), gen_elements(arr));
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function spec_and(...specs) {
|
|
639
|
+
if ((((specs) ?? []).length === 0)) {
|
|
640
|
+
((__eliscript_value_17) => { throw __eliscript_value_17; })(new (globalThis.RangeError)("spec-and requires at least one spec"));
|
|
641
|
+
}
|
|
642
|
+
{
|
|
643
|
+
let resolved = (Array.from(specs))["map"](resolve_spec);
|
|
644
|
+
return make_schema("and", "and", ({"specs": resolved}));
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function normalize_tagged_pairs(args, label) {
|
|
648
|
+
{
|
|
649
|
+
let count = ((args) ?? []).length;
|
|
650
|
+
if (((count === 0) || !((__eliscript_numeric_rem(count, 2) === 0)))) {
|
|
651
|
+
((__eliscript_value_18) => { throw __eliscript_value_18; })(new (globalThis.Error)((String(label) + String(" expects alternating tag and schema pairs"))));
|
|
652
|
+
}
|
|
653
|
+
{
|
|
654
|
+
let clauses = [];
|
|
655
|
+
let i = 0;
|
|
656
|
+
while (__eliscript_numeric_relation("<", i, count)) {
|
|
657
|
+
(clauses)["push"](({"tag": (args)[i], "spec": resolve_spec((args)[(i + 1)])}));
|
|
658
|
+
((i = (i + 2)));
|
|
659
|
+
}
|
|
660
|
+
return clauses;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function spec_or(...tag_spec_pairs) {
|
|
665
|
+
{
|
|
666
|
+
let clauses = normalize_tagged_pairs(tag_spec_pairs, "spec-or");
|
|
667
|
+
return make_schema("or", "or", ({"clauses": clauses}));
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
function normalize_key_entries(raw) {
|
|
671
|
+
if ((raw == null)) {
|
|
672
|
+
return [];
|
|
673
|
+
} else {
|
|
674
|
+
if (__eliscript_truthy(Collection.isMap(raw))) {
|
|
675
|
+
{
|
|
676
|
+
let entries = [];
|
|
677
|
+
Collection.reduceKV(raw, ((_acc, k, v) => {
|
|
678
|
+
(entries)["push"](({"key": k, "spec": resolve_spec(v)}));
|
|
679
|
+
return null;
|
|
680
|
+
}), null);
|
|
681
|
+
return entries;
|
|
682
|
+
}
|
|
683
|
+
} else {
|
|
684
|
+
if ((__eliscript_truthy(Array.isArray(raw)) || __eliscript_truthy(Collection.isSequential(raw)))) {
|
|
685
|
+
{
|
|
686
|
+
let arr = to_js_array(raw);
|
|
687
|
+
let entries = [];
|
|
688
|
+
let i = 0;
|
|
689
|
+
while (__eliscript_numeric_relation("<", i, ((arr) ?? []).length)) {
|
|
690
|
+
{
|
|
691
|
+
let item = (arr)[i];
|
|
692
|
+
if ((__eliscript_truthy(Array.isArray(item)) || __eliscript_truthy(Collection.isVector(item)))) {
|
|
693
|
+
{
|
|
694
|
+
let pair = to_js_array(item);
|
|
695
|
+
if ((!(((pair) ?? []).length === 2))) {
|
|
696
|
+
((__eliscript_value_19) => { throw __eliscript_value_19; })(new (globalThis.TypeError)("spec-keys entry pair must have 2 elements"));
|
|
697
|
+
}
|
|
698
|
+
(entries)["push"](({"key": (pair)[0], "spec": resolve_spec((pair)[1])}));
|
|
699
|
+
}
|
|
700
|
+
} else {
|
|
701
|
+
if (__eliscript_truthy(isKeyword(item))) {
|
|
702
|
+
{
|
|
703
|
+
let s = get_spec(item);
|
|
704
|
+
if ((s === null)) {
|
|
705
|
+
((__eliscript_value_20) => { throw __eliscript_value_20; })(new (globalThis.Error)((String("spec-keys unknown key spec: ") + String(qualifiedIdentifierName(item)))));
|
|
706
|
+
} else {
|
|
707
|
+
(entries)["push"](({"key": item, "spec": s}));
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
} else {
|
|
711
|
+
((__eliscript_value_21) => { throw __eliscript_value_21; })(new (globalThis.TypeError)("spec-keys entry must be [key schema] or registered keyword"));
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
((i = (i + 1)));
|
|
716
|
+
}
|
|
717
|
+
return entries;
|
|
718
|
+
}
|
|
719
|
+
} else {
|
|
720
|
+
if ((__eliscript_value_type(raw) === "object")) {
|
|
721
|
+
{
|
|
722
|
+
let keys = Object.keys(raw);
|
|
723
|
+
let entries = [];
|
|
724
|
+
let i = 0;
|
|
725
|
+
while (__eliscript_numeric_relation("<", i, ((keys) ?? []).length)) {
|
|
726
|
+
{
|
|
727
|
+
let k = (keys)[i];
|
|
728
|
+
(entries)["push"](({"key": k, "spec": resolve_spec((raw)[k])}));
|
|
729
|
+
}
|
|
730
|
+
((i = (i + 1)));
|
|
731
|
+
}
|
|
732
|
+
return entries;
|
|
733
|
+
}
|
|
734
|
+
} else {
|
|
735
|
+
return ((__eliscript_value_22) => { throw __eliscript_value_22; })(new (globalThis.TypeError)("spec-keys entries must be a map or list of [key spec] pairs"));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
function unqualified_key(k) {
|
|
742
|
+
if (__eliscript_truthy(isKeyword(k))) {
|
|
743
|
+
return keyword(identifierName_safe(k));
|
|
744
|
+
} else {
|
|
745
|
+
if (__eliscript_truthy(isEliscriptSymbol(k))) {
|
|
746
|
+
return eliscriptSymbol(identifierName_safe(k));
|
|
747
|
+
} else {
|
|
748
|
+
return k;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
function identifierName_safe(id) {
|
|
753
|
+
if (__eliscript_truthy(isIdentifier(id))) {
|
|
754
|
+
{
|
|
755
|
+
let q = qualifiedIdentifierName(id);
|
|
756
|
+
let idx = (q)["indexOf"]("/");
|
|
757
|
+
if (__eliscript_numeric_relation("<", idx, 0)) {
|
|
758
|
+
return q;
|
|
759
|
+
} else {
|
|
760
|
+
return (q)["slice"]((idx + 1));
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
} else {
|
|
764
|
+
return id;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
function normalize_unqualified_entries(entries) {
|
|
768
|
+
return (entries)["map"](((entry) => {
|
|
769
|
+
return ({"key": unqualified_key((entry)["key"]), "originalKey": (entry)["key"], "spec": (entry)["spec"]});
|
|
770
|
+
}));
|
|
771
|
+
}
|
|
772
|
+
function spec_keys(options) {
|
|
773
|
+
{
|
|
774
|
+
let req = normalize_key_entries(read_opt(options, "req", null, null, null));
|
|
775
|
+
let opt = normalize_key_entries(read_opt(options, "opt", null, null, null));
|
|
776
|
+
let req_un = normalize_unqualified_entries(normalize_key_entries(read_opt(options, "req-un", "reqUn", null, null)));
|
|
777
|
+
let opt_un = normalize_unqualified_entries(normalize_key_entries(read_opt(options, "opt-un", "optUn", null, null)));
|
|
778
|
+
let closed = truthy_QMARK_(read_opt(options, "closed?", "closed", null, false));
|
|
779
|
+
let all_req = (req)["concat"](req_un);
|
|
780
|
+
let all_opt = (opt)["concat"](opt_un);
|
|
781
|
+
return make_schema("keys", "keys", ({"req": all_req, "opt": all_opt, "closed": closed}));
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
function spec_coll_of(item_spec, options = null) {
|
|
785
|
+
{
|
|
786
|
+
let inner = resolve_spec(item_spec);
|
|
787
|
+
let kind = read_opt(options, "kind", null, null, null);
|
|
788
|
+
let min_c = read_opt(options, "min-count", "minCount", null, 0);
|
|
789
|
+
let max_c = read_opt(options, "max-count", "maxCount", null, null);
|
|
790
|
+
let distinct_QMARK_ = truthy_QMARK_(read_opt(options, "distinct", "distinct?", null, false));
|
|
791
|
+
return make_schema("coll-of", "coll-of", ({"item": inner, "kind": kind, "minCount": min_c, "maxCount": max_c, "distinct": distinct_QMARK_}));
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
function spec_map_of(key_spec, val_spec, options = null) {
|
|
795
|
+
{
|
|
796
|
+
let ks = resolve_spec(key_spec);
|
|
797
|
+
let vs = resolve_spec(val_spec);
|
|
798
|
+
let min_c = read_opt(options, "min-count", "minCount", null, 0);
|
|
799
|
+
let max_c = read_opt(options, "max-count", "maxCount", null, null);
|
|
800
|
+
return make_schema("map-of", "map-of", ({"key": ks, "val": vs, "minCount": min_c, "maxCount": max_c}));
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
function spec_tuple(...item_specs) {
|
|
804
|
+
{
|
|
805
|
+
let items = (Array.from(item_specs))["map"](resolve_spec);
|
|
806
|
+
return make_schema("tuple", "tuple", ({"items": items}));
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
function spec_cat(...tag_spec_pairs) {
|
|
810
|
+
{
|
|
811
|
+
let clauses = normalize_tagged_pairs(tag_spec_pairs, "spec-cat");
|
|
812
|
+
return make_schema("cat", "cat", ({"clauses": clauses}));
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
function spec_alt(...tag_spec_pairs) {
|
|
816
|
+
{
|
|
817
|
+
let clauses = normalize_tagged_pairs(tag_spec_pairs, "spec-alt");
|
|
818
|
+
return make_schema("alt", "alt", ({"clauses": clauses}));
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
function spec_rep_STAR_(spec) {
|
|
822
|
+
return make_schema("rep*", "rep*", ({"inner": resolve_spec(spec)}));
|
|
823
|
+
}
|
|
824
|
+
function spec_rep_PLUS_(spec) {
|
|
825
|
+
return make_schema("rep+", "rep+", ({"inner": resolve_spec(spec)}));
|
|
826
|
+
}
|
|
827
|
+
function spec_opt_QMARK_(spec) {
|
|
828
|
+
return make_schema("opt?", "opt?", ({"inner": resolve_spec(spec)}));
|
|
829
|
+
}
|
|
830
|
+
function spec_fn(options) {
|
|
831
|
+
{
|
|
832
|
+
let args_spec = read_opt(options, "args", null, null, null);
|
|
833
|
+
let ret_spec = read_opt(options, "ret", null, null, null);
|
|
834
|
+
let fn_spec = read_opt(options, "fn", null, null, null);
|
|
835
|
+
return make_schema("fn", "fspec", ({"args": ((args_spec == null) ? null : resolve_spec(args_spec)), "ret": ((ret_spec == null) ? null : resolve_spec(ret_spec)), "fn": ((fn_spec == null) ? null : resolve_spec(fn_spec))}));
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
function fdef(fn_value, fn_spec) {
|
|
839
|
+
{
|
|
840
|
+
let s = resolve_spec(fn_spec);
|
|
841
|
+
if ((!((s)["kind"] === "fn"))) {
|
|
842
|
+
((__eliscript_value_23) => { throw __eliscript_value_23; })(new (globalThis.TypeError)("fdef requires a spec-fn schema"));
|
|
843
|
+
}
|
|
844
|
+
if ((!(__eliscript_value_type(fn_value) === "function"))) {
|
|
845
|
+
((__eliscript_value_24) => { throw __eliscript_value_24; })(new (globalThis.TypeError)("fdef expects a function"));
|
|
846
|
+
}
|
|
847
|
+
((__eliscript_tdz_ready_20 === true ? REGISTRY : __eliscript_tdz_error("REGISTRY")))["set"](fn_value, s);
|
|
848
|
+
return instrument(fn_value, s);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
function instrument(fn_value, explicit_spec = null) {
|
|
852
|
+
{
|
|
853
|
+
let s = ((explicit_spec == null) ? ((__eliscript_tdz_ready_20 === true ? REGISTRY : __eliscript_tdz_error("REGISTRY")))["get"](fn_value) : resolve_spec(explicit_spec));
|
|
854
|
+
if ((s == null)) {
|
|
855
|
+
((__eliscript_value_25) => { throw __eliscript_value_25; })(new (globalThis.Error)("instrument: function has no registered spec-fn"));
|
|
856
|
+
}
|
|
857
|
+
{
|
|
858
|
+
let cfg = (s)["config"];
|
|
859
|
+
let args_spec = (cfg)["args"];
|
|
860
|
+
let ret_spec = (cfg)["ret"];
|
|
861
|
+
let fn_rel_spec = (cfg)["fn"];
|
|
862
|
+
let wrapped = ((...call_args) => {
|
|
863
|
+
{
|
|
864
|
+
let arg_vec = (PersistentVector)["from"](call_args);
|
|
865
|
+
let conformed_args = null;
|
|
866
|
+
if (__eliscript_truthy(args_spec)) {
|
|
867
|
+
((conformed_args = conform(args_spec, arg_vec)));
|
|
868
|
+
if (__eliscript_truthy(invalid_QMARK_(conformed_args))) {
|
|
869
|
+
((__eliscript_value_26) => { throw __eliscript_value_26; })(new (globalThis.Error)((String("Call args violated spec:\n") + String(explain_str(args_spec, arg_vec)))));
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
{
|
|
873
|
+
let ret = fn_value(...(call_args ?? []));
|
|
874
|
+
let conformed_ret = null;
|
|
875
|
+
if (__eliscript_truthy(ret_spec)) {
|
|
876
|
+
((conformed_ret = conform(ret_spec, ret)));
|
|
877
|
+
if (__eliscript_truthy(invalid_QMARK_(conformed_ret))) {
|
|
878
|
+
((__eliscript_value_27) => { throw __eliscript_value_27; })(new (globalThis.Error)((String("Return value violated spec:\n") + String(explain_str(ret_spec, ret)))));
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
if (__eliscript_truthy(fn_rel_spec)) {
|
|
882
|
+
{
|
|
883
|
+
let rel_input = kv_map(keyword("args"), (__eliscript_truthy(args_spec) ? conformed_args : arg_vec), keyword("ret"), (__eliscript_truthy(ret_spec) ? conformed_ret : ret));
|
|
884
|
+
if ((!__eliscript_truthy(valid_QMARK_(fn_rel_spec, rel_input)))) {
|
|
885
|
+
((__eliscript_value_28) => { throw __eliscript_value_28; })(new (globalThis.Error)((String("Function :fn invariant violated:\n") + String(explain_str(fn_rel_spec, rel_input)))));
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
return ret;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
((__eliscript_tdz_ready_20 === true ? REGISTRY : __eliscript_tdz_error("REGISTRY")))["set"](wrapped, s);
|
|
894
|
+
return wrapped;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
function to_js_array(coll) {
|
|
899
|
+
if ((coll == null)) {
|
|
900
|
+
return [];
|
|
901
|
+
} else {
|
|
902
|
+
if (__eliscript_truthy(Array.isArray(coll))) {
|
|
903
|
+
return coll;
|
|
904
|
+
} else {
|
|
905
|
+
if (__eliscript_truthy(Collection.isSeqable(coll))) {
|
|
906
|
+
{
|
|
907
|
+
let items = [];
|
|
908
|
+
Collection.reduce(coll, ((_acc, item) => {
|
|
909
|
+
(items)["push"](item);
|
|
910
|
+
return null;
|
|
911
|
+
}), null);
|
|
912
|
+
return items;
|
|
913
|
+
}
|
|
914
|
+
} else {
|
|
915
|
+
return ((__eliscript_value_29) => { throw __eliscript_value_29; })(new (globalThis.TypeError)((String("expected sequential or iterable collection, got ") + String(printValue(coll)))));
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
function array_contains_equal_QMARK_(items, target) {
|
|
921
|
+
{
|
|
922
|
+
let i = 0;
|
|
923
|
+
let found = false;
|
|
924
|
+
while ((!(__eliscript_truthy(found)) && __eliscript_numeric_relation("<", i, ((items) ?? []).length))) {
|
|
925
|
+
if (__eliscript_truthy(equalValues((items)[i], target))) {
|
|
926
|
+
((found = true));
|
|
927
|
+
}
|
|
928
|
+
((i = (i + 1)));
|
|
929
|
+
}
|
|
930
|
+
return found;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
function regex_schema_QMARK_(schema) {
|
|
934
|
+
{
|
|
935
|
+
let k = (schema)["kind"];
|
|
936
|
+
return ((k === "cat") || (k === "alt") || (k === "rep*") || (k === "rep+") || (k === "opt?"));
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
function push_problem(problems, path, pred, val, via, in_path, reason) {
|
|
940
|
+
return (problems)["push"](kv_map((__eliscript_tdz_ready_4 === true ? KW_PATH : __eliscript_tdz_error("KW_PATH")), (PersistentVector)["from"](path), (__eliscript_tdz_ready_5 === true ? KW_PRED : __eliscript_tdz_error("KW_PRED")), pred, (__eliscript_tdz_ready_6 === true ? KW_VAL : __eliscript_tdz_error("KW_VAL")), val, (__eliscript_tdz_ready_7 === true ? KW_VIA : __eliscript_tdz_error("KW_VIA")), (PersistentVector)["from"](via), (__eliscript_tdz_ready_8 === true ? KW_IN : __eliscript_tdz_error("KW_IN")), (PersistentVector)["from"](in_path), (__eliscript_tdz_ready_9 === true ? KW_REASON : __eliscript_tdz_error("KW_REASON")), reason));
|
|
941
|
+
}
|
|
942
|
+
function regex_match(schema, items, pos) {
|
|
943
|
+
{
|
|
944
|
+
let kind = (schema)["kind"];
|
|
945
|
+
let cfg = (schema)["config"];
|
|
946
|
+
if ((kind === "cat")) {
|
|
947
|
+
return regex_match_cat((cfg)["clauses"], 0, items, pos, EMPTY_MAP);
|
|
948
|
+
} else {
|
|
949
|
+
if ((kind === "alt")) {
|
|
950
|
+
{
|
|
951
|
+
let clauses = (cfg)["clauses"];
|
|
952
|
+
let i = 0;
|
|
953
|
+
let res = null;
|
|
954
|
+
while (((res === null) && __eliscript_numeric_relation("<", i, ((clauses) ?? []).length))) {
|
|
955
|
+
{
|
|
956
|
+
let clause = (clauses)[i];
|
|
957
|
+
let tag = (clause)["tag"];
|
|
958
|
+
let sub = (clause)["spec"];
|
|
959
|
+
let m = regex_match(sub, items, pos);
|
|
960
|
+
if (__eliscript_truthy((m)["ok"])) {
|
|
961
|
+
((res = ({"ok": true, "pos": (m)["pos"], "value": persistentVector(tag, (m)["value"])})));
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
((i = (i + 1)));
|
|
965
|
+
}
|
|
966
|
+
if ((res === null)) {
|
|
967
|
+
return ({"ok": false, "pos": pos, "reason": "no spec-alt branch matched", "schema": schema});
|
|
968
|
+
} else {
|
|
969
|
+
return res;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
} else {
|
|
973
|
+
if ((kind === "opt?")) {
|
|
974
|
+
{
|
|
975
|
+
let inner = (cfg)["inner"];
|
|
976
|
+
{
|
|
977
|
+
let m = regex_match(inner, items, pos);
|
|
978
|
+
if (__eliscript_truthy((m)["ok"])) {
|
|
979
|
+
return m;
|
|
980
|
+
} else {
|
|
981
|
+
return ({"ok": true, "pos": pos, "value": null});
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
} else {
|
|
986
|
+
if (((kind === "rep*") || (kind === "rep+"))) {
|
|
987
|
+
{
|
|
988
|
+
let inner = (cfg)["inner"];
|
|
989
|
+
let cursor = pos;
|
|
990
|
+
let acc = [];
|
|
991
|
+
let keep_going = true;
|
|
992
|
+
while ((__eliscript_truthy(keep_going) && __eliscript_numeric_relation("<", cursor, ((items) ?? []).length))) {
|
|
993
|
+
{
|
|
994
|
+
let m = regex_match(inner, items, cursor);
|
|
995
|
+
if ((__eliscript_truthy((m)["ok"]) && __eliscript_numeric_relation(">", (m)["pos"], cursor))) {
|
|
996
|
+
(acc)["push"]((m)["value"]);
|
|
997
|
+
((cursor = (m)["pos"]));
|
|
998
|
+
} else {
|
|
999
|
+
((keep_going = false));
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
if (((kind === "rep+") && (((acc) ?? []).length === 0))) {
|
|
1004
|
+
return ({"ok": false, "pos": pos, "reason": "expected at least one element for spec-rep+", "schema": inner});
|
|
1005
|
+
} else {
|
|
1006
|
+
return ({"ok": true, "pos": cursor, "value": (PersistentVector)["from"](acc)});
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
} else {
|
|
1010
|
+
if (__eliscript_numeric_relation(">=", pos, ((items) ?? []).length)) {
|
|
1011
|
+
return ({"ok": false, "pos": pos, "reason": "unexpected end of sequence", "schema": schema});
|
|
1012
|
+
} else {
|
|
1013
|
+
{
|
|
1014
|
+
let item = (items)[pos];
|
|
1015
|
+
let c = conform(schema, item);
|
|
1016
|
+
if (__eliscript_truthy(invalid_QMARK_(c))) {
|
|
1017
|
+
return ({"ok": false, "pos": pos, "reason": "element failed schema", "schema": schema, "item": item});
|
|
1018
|
+
} else {
|
|
1019
|
+
return ({"ok": true, "pos": (pos + 1), "value": c});
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
function regex_match_cat(clauses, idx, items, pos, acc_map) {
|
|
1030
|
+
if (__eliscript_numeric_relation(">=", idx, ((clauses) ?? []).length)) {
|
|
1031
|
+
return ({"ok": true, "pos": pos, "value": acc_map});
|
|
1032
|
+
} else {
|
|
1033
|
+
{
|
|
1034
|
+
let clause = (clauses)[idx];
|
|
1035
|
+
let tag = (clause)["tag"];
|
|
1036
|
+
let sub = (clause)["spec"];
|
|
1037
|
+
let sub_kind = (sub)["kind"];
|
|
1038
|
+
if (((sub_kind === "rep*") || (sub_kind === "rep+"))) {
|
|
1039
|
+
{
|
|
1040
|
+
let inner = ((sub)["config"])["inner"];
|
|
1041
|
+
let min_c = ((sub_kind === "rep+") ? 1 : 0);
|
|
1042
|
+
let matches = [];
|
|
1043
|
+
let cursor = pos;
|
|
1044
|
+
let keep_going = true;
|
|
1045
|
+
while ((__eliscript_truthy(keep_going) && __eliscript_numeric_relation("<", cursor, ((items) ?? []).length))) {
|
|
1046
|
+
{
|
|
1047
|
+
let m = regex_match(inner, items, cursor);
|
|
1048
|
+
if ((__eliscript_truthy((m)["ok"]) && __eliscript_numeric_relation(">", (m)["pos"], cursor))) {
|
|
1049
|
+
(matches)["push"](({"val": (m)["value"], "next": (m)["pos"]}));
|
|
1050
|
+
((cursor = (m)["pos"]));
|
|
1051
|
+
} else {
|
|
1052
|
+
((keep_going = false));
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
{
|
|
1057
|
+
let n = ((matches) ?? []).length;
|
|
1058
|
+
let found = null;
|
|
1059
|
+
if (__eliscript_numeric_relation("<", n, min_c)) {
|
|
1060
|
+
return ({"ok": false, "pos": cursor, "reason": "insufficient elements for repetition", "schema": sub, "clauseTag": tag});
|
|
1061
|
+
} else {
|
|
1062
|
+
while (((found === null) && __eliscript_numeric_relation(">=", n, min_c))) {
|
|
1063
|
+
{
|
|
1064
|
+
let end_pos = ((n === 0) ? pos : ((matches)[__eliscript_numeric_decrement(n)])["next"]);
|
|
1065
|
+
let slice_vals = [];
|
|
1066
|
+
let k = 0;
|
|
1067
|
+
while (__eliscript_numeric_relation("<", k, n)) {
|
|
1068
|
+
(slice_vals)["push"](((matches)[k])["val"]);
|
|
1069
|
+
((k = (k + 1)));
|
|
1070
|
+
}
|
|
1071
|
+
{
|
|
1072
|
+
let next_acc = Collection.assoc(acc_map, tag, (PersistentVector)["from"](slice_vals));
|
|
1073
|
+
let tail_res = regex_match_cat(clauses, (idx + 1), items, end_pos, next_acc);
|
|
1074
|
+
if (__eliscript_truthy((tail_res)["ok"])) {
|
|
1075
|
+
((found = tail_res));
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
((n = __eliscript_numeric_decrement(n)));
|
|
1080
|
+
}
|
|
1081
|
+
if ((found === null)) {
|
|
1082
|
+
return ({"ok": false, "pos": pos, "reason": "cat continuation failed", "schema": sub, "clauseTag": tag});
|
|
1083
|
+
} else {
|
|
1084
|
+
return found;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
} else {
|
|
1090
|
+
if ((sub_kind === "opt?")) {
|
|
1091
|
+
{
|
|
1092
|
+
let inner = ((sub)["config"])["inner"];
|
|
1093
|
+
let present = regex_match(inner, items, pos);
|
|
1094
|
+
let res = (__eliscript_truthy((present)["ok"]) ? ((next_acc) => {
|
|
1095
|
+
return regex_match_cat(clauses, (idx + 1), items, (present)["pos"], next_acc);
|
|
1096
|
+
})(Collection.assoc(acc_map, tag, (present)["value"])) : ({"ok": false}));
|
|
1097
|
+
if (__eliscript_truthy((res)["ok"])) {
|
|
1098
|
+
return res;
|
|
1099
|
+
} else {
|
|
1100
|
+
return regex_match_cat(clauses, (idx + 1), items, pos, acc_map);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
} else {
|
|
1104
|
+
{
|
|
1105
|
+
let m = regex_match(sub, items, pos);
|
|
1106
|
+
if (!(__eliscript_truthy((m)["ok"]))) {
|
|
1107
|
+
return ({"ok": false, "pos": (m)["pos"], "reason": (m)["reason"], "schema": (m)["schema"], "clauseTag": tag, "item": (m)["item"]});
|
|
1108
|
+
} else {
|
|
1109
|
+
return regex_match_cat(clauses, (idx + 1), items, (m)["pos"], Collection.assoc(acc_map, tag, (m)["value"]));
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
function regex_conform(schema, value) {
|
|
1118
|
+
if (!((__eliscript_truthy(Collection.isSequential(value)) || __eliscript_truthy(Collection.isList(value)) || __eliscript_truthy(Collection.isVector(value)) || __eliscript_truthy(Array.isArray(value))))) {
|
|
1119
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1120
|
+
} else {
|
|
1121
|
+
{
|
|
1122
|
+
let items = to_js_array(value);
|
|
1123
|
+
let m = regex_match(schema, items, 0);
|
|
1124
|
+
if ((__eliscript_truthy((m)["ok"]) && ((m)["pos"] === ((items) ?? []).length))) {
|
|
1125
|
+
return (m)["value"];
|
|
1126
|
+
} else {
|
|
1127
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
function conform(schema, value) {
|
|
1133
|
+
{
|
|
1134
|
+
let s = resolve_spec(schema);
|
|
1135
|
+
let kind = (s)["kind"];
|
|
1136
|
+
let cfg = (s)["config"];
|
|
1137
|
+
if ((kind === "any")) {
|
|
1138
|
+
return value;
|
|
1139
|
+
} else {
|
|
1140
|
+
if ((kind === "pred")) {
|
|
1141
|
+
if (__eliscript_truthy(truthy_QMARK_(((cfg)["pred"])(value)))) {
|
|
1142
|
+
return value;
|
|
1143
|
+
} else {
|
|
1144
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1145
|
+
}
|
|
1146
|
+
} else {
|
|
1147
|
+
if ((kind === "int-in")) {
|
|
1148
|
+
if ((__eliscript_truthy(Number.isSafeInteger(value)) && __eliscript_numeric_relation(">=", value, (cfg)["min"]) && __eliscript_numeric_relation("<=", value, (cfg)["max"]))) {
|
|
1149
|
+
return value;
|
|
1150
|
+
} else {
|
|
1151
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1152
|
+
}
|
|
1153
|
+
} else {
|
|
1154
|
+
if ((kind === "double-in")) {
|
|
1155
|
+
if (!((__eliscript_value_type(value) === "number"))) {
|
|
1156
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1157
|
+
} else {
|
|
1158
|
+
if (__eliscript_truthy(Number.isNaN(value))) {
|
|
1159
|
+
if (__eliscript_truthy((cfg)["NaN?"])) {
|
|
1160
|
+
return value;
|
|
1161
|
+
} else {
|
|
1162
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1163
|
+
}
|
|
1164
|
+
} else {
|
|
1165
|
+
if (!(__eliscript_truthy(Number.isFinite(value)))) {
|
|
1166
|
+
if (__eliscript_truthy((cfg)["infinite?"])) {
|
|
1167
|
+
return value;
|
|
1168
|
+
} else {
|
|
1169
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1170
|
+
}
|
|
1171
|
+
} else {
|
|
1172
|
+
if ((__eliscript_numeric_relation(">=", value, (cfg)["min"]) && __eliscript_numeric_relation("<=", value, (cfg)["max"]))) {
|
|
1173
|
+
return value;
|
|
1174
|
+
} else {
|
|
1175
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
} else {
|
|
1181
|
+
if ((kind === "string-len")) {
|
|
1182
|
+
if (!((__eliscript_value_type(value) === "string"))) {
|
|
1183
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1184
|
+
} else {
|
|
1185
|
+
{
|
|
1186
|
+
let len = ((value) ?? []).length;
|
|
1187
|
+
let hi = (cfg)["max"];
|
|
1188
|
+
if ((__eliscript_numeric_relation(">=", len, (cfg)["min"]) && ((hi == null) || __eliscript_numeric_relation("<=", len, hi)))) {
|
|
1189
|
+
return value;
|
|
1190
|
+
} else {
|
|
1191
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
} else {
|
|
1196
|
+
if ((kind === "nilable")) {
|
|
1197
|
+
if ((value === null)) {
|
|
1198
|
+
return null;
|
|
1199
|
+
} else {
|
|
1200
|
+
return conform((cfg)["inner"], value);
|
|
1201
|
+
}
|
|
1202
|
+
} else {
|
|
1203
|
+
if ((kind === "enum")) {
|
|
1204
|
+
if (__eliscript_truthy(array_contains_equal_QMARK_((cfg)["values"], value))) {
|
|
1205
|
+
return value;
|
|
1206
|
+
} else {
|
|
1207
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1208
|
+
}
|
|
1209
|
+
} else {
|
|
1210
|
+
if ((kind === "and")) {
|
|
1211
|
+
{
|
|
1212
|
+
let specs = (cfg)["specs"];
|
|
1213
|
+
let cur = value;
|
|
1214
|
+
let i = 0;
|
|
1215
|
+
let failed = false;
|
|
1216
|
+
while ((!(__eliscript_truthy(failed)) && __eliscript_numeric_relation("<", i, ((specs) ?? []).length))) {
|
|
1217
|
+
((cur = conform((specs)[i], cur)));
|
|
1218
|
+
if (__eliscript_truthy(invalid_QMARK_(cur))) {
|
|
1219
|
+
((failed = true));
|
|
1220
|
+
}
|
|
1221
|
+
((i = (i + 1)));
|
|
1222
|
+
}
|
|
1223
|
+
if (__eliscript_truthy(failed)) {
|
|
1224
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1225
|
+
} else {
|
|
1226
|
+
return cur;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
} else {
|
|
1230
|
+
if ((kind === "or")) {
|
|
1231
|
+
{
|
|
1232
|
+
let clauses = (cfg)["clauses"];
|
|
1233
|
+
let i = 0;
|
|
1234
|
+
let res = (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1235
|
+
while ((__eliscript_truthy(invalid_QMARK_(res)) && __eliscript_numeric_relation("<", i, ((clauses) ?? []).length))) {
|
|
1236
|
+
{
|
|
1237
|
+
let clause = (clauses)[i];
|
|
1238
|
+
let c = conform((clause)["spec"], value);
|
|
1239
|
+
if ((!__eliscript_truthy(invalid_QMARK_(c)))) {
|
|
1240
|
+
((res = persistentVector((clause)["tag"], c)));
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
((i = (i + 1)));
|
|
1244
|
+
}
|
|
1245
|
+
return res;
|
|
1246
|
+
}
|
|
1247
|
+
} else {
|
|
1248
|
+
if ((kind === "keys")) {
|
|
1249
|
+
if (!(__eliscript_truthy(Collection.isMap(value)))) {
|
|
1250
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1251
|
+
} else {
|
|
1252
|
+
{
|
|
1253
|
+
let req = (cfg)["req"];
|
|
1254
|
+
let opt = (cfg)["opt"];
|
|
1255
|
+
let closed = (cfg)["closed"];
|
|
1256
|
+
let out = value;
|
|
1257
|
+
let failed = false;
|
|
1258
|
+
let i = 0;
|
|
1259
|
+
while ((!(__eliscript_truthy(failed)) && __eliscript_numeric_relation("<", i, ((req) ?? []).length))) {
|
|
1260
|
+
{
|
|
1261
|
+
let entry = (req)[i];
|
|
1262
|
+
let k = (entry)["key"];
|
|
1263
|
+
let v = Collection.get(value, k, (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")));
|
|
1264
|
+
if ((v === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")))) {
|
|
1265
|
+
((failed = true));
|
|
1266
|
+
} else {
|
|
1267
|
+
{
|
|
1268
|
+
let cv = conform((entry)["spec"], v);
|
|
1269
|
+
if (__eliscript_truthy(invalid_QMARK_(cv))) {
|
|
1270
|
+
((failed = true));
|
|
1271
|
+
} else {
|
|
1272
|
+
if ((!__eliscript_truthy(equalValues(cv, v)))) {
|
|
1273
|
+
((out = Collection.assoc(out, k, cv)));
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
((i = (i + 1)));
|
|
1280
|
+
}
|
|
1281
|
+
((i = 0));
|
|
1282
|
+
while ((!(__eliscript_truthy(failed)) && __eliscript_numeric_relation("<", i, ((opt) ?? []).length))) {
|
|
1283
|
+
{
|
|
1284
|
+
let entry = (opt)[i];
|
|
1285
|
+
let k = (entry)["key"];
|
|
1286
|
+
let v = Collection.get(value, k, (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")));
|
|
1287
|
+
if ((!(v === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING"))))) {
|
|
1288
|
+
{
|
|
1289
|
+
let cv = conform((entry)["spec"], v);
|
|
1290
|
+
if (__eliscript_truthy(invalid_QMARK_(cv))) {
|
|
1291
|
+
((failed = true));
|
|
1292
|
+
} else {
|
|
1293
|
+
if ((!__eliscript_truthy(equalValues(cv, v)))) {
|
|
1294
|
+
((out = Collection.assoc(out, k, cv)));
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
((i = (i + 1)));
|
|
1301
|
+
}
|
|
1302
|
+
if ((!(__eliscript_truthy(failed)) && __eliscript_truthy(closed))) {
|
|
1303
|
+
{
|
|
1304
|
+
let ks = (req)["concat"](opt);
|
|
1305
|
+
Collection.reduceKV(value, ((_acc, k, _v) => {
|
|
1306
|
+
{
|
|
1307
|
+
let found = false;
|
|
1308
|
+
let j = 0;
|
|
1309
|
+
while ((!(__eliscript_truthy(found)) && __eliscript_numeric_relation("<", j, ((ks) ?? []).length))) {
|
|
1310
|
+
if (__eliscript_truthy(equalValues(k, ((ks)[j])["key"]))) {
|
|
1311
|
+
((found = true));
|
|
1312
|
+
}
|
|
1313
|
+
((j = (j + 1)));
|
|
1314
|
+
}
|
|
1315
|
+
if ((!__eliscript_truthy(found))) {
|
|
1316
|
+
((failed = true));
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
return null;
|
|
1320
|
+
}), null);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
if (__eliscript_truthy(failed)) {
|
|
1324
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1325
|
+
} else {
|
|
1326
|
+
return out;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
} else {
|
|
1331
|
+
if ((kind === "coll-of")) {
|
|
1332
|
+
if (!((__eliscript_truthy(Collection.isVector(value)) || __eliscript_truthy(Collection.isList(value)) || __eliscript_truthy(Collection.isSet(value)) || __eliscript_truthy(Collection.isQueue(value)) || __eliscript_truthy(Collection.isSequence(value)) || __eliscript_truthy(Array.isArray(value))))) {
|
|
1333
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1334
|
+
} else {
|
|
1335
|
+
{
|
|
1336
|
+
let expected_kind = (cfg)["kind"];
|
|
1337
|
+
let kind_ok = ((expected_kind == null) ? true : ((expected_kind === "vector") ? Collection.isVector(value) : ((expected_kind === "list") ? Collection.isList(value) : ((expected_kind === "set") ? Collection.isSet(value) : ((__eliscript_value_type(expected_kind) === "function") ? truthy_QMARK_(expected_kind(value)) : true)))));
|
|
1338
|
+
if (!(__eliscript_truthy(kind_ok))) {
|
|
1339
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1340
|
+
} else {
|
|
1341
|
+
{
|
|
1342
|
+
let items = to_js_array(value);
|
|
1343
|
+
let min_c = (cfg)["minCount"];
|
|
1344
|
+
let max_c = (cfg)["maxCount"];
|
|
1345
|
+
let uniq = (cfg)["distinct"];
|
|
1346
|
+
let item_spec = (cfg)["item"];
|
|
1347
|
+
let conformed = [];
|
|
1348
|
+
let seen = [];
|
|
1349
|
+
let failed = false;
|
|
1350
|
+
let i = 0;
|
|
1351
|
+
if ((__eliscript_numeric_relation("<", ((items) ?? []).length, min_c) || (!((max_c == null)) && __eliscript_numeric_relation(">", ((items) ?? []).length, max_c)))) {
|
|
1352
|
+
((failed = true));
|
|
1353
|
+
}
|
|
1354
|
+
while ((!(__eliscript_truthy(failed)) && __eliscript_numeric_relation("<", i, ((items) ?? []).length))) {
|
|
1355
|
+
{
|
|
1356
|
+
let el = (items)[i];
|
|
1357
|
+
let ce = conform(item_spec, el);
|
|
1358
|
+
if (__eliscript_truthy(invalid_QMARK_(ce))) {
|
|
1359
|
+
((failed = true));
|
|
1360
|
+
} else {
|
|
1361
|
+
if ((__eliscript_truthy(uniq) && __eliscript_truthy(array_contains_equal_QMARK_(seen, el)))) {
|
|
1362
|
+
((failed = true));
|
|
1363
|
+
} else {
|
|
1364
|
+
if (__eliscript_truthy(uniq)) {
|
|
1365
|
+
(seen)["push"](el);
|
|
1366
|
+
}
|
|
1367
|
+
(conformed)["push"](ce);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
((i = (i + 1)));
|
|
1372
|
+
}
|
|
1373
|
+
if (__eliscript_truthy(failed)) {
|
|
1374
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1375
|
+
} else {
|
|
1376
|
+
if (__eliscript_truthy(Collection.isVector(value))) {
|
|
1377
|
+
return (PersistentVector)["from"](conformed);
|
|
1378
|
+
} else {
|
|
1379
|
+
if (__eliscript_truthy(Collection.isSet(value))) {
|
|
1380
|
+
return persistentHashSet(...(conformed ?? []));
|
|
1381
|
+
} else {
|
|
1382
|
+
if (__eliscript_truthy(Collection.isList(value))) {
|
|
1383
|
+
return persistentList(...(conformed ?? []));
|
|
1384
|
+
} else {
|
|
1385
|
+
return (PersistentVector)["from"](conformed);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
} else {
|
|
1395
|
+
if ((kind === "map-of")) {
|
|
1396
|
+
if (!(__eliscript_truthy(Collection.isMap(value)))) {
|
|
1397
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1398
|
+
} else {
|
|
1399
|
+
{
|
|
1400
|
+
let min_c = (cfg)["minCount"];
|
|
1401
|
+
let max_c = (cfg)["maxCount"];
|
|
1402
|
+
let cnt = Collection.count(value);
|
|
1403
|
+
let ks = (cfg)["key"];
|
|
1404
|
+
let vs = (cfg)["val"];
|
|
1405
|
+
let entries = [];
|
|
1406
|
+
if ((__eliscript_numeric_relation("<", cnt, min_c) || (!((max_c == null)) && __eliscript_numeric_relation(">", cnt, max_c)))) {
|
|
1407
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1408
|
+
} else {
|
|
1409
|
+
Collection.reduceKV(value, ((_acc, k, v) => {
|
|
1410
|
+
(entries)["push"]([k, v]);
|
|
1411
|
+
return null;
|
|
1412
|
+
}), null);
|
|
1413
|
+
{
|
|
1414
|
+
let pairs = [];
|
|
1415
|
+
let failed = false;
|
|
1416
|
+
let i = 0;
|
|
1417
|
+
while ((!(__eliscript_truthy(failed)) && __eliscript_numeric_relation("<", i, ((entries) ?? []).length))) {
|
|
1418
|
+
{
|
|
1419
|
+
let pair = (entries)[i];
|
|
1420
|
+
let ck = conform(ks, (pair)[0]);
|
|
1421
|
+
let cv = conform(vs, (pair)[1]);
|
|
1422
|
+
if ((__eliscript_truthy(invalid_QMARK_(ck)) || __eliscript_truthy(invalid_QMARK_(cv)))) {
|
|
1423
|
+
((failed = true));
|
|
1424
|
+
} else {
|
|
1425
|
+
(pairs)["push"](ck);
|
|
1426
|
+
(pairs)["push"](cv);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
((i = (i + 1)));
|
|
1430
|
+
}
|
|
1431
|
+
if (__eliscript_truthy(failed)) {
|
|
1432
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1433
|
+
} else {
|
|
1434
|
+
return kv_map(...(pairs ?? []));
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
} else {
|
|
1441
|
+
if ((kind === "tuple")) {
|
|
1442
|
+
if (!((__eliscript_truthy(Collection.isVector(value)) || __eliscript_truthy(Array.isArray(value))))) {
|
|
1443
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1444
|
+
} else {
|
|
1445
|
+
{
|
|
1446
|
+
let items = to_js_array(value);
|
|
1447
|
+
let item_specs = (cfg)["items"];
|
|
1448
|
+
if (!((((items) ?? []).length === ((item_specs) ?? []).length))) {
|
|
1449
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1450
|
+
} else {
|
|
1451
|
+
{
|
|
1452
|
+
let conformed = [];
|
|
1453
|
+
let failed = false;
|
|
1454
|
+
let i = 0;
|
|
1455
|
+
while ((!(__eliscript_truthy(failed)) && __eliscript_numeric_relation("<", i, ((item_specs) ?? []).length))) {
|
|
1456
|
+
{
|
|
1457
|
+
let ce = conform((item_specs)[i], (items)[i]);
|
|
1458
|
+
if (__eliscript_truthy(invalid_QMARK_(ce))) {
|
|
1459
|
+
((failed = true));
|
|
1460
|
+
} else {
|
|
1461
|
+
(conformed)["push"](ce);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
((i = (i + 1)));
|
|
1465
|
+
}
|
|
1466
|
+
if (__eliscript_truthy(failed)) {
|
|
1467
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1468
|
+
} else {
|
|
1469
|
+
return (PersistentVector)["from"](conformed);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
} else {
|
|
1476
|
+
if (__eliscript_truthy(regex_schema_QMARK_(s))) {
|
|
1477
|
+
return regex_conform(s, value);
|
|
1478
|
+
} else {
|
|
1479
|
+
if ((kind === "fn")) {
|
|
1480
|
+
if ((__eliscript_value_type(value) === "function")) {
|
|
1481
|
+
return value;
|
|
1482
|
+
} else {
|
|
1483
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1484
|
+
}
|
|
1485
|
+
} else {
|
|
1486
|
+
return (__eliscript_tdz_ready_0 === true ? INVALID : __eliscript_tdz_error("INVALID"));
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
function valid_QMARK_(schema, value) {
|
|
1505
|
+
return (!__eliscript_truthy(invalid_QMARK_(conform(schema, value))));
|
|
1506
|
+
}
|
|
1507
|
+
function unform(schema, conformed) {
|
|
1508
|
+
{
|
|
1509
|
+
let s = resolve_spec(schema);
|
|
1510
|
+
let kind = (s)["kind"];
|
|
1511
|
+
let cfg = (s)["config"];
|
|
1512
|
+
if ((kind === "or")) {
|
|
1513
|
+
{
|
|
1514
|
+
let pair = to_js_array(conformed);
|
|
1515
|
+
let tag = (pair)[0];
|
|
1516
|
+
let val = (pair)[1];
|
|
1517
|
+
let clauses = (cfg)["clauses"];
|
|
1518
|
+
let i = 0;
|
|
1519
|
+
let found = null;
|
|
1520
|
+
while (((found === null) && __eliscript_numeric_relation("<", i, ((clauses) ?? []).length))) {
|
|
1521
|
+
{
|
|
1522
|
+
let c = (clauses)[i];
|
|
1523
|
+
if (__eliscript_truthy(equalValues((c)["tag"], tag))) {
|
|
1524
|
+
((found = unform((c)["spec"], val)));
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
((i = (i + 1)));
|
|
1528
|
+
}
|
|
1529
|
+
if ((found === null)) {
|
|
1530
|
+
return val;
|
|
1531
|
+
} else {
|
|
1532
|
+
return found;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
} else {
|
|
1536
|
+
if ((kind === "alt")) {
|
|
1537
|
+
{
|
|
1538
|
+
let pair = to_js_array(conformed);
|
|
1539
|
+
let tag = (pair)[0];
|
|
1540
|
+
let val = (pair)[1];
|
|
1541
|
+
let clauses = (cfg)["clauses"];
|
|
1542
|
+
let i = 0;
|
|
1543
|
+
let found = null;
|
|
1544
|
+
while (((found === null) && __eliscript_numeric_relation("<", i, ((clauses) ?? []).length))) {
|
|
1545
|
+
{
|
|
1546
|
+
let c = (clauses)[i];
|
|
1547
|
+
if (__eliscript_truthy(equalValues((c)["tag"], tag))) {
|
|
1548
|
+
((found = unform((c)["spec"], val)));
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
((i = (i + 1)));
|
|
1552
|
+
}
|
|
1553
|
+
return persistentVector(((found === null) ? val : found));
|
|
1554
|
+
}
|
|
1555
|
+
} else {
|
|
1556
|
+
if ((kind === "cat")) {
|
|
1557
|
+
{
|
|
1558
|
+
let clauses = (cfg)["clauses"];
|
|
1559
|
+
let items = [];
|
|
1560
|
+
let i = 0;
|
|
1561
|
+
while (__eliscript_numeric_relation("<", i, ((clauses) ?? []).length)) {
|
|
1562
|
+
{
|
|
1563
|
+
let c = (clauses)[i];
|
|
1564
|
+
let tag = (c)["tag"];
|
|
1565
|
+
let sub = (c)["spec"];
|
|
1566
|
+
if (__eliscript_truthy(Collection.contains(conformed, tag))) {
|
|
1567
|
+
{
|
|
1568
|
+
let v = Collection.get(conformed, tag);
|
|
1569
|
+
if ((((sub)["kind"] === "rep*") || ((sub)["kind"] === "rep+"))) {
|
|
1570
|
+
{
|
|
1571
|
+
let inner = ((sub)["config"])["inner"];
|
|
1572
|
+
let arr = to_js_array(v);
|
|
1573
|
+
let j = 0;
|
|
1574
|
+
while (__eliscript_numeric_relation("<", j, ((arr) ?? []).length)) {
|
|
1575
|
+
{
|
|
1576
|
+
let u = unform(inner, (arr)[j]);
|
|
1577
|
+
if (__eliscript_truthy(regex_schema_QMARK_(inner))) {
|
|
1578
|
+
{
|
|
1579
|
+
let ua = to_js_array(u);
|
|
1580
|
+
let k = 0;
|
|
1581
|
+
while (__eliscript_numeric_relation("<", k, ((ua) ?? []).length)) {
|
|
1582
|
+
(items)["push"]((ua)[k]);
|
|
1583
|
+
((k = (k + 1)));
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
} else {
|
|
1587
|
+
(items)["push"](u);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
((j = (j + 1)));
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
} else {
|
|
1594
|
+
{
|
|
1595
|
+
let u = unform(sub, v);
|
|
1596
|
+
if (__eliscript_truthy(regex_schema_QMARK_(sub))) {
|
|
1597
|
+
{
|
|
1598
|
+
let ua = to_js_array(u);
|
|
1599
|
+
let k = 0;
|
|
1600
|
+
while (__eliscript_numeric_relation("<", k, ((ua) ?? []).length)) {
|
|
1601
|
+
(items)["push"]((ua)[k]);
|
|
1602
|
+
((k = (k + 1)));
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
} else {
|
|
1606
|
+
(items)["push"](u);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
((i = (i + 1)));
|
|
1614
|
+
}
|
|
1615
|
+
return (PersistentVector)["from"](items);
|
|
1616
|
+
}
|
|
1617
|
+
} else {
|
|
1618
|
+
if (((kind === "rep*") || (kind === "rep+"))) {
|
|
1619
|
+
{
|
|
1620
|
+
let inner = (cfg)["inner"];
|
|
1621
|
+
let arr = to_js_array(conformed);
|
|
1622
|
+
let items = [];
|
|
1623
|
+
let i = 0;
|
|
1624
|
+
while (__eliscript_numeric_relation("<", i, ((arr) ?? []).length)) {
|
|
1625
|
+
{
|
|
1626
|
+
let u = unform(inner, (arr)[i]);
|
|
1627
|
+
if (__eliscript_truthy(regex_schema_QMARK_(inner))) {
|
|
1628
|
+
{
|
|
1629
|
+
let ua = to_js_array(u);
|
|
1630
|
+
let k = 0;
|
|
1631
|
+
while (__eliscript_numeric_relation("<", k, ((ua) ?? []).length)) {
|
|
1632
|
+
(items)["push"]((ua)[k]);
|
|
1633
|
+
((k = (k + 1)));
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
} else {
|
|
1637
|
+
(items)["push"](u);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
((i = (i + 1)));
|
|
1641
|
+
}
|
|
1642
|
+
return (PersistentVector)["from"](items);
|
|
1643
|
+
}
|
|
1644
|
+
} else {
|
|
1645
|
+
if ((kind === "opt?")) {
|
|
1646
|
+
if ((conformed === null)) {
|
|
1647
|
+
return EMPTY_VECTOR;
|
|
1648
|
+
} else {
|
|
1649
|
+
{
|
|
1650
|
+
let inner = (cfg)["inner"];
|
|
1651
|
+
let u = unform(inner, conformed);
|
|
1652
|
+
if (__eliscript_truthy(regex_schema_QMARK_(inner))) {
|
|
1653
|
+
return u;
|
|
1654
|
+
} else {
|
|
1655
|
+
return persistentVector(u);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
} else {
|
|
1660
|
+
if ((kind === "keys")) {
|
|
1661
|
+
{
|
|
1662
|
+
let out = conformed;
|
|
1663
|
+
let all_entries = ((cfg)["req"])["concat"]((cfg)["opt"]);
|
|
1664
|
+
let i = 0;
|
|
1665
|
+
while (__eliscript_numeric_relation("<", i, ((all_entries) ?? []).length)) {
|
|
1666
|
+
{
|
|
1667
|
+
let e = (all_entries)[i];
|
|
1668
|
+
let k = (e)["key"];
|
|
1669
|
+
if (__eliscript_truthy(Collection.contains(out, k))) {
|
|
1670
|
+
((out = Collection.assoc(out, k, unform((e)["spec"], Collection.get(out, k)))));
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
((i = (i + 1)));
|
|
1674
|
+
}
|
|
1675
|
+
return out;
|
|
1676
|
+
}
|
|
1677
|
+
} else {
|
|
1678
|
+
if ((kind === "coll-of")) {
|
|
1679
|
+
{
|
|
1680
|
+
let item_spec = (cfg)["item"];
|
|
1681
|
+
let arr = to_js_array(conformed);
|
|
1682
|
+
{
|
|
1683
|
+
let out = (arr)["map"](((el) => {
|
|
1684
|
+
return unform(item_spec, el);
|
|
1685
|
+
}));
|
|
1686
|
+
if (__eliscript_truthy(Collection.isSet(conformed))) {
|
|
1687
|
+
return persistentHashSet(...(out ?? []));
|
|
1688
|
+
} else {
|
|
1689
|
+
if (__eliscript_truthy(Collection.isList(conformed))) {
|
|
1690
|
+
return persistentList(...(out ?? []));
|
|
1691
|
+
} else {
|
|
1692
|
+
return (PersistentVector)["from"](out);
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
} else {
|
|
1698
|
+
if ((kind === "tuple")) {
|
|
1699
|
+
{
|
|
1700
|
+
let specs = (cfg)["items"];
|
|
1701
|
+
let arr = to_js_array(conformed);
|
|
1702
|
+
let out = [];
|
|
1703
|
+
let i = 0;
|
|
1704
|
+
while (__eliscript_numeric_relation("<", i, ((specs) ?? []).length)) {
|
|
1705
|
+
(out)["push"](unform((specs)[i], (arr)[i]));
|
|
1706
|
+
((i = (i + 1)));
|
|
1707
|
+
}
|
|
1708
|
+
return (PersistentVector)["from"](out);
|
|
1709
|
+
}
|
|
1710
|
+
} else {
|
|
1711
|
+
if ((kind === "and")) {
|
|
1712
|
+
{
|
|
1713
|
+
let specs = (cfg)["specs"];
|
|
1714
|
+
let cur = conformed;
|
|
1715
|
+
let i = __eliscript_numeric_decrement((((cfg)["specs"]) ?? []).length);
|
|
1716
|
+
while (__eliscript_numeric_relation(">=", i, 0)) {
|
|
1717
|
+
((cur = unform((specs)[i], cur)));
|
|
1718
|
+
((i = __eliscript_numeric_decrement(i)));
|
|
1719
|
+
}
|
|
1720
|
+
return cur;
|
|
1721
|
+
}
|
|
1722
|
+
} else {
|
|
1723
|
+
if ((kind === "nilable")) {
|
|
1724
|
+
if ((conformed === null)) {
|
|
1725
|
+
return null;
|
|
1726
|
+
} else {
|
|
1727
|
+
return unform((cfg)["inner"], conformed);
|
|
1728
|
+
}
|
|
1729
|
+
} else {
|
|
1730
|
+
return conformed;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
function explain_into(schema, value, path, via, in_path, problems) {
|
|
1744
|
+
{
|
|
1745
|
+
let s = resolve_spec(schema);
|
|
1746
|
+
let kind = (s)["kind"];
|
|
1747
|
+
let name = (s)["name"];
|
|
1748
|
+
let cfg = (s)["config"];
|
|
1749
|
+
let next_via = (via)["concat"]([name]);
|
|
1750
|
+
if ((kind === "any")) {
|
|
1751
|
+
return null;
|
|
1752
|
+
} else {
|
|
1753
|
+
if ((kind === "pred")) {
|
|
1754
|
+
if ((!__eliscript_truthy(truthy_QMARK_(((cfg)["pred"])(value))))) {
|
|
1755
|
+
return push_problem(problems, path, name, value, via, in_path, "predicate failed");
|
|
1756
|
+
} else {
|
|
1757
|
+
return null;
|
|
1758
|
+
}
|
|
1759
|
+
} else {
|
|
1760
|
+
if ((kind === "int-in")) {
|
|
1761
|
+
if ((!(__eliscript_truthy(Number.isSafeInteger(value)) && __eliscript_numeric_relation(">=", value, (cfg)["min"]) && __eliscript_numeric_relation("<=", value, (cfg)["max"])))) {
|
|
1762
|
+
return push_problem(problems, path, name, value, via, in_path, (String("expected integer in [") + String((cfg)["min"]) + String(", ") + String((cfg)["max"]) + String("]")));
|
|
1763
|
+
} else {
|
|
1764
|
+
return null;
|
|
1765
|
+
}
|
|
1766
|
+
} else {
|
|
1767
|
+
if ((kind === "double-in")) {
|
|
1768
|
+
if (__eliscript_truthy(invalid_QMARK_(conform(s, value)))) {
|
|
1769
|
+
return push_problem(problems, path, name, value, via, in_path, "number out of bounds or invalid float");
|
|
1770
|
+
} else {
|
|
1771
|
+
return null;
|
|
1772
|
+
}
|
|
1773
|
+
} else {
|
|
1774
|
+
if ((kind === "string-len")) {
|
|
1775
|
+
if (__eliscript_truthy(invalid_QMARK_(conform(s, value)))) {
|
|
1776
|
+
return push_problem(problems, path, name, value, via, in_path, "expected string within length bounds");
|
|
1777
|
+
} else {
|
|
1778
|
+
return null;
|
|
1779
|
+
}
|
|
1780
|
+
} else {
|
|
1781
|
+
if ((kind === "nilable")) {
|
|
1782
|
+
if ((!(value === null))) {
|
|
1783
|
+
return explain_into((cfg)["inner"], value, path, next_via, in_path, problems);
|
|
1784
|
+
} else {
|
|
1785
|
+
return null;
|
|
1786
|
+
}
|
|
1787
|
+
} else {
|
|
1788
|
+
if ((kind === "enum")) {
|
|
1789
|
+
if ((!__eliscript_truthy(array_contains_equal_QMARK_((cfg)["values"], value)))) {
|
|
1790
|
+
return push_problem(problems, path, "enum", value, via, in_path, "value not in allowed enum set");
|
|
1791
|
+
} else {
|
|
1792
|
+
return null;
|
|
1793
|
+
}
|
|
1794
|
+
} else {
|
|
1795
|
+
if ((kind === "and")) {
|
|
1796
|
+
{
|
|
1797
|
+
let specs = (cfg)["specs"];
|
|
1798
|
+
let cur = value;
|
|
1799
|
+
let i = 0;
|
|
1800
|
+
let failed = false;
|
|
1801
|
+
while ((!(__eliscript_truthy(failed)) && __eliscript_numeric_relation("<", i, ((specs) ?? []).length))) {
|
|
1802
|
+
{
|
|
1803
|
+
let sub = (specs)[i];
|
|
1804
|
+
{
|
|
1805
|
+
let c = conform(sub, cur);
|
|
1806
|
+
if (__eliscript_truthy(invalid_QMARK_(c))) {
|
|
1807
|
+
explain_into(sub, cur, (path)["concat"]([i]), next_via, in_path, problems);
|
|
1808
|
+
((failed = true));
|
|
1809
|
+
} else {
|
|
1810
|
+
((cur = c));
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
((i = (i + 1)));
|
|
1815
|
+
}
|
|
1816
|
+
return null;
|
|
1817
|
+
}
|
|
1818
|
+
} else {
|
|
1819
|
+
if ((kind === "or")) {
|
|
1820
|
+
if (__eliscript_truthy(invalid_QMARK_(conform(s, value)))) {
|
|
1821
|
+
{
|
|
1822
|
+
let clauses = (cfg)["clauses"];
|
|
1823
|
+
let i = 0;
|
|
1824
|
+
while (__eliscript_numeric_relation("<", i, ((clauses) ?? []).length)) {
|
|
1825
|
+
{
|
|
1826
|
+
let clause = (clauses)[i];
|
|
1827
|
+
explain_into((clause)["spec"], value, (path)["concat"]([(clause)["tag"]]), next_via, in_path, problems);
|
|
1828
|
+
}
|
|
1829
|
+
((i = (i + 1)));
|
|
1830
|
+
}
|
|
1831
|
+
return null;
|
|
1832
|
+
}
|
|
1833
|
+
} else {
|
|
1834
|
+
return null;
|
|
1835
|
+
}
|
|
1836
|
+
} else {
|
|
1837
|
+
if ((kind === "keys")) {
|
|
1838
|
+
if (!(__eliscript_truthy(Collection.isMap(value)))) {
|
|
1839
|
+
return push_problem(problems, path, "map?", value, via, in_path, "expected a map");
|
|
1840
|
+
} else {
|
|
1841
|
+
{
|
|
1842
|
+
let req = (cfg)["req"];
|
|
1843
|
+
let opt = (cfg)["opt"];
|
|
1844
|
+
let closed = (cfg)["closed"];
|
|
1845
|
+
let i = 0;
|
|
1846
|
+
while (__eliscript_numeric_relation("<", i, ((req) ?? []).length)) {
|
|
1847
|
+
{
|
|
1848
|
+
let entry = (req)[i];
|
|
1849
|
+
let k = (entry)["key"];
|
|
1850
|
+
let v = Collection.get(value, k, (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")));
|
|
1851
|
+
if ((v === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")))) {
|
|
1852
|
+
push_problem(problems, (path)["concat"]([k]), (String("contains? ") + String(printValue(k))), value, next_via, in_path, (String("missing required key ") + String(printValue(k))));
|
|
1853
|
+
} else {
|
|
1854
|
+
if ((!__eliscript_truthy(valid_QMARK_((entry)["spec"], v)))) {
|
|
1855
|
+
explain_into((entry)["spec"], v, (path)["concat"]([k]), next_via, (in_path)["concat"]([k]), problems);
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
((i = (i + 1)));
|
|
1860
|
+
}
|
|
1861
|
+
((i = 0));
|
|
1862
|
+
while (__eliscript_numeric_relation("<", i, ((opt) ?? []).length)) {
|
|
1863
|
+
{
|
|
1864
|
+
let entry = (opt)[i];
|
|
1865
|
+
let k = (entry)["key"];
|
|
1866
|
+
let v = Collection.get(value, k, (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")));
|
|
1867
|
+
if ((!((v === (__eliscript_tdz_ready_19 === true ? MISSING : __eliscript_tdz_error("MISSING")))) && !(__eliscript_truthy(valid_QMARK_((entry)["spec"], v))))) {
|
|
1868
|
+
explain_into((entry)["spec"], v, (path)["concat"]([k]), next_via, (in_path)["concat"]([k]), problems);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
((i = (i + 1)));
|
|
1872
|
+
}
|
|
1873
|
+
if (__eliscript_truthy(closed)) {
|
|
1874
|
+
{
|
|
1875
|
+
let all_ks = (req)["concat"](opt);
|
|
1876
|
+
return Collection.reduceKV(value, ((_acc, k, v) => {
|
|
1877
|
+
{
|
|
1878
|
+
let found = false;
|
|
1879
|
+
let j = 0;
|
|
1880
|
+
while ((!(__eliscript_truthy(found)) && __eliscript_numeric_relation("<", j, ((all_ks) ?? []).length))) {
|
|
1881
|
+
if (__eliscript_truthy(equalValues(k, ((all_ks)[j])["key"]))) {
|
|
1882
|
+
((found = true));
|
|
1883
|
+
}
|
|
1884
|
+
((j = (j + 1)));
|
|
1885
|
+
}
|
|
1886
|
+
if ((!__eliscript_truthy(found))) {
|
|
1887
|
+
push_problem(problems, path, "closed-keys", v, next_via, (in_path)["concat"]([k]), (String("unexpected extra key ") + String(printValue(k))));
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
return null;
|
|
1891
|
+
}), null);
|
|
1892
|
+
}
|
|
1893
|
+
} else {
|
|
1894
|
+
return null;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
} else {
|
|
1899
|
+
if ((kind === "coll-of")) {
|
|
1900
|
+
if (!((__eliscript_truthy(Collection.isVector(value)) || __eliscript_truthy(Collection.isList(value)) || __eliscript_truthy(Collection.isSet(value)) || __eliscript_truthy(Collection.isQueue(value)) || __eliscript_truthy(Collection.isSequence(value)) || __eliscript_truthy(Array.isArray(value))))) {
|
|
1901
|
+
return push_problem(problems, path, "coll?", value, via, in_path, "expected collection");
|
|
1902
|
+
} else {
|
|
1903
|
+
{
|
|
1904
|
+
let expected_kind = (cfg)["kind"];
|
|
1905
|
+
let kind_ok = ((expected_kind == null) ? true : ((expected_kind === "vector") ? Collection.isVector(value) : ((expected_kind === "list") ? Collection.isList(value) : ((expected_kind === "set") ? Collection.isSet(value) : ((__eliscript_value_type(expected_kind) === "function") ? truthy_QMARK_(expected_kind(value)) : true)))));
|
|
1906
|
+
if (!(__eliscript_truthy(kind_ok))) {
|
|
1907
|
+
return push_problem(problems, path, (String("kind:") + String(expected_kind)), value, via, in_path, "collection kind mismatch");
|
|
1908
|
+
} else {
|
|
1909
|
+
{
|
|
1910
|
+
let items = to_js_array(value);
|
|
1911
|
+
let min_c = (cfg)["minCount"];
|
|
1912
|
+
let max_c = (cfg)["maxCount"];
|
|
1913
|
+
let uniq = (cfg)["distinct"];
|
|
1914
|
+
let item_spec = (cfg)["item"];
|
|
1915
|
+
let seen = [];
|
|
1916
|
+
let i = 0;
|
|
1917
|
+
if (__eliscript_numeric_relation("<", ((items) ?? []).length, min_c)) {
|
|
1918
|
+
push_problem(problems, path, (String("min-count>=") + String(min_c)), value, next_via, in_path, (String("expected at least ") + String(min_c) + String(" elements, got ") + String(((items) ?? []).length)));
|
|
1919
|
+
}
|
|
1920
|
+
if ((!((max_c == null)) && __eliscript_numeric_relation(">", ((items) ?? []).length, max_c))) {
|
|
1921
|
+
push_problem(problems, path, (String("max-count<=") + String(max_c)), value, next_via, in_path, (String("expected at most ") + String(max_c) + String(" elements, got ") + String(((items) ?? []).length)));
|
|
1922
|
+
}
|
|
1923
|
+
while (__eliscript_numeric_relation("<", i, ((items) ?? []).length)) {
|
|
1924
|
+
{
|
|
1925
|
+
let el = (items)[i];
|
|
1926
|
+
if ((__eliscript_truthy(uniq) && __eliscript_truthy(array_contains_equal_QMARK_(seen, el)))) {
|
|
1927
|
+
push_problem(problems, path, "distinct", el, next_via, (in_path)["concat"]([i]), "duplicate collection element");
|
|
1928
|
+
}
|
|
1929
|
+
if (__eliscript_truthy(uniq)) {
|
|
1930
|
+
(seen)["push"](el);
|
|
1931
|
+
}
|
|
1932
|
+
if ((!__eliscript_truthy(valid_QMARK_(item_spec, el)))) {
|
|
1933
|
+
explain_into(item_spec, el, path, next_via, (in_path)["concat"]([i]), problems);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
((i = (i + 1)));
|
|
1937
|
+
}
|
|
1938
|
+
return null;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
} else {
|
|
1944
|
+
if ((kind === "map-of")) {
|
|
1945
|
+
if (!(__eliscript_truthy(Collection.isMap(value)))) {
|
|
1946
|
+
return push_problem(problems, path, "map?", value, via, in_path, "expected a map");
|
|
1947
|
+
} else {
|
|
1948
|
+
{
|
|
1949
|
+
let cnt = Collection.count(value);
|
|
1950
|
+
let min_c = (cfg)["minCount"];
|
|
1951
|
+
let max_c = (cfg)["maxCount"];
|
|
1952
|
+
let ks = (cfg)["key"];
|
|
1953
|
+
let vs = (cfg)["val"];
|
|
1954
|
+
let entries = [];
|
|
1955
|
+
if (__eliscript_numeric_relation("<", cnt, min_c)) {
|
|
1956
|
+
push_problem(problems, path, (String("min-count>=") + String(min_c)), value, next_via, in_path, (String("expected at least ") + String(min_c) + String(" map entries")));
|
|
1957
|
+
}
|
|
1958
|
+
if ((!((max_c == null)) && __eliscript_numeric_relation(">", cnt, max_c))) {
|
|
1959
|
+
push_problem(problems, path, (String("max-count<=") + String(max_c)), value, next_via, in_path, (String("expected at most ") + String(max_c) + String(" map entries")));
|
|
1960
|
+
}
|
|
1961
|
+
Collection.reduceKV(value, ((_acc, k, v) => {
|
|
1962
|
+
(entries)["push"]([k, v]);
|
|
1963
|
+
return null;
|
|
1964
|
+
}), null);
|
|
1965
|
+
{
|
|
1966
|
+
let i = 0;
|
|
1967
|
+
while (__eliscript_numeric_relation("<", i, ((entries) ?? []).length)) {
|
|
1968
|
+
{
|
|
1969
|
+
let pair = (entries)[i];
|
|
1970
|
+
let k = (pair)[0];
|
|
1971
|
+
let v = (pair)[1];
|
|
1972
|
+
if ((!__eliscript_truthy(valid_QMARK_(ks, k)))) {
|
|
1973
|
+
explain_into(ks, k, (path)["concat"]([keyword("key")]), next_via, (in_path)["concat"]([k]), problems);
|
|
1974
|
+
}
|
|
1975
|
+
if ((!__eliscript_truthy(valid_QMARK_(vs, v)))) {
|
|
1976
|
+
explain_into(vs, v, (path)["concat"]([keyword("val")]), next_via, (in_path)["concat"]([k]), problems);
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
((i = (i + 1)));
|
|
1980
|
+
}
|
|
1981
|
+
return null;
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
} else {
|
|
1986
|
+
if ((kind === "tuple")) {
|
|
1987
|
+
if (!((__eliscript_truthy(Collection.isVector(value)) || __eliscript_truthy(Array.isArray(value))))) {
|
|
1988
|
+
return push_problem(problems, path, "vector?", value, via, in_path, "expected tuple vector");
|
|
1989
|
+
} else {
|
|
1990
|
+
{
|
|
1991
|
+
let items = to_js_array(value);
|
|
1992
|
+
let specs = (cfg)["items"];
|
|
1993
|
+
if (!((((items) ?? []).length === ((specs) ?? []).length))) {
|
|
1994
|
+
return push_problem(problems, path, (String("count=") + String(((specs) ?? []).length)), value, via, in_path, (String("expected tuple of length ") + String(((specs) ?? []).length) + String(", got ") + String(((items) ?? []).length)));
|
|
1995
|
+
} else {
|
|
1996
|
+
{
|
|
1997
|
+
let i = 0;
|
|
1998
|
+
while (__eliscript_numeric_relation("<", i, ((specs) ?? []).length)) {
|
|
1999
|
+
if ((!__eliscript_truthy(valid_QMARK_((specs)[i], (items)[i])))) {
|
|
2000
|
+
explain_into((specs)[i], (items)[i], (path)["concat"]([i]), next_via, (in_path)["concat"]([i]), problems);
|
|
2001
|
+
}
|
|
2002
|
+
((i = (i + 1)));
|
|
2003
|
+
}
|
|
2004
|
+
return null;
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
} else {
|
|
2010
|
+
if (__eliscript_truthy(regex_schema_QMARK_(s))) {
|
|
2011
|
+
if (!((__eliscript_truthy(Collection.isSequential(value)) || __eliscript_truthy(Collection.isList(value)) || __eliscript_truthy(Collection.isVector(value)) || __eliscript_truthy(Array.isArray(value))))) {
|
|
2012
|
+
return push_problem(problems, path, "sequential?", value, via, in_path, "expected sequence");
|
|
2013
|
+
} else {
|
|
2014
|
+
{
|
|
2015
|
+
let items = to_js_array(value);
|
|
2016
|
+
let m = regex_match(s, items, 0);
|
|
2017
|
+
if (!(__eliscript_truthy((m)["ok"]))) {
|
|
2018
|
+
{
|
|
2019
|
+
let bad_pos = (m)["pos"];
|
|
2020
|
+
let tag = (m)["clauseTag"];
|
|
2021
|
+
return push_problem(problems, ((tag == null) ? path : (path)["concat"]([tag])), (__eliscript_truthy((m)["schema"]) ? ((m)["schema"])["name"] : name), (__eliscript_numeric_relation("<", bad_pos, ((items) ?? []).length) ? (items)[bad_pos] : null), next_via, (in_path)["concat"]([bad_pos]), (m)["reason"]);
|
|
2022
|
+
}
|
|
2023
|
+
} else {
|
|
2024
|
+
if (__eliscript_numeric_relation("<", (m)["pos"], ((items) ?? []).length)) {
|
|
2025
|
+
return push_problem(problems, path, name, (items)[(m)["pos"]], next_via, (in_path)["concat"]([(m)["pos"]]), "unexpected trailing element in sequence");
|
|
2026
|
+
} else {
|
|
2027
|
+
return null;
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
} else {
|
|
2033
|
+
if (__eliscript_truthy(invalid_QMARK_(conform(s, value)))) {
|
|
2034
|
+
return push_problem(problems, path, name, value, via, in_path, "schema check failed");
|
|
2035
|
+
} else {
|
|
2036
|
+
return null;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
function explain_data(schema, value) {
|
|
2055
|
+
{
|
|
2056
|
+
let s = resolve_spec(schema);
|
|
2057
|
+
if (__eliscript_truthy(valid_QMARK_(s, value))) {
|
|
2058
|
+
return null;
|
|
2059
|
+
} else {
|
|
2060
|
+
{
|
|
2061
|
+
let problems = [];
|
|
2062
|
+
explain_into(s, value, [], [], [], problems);
|
|
2063
|
+
if ((((problems) ?? []).length === 0)) {
|
|
2064
|
+
push_problem(problems, [], (s)["name"], value, [], [], "validation failed");
|
|
2065
|
+
}
|
|
2066
|
+
return kv_map((__eliscript_tdz_ready_1 === true ? KW_SCHEMA : __eliscript_tdz_error("KW_SCHEMA")), s, (__eliscript_tdz_ready_2 === true ? KW_VALUE : __eliscript_tdz_error("KW_VALUE")), value, (__eliscript_tdz_ready_3 === true ? KW_PROBLEMS : __eliscript_tdz_error("KW_PROBLEMS")), (PersistentVector)["from"](problems));
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
function explain_str(schema, value) {
|
|
2072
|
+
{
|
|
2073
|
+
let data = explain_data(schema, value);
|
|
2074
|
+
if ((data === null)) {
|
|
2075
|
+
return "Success!\n";
|
|
2076
|
+
} else {
|
|
2077
|
+
{
|
|
2078
|
+
let problems = Collection.get(data, (__eliscript_tdz_ready_3 === true ? KW_PROBLEMS : __eliscript_tdz_error("KW_PROBLEMS")), EMPTY_VECTOR);
|
|
2079
|
+
let lines = [];
|
|
2080
|
+
let i = 0;
|
|
2081
|
+
let count = Collection.count(problems);
|
|
2082
|
+
while (__eliscript_numeric_relation("<", i, count)) {
|
|
2083
|
+
{
|
|
2084
|
+
let p = (problems)["nth"](i);
|
|
2085
|
+
let val_str = printValue(Collection.get(p, (__eliscript_tdz_ready_6 === true ? KW_VAL : __eliscript_tdz_error("KW_VAL"))));
|
|
2086
|
+
let pred_str = Collection.get(p, (__eliscript_tdz_ready_5 === true ? KW_PRED : __eliscript_tdz_error("KW_PRED")));
|
|
2087
|
+
let in_vec = Collection.get(p, (__eliscript_tdz_ready_8 === true ? KW_IN : __eliscript_tdz_error("KW_IN")), EMPTY_VECTOR);
|
|
2088
|
+
let path_vec = Collection.get(p, (__eliscript_tdz_ready_4 === true ? KW_PATH : __eliscript_tdz_error("KW_PATH")), EMPTY_VECTOR);
|
|
2089
|
+
let reason = Collection.get(p, (__eliscript_tdz_ready_9 === true ? KW_REASON : __eliscript_tdz_error("KW_REASON")), "");
|
|
2090
|
+
(lines)["push"]((String(val_str) + String(" - failed: ") + String(pred_str) + String((__eliscript_numeric_relation(">", Collection.count(in_vec), 0) ? (String(" in: ") + String(printValue(in_vec))) : "")) + String((__eliscript_numeric_relation(">", Collection.count(path_vec), 0) ? (String(" at: ") + String(printValue(path_vec))) : "")) + String((__eliscript_numeric_relation(">", ((reason) ?? []).length, 0) ? (String(" (") + String(reason) + String(")")) : ""))));
|
|
2091
|
+
}
|
|
2092
|
+
((i = (i + 1)));
|
|
2093
|
+
}
|
|
2094
|
+
return (String(__eliscript_at_direct(lines, "join", "\n")) + String("\n"));
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
function explain(schema, value) {
|
|
2100
|
+
console.log((explain_str(schema, value))["trimEnd"]());
|
|
2101
|
+
return null;
|
|
2102
|
+
}
|
|
2103
|
+
function gen_from_spec(schema) {
|
|
2104
|
+
{
|
|
2105
|
+
let s = resolve_spec(schema);
|
|
2106
|
+
let custom = (s)["customGen"];
|
|
2107
|
+
let kind = (s)["kind"];
|
|
2108
|
+
let cfg = (s)["config"];
|
|
2109
|
+
if (!((custom == null))) {
|
|
2110
|
+
return custom;
|
|
2111
|
+
} else {
|
|
2112
|
+
if (((kind === "any") || (kind === "pred") || (kind === "int-in") || (kind === "double-in") || (kind === "string-len") || (kind === "enum"))) {
|
|
2113
|
+
return ((__eliscript_value_30) => { throw __eliscript_value_30; })(new (globalThis.Error)((String("no generator available for predicate schema ") + String((s)["name"]))));
|
|
2114
|
+
} else {
|
|
2115
|
+
if ((kind === "nilable")) {
|
|
2116
|
+
{
|
|
2117
|
+
let inner_gen = gen_from_spec((cfg)["inner"]);
|
|
2118
|
+
return make_gen("nilable", ((rng, size) => {
|
|
2119
|
+
if ((rng_next_int(rng, 0, 7) === 0)) {
|
|
2120
|
+
return null;
|
|
2121
|
+
} else {
|
|
2122
|
+
return (inner_gen)["sampleFn"](rng, size);
|
|
2123
|
+
}
|
|
2124
|
+
}));
|
|
2125
|
+
}
|
|
2126
|
+
} else {
|
|
2127
|
+
if ((kind === "and")) {
|
|
2128
|
+
{
|
|
2129
|
+
let specs = (cfg)["specs"];
|
|
2130
|
+
let base = gen_from_spec((specs)[0]);
|
|
2131
|
+
if ((((specs) ?? []).length === 1)) {
|
|
2132
|
+
return base;
|
|
2133
|
+
} else {
|
|
2134
|
+
return gen_such_that(((v) => {
|
|
2135
|
+
return valid_QMARK_(s, v);
|
|
2136
|
+
}), base);
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
} else {
|
|
2140
|
+
if ((kind === "or")) {
|
|
2141
|
+
{
|
|
2142
|
+
let clauses = (cfg)["clauses"];
|
|
2143
|
+
return gen_one_of((clauses)["map"](((c) => {
|
|
2144
|
+
return gen_from_spec((c)["spec"]);
|
|
2145
|
+
})));
|
|
2146
|
+
}
|
|
2147
|
+
} else {
|
|
2148
|
+
if ((kind === "keys")) {
|
|
2149
|
+
{
|
|
2150
|
+
let req = (cfg)["req"];
|
|
2151
|
+
let opt = (cfg)["opt"];
|
|
2152
|
+
{
|
|
2153
|
+
let req_gens = (req)["map"](((e) => {
|
|
2154
|
+
return ({"key": (e)["key"], "gen": gen_from_spec((e)["spec"])});
|
|
2155
|
+
}));
|
|
2156
|
+
let opt_gens = (opt)["map"](((e) => {
|
|
2157
|
+
return ({"key": (e)["key"], "gen": gen_from_spec((e)["spec"])});
|
|
2158
|
+
}));
|
|
2159
|
+
return make_gen("keys", ((rng, size) => {
|
|
2160
|
+
{
|
|
2161
|
+
let pairs = [];
|
|
2162
|
+
let i = 0;
|
|
2163
|
+
while (__eliscript_numeric_relation("<", i, ((req_gens) ?? []).length)) {
|
|
2164
|
+
{
|
|
2165
|
+
let entry = (req_gens)[i];
|
|
2166
|
+
(pairs)["push"]((entry)["key"]);
|
|
2167
|
+
(pairs)["push"](((entry)["gen"])["sampleFn"](rng, size));
|
|
2168
|
+
}
|
|
2169
|
+
((i = (i + 1)));
|
|
2170
|
+
}
|
|
2171
|
+
((i = 0));
|
|
2172
|
+
while (__eliscript_numeric_relation("<", i, ((opt_gens) ?? []).length)) {
|
|
2173
|
+
if ((rng_next_int(rng, 0, 1) === 1)) {
|
|
2174
|
+
{
|
|
2175
|
+
let entry = (opt_gens)[i];
|
|
2176
|
+
(pairs)["push"]((entry)["key"]);
|
|
2177
|
+
(pairs)["push"](((entry)["gen"])["sampleFn"](rng, size));
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
((i = (i + 1)));
|
|
2181
|
+
}
|
|
2182
|
+
return kv_map(...(pairs ?? []));
|
|
2183
|
+
}
|
|
2184
|
+
}));
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
} else {
|
|
2188
|
+
if ((kind === "coll-of")) {
|
|
2189
|
+
{
|
|
2190
|
+
let ig = gen_from_spec((cfg)["item"]);
|
|
2191
|
+
let expected_kind = (cfg)["kind"];
|
|
2192
|
+
let vg = gen_vector(ig, (cfg)["minCount"], (cfg)["maxCount"], (cfg)["distinct"]);
|
|
2193
|
+
if ((expected_kind === "set")) {
|
|
2194
|
+
return gen_fmap(((v) => {
|
|
2195
|
+
return persistentHashSet(...(to_js_array(v) ?? []));
|
|
2196
|
+
}), vg);
|
|
2197
|
+
} else {
|
|
2198
|
+
if ((expected_kind === "list")) {
|
|
2199
|
+
return gen_fmap(((v) => {
|
|
2200
|
+
return persistentList(...(to_js_array(v) ?? []));
|
|
2201
|
+
}), vg);
|
|
2202
|
+
} else {
|
|
2203
|
+
return vg;
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
} else {
|
|
2208
|
+
if ((kind === "map-of")) {
|
|
2209
|
+
return gen_map(gen_from_spec((cfg)["key"]), gen_from_spec((cfg)["val"]), (cfg)["minCount"], (cfg)["maxCount"]);
|
|
2210
|
+
} else {
|
|
2211
|
+
if ((kind === "tuple")) {
|
|
2212
|
+
return gen_tuple(...(((cfg)["items"])["map"](gen_from_spec) ?? []));
|
|
2213
|
+
} else {
|
|
2214
|
+
if ((kind === "cat")) {
|
|
2215
|
+
{
|
|
2216
|
+
let clauses = (cfg)["clauses"];
|
|
2217
|
+
return make_gen("cat", ((rng, size) => {
|
|
2218
|
+
{
|
|
2219
|
+
let out = [];
|
|
2220
|
+
let i = 0;
|
|
2221
|
+
while (__eliscript_numeric_relation("<", i, ((clauses) ?? []).length)) {
|
|
2222
|
+
{
|
|
2223
|
+
let sub = ((clauses)[i])["spec"];
|
|
2224
|
+
let sg = gen_from_spec(sub);
|
|
2225
|
+
let part = (sg)["sampleFn"](rng, size);
|
|
2226
|
+
if (__eliscript_truthy(regex_schema_QMARK_(sub))) {
|
|
2227
|
+
{
|
|
2228
|
+
let pa = to_js_array(part);
|
|
2229
|
+
let j = 0;
|
|
2230
|
+
while (__eliscript_numeric_relation("<", j, ((pa) ?? []).length)) {
|
|
2231
|
+
(out)["push"]((pa)[j]);
|
|
2232
|
+
((j = (j + 1)));
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
} else {
|
|
2236
|
+
(out)["push"](part);
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
((i = (i + 1)));
|
|
2240
|
+
}
|
|
2241
|
+
return (PersistentVector)["from"](out);
|
|
2242
|
+
}
|
|
2243
|
+
}));
|
|
2244
|
+
}
|
|
2245
|
+
} else {
|
|
2246
|
+
if ((kind === "alt")) {
|
|
2247
|
+
{
|
|
2248
|
+
let clauses = (cfg)["clauses"];
|
|
2249
|
+
return gen_one_of((clauses)["map"](((c) => {
|
|
2250
|
+
return gen_from_spec((c)["spec"]);
|
|
2251
|
+
})));
|
|
2252
|
+
}
|
|
2253
|
+
} else {
|
|
2254
|
+
if ((kind === "rep*")) {
|
|
2255
|
+
return gen_vector(gen_from_spec((cfg)["inner"]), 0, 8);
|
|
2256
|
+
} else {
|
|
2257
|
+
if ((kind === "rep+")) {
|
|
2258
|
+
return gen_vector(gen_from_spec((cfg)["inner"]), 1, 8);
|
|
2259
|
+
} else {
|
|
2260
|
+
if ((kind === "opt?")) {
|
|
2261
|
+
{
|
|
2262
|
+
let inner_g = gen_from_spec((cfg)["inner"]);
|
|
2263
|
+
return make_gen("opt?", ((rng, size) => {
|
|
2264
|
+
if ((rng_next_int(rng, 0, 1) === 0)) {
|
|
2265
|
+
return EMPTY_VECTOR;
|
|
2266
|
+
} else {
|
|
2267
|
+
{
|
|
2268
|
+
let v = (inner_g)["sampleFn"](rng, size);
|
|
2269
|
+
if (__eliscript_truthy(regex_schema_QMARK_((cfg)["inner"]))) {
|
|
2270
|
+
return v;
|
|
2271
|
+
} else {
|
|
2272
|
+
return persistentVector(v);
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
}));
|
|
2277
|
+
}
|
|
2278
|
+
} else {
|
|
2279
|
+
return ((__eliscript_value_31) => { throw __eliscript_value_31; })(new (globalThis.Error)((String("cannot synthesize generator for schema kind ") + String(kind))));
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
function gen_generate(schema_or_gen, options = null) {
|
|
2297
|
+
{
|
|
2298
|
+
let g = ensure_gen(schema_or_gen);
|
|
2299
|
+
let seed = read_opt(options, "seed", null, null, 42);
|
|
2300
|
+
let size = read_opt(options, "size", null, null, 20);
|
|
2301
|
+
let rng = make_rng(seed);
|
|
2302
|
+
return (g)["sampleFn"](rng, size);
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
function gen_sample(schema_or_gen, options = null) {
|
|
2306
|
+
{
|
|
2307
|
+
let g = ensure_gen(schema_or_gen);
|
|
2308
|
+
let count = read_opt(options, "count", null, null, 10);
|
|
2309
|
+
let seed = read_opt(options, "seed", null, null, 42);
|
|
2310
|
+
let size = read_opt(options, "size", null, null, 20);
|
|
2311
|
+
let rng = make_rng(seed);
|
|
2312
|
+
let items = [];
|
|
2313
|
+
let i = 0;
|
|
2314
|
+
while (__eliscript_numeric_relation("<", i, count)) {
|
|
2315
|
+
{
|
|
2316
|
+
let step_size = Math.min(size, (1 + Math.floor(__eliscript_numeric_div(__eliscript_numeric_mul(i, size), Math.max(1, count)))));
|
|
2317
|
+
(items)["push"]((g)["sampleFn"](rng, step_size));
|
|
2318
|
+
}
|
|
2319
|
+
((i = (i + 1)));
|
|
2320
|
+
}
|
|
2321
|
+
return (PersistentVector)["from"](items);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
function shrink_int_toward(val, target) {
|
|
2325
|
+
{
|
|
2326
|
+
let candidates = [];
|
|
2327
|
+
if ((!(val === target))) {
|
|
2328
|
+
(candidates)["push"](target);
|
|
2329
|
+
{
|
|
2330
|
+
let diff = __eliscript_numeric_sub(val, target);
|
|
2331
|
+
{
|
|
2332
|
+
let step = (__eliscript_numeric_relation(">", diff, 0) ? Math.floor(__eliscript_numeric_div(diff, 2)) : Math.ceil(__eliscript_numeric_div(diff, 2)));
|
|
2333
|
+
while (!((step === 0))) {
|
|
2334
|
+
{
|
|
2335
|
+
let cand = (target + step);
|
|
2336
|
+
if ((!((cand === val) || (cand === target)))) {
|
|
2337
|
+
(candidates)["push"](cand);
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
((step = (__eliscript_numeric_relation(">", step, 0) ? Math.floor(__eliscript_numeric_div(step, 2)) : Math.ceil(__eliscript_numeric_div(step, 2)))));
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
{
|
|
2345
|
+
let one_closer = (__eliscript_numeric_relation(">", val, target) ? __eliscript_numeric_decrement(val) : (val + 1));
|
|
2346
|
+
if ((!(one_closer === target))) {
|
|
2347
|
+
(candidates)["push"](one_closer);
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
return candidates;
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
function shrink_string_value(text, min_len) {
|
|
2355
|
+
{
|
|
2356
|
+
let candidates = [];
|
|
2357
|
+
let len = ((text) ?? []).length;
|
|
2358
|
+
if (__eliscript_numeric_relation(">", len, min_len)) {
|
|
2359
|
+
(candidates)["push"]((text)["slice"](0, min_len));
|
|
2360
|
+
{
|
|
2361
|
+
let half = Math.max(min_len, Math.floor(__eliscript_numeric_div((min_len + len), 2)));
|
|
2362
|
+
if ((__eliscript_numeric_relation(">", half, min_len) && __eliscript_numeric_relation("<", half, len))) {
|
|
2363
|
+
(candidates)["push"]((text)["slice"](0, half));
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
if (__eliscript_numeric_relation(">", len, (min_len + 1))) {
|
|
2367
|
+
(candidates)["push"]((text)["slice"](0, __eliscript_numeric_decrement(len)));
|
|
2368
|
+
(candidates)["push"]((text)["slice"](1));
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
return candidates;
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
function wrap_sequential_like(original, arr) {
|
|
2375
|
+
if (__eliscript_truthy(Collection.isSet(original))) {
|
|
2376
|
+
return persistentHashSet(...(arr ?? []));
|
|
2377
|
+
} else {
|
|
2378
|
+
if (__eliscript_truthy(Collection.isList(original))) {
|
|
2379
|
+
return persistentList(...(arr ?? []));
|
|
2380
|
+
} else {
|
|
2381
|
+
return (PersistentVector)["from"](arr);
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
function shrink_sequence_items(original, arr, item_spec, min_c) {
|
|
2386
|
+
{
|
|
2387
|
+
let candidates = [];
|
|
2388
|
+
let n = ((arr) ?? []).length;
|
|
2389
|
+
if ((!(n === 0))) {
|
|
2390
|
+
if (__eliscript_numeric_relation(">", n, min_c)) {
|
|
2391
|
+
(candidates)["push"](wrap_sequential_like(original, (arr)["slice"](0, min_c)));
|
|
2392
|
+
{
|
|
2393
|
+
let half = Math.max(min_c, Math.floor(__eliscript_numeric_div(n, 2)));
|
|
2394
|
+
if (__eliscript_numeric_relation("<", half, n)) {
|
|
2395
|
+
(candidates)["push"](wrap_sequential_like(original, (arr)["slice"](0, half)));
|
|
2396
|
+
{
|
|
2397
|
+
let second_half = (arr)["slice"](__eliscript_numeric_sub(n, half));
|
|
2398
|
+
if (__eliscript_numeric_relation(">=", ((second_half) ?? []).length, min_c)) {
|
|
2399
|
+
(candidates)["push"](wrap_sequential_like(original, second_half));
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
{
|
|
2405
|
+
let i = 0;
|
|
2406
|
+
while (__eliscript_numeric_relation("<", i, n)) {
|
|
2407
|
+
{
|
|
2408
|
+
let without = [];
|
|
2409
|
+
let j = 0;
|
|
2410
|
+
while (__eliscript_numeric_relation("<", j, n)) {
|
|
2411
|
+
if ((!(j === i))) {
|
|
2412
|
+
(without)["push"]((arr)[j]);
|
|
2413
|
+
}
|
|
2414
|
+
((j = (j + 1)));
|
|
2415
|
+
}
|
|
2416
|
+
if (__eliscript_numeric_relation(">=", ((without) ?? []).length, min_c)) {
|
|
2417
|
+
(candidates)["push"](wrap_sequential_like(original, without));
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
((i = (i + 1)));
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
if (__eliscript_truthy(item_spec)) {
|
|
2425
|
+
{
|
|
2426
|
+
let i = 0;
|
|
2427
|
+
while (__eliscript_numeric_relation("<", i, n)) {
|
|
2428
|
+
{
|
|
2429
|
+
let el_shrinks = shrink_value(item_spec, (arr)[i]);
|
|
2430
|
+
let si = 0;
|
|
2431
|
+
while (__eliscript_numeric_relation("<", si, ((el_shrinks) ?? []).length)) {
|
|
2432
|
+
{
|
|
2433
|
+
let copy = (arr)["slice"]();
|
|
2434
|
+
((copy)[i] = (el_shrinks)[si]);
|
|
2435
|
+
(candidates)["push"](wrap_sequential_like(original, copy));
|
|
2436
|
+
}
|
|
2437
|
+
((si = (si + 1)));
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
((i = (i + 1)));
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
return candidates;
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
function shrink_value(schema, value) {
|
|
2449
|
+
{
|
|
2450
|
+
let s = resolve_spec(schema);
|
|
2451
|
+
let kind = (s)["kind"];
|
|
2452
|
+
let cfg = (s)["config"];
|
|
2453
|
+
let candidates = [];
|
|
2454
|
+
if ((kind === "nilable")) {
|
|
2455
|
+
if ((!(value === null))) {
|
|
2456
|
+
(candidates)["push"](null);
|
|
2457
|
+
{
|
|
2458
|
+
let sub = shrink_value((cfg)["inner"], value);
|
|
2459
|
+
let i = 0;
|
|
2460
|
+
while (__eliscript_numeric_relation("<", i, ((sub) ?? []).length)) {
|
|
2461
|
+
(candidates)["push"]((sub)[i]);
|
|
2462
|
+
((i = (i + 1)));
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
} else {
|
|
2467
|
+
if ((kind === "int-in")) {
|
|
2468
|
+
{
|
|
2469
|
+
let lo = (cfg)["min"];
|
|
2470
|
+
let hi = (cfg)["max"];
|
|
2471
|
+
let target = (__eliscript_numeric_relation("<=", lo, 0) ? (__eliscript_numeric_relation(">=", hi, 0) ? 0 : hi) : lo);
|
|
2472
|
+
((candidates = shrink_int_toward(value, target)));
|
|
2473
|
+
}
|
|
2474
|
+
} else {
|
|
2475
|
+
if ((kind === "double-in")) {
|
|
2476
|
+
if (((__eliscript_value_type(value) === "number") && __eliscript_truthy(Number.isFinite(value)))) {
|
|
2477
|
+
{
|
|
2478
|
+
let lo = (cfg)["min"];
|
|
2479
|
+
let hi = (cfg)["max"];
|
|
2480
|
+
let target = (__eliscript_numeric_relation("<=", lo, 0) ? (__eliscript_numeric_relation(">=", hi, 0) ? 0 : hi) : lo);
|
|
2481
|
+
if ((!(value === target))) {
|
|
2482
|
+
(candidates)["push"](target);
|
|
2483
|
+
{
|
|
2484
|
+
let tr = Math.trunc(value);
|
|
2485
|
+
if ((!((tr === value)) && __eliscript_numeric_relation(">=", tr, lo) && __eliscript_numeric_relation("<=", tr, hi))) {
|
|
2486
|
+
(candidates)["push"](tr);
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
{
|
|
2490
|
+
let mid = __eliscript_numeric_div((value + target), 2);
|
|
2491
|
+
if ((!((mid === value)) && __eliscript_numeric_relation(">=", mid, lo) && __eliscript_numeric_relation("<=", mid, hi))) {
|
|
2492
|
+
(candidates)["push"](mid);
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
} else {
|
|
2499
|
+
if ((kind === "string-len")) {
|
|
2500
|
+
if ((__eliscript_value_type(value) === "string")) {
|
|
2501
|
+
((candidates = shrink_string_value(value, (cfg)["min"])));
|
|
2502
|
+
}
|
|
2503
|
+
} else {
|
|
2504
|
+
if ((kind === "pred")) {
|
|
2505
|
+
{
|
|
2506
|
+
let name = (s)["name"];
|
|
2507
|
+
if (__eliscript_truthy(Number.isSafeInteger(value))) {
|
|
2508
|
+
((candidates = shrink_int_toward(value, 0)));
|
|
2509
|
+
} else {
|
|
2510
|
+
if ((__eliscript_value_type(value) === "string")) {
|
|
2511
|
+
((candidates = shrink_string_value(value, 0)));
|
|
2512
|
+
} else {
|
|
2513
|
+
if ((name === "boolean?")) {
|
|
2514
|
+
if ((value === true)) {
|
|
2515
|
+
(candidates)["push"](false);
|
|
2516
|
+
}
|
|
2517
|
+
} else {
|
|
2518
|
+
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
} else {
|
|
2524
|
+
if ((kind === "coll-of")) {
|
|
2525
|
+
((candidates = shrink_sequence_items(value, to_js_array(value), (cfg)["item"], (cfg)["minCount"])));
|
|
2526
|
+
} else {
|
|
2527
|
+
if (((kind === "rep*") || (kind === "rep+"))) {
|
|
2528
|
+
((candidates = shrink_sequence_items(value, to_js_array(value), (cfg)["inner"], ((kind === "rep+") ? 1 : 0))));
|
|
2529
|
+
} else {
|
|
2530
|
+
if ((kind === "tuple")) {
|
|
2531
|
+
{
|
|
2532
|
+
let items = to_js_array(value);
|
|
2533
|
+
let specs = (cfg)["items"];
|
|
2534
|
+
let i = 0;
|
|
2535
|
+
while (__eliscript_numeric_relation("<", i, ((specs) ?? []).length)) {
|
|
2536
|
+
{
|
|
2537
|
+
let sub = shrink_value((specs)[i], (items)[i]);
|
|
2538
|
+
let j = 0;
|
|
2539
|
+
while (__eliscript_numeric_relation("<", j, ((sub) ?? []).length)) {
|
|
2540
|
+
{
|
|
2541
|
+
let copy = (items)["slice"]();
|
|
2542
|
+
((copy)[i] = (sub)[j]);
|
|
2543
|
+
(candidates)["push"]((PersistentVector)["from"](copy));
|
|
2544
|
+
}
|
|
2545
|
+
((j = (j + 1)));
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
((i = (i + 1)));
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
} else {
|
|
2552
|
+
if ((kind === "keys")) {
|
|
2553
|
+
if (__eliscript_truthy(Collection.isMap(value))) {
|
|
2554
|
+
{
|
|
2555
|
+
let req = (cfg)["req"];
|
|
2556
|
+
let opt = (cfg)["opt"];
|
|
2557
|
+
let i = 0;
|
|
2558
|
+
while (__eliscript_numeric_relation("<", i, ((opt) ?? []).length)) {
|
|
2559
|
+
{
|
|
2560
|
+
let k = ((opt)[i])["key"];
|
|
2561
|
+
if (__eliscript_truthy(Collection.contains(value, k))) {
|
|
2562
|
+
(candidates)["push"](Collection.dissoc(value, k));
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
((i = (i + 1)));
|
|
2566
|
+
}
|
|
2567
|
+
{
|
|
2568
|
+
let all_e = (req)["concat"](opt);
|
|
2569
|
+
((i = 0));
|
|
2570
|
+
while (__eliscript_numeric_relation("<", i, ((all_e) ?? []).length)) {
|
|
2571
|
+
{
|
|
2572
|
+
let e = (all_e)[i];
|
|
2573
|
+
let k = (e)["key"];
|
|
2574
|
+
if (__eliscript_truthy(Collection.contains(value, k))) {
|
|
2575
|
+
{
|
|
2576
|
+
let sub = shrink_value((e)["spec"], Collection.get(value, k));
|
|
2577
|
+
let j = 0;
|
|
2578
|
+
while (__eliscript_numeric_relation("<", j, ((sub) ?? []).length)) {
|
|
2579
|
+
(candidates)["push"](Collection.assoc(value, k, (sub)[j]));
|
|
2580
|
+
((j = (j + 1)));
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
((i = (i + 1)));
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
} else {
|
|
2591
|
+
if ((kind === "map-of")) {
|
|
2592
|
+
if (__eliscript_truthy(Collection.isMap(value))) {
|
|
2593
|
+
{
|
|
2594
|
+
let min_c = (cfg)["minCount"];
|
|
2595
|
+
let ks = (cfg)["key"];
|
|
2596
|
+
let vs = (cfg)["val"];
|
|
2597
|
+
let entries = [];
|
|
2598
|
+
Collection.reduceKV(value, ((_acc, k, v) => {
|
|
2599
|
+
(entries)["push"]([k, v]);
|
|
2600
|
+
return null;
|
|
2601
|
+
}), null);
|
|
2602
|
+
if (__eliscript_numeric_relation(">", Collection.count(value), min_c)) {
|
|
2603
|
+
{
|
|
2604
|
+
let i = 0;
|
|
2605
|
+
while (__eliscript_numeric_relation("<", i, ((entries) ?? []).length)) {
|
|
2606
|
+
(candidates)["push"](Collection.dissoc(value, ((entries)[i])[0]));
|
|
2607
|
+
((i = (i + 1)));
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
{
|
|
2612
|
+
let i = 0;
|
|
2613
|
+
while (__eliscript_numeric_relation("<", i, ((entries) ?? []).length)) {
|
|
2614
|
+
{
|
|
2615
|
+
let pair = (entries)[i];
|
|
2616
|
+
let k = (pair)[0];
|
|
2617
|
+
let v = (pair)[1];
|
|
2618
|
+
let v_shrinks = shrink_value(vs, v);
|
|
2619
|
+
let j = 0;
|
|
2620
|
+
while (__eliscript_numeric_relation("<", j, ((v_shrinks) ?? []).length)) {
|
|
2621
|
+
(candidates)["push"](Collection.assoc(value, k, (v_shrinks)[j]));
|
|
2622
|
+
((j = (j + 1)));
|
|
2623
|
+
}
|
|
2624
|
+
{
|
|
2625
|
+
let k_shrinks = shrink_value(ks, k);
|
|
2626
|
+
let kj = 0;
|
|
2627
|
+
while (__eliscript_numeric_relation("<", kj, ((k_shrinks) ?? []).length)) {
|
|
2628
|
+
{
|
|
2629
|
+
let nk = (k_shrinks)[kj];
|
|
2630
|
+
if ((!__eliscript_truthy(Collection.contains(value, nk)))) {
|
|
2631
|
+
(candidates)["push"](Collection.assoc(Collection.dissoc(value, k), nk, v));
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
((kj = (kj + 1)));
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
((i = (i + 1)));
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
} else {
|
|
2644
|
+
if ((kind === "and")) {
|
|
2645
|
+
{
|
|
2646
|
+
let specs = (cfg)["specs"];
|
|
2647
|
+
if (__eliscript_numeric_relation(">", ((specs) ?? []).length, 0)) {
|
|
2648
|
+
{
|
|
2649
|
+
let sub = shrink_value((specs)[0], value);
|
|
2650
|
+
let i = 0;
|
|
2651
|
+
while (__eliscript_numeric_relation("<", i, ((sub) ?? []).length)) {
|
|
2652
|
+
{
|
|
2653
|
+
let c = (sub)[i];
|
|
2654
|
+
if (__eliscript_truthy(valid_QMARK_(s, c))) {
|
|
2655
|
+
(candidates)["push"](c);
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
((i = (i + 1)));
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
} else {
|
|
2664
|
+
if ((kind === "or")) {
|
|
2665
|
+
{
|
|
2666
|
+
let clauses = (cfg)["clauses"];
|
|
2667
|
+
let i = 0;
|
|
2668
|
+
while (__eliscript_numeric_relation("<", i, ((clauses) ?? []).length)) {
|
|
2669
|
+
{
|
|
2670
|
+
let sub_spec = ((clauses)[i])["spec"];
|
|
2671
|
+
if (__eliscript_truthy(valid_QMARK_(sub_spec, value))) {
|
|
2672
|
+
{
|
|
2673
|
+
let sub = shrink_value(sub_spec, value);
|
|
2674
|
+
let j = 0;
|
|
2675
|
+
while (__eliscript_numeric_relation("<", j, ((sub) ?? []).length)) {
|
|
2676
|
+
(candidates)["push"]((sub)[j]);
|
|
2677
|
+
((j = (j + 1)));
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
((i = (i + 1)));
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
} else {
|
|
2686
|
+
if ((kind === "cat")) {
|
|
2687
|
+
{
|
|
2688
|
+
let arr = to_js_array(value);
|
|
2689
|
+
let i = 0;
|
|
2690
|
+
while (__eliscript_numeric_relation("<", i, ((arr) ?? []).length)) {
|
|
2691
|
+
{
|
|
2692
|
+
let el = (arr)[i];
|
|
2693
|
+
if (__eliscript_truthy(Number.isSafeInteger(el))) {
|
|
2694
|
+
{
|
|
2695
|
+
let sub = shrink_int_toward(el, 0);
|
|
2696
|
+
let j = 0;
|
|
2697
|
+
while (__eliscript_numeric_relation("<", j, ((sub) ?? []).length)) {
|
|
2698
|
+
{
|
|
2699
|
+
let copy = (arr)["slice"]();
|
|
2700
|
+
((copy)[i] = (sub)[j]);
|
|
2701
|
+
(candidates)["push"]((PersistentVector)["from"](copy));
|
|
2702
|
+
}
|
|
2703
|
+
((j = (j + 1)));
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
} else {
|
|
2707
|
+
if ((__eliscript_value_type(el) === "string")) {
|
|
2708
|
+
{
|
|
2709
|
+
let sub = shrink_string_value(el, 0);
|
|
2710
|
+
let j = 0;
|
|
2711
|
+
while (__eliscript_numeric_relation("<", j, ((sub) ?? []).length)) {
|
|
2712
|
+
{
|
|
2713
|
+
let copy = (arr)["slice"]();
|
|
2714
|
+
((copy)[i] = (sub)[j]);
|
|
2715
|
+
(candidates)["push"]((PersistentVector)["from"](copy));
|
|
2716
|
+
}
|
|
2717
|
+
((j = (j + 1)));
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
} else {
|
|
2721
|
+
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
((i = (i + 1)));
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
} else {
|
|
2729
|
+
null;
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
return candidates;
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
function eval_property(prop_fn, candidate) {
|
|
2747
|
+
try {
|
|
2748
|
+
{
|
|
2749
|
+
let res = prop_fn(candidate);
|
|
2750
|
+
return ({"passed": truthy_QMARK_(res), "error": null});
|
|
2751
|
+
}
|
|
2752
|
+
} catch (err) {
|
|
2753
|
+
return ({"passed": false, "error": (err)["message"]});
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
function shrink_counterexample(schema, initial_fail, initial_error, prop_fn, max_shrinks) {
|
|
2757
|
+
{
|
|
2758
|
+
let current = initial_fail;
|
|
2759
|
+
let current_error = initial_error;
|
|
2760
|
+
let steps = 0;
|
|
2761
|
+
let depth = 0;
|
|
2762
|
+
let improved = true;
|
|
2763
|
+
while ((__eliscript_truthy(improved) && __eliscript_numeric_relation("<", steps, max_shrinks))) {
|
|
2764
|
+
((improved = false));
|
|
2765
|
+
{
|
|
2766
|
+
let candidates = shrink_value(schema, current);
|
|
2767
|
+
let i = 0;
|
|
2768
|
+
while ((!(__eliscript_truthy(improved)) && __eliscript_numeric_relation("<", i, ((candidates) ?? []).length) && __eliscript_numeric_relation("<", steps, max_shrinks))) {
|
|
2769
|
+
{
|
|
2770
|
+
let cand = (candidates)[i];
|
|
2771
|
+
if ((!(__eliscript_truthy(equalValues(cand, current))) && __eliscript_truthy(valid_QMARK_(schema, cand)))) {
|
|
2772
|
+
((steps = (steps + 1)));
|
|
2773
|
+
{
|
|
2774
|
+
let ev = eval_property(prop_fn, cand);
|
|
2775
|
+
if ((!__eliscript_truthy((ev)["passed"]))) {
|
|
2776
|
+
((current = cand));
|
|
2777
|
+
((current_error = (ev)["error"]));
|
|
2778
|
+
((depth = (depth + 1)));
|
|
2779
|
+
((improved = true));
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
((i = (i + 1)));
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
return kv_map((__eliscript_tdz_ready_15 === true ? KW_SMALLEST : __eliscript_tdz_error("KW_SMALLEST")), current, (__eliscript_tdz_ready_16 === true ? KW_STEPS : __eliscript_tdz_error("KW_STEPS")), steps, (__eliscript_tdz_ready_17 === true ? KW_DEPTH : __eliscript_tdz_error("KW_DEPTH")), depth, (__eliscript_tdz_ready_18 === true ? KW_ERROR : __eliscript_tdz_error("KW_ERROR")), current_error);
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
function check_property(schema, prop_fn, options = null) {
|
|
2792
|
+
if ((!(__eliscript_value_type(prop_fn) === "function"))) {
|
|
2793
|
+
((__eliscript_value_32) => { throw __eliscript_value_32; })(new (globalThis.TypeError)("check-property expects a property function"));
|
|
2794
|
+
}
|
|
2795
|
+
{
|
|
2796
|
+
let s = resolve_spec(schema);
|
|
2797
|
+
let g = gen_from_spec(s);
|
|
2798
|
+
let num_tests = read_opt(options, "num-tests", "numTests", null, 100);
|
|
2799
|
+
let raw_seed = read_opt(options, "seed", null, null, null);
|
|
2800
|
+
let seed = ((raw_seed == null) ? __eliscript_numeric_uint32((__eliscript_numeric_mul(Date.now(), 2654435761) + Math.floor(__eliscript_numeric_mul(Math.random(), 100000)))) : __eliscript_numeric_uint32(raw_seed));
|
|
2801
|
+
let max_size = read_opt(options, "max-size", "maxSize", null, 30);
|
|
2802
|
+
let max_shrinks = read_opt(options, "max-shrinks", "maxShrinks", null, 200);
|
|
2803
|
+
let rng = make_rng(seed);
|
|
2804
|
+
let i = 0;
|
|
2805
|
+
let failure = null;
|
|
2806
|
+
while (((failure === null) && __eliscript_numeric_relation("<", i, num_tests))) {
|
|
2807
|
+
{
|
|
2808
|
+
let size = Math.min(max_size, (1 + Math.floor(__eliscript_numeric_div(__eliscript_numeric_mul(i, max_size), Math.max(1, num_tests)))));
|
|
2809
|
+
let sample = (g)["sampleFn"](rng, size);
|
|
2810
|
+
let ev = eval_property(prop_fn, sample);
|
|
2811
|
+
if ((!__eliscript_truthy((ev)["passed"]))) {
|
|
2812
|
+
((failure = ({"index": (i + 1), "sample": sample, "error": (ev)["error"]})));
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
((i = (i + 1)));
|
|
2816
|
+
}
|
|
2817
|
+
if ((failure === null)) {
|
|
2818
|
+
return kv_map((__eliscript_tdz_ready_10 === true ? KW_OK : __eliscript_tdz_error("KW_OK")), true, (__eliscript_tdz_ready_11 === true ? KW_SEED : __eliscript_tdz_error("KW_SEED")), seed, (__eliscript_tdz_ready_12 === true ? KW_NUM_TESTS : __eliscript_tdz_error("KW_NUM_TESTS")), num_tests);
|
|
2819
|
+
} else {
|
|
2820
|
+
{
|
|
2821
|
+
let shrunk = shrink_counterexample(s, (failure)["sample"], (failure)["error"], prop_fn, max_shrinks);
|
|
2822
|
+
return kv_map((__eliscript_tdz_ready_10 === true ? KW_OK : __eliscript_tdz_error("KW_OK")), false, (__eliscript_tdz_ready_11 === true ? KW_SEED : __eliscript_tdz_error("KW_SEED")), seed, (__eliscript_tdz_ready_12 === true ? KW_NUM_TESTS : __eliscript_tdz_error("KW_NUM_TESTS")), (failure)["index"], (__eliscript_tdz_ready_13 === true ? KW_FAIL : __eliscript_tdz_error("KW_FAIL")), (failure)["sample"], (__eliscript_tdz_ready_14 === true ? KW_SHRUNK : __eliscript_tdz_error("KW_SHRUNK")), shrunk);
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
export {INVALID, Schema, SchemaGen, check_property, conform, def_spec, explain, explain_data, explain_str, fdef, gen_bind, gen_boolean, gen_double, gen_elements, gen_fmap, gen_from_spec, gen_generate, gen_int, gen_keyword, gen_map, gen_one_of, gen_return, gen_sample, gen_string, gen_such_that, gen_symbol, gen_tuple, gen_vector, gen_QMARK_, get_spec, instrument, invalid_QMARK_, schema_QMARK_, shrink_value, spec_alt, spec_and, spec_any, spec_boolean, spec_cat, spec_coll_of, spec_double, spec_double_in, spec_enum, spec_fn, spec_int, spec_int_in, spec_keys, spec_keyword, spec_list, spec_map, spec_map_of, spec_nil, spec_nilable, spec_number, spec_opt_QMARK_, spec_or, spec_pred, spec_rep_PLUS_, spec_rep_STAR_, spec_set, spec_string, spec_string_len, spec_symbol, spec_tuple, spec_vector, unform, valid_QMARK_, with_gen};
|
|
2828
|
+
//# sourceMappingURL=schema.mjs.map
|