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
|
@@ -13,7 +13,35 @@
|
|
|
13
13
|
(require 'subr-x)
|
|
14
14
|
(require 'eliscript-diagnostic)
|
|
15
15
|
(require 'eliscript-parameters)
|
|
16
|
-
|
|
16
|
+
(require 'eliscript-ir)
|
|
17
|
+
|
|
18
|
+
(declare-function eliscript-ir-emitter--binding-initializer "eliscript-ir-emitter" (node))
|
|
19
|
+
(declare-function eliscript-ir-emitter--children "eliscript-ir-emitter" (node))
|
|
20
|
+
(declare-function eliscript-ir-emitter--split-counted-children "eliscript-ir-emitter" (node property))
|
|
21
|
+
|
|
22
|
+
;; Identical capsules share cycle guards and deterministic Number method
|
|
23
|
+
;; formatting without replacing global prototypes or native function values.
|
|
24
|
+
(defconst eliscript-emitter--array-text-import
|
|
25
|
+
"import { c as __eliscript_at, d as __eliscript_at_direct } from \"data:text/javascript;base64,dmFyIG09UmVmbGVjdC5hcHBseSx0dD1OdW1iZXIucHJvdG90eXBlLnZhbHVlT2Ysaj1OdW1iZXIucHJvdG90eXBlLnRvU3RyaW5nLFU9TnVtYmVyLG50PU9iamVjdC5jcmVhdGUsaD1CaWdJbnQsZXQ9RGF0YVZpZXcsb3Q9QXJyYXlCdWZmZXIsaXQ9RGF0YVZpZXcucHJvdG90eXBlLnNldEZsb2F0NjQsSj1EYXRhVmlldy5wcm90b3R5cGUuZ2V0VWludDMyLHJ0PVJhbmdlRXJyb3I7ZnVuY3Rpb24gY3QodCxuKXtsZXQgZT1oKG4pLG89aCh0KSxpPSIiO2lmKG88MG4pbz0tbztkb3tsZXQgZj1vJWU7aT0iMDEyMzQ1Njc4OWFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6IltVKGYpXStpLG8vPWV9d2hpbGUobyE9PTBuKTtyZXR1cm4gdDwwPyItIitpOml9ZnVuY3Rpb24gc3QodCxuKXtsZXQgZT1uZXcgZXQobmV3IG90KDgpKTttKGl0LGUsWzAsdCwhMV0pO2xldCBvPW0oSixlLFswLCExXSksaT1tKEosZSxbNCwhMV0pLGY9bz4+PjIwJjIwNDcsYj1vJjEwNDg1NzUscD1vPj4+MzEscj1oKGIpPDwzMm58aChpKTtpZihmIT09MClyKz0xbjw8NTJuO3I8PD0ybjtsZXQgbD00bix1PWY+MSYmYj09PTAmJmk9PT0wPzFuOjJuLGs9Mm47aWYoZj49MTA3NSl7bGV0IGM9aChmLTEwNzUpO3I8PD1jLHU8PD1jLGs8PD1jfWVsc2UgbDw8PWgoZj09PTA/MTA3NDoxMDc1LWYpO2xldCBkPWgobiksZz1udChudWxsKSxhPTAsUz0wLEQ9MDtpZihyPGwpd2hpbGUocjxsKXtpZihyKjJuPmwmJnIraz5sKWJyZWFrO3IqPWQsdSo9ZCxrKj1kLFMtLX1lbHNlIHdoaWxlKHI+PWwqZClsKj1kLFMrKztmb3IoOzspe2xldCBjPVUoci9sKTtyJT1sO2xldCBJPXI8dSx4PXIraz5sO2dbYSsrXT1jLEQ9RCoobiYxKStjJjE7bGV0IHE9cioybixQPXE+bHx8cT09PWwmJkQ9PT0xO2lmKFAmJnh8fCFQJiZJKXtpZihQKXtsZXQgUj1hLEI9ITA7d2hpbGUoUj4wJiZCKXtSLS07bGV0IEg9Z1tSXSsxO2lmKEg9PT1uKWdbUl09MDtlbHNlIGdbUl09SCxCPSExfWlmKEIpZ1swXT0xLFMrK31icmVha31pZihhPj02NCl0aHJvdyBuZXcgcnQoIm51bWJlciByYWRpeCBmb3JtYXR0aW5nIGRpZCBub3QgY29udmVyZ2UiKTtyKj1kLHUqPWQsayo9ZH13aGlsZShhPjEmJmdbYS0xXT09PTApYS0tO2xldCB3PSIiO2lmKFM8MCl7dz0iMC4iO2ZvcihsZXQgYz0wO2M8LTEtUztjKyspdys9IjAiO2ZvcihsZXQgYz0wO2M8YTtjKyspdys9IjAxMjM0NTY3ODlhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5eiJbZ1tjXV19ZWxzZXtsZXQgYz1TKzEsST1jPmE/YzphO2ZvcihsZXQgeD0wO3g8STt4Kyspe2lmKHg9PT1jJiZjPGEpdys9Ii4iO3crPXg8YT8iMDEyMzQ1Njc4OWFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6IltnW3hdXToiMCJ9fXJldHVybiBwPyItIit3Ond9ZnVuY3Rpb24gRyh0LG4pe2xldCBlO3RyeXtlPW0odHQsdCxbXSl9Y2F0Y2h7cmV0dXJuIG0oaix0LFtuXSl9bGV0IG89MTA7aWYobiE9PXZvaWQgMCl7bGV0IGk9K247aWYobz1pIT09aT8wOmktaSUxLG88Mnx8bz4zNnx8byE9PW8pcmV0dXJuIG0oaixlLFtvXSl9aWYobz09PTEwfHxlPT09MHx8ZSE9PWV8fGU9PT0xLzB8fGU9PT0tMS8wKXJldHVybiBtKGosZSxbMTBdKTtyZXR1cm4gZSUxPT09MD9jdChlLG8pOnN0KGUsbyl9dmFyIHM9UmVmbGVjdC5hcHBseSxNPUZ1bmN0aW9uLnByb3RvdHlwZS5jYWxsLE49RnVuY3Rpb24ucHJvdG90eXBlLmFwcGx5LEU9RnVuY3Rpb24ucHJvdG90eXBlLmJpbmQsVD1PYmplY3QuZGVmaW5lUHJvcGVydHksbHQ9T2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcixmdD1PYmplY3QuZ2V0UHJvdG90eXBlT2YsdXQ9T2JqZWN0LnNldFByb3RvdHlwZU9mLGF0PVJlZmxlY3Qub3duS2V5cyxwdD1TeW1ib2wuaGFzSW5zdGFuY2UsVj1BcnJheS5pc0FycmF5LEs9QXJyYXkucHJvdG90eXBlLmpvaW4sej1BcnJheS5wcm90b3R5cGUudG9TdHJpbmcseXQ9T2JqZWN0LnByb3RvdHlwZS50b1N0cmluZyxidD1TdHJpbmcsQz1UeXBlRXJyb3IsZHQ9U3ltYm9sLnRvUHJpbWl0aXZlLGd0PVdlYWtTZXQucHJvdG90eXBlLmhhcyx3dD1XZWFrU2V0LnByb3RvdHlwZS5hZGQseHQ9V2Vha1NldC5wcm90b3R5cGUuZGVsZXRlLEY9bmV3IFdlYWtTZXQsTz1udWxsLFc9KHQpPT50IT09bnVsbCYmKHR5cGVvZiB0PT09Im9iamVjdCJ8fHR5cGVvZiB0PT09ImZ1bmN0aW9uInx8dHlwZW9mIHQ+InUiJiZ0IT09dm9pZCAwKSxBPSh0KT0+dHlwZW9mIHQ9PT0iZnVuY3Rpb24ifHx0eXBlb2YgdD4idSImJnQhPT12b2lkIDA7ZnVuY3Rpb24gaHQoKXtsZXQgbj1uZXcgQygiY3ljbGljIGFycmF5IHRleHQgY29udmVyc2lvbiIpO3Rocm93IG4uZWxpc2NyaXB0RGlhZ25vc3RpYz17Zm9ybWF0OiJlbGlzY3JpcHQtZGlhZ25vc3RpYyIsdmVyc2lvbjoxLGNvZGU6IkVMSS1SVDAwMDkiLHNldmVyaXR5OiJlcnJvciIscGhhc2U6InJ1bnRpbWUiLG1lc3NhZ2U6ImN5Y2xpYyBhcnJheSB0ZXh0IGNvbnZlcnNpb24ifSxufWZ1bmN0aW9uIG10KHQpe2lmKCFXKHQpKXJldHVybiB0O2xldCBuPXRbZHRdO2lmKG4hPT12b2lkIDAmJm4hPT1udWxsKXtsZXQgZT1zKG4sdCxbInN0cmluZyJdKTtpZighVyhlKSlyZXR1cm4gZTt0aHJvdyBuZXcgQygiQ2Fubm90IGNvbnZlcnQgb2JqZWN0IHRvIHByaW1pdGl2ZSB2YWx1ZSIpfWZvcihsZXQgZT0wO2U8MjtlKyspe2xldCBvPXRbZT09PTA/InRvU3RyaW5nIjoidmFsdWVPZiJdO2lmKEEobykpe2xldCBpPW89PT16JiZWKHQpP3YodCk6cyhvLHQsW10pO2lmKCFXKGkpKXJldHVybiBpfX10aHJvdyBuZXcgQygiQ2Fubm90IGNvbnZlcnQgb2JqZWN0IHRvIHByaW1pdGl2ZSB2YWx1ZSIpfWZ1bmN0aW9uIFEodCl7bGV0IG49bXQodCk7aWYodHlwZW9mIG49PT0ic3ltYm9sIil0aHJvdyBuZXcgQygiQ2Fubm90IGNvbnZlcnQgYSBTeW1ib2wgdmFsdWUgdG8gYSBzdHJpbmciKTtyZXR1cm4gYnQobil9ZnVuY3Rpb24gXyh0LG4pe2xldCBlPSt0Lmxlbmd0aCxvPWUhPT1lfHxlPD0wPzA6ZT49OTAwNzE5OTI1NDc0MDk5MT85MDA3MTk5MjU0NzQwOTkxOmUtZSUxLGk9bj09PXZvaWQgMD8iLCI6UShuKSxmPU89PT1udWxsO2lmKGYpTz10O2Vsc2V7aWYodD09PU98fHMoZ3QsRixbdF0pKWh0KCk7cyh3dCxGLFt0XSl9dHJ5e2xldCBiPSIiO2ZvcihsZXQgcD0wO3A8bztwKyspe2lmKHApYis9aTtsZXQgcj10W3BdO2lmKHIhPT1udWxsJiZyIT09dm9pZCAwKWIrPVEocil9cmV0dXJuIGJ9ZmluYWxseXtpZihmKU89bnVsbDtlbHNlIHMoeHQsRixbdF0pfX1mdW5jdGlvbiB2KHQpe2xldCBuPXQuam9pbjtyZXR1cm4gQShuKT9uPT09Sz9fKHQsdm9pZCAwKTpzKG4sdCxbXSk6cyh5dCx0LFtdKX1mdW5jdGlvbiB5KHQsbil7cmV0dXJuIG48dC5sZW5ndGg/dFtuXTp2b2lkIDB9ZnVuY3Rpb24gWCh0LG4pe2xldCBlPVtdO2ZvcihsZXQgbz1uO288dC5sZW5ndGg7bysrKVQoZSxlLmxlbmd0aCx7dmFsdWU6dFtvXSx3cml0YWJsZTohMCxlbnVtZXJhYmxlOiEwLGNvbmZpZ3VyYWJsZTohMH0pO3JldHVybiBlfWZ1bmN0aW9uIFN0KHQsbil7bGV0IGU9W107Zm9yKGxldCBvPTA7bzx0Lmxlbmd0aCtuLmxlbmd0aDtvKyspVChlLG8se3ZhbHVlOm88dC5sZW5ndGg/dFtvXTpuW28tdC5sZW5ndGhdLHdyaXRhYmxlOiEwLGVudW1lcmFibGU6ITAsY29uZmlndXJhYmxlOiEwfSk7cmV0dXJuIGV9ZnVuY3Rpb24gWSguLi50KXtyZXR1cm4gdH1mdW5jdGlvbiBaKHQsbil7cmV0dXJuIG4/cyhOLFksW3ZvaWQgMCx0XSk6cyhZLHZvaWQgMCx0KX1mdW5jdGlvbiBMKHQsbixlKXtmb3IoOzspe2lmKHQ9PT1qKXJldHVybiBHKG4seShlLDApKTtpZih0PT09SyYmVihuKSlyZXR1cm4gXyhuLHkoZSwwKSk7aWYodD09PXomJlYobikpcmV0dXJuIHYobik7aWYodD09PU0pe2lmKCFBKG4pKXJldHVybiBzKHQsbixlKTtsZXQgbz1uLGk9eShlLDApO2U9WChlLDEpLHQ9byxuPWk7Y29udGludWV9aWYodD09PU4pe2lmKCFBKG4pKXJldHVybiBzKHQsbixlKTtsZXQgbz1uLGk9eShlLDApO2U9Wih5KGUsMSksITApLHQ9byxuPWk7Y29udGludWV9aWYodD09PXMpe2xldCBvPXkoZSwwKSxpPXkoZSwxKTtpZighQShvKSlyZXR1cm4gcyh0LG4sZSk7ZT1aKHkoZSwyKSwhMSksdD1vLG49aTtjb250aW51ZX1pZih0PT09RSl7bGV0IG89cyh0LG4sZSk7aWYobiE9PWomJm4hPT1LJiZuIT09eiYmbiE9PU0mJm4hPT1OJiZuIT09cyYmbiE9PUUpcmV0dXJuIG87bGV0IGk9bixmPXkoZSwwKSxiPVgoZSwxKSxwPSguLi51KT0+TChpLGYsU3QoYix1KSk7VChwLHB0LHt2YWx1ZToodSk9PnUgaW5zdGFuY2VvZiBpLGNvbmZpZ3VyYWJsZTohMH0pO2xldCByPXMoRSxwLFt2b2lkIDBdKTt1dChyLGZ0KG8pKTtsZXQgbD1hdChvKTtmb3IobGV0IHU9MDt1PGwubGVuZ3RoO3UrKylUKHIsbFt1XSxsdChvLGxbdV0pKTtyZXR1cm4gcn1yZXR1cm4gcyh0LG4sZSl9fWZ1bmN0aW9uIFJ0KHQsbil7bGV0IGU9dFtuXTtyZXR1cm4oLi4ubyk9PkwoZSx0LG8pfWZ1bmN0aW9uIEF0KHQsbiwuLi5lKXtsZXQgbz10W25dO3JldHVybiBMKG8sdCxlKX1leHBvcnR7UnQgYXMgYyxBdCBhcyBkfTs=\";\n")
|
|
26
|
+
|
|
27
|
+
(defconst eliscript-emitter--number-conversion-intrinsics
|
|
28
|
+
"const __eliscript_number_intrinsic = globalThis.Number;\nconst __eliscript_bigint_intrinsic = globalThis.BigInt;\nconst __eliscript_numeric_apply = globalThis.Reflect.apply;\nconst __eliscript_numeric_symbol = globalThis.Symbol.toPrimitive;\nconst __eliscript_numeric_error = globalThis.TypeError;\nconst __eliscript_numeric_trim = globalThis.String.prototype.trim;\nconst __eliscript_numeric_slice = globalThis.String.prototype.slice;\nconst __eliscript_numeric_exec = globalThis.RegExp.prototype.exec;\n")
|
|
29
|
+
(defconst eliscript-emitter--number-conversion-capsule
|
|
30
|
+
"import { __eliscript_number_intrinsic, __eliscript_bigint_intrinsic, __eliscript_numeric_apply, __eliscript_numeric_symbol, __eliscript_numeric_error, __eliscript_numeric_trim, __eliscript_numeric_slice, __eliscript_numeric_exec } from \"data:text/javascript;base64,ZXhwb3J0IGNvbnN0IF9fZWxpc2NyaXB0X251bWJlcl9pbnRyaW5zaWMgPSBnbG9iYWxUaGlzLk51bWJlcjsKZXhwb3J0IGNvbnN0IF9fZWxpc2NyaXB0X2JpZ2ludF9pbnRyaW5zaWMgPSBnbG9iYWxUaGlzLkJpZ0ludDsKZXhwb3J0IGNvbnN0IF9fZWxpc2NyaXB0X251bWVyaWNfYXBwbHkgPSBnbG9iYWxUaGlzLlJlZmxlY3QuYXBwbHk7CmV4cG9ydCBjb25zdCBfX2VsaXNjcmlwdF9udW1lcmljX3N5bWJvbCA9IGdsb2JhbFRoaXMuU3ltYm9sLnRvUHJpbWl0aXZlOwpleHBvcnQgY29uc3QgX19lbGlzY3JpcHRfbnVtZXJpY19lcnJvciA9IGdsb2JhbFRoaXMuVHlwZUVycm9yOwpleHBvcnQgY29uc3QgX19lbGlzY3JpcHRfbnVtZXJpY190cmltID0gZ2xvYmFsVGhpcy5TdHJpbmcucHJvdG90eXBlLnRyaW07CmV4cG9ydCBjb25zdCBfX2VsaXNjcmlwdF9udW1lcmljX3NsaWNlID0gZ2xvYmFsVGhpcy5TdHJpbmcucHJvdG90eXBlLnNsaWNlOwpleHBvcnQgY29uc3QgX19lbGlzY3JpcHRfbnVtZXJpY19leGVjID0gZ2xvYmFsVGhpcy5SZWdFeHAucHJvdG90eXBlLmV4ZWM7Cg==\";\n")
|
|
31
|
+
(defconst eliscript-emitter--number-conversion-body
|
|
32
|
+
"const __eliscript_numeric_radix = /^(?:0[xX][0-9a-fA-F]+|0[oO][0-7]+|0[bB][01]+)$/;\nconst __eliscript_numeric_object = (value) => value !== null && (typeof value === \"object\" || typeof value === \"function\" || (typeof value === \"undefined\" && value !== void 0));\nconst __eliscript_numeric_primitive = (value) => {\n if (!__eliscript_numeric_object(value)) return value;\n const exotic = value[__eliscript_numeric_symbol];\n if (exotic !== void 0 && exotic !== null) {\n const result = __eliscript_numeric_apply(exotic, value, [\"number\"]);\n if (!__eliscript_numeric_object(result)) return result;\n throw new __eliscript_numeric_error(\"Cannot convert object to primitive value\");\n }\n for (let index = 0; index < 2; index++) {\n const method = value[index === 0 ? \"valueOf\" : \"toString\"];\n if (typeof method === \"function\" || (typeof method === \"undefined\" && method !== void 0)) {\n const result = __eliscript_numeric_apply(method, value, []);\n if (!__eliscript_numeric_object(result)) return result;\n }\n }\n throw new __eliscript_numeric_error(\"Cannot convert object to primitive value\");\n};\nconst __eliscript_to_number = (value) => {\n const primitive = __eliscript_numeric_primitive(value);\n if (typeof primitive === \"string\") {\n const text = __eliscript_numeric_apply(__eliscript_numeric_trim, primitive, []);\n if (__eliscript_numeric_apply(__eliscript_numeric_exec, __eliscript_numeric_radix, [text]) !== null) {\n let first = 2;\n while (first < text.length && text[first] === \"0\") first++;\n if (first === text.length) return 0;\n const prefix = text[1];\n const limit = prefix === \"x\" || prefix === \"X\" ? 256 : prefix === \"b\" || prefix === \"B\" ? 1024 : 342;\n if (text.length - first > limit) return 1 / 0;\n const token = __eliscript_numeric_apply(__eliscript_numeric_slice, text, [0, 2]) + __eliscript_numeric_apply(__eliscript_numeric_slice, text, [first]);\n return __eliscript_number_intrinsic(__eliscript_bigint_intrinsic(token));\n }\n }\n return __eliscript_number_intrinsic(primitive);\n};\n")
|
|
33
|
+
(defconst eliscript-emitter--number-conversion-helper
|
|
34
|
+
(concat eliscript-emitter--number-conversion-intrinsics eliscript-emitter--number-conversion-body)
|
|
35
|
+
"Generated helper for exact nondecimal Number conversion across JS hosts.")
|
|
36
|
+
(defconst eliscript-emitter--numeric-operator-helper
|
|
37
|
+
"const __eliscript_numeric = (value) => {\n if (typeof value === \"number\" || typeof value === \"bigint\") return value;\n const primitive = __eliscript_numeric_primitive(value);\n if (typeof primitive === \"number\" || typeof primitive === \"bigint\") return primitive;\n return typeof primitive === \"string\" ? __eliscript_to_number(primitive) : +primitive;\n};\nconst __eliscript_implicit_number = (value) => {\n if (typeof value === \"number\") return value;\n const primitive = __eliscript_numeric_primitive(value);\n if (typeof primitive === \"bigint\") throw new __eliscript_numeric_error(\"Cannot convert a BigInt value to a number\");\n return typeof primitive === \"string\" ? __eliscript_to_number(primitive) : +primitive;\n};\nconst __eliscript_numeric_decrement = (value) => __eliscript_implicit_number(value) - 1;\nconst __eliscript_numeric_sub = (a, b) => { if (typeof a === \"number\" && typeof b === \"number\") return a - b; return __eliscript_numeric(a) - __eliscript_numeric(b); };\nconst __eliscript_numeric_mul = (a, b) => { if (typeof a === \"number\" && typeof b === \"number\") return a * b; return __eliscript_numeric(a) * __eliscript_numeric(b); };\nconst __eliscript_numeric_div = (a, b) => { if (typeof a === \"number\" && typeof b === \"number\") return a / b; return __eliscript_numeric(a) / __eliscript_numeric(b); };\nconst __eliscript_numeric_rem = (a, b) => { if (typeof a === \"number\" && typeof b === \"number\") return a % b; return __eliscript_numeric(a) % __eliscript_numeric(b); };\nconst __eliscript_numeric_and = (a, b) => { if (typeof a === \"number\" && typeof b === \"number\") return a & b; return __eliscript_numeric(a) & __eliscript_numeric(b); };\nconst __eliscript_numeric_or = (a, b) => { if (typeof a === \"number\" && typeof b === \"number\") return a | b; return __eliscript_numeric(a) | __eliscript_numeric(b); };\nconst __eliscript_numeric_xor = (a, b) => { if (typeof a === \"number\" && typeof b === \"number\") return a ^ b; return __eliscript_numeric(a) ^ __eliscript_numeric(b); };\nconst __eliscript_numeric_shl = (a, b) => { if (typeof a === \"number\" && typeof b === \"number\") return a << b; return __eliscript_numeric(a) << __eliscript_numeric(b); };\nconst __eliscript_numeric_shr = (a, b) => { if (typeof a === \"number\" && typeof b === \"number\") return a >> b; return __eliscript_numeric(a) >> __eliscript_numeric(b); };\nconst __eliscript_numeric_ushr = (a, b) => { if (typeof a === \"number\" && typeof b === \"number\") return a >>> b; return __eliscript_numeric(a) >>> __eliscript_numeric(b); };\nconst __eliscript_numeric_neg = (a) => typeof a === \"number\" ? -a : -__eliscript_numeric(a);\nconst __eliscript_numeric_int32 = (a) => typeof a === \"number\" ? a | 0 : __eliscript_numeric(a) | 0;\nconst __eliscript_numeric_uint32 = (a) => typeof a === \"number\" ? a >>> 0 : __eliscript_numeric(a) >>> 0;\nconst __eliscript_numeric_not = (a) => typeof a === \"number\" ? ~a : ~__eliscript_numeric(a);\nconst __eliscript_numeric_relation = (operator, left, right) => {\n if (typeof left === \"number\" && typeof right === \"number\") {\n if (operator === \"<\") return left < right;\n if (operator === \"<=\") return left <= right;\n if (operator === \">\") return left > right;\n return left >= right;\n }\n let a = __eliscript_numeric_primitive(left);\n let b = __eliscript_numeric_primitive(right);\n const x = typeof a, y = typeof b;\n if (!((x === \"string\" && y === \"string\") || (x === \"bigint\" && y === \"string\") || (x === \"string\" && y === \"bigint\"))) {\n a = __eliscript_numeric(a);\n b = __eliscript_numeric(b);\n }\n if (operator === \"<\") return a < b;\n if (operator === \"<=\") return a <= b;\n if (operator === \">\") return a > b;\n return a >= b;\n};\n"
|
|
38
|
+
"Generated primitive numeric operators with exact coercion ordering.")
|
|
39
|
+
(defconst eliscript-emitter--imul-intrinsic
|
|
40
|
+
"const __eliscript_numeric_imul_intrinsic = globalThis.Math.imul;\n")
|
|
41
|
+
(defconst eliscript-emitter--imul-capsule
|
|
42
|
+
"import { __eliscript_numeric_imul_intrinsic } from \"data:text/javascript;base64,ZXhwb3J0IGNvbnN0IF9fZWxpc2NyaXB0X251bWVyaWNfaW11bF9pbnRyaW5zaWMgPSBnbG9iYWxUaGlzLk1hdGguaW11bDsK\";\n")
|
|
43
|
+
(defconst eliscript-emitter--imul-operator-helper
|
|
44
|
+
"const __eliscript_numeric_imul = (a, b) => __eliscript_numeric_imul_intrinsic(__eliscript_implicit_number(a), __eliscript_implicit_number(b));\n")
|
|
17
45
|
(defconst eliscript-emitter--host-identity-token-helper
|
|
18
46
|
"const __eliscript_host_identity_token = (() => { const objects = new WeakMap(); const symbols = new Map(); let next = 1; return (value) => { const type = typeof value; if ((type !== \"object\" || value === null) && type !== \"function\" && type !== \"symbol\") throw new TypeError(\"host-identity-token expects an object, function, or symbol\"); const identities = type === \"symbol\" ? symbols : objects; const cached = identities.get(value); if (cached !== undefined) return cached; if (next > Number.MAX_SAFE_INTEGER) throw new RangeError(\"host identity token space exhausted\"); const token = next; next += 1; identities.set(value, token); return token; }; })();\n"
|
|
19
47
|
"Generated module helper for process-local opaque host identities.")
|
|
@@ -39,6 +67,224 @@
|
|
|
39
67
|
#'eliscript-symbol-reference-name)
|
|
40
68
|
|
|
41
69
|
(defvar eliscript-emitter--temporary-counter 0)
|
|
70
|
+
(defconst eliscript-emitter--tdz-import "import { tdz as __eliscript_tdz_error, immutable as __eliscript_const_error } from \"data:text/javascript;base64,Y29uc3QgRSA9IFJlZmVyZW5jZUVycm9yOyBjb25zdCBUID0gVHlwZUVycm9yOyBleHBvcnQgZnVuY3Rpb24gdGR6KG5hbWUpIHsgdGhyb3cgbmV3IEUoIkNhbm5vdCBhY2Nlc3MgJyIgKyBuYW1lICsgIicgYmVmb3JlIGluaXRpYWxpemF0aW9uIik7IH0gZXhwb3J0IGZ1bmN0aW9uIGltbXV0YWJsZSgpIHsgdGhyb3cgbmV3IFQoIkFzc2lnbm1lbnQgdG8gY29uc3RhbnQgdmFyaWFibGUuIik7IH0K\";\n")
|
|
71
|
+
;; Private module initialization state is separate from public ESM bindings.
|
|
72
|
+
(defvar eliscript-emitter--tdz-state nil)
|
|
73
|
+
(defconst eliscript-emitter--tdz-read-tag (make-symbol "eliscript-tdz-read"))
|
|
74
|
+
(defconst eliscript-emitter--tdz-write-tag (make-symbol "eliscript-tdz-write"))
|
|
75
|
+
(defconst eliscript-emitter--tdz-assignment-tag (make-symbol "eliscript-tdz-assignment"))
|
|
76
|
+
(defun eliscript-emitter--tdz-ready-name (record)
|
|
77
|
+
(format "__eliscript_tdz_ready_%d" (plist-get record :index)))
|
|
78
|
+
(defun eliscript-emitter--tdz-reader-name (record)
|
|
79
|
+
(format "__eliscript_tdz_read_%d" (plist-get record :index)))
|
|
80
|
+
(defun eliscript-emitter--tdz-writer-name (record)
|
|
81
|
+
(format "__eliscript_tdz_write_%d" (plist-get record :index)))
|
|
82
|
+
(defun eliscript-emitter--tdz-root (name)
|
|
83
|
+
;; Resolve the established emitted binding namespace, just like the
|
|
84
|
+
;; self-hosted emitter. Distinct source spellings can share a JS binding.
|
|
85
|
+
;; Reference mapping also accepts literal symbols, which are never bindings.
|
|
86
|
+
(eliscript-emitter--reference-name
|
|
87
|
+
(intern (car (split-string (symbol-name name) "[./]")))))
|
|
88
|
+
(defun eliscript-emitter--tdz-read-text (record reference)
|
|
89
|
+
(if (null record) (eliscript-emitter--reference-name reference)
|
|
90
|
+
(let* ((name (eliscript-emitter--binding-name (plist-get record :name)))
|
|
91
|
+
(text (eliscript-emitter--reference-name reference)))
|
|
92
|
+
(concat "(" (eliscript-emitter--tdz-reader-name record) "())" (substring text (length name))))))
|
|
93
|
+
(defun eliscript-emitter--tdz-write-text (record name value)
|
|
94
|
+
(if record (concat (eliscript-emitter--tdz-writer-name record) "(" value ")")
|
|
95
|
+
(format "(%s = %s)" (eliscript-emitter--binding-name name) value)))
|
|
96
|
+
(defun eliscript-emitter--tdz-prologue (state)
|
|
97
|
+
(when (plist-get state :variables)
|
|
98
|
+
(concat eliscript-emitter--tdz-import
|
|
99
|
+
(mapconcat
|
|
100
|
+
(lambda (record)
|
|
101
|
+
(let* ((ready (eliscript-emitter--tdz-ready-name record))
|
|
102
|
+
(name (eliscript-emitter--binding-name (plist-get record :name)))
|
|
103
|
+
(argument (format "__eliscript_tdz_value_%d" (plist-get record :index)))
|
|
104
|
+
(quoted (eliscript-emitter--json-string name)))
|
|
105
|
+
(concat "var " ready ";\n"
|
|
106
|
+
"function " (eliscript-emitter--tdz-reader-name record) "() { if (" ready
|
|
107
|
+
" !== true) __eliscript_tdz_error(" quoted "); return " name "; }\n"
|
|
108
|
+
"function " (eliscript-emitter--tdz-writer-name record) "(" argument ") { if (" ready
|
|
109
|
+
" !== true) __eliscript_tdz_error(" quoted "); "
|
|
110
|
+
(if (plist-get record :mutable) (concat "return (" name " = " argument ");") "return __eliscript_const_error();") " }\n")))
|
|
111
|
+
(plist-get state :variables) ""))))
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
(defun eliscript-emitter--tdz-legacy-shadow (pattern scope)
|
|
116
|
+
(let ((pending (list pattern)))
|
|
117
|
+
(while pending
|
|
118
|
+
(let ((item (pop pending)))
|
|
119
|
+
(cond ((and item (symbolp item) (not (keywordp item))
|
|
120
|
+
(not (string-prefix-p "&" (symbol-name item))))
|
|
121
|
+
(puthash (eliscript-emitter--binding-name item) nil scope))
|
|
122
|
+
((vectorp item)
|
|
123
|
+
(let ((index (1- (length item))))
|
|
124
|
+
(while (>= index 0) (push (aref item index) pending) (setq index (1- index))))))))))
|
|
125
|
+
|
|
126
|
+
(defun eliscript-emitter--tdz-legacy-parameters (parameters scope)
|
|
127
|
+
(dolist (parameter parameters) (eliscript-emitter--tdz-legacy-shadow parameter scope)))
|
|
128
|
+
(defun eliscript-emitter--tdz-legacy-predeclare (forms scope state)
|
|
129
|
+
(dolist (form forms)
|
|
130
|
+
(when (consp form)
|
|
131
|
+
(pcase (car form)
|
|
132
|
+
('module (eliscript-emitter--tdz-legacy-predeclare (cddr form) scope state))
|
|
133
|
+
((or 'defvar 'defconst)
|
|
134
|
+
(let ((record (list :index (length (plist-get state :variables)) :name (cadr form) :mutable (eq (car form) 'defvar))))
|
|
135
|
+
(setf (plist-get state :variables) (append (plist-get state :variables) (list record)))
|
|
136
|
+
(puthash form record (plist-get state :declarations))
|
|
137
|
+
(puthash (eliscript-emitter--binding-name (cadr form)) record scope)))
|
|
138
|
+
((or 'defun 'defn 'defasync) (puthash (eliscript-emitter--binding-name (cadr form)) nil scope))
|
|
139
|
+
((or 'import 'import-portable)
|
|
140
|
+
(dolist (name (cddr form))
|
|
141
|
+
(when (and name (symbolp name) (not (keywordp name)))
|
|
142
|
+
(puthash (eliscript-emitter--binding-name name) nil scope))))))))
|
|
143
|
+
(defun eliscript-emitter--tdz-legacy-sequence (forms scope)
|
|
144
|
+
(mapcar (lambda (form) (eliscript-emitter--tdz-legacy-expression form scope)) forms))
|
|
145
|
+
(defun eliscript-emitter--tdz-legacy-expression (form scope)
|
|
146
|
+
"Rewrite ordinary TDZ expression trees using explicit continuations."
|
|
147
|
+
(eliscript-emitter--run-depth-plan #'eliscript-emitter--tdz-depth-plan :expression form scope))
|
|
148
|
+
|
|
149
|
+
(defun eliscript-emitter--tdz-depth-plan (mode value scope)
|
|
150
|
+
(pcase mode
|
|
151
|
+
(:sequence
|
|
152
|
+
(list :children (mapcar (lambda (form) (list :expression form scope)) value)
|
|
153
|
+
(lambda (results) (list :value results))))
|
|
154
|
+
(:bindings
|
|
155
|
+
(let ((remaining (nth 0 value)) (original (nth 1 value)) (reversed (nth 2 value))
|
|
156
|
+
(operator (nth 3 value)) (body (nth 4 value)) (child (nth 5 value)) (sequential (nth 6 value)))
|
|
157
|
+
(if remaining
|
|
158
|
+
(let* ((binding (car remaining)) (parsed (eliscript-emitter--parse-binding binding)) (target (car parsed)))
|
|
159
|
+
(list :children (list (list :expression (cadr parsed) (if sequential child scope)))
|
|
160
|
+
(lambda (results)
|
|
161
|
+
(when sequential (eliscript-emitter--tdz-legacy-shadow target child))
|
|
162
|
+
(list :children
|
|
163
|
+
(list (list :bindings
|
|
164
|
+
(list (cdr remaining) original
|
|
165
|
+
(cons (if (or (symbolp binding) (vectorp binding)) binding (list target (car results))) reversed)
|
|
166
|
+
operator body child sequential) scope))
|
|
167
|
+
(lambda (tail) (list :value (car tail)))))))
|
|
168
|
+
(unless sequential
|
|
169
|
+
(dolist (binding original)
|
|
170
|
+
(eliscript-emitter--tdz-legacy-shadow (car (eliscript-emitter--parse-binding binding)) child)))
|
|
171
|
+
(list :children (list (list :sequence body child))
|
|
172
|
+
(lambda (results) (list :value (cons operator (cons (nreverse reversed) (car results)))))))))
|
|
173
|
+
(:expression
|
|
174
|
+
(cond
|
|
175
|
+
((vectorp value)
|
|
176
|
+
(list :children (list (list :sequence (append value nil) scope))
|
|
177
|
+
(lambda (results) (list :value (vconcat (car results))))))
|
|
178
|
+
((and (consp value) (memq (car value) '(let let* loop)))
|
|
179
|
+
(list :children (list (list :bindings (list (cadr value) (cadr value) nil (car value) (cddr value)
|
|
180
|
+
(copy-hash-table scope) (eq (car value) 'let*)) scope))
|
|
181
|
+
(lambda (results) (list :value (car results)))))
|
|
182
|
+
((and (consp value) (memq (car value) '(lambda fn async)))
|
|
183
|
+
(let ((child (copy-hash-table scope)))
|
|
184
|
+
(eliscript-emitter--tdz-legacy-parameters (cadr value) child)
|
|
185
|
+
(list :children (list (list :sequence (cddr value) child))
|
|
186
|
+
(lambda (results) (list :value (cons (car value) (cons (cadr value) (car results))))))))
|
|
187
|
+
((and (consp value) (not (memq (car value) '(quote js* setq set! try cond js-object))))
|
|
188
|
+
(let* ((operator (car value))
|
|
189
|
+
(fixed (memq operator '(if when unless progn do while recur and or not
|
|
190
|
+
+ * - / % mod = /= not= < <= > >= 1+ 1- eq equal null nil? undefined? nullish?
|
|
191
|
+
int32 uint32 imul32 bit-and bit-or bit-xor bit-not bit-shift-left bit-shift-right unsigned-bit-shift-right
|
|
192
|
+
value-type host-identity-token string-code-unit-at string-from-code-unit string-to-number string-to-bigint number-float64-words
|
|
193
|
+
list vector hash-map hash-set queue js-array car cdr cons js-cons nth js-nth aref length js-length
|
|
194
|
+
new print str object-keys object-has? object-assoc __eliscript_arity_error funcall apply get put js-call await throw))))
|
|
195
|
+
(list :children
|
|
196
|
+
(append (unless fixed (list (list :expression operator scope)))
|
|
197
|
+
(mapcar (lambda (form) (list :expression form scope)) (cdr value)))
|
|
198
|
+
(lambda (results) (list :value (if fixed (cons operator results) results))))))
|
|
199
|
+
(t (list :value (eliscript-emitter--tdz-legacy-expression-recursive value scope)))))
|
|
200
|
+
(_ (error "unknown TDZ continuation mode: %S" mode))))
|
|
201
|
+
|
|
202
|
+
(defun eliscript-emitter--tdz-legacy-expression-recursive (form scope)
|
|
203
|
+
(cond
|
|
204
|
+
((and form (symbolp form) (not (keywordp form)))
|
|
205
|
+
(let ((record (gethash (eliscript-emitter--tdz-root form) scope)))
|
|
206
|
+
(if record (list eliscript-emitter--tdz-read-tag record form) form)))
|
|
207
|
+
((vectorp form) (vconcat (eliscript-emitter--tdz-legacy-sequence (append form nil) scope)))
|
|
208
|
+
((consp form)
|
|
209
|
+
(let ((operator (car form)) (arguments (cdr form)))
|
|
210
|
+
(pcase operator
|
|
211
|
+
((or 'quote 'js*) form)
|
|
212
|
+
((or 'lambda 'fn 'async)
|
|
213
|
+
(let ((child (copy-hash-table scope)))
|
|
214
|
+
(eliscript-emitter--tdz-legacy-parameters (car arguments) child)
|
|
215
|
+
(cons operator (cons (car arguments) (eliscript-emitter--tdz-legacy-sequence (cdr arguments) child)))))
|
|
216
|
+
((or 'let 'let* 'loop)
|
|
217
|
+
(let ((child (copy-hash-table scope)) (sequential (eq operator 'let*)) bindings)
|
|
218
|
+
(dolist (binding (car arguments))
|
|
219
|
+
(let* ((parsed (eliscript-emitter--parse-binding binding))
|
|
220
|
+
(target (car parsed))
|
|
221
|
+
(value (eliscript-emitter--tdz-legacy-expression (cadr parsed) (if sequential child scope))))
|
|
222
|
+
(push (if (or (symbolp binding) (vectorp binding)) binding (list target value)) bindings)
|
|
223
|
+
(when sequential (eliscript-emitter--tdz-legacy-shadow target child))))
|
|
224
|
+
(unless sequential
|
|
225
|
+
(dolist (binding (car arguments))
|
|
226
|
+
(eliscript-emitter--tdz-legacy-shadow (car (eliscript-emitter--parse-binding binding)) child)))
|
|
227
|
+
(cons operator (cons (nreverse bindings) (eliscript-emitter--tdz-legacy-sequence (cdr arguments) child)))))
|
|
228
|
+
((or 'setq 'set!)
|
|
229
|
+
(if (eq operator 'set!) (eliscript-emitter--require-arity "set!" arguments 2 2)
|
|
230
|
+
(when (or (null arguments) (= (% (length arguments) 2) 1))
|
|
231
|
+
(eliscript-emitter--fail "setq expects one or more name/value pairs")))
|
|
232
|
+
(let ((pending arguments) pairs original-pairs guarded)
|
|
233
|
+
(while pending
|
|
234
|
+
(let* ((name (pop pending)) (value (pop pending))
|
|
235
|
+
(record (and (symbolp name) (gethash (eliscript-emitter--tdz-root name) scope)))
|
|
236
|
+
(rewritten (eliscript-emitter--tdz-legacy-expression value scope)))
|
|
237
|
+
(when record (setq guarded t))
|
|
238
|
+
(push (list name rewritten) original-pairs)
|
|
239
|
+
(push (list eliscript-emitter--tdz-write-tag record name rewritten) pairs)))
|
|
240
|
+
(if guarded
|
|
241
|
+
(list eliscript-emitter--tdz-assignment-tag operator (nreverse pairs))
|
|
242
|
+
(cons operator (apply #'append (nreverse original-pairs))))))
|
|
243
|
+
('try
|
|
244
|
+
(cons operator
|
|
245
|
+
(mapcar (lambda (clause)
|
|
246
|
+
(cond
|
|
247
|
+
((and (consp clause) (eq (car clause) 'catch))
|
|
248
|
+
(let ((child (copy-hash-table scope)))
|
|
249
|
+
(eliscript-emitter--tdz-legacy-shadow (cadr clause) child)
|
|
250
|
+
(cons 'catch (cons (cadr clause) (eliscript-emitter--tdz-legacy-sequence (cddr clause) child)))))
|
|
251
|
+
((and (consp clause) (eq (car clause) 'finally))
|
|
252
|
+
(cons 'finally (eliscript-emitter--tdz-legacy-sequence (cdr clause) scope)))
|
|
253
|
+
(t (eliscript-emitter--tdz-legacy-expression clause scope)))) arguments)))
|
|
254
|
+
('cond
|
|
255
|
+
(cons operator (mapcar (lambda (clause) (eliscript-emitter--tdz-legacy-sequence clause scope)) arguments)))
|
|
256
|
+
('js-object
|
|
257
|
+
(let ((pending arguments) fields)
|
|
258
|
+
(while pending
|
|
259
|
+
(let ((key (pop pending)) (value (pop pending)))
|
|
260
|
+
(push (if (or (symbolp key) (stringp key)) key (eliscript-emitter--tdz-legacy-expression key scope)) fields)
|
|
261
|
+
(push (eliscript-emitter--tdz-legacy-expression value scope) fields)))
|
|
262
|
+
(cons operator (nreverse fields))))
|
|
263
|
+
(_
|
|
264
|
+
(cons
|
|
265
|
+
(if (memq operator '(if when unless progn do while recur and or not
|
|
266
|
+
+ * - / % mod = /= not= < <= > >= 1+ 1- eq equal null nil? undefined? nullish?
|
|
267
|
+
int32 uint32 imul32 bit-and bit-or bit-xor bit-not bit-shift-left bit-shift-right unsigned-bit-shift-right
|
|
268
|
+
value-type host-identity-token string-code-unit-at string-from-code-unit string-to-number string-to-bigint number-float64-words
|
|
269
|
+
list vector hash-map hash-set queue js-array car cdr cons js-cons nth js-nth aref length js-length
|
|
270
|
+
new print str object-keys object-has? object-assoc __eliscript_arity_error funcall apply get put js-call await throw))
|
|
271
|
+
operator (eliscript-emitter--tdz-legacy-expression operator scope))
|
|
272
|
+
(eliscript-emitter--tdz-legacy-sequence arguments scope))))))
|
|
273
|
+
(t form)))
|
|
274
|
+
(defun eliscript-emitter--tdz-legacy-top (form scope state)
|
|
275
|
+
(if (not (consp form)) (eliscript-emitter--tdz-legacy-expression form scope)
|
|
276
|
+
(pcase (car form)
|
|
277
|
+
('module (cons 'module (cons (cadr form) (mapcar (lambda (child) (eliscript-emitter--tdz-legacy-top child scope state)) (cddr form)))))
|
|
278
|
+
((or 'import 'import-portable 'export) form)
|
|
279
|
+
((or 'defvar 'defconst)
|
|
280
|
+
(let ((copy (cons (car form) (cons (cadr form) (eliscript-emitter--tdz-legacy-sequence (cddr form) scope)))))
|
|
281
|
+
(puthash copy (gethash form (plist-get state :declarations)) (plist-get state :declarations)) copy))
|
|
282
|
+
((or 'defun 'defn 'defasync)
|
|
283
|
+
(let ((child (copy-hash-table scope)))
|
|
284
|
+
(eliscript-emitter--tdz-legacy-parameters (nth 2 form) child)
|
|
285
|
+
(append (list (car form) (cadr form) (nth 2 form)) (eliscript-emitter--tdz-legacy-sequence (nthcdr 3 form) child))))
|
|
286
|
+
('export-default (cons 'export-default (eliscript-emitter--tdz-legacy-sequence (cdr form) scope)))
|
|
287
|
+
(_ (eliscript-emitter--tdz-legacy-expression form scope)))))
|
|
42
288
|
|
|
43
289
|
(defun eliscript-emitter--fail (format-string &rest arguments)
|
|
44
290
|
"Signal a compiler error using FORMAT-STRING and ARGUMENTS."
|
|
@@ -48,13 +294,62 @@
|
|
|
48
294
|
|
|
49
295
|
(defun eliscript-emitter--json-string (value)
|
|
50
296
|
"Encode string VALUE as an ECMAScript string literal."
|
|
51
|
-
(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
297
|
+
(cl-labels
|
|
298
|
+
((encode (text)
|
|
299
|
+
(let* ((encoded (json-serialize text))
|
|
300
|
+
(decoded
|
|
301
|
+
;; Emacs 30 returns UTF-8 JSON strings as unibyte data. Decode
|
|
302
|
+
;; before composing them with multibyte emitter fragments.
|
|
303
|
+
(if (multibyte-string-p encoded) encoded
|
|
304
|
+
(decode-coding-string encoded 'utf-8-unix)))
|
|
305
|
+
(index 0))
|
|
306
|
+
;; Jansson uses uppercase escape digits; JSON.stringify uses
|
|
307
|
+
;; lowercase. Skip escaped backslashes so literal text such as
|
|
308
|
+
;; "\\u00AB" retains its exact original spelling.
|
|
309
|
+
(while (< index (length decoded))
|
|
310
|
+
(if (= (aref decoded index) ?\\)
|
|
311
|
+
(if (= (aref decoded (1+ index)) ?u)
|
|
312
|
+
(progn
|
|
313
|
+
(dotimes (digit 4)
|
|
314
|
+
(let* ((at (+ index 2 digit)) (unit (aref decoded at)))
|
|
315
|
+
(when (<= ?A unit ?F) (aset decoded at (+ unit 32)))))
|
|
316
|
+
(setq index (+ index 6)))
|
|
317
|
+
(setq index (+ index 2)))
|
|
318
|
+
(setq index (1+ index))))
|
|
319
|
+
decoded)))
|
|
320
|
+
(if (or (not (stringp value))
|
|
321
|
+
(not (cl-find-if (lambda (unit) (<= #xd800 unit #xdfff)) value)))
|
|
322
|
+
(encode value)
|
|
323
|
+
;; Emacs can represent raw UTF16 surrogate code units in a string, but
|
|
324
|
+
;; json-serialize accepts Unicode scalar values only. JSON.stringify
|
|
325
|
+
;; emits isolated halves as lowercase escapes and paired halves as one
|
|
326
|
+
;; scalar. Preserve the serializer's rejection of non-Unicode Emacs
|
|
327
|
+
;; characters rather than treating them as additional UTF16 code units.
|
|
328
|
+
(when (cl-find-if (lambda (unit) (> unit #x10ffff)) value)
|
|
329
|
+
(encode value))
|
|
330
|
+
(with-temp-buffer
|
|
331
|
+
(insert "\"")
|
|
332
|
+
(let ((start 0) (index 0) (size (length value)))
|
|
333
|
+
(while (< index size)
|
|
334
|
+
(let ((unit (aref value index)))
|
|
335
|
+
(if (<= #xd800 unit #xdfff)
|
|
336
|
+
(progn
|
|
337
|
+
(when (< start index)
|
|
338
|
+
(insert (substring (encode (substring value start index)) 1 -1)))
|
|
339
|
+
(if (and (<= unit #xdbff) (< (1+ index) size)
|
|
340
|
+
(<= #xdc00 (aref value (1+ index)) #xdfff))
|
|
341
|
+
(let ((point (+ #x10000 (ash (- unit #xd800) 10)
|
|
342
|
+
(- (aref value (1+ index)) #xdc00))))
|
|
343
|
+
(insert (substring (encode (char-to-string point)) 1 -1))
|
|
344
|
+
(setq index (+ index 2)))
|
|
345
|
+
(insert (format "\\u%04x" unit))
|
|
346
|
+
(setq index (1+ index)))
|
|
347
|
+
(setq start index))
|
|
348
|
+
(setq index (1+ index)))))
|
|
349
|
+
(when (< start size)
|
|
350
|
+
(insert (substring (encode (substring value start size)) 1 -1))))
|
|
351
|
+
(insert "\"")
|
|
352
|
+
(buffer-string)))))
|
|
58
353
|
|
|
59
354
|
(defun eliscript-emitter--fresh-name ()
|
|
60
355
|
"Return a fresh internal ECMAScript identifier."
|
|
@@ -89,10 +384,27 @@
|
|
|
89
384
|
"Emit comma-separated ARGUMENTS."
|
|
90
385
|
(mapconcat #'eliscript-emitter-emit-expression arguments ", "))
|
|
91
386
|
|
|
387
|
+
(defun eliscript-emitter--qualified-apply-callee-p (form)
|
|
388
|
+
"Whether FORM reads a qualified apply property in call position.
|
|
389
|
+
Keep references themselves unchanged: custom namespace objects and aliases
|
|
390
|
+
must retain their ordinary property identity and receiver."
|
|
391
|
+
(let ((reference (if (and (consp form)
|
|
392
|
+
(eq (car form) eliscript-emitter--tdz-read-tag))
|
|
393
|
+
(nth 2 form) form)))
|
|
394
|
+
(and (symbolp reference)
|
|
395
|
+
(string-match-p "[./]apply[./]*\\'" (symbol-name reference)))))
|
|
396
|
+
|
|
92
397
|
(defun eliscript-emitter--emit-callee (form)
|
|
93
398
|
"Emit FORM in a position where ECMAScript expects a callable value."
|
|
94
399
|
(let ((output (eliscript-emitter-emit-expression form)))
|
|
95
|
-
(
|
|
400
|
+
(cond
|
|
401
|
+
((eliscript-emitter--qualified-apply-callee-p form)
|
|
402
|
+
;; The already emitted reference retains its lexical/TDZ root lookup.
|
|
403
|
+
;; Capture the actual property before arguments, then let the shared
|
|
404
|
+
;; dispatcher recognize intrinsic Reflect.apply by identity only.
|
|
405
|
+
(format "__eliscript_at(%s, \"apply\")" (substring output 0 -6)))
|
|
406
|
+
((symbolp form) output)
|
|
407
|
+
(t (format "(%s)" output)))))
|
|
96
408
|
|
|
97
409
|
(defun eliscript-emitter--binding-pattern-p (form)
|
|
98
410
|
"Return non-nil when FORM is a vector binding pattern."
|
|
@@ -127,42 +439,379 @@
|
|
|
127
439
|
(t (eliscript-emitter--fail
|
|
128
440
|
"invalid binding pattern: %S" (eliscript-form-strip form))))))
|
|
129
441
|
|
|
442
|
+
(defun eliscript-emitter--boolean-p (form)
|
|
443
|
+
"Whether FORM is proven to return a JavaScript boolean."
|
|
444
|
+
(or (memq form '(t false))
|
|
445
|
+
(and (consp form)
|
|
446
|
+
(or (and (eq (car form) 'js*) (= (length form) 2)
|
|
447
|
+
(stringp (cadr form))
|
|
448
|
+
(string-match-p "\\`!![A-Za-z_$][A-Za-z0-9_$]*\\'" (string-trim (cadr form))))
|
|
449
|
+
(memq (car form)
|
|
450
|
+
'(not = /= not= < <= > >= eq equal nil? undefined? null nullish?))
|
|
451
|
+
(and (memq (car form) '(and or)) (cdr form)
|
|
452
|
+
(cl-every #'eliscript-emitter--boolean-p (cdr form)))))))
|
|
453
|
+
|
|
454
|
+
(defun eliscript-emitter--emit-test (form)
|
|
455
|
+
"Emit FORM as a condition preserving Lisp truth semantics."
|
|
456
|
+
(let ((output (eliscript-emitter-emit-expression form)))
|
|
457
|
+
(if (eliscript-emitter--boolean-p form) output
|
|
458
|
+
(format "__eliscript_truthy(%s)" output))))
|
|
459
|
+
|
|
460
|
+
(defun eliscript-emitter--context-sequential-safe-p (bindings)
|
|
461
|
+
"Whether parsed BINDINGS can share a scope without observing a TDZ."
|
|
462
|
+
(when (> (length bindings) 1)
|
|
463
|
+
(let ((names (make-hash-table :test #'equal)) (index 0) (safe t))
|
|
464
|
+
(dolist (binding bindings)
|
|
465
|
+
(let ((name (eliscript-emitter--binding-name (car binding))))
|
|
466
|
+
(if (gethash name names) (setq safe nil)
|
|
467
|
+
(puthash name (1+ index) names)))
|
|
468
|
+
(setq index (1+ index)))
|
|
469
|
+
(cl-labels
|
|
470
|
+
((walk-pattern (pattern)
|
|
471
|
+
(cond
|
|
472
|
+
((vectorp pattern)
|
|
473
|
+
(mapc #'walk-pattern (append pattern nil)))
|
|
474
|
+
((eliscript-binding-map-pattern-p pattern)
|
|
475
|
+
(let ((spec (eliscript-binding-map-spec
|
|
476
|
+
pattern (lambda (_form message)
|
|
477
|
+
(eliscript-emitter--fail "%s" message)))))
|
|
478
|
+
(dolist (entry (plist-get spec :entries))
|
|
479
|
+
(walk-pattern (plist-get entry :target))
|
|
480
|
+
(unless (memq (plist-get entry :key-kind) '(keys strs syms))
|
|
481
|
+
(walk (plist-get entry :key)))
|
|
482
|
+
(when (plist-member entry :default)
|
|
483
|
+
(walk (plist-get entry :default))))))))
|
|
484
|
+
(walk-bindings (nested)
|
|
485
|
+
(dolist (binding nested)
|
|
486
|
+
(if (or (symbolp binding) (vectorp binding)
|
|
487
|
+
(eliscript-binding-map-pattern-p binding))
|
|
488
|
+
(walk-pattern binding)
|
|
489
|
+
(walk-pattern (car binding))
|
|
490
|
+
(walk (cadr binding)))))
|
|
491
|
+
(walk (form)
|
|
492
|
+
;; Match references and assignment targets, not syntax names.
|
|
493
|
+
;; References inside a shadowing function remain conservative, as
|
|
494
|
+
;; in the independent IR proof; declaration names do not count.
|
|
495
|
+
(when safe
|
|
496
|
+
(cond
|
|
497
|
+
((and (symbolp form) form (not (keywordp form))
|
|
498
|
+
(not (memq form '(t false undefined))))
|
|
499
|
+
(let* ((name (eliscript-emitter--reference-name form))
|
|
500
|
+
(position (gethash (car (split-string name "\\.")) names)))
|
|
501
|
+
(when (and position (> position index)) (setq safe nil))))
|
|
502
|
+
((vectorp form) (mapc #'walk (append form nil)))
|
|
503
|
+
((consp form)
|
|
504
|
+
(let ((operator (car form)) (arguments (cdr form)))
|
|
505
|
+
(cond
|
|
506
|
+
((eq operator 'js*) (setq safe nil))
|
|
507
|
+
((eq operator 'quote) nil)
|
|
508
|
+
((memq operator '(lambda fn async))
|
|
509
|
+
(dolist (parameter
|
|
510
|
+
(eliscript-parameters-parse
|
|
511
|
+
(car arguments)
|
|
512
|
+
(lambda (_form message)
|
|
513
|
+
(eliscript-emitter--fail "%s" message))))
|
|
514
|
+
(walk-pattern (eliscript-parameter-form parameter)))
|
|
515
|
+
(mapc #'walk (cdr arguments)))
|
|
516
|
+
((memq operator '(let let* loop))
|
|
517
|
+
(walk-bindings (car arguments))
|
|
518
|
+
(mapc #'walk (cdr arguments)))
|
|
519
|
+
((eq operator 'try)
|
|
520
|
+
(dolist (clause arguments)
|
|
521
|
+
(pcase (car-safe clause)
|
|
522
|
+
('catch (walk-pattern (cadr clause))
|
|
523
|
+
(mapc #'walk (cddr clause)))
|
|
524
|
+
('finally (mapc #'walk (cdr clause)))
|
|
525
|
+
(_ (walk clause)))))
|
|
526
|
+
((eq operator 'cond)
|
|
527
|
+
(dolist (clause arguments) (mapc #'walk clause)))
|
|
528
|
+
((eq operator 'js-object)
|
|
529
|
+
(while arguments
|
|
530
|
+
(let ((key (pop arguments)) (value (pop arguments)))
|
|
531
|
+
(unless (or (keywordp key) (stringp key) (symbolp key))
|
|
532
|
+
(walk key))
|
|
533
|
+
(walk value))))
|
|
534
|
+
((memq operator
|
|
535
|
+
'(await throw if when unless progn do recur setq set!
|
|
536
|
+
while and or vector hash-map hash-set queue list js-array
|
|
537
|
+
not + * - / % mod = /= not= < <= > >= 1+ 1-
|
|
538
|
+
int32 uint32 imul32 bit-and bit-or bit-xor bit-not
|
|
539
|
+
bit-shift-left bit-shift-right unsigned-bit-shift-right
|
|
540
|
+
value-type host-identity-token string-code-unit-at
|
|
541
|
+
string-from-code-unit string-to-number string-to-bigint
|
|
542
|
+
number-float64-words eq equal null nil? undefined? nullish?
|
|
543
|
+
car cdr cons js-cons nth js-nth aref length js-length
|
|
544
|
+
object-keys object-has? object-assoc __eliscript_arity_error
|
|
545
|
+
get put js-call new print str funcall apply))
|
|
546
|
+
(mapc #'walk arguments))
|
|
547
|
+
(t (mapc #'walk form)))))))))
|
|
548
|
+
(setq index 0)
|
|
549
|
+
(dolist (binding bindings)
|
|
550
|
+
(walk (cadr binding))
|
|
551
|
+
(setq index (1+ index))))
|
|
552
|
+
safe)))
|
|
553
|
+
|
|
554
|
+
(defun eliscript-emitter--emit-context-let (bindings body sequential returning)
|
|
555
|
+
"Emit parsed simple BINDINGS and BODY without a closure.
|
|
556
|
+
Keep initializer and binding scopes separate, including sequential shadowing."
|
|
557
|
+
(if (null bindings)
|
|
558
|
+
(if returning (eliscript-emitter--emit-returning-body body)
|
|
559
|
+
(eliscript-emitter--emit-statement-body body))
|
|
560
|
+
(if (and sequential (eliscript-emitter--context-sequential-safe-p bindings))
|
|
561
|
+
(concat "{\n" (eliscript-emitter--indent
|
|
562
|
+
(string-join
|
|
563
|
+
(append (mapcar (lambda (binding)
|
|
564
|
+
(concat "let " (eliscript-emitter--emit-binding-target (car binding))
|
|
565
|
+
" = " (eliscript-emitter-emit-expression (cadr binding)) ";")) bindings)
|
|
566
|
+
(list (if returning (eliscript-emitter--emit-returning-body body)
|
|
567
|
+
(eliscript-emitter--emit-statement-body body)))) "\n")) "\n}")
|
|
568
|
+
(let* ((group (if sequential (list (car bindings)) bindings))
|
|
569
|
+
(temporaries (mapcar (lambda (_) (eliscript-emitter--fresh-name)) group))
|
|
570
|
+
initializers declarations)
|
|
571
|
+
(cl-mapc
|
|
572
|
+
(lambda (binding temporary)
|
|
573
|
+
(push (format "const %s = %s;" temporary
|
|
574
|
+
(eliscript-emitter-emit-expression (cadr binding)))
|
|
575
|
+
initializers)) group temporaries)
|
|
576
|
+
(cl-mapc
|
|
577
|
+
(lambda (binding temporary)
|
|
578
|
+
(push (format "let %s = %s;"
|
|
579
|
+
(eliscript-emitter--emit-binding-target (car binding)) temporary)
|
|
580
|
+
declarations)) group temporaries)
|
|
581
|
+
(push (eliscript-emitter--emit-context-let
|
|
582
|
+
(and sequential (cdr bindings)) body sequential returning) declarations)
|
|
583
|
+
(concat "{\n"
|
|
584
|
+
(eliscript-emitter--indent
|
|
585
|
+
(string-join
|
|
586
|
+
(append (nreverse initializers)
|
|
587
|
+
(list (concat "{\n"
|
|
588
|
+
(eliscript-emitter--indent
|
|
589
|
+
(string-join (nreverse declarations) "\n"))
|
|
590
|
+
"\n}"))) "\n"))
|
|
591
|
+
"\n}")))))
|
|
592
|
+
|
|
593
|
+
(defun eliscript-emitter--emit-context-cond (clauses returning)
|
|
594
|
+
"Emit CLAUSES as statements or RETURNING values."
|
|
595
|
+
(let ((result (if returning "return null;" "")) frames)
|
|
596
|
+
(while clauses
|
|
597
|
+
(let* ((clause (pop clauses)) (test (car clause)) (body (cdr clause)))
|
|
598
|
+
(if (eq test t)
|
|
599
|
+
(setq result (if returning (eliscript-emitter--emit-returning-body body)
|
|
600
|
+
(eliscript-emitter--emit-statement-body body))
|
|
601
|
+
clauses nil)
|
|
602
|
+
(let ((condition (eliscript-emitter--emit-test test))
|
|
603
|
+
(consequent (if returning (eliscript-emitter--emit-returning-body body)
|
|
604
|
+
(eliscript-emitter--emit-statement-body body))))
|
|
605
|
+
(push (list condition consequent) frames)))))
|
|
606
|
+
(dolist (frame frames)
|
|
607
|
+
(setq result (concat "if (" (car frame) ") {\n"
|
|
608
|
+
(eliscript-emitter--indent (cadr frame))
|
|
609
|
+
"\n} else {\n" (eliscript-emitter--indent result) "\n}")))
|
|
610
|
+
result))
|
|
611
|
+
|
|
612
|
+
(defun eliscript-emitter--run-depth-plan (adapter mode value options)
|
|
613
|
+
"Run ADAPTER's emission continuations without nesting host Lisp calls.
|
|
614
|
+
Children finish in source order; a continuation may schedule another stage
|
|
615
|
+
when temporary allocation or binding setup must occur between child groups."
|
|
616
|
+
(let* ((result (list nil))
|
|
617
|
+
(pending (list (list :visit mode value options result))))
|
|
618
|
+
(while pending
|
|
619
|
+
(let ((job (pop pending)))
|
|
620
|
+
(pcase (car job)
|
|
621
|
+
(:visit
|
|
622
|
+
(push (list :plan (funcall adapter (nth 1 job) (nth 2 job) (nth 3 job))
|
|
623
|
+
(nth 4 job)) pending))
|
|
624
|
+
(:plan
|
|
625
|
+
(let ((plan (nth 1 job)) (output (nth 2 job)))
|
|
626
|
+
(if (eq (car plan) :value)
|
|
627
|
+
(setcar output (nth 1 plan))
|
|
628
|
+
(let* ((specs (nth 1 plan))
|
|
629
|
+
(cells (mapcar (lambda (_spec) (list nil)) specs)))
|
|
630
|
+
(push (list :combine (nth 2 plan) cells output) pending)
|
|
631
|
+
(let ((pairs (cl-mapcar #'cons specs cells)))
|
|
632
|
+
(dolist (pair (nreverse pairs))
|
|
633
|
+
(let ((spec (car pair)))
|
|
634
|
+
(push (list :visit (nth 0 spec) (nth 1 spec) (nth 2 spec) (cdr pair))
|
|
635
|
+
pending))))))))
|
|
636
|
+
(:combine
|
|
637
|
+
(push (list :plan (funcall (nth 1 job) (mapcar #'car (nth 2 job)))
|
|
638
|
+
(nth 3 job)) pending)))))
|
|
639
|
+
(car result)))
|
|
640
|
+
|
|
641
|
+
(defun eliscript-emitter--emit-context (form returning)
|
|
642
|
+
"Emit FORM using explicit continuations for ordinary conditional trees."
|
|
643
|
+
(if (and (consp form) (memq (car form) '(if let let* progn do))
|
|
644
|
+
(not (eliscript-emitter--contains-await-p form)))
|
|
645
|
+
(eliscript-emitter--run-depth-plan #'eliscript-emitter--depth-plan :context form returning)
|
|
646
|
+
(eliscript-emitter--emit-context-recursive form returning)))
|
|
647
|
+
|
|
648
|
+
(defun eliscript-emitter--depth-plan (mode value options)
|
|
649
|
+
"Describe an ordinary form emission step without recursing into its tree."
|
|
650
|
+
(pcase mode
|
|
651
|
+
(:value (list :value value))
|
|
652
|
+
(:expression
|
|
653
|
+
(if (and (consp value) (eq (car value) 'if))
|
|
654
|
+
(let ((arguments (cdr value)))
|
|
655
|
+
(eliscript-emitter--require-arity "if" arguments 2 3)
|
|
656
|
+
(list :children (mapcar (lambda (form) (list :expression form nil))
|
|
657
|
+
(list (nth 0 arguments) (nth 1 arguments) (nth 2 arguments)))
|
|
658
|
+
(lambda (results)
|
|
659
|
+
(list :value (format "(%s ? %s : %s)"
|
|
660
|
+
(if (eliscript-emitter--boolean-p (car arguments)) (nth 0 results)
|
|
661
|
+
(format "__eliscript_truthy(%s)" (nth 0 results)))
|
|
662
|
+
(nth 1 results) (nth 2 results))))))
|
|
663
|
+
(list :value (eliscript-emitter--emit-expression-recursive value))))
|
|
664
|
+
(:body
|
|
665
|
+
(if (null value) (list :value (if options "return null;" ""))
|
|
666
|
+
(let ((remaining value) specs)
|
|
667
|
+
(while remaining
|
|
668
|
+
(push (list :context (car remaining) (and options (null (cdr remaining)))) specs)
|
|
669
|
+
(setq remaining (cdr remaining)))
|
|
670
|
+
(list :children (nreverse specs)
|
|
671
|
+
(lambda (results) (list :value (string-join results "\n")))))))
|
|
672
|
+
(:declaration
|
|
673
|
+
(let ((name (eliscript-emitter--emit-binding-target (car value))))
|
|
674
|
+
(list :children (list (list :expression (cadr value) nil))
|
|
675
|
+
(lambda (results) (list :value (concat "let " name " = " (car results) ";"))))))
|
|
676
|
+
(:context-let
|
|
677
|
+
(let ((bindings (nth 0 value)) (body (nth 1 value)) (sequential (nth 2 value)))
|
|
678
|
+
(cond
|
|
679
|
+
((null bindings) (list :children (list (list :body body options))
|
|
680
|
+
(lambda (results) (list :value (car results)))))
|
|
681
|
+
((and sequential (eliscript-emitter--context-sequential-safe-p bindings))
|
|
682
|
+
(list :children (append (mapcar (lambda (binding) (list :declaration binding nil)) bindings)
|
|
683
|
+
(list (list :body body options)))
|
|
684
|
+
(lambda (results)
|
|
685
|
+
(list :value (concat "{\n" (eliscript-emitter--indent (string-join results "\n")) "\n}")))))
|
|
686
|
+
(t
|
|
687
|
+
(let* ((group (if sequential (list (car bindings)) bindings))
|
|
688
|
+
(temporaries (mapcar (lambda (_binding) (eliscript-emitter--fresh-name)) group)))
|
|
689
|
+
(list :children (mapcar (lambda (binding) (list :expression (cadr binding) nil)) group)
|
|
690
|
+
(lambda (results)
|
|
691
|
+
(let ((initializers (cl-mapcar (lambda (temporary text) (format "const %s = %s;" temporary text)) temporaries results))
|
|
692
|
+
(declarations (cl-mapcar (lambda (binding temporary)
|
|
693
|
+
(format "let %s = %s;" (eliscript-emitter--emit-binding-target (car binding)) temporary)) group temporaries)))
|
|
694
|
+
(list :children (list (list :context-let (list (and sequential (cdr bindings)) body sequential) options))
|
|
695
|
+
(lambda (tail)
|
|
696
|
+
(list :value
|
|
697
|
+
(concat "{\n" (eliscript-emitter--indent
|
|
698
|
+
(string-join
|
|
699
|
+
(append initializers
|
|
700
|
+
(list (concat "{\n" (eliscript-emitter--indent
|
|
701
|
+
(string-join (append declarations tail) "\n")) "\n}"))) "\n")) "\n}"))))))))))))
|
|
702
|
+
(:context
|
|
703
|
+
(let ((operator (and (consp value) (car value))) (arguments (and (consp value) (cdr value))))
|
|
704
|
+
(cond
|
|
705
|
+
((eliscript-emitter--contains-await-p value)
|
|
706
|
+
(list :value (eliscript-emitter--emit-context-recursive value options)))
|
|
707
|
+
((memq operator '(progn do))
|
|
708
|
+
(list :children (list (list :body arguments options))
|
|
709
|
+
(lambda (results) (list :value (car results)))))
|
|
710
|
+
((eq operator 'if)
|
|
711
|
+
(list :children
|
|
712
|
+
(list (list :expression (nth 0 arguments) nil)
|
|
713
|
+
(list :context (nth 1 arguments) options)
|
|
714
|
+
(if (nthcdr 2 arguments) (list :context (nth 2 arguments) options)
|
|
715
|
+
(list :value (if options "return null;" "") nil)))
|
|
716
|
+
(lambda (results)
|
|
717
|
+
(list :value
|
|
718
|
+
(concat "if (" (if (eliscript-emitter--boolean-p (car arguments)) (nth 0 results)
|
|
719
|
+
(format "__eliscript_truthy(%s)" (nth 0 results))) ") {\n"
|
|
720
|
+
(eliscript-emitter--indent (nth 1 results)) "\n}"
|
|
721
|
+
(if (or options (nthcdr 2 arguments))
|
|
722
|
+
(concat " else {\n" (eliscript-emitter--indent (nth 2 results)) "\n}") ""))))))
|
|
723
|
+
((and (memq operator '(let let*))
|
|
724
|
+
(let ((parsed (mapcar #'eliscript-emitter--parse-binding (car arguments))))
|
|
725
|
+
(cl-every (lambda (binding) (symbolp (car binding))) parsed)))
|
|
726
|
+
(list :children
|
|
727
|
+
(list (list :context-let
|
|
728
|
+
(list (mapcar #'eliscript-emitter--parse-binding (car arguments))
|
|
729
|
+
(cdr arguments) (eq operator 'let*)) options))
|
|
730
|
+
(lambda (results) (list :value (car results)))))
|
|
731
|
+
(t (list :value (eliscript-emitter--emit-context-recursive value options))))))
|
|
732
|
+
(_ (error "unknown form emission continuation mode: %S" mode))))
|
|
733
|
+
|
|
734
|
+
(defun eliscript-emitter--emit-context-recursive (form returning)
|
|
735
|
+
"Emit FORM as a statement or a RETURNING body value."
|
|
736
|
+
(let ((operator (and (consp form) (car form)))
|
|
737
|
+
(arguments (and (consp form) (cdr form))))
|
|
738
|
+
(cond
|
|
739
|
+
((eliscript-emitter--contains-await-p form)
|
|
740
|
+
(concat (if returning "return " "") (eliscript-emitter-emit-expression form) ";"))
|
|
741
|
+
((memq operator '(progn do))
|
|
742
|
+
(if returning (eliscript-emitter--emit-returning-body arguments)
|
|
743
|
+
(eliscript-emitter--emit-statement-body arguments)))
|
|
744
|
+
((eq operator 'if)
|
|
745
|
+
(concat "if (" (eliscript-emitter--emit-test (car arguments)) ") {\n"
|
|
746
|
+
(eliscript-emitter--indent
|
|
747
|
+
(eliscript-emitter--emit-context (nth 1 arguments) returning))
|
|
748
|
+
"\n}"
|
|
749
|
+
(if (or returning (nthcdr 2 arguments))
|
|
750
|
+
(concat " else {\n" (eliscript-emitter--indent
|
|
751
|
+
(if (nthcdr 2 arguments)
|
|
752
|
+
(eliscript-emitter--emit-context (nth 2 arguments) returning)
|
|
753
|
+
"return null;")) "\n}") "")))
|
|
754
|
+
((memq operator '(when unless))
|
|
755
|
+
(concat "if ("
|
|
756
|
+
(if (eq operator 'when) (eliscript-emitter--emit-test (car arguments))
|
|
757
|
+
(concat "(!" (eliscript-emitter--emit-test (car arguments)) ")"))
|
|
758
|
+
") {\n"
|
|
759
|
+
(eliscript-emitter--indent
|
|
760
|
+
(if returning (eliscript-emitter--emit-returning-body (cdr arguments))
|
|
761
|
+
(eliscript-emitter--emit-statement-body (cdr arguments))))
|
|
762
|
+
"\n}" (if returning " else {\n return null;\n}" "")))
|
|
763
|
+
((eq operator 'cond)
|
|
764
|
+
(eliscript-emitter--emit-context-cond arguments returning))
|
|
765
|
+
((eq operator 'while)
|
|
766
|
+
(eliscript-emitter--require-arity "while" arguments 1)
|
|
767
|
+
(concat "while (" (eliscript-emitter--emit-test (car arguments)) ") {\n"
|
|
768
|
+
(eliscript-emitter--indent
|
|
769
|
+
(eliscript-emitter--emit-statement-body (cdr arguments)))
|
|
770
|
+
"\n}" (if returning "\nreturn null;" "")))
|
|
771
|
+
((and (memq operator '(let let*))
|
|
772
|
+
(let ((parsed (mapcar #'eliscript-emitter--parse-binding (car arguments))))
|
|
773
|
+
(cl-every (lambda (binding) (symbolp (car binding))) parsed)))
|
|
774
|
+
(eliscript-emitter--emit-context-let
|
|
775
|
+
(mapcar #'eliscript-emitter--parse-binding (car arguments))
|
|
776
|
+
(cdr arguments) (eq operator 'let*) returning))
|
|
777
|
+
(t (concat (if returning "return " "")
|
|
778
|
+
(eliscript-emitter-emit-expression form) ";")))))
|
|
779
|
+
|
|
130
780
|
(defun eliscript-emitter--emit-returning-body (forms)
|
|
131
781
|
"Emit FORMS as a block body that returns its final value."
|
|
132
|
-
(if (null forms)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
(mapcar (lambda (form)
|
|
139
|
-
(concat (eliscript-emitter-emit-expression form) ";"))
|
|
140
|
-
initial)
|
|
141
|
-
(list (concat "return "
|
|
142
|
-
(eliscript-emitter-emit-expression final)
|
|
143
|
-
";")))
|
|
144
|
-
"\n"))))
|
|
782
|
+
(if (null forms) "return null;"
|
|
783
|
+
(string-join
|
|
784
|
+
(append (mapcar (lambda (form) (eliscript-emitter--emit-context form nil))
|
|
785
|
+
(butlast forms))
|
|
786
|
+
(list (eliscript-emitter--emit-context (car (last forms)) t)))
|
|
787
|
+
"\n")))
|
|
145
788
|
|
|
146
789
|
(defun eliscript-emitter--emit-statement-body (forms)
|
|
147
790
|
"Emit FORMS as statements whose values are discarded."
|
|
148
|
-
(mapconcat
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
791
|
+
(mapconcat (lambda (form) (eliscript-emitter--emit-context form nil)) forms "\n"))
|
|
792
|
+
|
|
793
|
+
(defun eliscript-emitter--some-form (forms predicate &optional excluded)
|
|
794
|
+
"Find PREDICATE in source preorder without recursive host calls.
|
|
795
|
+
EXCLUDED operators prune their complete forms after the node predicate."
|
|
796
|
+
(let ((pending (list (cons :sequence forms))) found)
|
|
797
|
+
(while (and pending (not found))
|
|
798
|
+
(let* ((job (pop pending)) (value (cdr job)))
|
|
799
|
+
(if (eq (car job) :sequence)
|
|
800
|
+
(when value
|
|
801
|
+
(unless (consp value) (signal 'wrong-type-argument (list 'listp value)))
|
|
802
|
+
(push (cons :sequence (cdr value)) pending)
|
|
803
|
+
(push (cons :node (car value)) pending))
|
|
804
|
+
(setq found (funcall predicate value))
|
|
805
|
+
(unless found
|
|
806
|
+
(cond ((vectorp value) (push (cons :sequence (append value nil)) pending))
|
|
807
|
+
((and (consp value) (not (memq (car value) excluded)))
|
|
808
|
+
(push (cons :sequence value) pending)))))))
|
|
809
|
+
found))
|
|
153
810
|
|
|
154
811
|
(defun eliscript-emitter--contains-await-p (form)
|
|
155
|
-
"Return non-nil when FORM contains
|
|
156
|
-
(
|
|
157
|
-
|
|
158
|
-
(cl-some #'eliscript-emitter--contains-await-p (append form nil)))
|
|
159
|
-
((consp form)
|
|
160
|
-
(let ((operator (car form)))
|
|
161
|
-
(cond
|
|
162
|
-
((eq operator 'await) t)
|
|
163
|
-
((memq operator '(lambda fn async)) nil)
|
|
164
|
-
(t (cl-some #'eliscript-emitter--contains-await-p form)))))
|
|
165
|
-
(t nil)))
|
|
812
|
+
"Return non-nil when FORM contains await outside nested functions."
|
|
813
|
+
(eliscript-emitter--some-form (list form)
|
|
814
|
+
(lambda (node) (and (consp node) (eq (car node) 'await))) '(lambda fn async)))
|
|
166
815
|
|
|
167
816
|
(defun eliscript-emitter--emit-iife
|
|
168
817
|
(parameters body arguments asynchronous)
|
|
@@ -235,26 +884,16 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
235
884
|
(eliscript-parameters-parse
|
|
236
885
|
arguments
|
|
237
886
|
(lambda (_form message) (eliscript-emitter--fail "%s" message)))))
|
|
238
|
-
(format "%s(%s) => {\n%s\n}"
|
|
887
|
+
(format "(%s(%s) => {\n%s\n})"
|
|
239
888
|
(if asynchronous "async " "")
|
|
240
889
|
(mapconcat #'eliscript-emitter--emit-parameter parameters ", ")
|
|
241
890
|
(eliscript-emitter--indent
|
|
242
891
|
(eliscript-emitter--emit-function-body parameters body)))))
|
|
243
892
|
|
|
244
893
|
(defun eliscript-emitter--contains-function-recur-p (form)
|
|
245
|
-
"Return non-nil when FORM recurs
|
|
246
|
-
(
|
|
247
|
-
|
|
248
|
-
(cl-some #'eliscript-emitter--contains-function-recur-p
|
|
249
|
-
(append form nil)))
|
|
250
|
-
((consp form)
|
|
251
|
-
(let ((operator (car form)))
|
|
252
|
-
(cond
|
|
253
|
-
((eq operator 'recur) t)
|
|
254
|
-
((memq operator '(lambda fn async loop)) nil)
|
|
255
|
-
(t
|
|
256
|
-
(cl-some #'eliscript-emitter--contains-function-recur-p form)))))
|
|
257
|
-
(t nil)))
|
|
894
|
+
"Return non-nil when FORM recurs outside nested functions or loops."
|
|
895
|
+
(eliscript-emitter--some-form (list form)
|
|
896
|
+
(lambda (node) (and (consp node) (eq (car node) 'recur))) '(lambda fn async loop)))
|
|
258
897
|
|
|
259
898
|
(defun eliscript-emitter--emit-rebinding-target (binding temporary)
|
|
260
899
|
"Assign TEMPORARY to mutable BINDING, including a vector pattern."
|
|
@@ -304,22 +943,23 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
304
943
|
|
|
305
944
|
(defun eliscript-emitter--emit-tail-cond (clauses target)
|
|
306
945
|
"Emit conditional CLAUSES in recur-aware tail position for TARGET."
|
|
307
|
-
(
|
|
308
|
-
|
|
309
|
-
|
|
946
|
+
(let ((result "return null;") frames)
|
|
947
|
+
(while clauses
|
|
948
|
+
(let ((clause (pop clauses)))
|
|
310
949
|
(unless (and (listp clause) clause)
|
|
311
950
|
(eliscript-emitter--fail "cond clause must be a non-empty list"))
|
|
312
951
|
(let ((test (car clause))
|
|
313
952
|
(body (cdr clause)))
|
|
314
953
|
(if (eq test t)
|
|
315
|
-
(eliscript-emitter--emit-tail-body body target)
|
|
316
|
-
(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
954
|
+
(setq result (eliscript-emitter--emit-tail-body body target) clauses nil)
|
|
955
|
+
(let ((condition (eliscript-emitter-emit-expression test))
|
|
956
|
+
(consequent (eliscript-emitter--emit-tail-body body target)))
|
|
957
|
+
(push (list condition consequent) frames))))))
|
|
958
|
+
(dolist (frame frames)
|
|
959
|
+
(setq result (format "if (__eliscript_truthy(%s)) {\n%s\n} else {\n%s\n}"
|
|
960
|
+
(car frame) (eliscript-emitter--indent (cadr frame))
|
|
961
|
+
(eliscript-emitter--indent result))))
|
|
962
|
+
result))
|
|
323
963
|
|
|
324
964
|
(defun eliscript-emitter--emit-tail-let (arguments sequential target)
|
|
325
965
|
"Emit lexical ARGUMENTS in tail position for TARGET."
|
|
@@ -371,30 +1011,44 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
371
1011
|
(eliscript-emitter--indent
|
|
372
1012
|
(string-join (nreverse parts) "\n"))))))
|
|
373
1013
|
|
|
1014
|
+
(defun eliscript-emitter--assemble-tail-short-circuit (frames kind result)
|
|
1015
|
+
"Assemble emitted FRAMES and final RESULT of tail short-circuit KIND.
|
|
1016
|
+
FRAMES are in reverse evaluation order. Indent each fragment at its final
|
|
1017
|
+
depth once, rather than copying and reindenting the growing nested suffix."
|
|
1018
|
+
(if (null frames) result
|
|
1019
|
+
(with-temp-buffer
|
|
1020
|
+
(let ((depth 0))
|
|
1021
|
+
(cl-labels ((line (level text)
|
|
1022
|
+
(unless (= (point) (point-min)) (insert "\n"))
|
|
1023
|
+
(insert (if (= level 0) text
|
|
1024
|
+
(eliscript-emitter--indent text level)))))
|
|
1025
|
+
(dolist (frame (reverse frames))
|
|
1026
|
+
(let ((temporary (car frame)))
|
|
1027
|
+
(line depth (format "const %s = %s;" temporary (cadr frame)))
|
|
1028
|
+
(line depth (format "if (__eliscript_truthy(%s)) {" temporary))
|
|
1029
|
+
(when (eq kind 'or)
|
|
1030
|
+
(line (1+ depth) (format "return %s;" temporary))
|
|
1031
|
+
(line depth "} else {"))
|
|
1032
|
+
(setq depth (1+ depth))))
|
|
1033
|
+
(line depth result)
|
|
1034
|
+
(dolist (frame frames)
|
|
1035
|
+
(setq depth (1- depth))
|
|
1036
|
+
(when (eq kind 'and)
|
|
1037
|
+
(line depth "} else {")
|
|
1038
|
+
(line (1+ depth) (format "return %s;" (car frame))))
|
|
1039
|
+
(line depth "}"))))
|
|
1040
|
+
(buffer-string))))
|
|
1041
|
+
|
|
374
1042
|
(defun eliscript-emitter--emit-tail-short-circuit (arguments kind target)
|
|
375
1043
|
"Emit recur-aware short-circuit ARGUMENTS of KIND for TARGET."
|
|
376
|
-
(
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
"const %s = %s;\nif (__eliscript_truthy(%s)) {\n%s\n} else {\n%s\n}"
|
|
385
|
-
temporary
|
|
386
|
-
(eliscript-emitter-emit-expression (car arguments))
|
|
387
|
-
temporary
|
|
388
|
-
(eliscript-emitter--indent
|
|
389
|
-
(if (eq kind 'and)
|
|
390
|
-
(eliscript-emitter--emit-tail-short-circuit
|
|
391
|
-
(cdr arguments) kind target)
|
|
392
|
-
(format "return %s;" temporary)))
|
|
393
|
-
(eliscript-emitter--indent
|
|
394
|
-
(if (eq kind 'and)
|
|
395
|
-
(format "return %s;" temporary)
|
|
396
|
-
(eliscript-emitter--emit-tail-short-circuit
|
|
397
|
-
(cdr arguments) kind target))))))))
|
|
1044
|
+
(let (frames result)
|
|
1045
|
+
(while (cdr arguments)
|
|
1046
|
+
(let ((temporary (eliscript-emitter--fresh-name))
|
|
1047
|
+
(first (eliscript-emitter-emit-expression (pop arguments))))
|
|
1048
|
+
(push (list temporary first) frames)))
|
|
1049
|
+
(setq result (if arguments (eliscript-emitter--emit-tail-form (car arguments) target)
|
|
1050
|
+
(format "return %s;" (if (eq kind 'and) "true" "null"))))
|
|
1051
|
+
(eliscript-emitter--assemble-tail-short-circuit frames kind result)))
|
|
398
1052
|
|
|
399
1053
|
(defun eliscript-emitter--emit-tail-form (form target)
|
|
400
1054
|
"Emit FORM in a tail position controlled by TARGET."
|
|
@@ -436,7 +1090,123 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
436
1090
|
(_ (format "return %s;"
|
|
437
1091
|
(eliscript-emitter-emit-expression form)))))))
|
|
438
1092
|
|
|
1093
|
+
(defvar eliscript-emitter--numeric-profile nil)
|
|
1094
|
+
|
|
1095
|
+
(defun eliscript-emitter--scalar-proof-plan (model mode value context)
|
|
1096
|
+
"Prove scalar operations with explicit scope and short-circuit actions."
|
|
1097
|
+
(let ((scope (car context)) (state (cadr context)))
|
|
1098
|
+
(pcase mode
|
|
1099
|
+
(:value (list :value value))
|
|
1100
|
+
(:every
|
|
1101
|
+
(if (null value) (list :value t)
|
|
1102
|
+
(list :children (list (list :node (car value) context))
|
|
1103
|
+
(lambda (results)
|
|
1104
|
+
(if (car results)
|
|
1105
|
+
(list :children (list (list :every (cdr value) context))
|
|
1106
|
+
(lambda (tail) (list :value (car tail))))
|
|
1107
|
+
(list :value nil))))))
|
|
1108
|
+
(:bindings
|
|
1109
|
+
(let ((remaining (nth 0 value)) (inner (nth 1 value)) (forms (nth 2 value))
|
|
1110
|
+
(sequential (nth 3 value)) (valid (nth 4 value)))
|
|
1111
|
+
(if (null remaining)
|
|
1112
|
+
(if valid (list :children (list (list :every forms (list inner state)))
|
|
1113
|
+
(lambda (results) (list :value (car results)))) (list :value nil))
|
|
1114
|
+
(let* ((binding (car remaining))
|
|
1115
|
+
(target (if (eq model 'ir) (eliscript-ir-node-value binding)
|
|
1116
|
+
(if (consp binding) (car binding) binding)))
|
|
1117
|
+
(initializer (if (eq model 'ir) (eliscript-ir-emitter--binding-initializer binding)
|
|
1118
|
+
(and (consp binding) (cadr binding))))
|
|
1119
|
+
(shape (if (eq model 'ir)
|
|
1120
|
+
(and (eq (eliscript-ir-node-kind binding) 'lexical-binding)
|
|
1121
|
+
(not (eliscript-ir-property binding :pattern)))
|
|
1122
|
+
(and (symbolp target) (or (symbolp binding)
|
|
1123
|
+
(and (proper-list-p binding) (<= 1 (length binding) 2)))))))
|
|
1124
|
+
(list :children (list (if shape (list :node initializer (list (if sequential inner scope) state))
|
|
1125
|
+
(list :value nil context)))
|
|
1126
|
+
(lambda (results)
|
|
1127
|
+
(list :children (list (list :bindings
|
|
1128
|
+
(list (cdr remaining) (cons target inner) forms sequential (and valid (car results))) context))
|
|
1129
|
+
(lambda (tail) (list :value (car tail))))))))))
|
|
1130
|
+
(:pairs
|
|
1131
|
+
(if (null value) (list :value t)
|
|
1132
|
+
(let* ((ir (eq model 'ir)) (pair (if ir (car value) value))
|
|
1133
|
+
(target (if ir (eliscript-ir-node-value pair) (car pair)))
|
|
1134
|
+
(shape (and (or (not ir) (eq (eliscript-ir-node-kind pair) 'assignment-pair)) (memq target scope)))
|
|
1135
|
+
(operand (if ir (car (eliscript-ir-node-children pair)) (cadr pair))))
|
|
1136
|
+
(list :children (list (if shape (list :node operand context) (list :value nil context)))
|
|
1137
|
+
(lambda (results)
|
|
1138
|
+
(if (and ir (not (car results))) (list :value nil)
|
|
1139
|
+
(list :children (list (list :pairs (if ir (cdr value) (cddr value)) context))
|
|
1140
|
+
(lambda (tail) (list :value (and (car results) (car tail)))))))))))
|
|
1141
|
+
(:node
|
|
1142
|
+
(if (eq model 'ir)
|
|
1143
|
+
(if (null value) (list :value t)
|
|
1144
|
+
(let ((kind (eliscript-ir-node-kind value)) (datum (eliscript-ir-node-value value))
|
|
1145
|
+
(children (eliscript-ir-emitter--children value)))
|
|
1146
|
+
(pcase kind
|
|
1147
|
+
('literal (list :value (or (numberp datum) (memq datum '(nil t false undefined)))))
|
|
1148
|
+
('reference (list :value (memq datum scope)))
|
|
1149
|
+
('lexical-bindings
|
|
1150
|
+
(let ((split (eliscript-ir-emitter--split-counted-children value :binding-count)))
|
|
1151
|
+
(list :children (list (list :bindings (list (car split) scope (cadr split)
|
|
1152
|
+
(eliscript-ir-property value :sequential) t) context))
|
|
1153
|
+
(lambda (results) (list :value (car results))))))
|
|
1154
|
+
('assignment (list :children (list (list :pairs children context))
|
|
1155
|
+
(lambda (results) (list :value (car results)))))
|
|
1156
|
+
((or 'intrinsic 'conditional 'conditional-sugar 'short-circuit 'sequence 'loop)
|
|
1157
|
+
(when (eq kind 'loop) (setcar state t))
|
|
1158
|
+
(if (and (or (not (eq kind 'intrinsic))
|
|
1159
|
+
(memq datum '(+ - * / % mod 1+ 1- = eq < <= > >= /= not= not)))
|
|
1160
|
+
(or (not (and (eq kind 'intrinsic) (memq datum '(< <= > >=)))) (= (length children) 2)))
|
|
1161
|
+
(list :children (list (list :every children context)) (lambda (results) (list :value (car results))))
|
|
1162
|
+
(list :value nil)))
|
|
1163
|
+
(_ (list :value nil)))))
|
|
1164
|
+
(cond
|
|
1165
|
+
((or (numberp value) (memq value '(nil t false undefined))) (list :value t))
|
|
1166
|
+
((symbolp value) (list :value (memq value scope)))
|
|
1167
|
+
((consp value)
|
|
1168
|
+
(let ((operator (car value)) (arguments (cdr value)))
|
|
1169
|
+
(cond
|
|
1170
|
+
((memq operator '(let let*))
|
|
1171
|
+
(list :children (list (list :bindings (list (car arguments) scope (cdr arguments) (eq operator 'let*) t) context))
|
|
1172
|
+
(lambda (results) (list :value (car results)))))
|
|
1173
|
+
((memq operator '(setq set!)) (list :children (list (list :pairs arguments context))
|
|
1174
|
+
(lambda (results) (list :value (car results)))))
|
|
1175
|
+
((memq operator '(+ - * / % mod 1+ 1- = eq < <= > >= /= not= not and or if when unless progn do while))
|
|
1176
|
+
(when (eq operator 'while) (setcar state t))
|
|
1177
|
+
(if (or (not (memq operator '(< <= > >=))) (= (length arguments) 2))
|
|
1178
|
+
(list :children (list (list :every arguments context)) (lambda (results) (list :value (car results))))
|
|
1179
|
+
(list :value nil)))
|
|
1180
|
+
(t (list :value nil)))))
|
|
1181
|
+
(t (list :value nil)))))
|
|
1182
|
+
(_ (error "unknown scalar proof continuation: %S" mode)))))
|
|
1183
|
+
|
|
1184
|
+
(defun eliscript-emitter--closed-scalar-loop-p (names body)
|
|
1185
|
+
"Prove the original scalar subset without recursive expression scans."
|
|
1186
|
+
(when names
|
|
1187
|
+
(let* ((state (list nil))
|
|
1188
|
+
(valid (eliscript-emitter--run-depth-plan
|
|
1189
|
+
(lambda (mode value context) (eliscript-emitter--scalar-proof-plan 'form mode value context))
|
|
1190
|
+
:every body (list names state))))
|
|
1191
|
+
(and valid (car state)))))
|
|
1192
|
+
|
|
439
1193
|
(defun eliscript-emitter--emit-function-body (parameters body)
|
|
1194
|
+
"Version closed scalar loops behind one Number guard per parameter."
|
|
1195
|
+
(let ((names (mapcar #'eliscript-parameter-form parameters)))
|
|
1196
|
+
(if (and (not eliscript-emitter--numeric-profile)
|
|
1197
|
+
(cl-every (lambda (p) (eq (eliscript-parameter-kind p) 'required)) parameters)
|
|
1198
|
+
(cl-every #'symbolp names)
|
|
1199
|
+
(eliscript-emitter--closed-scalar-loop-p names body))
|
|
1200
|
+
(let ((fast (let ((eliscript-emitter--numeric-profile t))
|
|
1201
|
+
(eliscript-emitter--emit-function-body-unversioned parameters body)))
|
|
1202
|
+
(slow (eliscript-emitter--emit-function-body-unversioned parameters body)))
|
|
1203
|
+
(format "if (%s) {\n%s\n} else {\n%s\n}"
|
|
1204
|
+
(mapconcat (lambda (name) (format "typeof %s === \"number\""
|
|
1205
|
+
(eliscript-emitter--binding-name name))) names " && ")
|
|
1206
|
+
(eliscript-emitter--indent fast) (eliscript-emitter--indent slow)))
|
|
1207
|
+
(eliscript-emitter--emit-function-body-unversioned parameters body))))
|
|
1208
|
+
|
|
1209
|
+
(defun eliscript-emitter--emit-function-body-unversioned (parameters body)
|
|
440
1210
|
"Emit function BODY with recur-aware PARAMETER rebinding when required."
|
|
441
1211
|
(if (not (eliscript-emitter--contains-function-recur-p body))
|
|
442
1212
|
(eliscript-emitter--emit-returning-body body)
|
|
@@ -492,26 +1262,28 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
492
1262
|
(defun eliscript-emitter--emit-if (arguments)
|
|
493
1263
|
"Emit an if expression from ARGUMENTS."
|
|
494
1264
|
(eliscript-emitter--require-arity "if" arguments 2 3)
|
|
495
|
-
(format "(
|
|
496
|
-
(eliscript-emitter
|
|
1265
|
+
(format "(%s ? %s : %s)"
|
|
1266
|
+
(eliscript-emitter--emit-test (nth 0 arguments))
|
|
497
1267
|
(eliscript-emitter-emit-expression (nth 1 arguments))
|
|
498
1268
|
(eliscript-emitter-emit-expression (nth 2 arguments))))
|
|
499
1269
|
|
|
500
1270
|
(defun eliscript-emitter--emit-cond (clauses)
|
|
501
1271
|
"Emit nested conditional expressions for CLAUSES."
|
|
502
|
-
(
|
|
503
|
-
|
|
504
|
-
|
|
1272
|
+
(let ((result "null") frames)
|
|
1273
|
+
(while clauses
|
|
1274
|
+
(let ((clause (pop clauses)))
|
|
505
1275
|
(unless (and (listp clause) clause)
|
|
506
1276
|
(eliscript-emitter--fail "invalid cond clause: %S" clause))
|
|
507
1277
|
(let ((test (car clause))
|
|
508
1278
|
(body (cdr clause)))
|
|
509
1279
|
(if (eq test t)
|
|
510
|
-
(eliscript-emitter--emit-do body)
|
|
511
|
-
(
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
1280
|
+
(setq result (eliscript-emitter--emit-do body) clauses nil)
|
|
1281
|
+
(let ((condition (eliscript-emitter--emit-test test))
|
|
1282
|
+
(consequent (eliscript-emitter--emit-do body)))
|
|
1283
|
+
(push (list condition consequent) frames))))))
|
|
1284
|
+
(dolist (frame frames)
|
|
1285
|
+
(setq result (format "(%s ? %s : %s)" (car frame) (cadr frame) result)))
|
|
1286
|
+
result))
|
|
515
1287
|
|
|
516
1288
|
(defun eliscript-emitter--try-clause-operator (form)
|
|
517
1289
|
"Return FORM's try clause operator, or nil."
|
|
@@ -599,12 +1371,10 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
599
1371
|
""
|
|
600
1372
|
(eliscript-emitter--indent
|
|
601
1373
|
(concat
|
|
602
|
-
(format "while (
|
|
603
|
-
(eliscript-emitter
|
|
1374
|
+
(format "while (%s) {\n"
|
|
1375
|
+
(eliscript-emitter--emit-test test))
|
|
604
1376
|
(eliscript-emitter--indent
|
|
605
|
-
(
|
|
606
|
-
(concat (eliscript-emitter-emit-expression form) ";"))
|
|
607
|
-
body "\n"))
|
|
1377
|
+
(eliscript-emitter--emit-statement-body body))
|
|
608
1378
|
"\n}\nreturn null;"))
|
|
609
1379
|
""
|
|
610
1380
|
(eliscript-emitter--contains-await-p arguments))))
|
|
@@ -625,58 +1395,92 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
625
1395
|
|
|
626
1396
|
(defun eliscript-emitter--emit-short-circuit (arguments kind)
|
|
627
1397
|
"Emit Lisp-style short-circuit ARGUMENTS for KIND, either and or or."
|
|
628
|
-
(
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
1398
|
+
(let (frames result done)
|
|
1399
|
+
(while (not done)
|
|
1400
|
+
(cond
|
|
1401
|
+
((null arguments) (setq result (if (eq kind 'and) "true" "null") done t))
|
|
1402
|
+
((null (cdr arguments))
|
|
1403
|
+
(setq result (eliscript-emitter-emit-expression (car arguments)) done t))
|
|
1404
|
+
((and (cl-every #'eliscript-emitter--boolean-p arguments)
|
|
1405
|
+
(not (eliscript-emitter--contains-await-p arguments)))
|
|
1406
|
+
(setq result (format "(%s)" (mapconcat #'eliscript-emitter-emit-expression arguments
|
|
1407
|
+
(if (eq kind 'and) " && " " || ")))
|
|
1408
|
+
done t))
|
|
1409
|
+
(t
|
|
1410
|
+
(let ((temporary (eliscript-emitter--fresh-name))
|
|
1411
|
+
(first (eliscript-emitter-emit-expression (car arguments))))
|
|
1412
|
+
(setq arguments (cdr arguments))
|
|
1413
|
+
(push (list temporary first arguments) frames)))))
|
|
1414
|
+
(dolist (frame frames)
|
|
1415
|
+
(let ((temporary (car frame)))
|
|
1416
|
+
(setq result
|
|
1417
|
+
(format (if (eliscript-emitter--contains-await-p (nth 2 frame))
|
|
1418
|
+
"(await (async (%s) => (__eliscript_truthy(%s) ? %s : %s))(%s))"
|
|
1419
|
+
"((%s) => (__eliscript_truthy(%s) ? %s : %s))(%s)")
|
|
1420
|
+
temporary temporary
|
|
1421
|
+
(if (eq kind 'and) result temporary)
|
|
1422
|
+
(if (eq kind 'and) temporary result)
|
|
1423
|
+
(cadr frame)))))
|
|
1424
|
+
result))
|
|
1425
|
+
|
|
1426
|
+
(defun eliscript-emitter--numeric-tag (operator)
|
|
1427
|
+
"Return the primitive helper tag for OPERATOR."
|
|
1428
|
+
(cdr (assoc operator '(("-" . "sub") ("*" . "mul") ("/" . "div")
|
|
1429
|
+
("%" . "rem") ("&" . "and") ("|" . "or")
|
|
1430
|
+
("^" . "xor") ("<<" . "shl") (">>" . "shr")
|
|
1431
|
+
(">>>" . "ushr") ("imul" . "imul")))))
|
|
1432
|
+
(defun eliscript-emitter--relational-p (operator)
|
|
1433
|
+
"Return non-nil for a relational OPERATOR."
|
|
1434
|
+
(member operator '("<" "<=" ">" ">=")))
|
|
1435
|
+
(defun eliscript-emitter--numeric-coercion-p (name)
|
|
1436
|
+
"Return non-nil when intrinsic NAME needs numeric conversion."
|
|
1437
|
+
(memq name '(- * / % mod < <= > >= 1- int32 uint32 imul32 bit-not bit-and
|
|
1438
|
+
bit-or bit-xor bit-shift-left bit-shift-right unsigned-bit-shift-right)))
|
|
1439
|
+
(defun eliscript-emitter--numeric-binary (operator left right)
|
|
1440
|
+
"Emit OPERATOR over already emitted LEFT and RIGHT, preserving conversions."
|
|
1441
|
+
(cond (eliscript-emitter--numeric-profile (format "(%s %s %s)" left operator right))
|
|
1442
|
+
((and (equal operator "-") (equal right "1"))
|
|
1443
|
+
(format "__eliscript_numeric_decrement(%s)" left))
|
|
1444
|
+
((eliscript-emitter--relational-p operator)
|
|
1445
|
+
(format "__eliscript_numeric_relation(\"%s\", %s, %s)" operator left right))
|
|
1446
|
+
((eliscript-emitter--numeric-tag operator)
|
|
1447
|
+
(format "__eliscript_numeric_%s(%s, %s)"
|
|
1448
|
+
(eliscript-emitter--numeric-tag operator) left right))
|
|
1449
|
+
(t (format "(%s %s %s)" left operator right))))
|
|
1450
|
+
(defun eliscript-emitter--numeric-fold (operator expressions)
|
|
1451
|
+
"Left-fold emitted EXPRESSIONS with OPERATOR."
|
|
1452
|
+
(if (and (not eliscript-emitter--numeric-profile)
|
|
1453
|
+
(eliscript-emitter--numeric-tag operator) (cdr expressions))
|
|
1454
|
+
(let ((result (car expressions)))
|
|
1455
|
+
(dolist (right (cdr expressions))
|
|
1456
|
+
(setq result (eliscript-emitter--numeric-binary operator result right))) result)
|
|
1457
|
+
(format "(%s)" (string-join expressions (format " %s " operator)))))
|
|
649
1458
|
(defun eliscript-emitter--emit-infix (name arguments operator &optional minimum)
|
|
650
1459
|
"Emit ARGUMENTS joined by OPERATOR for Lisp function NAME."
|
|
651
1460
|
(eliscript-emitter--require-arity name arguments (or minimum 2))
|
|
652
|
-
(
|
|
653
|
-
(mapconcat #'eliscript-emitter-emit-expression
|
|
654
|
-
arguments
|
|
655
|
-
(format " %s " operator))))
|
|
1461
|
+
(eliscript-emitter--numeric-fold operator (mapcar #'eliscript-emitter-emit-expression arguments)))
|
|
656
1462
|
|
|
657
1463
|
(defun eliscript-emitter--emit-binary-infix (name arguments operator)
|
|
658
1464
|
"Emit exact binary NAME over ARGUMENTS using JavaScript OPERATOR."
|
|
659
1465
|
(eliscript-emitter--require-arity name arguments 2 2)
|
|
660
|
-
(
|
|
661
|
-
|
|
662
|
-
operator
|
|
663
|
-
(eliscript-emitter-emit-expression (nth 1 arguments))))
|
|
1466
|
+
(eliscript-emitter--numeric-binary operator
|
|
1467
|
+
(eliscript-emitter-emit-expression (nth 0 arguments)) (eliscript-emitter-emit-expression (nth 1 arguments))))
|
|
664
1468
|
|
|
665
1469
|
(defun eliscript-emitter--emit-comparison (name arguments operator)
|
|
666
1470
|
"Emit one-evaluation n-ary comparison NAME using OPERATOR."
|
|
667
1471
|
(eliscript-emitter--require-arity name arguments 2)
|
|
668
1472
|
(if (= (length arguments) 2)
|
|
669
|
-
(
|
|
670
|
-
|
|
671
|
-
operator
|
|
672
|
-
(eliscript-emitter-emit-expression (nth 1 arguments)))
|
|
1473
|
+
(eliscript-emitter--numeric-binary operator
|
|
1474
|
+
(eliscript-emitter-emit-expression (nth 0 arguments)) (eliscript-emitter-emit-expression (nth 1 arguments)))
|
|
673
1475
|
(let ((parameters (mapcar (lambda (_argument)
|
|
674
1476
|
(eliscript-emitter--fresh-name))
|
|
675
1477
|
arguments))
|
|
676
1478
|
comparisons)
|
|
677
1479
|
(cl-loop for left on parameters
|
|
678
1480
|
while (cdr left)
|
|
679
|
-
do (push (
|
|
1481
|
+
do (push (if (eliscript-emitter--relational-p operator)
|
|
1482
|
+
(eliscript-emitter--numeric-binary operator (car left) (cadr left))
|
|
1483
|
+
(format "%s %s %s" (car left) operator (cadr left)))
|
|
680
1484
|
comparisons))
|
|
681
1485
|
(format "((%s) => (%s))(%s)"
|
|
682
1486
|
(string-join parameters ", ")
|
|
@@ -746,21 +1550,77 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
746
1550
|
(eliscript-emitter-emit-expression (nth 2 arguments)))
|
|
747
1551
|
access)))
|
|
748
1552
|
|
|
1553
|
+
(defun eliscript-emitter--array-text-key-p (key)
|
|
1554
|
+
"Return non-nil for text and borrowed-call methods or computed KEY."
|
|
1555
|
+
(if (or (keywordp key) (stringp key) (numberp key) (memq key '(nil t false undefined)))
|
|
1556
|
+
(member (if (keywordp key) (substring (symbol-name key) 1) key)
|
|
1557
|
+
'("join" "toString" "call" "apply" "bind"))
|
|
1558
|
+
t))
|
|
1559
|
+
|
|
1560
|
+
(defun eliscript-emitter--primitive-literal-p (form)
|
|
1561
|
+
"Return non-nil for primitive literal FORM, excluding allocated tagged values."
|
|
1562
|
+
(or (numberp form) (stringp form) (memq form '(nil t false undefined))))
|
|
1563
|
+
|
|
749
1564
|
(defun eliscript-emitter--emit-js-call (arguments)
|
|
750
1565
|
"Emit a receiver-preserving JavaScript method call from ARGUMENTS."
|
|
751
1566
|
(eliscript-emitter--require-arity "js-call" arguments 2)
|
|
752
|
-
(format
|
|
1567
|
+
(format (if (eliscript-emitter--array-text-key-p (nth 1 arguments))
|
|
1568
|
+
(if (cl-every #'eliscript-emitter--primitive-literal-p (nthcdr 2 arguments))
|
|
1569
|
+
(if (nthcdr 2 arguments) "__eliscript_at_direct(%s, %s, %s)"
|
|
1570
|
+
"__eliscript_at_direct(%s, %s%s)")
|
|
1571
|
+
"__eliscript_at(%s, %s)(%s)")
|
|
1572
|
+
"(%s)[%s](%s)")
|
|
753
1573
|
(eliscript-emitter-emit-expression (nth 0 arguments))
|
|
754
1574
|
(eliscript-emitter--emit-property-key (nth 1 arguments))
|
|
755
1575
|
(eliscript-emitter--emit-arguments (nthcdr 2 arguments))))
|
|
756
1576
|
|
|
1577
|
+
(defun eliscript-emitter--number-text (value)
|
|
1578
|
+
"Spell numeric VALUE as the same binary64 literal as the JavaScript emitter.
|
|
1579
|
+
|
|
1580
|
+
Use Emacs's shortest round-tripping digits, then change only decimal-point
|
|
1581
|
+
placement and exponent spelling. No rounded decimal arithmetic is involved."
|
|
1582
|
+
(let* ((float-output-format nil)
|
|
1583
|
+
;; Eliscript Numbers have the same binary64 conversion as Number in
|
|
1584
|
+
;; the self-hosted reader, including Emacs integers beyond 2^53.
|
|
1585
|
+
(text (number-to-string (float value))))
|
|
1586
|
+
(when (string-match-p "INF\\|NaN" text)
|
|
1587
|
+
(eliscript-emitter--fail "non-finite numbers are not supported: %S" value))
|
|
1588
|
+
(if (zerop value)
|
|
1589
|
+
(if (string-prefix-p "-" text) "-0.0" "0")
|
|
1590
|
+
(let* ((negative (string-prefix-p "-" text))
|
|
1591
|
+
(unsigned (if negative (substring text 1) text))
|
|
1592
|
+
(exponent-at (string-match "[eE]" unsigned))
|
|
1593
|
+
(mantissa (if exponent-at (substring unsigned 0 exponent-at) unsigned))
|
|
1594
|
+
(exponent (if exponent-at (string-to-number (substring unsigned (1+ exponent-at))) 0))
|
|
1595
|
+
(point (or (string-match "\\." mantissa) (length mantissa)))
|
|
1596
|
+
(digits (replace-regexp-in-string "\\." "" mantissa t t))
|
|
1597
|
+
(position (+ point exponent)))
|
|
1598
|
+
(while (and (> (length digits) 1) (= (aref digits 0) ?0))
|
|
1599
|
+
(setq digits (substring digits 1) position (1- position)))
|
|
1600
|
+
(while (and (> (length digits) 1) (= (aref digits (1- (length digits))) ?0))
|
|
1601
|
+
(setq digits (substring digits 0 -1)))
|
|
1602
|
+
(concat
|
|
1603
|
+
(if negative "-" "")
|
|
1604
|
+
(cond
|
|
1605
|
+
((and (> position 0) (<= position 21))
|
|
1606
|
+
(if (>= position (length digits))
|
|
1607
|
+
(concat digits (make-string (- position (length digits)) ?0))
|
|
1608
|
+
(concat (substring digits 0 position) "." (substring digits position))))
|
|
1609
|
+
((and (> position -6) (<= position 0))
|
|
1610
|
+
(concat "0." (make-string (- position) ?0) digits))
|
|
1611
|
+
(t
|
|
1612
|
+
(concat (substring digits 0 1)
|
|
1613
|
+
(if (> (length digits) 1) (concat "." (substring digits 1)) "")
|
|
1614
|
+
"e" (if (> position 0) "+" "")
|
|
1615
|
+
(number-to-string (1- position))))))))))
|
|
1616
|
+
|
|
757
1617
|
(defun eliscript-emitter--emit-quoted (value)
|
|
758
1618
|
"Emit quoted Eliscript VALUE as canonical persistent data."
|
|
759
1619
|
(cond
|
|
760
1620
|
((null value) "__eliscript_list()")
|
|
761
1621
|
((eq value t) "true")
|
|
762
1622
|
((eq value 'undefined) "undefined")
|
|
763
|
-
((numberp value) (number-
|
|
1623
|
+
((numberp value) (eliscript-emitter--number-text value))
|
|
764
1624
|
((stringp value) (eliscript-emitter--json-string value))
|
|
765
1625
|
((keywordp value)
|
|
766
1626
|
(format "__eliscript_keyword(%s)"
|
|
@@ -837,8 +1697,8 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
837
1697
|
('or (eliscript-emitter--emit-short-circuit arguments 'or))
|
|
838
1698
|
('not
|
|
839
1699
|
(eliscript-emitter--require-arity "not" arguments 1 1)
|
|
840
|
-
(format "(
|
|
841
|
-
(eliscript-emitter
|
|
1700
|
+
(format "(!%s)"
|
|
1701
|
+
(eliscript-emitter--emit-test (car arguments))))
|
|
842
1702
|
('quote
|
|
843
1703
|
(eliscript-emitter--require-arity "quote" arguments 1 1)
|
|
844
1704
|
(eliscript-emitter--emit-quoted (car arguments)))
|
|
@@ -847,32 +1707,31 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
847
1707
|
arguments " + "))
|
|
848
1708
|
"0"))
|
|
849
1709
|
('* (if arguments
|
|
850
|
-
(
|
|
851
|
-
arguments " * "))
|
|
1710
|
+
(eliscript-emitter--emit-infix "*" arguments "*" 1)
|
|
852
1711
|
"1"))
|
|
853
1712
|
('-
|
|
854
1713
|
(eliscript-emitter--require-arity "-" arguments 1)
|
|
855
1714
|
(if (= (length arguments) 1)
|
|
856
|
-
(format "(-%s)" (eliscript-emitter-emit-expression (car arguments)))
|
|
1715
|
+
(format (if eliscript-emitter--numeric-profile "(-%s)" "__eliscript_numeric_neg(%s)") (eliscript-emitter-emit-expression (car arguments)))
|
|
857
1716
|
(eliscript-emitter--emit-infix "-" arguments "-")))
|
|
858
1717
|
('/
|
|
859
1718
|
(eliscript-emitter--require-arity "/" arguments 1)
|
|
860
1719
|
(if (= (length arguments) 1)
|
|
861
|
-
(
|
|
1720
|
+
(eliscript-emitter--numeric-binary "/" "1" (eliscript-emitter-emit-expression (car arguments)))
|
|
862
1721
|
(eliscript-emitter--emit-infix "/" arguments "/")))
|
|
863
1722
|
((or '% 'mod) (eliscript-emitter--emit-infix (symbol-name operator)
|
|
864
1723
|
arguments "%"))
|
|
865
1724
|
('int32
|
|
866
1725
|
(eliscript-emitter--require-arity "int32" arguments 1 1)
|
|
867
|
-
(format "(%s
|
|
1726
|
+
(format "__eliscript_numeric_int32(%s)"
|
|
868
1727
|
(eliscript-emitter-emit-expression (car arguments))))
|
|
869
1728
|
('uint32
|
|
870
1729
|
(eliscript-emitter--require-arity "uint32" arguments 1 1)
|
|
871
|
-
(format "(%s
|
|
1730
|
+
(format "__eliscript_numeric_uint32(%s)"
|
|
872
1731
|
(eliscript-emitter-emit-expression (car arguments))))
|
|
873
1732
|
('imul32
|
|
874
1733
|
(eliscript-emitter--require-arity "imul32" arguments 2 2)
|
|
875
|
-
(format "
|
|
1734
|
+
(format "__eliscript_numeric_imul(%s, %s)"
|
|
876
1735
|
(eliscript-emitter-emit-expression (nth 0 arguments))
|
|
877
1736
|
(eliscript-emitter-emit-expression (nth 1 arguments))))
|
|
878
1737
|
('bit-and
|
|
@@ -883,7 +1742,7 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
883
1742
|
(eliscript-emitter--emit-binary-infix "bit-xor" arguments "^"))
|
|
884
1743
|
('bit-not
|
|
885
1744
|
(eliscript-emitter--require-arity "bit-not" arguments 1 1)
|
|
886
|
-
(format "(
|
|
1745
|
+
(format "__eliscript_numeric_not(%s)"
|
|
887
1746
|
(eliscript-emitter-emit-expression (car arguments))))
|
|
888
1747
|
('bit-shift-left
|
|
889
1748
|
(eliscript-emitter--emit-binary-infix
|
|
@@ -917,7 +1776,7 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
917
1776
|
(eliscript-emitter-emit-expression (car arguments))))
|
|
918
1777
|
('string-to-number
|
|
919
1778
|
(eliscript-emitter--require-arity "string-to-number" arguments 1 1)
|
|
920
|
-
(format "
|
|
1779
|
+
(format "__eliscript_to_number(%s)"
|
|
921
1780
|
(eliscript-emitter-emit-expression (car arguments))))
|
|
922
1781
|
('string-to-bigint
|
|
923
1782
|
(eliscript-emitter--require-arity "string-to-bigint" arguments 1 1)
|
|
@@ -942,7 +1801,7 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
942
1801
|
(format "(%s + 1)" (eliscript-emitter-emit-expression (car arguments))))
|
|
943
1802
|
('1-
|
|
944
1803
|
(eliscript-emitter--require-arity "1-" arguments 1 1)
|
|
945
|
-
(
|
|
1804
|
+
(eliscript-emitter--numeric-binary "-" (eliscript-emitter-emit-expression (car arguments)) "1"))
|
|
946
1805
|
('eq
|
|
947
1806
|
(eliscript-emitter--require-arity (symbol-name operator) arguments 2 2)
|
|
948
1807
|
(format "(%s === %s)"
|
|
@@ -1061,7 +1920,7 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
1061
1920
|
('js-call (eliscript-emitter--emit-js-call arguments))
|
|
1062
1921
|
('new
|
|
1063
1922
|
(eliscript-emitter--require-arity "new" arguments 1)
|
|
1064
|
-
(format "new %s(%s)"
|
|
1923
|
+
(format "new (%s)(%s)"
|
|
1065
1924
|
(eliscript-emitter-emit-expression (car arguments))
|
|
1066
1925
|
(eliscript-emitter--emit-arguments (cdr arguments))))
|
|
1067
1926
|
('js*
|
|
@@ -1099,15 +1958,26 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
1099
1958
|
(eliscript-emitter--emit-arguments arguments))))))
|
|
1100
1959
|
|
|
1101
1960
|
(defun eliscript-emitter-emit-expression (form)
|
|
1961
|
+
"Emit FORM with explicit continuations for ordinary if expression trees."
|
|
1962
|
+
(if (and (consp form) (eq (car form) 'if))
|
|
1963
|
+
(eliscript-emitter--run-depth-plan #'eliscript-emitter--depth-plan :expression form nil)
|
|
1964
|
+
(eliscript-emitter--emit-expression-recursive form)))
|
|
1965
|
+
|
|
1966
|
+
(defun eliscript-emitter--emit-expression-recursive (form)
|
|
1102
1967
|
"Emit Eliscript FORM as an ECMAScript expression."
|
|
1103
1968
|
(cond
|
|
1969
|
+
((and (consp form) (eq (car form) eliscript-emitter--tdz-assignment-tag))
|
|
1970
|
+
(let ((outputs (mapcar #'eliscript-emitter-emit-expression (nth 2 form))))
|
|
1971
|
+
(if (eq (nth 1 form) 'set!) (car outputs)
|
|
1972
|
+
(format "(%s)" (string-join outputs ", ")))))
|
|
1973
|
+
((and (consp form) (eq (car form) eliscript-emitter--tdz-read-tag))
|
|
1974
|
+
(eliscript-emitter--tdz-read-text (nth 1 form) (nth 2 form)))
|
|
1975
|
+
((and (consp form) (eq (car form) eliscript-emitter--tdz-write-tag))
|
|
1976
|
+
(eliscript-emitter--tdz-write-text (nth 1 form) (nth 2 form)
|
|
1977
|
+
(eliscript-emitter-emit-expression (nth 3 form))))
|
|
1104
1978
|
((null form) "null")
|
|
1105
1979
|
((eq form t) "true")
|
|
1106
|
-
((numberp form)
|
|
1107
|
-
(let ((text (number-to-string form)))
|
|
1108
|
-
(when (string-match-p "INF\\|NaN" text)
|
|
1109
|
-
(eliscript-emitter--fail "non-finite numbers are not supported: %S" form))
|
|
1110
|
-
text))
|
|
1980
|
+
((numberp form) (eliscript-emitter--number-text form))
|
|
1111
1981
|
((stringp form) (eliscript-emitter--json-string form))
|
|
1112
1982
|
((keywordp form)
|
|
1113
1983
|
(format "__eliscript_keyword(%s)"
|
|
@@ -1184,10 +2054,14 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
1184
2054
|
(eliscript-emitter--emit-import arguments))
|
|
1185
2055
|
((or 'defvar 'defconst)
|
|
1186
2056
|
(eliscript-emitter--require-arity (symbol-name operator) arguments 1 2)
|
|
1187
|
-
(
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
2057
|
+
(concat
|
|
2058
|
+
(format "%s %s = %s;"
|
|
2059
|
+
(if (eq operator 'defconst) "const" "let")
|
|
2060
|
+
(eliscript-emitter--binding-name (car arguments))
|
|
2061
|
+
(eliscript-emitter-emit-expression (cadr arguments)))
|
|
2062
|
+
(let ((record (and eliscript-emitter--tdz-state
|
|
2063
|
+
(gethash form (plist-get eliscript-emitter--tdz-state :declarations)))))
|
|
2064
|
+
(when record (concat "\n" (eliscript-emitter--tdz-ready-name record) " = true;")))))
|
|
1191
2065
|
((or 'defun 'defn 'defasync)
|
|
1192
2066
|
(eliscript-emitter--require-arity (symbol-name operator) arguments 2)
|
|
1193
2067
|
(let ((name (nth 0 arguments))
|
|
@@ -1218,128 +2092,187 @@ Prefix the function with `async' when ASYNCHRONOUS is non-nil."
|
|
|
1218
2092
|
(eliscript-emitter-emit-expression (car arguments))))
|
|
1219
2093
|
(_ (concat (eliscript-emitter-emit-expression form) ";"))))))
|
|
1220
2094
|
|
|
2095
|
+
(defun eliscript-emitter--uses-number-conversion-p (forms)
|
|
2096
|
+
"Find the corresponding unquoted runtime operation without host recursion."
|
|
2097
|
+
(eliscript-emitter--some-form forms
|
|
2098
|
+
(lambda (node) (and (consp node) (memq (car node) '(string-to-number)) t)) '(quote)))
|
|
2099
|
+
|
|
2100
|
+
(defun eliscript-emitter--uses-numeric-coercion-p (forms)
|
|
2101
|
+
"Find unquoted dynamic numeric operations without host recursion."
|
|
2102
|
+
(eliscript-emitter--some-form forms
|
|
2103
|
+
(lambda (node) (and (consp node)
|
|
2104
|
+
(eliscript-emitter--numeric-coercion-p (car node))
|
|
2105
|
+
(or (not (eq (car node) '*)) (> (length (cdr node)) 1)))) '(quote)))
|
|
2106
|
+
|
|
1221
2107
|
(defun eliscript-emitter--uses-host-identity-token-p (forms)
|
|
1222
|
-
"
|
|
1223
|
-
(
|
|
1224
|
-
|
|
1225
|
-
(form)
|
|
1226
|
-
(cond
|
|
1227
|
-
((vectorp form) (cl-some #'walk (append form nil)))
|
|
1228
|
-
((consp form)
|
|
1229
|
-
(or (eq (car form) 'host-identity-token)
|
|
1230
|
-
(cl-some #'walk form)))
|
|
1231
|
-
(t nil))))
|
|
1232
|
-
(cl-some #'walk forms)))
|
|
2108
|
+
"Retain the original host-token scan, including its quoted-form traversal."
|
|
2109
|
+
(eliscript-emitter--some-form forms
|
|
2110
|
+
(lambda (node) (and (consp node) (eq (car node) 'host-identity-token)))))
|
|
1233
2111
|
|
|
1234
2112
|
(defun eliscript-emitter--uses-literal-runtime-p (forms)
|
|
1235
|
-
"
|
|
1236
|
-
(cl-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
(value (pop arguments)))
|
|
1243
|
-
(when (or (and (not (or (keywordp key)
|
|
1244
|
-
(stringp key)
|
|
1245
|
-
(symbolp key)))
|
|
1246
|
-
(walk key))
|
|
1247
|
-
(walk value))
|
|
1248
|
-
(setq found t))))
|
|
1249
|
-
found))
|
|
1250
|
-
(walk-static-key-call
|
|
1251
|
-
(arguments key-index)
|
|
1252
|
-
(cl-loop
|
|
1253
|
-
for argument in arguments
|
|
1254
|
-
for index from 0
|
|
1255
|
-
thereis
|
|
1256
|
-
(and (not (and (= index key-index) (keywordp argument)))
|
|
1257
|
-
(walk argument))))
|
|
1258
|
-
(walk
|
|
1259
|
-
(form)
|
|
2113
|
+
"Find canonical literal construction without recursive ordinary-tree walks."
|
|
2114
|
+
(cl-some #'eliscript-emitter--form-uses-literal-runtime-p forms))
|
|
2115
|
+
|
|
2116
|
+
(defun eliscript-emitter--form-uses-literal-runtime-p (form)
|
|
2117
|
+
(let ((pending (list form)) found)
|
|
2118
|
+
(while (and pending (not found))
|
|
2119
|
+
(let ((item (pop pending)))
|
|
1260
2120
|
(cond
|
|
1261
|
-
((keywordp
|
|
1262
|
-
((vectorp
|
|
1263
|
-
((consp
|
|
1264
|
-
(let ((operator (car
|
|
1265
|
-
(arguments (cdr form)))
|
|
2121
|
+
((keywordp item) (setq found t))
|
|
2122
|
+
((vectorp item) (setq found t))
|
|
2123
|
+
((consp item)
|
|
2124
|
+
(let ((operator (car item)) (arguments (cdr item)))
|
|
1266
2125
|
(cond
|
|
1267
|
-
((eq operator 'quote)
|
|
1268
|
-
(eliscript-emitter--quoted-uses-literal-runtime-p
|
|
1269
|
-
(car arguments)))
|
|
2126
|
+
((eq operator 'quote) (setq found (eliscript-emitter--quoted-uses-literal-runtime-p (car arguments))))
|
|
1270
2127
|
((memq operator '(import import-portable)) nil)
|
|
1271
|
-
((memq operator '(list vector hash-map hash-set queue)) t)
|
|
1272
|
-
((eq operator 'js-object)
|
|
1273
|
-
|
|
1274
|
-
(
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
2128
|
+
((memq operator '(list vector hash-map hash-set queue)) (setq found t))
|
|
2129
|
+
((eq operator 'js-object)
|
|
2130
|
+
;; Retain the original complete pair traversal of object fields.
|
|
2131
|
+
(while arguments
|
|
2132
|
+
(let ((key (pop arguments)) (value (pop arguments)))
|
|
2133
|
+
(when (or (and (not (or (keywordp key) (stringp key) (symbolp key)))
|
|
2134
|
+
(eliscript-emitter--form-uses-literal-runtime-p key))
|
|
2135
|
+
(eliscript-emitter--form-uses-literal-runtime-p value)) (setq found t)))))
|
|
2136
|
+
(t
|
|
2137
|
+
(let ((index 0) selected)
|
|
2138
|
+
(dolist (child (if (memq operator '(get put js-call aref object-has? object-assoc)) arguments item))
|
|
2139
|
+
(unless (and (memq operator '(get put js-call aref object-has? object-assoc)) (= index 1) (keywordp child))
|
|
2140
|
+
(push child selected))
|
|
2141
|
+
(setq index (1+ index)))
|
|
2142
|
+
(dolist (child selected) (push child pending))))))))))
|
|
2143
|
+
found))
|
|
1278
2144
|
|
|
1279
2145
|
(defun eliscript-emitter--uses-collection-runtime-p (forms)
|
|
1280
|
-
"
|
|
1281
|
-
(
|
|
1282
|
-
|
|
1283
|
-
(form)
|
|
1284
|
-
(cond
|
|
1285
|
-
((vectorp form) (cl-some #'walk (append form nil)))
|
|
1286
|
-
((consp form)
|
|
1287
|
-
(cond
|
|
1288
|
-
((eq (car form) 'quote) nil)
|
|
1289
|
-
((memq (car form) '(nth length)) t)
|
|
1290
|
-
(t (cl-some #'walk form))))
|
|
1291
|
-
(t nil))))
|
|
1292
|
-
(cl-some #'walk forms)))
|
|
2146
|
+
"Find the corresponding unquoted runtime operation without host recursion."
|
|
2147
|
+
(eliscript-emitter--some-form forms
|
|
2148
|
+
(lambda (node) (and (consp node) (memq (car node) '(nth length)) t)) '(quote)))
|
|
1293
2149
|
|
|
1294
2150
|
(defun eliscript-emitter--uses-list-runtime-p (forms)
|
|
1295
|
-
"
|
|
1296
|
-
(
|
|
1297
|
-
|
|
1298
|
-
(form)
|
|
1299
|
-
(cond
|
|
1300
|
-
((vectorp form) (cl-some #'walk (append form nil)))
|
|
1301
|
-
((consp form)
|
|
1302
|
-
(cond
|
|
1303
|
-
((eq (car form) 'quote) nil)
|
|
1304
|
-
((memq (car form) '(car cdr cons)) t)
|
|
1305
|
-
(t (cl-some #'walk form))))
|
|
1306
|
-
(t nil))))
|
|
1307
|
-
(cl-some #'walk forms)))
|
|
2151
|
+
"Find the corresponding unquoted runtime operation without host recursion."
|
|
2152
|
+
(eliscript-emitter--some-form forms
|
|
2153
|
+
(lambda (node) (and (consp node) (memq (car node) '(car cdr cons)) t)) '(quote)))
|
|
1308
2154
|
|
|
1309
2155
|
(defun eliscript-emitter--uses-value-runtime-p (forms)
|
|
1310
|
-
"
|
|
1311
|
-
(
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
2156
|
+
"Find the corresponding unquoted runtime operation without host recursion."
|
|
2157
|
+
(eliscript-emitter--some-form forms
|
|
2158
|
+
(lambda (node) (and (consp node) (memq (car node) '(equal)) t)) '(quote)))
|
|
2159
|
+
|
|
2160
|
+
(defun eliscript-emitter--forms-name-global-root-p (forms)
|
|
2161
|
+
"Find the unquoted global root binding without host recursion."
|
|
2162
|
+
(eliscript-emitter--some-form forms (lambda (node) (eq node 'globalThis)) '(quote)))
|
|
2163
|
+
|
|
2164
|
+
(defun eliscript-emitter--number-conversion-prologue (shadowed)
|
|
2165
|
+
"Capture intrinsics independently of a SHADOWED global root binding."
|
|
2166
|
+
(if shadowed
|
|
2167
|
+
(concat eliscript-emitter--number-conversion-capsule
|
|
2168
|
+
eliscript-emitter--number-conversion-body)
|
|
2169
|
+
eliscript-emitter--number-conversion-helper))
|
|
2170
|
+
|
|
2171
|
+
(defun eliscript-emitter--uses-imul-p (forms)
|
|
2172
|
+
"Find the corresponding unquoted runtime operation without host recursion."
|
|
2173
|
+
(eliscript-emitter--some-form forms
|
|
2174
|
+
(lambda (node) (and (consp node) (memq (car node) '(imul32)) t)) '(quote)))
|
|
2175
|
+
|
|
2176
|
+
(defun eliscript-emitter--imul-prologue (shadowed)
|
|
2177
|
+
"Capture Math.imul only when required, outside SHADOWED global bindings."
|
|
2178
|
+
(concat (if shadowed eliscript-emitter--imul-capsule eliscript-emitter--imul-intrinsic)
|
|
2179
|
+
eliscript-emitter--imul-operator-helper))
|
|
2180
|
+
|
|
2181
|
+
(defconst eliscript-emitter--unicode-runtime-import
|
|
2182
|
+
"import \"eliscript/runtime/unicode-case.mjs\";\n")
|
|
2183
|
+
|
|
2184
|
+
(defun eliscript-emitter--unicode-capsule-p (filename module-name)
|
|
2185
|
+
"Recognize bootstrap capsules by full source and module identity."
|
|
2186
|
+
(let ((name (if (symbolp module-name) (symbol-name module-name) module-name)))
|
|
2187
|
+
(and (stringp filename)
|
|
2188
|
+
(cl-some
|
|
2189
|
+
(lambda (entry)
|
|
2190
|
+
(and (equal name (cdr entry))
|
|
2191
|
+
(or (equal filename (car entry))
|
|
2192
|
+
(and (file-name-absolute-p filename)
|
|
2193
|
+
(string-suffix-p (concat "/" (car entry)) filename)))))
|
|
2194
|
+
'(("runtime/unicode-case.eli" . "eliscript.runtime.unicode-case")
|
|
2195
|
+
("runtime/unicode-case-data.eli" . "eliscript.runtime.unicode-case-data"))))))
|
|
2196
|
+
|
|
2197
|
+
(defun eliscript-emitter--forms-unicode-capsule-p (forms filename)
|
|
2198
|
+
"Require a single exact module as well as its compilation source context."
|
|
2199
|
+
(and (= (length forms) 1) (consp (car forms))
|
|
2200
|
+
(eq (caar forms) 'module)
|
|
2201
|
+
(eliscript-emitter--unicode-capsule-p filename (cadar forms))))
|
|
2202
|
+
|
|
2203
|
+
(defconst eliscript-emitter--math-runtime-import
|
|
2204
|
+
"import \"eliscript/runtime/math.mjs\";\n")
|
|
2205
|
+
|
|
2206
|
+
(defun eliscript-emitter--math-reference-p (value)
|
|
2207
|
+
"Recognize explicit references to the real Math namespace."
|
|
2208
|
+
(let ((name (if (symbolp value) (symbol-name value) value)))
|
|
2209
|
+
(and (stringp name)
|
|
2210
|
+
(or (member name '("Math" "globalThis/Math" "globalThis.Math"))
|
|
2211
|
+
(cl-some (lambda (prefix) (string-prefix-p prefix name))
|
|
2212
|
+
'("Math/" "Math." "globalThis/Math/" "globalThis/Math."
|
|
2213
|
+
"globalThis.Math/" "globalThis.Math."))))))
|
|
2214
|
+
|
|
2215
|
+
(defun eliscript-emitter--uses-math-runtime-p (forms)
|
|
2216
|
+
"Find unquoted Math references, including the existing raw namespace form."
|
|
2217
|
+
(eliscript-emitter--some-form forms
|
|
2218
|
+
(lambda (node)
|
|
2219
|
+
(or (and (symbolp node) (eliscript-emitter--math-reference-p node))
|
|
2220
|
+
(and (consp node) (eq (car node) 'js*)
|
|
2221
|
+
(member (cadr node) '("Math" "globalThis.Math"))))) '(quote)))
|
|
2222
|
+
|
|
2223
|
+
(defun eliscript-emitter--uses-array-text-p (forms)
|
|
2224
|
+
"Find unquoted guarded method calls without host recursion."
|
|
2225
|
+
(eliscript-emitter--some-form forms
|
|
2226
|
+
(lambda (node)
|
|
2227
|
+
(and (consp node)
|
|
2228
|
+
(or (and (eq (car node) 'js-call)
|
|
2229
|
+
(eliscript-emitter--array-text-key-p (nth 2 node)))
|
|
2230
|
+
(eliscript-emitter--qualified-apply-callee-p (car node))
|
|
2231
|
+
(and (memq (car node) '(funcall apply))
|
|
2232
|
+
(eliscript-emitter--qualified-apply-callee-p (nth 1 node)))))) '(quote)))
|
|
2233
|
+
|
|
2234
|
+
(defun eliscript-emit-module (forms &optional filename)
|
|
1325
2235
|
"Emit FORMS as one ECMAScript module."
|
|
1326
|
-
(let ((eliscript-emitter--
|
|
2236
|
+
(let* ((eliscript-emitter--tdz-state (list :variables nil :declarations (make-hash-table :test #'eq)))
|
|
2237
|
+
(scope (make-hash-table :test #'equal)))
|
|
2238
|
+
(eliscript-emitter--tdz-legacy-predeclare forms scope eliscript-emitter--tdz-state)
|
|
2239
|
+
(eliscript-emitter--emit-module-ready
|
|
2240
|
+
(mapcar (lambda (form) (eliscript-emitter--tdz-legacy-top form scope eliscript-emitter--tdz-state)) forms) forms filename)))
|
|
2241
|
+
|
|
2242
|
+
(defun eliscript-emitter--emit-module-ready (forms &optional source-forms filename)
|
|
2243
|
+
(let ((eliscript-emitter--temporary-counter 0)
|
|
2244
|
+
(prologue-forms (or source-forms forms)))
|
|
1327
2245
|
(concat
|
|
1328
2246
|
"// Generated by Eliscript. Do not edit.\n"
|
|
1329
|
-
(
|
|
2247
|
+
(eliscript-emitter--tdz-prologue eliscript-emitter--tdz-state)
|
|
2248
|
+
(if (eliscript-emitter--forms-unicode-capsule-p prologue-forms filename)
|
|
2249
|
+
"" eliscript-emitter--unicode-runtime-import)
|
|
2250
|
+
(if (eliscript-emitter--uses-math-runtime-p prologue-forms) eliscript-emitter--math-runtime-import "")
|
|
2251
|
+
(if (eliscript-emitter--uses-array-text-p prologue-forms) eliscript-emitter--array-text-import "")
|
|
2252
|
+
(if (eliscript-emitter--uses-literal-runtime-p prologue-forms)
|
|
1330
2253
|
eliscript-emitter--literal-runtime-import
|
|
1331
2254
|
"")
|
|
1332
|
-
(if (eliscript-emitter--uses-collection-runtime-p forms)
|
|
2255
|
+
(if (eliscript-emitter--uses-collection-runtime-p prologue-forms)
|
|
1333
2256
|
eliscript-emitter--collection-runtime-import
|
|
1334
2257
|
"")
|
|
1335
|
-
(if (eliscript-emitter--uses-list-runtime-p forms)
|
|
2258
|
+
(if (eliscript-emitter--uses-list-runtime-p prologue-forms)
|
|
1336
2259
|
eliscript-emitter--list-runtime-import
|
|
1337
2260
|
"")
|
|
1338
|
-
(if (eliscript-emitter--uses-value-runtime-p forms)
|
|
2261
|
+
(if (eliscript-emitter--uses-value-runtime-p prologue-forms)
|
|
1339
2262
|
eliscript-emitter--value-runtime-import
|
|
1340
2263
|
"")
|
|
1341
2264
|
"const __eliscript_truthy = (value) => value !== false && value != null;\n"
|
|
1342
|
-
(if (eliscript-emitter--uses-
|
|
2265
|
+
(if (or (eliscript-emitter--uses-number-conversion-p prologue-forms)
|
|
2266
|
+
(eliscript-emitter--uses-numeric-coercion-p prologue-forms))
|
|
2267
|
+
(eliscript-emitter--number-conversion-prologue
|
|
2268
|
+
(eliscript-emitter--forms-name-global-root-p prologue-forms))
|
|
2269
|
+
"")
|
|
2270
|
+
(if (eliscript-emitter--uses-numeric-coercion-p prologue-forms)
|
|
2271
|
+
eliscript-emitter--numeric-operator-helper "")
|
|
2272
|
+
(if (eliscript-emitter--uses-imul-p prologue-forms)
|
|
2273
|
+
(eliscript-emitter--imul-prologue
|
|
2274
|
+
(eliscript-emitter--forms-name-global-root-p prologue-forms)) "")
|
|
2275
|
+
(if (eliscript-emitter--uses-host-identity-token-p prologue-forms)
|
|
1343
2276
|
eliscript-emitter--host-identity-token-helper
|
|
1344
2277
|
"")
|
|
1345
2278
|
"\n"
|