eliscript 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/bootstrap/README.md +26 -0
- package/bootstrap/backends/README.md +515 -0
- package/bootstrap/backends/async.eli +230 -0
- package/bootstrap/backends/binary.eli +173 -0
- package/bootstrap/backends/capabilities.eli +74 -0
- package/bootstrap/backends/elf.eli +246 -0
- package/bootstrap/backends/managed.eli +5976 -0
- package/bootstrap/backends/memory.eli +100 -0
- package/bootstrap/backends/native.eli +2000 -0
- package/bootstrap/backends/numeric.eli +1362 -0
- package/bootstrap/backends/optimize.eli +79 -0
- package/bootstrap/backends/regexp.eli +2263 -0
- package/bootstrap/backends/sha256.eli +138 -0
- package/bootstrap/backends/wasm.eli +1161 -0
- package/bootstrap/compiler/analyzer.eli +165 -77
- package/bootstrap/compiler/compiler.eli +43 -19
- package/bootstrap/compiler/emitter.eli +780 -170
- package/bootstrap/compiler/expander.eli +136 -45
- package/bootstrap/compiler/formatter.eli +8 -1
- package/bootstrap/compiler/ir.eli +148 -45
- package/bootstrap/compiler/lower.eli +29 -2
- package/bootstrap/compiler/project.eli +51 -21
- package/bootstrap/compiler/reader.eli +128 -36
- package/bootstrap/compiler/source-map.eli +46 -4
- package/bootstrap/compiler/symbol.eli +2 -1
- package/bootstrap/compiler/syntax.eli +47 -12
- package/bootstrap/compiler/transient-analysis.eli +40 -4
- package/bootstrap/host/check-cli-legacy.mjs +163 -0
- package/bootstrap/host/check-cli.mjs +59 -158
- package/bootstrap/host/check-cli.mjs.map +1 -0
- package/bootstrap/host/compiler-session.eli +1579 -0
- package/bootstrap/host/compiler-tools.eli +513 -0
- package/bootstrap/host/eliscript-cli.mjs +53 -33
- package/bootstrap/host/eliscript-cli.mjs.map +1 -0
- package/bootstrap/host/project-cli-legacy.mjs +295 -0
- package/bootstrap/host/project-cli.mjs +74 -289
- package/bootstrap/host/project-cli.mjs.map +1 -0
- package/bootstrap/host/project-legacy.mjs +1080 -0
- package/bootstrap/host/project.mjs +210 -1060
- package/bootstrap/host/project.mjs.map +1 -0
- package/bootstrap/runtime/UNICODE-LICENSE.txt +39 -0
- package/bootstrap/runtime/memory.eli +30379 -0
- package/browser/host.mjs +732 -11
- package/browser/worker.mjs +6 -3
- package/compiler/eliscript-analyzer.el +371 -4
- package/compiler/eliscript-cli.el +84 -1
- package/compiler/eliscript-emitter.el +1189 -256
- package/compiler/eliscript-expander.el +147 -10
- package/compiler/eliscript-ir-emitter.el +725 -208
- package/compiler/eliscript-lower.el +127 -1
- package/compiler/eliscript-portable.el +177 -51
- package/compiler/eliscript-project.el +20 -2
- package/compiler/eliscript-reader.el +141 -57
- package/compiler/eliscript-source-map.el +26 -12
- package/compiler/eliscript-transient-analysis.el +382 -19
- package/dist/backends/async.mjs +561 -0
- package/dist/backends/async.mjs.macro-origins.json +1 -0
- package/dist/backends/async.mjs.map +1 -0
- package/dist/backends/binary.mjs +381 -0
- package/dist/backends/binary.mjs.macro-origins.json +1 -0
- package/dist/backends/binary.mjs.map +1 -0
- package/dist/backends/capabilities.mjs +237 -0
- package/dist/backends/capabilities.mjs.macro-origins.json +1 -0
- package/dist/backends/capabilities.mjs.map +1 -0
- package/dist/backends/elf.mjs +540 -0
- package/dist/backends/elf.mjs.macro-origins.json +1 -0
- package/dist/backends/elf.mjs.map +1 -0
- package/dist/backends/managed.mjs +10616 -0
- package/dist/backends/managed.mjs.macro-origins.json +1 -0
- package/dist/backends/managed.mjs.map +1 -0
- package/dist/backends/memory.mjs +278 -0
- package/dist/backends/memory.mjs.macro-origins.json +1 -0
- package/dist/backends/memory.mjs.map +1 -0
- package/dist/backends/native.mjs +4099 -0
- package/dist/backends/native.mjs.macro-origins.json +1 -0
- package/dist/backends/native.mjs.map +1 -0
- package/dist/backends/numeric.mjs +2458 -0
- package/dist/backends/numeric.mjs.macro-origins.json +1 -0
- package/dist/backends/numeric.mjs.map +1 -0
- package/dist/backends/optimize.mjs +204 -0
- package/dist/backends/optimize.mjs.macro-origins.json +1 -0
- package/dist/backends/optimize.mjs.map +1 -0
- package/dist/backends/regexp.mjs +2033 -0
- package/dist/backends/regexp.mjs.macro-origins.json +1 -0
- package/dist/backends/regexp.mjs.map +1 -0
- package/dist/backends/sha256.mjs +310 -0
- package/dist/backends/sha256.mjs.macro-origins.json +1 -0
- package/dist/backends/sha256.mjs.map +1 -0
- package/dist/backends/wasm.mjs +2258 -0
- package/dist/backends/wasm.mjs.macro-origins.json +1 -0
- package/dist/backends/wasm.mjs.map +1 -0
- package/dist/bootstrap/analyzer.mjs +1908 -776
- package/dist/bootstrap/analyzer.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -1
- package/dist/bootstrap/compiler.mjs +450 -142
- package/dist/bootstrap/compiler.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/compiler.mjs.map +1 -1
- package/dist/bootstrap/emitter.mjs +3083 -909
- package/dist/bootstrap/emitter.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/emitter.mjs.map +1 -1
- package/dist/bootstrap/expander.mjs +2887 -1233
- package/dist/bootstrap/expander.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/expander.mjs.map +1 -1
- package/dist/bootstrap/formatter.mjs +582 -218
- package/dist/bootstrap/formatter.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/formatter.mjs.map +1 -1
- package/dist/bootstrap/ir.mjs +670 -116
- package/dist/bootstrap/ir.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/ir.mjs.map +1 -1
- package/dist/bootstrap/lower.mjs +866 -257
- package/dist/bootstrap/lower.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/lower.mjs.map +1 -1
- package/dist/bootstrap/package.json +1 -0
- package/dist/bootstrap/project.mjs +1168 -498
- package/dist/bootstrap/project.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/project.mjs.map +1 -1
- package/dist/bootstrap/reader.mjs +674 -175
- package/dist/bootstrap/reader.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/reader.mjs.map +1 -1
- package/dist/bootstrap/runtime/math.mjs +1117 -0
- package/dist/bootstrap/runtime/math.mjs.map +1 -0
- package/dist/bootstrap/runtime/unicode-case-data.mjs +10125 -0
- package/dist/bootstrap/runtime/unicode-case-data.mjs.map +1 -0
- package/dist/bootstrap/runtime/unicode-case.mjs +281 -0
- package/dist/bootstrap/runtime/unicode-case.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +430 -119
- package/dist/bootstrap/source-map.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/source-map.mjs.map +1 -1
- package/dist/bootstrap/symbol.mjs +229 -53
- package/dist/bootstrap/symbol.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/symbol.mjs.map +1 -1
- package/dist/bootstrap/syntax.mjs +205 -7
- package/dist/bootstrap/syntax.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/syntax.mjs.map +1 -1
- package/dist/bootstrap/transient-analysis.mjs +1185 -489
- package/dist/bootstrap/transient-analysis.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -1
- package/dist/browser/compiler.js +199 -6478
- package/dist/browser/host.mjs +1078 -0
- package/dist/browser/loader.js +1 -0
- package/dist/browser/loader.mjs +231 -0
- package/dist/browser/worker.mjs +63 -0
- package/dist/compiler-artifact.json +1 -0
- package/dist/host/compiler-session.mjs +2980 -0
- package/dist/host/compiler-session.mjs.macro-origins.json +1 -0
- package/dist/host/compiler-session.mjs.map +1 -0
- package/dist/host/compiler-tools.mjs +1084 -0
- package/dist/host/compiler-tools.mjs.macro-origins.json +1 -0
- package/dist/host/compiler-tools.mjs.map +1 -0
- package/dist/literal-sources/runtime/core/collection-internals.eli +60 -0
- package/dist/literal-sources/runtime/core/collection.eli +639 -0
- package/dist/literal-sources/runtime/core/data-text.eli +290 -0
- package/dist/literal-sources/runtime/core/data.eli +22 -0
- package/dist/literal-sources/runtime/core/identifier.eli +44 -0
- package/dist/literal-sources/runtime/core/lazy-sequence.eli +131 -0
- package/dist/literal-sources/runtime/core/list.eli +19 -0
- package/dist/literal-sources/runtime/core/map.eli +9 -0
- package/dist/literal-sources/runtime/core/metadata-internals.eli +6 -0
- package/dist/literal-sources/runtime/core/metadata.eli +40 -0
- package/dist/literal-sources/runtime/core/object.eli +8 -0
- package/dist/literal-sources/runtime/core/order.eli +123 -0
- package/dist/literal-sources/runtime/core/persistent-kind.eli +28 -0
- package/dist/literal-sources/runtime/core/protocol-error.eli +32 -0
- package/dist/literal-sources/runtime/core/protocol.eli +28 -0
- package/dist/literal-sources/runtime/core/queue.eli +9 -0
- package/dist/literal-sources/runtime/core/record.eli +191 -0
- package/dist/literal-sources/runtime/core/regex.eli +158 -0
- package/dist/literal-sources/runtime/core/sequence.eli +305 -0
- package/dist/literal-sources/runtime/core/set-algebra.eli +28 -0
- package/dist/literal-sources/runtime/core/set.eli +9 -0
- package/dist/literal-sources/runtime/core/sorted.eli +408 -0
- package/dist/literal-sources/runtime/core/text.eli +14 -0
- package/dist/literal-sources/runtime/core/transducer.eli +268 -0
- package/dist/literal-sources/runtime/core/transient.eli +17 -0
- package/dist/literal-sources/runtime/core/truth.eli +4 -0
- package/dist/literal-sources/runtime/core/type.eli +232 -0
- package/dist/literal-sources/runtime/core/value-internals.eli +13 -0
- package/dist/literal-sources/runtime/core/value.eli +19 -0
- package/dist/literal-sources/runtime/core/vector.eli +25 -0
- package/dist/literal-sources/runtime/literals.eli +23 -0
- package/dist/literal-sources/runtime/testing/value.eli +6 -0
- package/dist/literal-sources/runtime/wire/http-rpc.eli +362 -0
- package/dist/literal-sources/runtime/wire/markdown.eli +275 -0
- package/dist/literal-sources/runtime/wire/schema.eli +193 -0
- package/dist/literal-sources/stdlib/bit.eli +36 -0
- package/dist/literal-sources/stdlib/core/data.eli +306 -0
- package/dist/literal-sources/stdlib/core/object.eli +89 -0
- package/dist/literal-sources/stdlib/core/protocol.eli +451 -0
- package/dist/literal-sources/stdlib/core/set.eli +312 -0
- package/dist/literal-sources/stdlib/core/text.eli +103 -0
- package/dist/literal-sources/stdlib/managed-literal-protocols.eli +494 -0
- package/dist/literal-sources/stdlib/managed-literals.eli +1469 -0
- package/dist/literal-sources/stdlib/managed-queue-state.eli +65 -0
- package/dist/literal-sources/stdlib/managed-sorted-state.eli +233 -0
- package/dist/literal-sources/stdlib/managed-transient-state.eli +348 -0
- package/dist/literal-sources/stdlib/managed-value-state.eli +153 -0
- package/dist/literal-sources/stdlib/managed-vector-view-state.eli +102 -0
- package/dist/literal-sources/stdlib/persistent-list.eli +145 -0
- package/dist/literal-sources/stdlib/persistent-map.eli +724 -0
- package/dist/literal-sources/stdlib/persistent-set.eli +236 -0
- package/dist/literal-sources/stdlib/persistent-vector.eli +359 -0
- package/dist/literal-sources/stdlib/value.eli +325 -0
- package/dist/package.json +10 -0
- package/dist/runtime/math.mjs +1116 -0
- package/dist/runtime/math.mjs.macro-origins.json +1 -0
- package/dist/runtime/math.mjs.map +1 -0
- package/dist/runtime/unicode-case-data.mjs +10124 -0
- package/dist/runtime/unicode-case-data.mjs.macro-origins.json +1 -0
- package/dist/runtime/unicode-case-data.mjs.map +1 -0
- package/dist/runtime/unicode-case.mjs +280 -0
- package/dist/runtime/unicode-case.mjs.macro-origins.json +1 -0
- package/dist/runtime/unicode-case.mjs.map +1 -0
- package/dist/runtime.eli +30379 -0
- package/dist/stage3-release.json +1 -0
- package/editor/README.md +1 -1
- package/editor/eliscript-mode.el +1 -1
- package/editor/eliscript-repl.el +1 -1
- package/package.json +106 -11
- package/platform/http.mjs +20 -0
- package/runtime/array-text.mjs +159 -0
- package/runtime/core/map-internals.mjs +27 -9
- package/runtime/core/object-impl.mjs +26 -17
- package/runtime/core/object-impl.mjs.map +1 -1
- package/runtime/core/protocol-impl.mjs +682 -255
- package/runtime/core/protocol-impl.mjs.map +1 -1
- package/runtime/core/protocol.mjs +4 -0
- package/runtime/core/record.mjs +23 -2
- package/runtime/core/regex.mjs +4 -0
- package/runtime/core/sorted.mjs +53 -0
- package/runtime/core/text-impl.mjs +167 -48
- package/runtime/core/text-impl.mjs.map +1 -1
- package/runtime/core/type.mjs +75 -3
- package/runtime/core/vector.mjs +6 -0
- package/runtime/math.eli +429 -0
- package/runtime/math.mjs +1116 -0
- package/runtime/math.mjs.map +1 -0
- package/runtime/number-radix.mjs +105 -0
- package/runtime/unicode-case-data.eli +29 -0
- package/runtime/unicode-case-data.mjs +10124 -0
- package/runtime/unicode-case-data.mjs.map +1 -0
- package/runtime/unicode-case.eli +100 -0
- package/runtime/unicode-case.mjs +280 -0
- package/runtime/unicode-case.mjs.map +1 -0
- package/runtime/wire/http-rpc.mjs +168 -0
- package/runtime/wire/markdown.mjs +196 -0
- package/runtime/wire/schema.mjs +109 -0
- package/stdlib/README.md +54 -0
- package/stdlib/core/protocol.eli +81 -17
- package/stdlib/core/seq.eli +1 -1
- package/stdlib/core/zipper.eli +172 -72
- package/stdlib/gepo.eli +12 -0
- package/stdlib/interop/js.eli +56 -15
- package/stdlib/managed-literal-protocols.eli +494 -0
- package/stdlib/managed-literals.eli +1469 -0
- package/stdlib/managed-protocol-error.eli +32 -0
- package/stdlib/managed-queue-state.eli +65 -0
- package/stdlib/managed-runtime-collection-internals.eli +60 -0
- package/stdlib/managed-runtime-collection.eli +639 -0
- package/stdlib/managed-runtime-data-text.eli +290 -0
- package/stdlib/managed-runtime-data.eli +22 -0
- package/stdlib/managed-runtime-identifier.eli +44 -0
- package/stdlib/managed-runtime-lazy-sequence.eli +131 -0
- package/stdlib/managed-runtime-list.eli +19 -0
- package/stdlib/managed-runtime-literals.eli +23 -0
- package/stdlib/managed-runtime-map.eli +9 -0
- package/stdlib/managed-runtime-metadata-internals.eli +6 -0
- package/stdlib/managed-runtime-metadata.eli +40 -0
- package/stdlib/managed-runtime-object.eli +8 -0
- package/stdlib/managed-runtime-order.eli +123 -0
- package/stdlib/managed-runtime-persistent-kind.eli +28 -0
- package/stdlib/managed-runtime-protocol.eli +28 -0
- package/stdlib/managed-runtime-queue.eli +9 -0
- package/stdlib/managed-runtime-record.eli +191 -0
- package/stdlib/managed-runtime-regex.eli +158 -0
- package/stdlib/managed-runtime-sequence.eli +305 -0
- package/stdlib/managed-runtime-set-algebra.eli +28 -0
- package/stdlib/managed-runtime-set.eli +9 -0
- package/stdlib/managed-runtime-sorted.eli +408 -0
- package/stdlib/managed-runtime-text.eli +14 -0
- package/stdlib/managed-runtime-transducer.eli +268 -0
- package/stdlib/managed-runtime-transient.eli +17 -0
- package/stdlib/managed-runtime-truth.eli +4 -0
- package/stdlib/managed-runtime-type.eli +232 -0
- package/stdlib/managed-runtime-value-internals.eli +13 -0
- package/stdlib/managed-runtime-value.eli +19 -0
- package/stdlib/managed-runtime-vector.eli +25 -0
- package/stdlib/managed-sorted-state.eli +233 -0
- package/stdlib/managed-testing-value.eli +6 -0
- package/stdlib/managed-transient-state.eli +348 -0
- package/stdlib/managed-value-state.eli +153 -0
- package/stdlib/managed-vector-view-state.eli +102 -0
- package/stdlib/managed-wire-http-rpc.eli +362 -0
- package/stdlib/managed-wire-markdown.eli +275 -0
- package/stdlib/managed-wire-schema.eli +193 -0
- package/stdlib/mdp.eli +7 -0
- package/stdlib/mds.eli +4 -0
- package/stdlib/persistent-vector.eli +23 -6
- package/tools/acceptance/check-legacy.mjs +687 -0
- package/tools/acceptance/check.eli +431 -0
- package/tools/acceptance/compile-evidence.el +49 -0
- package/tools/acceptance/finalize-legacy.mjs +498 -0
- package/tools/acceptance/finalize.eli +270 -0
- package/tools/backends/benchmark.mjs +175 -0
- package/tools/backends/build.mjs +135 -0
- package/tools/backends/compile.mjs +94 -0
- package/tools/backends/compiler-bootstrap.mjs +1001 -0
- package/tools/backends/compiler-browser.mjs +361 -0
- package/tools/backends/compiler-build.mjs +1628 -0
- package/tools/backends/compiler-cli-legacy.mjs +334 -0
- package/tools/backends/compiler-cli.mjs +29 -0
- package/tools/backends/compiler-corpus-bit.mjs +234 -0
- package/tools/backends/compiler-corpus-cli-adapters-legacy.mjs +362 -0
- package/tools/backends/compiler-corpus-cli-adapters.mjs +247 -0
- package/tools/backends/compiler-corpus-debugging.mjs +221 -0
- package/tools/backends/compiler-corpus-emitter.mjs +324 -0
- package/tools/backends/compiler-corpus-evaluation-adapters.mjs +65 -0
- package/tools/backends/compiler-corpus-execution-legacy.mjs +769 -0
- package/tools/backends/compiler-corpus-execution.mjs +3324 -0
- package/tools/backends/compiler-corpus-fuzz.mjs +229 -0
- package/tools/backends/compiler-corpus-generations.mjs +208 -0
- package/tools/backends/compiler-corpus-host-context-legacy.mjs +114 -0
- package/tools/backends/compiler-corpus-host-context.mjs +550 -0
- package/tools/backends/compiler-corpus-identity-host.mjs +553 -0
- package/tools/backends/compiler-corpus-identity-value-adapters-legacy.mjs +298 -0
- package/tools/backends/compiler-corpus-identity-value-adapters.mjs +69 -0
- package/tools/backends/compiler-corpus-isolated-exports.mjs +21 -0
- package/tools/backends/compiler-corpus-legacy.mjs +1155 -0
- package/tools/backends/compiler-corpus-literal-provider.mjs +282 -0
- package/tools/backends/compiler-corpus-managed-adapters-legacy.mjs +334 -0
- package/tools/backends/compiler-corpus-managed-adapters.mjs +937 -0
- package/tools/backends/compiler-corpus-managed-cases.mjs +179 -0
- package/tools/backends/compiler-corpus-managed-fixtures-legacy.mjs +879 -0
- package/tools/backends/compiler-corpus-managed-fixtures.mjs +1287 -0
- package/tools/backends/compiler-corpus-matchers.mjs +173 -0
- package/tools/backends/compiler-corpus-original-program.mjs +612 -0
- package/tools/backends/compiler-corpus-process.mjs +765 -0
- package/tools/backends/compiler-corpus-program-driver.mjs +306 -0
- package/tools/backends/compiler-corpus-project-adapters-legacy.mjs +497 -0
- package/tools/backends/compiler-corpus-project-adapters.mjs +340 -0
- package/tools/backends/compiler-corpus-project-entry-host.mjs +511 -0
- package/tools/backends/compiler-corpus-project-transport.mjs +151 -0
- package/tools/backends/compiler-corpus-raw-fixture-observer.mjs +1438 -0
- package/tools/backends/compiler-corpus-raw-language-fixtures.mjs +1456 -0
- package/tools/backends/compiler-corpus-raw-math-fixture.mjs +346 -0
- package/tools/backends/compiler-corpus-raw-special-fixtures.mjs +523 -0
- package/tools/backends/compiler-corpus-reference-legacy.mjs +263 -0
- package/tools/backends/compiler-corpus-reference.mjs +241 -0
- package/tools/backends/compiler-corpus-runtime-adapters-legacy.mjs +843 -0
- package/tools/backends/compiler-corpus-runtime-adapters.mjs +663 -0
- package/tools/backends/compiler-corpus-source-archive.mjs +206 -0
- package/tools/backends/compiler-corpus-tools-artifact-adapters.mjs +410 -0
- package/tools/backends/compiler-corpus-tools-cli.mjs +363 -0
- package/tools/backends/compiler-corpus-tools-reference.mjs +264 -0
- package/tools/backends/compiler-corpus.mjs +2054 -0
- package/tools/backends/compiler-debug.mjs +142 -0
- package/tools/backends/compiler-matrix.mjs +1955 -0
- package/tools/backends/compiler-metadata.mjs +203 -0
- package/tools/backends/compiler-package-browser.mjs +120 -0
- package/tools/backends/compiler-package-legacy.mjs +654 -0
- package/tools/backends/compiler-package.mjs +464 -0
- package/tools/backends/compiler-project.mjs +126 -0
- package/tools/backends/compiler-session.mjs +843 -0
- package/tools/backends/compiler-sha256.mjs +152 -0
- package/tools/backends/compiler-unicode-profile-host.mjs +196 -0
- package/tools/backends/compiler-worker.mjs +573 -0
- package/tools/backends/dist/bootstrap-js-stages.mjs +919 -0
- package/tools/backends/dist/bootstrap-js-stages.mjs.map +1 -0
- package/tools/backends/dist/managed-ir-inventory.mjs +488 -0
- package/tools/backends/dist/managed-ir-inventory.mjs.map +1 -0
- package/tools/backends/dist/record-grid.mjs +1256 -0
- package/tools/backends/dist/record-grid.mjs.map +1 -0
- package/tools/backends/dist/release-cli.mjs +462 -0
- package/tools/backends/dist/release-cli.mjs.map +1 -0
- package/tools/backends/dist/run-artifact.mjs +517 -0
- package/tools/backends/dist/run-artifact.mjs.map +1 -0
- package/tools/backends/eliscript/compiler-corpus-bit.eli +77 -0
- package/tools/backends/eliscript/compiler-corpus-debugging.eli +70 -0
- package/tools/backends/eliscript/compiler-corpus-project-entry-host.eli +256 -0
- package/tools/backends/managed-foreign-binding.mjs +497 -0
- package/tools/backends/managed-host-legacy.mjs +1181 -0
- package/tools/backends/managed-host-lifecycle.mjs +310 -0
- package/tools/backends/managed-host-object-provider.mjs +155 -0
- package/tools/backends/managed-host-object-realm.mjs +797 -0
- package/tools/backends/managed-host-proxy.mjs +71 -0
- package/tools/backends/managed-host-runtime.mjs +5868 -0
- package/tools/backends/managed-host.mjs +716 -0
- package/tools/backends/managed-module-graph-legacy.mjs +308 -0
- package/tools/backends/managed-module-graph.mjs +694 -0
- package/tools/backends/managed-runtime-host-legacy.mjs +195 -0
- package/tools/backends/managed-runtime.mjs +939 -0
- package/tools/backends/managed-source-view-legacy.mjs +332 -0
- package/tools/backends/managed-source-view.mjs +959 -0
- package/tools/backends/memory-runtime.mjs +100 -0
- package/tools/backends/native-benchmark.mjs +88 -0
- package/tools/backends/native-managed-runtime.mjs +677 -0
- package/tools/backends/native-memory.mjs +768 -0
- package/tools/backends/native-node-memory.mjs +142 -0
- package/tools/backends/native-node-runner.mjs +99 -0
- package/tools/backends/native-node-watchdog.mjs +19 -0
- package/tools/backends/native-node-worker.mjs +75 -0
- package/tools/backends/stage3-targets.mjs +493 -0
- package/tools/bootstrap-command.el +13 -0
- package/tools/bootstrap-runtime.el +101 -0
- package/tools/bootstrap-seed.el +55 -0
- package/tools/project/check-cli.eli +31 -0
- package/tools/project/project-cli.eli +42 -0
- package/tools/project/project.eli +122 -0
- package/tools/runtime/unicode-case-profiles.mjs +13 -0
- package/tools/runtime/unicode-case-runtime.el +57 -0
- package/tools/testing/source-debugging-corpus-host.eli +16 -0
- package/tools/testing/source-debugging.eli +139 -0
- package/tools/testing/stdlib-bit-corpus-host.eli +21 -0
- package/tools/testing/stdlib-bit-corpus-host.mjs +118 -0
- package/tools/testing/stdlib-bit.eli +104 -0
- package/tools/testing/stdlib-bit.mjs +255 -0
- package/bin/eliscript-bootstrap +0 -15
package/browser/host.mjs
CHANGED
|
@@ -108,6 +108,607 @@ function walkProgram(program, visit) {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
function isPlainLiteralNode(node) {
|
|
112
|
+
return (
|
|
113
|
+
node !== null &&
|
|
114
|
+
typeof node === "object" &&
|
|
115
|
+
node.kind === "literal" &&
|
|
116
|
+
node.properties?.literalKind === undefined
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function isConstantLiteralNode(node) {
|
|
121
|
+
if (node === null || typeof node !== "object" || node.kind !== "literal") {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
const literalKind = node.properties?.literalKind;
|
|
125
|
+
return (
|
|
126
|
+
literalKind === undefined ||
|
|
127
|
+
literalKind === "undefined" ||
|
|
128
|
+
literalKind === "keyword"
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function cloneLiteralNode(literal, span) {
|
|
133
|
+
return {
|
|
134
|
+
kind: "literal",
|
|
135
|
+
span: span ?? literal.span,
|
|
136
|
+
value: literal.value,
|
|
137
|
+
children: [],
|
|
138
|
+
...(literal.properties ? { properties: { ...literal.properties } } : {}),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function literalRuntimeValue(node) {
|
|
143
|
+
const literalKind = node.properties?.literalKind;
|
|
144
|
+
if (literalKind === "undefined") return undefined;
|
|
145
|
+
if (literalKind === "keyword") return `:${node.value}`;
|
|
146
|
+
return node.value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function literalTruthiness(node) {
|
|
150
|
+
if (!isConstantLiteralNode(node)) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
const literalKind = node.properties?.literalKind;
|
|
154
|
+
if (literalKind === "undefined") return false;
|
|
155
|
+
if (literalKind === "keyword") return true;
|
|
156
|
+
return node.value !== false && node.value !== null && node.value !== undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function collectMutatedNames(program) {
|
|
160
|
+
const mutated = new Set();
|
|
161
|
+
walkProgram(program, (node) => {
|
|
162
|
+
if (node.kind === "assignment") {
|
|
163
|
+
for (const pair of node.children ?? []) {
|
|
164
|
+
if (typeof pair?.value === "string") mutated.add(pair.value);
|
|
165
|
+
}
|
|
166
|
+
} else if (
|
|
167
|
+
node.kind === "variable-declaration" &&
|
|
168
|
+
node.properties?.mutable === true &&
|
|
169
|
+
typeof node.value === "string"
|
|
170
|
+
) {
|
|
171
|
+
mutated.add(node.value);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return mutated;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function foldIrNode(node, env = new Map(), mutated = new Set()) {
|
|
178
|
+
if (node === null || typeof node !== "object") return node;
|
|
179
|
+
if (node.kind === "export-declaration" || node.kind === "import-declaration") {
|
|
180
|
+
return node;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (node.kind === "reference" && typeof node.value === "string") {
|
|
184
|
+
if (!mutated.has(node.value) && env.has(node.value)) {
|
|
185
|
+
return cloneLiteralNode(env.get(node.value), node.span);
|
|
186
|
+
}
|
|
187
|
+
return node;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (node.kind === "module-declaration" && Array.isArray(node.children)) {
|
|
191
|
+
const scope = new Map(env);
|
|
192
|
+
let changed = false;
|
|
193
|
+
const nextChildren = node.children.map((child) => {
|
|
194
|
+
const next = foldIrNode(child, scope, mutated);
|
|
195
|
+
if (next !== child) changed = true;
|
|
196
|
+
if (
|
|
197
|
+
next.kind === "variable-declaration" &&
|
|
198
|
+
next.properties?.mutable !== true &&
|
|
199
|
+
typeof next.value === "string" &&
|
|
200
|
+
!mutated.has(next.value) &&
|
|
201
|
+
Array.isArray(next.children) &&
|
|
202
|
+
next.children.length === 1 &&
|
|
203
|
+
isConstantLiteralNode(next.children[0])
|
|
204
|
+
) {
|
|
205
|
+
scope.set(next.value, next.children[0]);
|
|
206
|
+
}
|
|
207
|
+
return next;
|
|
208
|
+
});
|
|
209
|
+
return changed ? { ...node, children: nextChildren } : node;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (
|
|
213
|
+
(node.kind === "function-declaration" || node.kind === "function-expression") &&
|
|
214
|
+
Array.isArray(node.children)
|
|
215
|
+
) {
|
|
216
|
+
const paramCount = node.properties?.parameterCount ?? 0;
|
|
217
|
+
const scope = new Map(env);
|
|
218
|
+
for (let index = 0; index < paramCount; index += 1) {
|
|
219
|
+
const param = node.children[index];
|
|
220
|
+
if (typeof param?.value === "string") scope.delete(param.value);
|
|
221
|
+
}
|
|
222
|
+
let changed = false;
|
|
223
|
+
const nextChildren = node.children.map((child, index) => {
|
|
224
|
+
if (index < paramCount) return child;
|
|
225
|
+
const next = foldIrNode(child, scope, mutated);
|
|
226
|
+
if (next !== child) changed = true;
|
|
227
|
+
return next;
|
|
228
|
+
});
|
|
229
|
+
return changed ? { ...node, children: nextChildren } : node;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (node.kind === "lexical-bindings" && Array.isArray(node.children)) {
|
|
233
|
+
const bindingCount = node.properties?.bindingCount ?? 0;
|
|
234
|
+
const sequential = node.properties?.sequential === true;
|
|
235
|
+
const outerScope = new Map(env);
|
|
236
|
+
const bodyScope = new Map(env);
|
|
237
|
+
let changed = false;
|
|
238
|
+
const nextChildren = node.children.map((child, index) => {
|
|
239
|
+
if (index < bindingCount && child.kind === "lexical-binding") {
|
|
240
|
+
const initScope = sequential ? bodyScope : outerScope;
|
|
241
|
+
let nextBinding = child;
|
|
242
|
+
if (Array.isArray(child.children) && child.children.length > 0) {
|
|
243
|
+
let bindingChanged = false;
|
|
244
|
+
const nextBindingChildren = child.children.map((expr) => {
|
|
245
|
+
const folded = foldIrNode(expr, initScope, mutated);
|
|
246
|
+
if (folded !== expr) bindingChanged = true;
|
|
247
|
+
return folded;
|
|
248
|
+
});
|
|
249
|
+
if (bindingChanged) {
|
|
250
|
+
changed = true;
|
|
251
|
+
nextBinding = { ...child, children: nextBindingChildren };
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (
|
|
255
|
+
typeof nextBinding.value === "string" &&
|
|
256
|
+
nextBinding.properties?.pattern !== true
|
|
257
|
+
) {
|
|
258
|
+
if (
|
|
259
|
+
!mutated.has(nextBinding.value) &&
|
|
260
|
+
Array.isArray(nextBinding.children) &&
|
|
261
|
+
nextBinding.children.length === 1 &&
|
|
262
|
+
isConstantLiteralNode(nextBinding.children[0])
|
|
263
|
+
) {
|
|
264
|
+
bodyScope.set(nextBinding.value, nextBinding.children[0]);
|
|
265
|
+
} else {
|
|
266
|
+
bodyScope.delete(nextBinding.value);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return nextBinding;
|
|
270
|
+
}
|
|
271
|
+
const next = foldIrNode(child, bodyScope, mutated);
|
|
272
|
+
if (next !== child) changed = true;
|
|
273
|
+
return next;
|
|
274
|
+
});
|
|
275
|
+
const updated = changed ? { ...node, children: nextChildren } : node;
|
|
276
|
+
const bodyNodes = updated.children.slice(bindingCount);
|
|
277
|
+
if (bodyNodes.length === 1 && isConstantLiteralNode(bodyNodes[0])) {
|
|
278
|
+
const allBindingsPureConstants = updated.children
|
|
279
|
+
.slice(0, bindingCount)
|
|
280
|
+
.every(
|
|
281
|
+
(binding) =>
|
|
282
|
+
binding.kind === "lexical-binding" &&
|
|
283
|
+
binding.properties?.pattern !== true &&
|
|
284
|
+
Array.isArray(binding.children) &&
|
|
285
|
+
binding.children.length === 1 &&
|
|
286
|
+
isConstantLiteralNode(binding.children[0]),
|
|
287
|
+
);
|
|
288
|
+
if (allBindingsPureConstants) {
|
|
289
|
+
return bodyNodes[0];
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return updated;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
296
|
+
let changed = false;
|
|
297
|
+
const optimizedChildren = node.children.map((child) => {
|
|
298
|
+
const next = foldIrNode(child, env, mutated);
|
|
299
|
+
if (next !== child) changed = true;
|
|
300
|
+
return next;
|
|
301
|
+
});
|
|
302
|
+
if (changed) {
|
|
303
|
+
node = { ...node, children: optimizedChildren };
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const children = node.children ?? [];
|
|
308
|
+
if (node.kind === "conditional" && children.length >= 2) {
|
|
309
|
+
const truthy = literalTruthiness(children[0]);
|
|
310
|
+
if (truthy === true) return children[1];
|
|
311
|
+
if (truthy === false) {
|
|
312
|
+
return (
|
|
313
|
+
children[2] ?? {
|
|
314
|
+
kind: "literal",
|
|
315
|
+
span: node.span,
|
|
316
|
+
value: null,
|
|
317
|
+
children: [],
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (node.kind === "short-circuit" && children.length > 0) {
|
|
324
|
+
if (node.value === "and") {
|
|
325
|
+
const remaining = [];
|
|
326
|
+
for (let index = 0; index < children.length; index += 1) {
|
|
327
|
+
const child = children[index];
|
|
328
|
+
const truthy = literalTruthiness(child);
|
|
329
|
+
if (truthy === false && remaining.length === 0) {
|
|
330
|
+
return child;
|
|
331
|
+
}
|
|
332
|
+
if (truthy === true && index < children.length - 1) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
remaining.push(child);
|
|
336
|
+
}
|
|
337
|
+
if (remaining.length === 1) return remaining[0];
|
|
338
|
+
if (remaining.length !== children.length) {
|
|
339
|
+
return { ...node, children: remaining };
|
|
340
|
+
}
|
|
341
|
+
} else if (node.value === "or") {
|
|
342
|
+
const remaining = [];
|
|
343
|
+
for (let index = 0; index < children.length; index += 1) {
|
|
344
|
+
const child = children[index];
|
|
345
|
+
const truthy = literalTruthiness(child);
|
|
346
|
+
if (truthy === true && remaining.length === 0) {
|
|
347
|
+
return child;
|
|
348
|
+
}
|
|
349
|
+
if (truthy === false && index < children.length - 1) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
remaining.push(child);
|
|
353
|
+
}
|
|
354
|
+
if (remaining.length === 1) return remaining[0];
|
|
355
|
+
if (remaining.length !== children.length) {
|
|
356
|
+
return { ...node, children: remaining };
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (node.kind === "intrinsic") {
|
|
362
|
+
if (node.value === "not" && children.length === 1) {
|
|
363
|
+
const truthy = literalTruthiness(children[0]);
|
|
364
|
+
if (truthy !== null) {
|
|
365
|
+
return {
|
|
366
|
+
kind: "literal",
|
|
367
|
+
span: node.span,
|
|
368
|
+
value: !truthy,
|
|
369
|
+
children: [],
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (
|
|
375
|
+
(node.value === "null" ||
|
|
376
|
+
node.value === "nil?" ||
|
|
377
|
+
node.value === "undefined?" ||
|
|
378
|
+
node.value === "nullish?") &&
|
|
379
|
+
children.length === 1 &&
|
|
380
|
+
isConstantLiteralNode(children[0])
|
|
381
|
+
) {
|
|
382
|
+
const raw = literalRuntimeValue(children[0]);
|
|
383
|
+
const result =
|
|
384
|
+
node.value === "undefined?"
|
|
385
|
+
? raw === undefined
|
|
386
|
+
: node.value === "nullish?"
|
|
387
|
+
? raw === null || raw === undefined
|
|
388
|
+
: raw === null;
|
|
389
|
+
return {
|
|
390
|
+
kind: "literal",
|
|
391
|
+
span: node.span,
|
|
392
|
+
value: result,
|
|
393
|
+
children: [],
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (
|
|
398
|
+
(node.value === "=" ||
|
|
399
|
+
node.value === "/=" ||
|
|
400
|
+
node.value === "not=" ||
|
|
401
|
+
node.value === "eq" ||
|
|
402
|
+
node.value === "equal") &&
|
|
403
|
+
children.length === 2 &&
|
|
404
|
+
isConstantLiteralNode(children[0]) &&
|
|
405
|
+
isConstantLiteralNode(children[1])
|
|
406
|
+
) {
|
|
407
|
+
const left = literalRuntimeValue(children[0]);
|
|
408
|
+
const right = literalRuntimeValue(children[1]);
|
|
409
|
+
const same = left === right;
|
|
410
|
+
return {
|
|
411
|
+
kind: "literal",
|
|
412
|
+
span: node.span,
|
|
413
|
+
value: node.value === "/=" || node.value === "not=" ? !same : same,
|
|
414
|
+
children: [],
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (
|
|
419
|
+
(node.value === "<" ||
|
|
420
|
+
node.value === "<=" ||
|
|
421
|
+
node.value === ">" ||
|
|
422
|
+
node.value === ">=") &&
|
|
423
|
+
children.length === 2 &&
|
|
424
|
+
isPlainLiteralNode(children[0]) &&
|
|
425
|
+
isPlainLiteralNode(children[1]) &&
|
|
426
|
+
typeof children[0].value === "number" &&
|
|
427
|
+
typeof children[1].value === "number"
|
|
428
|
+
) {
|
|
429
|
+
const left = children[0].value;
|
|
430
|
+
const right = children[1].value;
|
|
431
|
+
const compared =
|
|
432
|
+
node.value === "<"
|
|
433
|
+
? left < right
|
|
434
|
+
: node.value === "<="
|
|
435
|
+
? left <= right
|
|
436
|
+
: node.value === ">"
|
|
437
|
+
? left > right
|
|
438
|
+
: left >= right;
|
|
439
|
+
return {
|
|
440
|
+
kind: "literal",
|
|
441
|
+
span: node.span,
|
|
442
|
+
value: compared,
|
|
443
|
+
children: [],
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (
|
|
448
|
+
children.every(
|
|
449
|
+
(child) => isPlainLiteralNode(child) && typeof child.value === "number",
|
|
450
|
+
)
|
|
451
|
+
) {
|
|
452
|
+
const values = children.map((child) => child.value);
|
|
453
|
+
let folded;
|
|
454
|
+
switch (node.value) {
|
|
455
|
+
case "+":
|
|
456
|
+
folded = values.reduce((sum, item) => sum + item, 0);
|
|
457
|
+
break;
|
|
458
|
+
case "*":
|
|
459
|
+
folded = values.reduce((product, item) => product * item, 1);
|
|
460
|
+
break;
|
|
461
|
+
case "-":
|
|
462
|
+
if (values.length === 1) folded = -values[0];
|
|
463
|
+
else if (values.length >= 2) {
|
|
464
|
+
folded = values.slice(1).reduce((acc, item) => acc - item, values[0]);
|
|
465
|
+
}
|
|
466
|
+
break;
|
|
467
|
+
case "/":
|
|
468
|
+
if (values.length === 2 && values[1] !== 0) {
|
|
469
|
+
folded = values[0] / values[1];
|
|
470
|
+
}
|
|
471
|
+
break;
|
|
472
|
+
case "%":
|
|
473
|
+
if (values.length === 2 && values[1] !== 0) {
|
|
474
|
+
folded = values[0] % values[1];
|
|
475
|
+
}
|
|
476
|
+
break;
|
|
477
|
+
case "1+":
|
|
478
|
+
if (values.length === 1) folded = values[0] + 1;
|
|
479
|
+
break;
|
|
480
|
+
case "1-":
|
|
481
|
+
if (values.length === 1) folded = values[0] - 1;
|
|
482
|
+
break;
|
|
483
|
+
default:
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
if (typeof folded === "number" && Number.isFinite(folded)) {
|
|
487
|
+
return {
|
|
488
|
+
kind: "literal",
|
|
489
|
+
span: node.span,
|
|
490
|
+
value: folded,
|
|
491
|
+
children: [],
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (node.value === "+" && children.length >= 2) {
|
|
497
|
+
const nonZero = children.filter(
|
|
498
|
+
(child) => !(isPlainLiteralNode(child) && child.value === 0),
|
|
499
|
+
);
|
|
500
|
+
if (nonZero.length > 0 && nonZero.length < children.length) {
|
|
501
|
+
return nonZero.length === 1
|
|
502
|
+
? nonZero[0]
|
|
503
|
+
: { ...node, children: nonZero };
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (node.value === "*" && children.length >= 2) {
|
|
508
|
+
const nonOne = children.filter(
|
|
509
|
+
(child) => !(isPlainLiteralNode(child) && child.value === 1),
|
|
510
|
+
);
|
|
511
|
+
if (nonOne.length > 0 && nonOne.length < children.length) {
|
|
512
|
+
return nonOne.length === 1 ? nonOne[0] : { ...node, children: nonOne };
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
if (
|
|
518
|
+
node.kind === "string-concat" &&
|
|
519
|
+
children.every(
|
|
520
|
+
(child) =>
|
|
521
|
+
isPlainLiteralNode(child) &&
|
|
522
|
+
(typeof child.value === "string" ||
|
|
523
|
+
typeof child.value === "number" ||
|
|
524
|
+
typeof child.value === "boolean" ||
|
|
525
|
+
child.value === null),
|
|
526
|
+
)
|
|
527
|
+
) {
|
|
528
|
+
return {
|
|
529
|
+
kind: "literal",
|
|
530
|
+
span: node.span,
|
|
531
|
+
value: children
|
|
532
|
+
.map((child) => (child.value === null ? "" : String(child.value)))
|
|
533
|
+
.join(""),
|
|
534
|
+
children: [],
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
return node;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Performs a Closure-style IR optimization pass (constant propagation,
|
|
543
|
+
* constant folding, algebraic identity simplification, and dead conditional
|
|
544
|
+
* branch elimination) over a compiled Eliscript IR program.
|
|
545
|
+
*/
|
|
546
|
+
export function optimizeProgramIr(program) {
|
|
547
|
+
if (program === null || typeof program !== "object" || !Array.isArray(program.body)) {
|
|
548
|
+
return program;
|
|
549
|
+
}
|
|
550
|
+
const mutated = collectMutatedNames(program);
|
|
551
|
+
const topScope = new Map();
|
|
552
|
+
program.body = program.body.map((node) => {
|
|
553
|
+
const next = foldIrNode(node, topScope, mutated);
|
|
554
|
+
if (
|
|
555
|
+
next.kind === "variable-declaration" &&
|
|
556
|
+
next.properties?.mutable !== true &&
|
|
557
|
+
typeof next.value === "string" &&
|
|
558
|
+
!mutated.has(next.value) &&
|
|
559
|
+
Array.isArray(next.children) &&
|
|
560
|
+
next.children.length === 1 &&
|
|
561
|
+
isConstantLiteralNode(next.children[0])
|
|
562
|
+
) {
|
|
563
|
+
topScope.set(next.value, next.children[0]);
|
|
564
|
+
}
|
|
565
|
+
return next;
|
|
566
|
+
});
|
|
567
|
+
return program;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function isIdentifierChar(ch) {
|
|
571
|
+
if (!ch) return false;
|
|
572
|
+
const code = ch.charCodeAt(0);
|
|
573
|
+
return (
|
|
574
|
+
(code >= 48 && code <= 57) ||
|
|
575
|
+
(code >= 65 && code <= 90) ||
|
|
576
|
+
(code >= 97 && code <= 122) ||
|
|
577
|
+
code === 36 ||
|
|
578
|
+
code === 95 ||
|
|
579
|
+
code > 127
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function compactLineWhitespace(line) {
|
|
584
|
+
if (line.startsWith("//# sourceMappingURL=")) return line;
|
|
585
|
+
let result = "";
|
|
586
|
+
let index = 0;
|
|
587
|
+
const length = line.length;
|
|
588
|
+
while (index < length) {
|
|
589
|
+
const ch = line[index];
|
|
590
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
591
|
+
const quote = ch;
|
|
592
|
+
result += ch;
|
|
593
|
+
index += 1;
|
|
594
|
+
while (index < length) {
|
|
595
|
+
const cur = line[index];
|
|
596
|
+
result += cur;
|
|
597
|
+
index += 1;
|
|
598
|
+
if (cur === "\\" && index < length) {
|
|
599
|
+
result += line[index];
|
|
600
|
+
index += 1;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (cur === quote) break;
|
|
604
|
+
}
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
if (ch === " " || ch === "\t") {
|
|
608
|
+
while (index < length && (line[index] === " " || line[index] === "\t")) {
|
|
609
|
+
index += 1;
|
|
610
|
+
}
|
|
611
|
+
const prev = result[result.length - 1] ?? "";
|
|
612
|
+
const next = line[index] ?? "";
|
|
613
|
+
if (
|
|
614
|
+
(isIdentifierChar(prev) && isIdentifierChar(next)) ||
|
|
615
|
+
(prev === "+" && next === "+") ||
|
|
616
|
+
(prev === "-" && next === "-") ||
|
|
617
|
+
(prev === "/" && (next === "/" || next === "*"))
|
|
618
|
+
) {
|
|
619
|
+
result += " ";
|
|
620
|
+
}
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
result += ch;
|
|
624
|
+
index += 1;
|
|
625
|
+
}
|
|
626
|
+
return result;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Strips comments and compacts whitespace in emitted JavaScript while
|
|
631
|
+
* preserving string/template literals and sourceMappingURL directives.
|
|
632
|
+
*/
|
|
633
|
+
export function optimizeJavaScript(code) {
|
|
634
|
+
if (typeof code !== "string" || code.length === 0) return code;
|
|
635
|
+
let out = "";
|
|
636
|
+
let index = 0;
|
|
637
|
+
const length = code.length;
|
|
638
|
+
|
|
639
|
+
while (index < length) {
|
|
640
|
+
const ch = code[index];
|
|
641
|
+
const next = code[index + 1];
|
|
642
|
+
|
|
643
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
644
|
+
const quote = ch;
|
|
645
|
+
out += ch;
|
|
646
|
+
index += 1;
|
|
647
|
+
while (index < length) {
|
|
648
|
+
const current = code[index];
|
|
649
|
+
out += current;
|
|
650
|
+
index += 1;
|
|
651
|
+
if (current === "\\" && index < length) {
|
|
652
|
+
out += code[index];
|
|
653
|
+
index += 1;
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
if (current === quote) break;
|
|
657
|
+
}
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
if (ch === "/" && next === "/") {
|
|
662
|
+
const lineEnd = code.indexOf("\n", index + 2);
|
|
663
|
+
const comment = lineEnd < 0 ? code.slice(index) : code.slice(index, lineEnd);
|
|
664
|
+
if (comment.startsWith("//# sourceMappingURL=")) {
|
|
665
|
+
out += comment;
|
|
666
|
+
}
|
|
667
|
+
index = lineEnd < 0 ? length : lineEnd;
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (ch === "/" && next === "*") {
|
|
672
|
+
const closeIndex = code.indexOf("*/", index + 2);
|
|
673
|
+
if (closeIndex < 0) break;
|
|
674
|
+
const block = code.slice(index + 2, closeIndex);
|
|
675
|
+
out += block.includes("\n") ? "\n" : " ";
|
|
676
|
+
index = closeIndex + 2;
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
out += ch;
|
|
681
|
+
index += 1;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const lines = out
|
|
685
|
+
.split("\n")
|
|
686
|
+
.map((line) => compactLineWhitespace(line.trim()))
|
|
687
|
+
.filter((line) => line.length > 0);
|
|
688
|
+
return lines.length === 0 ? "" : `${lines.join("\n")}\n`;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
function applyPostCompileOptimization(javascript, sourceMap, meta, options = {}) {
|
|
692
|
+
let code =
|
|
693
|
+
options.minify === true || options.optimize === "compact"
|
|
694
|
+
? optimizeJavaScript(javascript)
|
|
695
|
+
: javascript;
|
|
696
|
+
let map = sourceMap;
|
|
697
|
+
if (typeof options.closureCompiler === "function") {
|
|
698
|
+
const transformed = options.closureCompiler(code, {
|
|
699
|
+
...meta,
|
|
700
|
+
sourceMap: map,
|
|
701
|
+
});
|
|
702
|
+
if (typeof transformed === "string") {
|
|
703
|
+
code = transformed;
|
|
704
|
+
} else if (transformed !== null && typeof transformed === "object") {
|
|
705
|
+
if (typeof transformed.javascript === "string") code = transformed.javascript;
|
|
706
|
+
if (typeof transformed.sourceMap === "string") map = transformed.sourceMap;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return { javascript: code, sourceMap: map };
|
|
710
|
+
}
|
|
711
|
+
|
|
111
712
|
function localSourceSpecifier(specifier) {
|
|
112
713
|
return specifier.startsWith(".") && specifier.endsWith(SOURCE_EXTENSION);
|
|
113
714
|
}
|
|
@@ -189,6 +790,16 @@ function failure(code, message, filename) {
|
|
|
189
790
|
// point the runtime at a served directory without an import map;
|
|
190
791
|
// - anything `resolveExternal` declines stays as written, which is what a
|
|
191
792
|
// third-party package import needs.
|
|
793
|
+
function normalizePackageSubpath(specifier) {
|
|
794
|
+
if (
|
|
795
|
+
/^eliscript\/(?:runtime|platform|dist\/stdlib|stdlib)\//u.test(specifier) &&
|
|
796
|
+
!/\.[a-z0-9]+$/iu.test(specifier)
|
|
797
|
+
) {
|
|
798
|
+
return `${specifier}${OUTPUT_EXTENSION}`;
|
|
799
|
+
}
|
|
800
|
+
return specifier;
|
|
801
|
+
}
|
|
802
|
+
|
|
192
803
|
function rewriteSpecifiers(program, source, resolveExternal) {
|
|
193
804
|
for (const node of importSpecifiers(program)) {
|
|
194
805
|
const specifier = node.value;
|
|
@@ -200,7 +811,9 @@ function rewriteSpecifiers(program, source, resolveExternal) {
|
|
|
200
811
|
continue;
|
|
201
812
|
}
|
|
202
813
|
if (specifier.startsWith(".") || specifier.startsWith("/")) continue;
|
|
203
|
-
const
|
|
814
|
+
const normalized = normalizePackageSubpath(specifier);
|
|
815
|
+
node.value = normalized;
|
|
816
|
+
const external = resolveExternal?.(normalized, source);
|
|
204
817
|
if (typeof external === "string" && external.length > 0) node.value = external;
|
|
205
818
|
}
|
|
206
819
|
}
|
|
@@ -216,6 +829,9 @@ export function compileSource(
|
|
|
216
829
|
options = {},
|
|
217
830
|
) {
|
|
218
831
|
const program = compile_ir_string(source, filename, options.macroContext ?? null);
|
|
832
|
+
if (options.optimize !== false) {
|
|
833
|
+
optimizeProgramIr(program);
|
|
834
|
+
}
|
|
219
835
|
rewriteSpecifiers(program, filename, options.resolveExternal);
|
|
220
836
|
const output = outputPathFor(filename);
|
|
221
837
|
const emission = emit_ir_string_with_source_map(
|
|
@@ -224,14 +840,17 @@ export function compileSource(
|
|
|
224
840
|
output,
|
|
225
841
|
mapSourcePath(output, filename),
|
|
226
842
|
);
|
|
227
|
-
|
|
228
|
-
javascript
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
843
|
+
const rewritten = rewriteEmittedExternals(
|
|
844
|
+
emission.javascript,
|
|
845
|
+
filename,
|
|
846
|
+
options.resolveExternal,
|
|
847
|
+
);
|
|
848
|
+
return applyPostCompileOptimization(
|
|
849
|
+
rewritten,
|
|
850
|
+
emission.sourceMap,
|
|
851
|
+
{ filename, output },
|
|
852
|
+
options,
|
|
853
|
+
);
|
|
235
854
|
}
|
|
236
855
|
|
|
237
856
|
/**
|
|
@@ -247,6 +866,9 @@ export function compileProject({
|
|
|
247
866
|
entry,
|
|
248
867
|
macroContext = null,
|
|
249
868
|
resolveExternal,
|
|
869
|
+
optimize = true,
|
|
870
|
+
minify = false,
|
|
871
|
+
closureCompiler,
|
|
250
872
|
}) {
|
|
251
873
|
for (const path of Object.keys(files)) outputPathFor(path);
|
|
252
874
|
if (files[entry] === undefined) {
|
|
@@ -262,6 +884,9 @@ export function compileProject({
|
|
|
262
884
|
let program;
|
|
263
885
|
try {
|
|
264
886
|
program = compile_ir_string(files[id], id, macroContext);
|
|
887
|
+
if (optimize !== false) {
|
|
888
|
+
optimizeProgramIr(program);
|
|
889
|
+
}
|
|
265
890
|
} catch (error) {
|
|
266
891
|
throw new BrowserCompileError([diagnosticOf(error, id)]);
|
|
267
892
|
}
|
|
@@ -284,11 +909,18 @@ export function compileProject({
|
|
|
284
909
|
output,
|
|
285
910
|
mapSourcePath(output, id),
|
|
286
911
|
);
|
|
912
|
+
const rewritten = rewriteEmittedExternals(emission.javascript, id, resolveExternal);
|
|
913
|
+
const optimized = applyPostCompileOptimization(
|
|
914
|
+
rewritten,
|
|
915
|
+
emission.sourceMap,
|
|
916
|
+
{ filename: id, output },
|
|
917
|
+
{ optimize, minify, closureCompiler },
|
|
918
|
+
);
|
|
287
919
|
modules[output] = {
|
|
288
920
|
id,
|
|
289
921
|
source: files[id],
|
|
290
|
-
javascript:
|
|
291
|
-
sourceMap:
|
|
922
|
+
javascript: optimized.javascript,
|
|
923
|
+
sourceMap: optimized.sourceMap,
|
|
292
924
|
};
|
|
293
925
|
}
|
|
294
926
|
return { plan, modules };
|
|
@@ -351,6 +983,95 @@ export function moduleGraphUrls(modules, entry) {
|
|
|
351
983
|
return { entryUrl, urls, release };
|
|
352
984
|
}
|
|
353
985
|
|
|
986
|
+
/**
|
|
987
|
+
* Compiles one Eliscript module in memory and executes it immediately via a
|
|
988
|
+
* temporary Blob URL.
|
|
989
|
+
*
|
|
990
|
+
* @param {string} source Eliscript source text
|
|
991
|
+
* @param {string} [filename="module.eli"] virtual filename for diagnostics/maps
|
|
992
|
+
* @param {object} [options={}] compilation options (e.g., resolveExternal)
|
|
993
|
+
* @returns {Promise<{ module: object, javascript: string, sourceMap: string }>}
|
|
994
|
+
*/
|
|
995
|
+
export async function runSource(
|
|
996
|
+
source,
|
|
997
|
+
filename = `module${SOURCE_EXTENSION}`,
|
|
998
|
+
options = {},
|
|
999
|
+
) {
|
|
1000
|
+
const compiled = compileSource(source, filename, options);
|
|
1001
|
+
const url = URL.createObjectURL(
|
|
1002
|
+
new Blob([compiled.javascript], { type: "text/javascript" }),
|
|
1003
|
+
);
|
|
1004
|
+
try {
|
|
1005
|
+
const module = await import(url);
|
|
1006
|
+
return {
|
|
1007
|
+
module,
|
|
1008
|
+
javascript: compiled.javascript,
|
|
1009
|
+
sourceMap: compiled.sourceMap,
|
|
1010
|
+
};
|
|
1011
|
+
} finally {
|
|
1012
|
+
URL.revokeObjectURL(url);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function scriptFilename(script, index) {
|
|
1017
|
+
const explicit = script?.getAttribute?.("data-filename") || script?.dataset?.filename;
|
|
1018
|
+
if (typeof explicit === "string" && explicit.trim().length > 0) {
|
|
1019
|
+
const name = explicit.trim();
|
|
1020
|
+
return name.endsWith(SOURCE_EXTENSION) ? name : `${name}${SOURCE_EXTENSION}`;
|
|
1021
|
+
}
|
|
1022
|
+
if (typeof script?.src === "string" && script.src.length > 0) {
|
|
1023
|
+
try {
|
|
1024
|
+
const url = new URL(script.src, globalThis.location?.href ?? "http://localhost/");
|
|
1025
|
+
const tail = url.pathname.split("/").filter(Boolean).pop();
|
|
1026
|
+
if (tail && tail.endsWith(SOURCE_EXTENSION)) return tail;
|
|
1027
|
+
} catch {}
|
|
1028
|
+
}
|
|
1029
|
+
return `inline-${index + 1}${SOURCE_EXTENSION}`;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* Scans a DOM root for `<script type="text/eliscript">` elements (both inline
|
|
1034
|
+
* and external `src="..."`) and compiles + executes each one in document order.
|
|
1035
|
+
*
|
|
1036
|
+
* @param {ParentNode} [root=globalThis.document]
|
|
1037
|
+
* @param {object} [options={}]
|
|
1038
|
+
* @returns {Promise<Array<{ script: Element, filename: string, module: object, javascript: string, sourceMap: string }>>}
|
|
1039
|
+
*/
|
|
1040
|
+
export async function mountEliscriptScripts(
|
|
1041
|
+
root = globalThis.document,
|
|
1042
|
+
options = {},
|
|
1043
|
+
) {
|
|
1044
|
+
if (!root || typeof root.querySelectorAll !== "function") return [];
|
|
1045
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
1046
|
+
const scripts = Array.from(root.querySelectorAll('script[type="text/eliscript"]'));
|
|
1047
|
+
const mounted = [];
|
|
1048
|
+
for (let index = 0; index < scripts.length; index += 1) {
|
|
1049
|
+
const script = scripts[index];
|
|
1050
|
+
if (script.dataset?.eliscriptMounted === "true") continue;
|
|
1051
|
+
if (script.dataset) script.dataset.eliscriptMounted = "true";
|
|
1052
|
+
const filename = scriptFilename(script, index);
|
|
1053
|
+
let source = script.textContent ?? "";
|
|
1054
|
+
if (typeof script.src === "string" && script.src.length > 0) {
|
|
1055
|
+
const response = await fetchImpl(script.src);
|
|
1056
|
+
if (!response.ok) {
|
|
1057
|
+
throw failure(
|
|
1058
|
+
"ELI-BROWSER-0005",
|
|
1059
|
+
`failed to fetch ${script.src}: ${response.status}`,
|
|
1060
|
+
filename,
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
source = await response.text();
|
|
1064
|
+
}
|
|
1065
|
+
const executed = await runSource(source, filename, options);
|
|
1066
|
+
mounted.push({
|
|
1067
|
+
script,
|
|
1068
|
+
filename,
|
|
1069
|
+
...executed,
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
return mounted;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
354
1075
|
export const browserHostSurface = Object.freeze({
|
|
355
1076
|
sourceExtension: SOURCE_EXTENSION,
|
|
356
1077
|
outputExtension: OUTPUT_EXTENSION,
|