eliscript 0.0.1 → 0.0.2
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 +59 -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-legacy.mjs +37 -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 +89 -0
- 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 +446 -0
- package/dist/browser/loader.js +1 -0
- package/dist/browser/loader.mjs +231 -0
- package/dist/browser/worker.mjs +60 -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 +579 -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 +23 -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 +20 -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 +483 -0
- package/dist/literal-sources/stdlib/managed-literals.eli +1414 -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 +97 -10
- 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 +114 -47
- package/stdlib/gepo.eli +12 -0
- package/stdlib/interop/js.eli +56 -15
- package/stdlib/managed-literal-protocols.eli +483 -0
- package/stdlib/managed-literals.eli +1414 -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 +579 -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 +23 -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 +20 -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 +460 -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 +486 -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,1181 @@
|
|
|
1
|
+
import {hostUnicodeCaseVersion} from '../runtime/unicode-case-profiles.mjs';
|
|
2
|
+
import {createManagedSourceView,createManagedLiteralHostProvider} from './managed-source-view.mjs';
|
|
3
|
+
import * as httpHostCapabilities from '../../platform/http.mjs';
|
|
4
|
+
// Bulk host boundary for the .eli managed heap. GC, value operations and allocation
|
|
5
|
+
// execute in the compiled runtime. Handles own explicit roots until release.
|
|
6
|
+
export function failManagedRuntime(code,sourceClass=0) {
|
|
7
|
+
const message=code===1?'invalid managed value handle':code===2?'managed capacity exhausted':code===4?'invalid UTF-8 input':code===5?'invalid UTF-16 surrogate':code===6?'managed string sealing error':code===8?'uninitialized managed module binding':code===12?'uninitialized managed lexical binding':code===9?'cyclic array text conversion':code===10?'invalid Number.toString radix':'managed argument or bounds error';
|
|
8
|
+
const Constructor=sourceClass===2?TypeError:sourceClass===3?RangeError:sourceClass===4?SyntaxError:sourceClass===5?ReferenceError:
|
|
9
|
+
(code===8||code===12)?ReferenceError:code===9?TypeError:code===10?RangeError:Error;
|
|
10
|
+
const error=new Constructor(message);
|
|
11
|
+
error.eliscriptDiagnostic={format:'eliscript-diagnostic',version:1,code:`ELI-RT${String(code).padStart(4,'0')}`,severity:'error',phase:'runtime',message:error.message};throw error;
|
|
12
|
+
}
|
|
13
|
+
function word(x,max=0xffffffff) {if(typeof x!=='number'||!Number.isInteger(x)||x<0||x>max||Object.is(x,-0))failManagedRuntime(3);return x;}
|
|
14
|
+
function flag(value) {if(typeof value!=='boolean')failManagedRuntime(3);return Number(value);}
|
|
15
|
+
const hostWellKnownSymbols=Object.freeze([
|
|
16
|
+
Symbol.iterator,Symbol.toPrimitive,Symbol.match,Symbol.replace,Symbol.search,Symbol.split,
|
|
17
|
+
Symbol.species,Symbol.isConcatSpreadable,Symbol.toStringTag,Symbol.hasInstance,
|
|
18
|
+
Symbol.asyncIterator,Symbol.unscopables,Symbol.matchAll,Symbol.dispose,Symbol.asyncDispose,
|
|
19
|
+
]);
|
|
20
|
+
const hostFunctionToString=Function.prototype.toString;
|
|
21
|
+
const hostCrypto=globalThis.crypto;
|
|
22
|
+
const hostGetRandomValues=hostCrypto?.getRandomValues;
|
|
23
|
+
const hostObjectToString=Object.prototype.toString;
|
|
24
|
+
const hostPromiseThen=Promise.prototype.then;
|
|
25
|
+
const hostCollectionIntrinsics=Object.freeze([
|
|
26
|
+
Map.prototype.get,Map.prototype.set,Map.prototype.has,Map.prototype.delete,Map.prototype.clear,
|
|
27
|
+
Map.prototype.entries,Map.prototype.keys,Map.prototype.values,Map.prototype.forEach,
|
|
28
|
+
Object.getOwnPropertyDescriptor(Map.prototype,'size').get,
|
|
29
|
+
Set.prototype.add,Set.prototype.has,Set.prototype.delete,Set.prototype.clear,
|
|
30
|
+
Set.prototype.entries,Set.prototype.keys,Set.prototype.values,Set.prototype.forEach,
|
|
31
|
+
Object.getOwnPropertyDescriptor(Set.prototype,'size').get,
|
|
32
|
+
WeakMap.prototype.get,WeakMap.prototype.set,WeakMap.prototype.has,WeakMap.prototype.delete,
|
|
33
|
+
WeakSet.prototype.add,WeakSet.prototype.has,WeakSet.prototype.delete,
|
|
34
|
+
]);
|
|
35
|
+
const hostIteratorIntrinsics=Object.freeze({
|
|
36
|
+
328:Object.getPrototypeOf(Reflect.apply(Array.prototype.values,[],[])).next,
|
|
37
|
+
329:Object.getPrototypeOf(Reflect.apply(hostCollectionIntrinsics[5],new Map(),[])).next,
|
|
38
|
+
330:Object.getPrototypeOf(Reflect.apply(hostCollectionIntrinsics[16],new Set(),[])).next,
|
|
39
|
+
332:Object.getPrototypeOf(Reflect.apply(RegExp.prototype[Symbol.matchAll],/(?:)/g,[''])).next,
|
|
40
|
+
333:Object.getPrototypeOf(Reflect.apply(String.prototype[Symbol.iterator],'',[])).next,
|
|
41
|
+
});
|
|
42
|
+
export function createManagedHostCapabilityBridge(descriptor,options={}) {
|
|
43
|
+
const declared=descriptor?.hostCapabilities??[],names=new Set();let handler,closed=false;
|
|
44
|
+
if(!Array.isArray(declared))throw new TypeError('managed host capabilities must be an array');
|
|
45
|
+
for(const item of declared){
|
|
46
|
+
if(!['console-log','console-log-capture','source-operation'].includes(item?.name)||item.module!=='eliscript.host'||item.arity!==2||item.abi!=='managed-host-call-v1'||names.has(item.name))
|
|
47
|
+
throw new TypeError('unsupported or duplicate managed host capability');
|
|
48
|
+
names.add(item.name);
|
|
49
|
+
}
|
|
50
|
+
return Object.freeze({
|
|
51
|
+
attach(value){if(closed||handler||typeof value!=='function')throw new TypeError('managed host capability bridge cannot attach');handler=value;},
|
|
52
|
+
dispatch(name,heap,argumentsList){
|
|
53
|
+
if(closed||!handler)throw new Error('managed host capability bridge is unavailable');
|
|
54
|
+
if(!names.has(name))throw new TypeError('undeclared managed host capability');
|
|
55
|
+
return handler(name,word(heap),word(argumentsList));
|
|
56
|
+
},
|
|
57
|
+
close(){closed=true;handler=undefined;},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function managedWeakReference(value){return typeof WeakRef==='function'?new WeakRef(value):{deref:()=>value};}
|
|
61
|
+
function yieldManagedJobs(signal) {
|
|
62
|
+
if(signal?.aborted)return Promise.reject(signal.reason??new DOMException('The operation was aborted','AbortError'));
|
|
63
|
+
return new Promise((resolve,reject)=>{
|
|
64
|
+
const abort=()=>{clearTimeout(timer);signal?.removeEventListener('abort',abort);reject(signal.reason??new DOMException('The operation was aborted','AbortError'));};
|
|
65
|
+
const timer=setTimeout(()=>{signal?.removeEventListener('abort',abort);resolve();},0);
|
|
66
|
+
signal?.addEventListener('abort',abort,{once:true});
|
|
67
|
+
if(signal?.aborted)abort();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export function validateManagedRuntimeOptions({initializeModule:initialize=true,unicodeVersion='host',randomSeed}={}) {
|
|
71
|
+
if(typeof initialize!=='boolean'||!['host',15.1,16,17].includes(unicodeVersion))failManagedRuntime(3);
|
|
72
|
+
if(randomSeed===undefined)return undefined;
|
|
73
|
+
if(!(Array.isArray(randomSeed)||randomSeed instanceof Uint32Array)||randomSeed.length!==4)failManagedRuntime(3);
|
|
74
|
+
const seed=[word(randomSeed[0]),word(randomSeed[1]),word(randomSeed[2]),word(randomSeed[3])];
|
|
75
|
+
if(seed.every(value=>value===0))failManagedRuntime(3);
|
|
76
|
+
return Object.freeze(seed);
|
|
77
|
+
}
|
|
78
|
+
export function createManagedHostRuntime(e,descriptor,memory,options={},lifecycle={}) {
|
|
79
|
+
const {maxSlots=1024,initialBytes=65536,maxBytes=16777216,initializeModule:initialize=true,unicodeVersion='host',randomSeed}=options;
|
|
80
|
+
const currentConsole=()=>Object.hasOwn(options,'console')?options.console:globalThis.console;
|
|
81
|
+
const configuredRandomSeed=validateManagedRuntimeOptions({initializeModule:initialize,unicodeVersion,randomSeed});
|
|
82
|
+
const entries=new Map(),moduleExports=new Map();let moduleInfo=null;
|
|
83
|
+
if(descriptor!==null) {
|
|
84
|
+
if(descriptor?.format!=='eliscript-managed-control'||descriptor.version!==1||!['managed-control-v1','managed-module-v1'].includes(descriptor.abi)||!Array.isArray(descriptor.functions))failManagedRuntime(3);
|
|
85
|
+
if(descriptor.abi==='managed-module-v1'){
|
|
86
|
+
moduleInfo=descriptor.module;
|
|
87
|
+
if(!moduleInfo||typeof moduleInfo!=='object'||Array.isArray(moduleInfo)||!Number.isInteger(moduleInfo.bindingCount)||moduleInfo.bindingCount<0||moduleInfo.bindingCount>1048574||!Number.isInteger(moduleInfo.functionCount)||moduleInfo.functionCount<0||moduleInfo.functionCount>1048575||!Array.isArray(moduleInfo.exports)||moduleInfo.exports.length!==descriptor.functions.length)failManagedRuntime(3);
|
|
88
|
+
for(const[field,suffix,arity]of[['initialize','init',1],['get','get',3],['status','status',1],['close','close',1],['abort','abort',2]]){
|
|
89
|
+
const name='__eliscript_module_'+suffix;if(moduleInfo[field]!==name||typeof e[name]!=='function'||e[name].length!==arity)failManagedRuntime(3);
|
|
90
|
+
}
|
|
91
|
+
}else if(descriptor.module!==undefined)failManagedRuntime(3);
|
|
92
|
+
for(const[position,item]of descriptor.functions.entries()){
|
|
93
|
+
const wireName=moduleInfo?item?.wireName:item?.name;
|
|
94
|
+
if(typeof item?.name!=='string'||entries.has(item.name)||typeof e[wireName]!=='function')failManagedRuntime(3);
|
|
95
|
+
if(moduleInfo?wireName!=='__eliscript_export_'+position:item.wireName!==undefined)failManagedRuntime(3);
|
|
96
|
+
const binding=item.callingConvention==='module-binding',uniform=item.callingConvention==='argument-list';
|
|
97
|
+
if(item.callingConvention!==undefined&&!uniform&&!binding)failManagedRuntime(3);
|
|
98
|
+
if(binding){
|
|
99
|
+
if(!moduleInfo||item.arity!==null||item.parameterKinds!==undefined||!Number.isInteger(item.bindingIndex)||item.bindingIndex<0||item.bindingIndex>=moduleInfo.bindingCount||e[wireName].length!==4)failManagedRuntime(3);
|
|
100
|
+
}else if(item.bindingIndex!==undefined)failManagedRuntime(3);
|
|
101
|
+
if(uniform){
|
|
102
|
+
// Required destructuring parameters also use the argument-list ABI.
|
|
103
|
+
// Legacy fixed-arity readers reject null instead of miscalling this entry.
|
|
104
|
+
if(item.arity!==null||!Array.isArray(item.parameterKinds)||item.parameterKinds.length===0||item.parameterKinds.length>65535||e[wireName].length!==4)failManagedRuntime(3);
|
|
105
|
+
let mode='required';
|
|
106
|
+
for(let i=0;i<item.parameterKinds.length;i++){
|
|
107
|
+
const kind=item.parameterKinds[i];
|
|
108
|
+
if(!((kind==='required'&&mode==='required')||(kind==='optional'&&mode!=='rest')||(kind==='rest'&&i===item.parameterKinds.length-1&&mode!=='rest')))failManagedRuntime(3);
|
|
109
|
+
mode=kind;
|
|
110
|
+
}
|
|
111
|
+
}else if(!binding&&(!Number.isInteger(item.arity)||item.arity<0||item.arity>65535||item.parameterKinds!==undefined||e[wireName].length!==item.arity+1))failManagedRuntime(3);
|
|
112
|
+
entries.set(item.name,{arity:item.arity,uniform:uniform||binding,binding,index:item.bindingIndex,wireName});
|
|
113
|
+
}
|
|
114
|
+
if(moduleInfo){
|
|
115
|
+
for(const item of moduleInfo.exports){
|
|
116
|
+
const entry=entries.get(item?.name);if(!entry||moduleExports.has(item.name)||!Number.isInteger(item.index)||item.index<0||(item.name.startsWith('__eliscript_')&&item.name!=='__eliscript_portable__'))failManagedRuntime(3);
|
|
117
|
+
if(item.kind===0){if(!entry.binding||item.index!==entry.index||item.index>=moduleInfo.bindingCount)failManagedRuntime(3);}
|
|
118
|
+
else if(item.kind===1){if(entry.binding||item.index>=moduleInfo.functionCount)failManagedRuntime(3);}else failManagedRuntime(3);
|
|
119
|
+
moduleExports.set(item.name,item);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if(!moduleInfo&&['init','get','status','close','abort'].some(name=>Object.hasOwn(e,'__eliscript_module_'+name)))failManagedRuntime(3);
|
|
124
|
+
const literalBindings=descriptor?.literalRuntime?.bindings;
|
|
125
|
+
if(descriptor?.literalRuntime!==undefined){
|
|
126
|
+
if(!moduleInfo||descriptor.literalRuntime?.version!==1||!literalBindings||typeof literalBindings!=='object')throw new TypeError('invalid managed literal runtime descriptor');
|
|
127
|
+
for(const name of ['literal-kind','literal-export-value','literal-import-value']){
|
|
128
|
+
const binding=literalBindings[name];
|
|
129
|
+
if(!binding||![0,1].includes(binding.kind)||!Number.isInteger(binding.index)||binding.index<0||
|
|
130
|
+
binding.index>=(binding.kind===0?moduleInfo.bindingCount:moduleInfo.functionCount))throw new TypeError('invalid managed literal runtime binding: '+name);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const handles=new WeakMap(),frames=new WeakMap(),view=()=>memory.view();
|
|
134
|
+
let exceptionHeap=0;
|
|
135
|
+
const call=(name,...args)=>{const result=e[name](...args)>>>0;const code=e['last-error']();
|
|
136
|
+
if(code===11&&exceptionHeap&&typeof e['value-exception-take']==='function'){
|
|
137
|
+
const value=e['value-exception-take'](exceptionHeap)>>>0,failed=e['last-error']();if(failed)failManagedRuntime(failed);
|
|
138
|
+
if(value>3&&e['value-kind'](heap,value)===35){
|
|
139
|
+
const entry=foreignEntries.get(e['value-foreign-token'](heap,value)>>>0);
|
|
140
|
+
if(entry)throw entry.value;
|
|
141
|
+
}
|
|
142
|
+
throw wrap(value);
|
|
143
|
+
}
|
|
144
|
+
if(code){
|
|
145
|
+
const sourceClass=exceptionHeap&&typeof e['value-exception-class']==='function'?e['value-exception-class'](exceptionHeap)>>>0:0;
|
|
146
|
+
if(exceptionHeap&&typeof e['value-exception-class-set']==='function')e['value-exception-class-set'](exceptionHeap,0);
|
|
147
|
+
failManagedRuntime(code,sourceClass);
|
|
148
|
+
}return result;};
|
|
149
|
+
const caseConfigurable=typeof e['runtime-case-version']==='function';
|
|
150
|
+
const caseVersion=caseConfigurable?(unicodeVersion==='host'?hostUnicodeCaseVersion():unicodeVersion===15.1?151:unicodeVersion*10):170;
|
|
151
|
+
if(caseConfigurable)call('runtime-case-version',caseVersion);
|
|
152
|
+
else if(unicodeVersion!=='host')failManagedRuntime(3);
|
|
153
|
+
if(typeof e['runtime-random-seed']==='function'){
|
|
154
|
+
let seed=configuredRandomSeed;
|
|
155
|
+
if(seed===undefined){
|
|
156
|
+
if(typeof hostGetRandomValues!=='function')throw new Error('managed runtime entropy is unavailable');
|
|
157
|
+
const words=new Uint32Array(4);Reflect.apply(hostGetRandomValues,hostCrypto,[words]);
|
|
158
|
+
// The generator has no all-zero state. This maps the one unusable entropy
|
|
159
|
+
// value to a valid seed without retrying or requesting unbounded data.
|
|
160
|
+
if(words.every(value=>value===0))words[3]=1;
|
|
161
|
+
seed=words;
|
|
162
|
+
}
|
|
163
|
+
call('runtime-random-seed',...seed);
|
|
164
|
+
}else if(configuredRandomSeed!==undefined)failManagedRuntime(3);
|
|
165
|
+
const heap=call('heap-new',word(maxSlots),word(initialBytes),word(maxBytes));exceptionHeap=heap;
|
|
166
|
+
function id(value) {
|
|
167
|
+
if(value===null)return 0;if(value===false)return 1;if(value===true)return 2;if(value===undefined)return 3;
|
|
168
|
+
const entry=handles.get(value);if(!entry)failManagedRuntime(typeof value==='number'?3:1);
|
|
169
|
+
call('value-kind',heap,entry.id);return entry.id;
|
|
170
|
+
}
|
|
171
|
+
function wrap(value,owned=false) {
|
|
172
|
+
if(value<=3)return [null,false,true,undefined][value];
|
|
173
|
+
const kind=call('value-kind',heap,value),handle=Object.freeze({kind});
|
|
174
|
+
if(!owned)call('heap-pin',heap,value);handles.set(handle,{id:value,roots:1});return handle;
|
|
175
|
+
}
|
|
176
|
+
function frameId(token) {const entry=frames.get(token);if(!entry)failManagedRuntime(1);return entry.id;}
|
|
177
|
+
function withCallBoundary(operation) {
|
|
178
|
+
const previous=typeof e['value-function-current-this']==='function'?call('value-function-current-this',heap):3;
|
|
179
|
+
if(previous>3)call('heap-pin',heap,previous);
|
|
180
|
+
const target=call('frame-current',heap);let failed=false;
|
|
181
|
+
try{return operation();}
|
|
182
|
+
catch(error){
|
|
183
|
+
failed=true;
|
|
184
|
+
try{call('frame-unwind',heap,target);}catch{}
|
|
185
|
+
try{if(typeof e['value-call-restore']==='function')call('value-call-restore',heap,previous);else if(typeof e['value-call-reset']==='function')call('value-call-reset',heap);}catch{}
|
|
186
|
+
throw error;
|
|
187
|
+
}finally{if(previous>3)try{call('heap-release',heap,previous);}catch(error){if(!failed)throw error;}}
|
|
188
|
+
}
|
|
189
|
+
function data(value,kind) {const v=id(value);return {v,length:call('value-length',heap,v),offset:call('value-data',heap,v,kind)};}
|
|
190
|
+
function refs(input,kind) {
|
|
191
|
+
if(!Array.isArray(input))failManagedRuntime(3);const borrowed=[];
|
|
192
|
+
try {
|
|
193
|
+
if(kind===14){
|
|
194
|
+
// Snapshot own slots and names, preserving holes. An overridden iterator
|
|
195
|
+
// cannot replace this shape or discard operands protected before getters.
|
|
196
|
+
const length=word(input.length),values=[];
|
|
197
|
+
for(const key of Object.keys(input)){const v=id(input[key]);call('heap-pin',heap,v);borrowed.push(v);values.push([key,v]);}
|
|
198
|
+
const value=call('value-array-new',heap,length);call('heap-pin',heap,value);
|
|
199
|
+
try{
|
|
200
|
+
const offset=call('value-data',heap,value,14),target=view(),names=[];
|
|
201
|
+
for(const[key,v]of values){const index=Number(key);if(Number.isInteger(index)&&index>=0&&index<length&&String(index)===key)target.setUint32(offset+index*4,v,true);else names.push([key,v]);}
|
|
202
|
+
for(const[key,v]of names){const name=api.string(key);try{objectCall('value-array-define',value,id(name),v);}finally{api.release(name);}}
|
|
203
|
+
return wrap(value);
|
|
204
|
+
}finally{call('heap-release',heap,value);}
|
|
205
|
+
}
|
|
206
|
+
// Protect operands before later getters or result allocation can collect them.
|
|
207
|
+
const values=Array.from(input,x=>{const v=id(x);call('heap-pin',heap,v);borrowed.push(v);return v;});
|
|
208
|
+
const value=kind===14?call('value-array-new',heap,word(values.length)):call('value-refs',heap,kind,word(values.length)),offset=call('value-data',heap,value,kind),target=view();
|
|
209
|
+
values.forEach((v,i)=>target.setUint32(offset+i*4,v,true));return wrap(value);
|
|
210
|
+
} finally {for(const value of borrowed)call('heap-release',heap,value);}
|
|
211
|
+
}
|
|
212
|
+
function objectCall(name,...args) {
|
|
213
|
+
return withCallBoundary(()=>call(name,heap,...args));
|
|
214
|
+
}
|
|
215
|
+
function sourceObject(input) {
|
|
216
|
+
if(input===null||typeof input!=='object'||Array.isArray(input))failManagedRuntime(3);
|
|
217
|
+
const borrowed=[];let object=0;
|
|
218
|
+
try {
|
|
219
|
+
const values=Object.keys(input).map(key=>{const value=id(input[key]);call('heap-pin',heap,value);borrowed.push(value);return [key,value];});
|
|
220
|
+
object=objectCall('value-object-new',3);call('heap-pin',heap,object);
|
|
221
|
+
for(const [key,value]of values){const name=api.string(key);try{objectCall('value-object-put',object,id(name),value,2);}finally{api.release(name);}}
|
|
222
|
+
return wrap(object);
|
|
223
|
+
}finally{if(object)call('heap-release',heap,object);for(const value of borrowed)call('heap-release',heap,value);}
|
|
224
|
+
}
|
|
225
|
+
function initializeModuleInstance(){
|
|
226
|
+
if(!moduleInfo)failManagedRuntime(3);const status=call(moduleInfo.status,heap);
|
|
227
|
+
try{return withCollectionBoundary(()=>withCallBoundary(()=>{call(moduleInfo.initialize,heap);return true;}));}
|
|
228
|
+
catch(error){
|
|
229
|
+
try{if(status===0&&call(moduleInfo.status,heap)===1){const match=/^ELI-RT([0-9]+)$/.exec(error?.eliscriptDiagnostic?.code??'');e[moduleInfo.abort](heap,match?Number(match[1]):3);}}catch{}
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// A compiled-runtime cleanup boundary shared by module close and native
|
|
234
|
+
// transport disposal. Realm-root cleanup can be added here independently of
|
|
235
|
+
// transport ownership; externally held values keep their own heap roots.
|
|
236
|
+
lifecycle.dispose=()=>{
|
|
237
|
+
let failed=false,failure;
|
|
238
|
+
const cleanup=[
|
|
239
|
+
()=>{if(typeof e['value-async-close']==='function')call('value-async-close',heap);},
|
|
240
|
+
()=>{if(moduleInfo)call(moduleInfo.close,heap);else if(typeof e['value-standard-prototypes-close']==='function')call('value-standard-prototypes-close',heap);},
|
|
241
|
+
()=>{if(typeof e['value-call-reset']==='function')call('value-call-reset',heap);},
|
|
242
|
+
()=>{capabilityOpen=false;},
|
|
243
|
+
()=>{for(const pending of hostPromiseJobs)pending.close();hostPromiseJobs.clear();},
|
|
244
|
+
()=>{let failure;for(const token of consoleRoots)try{api.release(token);}catch(error){failure??=error;}consoleRoots.clear();if(failure)throw failure;},
|
|
245
|
+
()=>{if(foreignBuffer){api.release(foreignBuffer);foreignBuffer=undefined;foreignBufferCapacity=0;}foreignEntries.clear();foreignSymbols.clear();sourceCache.clear();sourceSymbols.clear();},
|
|
246
|
+
()=>{lifecycle.capabilityBridge?.close();},
|
|
247
|
+
()=>{options.moduleGraph?.close();},
|
|
248
|
+
];
|
|
249
|
+
for(const action of cleanup){try{action();}catch(error){if(!failed){failed=true;failure=error;}}}
|
|
250
|
+
if(failed)throw failure;
|
|
251
|
+
};
|
|
252
|
+
const consoleRoots=new Set();
|
|
253
|
+
const hostPromiseJobs=new Set();
|
|
254
|
+
let capabilityOpen=true,foreignBuffer,foreignBufferCapacity=0,nextForeignToken=1;
|
|
255
|
+
const foreignEntries=new Map(),foreignObjects=new WeakMap(),foreignSymbols=new Map(),sourceViews=new WeakMap(),sourceViewOperations=new WeakMap(),sourceSymbols=new Map(),sourceCache=new Map(),consoleCaptures=new WeakSet();
|
|
256
|
+
const sourceFinalizers=typeof FinalizationRegistry==='function'?new FinalizationRegistry(({raw,token})=>{
|
|
257
|
+
const entry=sourceCache.get(raw);
|
|
258
|
+
if(capabilityOpen&&entry?.token===token&&entry.reference.deref()===undefined){
|
|
259
|
+
sourceCache.delete(raw);consoleRoots.delete(token);try{api.release(token);}catch{}
|
|
260
|
+
}
|
|
261
|
+
}):null;
|
|
262
|
+
function rememberSource(raw,value,token,refresh,synchronize){
|
|
263
|
+
const previous=sourceCache.get(raw);
|
|
264
|
+
if(previous){sourceFinalizers?.unregister(previous.token);consoleRoots.delete(previous.token);api.release(previous.token);}
|
|
265
|
+
const reference=managedWeakReference(value);
|
|
266
|
+
sourceViewOperations.set(value,{refresh,synchronize});
|
|
267
|
+
sourceCache.set(raw,{
|
|
268
|
+
reference,token,refreshing:false,
|
|
269
|
+
get refresh(){return sourceViewOperations.get(reference.deref())?.refresh;},
|
|
270
|
+
set refresh(operation){const target=reference.deref();if(target!==undefined)sourceViewOperations.get(target).refresh=operation;},
|
|
271
|
+
get synchronize(){return sourceViewOperations.get(reference.deref())?.synchronize;},
|
|
272
|
+
set synchronize(operation){const target=reference.deref();if(target!==undefined)sourceViewOperations.get(target).synchronize=operation;},
|
|
273
|
+
});
|
|
274
|
+
sourceViews.set(value,raw);consoleRoots.add(token);
|
|
275
|
+
if(sourceFinalizers&&typeof WeakRef==='function')sourceFinalizers.register(value,{raw,token},token);
|
|
276
|
+
}
|
|
277
|
+
let collectionSynchronization=0;
|
|
278
|
+
function synchronizeCollections(){
|
|
279
|
+
if(collectionSynchronization||!capabilityOpen)return;
|
|
280
|
+
collectionSynchronization++;
|
|
281
|
+
try{
|
|
282
|
+
const entries=[...sourceCache.values()];
|
|
283
|
+
for(const entry of entries)if(entry.reference.deref()!==undefined&&entry.synchronize)entry.synchronize();
|
|
284
|
+
}finally{collectionSynchronization--;}
|
|
285
|
+
}
|
|
286
|
+
function withCollectionBoundary(operation){
|
|
287
|
+
synchronizeCollections();let failed=false;
|
|
288
|
+
try{return operation();}catch(error){failed=true;throw error;}
|
|
289
|
+
finally{try{synchronizeCollections();}catch(error){if(!failed)throw error;}}
|
|
290
|
+
}
|
|
291
|
+
const hostModules=options.hostModules instanceof Map?options.hostModules:new Map(Object.entries(options.hostModules??{}));
|
|
292
|
+
const defaultHostModules=new Map();
|
|
293
|
+
for(const declaration of descriptor?.hostModules??[]){
|
|
294
|
+
if(declaration.specifier==='eliscript/platform/http.mjs'||declaration.specifier==='eliscript/platform/http')
|
|
295
|
+
defaultHostModules.set(declaration.id,declaration.specifier);
|
|
296
|
+
}
|
|
297
|
+
function hasHostNamespace(id){return hostModules.has(id)||defaultHostModules.has(id);}
|
|
298
|
+
function hostNamespace(id){
|
|
299
|
+
if(hostModules.has(id))return hostModules.get(id);
|
|
300
|
+
const specifier=defaultHostModules.get(id);
|
|
301
|
+
if(specifier==='eliscript/platform/http.mjs'||specifier==='eliscript/platform/http')
|
|
302
|
+
return hostModules.has(specifier)?hostModules.get(specifier):httpHostCapabilities;
|
|
303
|
+
throw new TypeError('undeclared managed host module');
|
|
304
|
+
}
|
|
305
|
+
let literalHostProvider,literalHostProviderIdentity,literalVectorIdentity,literalReducedIdentity,literalRecordIdentity,literalMetadataIdentity,literalTypeIdentity,literalProtocolIdentity,literalRegexIdentity,literalSortedIdentity;
|
|
306
|
+
let literalProtocolNamespaceIdentities=[];
|
|
307
|
+
function literalHostModule(specifiers){
|
|
308
|
+
for(const specifier of specifiers)if(hostModules.has(specifier))return hostModules.get(specifier);
|
|
309
|
+
for(const declaration of descriptor?.hostModules??[]){
|
|
310
|
+
if(specifiers.includes(declaration.specifier)&&hostModules.has(declaration.id))return hostModules.get(declaration.id);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function literalProvider(){
|
|
314
|
+
const provider=options.literalHostProvider??literalHostModule(['eliscript/runtime/literals','eliscript/runtime/literals.mjs']);
|
|
315
|
+
const vector=literalHostModule(['eliscript/runtime/core/vector','eliscript/runtime/core/vector.mjs']);
|
|
316
|
+
const reduced=literalHostModule(['eliscript/runtime/core/collection-internals','eliscript/runtime/core/collection-internals.mjs']);
|
|
317
|
+
const record=literalHostModule(['eliscript/runtime/core/record','eliscript/runtime/core/record.mjs']);
|
|
318
|
+
const metadata=literalHostModule(['eliscript/runtime/core/metadata','eliscript/runtime/core/metadata.mjs']);
|
|
319
|
+
const type=literalHostModule(['eliscript/runtime/core/type','eliscript/runtime/core/type.mjs']);
|
|
320
|
+
const protocol=literalHostModule(['eliscript/runtime/core/protocol','eliscript/runtime/core/protocol.mjs']);
|
|
321
|
+
const regex=literalHostModule(['eliscript/runtime/core/regex','eliscript/runtime/core/regex.mjs']);
|
|
322
|
+
const sorted=literalHostModule(['eliscript/runtime/core/sorted','eliscript/runtime/core/sorted.mjs']);
|
|
323
|
+
const protocolNamespaceEntries=['collection','value','metadata','transient','order','data-text'].map(family=>
|
|
324
|
+
[family,literalHostModule(['eliscript/runtime/core/'+family,'eliscript/runtime/core/'+family+'.mjs'])]);
|
|
325
|
+
if(!literalHostProvider||provider!==literalHostProviderIdentity||vector!==literalVectorIdentity||reduced!==literalReducedIdentity||record!==literalRecordIdentity||metadata!==literalMetadataIdentity||type!==literalTypeIdentity||protocol!==literalProtocolIdentity||regex!==literalRegexIdentity||sorted!==literalSortedIdentity||protocolNamespaceEntries.some((entry,index)=>entry[1]!==literalProtocolNamespaceIdentities[index])){
|
|
326
|
+
const modules={
|
|
327
|
+
...(vector?{readPersistentVectorView:vector.readPersistentVectorView,subvec:vector.subvec}:{}),
|
|
328
|
+
...(reduced?{isReducedValue:reduced.isReducedValue,reducedValue:reduced.reducedValue,unreducedValue:reduced.unreducedValue}:{}),
|
|
329
|
+
...(record?{isRecordType:record.isRecordType,isRecord:record.isRecord,readRecordState:record.readRecordState,materializeRecordType:record.materializeRecordType}:{}),
|
|
330
|
+
...(metadata?{meta:metadata.meta,withMeta:metadata.withMeta}:{}),
|
|
331
|
+
...(type?{materializeTypeDefinition:type.materializeTypeDefinition,materializeTypeValue:type.materializeTypeValue,reifyProtocols:type.reifyProtocols,
|
|
332
|
+
readTypeState:type.readTypeState,readTypeValueState:type.readTypeValueState,readReifiedState:type.readReifiedState}:{}),
|
|
333
|
+
...(protocol?{isProtocol:protocol.isProtocol,protocolDefinition:protocol.protocolDefinition,
|
|
334
|
+
materializeProtocolFromDefinition:protocol.materializeProtocolFromDefinition,extendProtocolDefault:protocol.extendProtocolDefault,
|
|
335
|
+
readProtocolOperationsOwner:protocol.readProtocolOperationsOwner,readProtocolMethodOwner:protocol.readProtocolMethodOwner}:{}),
|
|
336
|
+
...(regex?{readRegexState:regex.readRegexState,compileRegex:regex.compileRegex}:{}),
|
|
337
|
+
...(sorted?{readSortedMapState:sorted.readSortedMapState,readSortedSetState:sorted.readSortedSetState,
|
|
338
|
+
materializeSortedMap:sorted.materializeSortedMap,materializeSortedSet:sorted.materializeSortedSet,
|
|
339
|
+
isDefaultSortedComparator:sorted.isDefaultSortedComparator,defaultSortedComparator:sorted.defaultSortedComparator}:{}),
|
|
340
|
+
protocolNamespaces:{...provider?.protocolNamespaces,...Object.fromEntries(protocolNamespaceEntries.filter(entry=>entry[1]!==undefined))},
|
|
341
|
+
};
|
|
342
|
+
literalHostProvider=createManagedLiteralHostProvider(provider,modules);
|
|
343
|
+
literalHostProviderIdentity=provider;
|
|
344
|
+
literalVectorIdentity=vector;literalReducedIdentity=reduced;
|
|
345
|
+
literalRecordIdentity=record;literalMetadataIdentity=metadata;
|
|
346
|
+
literalTypeIdentity=type;
|
|
347
|
+
literalProtocolIdentity=protocol;
|
|
348
|
+
literalRegexIdentity=regex;
|
|
349
|
+
literalSortedIdentity=sorted;
|
|
350
|
+
literalProtocolNamespaceIdentities=protocolNamespaceEntries.map(entry=>entry[1]);
|
|
351
|
+
}
|
|
352
|
+
return literalHostProvider;
|
|
353
|
+
}
|
|
354
|
+
function reserveForeignBuffer(count){
|
|
355
|
+
if(count<=foreignBufferCapacity)return;
|
|
356
|
+
if(foreignBuffer){if(count>maxSlots)call('heap-collect',heap);pruneForeignValues();count=foreignEntries.size+1;if(count<=foreignBufferCapacity)return;}
|
|
357
|
+
if(count>maxSlots)failManagedRuntime(2);
|
|
358
|
+
const capacity=Math.min(maxSlots,Math.max(count,16,foreignBufferCapacity*2));
|
|
359
|
+
if(foreignBuffer)call('value-bytes-resize',heap,id(foreignBuffer),word(capacity*4));
|
|
360
|
+
else foreignBuffer=wrap(call('value-bytes',heap,word(capacity*4)));
|
|
361
|
+
foreignBufferCapacity=capacity;
|
|
362
|
+
}
|
|
363
|
+
function pruneForeignValues(){
|
|
364
|
+
if(!capabilityOpen||foreignEntries.size===0||!foreignBuffer)return;
|
|
365
|
+
call('value-foreign-live-tokens-into',heap,id(foreignBuffer));
|
|
366
|
+
const bytes=api.readBytes(foreignBuffer),buffer=new DataView(bytes.buffer,bytes.byteOffset,bytes.byteLength),live=new Set();
|
|
367
|
+
for(let index=0;index<bytes.byteLength;index+=4)live.add(buffer.getUint32(index,true));
|
|
368
|
+
for(const token of foreignEntries.keys())if(!live.has(token))foreignEntries.delete(token);
|
|
369
|
+
}
|
|
370
|
+
const projectSteps=new Set(descriptor?.project?.modules?.flatMap(module=>module.steps.map(step=>step.run))??[]);
|
|
371
|
+
const projectTransport=descriptor?.project?Object.freeze({
|
|
372
|
+
prepare(){
|
|
373
|
+
const name=descriptor.project.prepare;
|
|
374
|
+
if(typeof name!=='string'||typeof e[name]!=='function'||e[name].length!==1)failManagedRuntime(3);
|
|
375
|
+
return withCollectionBoundary(()=>withCallBoundary(()=>{call(name,heap);return true;}));
|
|
376
|
+
},
|
|
377
|
+
run(name){
|
|
378
|
+
if(!projectSteps.has(name)||typeof e[name]!=='function'||e[name].length!==1)failManagedRuntime(3);
|
|
379
|
+
return withCollectionBoundary(()=>withCallBoundary(()=>{call(name,heap);return true;}));
|
|
380
|
+
},
|
|
381
|
+
get(kind,index){
|
|
382
|
+
if(!moduleInfo||(kind!==0&&kind!==1))failManagedRuntime(3);
|
|
383
|
+
return withHostValues(({decode})=>decode(call(moduleInfo.get,heap,kind,word(index))));
|
|
384
|
+
},
|
|
385
|
+
bindHoisted(kind,index,value){
|
|
386
|
+
if(!moduleInfo||kind!==1||typeof value!=='function')failManagedRuntime(3);
|
|
387
|
+
return withHostValues(({decode})=>decode(call(moduleInfo.get,heap,kind,word(index))));
|
|
388
|
+
},
|
|
389
|
+
invoke(kind,index,receiver,args,newTarget){
|
|
390
|
+
if(!moduleInfo||(kind!==0&&kind!==1)||!Array.isArray(args))failManagedRuntime(3);
|
|
391
|
+
return withHostValues(({encode,decode,argv,hold})=>{
|
|
392
|
+
const raw=call(moduleInfo.get,heap,kind,word(index));hold(raw);
|
|
393
|
+
const values=argv(args.map(value=>encode(value)));
|
|
394
|
+
return decode(newTarget===undefined?
|
|
395
|
+
objectCall('value-source-invoke-with-this',raw,encode(receiver),values,args.length):
|
|
396
|
+
objectCall('value-source-construct-target',raw,values,args.length,encode(newTarget)));
|
|
397
|
+
});
|
|
398
|
+
},
|
|
399
|
+
}):undefined;
|
|
400
|
+
const api=Object.freeze({
|
|
401
|
+
unicodeVersion:caseVersion===151?15.1:caseVersion/10,
|
|
402
|
+
project:projectTransport,
|
|
403
|
+
initializeModule:initializeModuleInstance,
|
|
404
|
+
getExport(name){if(!moduleInfo||typeof name!=='string'||!moduleExports.has(name))failManagedRuntime(3);const item=moduleExports.get(name);return wrap(call(moduleInfo.get,heap,item.kind,item.index));},
|
|
405
|
+
closeModule(){if(!moduleInfo&&typeof e['value-standard-prototypes-close']!=='function')failManagedRuntime(3);lifecycle.dispose();return moduleInfo!==null;},
|
|
406
|
+
invoke(name,args=[]) {
|
|
407
|
+
const output=withCollectionBoundary(()=>withCallBoundary(()=>{
|
|
408
|
+
if(typeof name!=='string'||!entries.has(name)||!Array.isArray(args))failManagedRuntime(3);
|
|
409
|
+
const entry=entries.get(name);if(!entry.uniform&&args.length!==entry.arity)failManagedRuntime(3);
|
|
410
|
+
const borrowed=[];let entered=false,target=0,argumentsList=0,callee=0,failed=false,result;
|
|
411
|
+
try {
|
|
412
|
+
if(entry.binding){
|
|
413
|
+
// Resolve and borrow the live callee before argument getters can replace it.
|
|
414
|
+
const item=moduleExports.get(name);callee=call(moduleInfo.get,heap,item.kind,item.index);call('heap-pin',heap,callee);borrowed.push(callee);
|
|
415
|
+
}
|
|
416
|
+
const values=Array.from(args,value=>{const v=id(value);call('heap-pin',heap,v);borrowed.push(v);return v;});
|
|
417
|
+
target=call('frame-current',heap);entered=true;
|
|
418
|
+
if(entry.uniform){
|
|
419
|
+
const allocated=call('value-refs',heap,7,word(values.length));call('heap-pin',heap,allocated);argumentsList=allocated;
|
|
420
|
+
const offset=call('value-data',heap,argumentsList,7),targetView=view();
|
|
421
|
+
values.forEach((v,i)=>targetView.setUint32(offset+i*4,v,true));
|
|
422
|
+
return result=wrap(call(entry.wireName,heap,entry.binding?callee:0,argumentsList,values.length));
|
|
423
|
+
}
|
|
424
|
+
return result=wrap(call(entry.wireName,heap,...values));
|
|
425
|
+
} catch(error){
|
|
426
|
+
failed=true;
|
|
427
|
+
// Cleanup must neither replace a source throw (including primitives) nor
|
|
428
|
+
// prevent later roots from being returned when one cleanup action fails.
|
|
429
|
+
if(entered)try{call('frame-unwind',heap,target);}catch{}
|
|
430
|
+
if(typeof e['value-exception-clear']==='function')try{call('value-exception-clear',heap);}catch{}
|
|
431
|
+
throw error;
|
|
432
|
+
} finally{
|
|
433
|
+
let cleanupFailed=false,cleanupError;
|
|
434
|
+
if(argumentsList)try{call('heap-release',heap,argumentsList);}catch(error){cleanupFailed=true;cleanupError=error;}
|
|
435
|
+
for(const value of borrowed)try{call('heap-release',heap,value);}catch(error){if(!cleanupFailed){cleanupFailed=true;cleanupError=error;}}
|
|
436
|
+
if(!failed&&cleanupFailed){
|
|
437
|
+
// A successful result has not crossed the host boundary if cleanup fails.
|
|
438
|
+
// Return its newly acquired root as well, preserving the cleanup error.
|
|
439
|
+
try{api.release(result);}catch{}
|
|
440
|
+
throw cleanupError;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}));
|
|
444
|
+
pruneForeignValues();return output;
|
|
445
|
+
},
|
|
446
|
+
promiseState(value) {return call('value-promise-state',heap,id(value));},
|
|
447
|
+
promiseResult(value) {return wrap(call('value-promise-result',heap,id(value)));},
|
|
448
|
+
drainJobs(limit=1024) {
|
|
449
|
+
if(typeof e['value-async-drain']!=='function')failManagedRuntime(3);
|
|
450
|
+
try{return withCollectionBoundary(()=>objectCall('value-async-drain',word(limit)));}
|
|
451
|
+
catch(error){
|
|
452
|
+
if(typeof e['value-async-reset']==='function')try{e['value-async-reset'](heap);}catch{}
|
|
453
|
+
throw error;
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
async invokeAsync(name,args=[],{signal,jobLimit=1024}={}) {
|
|
457
|
+
if(signal?.aborted)throw signal.reason??new DOMException('The operation was aborted','AbortError');
|
|
458
|
+
word(jobLimit);if(jobLimit===0)failManagedRuntime(3);
|
|
459
|
+
const promise=api.invoke(name,args);
|
|
460
|
+
if(promise?.kind!==26)return promise;
|
|
461
|
+
let failed=false;
|
|
462
|
+
try {
|
|
463
|
+
for(;;){
|
|
464
|
+
if(signal?.aborted)throw signal.reason??new DOMException('The operation was aborted','AbortError');
|
|
465
|
+
const state=api.promiseState(promise);
|
|
466
|
+
if(state===1)return api.promiseResult(promise);
|
|
467
|
+
if(state===2)throw api.promiseResult(promise);
|
|
468
|
+
if(state!==0)failManagedRuntime(3);
|
|
469
|
+
api.drainJobs(jobLimit);
|
|
470
|
+
if(api.promiseState(promise)===0)await yieldManagedJobs(signal);
|
|
471
|
+
}
|
|
472
|
+
} catch(error){failed=true;throw error;}
|
|
473
|
+
finally {try{api.release(promise);}catch(error){if(!failed)throw error;}}
|
|
474
|
+
},
|
|
475
|
+
number(input) {
|
|
476
|
+
if(typeof input!=='number')failManagedRuntime(3);const bits=new DataView(new ArrayBuffer(8));bits.setFloat64(0,input,true);
|
|
477
|
+
return wrap(call('value-number',heap,bits.getUint32(0,true),bits.getUint32(4,true)));
|
|
478
|
+
},
|
|
479
|
+
readNumber(value) {return view().getFloat64(data(value,4).offset,true);},
|
|
480
|
+
bigint(input) {
|
|
481
|
+
if(typeof input!=='bigint')failManagedRuntime(3);
|
|
482
|
+
const text=api.string(String(input));
|
|
483
|
+
try{return wrap(objectCall('value-bigint-parse',id(text)));}finally{api.release(text);}
|
|
484
|
+
},
|
|
485
|
+
readBigInt(value) {
|
|
486
|
+
const text=wrap(objectCall('value-bigint-to-string',id(value),10));
|
|
487
|
+
try{return BigInt(api.readString(text));}finally{api.release(text);}
|
|
488
|
+
},
|
|
489
|
+
binary(a,b,operation) {return wrap(call('value-number-binary',heap,id(a),id(b),word(operation,3)));},
|
|
490
|
+
negate(value) {return wrap(call('value-number-negate',heap,id(value)));},
|
|
491
|
+
compare(a,b,operation) {return !!call('value-number-compare',heap,id(a),id(b),word(operation,5));},
|
|
492
|
+
truth(value) {return !!call('value-truth',heap,id(value));},
|
|
493
|
+
keyEqual(left,right) {return !!call('value-key-equal',heap,id(left),id(right));},
|
|
494
|
+
keyHash(value) {return call('value-key-hash',heap,id(value));},
|
|
495
|
+
map(capacity=4) {return wrap(call('value-table-new',heap,10,word(capacity)));},
|
|
496
|
+
setTable(capacity=4) {return wrap(call('value-table-new',heap,11,word(capacity)));},
|
|
497
|
+
tableSize(table) {return call('value-table-size',heap,id(table));},
|
|
498
|
+
tableHas(table,key) {return !!call('value-table-has',heap,id(table),id(key));},
|
|
499
|
+
tableGet(table,key) {return wrap(call('value-table-get',heap,id(table),id(key)));},
|
|
500
|
+
tableSet(table,key,value) {call('value-table-put',heap,id(table),id(key),id(value));return table;},
|
|
501
|
+
tableAdd(table,key) {call('value-table-add',heap,id(table),id(key));return table;},
|
|
502
|
+
tableDelete(table,key) {return !!call('value-table-delete',heap,id(table),id(key));},
|
|
503
|
+
tableClear(table) {call('value-table-clear',heap,id(table));},
|
|
504
|
+
tableIterator(table) {return wrap(call('value-table-iterator',heap,id(table)));},
|
|
505
|
+
iteratorNext(iterator) {
|
|
506
|
+
const it=id(iterator);if(!call('value-iterator-next',heap,it))return Object.freeze({done:true});
|
|
507
|
+
const key=wrap(call('value-iterator-key',heap,it));
|
|
508
|
+
try {return Object.freeze({done:false,key,value:wrap(call('value-iterator-value',heap,it))});}
|
|
509
|
+
catch(error){if(key!==null&&typeof key==='object'){const entry=handles.get(key);call('heap-release',heap,entry.id);entry.roots--;}throw error;}
|
|
510
|
+
},
|
|
511
|
+
closeIterator(iterator) {call('value-iterator-close',heap,id(iterator));},
|
|
512
|
+
string(input) {
|
|
513
|
+
if(typeof input!=='string')failManagedRuntime(3);
|
|
514
|
+
const length=word(input.length),bytes=new Uint8Array(length*2),units=new DataView(bytes.buffer);
|
|
515
|
+
for(let i=0;i<length;i++)units.setUint16(i*2,input.charCodeAt(i),true);
|
|
516
|
+
const value=call('value-string',heap,length),offset=call('value-data',heap,value,5);
|
|
517
|
+
memory.writeBytes(offset,bytes);
|
|
518
|
+
call('value-seal',heap,value);return wrap(value);
|
|
519
|
+
},
|
|
520
|
+
readString(value) {
|
|
521
|
+
const {length,offset}=data(value,5),bytes=memory.readBytes(offset,length*2);
|
|
522
|
+
const source=new DataView(bytes.buffer,bytes.byteOffset,bytes.byteLength),parts=[];
|
|
523
|
+
for(let start=0;start<length;start+=8192) {const units=[];for(let i=start;i<Math.min(start+8192,length);i++)units.push(source.getUint16(i*2,true));parts.push(String.fromCharCode(...units));}
|
|
524
|
+
return parts.join('');
|
|
525
|
+
},
|
|
526
|
+
concatStrings(left,right) {return wrap(call('value-string-concat',heap,id(left),id(right)));},
|
|
527
|
+
sliceString(value,start,end) {const v=id(value);return wrap(call('value-string-slice',heap,v,word(start),end===undefined?call('value-length',heap,v):word(end)));},
|
|
528
|
+
compareStrings(left,right) {const result=call('value-string-compare',heap,id(left),id(right));return result===0?0:result===1?-1:1;},
|
|
529
|
+
findString(value,needle,start=0) {const result=call('value-string-find',heap,id(value),id(needle),word(start));return result===0xffffffff?-1:result;},
|
|
530
|
+
codePoint(value,index) {return call('value-string-code-point',heap,id(value),word(index));},
|
|
531
|
+
encodeUtf8(value,{strict=false}={}) {return wrap(call('value-utf8-encode',heap,id(value),flag(strict)));},
|
|
532
|
+
decodeUtf8(value,{strict=false,preserveBOM=false}={}) {return wrap(call('value-utf8-decode',heap,id(value),flag(strict),flag(preserveBOM)));},
|
|
533
|
+
bytes(input) {
|
|
534
|
+
if(!Array.isArray(input)&&!(input instanceof Uint8Array))failManagedRuntime(3);
|
|
535
|
+
const values=Array.from(input,x=>word(x,255)),value=call('value-bytes',heap,word(values.length)),offset=call('value-data',heap,value,6);
|
|
536
|
+
memory.writeBytes(offset,Uint8Array.from(values));return wrap(value);
|
|
537
|
+
},
|
|
538
|
+
readBytes(value) {const {length,offset}=data(value,6);return memory.readBytes(offset,length);},
|
|
539
|
+
array(input=[]) {return refs(input,7);},sourceArray(input=[]) {return refs(input,14);},record(input=[]) {return refs(input,8);},
|
|
540
|
+
sourceObject,
|
|
541
|
+
toHostValue(value){return withHostValues(({decode})=>decode(id(value)));},
|
|
542
|
+
fromHostValue(value){return withHostValues(({encode})=>wrap(encode(value)));},
|
|
543
|
+
objectGet(value,key) {return wrap(objectCall('value-object-get',id(value),id(key)));},
|
|
544
|
+
errorStackAvailable(value,key) {
|
|
545
|
+
// Older artifacts retain their ordinary property-read behavior.
|
|
546
|
+
if(typeof e['value-error-stack-available']!=='function')return true;
|
|
547
|
+
return !!objectCall('value-error-stack-available',id(value),id(key));
|
|
548
|
+
},
|
|
549
|
+
objectHas(value,key) {return !!objectCall('value-object-has',id(value),id(key));},
|
|
550
|
+
objectSet(value,key,child) {objectCall('value-object-put',id(value),id(key),id(child),0);return value;},
|
|
551
|
+
objectKeys(value) {return wrap(objectCall('value-object-keys',id(value)));},
|
|
552
|
+
objectCopy(value) {return wrap(objectCall('value-object-copy',id(value)));},
|
|
553
|
+
get(value,index) {return wrap(call('value-get',heap,id(value),word(index)));},
|
|
554
|
+
set(value,index,child) {call('value-set',heap,id(value),word(index),id(child));},
|
|
555
|
+
length(value) {return call('value-length',heap,id(value));},
|
|
556
|
+
resize(value,length) {const v=id(value),kind=call('value-kind',heap,v);if(kind!==6&&kind!==7&&kind!==14)failManagedRuntime(1);
|
|
557
|
+
call(kind===6?'value-bytes-resize':kind===14?'value-array-resize':'value-refs-resize',heap,v,word(length));},
|
|
558
|
+
pin(value) {const v=id(value);call('heap-pin',heap,v);if(v>3)handles.get(value).roots++;},
|
|
559
|
+
release(value) {
|
|
560
|
+
if(value===null||typeof value==='boolean'||value===undefined)return;
|
|
561
|
+
const entry=handles.get(value);if(!entry)failManagedRuntime(1);if(!entry.roots)failManagedRuntime(3);
|
|
562
|
+
call('heap-release',heap,entry.id);entry.roots--;
|
|
563
|
+
},
|
|
564
|
+
auto(thresholdBytes) {call('heap-auto',heap,word(thresholdBytes));},
|
|
565
|
+
frame(count) {const value=call('frame-new',heap,word(count)),token=Object.freeze({frame:true});frames.set(token,{id:value});return token;},
|
|
566
|
+
frameSet(token,index,value) {call('frame-set',heap,frameId(token),word(index),id(value));},
|
|
567
|
+
frameGet(token,index) {return wrap(call('frame-get',heap,frameId(token),word(index)));},
|
|
568
|
+
leaveFrame(token) {call('frame-pop',heap,frameId(token));},
|
|
569
|
+
frameReturn(token,value) {return wrap(call('frame-return',heap,frameId(token),id(value)),true);},
|
|
570
|
+
unwindFrames(target=null) {call('frame-unwind',heap,target===null?0:frameId(target));},
|
|
571
|
+
collect() {const result=call('heap-collect',heap);pruneForeignValues();return result;},live() {return call('heap-live',heap);},
|
|
572
|
+
stats() {return Object.freeze({usedBytes:call('heap-used',heap),capacityBytes:call('heap-capacity',heap),liveValues:call('heap-live',heap),frameDepth:call('frame-depth',heap),collections:call('heap-collections',heap)});},
|
|
573
|
+
});
|
|
574
|
+
function withHostValues(operation,sourceErrors=false){
|
|
575
|
+
if(!capabilityOpen)throw new Error('managed host transport is closed');
|
|
576
|
+
let sourceThrow=false,thrownValue=0,thrownPinned=false,result;
|
|
577
|
+
try{result=withCollectionBoundary(()=>withCallBoundary(()=>{
|
|
578
|
+
const roots=[];let memo=new Map(),reverse=new Map();
|
|
579
|
+
const hold=raw=>{const token=wrap(raw);roots.push(token);return token;};
|
|
580
|
+
const readString=raw=>api.readString(hold(raw));
|
|
581
|
+
const kind=raw=>raw<=3?0:call('value-kind',heap,raw);
|
|
582
|
+
const field=(raw,key)=>{
|
|
583
|
+
const token=api.string(key);roots.push(token);return objectCall('value-object-get',raw,id(token));
|
|
584
|
+
};
|
|
585
|
+
const argv=values=>{
|
|
586
|
+
const raw=call('value-refs',heap,7,word(values.length));hold(raw);
|
|
587
|
+
values.forEach((value,index)=>call('value-set',heap,raw,index,value));return raw;
|
|
588
|
+
};
|
|
589
|
+
const reflect=(raw,operation,key)=>{
|
|
590
|
+
const list=argv(key===undefined?[raw]:[raw,key]);const result=objectCall('value-object-reflection',list,key===undefined?1:2,operation);
|
|
591
|
+
hold(result);return result;
|
|
592
|
+
};
|
|
593
|
+
const sourceThrown=error=>{
|
|
594
|
+
if(error===null||typeof error!=='object'||!handles.has(error))return error;
|
|
595
|
+
let value;
|
|
596
|
+
try{value=decode(id(error));}catch{return error;}
|
|
597
|
+
try{api.release(error);}catch{}
|
|
598
|
+
return value;
|
|
599
|
+
};
|
|
600
|
+
const using=operation=>{
|
|
601
|
+
if(!capabilityOpen)throw new Error('managed host value is closed');
|
|
602
|
+
const start=roots.length,previousMemo=memo,previousReverse=reverse;let failed=false;
|
|
603
|
+
memo=new Map();reverse=new Map();
|
|
604
|
+
try{return withCollectionBoundary(()=>withCallBoundary(operation));}catch(error){failed=true;throw sourceThrown(error);}
|
|
605
|
+
finally{
|
|
606
|
+
memo=previousMemo;reverse=previousReverse;
|
|
607
|
+
let cleanup;for(const token of roots.splice(start))if(!consoleRoots.has(token))try{api.release(token);}catch(error){cleanup??=error;}
|
|
608
|
+
if(!failed&&cleanup)throw cleanup;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
const nativeReflect=(operation,values)=>using(()=>{
|
|
612
|
+
const operands=argv(values.map(value=>encode(value)));
|
|
613
|
+
return decode(objectCall('value-host-reflection',operands,values.length,operation));
|
|
614
|
+
});
|
|
615
|
+
function literalOperation(name,arguments_){
|
|
616
|
+
if(!literalBindings)throw new TypeError('persistent values require the compiled literal runtime');
|
|
617
|
+
const binding=literalBindings[name],function_=call(moduleInfo.get,heap,binding.kind,binding.index);hold(function_);
|
|
618
|
+
const argumentsList=argv(arguments_);
|
|
619
|
+
const result=objectCall('value-source-invoke-with-this',function_,3,argumentsList,arguments_.length);hold(result);return result;
|
|
620
|
+
}
|
|
621
|
+
function encodeLiteral(value,type){
|
|
622
|
+
if(!literalBindings)throw new TypeError('persistent values require the compiled literal runtime');
|
|
623
|
+
const record=literalProvider().read(value);
|
|
624
|
+
if(record.kind!==type||(!['subvector','reduced','record-type','record','type-definition','reified','regex-pattern','sorted-map','sorted-default-comparator'].includes(type)&&!Array.isArray(record.values)))throw new TypeError('invalid literal host provider record');
|
|
625
|
+
const rawRecord=objectCall('value-object-new',3);hold(rawRecord);
|
|
626
|
+
const put=(key,child)=>objectCall('value-object-put',rawRecord,encode(key),child,2);
|
|
627
|
+
put('kind',encode(type));
|
|
628
|
+
if(type==='reduced')put('value',encode(record.value));
|
|
629
|
+
else if(type==='sorted-default-comparator'){}
|
|
630
|
+
else if(type==='sorted-map'){
|
|
631
|
+
if(!Array.isArray(record.entries))throw new TypeError('invalid sorted map boundary entries');
|
|
632
|
+
const entries=call('value-array-new',heap,record.entries.length);hold(entries);
|
|
633
|
+
for(let index=0;index<record.entries.length;index++){
|
|
634
|
+
const entry=record.entries[index];
|
|
635
|
+
if(!Array.isArray(entry)||entry.length!==2)throw new TypeError('invalid sorted map boundary entry');
|
|
636
|
+
call('value-set',heap,entries,index,encodeList(entry));
|
|
637
|
+
}
|
|
638
|
+
put('entries',entries);put('comparison',encode(record.comparison));
|
|
639
|
+
}else if(type==='sorted-set'){
|
|
640
|
+
put('values',encodeList(record.values));put('comparison',encode(record.comparison));
|
|
641
|
+
}
|
|
642
|
+
else if(type==='regex-pattern'){
|
|
643
|
+
put('source',encode(record.source));put('flags',encode(record.flags));
|
|
644
|
+
}
|
|
645
|
+
else if(type==='type-definition'){
|
|
646
|
+
put('name',encode(record.name));put('fields',encodeLiteralArray(record.fields));
|
|
647
|
+
put('protocolPlans',encodeLiteralProtocolPlans(record.protocolPlans));
|
|
648
|
+
}else if(type==='reified')put('protocolPlans',encodeLiteralProtocolPlans(record.protocolPlans));
|
|
649
|
+
else if(type==='type-value'){
|
|
650
|
+
put('type',encode(record.type));put('values',encodeLiteralArray(record.values));
|
|
651
|
+
}
|
|
652
|
+
else if(type==='record-type'){
|
|
653
|
+
put('name',encode(record.name));put('fields',encodeLiteralArray(record.fields));
|
|
654
|
+
}else if(type==='record'){
|
|
655
|
+
put('type',encode(record.type));put('map',encode(record.map));
|
|
656
|
+
}
|
|
657
|
+
else if(type==='subvector'){
|
|
658
|
+
put('source',encode(record.source));put('start',encode(record.start));put('end',encode(record.end));
|
|
659
|
+
}else if(type==='keyword'||type==='symbol'){
|
|
660
|
+
if(record.values.length!==2)throw new TypeError('invalid literal identifier record');
|
|
661
|
+
put('namespace',encode(record.values[0]));put('name',encode(record.values[1]));
|
|
662
|
+
}else{
|
|
663
|
+
let values=record.values;
|
|
664
|
+
if(type==='map'){
|
|
665
|
+
values=[];
|
|
666
|
+
for(const entry of record.values){if(!Array.isArray(entry)||entry.length!==2)throw new TypeError('invalid persistent map boundary entry');values.push(entry[0],entry[1]);}
|
|
667
|
+
}
|
|
668
|
+
put('values',encodeList(values));
|
|
669
|
+
}
|
|
670
|
+
put('metadata',encode(record.metadata??null));
|
|
671
|
+
const raw=literalOperation('literal-import-value',[rawRecord]),token=hold(raw);
|
|
672
|
+
if(kind(raw)!==(['record-type','type-definition','sorted-default-comparator'].includes(type)?18:13))throw new TypeError('compiled literal import did not return its persistent value kind');
|
|
673
|
+
memo.set(raw,value);reverse.set(value,raw);rememberSource(raw,value,token);
|
|
674
|
+
return raw;
|
|
675
|
+
}
|
|
676
|
+
function encodeLiteralArray(values){
|
|
677
|
+
if(!Array.isArray(values))throw new TypeError('invalid persistent declaration array');
|
|
678
|
+
if(reverse.has(values))return reverse.get(values);
|
|
679
|
+
if(sourceViews.has(values))return sourceViews.get(values);
|
|
680
|
+
const raw=call('value-array-new',heap,word(values.length)),token=hold(raw);
|
|
681
|
+
memo.set(raw,values);reverse.set(values,raw);
|
|
682
|
+
try{
|
|
683
|
+
for(let index=0;index<values.length;index++){
|
|
684
|
+
const descriptor=Reflect.getOwnPropertyDescriptor(values,String(index));
|
|
685
|
+
if(!descriptor?.enumerable||!Object.hasOwn(descriptor,'value'))throw new TypeError('persistent declaration arrays must contain dense data values');
|
|
686
|
+
call('value-set',heap,raw,index,encode(descriptor.value));
|
|
687
|
+
}
|
|
688
|
+
if(Object.isFrozen(values))objectCall('value-object-integrity',raw,0);
|
|
689
|
+
rememberSource(raw,values,token);return raw;
|
|
690
|
+
}catch(error){
|
|
691
|
+
memo.delete(raw);reverse.delete(values);throw error;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
function encodeLiteralProtocolPlans(plans){
|
|
695
|
+
if(!Array.isArray(plans))throw new TypeError('invalid type protocol plan snapshot');
|
|
696
|
+
const raw=call('value-array-new',heap,plans.length);hold(raw);
|
|
697
|
+
for(let index=0;index<plans.length;index++){
|
|
698
|
+
const plan=plans[index];
|
|
699
|
+
if(!Array.isArray(plan)||plan.length!==2||plan[1]===null||typeof plan[1]!=='object')throw new TypeError('invalid type protocol implementation snapshot');
|
|
700
|
+
const pair=call('value-array-new',heap,2);hold(pair);
|
|
701
|
+
const implementations=objectCall('value-object-new',0);hold(implementations);
|
|
702
|
+
for(const key of Reflect.ownKeys(plan[1])){
|
|
703
|
+
const entry=Reflect.getOwnPropertyDescriptor(plan[1],key);
|
|
704
|
+
if(typeof key!=='string'||!entry?.enumerable||!Object.hasOwn(entry,'value')||typeof entry.value!=='function')throw new TypeError('invalid type protocol method snapshot');
|
|
705
|
+
objectCall('value-object-put',implementations,encode(key),encode(entry.value),2);
|
|
706
|
+
}
|
|
707
|
+
objectCall('value-object-integrity',implementations,0);
|
|
708
|
+
call('value-set',heap,pair,0,encode(plan[0]));call('value-set',heap,pair,1,implementations);
|
|
709
|
+
objectCall('value-object-integrity',pair,0);
|
|
710
|
+
call('value-set',heap,raw,index,pair);
|
|
711
|
+
}
|
|
712
|
+
objectCall('value-object-integrity',raw,0);return raw;
|
|
713
|
+
}
|
|
714
|
+
function encode(value){
|
|
715
|
+
if(value===null)return 0;if(value===false)return 1;if(value===true)return 2;if(value===undefined)return 3;
|
|
716
|
+
if(reverse.has(value))return reverse.get(value);
|
|
717
|
+
if((typeof value==='object'||typeof value==='function')&&sourceViews.has(value))return sourceViews.get(value);
|
|
718
|
+
if(typeof value==='symbol'&&sourceSymbols.has(value))return sourceSymbols.get(value);
|
|
719
|
+
if(typeof value==='number'){const token=api.number(value);roots.push(token);return id(token);}
|
|
720
|
+
if(typeof value==='string'){const token=api.string(value);roots.push(token);return id(token);}
|
|
721
|
+
if(typeof value==='bigint'){const token=api.bigint(value);roots.push(token);return id(token);}
|
|
722
|
+
if(typeof value!=='object'&&typeof value!=='function'&&typeof value!=='symbol')throw new TypeError('host value has no managed representation');
|
|
723
|
+
const standardReference=literalBindings?literalProvider().standardProtocolReference?.(value):undefined;
|
|
724
|
+
if(standardReference!==undefined&&literalBindings['literal-protocol-for-role']){
|
|
725
|
+
const protocolRaw=literalOperation('literal-protocol-for-role',[encode(standardReference.role)]);hold(protocolRaw);
|
|
726
|
+
if(protocolRaw!==3){
|
|
727
|
+
decode(protocolRaw);
|
|
728
|
+
const bound=typeof value==='symbol'?sourceSymbols.get(value):reverse.get(value)??sourceViews.get(value);
|
|
729
|
+
if(bound===undefined)throw new TypeError('canonical protocol identity lookup did not bind the actual host member');
|
|
730
|
+
hold(bound);return bound;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
if(value!==null&&(typeof value==='object'||typeof value==='function')){
|
|
734
|
+
const literalKind=literalProvider().kind(value);
|
|
735
|
+
// A host-created protocol may contain mutable extension tables. Keep its
|
|
736
|
+
// actual foreign capability until it belongs to this target; a definition
|
|
737
|
+
// alone is not a faithful snapshot of those dispatch semantics.
|
|
738
|
+
if(literalKind!==null&&!['protocol','protocol-operations','protocol-method'].includes(literalKind))return encodeLiteral(value,literalKind);
|
|
739
|
+
}
|
|
740
|
+
let entry=typeof value==='symbol'?foreignSymbols.get(value):foreignObjects.get(value);
|
|
741
|
+
if(entry&&foreignEntries.has(entry.token)){
|
|
742
|
+
const type=e['value-kind'](heap,entry.raw)>>>0,error=e['last-error']()>>>0;
|
|
743
|
+
if(error===0&&(type===35||type===22)){hold(entry.raw);return entry.raw;}
|
|
744
|
+
}
|
|
745
|
+
if(nextForeignToken>0xffffffff)throw new RangeError('managed foreign reference identities exhausted');
|
|
746
|
+
const identity=nextForeignToken++;let raw;
|
|
747
|
+
if(typeof value==='symbol'){
|
|
748
|
+
const known=hostWellKnownSymbols.indexOf(value);
|
|
749
|
+
if(known>=0){const raw=call('value-symbol-well-known',heap,known);hold(raw);return raw;}
|
|
750
|
+
const registered=Symbol.keyFor(value);
|
|
751
|
+
if(registered!==undefined){const description=encode(registered),raw=objectCall('value-symbol-builtin',argv([description]),1,1);hold(raw);return raw;}
|
|
752
|
+
reserveForeignBuffer(foreignEntries.size+1);raw=objectCall('value-symbol-external',identity,encode(value.description));
|
|
753
|
+
}else{
|
|
754
|
+
reserveForeignBuffer(foreignEntries.size+1);
|
|
755
|
+
raw=objectCall('value-foreign-new',identity,typeof value==='function'?1:0);hold(raw);
|
|
756
|
+
if(typeof value==='function'){
|
|
757
|
+
let constructible=false;
|
|
758
|
+
try{Reflect.construct(new Proxy(value,{construct(){return {};}}),[]);constructible=true;}catch{}
|
|
759
|
+
objectCall('value-foreign-constructor-set',raw,constructible?1:0);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
hold(raw);entry={token:identity,raw,value};foreignEntries.set(identity,entry);
|
|
763
|
+
if(typeof value==='symbol')foreignSymbols.set(value,entry);else foreignObjects.set(value,entry);
|
|
764
|
+
return raw;
|
|
765
|
+
}
|
|
766
|
+
function encodeList(values){
|
|
767
|
+
const raw=call('value-array-new',heap,word(values.length));hold(raw);
|
|
768
|
+
for(let index=0;index<values.length;index++)call('value-set',heap,raw,index,encode(values[index]));
|
|
769
|
+
return raw;
|
|
770
|
+
}
|
|
771
|
+
function encodeDescriptor(value){
|
|
772
|
+
if(value===undefined)return 3;
|
|
773
|
+
const raw=objectCall('value-object-new',3);hold(raw);
|
|
774
|
+
for(const key of Reflect.ownKeys(value)){
|
|
775
|
+
const property=encode(key),child=encode(value[key]);
|
|
776
|
+
objectCall('value-object-put',raw,property,child,2);
|
|
777
|
+
}
|
|
778
|
+
return raw;
|
|
779
|
+
}
|
|
780
|
+
function propertyDescriptor(raw,key){
|
|
781
|
+
const description=objectCall('value-source-own-descriptor',raw,key);hold(description);
|
|
782
|
+
if(description===3)return undefined;
|
|
783
|
+
const item={enumerable:field(description,'enumerable')===2,configurable:field(description,'configurable')===2};
|
|
784
|
+
const valueKey=api.string('value');roots.push(valueKey);
|
|
785
|
+
if(objectCall('value-object-has',description,id(valueKey))){item.value=decode(field(description,'value'));item.writable=field(description,'writable')===2;}
|
|
786
|
+
else{const getter=field(description,'get'),setter=field(description,'set');item.get=getter===3?undefined:decode(getter);item.set=setter===3?undefined:decode(setter);}
|
|
787
|
+
return item;
|
|
788
|
+
}
|
|
789
|
+
function copyProperties(raw,target){
|
|
790
|
+
const names=reflect(raw,1),symbols=call('value-object-symbols',heap,raw);hold(symbols);
|
|
791
|
+
for(const keys of[names,symbols]){
|
|
792
|
+
const count=call('value-length',heap,keys);
|
|
793
|
+
for(let index=0;index<count;index++){
|
|
794
|
+
const key=call('value-get',heap,keys,index);hold(key);
|
|
795
|
+
const property=decode(key),item=propertyDescriptor(raw,key);
|
|
796
|
+
if(item===undefined)continue;
|
|
797
|
+
Object.defineProperty(target,property,item);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function pendingPromise(raw){
|
|
802
|
+
let timer,finished=false,created,promise;
|
|
803
|
+
const continuations=new WeakMap();
|
|
804
|
+
promise=new Promise((resolve,reject)=>{created={resolve,reject};});
|
|
805
|
+
continuations.set(promise,created);created=undefined;
|
|
806
|
+
const reference=managedWeakReference(promise);
|
|
807
|
+
const pending={close(){
|
|
808
|
+
if(finished)return;
|
|
809
|
+
finished=true;clearTimeout(timer);hostPromiseJobs.delete(pending);
|
|
810
|
+
const target=reference.deref(),continuation=target===undefined?undefined:continuations.get(target);
|
|
811
|
+
if(continuation)continuation.reject(new Error('managed host promise is closed'));
|
|
812
|
+
}};
|
|
813
|
+
const advance=()=>{
|
|
814
|
+
if(finished)return;
|
|
815
|
+
const target=reference.deref(),continuation=target===undefined?undefined:continuations.get(target);
|
|
816
|
+
if(!continuation){finished=true;hostPromiseJobs.delete(pending);return;}
|
|
817
|
+
try{
|
|
818
|
+
if(!capabilityOpen){pending.close();return;}
|
|
819
|
+
api.drainJobs(options.jobLimit??1024);
|
|
820
|
+
const status=call('value-promise-state',heap,raw);
|
|
821
|
+
if(status===0){timer=setTimeout(advance,0);return;}
|
|
822
|
+
if(status!==1&&status!==2)throw new TypeError('invalid managed promise state');
|
|
823
|
+
const value=using(()=>decode(call('value-promise-result',heap,raw)));
|
|
824
|
+
finished=true;hostPromiseJobs.delete(pending);
|
|
825
|
+
if(status===1)continuation.resolve(value);else continuation.reject(value);
|
|
826
|
+
}catch(error){finished=true;hostPromiseJobs.delete(pending);continuation.reject(sourceThrown(error));}
|
|
827
|
+
};
|
|
828
|
+
hostPromiseJobs.add(pending);promise.catch(()=>{});queueMicrotask(advance);
|
|
829
|
+
return promise;
|
|
830
|
+
}
|
|
831
|
+
function attachCollection(raw,result,type){
|
|
832
|
+
const valueReference=managedWeakReference(result);
|
|
833
|
+
const weak=value=>(typeof WeakRef==='function'&&((typeof value==='object'&&value!==null)||typeof value==='function'))?{reference:new WeakRef(value)}:{value};
|
|
834
|
+
const unweak=item=>item.reference?item.reference.deref():item.value;
|
|
835
|
+
let baseline=[],busy=false;
|
|
836
|
+
const readHost=target=>{
|
|
837
|
+
const iterator=Reflect.apply(hostCollectionIntrinsics[type===15?5:16],target,[]),items=[];
|
|
838
|
+
for(const item of iterator)items.push(type===15?item:[item,item]);
|
|
839
|
+
return items;
|
|
840
|
+
};
|
|
841
|
+
const same=(left,right)=>left.length===right.length&&left.every((entry,index)=>
|
|
842
|
+
Object.is(entry[0],unweak(right[index][0]))&&Object.is(entry[1],unweak(right[index][1])));
|
|
843
|
+
const remember=items=>{baseline=items.map(([key,value])=>[weak(key),weak(value)]);};
|
|
844
|
+
const readSource=()=>{
|
|
845
|
+
const table=view().getUint32(call('value-data',heap,raw,type),true),items=[];
|
|
846
|
+
const iterator=call('value-table-iterator',heap,table);hold(iterator);
|
|
847
|
+
try{
|
|
848
|
+
while(call('value-iterator-next',heap,iterator)){
|
|
849
|
+
const key=decode(call('value-iterator-key',heap,iterator));
|
|
850
|
+
items.push([key,type===15?decode(call('value-iterator-value',heap,iterator)):key]);
|
|
851
|
+
}
|
|
852
|
+
}finally{call('value-iterator-close',heap,iterator);}
|
|
853
|
+
return {table,items};
|
|
854
|
+
};
|
|
855
|
+
// Retain the longest ordered prefix already present. Delete/reinsert only
|
|
856
|
+
// the suffix that actually moved, so live table iterators retain tickets.
|
|
857
|
+
const retainedPrefix=(current,desired)=>{
|
|
858
|
+
let cursor=0,prefix=0;
|
|
859
|
+
for(const entry of desired){
|
|
860
|
+
let found=-1;
|
|
861
|
+
for(let index=cursor;index<current.length;index++)if(Object.is(current[index][0],entry[0])){found=index;break;}
|
|
862
|
+
if(found<0)break;cursor=found+1;prefix++;
|
|
863
|
+
}
|
|
864
|
+
return prefix;
|
|
865
|
+
};
|
|
866
|
+
const importHost=(target,host)=>{
|
|
867
|
+
const {table,items}=readSource(),prefix=retainedPrefix(items,host),kept=new Set(host.slice(0,prefix).map(item=>item[0]));
|
|
868
|
+
for(const [key]of items)if(!kept.has(key))call('value-table-delete',heap,table,encode(key));
|
|
869
|
+
for(const [key,value]of host){
|
|
870
|
+
if(type===15)call('value-table-put',heap,table,encode(key),encode(value));
|
|
871
|
+
else call('value-table-add',heap,table,encode(key));
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
const exportSource=(target)=>{
|
|
875
|
+
const {items}=readSource(),current=readHost(target),prefix=retainedPrefix(current,items),kept=new Set(items.slice(0,prefix).map(item=>item[0]));
|
|
876
|
+
const remove=hostCollectionIntrinsics[type===15?3:12],insert=hostCollectionIntrinsics[type===15?1:10];
|
|
877
|
+
for(const [key]of current)if(!kept.has(key))Reflect.apply(remove,target,[key]);
|
|
878
|
+
for(const [key,value]of items)Reflect.apply(insert,target,type===15?[key,value]:[key]);
|
|
879
|
+
remember(items);
|
|
880
|
+
};
|
|
881
|
+
const synchronizeCollection=()=>{
|
|
882
|
+
const target=valueReference.deref();if(target===undefined||busy)return;
|
|
883
|
+
busy=true;
|
|
884
|
+
try{return using(()=>{
|
|
885
|
+
const host=readHost(target);
|
|
886
|
+
if(!same(host,baseline))importHost(target,host);
|
|
887
|
+
exportSource(target);
|
|
888
|
+
});}finally{busy=false;}
|
|
889
|
+
};
|
|
890
|
+
const entry=sourceCache.get(raw);
|
|
891
|
+
entry.synchronize=synchronizeCollection;
|
|
892
|
+
entry.refresh=synchronizeCollection;
|
|
893
|
+
busy=true;
|
|
894
|
+
try{exportSource(result);}finally{busy=false;}
|
|
895
|
+
}
|
|
896
|
+
let bindingStandardProtocols=false;
|
|
897
|
+
function decodeLiteralProtocol(raw,record,token){
|
|
898
|
+
const role=decode(field(record,'role'));
|
|
899
|
+
const standard=role===undefined?undefined:literalProvider().standardProtocol?.(role);
|
|
900
|
+
if(role!==undefined&&standard===undefined)throw new TypeError('literal host provider cannot bind the canonical protocol role');
|
|
901
|
+
const definitionRaw=field(record,'definition');hold(definitionRaw);
|
|
902
|
+
const namesRaw=field(definitionRaw,'operations');hold(namesRaw);
|
|
903
|
+
const operationsRaw=field(record,'operations');hold(operationsRaw);
|
|
904
|
+
if(kind(namesRaw)!==14||kind(operationsRaw)!==13)throw new TypeError('compiled protocol has an invalid definition');
|
|
905
|
+
const names=[],methods=[],slots=[],rawSlots=[],implementations=Object.create(null);
|
|
906
|
+
for(let index=0,count=call('value-length',heap,namesRaw);index<count;index++){
|
|
907
|
+
const name=decode(call('value-get',heap,namesRaw,index));
|
|
908
|
+
if(typeof name!=='string')throw new TypeError('compiled protocol has an invalid operation');
|
|
909
|
+
const method=field(operationsRaw,name);hold(method);
|
|
910
|
+
if(kind(method)!==18)throw new TypeError('compiled protocol has an invalid dispatch function');
|
|
911
|
+
const slot=field(method,'slot');hold(slot);
|
|
912
|
+
if(kind(slot)!==22)throw new TypeError('compiled protocol has an invalid slot');
|
|
913
|
+
names.push(name);methods.push(method);rawSlots.push(slot);
|
|
914
|
+
if(standard!==undefined){
|
|
915
|
+
if(!Object.hasOwn(standard.operations,name))throw new TypeError('canonical protocol operation contract mismatch');
|
|
916
|
+
const symbol=standard.operations[name].slot;
|
|
917
|
+
const previous=memo.get(slot)??sourceCache.get(slot)?.reference.deref();
|
|
918
|
+
if(previous!==undefined&&previous!==symbol)throw new TypeError('canonical protocol slot was already decoded with a different identity');
|
|
919
|
+
sourceSymbols.set(symbol,slot);reverse.set(symbol,slot);memo.set(slot,symbol);slots.push(symbol);
|
|
920
|
+
}else slots.push(decode(slot));
|
|
921
|
+
Object.defineProperty(implementations,name,{enumerable:true,value:(receiver,...arguments_)=>using(()=>{
|
|
922
|
+
const operands=argv([encode(receiver),...arguments_.map(value=>encode(value))]);
|
|
923
|
+
return decode(objectCall('value-source-invoke-with-this',method,3,operands,arguments_.length+1));
|
|
924
|
+
})});
|
|
925
|
+
}
|
|
926
|
+
const definition={format:decode(field(definitionRaw,'format')),version:decode(field(definitionRaw,'version')),
|
|
927
|
+
name:decode(field(definitionRaw,'name')),operations:names};
|
|
928
|
+
const protocol=literalProvider().create('protocol',undefined,null,{definition,slots,implementations,role});
|
|
929
|
+
memo.set(raw,protocol);reverse.set(protocol,raw);rememberSource(raw,protocol,token);
|
|
930
|
+
const operations=protocol.operations,operationsToken=hold(operationsRaw);
|
|
931
|
+
memo.set(operationsRaw,operations);reverse.set(operations,operationsRaw);rememberSource(operationsRaw,operations,operationsToken);
|
|
932
|
+
for(let index=0;index<names.length;index++){
|
|
933
|
+
const method=operations[names[index]],methodRaw=methods[index],methodToken=hold(methodRaw);
|
|
934
|
+
memo.set(methodRaw,method);reverse.set(method,methodRaw);rememberSource(methodRaw,method,methodToken);
|
|
935
|
+
const slotRaw=rawSlots[index];
|
|
936
|
+
sourceSymbols.set(method.slot,slotRaw);reverse.set(method.slot,slotRaw);memo.set(slotRaw,method.slot);
|
|
937
|
+
}
|
|
938
|
+
return protocol;
|
|
939
|
+
}
|
|
940
|
+
function decode(raw){
|
|
941
|
+
if(raw<=3)return[null,false,true,undefined][raw];
|
|
942
|
+
if(memo.has(raw))return memo.get(raw);
|
|
943
|
+
const token=hold(raw),type=kind(raw);
|
|
944
|
+
if(type===4)return api.readNumber(token);
|
|
945
|
+
if(type===5)return api.readString(token);
|
|
946
|
+
if(type===34)return api.readBigInt(token);
|
|
947
|
+
if(type===35){const identity=call('value-foreign-token',heap,raw),entry=foreignEntries.get(identity);if(!entry)throw new ReferenceError('managed host reference has been released');return entry.value;}
|
|
948
|
+
const cachedEntry=sourceCache.get(raw),cached=cachedEntry?.reference.deref();
|
|
949
|
+
if(cached!==undefined){
|
|
950
|
+
memo.set(raw,cached);reverse.set(cached,raw);
|
|
951
|
+
if(cachedEntry.refresh&&!cachedEntry.refreshing){cachedEntry.refreshing=true;try{cachedEntry.refresh();}finally{cachedEntry.refreshing=false;}}
|
|
952
|
+
return cached;
|
|
953
|
+
}
|
|
954
|
+
if(type===22){
|
|
955
|
+
for(const [symbol,bound]of sourceSymbols)if(bound===raw){memo.set(raw,symbol);reverse.set(symbol,raw);return symbol;}
|
|
956
|
+
// A slot can precede its owner in an output graph. Query only actual
|
|
957
|
+
// already-registered target roles before creating any local Symbol.
|
|
958
|
+
if(!bindingStandardProtocols&&literalBindings?.['literal-protocol-for-role']){
|
|
959
|
+
bindingStandardProtocols=true;
|
|
960
|
+
try{
|
|
961
|
+
for(const role of literalProvider().standardProtocolRoles?.()??[]){
|
|
962
|
+
const protocol=literalOperation('literal-protocol-for-role',[encode(role)]);hold(protocol);
|
|
963
|
+
if(protocol!==3)decode(protocol);
|
|
964
|
+
if(memo.has(raw))return memo.get(raw);
|
|
965
|
+
}
|
|
966
|
+
}finally{bindingStandardProtocols=false;}
|
|
967
|
+
}
|
|
968
|
+
const payload=call('value-data',heap,raw,22),p=view(),provenance=p.getUint32(payload-20,true),identifier=p.getUint32(payload-16,true),description=p.getUint32(payload,true);
|
|
969
|
+
const text=description===3?undefined:readString(description);
|
|
970
|
+
const external=provenance===3?foreignEntries.get(identifier):undefined;
|
|
971
|
+
if(provenance===3&&!external)throw new ReferenceError('managed host Symbol has been released');
|
|
972
|
+
const value=external?external.value:provenance===2?hostWellKnownSymbols[identifier]:provenance===1?Symbol.for(text):Symbol(text);
|
|
973
|
+
if(provenance===2&&value===undefined)throw new TypeError('unknown managed well-known Symbol');
|
|
974
|
+
memo.set(raw,value);reverse.set(value,raw);if(!sourceSymbols.has(value)){sourceSymbols.set(value,raw);consoleRoots.add(token);}return value;
|
|
975
|
+
}
|
|
976
|
+
if((type===13||type===18)&&literalBindings){
|
|
977
|
+
const brand=literalOperation('literal-kind',[raw]);
|
|
978
|
+
if(brand!==0){
|
|
979
|
+
const type=readString(brand),record=literalOperation('literal-export-value',[raw]);
|
|
980
|
+
if(record===0)throw new TypeError('compiled persistent value lost its literal brand');
|
|
981
|
+
const declaredKind=readString(field(record,'kind'));
|
|
982
|
+
if(declaredKind!==type)throw new TypeError('compiled persistent literal kind mismatch');
|
|
983
|
+
if(type==='protocol')return decodeLiteralProtocol(raw,record,token);
|
|
984
|
+
if(type==='protocol-operations'||type==='protocol-method'){
|
|
985
|
+
const ownerRaw=field(record,'protocol');hold(ownerRaw);
|
|
986
|
+
const owner=decode(ownerRaw);
|
|
987
|
+
const result=type==='protocol-operations'?owner.operations:owner.operations[decode(field(record,'operation'))];
|
|
988
|
+
if(memo.get(raw)!==result)throw new TypeError('compiled protocol member does not belong to its declared owner');
|
|
989
|
+
return result;
|
|
990
|
+
}
|
|
991
|
+
let values,vectorView;
|
|
992
|
+
if(type==='reduced')values=decode(field(record,'value'));
|
|
993
|
+
else if(type==='sorted-default-comparator'){}
|
|
994
|
+
else if(type==='sorted-map'||type==='sorted-set'){
|
|
995
|
+
const array=field(record,type==='sorted-map'?'entries':'values');hold(array);
|
|
996
|
+
if(kind(array)!==14)throw new TypeError('compiled sorted value has no bulk data');
|
|
997
|
+
values=[];
|
|
998
|
+
for(let index=0,count=call('value-length',heap,array);index<count;index++)values.push(decode(call('value-get',heap,array,index)));
|
|
999
|
+
vectorView={comparison:decode(field(record,'comparison'))};
|
|
1000
|
+
}
|
|
1001
|
+
else if(type==='regex-pattern')vectorView={source:decode(field(record,'source')),flags:decode(field(record,'flags'))};
|
|
1002
|
+
else if(type==='type-definition'){
|
|
1003
|
+
const fields=field(record,'fields');hold(fields);
|
|
1004
|
+
if(kind(fields)!==14)throw new TypeError('compiled type declaration has no field list');
|
|
1005
|
+
vectorView={name:decode(field(record,'name')),fields:decode(fields),protocolPlans:decode(field(record,'protocolPlans'))};
|
|
1006
|
+
}else if(type==='reified')vectorView={protocolPlans:decode(field(record,'protocolPlans'))};
|
|
1007
|
+
else if(type==='type-value'){
|
|
1008
|
+
vectorView={type:decode(field(record,'type'))};
|
|
1009
|
+
const array=field(record,'values');hold(array);
|
|
1010
|
+
if(kind(array)!==14)throw new TypeError('compiled type value has no field list');
|
|
1011
|
+
values=decode(array);
|
|
1012
|
+
}
|
|
1013
|
+
else if(type==='record-type'){
|
|
1014
|
+
const fields=field(record,'fields');hold(fields);
|
|
1015
|
+
if(kind(fields)!==14)throw new TypeError('compiled record declaration has no field list');
|
|
1016
|
+
vectorView={name:decode(field(record,'name')),fields:decode(fields)};
|
|
1017
|
+
}else if(type==='record')vectorView={type:decode(field(record,'type')),map:decode(field(record,'map'))};
|
|
1018
|
+
else if(type==='subvector')vectorView={source:decode(field(record,'source')),start:decode(field(record,'start')),end:decode(field(record,'end'))};
|
|
1019
|
+
else if(type==='keyword'||type==='symbol')values=[decode(field(record,'namespace')),decode(field(record,'name'))];
|
|
1020
|
+
else{
|
|
1021
|
+
const array=field(record,'values');hold(array);
|
|
1022
|
+
if(kind(array)!==14)throw new TypeError('compiled persistent literal has no bulk values');
|
|
1023
|
+
values=[];
|
|
1024
|
+
for(let index=0,count=call('value-length',heap,array);index<count;index++)values.push(decode(call('value-get',heap,array,index)));
|
|
1025
|
+
if(type==='map'){
|
|
1026
|
+
if(values.length%2)throw new TypeError('compiled persistent map has an incomplete entry');
|
|
1027
|
+
const entries=[];for(let index=0;index<values.length;index+=2)entries.push([values[index],values[index+1]]);values=entries;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
const metadata=decode(field(record,'metadata'));
|
|
1031
|
+
const result=literalProvider().create(type,values,metadata,vectorView);
|
|
1032
|
+
memo.set(raw,result);reverse.set(result,raw);rememberSource(raw,result,token);return result;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
let result,refresh,synchronize;
|
|
1036
|
+
if(type===14)result=new Array(call('value-length',heap,raw));
|
|
1037
|
+
else if(type===13||type===17)result={};
|
|
1038
|
+
else if(type===15)result=new Map();
|
|
1039
|
+
else if(type===16)result=new Set();
|
|
1040
|
+
else if(type===23)result=new WeakMap();
|
|
1041
|
+
else if(type===24)result=new WeakSet();
|
|
1042
|
+
else if(type===36)result=Object(decode(call('value-source-boxed-primitive',heap,raw)));
|
|
1043
|
+
else if(type===18){
|
|
1044
|
+
const constructible=call('value-function-constructible',heap,raw)!==0;
|
|
1045
|
+
// A bound target has no nonconfigurable own prototype. The owning
|
|
1046
|
+
// runtime supplies the source function's exact own descriptors.
|
|
1047
|
+
result=constructible?function(){}.bind(undefined):()=>{};
|
|
1048
|
+
}else if(type===21){
|
|
1049
|
+
const payload=call('value-data',heap,raw,21),p=view(),source=p.getUint32(payload+4,true),bits=p.getUint32(payload-16,true);
|
|
1050
|
+
const flags=(bits&8?'g':'')+(bits&32?'i':'')+(bits&1?'m':'')+(bits&2?'s':'')+(bits&4?'u':'')+(bits&16?'y':'');
|
|
1051
|
+
result=new RegExp(readString(source),flags);
|
|
1052
|
+
}else if(type===26){
|
|
1053
|
+
const state=call('value-promise-state',heap,raw);
|
|
1054
|
+
if(state===0)result=pendingPromise(raw);
|
|
1055
|
+
else{
|
|
1056
|
+
const value=decode(call('value-promise-result',heap,raw));
|
|
1057
|
+
result=state===1?Promise.resolve(value):Promise.reject(value);
|
|
1058
|
+
if(state===2)result.catch(()=>{});
|
|
1059
|
+
}
|
|
1060
|
+
}else throw new TypeError('console value has no managed host representation');
|
|
1061
|
+
if(type===13||type===14||type===17||type===18||type===36){
|
|
1062
|
+
const target=result;
|
|
1063
|
+
const sourceView=createManagedSourceView({target,operations:{
|
|
1064
|
+
descriptor:key=>using(()=>propertyDescriptor(raw,encode(key))),
|
|
1065
|
+
keys:()=>using(()=>{
|
|
1066
|
+
const output=[],names=objectCall('value-source-own-keys',raw,1);hold(names);
|
|
1067
|
+
const symbols=objectCall('value-source-own-keys',raw,2);hold(symbols);
|
|
1068
|
+
for(const list of[names,symbols])for(let index=0,count=call('value-length',heap,list);index<count;index++)output.push(decode(call('value-get',heap,list,index)));
|
|
1069
|
+
return output;
|
|
1070
|
+
}),
|
|
1071
|
+
get:(key,receiver)=>nativeReflect(1,[result,key,receiver]),
|
|
1072
|
+
set:(key,value,receiver)=>nativeReflect(2,[result,key,value,receiver]),
|
|
1073
|
+
has:key=>nativeReflect(14,[result,key]),
|
|
1074
|
+
define:(key,entry)=>nativeReflect(10,[result,key,entry]),
|
|
1075
|
+
delete:key=>nativeReflect(11,[result,key]),
|
|
1076
|
+
prototype:()=>using(()=>decode(reflect(raw,0))),
|
|
1077
|
+
setPrototype:prototype=>nativeReflect(7,[result,prototype]),
|
|
1078
|
+
extensible:()=>nativeReflect(13,[result]),
|
|
1079
|
+
preventExtensions:()=>nativeReflect(12,[result]),
|
|
1080
|
+
apply:(receiver,args)=>using(()=>{
|
|
1081
|
+
const list=argv(args.map(value=>encode(value)));
|
|
1082
|
+
return decode(objectCall('value-source-invoke-with-this',raw,encode(receiver),list,args.length));
|
|
1083
|
+
}),
|
|
1084
|
+
construct:type===18&&call('value-function-constructible',heap,raw)!==0?(args,newTarget)=>using(()=>{
|
|
1085
|
+
const list=argv(args.map(value=>encode(value)));
|
|
1086
|
+
return decode(objectCall('value-source-construct-target',raw,list,args.length,encode(newTarget)));
|
|
1087
|
+
}):undefined,
|
|
1088
|
+
}});
|
|
1089
|
+
result=sourceView.value;
|
|
1090
|
+
refresh=sourceView.refresh;
|
|
1091
|
+
}
|
|
1092
|
+
memo.set(raw,result);reverse.set(result,raw);rememberSource(raw,result,token,refresh,synchronize);
|
|
1093
|
+
if(refresh){const entry=sourceCache.get(raw);entry.refreshing=true;try{refresh();}finally{entry.refreshing=false;}}
|
|
1094
|
+
if(type===15||type===16)attachCollection(raw,result,type);
|
|
1095
|
+
if(type===13||type===14||type===17||type===18||type===36)return result;
|
|
1096
|
+
if(type!==26)copyProperties(raw,result);
|
|
1097
|
+
return result;
|
|
1098
|
+
}
|
|
1099
|
+
let failed=false;
|
|
1100
|
+
try{return operation({encode,encodeList,encodeDescriptor,decode,argv,hold,kind,reflect,field,roots});
|
|
1101
|
+
}catch(error){
|
|
1102
|
+
failed=true;error=sourceThrown(error);if(!sourceErrors)throw error;try{thrownValue=encode(error);call('heap-pin',heap,thrownValue);thrownPinned=true;sourceThrow=true;return 0;}catch{throw error;}
|
|
1103
|
+
}finally{
|
|
1104
|
+
let cleanup;for(let index=roots.length-1;index>=0;index--)if(!consoleRoots.has(roots[index]))try{api.release(roots[index]);}catch(error){cleanup??=error;}
|
|
1105
|
+
memo.clear();reverse.clear();
|
|
1106
|
+
if(!failed&&cleanup)throw cleanup;
|
|
1107
|
+
}
|
|
1108
|
+
}));}catch(error){if(!sourceThrow)throw error;}
|
|
1109
|
+
if(sourceThrow){if(thrownPinned)call('heap-release',heap,thrownValue);e['value-throw'](heap,thrownValue);return 0;}
|
|
1110
|
+
return result;
|
|
1111
|
+
}
|
|
1112
|
+
if(lifecycle.capabilityBridge){
|
|
1113
|
+
lifecycle.capabilityBridge.attach((name,owner,argumentsList)=>{
|
|
1114
|
+
if(owner!==heap)throw new TypeError('host capability belongs to another managed heap');
|
|
1115
|
+
return withHostValues(({encode,encodeList,encodeDescriptor,decode,argv,hold,kind,reflect,field,roots})=>{
|
|
1116
|
+
hold(argumentsList);if(kind(argumentsList)!==7)throw new TypeError('host operation requires its argument tuple');
|
|
1117
|
+
const values=[],count=call('value-length',heap,argumentsList);
|
|
1118
|
+
for(let index=0;index<count;index++)values.push(decode(call('value-get',heap,argumentsList,index)));
|
|
1119
|
+
let output;
|
|
1120
|
+
if(name==='console-log-capture'){
|
|
1121
|
+
const receiver=currentConsole(),callee=receiver.log,capture=Object.freeze({receiver,callee});consoleCaptures.add(capture);output=capture;
|
|
1122
|
+
}else if(name==='console-log'){
|
|
1123
|
+
const[capture,...args]=values;if(!consoleCaptures.has(capture))throw new TypeError('invalid console-log capture');
|
|
1124
|
+
output=Reflect.apply(capture.callee,capture.receiver,args);
|
|
1125
|
+
}else if(name==='source-operation'){
|
|
1126
|
+
const[operation,target,key,value]=values;
|
|
1127
|
+
if(!Number.isInteger(operation)||operation<0||(operation>24&&operation!==28&&operation!==29&&operation!==30&&operation!==31))throw new TypeError('unknown managed host operation');
|
|
1128
|
+
switch(operation){
|
|
1129
|
+
case 0:{
|
|
1130
|
+
const declarations=descriptor.hostModules?.filter(item=>item.id===target)??[];
|
|
1131
|
+
if(!declarations.length||!hasHostNamespace(target))throw new TypeError('undeclared managed host module');
|
|
1132
|
+
const namespace=hostNamespace(target);
|
|
1133
|
+
if(key===undefined){if(!declarations.some(item=>item.namespace))throw new TypeError('host namespace import was not declared');output=namespace;}
|
|
1134
|
+
else{if(!declarations.some(item=>item.namespace||item.allowedExports.includes(key)))throw new TypeError('host export import was not declared');if(!Object.hasOwn(namespace,key))throw new SyntaxError('host module does not export '+key);output=namespace[key];}
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1137
|
+
case 1:output=Reflect.get(target,key,values.length>3?value:target);break;
|
|
1138
|
+
case 2:if(!Reflect.set(target,key,value))throw new TypeError('host property assignment failed');output=value;break;
|
|
1139
|
+
case 3:output=Object.hasOwn(target,key);break;
|
|
1140
|
+
case 4:return encodeList(Reflect.ownKeys(target));
|
|
1141
|
+
case 5:return encodeDescriptor(Reflect.getOwnPropertyDescriptor(target,key));
|
|
1142
|
+
case 6:output=Reflect.getPrototypeOf(target);break;
|
|
1143
|
+
case 7:if(!Reflect.setPrototypeOf(target,key))throw new TypeError('host prototype assignment failed');output=target;break;
|
|
1144
|
+
case 8:output=Reflect.apply(target,key,values.slice(3));break;
|
|
1145
|
+
case 9:output=Reflect.construct(target,values.slice(2));break;
|
|
1146
|
+
case 10:Object.defineProperty(target,key,value);output=target;break;
|
|
1147
|
+
case 11:output=Reflect.deleteProperty(target,key);break;
|
|
1148
|
+
case 12:output=Object.preventExtensions(target);break;
|
|
1149
|
+
case 13:output=Reflect.isExtensible(target);break;
|
|
1150
|
+
case 14:output=Reflect.has(target,key);break;
|
|
1151
|
+
case 15:output=Object.freeze(target);break;
|
|
1152
|
+
case 16:output=Array.isArray(target);break;
|
|
1153
|
+
case 17:output=Object.isFrozen(target);break;
|
|
1154
|
+
case 18:
|
|
1155
|
+
if(!options.moduleGraph||typeof options.moduleGraph.bindingChanged!=='function')throw new TypeError('managed module graph is unavailable');
|
|
1156
|
+
options.moduleGraph.bindingChanged(target,key,value);output=undefined;break;
|
|
1157
|
+
case 19:output=Reflect.construct(target,values.slice(3),key);break;
|
|
1158
|
+
case 20:output=Reflect.set(target,key,value,values.length>4?values[4]:target);break;
|
|
1159
|
+
case 21:output=Reflect.defineProperty(target,key,value);break;
|
|
1160
|
+
case 22:output=Reflect.setPrototypeOf(target,key);break;
|
|
1161
|
+
case 23:output=Reflect.preventExtensions(target);break;
|
|
1162
|
+
case 24:output=Reflect.apply(hostFunctionToString,target,[]);break;
|
|
1163
|
+
case 28:output=Reflect.apply(hostObjectToString,target,[]);break;
|
|
1164
|
+
case 29:{
|
|
1165
|
+
if(!Number.isInteger(target)||target<300||target>325)throw new TypeError('unknown managed collection intrinsic');
|
|
1166
|
+
output=Reflect.apply(hostCollectionIntrinsics[target-300],key,values.slice(3));break;
|
|
1167
|
+
}
|
|
1168
|
+
case 30:{
|
|
1169
|
+
if(!Number.isInteger(target)||!Object.hasOwn(hostIteratorIntrinsics,target))throw new TypeError('unknown managed iterator intrinsic');
|
|
1170
|
+
output=Reflect.apply(hostIteratorIntrinsics[target],key,values.slice(3));break;
|
|
1171
|
+
}
|
|
1172
|
+
case 31:output=Reflect.apply(hostPromiseThen,target,values.slice(2));break;
|
|
1173
|
+
}
|
|
1174
|
+
}else throw new TypeError('unknown managed host capability');
|
|
1175
|
+
return encode(output);
|
|
1176
|
+
},true);
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
if(moduleInfo&&initialize)initializeModuleInstance();
|
|
1180
|
+
return api;
|
|
1181
|
+
}
|