eliscript 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/bootstrap/README.md +26 -0
- package/bootstrap/backends/README.md +515 -0
- package/bootstrap/backends/async.eli +230 -0
- package/bootstrap/backends/binary.eli +173 -0
- package/bootstrap/backends/capabilities.eli +74 -0
- package/bootstrap/backends/elf.eli +246 -0
- package/bootstrap/backends/managed.eli +5976 -0
- package/bootstrap/backends/memory.eli +100 -0
- package/bootstrap/backends/native.eli +2000 -0
- package/bootstrap/backends/numeric.eli +1362 -0
- package/bootstrap/backends/optimize.eli +79 -0
- package/bootstrap/backends/regexp.eli +2263 -0
- package/bootstrap/backends/sha256.eli +138 -0
- package/bootstrap/backends/wasm.eli +1161 -0
- package/bootstrap/compiler/analyzer.eli +165 -77
- package/bootstrap/compiler/compiler.eli +43 -19
- package/bootstrap/compiler/emitter.eli +780 -170
- package/bootstrap/compiler/expander.eli +136 -45
- package/bootstrap/compiler/formatter.eli +8 -1
- package/bootstrap/compiler/ir.eli +148 -45
- package/bootstrap/compiler/lower.eli +29 -2
- package/bootstrap/compiler/project.eli +51 -21
- package/bootstrap/compiler/reader.eli +128 -36
- package/bootstrap/compiler/source-map.eli +46 -4
- package/bootstrap/compiler/symbol.eli +2 -1
- package/bootstrap/compiler/syntax.eli +47 -12
- package/bootstrap/compiler/transient-analysis.eli +40 -4
- package/bootstrap/host/check-cli-legacy.mjs +163 -0
- package/bootstrap/host/check-cli.mjs +59 -158
- package/bootstrap/host/check-cli.mjs.map +1 -0
- package/bootstrap/host/compiler-session.eli +1579 -0
- package/bootstrap/host/compiler-tools.eli +513 -0
- package/bootstrap/host/eliscript-cli.mjs +53 -33
- package/bootstrap/host/eliscript-cli.mjs.map +1 -0
- package/bootstrap/host/project-cli-legacy.mjs +295 -0
- package/bootstrap/host/project-cli.mjs +74 -289
- package/bootstrap/host/project-cli.mjs.map +1 -0
- package/bootstrap/host/project-legacy.mjs +1080 -0
- package/bootstrap/host/project.mjs +210 -1060
- package/bootstrap/host/project.mjs.map +1 -0
- package/bootstrap/runtime/UNICODE-LICENSE.txt +39 -0
- package/bootstrap/runtime/memory.eli +30379 -0
- package/browser/host.mjs +732 -11
- package/browser/worker.mjs +6 -3
- package/compiler/eliscript-analyzer.el +371 -4
- package/compiler/eliscript-cli.el +84 -1
- package/compiler/eliscript-emitter.el +1189 -256
- package/compiler/eliscript-expander.el +147 -10
- package/compiler/eliscript-ir-emitter.el +725 -208
- package/compiler/eliscript-lower.el +127 -1
- package/compiler/eliscript-portable.el +177 -51
- package/compiler/eliscript-project.el +20 -2
- package/compiler/eliscript-reader.el +141 -57
- package/compiler/eliscript-source-map.el +26 -12
- package/compiler/eliscript-transient-analysis.el +382 -19
- package/dist/backends/async.mjs +561 -0
- package/dist/backends/async.mjs.macro-origins.json +1 -0
- package/dist/backends/async.mjs.map +1 -0
- package/dist/backends/binary.mjs +381 -0
- package/dist/backends/binary.mjs.macro-origins.json +1 -0
- package/dist/backends/binary.mjs.map +1 -0
- package/dist/backends/capabilities.mjs +237 -0
- package/dist/backends/capabilities.mjs.macro-origins.json +1 -0
- package/dist/backends/capabilities.mjs.map +1 -0
- package/dist/backends/elf.mjs +540 -0
- package/dist/backends/elf.mjs.macro-origins.json +1 -0
- package/dist/backends/elf.mjs.map +1 -0
- package/dist/backends/managed.mjs +10616 -0
- package/dist/backends/managed.mjs.macro-origins.json +1 -0
- package/dist/backends/managed.mjs.map +1 -0
- package/dist/backends/memory.mjs +278 -0
- package/dist/backends/memory.mjs.macro-origins.json +1 -0
- package/dist/backends/memory.mjs.map +1 -0
- package/dist/backends/native.mjs +4099 -0
- package/dist/backends/native.mjs.macro-origins.json +1 -0
- package/dist/backends/native.mjs.map +1 -0
- package/dist/backends/numeric.mjs +2458 -0
- package/dist/backends/numeric.mjs.macro-origins.json +1 -0
- package/dist/backends/numeric.mjs.map +1 -0
- package/dist/backends/optimize.mjs +204 -0
- package/dist/backends/optimize.mjs.macro-origins.json +1 -0
- package/dist/backends/optimize.mjs.map +1 -0
- package/dist/backends/regexp.mjs +2033 -0
- package/dist/backends/regexp.mjs.macro-origins.json +1 -0
- package/dist/backends/regexp.mjs.map +1 -0
- package/dist/backends/sha256.mjs +310 -0
- package/dist/backends/sha256.mjs.macro-origins.json +1 -0
- package/dist/backends/sha256.mjs.map +1 -0
- package/dist/backends/wasm.mjs +2258 -0
- package/dist/backends/wasm.mjs.macro-origins.json +1 -0
- package/dist/backends/wasm.mjs.map +1 -0
- package/dist/bootstrap/analyzer.mjs +1908 -776
- package/dist/bootstrap/analyzer.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -1
- package/dist/bootstrap/compiler.mjs +450 -142
- package/dist/bootstrap/compiler.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/compiler.mjs.map +1 -1
- package/dist/bootstrap/emitter.mjs +3083 -909
- package/dist/bootstrap/emitter.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/emitter.mjs.map +1 -1
- package/dist/bootstrap/expander.mjs +2887 -1233
- package/dist/bootstrap/expander.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/expander.mjs.map +1 -1
- package/dist/bootstrap/formatter.mjs +582 -218
- package/dist/bootstrap/formatter.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/formatter.mjs.map +1 -1
- package/dist/bootstrap/ir.mjs +670 -116
- package/dist/bootstrap/ir.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/ir.mjs.map +1 -1
- package/dist/bootstrap/lower.mjs +866 -257
- package/dist/bootstrap/lower.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/lower.mjs.map +1 -1
- package/dist/bootstrap/package.json +1 -0
- package/dist/bootstrap/project.mjs +1168 -498
- package/dist/bootstrap/project.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/project.mjs.map +1 -1
- package/dist/bootstrap/reader.mjs +674 -175
- package/dist/bootstrap/reader.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/reader.mjs.map +1 -1
- package/dist/bootstrap/runtime/math.mjs +1117 -0
- package/dist/bootstrap/runtime/math.mjs.map +1 -0
- package/dist/bootstrap/runtime/unicode-case-data.mjs +10125 -0
- package/dist/bootstrap/runtime/unicode-case-data.mjs.map +1 -0
- package/dist/bootstrap/runtime/unicode-case.mjs +281 -0
- package/dist/bootstrap/runtime/unicode-case.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +430 -119
- package/dist/bootstrap/source-map.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/source-map.mjs.map +1 -1
- package/dist/bootstrap/symbol.mjs +229 -53
- package/dist/bootstrap/symbol.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/symbol.mjs.map +1 -1
- package/dist/bootstrap/syntax.mjs +205 -7
- package/dist/bootstrap/syntax.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/syntax.mjs.map +1 -1
- package/dist/bootstrap/transient-analysis.mjs +1185 -489
- package/dist/bootstrap/transient-analysis.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -1
- package/dist/browser/compiler.js +199 -6478
- package/dist/browser/host.mjs +1078 -0
- package/dist/browser/loader.js +1 -0
- package/dist/browser/loader.mjs +231 -0
- package/dist/browser/worker.mjs +63 -0
- package/dist/compiler-artifact.json +1 -0
- package/dist/host/compiler-session.mjs +2980 -0
- package/dist/host/compiler-session.mjs.macro-origins.json +1 -0
- package/dist/host/compiler-session.mjs.map +1 -0
- package/dist/host/compiler-tools.mjs +1084 -0
- package/dist/host/compiler-tools.mjs.macro-origins.json +1 -0
- package/dist/host/compiler-tools.mjs.map +1 -0
- package/dist/literal-sources/runtime/core/collection-internals.eli +60 -0
- package/dist/literal-sources/runtime/core/collection.eli +639 -0
- package/dist/literal-sources/runtime/core/data-text.eli +290 -0
- package/dist/literal-sources/runtime/core/data.eli +22 -0
- package/dist/literal-sources/runtime/core/identifier.eli +44 -0
- package/dist/literal-sources/runtime/core/lazy-sequence.eli +131 -0
- package/dist/literal-sources/runtime/core/list.eli +19 -0
- package/dist/literal-sources/runtime/core/map.eli +9 -0
- package/dist/literal-sources/runtime/core/metadata-internals.eli +6 -0
- package/dist/literal-sources/runtime/core/metadata.eli +40 -0
- package/dist/literal-sources/runtime/core/object.eli +8 -0
- package/dist/literal-sources/runtime/core/order.eli +123 -0
- package/dist/literal-sources/runtime/core/persistent-kind.eli +28 -0
- package/dist/literal-sources/runtime/core/protocol-error.eli +32 -0
- package/dist/literal-sources/runtime/core/protocol.eli +28 -0
- package/dist/literal-sources/runtime/core/queue.eli +9 -0
- package/dist/literal-sources/runtime/core/record.eli +191 -0
- package/dist/literal-sources/runtime/core/regex.eli +158 -0
- package/dist/literal-sources/runtime/core/sequence.eli +305 -0
- package/dist/literal-sources/runtime/core/set-algebra.eli +28 -0
- package/dist/literal-sources/runtime/core/set.eli +9 -0
- package/dist/literal-sources/runtime/core/sorted.eli +408 -0
- package/dist/literal-sources/runtime/core/text.eli +14 -0
- package/dist/literal-sources/runtime/core/transducer.eli +268 -0
- package/dist/literal-sources/runtime/core/transient.eli +17 -0
- package/dist/literal-sources/runtime/core/truth.eli +4 -0
- package/dist/literal-sources/runtime/core/type.eli +232 -0
- package/dist/literal-sources/runtime/core/value-internals.eli +13 -0
- package/dist/literal-sources/runtime/core/value.eli +19 -0
- package/dist/literal-sources/runtime/core/vector.eli +25 -0
- package/dist/literal-sources/runtime/literals.eli +23 -0
- package/dist/literal-sources/runtime/testing/value.eli +6 -0
- package/dist/literal-sources/runtime/wire/http-rpc.eli +362 -0
- package/dist/literal-sources/runtime/wire/markdown.eli +275 -0
- package/dist/literal-sources/runtime/wire/schema.eli +193 -0
- package/dist/literal-sources/stdlib/bit.eli +36 -0
- package/dist/literal-sources/stdlib/core/data.eli +306 -0
- package/dist/literal-sources/stdlib/core/object.eli +89 -0
- package/dist/literal-sources/stdlib/core/protocol.eli +451 -0
- package/dist/literal-sources/stdlib/core/set.eli +312 -0
- package/dist/literal-sources/stdlib/core/text.eli +103 -0
- package/dist/literal-sources/stdlib/managed-literal-protocols.eli +494 -0
- package/dist/literal-sources/stdlib/managed-literals.eli +1469 -0
- package/dist/literal-sources/stdlib/managed-queue-state.eli +65 -0
- package/dist/literal-sources/stdlib/managed-sorted-state.eli +233 -0
- package/dist/literal-sources/stdlib/managed-transient-state.eli +348 -0
- package/dist/literal-sources/stdlib/managed-value-state.eli +153 -0
- package/dist/literal-sources/stdlib/managed-vector-view-state.eli +102 -0
- package/dist/literal-sources/stdlib/persistent-list.eli +145 -0
- package/dist/literal-sources/stdlib/persistent-map.eli +724 -0
- package/dist/literal-sources/stdlib/persistent-set.eli +236 -0
- package/dist/literal-sources/stdlib/persistent-vector.eli +359 -0
- package/dist/literal-sources/stdlib/value.eli +325 -0
- package/dist/package.json +10 -0
- package/dist/runtime/math.mjs +1116 -0
- package/dist/runtime/math.mjs.macro-origins.json +1 -0
- package/dist/runtime/math.mjs.map +1 -0
- package/dist/runtime/unicode-case-data.mjs +10124 -0
- package/dist/runtime/unicode-case-data.mjs.macro-origins.json +1 -0
- package/dist/runtime/unicode-case-data.mjs.map +1 -0
- package/dist/runtime/unicode-case.mjs +280 -0
- package/dist/runtime/unicode-case.mjs.macro-origins.json +1 -0
- package/dist/runtime/unicode-case.mjs.map +1 -0
- package/dist/runtime.eli +30379 -0
- package/dist/stage3-release.json +1 -0
- package/editor/README.md +1 -1
- package/editor/eliscript-mode.el +1 -1
- package/editor/eliscript-repl.el +1 -1
- package/package.json +106 -11
- package/platform/http.mjs +20 -0
- package/runtime/array-text.mjs +159 -0
- package/runtime/core/map-internals.mjs +27 -9
- package/runtime/core/object-impl.mjs +26 -17
- package/runtime/core/object-impl.mjs.map +1 -1
- package/runtime/core/protocol-impl.mjs +682 -255
- package/runtime/core/protocol-impl.mjs.map +1 -1
- package/runtime/core/protocol.mjs +4 -0
- package/runtime/core/record.mjs +23 -2
- package/runtime/core/regex.mjs +4 -0
- package/runtime/core/sorted.mjs +53 -0
- package/runtime/core/text-impl.mjs +167 -48
- package/runtime/core/text-impl.mjs.map +1 -1
- package/runtime/core/type.mjs +75 -3
- package/runtime/core/vector.mjs +6 -0
- package/runtime/math.eli +429 -0
- package/runtime/math.mjs +1116 -0
- package/runtime/math.mjs.map +1 -0
- package/runtime/number-radix.mjs +105 -0
- package/runtime/unicode-case-data.eli +29 -0
- package/runtime/unicode-case-data.mjs +10124 -0
- package/runtime/unicode-case-data.mjs.map +1 -0
- package/runtime/unicode-case.eli +100 -0
- package/runtime/unicode-case.mjs +280 -0
- package/runtime/unicode-case.mjs.map +1 -0
- package/runtime/wire/http-rpc.mjs +168 -0
- package/runtime/wire/markdown.mjs +196 -0
- package/runtime/wire/schema.mjs +109 -0
- package/stdlib/README.md +54 -0
- package/stdlib/core/protocol.eli +81 -17
- package/stdlib/core/seq.eli +1 -1
- package/stdlib/core/zipper.eli +172 -72
- package/stdlib/gepo.eli +12 -0
- package/stdlib/interop/js.eli +56 -15
- package/stdlib/managed-literal-protocols.eli +494 -0
- package/stdlib/managed-literals.eli +1469 -0
- package/stdlib/managed-protocol-error.eli +32 -0
- package/stdlib/managed-queue-state.eli +65 -0
- package/stdlib/managed-runtime-collection-internals.eli +60 -0
- package/stdlib/managed-runtime-collection.eli +639 -0
- package/stdlib/managed-runtime-data-text.eli +290 -0
- package/stdlib/managed-runtime-data.eli +22 -0
- package/stdlib/managed-runtime-identifier.eli +44 -0
- package/stdlib/managed-runtime-lazy-sequence.eli +131 -0
- package/stdlib/managed-runtime-list.eli +19 -0
- package/stdlib/managed-runtime-literals.eli +23 -0
- package/stdlib/managed-runtime-map.eli +9 -0
- package/stdlib/managed-runtime-metadata-internals.eli +6 -0
- package/stdlib/managed-runtime-metadata.eli +40 -0
- package/stdlib/managed-runtime-object.eli +8 -0
- package/stdlib/managed-runtime-order.eli +123 -0
- package/stdlib/managed-runtime-persistent-kind.eli +28 -0
- package/stdlib/managed-runtime-protocol.eli +28 -0
- package/stdlib/managed-runtime-queue.eli +9 -0
- package/stdlib/managed-runtime-record.eli +191 -0
- package/stdlib/managed-runtime-regex.eli +158 -0
- package/stdlib/managed-runtime-sequence.eli +305 -0
- package/stdlib/managed-runtime-set-algebra.eli +28 -0
- package/stdlib/managed-runtime-set.eli +9 -0
- package/stdlib/managed-runtime-sorted.eli +408 -0
- package/stdlib/managed-runtime-text.eli +14 -0
- package/stdlib/managed-runtime-transducer.eli +268 -0
- package/stdlib/managed-runtime-transient.eli +17 -0
- package/stdlib/managed-runtime-truth.eli +4 -0
- package/stdlib/managed-runtime-type.eli +232 -0
- package/stdlib/managed-runtime-value-internals.eli +13 -0
- package/stdlib/managed-runtime-value.eli +19 -0
- package/stdlib/managed-runtime-vector.eli +25 -0
- package/stdlib/managed-sorted-state.eli +233 -0
- package/stdlib/managed-testing-value.eli +6 -0
- package/stdlib/managed-transient-state.eli +348 -0
- package/stdlib/managed-value-state.eli +153 -0
- package/stdlib/managed-vector-view-state.eli +102 -0
- package/stdlib/managed-wire-http-rpc.eli +362 -0
- package/stdlib/managed-wire-markdown.eli +275 -0
- package/stdlib/managed-wire-schema.eli +193 -0
- package/stdlib/mdp.eli +7 -0
- package/stdlib/mds.eli +4 -0
- package/stdlib/persistent-vector.eli +23 -6
- package/tools/acceptance/check-legacy.mjs +687 -0
- package/tools/acceptance/check.eli +431 -0
- package/tools/acceptance/compile-evidence.el +49 -0
- package/tools/acceptance/finalize-legacy.mjs +498 -0
- package/tools/acceptance/finalize.eli +270 -0
- package/tools/backends/benchmark.mjs +175 -0
- package/tools/backends/build.mjs +135 -0
- package/tools/backends/compile.mjs +94 -0
- package/tools/backends/compiler-bootstrap.mjs +1001 -0
- package/tools/backends/compiler-browser.mjs +361 -0
- package/tools/backends/compiler-build.mjs +1628 -0
- package/tools/backends/compiler-cli-legacy.mjs +334 -0
- package/tools/backends/compiler-cli.mjs +29 -0
- package/tools/backends/compiler-corpus-bit.mjs +234 -0
- package/tools/backends/compiler-corpus-cli-adapters-legacy.mjs +362 -0
- package/tools/backends/compiler-corpus-cli-adapters.mjs +247 -0
- package/tools/backends/compiler-corpus-debugging.mjs +221 -0
- package/tools/backends/compiler-corpus-emitter.mjs +324 -0
- package/tools/backends/compiler-corpus-evaluation-adapters.mjs +65 -0
- package/tools/backends/compiler-corpus-execution-legacy.mjs +769 -0
- package/tools/backends/compiler-corpus-execution.mjs +3324 -0
- package/tools/backends/compiler-corpus-fuzz.mjs +229 -0
- package/tools/backends/compiler-corpus-generations.mjs +208 -0
- package/tools/backends/compiler-corpus-host-context-legacy.mjs +114 -0
- package/tools/backends/compiler-corpus-host-context.mjs +550 -0
- package/tools/backends/compiler-corpus-identity-host.mjs +553 -0
- package/tools/backends/compiler-corpus-identity-value-adapters-legacy.mjs +298 -0
- package/tools/backends/compiler-corpus-identity-value-adapters.mjs +69 -0
- package/tools/backends/compiler-corpus-isolated-exports.mjs +21 -0
- package/tools/backends/compiler-corpus-legacy.mjs +1155 -0
- package/tools/backends/compiler-corpus-literal-provider.mjs +282 -0
- package/tools/backends/compiler-corpus-managed-adapters-legacy.mjs +334 -0
- package/tools/backends/compiler-corpus-managed-adapters.mjs +937 -0
- package/tools/backends/compiler-corpus-managed-cases.mjs +179 -0
- package/tools/backends/compiler-corpus-managed-fixtures-legacy.mjs +879 -0
- package/tools/backends/compiler-corpus-managed-fixtures.mjs +1287 -0
- package/tools/backends/compiler-corpus-matchers.mjs +173 -0
- package/tools/backends/compiler-corpus-original-program.mjs +612 -0
- package/tools/backends/compiler-corpus-process.mjs +765 -0
- package/tools/backends/compiler-corpus-program-driver.mjs +306 -0
- package/tools/backends/compiler-corpus-project-adapters-legacy.mjs +497 -0
- package/tools/backends/compiler-corpus-project-adapters.mjs +340 -0
- package/tools/backends/compiler-corpus-project-entry-host.mjs +511 -0
- package/tools/backends/compiler-corpus-project-transport.mjs +151 -0
- package/tools/backends/compiler-corpus-raw-fixture-observer.mjs +1438 -0
- package/tools/backends/compiler-corpus-raw-language-fixtures.mjs +1456 -0
- package/tools/backends/compiler-corpus-raw-math-fixture.mjs +346 -0
- package/tools/backends/compiler-corpus-raw-special-fixtures.mjs +523 -0
- package/tools/backends/compiler-corpus-reference-legacy.mjs +263 -0
- package/tools/backends/compiler-corpus-reference.mjs +241 -0
- package/tools/backends/compiler-corpus-runtime-adapters-legacy.mjs +843 -0
- package/tools/backends/compiler-corpus-runtime-adapters.mjs +663 -0
- package/tools/backends/compiler-corpus-source-archive.mjs +206 -0
- package/tools/backends/compiler-corpus-tools-artifact-adapters.mjs +410 -0
- package/tools/backends/compiler-corpus-tools-cli.mjs +363 -0
- package/tools/backends/compiler-corpus-tools-reference.mjs +264 -0
- package/tools/backends/compiler-corpus.mjs +2054 -0
- package/tools/backends/compiler-debug.mjs +142 -0
- package/tools/backends/compiler-matrix.mjs +1955 -0
- package/tools/backends/compiler-metadata.mjs +203 -0
- package/tools/backends/compiler-package-browser.mjs +120 -0
- package/tools/backends/compiler-package-legacy.mjs +654 -0
- package/tools/backends/compiler-package.mjs +464 -0
- package/tools/backends/compiler-project.mjs +126 -0
- package/tools/backends/compiler-session.mjs +843 -0
- package/tools/backends/compiler-sha256.mjs +152 -0
- package/tools/backends/compiler-unicode-profile-host.mjs +196 -0
- package/tools/backends/compiler-worker.mjs +573 -0
- package/tools/backends/dist/bootstrap-js-stages.mjs +919 -0
- package/tools/backends/dist/bootstrap-js-stages.mjs.map +1 -0
- package/tools/backends/dist/managed-ir-inventory.mjs +488 -0
- package/tools/backends/dist/managed-ir-inventory.mjs.map +1 -0
- package/tools/backends/dist/record-grid.mjs +1256 -0
- package/tools/backends/dist/record-grid.mjs.map +1 -0
- package/tools/backends/dist/release-cli.mjs +462 -0
- package/tools/backends/dist/release-cli.mjs.map +1 -0
- package/tools/backends/dist/run-artifact.mjs +517 -0
- package/tools/backends/dist/run-artifact.mjs.map +1 -0
- package/tools/backends/eliscript/compiler-corpus-bit.eli +77 -0
- package/tools/backends/eliscript/compiler-corpus-debugging.eli +70 -0
- package/tools/backends/eliscript/compiler-corpus-project-entry-host.eli +256 -0
- package/tools/backends/managed-foreign-binding.mjs +497 -0
- package/tools/backends/managed-host-legacy.mjs +1181 -0
- package/tools/backends/managed-host-lifecycle.mjs +310 -0
- package/tools/backends/managed-host-object-provider.mjs +155 -0
- package/tools/backends/managed-host-object-realm.mjs +797 -0
- package/tools/backends/managed-host-proxy.mjs +71 -0
- package/tools/backends/managed-host-runtime.mjs +5868 -0
- package/tools/backends/managed-host.mjs +716 -0
- package/tools/backends/managed-module-graph-legacy.mjs +308 -0
- package/tools/backends/managed-module-graph.mjs +694 -0
- package/tools/backends/managed-runtime-host-legacy.mjs +195 -0
- package/tools/backends/managed-runtime.mjs +939 -0
- package/tools/backends/managed-source-view-legacy.mjs +332 -0
- package/tools/backends/managed-source-view.mjs +959 -0
- package/tools/backends/memory-runtime.mjs +100 -0
- package/tools/backends/native-benchmark.mjs +88 -0
- package/tools/backends/native-managed-runtime.mjs +677 -0
- package/tools/backends/native-memory.mjs +768 -0
- package/tools/backends/native-node-memory.mjs +142 -0
- package/tools/backends/native-node-runner.mjs +99 -0
- package/tools/backends/native-node-watchdog.mjs +19 -0
- package/tools/backends/native-node-worker.mjs +75 -0
- package/tools/backends/stage3-targets.mjs +493 -0
- package/tools/bootstrap-command.el +13 -0
- package/tools/bootstrap-runtime.el +101 -0
- package/tools/bootstrap-seed.el +55 -0
- package/tools/project/check-cli.eli +31 -0
- package/tools/project/project-cli.eli +42 -0
- package/tools/project/project.eli +122 -0
- package/tools/runtime/unicode-case-profiles.mjs +13 -0
- package/tools/runtime/unicode-case-runtime.el +57 -0
- package/tools/testing/source-debugging-corpus-host.eli +16 -0
- package/tools/testing/source-debugging.eli +139 -0
- package/tools/testing/stdlib-bit-corpus-host.eli +21 -0
- package/tools/testing/stdlib-bit-corpus-host.mjs +118 -0
- package/tools/testing/stdlib-bit.eli +104 -0
- package/tools/testing/stdlib-bit.mjs +255 -0
- package/bin/eliscript-bootstrap +0 -15
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
(module eliscript.managed-wire-markdown
|
|
2
|
+
(import "../../stdlib/managed-literals.eli" literal-each)
|
|
3
|
+
(defconst number-pattern (js* "/^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$/u"))
|
|
4
|
+
(defun object? (value) (and (not (nil? value)) (= (js* "typeof value") "object") (not (Array/isArray value))))
|
|
5
|
+
(defun truth (value) (js* "!!value"))
|
|
6
|
+
(defun own (value key) (Object/hasOwn value key))
|
|
7
|
+
(defun put-data (target key value)
|
|
8
|
+
(Object/defineProperty target key (js-object :value value :writable t :enumerable t :configurable t)))
|
|
9
|
+
(defconst MarkdownError (funcall
|
|
10
|
+
(js* "(implementation, name) => { if (typeof name !== \"string\") throw new TypeError(\"class name must be a string\"); return ({ [name]: class { constructor(...args) { return implementation(this, ...args); } } })[name]; }")
|
|
11
|
+
(lambda (self code line message)
|
|
12
|
+
(let ((error (new globalThis/Error (str code " at line " line ": " message))))
|
|
13
|
+
(Object/setPrototypeOf error (Object/getPrototypeOf self))
|
|
14
|
+
(put error :name "MarkdownError") (put error :code code) (put error :line line) error)) "MarkdownError"))
|
|
15
|
+
(Object/setPrototypeOf MarkdownError globalThis/Error)
|
|
16
|
+
(Object/setPrototypeOf (get MarkdownError :prototype) (get globalThis/Error :prototype))
|
|
17
|
+
(Object/defineProperty MarkdownError "length" (js-object :value 3 :configurable t))
|
|
18
|
+
(defun fail (code line message) (throw (new MarkdownError code line message)))
|
|
19
|
+
(defun scalar (text)
|
|
20
|
+
(cond
|
|
21
|
+
((and (js-call text :startsWith "\"") (js-call text :endsWith "\"") (>= (js-length text) 2))
|
|
22
|
+
(js-call (js-call text :slice 1 -1) :replace (js* "/\\\\([\"\\\\ntr])/gu")
|
|
23
|
+
(lambda (matched character)
|
|
24
|
+
(let ((value (get (js-object :n "\n" :t "\t" :r "\r") character)))
|
|
25
|
+
(if (nullish? value) character value)))))
|
|
26
|
+
((js-call number-pattern :test text)
|
|
27
|
+
(let ((value (funcall globalThis/Number text)))
|
|
28
|
+
(unless (Number/isFinite value) (throw (new globalThis/RangeError "Number exceeds finite IEEE 754 range"))) value))
|
|
29
|
+
((= text "true") t) ((= text "false") false) ((or (= text "null") (= text "")) nil)
|
|
30
|
+
((= text "{}") (js-object)) ((= text "[]") (js-array)) (t text)))
|
|
31
|
+
(defun cells (text)
|
|
32
|
+
(let ((result (js-array)) (cell "") (index 1))
|
|
33
|
+
(while (< index (1- (js-length text)))
|
|
34
|
+
(let ((character (aref text index)))
|
|
35
|
+
(cond ((and (= character "\\") (= (aref text (1+ index)) "|")) (setq cell (str cell "|") index (1+ index)))
|
|
36
|
+
((= character "|") (js-call result :push (js-call cell :trim)) (setq cell ""))
|
|
37
|
+
(t (setq cell (str cell character)))))
|
|
38
|
+
(setq index (1+ index))) (js-call result :push (js-call cell :trim)) result))
|
|
39
|
+
(defun leading (raw) (get (js-call raw :match (js* "/^\\s*/u")) 0))
|
|
40
|
+
(defun table-token (lines index text level line)
|
|
41
|
+
(if (or (>= (1+ index) (js-length lines))
|
|
42
|
+
(not (js-call (js-call (aref lines (1+ index)) :trim) :startsWith "|"))
|
|
43
|
+
(not (js-call (js-call (aref lines (1+ index)) :trim) :endsWith "|"))) nil
|
|
44
|
+
(let ((separator (cells (js-call (aref lines (1+ index)) :trim))))
|
|
45
|
+
(if (not (js-call separator :every (lambda (cell) (js-call (js* "/^:?-+:?$/u") :test cell)))) nil
|
|
46
|
+
(progn
|
|
47
|
+
(when (js-call (leading (aref lines (1+ index))) :includes "\t") (fail "MDP-E009" (1+ line) "Tab indentation"))
|
|
48
|
+
(let ((headers (cells text)) (rows (js-array)))
|
|
49
|
+
(when (or (js-call headers :some (lambda (header) (not (truth header))))
|
|
50
|
+
(/= (get (new globalThis/Set headers) :size) (js-length headers))) (fail "MDP-E005" line "Invalid table header"))
|
|
51
|
+
(unless (= (js-length separator) (js-length headers)) (fail "MDP-E004" (1+ line) "Separator width"))
|
|
52
|
+
(setq index (1+ index))
|
|
53
|
+
(while (and (< (1+ index) (js-length lines))
|
|
54
|
+
(js-call (js* "/^\\s*\\|.*\\|\\s*$/u") :test (aref lines (1+ index))))
|
|
55
|
+
(when (js-call (leading (aref lines (1+ index))) :includes "\t") (fail "MDP-E009" (+ index 2) "Tab indentation"))
|
|
56
|
+
(setq index (1+ index))
|
|
57
|
+
(let ((row (cells (js-call (aref lines index) :trim))))
|
|
58
|
+
(unless (= (js-length row) (js-length headers)) (fail "MDP-E004" (1+ index) "Row width"))
|
|
59
|
+
(if (= (js-length headers) 1) (js-call rows :push (scalar (aref row 0)))
|
|
60
|
+
(let ((value (js-object)))
|
|
61
|
+
(js-call row :forEach (lambda (cell at)
|
|
62
|
+
(unless (= cell "") (put-data value (aref headers at) (scalar cell)))))
|
|
63
|
+
(js-call rows :push value)))))
|
|
64
|
+
(js-object :index index :token (js-object :kind "table" :value rows :level level :line line))))))))
|
|
65
|
+
(defun tokenize (source)
|
|
66
|
+
(let ((lines (js-call (js-call source :replace (js* "/^\\uFEFF/u") "") :split (js* "/\\r\\n?|\\n/u")))
|
|
67
|
+
(tokens (js-array)) (fence nil) (html nil) (index 0))
|
|
68
|
+
(while (< index (js-length lines))
|
|
69
|
+
(let* ((raw (aref lines index)) (text (js-call raw :trim)) (line (1+ index)) (handled false))
|
|
70
|
+
(unless (nil? fence)
|
|
71
|
+
(when (js-call (new globalThis/RegExp (str "^ {0,3}" (get fence :char) "{" (get fence :size) ",}\\s*$") "u") :test raw)
|
|
72
|
+
(setq fence nil))
|
|
73
|
+
(setq handled t))
|
|
74
|
+
(when (and (not handled) (not (nil? html)))
|
|
75
|
+
(when (if (= html "blank") (= text "") (js-call html :test raw)) (setq html nil))
|
|
76
|
+
(setq handled t))
|
|
77
|
+
(unless handled
|
|
78
|
+
(let ((fenced (js-call raw :match (js* "/^ {0,3}(`{3,}|~{3,})/u"))))
|
|
79
|
+
(when (truth fenced)
|
|
80
|
+
(setq fence (js-object :char (aref (aref fenced 1) 0) :size (js-length (aref fenced 1))) handled t))))
|
|
81
|
+
(unless handled
|
|
82
|
+
(when (js-call (js* "/^ {0,3}<!--/u") :test raw)
|
|
83
|
+
(unless (js-call raw :includes "-->") (setq html (js* "/-->/u"))) (setq handled t)))
|
|
84
|
+
(unless handled
|
|
85
|
+
(let ((special (js-call raw :match (js* "/^ {0,3}<(script|pre|style|textarea)(?:\\s|>)/iu"))))
|
|
86
|
+
(when (truth special)
|
|
87
|
+
(let ((end (new globalThis/RegExp (str "</" (aref special 1) ">") "iu")))
|
|
88
|
+
(unless (js-call end :test raw) (setq html end))) (setq handled t))))
|
|
89
|
+
(unless handled
|
|
90
|
+
(when (js-call (js* "/^ {0,3}<\\?/u") :test raw)
|
|
91
|
+
(unless (js-call raw :includes "?>") (setq html (js* "/\\?>/u"))) (setq handled t)))
|
|
92
|
+
(unless handled
|
|
93
|
+
(when (js-call (js* "/^ {0,3}<!\\[CDATA\\[/u") :test raw)
|
|
94
|
+
(unless (js-call raw :includes "]]>") (setq html (js* "/\\]\\]>/u"))) (setq handled t)))
|
|
95
|
+
(unless handled
|
|
96
|
+
(when (js-call (js* "/^ {0,3}<![A-Z]/u") :test raw)
|
|
97
|
+
(unless (js-call raw :includes ">") (setq html (js* "/>/u"))) (setq handled t)))
|
|
98
|
+
(unless handled
|
|
99
|
+
(let ((block-tag (js* "/^ {0,3}<\\/?(?:address|article|aside|base|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\\s|\\/?>)/iu")))
|
|
100
|
+
(when (or (js-call block-tag :test raw)
|
|
101
|
+
(js-call (js* "/^ {0,3}<\\/?[A-Za-z][\\w-]*(?:\\s[^>]*|\\/?)>\\s*$/u") :test raw))
|
|
102
|
+
(setq html "blank" handled t))))
|
|
103
|
+
(unless handled
|
|
104
|
+
(let ((heading (js-call raw :match (js* "/^ {0,3}(#{1,2})(?:[ \\t]+(.*)|$)/u"))))
|
|
105
|
+
(when (truth heading)
|
|
106
|
+
(let ((title (js-call (js-call (if (nullish? (aref heading 2)) "" (aref heading 2)) :replace
|
|
107
|
+
(js* "/(?:^|\\s+)#+\\s*$/u") "") :trim)))
|
|
108
|
+
(unless (truth title) (fail "MDP-E007" line "Empty heading"))
|
|
109
|
+
(js-call tokens :push (js-object :kind "heading" :level (js-length (aref heading 1)) :title title :line line)))
|
|
110
|
+
(setq handled t))))
|
|
111
|
+
(unless handled
|
|
112
|
+
(let* ((field (js-call text :match (js* "/^-\\s+([^]*?):(?: (.*)|\\s*)$/u")))
|
|
113
|
+
(pipe (and (js-call text :startsWith "|") (js-call text :endsWith "|") (> (js-length text) 1))))
|
|
114
|
+
(when (or (truth field) pipe)
|
|
115
|
+
(let ((indent (leading raw)))
|
|
116
|
+
(when (js-call indent :includes "\t") (fail "MDP-E009" line "Tab indentation"))
|
|
117
|
+
(let ((level (Math/floor (/ (js-length indent) 2))))
|
|
118
|
+
(if (truth field)
|
|
119
|
+
(js-call tokens :push (js-object :kind "field" :key (js-call (aref field 1) :trim)
|
|
120
|
+
:text (js-call (if (nullish? (aref field 2)) "" (aref field 2)) :trim) :level level :line line))
|
|
121
|
+
(let ((table (table-token lines index text level line)))
|
|
122
|
+
(unless (nil? table)
|
|
123
|
+
(setq index (get table :index)) (js-call tokens :push (get table :token)))))))))))
|
|
124
|
+
(setq index (1+ index))) tokens))
|
|
125
|
+
(defun option (options key fallback)
|
|
126
|
+
(let ((value (aref options key))) (if (undefined? value) fallback value)))
|
|
127
|
+
(defun parse (source &rest optional-options)
|
|
128
|
+
(let* ((options (if (or (= (js-length optional-options) 0) (undefined? (aref optional-options 0))) (js-object) (aref optional-options 0)))
|
|
129
|
+
(max-length (option options "maxLength" 16777216)) (max-depth (option options "maxDepth" 256)))
|
|
130
|
+
(unless (= (js* "typeof source") "string") (throw (new globalThis/TypeError "Markdown source must be a string")))
|
|
131
|
+
(unless (and (Number/isSafeInteger max-length) (>= max-length 1) (Number/isSafeInteger max-depth) (>= max-depth 0) (<= max-depth 512))
|
|
132
|
+
(throw (new globalThis/RangeError "Invalid parser limits")))
|
|
133
|
+
(when (> (js-length source) max-length) (throw (new globalThis/RangeError "Markdown length limit")))
|
|
134
|
+
(let ((tokens (tokenize source)) (cursor 0) (block nil))
|
|
135
|
+
(setq block (lambda (level root)
|
|
136
|
+
(when (> level max-depth) (throw (new globalThis/RangeError "Markdown depth limit")))
|
|
137
|
+
(let ((value (js-object)) (mode "object") (populated false) (done false))
|
|
138
|
+
(while (and (not done) (< cursor (js-length tokens)))
|
|
139
|
+
(let ((token (aref tokens cursor)))
|
|
140
|
+
(if (or (= (get token :kind) "heading") (< (get token :level) level)) (setq done t)
|
|
141
|
+
(progn
|
|
142
|
+
(when (and (> (get token :level) level) (not (and (= (get token :kind) "table") (= level 0) (<= (get token :level) 1))))
|
|
143
|
+
(fail (if (or (= (get token :kind) "table") (= (get token :key) "")) "MDP-E006" "MDP-E009") (get token :line) "Unattached indentation"))
|
|
144
|
+
(setq cursor (1+ cursor))
|
|
145
|
+
(if (= (get token :kind) "table")
|
|
146
|
+
(progn
|
|
147
|
+
(when root (fail "MDP-E006" (get token :line) "Root table"))
|
|
148
|
+
(when populated (fail "MDP-E002" (get token :line) "Mixed contents"))
|
|
149
|
+
(setq value (get token :value) mode "table" populated t))
|
|
150
|
+
(let ((element (= (get token :key) "")))
|
|
151
|
+
(when (and element root) (fail "MDP-E006" (get token :line) "Root element"))
|
|
152
|
+
(when (or (= mode "table") (and populated (not (eq element (= mode "elements")))))
|
|
153
|
+
(fail "MDP-E002" (get token :line) "Mixed contents"))
|
|
154
|
+
(when (and element (not populated)) (setq value (js-array) mode "elements"))
|
|
155
|
+
(when (and (not element) (own value (get token :key))) (fail "MDP-E003" (get token :line) "Duplicate key"))
|
|
156
|
+
(let* ((child (scalar (get token :text))) (next (aref tokens cursor)))
|
|
157
|
+
(when (and (truth next) (not (= (get next :kind) "heading")) (> (get next :level) level))
|
|
158
|
+
(when (or (/= (get next :level) (1+ level)) (not (= (get token :text) "")))
|
|
159
|
+
(fail (if (= (get next :kind) "table") "MDP-E006" "MDP-E009") (get next :line) "Child requires a container"))
|
|
160
|
+
(setq child (funcall block (1+ level) false)))
|
|
161
|
+
(if element (js-call value :push child) (put-data value (get token :key) child)))
|
|
162
|
+
(setq populated t))))))) value)))
|
|
163
|
+
(let ((result (funcall block 0 t)) (current nil))
|
|
164
|
+
(while (< cursor (js-length tokens))
|
|
165
|
+
(let ((token (aref tokens cursor)))
|
|
166
|
+
(setq cursor (1+ cursor))
|
|
167
|
+
(if (= (get token :level) 1)
|
|
168
|
+
(progn
|
|
169
|
+
(when (own result (get token :title)) (fail "MDP-E003" (get token :line) "Duplicate section"))
|
|
170
|
+
(setq current (funcall block 0 false)) (put-data result (get token :title) current))
|
|
171
|
+
(progn
|
|
172
|
+
(when (nil? current) (fail "MDP-E001" (get token :line) "Orphan heading"))
|
|
173
|
+
(when (Array/isArray current) (fail "MDP-E002" (get token :line) "Table with subsection"))
|
|
174
|
+
(when (own current (get token :title)) (fail "MDP-E003" (get token :line) "Duplicate subsection"))
|
|
175
|
+
(put-data current (get token :title) (funcall block 0 false))))) ) result))))
|
|
176
|
+
|
|
177
|
+
(defun atom (value)
|
|
178
|
+
(cond ((nil? value) "null")
|
|
179
|
+
((= (js* "typeof value") "string")
|
|
180
|
+
(if (or (= value "") (not (= (js-call value :trim) value)) (js-call (js* "/[\\n\\r\\t]/u") :test value)
|
|
181
|
+
(js-call number-pattern :test value) (js-call (js-array "true" "false" "null" "{}" "[]") :includes value)
|
|
182
|
+
(and (js-call value :startsWith "\"") (js-call value :endsWith "\"")))
|
|
183
|
+
(str "\"" (js-call value :replace (js* "/[\"\\\\\\n\\r\\t]/gu")
|
|
184
|
+
(lambda (character) (get (js-object "\"" "\\\"" "\\" "\\\\" "\n" "\\n" "\r" "\\r" "\t" "\\t") character))) "\"") value))
|
|
185
|
+
((or (= (js* "typeof value") "boolean") (and (= (js* "typeof value") "number") (Number/isFinite value))) (funcall globalThis/String value))
|
|
186
|
+
((and (Array/isArray value) (= (js-length value) 0)) "[]")
|
|
187
|
+
((and (object? value) (js-call (js-array (get globalThis/Object :prototype) nil) :includes (Object/getPrototypeOf value))
|
|
188
|
+
(= (js-length (Object/keys value)) 0)) "{}")
|
|
189
|
+
(t (throw (new globalThis/TypeError "Expected a finite JSON scalar")))))
|
|
190
|
+
(defun leaf (value)
|
|
191
|
+
(or (nil? value) (not (= (js* "typeof value") "object"))
|
|
192
|
+
(if (Array/isArray value) (= (js-length value) 0) (= (js-length (Object/keys value)) 0))))
|
|
193
|
+
(defun key-text (key &optional heading)
|
|
194
|
+
(when (or (not (truth key)) (not (= (js-call key :trim) key)) (js-call (js* "/[\\r\\n\\t]/u") :test key)
|
|
195
|
+
(if heading (js-call (js* "/\\s#+$/u") :test key) (js-call (js* "/: /u") :test key)))
|
|
196
|
+
(throw (new globalThis/TypeError "Unrepresentable Markdown key"))) key)
|
|
197
|
+
(defun append-child (lines prefix child depth body)
|
|
198
|
+
(let* ((push (get lines :push)) (first (funcall prefix)) (tail (funcall body child depth)) (arguments (js-array first)))
|
|
199
|
+
(literal-each tail (lambda (line) (put arguments (js-length arguments) line)))
|
|
200
|
+
(Reflect/apply push lines arguments)))
|
|
201
|
+
(defun flat-object-keys (data)
|
|
202
|
+
;; Collect one mapped level before Set construction, keeping the original
|
|
203
|
+
;; index order, length snapshots and HasProperty/Get order for holes.
|
|
204
|
+
(let ((result (js-array)) (length (js-length data)) (index 0))
|
|
205
|
+
(while (< index length)
|
|
206
|
+
(when (Reflect/has data index)
|
|
207
|
+
(let* ((item (aref data index)) (keys (if (object? item) (Object/keys item) (js-array))))
|
|
208
|
+
(if (Array/isArray keys)
|
|
209
|
+
(let ((key-length (js-length keys)) (key-index 0))
|
|
210
|
+
(while (< key-index key-length)
|
|
211
|
+
(when (Reflect/has keys key-index)
|
|
212
|
+
(put result (js-length result) (aref keys key-index)))
|
|
213
|
+
(setq key-index (1+ key-index))))
|
|
214
|
+
(put result (js-length result) keys))))
|
|
215
|
+
(setq index (1+ index))) result))
|
|
216
|
+
(defun encode (value &rest optional-options)
|
|
217
|
+
(let* ((options (if (or (= (js-length optional-options) 0) (undefined? (aref optional-options 0))) (js-object) (aref optional-options 0)))
|
|
218
|
+
(max-depth (option options "maxDepth" 256)) (max-length (option options "maxLength" 16777216)))
|
|
219
|
+
(unless (and (object? value) (js-call (js-array (get globalThis/Object :prototype) nil) :includes (Object/getPrototypeOf value)))
|
|
220
|
+
(throw (new globalThis/TypeError "Markdown document must be a plain object")))
|
|
221
|
+
(unless (and (Number/isSafeInteger max-depth) (>= max-depth 0) (<= max-depth 512) (Number/isSafeInteger max-length) (>= max-length 1))
|
|
222
|
+
(throw (new globalThis/RangeError "Invalid encoder limits")))
|
|
223
|
+
(let ((active (new globalThis/Set)) (body nil))
|
|
224
|
+
(setq body (lambda (data depth)
|
|
225
|
+
(when (> depth max-depth) (throw (new globalThis/RangeError "Markdown depth limit")))
|
|
226
|
+
(when (js-call active :has data) (throw (new globalThis/TypeError "Cyclic Markdown value")))
|
|
227
|
+
(js-call active :add data)
|
|
228
|
+
(let ((pad (js-call " " :repeat depth)) (lines (js-array)))
|
|
229
|
+
(cond
|
|
230
|
+
((Array/isArray data)
|
|
231
|
+
(let ((index 0))
|
|
232
|
+
(while (< index (js-length data))
|
|
233
|
+
(unless (own data index) (throw (new globalThis/TypeError "Sparse arrays are not JSON values")))
|
|
234
|
+
(setq index (1+ index))))
|
|
235
|
+
(if (js-call data :every leaf)
|
|
236
|
+
(progn
|
|
237
|
+
(setq lines (js-array (str pad "| value |") (str pad "| --- |")))
|
|
238
|
+
(literal-each (js-call data :map (lambda (item) (str pad "| " (js-call (atom item) :replaceAll "|" "\\|") " |")))
|
|
239
|
+
(lambda (line) (put lines (js-length lines) line))))
|
|
240
|
+
(let ((keys (js-array)))
|
|
241
|
+
(literal-each (new globalThis/Set (flat-object-keys data))
|
|
242
|
+
(lambda (key) (put keys (js-length keys) key)))
|
|
243
|
+
(if (and (> (js-length keys) 1) (js-call data :every (lambda (item) (and (object? item) (js-call (Object/values item) :every leaf)))))
|
|
244
|
+
(let ((row (lambda (values) (str pad "| " (js-call values :join " | ") " |")))
|
|
245
|
+
(cell (lambda (item) (js-call (atom item) :replaceAll "|" "\\|"))))
|
|
246
|
+
(setq lines (js-array
|
|
247
|
+
(funcall row (js-call keys :map (lambda (key) (js-call (key-text key) :replaceAll "|" "\\|"))))
|
|
248
|
+
(funcall row (js-call keys :map (lambda () "---")))))
|
|
249
|
+
(literal-each (js-call data :map (lambda (item)
|
|
250
|
+
(funcall row (js-call keys :map (lambda (key) (if (own item key) (funcall cell (aref item key)) ""))))))
|
|
251
|
+
(lambda (line) (put lines (js-length lines) line))))
|
|
252
|
+
(literal-each data (lambda (child)
|
|
253
|
+
(if (leaf child) (js-call lines :push (str pad "- : " (atom child)))
|
|
254
|
+
(append-child lines (lambda () (str pad "- :")) child (1+ depth) body))))))))
|
|
255
|
+
((object? data)
|
|
256
|
+
(unless (and (eq (Object/getPrototypeOf data) (get globalThis/Object :prototype))
|
|
257
|
+
(not (nil? data)))
|
|
258
|
+
(unless (nil? (Object/getPrototypeOf data)) (throw (new globalThis/TypeError "Expected plain JSON object"))))
|
|
259
|
+
(literal-each (Object/entries data) (lambda (entry)
|
|
260
|
+
(let ((key (aref entry 0)) (child (aref entry 1)))
|
|
261
|
+
(if (leaf child) (js-call lines :push (str pad "- " (key-text key) ": " (atom child)))
|
|
262
|
+
(append-child lines (lambda () (str pad "- " (key-text key) ":")) child (1+ depth) body))))))
|
|
263
|
+
(t (throw (new globalThis/TypeError "Expected JSON container"))))
|
|
264
|
+
(js-call active :delete data) lines)))
|
|
265
|
+
(js-call active :add value)
|
|
266
|
+
(let ((preamble (js-array)) (sections (js-array)))
|
|
267
|
+
(literal-each (Object/entries value) (lambda (entry)
|
|
268
|
+
(let ((key (aref entry 0)) (child (aref entry 1)))
|
|
269
|
+
(if (leaf child) (js-call preamble :push (str "- " (key-text key) ": " (atom child)))
|
|
270
|
+
(js-call sections :push (str "# " (key-text key t) "\n\n" (js-call (funcall body child 0) :join "\n")))))))
|
|
271
|
+
(let ((parts (if (> (js-length preamble) 0) (js-array (js-call preamble :join "\n")) (js-array))))
|
|
272
|
+
(literal-each sections (lambda (section) (put parts (js-length parts) section)))
|
|
273
|
+
(let ((output (str (js-call parts :join "\n\n") "\n")))
|
|
274
|
+
(when (> (js-length output) max-length) (throw (new globalThis/RangeError "Markdown length limit"))) output))))))
|
|
275
|
+
(export MarkdownError parse encode))
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
(module eliscript.managed-wire-schema
|
|
2
|
+
(import "./markdown.eli" parse)
|
|
3
|
+
(import "../../stdlib/managed-literal-protocols.eli" managed-literal-reduce-iterable managed-literal-reduced)
|
|
4
|
+
|
|
5
|
+
(defconst types (new globalThis/Set (js-array "any" "string" "int" "float" "number" "bool" "null" "date" "datetime")))
|
|
6
|
+
(defconst reserved (new globalThis/Set (js-array "Preamble" "Sections")))
|
|
7
|
+
(defconst date-pattern (js* "/^\\d{4}-\\d{2}-\\d{2}$/u"))
|
|
8
|
+
(defconst datetime-pattern (js* "/^\\d{4}-\\d{2}-\\d{2}[Tt]\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:[Zz]|[+-]\\d{2}:\\d{2})$/u"))
|
|
9
|
+
(defun fail (message) (throw (new globalThis/TypeError message)))
|
|
10
|
+
(defun object? (value) (and (not (nil? value)) (= (js* "typeof value") "object") (not (Array/isArray value))))
|
|
11
|
+
(defun truth (value) (funcall globalThis/Boolean value))
|
|
12
|
+
(defun each (values visit)
|
|
13
|
+
(managed-literal-reduce-iterable values (lambda (ignored value) (funcall visit value) nil) (js-array nil)))
|
|
14
|
+
(defun at (document path)
|
|
15
|
+
(managed-literal-reduce-iterable (js-call path :split ".")
|
|
16
|
+
(lambda (value part)
|
|
17
|
+
(if (and (object? value) (Object/hasOwn value part)) (aref value part)
|
|
18
|
+
(managed-literal-reduced undefined))) (js-array document)))
|
|
19
|
+
(defun copy-row (row)
|
|
20
|
+
(let ((result (js-object)))
|
|
21
|
+
(each (Reflect/ownKeys row) (lambda (key)
|
|
22
|
+
(let ((descriptor (Object/getOwnPropertyDescriptor row key)))
|
|
23
|
+
(when (and (not (undefined? descriptor)) (truth (aref descriptor "enumerable")))
|
|
24
|
+
(Object/defineProperty result key (js-object :value (aref row key) :enumerable t :writable t :configurable t))))))
|
|
25
|
+
result))
|
|
26
|
+
(defun decimal-part (text start end) (funcall globalThis/Number (js-call text :slice start end)))
|
|
27
|
+
(defun valid-date? (value)
|
|
28
|
+
(and (= (js* "typeof value") "string") (= (js-length value) 10) (js-call date-pattern :test value)
|
|
29
|
+
(let* ((year (decimal-part value 0 4)) (month (decimal-part value 5 7)) (day (decimal-part value 8 10))
|
|
30
|
+
(leap (and (= (% year 4) 0) (or (/= (% year 100) 0) (= (% year 400) 0))))
|
|
31
|
+
(days (if (= month 2) (if leap 29 28)
|
|
32
|
+
(if (js-call (js-array 4 6 9 11) :includes month) 30 31))))
|
|
33
|
+
(and (>= month 1) (<= month 12) (>= day 1) (<= day days)))))
|
|
34
|
+
(defun valid-datetime? (value)
|
|
35
|
+
(and (= (js* "typeof value") "string") (js-call datetime-pattern :test value)
|
|
36
|
+
(valid-date? (js-call value :slice 0 10))
|
|
37
|
+
(let* ((hour (decimal-part value 11 13)) (minute (decimal-part value 14 16)) (second (decimal-part value 17 19))
|
|
38
|
+
(zone-end (1- (js-length value))) (last (aref value zone-end))
|
|
39
|
+
(zulu (or (= last "Z") (= last "z")))
|
|
40
|
+
(zone-start (if zulu zone-end (- (js-length value) 6)))
|
|
41
|
+
(millisecond 0))
|
|
42
|
+
;; The ISO Date parser keeps the first three fractional second digits;
|
|
43
|
+
;; subsequent digits do not turn a midnight millisecond into nonzero.
|
|
44
|
+
(when (= (aref value 19) ".")
|
|
45
|
+
(let ((fraction (js-call value :slice 20 zone-start)))
|
|
46
|
+
(setq millisecond (funcall globalThis/Number (js-call (str fraction "000") :slice 0 3)))))
|
|
47
|
+
(and (<= hour 24) (<= minute 59) (<= second 59)
|
|
48
|
+
(or (< hour 24) (and (= minute 0) (= second 0) (= millisecond 0)))
|
|
49
|
+
(or zulu (and (<= (decimal-part value (1+ zone-start) (+ zone-start 3)) 23)
|
|
50
|
+
(<= (decimal-part value (+ zone-start 4) (+ zone-start 6)) 59)))))))
|
|
51
|
+
(defun typed? (value type)
|
|
52
|
+
(cond ((= type "any") t)
|
|
53
|
+
((= type "string") (= (js* "typeof value") "string"))
|
|
54
|
+
((= type "int") (and (Number/isFinite value) (Number/isInteger value)))
|
|
55
|
+
((or (= type "float") (= type "number")) (and (= (js* "typeof value") "number") (Number/isFinite value)))
|
|
56
|
+
((= type "bool") (= (js* "typeof value") "boolean"))
|
|
57
|
+
((= type "null") (nil? value))
|
|
58
|
+
((= type "date") (valid-date? value))
|
|
59
|
+
((= type "datetime") (valid-datetime? value))
|
|
60
|
+
(t undefined)))
|
|
61
|
+
(defun validate (data schema)
|
|
62
|
+
(when (= (js* "typeof data") "string") (setq data (parse data)))
|
|
63
|
+
(when (= (js* "typeof schema") "string") (setq schema (parse schema)))
|
|
64
|
+
(unless (and (object? data) (object? schema) (= (aref schema "mds") "0.1"))
|
|
65
|
+
(fail "Expected object data and an MDS/0.1 schema"))
|
|
66
|
+
(each (Object/entries schema) (lambda (entry)
|
|
67
|
+
(let ((name (aref entry 0)) (value (aref entry 1)))
|
|
68
|
+
(when (and (not (js-call reserved :has name)) (object? value))
|
|
69
|
+
(fail "Schema field definition must be a table")))))
|
|
70
|
+
(let* ((definitions (js-call (Object/keys schema) :filter
|
|
71
|
+
(lambda (key &rest ignored) (and (not (js-call reserved :has key)) (Array/isArray (aref schema key))))))
|
|
72
|
+
(fields (new globalThis/Map)) (names (js-call definitions :slice)))
|
|
73
|
+
(when (Object/hasOwn schema "Preamble") (js-call names :push "Preamble"))
|
|
74
|
+
(each names (lambda (name)
|
|
75
|
+
(let ((rows (aref schema name)) (seen (new globalThis/Set)))
|
|
76
|
+
(unless (Array/isArray rows) (fail "Schema field definition must be a table"))
|
|
77
|
+
(js-call fields :set name (js-call rows :map (lambda (row &rest ignored)
|
|
78
|
+
(unless (and (object? row)
|
|
79
|
+
(let ((name (aref row "name"))) (= (js* "typeof name") "string"))
|
|
80
|
+
(truth (aref row "name"))
|
|
81
|
+
(js-call types :has (aref row "type")) (not (js-call seen :has (aref row "name"))))
|
|
82
|
+
(fail "Invalid schema field declaration"))
|
|
83
|
+
(js-call seen :add (aref row "name"))
|
|
84
|
+
(when (and (Object/hasOwn row "required")
|
|
85
|
+
(let ((required (aref row "required"))) (/= (js* "typeof required") "boolean")))
|
|
86
|
+
(fail "required must be boolean"))
|
|
87
|
+
(each (js-array "min" "max" "min_len" "max_len") (lambda (key)
|
|
88
|
+
(when (and (Object/hasOwn row key)
|
|
89
|
+
(or (let ((value (aref row key))) (/= (js* "typeof value") "number"))
|
|
90
|
+
(not (Number/isFinite (aref row key)))
|
|
91
|
+
(and (js-call key :endsWith "_len")
|
|
92
|
+
(or (not (Number/isInteger (aref row key))) (< (aref row key) 0)))))
|
|
93
|
+
(fail (str "Invalid " key " constraint")))))
|
|
94
|
+
(when (or (and (not (undefined? (aref row "min"))) (not (undefined? (aref row "max")))
|
|
95
|
+
(> (aref row "min") (aref row "max")))
|
|
96
|
+
(and (not (undefined? (aref row "min_len"))) (not (undefined? (aref row "max_len")))
|
|
97
|
+
(> (aref row "min_len") (aref row "max_len")))) (fail "Inverted field bounds"))
|
|
98
|
+
(when (and (Object/hasOwn row "enum")
|
|
99
|
+
(let ((value (aref row "enum"))) (/= (js* "typeof value") "string"))) (fail "enum must be text"))
|
|
100
|
+
(let ((pattern undefined))
|
|
101
|
+
(when (Object/hasOwn row "pattern")
|
|
102
|
+
(unless (let ((value (aref row "pattern"))) (= (js* "typeof value") "string")) (fail "pattern must be text"))
|
|
103
|
+
(setq pattern (new globalThis/RegExp (aref row "pattern") "u")))
|
|
104
|
+
(let ((result (copy-row row)))
|
|
105
|
+
(Object/defineProperty result "pattern" (js-object :value pattern :enumerable t :writable t :configurable t)) result))))))))
|
|
106
|
+
(let ((declarations undefined) (declared (new globalThis/Map)))
|
|
107
|
+
(if (Object/hasOwn schema "Sections")
|
|
108
|
+
(progn (unless (Array/isArray (aref schema "Sections")) (fail "Sections must be a table"))
|
|
109
|
+
(setq declarations (aref schema "Sections")))
|
|
110
|
+
(setq declarations (js-call definitions :map (lambda (name &rest ignored) (js-object :name name :required t)))))
|
|
111
|
+
(each declarations (lambda (row)
|
|
112
|
+
(unless (and (object? row)
|
|
113
|
+
(let ((name (aref row "name"))) (= (js* "typeof name") "string"))
|
|
114
|
+
(truth (aref row "name"))
|
|
115
|
+
(not (js-call (js-call (aref row "name") :split ".") :some
|
|
116
|
+
(lambda (part &rest ignored) (not (truth part)))))
|
|
117
|
+
(not (js-call declared :has (aref row "name")))
|
|
118
|
+
(let ((kind (aref row "kind")))
|
|
119
|
+
(js-call (js-array "object" "list" "any") :includes
|
|
120
|
+
(if (nullish? kind) "any" kind))))
|
|
121
|
+
(fail "Invalid section declaration"))
|
|
122
|
+
(each (js-array "required" "additional") (lambda (key)
|
|
123
|
+
(when (and (Object/hasOwn row key)
|
|
124
|
+
(let ((value (aref row key))) (/= (js* "typeof value") "boolean"))) (fail (str key " must be boolean")))))
|
|
125
|
+
(each (js-array "min_rows" "max_rows") (lambda (key)
|
|
126
|
+
(when (and (Object/hasOwn row key) (or (not (Number/isSafeInteger (aref row key))) (< (aref row key) 0)))
|
|
127
|
+
(fail (str "Invalid " key " constraint")))))
|
|
128
|
+
(when (and (not (undefined? (aref row "min_rows"))) (not (undefined? (aref row "max_rows")))
|
|
129
|
+
(> (aref row "min_rows") (aref row "max_rows"))) (fail "Inverted row bounds"))
|
|
130
|
+
(js-call declared :set (aref row "name") row)))
|
|
131
|
+
(let ((errors (js-array)) (error nil) (check-row nil))
|
|
132
|
+
(setq error (lambda (path rule expected actual)
|
|
133
|
+
(js-call errors :push (js-object :path path :rule rule :expected expected :actual actual))))
|
|
134
|
+
(setq check-row (lambda (value rows path &rest optional-arguments)
|
|
135
|
+
(let ((additional (aref optional-arguments 0)))
|
|
136
|
+
(when (undefined? additional) (setq additional t))
|
|
137
|
+
(if (not (object? value)) (funcall error path "kind" "object" value)
|
|
138
|
+
(progn
|
|
139
|
+
(each rows (lambda (row)
|
|
140
|
+
(let ((field-path (str path "." (aref row "name"))))
|
|
141
|
+
(if (not (Object/hasOwn value (aref row "name")))
|
|
142
|
+
(when (truth (aref row "required")) (funcall error field-path "required" t "missing"))
|
|
143
|
+
(let ((actual (aref value (aref row "name"))))
|
|
144
|
+
(if (not (truth (typed? actual (aref row "type"))))
|
|
145
|
+
(funcall error field-path "type" (aref row "type") actual)
|
|
146
|
+
(progn
|
|
147
|
+
(when (and (not (undefined? (aref row "enum"))))
|
|
148
|
+
(unless (js-call (js-call (js-call (aref row "enum") :split ",") :map
|
|
149
|
+
(lambda (text &rest ignored) (js-call text :trim))) :includes (funcall globalThis/String actual))
|
|
150
|
+
(funcall error field-path "enum" (aref row "enum") actual)))
|
|
151
|
+
(each (js-array "min" "max") (lambda (key)
|
|
152
|
+
(when (and (= (js* "typeof actual") "number") (not (undefined? (aref row key)))
|
|
153
|
+
(if (= key "min") (< actual (aref row key)) (> actual (aref row key))))
|
|
154
|
+
(funcall error field-path key (aref row key) actual))))
|
|
155
|
+
(when (= (js* "typeof actual") "string")
|
|
156
|
+
(let ((length (managed-literal-reduce-iterable actual
|
|
157
|
+
(lambda (size ignored) (1+ size)) (js-array 0))))
|
|
158
|
+
(each (js-array "min_len" "max_len") (lambda (key)
|
|
159
|
+
(when (and (not (undefined? (aref row key)))
|
|
160
|
+
(if (= key "min_len") (< length (aref row key)) (> length (aref row key))))
|
|
161
|
+
(funcall error field-path key (aref row key) length)))))
|
|
162
|
+
(when (and (truth (aref row "pattern")) (not (js-call (aref row "pattern") :test actual)))
|
|
163
|
+
(funcall error field-path "pattern" (aref (aref row "pattern") "source") actual))))))))))
|
|
164
|
+
(unless (truth additional)
|
|
165
|
+
(let ((allowed (new globalThis/Set (js-call rows :map (lambda (row &rest ignored) (aref row "name"))))))
|
|
166
|
+
(each (Object/keys value) (lambda (key)
|
|
167
|
+
(when (and (not (js-call allowed :has key))
|
|
168
|
+
(or (nil? (aref value key)) (let ((item (aref value key))) (/= (js* "typeof item") "object"))))
|
|
169
|
+
(funcall error (str path "." key) "additional" false (aref value key))))))))))))
|
|
170
|
+
(when (js-call fields :has "Preamble") (funcall check-row data (js-call fields :get "Preamble") "preamble"))
|
|
171
|
+
(let ((names (new globalThis/Set definitions)))
|
|
172
|
+
(each (js-call declared :keys) (lambda (name) (js-call names :add name)))
|
|
173
|
+
(each names (lambda (name)
|
|
174
|
+
(let* ((raw-policy (js-call declared :get name)) (policy (if (nullish? raw-policy) (js-object) raw-policy))
|
|
175
|
+
(value (at data name)))
|
|
176
|
+
(if (undefined? value)
|
|
177
|
+
(when (truth (aref policy "required")) (funcall error name "required" t "missing"))
|
|
178
|
+
(let ((kind (if (Array/isArray value) "list" (if (object? value) "object" "scalar"))))
|
|
179
|
+
(if (and (truth (aref policy "kind")) (/= (aref policy "kind") "any") (/= (aref policy "kind") kind))
|
|
180
|
+
(funcall error name "kind" (aref policy "kind") kind)
|
|
181
|
+
(if (Array/isArray value)
|
|
182
|
+
(progn
|
|
183
|
+
(each (js-array "min_rows" "max_rows") (lambda (key)
|
|
184
|
+
(when (and (not (undefined? (aref policy key)))
|
|
185
|
+
(if (= key "min_rows") (< (js-length value) (aref policy key)) (> (js-length value) (aref policy key))))
|
|
186
|
+
(funcall error name key (aref policy key) (js-length value)))))
|
|
187
|
+
(when (js-call fields :has name)
|
|
188
|
+
(js-call value :forEach (lambda (row index &rest ignored)
|
|
189
|
+
(funcall check-row row (js-call fields :get name) (str name "[" index "]") (aref policy "additional"))))))
|
|
190
|
+
(when (js-call fields :has name)
|
|
191
|
+
(funcall check-row value (js-call fields :get name) name (aref policy "additional")))))))))))
|
|
192
|
+
(js-object :valid (= (js-length errors) 0) :errors errors)))))
|
|
193
|
+
(export validate))
|
package/stdlib/mdp.eli
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
(module eliscript.mdp
|
|
2
|
+
(import "../runtime/wire/markdown.mjs" :as Wire)
|
|
3
|
+
(defun mdp-parse (source &rest options)
|
|
4
|
+
(apply Wire/parse (js-cons source options)))
|
|
5
|
+
(defun mdp-encode (value &rest options)
|
|
6
|
+
(apply Wire/encode (js-cons value options)))
|
|
7
|
+
(export mdp-encode mdp-parse))
|
package/stdlib/mds.eli
ADDED
|
@@ -6,15 +6,28 @@
|
|
|
6
6
|
(defconst persistent-vector-max-count 2147483647)
|
|
7
7
|
|
|
8
8
|
(defportable array-reverse (values)
|
|
9
|
-
(
|
|
9
|
+
(cond
|
|
10
|
+
((= (js-length values) 0) (js-array))
|
|
11
|
+
((= (js-length values) 1) (js-array (get values 0)))
|
|
12
|
+
((= (js-length values) 2)
|
|
13
|
+
;; Snapshot in original getter order before reversing the data slots.
|
|
14
|
+
(let* ((first (get values 0)) (second (get values 1))) (js-array second first)))
|
|
15
|
+
(t (let ((result (js-array))
|
|
10
16
|
(index 0))
|
|
11
17
|
(while (< index (js-length values))
|
|
12
18
|
(setq result (js-cons (get values index) result)
|
|
13
19
|
index (1+ index)))
|
|
14
|
-
result))
|
|
20
|
+
result))))
|
|
15
21
|
|
|
16
22
|
(defportable array-copy-assoc (values wanted-index wanted-value)
|
|
17
|
-
(
|
|
23
|
+
(cond
|
|
24
|
+
((and (= (js-length values) 0) (= wanted-index 0)) (js-array wanted-value))
|
|
25
|
+
((and (= (js-length values) 1) (= wanted-index 0)) (js-array wanted-value))
|
|
26
|
+
((and (= (js-length values) 1) (= wanted-index 1)) (js-array (get values 0) wanted-value))
|
|
27
|
+
((and (= (js-length values) 2) (= wanted-index 0)) (js-array wanted-value (get values 1)))
|
|
28
|
+
((and (= (js-length values) 2) (= wanted-index 1)) (js-array (get values 0) wanted-value))
|
|
29
|
+
((and (= (js-length values) 2) (= wanted-index 2)) (js-array (get values 0) (get values 1) wanted-value))
|
|
30
|
+
(t (let ((result (js-array))
|
|
18
31
|
(index 0)
|
|
19
32
|
(result-length
|
|
20
33
|
(if (< wanted-index (js-length values))
|
|
@@ -28,16 +41,20 @@
|
|
|
28
41
|
(get values index))
|
|
29
42
|
result)
|
|
30
43
|
index (1+ index)))
|
|
31
|
-
(array-reverse result)))
|
|
44
|
+
(array-reverse result)))))
|
|
32
45
|
|
|
33
46
|
(defportable array-drop-last (values)
|
|
34
|
-
(
|
|
47
|
+
(cond
|
|
48
|
+
((<= (js-length values) 1) (js-array))
|
|
49
|
+
((= (js-length values) 2) (js-array (get values 0)))
|
|
50
|
+
((= (js-length values) 3) (js-array (get values 0) (get values 1)))
|
|
51
|
+
(t (let ((result (js-array))
|
|
35
52
|
(index 0)
|
|
36
53
|
(result-length (1- (js-length values))))
|
|
37
54
|
(while (< index result-length)
|
|
38
55
|
(setq result (js-cons (get values index) result)
|
|
39
56
|
index (1+ index)))
|
|
40
|
-
(array-reverse result)))
|
|
57
|
+
(array-reverse result)))))
|
|
41
58
|
|
|
42
59
|
(defportable make-vector-node (slots)
|
|
43
60
|
(js-object :slots slots))
|