eliscript 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/bootstrap/README.md +26 -0
- package/bootstrap/backends/README.md +515 -0
- package/bootstrap/backends/async.eli +230 -0
- package/bootstrap/backends/binary.eli +173 -0
- package/bootstrap/backends/capabilities.eli +74 -0
- package/bootstrap/backends/elf.eli +246 -0
- package/bootstrap/backends/managed.eli +5976 -0
- package/bootstrap/backends/memory.eli +100 -0
- package/bootstrap/backends/native.eli +2000 -0
- package/bootstrap/backends/numeric.eli +1362 -0
- package/bootstrap/backends/optimize.eli +79 -0
- package/bootstrap/backends/regexp.eli +2263 -0
- package/bootstrap/backends/sha256.eli +138 -0
- package/bootstrap/backends/wasm.eli +1161 -0
- package/bootstrap/compiler/analyzer.eli +165 -77
- package/bootstrap/compiler/compiler.eli +43 -19
- package/bootstrap/compiler/emitter.eli +780 -170
- package/bootstrap/compiler/expander.eli +136 -45
- package/bootstrap/compiler/formatter.eli +8 -1
- package/bootstrap/compiler/ir.eli +148 -45
- package/bootstrap/compiler/lower.eli +29 -2
- package/bootstrap/compiler/project.eli +51 -21
- package/bootstrap/compiler/reader.eli +128 -36
- package/bootstrap/compiler/source-map.eli +46 -4
- package/bootstrap/compiler/symbol.eli +2 -1
- package/bootstrap/compiler/syntax.eli +47 -12
- package/bootstrap/compiler/transient-analysis.eli +40 -4
- package/bootstrap/host/check-cli-legacy.mjs +163 -0
- package/bootstrap/host/check-cli.mjs +59 -158
- package/bootstrap/host/check-cli.mjs.map +1 -0
- package/bootstrap/host/compiler-session.eli +1579 -0
- package/bootstrap/host/compiler-tools.eli +513 -0
- package/bootstrap/host/eliscript-cli-legacy.mjs +37 -0
- package/bootstrap/host/eliscript-cli.mjs +53 -33
- package/bootstrap/host/eliscript-cli.mjs.map +1 -0
- package/bootstrap/host/project-cli-legacy.mjs +295 -0
- package/bootstrap/host/project-cli.mjs +74 -289
- package/bootstrap/host/project-cli.mjs.map +1 -0
- package/bootstrap/host/project-legacy.mjs +1080 -0
- package/bootstrap/host/project.mjs +210 -1060
- package/bootstrap/host/project.mjs.map +1 -0
- package/bootstrap/runtime/UNICODE-LICENSE.txt +39 -0
- package/bootstrap/runtime/memory.eli +30379 -0
- package/browser/host.mjs +89 -0
- package/compiler/eliscript-analyzer.el +371 -4
- package/compiler/eliscript-cli.el +84 -1
- package/compiler/eliscript-emitter.el +1189 -256
- package/compiler/eliscript-expander.el +147 -10
- package/compiler/eliscript-ir-emitter.el +725 -208
- package/compiler/eliscript-lower.el +127 -1
- package/compiler/eliscript-portable.el +177 -51
- package/compiler/eliscript-project.el +20 -2
- package/compiler/eliscript-reader.el +141 -57
- package/compiler/eliscript-source-map.el +26 -12
- package/compiler/eliscript-transient-analysis.el +382 -19
- package/dist/backends/async.mjs +561 -0
- package/dist/backends/async.mjs.macro-origins.json +1 -0
- package/dist/backends/async.mjs.map +1 -0
- package/dist/backends/binary.mjs +381 -0
- package/dist/backends/binary.mjs.macro-origins.json +1 -0
- package/dist/backends/binary.mjs.map +1 -0
- package/dist/backends/capabilities.mjs +237 -0
- package/dist/backends/capabilities.mjs.macro-origins.json +1 -0
- package/dist/backends/capabilities.mjs.map +1 -0
- package/dist/backends/elf.mjs +540 -0
- package/dist/backends/elf.mjs.macro-origins.json +1 -0
- package/dist/backends/elf.mjs.map +1 -0
- package/dist/backends/managed.mjs +10616 -0
- package/dist/backends/managed.mjs.macro-origins.json +1 -0
- package/dist/backends/managed.mjs.map +1 -0
- package/dist/backends/memory.mjs +278 -0
- package/dist/backends/memory.mjs.macro-origins.json +1 -0
- package/dist/backends/memory.mjs.map +1 -0
- package/dist/backends/native.mjs +4099 -0
- package/dist/backends/native.mjs.macro-origins.json +1 -0
- package/dist/backends/native.mjs.map +1 -0
- package/dist/backends/numeric.mjs +2458 -0
- package/dist/backends/numeric.mjs.macro-origins.json +1 -0
- package/dist/backends/numeric.mjs.map +1 -0
- package/dist/backends/optimize.mjs +204 -0
- package/dist/backends/optimize.mjs.macro-origins.json +1 -0
- package/dist/backends/optimize.mjs.map +1 -0
- package/dist/backends/regexp.mjs +2033 -0
- package/dist/backends/regexp.mjs.macro-origins.json +1 -0
- package/dist/backends/regexp.mjs.map +1 -0
- package/dist/backends/sha256.mjs +310 -0
- package/dist/backends/sha256.mjs.macro-origins.json +1 -0
- package/dist/backends/sha256.mjs.map +1 -0
- package/dist/backends/wasm.mjs +2258 -0
- package/dist/backends/wasm.mjs.macro-origins.json +1 -0
- package/dist/backends/wasm.mjs.map +1 -0
- package/dist/bootstrap/analyzer.mjs +1908 -776
- package/dist/bootstrap/analyzer.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -1
- package/dist/bootstrap/compiler.mjs +450 -142
- package/dist/bootstrap/compiler.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/compiler.mjs.map +1 -1
- package/dist/bootstrap/emitter.mjs +3083 -909
- package/dist/bootstrap/emitter.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/emitter.mjs.map +1 -1
- package/dist/bootstrap/expander.mjs +2887 -1233
- package/dist/bootstrap/expander.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/expander.mjs.map +1 -1
- package/dist/bootstrap/formatter.mjs +582 -218
- package/dist/bootstrap/formatter.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/formatter.mjs.map +1 -1
- package/dist/bootstrap/ir.mjs +670 -116
- package/dist/bootstrap/ir.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/ir.mjs.map +1 -1
- package/dist/bootstrap/lower.mjs +866 -257
- package/dist/bootstrap/lower.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/lower.mjs.map +1 -1
- package/dist/bootstrap/package.json +1 -0
- package/dist/bootstrap/project.mjs +1168 -498
- package/dist/bootstrap/project.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/project.mjs.map +1 -1
- package/dist/bootstrap/reader.mjs +674 -175
- package/dist/bootstrap/reader.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/reader.mjs.map +1 -1
- package/dist/bootstrap/runtime/math.mjs +1117 -0
- package/dist/bootstrap/runtime/math.mjs.map +1 -0
- package/dist/bootstrap/runtime/unicode-case-data.mjs +10125 -0
- package/dist/bootstrap/runtime/unicode-case-data.mjs.map +1 -0
- package/dist/bootstrap/runtime/unicode-case.mjs +281 -0
- package/dist/bootstrap/runtime/unicode-case.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +430 -119
- package/dist/bootstrap/source-map.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/source-map.mjs.map +1 -1
- package/dist/bootstrap/symbol.mjs +229 -53
- package/dist/bootstrap/symbol.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/symbol.mjs.map +1 -1
- package/dist/bootstrap/syntax.mjs +205 -7
- package/dist/bootstrap/syntax.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/syntax.mjs.map +1 -1
- package/dist/bootstrap/transient-analysis.mjs +1185 -489
- package/dist/bootstrap/transient-analysis.mjs.macro-origins.json +1 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -1
- package/dist/browser/compiler.js +199 -6478
- package/dist/browser/host.mjs +446 -0
- package/dist/browser/loader.js +1 -0
- package/dist/browser/loader.mjs +231 -0
- package/dist/browser/worker.mjs +60 -0
- package/dist/compiler-artifact.json +1 -0
- package/dist/host/compiler-session.mjs +2980 -0
- package/dist/host/compiler-session.mjs.macro-origins.json +1 -0
- package/dist/host/compiler-session.mjs.map +1 -0
- package/dist/host/compiler-tools.mjs +1084 -0
- package/dist/host/compiler-tools.mjs.macro-origins.json +1 -0
- package/dist/host/compiler-tools.mjs.map +1 -0
- package/dist/literal-sources/runtime/core/collection-internals.eli +60 -0
- package/dist/literal-sources/runtime/core/collection.eli +579 -0
- package/dist/literal-sources/runtime/core/data-text.eli +290 -0
- package/dist/literal-sources/runtime/core/data.eli +22 -0
- package/dist/literal-sources/runtime/core/identifier.eli +44 -0
- package/dist/literal-sources/runtime/core/lazy-sequence.eli +131 -0
- package/dist/literal-sources/runtime/core/list.eli +19 -0
- package/dist/literal-sources/runtime/core/map.eli +9 -0
- package/dist/literal-sources/runtime/core/metadata-internals.eli +6 -0
- package/dist/literal-sources/runtime/core/metadata.eli +23 -0
- package/dist/literal-sources/runtime/core/object.eli +8 -0
- package/dist/literal-sources/runtime/core/order.eli +123 -0
- package/dist/literal-sources/runtime/core/persistent-kind.eli +28 -0
- package/dist/literal-sources/runtime/core/protocol-error.eli +32 -0
- package/dist/literal-sources/runtime/core/protocol.eli +28 -0
- package/dist/literal-sources/runtime/core/queue.eli +9 -0
- package/dist/literal-sources/runtime/core/record.eli +191 -0
- package/dist/literal-sources/runtime/core/regex.eli +158 -0
- package/dist/literal-sources/runtime/core/sequence.eli +305 -0
- package/dist/literal-sources/runtime/core/set-algebra.eli +28 -0
- package/dist/literal-sources/runtime/core/set.eli +9 -0
- package/dist/literal-sources/runtime/core/sorted.eli +408 -0
- package/dist/literal-sources/runtime/core/text.eli +14 -0
- package/dist/literal-sources/runtime/core/transducer.eli +268 -0
- package/dist/literal-sources/runtime/core/transient.eli +17 -0
- package/dist/literal-sources/runtime/core/truth.eli +4 -0
- package/dist/literal-sources/runtime/core/type.eli +232 -0
- package/dist/literal-sources/runtime/core/value-internals.eli +13 -0
- package/dist/literal-sources/runtime/core/value.eli +19 -0
- package/dist/literal-sources/runtime/core/vector.eli +20 -0
- package/dist/literal-sources/runtime/literals.eli +23 -0
- package/dist/literal-sources/runtime/testing/value.eli +6 -0
- package/dist/literal-sources/runtime/wire/http-rpc.eli +362 -0
- package/dist/literal-sources/runtime/wire/markdown.eli +275 -0
- package/dist/literal-sources/runtime/wire/schema.eli +193 -0
- package/dist/literal-sources/stdlib/bit.eli +36 -0
- package/dist/literal-sources/stdlib/core/data.eli +306 -0
- package/dist/literal-sources/stdlib/core/object.eli +89 -0
- package/dist/literal-sources/stdlib/core/protocol.eli +451 -0
- package/dist/literal-sources/stdlib/core/set.eli +312 -0
- package/dist/literal-sources/stdlib/core/text.eli +103 -0
- package/dist/literal-sources/stdlib/managed-literal-protocols.eli +483 -0
- package/dist/literal-sources/stdlib/managed-literals.eli +1414 -0
- package/dist/literal-sources/stdlib/managed-queue-state.eli +65 -0
- package/dist/literal-sources/stdlib/managed-sorted-state.eli +233 -0
- package/dist/literal-sources/stdlib/managed-transient-state.eli +348 -0
- package/dist/literal-sources/stdlib/managed-value-state.eli +153 -0
- package/dist/literal-sources/stdlib/managed-vector-view-state.eli +102 -0
- package/dist/literal-sources/stdlib/persistent-list.eli +145 -0
- package/dist/literal-sources/stdlib/persistent-map.eli +724 -0
- package/dist/literal-sources/stdlib/persistent-set.eli +236 -0
- package/dist/literal-sources/stdlib/persistent-vector.eli +359 -0
- package/dist/literal-sources/stdlib/value.eli +325 -0
- package/dist/package.json +10 -0
- package/dist/runtime/math.mjs +1116 -0
- package/dist/runtime/math.mjs.macro-origins.json +1 -0
- package/dist/runtime/math.mjs.map +1 -0
- package/dist/runtime/unicode-case-data.mjs +10124 -0
- package/dist/runtime/unicode-case-data.mjs.macro-origins.json +1 -0
- package/dist/runtime/unicode-case-data.mjs.map +1 -0
- package/dist/runtime/unicode-case.mjs +280 -0
- package/dist/runtime/unicode-case.mjs.macro-origins.json +1 -0
- package/dist/runtime/unicode-case.mjs.map +1 -0
- package/dist/runtime.eli +30379 -0
- package/dist/stage3-release.json +1 -0
- package/editor/README.md +1 -1
- package/editor/eliscript-mode.el +1 -1
- package/editor/eliscript-repl.el +1 -1
- package/package.json +97 -10
- package/platform/http.mjs +20 -0
- package/runtime/array-text.mjs +159 -0
- package/runtime/core/map-internals.mjs +27 -9
- package/runtime/core/object-impl.mjs +26 -17
- package/runtime/core/object-impl.mjs.map +1 -1
- package/runtime/core/protocol-impl.mjs +682 -255
- package/runtime/core/protocol-impl.mjs.map +1 -1
- package/runtime/core/protocol.mjs +4 -0
- package/runtime/core/record.mjs +23 -2
- package/runtime/core/regex.mjs +4 -0
- package/runtime/core/sorted.mjs +53 -0
- package/runtime/core/text-impl.mjs +167 -48
- package/runtime/core/text-impl.mjs.map +1 -1
- package/runtime/core/type.mjs +75 -3
- package/runtime/core/vector.mjs +6 -0
- package/runtime/math.eli +429 -0
- package/runtime/math.mjs +1116 -0
- package/runtime/math.mjs.map +1 -0
- package/runtime/number-radix.mjs +105 -0
- package/runtime/unicode-case-data.eli +29 -0
- package/runtime/unicode-case-data.mjs +10124 -0
- package/runtime/unicode-case-data.mjs.map +1 -0
- package/runtime/unicode-case.eli +100 -0
- package/runtime/unicode-case.mjs +280 -0
- package/runtime/unicode-case.mjs.map +1 -0
- package/runtime/wire/http-rpc.mjs +168 -0
- package/runtime/wire/markdown.mjs +196 -0
- package/runtime/wire/schema.mjs +109 -0
- package/stdlib/README.md +54 -0
- package/stdlib/core/protocol.eli +81 -17
- package/stdlib/core/seq.eli +1 -1
- package/stdlib/core/zipper.eli +114 -47
- package/stdlib/gepo.eli +12 -0
- package/stdlib/interop/js.eli +56 -15
- package/stdlib/managed-literal-protocols.eli +483 -0
- package/stdlib/managed-literals.eli +1414 -0
- package/stdlib/managed-protocol-error.eli +32 -0
- package/stdlib/managed-queue-state.eli +65 -0
- package/stdlib/managed-runtime-collection-internals.eli +60 -0
- package/stdlib/managed-runtime-collection.eli +579 -0
- package/stdlib/managed-runtime-data-text.eli +290 -0
- package/stdlib/managed-runtime-data.eli +22 -0
- package/stdlib/managed-runtime-identifier.eli +44 -0
- package/stdlib/managed-runtime-lazy-sequence.eli +131 -0
- package/stdlib/managed-runtime-list.eli +19 -0
- package/stdlib/managed-runtime-literals.eli +23 -0
- package/stdlib/managed-runtime-map.eli +9 -0
- package/stdlib/managed-runtime-metadata-internals.eli +6 -0
- package/stdlib/managed-runtime-metadata.eli +23 -0
- package/stdlib/managed-runtime-object.eli +8 -0
- package/stdlib/managed-runtime-order.eli +123 -0
- package/stdlib/managed-runtime-persistent-kind.eli +28 -0
- package/stdlib/managed-runtime-protocol.eli +28 -0
- package/stdlib/managed-runtime-queue.eli +9 -0
- package/stdlib/managed-runtime-record.eli +191 -0
- package/stdlib/managed-runtime-regex.eli +158 -0
- package/stdlib/managed-runtime-sequence.eli +305 -0
- package/stdlib/managed-runtime-set-algebra.eli +28 -0
- package/stdlib/managed-runtime-set.eli +9 -0
- package/stdlib/managed-runtime-sorted.eli +408 -0
- package/stdlib/managed-runtime-text.eli +14 -0
- package/stdlib/managed-runtime-transducer.eli +268 -0
- package/stdlib/managed-runtime-transient.eli +17 -0
- package/stdlib/managed-runtime-truth.eli +4 -0
- package/stdlib/managed-runtime-type.eli +232 -0
- package/stdlib/managed-runtime-value-internals.eli +13 -0
- package/stdlib/managed-runtime-value.eli +19 -0
- package/stdlib/managed-runtime-vector.eli +20 -0
- package/stdlib/managed-sorted-state.eli +233 -0
- package/stdlib/managed-testing-value.eli +6 -0
- package/stdlib/managed-transient-state.eli +348 -0
- package/stdlib/managed-value-state.eli +153 -0
- package/stdlib/managed-vector-view-state.eli +102 -0
- package/stdlib/managed-wire-http-rpc.eli +362 -0
- package/stdlib/managed-wire-markdown.eli +275 -0
- package/stdlib/managed-wire-schema.eli +193 -0
- package/stdlib/mdp.eli +7 -0
- package/stdlib/mds.eli +4 -0
- package/stdlib/persistent-vector.eli +23 -6
- package/tools/acceptance/check-legacy.mjs +687 -0
- package/tools/acceptance/check.eli +431 -0
- package/tools/acceptance/compile-evidence.el +49 -0
- package/tools/acceptance/finalize-legacy.mjs +498 -0
- package/tools/acceptance/finalize.eli +270 -0
- package/tools/backends/benchmark.mjs +175 -0
- package/tools/backends/build.mjs +135 -0
- package/tools/backends/compile.mjs +94 -0
- package/tools/backends/compiler-bootstrap.mjs +1001 -0
- package/tools/backends/compiler-browser.mjs +361 -0
- package/tools/backends/compiler-build.mjs +1628 -0
- package/tools/backends/compiler-cli-legacy.mjs +334 -0
- package/tools/backends/compiler-cli.mjs +29 -0
- package/tools/backends/compiler-corpus-bit.mjs +234 -0
- package/tools/backends/compiler-corpus-cli-adapters-legacy.mjs +362 -0
- package/tools/backends/compiler-corpus-cli-adapters.mjs +247 -0
- package/tools/backends/compiler-corpus-debugging.mjs +221 -0
- package/tools/backends/compiler-corpus-emitter.mjs +324 -0
- package/tools/backends/compiler-corpus-evaluation-adapters.mjs +65 -0
- package/tools/backends/compiler-corpus-execution-legacy.mjs +769 -0
- package/tools/backends/compiler-corpus-execution.mjs +3324 -0
- package/tools/backends/compiler-corpus-fuzz.mjs +229 -0
- package/tools/backends/compiler-corpus-generations.mjs +208 -0
- package/tools/backends/compiler-corpus-host-context-legacy.mjs +114 -0
- package/tools/backends/compiler-corpus-host-context.mjs +550 -0
- package/tools/backends/compiler-corpus-identity-host.mjs +553 -0
- package/tools/backends/compiler-corpus-identity-value-adapters-legacy.mjs +298 -0
- package/tools/backends/compiler-corpus-identity-value-adapters.mjs +69 -0
- package/tools/backends/compiler-corpus-isolated-exports.mjs +21 -0
- package/tools/backends/compiler-corpus-legacy.mjs +1155 -0
- package/tools/backends/compiler-corpus-literal-provider.mjs +282 -0
- package/tools/backends/compiler-corpus-managed-adapters-legacy.mjs +334 -0
- package/tools/backends/compiler-corpus-managed-adapters.mjs +937 -0
- package/tools/backends/compiler-corpus-managed-cases.mjs +179 -0
- package/tools/backends/compiler-corpus-managed-fixtures-legacy.mjs +879 -0
- package/tools/backends/compiler-corpus-managed-fixtures.mjs +1287 -0
- package/tools/backends/compiler-corpus-matchers.mjs +173 -0
- package/tools/backends/compiler-corpus-original-program.mjs +612 -0
- package/tools/backends/compiler-corpus-process.mjs +765 -0
- package/tools/backends/compiler-corpus-program-driver.mjs +306 -0
- package/tools/backends/compiler-corpus-project-adapters-legacy.mjs +497 -0
- package/tools/backends/compiler-corpus-project-adapters.mjs +340 -0
- package/tools/backends/compiler-corpus-project-entry-host.mjs +511 -0
- package/tools/backends/compiler-corpus-project-transport.mjs +151 -0
- package/tools/backends/compiler-corpus-raw-fixture-observer.mjs +1438 -0
- package/tools/backends/compiler-corpus-raw-language-fixtures.mjs +1456 -0
- package/tools/backends/compiler-corpus-raw-math-fixture.mjs +346 -0
- package/tools/backends/compiler-corpus-raw-special-fixtures.mjs +523 -0
- package/tools/backends/compiler-corpus-reference-legacy.mjs +263 -0
- package/tools/backends/compiler-corpus-reference.mjs +241 -0
- package/tools/backends/compiler-corpus-runtime-adapters-legacy.mjs +843 -0
- package/tools/backends/compiler-corpus-runtime-adapters.mjs +663 -0
- package/tools/backends/compiler-corpus-source-archive.mjs +206 -0
- package/tools/backends/compiler-corpus-tools-artifact-adapters.mjs +410 -0
- package/tools/backends/compiler-corpus-tools-cli.mjs +363 -0
- package/tools/backends/compiler-corpus-tools-reference.mjs +264 -0
- package/tools/backends/compiler-corpus.mjs +2054 -0
- package/tools/backends/compiler-debug.mjs +142 -0
- package/tools/backends/compiler-matrix.mjs +1955 -0
- package/tools/backends/compiler-metadata.mjs +203 -0
- package/tools/backends/compiler-package-browser.mjs +120 -0
- package/tools/backends/compiler-package-legacy.mjs +654 -0
- package/tools/backends/compiler-package.mjs +464 -0
- package/tools/backends/compiler-project.mjs +126 -0
- package/tools/backends/compiler-session.mjs +843 -0
- package/tools/backends/compiler-sha256.mjs +152 -0
- package/tools/backends/compiler-unicode-profile-host.mjs +196 -0
- package/tools/backends/compiler-worker.mjs +573 -0
- package/tools/backends/dist/bootstrap-js-stages.mjs +919 -0
- package/tools/backends/dist/bootstrap-js-stages.mjs.map +1 -0
- package/tools/backends/dist/managed-ir-inventory.mjs +488 -0
- package/tools/backends/dist/managed-ir-inventory.mjs.map +1 -0
- package/tools/backends/dist/record-grid.mjs +1256 -0
- package/tools/backends/dist/record-grid.mjs.map +1 -0
- package/tools/backends/dist/release-cli.mjs +460 -0
- package/tools/backends/dist/release-cli.mjs.map +1 -0
- package/tools/backends/dist/run-artifact.mjs +517 -0
- package/tools/backends/dist/run-artifact.mjs.map +1 -0
- package/tools/backends/eliscript/compiler-corpus-bit.eli +77 -0
- package/tools/backends/eliscript/compiler-corpus-debugging.eli +70 -0
- package/tools/backends/eliscript/compiler-corpus-project-entry-host.eli +256 -0
- package/tools/backends/managed-foreign-binding.mjs +497 -0
- package/tools/backends/managed-host-legacy.mjs +1181 -0
- package/tools/backends/managed-host-lifecycle.mjs +310 -0
- package/tools/backends/managed-host-object-provider.mjs +155 -0
- package/tools/backends/managed-host-object-realm.mjs +797 -0
- package/tools/backends/managed-host-proxy.mjs +71 -0
- package/tools/backends/managed-host-runtime.mjs +5868 -0
- package/tools/backends/managed-host.mjs +716 -0
- package/tools/backends/managed-module-graph-legacy.mjs +308 -0
- package/tools/backends/managed-module-graph.mjs +694 -0
- package/tools/backends/managed-runtime-host-legacy.mjs +195 -0
- package/tools/backends/managed-runtime.mjs +939 -0
- package/tools/backends/managed-source-view-legacy.mjs +332 -0
- package/tools/backends/managed-source-view.mjs +959 -0
- package/tools/backends/memory-runtime.mjs +100 -0
- package/tools/backends/native-benchmark.mjs +88 -0
- package/tools/backends/native-managed-runtime.mjs +677 -0
- package/tools/backends/native-memory.mjs +768 -0
- package/tools/backends/native-node-memory.mjs +142 -0
- package/tools/backends/native-node-runner.mjs +99 -0
- package/tools/backends/native-node-watchdog.mjs +19 -0
- package/tools/backends/native-node-worker.mjs +75 -0
- package/tools/backends/stage3-targets.mjs +486 -0
- package/tools/bootstrap-command.el +13 -0
- package/tools/bootstrap-runtime.el +101 -0
- package/tools/bootstrap-seed.el +55 -0
- package/tools/project/check-cli.eli +31 -0
- package/tools/project/project-cli.eli +42 -0
- package/tools/project/project.eli +122 -0
- package/tools/runtime/unicode-case-profiles.mjs +13 -0
- package/tools/runtime/unicode-case-runtime.el +57 -0
- package/tools/testing/source-debugging-corpus-host.eli +16 -0
- package/tools/testing/source-debugging.eli +139 -0
- package/tools/testing/stdlib-bit-corpus-host.eli +21 -0
- package/tools/testing/stdlib-bit-corpus-host.mjs +118 -0
- package/tools/testing/stdlib-bit.eli +104 -0
- package/tools/testing/stdlib-bit.mjs +255 -0
- package/bin/eliscript-bootstrap +0 -15
|
@@ -0,0 +1,2458 @@
|
|
|
1
|
+
// Generated by Eliscript. Do not edit.
|
|
2
|
+
import "eliscript/runtime/unicode-case.mjs";
|
|
3
|
+
const __eliscript_truthy = (value) => value !== false && value != null;
|
|
4
|
+
const __eliscript_number_intrinsic = globalThis.Number;
|
|
5
|
+
const __eliscript_bigint_intrinsic = globalThis.BigInt;
|
|
6
|
+
const __eliscript_numeric_apply = globalThis.Reflect.apply;
|
|
7
|
+
const __eliscript_numeric_symbol = globalThis.Symbol.toPrimitive;
|
|
8
|
+
const __eliscript_numeric_error = globalThis.TypeError;
|
|
9
|
+
const __eliscript_numeric_trim = globalThis.String.prototype.trim;
|
|
10
|
+
const __eliscript_numeric_slice = globalThis.String.prototype.slice;
|
|
11
|
+
const __eliscript_numeric_exec = globalThis.RegExp.prototype.exec;
|
|
12
|
+
const __eliscript_numeric_radix = /^(?:0[xX][0-9a-fA-F]+|0[oO][0-7]+|0[bB][01]+)$/;
|
|
13
|
+
const __eliscript_numeric_object = (value) => value !== null && (typeof value === "object" || typeof value === "function" || (typeof value === "undefined" && value !== void 0));
|
|
14
|
+
const __eliscript_numeric_primitive = (value) => {
|
|
15
|
+
if (!__eliscript_numeric_object(value)) return value;
|
|
16
|
+
const exotic = value[__eliscript_numeric_symbol];
|
|
17
|
+
if (exotic !== void 0 && exotic !== null) {
|
|
18
|
+
const result = __eliscript_numeric_apply(exotic, value, ["number"]);
|
|
19
|
+
if (!__eliscript_numeric_object(result)) return result;
|
|
20
|
+
throw new __eliscript_numeric_error("Cannot convert object to primitive value");
|
|
21
|
+
}
|
|
22
|
+
for (let index = 0; index < 2; index++) {
|
|
23
|
+
const method = value[index === 0 ? "valueOf" : "toString"];
|
|
24
|
+
if (typeof method === "function" || (typeof method === "undefined" && method !== void 0)) {
|
|
25
|
+
const result = __eliscript_numeric_apply(method, value, []);
|
|
26
|
+
if (!__eliscript_numeric_object(result)) return result;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
throw new __eliscript_numeric_error("Cannot convert object to primitive value");
|
|
30
|
+
};
|
|
31
|
+
const __eliscript_to_number = (value) => {
|
|
32
|
+
const primitive = __eliscript_numeric_primitive(value);
|
|
33
|
+
if (typeof primitive === "string") {
|
|
34
|
+
const text = __eliscript_numeric_apply(__eliscript_numeric_trim, primitive, []);
|
|
35
|
+
if (__eliscript_numeric_apply(__eliscript_numeric_exec, __eliscript_numeric_radix, [text]) !== null) {
|
|
36
|
+
let first = 2;
|
|
37
|
+
while (first < text.length && text[first] === "0") first++;
|
|
38
|
+
if (first === text.length) return 0;
|
|
39
|
+
const prefix = text[1];
|
|
40
|
+
const limit = prefix === "x" || prefix === "X" ? 256 : prefix === "b" || prefix === "B" ? 1024 : 342;
|
|
41
|
+
if (text.length - first > limit) return 1 / 0;
|
|
42
|
+
const token = __eliscript_numeric_apply(__eliscript_numeric_slice, text, [0, 2]) + __eliscript_numeric_apply(__eliscript_numeric_slice, text, [first]);
|
|
43
|
+
return __eliscript_number_intrinsic(__eliscript_bigint_intrinsic(token));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return __eliscript_number_intrinsic(primitive);
|
|
47
|
+
};
|
|
48
|
+
const __eliscript_numeric = (value) => {
|
|
49
|
+
if (typeof value === "number" || typeof value === "bigint") return value;
|
|
50
|
+
const primitive = __eliscript_numeric_primitive(value);
|
|
51
|
+
if (typeof primitive === "number" || typeof primitive === "bigint") return primitive;
|
|
52
|
+
return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
|
|
53
|
+
};
|
|
54
|
+
const __eliscript_implicit_number = (value) => {
|
|
55
|
+
if (typeof value === "number") return value;
|
|
56
|
+
const primitive = __eliscript_numeric_primitive(value);
|
|
57
|
+
if (typeof primitive === "bigint") throw new __eliscript_numeric_error("Cannot convert a BigInt value to a number");
|
|
58
|
+
return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
|
|
59
|
+
};
|
|
60
|
+
const __eliscript_numeric_decrement = (value) => __eliscript_implicit_number(value) - 1;
|
|
61
|
+
const __eliscript_numeric_sub = (a, b) => { if (typeof a === "number" && typeof b === "number") return a - b; return __eliscript_numeric(a) - __eliscript_numeric(b); };
|
|
62
|
+
const __eliscript_numeric_mul = (a, b) => { if (typeof a === "number" && typeof b === "number") return a * b; return __eliscript_numeric(a) * __eliscript_numeric(b); };
|
|
63
|
+
const __eliscript_numeric_div = (a, b) => { if (typeof a === "number" && typeof b === "number") return a / b; return __eliscript_numeric(a) / __eliscript_numeric(b); };
|
|
64
|
+
const __eliscript_numeric_rem = (a, b) => { if (typeof a === "number" && typeof b === "number") return a % b; return __eliscript_numeric(a) % __eliscript_numeric(b); };
|
|
65
|
+
const __eliscript_numeric_and = (a, b) => { if (typeof a === "number" && typeof b === "number") return a & b; return __eliscript_numeric(a) & __eliscript_numeric(b); };
|
|
66
|
+
const __eliscript_numeric_or = (a, b) => { if (typeof a === "number" && typeof b === "number") return a | b; return __eliscript_numeric(a) | __eliscript_numeric(b); };
|
|
67
|
+
const __eliscript_numeric_xor = (a, b) => { if (typeof a === "number" && typeof b === "number") return a ^ b; return __eliscript_numeric(a) ^ __eliscript_numeric(b); };
|
|
68
|
+
const __eliscript_numeric_shl = (a, b) => { if (typeof a === "number" && typeof b === "number") return a << b; return __eliscript_numeric(a) << __eliscript_numeric(b); };
|
|
69
|
+
const __eliscript_numeric_shr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >> b; return __eliscript_numeric(a) >> __eliscript_numeric(b); };
|
|
70
|
+
const __eliscript_numeric_ushr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >>> b; return __eliscript_numeric(a) >>> __eliscript_numeric(b); };
|
|
71
|
+
const __eliscript_numeric_neg = (a) => typeof a === "number" ? -a : -__eliscript_numeric(a);
|
|
72
|
+
const __eliscript_numeric_int32 = (a) => typeof a === "number" ? a | 0 : __eliscript_numeric(a) | 0;
|
|
73
|
+
const __eliscript_numeric_uint32 = (a) => typeof a === "number" ? a >>> 0 : __eliscript_numeric(a) >>> 0;
|
|
74
|
+
const __eliscript_numeric_not = (a) => typeof a === "number" ? ~a : ~__eliscript_numeric(a);
|
|
75
|
+
const __eliscript_numeric_relation = (operator, left, right) => {
|
|
76
|
+
if (typeof left === "number" && typeof right === "number") {
|
|
77
|
+
if (operator === "<") return left < right;
|
|
78
|
+
if (operator === "<=") return left <= right;
|
|
79
|
+
if (operator === ">") return left > right;
|
|
80
|
+
return left >= right;
|
|
81
|
+
}
|
|
82
|
+
let a = __eliscript_numeric_primitive(left);
|
|
83
|
+
let b = __eliscript_numeric_primitive(right);
|
|
84
|
+
const x = typeof a, y = typeof b;
|
|
85
|
+
if (!((x === "string" && y === "string") || (x === "bigint" && y === "string") || (x === "string" && y === "bigint"))) {
|
|
86
|
+
a = __eliscript_numeric(a);
|
|
87
|
+
b = __eliscript_numeric(b);
|
|
88
|
+
}
|
|
89
|
+
if (operator === "<") return a < b;
|
|
90
|
+
if (operator === "<=") return a <= b;
|
|
91
|
+
if (operator === ">") return a > b;
|
|
92
|
+
return a >= b;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
import {emit_module_numeric} from "../bootstrap/emitter.mjs";
|
|
96
|
+
import {optimize_program} from "./optimize.mjs";
|
|
97
|
+
function backend_fail(node, message) {
|
|
98
|
+
{
|
|
99
|
+
let record = ((__eliscript_value_1) => (__eliscript_truthy(__eliscript_value_1) ? __eliscript_value_1 : ({})))(node);
|
|
100
|
+
let span = ((__eliscript_value_2) => (__eliscript_truthy(__eliscript_value_2) ? __eliscript_value_2 : ({})))(((record)["span"] ?? null));
|
|
101
|
+
return ((__eliscript_value_3) => { throw __eliscript_value_3; })(({"message": message, "eliscriptDiagnostic": ({"format": "eliscript-diagnostic", "version": 1, "code": "ELI-B0001", "severity": "error", "phase": "numeric-backend", "message": message, "location": ({"file": ((span)["filename"] ?? ((record)["filename"] ?? "<ir>")), "start": ({"line": ((span)["line"] ?? 1), "column": ((span)["column"] ?? 1)})})})}));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function find_local(scope, name) {
|
|
105
|
+
{
|
|
106
|
+
const __eliscript_value_4 = __eliscript_numeric_decrement(((scope) ?? []).length);
|
|
107
|
+
const __eliscript_value_5 = null;
|
|
108
|
+
{
|
|
109
|
+
let index = __eliscript_value_4;
|
|
110
|
+
let found = __eliscript_value_5;
|
|
111
|
+
while ((__eliscript_numeric_relation(">=", index, 0) && (!__eliscript_truthy(found)))) {
|
|
112
|
+
{
|
|
113
|
+
const __eliscript_value_6 = ((((scope) ?? [])[index]) ?? null);
|
|
114
|
+
{
|
|
115
|
+
let entry = __eliscript_value_6;
|
|
116
|
+
if (((entry)["name"] === name)) {
|
|
117
|
+
((found = entry));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
((index = __eliscript_numeric_decrement(index)));
|
|
122
|
+
}
|
|
123
|
+
return found;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function find_function(functions, name) {
|
|
128
|
+
{
|
|
129
|
+
const __eliscript_value_7 = 0;
|
|
130
|
+
const __eliscript_value_8 = null;
|
|
131
|
+
{
|
|
132
|
+
let index = __eliscript_value_7;
|
|
133
|
+
let found = __eliscript_value_8;
|
|
134
|
+
while ((__eliscript_numeric_relation("<", index, ((functions) ?? []).length) && (!__eliscript_truthy(found)))) {
|
|
135
|
+
if (((((((functions) ?? [])[index]) ?? null))["name"] === name)) {
|
|
136
|
+
((found = ((((functions) ?? [])[index]) ?? null)));
|
|
137
|
+
}
|
|
138
|
+
((index = (index + 1)));
|
|
139
|
+
}
|
|
140
|
+
return found;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function typed(kind, type, children, value) {
|
|
145
|
+
return ({"kind": kind, "type": type, "children": children, "value": value});
|
|
146
|
+
}
|
|
147
|
+
function require_type(original, expression, type) {
|
|
148
|
+
if ((!((expression)["type"] === type))) {
|
|
149
|
+
backend_fail(original, (String(((type === "u32") ? "memory-u32" : "numeric-f64")) + String(" ABI requires ") + String(type) + String(" operands")));
|
|
150
|
+
}
|
|
151
|
+
return expression;
|
|
152
|
+
}
|
|
153
|
+
function typed_sequence(nodes, scope, state, functions, discarded = null) {
|
|
154
|
+
{
|
|
155
|
+
const __eliscript_value_9 = [];
|
|
156
|
+
const __eliscript_value_10 = 0;
|
|
157
|
+
const __eliscript_value_11 = "i32";
|
|
158
|
+
{
|
|
159
|
+
let result = __eliscript_value_9;
|
|
160
|
+
let index = __eliscript_value_10;
|
|
161
|
+
let type = __eliscript_value_11;
|
|
162
|
+
while (__eliscript_numeric_relation("<", index, ((nodes) ?? []).length)) {
|
|
163
|
+
{
|
|
164
|
+
const __eliscript_value_12 = lower_expression(((((nodes) ?? [])[index]) ?? null), scope, state, functions, ((__eliscript_value_13) => (__eliscript_truthy(__eliscript_value_13) ? __eliscript_value_13 : __eliscript_numeric_relation("<", index, __eliscript_numeric_decrement(((nodes) ?? []).length))))(discarded));
|
|
165
|
+
{
|
|
166
|
+
let expression = __eliscript_value_12;
|
|
167
|
+
((type = (expression)["type"]));
|
|
168
|
+
(result)["push"](expression);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
((index = (index + 1)));
|
|
172
|
+
}
|
|
173
|
+
return typed("sequence", type, result, null);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function new_local(state, name, type) {
|
|
178
|
+
{
|
|
179
|
+
let locals = (state)["locals"];
|
|
180
|
+
let entry = ({"name": name, "type": type, "index": ((locals) ?? []).length});
|
|
181
|
+
(locals)["push"](entry);
|
|
182
|
+
return entry;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function lower_bindings(node, scope, state, functions) {
|
|
186
|
+
{
|
|
187
|
+
let properties = (node)["properties"];
|
|
188
|
+
let count = (properties)["bindingCount"];
|
|
189
|
+
let children = (node)["children"];
|
|
190
|
+
let inner = (scope)["slice"]();
|
|
191
|
+
let initializers = [];
|
|
192
|
+
let pending = [];
|
|
193
|
+
let index = 0;
|
|
194
|
+
while (__eliscript_numeric_relation("<", index, count)) {
|
|
195
|
+
{
|
|
196
|
+
const __eliscript_value_14 = ((((children) ?? [])[index]) ?? null);
|
|
197
|
+
{
|
|
198
|
+
let binding = __eliscript_value_14;
|
|
199
|
+
if ((!(((binding)["kind"] === "lexical-binding") && ((((binding)["children"]) ?? []).length === 1)))) {
|
|
200
|
+
backend_fail(binding, "numeric-f64 ABI requires simple initialized bindings");
|
|
201
|
+
}
|
|
202
|
+
if (__eliscript_truthy(find_local(pending, (binding)["value"]))) {
|
|
203
|
+
backend_fail(binding, "duplicate lexical binding");
|
|
204
|
+
}
|
|
205
|
+
{
|
|
206
|
+
let init = lower_expression((((((binding)["children"]) ?? [])[0]) ?? null), (__eliscript_truthy((properties)["sequential"]) ? inner : scope), state, functions);
|
|
207
|
+
let local = new_local(state, (binding)["value"], (init)["type"]);
|
|
208
|
+
(initializers)["push"](typed("initialize", (init)["type"], [init], (local)["index"]));
|
|
209
|
+
(pending)["push"](local);
|
|
210
|
+
if (__eliscript_truthy((properties)["sequential"])) {
|
|
211
|
+
(inner)["push"](local);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
((index = (index + 1)));
|
|
217
|
+
}
|
|
218
|
+
if ((!__eliscript_truthy((properties)["sequential"]))) {
|
|
219
|
+
{
|
|
220
|
+
const __eliscript_value_15 = 0;
|
|
221
|
+
{
|
|
222
|
+
let index = __eliscript_value_15;
|
|
223
|
+
while (__eliscript_numeric_relation("<", index, ((pending) ?? []).length)) {
|
|
224
|
+
(inner)["push"](((((pending) ?? [])[index]) ?? null));
|
|
225
|
+
((index = (index + 1)));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
{
|
|
231
|
+
const __eliscript_value_16 = typed_sequence((children)["slice"](count), inner, state, functions, ((state)["discarded"] ?? null));
|
|
232
|
+
{
|
|
233
|
+
let body = __eliscript_value_16;
|
|
234
|
+
(initializers)["push"](body);
|
|
235
|
+
return typed("sequence", (body)["type"], initializers, null);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function lower_expression(node, scope, state, functions, discarded = null) {
|
|
241
|
+
{
|
|
242
|
+
const __eliscript_value_17 = ((state)["discarded"] ?? null);
|
|
243
|
+
{
|
|
244
|
+
let previous = __eliscript_value_17;
|
|
245
|
+
((state)["discarded"] = discarded);
|
|
246
|
+
{
|
|
247
|
+
const __eliscript_value_18 = lower_expression_body(node, scope, state, functions);
|
|
248
|
+
const __eliscript_value_19 = ((node)["span"] ?? null);
|
|
249
|
+
{
|
|
250
|
+
let lowered = __eliscript_value_18;
|
|
251
|
+
let span = __eliscript_value_19;
|
|
252
|
+
((state)["discarded"] = previous);
|
|
253
|
+
if (__eliscript_truthy(span)) {
|
|
254
|
+
((lowered)["span"] = span);
|
|
255
|
+
}
|
|
256
|
+
return lowered;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function lower_conditional_chain(node, scope, state, functions) {
|
|
263
|
+
{
|
|
264
|
+
const __eliscript_value_20 = (node)["children"];
|
|
265
|
+
const __eliscript_value_21 = [];
|
|
266
|
+
const __eliscript_value_22 = ((state)["discarded"] ?? null);
|
|
267
|
+
const __eliscript_value_23 = 0;
|
|
268
|
+
const __eliscript_value_24 = typed("literal", "i32", [], 0);
|
|
269
|
+
{
|
|
270
|
+
let clauses = __eliscript_value_20;
|
|
271
|
+
let lowered = __eliscript_value_21;
|
|
272
|
+
let discarded = __eliscript_value_22;
|
|
273
|
+
let index = __eliscript_value_23;
|
|
274
|
+
let zero = __eliscript_value_24;
|
|
275
|
+
while (__eliscript_numeric_relation("<", index, ((clauses) ?? []).length)) {
|
|
276
|
+
{
|
|
277
|
+
let clause = ((((clauses) ?? [])[index]) ?? null);
|
|
278
|
+
let parts = (clause)["children"];
|
|
279
|
+
if ((!(((clause)["kind"] === "conditional-clause") && __eliscript_numeric_relation(">", ((parts) ?? []).length, 0)))) {
|
|
280
|
+
backend_fail(clause, "cond requires nonempty clauses");
|
|
281
|
+
}
|
|
282
|
+
{
|
|
283
|
+
let test = ((((parts) ?? [])[0]) ?? null);
|
|
284
|
+
let condition = lower_expression(test, scope, state, functions);
|
|
285
|
+
let single = (((parts) ?? []).length === 1);
|
|
286
|
+
let saved = ((__eliscript_value_25) => (__eliscript_truthy(__eliscript_value_25) ? new_local(state, "cond-test", (condition)["type"]) : __eliscript_value_25))(single);
|
|
287
|
+
let body = (__eliscript_truthy(single) ? typed("local", (condition)["type"], [], (saved)["index"]) : typed_sequence((parts)["slice"](1), scope, state, functions, discarded));
|
|
288
|
+
if (__eliscript_truthy(discarded)) {
|
|
289
|
+
((body = typed("sequence", "i32", [body, zero], null)));
|
|
290
|
+
}
|
|
291
|
+
(lowered)["push"](({"source": clause, "test": test, "condition": condition, "saved": saved, "body": body}));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
((index = (index + 1)));
|
|
295
|
+
}
|
|
296
|
+
{
|
|
297
|
+
const __eliscript_value_26 = zero;
|
|
298
|
+
const __eliscript_value_27 = __eliscript_numeric_decrement(((lowered) ?? []).length);
|
|
299
|
+
{
|
|
300
|
+
let result = __eliscript_value_26;
|
|
301
|
+
let index = __eliscript_value_27;
|
|
302
|
+
while (__eliscript_numeric_relation(">=", index, 0)) {
|
|
303
|
+
{
|
|
304
|
+
let entry = ((((lowered) ?? [])[index]) ?? null);
|
|
305
|
+
let test = (entry)["test"];
|
|
306
|
+
let condition = (entry)["condition"];
|
|
307
|
+
let saved = (entry)["saved"];
|
|
308
|
+
let body = (entry)["body"];
|
|
309
|
+
let always = (((test)["kind"] === "literal") && (((__eliscript_value) => { if (__eliscript_value === null) return "null"; const __eliscript_host_type = typeof __eliscript_value; if (__eliscript_host_type !== "object" && __eliscript_host_type !== "function") return __eliscript_host_type; try { const __eliscript_type = Object.getOwnPropertyDescriptor(__eliscript_value, Symbol.for("eliscript.value.type")); if (__eliscript_type && Object.prototype.hasOwnProperty.call(__eliscript_type, "value") && (__eliscript_type.value === "keyword" || __eliscript_type.value === "symbol")) return __eliscript_type.value; const __eliscript_kind = Object.getOwnPropertyDescriptor(__eliscript_value, "kind"); if (__eliscript_kind && Object.prototype.hasOwnProperty.call(__eliscript_kind, "value")) { if (__eliscript_kind.value === "eliscript/keyword") return "keyword"; if (__eliscript_kind.value === "eliscript/symbol") return "symbol"; } return __eliscript_host_type; } catch { return __eliscript_host_type; } })((test)["value"]) === "boolean") && ((test)["value"] === true));
|
|
310
|
+
if (__eliscript_truthy(always)) {
|
|
311
|
+
((result = body));
|
|
312
|
+
} else {
|
|
313
|
+
require_type((entry)["source"], result, (body)["type"]);
|
|
314
|
+
((result = typed("if", (body)["type"], [(__eliscript_truthy(saved) ? typed("local", (condition)["type"], [], (saved)["index"]) : condition), body, result], null)));
|
|
315
|
+
}
|
|
316
|
+
if (__eliscript_truthy(saved)) {
|
|
317
|
+
((result = typed("sequence", (result)["type"], [typed("initialize", (condition)["type"], [condition], (saved)["index"]), result], null)));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
((index = __eliscript_numeric_decrement(index)));
|
|
321
|
+
}
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function lower_expression_body(node, scope, state, functions) {
|
|
329
|
+
{
|
|
330
|
+
const __eliscript_value_28 = (node)["kind"];
|
|
331
|
+
const __eliscript_value_29 = (node)["value"];
|
|
332
|
+
const __eliscript_value_30 = (node)["children"];
|
|
333
|
+
{
|
|
334
|
+
let kind = __eliscript_value_28;
|
|
335
|
+
let value = __eliscript_value_29;
|
|
336
|
+
let children = __eliscript_value_30;
|
|
337
|
+
if (((kind === "literal") && (!__eliscript_truthy(((node)["properties"] ?? null))))) {
|
|
338
|
+
if ((((__eliscript_value) => { if (__eliscript_value === null) return "null"; const __eliscript_host_type = typeof __eliscript_value; if (__eliscript_host_type !== "object" && __eliscript_host_type !== "function") return __eliscript_host_type; try { const __eliscript_type = Object.getOwnPropertyDescriptor(__eliscript_value, Symbol.for("eliscript.value.type")); if (__eliscript_type && Object.prototype.hasOwnProperty.call(__eliscript_type, "value") && (__eliscript_type.value === "keyword" || __eliscript_type.value === "symbol")) return __eliscript_type.value; const __eliscript_kind = Object.getOwnPropertyDescriptor(__eliscript_value, "kind"); if (__eliscript_kind && Object.prototype.hasOwnProperty.call(__eliscript_kind, "value")) { if (__eliscript_kind.value === "eliscript/keyword") return "keyword"; if (__eliscript_kind.value === "eliscript/symbol") return "symbol"; } return __eliscript_host_type; } catch { return __eliscript_host_type; } })(value) === "number")) {
|
|
339
|
+
{
|
|
340
|
+
const __eliscript_value_31 = ((state)["scalarType"] ?? "f64");
|
|
341
|
+
{
|
|
342
|
+
let type = __eliscript_value_31;
|
|
343
|
+
if (((type === "u32") && (((__eliscript_value_32, __eliscript_value_33) => (__eliscript_value_32 !== __eliscript_value_33))(value, __eliscript_numeric_uint32(value)) || __eliscript_numeric_relation("<", value, 0) || __eliscript_numeric_relation(">", value, 4294967295) || ((value === 0) && __eliscript_numeric_relation("<", __eliscript_numeric_div(1, value), 0))))) {
|
|
344
|
+
backend_fail(node, "memory-u32 literals must be unsigned integers, excluding negative zero");
|
|
345
|
+
}
|
|
346
|
+
return typed("literal", type, [], value);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
if (((((__eliscript_value) => { if (__eliscript_value === null) return "null"; const __eliscript_host_type = typeof __eliscript_value; if (__eliscript_host_type !== "object" && __eliscript_host_type !== "function") return __eliscript_host_type; try { const __eliscript_type = Object.getOwnPropertyDescriptor(__eliscript_value, Symbol.for("eliscript.value.type")); if (__eliscript_type && Object.prototype.hasOwnProperty.call(__eliscript_type, "value") && (__eliscript_type.value === "keyword" || __eliscript_type.value === "symbol")) return __eliscript_type.value; const __eliscript_kind = Object.getOwnPropertyDescriptor(__eliscript_value, "kind"); if (__eliscript_kind && Object.prototype.hasOwnProperty.call(__eliscript_kind, "value")) { if (__eliscript_kind.value === "eliscript/keyword") return "keyword"; if (__eliscript_kind.value === "eliscript/symbol") return "symbol"; } return __eliscript_host_type; } catch { return __eliscript_host_type; } })(value) === "boolean") || (value === null))) {
|
|
351
|
+
return typed("literal", "i32", [], (__eliscript_truthy(value) ? 1 : 0));
|
|
352
|
+
} else {
|
|
353
|
+
return backend_fail(node, "numeric-f64 ABI does not support this literal");
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
} else {
|
|
357
|
+
if ((kind === "reference")) {
|
|
358
|
+
{
|
|
359
|
+
const __eliscript_value_34 = find_local(scope, value);
|
|
360
|
+
{
|
|
361
|
+
let local = __eliscript_value_34;
|
|
362
|
+
if ((!__eliscript_truthy(local))) {
|
|
363
|
+
backend_fail(node, (String("unknown numeric local: ") + String(value)));
|
|
364
|
+
}
|
|
365
|
+
return typed("local", (local)["type"], [], (local)["index"]);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
if ((kind === "lexical-bindings")) {
|
|
370
|
+
return lower_bindings(node, scope, state, functions);
|
|
371
|
+
} else {
|
|
372
|
+
if ((kind === "sequence")) {
|
|
373
|
+
return typed_sequence(children, scope, state, functions, ((state)["discarded"] ?? null));
|
|
374
|
+
} else {
|
|
375
|
+
if ((kind === "conditional-chain")) {
|
|
376
|
+
return lower_conditional_chain(node, scope, state, functions);
|
|
377
|
+
} else {
|
|
378
|
+
if ((kind === "assignment")) {
|
|
379
|
+
{
|
|
380
|
+
const __eliscript_value_35 = [];
|
|
381
|
+
const __eliscript_value_36 = 0;
|
|
382
|
+
const __eliscript_value_37 = "i32";
|
|
383
|
+
{
|
|
384
|
+
let assignments = __eliscript_value_35;
|
|
385
|
+
let index = __eliscript_value_36;
|
|
386
|
+
let type = __eliscript_value_37;
|
|
387
|
+
while (__eliscript_numeric_relation("<", index, ((children) ?? []).length)) {
|
|
388
|
+
{
|
|
389
|
+
let pair = ((((children) ?? [])[index]) ?? null);
|
|
390
|
+
let local = find_local(scope, (pair)["value"]);
|
|
391
|
+
if ((!__eliscript_truthy(((__eliscript_value_38) => (__eliscript_truthy(__eliscript_value_38) ? local : __eliscript_value_38))(((pair)["kind"] === "assignment-pair"))))) {
|
|
392
|
+
backend_fail(pair, "assignment must address an existing numeric local");
|
|
393
|
+
}
|
|
394
|
+
{
|
|
395
|
+
const __eliscript_value_39 = lower_expression((((((pair)["children"]) ?? [])[0]) ?? null), scope, state, functions);
|
|
396
|
+
{
|
|
397
|
+
let rhs = __eliscript_value_39;
|
|
398
|
+
require_type(pair, rhs, (local)["type"]);
|
|
399
|
+
((type = (rhs)["type"]));
|
|
400
|
+
(assignments)["push"](typed("set", type, [rhs], (local)["index"]));
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
((index = (index + 1)));
|
|
405
|
+
}
|
|
406
|
+
return typed("sequence", type, assignments, null);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
} else {
|
|
410
|
+
if (((kind === "loop") && (value === "while"))) {
|
|
411
|
+
return typed("while", "i32", [lower_expression(((((children) ?? [])[0]) ?? null), scope, state, functions), typed_sequence((children)["slice"](1), scope, state, functions, true)], null);
|
|
412
|
+
} else {
|
|
413
|
+
if (((((state)["scalarType"] ?? "f64") === "u32") && (kind === "conditional-sugar") && ((value === "when") || (value === "unless")))) {
|
|
414
|
+
{
|
|
415
|
+
let condition = lower_expression(((((children) ?? [])[0]) ?? null), scope, state, functions);
|
|
416
|
+
let body = typed_sequence((children)["slice"](1), scope, state, functions, true);
|
|
417
|
+
let zero = typed("literal", "i32", [], 0);
|
|
418
|
+
let yes = typed("sequence", "i32", [body, zero], null);
|
|
419
|
+
return typed("if", "i32", ((value === "when") ? [condition, yes, zero] : [condition, zero, yes]), null);
|
|
420
|
+
}
|
|
421
|
+
} else {
|
|
422
|
+
if (((kind === "conditional") && (((children) ?? []).length === 3))) {
|
|
423
|
+
{
|
|
424
|
+
let condition = lower_expression(((((children) ?? [])[0]) ?? null), scope, state, functions);
|
|
425
|
+
let yes = lower_expression(((((children) ?? [])[1]) ?? null), scope, state, functions, ((state)["discarded"] ?? null));
|
|
426
|
+
let no = lower_expression(((((children) ?? [])[2]) ?? null), scope, state, functions, ((state)["discarded"] ?? null));
|
|
427
|
+
if (__eliscript_truthy(((state)["discarded"] ?? null))) {
|
|
428
|
+
{
|
|
429
|
+
const __eliscript_value_40 = typed("literal", "i32", [], 0);
|
|
430
|
+
{
|
|
431
|
+
let zero = __eliscript_value_40;
|
|
432
|
+
((yes = typed("sequence", "i32", [yes, zero], null)));
|
|
433
|
+
((no = typed("sequence", "i32", [no, zero], null)));
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
require_type(node, no, (yes)["type"]);
|
|
438
|
+
return typed("if", (yes)["type"], [condition, yes, no], null);
|
|
439
|
+
}
|
|
440
|
+
} else {
|
|
441
|
+
if (((kind === "short-circuit") && ((value === "and") || (value === "or")) && __eliscript_numeric_relation(">", ((children) ?? []).length, 0))) {
|
|
442
|
+
{
|
|
443
|
+
const __eliscript_value_41 = [];
|
|
444
|
+
const __eliscript_value_42 = 0;
|
|
445
|
+
const __eliscript_value_43 = null;
|
|
446
|
+
{
|
|
447
|
+
let operands = __eliscript_value_41;
|
|
448
|
+
let index = __eliscript_value_42;
|
|
449
|
+
let type = __eliscript_value_43;
|
|
450
|
+
while (__eliscript_numeric_relation("<", index, ((children) ?? []).length)) {
|
|
451
|
+
{
|
|
452
|
+
const __eliscript_value_44 = lower_expression(((((children) ?? [])[index]) ?? null), scope, state, functions);
|
|
453
|
+
{
|
|
454
|
+
let operand = __eliscript_value_44;
|
|
455
|
+
if (__eliscript_truthy(type)) {
|
|
456
|
+
require_type(node, operand, type);
|
|
457
|
+
} else {
|
|
458
|
+
((type = (operand)["type"]));
|
|
459
|
+
}
|
|
460
|
+
(operands)["push"](operand);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
((index = (index + 1)));
|
|
464
|
+
}
|
|
465
|
+
return typed(value, type, operands, null);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
} else {
|
|
469
|
+
if ((kind === "intrinsic")) {
|
|
470
|
+
{
|
|
471
|
+
const __eliscript_value_45 = [];
|
|
472
|
+
const __eliscript_value_46 = 0;
|
|
473
|
+
const __eliscript_value_47 = ((state)["scalarType"] ?? "f64");
|
|
474
|
+
{
|
|
475
|
+
let operands = __eliscript_value_45;
|
|
476
|
+
let index = __eliscript_value_46;
|
|
477
|
+
let operand_type = __eliscript_value_47;
|
|
478
|
+
while (__eliscript_numeric_relation("<", index, ((children) ?? []).length)) {
|
|
479
|
+
(operands)["push"](lower_expression(((((children) ?? [])[index]) ?? null), scope, state, functions));
|
|
480
|
+
((index = (index + 1)));
|
|
481
|
+
}
|
|
482
|
+
if ((__eliscript_numeric_relation(">", ((operands) ?? []).length, 0) && ((((((operands) ?? [])[0]) ?? null))["type"] === "f64"))) {
|
|
483
|
+
((operand_type = "f64"));
|
|
484
|
+
}
|
|
485
|
+
if (((value === "not") && (((operands) ?? []).length === 1))) {
|
|
486
|
+
return typed("not", "i32", operands, null);
|
|
487
|
+
} else {
|
|
488
|
+
if ((((value === "+") || (value === "-") || (value === "*") || (value === "/")) && __eliscript_numeric_relation("<=", ((operands) ?? []).length, 2) && (__eliscript_numeric_relation(">", ((operands) ?? []).length, 0) || (value === "+") || (value === "*")))) {
|
|
489
|
+
{
|
|
490
|
+
const __eliscript_value_48 = 0;
|
|
491
|
+
{
|
|
492
|
+
let index = __eliscript_value_48;
|
|
493
|
+
while (__eliscript_numeric_relation("<", index, ((operands) ?? []).length)) {
|
|
494
|
+
require_type(node, ((((operands) ?? [])[index]) ?? null), operand_type);
|
|
495
|
+
((index = (index + 1)));
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (((operand_type === "u32") && (value === "/"))) {
|
|
500
|
+
backend_fail(node, "memory-u32 division requires explicit word-div");
|
|
501
|
+
}
|
|
502
|
+
return typed(((operand_type === "u32") ? "word-arithmetic" : "arithmetic"), operand_type, operands, value);
|
|
503
|
+
} else {
|
|
504
|
+
if ((((value === "1+") || (value === "1-")) && (((operands) ?? []).length === 1))) {
|
|
505
|
+
require_type(node, ((((operands) ?? [])[0]) ?? null), operand_type);
|
|
506
|
+
return typed(((operand_type === "u32") ? "word-arithmetic" : "arithmetic"), operand_type, operands, value);
|
|
507
|
+
} else {
|
|
508
|
+
if ((((value === "=") || ((((state)["scalarType"] ?? "f64") === "u32") && (value === "/=")) || (value === "<") || (value === "<=") || (value === ">") || (value === ">=")) && (((operands) ?? []).length === 2))) {
|
|
509
|
+
require_type(node, ((((operands) ?? [])[0]) ?? null), operand_type);
|
|
510
|
+
require_type(node, ((((operands) ?? [])[1]) ?? null), operand_type);
|
|
511
|
+
return typed(((operand_type === "u32") ? "word-compare" : "compare"), "i32", operands, value);
|
|
512
|
+
} else {
|
|
513
|
+
return backend_fail(node, (String("unsupported numeric intrinsic: ") + String(value)));
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
} else {
|
|
521
|
+
if (((kind === "call") && __eliscript_numeric_relation(">", ((children) ?? []).length, 0) && ((((((children) ?? [])[0]) ?? null))["kind"] === "reference"))) {
|
|
522
|
+
{
|
|
523
|
+
let name = (((((children) ?? [])[0]) ?? null))["value"];
|
|
524
|
+
let capability = find_function(((state)["capabilities"] ?? []), name);
|
|
525
|
+
let function$ = ((__eliscript_value_49) => (__eliscript_truthy(__eliscript_value_49) ? __eliscript_value_49 : find_function(functions, name)))(capability);
|
|
526
|
+
let arguments$ = [];
|
|
527
|
+
let index = 1;
|
|
528
|
+
if (__eliscript_truthy(find_local(scope, name))) {
|
|
529
|
+
backend_fail(node, "numeric calls cannot resolve a shadowed function");
|
|
530
|
+
}
|
|
531
|
+
if ((!__eliscript_truthy(function$))) {
|
|
532
|
+
backend_fail(node, (String("unknown numeric function: ") + String(name)));
|
|
533
|
+
}
|
|
534
|
+
if ((!(__eliscript_numeric_decrement(((children) ?? []).length) === (function$)["arity"]))) {
|
|
535
|
+
backend_fail(node, "numeric call arity mismatch");
|
|
536
|
+
}
|
|
537
|
+
if (__eliscript_truthy(((__eliscript_value_50) => (__eliscript_truthy(__eliscript_value_50) ? ((capability)["staticLiteral"] ?? null) : __eliscript_value_50))(capability))) {
|
|
538
|
+
{
|
|
539
|
+
const __eliscript_value_51 = ((((children) ?? [])[1]) ?? null);
|
|
540
|
+
{
|
|
541
|
+
let literal = __eliscript_value_51;
|
|
542
|
+
if ((!(((literal)["kind"] === "literal") && (((literal)["properties"] ?? null) === null) && (((__eliscript_value) => { if (__eliscript_value === null) return "null"; const __eliscript_host_type = typeof __eliscript_value; if (__eliscript_host_type !== "object" && __eliscript_host_type !== "function") return __eliscript_host_type; try { const __eliscript_type = Object.getOwnPropertyDescriptor(__eliscript_value, Symbol.for("eliscript.value.type")); if (__eliscript_type && Object.prototype.hasOwnProperty.call(__eliscript_type, "value") && (__eliscript_type.value === "keyword" || __eliscript_type.value === "symbol")) return __eliscript_type.value; const __eliscript_kind = Object.getOwnPropertyDescriptor(__eliscript_value, "kind"); if (__eliscript_kind && Object.prototype.hasOwnProperty.call(__eliscript_kind, "value")) { if (__eliscript_kind.value === "eliscript/keyword") return "keyword"; if (__eliscript_kind.value === "eliscript/symbol") return "symbol"; } return __eliscript_host_type; } catch { return __eliscript_host_type; } })((literal)["value"]) === "number")))) {
|
|
543
|
+
backend_fail(node, "f64-literal requires one static Number literal");
|
|
544
|
+
}
|
|
545
|
+
return typed("literal", "f64", [], (literal)["value"]);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
} else {
|
|
549
|
+
if (__eliscript_truthy(((__eliscript_value_52) => (__eliscript_truthy(__eliscript_value_52) ? ((capability)["staticData"] ?? null) : __eliscript_value_52))(capability))) {
|
|
550
|
+
{
|
|
551
|
+
const __eliscript_value_53 = ((((children) ?? [])[2]) ?? null);
|
|
552
|
+
const __eliscript_value_54 = require_type(node, lower_expression(((((children) ?? [])[1]) ?? null), scope, state, functions), "u32");
|
|
553
|
+
{
|
|
554
|
+
let literal = __eliscript_value_53;
|
|
555
|
+
let destination = __eliscript_value_54;
|
|
556
|
+
if ((!(((literal)["kind"] === "literal") && (((literal)["properties"] ?? null) === null) && (((__eliscript_value) => { if (__eliscript_value === null) return "null"; const __eliscript_host_type = typeof __eliscript_value; if (__eliscript_host_type !== "object" && __eliscript_host_type !== "function") return __eliscript_host_type; try { const __eliscript_type = Object.getOwnPropertyDescriptor(__eliscript_value, Symbol.for("eliscript.value.type")); if (__eliscript_type && Object.prototype.hasOwnProperty.call(__eliscript_type, "value") && (__eliscript_type.value === "keyword" || __eliscript_type.value === "symbol")) return __eliscript_type.value; const __eliscript_kind = Object.getOwnPropertyDescriptor(__eliscript_value, "kind"); if (__eliscript_kind && Object.prototype.hasOwnProperty.call(__eliscript_kind, "value")) { if (__eliscript_kind.value === "eliscript/keyword") return "keyword"; if (__eliscript_kind.value === "eliscript/symbol") return "symbol"; } return __eliscript_host_type; } catch { return __eliscript_host_type; } })((literal)["value"]) === "string")))) {
|
|
557
|
+
backend_fail(node, "copy-static-u16 requires a static UTF16 string");
|
|
558
|
+
}
|
|
559
|
+
return typed("memory-data-copy", "u32", [destination], (literal)["value"]);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
} else {
|
|
563
|
+
while (__eliscript_numeric_relation("<", index, ((children) ?? []).length)) {
|
|
564
|
+
(arguments$)["push"](require_type(node, lower_expression(((((children) ?? [])[index]) ?? null), scope, state, functions), (__eliscript_truthy(((__eliscript_value_55) => (__eliscript_truthy(__eliscript_value_55) ? ((capability)["parameterTypes"] ?? null) : __eliscript_value_55))(capability)) ? (((((capability)["parameterTypes"]) ?? [])[__eliscript_numeric_decrement(index)]) ?? null) : ((state)["scalarType"] ?? "f64"))));
|
|
565
|
+
((index = (index + 1)));
|
|
566
|
+
}
|
|
567
|
+
return typed((__eliscript_truthy(capability) ? "memory-op" : "call"), (__eliscript_truthy(capability) ? ((capability)["resultType"] ?? ((state)["scalarType"] ?? "f64")) : ((state)["scalarType"] ?? "f64")), arguments$, (__eliscript_truthy(capability) ? name : (function$)["index"]));
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
} else {
|
|
572
|
+
return backend_fail(node, (String("unsupported numeric IR: ") + String(kind) + String(":") + String(value)));
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
function collect_declarations(nodes, declarations) {
|
|
589
|
+
{
|
|
590
|
+
const __eliscript_value_56 = 0;
|
|
591
|
+
{
|
|
592
|
+
let index = __eliscript_value_56;
|
|
593
|
+
while (__eliscript_numeric_relation("<", index, ((nodes) ?? []).length)) {
|
|
594
|
+
{
|
|
595
|
+
const __eliscript_value_57 = ((((nodes) ?? [])[index]) ?? null);
|
|
596
|
+
{
|
|
597
|
+
let node = __eliscript_value_57;
|
|
598
|
+
if (((node)["kind"] === "module-declaration")) {
|
|
599
|
+
collect_declarations((node)["children"], declarations);
|
|
600
|
+
} else {
|
|
601
|
+
(declarations)["push"](node);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
((index = (index + 1)));
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return declarations;
|
|
610
|
+
}
|
|
611
|
+
function lower_scalar_program(program, abi, allowed_capabilities) {
|
|
612
|
+
if ((!((abi === "numeric-f64") || (abi === "memory-u32")))) {
|
|
613
|
+
backend_fail(program, "unsupported scalar ABI");
|
|
614
|
+
}
|
|
615
|
+
{
|
|
616
|
+
const __eliscript_value_58 = ((abi === "memory-u32") ? "u32" : "f64");
|
|
617
|
+
const __eliscript_value_59 = [];
|
|
618
|
+
const __eliscript_value_60 = [];
|
|
619
|
+
const __eliscript_value_61 = [];
|
|
620
|
+
const __eliscript_value_62 = collect_declarations((program)["body"], []);
|
|
621
|
+
const __eliscript_value_63 = 0;
|
|
622
|
+
{
|
|
623
|
+
let scalar_type = __eliscript_value_58;
|
|
624
|
+
let capabilities = __eliscript_value_59;
|
|
625
|
+
let functions = __eliscript_value_60;
|
|
626
|
+
let exports = __eliscript_value_61;
|
|
627
|
+
let nodes = __eliscript_value_62;
|
|
628
|
+
let index = __eliscript_value_63;
|
|
629
|
+
while (__eliscript_numeric_relation("<", index, ((nodes) ?? []).length)) {
|
|
630
|
+
{
|
|
631
|
+
const __eliscript_value_64 = ((((nodes) ?? [])[index]) ?? null);
|
|
632
|
+
{
|
|
633
|
+
let node = __eliscript_value_64;
|
|
634
|
+
if (((abi === "memory-u32") && ((node)["kind"] === "import-declaration"))) {
|
|
635
|
+
if ((!((node)["value"] === "eliscript:memory32"))) {
|
|
636
|
+
backend_fail(node, "memory-u32 accepts only the memory32 capability import");
|
|
637
|
+
}
|
|
638
|
+
{
|
|
639
|
+
const __eliscript_value_65 = 0;
|
|
640
|
+
{
|
|
641
|
+
let position = __eliscript_value_65;
|
|
642
|
+
while (__eliscript_numeric_relation("<", position, (((node)["children"]) ?? []).length)) {
|
|
643
|
+
{
|
|
644
|
+
let binding = (((((node)["children"]) ?? [])[position]) ?? null);
|
|
645
|
+
let capability = find_function(allowed_capabilities, (binding)["value"]);
|
|
646
|
+
if ((!__eliscript_truthy(((__eliscript_value_66) => (__eliscript_truthy(__eliscript_value_66) ? ((__eliscript_value_67) => (__eliscript_truthy(__eliscript_value_67) ? (!__eliscript_truthy(find_function(capabilities, (binding)["value"]))) : __eliscript_value_67))(capability) : __eliscript_value_66))(((binding)["kind"] === "import-named"))))) {
|
|
647
|
+
backend_fail(binding, "unknown, renamed or duplicate memory32 capability");
|
|
648
|
+
}
|
|
649
|
+
(capabilities)["push"](capability);
|
|
650
|
+
}
|
|
651
|
+
((position = (position + 1)));
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
} else {
|
|
656
|
+
if (((node)["kind"] === "export-declaration")) {
|
|
657
|
+
{
|
|
658
|
+
const __eliscript_value_68 = 0;
|
|
659
|
+
{
|
|
660
|
+
let position = __eliscript_value_68;
|
|
661
|
+
while (__eliscript_numeric_relation("<", position, (((node)["children"]) ?? []).length)) {
|
|
662
|
+
{
|
|
663
|
+
const __eliscript_value_69 = (((((node)["children"]) ?? [])[position]) ?? null);
|
|
664
|
+
{
|
|
665
|
+
let child = __eliscript_value_69;
|
|
666
|
+
if ((!((child)["kind"] === "reference"))) {
|
|
667
|
+
backend_fail(child, "numeric exports require named functions");
|
|
668
|
+
}
|
|
669
|
+
(exports)["push"]((child)["value"]);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
((position = (position + 1)));
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
} else {
|
|
677
|
+
if ((((node)["kind"] === "function-declaration") && (!__eliscript_truthy(((node)["properties"])["async"])))) {
|
|
678
|
+
if (__eliscript_truthy(find_function(functions, (node)["value"]))) {
|
|
679
|
+
backend_fail(node, "duplicate numeric function");
|
|
680
|
+
}
|
|
681
|
+
(functions)["push"](({"name": (node)["value"], "index": ((functions) ?? []).length, "arity": ((node)["properties"])["parameterCount"], "source": node}));
|
|
682
|
+
} else {
|
|
683
|
+
backend_fail(node, "numeric-f64 ABI requires synchronous functions and exports");
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
((index = (index + 1)));
|
|
690
|
+
}
|
|
691
|
+
if ((((functions) ?? []).length === 0)) {
|
|
692
|
+
backend_fail(program, "numeric-f64 ABI requires at least one function");
|
|
693
|
+
}
|
|
694
|
+
((index = 0));
|
|
695
|
+
while (__eliscript_numeric_relation("<", index, ((functions) ?? []).length)) {
|
|
696
|
+
if (__eliscript_truthy(find_function(capabilities, (((((functions) ?? [])[index]) ?? null))["name"]))) {
|
|
697
|
+
backend_fail((((((functions) ?? [])[index]) ?? null))["source"], "function shadows memory32 capability");
|
|
698
|
+
}
|
|
699
|
+
{
|
|
700
|
+
let function$ = ((((functions) ?? [])[index]) ?? null);
|
|
701
|
+
let node = (function$)["source"];
|
|
702
|
+
let children = (node)["children"];
|
|
703
|
+
let arity = (function$)["arity"];
|
|
704
|
+
let state = ({"locals": [], "scalarType": scalar_type, "capabilities": capabilities});
|
|
705
|
+
let scope = [];
|
|
706
|
+
let position = 0;
|
|
707
|
+
while (__eliscript_numeric_relation("<", position, arity)) {
|
|
708
|
+
{
|
|
709
|
+
const __eliscript_value_70 = ((((children) ?? [])[position]) ?? null);
|
|
710
|
+
{
|
|
711
|
+
let parameter = __eliscript_value_70;
|
|
712
|
+
if ((!(((parameter)["kind"] === "parameter-binding") && (((parameter)["properties"])["parameterKind"] === "required") && (!__eliscript_truthy(find_local(scope, (parameter)["value"])))))) {
|
|
713
|
+
backend_fail(parameter, "numeric-f64 ABI requires distinct required parameters");
|
|
714
|
+
}
|
|
715
|
+
(scope)["push"](new_local(state, (parameter)["value"], scalar_type));
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
((position = (position + 1)));
|
|
719
|
+
}
|
|
720
|
+
{
|
|
721
|
+
const __eliscript_value_71 = typed_sequence((children)["slice"](arity), scope, state, functions);
|
|
722
|
+
{
|
|
723
|
+
let body = __eliscript_value_71;
|
|
724
|
+
require_type(node, body, scalar_type);
|
|
725
|
+
((function$)["body"] = body);
|
|
726
|
+
((function$)["locals"] = (state)["locals"]);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
((index = (index + 1)));
|
|
731
|
+
}
|
|
732
|
+
((index = 0));
|
|
733
|
+
while (__eliscript_numeric_relation("<", index, ((exports) ?? []).length)) {
|
|
734
|
+
if ((!__eliscript_truthy(find_function(functions, ((((exports) ?? [])[index]) ?? null))))) {
|
|
735
|
+
backend_fail(program, (String("unknown numeric export: ") + String(((((exports) ?? [])[index]) ?? null))));
|
|
736
|
+
}
|
|
737
|
+
{
|
|
738
|
+
const __eliscript_value_72 = 0;
|
|
739
|
+
{
|
|
740
|
+
let prior = __eliscript_value_72;
|
|
741
|
+
while (__eliscript_numeric_relation("<", prior, index)) {
|
|
742
|
+
if ((((((exports) ?? [])[prior]) ?? null) === ((((exports) ?? [])[index]) ?? null))) {
|
|
743
|
+
backend_fail(program, "duplicate numeric export");
|
|
744
|
+
}
|
|
745
|
+
((prior = (prior + 1)));
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
((index = (index + 1)));
|
|
750
|
+
}
|
|
751
|
+
return ({"abi": abi, "filename": (program)["filename"], "functions": functions, "exports": exports});
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function lower_numeric_program(program) {
|
|
756
|
+
return lower_scalar_program(program, "numeric-f64", []);
|
|
757
|
+
}
|
|
758
|
+
function tree_size(node) {
|
|
759
|
+
{
|
|
760
|
+
const __eliscript_value_73 = 1;
|
|
761
|
+
const __eliscript_value_74 = (node)["children"];
|
|
762
|
+
const __eliscript_value_75 = 0;
|
|
763
|
+
{
|
|
764
|
+
let size = __eliscript_value_73;
|
|
765
|
+
let children = __eliscript_value_74;
|
|
766
|
+
let index = __eliscript_value_75;
|
|
767
|
+
while (__eliscript_numeric_relation("<", index, ((children) ?? []).length)) {
|
|
768
|
+
((size = (size + tree_size(((((children) ?? [])[index]) ?? null)))));
|
|
769
|
+
((index = (index + 1)));
|
|
770
|
+
}
|
|
771
|
+
return size;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
function contains_kind(node, kind) {
|
|
776
|
+
{
|
|
777
|
+
const __eliscript_value_76 = (((node)["kind"] === kind) || ((kind === "while") && (((node)["kind"] === "remainder-while") || ((node)["kind"] === "guarded-while"))));
|
|
778
|
+
const __eliscript_value_77 = 0;
|
|
779
|
+
{
|
|
780
|
+
let found = __eliscript_value_76;
|
|
781
|
+
let index = __eliscript_value_77;
|
|
782
|
+
while (((!__eliscript_truthy(found)) && __eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length))) {
|
|
783
|
+
((found = contains_kind((((((node)["children"]) ?? [])[index]) ?? null), kind)));
|
|
784
|
+
((index = (index + 1)));
|
|
785
|
+
}
|
|
786
|
+
return found;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
function writes_local(node, local) {
|
|
791
|
+
{
|
|
792
|
+
const __eliscript_value_78 = (((((node)["kind"] === "set") || ((node)["kind"] === "initialize")) && ((node)["value"] === local)) ? 1 : 0);
|
|
793
|
+
const __eliscript_value_79 = 0;
|
|
794
|
+
{
|
|
795
|
+
let count = __eliscript_value_78;
|
|
796
|
+
let index = __eliscript_value_79;
|
|
797
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
798
|
+
((count = (count + writes_local((((((node)["children"]) ?? [])[index]) ?? null), local))));
|
|
799
|
+
((index = (index + 1)));
|
|
800
|
+
}
|
|
801
|
+
return count;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
function numeric_pure(node) {
|
|
806
|
+
{
|
|
807
|
+
const __eliscript_value_80 = (node)["kind"];
|
|
808
|
+
const __eliscript_value_81 = 0;
|
|
809
|
+
const __eliscript_value_82 = true;
|
|
810
|
+
{
|
|
811
|
+
let kind = __eliscript_value_80;
|
|
812
|
+
let index = __eliscript_value_81;
|
|
813
|
+
let pure = __eliscript_value_82;
|
|
814
|
+
if ((!((kind === "literal") || (kind === "local") || (kind === "arithmetic") || (kind === "compare") || (kind === "not") || (kind === "int-number") || (kind === "int-literal") || (kind === "int-add") || (kind === "int-sub") || (kind === "int-and") || (kind === "int-compare")))) {
|
|
815
|
+
((pure = null));
|
|
816
|
+
}
|
|
817
|
+
while (__eliscript_truthy(((__eliscript_value_83) => (__eliscript_truthy(__eliscript_value_83) ? __eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length) : __eliscript_value_83))(pure))) {
|
|
818
|
+
((pure = numeric_pure((((((node)["children"]) ?? [])[index]) ?? null))));
|
|
819
|
+
((index = (index + 1)));
|
|
820
|
+
}
|
|
821
|
+
return pure;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
function copy_offset(node, offset, aliases) {
|
|
826
|
+
{
|
|
827
|
+
let kind = (node)["kind"];
|
|
828
|
+
let value = (node)["value"];
|
|
829
|
+
let children = [];
|
|
830
|
+
let index = 0;
|
|
831
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
832
|
+
(children)["push"](copy_offset((((((node)["children"]) ?? [])[index]) ?? null), offset, aliases));
|
|
833
|
+
((index = (index + 1)));
|
|
834
|
+
}
|
|
835
|
+
if (__eliscript_truthy(((__eliscript_value_84) => (__eliscript_truthy(__eliscript_value_84) ? ((__eliscript_value_85) => (__eliscript_truthy(__eliscript_value_85) ? ((((aliases) ?? [])[value]) ?? null) : __eliscript_value_85))(__eliscript_numeric_relation("<", value, ((aliases) ?? []).length)) : __eliscript_value_84))((kind === "local")))) {
|
|
836
|
+
return ((((aliases) ?? [])[value]) ?? null);
|
|
837
|
+
} else {
|
|
838
|
+
return typed(kind, (node)["type"], children, (((kind === "local") || (kind === "set") || (kind === "initialize")) ? (offset + value) : value));
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function inline_numeric_node(node, functions, locals) {
|
|
843
|
+
{
|
|
844
|
+
const __eliscript_value_86 = [];
|
|
845
|
+
const __eliscript_value_87 = 0;
|
|
846
|
+
{
|
|
847
|
+
let children = __eliscript_value_86;
|
|
848
|
+
let index = __eliscript_value_87;
|
|
849
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
850
|
+
(children)["push"](inline_numeric_node((((((node)["children"]) ?? [])[index]) ?? null), functions, locals));
|
|
851
|
+
((index = (index + 1)));
|
|
852
|
+
}
|
|
853
|
+
if (((node)["kind"] === "call")) {
|
|
854
|
+
{
|
|
855
|
+
let callee = ((((functions) ?? [])[(node)["value"]]) ?? null);
|
|
856
|
+
let body = (callee)["body"];
|
|
857
|
+
if (((!__eliscript_truthy(contains_kind(body, "call"))) && __eliscript_numeric_relation("<=", tree_size(body), ((callee)["inlineLimit"] ?? 128)))) {
|
|
858
|
+
{
|
|
859
|
+
const __eliscript_value_88 = ((locals) ?? []).length;
|
|
860
|
+
const __eliscript_value_89 = [];
|
|
861
|
+
const __eliscript_value_90 = [];
|
|
862
|
+
const __eliscript_value_91 = true;
|
|
863
|
+
const __eliscript_value_92 = 0;
|
|
864
|
+
{
|
|
865
|
+
let offset = __eliscript_value_88;
|
|
866
|
+
let aliases = __eliscript_value_89;
|
|
867
|
+
let sequence = __eliscript_value_90;
|
|
868
|
+
let pure = __eliscript_value_91;
|
|
869
|
+
let index = __eliscript_value_92;
|
|
870
|
+
while (__eliscript_numeric_relation("<", index, ((children) ?? []).length)) {
|
|
871
|
+
if ((!__eliscript_truthy(numeric_pure(((((children) ?? [])[index]) ?? null))))) {
|
|
872
|
+
((pure = null));
|
|
873
|
+
}
|
|
874
|
+
((index = (index + 1)));
|
|
875
|
+
}
|
|
876
|
+
((index = 0));
|
|
877
|
+
while (__eliscript_numeric_relation("<", index, (((callee)["locals"]) ?? []).length)) {
|
|
878
|
+
{
|
|
879
|
+
const __eliscript_value_93 = (((((callee)["locals"]) ?? [])[index]) ?? null);
|
|
880
|
+
{
|
|
881
|
+
let entry = __eliscript_value_93;
|
|
882
|
+
(locals)["push"](({"name": (entry)["name"], "index": ((locals) ?? []).length, "type": (entry)["type"], "boundedInteger": ((entry)["boundedInteger"] ?? null)}));
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
((index = (index + 1)));
|
|
886
|
+
}
|
|
887
|
+
((index = 0));
|
|
888
|
+
while (__eliscript_numeric_relation("<", index, (callee)["arity"])) {
|
|
889
|
+
{
|
|
890
|
+
let argument = ((((children) ?? [])[index]) ?? null);
|
|
891
|
+
let alias = ((__eliscript_value_94) => (__eliscript_truthy(__eliscript_value_94) ? ((writes_local(body, index) === 0) && (((argument)["kind"] === "local") || ((argument)["kind"] === "literal"))) : __eliscript_value_94))(pure);
|
|
892
|
+
(aliases)["push"]((__eliscript_truthy(alias) ? argument : null));
|
|
893
|
+
if ((!__eliscript_truthy(alias))) {
|
|
894
|
+
(sequence)["push"](typed("initialize", "f64", [argument], (offset + index)));
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
((index = (index + 1)));
|
|
898
|
+
}
|
|
899
|
+
(sequence)["push"](copy_offset(body, offset, aliases));
|
|
900
|
+
return typed("sequence", "f64", sequence, null);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
} else {
|
|
904
|
+
return typed("call", "f64", children, (node)["value"]);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
} else {
|
|
908
|
+
return typed((node)["kind"], (node)["type"], children, (node)["value"]);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
function loop_invariant(node, loop) {
|
|
914
|
+
{
|
|
915
|
+
const __eliscript_value_95 = (node)["kind"];
|
|
916
|
+
const __eliscript_value_96 = 0;
|
|
917
|
+
const __eliscript_value_97 = numeric_pure(node);
|
|
918
|
+
{
|
|
919
|
+
let kind = __eliscript_value_95;
|
|
920
|
+
let index = __eliscript_value_96;
|
|
921
|
+
let invariant = __eliscript_value_97;
|
|
922
|
+
if (((kind === "local") && __eliscript_numeric_relation(">", writes_local(loop, (node)["value"]), 0))) {
|
|
923
|
+
((invariant = null));
|
|
924
|
+
}
|
|
925
|
+
while (__eliscript_truthy(((__eliscript_value_98) => (__eliscript_truthy(__eliscript_value_98) ? __eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length) : __eliscript_value_98))(invariant))) {
|
|
926
|
+
((invariant = loop_invariant((((((node)["children"]) ?? [])[index]) ?? null), loop)));
|
|
927
|
+
((index = (index + 1)));
|
|
928
|
+
}
|
|
929
|
+
return invariant;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
function lift_invariants(node, loop, prelude) {
|
|
934
|
+
if (__eliscript_truthy(((__eliscript_value_99) => (__eliscript_truthy(__eliscript_value_99) ? ((__eliscript_value_100) => (__eliscript_truthy(__eliscript_value_100) ? loop_invariant((((((node)["children"]) ?? [])[0]) ?? null), loop) : __eliscript_value_100))((writes_local(loop, (node)["value"]) === 1)) : __eliscript_value_99))(((node)["kind"] === "initialize")))) {
|
|
935
|
+
(prelude)["push"](node);
|
|
936
|
+
return typed("local", (node)["type"], [], (node)["value"]);
|
|
937
|
+
} else {
|
|
938
|
+
{
|
|
939
|
+
const __eliscript_value_101 = [];
|
|
940
|
+
const __eliscript_value_102 = 0;
|
|
941
|
+
{
|
|
942
|
+
let children = __eliscript_value_101;
|
|
943
|
+
let index = __eliscript_value_102;
|
|
944
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
945
|
+
(children)["push"](lift_invariants((((((node)["children"]) ?? [])[index]) ?? null), loop, prelude));
|
|
946
|
+
((index = (index + 1)));
|
|
947
|
+
}
|
|
948
|
+
return typed((node)["kind"], (node)["type"], children, (node)["value"]);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
function optimize_numeric_loops(node) {
|
|
954
|
+
{
|
|
955
|
+
const __eliscript_value_103 = [];
|
|
956
|
+
const __eliscript_value_104 = 0;
|
|
957
|
+
{
|
|
958
|
+
let children = __eliscript_value_103;
|
|
959
|
+
let index = __eliscript_value_104;
|
|
960
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
961
|
+
(children)["push"](optimize_numeric_loops((((((node)["children"]) ?? [])[index]) ?? null)));
|
|
962
|
+
((index = (index + 1)));
|
|
963
|
+
}
|
|
964
|
+
{
|
|
965
|
+
const __eliscript_value_105 = typed((node)["kind"], (node)["type"], children, (node)["value"]);
|
|
966
|
+
{
|
|
967
|
+
let copy = __eliscript_value_105;
|
|
968
|
+
if (((copy)["kind"] === "while")) {
|
|
969
|
+
{
|
|
970
|
+
let prelude = [];
|
|
971
|
+
let lifted = lift_invariants(copy, copy, prelude);
|
|
972
|
+
(prelude)["push"](lifted);
|
|
973
|
+
return typed("sequence", (copy)["type"], prelude, null);
|
|
974
|
+
}
|
|
975
|
+
} else {
|
|
976
|
+
return copy;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
function square_local(node) {
|
|
984
|
+
if ((((node)["kind"] === "arithmetic") && ((node)["value"] === "*") && ((((node)["children"]) ?? []).length === 2) && (((((((node)["children"]) ?? [])[0]) ?? null))["kind"] === "local") && (((((((node)["children"]) ?? [])[1]) ?? null))["kind"] === "local") && (((((((node)["children"]) ?? [])[0]) ?? null))["value"] === ((((((node)["children"]) ?? [])[1]) ?? null))["value"]))) {
|
|
985
|
+
return ((((((node)["children"]) ?? [])[0]) ?? null))["value"];
|
|
986
|
+
} else {
|
|
987
|
+
return -1;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
function square_uses(node, local) {
|
|
991
|
+
{
|
|
992
|
+
const __eliscript_value_106 = ((square_local(node) === local) ? 1 : 0);
|
|
993
|
+
const __eliscript_value_107 = 0;
|
|
994
|
+
{
|
|
995
|
+
let count = __eliscript_value_106;
|
|
996
|
+
let index = __eliscript_value_107;
|
|
997
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
998
|
+
((count = (count + square_uses((((((node)["children"]) ?? [])[index]) ?? null), local))));
|
|
999
|
+
((index = (index + 1)));
|
|
1000
|
+
}
|
|
1001
|
+
return count;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
function pure_conjunction(node) {
|
|
1006
|
+
if (((node)["kind"] === "and")) {
|
|
1007
|
+
{
|
|
1008
|
+
const __eliscript_value_108 = true;
|
|
1009
|
+
const __eliscript_value_109 = 0;
|
|
1010
|
+
{
|
|
1011
|
+
let pure = __eliscript_value_108;
|
|
1012
|
+
let index = __eliscript_value_109;
|
|
1013
|
+
while (__eliscript_truthy(((__eliscript_value_110) => (__eliscript_truthy(__eliscript_value_110) ? __eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length) : __eliscript_value_110))(pure))) {
|
|
1014
|
+
((pure = pure_conjunction((((((node)["children"]) ?? [])[index]) ?? null))));
|
|
1015
|
+
((index = (index + 1)));
|
|
1016
|
+
}
|
|
1017
|
+
return pure;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
} else {
|
|
1021
|
+
return numeric_pure(node);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
function collect_squares(node, body, caches, locals) {
|
|
1025
|
+
{
|
|
1026
|
+
const __eliscript_value_111 = square_local(node);
|
|
1027
|
+
const __eliscript_value_112 = 0;
|
|
1028
|
+
{
|
|
1029
|
+
let local = __eliscript_value_111;
|
|
1030
|
+
let index = __eliscript_value_112;
|
|
1031
|
+
if ((__eliscript_numeric_relation(">=", local, 0) && __eliscript_numeric_relation(">", square_uses(body, local), 0) && (!__eliscript_truthy(find_local(caches, (String(local))))))) {
|
|
1032
|
+
(caches)["push"](({"name": (String(local)), "operand": local, "storage": ((locals) ?? []).length, "ready": null}));
|
|
1033
|
+
(locals)["push"](({"name": "cached-square", "index": ((locals) ?? []).length, "type": "f64", "pureGuardCache": true}));
|
|
1034
|
+
}
|
|
1035
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
1036
|
+
collect_squares((((((node)["children"]) ?? [])[index]) ?? null), body, caches, locals);
|
|
1037
|
+
((index = (index + 1)));
|
|
1038
|
+
}
|
|
1039
|
+
return null;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
function clear_square_caches(caches, local) {
|
|
1044
|
+
{
|
|
1045
|
+
const __eliscript_value_113 = 0;
|
|
1046
|
+
{
|
|
1047
|
+
let index = __eliscript_value_113;
|
|
1048
|
+
while (__eliscript_numeric_relation("<", index, ((caches) ?? []).length)) {
|
|
1049
|
+
if ((__eliscript_numeric_relation("<", local, 0) || ((((((caches) ?? [])[index]) ?? null))["operand"] === local))) {
|
|
1050
|
+
((((((caches) ?? [])[index]) ?? null))["ready"] = null);
|
|
1051
|
+
}
|
|
1052
|
+
((index = (index + 1)));
|
|
1053
|
+
}
|
|
1054
|
+
return null;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
function reuse_squares(node, caches, condition) {
|
|
1059
|
+
{
|
|
1060
|
+
let kind = (node)["kind"];
|
|
1061
|
+
let value = (node)["value"];
|
|
1062
|
+
let local = square_local(node);
|
|
1063
|
+
let cache = (__eliscript_numeric_relation(">=", local, 0) ? find_local(caches, (String(local))) : null);
|
|
1064
|
+
if (__eliscript_truthy(((__eliscript_value_114) => (__eliscript_truthy(__eliscript_value_114) ? (cache)["ready"] : __eliscript_value_114))(cache))) {
|
|
1065
|
+
return typed("local", "f64", [], (cache)["storage"]);
|
|
1066
|
+
} else {
|
|
1067
|
+
{
|
|
1068
|
+
const __eliscript_value_115 = [];
|
|
1069
|
+
const __eliscript_value_116 = 0;
|
|
1070
|
+
{
|
|
1071
|
+
let children = __eliscript_value_115;
|
|
1072
|
+
let index = __eliscript_value_116;
|
|
1073
|
+
if (((kind === "if") || (kind === "while") || (kind === "remainder-while") || (kind === "or"))) {
|
|
1074
|
+
clear_square_caches(caches, -1);
|
|
1075
|
+
}
|
|
1076
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
1077
|
+
(children)["push"](reuse_squares((((((node)["children"]) ?? [])[index]) ?? null), caches, condition));
|
|
1078
|
+
((index = (index + 1)));
|
|
1079
|
+
}
|
|
1080
|
+
{
|
|
1081
|
+
const __eliscript_value_117 = typed(kind, (node)["type"], children, value);
|
|
1082
|
+
{
|
|
1083
|
+
let copy = __eliscript_value_117;
|
|
1084
|
+
if (((kind === "set") || (kind === "initialize"))) {
|
|
1085
|
+
clear_square_caches(caches, value);
|
|
1086
|
+
}
|
|
1087
|
+
if (((kind === "if") || (kind === "while") || (kind === "remainder-while") || (kind === "or") || (kind === "call"))) {
|
|
1088
|
+
clear_square_caches(caches, -1);
|
|
1089
|
+
}
|
|
1090
|
+
if (__eliscript_truthy(((__eliscript_value_118) => (__eliscript_truthy(__eliscript_value_118) ? condition : __eliscript_value_118))(cache))) {
|
|
1091
|
+
((cache)["ready"] = true);
|
|
1092
|
+
return typed("set", "f64", [copy], (cache)["storage"]);
|
|
1093
|
+
} else {
|
|
1094
|
+
return copy;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
function optimize_loop_squares(node, locals) {
|
|
1104
|
+
{
|
|
1105
|
+
const __eliscript_value_119 = [];
|
|
1106
|
+
const __eliscript_value_120 = 0;
|
|
1107
|
+
{
|
|
1108
|
+
let children = __eliscript_value_119;
|
|
1109
|
+
let index = __eliscript_value_120;
|
|
1110
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
1111
|
+
(children)["push"](optimize_loop_squares((((((node)["children"]) ?? [])[index]) ?? null), locals));
|
|
1112
|
+
((index = (index + 1)));
|
|
1113
|
+
}
|
|
1114
|
+
if (__eliscript_truthy(((__eliscript_value_121) => (__eliscript_truthy(__eliscript_value_121) ? pure_conjunction(((((children) ?? [])[0]) ?? null)) : __eliscript_value_121))((((node)["kind"] === "while") || ((node)["kind"] === "remainder-while"))))) {
|
|
1115
|
+
{
|
|
1116
|
+
const __eliscript_value_122 = [];
|
|
1117
|
+
{
|
|
1118
|
+
let caches = __eliscript_value_122;
|
|
1119
|
+
collect_squares(((((children) ?? [])[0]) ?? null), ((((children) ?? [])[1]) ?? null), caches, locals);
|
|
1120
|
+
{
|
|
1121
|
+
const __eliscript_value_123 = reuse_squares(((((children) ?? [])[0]) ?? null), caches, true);
|
|
1122
|
+
{
|
|
1123
|
+
let condition = __eliscript_value_123;
|
|
1124
|
+
return typed((node)["kind"], "i32", [condition, reuse_squares(((((children) ?? [])[1]) ?? null), caches, null)], null);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
} else {
|
|
1130
|
+
return typed((node)["kind"], (node)["type"], children, (node)["value"]);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
function optimize_numeric_program(program, options = null) {
|
|
1136
|
+
if ((!(((program)["abi"] ?? null) === "numeric-f64"))) {
|
|
1137
|
+
backend_fail(program, "numeric optimization requires validated numeric-f64 input");
|
|
1138
|
+
}
|
|
1139
|
+
{
|
|
1140
|
+
let functions = (program)["functions"];
|
|
1141
|
+
let inline_functions = prepare_nested_callees(functions, options);
|
|
1142
|
+
let output = [];
|
|
1143
|
+
let index = 0;
|
|
1144
|
+
while (__eliscript_numeric_relation("<", index, ((functions) ?? []).length)) {
|
|
1145
|
+
{
|
|
1146
|
+
let function$ = ((((functions) ?? [])[index]) ?? null);
|
|
1147
|
+
let locals = ((function$)["locals"])["slice"]();
|
|
1148
|
+
let body = (function$)["body"];
|
|
1149
|
+
if (__eliscript_truthy(((((__eliscript_value_124) => (__eliscript_truthy(__eliscript_value_124) ? __eliscript_value_124 : ({})))(options))["inlining"] ?? true))) {
|
|
1150
|
+
((body = inline_numeric_node(body, inline_functions, locals)));
|
|
1151
|
+
}
|
|
1152
|
+
if (__eliscript_truthy(((((__eliscript_value_125) => (__eliscript_truthy(__eliscript_value_125) ? __eliscript_value_125 : ({})))(options))["loops"] ?? true))) {
|
|
1153
|
+
((body = optimize_loop_squares(optimize_numeric_loops(body), locals)));
|
|
1154
|
+
}
|
|
1155
|
+
if (__eliscript_truthy(((((__eliscript_value_126) => (__eliscript_truthy(__eliscript_value_126) ? __eliscript_value_126 : ({})))(options))["integers"] ?? true))) {
|
|
1156
|
+
((body = specialize_integer_locals(body, locals, (function$)["arity"])));
|
|
1157
|
+
}
|
|
1158
|
+
if (__eliscript_truthy(((__eliscript_value_127) => (__eliscript_truthy(__eliscript_value_127) ? ((((__eliscript_value_129) => (__eliscript_truthy(__eliscript_value_129) ? __eliscript_value_129 : ({})))(options))["parallel"] ?? true) : __eliscript_value_127))(((((__eliscript_value_128) => (__eliscript_truthy(__eliscript_value_128) ? __eliscript_value_128 : ({})))(options))["inlining"] ?? true)))) {
|
|
1159
|
+
((body = parallelize_call_loop((function$)["body"], functions, locals, (function$)["arity"], body, ((((__eliscript_value_130) => (__eliscript_truthy(__eliscript_value_130) ? __eliscript_value_130 : ({})))(options))["parallelSingle"] ?? null))));
|
|
1160
|
+
}
|
|
1161
|
+
if (__eliscript_truthy(((((__eliscript_value_131) => (__eliscript_truthy(__eliscript_value_131) ? __eliscript_value_131 : ({})))(options))["cyclicMultiple"] ?? null))) {
|
|
1162
|
+
((body = specialize_cyclic_locals(body, locals)));
|
|
1163
|
+
}
|
|
1164
|
+
if (__eliscript_truthy(((((__eliscript_value_132) => (__eliscript_truthy(__eliscript_value_132) ? __eliscript_value_132 : ({})))(options))["guardedUnroll"] ?? true))) {
|
|
1165
|
+
((body = expand_compound_loops(body, locals)));
|
|
1166
|
+
}
|
|
1167
|
+
if (__eliscript_truthy(((((__eliscript_value_133) => (__eliscript_truthy(__eliscript_value_133) ? __eliscript_value_133 : ({})))(options))["constantFlow"] ?? null))) {
|
|
1168
|
+
{
|
|
1169
|
+
const __eliscript_value_134 = [];
|
|
1170
|
+
{
|
|
1171
|
+
let reads = __eliscript_value_134;
|
|
1172
|
+
((body = fold_constant_flow(body, [])));
|
|
1173
|
+
collect_flow_reads(body, reads);
|
|
1174
|
+
((body = remove_unread_stores(body, reads)));
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
if (__eliscript_truthy(((((__eliscript_value_135) => (__eliscript_truthy(__eliscript_value_135) ? __eliscript_value_135 : ({})))(options))["unswitch"] ?? null))) {
|
|
1179
|
+
((body = unswitch_numeric_loops(body)));
|
|
1180
|
+
}
|
|
1181
|
+
if (__eliscript_truthy(((((__eliscript_value_136) => (__eliscript_truthy(__eliscript_value_136) ? __eliscript_value_136 : ({})))(options))["countedGuards"] ?? null))) {
|
|
1182
|
+
((body = counted_compound_loops(body, locals)));
|
|
1183
|
+
}
|
|
1184
|
+
(output)["push"](({"name": (function$)["name"], "index": (function$)["index"], "arity": (function$)["arity"], "source": (function$)["source"], "locals": locals, "body": body}));
|
|
1185
|
+
}
|
|
1186
|
+
((index = (index + 1)));
|
|
1187
|
+
}
|
|
1188
|
+
return ({"abi": "numeric-f64", "filename": (program)["filename"], "exports": (program)["exports"], "functions": output});
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
function loop_depth(node, depth) {
|
|
1192
|
+
{
|
|
1193
|
+
const __eliscript_value_137 = depth;
|
|
1194
|
+
const __eliscript_value_138 = 0;
|
|
1195
|
+
const __eliscript_value_139 = ((((node)["kind"] === "while") || ((node)["kind"] === "remainder-while") || ((node)["kind"] === "guarded-while")) ? (depth + 1) : depth);
|
|
1196
|
+
{
|
|
1197
|
+
let best = __eliscript_value_137;
|
|
1198
|
+
let index = __eliscript_value_138;
|
|
1199
|
+
let next = __eliscript_value_139;
|
|
1200
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
1201
|
+
{
|
|
1202
|
+
const __eliscript_value_140 = loop_depth((((((node)["children"]) ?? [])[index]) ?? null), next);
|
|
1203
|
+
{
|
|
1204
|
+
let candidate = __eliscript_value_140;
|
|
1205
|
+
if (__eliscript_numeric_relation(">", candidate, best)) {
|
|
1206
|
+
((best = candidate));
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
((index = (index + 1)));
|
|
1211
|
+
}
|
|
1212
|
+
return best;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
function prepare_nested_callees(functions, options) {
|
|
1217
|
+
{
|
|
1218
|
+
const __eliscript_value_141 = [];
|
|
1219
|
+
const __eliscript_value_142 = 0;
|
|
1220
|
+
{
|
|
1221
|
+
let prepared = __eliscript_value_141;
|
|
1222
|
+
let index = __eliscript_value_142;
|
|
1223
|
+
while (__eliscript_numeric_relation("<", index, ((functions) ?? []).length)) {
|
|
1224
|
+
{
|
|
1225
|
+
let function$ = ((((functions) ?? [])[index]) ?? null);
|
|
1226
|
+
let body = (function$)["body"];
|
|
1227
|
+
if (__eliscript_truthy(((__eliscript_value_143) => (__eliscript_truthy(__eliscript_value_143) ? ((!__eliscript_truthy(contains_kind(body, "call"))) && __eliscript_numeric_relation(">=", loop_depth(body, 0), 2) && __eliscript_numeric_relation("<=", tree_size(body), 128)) : __eliscript_value_143))(((((__eliscript_value_144) => (__eliscript_truthy(__eliscript_value_144) ? __eliscript_value_144 : ({})))(options))["inlining"] ?? true)))) {
|
|
1228
|
+
{
|
|
1229
|
+
const __eliscript_value_145 = ((function$)["locals"])["slice"]();
|
|
1230
|
+
{
|
|
1231
|
+
let locals = __eliscript_value_145;
|
|
1232
|
+
if (__eliscript_truthy(((((__eliscript_value_146) => (__eliscript_truthy(__eliscript_value_146) ? __eliscript_value_146 : ({})))(options))["loops"] ?? true))) {
|
|
1233
|
+
((body = optimize_loop_squares(optimize_numeric_loops(body), locals)));
|
|
1234
|
+
}
|
|
1235
|
+
if (__eliscript_truthy(((((__eliscript_value_147) => (__eliscript_truthy(__eliscript_value_147) ? __eliscript_value_147 : ({})))(options))["integers"] ?? true))) {
|
|
1236
|
+
((body = specialize_integer_locals(body, locals, (function$)["arity"])));
|
|
1237
|
+
}
|
|
1238
|
+
(prepared)["push"](({"name": (function$)["name"], "arity": (function$)["arity"], "index": (function$)["index"], "locals": locals, "body": body, "inlineLimit": 512}));
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
} else {
|
|
1242
|
+
(prepared)["push"](function$);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
((index = (index + 1)));
|
|
1246
|
+
}
|
|
1247
|
+
return prepared;
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
function flatten_statements(node, output) {
|
|
1252
|
+
if (((node)["kind"] === "sequence")) {
|
|
1253
|
+
{
|
|
1254
|
+
const __eliscript_value_148 = 0;
|
|
1255
|
+
{
|
|
1256
|
+
let index = __eliscript_value_148;
|
|
1257
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
1258
|
+
flatten_statements((((((node)["children"]) ?? [])[index]) ?? null), output);
|
|
1259
|
+
((index = (index + 1)));
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
} else {
|
|
1264
|
+
(output)["push"](node);
|
|
1265
|
+
}
|
|
1266
|
+
return output;
|
|
1267
|
+
}
|
|
1268
|
+
function scalar_pure_value(node) {
|
|
1269
|
+
if ((((node)["kind"] === "if") || ((node)["kind"] === "and") || ((node)["kind"] === "or") || ((node)["kind"] === "sequence"))) {
|
|
1270
|
+
{
|
|
1271
|
+
const __eliscript_value_149 = true;
|
|
1272
|
+
const __eliscript_value_150 = 0;
|
|
1273
|
+
{
|
|
1274
|
+
let pure = __eliscript_value_149;
|
|
1275
|
+
let index = __eliscript_value_150;
|
|
1276
|
+
while (__eliscript_truthy(((__eliscript_value_151) => (__eliscript_truthy(__eliscript_value_151) ? __eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length) : __eliscript_value_151))(pure))) {
|
|
1277
|
+
((pure = scalar_pure_value((((((node)["children"]) ?? [])[index]) ?? null))));
|
|
1278
|
+
((index = (index + 1)));
|
|
1279
|
+
}
|
|
1280
|
+
return pure;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
} else {
|
|
1284
|
+
return numeric_pure(node);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
function reads_local(node, local) {
|
|
1288
|
+
{
|
|
1289
|
+
const __eliscript_value_152 = local_node_is(node, local);
|
|
1290
|
+
const __eliscript_value_153 = 0;
|
|
1291
|
+
{
|
|
1292
|
+
let found = __eliscript_value_152;
|
|
1293
|
+
let index = __eliscript_value_153;
|
|
1294
|
+
while (((!__eliscript_truthy(found)) && __eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length))) {
|
|
1295
|
+
((found = reads_local((((((node)["children"]) ?? [])[index]) ?? null), local)));
|
|
1296
|
+
((index = (index + 1)));
|
|
1297
|
+
}
|
|
1298
|
+
return found;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
function single_loop_shape(body) {
|
|
1303
|
+
{
|
|
1304
|
+
const __eliscript_value_154 = flatten_statements(body, []);
|
|
1305
|
+
const __eliscript_value_155 = 0;
|
|
1306
|
+
const __eliscript_value_156 = null;
|
|
1307
|
+
const __eliscript_value_157 = true;
|
|
1308
|
+
{
|
|
1309
|
+
let statements = __eliscript_value_154;
|
|
1310
|
+
let position = __eliscript_value_155;
|
|
1311
|
+
let loop = __eliscript_value_156;
|
|
1312
|
+
let valid = __eliscript_value_157;
|
|
1313
|
+
while (__eliscript_numeric_relation("<", position, ((statements) ?? []).length)) {
|
|
1314
|
+
{
|
|
1315
|
+
const __eliscript_value_158 = ((((statements) ?? [])[position]) ?? null);
|
|
1316
|
+
{
|
|
1317
|
+
let statement = __eliscript_value_158;
|
|
1318
|
+
if (((statement)["kind"] === "while")) {
|
|
1319
|
+
if (__eliscript_truthy(loop)) {
|
|
1320
|
+
((valid = null));
|
|
1321
|
+
} else {
|
|
1322
|
+
((loop = ({"node": statement, "position": position})));
|
|
1323
|
+
}
|
|
1324
|
+
} else {
|
|
1325
|
+
if ((!__eliscript_truthy(loop))) {
|
|
1326
|
+
if ((!__eliscript_truthy(((__eliscript_value_159) => (__eliscript_truthy(__eliscript_value_159) ? scalar_pure_value((((((statement)["children"]) ?? [])[0]) ?? null)) : __eliscript_value_159))(((statement)["kind"] === "initialize"))))) {
|
|
1327
|
+
((valid = null));
|
|
1328
|
+
}
|
|
1329
|
+
} else {
|
|
1330
|
+
if ((!__eliscript_truthy(scalar_pure_value(statement)))) {
|
|
1331
|
+
((valid = null));
|
|
1332
|
+
} else {
|
|
1333
|
+
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
((position = (position + 1)));
|
|
1340
|
+
}
|
|
1341
|
+
if (__eliscript_truthy(((__eliscript_value_160) => (__eliscript_truthy(__eliscript_value_160) ? loop : __eliscript_value_160))(valid))) {
|
|
1342
|
+
{
|
|
1343
|
+
let condition = ((((((loop)["node"])["children"]) ?? [])[0]) ?? null);
|
|
1344
|
+
let tail = last_statement(((((((loop)["node"])["children"]) ?? [])[1]) ?? null));
|
|
1345
|
+
if (__eliscript_truthy(((__eliscript_value_161) => (__eliscript_truthy(__eliscript_value_161) ? ((__eliscript_value_162) => (__eliscript_truthy(__eliscript_value_162) ? ((__eliscript_value_163) => (__eliscript_truthy(__eliscript_value_163) ? ((__eliscript_value_164) => (__eliscript_truthy(__eliscript_value_164) ? ((__eliscript_value_165) => (__eliscript_truthy(__eliscript_value_165) ? increment_is((((((tail)["children"]) ?? [])[0]) ?? null), (tail)["value"]) : __eliscript_value_165))(local_node_is((((((condition)["children"]) ?? [])[0]) ?? null), (tail)["value"])) : __eliscript_value_164))(((tail)["kind"] === "set")) : __eliscript_value_163))((((((((condition)["children"]) ?? [])[0]) ?? null))["kind"] === "local")) : __eliscript_value_162))(((condition)["value"] === "<")) : __eliscript_value_161))(((condition)["kind"] === "compare")))) {
|
|
1346
|
+
{
|
|
1347
|
+
let counter = (tail)["value"];
|
|
1348
|
+
let initializer = find_write(body, counter, "initialize");
|
|
1349
|
+
if (__eliscript_truthy(((__eliscript_value_166) => (__eliscript_truthy(__eliscript_value_166) ? ((__eliscript_value_167) => (__eliscript_truthy(__eliscript_value_167) ? ((__eliscript_value_168) => (__eliscript_truthy(__eliscript_value_168) ? (((((((initializer)["children"]) ?? [])[0]) ?? null))["value"] === 0) : __eliscript_value_168))(positive_integer_literal((((((initializer)["children"]) ?? [])[0]) ?? null))) : __eliscript_value_167))((writes_local(body, counter) === 2)) : __eliscript_value_166))(initializer))) {
|
|
1350
|
+
((loop)["counter"] = counter);
|
|
1351
|
+
((loop)["bound"] = (((((condition)["children"]) ?? [])[1]) ?? null));
|
|
1352
|
+
((loop)["statements"] = statements);
|
|
1353
|
+
((valid = true));
|
|
1354
|
+
return loop;
|
|
1355
|
+
} else {
|
|
1356
|
+
return null;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
} else {
|
|
1360
|
+
return null;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
} else {
|
|
1364
|
+
return null;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
function append_numeric_frame(locals, callee) {
|
|
1370
|
+
{
|
|
1371
|
+
const __eliscript_value_169 = ((locals) ?? []).length;
|
|
1372
|
+
const __eliscript_value_170 = 0;
|
|
1373
|
+
{
|
|
1374
|
+
let offset = __eliscript_value_169;
|
|
1375
|
+
let index = __eliscript_value_170;
|
|
1376
|
+
while (__eliscript_numeric_relation("<", index, (((callee)["locals"]) ?? []).length)) {
|
|
1377
|
+
{
|
|
1378
|
+
const __eliscript_value_171 = (((((callee)["locals"]) ?? [])[index]) ?? null);
|
|
1379
|
+
{
|
|
1380
|
+
let entry = __eliscript_value_171;
|
|
1381
|
+
(locals)["push"](({"name": (entry)["name"], "index": ((locals) ?? []).length, "type": (entry)["type"], "boundedInteger": ((entry)["boundedInteger"] ?? null)}));
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
((index = (index + 1)));
|
|
1385
|
+
}
|
|
1386
|
+
return offset;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
function parallelize_call_loop(original, functions, locals, arity, fallback, single) {
|
|
1391
|
+
{
|
|
1392
|
+
const __eliscript_value_172 = single_loop_shape(original);
|
|
1393
|
+
{
|
|
1394
|
+
let outer = __eliscript_value_172;
|
|
1395
|
+
if ((!__eliscript_truthy(outer))) {
|
|
1396
|
+
return fallback;
|
|
1397
|
+
} else {
|
|
1398
|
+
{
|
|
1399
|
+
let loop = (outer)["node"];
|
|
1400
|
+
let bound = (outer)["bound"];
|
|
1401
|
+
let statements = flatten_statements((((((loop)["children"]) ?? [])[1]) ?? null), []);
|
|
1402
|
+
let first = ((((statements) ?? [])[0]) ?? null);
|
|
1403
|
+
let addition = (((first)["kind"] === "set") ? (((((first)["children"]) ?? [])[0]) ?? null) : null);
|
|
1404
|
+
let call = (__eliscript_truthy(((__eliscript_value_173) => (__eliscript_truthy(__eliscript_value_173) ? (((addition)["kind"] === "arithmetic") && ((addition)["value"] === "+")) : __eliscript_value_173))(addition)) ? (((((addition)["children"]) ?? [])[1]) ?? null) : null);
|
|
1405
|
+
let accumulator = (first)["value"];
|
|
1406
|
+
let valid = ((__eliscript_value_174) => (__eliscript_truthy(__eliscript_value_174) ? ((__eliscript_value_175) => (__eliscript_truthy(__eliscript_value_175) ? ((__eliscript_value_176) => (__eliscript_truthy(__eliscript_value_176) ? (((bound)["kind"] === "local") && __eliscript_numeric_relation("<", (bound)["value"], arity) && (writes_local(original, (bound)["value"]) === 0)) : __eliscript_value_176))(local_node_is((((((addition)["children"]) ?? [])[0]) ?? null), accumulator)) : __eliscript_value_175))(((call)["kind"] === "call")) : __eliscript_value_174))(call);
|
|
1407
|
+
if ((!__eliscript_truthy(valid))) {
|
|
1408
|
+
return fallback;
|
|
1409
|
+
} else {
|
|
1410
|
+
{
|
|
1411
|
+
let callee = ((((functions) ?? [])[(call)["value"]]) ?? null);
|
|
1412
|
+
let inner = single_loop_shape((callee)["body"]);
|
|
1413
|
+
let index = 1;
|
|
1414
|
+
while (__eliscript_numeric_relation("<", index, ((statements) ?? []).length)) {
|
|
1415
|
+
{
|
|
1416
|
+
const __eliscript_value_177 = ((((statements) ?? [])[index]) ?? null);
|
|
1417
|
+
{
|
|
1418
|
+
let statement = __eliscript_value_177;
|
|
1419
|
+
if ((!__eliscript_truthy(((__eliscript_value_178) => (__eliscript_truthy(__eliscript_value_178) ? ((__eliscript_value_179) => (__eliscript_truthy(__eliscript_value_179) ? ((__eliscript_value_182) => (__eliscript_truthy(__eliscript_value_182) ? (!__eliscript_truthy(reads_local((((((statement)["children"]) ?? [])[0]) ?? null), accumulator))) : __eliscript_value_182))(scalar_pure_value((((((statement)["children"]) ?? [])[0]) ?? null))) : __eliscript_value_179))(((__eliscript_value_180, __eliscript_value_181) => (__eliscript_value_180 !== __eliscript_value_181))((statement)["value"], accumulator)) : __eliscript_value_178))(((statement)["kind"] === "set"))))) {
|
|
1420
|
+
((valid = null));
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
((index = (index + 1)));
|
|
1425
|
+
}
|
|
1426
|
+
((index = 0));
|
|
1427
|
+
while (__eliscript_numeric_relation("<", index, (((call)["children"]) ?? []).length)) {
|
|
1428
|
+
{
|
|
1429
|
+
const __eliscript_value_183 = (((((call)["children"]) ?? [])[index]) ?? null);
|
|
1430
|
+
{
|
|
1431
|
+
let argument = __eliscript_value_183;
|
|
1432
|
+
if ((!__eliscript_truthy(((__eliscript_value_184) => (__eliscript_truthy(__eliscript_value_184) ? (!__eliscript_truthy(reads_local(argument, accumulator))) : __eliscript_value_184))(scalar_pure_value(argument))))) {
|
|
1433
|
+
((valid = null));
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
((index = (index + 1)));
|
|
1438
|
+
}
|
|
1439
|
+
if (__eliscript_truthy(inner)) {
|
|
1440
|
+
{
|
|
1441
|
+
let limit = (inner)["bound"];
|
|
1442
|
+
let kernel_body = flatten_statements(((((((inner)["node"])["children"]) ?? [])[1]) ?? null), []);
|
|
1443
|
+
let index = 0;
|
|
1444
|
+
if ((!(((limit)["kind"] === "local") && __eliscript_numeric_relation("<", (limit)["value"], (callee)["arity"]) && (writes_local((callee)["body"], (limit)["value"]) === 0)))) {
|
|
1445
|
+
((valid = null));
|
|
1446
|
+
}
|
|
1447
|
+
while (__eliscript_numeric_relation("<", index, ((kernel_body) ?? []).length)) {
|
|
1448
|
+
{
|
|
1449
|
+
const __eliscript_value_185 = ((((kernel_body) ?? [])[index]) ?? null);
|
|
1450
|
+
{
|
|
1451
|
+
let statement = __eliscript_value_185;
|
|
1452
|
+
if ((!__eliscript_truthy(((__eliscript_value_186) => (__eliscript_truthy(__eliscript_value_186) ? scalar_pure_value((((((statement)["children"]) ?? [])[0]) ?? null)) : __eliscript_value_186))((((statement)["kind"] === "set") || ((statement)["kind"] === "initialize")))))) {
|
|
1453
|
+
((valid = null));
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
((index = (index + 1)));
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
if (((!__eliscript_truthy(valid)) || (!__eliscript_truthy(inner)))) {
|
|
1462
|
+
return fallback;
|
|
1463
|
+
} else {
|
|
1464
|
+
{
|
|
1465
|
+
const __eliscript_value_187 = (((((call)["children"]) ?? [])[((inner)["bound"])["value"]]) ?? null);
|
|
1466
|
+
{
|
|
1467
|
+
let input = __eliscript_value_187;
|
|
1468
|
+
if ((!(((input)["kind"] === "literal") || (((input)["kind"] === "local") && __eliscript_numeric_relation("<", (input)["value"], arity) && (writes_local(original, (input)["value"]) === 0))))) {
|
|
1469
|
+
return fallback;
|
|
1470
|
+
} else {
|
|
1471
|
+
return emit_parallel_call_loop(outer, inner, callee, call, statements, input, bound, accumulator, locals, fallback, single);
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
function emit_parallel_call_loop(outer, inner, callee, call, statements, input, bound, accumulator, locals, fallback, single) {
|
|
1484
|
+
{
|
|
1485
|
+
let offset0 = append_numeric_frame(locals, callee);
|
|
1486
|
+
let offset1 = append_numeric_frame(locals, callee);
|
|
1487
|
+
let aliases0 = [];
|
|
1488
|
+
let aliases1 = [];
|
|
1489
|
+
let pair = [];
|
|
1490
|
+
let work = [];
|
|
1491
|
+
let index = 0;
|
|
1492
|
+
let lane_loop = null;
|
|
1493
|
+
let kernel_statements = (inner)["statements"];
|
|
1494
|
+
let kernel_body = flatten_statements(((((((inner)["node"])["children"]) ?? [])[1]) ?? null), []);
|
|
1495
|
+
let counter = (inner)["counter"];
|
|
1496
|
+
let limit_parameter = ((inner)["bound"])["value"];
|
|
1497
|
+
while (__eliscript_numeric_relation("<", index, (((callee)["locals"]) ?? []).length)) {
|
|
1498
|
+
(aliases0)["push"](((index === limit_parameter) ? input : null));
|
|
1499
|
+
(aliases1)["push"](((index === limit_parameter) ? input : ((index === counter) ? typed("local", "f64", [], (offset0 + counter)) : null)));
|
|
1500
|
+
((index = (index + 1)));
|
|
1501
|
+
}
|
|
1502
|
+
{
|
|
1503
|
+
const __eliscript_value_188 = 0;
|
|
1504
|
+
{
|
|
1505
|
+
let lane = __eliscript_value_188;
|
|
1506
|
+
while (__eliscript_numeric_relation("<", lane, 2)) {
|
|
1507
|
+
{
|
|
1508
|
+
const __eliscript_value_189 = ((lane === 0) ? offset0 : offset1);
|
|
1509
|
+
const __eliscript_value_190 = ((lane === 0) ? aliases0 : aliases1);
|
|
1510
|
+
const __eliscript_value_191 = 0;
|
|
1511
|
+
{
|
|
1512
|
+
let offset = __eliscript_value_189;
|
|
1513
|
+
let aliases = __eliscript_value_190;
|
|
1514
|
+
let index = __eliscript_value_191;
|
|
1515
|
+
while (__eliscript_numeric_relation("<", index, (callee)["arity"])) {
|
|
1516
|
+
(pair)["push"](typed("initialize", "f64", [(((((call)["children"]) ?? [])[index]) ?? null)], (offset + index)));
|
|
1517
|
+
((index = (index + 1)));
|
|
1518
|
+
}
|
|
1519
|
+
((index = 0));
|
|
1520
|
+
while (__eliscript_numeric_relation("<", index, (inner)["position"])) {
|
|
1521
|
+
(pair)["push"](copy_offset(((((kernel_statements) ?? [])[index]) ?? null), offset, aliases));
|
|
1522
|
+
((index = (index + 1)));
|
|
1523
|
+
}
|
|
1524
|
+
((index = 1));
|
|
1525
|
+
while (__eliscript_numeric_relation("<", index, ((statements) ?? []).length)) {
|
|
1526
|
+
(pair)["push"](((((statements) ?? [])[index]) ?? null));
|
|
1527
|
+
((index = (index + 1)));
|
|
1528
|
+
}
|
|
1529
|
+
((index = 0));
|
|
1530
|
+
while (__eliscript_numeric_relation("<", index, __eliscript_numeric_decrement(((kernel_body) ?? []).length))) {
|
|
1531
|
+
(work)["push"](copy_offset(((((kernel_body) ?? [])[index]) ?? null), offset, aliases));
|
|
1532
|
+
((index = (index + 1)));
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
((lane = (lane + 1)));
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
(work)["push"](copy_offset(((((kernel_body) ?? [])[__eliscript_numeric_decrement(((kernel_body) ?? []).length)]) ?? null), offset0, aliases0));
|
|
1541
|
+
((lane_loop = typed("while", "i32", [copy_offset(((((((inner)["node"])["children"]) ?? [])[0]) ?? null), offset0, aliases0), typed("sequence", "f64", work, null)], null)));
|
|
1542
|
+
(pair)["push"](lane_loop);
|
|
1543
|
+
{
|
|
1544
|
+
const __eliscript_value_192 = 0;
|
|
1545
|
+
{
|
|
1546
|
+
let lane = __eliscript_value_192;
|
|
1547
|
+
while (__eliscript_numeric_relation("<", lane, 2)) {
|
|
1548
|
+
{
|
|
1549
|
+
let offset = ((lane === 0) ? offset0 : offset1);
|
|
1550
|
+
let aliases = ((lane === 0) ? aliases0 : aliases1);
|
|
1551
|
+
let suffix = [];
|
|
1552
|
+
let index = ((inner)["position"] + 1);
|
|
1553
|
+
while (__eliscript_numeric_relation("<", index, ((kernel_statements) ?? []).length)) {
|
|
1554
|
+
(suffix)["push"](copy_offset(((((kernel_statements) ?? [])[index]) ?? null), offset, aliases));
|
|
1555
|
+
((index = (index + 1)));
|
|
1556
|
+
}
|
|
1557
|
+
(pair)["push"](typed("set", "f64", [typed("arithmetic", "f64", [typed("local", "f64", [], accumulator), typed("sequence", "f64", suffix, null)], "+")], accumulator));
|
|
1558
|
+
}
|
|
1559
|
+
((lane = (lane + 1)));
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
{
|
|
1564
|
+
const __eliscript_value_193 = [];
|
|
1565
|
+
const __eliscript_value_194 = 0;
|
|
1566
|
+
const __eliscript_value_195 = (outer)["statements"];
|
|
1567
|
+
{
|
|
1568
|
+
let body = __eliscript_value_193;
|
|
1569
|
+
let index = __eliscript_value_194;
|
|
1570
|
+
let outer_statements = __eliscript_value_195;
|
|
1571
|
+
while (__eliscript_numeric_relation("<", index, (outer)["position"])) {
|
|
1572
|
+
(body)["push"](((((outer_statements) ?? [])[index]) ?? null));
|
|
1573
|
+
((index = (index + 1)));
|
|
1574
|
+
}
|
|
1575
|
+
(body)["push"](typed("while", "i32", [typed("compare", "i32", [typed("arithmetic", "f64", [typed("local", "f64", [], (outer)["counter"])], "1+"), bound], "<"), typed("sequence", "f64", pair, null)], null));
|
|
1576
|
+
(body)["push"]((outer)["node"]);
|
|
1577
|
+
((index = ((outer)["position"] + 1)));
|
|
1578
|
+
while (__eliscript_numeric_relation("<", index, ((outer_statements) ?? []).length)) {
|
|
1579
|
+
(body)["push"](((((outer_statements) ?? [])[index]) ?? null));
|
|
1580
|
+
((index = (index + 1)));
|
|
1581
|
+
}
|
|
1582
|
+
return typed("if", "f64", [typed("and", "i32", [typed("compare", "i32", [input, typed("literal", "f64", [], (__eliscript_truthy(single) ? 1 : 2))], ">="), typed("compare", "i32", [input, typed("literal", "f64", [], 2147483647)], "<="), typed("compare", "i32", [bound, typed("literal", "f64", [], 2)], ">="), typed("compare", "i32", [bound, typed("literal", "f64", [], 2147483647)], "<=")], null), (__eliscript_truthy(single) ? typed("if", "f64", [typed("compare", "i32", [input, typed("literal", "f64", [], 1)], "<="), replace_numeric_node(typed("sequence", "f64", body, null), lane_loop, typed("sequence", "i32", [typed("sequence", "f64", work, null), typed("literal", "i32", [], 0)], null)), typed("sequence", "f64", body, null)], null) : typed("sequence", "f64", body, null)), fallback], null);
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
function replace_numeric_node(node, selected, replacement) {
|
|
1588
|
+
if ((node === selected)) {
|
|
1589
|
+
return replacement;
|
|
1590
|
+
} else {
|
|
1591
|
+
{
|
|
1592
|
+
const __eliscript_value_196 = [];
|
|
1593
|
+
const __eliscript_value_197 = 0;
|
|
1594
|
+
{
|
|
1595
|
+
let children = __eliscript_value_196;
|
|
1596
|
+
let i = __eliscript_value_197;
|
|
1597
|
+
while (__eliscript_numeric_relation("<", i, (((node)["children"]) ?? []).length)) {
|
|
1598
|
+
(children)["push"](replace_numeric_node((((((node)["children"]) ?? [])[i]) ?? null), selected, replacement));
|
|
1599
|
+
((i = (i + 1)));
|
|
1600
|
+
}
|
|
1601
|
+
return typed((node)["kind"], (node)["type"], children, (node)["value"]);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
function positive_integer_literal(node) {
|
|
1607
|
+
return (((node)["kind"] === "literal") && ((node)["type"] === "f64") && __eliscript_numeric_relation(">=", (node)["value"], 0) && __eliscript_numeric_relation("<=", (node)["value"], 2147483647) && ((node)["value"] === __eliscript_numeric_uint32((node)["value"])) && (!(((node)["value"] === 0) && __eliscript_numeric_relation("<", __eliscript_numeric_div(1, (node)["value"]), 0))));
|
|
1608
|
+
}
|
|
1609
|
+
function local_node_is(node, index) {
|
|
1610
|
+
return (((node)["kind"] === "local") && ((node)["value"] === index));
|
|
1611
|
+
}
|
|
1612
|
+
function increment_is(node, index) {
|
|
1613
|
+
return ((__eliscript_value_198) => (__eliscript_truthy(__eliscript_value_198) ? ((__eliscript_value_199) => (__eliscript_truthy(__eliscript_value_199) ? local_node_is((((((node)["children"]) ?? [])[0]) ?? null), index) : __eliscript_value_199))(((node)["value"] === "1+")) : __eliscript_value_198))(((node)["kind"] === "arithmetic"));
|
|
1614
|
+
}
|
|
1615
|
+
function find_write(node, index, kind) {
|
|
1616
|
+
{
|
|
1617
|
+
const __eliscript_value_200 = null;
|
|
1618
|
+
const __eliscript_value_201 = 0;
|
|
1619
|
+
{
|
|
1620
|
+
let found = __eliscript_value_200;
|
|
1621
|
+
let position = __eliscript_value_201;
|
|
1622
|
+
if ((((node)["kind"] === kind) && ((node)["value"] === index))) {
|
|
1623
|
+
return node;
|
|
1624
|
+
} else {
|
|
1625
|
+
while (((!__eliscript_truthy(found)) && __eliscript_numeric_relation("<", position, (((node)["children"]) ?? []).length))) {
|
|
1626
|
+
((found = find_write((((((node)["children"]) ?? [])[position]) ?? null), index, kind)));
|
|
1627
|
+
((position = (position + 1)));
|
|
1628
|
+
}
|
|
1629
|
+
return found;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
function last_statement(node) {
|
|
1635
|
+
if ((((node)["kind"] === "sequence") && __eliscript_numeric_relation(">", (((node)["children"]) ?? []).length, 0))) {
|
|
1636
|
+
return last_statement((((((node)["children"]) ?? [])[__eliscript_numeric_decrement((((node)["children"]) ?? []).length)]) ?? null));
|
|
1637
|
+
} else {
|
|
1638
|
+
return node;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
function counter_bound(node, index, root, arity) {
|
|
1642
|
+
{
|
|
1643
|
+
const __eliscript_value_202 = null;
|
|
1644
|
+
const __eliscript_value_203 = 0;
|
|
1645
|
+
{
|
|
1646
|
+
let found = __eliscript_value_202;
|
|
1647
|
+
let position = __eliscript_value_203;
|
|
1648
|
+
if (((node)["kind"] === "while")) {
|
|
1649
|
+
{
|
|
1650
|
+
let condition = (((((node)["children"]) ?? [])[0]) ?? null);
|
|
1651
|
+
let first = (((condition)["kind"] === "and") ? (((((condition)["children"]) ?? [])[0]) ?? null) : condition);
|
|
1652
|
+
let tail = last_statement((((((node)["children"]) ?? [])[1]) ?? null));
|
|
1653
|
+
if (__eliscript_truthy(((__eliscript_value_204) => (__eliscript_truthy(__eliscript_value_204) ? ((__eliscript_value_205) => (__eliscript_truthy(__eliscript_value_205) ? ((__eliscript_value_206) => (__eliscript_truthy(__eliscript_value_206) ? ((__eliscript_value_207) => (__eliscript_truthy(__eliscript_value_207) ? ((__eliscript_value_208) => (__eliscript_truthy(__eliscript_value_208) ? increment_is((((((tail)["children"]) ?? [])[0]) ?? null), index) : __eliscript_value_208))(((tail)["value"] === index)) : __eliscript_value_207))(((tail)["kind"] === "set")) : __eliscript_value_206))(local_node_is((((((first)["children"]) ?? [])[0]) ?? null), index)) : __eliscript_value_205))(((first)["value"] === "<")) : __eliscript_value_204))(((first)["kind"] === "compare")))) {
|
|
1654
|
+
{
|
|
1655
|
+
const __eliscript_value_209 = (((((first)["children"]) ?? [])[1]) ?? null);
|
|
1656
|
+
{
|
|
1657
|
+
let bound = __eliscript_value_209;
|
|
1658
|
+
if (__eliscript_truthy(((__eliscript_value_210) => (__eliscript_truthy(__eliscript_value_210) ? __eliscript_value_210 : (((bound)["kind"] === "local") && __eliscript_numeric_relation("<", (bound)["value"], arity) && (writes_local(root, (bound)["value"]) === 0))))(positive_integer_literal(bound)))) {
|
|
1659
|
+
((found = bound));
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
while (((!__eliscript_truthy(found)) && __eliscript_numeric_relation("<", position, (((node)["children"]) ?? []).length))) {
|
|
1667
|
+
((found = counter_bound((((((node)["children"]) ?? [])[position]) ?? null), index, root, arity)));
|
|
1668
|
+
((position = (position + 1)));
|
|
1669
|
+
}
|
|
1670
|
+
return found;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
function cyclic_integer(node, index) {
|
|
1675
|
+
if (((node)["kind"] === "if")) {
|
|
1676
|
+
{
|
|
1677
|
+
let children = (node)["children"];
|
|
1678
|
+
let condition = ((((children) ?? [])[0]) ?? null);
|
|
1679
|
+
let yes = ((((children) ?? [])[1]) ?? null);
|
|
1680
|
+
let no = ((((children) ?? [])[2]) ?? null);
|
|
1681
|
+
return ((__eliscript_value_211) => (__eliscript_truthy(__eliscript_value_211) ? ((__eliscript_value_212) => (__eliscript_truthy(__eliscript_value_212) ? ((__eliscript_value_213) => (__eliscript_truthy(__eliscript_value_213) ? ((__eliscript_value_214) => (__eliscript_truthy(__eliscript_value_214) ? ((__eliscript_value_215) => (__eliscript_truthy(__eliscript_value_215) ? ((__eliscript_value_216) => (__eliscript_truthy(__eliscript_value_216) ? ((__eliscript_value_217) => (__eliscript_truthy(__eliscript_value_217) ? ((no)["value"] === 0) : __eliscript_value_217))(positive_integer_literal(no)) : __eliscript_value_216))(increment_is(yes, index)) : __eliscript_value_215))(__eliscript_numeric_relation("<=", ((((((condition)["children"]) ?? [])[1]) ?? null))["value"], 2147483646)) : __eliscript_value_214))(positive_integer_literal((((((condition)["children"]) ?? [])[1]) ?? null))) : __eliscript_value_213))(local_node_is((((((condition)["children"]) ?? [])[0]) ?? null), index)) : __eliscript_value_212))(((condition)["value"] === "<")) : __eliscript_value_211))(((condition)["kind"] === "compare"));
|
|
1682
|
+
}
|
|
1683
|
+
} else {
|
|
1684
|
+
return null;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
function cycle_writes_proven(node, index) {
|
|
1688
|
+
{
|
|
1689
|
+
const __eliscript_value_218 = (node)["kind"];
|
|
1690
|
+
const __eliscript_value_219 = true;
|
|
1691
|
+
const __eliscript_value_220 = 0;
|
|
1692
|
+
{
|
|
1693
|
+
let kind = __eliscript_value_218;
|
|
1694
|
+
let valid = __eliscript_value_219;
|
|
1695
|
+
let i = __eliscript_value_220;
|
|
1696
|
+
if (((node)["value"] === index)) {
|
|
1697
|
+
if ((kind === "initialize")) {
|
|
1698
|
+
((valid = ((__eliscript_value_221) => (__eliscript_truthy(__eliscript_value_221) ? (((((((node)["children"]) ?? [])[0]) ?? null))["value"] === 0) : __eliscript_value_221))(positive_integer_literal((((((node)["children"]) ?? [])[0]) ?? null)))));
|
|
1699
|
+
} else {
|
|
1700
|
+
if ((kind === "set")) {
|
|
1701
|
+
((valid = cyclic_integer((((((node)["children"]) ?? [])[0]) ?? null), index)));
|
|
1702
|
+
} else {
|
|
1703
|
+
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
while (__eliscript_truthy(((__eliscript_value_222) => (__eliscript_truthy(__eliscript_value_222) ? __eliscript_numeric_relation("<", i, (((node)["children"]) ?? []).length) : __eliscript_value_222))(valid))) {
|
|
1708
|
+
((valid = cycle_writes_proven((((((node)["children"]) ?? [])[i]) ?? null), index)));
|
|
1709
|
+
((i = (i + 1)));
|
|
1710
|
+
}
|
|
1711
|
+
return valid;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
function specialize_cyclic_locals(body, locals) {
|
|
1716
|
+
{
|
|
1717
|
+
const __eliscript_value_223 = [];
|
|
1718
|
+
const __eliscript_value_224 = ((locals) ?? []).length;
|
|
1719
|
+
const __eliscript_value_225 = 0;
|
|
1720
|
+
const __eliscript_value_226 = null;
|
|
1721
|
+
{
|
|
1722
|
+
let descriptors = __eliscript_value_223;
|
|
1723
|
+
let count = __eliscript_value_224;
|
|
1724
|
+
let i = __eliscript_value_225;
|
|
1725
|
+
let selected = __eliscript_value_226;
|
|
1726
|
+
while (__eliscript_numeric_relation("<", i, count)) {
|
|
1727
|
+
{
|
|
1728
|
+
const __eliscript_value_227 = null;
|
|
1729
|
+
{
|
|
1730
|
+
let entry = __eliscript_value_227;
|
|
1731
|
+
if (__eliscript_truthy(((__eliscript_value_228) => (__eliscript_truthy(__eliscript_value_228) ? ((__eliscript_value_229) => (__eliscript_truthy(__eliscript_value_229) ? ((__eliscript_value_230) => (__eliscript_truthy(__eliscript_value_230) ? cycle_writes_proven(body, i) : __eliscript_value_230))(find_write(body, i, "set")) : __eliscript_value_229))(find_write(body, i, "initialize")) : __eliscript_value_228))(((((((locals) ?? [])[i]) ?? null))["type"] === "f64")))) {
|
|
1732
|
+
((entry = ({"storage": ((locals) ?? []).length})));
|
|
1733
|
+
(locals)["push"](({"name": "integer-cycle", "index": ((locals) ?? []).length, "type": "i32"}));
|
|
1734
|
+
((selected = true));
|
|
1735
|
+
}
|
|
1736
|
+
(descriptors)["push"](entry);
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
((i = (i + 1)));
|
|
1740
|
+
}
|
|
1741
|
+
if (__eliscript_truthy(selected)) {
|
|
1742
|
+
return rewrite_integers(body, descriptors);
|
|
1743
|
+
} else {
|
|
1744
|
+
return body;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
function counter_depth(node, index, depth) {
|
|
1750
|
+
{
|
|
1751
|
+
let kind = (node)["kind"];
|
|
1752
|
+
let children = (node)["children"];
|
|
1753
|
+
let best = -1;
|
|
1754
|
+
let position = 0;
|
|
1755
|
+
if ((kind === "while")) {
|
|
1756
|
+
{
|
|
1757
|
+
let condition = ((((children) ?? [])[0]) ?? null);
|
|
1758
|
+
let first = (((condition)["kind"] === "and") ? (((((condition)["children"]) ?? [])[0]) ?? null) : condition);
|
|
1759
|
+
if (__eliscript_truthy(((__eliscript_value_231) => (__eliscript_truthy(__eliscript_value_231) ? local_node_is((((((first)["children"]) ?? [])[0]) ?? null), index) : __eliscript_value_231))(((first)["kind"] === "compare")))) {
|
|
1760
|
+
((best = depth));
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
while (__eliscript_numeric_relation("<", position, ((children) ?? []).length)) {
|
|
1765
|
+
{
|
|
1766
|
+
const __eliscript_value_232 = counter_depth(((((children) ?? [])[position]) ?? null), index, ((kind === "while") ? (depth + 1) : depth));
|
|
1767
|
+
{
|
|
1768
|
+
let candidate = __eliscript_value_232;
|
|
1769
|
+
if (__eliscript_numeric_relation(">", candidate, best)) {
|
|
1770
|
+
((best = candidate));
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
((position = (position + 1)));
|
|
1775
|
+
}
|
|
1776
|
+
return best;
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
function integer_value(node) {
|
|
1780
|
+
if (((node)["kind"] === "int-number")) {
|
|
1781
|
+
return (((((node)["children"]) ?? [])[0]) ?? null);
|
|
1782
|
+
} else {
|
|
1783
|
+
if (__eliscript_truthy(positive_integer_literal(node))) {
|
|
1784
|
+
return typed("int-literal", "i32", [], (node)["value"]);
|
|
1785
|
+
} else {
|
|
1786
|
+
if ((((node)["kind"] === "arithmetic") && ((node)["value"] === "1+"))) {
|
|
1787
|
+
return typed("int-add", "i32", [integer_value((((((node)["children"]) ?? [])[0]) ?? null)), typed("int-literal", "i32", [], 1)], null);
|
|
1788
|
+
} else {
|
|
1789
|
+
if (((node)["kind"] === "if")) {
|
|
1790
|
+
{
|
|
1791
|
+
let condition = (((((node)["children"]) ?? [])[0]) ?? null);
|
|
1792
|
+
let yes = integer_value((((((node)["children"]) ?? [])[1]) ?? null));
|
|
1793
|
+
let no = integer_value((((((node)["children"]) ?? [])[2]) ?? null));
|
|
1794
|
+
if (__eliscript_truthy(((__eliscript_value_233) => (__eliscript_truthy(__eliscript_value_233) ? ((__eliscript_value_234) => (__eliscript_truthy(__eliscript_value_234) ? ((__eliscript_value_235) => (__eliscript_truthy(__eliscript_value_235) ? ((__eliscript_value_236) => (__eliscript_truthy(__eliscript_value_236) ? ((__eliscript_value_237) => (__eliscript_truthy(__eliscript_value_237) ? ((__eliscript_value_238) => (__eliscript_truthy(__eliscript_value_238) ? ((__eliscript_value_239) => (__eliscript_truthy(__eliscript_value_239) ? ((__eliscript_value_240) => (__eliscript_truthy(__eliscript_value_240) ? (__eliscript_numeric_and((((((((condition)["children"]) ?? [])[1]) ?? null))["value"] + 1), ((((((condition)["children"]) ?? [])[1]) ?? null))["value"]) === 0) : __eliscript_value_240))(local_node_is((((((yes)["children"]) ?? [])[0]) ?? null), ((((((condition)["children"]) ?? [])[0]) ?? null))["value"])) : __eliscript_value_239))((((((((condition)["children"]) ?? [])[0]) ?? null))["kind"] === "local")) : __eliscript_value_238))((((((((condition)["children"]) ?? [])[1]) ?? null))["kind"] === "int-literal")) : __eliscript_value_237))(((no)["value"] === 0)) : __eliscript_value_236))(((no)["kind"] === "int-literal")) : __eliscript_value_235))(((yes)["kind"] === "int-add")) : __eliscript_value_234))(((condition)["value"] === "<")) : __eliscript_value_233))(((condition)["kind"] === "int-compare")))) {
|
|
1795
|
+
return typed("int-and", "i32", [yes, (((((condition)["children"]) ?? [])[1]) ?? null)], null);
|
|
1796
|
+
} else {
|
|
1797
|
+
return typed("if", "i32", [condition, yes, no], null);
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
} else {
|
|
1801
|
+
return backend_fail(node, "integer specialization lacks a range proof");
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
function integer_operand(node) {
|
|
1808
|
+
return ((__eliscript_value_241) => (__eliscript_truthy(__eliscript_value_241) ? __eliscript_value_241 : positive_integer_literal(node)))(((node)["kind"] === "int-number"));
|
|
1809
|
+
}
|
|
1810
|
+
function rewrite_integers(node, descriptors) {
|
|
1811
|
+
{
|
|
1812
|
+
let kind = (node)["kind"];
|
|
1813
|
+
let value = (node)["value"];
|
|
1814
|
+
let descriptor = (((kind === "local") || (kind === "set") || (kind === "initialize")) ? ((((descriptors) ?? [])[value]) ?? null) : null);
|
|
1815
|
+
let children = [];
|
|
1816
|
+
let position = 0;
|
|
1817
|
+
while (__eliscript_numeric_relation("<", position, (((node)["children"]) ?? []).length)) {
|
|
1818
|
+
(children)["push"](rewrite_integers((((((node)["children"]) ?? [])[position]) ?? null), descriptors));
|
|
1819
|
+
((position = (position + 1)));
|
|
1820
|
+
}
|
|
1821
|
+
if (__eliscript_truthy(((__eliscript_value_242) => (__eliscript_truthy(__eliscript_value_242) ? (kind === "local") : __eliscript_value_242))(descriptor))) {
|
|
1822
|
+
return typed("int-number", "f64", [typed("local", "i32", [], (descriptor)["storage"])], null);
|
|
1823
|
+
} else {
|
|
1824
|
+
if (__eliscript_truthy(((__eliscript_value_243) => (__eliscript_truthy(__eliscript_value_243) ? ((kind === "set") || (kind === "initialize")) : __eliscript_value_243))(descriptor))) {
|
|
1825
|
+
return typed("int-number", "f64", [typed(kind, "i32", [integer_value(((((children) ?? [])[0]) ?? null))], (descriptor)["storage"])], null);
|
|
1826
|
+
} else {
|
|
1827
|
+
if (((kind === "compare") && (value === "<") && (((((((node)["children"]) ?? [])[0]) ?? null))["kind"] === "local"))) {
|
|
1828
|
+
{
|
|
1829
|
+
let entry = ((((descriptors) ?? [])[((((((node)["children"]) ?? [])[0]) ?? null))["value"]]) ?? null);
|
|
1830
|
+
let right = (((((node)["children"]) ?? [])[1]) ?? null);
|
|
1831
|
+
let bound = (__eliscript_truthy(entry) ? ((entry)["bound"] ?? null) : null);
|
|
1832
|
+
if (__eliscript_truthy(((__eliscript_value_244) => (__eliscript_truthy(__eliscript_value_244) ? (((right)["kind"] === (bound)["kind"]) && ((right)["value"] === (bound)["value"])) : __eliscript_value_244))(bound))) {
|
|
1833
|
+
return typed("int-compare", "i32", [integer_value(((((children) ?? [])[0]) ?? null)), typed("local", "i32", [], (entry)["limit"])], value);
|
|
1834
|
+
} else {
|
|
1835
|
+
if (__eliscript_truthy(((__eliscript_value_245) => (__eliscript_truthy(__eliscript_value_245) ? integer_operand(((((children) ?? [])[1]) ?? null)) : __eliscript_value_245))(integer_operand(((((children) ?? [])[0]) ?? null))))) {
|
|
1836
|
+
return typed("int-compare", "i32", [integer_value(((((children) ?? [])[0]) ?? null)), integer_value(((((children) ?? [])[1]) ?? null))], value);
|
|
1837
|
+
} else {
|
|
1838
|
+
return typed(kind, (node)["type"], children, value);
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
} else {
|
|
1843
|
+
return typed(kind, (node)["type"], children, value);
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
function specialize_integer_locals(body, locals, arity) {
|
|
1850
|
+
{
|
|
1851
|
+
const __eliscript_value_246 = [];
|
|
1852
|
+
const __eliscript_value_247 = [];
|
|
1853
|
+
const __eliscript_value_248 = [];
|
|
1854
|
+
const __eliscript_value_249 = ((locals) ?? []).length;
|
|
1855
|
+
const __eliscript_value_250 = 0;
|
|
1856
|
+
const __eliscript_value_251 = 0;
|
|
1857
|
+
const __eliscript_value_252 = null;
|
|
1858
|
+
{
|
|
1859
|
+
let descriptors = __eliscript_value_246;
|
|
1860
|
+
let guards = __eliscript_value_247;
|
|
1861
|
+
let prelude = __eliscript_value_248;
|
|
1862
|
+
let count = __eliscript_value_249;
|
|
1863
|
+
let index = __eliscript_value_250;
|
|
1864
|
+
let selected = __eliscript_value_251;
|
|
1865
|
+
let small = __eliscript_value_252;
|
|
1866
|
+
while (__eliscript_numeric_relation("<", index, count)) {
|
|
1867
|
+
{
|
|
1868
|
+
const __eliscript_value_253 = find_write(body, index, "initialize");
|
|
1869
|
+
const __eliscript_value_254 = find_write(body, index, "set");
|
|
1870
|
+
const __eliscript_value_255 = null;
|
|
1871
|
+
{
|
|
1872
|
+
let initializer = __eliscript_value_253;
|
|
1873
|
+
let update = __eliscript_value_254;
|
|
1874
|
+
let entry = __eliscript_value_255;
|
|
1875
|
+
if (__eliscript_truthy(((__eliscript_value_256) => (__eliscript_truthy(__eliscript_value_256) ? ((__eliscript_value_257) => (__eliscript_truthy(__eliscript_value_257) ? ((__eliscript_value_258) => (__eliscript_truthy(__eliscript_value_258) ? ((__eliscript_value_259) => (__eliscript_truthy(__eliscript_value_259) ? (((((((initializer)["children"]) ?? [])[0]) ?? null))["value"] === 0) : __eliscript_value_259))(positive_integer_literal((((((initializer)["children"]) ?? [])[0]) ?? null))) : __eliscript_value_258))((writes_local(body, index) === 2)) : __eliscript_value_257))(update) : __eliscript_value_256))(initializer))) {
|
|
1876
|
+
{
|
|
1877
|
+
let rhs = (((((update)["children"]) ?? [])[0]) ?? null);
|
|
1878
|
+
let bound = (__eliscript_truthy(increment_is(rhs, index)) ? counter_bound(body, index, body, arity) : null);
|
|
1879
|
+
if (__eliscript_truthy(((__eliscript_value_260) => (__eliscript_truthy(__eliscript_value_260) ? __eliscript_value_260 : cyclic_integer(rhs, index)))(bound))) {
|
|
1880
|
+
((entry = ({"storage": ((locals) ?? []).length, "bound": bound})));
|
|
1881
|
+
(locals)["push"](({"name": "integer-counter", "index": ((locals) ?? []).length, "type": "i32", "boundedInteger": true}));
|
|
1882
|
+
if (__eliscript_truthy(bound)) {
|
|
1883
|
+
((entry)["limit"] = ((locals) ?? []).length);
|
|
1884
|
+
(locals)["push"](({"name": "integer-limit", "index": ((locals) ?? []).length, "type": "i32", "boundedInteger": true}));
|
|
1885
|
+
if ((!__eliscript_truthy(positive_integer_literal(bound)))) {
|
|
1886
|
+
(guards)["push"](typed("compare", "i32", [bound, typed("literal", "f64", [], 0)], ">="));
|
|
1887
|
+
(guards)["push"](typed("compare", "i32", [bound, typed("literal", "f64", [], 2147483647)], "<="));
|
|
1888
|
+
}
|
|
1889
|
+
(prelude)["push"](typed("initialize", "i32", [typed("ceil-int", "i32", [bound], null)], (entry)["limit"]));
|
|
1890
|
+
((entry)["depth"] = counter_depth(body, index, 0));
|
|
1891
|
+
if ((((bound)["kind"] === "local") && ((!__eliscript_truthy(small)) || __eliscript_numeric_relation(">", (entry)["depth"], (small)["depth"])))) {
|
|
1892
|
+
((small = entry));
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
((selected = (selected + 1)));
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
(descriptors)["push"](entry);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
((index = (index + 1)));
|
|
1903
|
+
}
|
|
1904
|
+
if ((selected === 0)) {
|
|
1905
|
+
return body;
|
|
1906
|
+
} else {
|
|
1907
|
+
{
|
|
1908
|
+
const __eliscript_value_261 = rewrite_integers(body, descriptors);
|
|
1909
|
+
{
|
|
1910
|
+
let rewritten = __eliscript_value_261;
|
|
1911
|
+
(prelude)["push"]((__eliscript_truthy(small) ? typed("if", "f64", [typed("int-compare", "i32", [typed("local", "i32", [], (small)["limit"]), typed("int-literal", "i32", [], 2)], "<"), unroll_integer_loops(single_iteration_loops(rewritten, small)), unroll_integer_loops(rewritten)], null) : unroll_integer_loops(rewritten)));
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
{
|
|
1915
|
+
const __eliscript_value_262 = typed("sequence", "f64", prelude, null);
|
|
1916
|
+
{
|
|
1917
|
+
let fast = __eliscript_value_262;
|
|
1918
|
+
if ((((guards) ?? []).length === 0)) {
|
|
1919
|
+
return fast;
|
|
1920
|
+
} else {
|
|
1921
|
+
return typed("if", "f64", [typed("and", "i32", guards, null), fast, body], null);
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
function unroll_integer_loops(node) {
|
|
1930
|
+
{
|
|
1931
|
+
const __eliscript_value_263 = [];
|
|
1932
|
+
const __eliscript_value_264 = 0;
|
|
1933
|
+
{
|
|
1934
|
+
let children = __eliscript_value_263;
|
|
1935
|
+
let index = __eliscript_value_264;
|
|
1936
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
1937
|
+
(children)["push"](unroll_integer_loops((((((node)["children"]) ?? [])[index]) ?? null)));
|
|
1938
|
+
((index = (index + 1)));
|
|
1939
|
+
}
|
|
1940
|
+
{
|
|
1941
|
+
const __eliscript_value_265 = typed((node)["kind"], (node)["type"], children, (node)["value"]);
|
|
1942
|
+
{
|
|
1943
|
+
let copy = __eliscript_value_265;
|
|
1944
|
+
if (((copy)["kind"] === "while")) {
|
|
1945
|
+
{
|
|
1946
|
+
let condition = ((((children) ?? [])[0]) ?? null);
|
|
1947
|
+
let body = ((((children) ?? [])[1]) ?? null);
|
|
1948
|
+
let operands = (condition)["children"];
|
|
1949
|
+
let tail = last_statement(body);
|
|
1950
|
+
if (((tail)["kind"] === "int-number")) {
|
|
1951
|
+
((tail = (((((tail)["children"]) ?? [])[0]) ?? null)));
|
|
1952
|
+
}
|
|
1953
|
+
if (__eliscript_truthy(((__eliscript_value_266) => (__eliscript_truthy(__eliscript_value_266) ? ((__eliscript_value_267) => (__eliscript_truthy(__eliscript_value_267) ? (((((((operands) ?? [])[1]) ?? null))["kind"] === "local") && ((tail)["kind"] === "set") && (((((((tail)["children"]) ?? [])[0]) ?? null))["kind"] === "int-add") && (writes_local(body, (((((operands) ?? [])[0]) ?? null))["value"]) === 1) && (writes_local(body, (((((operands) ?? [])[1]) ?? null))["value"]) === 0) && (!__eliscript_truthy(contains_kind(body, "while"))) && __eliscript_numeric_relation("<=", tree_size(body), 128)) : __eliscript_value_267))(local_node_is(((((operands) ?? [])[0]) ?? null), (tail)["value"])) : __eliscript_value_266))(((condition)["kind"] === "int-compare")))) {
|
|
1954
|
+
return typed("sequence", "i32", [typed("while", "i32", [typed("int-compare", "i32", [typed("int-literal", "i32", [], 3), typed("int-sub", "i32", [((((operands) ?? [])[1]) ?? null), ((((operands) ?? [])[0]) ?? null)], null)], "<"), typed("sequence", (body)["type"], [body, body, body, body], null)], null), typed("remainder-while", "i32", children, null)], null);
|
|
1955
|
+
} else {
|
|
1956
|
+
return copy;
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
} else {
|
|
1960
|
+
return copy;
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
function single_iteration_loops(node, entry) {
|
|
1968
|
+
{
|
|
1969
|
+
const __eliscript_value_268 = [];
|
|
1970
|
+
const __eliscript_value_269 = 0;
|
|
1971
|
+
{
|
|
1972
|
+
let children = __eliscript_value_268;
|
|
1973
|
+
let index = __eliscript_value_269;
|
|
1974
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
1975
|
+
(children)["push"](single_iteration_loops((((((node)["children"]) ?? [])[index]) ?? null), entry));
|
|
1976
|
+
((index = (index + 1)));
|
|
1977
|
+
}
|
|
1978
|
+
if (((node)["kind"] === "while")) {
|
|
1979
|
+
{
|
|
1980
|
+
let condition = ((((children) ?? [])[0]) ?? null);
|
|
1981
|
+
let first = (((condition)["kind"] === "and") ? (((((condition)["children"]) ?? [])[0]) ?? null) : condition);
|
|
1982
|
+
if (__eliscript_truthy(((__eliscript_value_270) => (__eliscript_truthy(__eliscript_value_270) ? ((__eliscript_value_271) => (__eliscript_truthy(__eliscript_value_271) ? local_node_is((((((first)["children"]) ?? [])[1]) ?? null), (entry)["limit"]) : __eliscript_value_271))(local_node_is((((((first)["children"]) ?? [])[0]) ?? null), (entry)["storage"])) : __eliscript_value_270))(((first)["kind"] === "int-compare")))) {
|
|
1983
|
+
return typed("if", "i32", [condition, typed("sequence", "i32", [((((children) ?? [])[1]) ?? null), typed("literal", "i32", [], 0)], null), typed("literal", "i32", [], 0)], null);
|
|
1984
|
+
} else {
|
|
1985
|
+
return typed("while", "i32", children, null);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
} else {
|
|
1989
|
+
return typed((node)["kind"], (node)["type"], children, (node)["value"]);
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
function expandable_guard(node, locals) {
|
|
1995
|
+
{
|
|
1996
|
+
const __eliscript_value_272 = (node)["kind"];
|
|
1997
|
+
{
|
|
1998
|
+
let kind = __eliscript_value_272;
|
|
1999
|
+
if ((kind === "and")) {
|
|
2000
|
+
{
|
|
2001
|
+
const __eliscript_value_273 = 0;
|
|
2002
|
+
const __eliscript_value_274 = true;
|
|
2003
|
+
{
|
|
2004
|
+
let index = __eliscript_value_273;
|
|
2005
|
+
let pure = __eliscript_value_274;
|
|
2006
|
+
while (__eliscript_truthy(((__eliscript_value_275) => (__eliscript_truthy(__eliscript_value_275) ? __eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length) : __eliscript_value_275))(pure))) {
|
|
2007
|
+
((pure = expandable_guard((((((node)["children"]) ?? [])[index]) ?? null), locals)));
|
|
2008
|
+
((index = (index + 1)));
|
|
2009
|
+
}
|
|
2010
|
+
return pure;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
} else {
|
|
2014
|
+
if ((kind === "set")) {
|
|
2015
|
+
return ((__eliscript_value_276) => (__eliscript_truthy(__eliscript_value_276) ? numeric_pure((((((node)["children"]) ?? [])[0]) ?? null)) : __eliscript_value_276))(((((((locals) ?? [])[(node)["value"]]) ?? null))["pureGuardCache"] ?? null));
|
|
2016
|
+
} else {
|
|
2017
|
+
if (((kind === "arithmetic") || (kind === "compare") || (kind === "not"))) {
|
|
2018
|
+
{
|
|
2019
|
+
const __eliscript_value_277 = 0;
|
|
2020
|
+
const __eliscript_value_278 = true;
|
|
2021
|
+
{
|
|
2022
|
+
let index = __eliscript_value_277;
|
|
2023
|
+
let pure = __eliscript_value_278;
|
|
2024
|
+
while (__eliscript_truthy(((__eliscript_value_279) => (__eliscript_truthy(__eliscript_value_279) ? __eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length) : __eliscript_value_279))(pure))) {
|
|
2025
|
+
((pure = expandable_guard((((((node)["children"]) ?? [])[index]) ?? null), locals)));
|
|
2026
|
+
((index = (index + 1)));
|
|
2027
|
+
}
|
|
2028
|
+
return pure;
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
} else {
|
|
2032
|
+
return numeric_pure(node);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
function expand_compound_loops(node, locals) {
|
|
2040
|
+
{
|
|
2041
|
+
const __eliscript_value_280 = [];
|
|
2042
|
+
const __eliscript_value_281 = 0;
|
|
2043
|
+
{
|
|
2044
|
+
let children = __eliscript_value_280;
|
|
2045
|
+
let index = __eliscript_value_281;
|
|
2046
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
2047
|
+
(children)["push"](expand_compound_loops((((((node)["children"]) ?? [])[index]) ?? null), locals));
|
|
2048
|
+
((index = (index + 1)));
|
|
2049
|
+
}
|
|
2050
|
+
return typed((__eliscript_truthy(((__eliscript_value_282) => (__eliscript_truthy(__eliscript_value_282) ? ((__eliscript_value_283) => (__eliscript_truthy(__eliscript_value_283) ? ((__eliscript_value_284) => (__eliscript_truthy(__eliscript_value_284) ? ((!__eliscript_truthy(contains_kind(((((children) ?? [])[1]) ?? null), "while"))) && __eliscript_numeric_relation("<=", tree_size(((((children) ?? [])[1]) ?? null)), 128)) : __eliscript_value_284))(expandable_guard(((((children) ?? [])[0]) ?? null), locals)) : __eliscript_value_283))(((((((children) ?? [])[0]) ?? null))["kind"] === "and")) : __eliscript_value_282))(((node)["kind"] === "while"))) ? "guarded-while" : (node)["kind"]), (node)["type"], children, (node)["value"]);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
function counted_compound_loops(node, locals) {
|
|
2055
|
+
{
|
|
2056
|
+
const __eliscript_value_285 = [];
|
|
2057
|
+
const __eliscript_value_286 = 0;
|
|
2058
|
+
{
|
|
2059
|
+
let children = __eliscript_value_285;
|
|
2060
|
+
let index = __eliscript_value_286;
|
|
2061
|
+
while (__eliscript_numeric_relation("<", index, (((node)["children"]) ?? []).length)) {
|
|
2062
|
+
(children)["push"](counted_compound_loops((((((node)["children"]) ?? [])[index]) ?? null), locals));
|
|
2063
|
+
((index = (index + 1)));
|
|
2064
|
+
}
|
|
2065
|
+
{
|
|
2066
|
+
const __eliscript_value_287 = typed((node)["kind"], (node)["type"], children, (node)["value"]);
|
|
2067
|
+
{
|
|
2068
|
+
let copy = __eliscript_value_287;
|
|
2069
|
+
if (((node)["kind"] === "guarded-while")) {
|
|
2070
|
+
{
|
|
2071
|
+
let condition = ((((children) ?? [])[0]) ?? null);
|
|
2072
|
+
let body = ((((children) ?? [])[1]) ?? null);
|
|
2073
|
+
let guards = (condition)["children"];
|
|
2074
|
+
let counter = ((((guards) ?? [])[0]) ?? null);
|
|
2075
|
+
let a = (((((counter)["children"]) ?? [])[0]) ?? null);
|
|
2076
|
+
let b = (((((counter)["children"]) ?? [])[1]) ?? null);
|
|
2077
|
+
let tail = last_statement(body);
|
|
2078
|
+
if (((tail)["kind"] === "int-number")) {
|
|
2079
|
+
((tail = (((((tail)["children"]) ?? [])[0]) ?? null)));
|
|
2080
|
+
}
|
|
2081
|
+
if (__eliscript_truthy(((__eliscript_value_288) => (__eliscript_truthy(__eliscript_value_288) ? ((__eliscript_value_289) => (__eliscript_truthy(__eliscript_value_289) ? ((__eliscript_value_290) => (__eliscript_truthy(__eliscript_value_290) ? ((__eliscript_value_291) => (__eliscript_truthy(__eliscript_value_291) ? ((__eliscript_value_292) => (__eliscript_truthy(__eliscript_value_292) ? ((__eliscript_value_293) => (__eliscript_truthy(__eliscript_value_293) ? ((__eliscript_value_294) => (__eliscript_truthy(__eliscript_value_294) ? ((__eliscript_value_295) => (__eliscript_truthy(__eliscript_value_295) ? ((__eliscript_value_296) => (__eliscript_truthy(__eliscript_value_296) ? ((__eliscript_value_297) => (__eliscript_truthy(__eliscript_value_297) ? ((__eliscript_value_298) => (__eliscript_truthy(__eliscript_value_298) ? ((__eliscript_value_299) => (__eliscript_truthy(__eliscript_value_299) ? (((((((((((((tail)["children"]) ?? [])[0]) ?? null))["children"]) ?? [])[1]) ?? null))["kind"] === "int-literal") && ((((((((((((tail)["children"]) ?? [])[0]) ?? null))["children"]) ?? [])[1]) ?? null))["value"] === 1)) : __eliscript_value_299))(local_node_is(((((((((((tail)["children"]) ?? [])[0]) ?? null))["children"]) ?? [])[0]) ?? null), (a)["value"])) : __eliscript_value_298))((((((((tail)["children"]) ?? [])[0]) ?? null))["kind"] === "int-add")) : __eliscript_value_297))((writes_local(body, (b)["value"]) === 0)) : __eliscript_value_296))((writes_local(body, (a)["value"]) === 1)) : __eliscript_value_295))(((tail)["value"] === (a)["value"])) : __eliscript_value_294))(((tail)["kind"] === "set")) : __eliscript_value_293))(((((((locals) ?? [])[(b)["value"]]) ?? null))["boundedInteger"] ?? null)) : __eliscript_value_292))(((((((locals) ?? [])[(a)["value"]]) ?? null))["boundedInteger"] ?? null)) : __eliscript_value_291))(((b)["kind"] === "local")) : __eliscript_value_290))(((a)["kind"] === "local")) : __eliscript_value_289))(((counter)["value"] === "<")) : __eliscript_value_288))(((counter)["kind"] === "int-compare")))) {
|
|
2082
|
+
return typed("guarded-counter-while", (node)["type"], [condition, body, typed("int-compare", "i32", [typed("int-literal", "i32", [], 3), typed("int-sub", "i32", [b, a], null)], "<"), ((((guards) ?? []).length === 2) ? ((((guards) ?? [])[1]) ?? null) : typed("and", "i32", (guards)["slice"](1), null))], null);
|
|
2083
|
+
} else {
|
|
2084
|
+
return copy;
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
} else {
|
|
2088
|
+
return copy;
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
function flow_literal(node) {
|
|
2096
|
+
return (((node)["kind"] === "literal") || ((node)["kind"] === "int-literal"));
|
|
2097
|
+
}
|
|
2098
|
+
function invalidate_flow_writes(node, known) {
|
|
2099
|
+
if (((((node)["kind"] === "set") || ((node)["kind"] === "initialize")) && __eliscript_numeric_relation("<", (node)["value"], ((known) ?? []).length))) {
|
|
2100
|
+
(known)["splice"]((node)["value"], 1, null);
|
|
2101
|
+
}
|
|
2102
|
+
{
|
|
2103
|
+
const __eliscript_value_300 = 0;
|
|
2104
|
+
{
|
|
2105
|
+
let i = __eliscript_value_300;
|
|
2106
|
+
while (__eliscript_numeric_relation("<", i, (((node)["children"]) ?? []).length)) {
|
|
2107
|
+
invalidate_flow_writes((((((node)["children"]) ?? [])[i]) ?? null), known);
|
|
2108
|
+
((i = (i + 1)));
|
|
2109
|
+
}
|
|
2110
|
+
return null;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
function same_flow_literal(left, right) {
|
|
2115
|
+
return ((__eliscript_value_301) => (__eliscript_truthy(__eliscript_value_301) ? ((__eliscript_value_302) => (__eliscript_truthy(__eliscript_value_302) ? ((__eliscript_value_303) => (__eliscript_truthy(__eliscript_value_303) ? ((__eliscript_value_304) => (__eliscript_truthy(__eliscript_value_304) ? ((a, b) => {
|
|
2116
|
+
return ((((((a) ?? [])[0]) ?? null) === ((((b) ?? [])[0]) ?? null)) && (((((a) ?? [])[1]) ?? null) === ((((b) ?? [])[1]) ?? null)));
|
|
2117
|
+
})(((__eliscript_number) => { const __eliscript_bytes = new DataView(new ArrayBuffer(8)); __eliscript_bytes.setFloat64(0, __eliscript_number === 0 ? 0 : __eliscript_number, true); return [__eliscript_bytes.getUint32(0, true), __eliscript_bytes.getUint32(4, true)]; })((left)["value"]), ((__eliscript_number) => { const __eliscript_bytes = new DataView(new ArrayBuffer(8)); __eliscript_bytes.setFloat64(0, __eliscript_number === 0 ? 0 : __eliscript_number, true); return [__eliscript_bytes.getUint32(0, true), __eliscript_bytes.getUint32(4, true)]; })((right)["value"])) : __eliscript_value_304))((((__eliscript_value_305, __eliscript_value_306) => (__eliscript_value_305 !== __eliscript_value_306))((left)["value"], 0) || (__eliscript_numeric_div(1, (left)["value"]) === __eliscript_numeric_div(1, (right)["value"])))) : __eliscript_value_303))(((left)["type"] === (right)["type"])) : __eliscript_value_302))(right) : __eliscript_value_301))(left);
|
|
2118
|
+
}
|
|
2119
|
+
function fold_literal_operation(node) {
|
|
2120
|
+
{
|
|
2121
|
+
let kind = (node)["kind"];
|
|
2122
|
+
let children = (node)["children"];
|
|
2123
|
+
let op = (node)["value"];
|
|
2124
|
+
let i = 0;
|
|
2125
|
+
let all = true;
|
|
2126
|
+
while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
|
|
2127
|
+
if ((!__eliscript_truthy(flow_literal(((((children) ?? [])[i]) ?? null))))) {
|
|
2128
|
+
((all = null));
|
|
2129
|
+
}
|
|
2130
|
+
((i = (i + 1)));
|
|
2131
|
+
}
|
|
2132
|
+
if ((!__eliscript_truthy(all))) {
|
|
2133
|
+
return node;
|
|
2134
|
+
} else {
|
|
2135
|
+
{
|
|
2136
|
+
const __eliscript_value_307 = (__eliscript_numeric_relation(">", ((children) ?? []).length, 0) ? (((((children) ?? [])[0]) ?? null))["value"] : 0);
|
|
2137
|
+
const __eliscript_value_308 = (__eliscript_numeric_relation(">", ((children) ?? []).length, 1) ? (((((children) ?? [])[1]) ?? null))["value"] : 1);
|
|
2138
|
+
const __eliscript_value_309 = null;
|
|
2139
|
+
const __eliscript_value_310 = true;
|
|
2140
|
+
{
|
|
2141
|
+
let a = __eliscript_value_307;
|
|
2142
|
+
let b = __eliscript_value_308;
|
|
2143
|
+
let value = __eliscript_value_309;
|
|
2144
|
+
let valid = __eliscript_value_310;
|
|
2145
|
+
if ((kind === "arithmetic")) {
|
|
2146
|
+
((value = ((((children) ?? []).length === 0) ? ((op === "*") ? 1 : 0) : ((op === "1+") ? (a + 1) : ((op === "1-") ? __eliscript_numeric_decrement(a) : ((((children) ?? []).length === 1) ? ((op === "-") ? __eliscript_numeric_neg(a) : ((op === "/") ? __eliscript_numeric_div(1, a) : a)) : ((op === "+") ? (a + b) : ((op === "-") ? __eliscript_numeric_sub(a, b) : ((op === "*") ? __eliscript_numeric_mul(a, b) : __eliscript_numeric_div(a, b))))))))));
|
|
2147
|
+
} else {
|
|
2148
|
+
if (((kind === "compare") || (kind === "int-compare"))) {
|
|
2149
|
+
((value = (__eliscript_truthy(((op === "=") ? (a === b) : ((op === "<") ? __eliscript_numeric_relation("<", a, b) : ((op === "<=") ? __eliscript_numeric_relation("<=", a, b) : ((op === ">") ? __eliscript_numeric_relation(">", a, b) : __eliscript_numeric_relation(">=", a, b)))))) ? 1 : 0)));
|
|
2150
|
+
} else {
|
|
2151
|
+
if ((kind === "int-number")) {
|
|
2152
|
+
((value = a));
|
|
2153
|
+
} else {
|
|
2154
|
+
if ((kind === "int-add")) {
|
|
2155
|
+
((value = __eliscript_numeric_or((a + b), 0)));
|
|
2156
|
+
} else {
|
|
2157
|
+
if ((kind === "int-sub")) {
|
|
2158
|
+
((value = __eliscript_numeric_or(__eliscript_numeric_sub(a, b), 0)));
|
|
2159
|
+
} else {
|
|
2160
|
+
if ((kind === "int-and")) {
|
|
2161
|
+
((value = __eliscript_numeric_and(a, b)));
|
|
2162
|
+
} else {
|
|
2163
|
+
if ((kind === "not")) {
|
|
2164
|
+
((value = ((((((((children) ?? [])[0]) ?? null))["type"] === "i32") && (a === 0)) ? 1 : 0)));
|
|
2165
|
+
} else {
|
|
2166
|
+
((valid = null));
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
if (__eliscript_truthy(valid)) {
|
|
2175
|
+
return typed("literal", (node)["type"], [], value);
|
|
2176
|
+
} else {
|
|
2177
|
+
return node;
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
function fold_constant_flow(node, known) {
|
|
2185
|
+
{
|
|
2186
|
+
const __eliscript_value_311 = (node)["kind"];
|
|
2187
|
+
const __eliscript_value_312 = (node)["value"];
|
|
2188
|
+
const __eliscript_value_313 = (node)["children"];
|
|
2189
|
+
{
|
|
2190
|
+
let kind = __eliscript_value_311;
|
|
2191
|
+
let value = __eliscript_value_312;
|
|
2192
|
+
let children = __eliscript_value_313;
|
|
2193
|
+
if ((kind === "local")) {
|
|
2194
|
+
return ((__eliscript_value_314) => (__eliscript_truthy(__eliscript_value_314) ? __eliscript_value_314 : node))(((((known) ?? [])[value]) ?? null));
|
|
2195
|
+
} else {
|
|
2196
|
+
if ((kind === "if")) {
|
|
2197
|
+
{
|
|
2198
|
+
const __eliscript_value_315 = fold_constant_flow(((((children) ?? [])[0]) ?? null), known);
|
|
2199
|
+
{
|
|
2200
|
+
let guard = __eliscript_value_315;
|
|
2201
|
+
if (__eliscript_truthy(flow_literal(guard))) {
|
|
2202
|
+
return fold_constant_flow(((((children) ?? [])[((((guard)["type"] === "f64") || ((__eliscript_value_316, __eliscript_value_317) => (__eliscript_value_316 !== __eliscript_value_317))((guard)["value"], 0)) ? 1 : 2)]) ?? null), known);
|
|
2203
|
+
} else {
|
|
2204
|
+
{
|
|
2205
|
+
let yes_known = (known)["slice"]();
|
|
2206
|
+
let no_known = (known)["slice"]();
|
|
2207
|
+
let yes = fold_constant_flow(((((children) ?? [])[1]) ?? null), yes_known);
|
|
2208
|
+
let no = fold_constant_flow(((((children) ?? [])[2]) ?? null), no_known);
|
|
2209
|
+
let i = 0;
|
|
2210
|
+
while (__eliscript_numeric_relation("<", i, ((known) ?? []).length)) {
|
|
2211
|
+
(known)["splice"](i, 1, (__eliscript_truthy(same_flow_literal(((((yes_known) ?? [])[i]) ?? null), ((((no_known) ?? [])[i]) ?? null))) ? ((((yes_known) ?? [])[i]) ?? null) : null));
|
|
2212
|
+
((i = (i + 1)));
|
|
2213
|
+
}
|
|
2214
|
+
return typed(kind, (node)["type"], [guard, yes, no], value);
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
} else {
|
|
2220
|
+
if (((kind === "while") || (kind === "remainder-while") || (kind === "guarded-while"))) {
|
|
2221
|
+
invalidate_flow_writes(node, known);
|
|
2222
|
+
{
|
|
2223
|
+
let inner = (known)["slice"]();
|
|
2224
|
+
let guard = fold_constant_flow(((((children) ?? [])[0]) ?? null), inner);
|
|
2225
|
+
let body = fold_constant_flow(((((children) ?? [])[1]) ?? null), inner);
|
|
2226
|
+
return typed(kind, (node)["type"], [guard, body], value);
|
|
2227
|
+
}
|
|
2228
|
+
} else {
|
|
2229
|
+
if (((kind === "and") || (kind === "or"))) {
|
|
2230
|
+
invalidate_flow_writes(node, known);
|
|
2231
|
+
{
|
|
2232
|
+
const __eliscript_value_318 = [];
|
|
2233
|
+
const __eliscript_value_319 = 0;
|
|
2234
|
+
{
|
|
2235
|
+
let output = __eliscript_value_318;
|
|
2236
|
+
let i = __eliscript_value_319;
|
|
2237
|
+
while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
|
|
2238
|
+
(output)["push"](fold_constant_flow(((((children) ?? [])[i]) ?? null), (known)["slice"]()));
|
|
2239
|
+
((i = (i + 1)));
|
|
2240
|
+
}
|
|
2241
|
+
return typed(kind, (node)["type"], output, value);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
} else {
|
|
2245
|
+
{
|
|
2246
|
+
const __eliscript_value_320 = [];
|
|
2247
|
+
const __eliscript_value_321 = 0;
|
|
2248
|
+
{
|
|
2249
|
+
let output = __eliscript_value_320;
|
|
2250
|
+
let i = __eliscript_value_321;
|
|
2251
|
+
while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
|
|
2252
|
+
(output)["push"](fold_constant_flow(((((children) ?? [])[i]) ?? null), known));
|
|
2253
|
+
((i = (i + 1)));
|
|
2254
|
+
}
|
|
2255
|
+
{
|
|
2256
|
+
const __eliscript_value_322 = fold_literal_operation(typed(kind, (node)["type"], output, value));
|
|
2257
|
+
{
|
|
2258
|
+
let copy = __eliscript_value_322;
|
|
2259
|
+
if (((kind === "set") || (kind === "initialize"))) {
|
|
2260
|
+
while (__eliscript_numeric_relation("<=", ((known) ?? []).length, value)) {
|
|
2261
|
+
(known)["push"](null);
|
|
2262
|
+
}
|
|
2263
|
+
(known)["splice"](value, 1, (__eliscript_truthy(flow_literal(((((output) ?? [])[0]) ?? null))) ? ((((output) ?? [])[0]) ?? null) : null));
|
|
2264
|
+
}
|
|
2265
|
+
return copy;
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
function collect_flow_reads(node, reads) {
|
|
2278
|
+
if (((node)["kind"] === "local")) {
|
|
2279
|
+
(reads)["push"]((node)["value"]);
|
|
2280
|
+
}
|
|
2281
|
+
{
|
|
2282
|
+
const __eliscript_value_323 = 0;
|
|
2283
|
+
{
|
|
2284
|
+
let i = __eliscript_value_323;
|
|
2285
|
+
while (__eliscript_numeric_relation("<", i, (((node)["children"]) ?? []).length)) {
|
|
2286
|
+
collect_flow_reads((((((node)["children"]) ?? [])[i]) ?? null), reads);
|
|
2287
|
+
((i = (i + 1)));
|
|
2288
|
+
}
|
|
2289
|
+
return null;
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
function remove_unread_stores(node, reads) {
|
|
2294
|
+
{
|
|
2295
|
+
const __eliscript_value_324 = [];
|
|
2296
|
+
const __eliscript_value_325 = 0;
|
|
2297
|
+
const __eliscript_value_326 = (node)["kind"];
|
|
2298
|
+
{
|
|
2299
|
+
let children = __eliscript_value_324;
|
|
2300
|
+
let i = __eliscript_value_325;
|
|
2301
|
+
let kind = __eliscript_value_326;
|
|
2302
|
+
while (__eliscript_numeric_relation("<", i, (((node)["children"]) ?? []).length)) {
|
|
2303
|
+
(children)["push"](remove_unread_stores((((((node)["children"]) ?? [])[i]) ?? null), reads));
|
|
2304
|
+
((i = (i + 1)));
|
|
2305
|
+
}
|
|
2306
|
+
if ((((kind === "set") || (kind === "initialize")) && (!__eliscript_truthy((reads)["includes"]((node)["value"]))))) {
|
|
2307
|
+
return ((((children) ?? [])[0]) ?? null);
|
|
2308
|
+
} else {
|
|
2309
|
+
return typed(kind, (node)["type"], children, (node)["value"]);
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
function invariant_guard(node, body) {
|
|
2315
|
+
{
|
|
2316
|
+
const __eliscript_value_327 = (node)["kind"];
|
|
2317
|
+
const __eliscript_value_328 = (node)["children"];
|
|
2318
|
+
const __eliscript_value_329 = 0;
|
|
2319
|
+
const __eliscript_value_330 = true;
|
|
2320
|
+
{
|
|
2321
|
+
let kind = __eliscript_value_327;
|
|
2322
|
+
let children = __eliscript_value_328;
|
|
2323
|
+
let i = __eliscript_value_329;
|
|
2324
|
+
let valid = __eliscript_value_330;
|
|
2325
|
+
if ((kind === "local")) {
|
|
2326
|
+
((valid = (writes_local(body, (node)["value"]) === 0)));
|
|
2327
|
+
} else {
|
|
2328
|
+
if (((kind === "literal") || (kind === "int-literal"))) {
|
|
2329
|
+
|
|
2330
|
+
} else {
|
|
2331
|
+
if (((kind === "arithmetic") || (kind === "compare") || (kind === "and") || (kind === "or") || (kind === "not") || (kind === "int-add") || (kind === "int-sub") || (kind === "int-and") || (kind === "int-compare") || (kind === "int-number") || (kind === "ceil-int"))) {
|
|
2332
|
+
|
|
2333
|
+
} else {
|
|
2334
|
+
((valid = null));
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
while (__eliscript_truthy(((__eliscript_value_331) => (__eliscript_truthy(__eliscript_value_331) ? __eliscript_numeric_relation("<", i, ((children) ?? []).length) : __eliscript_value_331))(valid))) {
|
|
2339
|
+
((valid = invariant_guard(((((children) ?? [])[i]) ?? null), body)));
|
|
2340
|
+
((i = (i + 1)));
|
|
2341
|
+
}
|
|
2342
|
+
return valid;
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
function invariant_if_path(node, body, path) {
|
|
2347
|
+
{
|
|
2348
|
+
const __eliscript_value_332 = (node)["kind"];
|
|
2349
|
+
const __eliscript_value_333 = (node)["children"];
|
|
2350
|
+
const __eliscript_value_334 = 0;
|
|
2351
|
+
const __eliscript_value_335 = null;
|
|
2352
|
+
{
|
|
2353
|
+
let kind = __eliscript_value_332;
|
|
2354
|
+
let children = __eliscript_value_333;
|
|
2355
|
+
let i = __eliscript_value_334;
|
|
2356
|
+
let found = __eliscript_value_335;
|
|
2357
|
+
if (__eliscript_truthy(((__eliscript_value_336) => (__eliscript_truthy(__eliscript_value_336) ? invariant_guard(((((children) ?? [])[0]) ?? null), body) : __eliscript_value_336))((kind === "if")))) {
|
|
2358
|
+
return ({"path": path, "condition": ((((children) ?? [])[0]) ?? null)});
|
|
2359
|
+
} else {
|
|
2360
|
+
if ((!((kind === "while") || (kind === "remainder-while") || (kind === "guarded-while")))) {
|
|
2361
|
+
while (((!__eliscript_truthy(found)) && __eliscript_numeric_relation("<", i, ((children) ?? []).length))) {
|
|
2362
|
+
{
|
|
2363
|
+
const __eliscript_value_337 = (path)["slice"]();
|
|
2364
|
+
{
|
|
2365
|
+
let next = __eliscript_value_337;
|
|
2366
|
+
(next)["push"](i);
|
|
2367
|
+
((found = invariant_if_path(((((children) ?? [])[i]) ?? null), body, next)));
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
((i = (i + 1)));
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
return found;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
function same_numeric_tree(left, right) {
|
|
2379
|
+
{
|
|
2380
|
+
const __eliscript_value_338 = (left)["children"];
|
|
2381
|
+
const __eliscript_value_339 = (right)["children"];
|
|
2382
|
+
const __eliscript_value_340 = 0;
|
|
2383
|
+
const __eliscript_value_341 = (((left)["kind"] === (right)["kind"]) && ((left)["type"] === (right)["type"]) && ((((left)["children"]) ?? []).length === (((right)["children"]) ?? []).length));
|
|
2384
|
+
{
|
|
2385
|
+
let a = __eliscript_value_338;
|
|
2386
|
+
let b = __eliscript_value_339;
|
|
2387
|
+
let i = __eliscript_value_340;
|
|
2388
|
+
let same = __eliscript_value_341;
|
|
2389
|
+
if (__eliscript_truthy(same)) {
|
|
2390
|
+
((same = (__eliscript_truthy(flow_literal(left)) ? same_flow_literal(left, right) : ((left)["value"] === (right)["value"]))));
|
|
2391
|
+
}
|
|
2392
|
+
while (__eliscript_truthy(((__eliscript_value_342) => (__eliscript_truthy(__eliscript_value_342) ? __eliscript_numeric_relation("<", i, ((a) ?? []).length) : __eliscript_value_342))(same))) {
|
|
2393
|
+
((same = same_numeric_tree(((((a) ?? [])[i]) ?? null), ((((b) ?? [])[i]) ?? null))));
|
|
2394
|
+
((i = (i + 1)));
|
|
2395
|
+
}
|
|
2396
|
+
return same;
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
function select_invariant_copies(node, guard, arm) {
|
|
2401
|
+
if (__eliscript_truthy(((__eliscript_value_343) => (__eliscript_truthy(__eliscript_value_343) ? same_numeric_tree((((((node)["children"]) ?? [])[0]) ?? null), guard) : __eliscript_value_343))(((node)["kind"] === "if")))) {
|
|
2402
|
+
return select_invariant_copies((((((node)["children"]) ?? [])[arm]) ?? null), guard, arm);
|
|
2403
|
+
} else {
|
|
2404
|
+
{
|
|
2405
|
+
const __eliscript_value_344 = [];
|
|
2406
|
+
const __eliscript_value_345 = 0;
|
|
2407
|
+
{
|
|
2408
|
+
let children = __eliscript_value_344;
|
|
2409
|
+
let i = __eliscript_value_345;
|
|
2410
|
+
while (__eliscript_numeric_relation("<", i, (((node)["children"]) ?? []).length)) {
|
|
2411
|
+
(children)["push"](select_invariant_copies((((((node)["children"]) ?? [])[i]) ?? null), guard, arm));
|
|
2412
|
+
((i = (i + 1)));
|
|
2413
|
+
}
|
|
2414
|
+
return typed((node)["kind"], (node)["type"], children, (node)["value"]);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
function unswitch_numeric_loops(node) {
|
|
2420
|
+
{
|
|
2421
|
+
const __eliscript_value_346 = [];
|
|
2422
|
+
const __eliscript_value_347 = (node)["kind"];
|
|
2423
|
+
const __eliscript_value_348 = 0;
|
|
2424
|
+
{
|
|
2425
|
+
let children = __eliscript_value_346;
|
|
2426
|
+
let kind = __eliscript_value_347;
|
|
2427
|
+
let i = __eliscript_value_348;
|
|
2428
|
+
while (__eliscript_numeric_relation("<", i, (((node)["children"]) ?? []).length)) {
|
|
2429
|
+
(children)["push"](unswitch_numeric_loops((((((node)["children"]) ?? [])[i]) ?? null)));
|
|
2430
|
+
((i = (i + 1)));
|
|
2431
|
+
}
|
|
2432
|
+
{
|
|
2433
|
+
const __eliscript_value_349 = typed(kind, (node)["type"], children, (node)["value"]);
|
|
2434
|
+
{
|
|
2435
|
+
let copy = __eliscript_value_349;
|
|
2436
|
+
if ((((kind === "while") || (kind === "remainder-while") || (kind === "guarded-while")) && __eliscript_numeric_relation("<=", tree_size(((((children) ?? [])[1]) ?? null)), 512))) {
|
|
2437
|
+
{
|
|
2438
|
+
let body = ((((children) ?? [])[1]) ?? null);
|
|
2439
|
+
let choice = invariant_if_path(body, copy, []);
|
|
2440
|
+
if (__eliscript_truthy(choice)) {
|
|
2441
|
+
return typed("if", (copy)["type"], [(choice)["condition"], typed(kind, (copy)["type"], [((((children) ?? [])[0]) ?? null), select_invariant_copies(body, (choice)["condition"], 1)], (copy)["value"]), typed(kind, (copy)["type"], [((((children) ?? [])[0]) ?? null), select_invariant_copies(body, (choice)["condition"], 2)], (copy)["value"])], null);
|
|
2442
|
+
} else {
|
|
2443
|
+
return copy;
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
} else {
|
|
2447
|
+
return copy;
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
function emit_numeric_javascript(program) {
|
|
2455
|
+
lower_numeric_program(program);
|
|
2456
|
+
return emit_module_numeric(optimize_program(program));
|
|
2457
|
+
}
|
|
2458
|
+
export {emit_numeric_javascript, lower_scalar_program, lower_numeric_program, optimize_numeric_program, numeric_pure, tree_size, backend_fail, find_function};
|