eliscript 0.1.3 → 0.1.4
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/COPYING.RUNTIME +93 -0
- package/README.md +15 -3
- package/bin/eliscript-test +29 -0
- package/bootstrap/backends/README.md +5 -4
- package/bootstrap/backends/binary.eli +89 -22
- package/bootstrap/backends/capabilities.eli +9 -4
- package/bootstrap/backends/managed-layout.eli +93 -81
- package/bootstrap/backends/managed.eli +651 -125
- package/bootstrap/backends/native.eli +1791 -324
- package/bootstrap/backends/numeric.eli +71 -7
- package/bootstrap/backends/sha256.eli +165 -68
- package/bootstrap/backends/wasm.eli +461 -52
- package/bootstrap/compiler/analyzer.eli +692 -2
- package/bootstrap/compiler/compiler.eli +16 -3
- package/bootstrap/compiler/emitter.eli +80 -35
- package/bootstrap/compiler/project.eli +175 -1
- package/bootstrap/compiler/transient-analysis.eli +2 -2
- package/bootstrap/host/build.eli +1 -0
- package/bootstrap/host/build.mjs +1 -1
- package/bootstrap/host/build.mjs.map +1 -1
- package/bootstrap/host/bun.mjs +7 -9
- package/bootstrap/host/bun.mjs.map +1 -1
- package/bootstrap/host/check-cli-ground.eli +47 -5
- package/bootstrap/host/check-cli-ground.mjs +60 -19
- package/bootstrap/host/check-cli-ground.mjs.map +1 -1
- package/bootstrap/host/check-cli.mjs +41 -1
- package/bootstrap/host/check-cli.mjs.map +1 -1
- package/bootstrap/host/compiler-session.eli +136 -22
- package/bootstrap/host/eliscript-cli.mjs +1 -1
- package/bootstrap/host/eliscript-cli.mjs.map +1 -1
- package/bootstrap/host/evaluation-cli.eli +33 -1
- package/bootstrap/host/evaluation-cli.mjs +65 -28
- package/bootstrap/host/evaluation-cli.mjs.map +1 -1
- package/bootstrap/host/evaluation.eli +651 -42
- package/bootstrap/host/evaluation.mjs +884 -72
- package/bootstrap/host/evaluation.mjs.map +1 -1
- package/bootstrap/host/project-cli-ground.eli +6 -1
- package/bootstrap/host/project-cli-ground.mjs +33 -32
- package/bootstrap/host/project-cli-ground.mjs.map +1 -1
- package/bootstrap/host/project-cli.mjs +1 -1
- package/bootstrap/host/project-cli.mjs.map +1 -1
- package/bootstrap/host/project-ground.eli +266 -45
- package/bootstrap/host/project-ground.mjs +429 -159
- package/bootstrap/host/project-ground.mjs.map +1 -1
- package/bootstrap/host/project.mjs +30 -40
- package/bootstrap/host/project.mjs.map +1 -1
- package/bootstrap/host/test-cli.eli +379 -0
- package/bootstrap/host/test-cli.mjs +494 -0
- package/bootstrap/host/test-cli.mjs.map +1 -0
- package/browser/README.md +7 -0
- package/browser/host.mjs +21 -29
- package/browser/host.mjs.map +1 -1
- package/browser/worker.mjs +7 -9
- package/browser/worker.mjs.map +1 -1
- package/compiler/eliscript-analyzer.el +694 -0
- package/compiler/eliscript-cli.el +66 -22
- package/compiler/eliscript-emitter.el +67 -43
- package/compiler/eliscript-ir-emitter.el +71 -36
- package/compiler/eliscript-project.el +360 -80
- package/compiler/eliscript-transient-analysis.el +5 -5
- package/compiler/eliscript.el +6 -0
- package/dist/backends/binary.mjs +148 -26
- package/dist/backends/binary.mjs.map +1 -1
- package/dist/backends/capabilities.mjs +11 -4
- package/dist/backends/capabilities.mjs.map +1 -1
- package/dist/backends/elf.mjs +4 -4
- package/dist/backends/elf.mjs.map +1 -1
- package/dist/backends/managed-layout.mjs +53 -56
- package/dist/backends/managed-layout.mjs.map +1 -1
- package/dist/backends/managed.mjs +1116 -375
- package/dist/backends/managed.mjs.map +1 -1
- package/dist/backends/memory.mjs +24 -26
- package/dist/backends/memory.mjs.map +1 -1
- package/dist/backends/native.mjs +2529 -434
- package/dist/backends/native.mjs.map +1 -1
- package/dist/backends/numeric.mjs +140 -33
- package/dist/backends/numeric.mjs.map +1 -1
- package/dist/backends/optimize.mjs +2 -2
- package/dist/backends/optimize.mjs.map +1 -1
- package/dist/backends/regexp.mjs +33 -35
- package/dist/backends/regexp.mjs.map +1 -1
- package/dist/backends/sha256.mjs +159 -59
- package/dist/backends/sha256.mjs.map +1 -1
- package/dist/backends/wasm.mjs +609 -73
- package/dist/backends/wasm.mjs.map +1 -1
- package/dist/bootstrap/analyzer.mjs +1018 -2
- package/dist/bootstrap/analyzer.mjs.map +1 -1
- package/dist/bootstrap/compiler.mjs +30 -23
- package/dist/bootstrap/compiler.mjs.map +1 -1
- package/dist/bootstrap/emitter.mjs +206 -161
- package/dist/bootstrap/emitter.mjs.macro-origins.json +16 -16
- package/dist/bootstrap/emitter.mjs.map +1 -1
- package/dist/bootstrap/expander.mjs +27 -31
- package/dist/bootstrap/expander.mjs.map +1 -1
- package/dist/bootstrap/ir.mjs +22 -24
- package/dist/bootstrap/ir.mjs.map +1 -1
- package/dist/bootstrap/project.mjs +246 -1
- package/dist/bootstrap/project.mjs.map +1 -1
- package/dist/bootstrap/reader.mjs +2 -2
- package/dist/bootstrap/reader.mjs.map +1 -1
- package/dist/bootstrap/source-map.mjs +34 -48
- package/dist/bootstrap/source-map.mjs.map +1 -1
- package/dist/bootstrap/transient-analysis.mjs +2 -2
- package/dist/bootstrap/transient-analysis.mjs.map +1 -1
- package/dist/browser/compiler.js +106 -106
- package/dist/browser/host.mjs +21 -29
- package/dist/browser/loader.js +1 -1
- package/dist/browser/worker.mjs +95 -95
- package/dist/compiler-artifact.json +1 -1
- package/dist/host/compiler-session.mjs +405 -228
- package/dist/host/compiler-session.mjs.map +1 -1
- package/dist/host/compiler-tools.mjs +44 -46
- package/dist/host/compiler-tools.mjs.map +1 -1
- package/dist/literal-sources/runtime/core/array-map.eli +45 -0
- package/dist/literal-sources/runtime/core/collection-internals.eli +22 -2
- package/dist/literal-sources/runtime/core/collection.eli +282 -23
- package/dist/literal-sources/runtime/core/data-text.eli +196 -13
- package/dist/literal-sources/runtime/core/data.eli +1 -1
- package/dist/literal-sources/runtime/core/identifier.eli +1 -1
- package/dist/literal-sources/runtime/core/lazy-sequence.eli +822 -44
- package/dist/literal-sources/runtime/core/list.eli +1 -1
- package/dist/literal-sources/runtime/core/map.eli +1 -1
- package/dist/literal-sources/runtime/core/metadata-internals.eli +2 -2
- package/dist/literal-sources/runtime/core/metadata.eli +2 -2
- package/dist/literal-sources/{stdlib/core/object.eli → runtime/core/object-impl.eli} +6 -6
- package/dist/literal-sources/runtime/core/object.eli +1 -1
- package/dist/literal-sources/runtime/core/order.eli +3 -3
- package/dist/literal-sources/runtime/core/persistent-kind.eli +1 -1
- package/dist/literal-sources/{stdlib/core/protocol.eli → runtime/core/protocol-impl.eli} +2 -2
- package/dist/literal-sources/runtime/core/protocol.eli +5 -3
- package/dist/literal-sources/runtime/core/queue.eli +1 -1
- package/dist/literal-sources/runtime/core/record.eli +3 -3
- package/dist/literal-sources/runtime/core/regex.eli +2 -2
- package/dist/literal-sources/runtime/core/sequence.eli +1 -1
- package/dist/literal-sources/runtime/core/set-algebra.eli +1 -1
- package/dist/literal-sources/runtime/core/set.eli +1 -1
- package/dist/literal-sources/runtime/core/sorted.eli +4 -4
- package/dist/literal-sources/{stdlib/core/text.eli → runtime/core/text-impl.eli} +2 -2
- package/dist/literal-sources/runtime/core/text.eli +1 -1
- package/dist/literal-sources/runtime/core/transducer.eli +24 -2
- package/dist/literal-sources/runtime/core/transient.eli +7 -5
- package/dist/literal-sources/runtime/core/type.eli +1 -1
- package/dist/literal-sources/runtime/core/value-internals.eli +3 -3
- package/dist/literal-sources/runtime/core/value.eli +2 -2
- package/dist/literal-sources/runtime/core/vector.eli +5 -2
- package/dist/literal-sources/{stdlib → runtime/managed}/managed-literal-protocols.eli +100 -34
- package/dist/literal-sources/{stdlib → runtime/managed}/managed-literals.eli +406 -81
- package/{stdlib → dist/literal-sources/runtime/managed}/managed-queue-state.eli +1 -1
- package/{stdlib → dist/literal-sources/runtime/managed}/managed-sorted-state.eli +1 -1
- package/dist/literal-sources/runtime/managed/managed-transient-state.eli +1206 -0
- package/{stdlib → dist/literal-sources/runtime/managed}/managed-value-state.eli +30 -6
- package/dist/literal-sources/{stdlib → runtime/managed}/managed-vector-view-state.eli +1 -1
- package/dist/literal-sources/runtime/wire/http-rpc.eli +1 -1
- package/dist/literal-sources/runtime/wire/markdown.eli +1 -1
- package/dist/literal-sources/runtime/wire/schema.eli +1 -1
- package/dist/literal-sources/stdlib/bit.eli +89 -1
- package/dist/literal-sources/stdlib/data.eli +522 -0
- package/dist/literal-sources/stdlib/interop/object.eli +39 -0
- package/dist/literal-sources/stdlib/persistent-list.eli +60 -21
- package/dist/literal-sources/stdlib/persistent-map.eli +335 -324
- package/dist/literal-sources/stdlib/persistent-set.eli +8 -6
- package/dist/literal-sources/stdlib/persistent-vector.eli +18 -18
- package/dist/literal-sources/stdlib/protocol.eli +63 -0
- package/{stdlib/core → dist/literal-sources/stdlib}/set.eli +8 -8
- package/dist/literal-sources/stdlib/string.eli +362 -0
- package/dist/runtime/lisp/async-runtime.mjs +55 -59
- package/dist/runtime/lisp/async-runtime.mjs.map +1 -1
- package/dist/runtime/lisp/builtins.mjs +232 -280
- package/dist/runtime/lisp/builtins.mjs.map +1 -1
- package/dist/runtime/lisp/cli.mjs +159 -167
- package/dist/runtime/lisp/cli.mjs.map +1 -1
- package/dist/runtime/lisp/compiler.mjs +359 -419
- package/dist/runtime/lisp/compiler.mjs.map +1 -1
- package/dist/runtime/lisp/core.mjs +24 -24
- package/dist/runtime/lisp/core.mjs.map +1 -1
- package/dist/runtime/lisp/evaluator.mjs +315 -385
- package/dist/runtime/lisp/evaluator.mjs.map +1 -1
- package/dist/runtime/lisp/extensions.mjs +85 -103
- package/dist/runtime/lisp/extensions.mjs.map +1 -1
- package/dist/runtime/lisp/host-io.mjs +106 -122
- package/dist/runtime/lisp/host-io.mjs.map +1 -1
- package/dist/runtime/lisp/io-worker.mjs +117 -135
- package/dist/runtime/lisp/io-worker.mjs.map +1 -1
- package/dist/runtime/lisp/keymap.mjs +5 -5
- package/dist/runtime/lisp/keymap.mjs.map +1 -1
- package/dist/runtime/lisp/macros-forms.mjs +49 -51
- package/dist/runtime/lisp/macros-forms.mjs.map +1 -1
- package/dist/runtime/lisp/reader-format.mjs +31 -31
- package/dist/runtime/lisp/reader-format.mjs.map +1 -1
- package/dist/runtime/lisp/regexp-buffer.mjs +9 -9
- package/dist/runtime/lisp/regexp-buffer.mjs.map +1 -1
- package/dist/runtime/math.mjs +32 -38
- package/dist/runtime/math.mjs.map +1 -1
- package/dist/runtime/number-radix.mjs +5 -7
- package/dist/runtime/number-radix.mjs.map +1 -1
- package/dist/runtime/primitives.mjs +81 -46
- package/dist/runtime/primitives.mjs.macro-origins.json +294 -44
- package/dist/runtime/primitives.mjs.map +1 -1
- package/dist/runtime/unicode-case.mjs +6 -6
- package/dist/runtime/unicode-case.mjs.map +1 -1
- package/dist/runtime.eli +3068 -1882
- package/dist/stage3-release.json +1 -1
- package/dist/stdlib/async.mjs +1838 -0
- package/dist/stdlib/bit.mjs +116 -0
- package/dist/stdlib/collection.mjs +193 -0
- package/dist/stdlib/core.mjs +28 -0
- package/dist/stdlib/data-text.mjs +54 -0
- package/dist/stdlib/data.mjs +601 -0
- package/dist/stdlib/devtools.mjs +565 -0
- package/dist/stdlib/diff.mjs +180 -0
- package/dist/stdlib/fn.mjs +164 -0
- package/dist/stdlib/hierarchy.mjs +189 -0
- package/dist/stdlib/identifier.mjs +33 -0
- package/dist/stdlib/interop/js.mjs +706 -0
- package/dist/stdlib/interop/object.mjs +40 -0
- package/dist/stdlib/json.mjs +843 -0
- package/dist/stdlib/lazy-sequence.mjs +117 -0
- package/dist/stdlib/math.mjs +386 -0
- package/dist/stdlib/meta.mjs +21 -0
- package/dist/stdlib/multimethod.mjs +345 -0
- package/dist/stdlib/numeric.mjs +327 -0
- package/dist/stdlib/order.mjs +194 -0
- package/dist/stdlib/persistent-list.mjs +171 -0
- package/dist/stdlib/persistent-map.mjs +781 -0
- package/dist/stdlib/persistent-queue.mjs +44 -0
- package/dist/stdlib/persistent-set.mjs +225 -0
- package/dist/stdlib/persistent-vector.mjs +316 -0
- package/dist/stdlib/portable/data-text.mjs +1094 -0
- package/dist/stdlib/portable/data.mjs +62 -0
- package/dist/stdlib/portable/identifier.mjs +179 -0
- package/dist/stdlib/portable/metadata.mjs +63 -0
- package/dist/stdlib/portable/object.mjs +140 -0
- package/dist/stdlib/portable/sequence.mjs +142 -0
- package/dist/stdlib/portable/text.mjs +111 -0
- package/dist/stdlib/pprint.mjs +807 -0
- package/dist/stdlib/protocol.mjs +61 -0
- package/dist/stdlib/record.mjs +25 -0
- package/dist/stdlib/regex.mjs +115 -0
- package/dist/stdlib/result.mjs +198 -0
- package/dist/stdlib/schema.mjs +2828 -0
- package/dist/stdlib/seq.mjs +913 -0
- package/dist/stdlib/set.mjs +317 -0
- package/dist/stdlib/sorted.mjs +56 -0
- package/dist/stdlib/state.mjs +451 -0
- package/dist/stdlib/string.mjs +494 -0
- package/dist/stdlib/tap.mjs +187 -0
- package/dist/stdlib/test.mjs +669 -0
- package/dist/stdlib/time.mjs +522 -0
- package/dist/stdlib/transducer.mjs +85 -0
- package/dist/stdlib/transient.mjs +32 -0
- package/dist/stdlib/type.mjs +28 -0
- package/dist/stdlib/uuid.mjs +377 -0
- package/dist/stdlib/value.mjs +334 -0
- package/dist/stdlib/walk.mjs +243 -0
- package/dist/stdlib/wire/gepo.mjs +28 -0
- package/dist/stdlib/wire/mdp.mjs +13 -0
- package/dist/stdlib/wire/mds.mjs +10 -0
- package/dist/stdlib/zipper.mjs +1025 -0
- package/editor/README.md +15 -0
- package/editor/eliscript-data.el +221 -8
- package/editor/eliscript-mode.el +207 -48
- package/editor/eliscript-runtime.el +6 -3
- package/package.json +49 -15
- package/platform/README.md +6 -0
- package/platform/browser.mjs +10 -12
- package/platform/browser.mjs.map +1 -1
- package/runtime/README.md +12 -5
- package/runtime/core/array-map.eli +538 -0
- package/runtime/core/array-map.mjs +651 -0
- package/runtime/core/array-map.mjs.map +1 -0
- package/runtime/core/collection-internals.eli +85 -33
- package/runtime/core/collection-internals.mjs +245 -193
- package/runtime/core/collection-internals.mjs.map +1 -1
- package/runtime/core/collection.eli +105 -3
- package/runtime/core/collection.mjs +190 -53
- package/runtime/core/collection.mjs.map +1 -1
- package/runtime/core/data-text.eli +224 -16
- package/runtime/core/data-text.mjs +345 -83
- package/runtime/core/data-text.mjs.map +1 -1
- package/runtime/core/data.eli +50 -33
- package/runtime/core/data.mjs +72 -36
- package/runtime/core/data.mjs.map +1 -1
- package/runtime/core/identifier.mjs +15 -19
- package/runtime/core/identifier.mjs.map +1 -1
- package/runtime/core/lazy-sequence.eli +885 -15
- package/runtime/core/lazy-sequence.mjs +1265 -38
- package/runtime/core/lazy-sequence.mjs.map +1 -1
- package/runtime/core/map-internals.eli +209 -1
- package/runtime/core/map-internals.mjs +359 -71
- package/runtime/core/map-internals.mjs.map +1 -1
- package/runtime/core/map.eli +75 -7
- package/runtime/core/map.mjs +122 -47
- package/runtime/core/map.mjs.map +1 -1
- package/{stdlib/core/object.eli → runtime/core/object-impl.eli} +6 -6
- package/runtime/core/object-impl.mjs +5 -5
- package/runtime/core/object-impl.mjs.map +1 -1
- package/runtime/core/order.eli +15 -3
- package/runtime/core/order.mjs +23 -8
- package/runtime/core/order.mjs.map +1 -1
- package/runtime/core/persistent-kind.mjs +9 -13
- package/runtime/core/persistent-kind.mjs.map +1 -1
- package/runtime/core/protocol-error.mjs +9 -11
- package/runtime/core/protocol-error.mjs.map +1 -1
- package/{stdlib/core/protocol.eli → runtime/core/protocol-impl.eli} +2 -2
- package/runtime/core/protocol-impl.mjs +10 -10
- package/runtime/core/protocol-impl.mjs.map +1 -1
- package/runtime/core/queue.mjs +14 -16
- package/runtime/core/queue.mjs.map +1 -1
- package/runtime/core/record.eli +2 -2
- package/runtime/core/record.mjs +13 -17
- package/runtime/core/record.mjs.map +1 -1
- package/runtime/core/regex.mjs +18 -22
- package/runtime/core/regex.mjs.map +1 -1
- package/runtime/core/sequence.eli +33 -31
- package/runtime/core/sequence.mjs +60 -93
- package/runtime/core/sequence.mjs.map +1 -1
- package/runtime/core/set.eli +53 -27
- package/runtime/core/set.mjs +113 -82
- package/runtime/core/set.mjs.map +1 -1
- package/runtime/core/sorted.mjs +91 -108
- package/runtime/core/sorted.mjs.map +1 -1
- package/{stdlib/core/text.eli → runtime/core/text-impl.eli} +2 -2
- package/runtime/core/text-impl.mjs +1 -1
- package/runtime/core/text-impl.mjs.map +1 -1
- package/runtime/core/transducer.eli +24 -0
- package/runtime/core/transducer.mjs +27 -1
- package/runtime/core/transducer.mjs.map +1 -1
- package/runtime/core/transient-internals.eli +12 -4
- package/runtime/core/transient-internals.mjs +19 -6
- package/runtime/core/transient-internals.mjs.map +1 -1
- package/runtime/core/transient.eli +31 -0
- package/runtime/core/transient.mjs +33 -2
- package/runtime/core/transient.mjs.map +1 -1
- package/runtime/core/value-internals.mjs +29 -35
- package/runtime/core/value-internals.mjs.map +1 -1
- package/runtime/core/vector.eli +73 -20
- package/runtime/core/vector.mjs +159 -156
- package/runtime/core/vector.mjs.map +1 -1
- package/runtime/literals.eli +16 -9
- package/runtime/literals.mjs +25 -9
- package/runtime/literals.mjs.map +1 -1
- package/{stdlib → runtime/managed}/managed-literal-protocols.eli +100 -34
- package/{stdlib → runtime/managed}/managed-literals.eli +406 -81
- package/{dist/literal-sources/stdlib → runtime/managed}/managed-queue-state.eli +1 -1
- package/runtime/managed/managed-runtime-array-map.eli +45 -0
- package/{stdlib → runtime/managed}/managed-runtime-collection-internals.eli +22 -2
- package/{stdlib → runtime/managed}/managed-runtime-collection.eli +282 -23
- package/{stdlib → runtime/managed}/managed-runtime-data-text.eli +196 -13
- package/{stdlib → runtime/managed}/managed-runtime-data.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-identifier.eli +1 -1
- package/runtime/managed/managed-runtime-lazy-sequence.eli +935 -0
- package/{stdlib → runtime/managed}/managed-runtime-list.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-map.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-metadata-internals.eli +2 -2
- package/{stdlib → runtime/managed}/managed-runtime-metadata.eli +2 -2
- package/{stdlib → runtime/managed}/managed-runtime-object.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-order.eli +3 -3
- package/{stdlib → runtime/managed}/managed-runtime-persistent-kind.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-protocol.eli +5 -3
- package/{stdlib → runtime/managed}/managed-runtime-queue.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-record.eli +3 -3
- package/{stdlib → runtime/managed}/managed-runtime-regex.eli +2 -2
- package/{stdlib → runtime/managed}/managed-runtime-sequence.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-set-algebra.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-set.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-sorted.eli +4 -4
- package/{stdlib → runtime/managed}/managed-runtime-text.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-transducer.eli +24 -2
- package/{stdlib → runtime/managed}/managed-runtime-transient.eli +7 -5
- package/{stdlib → runtime/managed}/managed-runtime-type.eli +1 -1
- package/{stdlib → runtime/managed}/managed-runtime-value-internals.eli +3 -3
- package/{stdlib → runtime/managed}/managed-runtime-value.eli +2 -2
- package/{stdlib → runtime/managed}/managed-runtime-vector.eli +5 -2
- package/{dist/literal-sources/stdlib → runtime/managed}/managed-sorted-state.eli +1 -1
- package/runtime/managed/managed-transient-state.eli +1206 -0
- package/{dist/literal-sources/stdlib → runtime/managed}/managed-value-state.eli +30 -6
- package/{stdlib → runtime/managed}/managed-vector-view-state.eli +1 -1
- package/{stdlib → runtime/managed}/managed-wire-http-rpc.eli +1 -1
- package/{stdlib → runtime/managed}/managed-wire-markdown.eli +1 -1
- package/{stdlib → runtime/managed}/managed-wire-schema.eli +1 -1
- package/runtime/math.mjs +32 -38
- package/runtime/math.mjs.map +1 -1
- package/runtime/number-radix.mjs +5 -7
- package/runtime/number-radix.mjs.map +1 -1
- package/runtime/primitives.eli +19 -6
- package/runtime/primitives.mjs +81 -46
- package/runtime/primitives.mjs.map +1 -1
- package/runtime/source-mapping.mjs +17 -23
- package/runtime/source-mapping.mjs.map +1 -1
- package/runtime/testing/map.eli +70 -41
- package/runtime/testing/map.mjs +57 -34
- package/runtime/testing/map.mjs.map +1 -1
- package/runtime/unicode-case.mjs +6 -6
- package/runtime/unicode-case.mjs.map +1 -1
- package/runtime/wire/http-rpc.mjs +12 -18
- package/runtime/wire/http-rpc.mjs.map +1 -1
- package/runtime/wire/markdown.mjs +42 -42
- package/runtime/wire/markdown.mjs.map +1 -1
- package/runtime/wire/schema.mjs +13 -13
- package/runtime/wire/schema.mjs.map +1 -1
- package/runtime/worker-value-codec.mjs +5 -7
- package/runtime/worker-value-codec.mjs.map +1 -1
- package/runtime/worker-value-stream.mjs +128 -135
- package/runtime/worker-value-stream.mjs.map +1 -1
- package/runtime/worker.mjs +75 -89
- package/runtime/worker.mjs.map +1 -1
- package/stdlib/README.md +25 -18
- package/stdlib/async.eli +1245 -0
- package/stdlib/bit.eli +89 -1
- package/stdlib/bit.mjs +89 -2
- package/stdlib/bit.mjs.map +1 -1
- package/stdlib/{core/collection.eli → collection.eli} +39 -4
- package/stdlib/core.eli +956 -0
- package/stdlib/data-text.eli +62 -1091
- package/stdlib/data.eli +517 -37
- package/stdlib/devtools.eli +399 -0
- package/stdlib/diff.eli +134 -0
- package/stdlib/{function.eli → fn.eli} +1 -1
- package/stdlib/identifier.eli +21 -136
- package/stdlib/interop/object.eli +39 -0
- package/stdlib/{core/lazy-sequence.eli → lazy-sequence.eli} +28 -2
- package/stdlib/math.eli +267 -0
- package/stdlib/{core/metadata.eli → meta.eli} +2 -2
- package/stdlib/{core/order.eli → order.eli} +6 -6
- package/stdlib/persistent-list.eli +60 -21
- package/stdlib/persistent-map.eli +335 -324
- package/stdlib/persistent-set.eli +8 -6
- package/stdlib/persistent-vector.eli +18 -18
- package/stdlib/portable/data-text.eli +1092 -0
- package/stdlib/portable/data.eli +42 -0
- package/stdlib/portable/identifier.eli +147 -0
- package/stdlib/{metadata.eli → portable/metadata.eli} +5 -5
- package/stdlib/{object.eli → portable/object.eli} +1 -1
- package/stdlib/{sequence.eli → portable/sequence.eli} +1 -1
- package/stdlib/{text.eli → portable/text.eli} +1 -1
- package/stdlib/pprint.eli +588 -0
- package/stdlib/protocol.eli +63 -0
- package/stdlib/{core/record.eli → record.eli} +2 -2
- package/stdlib/regex.eli +70 -0
- package/stdlib/result.eli +53 -44
- package/stdlib/schema.eli +1886 -0
- package/stdlib/{core/seq.eli → seq.eli} +97 -90
- package/{dist/literal-sources/stdlib/core → stdlib}/set.eli +8 -8
- package/stdlib/{core/sorted.eli → sorted.eli} +2 -2
- package/stdlib/{state/atom.eli → state.eli} +137 -7
- package/stdlib/string.eli +362 -0
- package/stdlib/tap.eli +135 -0
- package/stdlib/test.eli +566 -0
- package/stdlib/time.eli +419 -0
- package/stdlib/{core/transducer.eli → transducer.eli} +4 -2
- package/stdlib/{core/transient.eli → transient.eli} +11 -5
- package/stdlib/{core/type.eli → type.eli} +2 -2
- package/stdlib/uuid.eli +288 -0
- package/stdlib/{core/walk.eli → walk.eli} +6 -6
- package/stdlib/{gepo.eli → wire/gepo.eli} +2 -2
- package/stdlib/{mdp.eli → wire/mdp.eli} +2 -2
- package/stdlib/{mds.eli → wire/mds.eli} +2 -2
- package/stdlib/{core/zipper.eli → zipper.eli} +179 -138
- package/tests/helpers/wasm-managed-math-node.mjs +495 -582
- package/tools/acceptance/check-ground.mjs +106 -132
- package/tools/acceptance/check.mjs +16 -16
- package/tools/acceptance/retained-performance-snapshot.mjs +265 -149
- package/tools/acceptance/retained-soak.mjs +5 -7
- package/tools/acceptance/retained-transient.mjs +5 -7
- package/tools/backends/build.mjs +373 -95
- package/tools/backends/compiler-bootstrap.mjs +271 -317
- package/tools/backends/compiler-browser.mjs +7 -9
- package/tools/backends/compiler-build.mjs +77 -97
- package/tools/backends/compiler-cli-ground.mjs +47 -47
- package/tools/backends/compiler-data-transport.mjs +27 -31
- package/tools/backends/compiler-host-iteration.mjs +13 -21
- package/tools/backends/compiler-host-record.mjs +28 -34
- package/tools/backends/compiler-metadata.mjs +145 -53
- package/tools/backends/compiler-package-ground.mjs +39 -47
- package/tools/backends/compiler-package-loader.mjs +164 -206
- package/tools/backends/compiler-session.mjs +432 -324
- package/tools/backends/compiler-worker.mjs +79 -89
- package/tools/backends/dist/bootstrap-js-stages.mjs +17 -19
- package/tools/backends/dist/bootstrap-js-stages.mjs.map +1 -1
- package/tools/backends/dist/managed-ir-inventory.mjs +1 -1
- package/tools/backends/dist/managed-ir-inventory.mjs.map +1 -1
- package/tools/backends/dist/release-cli.mjs +151 -22
- package/tools/backends/dist/release-cli.mjs.map +1 -1
- package/tools/backends/dist/run-artifact.mjs +54 -76
- package/tools/backends/dist/run-artifact.mjs.map +1 -1
- package/tools/backends/managed-foreign-binding.mjs +370 -114
- package/tools/backends/managed-host-ground.mjs +14 -17
- package/tools/backends/managed-host-lifecycle.mjs +42 -53
- package/tools/backends/managed-host-object-realm.mjs +121 -111
- package/tools/backends/managed-host-proxy.mjs +5 -7
- package/tools/backends/managed-host-runtime.mjs +6295 -4350
- package/tools/backends/managed-host.mjs +234 -188
- package/tools/backends/managed-layout.mjs +53 -56
- package/tools/backends/managed-module-graph-ground.mjs +488 -568
- package/tools/backends/managed-module-graph.mjs +62 -76
- package/tools/backends/managed-runtime-host-ground.mjs +352 -400
- package/tools/backends/managed-runtime.mjs +227 -266
- package/tools/backends/managed-source-view-ground.mjs +165 -161
- package/tools/backends/managed-source-view.mjs +415 -154
- package/tools/backends/native-managed-runtime.mjs +96 -138
- package/tools/backends/native-memory.mjs +1122 -742
- package/tools/backends/native-node-ffi.mjs +2439 -0
- package/tools/backends/native-node-memory.mjs +793 -383
- package/tools/backends/native-node-runner.mjs +1458 -579
- package/tools/backends/native-node-watchdog.mjs +12 -14
- package/tools/backends/native-node-worker.mjs +46 -50
- package/tools/backends/stage3-targets.mjs +2 -2
- package/tools/bootstrap-runtime.el +4 -4
- package/tools/collections/transient-builder-benchmark.mjs +17 -17
- package/tools/project/check-cli.eli +27 -3
- package/tools/project/project-cli.eli +1 -1
- package/tools/testing/maintained-suite-source.mjs +5 -7
- package/tools/testing/maintained-suite-source.mjs.map +1 -1
- package/dist/literal-sources/stdlib/core/data.eli +0 -306
- package/dist/literal-sources/stdlib/managed-transient-state.eli +0 -353
- package/stdlib/core/data-text.eli +0 -16
- package/stdlib/core/data.eli +0 -306
- package/stdlib/core/identifier.eli +0 -32
- package/stdlib/core/regex.eli +0 -17
- package/stdlib/deferred.eli +0 -70
- package/stdlib/managed-runtime-lazy-sequence.eli +0 -157
- package/stdlib/managed-transient-state.eli +0 -353
- /package/{stdlib → runtime/managed}/managed-protocol-error.eli +0 -0
- /package/{stdlib → runtime/managed}/managed-runtime-literals.eli +0 -0
- /package/{stdlib → runtime/managed}/managed-runtime-truth.eli +0 -0
- /package/{stdlib → runtime/managed}/managed-testing-value.eli +0 -0
package/dist/backends/native.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// Generated by Eliscript. Do not edit.
|
|
2
|
+
import { tdz as __eliscript_tdz_error, immutable as __eliscript_const_error } from "eliscript/runtime/errors.mjs";
|
|
3
|
+
var __eliscript_tdz_ready_0;
|
|
4
|
+
var __eliscript_tdz_ready_1;
|
|
5
|
+
var __eliscript_tdz_ready_2;
|
|
2
6
|
import "eliscript/runtime/unicode-case.mjs";
|
|
3
7
|
import "eliscript/runtime/math.mjs";
|
|
4
8
|
import { __eliscript_at, __eliscript_at_direct, __eliscript_to_number, __eliscript_numeric_decrement, __eliscript_numeric_relation, __eliscript_numeric_sub, __eliscript_numeric_mul, __eliscript_numeric_div, __eliscript_numeric_rem, __eliscript_numeric_and, __eliscript_numeric_or, __eliscript_numeric_xor, __eliscript_numeric_shl, __eliscript_numeric_shr, __eliscript_numeric_ushr, __eliscript_numeric_neg, __eliscript_numeric_int32, __eliscript_numeric_uint32, __eliscript_numeric_not } from "eliscript/runtime/prelude.mjs";
|
|
@@ -7,14 +11,14 @@ import { valueType as __eliscript_value_type } from "eliscript/runtime/primitive
|
|
|
7
11
|
const __eliscript_truthy = (value) => value !== false && value != null;
|
|
8
12
|
|
|
9
13
|
import {optimize_program} from "./optimize.mjs";
|
|
10
|
-
import {lower_numeric_program, optimize_numeric_program, numeric_pure, backend_fail, find_function} from "./numeric.mjs";
|
|
11
|
-
import {sha256_bytes, sha256_words_le} from "./sha256.mjs";
|
|
14
|
+
import {lower_numeric_program, optimize_numeric_program, numeric_pure, backend_fail, find_function, runtime_body_cache_get} from "./numeric.mjs";
|
|
15
|
+
import {sha256_bytes, sha256_words_le, sha256_string_utf16le} from "./sha256.mjs";
|
|
12
16
|
import {lower_memory_program} from "./memory.mjs";
|
|
13
17
|
import {emit_elf_object, emit_elf_library} from "./elf.mjs";
|
|
14
18
|
import {prepare_host_capabilities, prepare_fresh_host_capabilities, host_capability_index} from "./capabilities.mjs";
|
|
15
|
-
import {binary_output, binary_byte, binary_u32, binary_append, binary_append_owned, binary_slice, binary_finish} from "./binary.mjs";
|
|
19
|
+
import {binary_output, binary_byte, binary_u32, binary_append, binary_append_owned, binary_slice, binary_to_array, binary_finish} from "./binary.mjs";
|
|
16
20
|
function native_word_buffer() {
|
|
17
|
-
return ({"length": 0, "chunks": [], "cache": [], "units": [], "cacheIndex": -1, "dirty": false});
|
|
21
|
+
return ({"length": 0, "chunks": [], "cache": [], "units": [], "cacheIndex": -1, "dirty": false, "hasHole": false});
|
|
18
22
|
}
|
|
19
23
|
function native_word_flush(words) {
|
|
20
24
|
if (__eliscript_truthy((words)["dirty"])) {
|
|
@@ -111,6 +115,9 @@ function native_word_resize(words, length) {
|
|
|
111
115
|
if ((!(__eliscript_truthy(Number.isSafeInteger(length)) && __eliscript_numeric_relation(">=", length, 0)))) {
|
|
112
116
|
backend_fail(null, "native word buffer length is invalid");
|
|
113
117
|
}
|
|
118
|
+
if (__eliscript_numeric_relation(">", length, ((words) ?? []).length)) {
|
|
119
|
+
((words)["hasHole"] = true);
|
|
120
|
+
}
|
|
114
121
|
if (__eliscript_numeric_relation("<", length, ((words) ?? []).length)) {
|
|
115
122
|
{
|
|
116
123
|
let block = (globalThis.Math)["floor"](__eliscript_numeric_div(length, 1024));
|
|
@@ -147,12 +154,47 @@ function native_word_push(words, value) {
|
|
|
147
154
|
} else {
|
|
148
155
|
{
|
|
149
156
|
let index = ((words) ?? []).length;
|
|
150
|
-
|
|
157
|
+
((words)["length"] = (index + 1));
|
|
151
158
|
native_word_set(words, index, value);
|
|
152
159
|
return ((words) ?? []).length;
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
}
|
|
163
|
+
function native_word_append_u32(words, u32arr) {
|
|
164
|
+
{
|
|
165
|
+
let len = ((u32arr) ?? []).length;
|
|
166
|
+
let src = 0;
|
|
167
|
+
if (__eliscript_truthy(Array.isArray(words))) {
|
|
168
|
+
while (__eliscript_numeric_relation("<", src, len)) {
|
|
169
|
+
(words)["push"](__eliscript_numeric_uint32((u32arr)[src]));
|
|
170
|
+
((src = (src + 1)));
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
{
|
|
174
|
+
let pos = ((words) ?? []).length;
|
|
175
|
+
while (__eliscript_numeric_relation("<", src, len)) {
|
|
176
|
+
{
|
|
177
|
+
let block = (globalThis.Math)["floor"](__eliscript_numeric_div(pos, 1024));
|
|
178
|
+
let offset = __eliscript_numeric_rem(pos, 1024);
|
|
179
|
+
let room = __eliscript_numeric_sub(1024, offset);
|
|
180
|
+
let take = (__eliscript_numeric_relation("<", __eliscript_numeric_sub(len, src), room) ? __eliscript_numeric_sub(len, src) : room);
|
|
181
|
+
let cache = native_word_cache(words, block);
|
|
182
|
+
let end = (offset + take);
|
|
183
|
+
let dst = offset;
|
|
184
|
+
while (__eliscript_numeric_relation("<", dst, end)) {
|
|
185
|
+
((cache)[dst] = (u32arr)[src]);
|
|
186
|
+
((dst = (dst + 1)), (src = (src + 1)));
|
|
187
|
+
}
|
|
188
|
+
((words)["dirty"] = true);
|
|
189
|
+
((pos = (pos + take)));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
((words)["length"] = pos);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return ((words) ?? []).length;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
156
198
|
function word(state, value) {
|
|
157
199
|
return native_word_push((state)["words"], value);
|
|
158
200
|
}
|
|
@@ -241,13 +283,13 @@ function string_bytes(bytes, name) {
|
|
|
241
283
|
}
|
|
242
284
|
function integer_register(state, register, low, high) {
|
|
243
285
|
word(state, (3531603968 + __eliscript_numeric_mul(__eliscript_numeric_and(low, 65535), 32) + register));
|
|
244
|
-
if ((!(__eliscript_truthy(((state)["compact"] ?? null))) || (
|
|
286
|
+
if ((!(__eliscript_truthy(((state)["compact"] ?? null))) || (__eliscript_numeric_ushr(low, 16) !== 0))) {
|
|
245
287
|
word(state, (4070572032 + __eliscript_numeric_mul(__eliscript_numeric_ushr(low, 16), 32) + register));
|
|
246
288
|
}
|
|
247
|
-
if ((!(__eliscript_truthy(((state)["compact"] ?? null))) || (
|
|
289
|
+
if ((!(__eliscript_truthy(((state)["compact"] ?? null))) || (__eliscript_numeric_and(high, 65535) !== 0))) {
|
|
248
290
|
word(state, (4072669184 + __eliscript_numeric_mul(__eliscript_numeric_and(high, 65535), 32) + register));
|
|
249
291
|
}
|
|
250
|
-
if ((!(__eliscript_truthy(((state)["compact"] ?? null))) || (
|
|
292
|
+
if ((!(__eliscript_truthy(((state)["compact"] ?? null))) || (__eliscript_numeric_ushr(high, 16) !== 0))) {
|
|
251
293
|
return word(state, (4074766336 + __eliscript_numeric_mul(__eliscript_numeric_ushr(high, 16), 32) + register));
|
|
252
294
|
} else {
|
|
253
295
|
return null;
|
|
@@ -257,11 +299,11 @@ function memory_integer_register(state, register, value) {
|
|
|
257
299
|
{
|
|
258
300
|
let low = __eliscript_numeric_and(value, 65535);
|
|
259
301
|
let high = __eliscript_numeric_ushr(value, 16);
|
|
260
|
-
if (((low === 0) && (
|
|
302
|
+
if (((low === 0) && (high !== 0))) {
|
|
261
303
|
return word(state, (1386217472 + __eliscript_numeric_mul(high, 32) + register));
|
|
262
304
|
} else {
|
|
263
305
|
word(state, (1384120320 + __eliscript_numeric_mul(low, 32) + register));
|
|
264
|
-
if ((
|
|
306
|
+
if ((high !== 0)) {
|
|
265
307
|
return word(state, (1923088384 + __eliscript_numeric_mul(high, 32) + register));
|
|
266
308
|
} else {
|
|
267
309
|
return null;
|
|
@@ -276,19 +318,19 @@ function memory_wide_register(state, register, low, high) {
|
|
|
276
318
|
let h2 = __eliscript_numeric_and(high, 65535);
|
|
277
319
|
let h3 = __eliscript_numeric_ushr(high, 16);
|
|
278
320
|
let started = null;
|
|
279
|
-
if ((
|
|
321
|
+
if ((h0 !== 0)) {
|
|
280
322
|
word(state, (3531603968 + __eliscript_numeric_mul(h0, 32) + register));
|
|
281
323
|
((started = true));
|
|
282
324
|
}
|
|
283
|
-
if ((
|
|
325
|
+
if ((h1 !== 0)) {
|
|
284
326
|
word(state, ((__eliscript_truthy(started) ? 4070572032 : 3533701120) + __eliscript_numeric_mul(h1, 32) + register));
|
|
285
327
|
((started = true));
|
|
286
328
|
}
|
|
287
|
-
if ((
|
|
329
|
+
if ((h2 !== 0)) {
|
|
288
330
|
word(state, ((__eliscript_truthy(started) ? 4072669184 : 3535798272) + __eliscript_numeric_mul(h2, 32) + register));
|
|
289
331
|
((started = true));
|
|
290
332
|
}
|
|
291
|
-
if ((
|
|
333
|
+
if ((h3 !== 0)) {
|
|
292
334
|
word(state, ((__eliscript_truthy(started) ? 4074766336 : 3537895424) + __eliscript_numeric_mul(h3, 32) + register));
|
|
293
335
|
((started = true));
|
|
294
336
|
}
|
|
@@ -369,7 +411,7 @@ function collect_loop_literals(node, depth, entries) {
|
|
|
369
411
|
let kind = (node)["kind"];
|
|
370
412
|
let children = (node)["children"];
|
|
371
413
|
let i = 0;
|
|
372
|
-
if ((__eliscript_numeric_relation(">", depth, 0) && (kind === "literal") && ((node)["type"] === "f64") && ((
|
|
414
|
+
if ((__eliscript_numeric_relation(">", depth, 0) && (kind === "literal") && ((node)["type"] === "f64") && ((node)["value"] !== 0))) {
|
|
373
415
|
{
|
|
374
416
|
let bits = __eliscript_number_float64_words((node)["value"]);
|
|
375
417
|
let found = null;
|
|
@@ -434,7 +476,7 @@ function finish_literals(state) {
|
|
|
434
476
|
let constants = (state)["constants"];
|
|
435
477
|
let words = (state)["words"];
|
|
436
478
|
let i = 0;
|
|
437
|
-
if ((__eliscript_numeric_relation(">", ((constants) ?? []).length, 0) && (
|
|
479
|
+
if ((__eliscript_numeric_relation(">", ((constants) ?? []).length, 0) && (__eliscript_numeric_and(((words) ?? []).length, 1) !== 0))) {
|
|
438
480
|
word(state, 3573751839);
|
|
439
481
|
}
|
|
440
482
|
while (__eliscript_numeric_relation("<", i, ((constants) ?? []).length)) {
|
|
@@ -507,14 +549,15 @@ function local_access(state, index, type, store, operand = null) {
|
|
|
507
549
|
if (__eliscript_numeric_relation("<=", register, -2)) {
|
|
508
550
|
{
|
|
509
551
|
let physical = __eliscript_numeric_sub(__eliscript_numeric_neg(register), 2);
|
|
510
|
-
return word(state, ((__eliscript_truthy(wide) ? 2852127712 : 704644064) + (__eliscript_truthy(store) ? physical : __eliscript_numeric_mul(physical, 65536)))
|
|
552
|
+
return word(state, ((__eliscript_truthy(wide) ? 2852127712 : 704644064) + (__eliscript_truthy(store) ? physical : data) + __eliscript_numeric_mul((__eliscript_truthy(store) ? data : physical), 65536)));
|
|
511
553
|
}
|
|
512
554
|
} else {
|
|
513
555
|
if (__eliscript_numeric_relation(">=", register, 0)) {
|
|
514
556
|
return word(state, ((type === "f64") ? (509624320 + (__eliscript_truthy(store) ? register : __eliscript_numeric_mul(register, 32))) : (__eliscript_truthy(wide) ? (__eliscript_truthy(store) ? (2657550336 + register) : (2657484800 + __eliscript_numeric_mul(register, 32))) : (__eliscript_truthy(store) ? (505872384 + register) : (505806848 + __eliscript_numeric_mul(register, 32))))));
|
|
515
557
|
} else {
|
|
516
558
|
{
|
|
517
|
-
let
|
|
559
|
+
let local_offsets = ((state)["localOffsets"] ?? null);
|
|
560
|
+
let offset = ((__eliscript_truthy(((state)["memory"] ?? null)) && __eliscript_truthy(local_offsets) && __eliscript_numeric_relation("<", index, ((local_offsets) ?? []).length) && __eliscript_numeric_relation(">", ((((local_offsets) ?? [])[index]) ?? null), 0)) ? ((((local_offsets) ?? [])[index]) ?? null) : __eliscript_numeric_mul((index + 1), 8));
|
|
518
561
|
if ((__eliscript_truthy(((state)["memory"] ?? null)) && __eliscript_numeric_relation("<=", offset, 256))) {
|
|
519
562
|
return word(state, (((type === "f64") ? (__eliscript_truthy(store) ? 4227858432 : 4232052736) : (__eliscript_truthy(wide) ? (__eliscript_truthy(store) ? 4160749568 : 4164943872) : (__eliscript_truthy(store) ? 3087007744 : 3091202048))) + __eliscript_numeric_mul(__eliscript_numeric_and(__eliscript_numeric_neg(offset), 511), 4096) + 928 + data));
|
|
520
563
|
} else {
|
|
@@ -552,6 +595,26 @@ function register_weights(node, counts) {
|
|
|
552
595
|
return call;
|
|
553
596
|
}
|
|
554
597
|
}
|
|
598
|
+
function memory_register_weights(node, counts, weight) {
|
|
599
|
+
{
|
|
600
|
+
let kind = (node)["kind"];
|
|
601
|
+
let children = (node)["children"];
|
|
602
|
+
let i = 0;
|
|
603
|
+
let loop = ((kind === "while") || (kind === "remainder-while") || (kind === "guarded-while"));
|
|
604
|
+
let child_weight = (__eliscript_truthy(loop) ? Math.min(1024, __eliscript_numeric_mul(weight, 8)) : weight);
|
|
605
|
+
if (((kind === "local") || (kind === "set") || (kind === "initialize"))) {
|
|
606
|
+
{
|
|
607
|
+
let index = (node)["value"];
|
|
608
|
+
(counts)["splice"](index, 1, (((((counts) ?? [])[index]) ?? null) + weight));
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
|
|
612
|
+
memory_register_weights(((((children) ?? [])[i]) ?? null), counts, child_weight);
|
|
613
|
+
((i = (i + 1)));
|
|
614
|
+
}
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
555
618
|
function live_union(left, right) {
|
|
556
619
|
{
|
|
557
620
|
let result = (left)["slice"]();
|
|
@@ -601,7 +664,7 @@ function live_before(node, after, graph) {
|
|
|
601
664
|
}
|
|
602
665
|
} else {
|
|
603
666
|
if (((kind === "set") || (kind === "initialize"))) {
|
|
604
|
-
((node)["storeLive"] = ((
|
|
667
|
+
((node)["storeLive"] = ((__eliscript_value_1) => (__eliscript_truthy(__eliscript_value_1) ? __eliscript_value_1 : (live)["includes"](value)))(((node)["storeLive"] ?? null)));
|
|
605
668
|
interference(graph, value, live);
|
|
606
669
|
{
|
|
607
670
|
let at = (live)["indexOf"](value);
|
|
@@ -621,7 +684,7 @@ function live_before(node, after, graph) {
|
|
|
621
684
|
{
|
|
622
685
|
let next = live_before(((((children) ?? [])[0]) ?? null), live_union(after, live_before(((((children) ?? [])[1]) ?? null), live, graph)), graph);
|
|
623
686
|
let joined = live_union(live, next);
|
|
624
|
-
((changed = ((
|
|
687
|
+
((changed = (((joined) ?? []).length !== ((live) ?? []).length)));
|
|
625
688
|
((live = joined));
|
|
626
689
|
}
|
|
627
690
|
}
|
|
@@ -663,7 +726,7 @@ function allocate_registers(body, locals, arity) {
|
|
|
663
726
|
{
|
|
664
727
|
let j = 0;
|
|
665
728
|
while (__eliscript_numeric_relation("<", j, arity)) {
|
|
666
|
-
if (((
|
|
729
|
+
if (((i !== j) && __eliscript_numeric_relation(">", ((((counts) ?? [])[i]) ?? null), 0) && __eliscript_numeric_relation(">", ((((counts) ?? [])[j]) ?? null), 0))) {
|
|
667
730
|
interference(graph, i, [j]);
|
|
668
731
|
}
|
|
669
732
|
((j = (j + 1)));
|
|
@@ -690,6 +753,333 @@ function allocate_registers(body, locals, arity) {
|
|
|
690
753
|
return ({"registers": registers, "leaf": true});
|
|
691
754
|
}
|
|
692
755
|
}
|
|
756
|
+
function memory_bitset_copy(bits) {
|
|
757
|
+
return (bits)["slice"]();
|
|
758
|
+
}
|
|
759
|
+
function memory_bitset_union(left, right, words) {
|
|
760
|
+
{
|
|
761
|
+
let out = (left)["slice"]();
|
|
762
|
+
let w = 0;
|
|
763
|
+
while (__eliscript_numeric_relation("<", w, words)) {
|
|
764
|
+
((out)[w] = __eliscript_numeric_or((left)[w], (right)[w]));
|
|
765
|
+
((w = (w + 1)));
|
|
766
|
+
}
|
|
767
|
+
return out;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
function memory_bitset_disjoint_p(left, right, words) {
|
|
771
|
+
{
|
|
772
|
+
let w = 0;
|
|
773
|
+
let disjoint = true;
|
|
774
|
+
while ((__eliscript_truthy(disjoint) && __eliscript_numeric_relation("<", w, words))) {
|
|
775
|
+
if ((__eliscript_numeric_and((left)[w], (right)[w]) !== 0)) {
|
|
776
|
+
((disjoint = null));
|
|
777
|
+
}
|
|
778
|
+
((w = (w + 1)));
|
|
779
|
+
}
|
|
780
|
+
return disjoint;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function memory_bitset_interfere(graph, index, live, words) {
|
|
784
|
+
{
|
|
785
|
+
let idx_word = __eliscript_numeric_ushr(index, 5);
|
|
786
|
+
let idx_bit = __eliscript_numeric_shl(1, __eliscript_numeric_and(index, 31));
|
|
787
|
+
let row = ((((graph) ?? [])[index]) ?? null);
|
|
788
|
+
let w = 0;
|
|
789
|
+
while (__eliscript_numeric_relation("<", w, words)) {
|
|
790
|
+
{
|
|
791
|
+
let lw = (live)[w];
|
|
792
|
+
let masked = ((w === idx_word) ? __eliscript_numeric_and(lw, __eliscript_numeric_not(idx_bit)) : lw);
|
|
793
|
+
if ((masked !== 0)) {
|
|
794
|
+
((row)[w] = __eliscript_numeric_or((row)[w], masked));
|
|
795
|
+
{
|
|
796
|
+
let rem = __eliscript_numeric_or(masked, 0);
|
|
797
|
+
let base_idx = __eliscript_numeric_mul(w, 32);
|
|
798
|
+
while ((rem !== 0)) {
|
|
799
|
+
{
|
|
800
|
+
let lsb = __eliscript_numeric_and(rem, __eliscript_numeric_neg(rem));
|
|
801
|
+
let bit = __eliscript_numeric_sub(31, Math.clz32(lsb));
|
|
802
|
+
let other = (base_idx + bit);
|
|
803
|
+
let orow = ((((graph) ?? [])[other]) ?? null);
|
|
804
|
+
((orow)[idx_word] = __eliscript_numeric_or((orow)[idx_word], idx_bit));
|
|
805
|
+
((rem = __eliscript_numeric_xor(rem, lsb)));
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
((w = (w + 1)));
|
|
812
|
+
}
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
function memory_addr_base_local(node) {
|
|
817
|
+
{
|
|
818
|
+
let kind = (node)["kind"];
|
|
819
|
+
let val = (node)["value"];
|
|
820
|
+
let children = (node)["children"];
|
|
821
|
+
if (((kind === "local") && __eliscript_truthy(memory_word_type((node)["type"])))) {
|
|
822
|
+
return val;
|
|
823
|
+
} else {
|
|
824
|
+
if (((kind === "word-arithmetic") && (val === "1+") && (((children) ?? []).length === 1) && __eliscript_truthy(memory_word_type((node)["type"])) && ((((((children) ?? [])[0]) ?? null))["kind"] === "local") && __eliscript_truthy(memory_word_type((((((children) ?? [])[0]) ?? null))["type"])))) {
|
|
825
|
+
return (((((children) ?? [])[0]) ?? null))["value"];
|
|
826
|
+
} else {
|
|
827
|
+
if (((kind === "word-arithmetic") && (val === "+") && (((children) ?? []).length === 2) && __eliscript_truthy(memory_word_type((node)["type"])))) {
|
|
828
|
+
{
|
|
829
|
+
let left = ((((children) ?? [])[0]) ?? null);
|
|
830
|
+
let right = ((((children) ?? [])[1]) ?? null);
|
|
831
|
+
if ((((left)["kind"] === "local") && __eliscript_truthy(memory_word_type((left)["type"])) && __eliscript_numeric_relation(">=", memory_word_imm12(right), 0))) {
|
|
832
|
+
return (left)["value"];
|
|
833
|
+
} else {
|
|
834
|
+
if ((((right)["kind"] === "local") && __eliscript_truthy(memory_word_type((right)["type"])) && __eliscript_numeric_relation(">=", memory_word_imm12(left), 0))) {
|
|
835
|
+
return (right)["value"];
|
|
836
|
+
} else {
|
|
837
|
+
return -1;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
} else {
|
|
842
|
+
return -1;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
function memory_live_before(node, after, graph, words) {
|
|
849
|
+
{
|
|
850
|
+
let kind = (node)["kind"];
|
|
851
|
+
let children = (node)["children"];
|
|
852
|
+
let value = (node)["value"];
|
|
853
|
+
let live = memory_bitset_copy(after);
|
|
854
|
+
if ((kind === "local")) {
|
|
855
|
+
memory_bitset_interfere(graph, value, live, words);
|
|
856
|
+
{
|
|
857
|
+
let w = __eliscript_numeric_ushr(value, 5);
|
|
858
|
+
let b = __eliscript_numeric_shl(1, __eliscript_numeric_and(value, 31));
|
|
859
|
+
((live)[w] = __eliscript_numeric_or((live)[w], b));
|
|
860
|
+
}
|
|
861
|
+
} else {
|
|
862
|
+
if (((kind === "set") || (kind === "initialize"))) {
|
|
863
|
+
memory_bitset_interfere(graph, value, live, words);
|
|
864
|
+
{
|
|
865
|
+
let w = __eliscript_numeric_ushr(value, 5);
|
|
866
|
+
let b = __eliscript_numeric_shl(1, __eliscript_numeric_and(value, 31));
|
|
867
|
+
((live)[w] = __eliscript_numeric_and((live)[w], __eliscript_numeric_not(b)));
|
|
868
|
+
}
|
|
869
|
+
((live = memory_live_before(((((children) ?? [])[0]) ?? null), live, graph, words)));
|
|
870
|
+
} else {
|
|
871
|
+
if ((kind === "if")) {
|
|
872
|
+
{
|
|
873
|
+
let t_live = memory_live_before(((((children) ?? [])[1]) ?? null), live, graph, words);
|
|
874
|
+
let e_live = memory_live_before(((((children) ?? [])[2]) ?? null), live, graph, words);
|
|
875
|
+
((live = memory_live_before(((((children) ?? [])[0]) ?? null), memory_bitset_union(t_live, e_live, words), graph, words)));
|
|
876
|
+
}
|
|
877
|
+
} else {
|
|
878
|
+
if (((kind === "while") || (kind === "remainder-while") || (kind === "guarded-while"))) {
|
|
879
|
+
{
|
|
880
|
+
let changed = true;
|
|
881
|
+
while (__eliscript_truthy(changed)) {
|
|
882
|
+
((changed = null));
|
|
883
|
+
{
|
|
884
|
+
let body_in = memory_live_before(((((children) ?? [])[1]) ?? null), live, graph, words);
|
|
885
|
+
let cond_after = memory_bitset_union(after, body_in, words);
|
|
886
|
+
let next = memory_live_before(((((children) ?? [])[0]) ?? null), cond_after, graph, words);
|
|
887
|
+
let w = 0;
|
|
888
|
+
while (__eliscript_numeric_relation("<", w, words)) {
|
|
889
|
+
{
|
|
890
|
+
let lw = (live)[w];
|
|
891
|
+
let nw = __eliscript_numeric_or(lw, (next)[w]);
|
|
892
|
+
if ((__eliscript_numeric_and(nw, __eliscript_numeric_not(lw)) !== 0)) {
|
|
893
|
+
((live)[w] = nw);
|
|
894
|
+
((changed = true));
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
((w = (w + 1)));
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
} else {
|
|
903
|
+
if (((kind === "memory-op") && (((children) ?? []).length === 2) && __eliscript_numeric_relation(">", memory_width(value), 0))) {
|
|
904
|
+
{
|
|
905
|
+
let c0 = ((((children) ?? [])[0]) ?? null);
|
|
906
|
+
let addr_idx = memory_addr_base_local(c0);
|
|
907
|
+
if (__eliscript_numeric_relation(">=", addr_idx, 0)) {
|
|
908
|
+
{
|
|
909
|
+
let aw = __eliscript_numeric_ushr(addr_idx, 5);
|
|
910
|
+
let ab = __eliscript_numeric_shl(1, __eliscript_numeric_and(addr_idx, 31));
|
|
911
|
+
((live)[aw] = __eliscript_numeric_or((live)[aw], ab));
|
|
912
|
+
memory_bitset_interfere(graph, addr_idx, live, words);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
((live = memory_live_before(((((children) ?? [])[1]) ?? null), live, graph, words)));
|
|
916
|
+
((live = memory_live_before(c0, live, graph, words)));
|
|
917
|
+
}
|
|
918
|
+
} else {
|
|
919
|
+
if (((((children) ?? []).length === 2) && ((kind === "word-compare") || (kind === "v64-compare") || (kind === "word-arithmetic") || (kind === "memory-op")) && ((((((children) ?? [])[0]) ?? null))["kind"] === "local") && !(__eliscript_truthy(memory_expr_writes_local_p(((((children) ?? [])[1]) ?? null), (((((children) ?? [])[0]) ?? null))["value"]))))) {
|
|
920
|
+
{
|
|
921
|
+
let c0 = ((((children) ?? [])[0]) ?? null);
|
|
922
|
+
let lidx = (c0)["value"];
|
|
923
|
+
let lw = __eliscript_numeric_ushr(lidx, 5);
|
|
924
|
+
let lb = __eliscript_numeric_shl(1, __eliscript_numeric_and(lidx, 31));
|
|
925
|
+
((live)[lw] = __eliscript_numeric_or((live)[lw], lb));
|
|
926
|
+
memory_bitset_interfere(graph, lidx, live, words);
|
|
927
|
+
((live = memory_live_before(((((children) ?? [])[1]) ?? null), live, graph, words)));
|
|
928
|
+
((live = memory_live_before(c0, live, graph, words)));
|
|
929
|
+
}
|
|
930
|
+
} else {
|
|
931
|
+
{
|
|
932
|
+
let i = __eliscript_numeric_decrement(((children) ?? []).length);
|
|
933
|
+
let short = ((kind === "and") || (kind === "or"));
|
|
934
|
+
while (__eliscript_numeric_relation(">=", i, 0)) {
|
|
935
|
+
((live = memory_live_before(((((children) ?? [])[i]) ?? null), (__eliscript_truthy(short) ? memory_bitset_union(after, live, words) : live), graph, words)));
|
|
936
|
+
((i = __eliscript_numeric_decrement(i)));
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return live;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
function allocate_memory_registers(body, locals, pin_memory = null, arity = null) {
|
|
949
|
+
{
|
|
950
|
+
let count = ((locals) ?? []).length;
|
|
951
|
+
if ((count === 0)) {
|
|
952
|
+
return ({"registers": [], "saved": 0, "offsets": [], "spilled": 0, "noInit": []});
|
|
953
|
+
} else {
|
|
954
|
+
{
|
|
955
|
+
let counts = (new (globalThis.Array)(count))["fill"](0);
|
|
956
|
+
let registers = (new (globalThis.Array)(count))["fill"](-1);
|
|
957
|
+
let offsets = (new (globalThis.Array)(count))["fill"](0);
|
|
958
|
+
let no_init = (new (globalThis.Array)(count))["fill"](false);
|
|
959
|
+
let words = Math.max(1, Math.ceil(__eliscript_numeric_div(count, 32)));
|
|
960
|
+
let graph = new (globalThis.Array)(count);
|
|
961
|
+
let param_count = ((arity == null) ? 0 : arity);
|
|
962
|
+
let candidates = [];
|
|
963
|
+
let index = 0;
|
|
964
|
+
while (__eliscript_numeric_relation("<", index, count)) {
|
|
965
|
+
((graph)[index] = new (globalThis.Uint32Array)(words));
|
|
966
|
+
((index = (index + 1)));
|
|
967
|
+
}
|
|
968
|
+
memory_register_weights(body, counts, 1);
|
|
969
|
+
{
|
|
970
|
+
let empty = new (globalThis.Uint32Array)(words);
|
|
971
|
+
let entry_live = memory_live_before(body, empty, graph, words);
|
|
972
|
+
let entry_mask = memory_bitset_copy(entry_live);
|
|
973
|
+
((index = 0));
|
|
974
|
+
while (__eliscript_numeric_relation("<", index, param_count)) {
|
|
975
|
+
{
|
|
976
|
+
let w = __eliscript_numeric_ushr(index, 5);
|
|
977
|
+
let b = __eliscript_numeric_shl(1, __eliscript_numeric_and(index, 31));
|
|
978
|
+
((entry_mask)[w] = __eliscript_numeric_or((entry_mask)[w], b));
|
|
979
|
+
}
|
|
980
|
+
((index = (index + 1)));
|
|
981
|
+
}
|
|
982
|
+
((index = 0));
|
|
983
|
+
while (__eliscript_numeric_relation("<", index, count)) {
|
|
984
|
+
if ((__eliscript_numeric_and((entry_mask)[__eliscript_numeric_ushr(index, 5)], __eliscript_numeric_shl(1, __eliscript_numeric_and(index, 31))) !== 0)) {
|
|
985
|
+
memory_bitset_interfere(graph, index, entry_mask, words);
|
|
986
|
+
}
|
|
987
|
+
if ((__eliscript_numeric_relation(">=", index, param_count) && (__eliscript_numeric_and((entry_live)[__eliscript_numeric_ushr(index, 5)], __eliscript_numeric_shl(1, __eliscript_numeric_and(index, 31))) === 0))) {
|
|
988
|
+
((no_init)[index] = true);
|
|
989
|
+
}
|
|
990
|
+
{
|
|
991
|
+
let type = (((((locals) ?? [])[index]) ?? null))["type"];
|
|
992
|
+
if ((__eliscript_numeric_relation(">", ((((counts) ?? [])[index]) ?? null), 1) && (__eliscript_truthy(memory_word_type(type)) || __eliscript_truthy(memory_wide_type(type))))) {
|
|
993
|
+
(candidates)["push"](index);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
((index = (index + 1)));
|
|
997
|
+
}
|
|
998
|
+
(candidates)["sort"](((left, right) => {
|
|
999
|
+
return __eliscript_numeric_sub(((((counts) ?? [])[right]) ?? null), ((((counts) ?? [])[left]) ?? null));
|
|
1000
|
+
}));
|
|
1001
|
+
{
|
|
1002
|
+
let max_regs = (__eliscript_truthy(pin_memory) ? 7 : 9);
|
|
1003
|
+
let reg_masks = new (globalThis.Array)(max_regs);
|
|
1004
|
+
let max_reg = -1;
|
|
1005
|
+
let c_len = ((candidates) ?? []).length;
|
|
1006
|
+
let ci = 0;
|
|
1007
|
+
((index = 0));
|
|
1008
|
+
while (__eliscript_numeric_relation("<", index, max_regs)) {
|
|
1009
|
+
((reg_masks)[index] = new (globalThis.Uint32Array)(words));
|
|
1010
|
+
((index = (index + 1)));
|
|
1011
|
+
}
|
|
1012
|
+
while (__eliscript_numeric_relation("<", ci, c_len)) {
|
|
1013
|
+
{
|
|
1014
|
+
let cand = ((((candidates) ?? [])[ci]) ?? null);
|
|
1015
|
+
let r = 0;
|
|
1016
|
+
let placed = null;
|
|
1017
|
+
while ((!(__eliscript_truthy(placed)) && __eliscript_numeric_relation("<", r, max_regs))) {
|
|
1018
|
+
{
|
|
1019
|
+
let rm = ((((reg_masks) ?? [])[r]) ?? null);
|
|
1020
|
+
if (__eliscript_truthy(memory_bitset_disjoint_p(((((graph) ?? [])[cand]) ?? null), rm, words))) {
|
|
1021
|
+
((registers)[cand] = __eliscript_numeric_sub(-22, r));
|
|
1022
|
+
{
|
|
1023
|
+
let w = __eliscript_numeric_ushr(cand, 5);
|
|
1024
|
+
let b = __eliscript_numeric_shl(1, __eliscript_numeric_and(cand, 31));
|
|
1025
|
+
((rm)[w] = __eliscript_numeric_or((rm)[w], b));
|
|
1026
|
+
}
|
|
1027
|
+
if (__eliscript_numeric_relation(">", r, max_reg)) {
|
|
1028
|
+
((max_reg = r));
|
|
1029
|
+
}
|
|
1030
|
+
((placed = true));
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
((r = (r + 1)));
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
((ci = (ci + 1)));
|
|
1037
|
+
}
|
|
1038
|
+
{
|
|
1039
|
+
let slot_masks = [];
|
|
1040
|
+
((index = 0));
|
|
1041
|
+
while (__eliscript_numeric_relation("<", index, count)) {
|
|
1042
|
+
if (((((((registers) ?? [])[index]) ?? null) === -1) && (__eliscript_numeric_relation("<", index, param_count) || __eliscript_numeric_relation(">", ((((counts) ?? [])[index]) ?? null), 0)))) {
|
|
1043
|
+
{
|
|
1044
|
+
let s = 0;
|
|
1045
|
+
let s_len = ((slot_masks) ?? []).length;
|
|
1046
|
+
let placed = null;
|
|
1047
|
+
let irow = ((((graph) ?? [])[index]) ?? null);
|
|
1048
|
+
while ((!(__eliscript_truthy(placed)) && __eliscript_numeric_relation("<", s, s_len))) {
|
|
1049
|
+
{
|
|
1050
|
+
let sm = ((((slot_masks) ?? [])[s]) ?? null);
|
|
1051
|
+
if (__eliscript_truthy(memory_bitset_disjoint_p(irow, sm, words))) {
|
|
1052
|
+
{
|
|
1053
|
+
let w = __eliscript_numeric_ushr(index, 5);
|
|
1054
|
+
let b = __eliscript_numeric_shl(1, __eliscript_numeric_and(index, 31));
|
|
1055
|
+
((sm)[w] = __eliscript_numeric_or((sm)[w], b));
|
|
1056
|
+
}
|
|
1057
|
+
((offsets)[index] = __eliscript_numeric_mul((s + 1), 8));
|
|
1058
|
+
((placed = true));
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
((s = (s + 1)));
|
|
1062
|
+
}
|
|
1063
|
+
if ((!__eliscript_truthy(placed))) {
|
|
1064
|
+
{
|
|
1065
|
+
let sm = new (globalThis.Uint32Array)(words);
|
|
1066
|
+
((sm)[__eliscript_numeric_ushr(index, 5)] = __eliscript_numeric_shl(1, __eliscript_numeric_and(index, 31)));
|
|
1067
|
+
(slot_masks)["push"](sm);
|
|
1068
|
+
((offsets)[index] = __eliscript_numeric_mul(((slot_masks) ?? []).length, 8));
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
((index = (index + 1)));
|
|
1074
|
+
}
|
|
1075
|
+
return ({"registers": registers, "saved": (__eliscript_numeric_relation(">=", max_reg, 0) ? (max_reg + 1) : 0), "offsets": offsets, "spilled": ((slot_masks) ?? []).length, "noInit": no_init});
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
693
1083
|
function assign_register_class(counts, locals, registers, available, type, graph) {
|
|
694
1084
|
{
|
|
695
1085
|
let i = 0;
|
|
@@ -861,7 +1251,7 @@ function direct_value_tree(node) {
|
|
|
861
1251
|
}
|
|
862
1252
|
}
|
|
863
1253
|
function direct_value(state, node) {
|
|
864
|
-
return ((
|
|
1254
|
+
return ((__eliscript_value_2) => (__eliscript_truthy(__eliscript_value_2) ? ((__eliscript_value_3) => (__eliscript_truthy(__eliscript_value_3) ? ((__eliscript_value_4) => (__eliscript_truthy(__eliscript_value_4) ? __eliscript_numeric_relation("<=", pure_depth(node), __eliscript_numeric_sub(7, ((state)["depth"] ?? 0))) : __eliscript_value_4))(direct_value_tree(node)) : __eliscript_value_3))(((node)["type"] === "f64")) : __eliscript_value_2))(((state)["compact"] ?? null));
|
|
865
1255
|
}
|
|
866
1256
|
function retarget_last(state, register) {
|
|
867
1257
|
{
|
|
@@ -1161,14 +1551,14 @@ function patch_jump_record(state, at, target, record, descriptor) {
|
|
|
1161
1551
|
{
|
|
1162
1552
|
let words = (state)["words"];
|
|
1163
1553
|
let opcode = native_word_at(words, at);
|
|
1164
|
-
let branches = ((
|
|
1554
|
+
let branches = ((__eliscript_value_5) => (__eliscript_truthy(__eliscript_value_5) ? __eliscript_value_5 : ((created) => {
|
|
1165
1555
|
((state)["branches"] = created);
|
|
1166
1556
|
return created;
|
|
1167
1557
|
})([])))(((state)["branches"] ?? null));
|
|
1168
1558
|
let kind = branch_kind(opcode);
|
|
1169
1559
|
let distance = __eliscript_numeric_sub(target, at);
|
|
1170
1560
|
{
|
|
1171
|
-
let entry = ((
|
|
1561
|
+
let entry = ((__eliscript_value_6) => (__eliscript_truthy(__eliscript_value_6) ? __eliscript_value_6 : ({"at": at, "target": target, "opcode": opcode, "kind": kind, "size": 1})))(record);
|
|
1172
1562
|
if (__eliscript_truthy(record)) {
|
|
1173
1563
|
((entry)["at"] = at);
|
|
1174
1564
|
((entry)["target"] = target);
|
|
@@ -1257,7 +1647,7 @@ function relaxed_branch(state, entry, at, target) {
|
|
|
1257
1647
|
if ((size === 1)) {
|
|
1258
1648
|
return word(state, branch_word(335544320, __eliscript_numeric_sub(target, at)));
|
|
1259
1649
|
} else {
|
|
1260
|
-
return long_jump(state, __eliscript_numeric_sub(target, at), (
|
|
1650
|
+
return long_jump(state, __eliscript_numeric_sub(target, at), (__eliscript_numeric_and(opcode, 2147483648) !== 0));
|
|
1261
1651
|
}
|
|
1262
1652
|
} else {
|
|
1263
1653
|
word(state, branch_word(__eliscript_numeric_xor(opcode, ((kind === 1) ? 1 : 16777216)), size));
|
|
@@ -1273,122 +1663,158 @@ function relaxed_branch(state, entry, at, target) {
|
|
|
1273
1663
|
function finish_branches(state, offsets) {
|
|
1274
1664
|
{
|
|
1275
1665
|
let branches = ((state)["branches"] ?? []);
|
|
1276
|
-
let
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
while (__eliscript_truthy(changed)) {
|
|
1281
|
-
((changed = false));
|
|
1666
|
+
let branch_count = ((branches) ?? []).length;
|
|
1667
|
+
let fast = true;
|
|
1668
|
+
let k = 0;
|
|
1669
|
+
while ((__eliscript_truthy(fast) && __eliscript_numeric_relation("<", k, branch_count))) {
|
|
1282
1670
|
{
|
|
1283
|
-
let
|
|
1284
|
-
(
|
|
1285
|
-
((
|
|
1286
|
-
|
|
1287
|
-
}));
|
|
1671
|
+
let entry = ((((branches) ?? [])[k]) ?? null);
|
|
1672
|
+
if ((!__eliscript_truthy(branch_fits(__eliscript_numeric_sub((entry)["target"], (entry)["at"]), branch_limit((entry)["kind"]))))) {
|
|
1673
|
+
((fast = null));
|
|
1674
|
+
}
|
|
1288
1675
|
}
|
|
1289
|
-
(
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1676
|
+
((k = (k + 1)));
|
|
1677
|
+
}
|
|
1678
|
+
if ((__eliscript_truthy(fast) && (__eliscript_truthy(Array.isArray((state)["words"])) || !(__eliscript_truthy((((state)["words"])["hasHole"] ?? null)))))) {
|
|
1679
|
+
((state)["branches"] = []);
|
|
1680
|
+
return ((state)["cachedBranches"] = []);
|
|
1681
|
+
} else {
|
|
1682
|
+
{
|
|
1683
|
+
let changed = true;
|
|
1684
|
+
let cached_groups = ((state)["cachedBranches"] ?? []);
|
|
1685
|
+
let gi = 0;
|
|
1686
|
+
while (__eliscript_numeric_relation("<", gi, ((cached_groups) ?? []).length)) {
|
|
1687
|
+
{
|
|
1688
|
+
let group = ((((cached_groups) ?? [])[gi]) ?? null);
|
|
1689
|
+
let base = (group)["base"];
|
|
1690
|
+
let arr = (group)["branches"];
|
|
1691
|
+
let bi = 0;
|
|
1692
|
+
let blen = ((arr) ?? []).length;
|
|
1693
|
+
while (__eliscript_numeric_relation("<", bi, blen)) {
|
|
1694
|
+
(branches)["push"](({"at": (base + (arr)[bi]), "target": (base + (arr)[(bi + 1)]), "opcode": (arr)[(bi + 2)], "kind": (arr)[(bi + 3)], "size": 1}));
|
|
1695
|
+
((bi = (bi + 4)));
|
|
1696
|
+
}
|
|
1302
1697
|
}
|
|
1698
|
+
((gi = (gi + 1)));
|
|
1303
1699
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
while (__eliscript_numeric_relation(">=", index, 0)) {
|
|
1319
|
-
{
|
|
1320
|
-
let entry = (__eliscript_numeric_relation(">=", next, 0) ? ((((branches) ?? [])[next]) ?? null) : null);
|
|
1321
|
-
if ((__eliscript_truthy(entry) && ((entry)["at"] === index))) {
|
|
1700
|
+
((state)["cachedBranches"] = []);
|
|
1701
|
+
(branches)["sort"](((left, right) => {
|
|
1702
|
+
return __eliscript_numeric_sub((left)["at"], (right)["at"]);
|
|
1703
|
+
}));
|
|
1704
|
+
while (__eliscript_truthy(changed)) {
|
|
1705
|
+
((changed = false));
|
|
1706
|
+
{
|
|
1707
|
+
let growth = 0;
|
|
1708
|
+
(branches)["forEach"](((entry) => {
|
|
1709
|
+
((entry)["before"] = growth);
|
|
1710
|
+
return ((growth = (growth + __eliscript_numeric_decrement((entry)["size"]))));
|
|
1711
|
+
}));
|
|
1712
|
+
}
|
|
1713
|
+
(branches)["forEach"](((entry) => {
|
|
1322
1714
|
{
|
|
1323
|
-
let at =
|
|
1715
|
+
let at = branch_position(branches, (entry)["at"]);
|
|
1324
1716
|
let target = branch_position(branches, (entry)["target"]);
|
|
1325
|
-
let
|
|
1326
|
-
(
|
|
1327
|
-
|
|
1328
|
-
((
|
|
1329
|
-
|
|
1717
|
+
let kind = (entry)["kind"];
|
|
1718
|
+
let opcode = (entry)["opcode"];
|
|
1719
|
+
let always = ((kind === 1) && __eliscript_numeric_relation(">=", __eliscript_numeric_and(opcode, 15), 14));
|
|
1720
|
+
let size = (__eliscript_truthy(branch_fits(__eliscript_numeric_sub(target, at), branch_limit(kind))) ? 1 : (((kind === 0) || __eliscript_truthy(always)) ? (__eliscript_truthy(branch_fits(__eliscript_numeric_sub(target, at), 33554432)) ? 1 : 7) : (__eliscript_truthy(branch_fits(__eliscript_numeric_decrement(__eliscript_numeric_sub(target, at)), 33554432)) ? 2 : 8)));
|
|
1721
|
+
if (__eliscript_numeric_relation(">", size, (entry)["size"])) {
|
|
1722
|
+
((entry)["size"] = size);
|
|
1723
|
+
return ((changed = true));
|
|
1724
|
+
} else {
|
|
1725
|
+
return null;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
}));
|
|
1729
|
+
}
|
|
1730
|
+
{
|
|
1731
|
+
let words = (state)["words"];
|
|
1732
|
+
let original_size = ((words) ?? []).length;
|
|
1733
|
+
let count = ((branches) ?? []).length;
|
|
1734
|
+
let last = (__eliscript_numeric_relation(">", count, 0) ? ((((branches) ?? [])[__eliscript_numeric_decrement(count)]) ?? null) : null);
|
|
1735
|
+
let final_size = (original_size + (__eliscript_truthy(last) ? ((last)["before"] + __eliscript_numeric_decrement((last)["size"])) : 0));
|
|
1736
|
+
let scratch = [];
|
|
1737
|
+
let out = ({"words": scratch, "compact": null});
|
|
1738
|
+
let index = __eliscript_numeric_decrement(original_size);
|
|
1739
|
+
let next = __eliscript_numeric_decrement(count);
|
|
1740
|
+
let write = __eliscript_numeric_decrement(final_size);
|
|
1741
|
+
native_word_resize(words, final_size);
|
|
1742
|
+
while (__eliscript_numeric_relation(">=", index, 0)) {
|
|
1743
|
+
{
|
|
1744
|
+
let entry = (__eliscript_numeric_relation(">=", next, 0) ? ((((branches) ?? [])[next]) ?? null) : null);
|
|
1745
|
+
if ((__eliscript_truthy(entry) && ((entry)["at"] === index))) {
|
|
1746
|
+
{
|
|
1747
|
+
let at = __eliscript_numeric_sub(write, __eliscript_numeric_decrement((entry)["size"]));
|
|
1748
|
+
let target = branch_position(branches, (entry)["target"]);
|
|
1749
|
+
let j = 0;
|
|
1750
|
+
((scratch)["length"] = 0);
|
|
1751
|
+
relaxed_branch(out, entry, at, target);
|
|
1752
|
+
((j = __eliscript_numeric_decrement(((scratch) ?? []).length)));
|
|
1753
|
+
while (__eliscript_numeric_relation(">=", j, 0)) {
|
|
1754
|
+
{
|
|
1755
|
+
let value = ((((scratch) ?? [])[j]) ?? null);
|
|
1756
|
+
if ((!((write === index) && (native_word_at(words, index) === value)))) {
|
|
1757
|
+
native_word_set(words, write, value);
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
((write = __eliscript_numeric_decrement(write)));
|
|
1761
|
+
((j = __eliscript_numeric_decrement(j)));
|
|
1762
|
+
}
|
|
1763
|
+
((next = __eliscript_numeric_decrement(next)));
|
|
1764
|
+
}
|
|
1765
|
+
} else {
|
|
1330
1766
|
{
|
|
1331
|
-
let value = (
|
|
1332
|
-
if ((!(
|
|
1767
|
+
let value = native_word_at(words, index);
|
|
1768
|
+
if ((!(write === index))) {
|
|
1333
1769
|
native_word_set(words, write, value);
|
|
1334
1770
|
}
|
|
1771
|
+
((write = __eliscript_numeric_decrement(write)));
|
|
1335
1772
|
}
|
|
1336
|
-
((write = __eliscript_numeric_decrement(write)));
|
|
1337
|
-
((j = __eliscript_numeric_decrement(j)));
|
|
1338
1773
|
}
|
|
1339
|
-
((next = __eliscript_numeric_decrement(next)));
|
|
1340
1774
|
}
|
|
1341
|
-
|
|
1775
|
+
((index = __eliscript_numeric_decrement(index)));
|
|
1776
|
+
}
|
|
1777
|
+
((index = 0));
|
|
1778
|
+
while (__eliscript_numeric_relation("<", index, ((offsets) ?? []).length)) {
|
|
1779
|
+
((offsets)[index] = __eliscript_numeric_mul(branch_position(branches, __eliscript_numeric_div(((((offsets) ?? [])[index]) ?? null), 4)), 4));
|
|
1780
|
+
((index = (index + 1)));
|
|
1781
|
+
}
|
|
1782
|
+
(((state)["constants"] ?? []))["forEach"](((entry) => {
|
|
1342
1783
|
{
|
|
1343
|
-
let
|
|
1344
|
-
|
|
1345
|
-
|
|
1784
|
+
let uses = (entry)["uses"];
|
|
1785
|
+
let i = 0;
|
|
1786
|
+
while (__eliscript_numeric_relation("<", i, ((uses) ?? []).length)) {
|
|
1787
|
+
((uses)[i] = branch_position(branches, ((((uses) ?? [])[i]) ?? null)));
|
|
1788
|
+
((i = (i + 1)));
|
|
1346
1789
|
}
|
|
1347
|
-
|
|
1790
|
+
return null;
|
|
1791
|
+
}
|
|
1792
|
+
}));
|
|
1793
|
+
{
|
|
1794
|
+
let uses = ((state)["tableUses"] ?? []);
|
|
1795
|
+
let i = 0;
|
|
1796
|
+
while (__eliscript_numeric_relation("<", i, ((uses) ?? []).length)) {
|
|
1797
|
+
((uses)[i] = branch_position(branches, ((((uses) ?? [])[i]) ?? null)));
|
|
1798
|
+
((i = (i + 1)));
|
|
1348
1799
|
}
|
|
1349
1800
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
while (__eliscript_numeric_relation("<", i, ((uses) ?? []).length)) {
|
|
1363
|
-
((uses)[i] = branch_position(branches, ((((uses) ?? [])[i]) ?? null)));
|
|
1364
|
-
((i = (i + 1)));
|
|
1365
|
-
}
|
|
1366
|
-
return null;
|
|
1367
|
-
}
|
|
1368
|
-
}));
|
|
1369
|
-
{
|
|
1370
|
-
let uses = ((state)["tableUses"] ?? []);
|
|
1371
|
-
let i = 0;
|
|
1372
|
-
while (__eliscript_numeric_relation("<", i, ((uses) ?? []).length)) {
|
|
1373
|
-
((uses)[i] = branch_position(branches, ((((uses) ?? [])[i]) ?? null)));
|
|
1374
|
-
((i = (i + 1)));
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
{
|
|
1378
|
-
let ranges = ((state)["debugRanges"] ?? null);
|
|
1379
|
-
let i = 0;
|
|
1380
|
-
if (__eliscript_truthy(ranges)) {
|
|
1381
|
-
while (__eliscript_numeric_relation("<", i, ((ranges) ?? []).length)) {
|
|
1382
|
-
{
|
|
1383
|
-
let range = ((((ranges) ?? [])[i]) ?? null);
|
|
1384
|
-
((range)["start"] = __eliscript_numeric_mul(branch_position(branches, __eliscript_numeric_div((range)["start"], 4)), 4));
|
|
1385
|
-
((range)["end"] = __eliscript_numeric_mul(branch_position(branches, __eliscript_numeric_div((range)["end"], 4)), 4));
|
|
1801
|
+
{
|
|
1802
|
+
let ranges = ((state)["debugRanges"] ?? null);
|
|
1803
|
+
let i = 0;
|
|
1804
|
+
if (__eliscript_truthy(ranges)) {
|
|
1805
|
+
while (__eliscript_numeric_relation("<", i, ((ranges) ?? []).length)) {
|
|
1806
|
+
{
|
|
1807
|
+
let range = ((((ranges) ?? [])[i]) ?? null);
|
|
1808
|
+
((range)["start"] = __eliscript_numeric_mul(branch_position(branches, __eliscript_numeric_div((range)["start"], 4)), 4));
|
|
1809
|
+
((range)["end"] = __eliscript_numeric_mul(branch_position(branches, __eliscript_numeric_div((range)["end"], 4)), 4));
|
|
1810
|
+
}
|
|
1811
|
+
((i = (i + 1)));
|
|
1812
|
+
}
|
|
1386
1813
|
}
|
|
1387
|
-
((i = (i + 1)));
|
|
1388
1814
|
}
|
|
1815
|
+
return ((state)["branches"] = []);
|
|
1389
1816
|
}
|
|
1390
1817
|
}
|
|
1391
|
-
return ((state)["branches"] = []);
|
|
1392
1818
|
}
|
|
1393
1819
|
}
|
|
1394
1820
|
}
|
|
@@ -1614,26 +2040,389 @@ function emit_call(state, node) {
|
|
|
1614
2040
|
return ((state)["depth"] = depth);
|
|
1615
2041
|
}
|
|
1616
2042
|
}
|
|
1617
|
-
function
|
|
1618
|
-
|
|
2043
|
+
function memory_word_imm12(node) {
|
|
2044
|
+
{
|
|
2045
|
+
let kind = (node)["kind"];
|
|
2046
|
+
let value = (node)["value"];
|
|
2047
|
+
if ((__eliscript_truthy(memory_word_type((node)["type"])) && ((kind === "literal") || (kind === "int-literal")) && (__eliscript_value_type(value) === "number") && __eliscript_truthy(Number.isInteger(value)) && __eliscript_numeric_relation(">=", value, 0) && __eliscript_numeric_relation("<=", value, 4095))) {
|
|
2048
|
+
return value;
|
|
2049
|
+
} else {
|
|
2050
|
+
return -1;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
function memory_word_compare_code(name) {
|
|
2055
|
+
if ((name === "=")) {
|
|
2056
|
+
return 0;
|
|
2057
|
+
} else {
|
|
2058
|
+
if ((name === "/=")) {
|
|
2059
|
+
return 1;
|
|
2060
|
+
} else {
|
|
2061
|
+
if ((name === "<")) {
|
|
2062
|
+
return 3;
|
|
2063
|
+
} else {
|
|
2064
|
+
if ((name === "<=")) {
|
|
2065
|
+
return 9;
|
|
2066
|
+
} else {
|
|
2067
|
+
if ((name === ">")) {
|
|
2068
|
+
return 8;
|
|
2069
|
+
} else {
|
|
2070
|
+
return 2;
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
function memory_wide_imm12(node) {
|
|
2078
|
+
if ((__eliscript_truthy(memory_wide_type((node)["type"])) && ((node)["kind"] === "literal"))) {
|
|
1619
2079
|
{
|
|
1620
|
-
let
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
patch_jump(state, initial, (((state)["words"]) ?? []).length);
|
|
1624
|
-
patch_conditions(state, condition_jumps(state, ((((children) ?? [])[0]) ?? null), true), start);
|
|
1625
|
-
if (__eliscript_truthy(used)) {
|
|
1626
|
-
return integer_register(state, 0, 0, 0);
|
|
2080
|
+
let value = (node)["value"];
|
|
2081
|
+
if ((!((value === null)) && (__eliscript_value_type(value) === "object") && ((value)["high"] === 0) && __eliscript_numeric_relation(">=", (value)["low"], 0) && __eliscript_numeric_relation("<=", (value)["low"], 4095))) {
|
|
2082
|
+
return (value)["low"];
|
|
1627
2083
|
} else {
|
|
1628
2084
|
return null;
|
|
1629
2085
|
}
|
|
1630
2086
|
}
|
|
1631
2087
|
} else {
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
2088
|
+
return null;
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
function memory_word_pow2_shift(node) {
|
|
2092
|
+
{
|
|
2093
|
+
let kind = (node)["kind"];
|
|
2094
|
+
let value = (node)["value"];
|
|
2095
|
+
if ((__eliscript_truthy(memory_word_type((node)["type"])) && ((kind === "literal") || (kind === "int-literal")) && (__eliscript_value_type(value) === "number") && __eliscript_truthy(Number.isInteger(value)) && __eliscript_numeric_relation(">", value, 1) && __eliscript_numeric_relation("<=", value, 1073741824) && (__eliscript_numeric_and(value, __eliscript_numeric_decrement(value)) === 0))) {
|
|
2096
|
+
{
|
|
2097
|
+
let k = 0;
|
|
2098
|
+
let v = value;
|
|
2099
|
+
while (__eliscript_numeric_relation(">", v, 1)) {
|
|
2100
|
+
((v = __eliscript_numeric_ushr(v, 1)), (k = (k + 1)));
|
|
2101
|
+
}
|
|
2102
|
+
return k;
|
|
2103
|
+
}
|
|
2104
|
+
} else {
|
|
2105
|
+
return 0;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
function memory_dynamic_ref_local(children, is_or) {
|
|
2110
|
+
if ((((children) ?? []).length === 2)) {
|
|
2111
|
+
{
|
|
2112
|
+
let c0 = ((((children) ?? [])[0]) ?? null);
|
|
2113
|
+
let c1 = ((((children) ?? [])[1]) ?? null);
|
|
2114
|
+
if ((((c0)["kind"] === "word-compare") && ((c1)["kind"] === "word-compare") && ((c0)["value"] === (__eliscript_truthy(is_or) ? "/=" : "=")) && ((c1)["value"] === (__eliscript_truthy(is_or) ? ">" : "<=")))) {
|
|
2115
|
+
{
|
|
2116
|
+
let c0_ch = (c0)["children"];
|
|
2117
|
+
let c1_ch = (c1)["children"];
|
|
2118
|
+
let c0_0 = ((((c0_ch) ?? [])[0]) ?? null);
|
|
2119
|
+
let c0_1 = ((((c0_ch) ?? [])[1]) ?? null);
|
|
2120
|
+
let c1_0 = ((((c1_ch) ?? [])[0]) ?? null);
|
|
2121
|
+
let c1_1 = ((((c1_ch) ?? [])[1]) ?? null);
|
|
2122
|
+
if ((((c0_0)["kind"] === "memory-op") && ((c0_0)["value"] === "v64-high") && (memory_word_imm12(c0_1) === 0) && ((c1_0)["kind"] === "memory-op") && ((c1_0)["value"] === "v64-low") && (memory_word_imm12(c1_1) === 3))) {
|
|
2123
|
+
{
|
|
2124
|
+
let arg0 = (((((c0_0)["children"]) ?? [])[0]) ?? null);
|
|
2125
|
+
let arg1 = (((((c1_0)["children"]) ?? [])[0]) ?? null);
|
|
2126
|
+
if ((((arg0)["kind"] === "local") && ((arg1)["kind"] === "local") && ((arg0)["value"] === (arg1)["value"]))) {
|
|
2127
|
+
return arg0;
|
|
2128
|
+
} else {
|
|
2129
|
+
return null;
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
} else {
|
|
2133
|
+
return null;
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
} else {
|
|
2137
|
+
return null;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
} else {
|
|
2141
|
+
return null;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
function memory_word_lit_val(node) {
|
|
2145
|
+
{
|
|
2146
|
+
let kind = (node)["kind"];
|
|
2147
|
+
let value = (node)["value"];
|
|
2148
|
+
if ((__eliscript_truthy(memory_word_type((node)["type"])) && ((kind === "literal") || (kind === "int-literal")) && (__eliscript_value_type(value) === "number") && __eliscript_truthy(Number.isInteger(value)))) {
|
|
2149
|
+
return value;
|
|
2150
|
+
} else {
|
|
2151
|
+
return -1;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
function memory_bool01_p(node) {
|
|
2156
|
+
{
|
|
2157
|
+
let kind = (node)["kind"];
|
|
2158
|
+
let children = (node)["children"];
|
|
2159
|
+
if (((kind === "word-compare") || (kind === "v64-compare"))) {
|
|
2160
|
+
return (((children) ?? []).length === 2);
|
|
2161
|
+
} else {
|
|
2162
|
+
if ((kind === "not")) {
|
|
2163
|
+
return (((children) ?? []).length === 1);
|
|
2164
|
+
} else {
|
|
2165
|
+
if ((kind === "if")) {
|
|
2166
|
+
return ((__eliscript_value_7) => (__eliscript_truthy(__eliscript_value_7) ? ((tv, ev) => {
|
|
2167
|
+
return (((tv === 1) && (ev === 0)) || ((tv === 0) && (ev === 1)));
|
|
2168
|
+
})(memory_word_lit_val(((((children) ?? [])[1]) ?? null)), memory_word_lit_val(((((children) ?? [])[2]) ?? null))) : __eliscript_value_7))((((children) ?? []).length === 3));
|
|
2169
|
+
} else {
|
|
2170
|
+
if ((kind === "sequence")) {
|
|
2171
|
+
return ((__eliscript_value_8) => (__eliscript_truthy(__eliscript_value_8) ? memory_bool01_p(((((children) ?? [])[__eliscript_numeric_decrement(((children) ?? []).length)]) ?? null)) : __eliscript_value_8))(__eliscript_numeric_relation(">", ((children) ?? []).length, 0));
|
|
2172
|
+
} else {
|
|
2173
|
+
return null;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
function memory_bool01_jumps(state, node, when_true) {
|
|
2181
|
+
{
|
|
2182
|
+
let kind = (node)["kind"];
|
|
2183
|
+
let children = (node)["children"];
|
|
2184
|
+
if ((kind === "sequence")) {
|
|
2185
|
+
{
|
|
2186
|
+
let clen = ((children) ?? []).length;
|
|
2187
|
+
let si = 0;
|
|
2188
|
+
while (__eliscript_numeric_relation("<", si, __eliscript_numeric_decrement(clen))) {
|
|
2189
|
+
memory_discarded(state, ((((children) ?? [])[si]) ?? null));
|
|
2190
|
+
((si = (si + 1)));
|
|
2191
|
+
}
|
|
2192
|
+
return memory_bool01_jumps(state, ((((children) ?? [])[__eliscript_numeric_decrement(clen)]) ?? null), when_true);
|
|
2193
|
+
}
|
|
2194
|
+
} else {
|
|
2195
|
+
if ((kind === "if")) {
|
|
2196
|
+
{
|
|
2197
|
+
let tv = memory_word_lit_val(((((children) ?? [])[1]) ?? null));
|
|
2198
|
+
return memory_condition_jumps(state, ((((children) ?? [])[0]) ?? null), ((tv === 1) ? when_true : (!__eliscript_truthy(when_true))));
|
|
2199
|
+
}
|
|
2200
|
+
} else {
|
|
2201
|
+
return memory_condition_jumps(state, node, when_true);
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
function memory_condition_jumps(state, node, when_true) {
|
|
2207
|
+
{
|
|
2208
|
+
let kind = (node)["kind"];
|
|
2209
|
+
let children = (node)["children"];
|
|
2210
|
+
let jumps = [];
|
|
2211
|
+
let opt = ((__eliscript_value_9) => (__eliscript_truthy(__eliscript_value_9) ? ((__eliscript_value_10) => (__eliscript_truthy(__eliscript_value_10) ? (!__eliscript_truthy(((state)["debugRanges"] ?? null))) : __eliscript_value_10))(((state)["optimizeMemory"] ?? null)) : __eliscript_value_9))(((state)["memory"] ?? null));
|
|
2212
|
+
if ((__eliscript_truthy(opt) && (kind === "sequence") && ((node)["type"] === "i32"))) {
|
|
2213
|
+
{
|
|
2214
|
+
let clen = ((children) ?? []).length;
|
|
2215
|
+
if ((clen === 0)) {
|
|
2216
|
+
if (!(__eliscript_truthy(when_true))) {
|
|
2217
|
+
(jumps)["push"](jump(state, "jump"));
|
|
2218
|
+
}
|
|
2219
|
+
} else {
|
|
2220
|
+
{
|
|
2221
|
+
let si = 0;
|
|
2222
|
+
while (__eliscript_numeric_relation("<", si, __eliscript_numeric_decrement(clen))) {
|
|
2223
|
+
memory_discarded(state, ((((children) ?? [])[si]) ?? null));
|
|
2224
|
+
((si = (si + 1)));
|
|
2225
|
+
}
|
|
2226
|
+
{
|
|
2227
|
+
let last = ((((children) ?? [])[__eliscript_numeric_decrement(clen)]) ?? null);
|
|
2228
|
+
if (((last)["type"] === "i32")) {
|
|
2229
|
+
((jumps = memory_condition_jumps(state, last, when_true)));
|
|
2230
|
+
} else {
|
|
2231
|
+
if (__eliscript_truthy(memory_bool01_p(last))) {
|
|
2232
|
+
((jumps = memory_bool01_jumps(state, last, when_true)));
|
|
2233
|
+
} else {
|
|
2234
|
+
if (((last)["type"] === "u32")) {
|
|
2235
|
+
expression(state, last);
|
|
2236
|
+
(jumps)["push"](jump(state, (__eliscript_truthy(when_true) ? "nonzero" : "zero")));
|
|
2237
|
+
} else {
|
|
2238
|
+
condition(state, last);
|
|
2239
|
+
(jumps)["push"](jump(state, (__eliscript_truthy(when_true) ? "nonzero" : "zero")));
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
} else {
|
|
2248
|
+
if ((__eliscript_truthy(opt) && (kind === "if") && ((node)["type"] === "i32") && (((children) ?? []).length === 3) && __eliscript_truthy(((tv, ev) => {
|
|
2249
|
+
return (((tv === 1) && (ev === 0)) || ((tv === 0) && (ev === 1)));
|
|
2250
|
+
})(memory_word_lit_val(((((children) ?? [])[1]) ?? null)), memory_word_lit_val(((((children) ?? [])[2]) ?? null)))))) {
|
|
2251
|
+
{
|
|
2252
|
+
let tv = memory_word_lit_val(((((children) ?? [])[1]) ?? null));
|
|
2253
|
+
((jumps = memory_condition_jumps(state, ((((children) ?? [])[0]) ?? null), ((tv === 1) ? when_true : (!__eliscript_truthy(when_true))))));
|
|
2254
|
+
}
|
|
2255
|
+
} else {
|
|
2256
|
+
if ((__eliscript_truthy(opt) && (kind === "not") && ((node)["type"] === "i32") && (((children) ?? []).length === 1))) {
|
|
2257
|
+
((jumps = memory_condition_jumps(state, ((((children) ?? [])[0]) ?? null), (!__eliscript_truthy(when_true)))));
|
|
2258
|
+
} else {
|
|
2259
|
+
if ((__eliscript_truthy(opt) && ((kind === "and") || (kind === "or")) && ((node)["type"] === "i32"))) {
|
|
2260
|
+
{
|
|
2261
|
+
let dyn = memory_dynamic_ref_local(children, (kind === "or"));
|
|
2262
|
+
if (!((dyn === null))) {
|
|
2263
|
+
{
|
|
2264
|
+
let code = ((kind === "or") ? 8 : 9);
|
|
2265
|
+
let dr = local_register(state, dyn, "v64");
|
|
2266
|
+
if (__eliscript_numeric_relation(">=", dr, 0)) {
|
|
2267
|
+
word(state, (4043312159 + __eliscript_numeric_mul(dr, 32)));
|
|
2268
|
+
} else {
|
|
2269
|
+
expression(state, dyn);
|
|
2270
|
+
word(state, 4043312159);
|
|
2271
|
+
}
|
|
2272
|
+
(jumps)["push"]((((state)["words"]) ?? []).length);
|
|
2273
|
+
word(state, (1409286144 + (__eliscript_truthy(when_true) ? code : __eliscript_numeric_xor(code, 1))));
|
|
2274
|
+
}
|
|
2275
|
+
} else {
|
|
2276
|
+
{
|
|
2277
|
+
let skip = [];
|
|
2278
|
+
let i = 0;
|
|
2279
|
+
let every = ((kind === "and") ? (!__eliscript_truthy(when_true)) : when_true);
|
|
2280
|
+
while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
|
|
2281
|
+
{
|
|
2282
|
+
let last = (i === __eliscript_numeric_decrement(((children) ?? []).length));
|
|
2283
|
+
let output = ((__eliscript_truthy(every) || __eliscript_truthy(last)) ? jumps : skip);
|
|
2284
|
+
let positions = memory_condition_jumps(state, ((((children) ?? [])[i]) ?? null), ((__eliscript_truthy(every) || __eliscript_truthy(last)) ? when_true : (!__eliscript_truthy(when_true))));
|
|
2285
|
+
let j = 0;
|
|
2286
|
+
while (__eliscript_numeric_relation("<", j, ((positions) ?? []).length)) {
|
|
2287
|
+
(output)["push"](((((positions) ?? [])[j]) ?? null));
|
|
2288
|
+
((j = (j + 1)));
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
((i = (i + 1)));
|
|
2292
|
+
}
|
|
2293
|
+
if ((((children) ?? []).length === 0)) {
|
|
2294
|
+
if ((when_true === (kind === "and"))) {
|
|
2295
|
+
(jumps)["push"](jump(state, "jump"));
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
patch_conditions(state, skip, (((state)["words"]) ?? []).length);
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
} else {
|
|
2303
|
+
if ((__eliscript_truthy(opt) && ((kind === "word-compare") || (kind === "v64-compare")) && (((children) ?? []).length === 2))) {
|
|
2304
|
+
{
|
|
2305
|
+
let name = (node)["value"];
|
|
2306
|
+
let code = memory_word_compare_code(name);
|
|
2307
|
+
let left = ((((children) ?? [])[0]) ?? null);
|
|
2308
|
+
let right = ((((children) ?? [])[1]) ?? null);
|
|
2309
|
+
let lv = ((kind === "word-compare") ? memory_word_lit_val(left) : -1);
|
|
2310
|
+
let rv = ((kind === "word-compare") ? memory_word_lit_val(right) : -1);
|
|
2311
|
+
if (((kind === "word-compare") && ((name === "=") || (name === "/=")) && ((rv === 0) || (rv === 1)) && __eliscript_truthy(memory_bool01_p(left)))) {
|
|
2312
|
+
{
|
|
2313
|
+
let want_one = (rv === 1);
|
|
2314
|
+
let flip = ((name === "=") ? (!__eliscript_truthy(want_one)) : want_one);
|
|
2315
|
+
((jumps = memory_bool01_jumps(state, left, (__eliscript_truthy(flip) ? (!__eliscript_truthy(when_true)) : when_true))));
|
|
2316
|
+
}
|
|
2317
|
+
} else {
|
|
2318
|
+
if (((kind === "word-compare") && ((name === "=") || (name === "/=")) && ((lv === 0) || (lv === 1)) && __eliscript_truthy(memory_bool01_p(right)))) {
|
|
2319
|
+
{
|
|
2320
|
+
let want_one = (lv === 1);
|
|
2321
|
+
let flip = ((name === "=") ? (!__eliscript_truthy(want_one)) : want_one);
|
|
2322
|
+
((jumps = memory_bool01_jumps(state, right, (__eliscript_truthy(flip) ? (!__eliscript_truthy(when_true)) : when_true))));
|
|
2323
|
+
}
|
|
2324
|
+
} else {
|
|
2325
|
+
if ((kind === "word-compare")) {
|
|
2326
|
+
{
|
|
2327
|
+
let imm = memory_word_imm12(right);
|
|
2328
|
+
let rL = (__eliscript_truthy(memory_word_type((left)["type"])) ? local_register(state, left, "u32") : -1);
|
|
2329
|
+
let rR = (__eliscript_truthy(memory_word_type((right)["type"])) ? local_register(state, right, "u32") : -1);
|
|
2330
|
+
if (__eliscript_numeric_relation(">=", imm, 0)) {
|
|
2331
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
2332
|
+
expression(state, left);
|
|
2333
|
+
}
|
|
2334
|
+
word(state, (1895825439 + __eliscript_numeric_mul(imm, 1024) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
2335
|
+
} else {
|
|
2336
|
+
if (__eliscript_numeric_relation(">=", rR, 0)) {
|
|
2337
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
2338
|
+
expression(state, left);
|
|
2339
|
+
}
|
|
2340
|
+
word(state, (1795162143 + __eliscript_numeric_mul(rR, 65536) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
2341
|
+
} else {
|
|
2342
|
+
if ((__eliscript_numeric_relation(">=", rL, 0) && !(__eliscript_truthy(memory_expr_writes_reg_p(state, right, rL))))) {
|
|
2343
|
+
expression(state, right);
|
|
2344
|
+
word(state, (1795162143 + __eliscript_numeric_mul(rL, 32)));
|
|
2345
|
+
} else {
|
|
2346
|
+
expression(state, left);
|
|
2347
|
+
if ((__eliscript_truthy(((state)["memory"] ?? null)) && !(__eliscript_truthy(((state)["compact"] ?? null))) && !(__eliscript_truthy(((state)["leaf"] ?? null))) && __eliscript_truthy(memory_word_type((right)["type"])) && (((right)["kind"] === "literal") || ((right)["kind"] === "int-literal") || ((right)["kind"] === "local")))) {
|
|
2348
|
+
word(state, 704644065);
|
|
2349
|
+
expression(state, right);
|
|
2350
|
+
} else {
|
|
2351
|
+
push_value(state, "u32");
|
|
2352
|
+
expression(state, right);
|
|
2353
|
+
pop_value(state, "u32");
|
|
2354
|
+
}
|
|
2355
|
+
word(state, 1795162175);
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
} else {
|
|
2361
|
+
{
|
|
2362
|
+
let wimm = memory_wide_imm12(right);
|
|
2363
|
+
let rL = (__eliscript_truthy(memory_wide_type((left)["type"])) ? local_register(state, left, "v64") : -1);
|
|
2364
|
+
let rR = (__eliscript_truthy(memory_wide_type((right)["type"])) ? local_register(state, right, "v64") : -1);
|
|
2365
|
+
if (!((wimm === null))) {
|
|
2366
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
2367
|
+
expression(state, left);
|
|
2368
|
+
}
|
|
2369
|
+
word(state, (4043309087 + __eliscript_numeric_mul(wimm, 1024) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
2370
|
+
} else {
|
|
2371
|
+
if (__eliscript_numeric_relation(">=", rR, 0)) {
|
|
2372
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
2373
|
+
expression(state, left);
|
|
2374
|
+
}
|
|
2375
|
+
word(state, (3942645791 + __eliscript_numeric_mul(rR, 65536) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
2376
|
+
} else {
|
|
2377
|
+
if ((__eliscript_numeric_relation(">=", rL, 0) && !(__eliscript_truthy(memory_expr_writes_reg_p(state, right, rL))))) {
|
|
2378
|
+
expression(state, right);
|
|
2379
|
+
word(state, (3942645791 + __eliscript_numeric_mul(rL, 32)));
|
|
2380
|
+
} else {
|
|
2381
|
+
memory_wide_operands(state, left, right);
|
|
2382
|
+
word(state, 3942645823);
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
(jumps)["push"]((((state)["words"]) ?? []).length);
|
|
2389
|
+
word(state, (1409286144 + (__eliscript_truthy(when_true) ? code : __eliscript_numeric_xor(code, 1))));
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
} else {
|
|
2394
|
+
condition(state, node);
|
|
2395
|
+
(jumps)["push"](jump(state, (__eliscript_truthy(when_true) ? "nonzero" : "zero")));
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
return jumps;
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
function emit_loop(state, children, used) {
|
|
2405
|
+
if (__eliscript_truthy(((state)["compact"] ?? null))) {
|
|
2406
|
+
{
|
|
2407
|
+
let initial = jump(state, "jump");
|
|
2408
|
+
let start = (((state)["words"]) ?? []).length;
|
|
2409
|
+
discarded(state, ((((children) ?? [])[1]) ?? null));
|
|
2410
|
+
patch_jump(state, initial, (((state)["words"]) ?? []).length);
|
|
2411
|
+
patch_conditions(state, condition_jumps(state, ((((children) ?? [])[0]) ?? null), true), start);
|
|
2412
|
+
if (__eliscript_truthy(used)) {
|
|
2413
|
+
return integer_register(state, 0, 0, 0);
|
|
2414
|
+
} else {
|
|
2415
|
+
return null;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
} else {
|
|
2419
|
+
{
|
|
2420
|
+
let start = (((state)["words"]) ?? []).length;
|
|
1635
2421
|
{
|
|
1636
|
-
let end =
|
|
2422
|
+
let end = (__eliscript_truthy(((state)["memory"] ?? null)) ? memory_condition_jumps(state, ((((children) ?? [])[0]) ?? null), null) : (() => {
|
|
2423
|
+
condition(state, ((((children) ?? [])[0]) ?? null));
|
|
2424
|
+
return [jump(state, "zero")];
|
|
2425
|
+
})());
|
|
1637
2426
|
if (__eliscript_truthy(((state)["memory"] ?? null))) {
|
|
1638
2427
|
memory_discarded(state, ((((children) ?? [])[1]) ?? null));
|
|
1639
2428
|
} else {
|
|
@@ -1643,7 +2432,7 @@ function emit_loop(state, children, used) {
|
|
|
1643
2432
|
let back = jump(state, "jump");
|
|
1644
2433
|
patch_jump(state, back, start);
|
|
1645
2434
|
}
|
|
1646
|
-
|
|
2435
|
+
patch_conditions(state, end, (((state)["words"]) ?? []).length);
|
|
1647
2436
|
if (__eliscript_truthy(((state)["memory"] ?? null))) {
|
|
1648
2437
|
if (__eliscript_truthy(used)) {
|
|
1649
2438
|
return memory_integer_register(state, 0, 0);
|
|
@@ -1743,6 +2532,37 @@ function expression(state, node, unused = null, local_target = null) {
|
|
|
1743
2532
|
function memory_discarded(state, node) {
|
|
1744
2533
|
return expression(state, node, true);
|
|
1745
2534
|
}
|
|
2535
|
+
const native_single_sink_rd0_ops = new (globalThis.Set)(["load-u8", "load-u16", "load-u32", "load-v64", "load-bits64", "v64-low", "bits64-low", "v64-high", "bits64-high", "v64-from-u32", "v64-pack", "bits64-pack", "word-and", "word-or", "word-xor", "word-div", "v64-add", "v64-sub", "v64-and", "v64-or", "v64-xor", "v64-shl", "v64-shr", "bits64-add", "bits64-sub", "bits64-and", "bits64-or", "bits64-xor", "bits64-shl", "bits64-shr"]);
|
|
2536
|
+
__eliscript_tdz_ready_0 = true;
|
|
2537
|
+
function memory_single_sink_rd0_p(node) {
|
|
2538
|
+
{
|
|
2539
|
+
let kind = (node)["kind"];
|
|
2540
|
+
let val = (node)["value"];
|
|
2541
|
+
let children = (node)["children"];
|
|
2542
|
+
if ((kind === "word-arithmetic")) {
|
|
2543
|
+
return __eliscript_numeric_relation(">", ((children) ?? []).length, 0);
|
|
2544
|
+
} else {
|
|
2545
|
+
if ((kind === "memory-op")) {
|
|
2546
|
+
if (__eliscript_truthy(((__eliscript_tdz_ready_0 === true ? native_single_sink_rd0_ops : __eliscript_tdz_error("native_single_sink_rd0_ops")))["has"](val))) {
|
|
2547
|
+
return true;
|
|
2548
|
+
} else {
|
|
2549
|
+
if ((((val === "word-shl") || (val === "word-shr")) && (((children) ?? []).length === 2))) {
|
|
2550
|
+
{
|
|
2551
|
+
let c1 = ((((children) ?? [])[1]) ?? null);
|
|
2552
|
+
let ck = (c1)["kind"];
|
|
2553
|
+
let cv = (c1)["value"];
|
|
2554
|
+
return (!(((ck === "literal") || (ck === "int-literal")) && (__eliscript_value_type(cv) === "number") && (__eliscript_numeric_uint32(cv) === 0)));
|
|
2555
|
+
}
|
|
2556
|
+
} else {
|
|
2557
|
+
return null;
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
} else {
|
|
2561
|
+
return null;
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
1746
2566
|
function memory_discarded_body(state, node) {
|
|
1747
2567
|
{
|
|
1748
2568
|
let kind = (node)["kind"];
|
|
@@ -1751,30 +2571,95 @@ function memory_discarded_body(state, node) {
|
|
|
1751
2571
|
if (((kind === "literal") || (kind === "int-literal") || (kind === "local"))) {
|
|
1752
2572
|
return null;
|
|
1753
2573
|
} else {
|
|
1754
|
-
if (((kind === "
|
|
1755
|
-
|
|
1756
|
-
memory_discarded(state, ((((children) ?? [])[i]) ?? null));
|
|
1757
|
-
((i = (i + 1)));
|
|
1758
|
-
}
|
|
1759
|
-
return null;
|
|
2574
|
+
if (((kind === "memory-op") && __eliscript_numeric_relation(">", memory_width((node)["value"]), 0) && (((children) ?? []).length === 2))) {
|
|
2575
|
+
return memory_operation(state, node, true);
|
|
1760
2576
|
} else {
|
|
1761
|
-
if ((kind === "
|
|
1762
|
-
condition(state, ((((children) ?? [])[0]) ?? null));
|
|
2577
|
+
if ((((kind === "set") || (kind === "initialize")) && !(__eliscript_truthy(((state)["debugRanges"] ?? null))) && !(((node)["type"] === "f64")))) {
|
|
1763
2578
|
{
|
|
1764
|
-
let
|
|
1765
|
-
|
|
1766
|
-
{
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
2579
|
+
let rhs = ((((children) ?? [])[0]) ?? null);
|
|
2580
|
+
let ltype = (node)["type"];
|
|
2581
|
+
let dst_raw = ((regs, idx) => {
|
|
2582
|
+
if (__eliscript_numeric_relation("<", idx, ((regs) ?? []).length)) {
|
|
2583
|
+
return ((((regs) ?? [])[idx]) ?? null);
|
|
2584
|
+
} else {
|
|
2585
|
+
return -1;
|
|
2586
|
+
}
|
|
2587
|
+
})((state)["registers"], (node)["value"]);
|
|
2588
|
+
let dst_reg = (__eliscript_numeric_relation("<=", dst_raw, -2) ? __eliscript_numeric_sub(__eliscript_numeric_neg(dst_raw), 2) : -1);
|
|
2589
|
+
let rk = (rhs)["kind"];
|
|
2590
|
+
let rv = (rhs)["value"];
|
|
2591
|
+
if (((rk === "local") && __eliscript_truthy(memory_same_abi_type(ltype, (rhs)["type"])))) {
|
|
2592
|
+
{
|
|
2593
|
+
let src_reg = local_register(state, rhs, ltype);
|
|
2594
|
+
if (__eliscript_numeric_relation(">=", src_reg, 0)) {
|
|
2595
|
+
if ((!(src_reg === dst_reg))) {
|
|
2596
|
+
return local_access(state, (node)["value"], ltype, true, src_reg);
|
|
2597
|
+
} else {
|
|
2598
|
+
return null;
|
|
2599
|
+
}
|
|
2600
|
+
} else {
|
|
2601
|
+
return expression_body(state, node);
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
} else {
|
|
2605
|
+
if ((__eliscript_numeric_relation(">=", dst_reg, 0) && ((rk === "literal") || (rk === "int-literal")) && __eliscript_truthy((__eliscript_truthy(memory_wide_type(ltype)) ? ((__eliscript_value_11) => (__eliscript_truthy(__eliscript_value_11) ? ((__eliscript_value_type(rv) === "number") || ((!(rv === null)) && (__eliscript_value_type(rv) === "object"))) : __eliscript_value_11))(memory_wide_type((rhs)["type"])) : ((__eliscript_value_12) => (__eliscript_truthy(__eliscript_value_12) ? ((__eliscript_value_13) => (__eliscript_truthy(__eliscript_value_13) ? ((__eliscript_value_14) => (__eliscript_truthy(__eliscript_value_14) ? Number.isInteger(rv) : __eliscript_value_14))((__eliscript_value_type(rv) === "number")) : __eliscript_value_13))(memory_word_type((rhs)["type"])) : __eliscript_value_12))(memory_word_type(ltype)))))) {
|
|
2606
|
+
if (__eliscript_truthy(memory_wide_type(ltype))) {
|
|
2607
|
+
if ((!((rv === null)) && (__eliscript_value_type(rv) === "object"))) {
|
|
2608
|
+
return memory_wide_register(state, dst_reg, __eliscript_numeric_uint32((rv)["low"]), __eliscript_numeric_uint32((rv)["high"]));
|
|
2609
|
+
} else {
|
|
2610
|
+
return memory_wide_register(state, dst_reg, __eliscript_numeric_uint32(rv), 0);
|
|
2611
|
+
}
|
|
2612
|
+
} else {
|
|
2613
|
+
return memory_integer_register(state, dst_reg, rv);
|
|
2614
|
+
}
|
|
2615
|
+
} else {
|
|
2616
|
+
if (((dst_reg === -1) && ((rk === "literal") || (rk === "int-literal")) && __eliscript_truthy((__eliscript_truthy(memory_wide_type(ltype)) ? ((!((rv === null)) && (__eliscript_value_type(rv) === "object")) ? (((rv)["low"] === 0) && ((rv)["high"] === 0)) : (rv === 0)) : (rv === 0))))) {
|
|
2617
|
+
return local_access(state, (node)["value"], ltype, true, 31);
|
|
2618
|
+
} else {
|
|
2619
|
+
if ((__eliscript_numeric_relation(">=", dst_reg, 0) && __eliscript_truthy(memory_same_abi_type(ltype, (rhs)["type"])) && __eliscript_truthy(memory_single_sink_rd0_p(rhs)))) {
|
|
2620
|
+
expression(state, rhs);
|
|
2621
|
+
{
|
|
2622
|
+
let words = (state)["words"];
|
|
2623
|
+
let wlen = ((words) ?? []).length;
|
|
2624
|
+
if ((__eliscript_numeric_relation(">", wlen, 0) && (__eliscript_numeric_and(native_word_at(words, __eliscript_numeric_decrement(wlen)), 31) === 0))) {
|
|
2625
|
+
return retarget_last(state, dst_reg);
|
|
2626
|
+
} else {
|
|
2627
|
+
return local_access(state, (node)["value"], ltype, true);
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
} else {
|
|
2631
|
+
return expression_body(state, node);
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
1771
2635
|
}
|
|
1772
2636
|
}
|
|
1773
2637
|
} else {
|
|
1774
|
-
if (((kind === "
|
|
1775
|
-
|
|
2638
|
+
if (((kind === "sequence") || (((kind === "word-compare") || (kind === "v64-compare")) && (((children) ?? []).length === 2)) || ((kind === "word-arithmetic") && __eliscript_numeric_relation("<=", ((children) ?? []).length, 2) && __eliscript_truthy((["+", "-", "*", "1+", "1-"])["includes"]((node)["value"]))))) {
|
|
2639
|
+
while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
|
|
2640
|
+
memory_discarded(state, ((((children) ?? [])[i]) ?? null));
|
|
2641
|
+
((i = (i + 1)));
|
|
2642
|
+
}
|
|
2643
|
+
return null;
|
|
1776
2644
|
} else {
|
|
1777
|
-
|
|
2645
|
+
if ((kind === "if")) {
|
|
2646
|
+
{
|
|
2647
|
+
let otherwise = memory_condition_jumps(state, ((((children) ?? [])[0]) ?? null), null);
|
|
2648
|
+
memory_discarded(state, ((((children) ?? [])[1]) ?? null));
|
|
2649
|
+
{
|
|
2650
|
+
let end = jump(state, "jump");
|
|
2651
|
+
patch_conditions(state, otherwise, (((state)["words"]) ?? []).length);
|
|
2652
|
+
memory_discarded(state, ((((children) ?? [])[2]) ?? null));
|
|
2653
|
+
return patch_jump(state, end, (((state)["words"]) ?? []).length);
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
} else {
|
|
2657
|
+
if (((kind === "while") || (kind === "remainder-while") || (kind === "guarded-while"))) {
|
|
2658
|
+
return emit_loop(state, children, null);
|
|
2659
|
+
} else {
|
|
2660
|
+
return expression_body(state, node);
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
1778
2663
|
}
|
|
1779
2664
|
}
|
|
1780
2665
|
}
|
|
@@ -1934,10 +2819,10 @@ function expression_body(state, node, local_target = null) {
|
|
|
1934
2819
|
} else {
|
|
1935
2820
|
if ((kind === "if")) {
|
|
1936
2821
|
{
|
|
1937
|
-
let otherwise = (__eliscript_truthy(((state)["compact"] ?? null)) ? condition_jumps(state, ((((children) ?? [])[0]) ?? null), null) : (() => {
|
|
2822
|
+
let otherwise = (__eliscript_truthy(((state)["compact"] ?? null)) ? condition_jumps(state, ((((children) ?? [])[0]) ?? null), null) : (__eliscript_truthy(((state)["memory"] ?? null)) ? memory_condition_jumps(state, ((((children) ?? [])[0]) ?? null), null) : (() => {
|
|
1938
2823
|
condition(state, ((((children) ?? [])[0]) ?? null));
|
|
1939
2824
|
return [jump(state, "zero")];
|
|
1940
|
-
})());
|
|
2825
|
+
})()));
|
|
1941
2826
|
expression(state, ((((children) ?? [])[1]) ?? null));
|
|
1942
2827
|
{
|
|
1943
2828
|
let end = jump(state, "jump");
|
|
@@ -2004,7 +2889,7 @@ function expression_body(state, node, local_target = null) {
|
|
|
2004
2889
|
}
|
|
2005
2890
|
function typed_code(program, options = null) {
|
|
2006
2891
|
{
|
|
2007
|
-
let compact = ((((
|
|
2892
|
+
let compact = ((((__eliscript_value_15) => (__eliscript_truthy(__eliscript_value_15) ? __eliscript_value_15 : ({})))(options))["registerAllocation"] ?? true);
|
|
2008
2893
|
let state = ({"words": [], "calls": [], "constants": [], "compact": compact});
|
|
2009
2894
|
let functions = (program)["functions"];
|
|
2010
2895
|
let offsets = [];
|
|
@@ -2104,7 +2989,7 @@ function typed_code(program, options = null) {
|
|
|
2104
2989
|
}
|
|
2105
2990
|
function native_program_ro_bytes(program, options) {
|
|
2106
2991
|
{
|
|
2107
|
-
let ro_data = ((
|
|
2992
|
+
let ro_data = ((__eliscript_value_16) => (__eliscript_truthy(__eliscript_value_16) ? __eliscript_value_16 : ((((__eliscript_value_17) => (__eliscript_truthy(__eliscript_value_17) ? __eliscript_value_17 : ({})))(options))["roData"] ?? null)))(((program)["roData"] ?? null));
|
|
2108
2993
|
if ((__eliscript_truthy(ro_data) && !((((ro_data)["bytes"] ?? null) === null)) && __eliscript_numeric_relation(">", (((ro_data)["bytes"]) ?? []).length, 0))) {
|
|
2109
2994
|
return (ro_data)["bytes"];
|
|
2110
2995
|
} else {
|
|
@@ -2216,7 +3101,7 @@ function emit_native_numeric_object(program, target, options = null) {
|
|
|
2216
3101
|
}
|
|
2217
3102
|
lower_numeric_program(program);
|
|
2218
3103
|
{
|
|
2219
|
-
let typed_program = optimize_numeric_program(lower_numeric_program(optimize_program(program)), ({"unswitch": ((((
|
|
3104
|
+
let typed_program = optimize_numeric_program(lower_numeric_program(optimize_program(program)), ({"unswitch": ((((__eliscript_value_18) => (__eliscript_truthy(__eliscript_value_18) ? __eliscript_value_18 : ({})))(options))["registerAllocation"] ?? true), "constantFlow": ((((__eliscript_value_19) => (__eliscript_truthy(__eliscript_value_19) ? __eliscript_value_19 : ({})))(options))["registerAllocation"] ?? true), "parallelSingle": ((((__eliscript_value_20) => (__eliscript_truthy(__eliscript_value_20) ? __eliscript_value_20 : ({})))(options))["registerAllocation"] ?? true), "cyclicMultiple": ((((__eliscript_value_21) => (__eliscript_truthy(__eliscript_value_21) ? __eliscript_value_21 : ({})))(options))["registerAllocation"] ?? true)}));
|
|
2220
3105
|
if ((target === "arm64-linux")) {
|
|
2221
3106
|
return emit_elf_object(typed_program, typed_code(typed_program, options), options);
|
|
2222
3107
|
} else {
|
|
@@ -2241,15 +3126,16 @@ function export_trie(program, offsets) {
|
|
|
2241
3126
|
{
|
|
2242
3127
|
let root = ({"children": [], "address": -1, "offset": 0});
|
|
2243
3128
|
let functions = (program)["functions"];
|
|
3129
|
+
let export_set = new (globalThis.Set)((program)["exports"]);
|
|
2244
3130
|
let nodes = [];
|
|
2245
3131
|
let i = 0;
|
|
2246
3132
|
while (__eliscript_numeric_relation("<", i, ((functions) ?? []).length)) {
|
|
2247
|
-
if (__eliscript_truthy((
|
|
3133
|
+
if (__eliscript_truthy((export_set)["has"](((functions)[i])["name"]))) {
|
|
2248
3134
|
{
|
|
2249
3135
|
let bytes = [];
|
|
2250
3136
|
let node = root;
|
|
2251
3137
|
let j = 0;
|
|
2252
|
-
string_bytes(bytes, (String("_") + String(((
|
|
3138
|
+
string_bytes(bytes, (String("_") + String(((functions)[i])["name"])));
|
|
2253
3139
|
while (__eliscript_numeric_relation("<", j, __eliscript_numeric_decrement(((bytes) ?? []).length))) {
|
|
2254
3140
|
{
|
|
2255
3141
|
let edges = (node)["children"];
|
|
@@ -2365,6 +3251,8 @@ function be64(output, value) {
|
|
|
2365
3251
|
be32(output, __eliscript_numeric_uint32(__eliscript_numeric_div(value, 4294967296)));
|
|
2366
3252
|
return be32(output, __eliscript_numeric_uint32(value));
|
|
2367
3253
|
}
|
|
3254
|
+
const page_sha256_cache = new (globalThis.Map)();
|
|
3255
|
+
__eliscript_tdz_ready_1 = true;
|
|
2368
3256
|
function page_signature(image, executable_size, main) {
|
|
2369
3257
|
{
|
|
2370
3258
|
let identifier = [];
|
|
@@ -2372,6 +3260,8 @@ function page_signature(image, executable_size, main) {
|
|
|
2372
3260
|
let pages = (globalThis.Math)["ceil"](__eliscript_numeric_div(limit, 4096));
|
|
2373
3261
|
let directory = [];
|
|
2374
3262
|
let output = [];
|
|
3263
|
+
let chunks = (__eliscript_truthy(Array.isArray(image)) ? null : ((image)["chunks"] ?? null));
|
|
3264
|
+
let chunk_count = (__eliscript_truthy(Array.isArray(chunks)) ? ((chunks) ?? []).length : 0);
|
|
2375
3265
|
string_bytes(identifier, "eliscript-native");
|
|
2376
3266
|
{
|
|
2377
3267
|
let hash_offset = (88 + ((identifier) ?? []).length);
|
|
@@ -2397,7 +3287,27 @@ function page_signature(image, executable_size, main) {
|
|
|
2397
3287
|
{
|
|
2398
3288
|
let i = 0;
|
|
2399
3289
|
while (__eliscript_numeric_relation("<", i, pages)) {
|
|
2400
|
-
|
|
3290
|
+
{
|
|
3291
|
+
let chunk = (__eliscript_numeric_relation("<", i, chunk_count) ? (chunks)[i] : null);
|
|
3292
|
+
let digest = (((__eliscript_value_type(chunk) === "string") && (((chunk) ?? []).length === 2048)) ? ((cached_digest) => {
|
|
3293
|
+
if (__eliscript_truthy(cached_digest)) {
|
|
3294
|
+
return cached_digest;
|
|
3295
|
+
} else {
|
|
3296
|
+
{
|
|
3297
|
+
let computed = sha256_string_utf16le(chunk);
|
|
3298
|
+
if (__eliscript_numeric_relation("<", ((__eliscript_tdz_ready_1 === true ? page_sha256_cache : __eliscript_tdz_error("page_sha256_cache")))["size"], 4096)) {
|
|
3299
|
+
((__eliscript_tdz_ready_1 === true ? page_sha256_cache : __eliscript_tdz_error("page_sha256_cache")))["set"](chunk, computed);
|
|
3300
|
+
}
|
|
3301
|
+
return computed;
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
})(((__eliscript_tdz_ready_1 === true ? page_sha256_cache : __eliscript_tdz_error("page_sha256_cache")))["get"](chunk)) : sha256_bytes(binary_slice(image, __eliscript_numeric_mul(i, 4096), __eliscript_numeric_mul((i + 1), 4096))));
|
|
3305
|
+
let k = 0;
|
|
3306
|
+
while (__eliscript_numeric_relation("<", k, 32)) {
|
|
3307
|
+
(directory)["push"]((digest)[k]);
|
|
3308
|
+
((k = (k + 1)));
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
2401
3311
|
((i = (i + 1)));
|
|
2402
3312
|
}
|
|
2403
3313
|
}
|
|
@@ -2424,11 +3334,14 @@ function macho_library(program, code, entry = null, options = null) {
|
|
|
2424
3334
|
let text_end = (__eliscript_truthy(has_ro) ? (ro_file_offset + ro_len) : (4096 + size));
|
|
2425
3335
|
let text_size = align_size(text_end, 16384);
|
|
2426
3336
|
let trie = export_trie(program, offsets);
|
|
3337
|
+
let export_set = new (globalThis.Set)((program)["exports"]);
|
|
2427
3338
|
let symbols = [];
|
|
2428
3339
|
let strings = [0];
|
|
2429
3340
|
let local_count = 0;
|
|
3341
|
+
let want_packed = ((!(options === null)) && (((options)["binaryEncoding"] ?? null) === "u16le-chunks"));
|
|
3342
|
+
let _check_encoding = ((!((options === null)) && __eliscript_truthy(Object.hasOwn(options, "binaryEncoding")) && !(__eliscript_truthy(want_packed))) ? binary_output(options) : null);
|
|
2430
3343
|
let commands = [];
|
|
2431
|
-
let image = binary_output(
|
|
3344
|
+
let image = binary_output(({"binaryEncoding": "u16le-chunks"}));
|
|
2432
3345
|
let i = 0;
|
|
2433
3346
|
{
|
|
2434
3347
|
let pass = 0;
|
|
@@ -2438,12 +3351,12 @@ function macho_library(program, code, entry = null, options = null) {
|
|
|
2438
3351
|
((i = 0));
|
|
2439
3352
|
while (__eliscript_numeric_relation("<", i, ((functions) ?? []).length)) {
|
|
2440
3353
|
{
|
|
2441
|
-
let function$ = (
|
|
2442
|
-
let public$ = (
|
|
3354
|
+
let function$ = (functions)[i];
|
|
3355
|
+
let public$ = (export_set)["has"]((function$)["name"]);
|
|
2443
3356
|
if (__eliscript_truthy((__eliscript_truthy(public$) ? external : (!__eliscript_truthy(external))))) {
|
|
2444
3357
|
u32(symbols, ((strings) ?? []).length);
|
|
2445
3358
|
(symbols)["push"]((__eliscript_truthy(public$) ? 15 : 14), 1, 0, 0);
|
|
2446
|
-
u64(symbols, ((__eliscript_truthy(entry) ? 4294967296 : 0) + 4096 + (
|
|
3359
|
+
u64(symbols, ((__eliscript_truthy(entry) ? 4294967296 : 0) + 4096 + (offsets)[i]));
|
|
2447
3360
|
string_bytes(strings, (String("_") + String((function$)["name"])));
|
|
2448
3361
|
if ((!__eliscript_truthy(public$))) {
|
|
2449
3362
|
((local_count = (local_count + 1)));
|
|
@@ -2534,8 +3447,11 @@ function macho_library(program, code, entry = null, options = null) {
|
|
|
2534
3447
|
dylib_command(commands, 12, "/usr/lib/libSystem.B.dylib");
|
|
2535
3448
|
u32(commands, 27);
|
|
2536
3449
|
u32(commands, 24);
|
|
3450
|
+
if ((!__eliscript_truthy(Array.isArray(words)))) {
|
|
3451
|
+
native_word_flush(words);
|
|
3452
|
+
}
|
|
2537
3453
|
{
|
|
2538
|
-
let word_digest = sha256_words_le(words, (__eliscript_truthy(Array.isArray(words)) ? null : native_word_at));
|
|
3454
|
+
let word_digest = sha256_words_le(words, ((__eliscript_truthy(Array.isArray(words)) || (__eliscript_truthy(Array.isArray(((words)["chunks"] ?? null))) && !(__eliscript_truthy(((words)["dirty"] ?? null))) && !(__eliscript_truthy(((words)["hasHole"] ?? null))))) ? null : native_word_at));
|
|
2539
3455
|
append(commands, ((__eliscript_truthy(has_ro) ? ((combined) => {
|
|
2540
3456
|
append(combined, sha256_bytes(ro_bytes));
|
|
2541
3457
|
return sha256_bytes(combined);
|
|
@@ -2605,7 +3521,11 @@ function macho_library(program, code, entry = null, options = null) {
|
|
|
2605
3521
|
if (__eliscript_truthy(has_ro)) {
|
|
2606
3522
|
((code)["roDataSection"] = ({"name": "__const", "segment": "__TEXT", "fileOffset": ro_file_offset, "virtualAddress": ((__eliscript_truthy(entry) ? 4294967296 : 0) + ro_file_offset), "size": ro_len, "align": 8}));
|
|
2607
3523
|
}
|
|
2608
|
-
|
|
3524
|
+
if (__eliscript_truthy(want_packed)) {
|
|
3525
|
+
return binary_finish(image);
|
|
3526
|
+
} else {
|
|
3527
|
+
return binary_to_array(image);
|
|
3528
|
+
}
|
|
2609
3529
|
}
|
|
2610
3530
|
}
|
|
2611
3531
|
}
|
|
@@ -2615,7 +3535,7 @@ function emit_native_numeric_library(program, target, options = null) {
|
|
|
2615
3535
|
}
|
|
2616
3536
|
lower_numeric_program(program);
|
|
2617
3537
|
{
|
|
2618
|
-
let typed_program = optimize_numeric_program(lower_numeric_program(optimize_program(program)), ({"unswitch": ((((
|
|
3538
|
+
let typed_program = optimize_numeric_program(lower_numeric_program(optimize_program(program)), ({"unswitch": ((((__eliscript_value_22) => (__eliscript_truthy(__eliscript_value_22) ? __eliscript_value_22 : ({})))(options))["registerAllocation"] ?? true), "constantFlow": ((((__eliscript_value_23) => (__eliscript_truthy(__eliscript_value_23) ? __eliscript_value_23 : ({})))(options))["registerAllocation"] ?? true), "parallelSingle": ((((__eliscript_value_24) => (__eliscript_truthy(__eliscript_value_24) ? __eliscript_value_24 : ({})))(options))["registerAllocation"] ?? true), "cyclicMultiple": ((((__eliscript_value_25) => (__eliscript_truthy(__eliscript_value_25) ? __eliscript_value_25 : ({})))(options))["registerAllocation"] ?? true)}));
|
|
2619
3539
|
if ((target === "arm64-linux")) {
|
|
2620
3540
|
return emit_elf_library(typed_program, typed_code(typed_program, options), options);
|
|
2621
3541
|
} else {
|
|
@@ -2629,7 +3549,7 @@ function emit_native_numeric_executable(program, target, entry, options = null)
|
|
|
2629
3549
|
}
|
|
2630
3550
|
lower_numeric_program(program);
|
|
2631
3551
|
{
|
|
2632
|
-
let typed_program = optimize_numeric_program(lower_numeric_program(optimize_program(program)), ({"unswitch": ((((
|
|
3552
|
+
let typed_program = optimize_numeric_program(lower_numeric_program(optimize_program(program)), ({"unswitch": ((((__eliscript_value_26) => (__eliscript_truthy(__eliscript_value_26) ? __eliscript_value_26 : ({})))(options))["registerAllocation"] ?? true), "constantFlow": ((((__eliscript_value_27) => (__eliscript_truthy(__eliscript_value_27) ? __eliscript_value_27 : ({})))(options))["registerAllocation"] ?? true), "parallelSingle": ((((__eliscript_value_28) => (__eliscript_truthy(__eliscript_value_28) ? __eliscript_value_28 : ({})))(options))["registerAllocation"] ?? true), "cyclicMultiple": ((((__eliscript_value_29) => (__eliscript_truthy(__eliscript_value_29) ? __eliscript_value_29 : ({})))(options))["registerAllocation"] ?? true)}));
|
|
2633
3553
|
let function$ = find_function((typed_program)["functions"], entry);
|
|
2634
3554
|
if ((!(__eliscript_truthy(function$) && ((function$)["arity"] === 0) && __eliscript_truthy(((typed_program)["exports"])["includes"](entry))))) {
|
|
2635
3555
|
backend_fail(program, "native executable entry must be an exported zero-argument f64 function");
|
|
@@ -2675,11 +3595,14 @@ function memory_error(state, code) {
|
|
|
2675
3595
|
{
|
|
2676
3596
|
let sites = ((state)["trapSites"] ?? null);
|
|
2677
3597
|
if (__eliscript_truthy(sites)) {
|
|
2678
|
-
memory_integer_register(state, 9, (((sites) ?? []).length + 1));
|
|
2679
3598
|
{
|
|
2680
|
-
let
|
|
2681
|
-
(
|
|
2682
|
-
|
|
3599
|
+
let site_id = (((state)["trapSiteBase"] ?? 0) + (((sites) ?? []).length + 1));
|
|
3600
|
+
memory_integer_register(state, 9, site_id);
|
|
3601
|
+
{
|
|
3602
|
+
let range = ({"kind": "trap-site", "function": (state)["debugFunction"], "functionIndex": (state)["debugFunctionIndex"], "depth": ((state)["debugDepth"] ?? 0), "start": __eliscript_numeric_mul(4, (((state)["words"]) ?? []).length), "end": (4 + __eliscript_numeric_mul(4, (((state)["words"]) ?? []).length)), "span": null, "code": code, "site": site_id});
|
|
3603
|
+
(sites)["push"](range);
|
|
3604
|
+
((state)["debugRanges"])["push"](range);
|
|
3605
|
+
}
|
|
2683
3606
|
}
|
|
2684
3607
|
word(state, 3103792745);
|
|
2685
3608
|
}
|
|
@@ -2770,6 +3693,8 @@ function memory_word(state, node) {
|
|
|
2770
3693
|
let children = (node)["children"];
|
|
2771
3694
|
let count = ((children) ?? []).length;
|
|
2772
3695
|
let name = (node)["value"];
|
|
3696
|
+
let opt = ((__eliscript_value_30) => (__eliscript_truthy(__eliscript_value_30) ? ((state)["optimizeMemory"] ?? null) : __eliscript_value_30))(((state)["memory"] ?? null));
|
|
3697
|
+
let no_debug = (!__eliscript_truthy(((state)["debugRanges"] ?? null)));
|
|
2773
3698
|
if ((count === 0)) {
|
|
2774
3699
|
if (__eliscript_truthy(((state)["memory"] ?? null))) {
|
|
2775
3700
|
return memory_integer_register(state, 0, ((name === "*") ? 1 : 0));
|
|
@@ -2777,39 +3702,106 @@ function memory_word(state, node) {
|
|
|
2777
3702
|
return integer_register(state, 0, ((name === "*") ? 1 : 0), 0);
|
|
2778
3703
|
}
|
|
2779
3704
|
} else {
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
if ((__eliscript_truthy(((state)["memory"] ?? null)) && !(__eliscript_truthy(((state)["compact"] ?? null))) && !(__eliscript_truthy(((state)["leaf"] ?? null))) && ((((state)["registers"]) ?? []).length === 0) && __eliscript_truthy(memory_word_type((right)["type"])) && (((right)["kind"] === "literal") || ((right)["kind"] === "int-literal") || ((right)["kind"] === "local")))) {
|
|
2785
|
-
word(state, 704644065);
|
|
2786
|
-
expression(state, right);
|
|
2787
|
-
} else {
|
|
2788
|
-
push_value(state, "u32");
|
|
2789
|
-
expression(state, right);
|
|
2790
|
-
pop_value(state, "u32");
|
|
2791
|
-
}
|
|
2792
|
-
}
|
|
2793
|
-
if (((node)["kind"] === "word-compare")) {
|
|
3705
|
+
{
|
|
3706
|
+
let left = ((((children) ?? [])[0]) ?? null);
|
|
3707
|
+
let rL = ((__eliscript_truthy(opt) && __eliscript_truthy(no_debug) && __eliscript_truthy(memory_word_type((left)["type"]))) ? local_register(state, left, "u32") : -1);
|
|
3708
|
+
if ((count === 2)) {
|
|
2794
3709
|
{
|
|
2795
|
-
let
|
|
2796
|
-
|
|
2797
|
-
|
|
3710
|
+
let right = ((((children) ?? [])[1]) ?? null);
|
|
3711
|
+
let imm = (__eliscript_truthy(opt) ? memory_word_imm12(right) : -1);
|
|
3712
|
+
let shift = ((__eliscript_truthy(opt) && ((node)["kind"] === "word-arithmetic") && (name === "*")) ? memory_word_pow2_shift(right) : 0);
|
|
3713
|
+
let rR = ((__eliscript_truthy(opt) && __eliscript_truthy(no_debug) && __eliscript_truthy(memory_word_type((right)["type"]))) ? local_register(state, right, "u32") : -1);
|
|
3714
|
+
if ((((node)["kind"] === "word-arithmetic") && ((name === "+") || (name === "-")) && __eliscript_numeric_relation(">=", imm, 0))) {
|
|
3715
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
3716
|
+
expression(state, left);
|
|
3717
|
+
}
|
|
3718
|
+
return word(state, (((name === "+") ? 285212672 : 1358954496) + __eliscript_numeric_mul(imm, 1024) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
3719
|
+
} else {
|
|
3720
|
+
if (__eliscript_numeric_relation(">", shift, 0)) {
|
|
3721
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
3722
|
+
expression(state, left);
|
|
3723
|
+
}
|
|
3724
|
+
return word(state, (1392508928 + __eliscript_numeric_mul(__eliscript_numeric_sub(32, shift), 65536) + __eliscript_numeric_mul(__eliscript_numeric_sub(31, shift), 1024) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
3725
|
+
} else {
|
|
3726
|
+
if ((((node)["kind"] === "word-compare") && __eliscript_numeric_relation(">=", imm, 0))) {
|
|
3727
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
3728
|
+
expression(state, left);
|
|
3729
|
+
}
|
|
3730
|
+
word(state, (1895825439 + __eliscript_numeric_mul(imm, 1024) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
3731
|
+
{
|
|
3732
|
+
let code = memory_word_compare_code(name);
|
|
3733
|
+
return word(state, (446629856 + __eliscript_numeric_mul(__eliscript_numeric_xor(code, 1), 4096)));
|
|
3734
|
+
}
|
|
3735
|
+
} else {
|
|
3736
|
+
if (__eliscript_numeric_relation(">=", rR, 0)) {
|
|
3737
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
3738
|
+
expression(state, left);
|
|
3739
|
+
}
|
|
3740
|
+
if (((node)["kind"] === "word-compare")) {
|
|
3741
|
+
{
|
|
3742
|
+
let code = memory_word_compare_code(name);
|
|
3743
|
+
word(state, (1795162143 + __eliscript_numeric_mul(rR, 65536) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
3744
|
+
return word(state, (446629856 + __eliscript_numeric_mul(__eliscript_numeric_xor(code, 1), 4096)));
|
|
3745
|
+
}
|
|
3746
|
+
} else {
|
|
3747
|
+
return word(state, (((name === "+") ? 184549376 : ((name === "-") ? 1258291200 : 453016576)) + __eliscript_numeric_mul(rR, 65536) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
3748
|
+
}
|
|
3749
|
+
} else {
|
|
3750
|
+
if ((__eliscript_truthy(opt) && __eliscript_truthy(no_debug) && __eliscript_numeric_relation(">=", rL, 0) && !(__eliscript_truthy(memory_expr_writes_reg_p(state, right, rL))))) {
|
|
3751
|
+
expression(state, right);
|
|
3752
|
+
if (((node)["kind"] === "word-compare")) {
|
|
3753
|
+
{
|
|
3754
|
+
let code = memory_word_compare_code(name);
|
|
3755
|
+
word(state, (1795162143 + __eliscript_numeric_mul(rL, 32)));
|
|
3756
|
+
return word(state, (446629856 + __eliscript_numeric_mul(__eliscript_numeric_xor(code, 1), 4096)));
|
|
3757
|
+
}
|
|
3758
|
+
} else {
|
|
3759
|
+
return word(state, (((name === "+") ? 184549376 : ((name === "-") ? 1258291200 : 453016576)) + __eliscript_numeric_mul(rL, 32)));
|
|
3760
|
+
}
|
|
3761
|
+
} else {
|
|
3762
|
+
expression(state, left);
|
|
3763
|
+
if ((__eliscript_truthy(((state)["memory"] ?? null)) && !(__eliscript_truthy(((state)["compact"] ?? null))) && !(__eliscript_truthy(((state)["leaf"] ?? null))) && __eliscript_truthy(memory_word_type((right)["type"])) && (((right)["kind"] === "literal") || ((right)["kind"] === "int-literal") || ((right)["kind"] === "local")))) {
|
|
3764
|
+
word(state, 704644065);
|
|
3765
|
+
expression(state, right);
|
|
3766
|
+
} else {
|
|
3767
|
+
push_value(state, "u32");
|
|
3768
|
+
expression(state, right);
|
|
3769
|
+
pop_value(state, "u32");
|
|
3770
|
+
}
|
|
3771
|
+
if (((node)["kind"] === "word-compare")) {
|
|
3772
|
+
{
|
|
3773
|
+
let code = memory_word_compare_code(name);
|
|
3774
|
+
word(state, 1795162175);
|
|
3775
|
+
return word(state, (446629856 + __eliscript_numeric_mul(__eliscript_numeric_xor(code, 1), 4096)));
|
|
3776
|
+
}
|
|
3777
|
+
} else {
|
|
3778
|
+
return word(state, ((name === "+") ? 184549408 : ((name === "-") ? 1258291232 : 453016608)));
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
}
|
|
3783
|
+
}
|
|
3784
|
+
}
|
|
2798
3785
|
}
|
|
2799
3786
|
} else {
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
if ((name === "-")) {
|
|
2804
|
-
return word(state, 1258292192);
|
|
2805
|
-
} else {
|
|
2806
|
-
if ((name === "1+")) {
|
|
2807
|
-
return word(state, 285213696);
|
|
3787
|
+
if ((name === "-")) {
|
|
3788
|
+
expression(state, left);
|
|
3789
|
+
return word(state, 1258292192);
|
|
2808
3790
|
} else {
|
|
2809
|
-
if ((name === "1
|
|
2810
|
-
|
|
3791
|
+
if ((name === "1+")) {
|
|
3792
|
+
if (__eliscript_numeric_relation(">=", rL, 0)) {
|
|
3793
|
+
return word(state, (285213696 + __eliscript_numeric_mul(rL, 32)));
|
|
3794
|
+
} else {
|
|
3795
|
+
expression(state, left);
|
|
3796
|
+
return word(state, 285213696);
|
|
3797
|
+
}
|
|
2811
3798
|
} else {
|
|
2812
|
-
|
|
3799
|
+
if (__eliscript_numeric_relation(">=", rL, 0)) {
|
|
3800
|
+
return word(state, (1358955520 + __eliscript_numeric_mul(rL, 32)));
|
|
3801
|
+
} else {
|
|
3802
|
+
expression(state, left);
|
|
3803
|
+
return word(state, 1358955520);
|
|
3804
|
+
}
|
|
2813
3805
|
}
|
|
2814
3806
|
}
|
|
2815
3807
|
}
|
|
@@ -2846,6 +3838,9 @@ function memory_grow(state, node) {
|
|
|
2846
3838
|
patch_jump(state, done, (((state)["words"]) ?? []).length);
|
|
2847
3839
|
}
|
|
2848
3840
|
word(state, 4177528426);
|
|
3841
|
+
if (__eliscript_truthy(((state)["pinMemory"] ?? null))) {
|
|
3842
|
+
word(state, 2852783100);
|
|
3843
|
+
}
|
|
2849
3844
|
{
|
|
2850
3845
|
let end = jump(state, "jump");
|
|
2851
3846
|
patch_jump(state, failed, (((state)["words"]) ?? []).length);
|
|
@@ -2884,6 +3879,24 @@ function memory_copy_op(state, node) {
|
|
|
2884
3879
|
{
|
|
2885
3880
|
let backward = (((state)["words"]) ?? []).length;
|
|
2886
3881
|
word(state, 1409286152);
|
|
3882
|
+
{
|
|
3883
|
+
let fwd32 = (((state)["words"]) ?? []).length;
|
|
3884
|
+
word(state, 4043342271);
|
|
3885
|
+
{
|
|
3886
|
+
let fwd8_skip = (((state)["words"]) ?? []).length;
|
|
3887
|
+
word(state, 1409286147);
|
|
3888
|
+
word(state, 2831236428);
|
|
3889
|
+
word(state, 2827042092);
|
|
3890
|
+
word(state, 2831236428);
|
|
3891
|
+
word(state, 2827042092);
|
|
3892
|
+
word(state, 3506471341);
|
|
3893
|
+
{
|
|
3894
|
+
let back32 = jump(state, "jump");
|
|
3895
|
+
patch_jump(state, back32, fwd32);
|
|
3896
|
+
}
|
|
3897
|
+
patch_jump(state, fwd8_skip, (((state)["words"]) ?? []).length);
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
2887
3900
|
{
|
|
2888
3901
|
let fwd8 = (((state)["words"]) ?? []).length;
|
|
2889
3902
|
word(state, 4043317695);
|
|
@@ -2964,59 +3977,143 @@ function memory_copy_op(state, node) {
|
|
|
2964
3977
|
function memory_fill_op(state, node) {
|
|
2965
3978
|
{
|
|
2966
3979
|
let children = (node)["children"];
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
memory_conditional_error(state, 1409286153, 1);
|
|
2981
|
-
{
|
|
2982
|
-
let done = (((state)["words"]) ?? []).length;
|
|
2983
|
-
word(state, 3019898893);
|
|
2984
|
-
word(state, 4181721705);
|
|
2985
|
-
word(state, 2332033321);
|
|
2986
|
-
word(state, 3544194444);
|
|
2987
|
-
integer_register(state, 10, 16843009, 16843009);
|
|
2988
|
-
word(state, 2601155980);
|
|
3980
|
+
let val_node = ((((children) ?? [])[1]) ?? null);
|
|
3981
|
+
let val0 = ((((val_node)["kind"] === "literal") || ((val_node)["kind"] === "int-literal")) && (__eliscript_value_type((val_node)["value"]) === "number") && (__eliscript_numeric_and(__eliscript_numeric_uint32((val_node)["value"]), 255) === 0));
|
|
3982
|
+
if (__eliscript_truthy(val0)) {
|
|
3983
|
+
expression(state, ((((children) ?? [])[0]) ?? null));
|
|
3984
|
+
push_value(state, "u32");
|
|
3985
|
+
expression(state, ((((children) ?? [])[2]) ?? null));
|
|
3986
|
+
word(state, 704644077);
|
|
3987
|
+
pop_value(state, "u32");
|
|
3988
|
+
word(state, 704709600);
|
|
3989
|
+
word(state, 2332885002);
|
|
3990
|
+
word(state, 4181722731);
|
|
3991
|
+
word(state, 3943367007);
|
|
3992
|
+
memory_conditional_error(state, 1409286153, 1);
|
|
2989
3993
|
{
|
|
2990
|
-
let
|
|
2991
|
-
word(state,
|
|
3994
|
+
let done = (((state)["words"]) ?? []).length;
|
|
3995
|
+
word(state, 3019898893);
|
|
3996
|
+
word(state, 4181721705);
|
|
3997
|
+
word(state, 2332033321);
|
|
3998
|
+
{
|
|
3999
|
+
let fill32 = (((state)["words"]) ?? []).length;
|
|
4000
|
+
word(state, 4043342271);
|
|
4001
|
+
{
|
|
4002
|
+
let fill8 = (((state)["words"]) ?? []).length;
|
|
4003
|
+
word(state, 1409286147);
|
|
4004
|
+
word(state, 2827058495);
|
|
4005
|
+
word(state, 2827058495);
|
|
4006
|
+
word(state, 3506471341);
|
|
4007
|
+
{
|
|
4008
|
+
let back32 = jump(state, "jump");
|
|
4009
|
+
patch_jump(state, back32, fill32);
|
|
4010
|
+
}
|
|
4011
|
+
patch_jump(state, fill8, (((state)["words"]) ?? []).length);
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
{
|
|
4015
|
+
let fill8 = (((state)["words"]) ?? []).length;
|
|
4016
|
+
word(state, 4043317695);
|
|
4017
|
+
{
|
|
4018
|
+
let fill1 = (((state)["words"]) ?? []).length;
|
|
4019
|
+
word(state, 1409286147);
|
|
4020
|
+
word(state, 4160783679);
|
|
4021
|
+
word(state, 3506446765);
|
|
4022
|
+
{
|
|
4023
|
+
let back8 = jump(state, "jump");
|
|
4024
|
+
patch_jump(state, back8, fill8);
|
|
4025
|
+
}
|
|
4026
|
+
patch_jump(state, fill1, (((state)["words"]) ?? []).length);
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
2992
4029
|
{
|
|
2993
|
-
let
|
|
2994
|
-
word(state,
|
|
2995
|
-
word(state, 4160783660);
|
|
2996
|
-
word(state, 3506446765);
|
|
4030
|
+
let fill_done = (((state)["words"]) ?? []).length;
|
|
4031
|
+
word(state, 3019898893);
|
|
2997
4032
|
{
|
|
2998
|
-
let
|
|
2999
|
-
|
|
4033
|
+
let fill1_loop = (((state)["words"]) ?? []).length;
|
|
4034
|
+
word(state, 939529535);
|
|
4035
|
+
word(state, 4043310509);
|
|
4036
|
+
{
|
|
4037
|
+
let back1 = (((state)["words"]) ?? []).length;
|
|
4038
|
+
word(state, 1409286145);
|
|
4039
|
+
patch_jump(state, back1, fill1_loop);
|
|
4040
|
+
}
|
|
3000
4041
|
}
|
|
3001
|
-
patch_jump(state,
|
|
4042
|
+
patch_jump(state, fill_done, (((state)["words"]) ?? []).length);
|
|
3002
4043
|
}
|
|
4044
|
+
patch_jump(state, done, (((state)["words"]) ?? []).length);
|
|
3003
4045
|
}
|
|
4046
|
+
} else {
|
|
4047
|
+
expression(state, ((((children) ?? [])[0]) ?? null));
|
|
4048
|
+
push_value(state, "u32");
|
|
4049
|
+
expression(state, ((((children) ?? [])[1]) ?? null));
|
|
4050
|
+
push_value(state, "u32");
|
|
4051
|
+
expression(state, ((((children) ?? [])[2]) ?? null));
|
|
4052
|
+
word(state, 704644077);
|
|
4053
|
+
pop_value(state, "u32");
|
|
4054
|
+
word(state, 704709612);
|
|
4055
|
+
pop_value(state, "u32");
|
|
4056
|
+
word(state, 704709600);
|
|
4057
|
+
word(state, 2332885002);
|
|
4058
|
+
word(state, 4181722731);
|
|
4059
|
+
word(state, 3943367007);
|
|
4060
|
+
memory_conditional_error(state, 1409286153, 1);
|
|
3004
4061
|
{
|
|
3005
|
-
let
|
|
4062
|
+
let done = (((state)["words"]) ?? []).length;
|
|
3006
4063
|
word(state, 3019898893);
|
|
4064
|
+
word(state, 4181721705);
|
|
4065
|
+
word(state, 2332033321);
|
|
4066
|
+
word(state, 3544194444);
|
|
4067
|
+
integer_register(state, 10, 16843009, 16843009);
|
|
4068
|
+
word(state, 2601155980);
|
|
3007
4069
|
{
|
|
3008
|
-
let
|
|
3009
|
-
word(state,
|
|
3010
|
-
word(state, 4043310509);
|
|
4070
|
+
let fill32 = (((state)["words"]) ?? []).length;
|
|
4071
|
+
word(state, 4043342271);
|
|
3011
4072
|
{
|
|
3012
|
-
let
|
|
3013
|
-
word(state,
|
|
3014
|
-
|
|
4073
|
+
let fill8 = (((state)["words"]) ?? []).length;
|
|
4074
|
+
word(state, 1409286147);
|
|
4075
|
+
word(state, 2827039020);
|
|
4076
|
+
word(state, 2827039020);
|
|
4077
|
+
word(state, 3506471341);
|
|
4078
|
+
{
|
|
4079
|
+
let back32 = jump(state, "jump");
|
|
4080
|
+
patch_jump(state, back32, fill32);
|
|
4081
|
+
}
|
|
4082
|
+
patch_jump(state, fill8, (((state)["words"]) ?? []).length);
|
|
4083
|
+
}
|
|
4084
|
+
}
|
|
4085
|
+
{
|
|
4086
|
+
let fill8 = (((state)["words"]) ?? []).length;
|
|
4087
|
+
word(state, 4043317695);
|
|
4088
|
+
{
|
|
4089
|
+
let fill1 = (((state)["words"]) ?? []).length;
|
|
4090
|
+
word(state, 1409286147);
|
|
4091
|
+
word(state, 4160783660);
|
|
4092
|
+
word(state, 3506446765);
|
|
4093
|
+
{
|
|
4094
|
+
let back8 = jump(state, "jump");
|
|
4095
|
+
patch_jump(state, back8, fill8);
|
|
4096
|
+
}
|
|
4097
|
+
patch_jump(state, fill1, (((state)["words"]) ?? []).length);
|
|
4098
|
+
}
|
|
4099
|
+
}
|
|
4100
|
+
{
|
|
4101
|
+
let fill_done = (((state)["words"]) ?? []).length;
|
|
4102
|
+
word(state, 3019898893);
|
|
4103
|
+
{
|
|
4104
|
+
let fill1_loop = (((state)["words"]) ?? []).length;
|
|
4105
|
+
word(state, 939529516);
|
|
4106
|
+
word(state, 4043310509);
|
|
4107
|
+
{
|
|
4108
|
+
let back1 = (((state)["words"]) ?? []).length;
|
|
4109
|
+
word(state, 1409286145);
|
|
4110
|
+
patch_jump(state, back1, fill1_loop);
|
|
4111
|
+
}
|
|
3015
4112
|
}
|
|
4113
|
+
patch_jump(state, fill_done, (((state)["words"]) ?? []).length);
|
|
3016
4114
|
}
|
|
3017
|
-
patch_jump(state,
|
|
4115
|
+
patch_jump(state, done, (((state)["words"]) ?? []).length);
|
|
3018
4116
|
}
|
|
3019
|
-
patch_jump(state, done, (((state)["words"]) ?? []).length);
|
|
3020
4117
|
}
|
|
3021
4118
|
return memory_integer_register(state, 0, 0);
|
|
3022
4119
|
}
|
|
@@ -3036,12 +4133,36 @@ function memory_v64_compare(state, node) {
|
|
|
3036
4133
|
{
|
|
3037
4134
|
let children = (node)["children"];
|
|
3038
4135
|
let name = (node)["value"];
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
4136
|
+
let left = ((((children) ?? [])[0]) ?? null);
|
|
4137
|
+
let right = ((((children) ?? [])[1]) ?? null);
|
|
4138
|
+
let opt = ((__eliscript_value_31) => (__eliscript_truthy(__eliscript_value_31) ? ((state)["optimizeMemory"] ?? null) : __eliscript_value_31))(((state)["memory"] ?? null));
|
|
4139
|
+
let no_debug = (!__eliscript_truthy(((state)["debugRanges"] ?? null)));
|
|
4140
|
+
let wimm = (__eliscript_truthy(opt) ? memory_wide_imm12(right) : null);
|
|
4141
|
+
let rL = ((__eliscript_truthy(opt) && __eliscript_truthy(no_debug) && __eliscript_truthy(memory_wide_type((left)["type"]))) ? local_register(state, left, "v64") : -1);
|
|
4142
|
+
let rR = ((__eliscript_truthy(opt) && __eliscript_truthy(no_debug) && __eliscript_truthy(memory_wide_type((right)["type"]))) ? local_register(state, right, "v64") : -1);
|
|
4143
|
+
let code = ((name === "=") ? 0 : ((name === "/=") ? 1 : ((name === "<") ? 3 : ((name === "<=") ? 9 : ((name === ">") ? 8 : 2)))));
|
|
4144
|
+
if (!((wimm === null))) {
|
|
4145
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
4146
|
+
expression(state, left);
|
|
4147
|
+
}
|
|
4148
|
+
word(state, (4043309087 + __eliscript_numeric_mul(wimm, 1024) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
4149
|
+
} else {
|
|
4150
|
+
if (__eliscript_numeric_relation(">=", rR, 0)) {
|
|
4151
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
4152
|
+
expression(state, left);
|
|
4153
|
+
}
|
|
4154
|
+
word(state, (3942645791 + __eliscript_numeric_mul(rR, 65536) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
4155
|
+
} else {
|
|
4156
|
+
if ((__eliscript_numeric_relation(">=", rL, 0) && !(__eliscript_truthy(memory_expr_writes_reg_p(state, right, rL))))) {
|
|
4157
|
+
expression(state, right);
|
|
4158
|
+
word(state, (3942645791 + __eliscript_numeric_mul(rL, 32)));
|
|
4159
|
+
} else {
|
|
4160
|
+
memory_wide_operands(state, left, right);
|
|
4161
|
+
word(state, 3942645823);
|
|
4162
|
+
}
|
|
4163
|
+
}
|
|
3044
4164
|
}
|
|
4165
|
+
return word(state, (446629856 + __eliscript_numeric_mul(__eliscript_numeric_xor(code, 1), 4096)));
|
|
3045
4166
|
}
|
|
3046
4167
|
}
|
|
3047
4168
|
function memory_f64_unary_instruction(name) {
|
|
@@ -3082,7 +4203,120 @@ function memory_f64_unary(state, node) {
|
|
|
3082
4203
|
word(state, memory_f64_unary_instruction((node)["value"]));
|
|
3083
4204
|
return word(state, 3575333897);
|
|
3084
4205
|
}
|
|
3085
|
-
function
|
|
4206
|
+
function memory_expr_writes_local_p(node, target) {
|
|
4207
|
+
{
|
|
4208
|
+
let kind = (node)["kind"];
|
|
4209
|
+
let children = (node)["children"];
|
|
4210
|
+
let i = 0;
|
|
4211
|
+
let found = null;
|
|
4212
|
+
if ((((kind === "set") || (kind === "initialize")) && ((node)["value"] === target))) {
|
|
4213
|
+
return true;
|
|
4214
|
+
} else {
|
|
4215
|
+
if (__eliscript_truthy(children)) {
|
|
4216
|
+
while ((!(__eliscript_truthy(found)) && __eliscript_numeric_relation("<", i, ((children) ?? []).length))) {
|
|
4217
|
+
if (__eliscript_truthy(memory_expr_writes_local_p(((((children) ?? [])[i]) ?? null), target))) {
|
|
4218
|
+
((found = true));
|
|
4219
|
+
}
|
|
4220
|
+
((i = (i + 1)));
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
return found;
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
}
|
|
4227
|
+
function memory_expr_writes_reg_p(state, node, target_reg) {
|
|
4228
|
+
{
|
|
4229
|
+
let kind = (node)["kind"];
|
|
4230
|
+
let children = (node)["children"];
|
|
4231
|
+
let i = 0;
|
|
4232
|
+
let found = null;
|
|
4233
|
+
if ((((kind === "set") || (kind === "initialize")) && __eliscript_truthy(((regs) => {
|
|
4234
|
+
return ((idx) => {
|
|
4235
|
+
return ((raw) => {
|
|
4236
|
+
return (__eliscript_numeric_relation("<=", raw, -2) && (__eliscript_numeric_sub(__eliscript_numeric_neg(raw), 2) === target_reg));
|
|
4237
|
+
})((__eliscript_numeric_relation("<", idx, ((regs) ?? []).length) ? ((((regs) ?? [])[idx]) ?? null) : -1));
|
|
4238
|
+
})((node)["value"]);
|
|
4239
|
+
})((state)["registers"])))) {
|
|
4240
|
+
return true;
|
|
4241
|
+
} else {
|
|
4242
|
+
if (__eliscript_truthy(children)) {
|
|
4243
|
+
while ((!(__eliscript_truthy(found)) && __eliscript_numeric_relation("<", i, ((children) ?? []).length))) {
|
|
4244
|
+
if (__eliscript_truthy(memory_expr_writes_reg_p(state, ((((children) ?? [])[i]) ?? null), target_reg))) {
|
|
4245
|
+
((found = true));
|
|
4246
|
+
}
|
|
4247
|
+
((i = (i + 1)));
|
|
4248
|
+
}
|
|
4249
|
+
}
|
|
4250
|
+
return found;
|
|
4251
|
+
}
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4254
|
+
function memory_addr_base_imm(state, addr) {
|
|
4255
|
+
{
|
|
4256
|
+
let kind = (addr)["kind"];
|
|
4257
|
+
let val = (addr)["value"];
|
|
4258
|
+
let children = (addr)["children"];
|
|
4259
|
+
if (((kind === "word-arithmetic") && __eliscript_truthy(memory_word_type((addr)["type"])))) {
|
|
4260
|
+
if (((val === "+") && (((children) ?? []).length === 2))) {
|
|
4261
|
+
{
|
|
4262
|
+
let left = ((((children) ?? [])[0]) ?? null);
|
|
4263
|
+
let right = ((((children) ?? [])[1]) ?? null);
|
|
4264
|
+
let rL = (__eliscript_truthy(memory_word_type((left)["type"])) ? local_register(state, left, "u32") : -1);
|
|
4265
|
+
let immR = memory_word_imm12(right);
|
|
4266
|
+
if ((__eliscript_numeric_relation(">=", rL, 0) && __eliscript_numeric_relation(">=", immR, 0))) {
|
|
4267
|
+
return ({"reg": rL, "imm": immR, "local": (left)["value"]});
|
|
4268
|
+
} else {
|
|
4269
|
+
{
|
|
4270
|
+
let rR = (__eliscript_truthy(memory_word_type((right)["type"])) ? local_register(state, right, "u32") : -1);
|
|
4271
|
+
let immL = memory_word_imm12(left);
|
|
4272
|
+
if ((__eliscript_numeric_relation(">=", rR, 0) && __eliscript_numeric_relation(">=", immL, 0))) {
|
|
4273
|
+
return ({"reg": rR, "imm": immL, "local": (right)["value"]});
|
|
4274
|
+
} else {
|
|
4275
|
+
return null;
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
}
|
|
4280
|
+
} else {
|
|
4281
|
+
if (((val === "1+") && (((children) ?? []).length === 1))) {
|
|
4282
|
+
{
|
|
4283
|
+
let arg = ((((children) ?? [])[0]) ?? null);
|
|
4284
|
+
let rA = (__eliscript_truthy(memory_word_type((arg)["type"])) ? local_register(state, arg, "u32") : -1);
|
|
4285
|
+
if (__eliscript_numeric_relation(">=", rA, 0)) {
|
|
4286
|
+
return ({"reg": rA, "imm": 1, "local": (arg)["value"]});
|
|
4287
|
+
} else {
|
|
4288
|
+
return null;
|
|
4289
|
+
}
|
|
4290
|
+
}
|
|
4291
|
+
} else {
|
|
4292
|
+
return null;
|
|
4293
|
+
}
|
|
4294
|
+
}
|
|
4295
|
+
} else {
|
|
4296
|
+
return null;
|
|
4297
|
+
}
|
|
4298
|
+
}
|
|
4299
|
+
}
|
|
4300
|
+
function memory_emit_pinned_bounds(state, width, idx_reg) {
|
|
4301
|
+
word(state, (2432696330 + __eliscript_numeric_mul(width, 1024) + __eliscript_numeric_mul(idx_reg, 32)));
|
|
4302
|
+
word(state, 3944481119);
|
|
4303
|
+
if (__eliscript_truthy(((state)["trapSites"] ?? null))) {
|
|
4304
|
+
return memory_conditional_error(state, 1409286153, 1);
|
|
4305
|
+
} else {
|
|
4306
|
+
((state)["boundsErrors"])["push"]((((state)["words"]) ?? []).length);
|
|
4307
|
+
return word(state, 1409286152);
|
|
4308
|
+
}
|
|
4309
|
+
}
|
|
4310
|
+
function memory_emit_pinned_store(state, name, width, idx_reg, rV, discard = null) {
|
|
4311
|
+
memory_emit_pinned_bounds(state, width, idx_reg);
|
|
4312
|
+
word(state, (((name === "store-u8") ? 941648736 : ((name === "store-u16") ? 2015390560 : ((name === "store-u32") ? 3089132384 : 4162874208))) + __eliscript_numeric_mul(idx_reg, 65536) + rV));
|
|
4313
|
+
if ((!__eliscript_truthy(discard))) {
|
|
4314
|
+
return memory_integer_register(state, 0, 0);
|
|
4315
|
+
} else {
|
|
4316
|
+
return null;
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4319
|
+
function memory_operation(state, node, discard = null) {
|
|
3086
4320
|
{
|
|
3087
4321
|
let name = (node)["value"];
|
|
3088
4322
|
let children = (node)["children"];
|
|
@@ -3098,37 +4332,131 @@ function memory_operation(state, node) {
|
|
|
3098
4332
|
return memory_fill_op(state, node);
|
|
3099
4333
|
} else {
|
|
3100
4334
|
if (__eliscript_numeric_relation(">", width, 0)) {
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
4335
|
+
{
|
|
4336
|
+
let addr = ((((children) ?? [])[0]) ?? null);
|
|
4337
|
+
let no_debug = (!__eliscript_truthy(((state)["debugRanges"] ?? null)));
|
|
4338
|
+
let pin = ((state)["pinMemory"] ?? null);
|
|
4339
|
+
let right = (__eliscript_truthy(store) ? ((((children) ?? [])[1]) ?? null) : null);
|
|
4340
|
+
let rV = ((__eliscript_truthy(pin) && __eliscript_truthy(store) && __eliscript_truthy(no_debug) && (name !== "store-f64")) ? ((rtype) => {
|
|
4341
|
+
return ((rk) => {
|
|
4342
|
+
return ((rv) => {
|
|
4343
|
+
return ((reg) => {
|
|
4344
|
+
return (__eliscript_numeric_relation(">=", reg, 0) ? reg : ((((rk === "literal") || (rk === "int-literal")) && __eliscript_truthy((__eliscript_truthy(memory_wide_type(rtype)) ? ((!((rv === null)) && (__eliscript_value_type(rv) === "object")) ? (((rv)["low"] === 0) && ((rv)["high"] === 0)) : (rv === 0)) : (rv === 0)))) ? 31 : -1));
|
|
4345
|
+
})(((__eliscript_truthy(memory_word_type(rtype)) || __eliscript_truthy(memory_wide_type(rtype))) ? local_register(state, right, rtype) : -1));
|
|
4346
|
+
})((right)["value"]);
|
|
4347
|
+
})((right)["kind"]);
|
|
4348
|
+
})((right)["type"]) : -1);
|
|
4349
|
+
let constAddr = ((__eliscript_truthy(pin) && __eliscript_truthy(no_debug) && __eliscript_truthy(memory_word_type((addr)["type"]))) ? memory_word_imm12(addr) : -1);
|
|
4350
|
+
let rA = ((__eliscript_truthy(pin) && __eliscript_truthy(no_debug) && __eliscript_numeric_relation("<", constAddr, 0) && __eliscript_truthy(memory_word_type((addr)["type"]))) ? local_register(state, addr, "u32") : -1);
|
|
4351
|
+
let baseImmRaw = ((__eliscript_truthy(pin) && __eliscript_truthy(no_debug) && __eliscript_numeric_relation("<", constAddr, 0) && __eliscript_numeric_relation("<", rA, 0)) ? memory_addr_base_imm(state, addr) : null);
|
|
4352
|
+
let baseImm = (__eliscript_truthy(baseImmRaw) ? (((baseImmRaw)["imm"] === 0) ? (() => {
|
|
4353
|
+
((rA = (baseImmRaw)["reg"]));
|
|
4354
|
+
return null;
|
|
4355
|
+
})() : baseImmRaw) : null);
|
|
4356
|
+
let addrReg = (__eliscript_numeric_relation(">=", rA, 0) ? rA : (__eliscript_truthy(baseImm) ? (baseImm)["reg"] : -1));
|
|
4357
|
+
if ((__eliscript_numeric_relation(">=", constAddr, 0) && __eliscript_numeric_relation("<=", (constAddr + width), 4095) && (__eliscript_numeric_rem(constAddr, width) === 0) && (name !== "store-f64"))) {
|
|
4358
|
+
if ((__eliscript_truthy(store) && __eliscript_numeric_relation("<", rV, 0))) {
|
|
3108
4359
|
expression(state, right);
|
|
3109
|
-
|
|
3110
|
-
|
|
4360
|
+
}
|
|
4361
|
+
word(state, (4043309983 + __eliscript_numeric_mul((constAddr + width), 1024)));
|
|
4362
|
+
if (__eliscript_truthy(((state)["trapSites"] ?? null))) {
|
|
4363
|
+
memory_conditional_error(state, 1409286146, 1);
|
|
3111
4364
|
} else {
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
4365
|
+
((state)["boundsErrors"])["push"]((((state)["words"]) ?? []).length);
|
|
4366
|
+
word(state, 1409286147);
|
|
4367
|
+
}
|
|
4368
|
+
{
|
|
4369
|
+
let scaled = __eliscript_numeric_div(constAddr, width);
|
|
4370
|
+
if (__eliscript_truthy(store)) {
|
|
4371
|
+
word(state, (((name === "store-u8") ? 956302176 : ((name === "store-u16") ? 2030044000 : ((name === "store-u32") ? 3103785824 : 4177527648))) + __eliscript_numeric_mul(scaled, 1024) + (__eliscript_numeric_relation(">=", rV, 0) ? rV : 0)));
|
|
4372
|
+
if ((!__eliscript_truthy(discard))) {
|
|
4373
|
+
return memory_integer_register(state, 0, 0);
|
|
4374
|
+
} else {
|
|
4375
|
+
return null;
|
|
4376
|
+
}
|
|
4377
|
+
} else {
|
|
4378
|
+
return word(state, (((name === "load-u8") ? 960496480 : ((name === "load-u16") ? 2034238304 : ((name === "load-u32") ? 3107980128 : ((name === "load-f64") ? 4248830816 : 4181721952)))) + __eliscript_numeric_mul(scaled, 1024)));
|
|
4379
|
+
}
|
|
4380
|
+
}
|
|
4381
|
+
} else {
|
|
4382
|
+
if ((__eliscript_truthy(pin) && !(__eliscript_truthy(store)) && (__eliscript_numeric_relation(">=", rA, 0) || __eliscript_truthy(baseImm)))) {
|
|
4383
|
+
{
|
|
4384
|
+
let idx_reg = (__eliscript_numeric_relation(">=", rA, 0) ? rA : (() => {
|
|
4385
|
+
word(state, (285212681 + __eliscript_numeric_mul((baseImm)["imm"], 1024) + __eliscript_numeric_mul((baseImm)["reg"], 32)));
|
|
4386
|
+
return 9;
|
|
4387
|
+
})());
|
|
4388
|
+
memory_emit_pinned_bounds(state, width, idx_reg);
|
|
4389
|
+
return word(state, (((name === "load-u8") ? 945843040 : ((name === "load-u16") ? 2019584864 : ((name === "load-u32") ? 3093326688 : ((name === "load-f64") ? 4234177376 : 4167068512)))) + __eliscript_numeric_mul(idx_reg, 65536)));
|
|
4390
|
+
}
|
|
4391
|
+
} else {
|
|
4392
|
+
if ((__eliscript_truthy(pin) && __eliscript_truthy(store) && __eliscript_numeric_relation(">=", rV, 0))) {
|
|
4393
|
+
{
|
|
4394
|
+
let idx_reg = (__eliscript_numeric_relation(">=", rA, 0) ? rA : (__eliscript_truthy(baseImm) ? (() => {
|
|
4395
|
+
word(state, (285212681 + __eliscript_numeric_mul((baseImm)["imm"], 1024) + __eliscript_numeric_mul((baseImm)["reg"], 32)));
|
|
4396
|
+
return 9;
|
|
4397
|
+
})() : (() => {
|
|
4398
|
+
expression(state, addr);
|
|
4399
|
+
return 0;
|
|
4400
|
+
})()));
|
|
4401
|
+
return memory_emit_pinned_store(state, name, width, idx_reg, rV, discard);
|
|
4402
|
+
}
|
|
4403
|
+
} else {
|
|
4404
|
+
if ((__eliscript_truthy(pin) && __eliscript_truthy(store) && __eliscript_truthy(no_debug) && (name !== "store-f64") && __eliscript_numeric_relation("<", rV, 0) && (__eliscript_numeric_relation(">=", rA, 0) || __eliscript_truthy(baseImm)) && (__eliscript_numeric_relation(">=", addrReg, 0) && !(__eliscript_truthy(memory_expr_writes_reg_p(state, right, addrReg)))))) {
|
|
4405
|
+
expression(state, right);
|
|
4406
|
+
{
|
|
4407
|
+
let idx_reg = (__eliscript_numeric_relation(">=", rA, 0) ? rA : (() => {
|
|
4408
|
+
word(state, (285212681 + __eliscript_numeric_mul((baseImm)["imm"], 1024) + __eliscript_numeric_mul((baseImm)["reg"], 32)));
|
|
4409
|
+
return 9;
|
|
4410
|
+
})());
|
|
4411
|
+
return memory_emit_pinned_store(state, name, width, idx_reg, 0, discard);
|
|
4412
|
+
}
|
|
4413
|
+
} else {
|
|
4414
|
+
expression(state, addr);
|
|
4415
|
+
if (__eliscript_truthy(store)) {
|
|
4416
|
+
{
|
|
4417
|
+
let move_temp = ((name === "store-f64") ? 509624322 : (((name === "store-v64") || (name === "store-bits64")) ? 2852127714 : 704644066));
|
|
4418
|
+
if ((((right)["kind"] === "literal") || ((right)["kind"] === "int-literal") || ((right)["kind"] === "local"))) {
|
|
4419
|
+
word(state, 704644065);
|
|
4420
|
+
expression(state, right);
|
|
4421
|
+
word(state, move_temp);
|
|
4422
|
+
word(state, 704709600);
|
|
4423
|
+
} else {
|
|
4424
|
+
push_value(state, "u32");
|
|
4425
|
+
expression(state, right);
|
|
4426
|
+
word(state, move_temp);
|
|
4427
|
+
pop_value(state, "u32");
|
|
4428
|
+
word(state, 704709600);
|
|
4429
|
+
}
|
|
4430
|
+
}
|
|
4431
|
+
}
|
|
4432
|
+
word(state, (2432696330 + __eliscript_numeric_mul(width, 1024)));
|
|
4433
|
+
if (__eliscript_truthy(pin)) {
|
|
4434
|
+
word(state, 3944481119);
|
|
4435
|
+
if (__eliscript_truthy(((state)["trapSites"] ?? null))) {
|
|
4436
|
+
memory_conditional_error(state, 1409286153, 1);
|
|
4437
|
+
} else {
|
|
4438
|
+
((state)["boundsErrors"])["push"]((((state)["words"]) ?? []).length);
|
|
4439
|
+
word(state, 1409286152);
|
|
4440
|
+
}
|
|
4441
|
+
word(state, ((name === "load-u8") ? 945843040 : ((name === "load-u16") ? 2019584864 : ((name === "load-u32") ? 3093326688 : ((name === "load-f64") ? 4234177376 : (((name === "load-v64") || (name === "load-bits64")) ? 4167068512 : ((name === "store-u8") ? 941648738 : ((name === "store-u16") ? 2015390562 : ((name === "store-u32") ? 3089132386 : ((name === "store-f64") ? 4229983074 : 4162874210))))))))));
|
|
4442
|
+
} else {
|
|
4443
|
+
word(state, 4181722731);
|
|
4444
|
+
word(state, 3943367007);
|
|
4445
|
+
memory_conditional_error(state, 1409286153, 1);
|
|
4446
|
+
word(state, 4181721705);
|
|
4447
|
+
word(state, 2332033321);
|
|
4448
|
+
word(state, ((name === "load-u8") ? 960495904 : ((name === "load-u16") ? 2034237728 : ((name === "load-u32") ? 3107979552 : ((name === "load-f64") ? 4248830240 : (((name === "load-v64") || (name === "load-bits64")) ? 4181721376 : ((name === "store-u8") ? 956301602 : ((name === "store-u16") ? 2030043426 : ((name === "store-u32") ? 3103785250 : ((name === "store-f64") ? 4244635938 : 4177527074))))))))));
|
|
4449
|
+
}
|
|
4450
|
+
if ((__eliscript_truthy(store) && !(__eliscript_truthy(discard)))) {
|
|
4451
|
+
return memory_integer_register(state, 0, 0);
|
|
4452
|
+
} else {
|
|
4453
|
+
return null;
|
|
4454
|
+
}
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
3117
4457
|
}
|
|
3118
4458
|
}
|
|
3119
4459
|
}
|
|
3120
|
-
word(state, (2432696330 + __eliscript_numeric_mul(width, 1024)));
|
|
3121
|
-
word(state, 4181722731);
|
|
3122
|
-
word(state, 3943367007);
|
|
3123
|
-
memory_conditional_error(state, 1409286153, 1);
|
|
3124
|
-
word(state, 4181721705);
|
|
3125
|
-
word(state, 2332033321);
|
|
3126
|
-
word(state, ((name === "load-u8") ? 960495904 : ((name === "load-u16") ? 2034237728 : ((name === "load-u32") ? 3107979552 : ((name === "load-f64") ? 4248830240 : (((name === "load-v64") || (name === "load-bits64")) ? 4181721376 : ((name === "store-u8") ? 956301602 : ((name === "store-u16") ? 2030043426 : ((name === "store-u32") ? 3103785250 : ((name === "store-f64") ? 4244635938 : 4177527074))))))))));
|
|
3127
|
-
if (__eliscript_truthy(store)) {
|
|
3128
|
-
return memory_integer_register(state, 0, 0);
|
|
3129
|
-
} else {
|
|
3130
|
-
return null;
|
|
3131
|
-
}
|
|
3132
4460
|
} else {
|
|
3133
4461
|
if ((name === "f64-from-bits64")) {
|
|
3134
4462
|
expression(state, ((((children) ?? [])[0]) ?? null));
|
|
@@ -3139,12 +4467,29 @@ function memory_operation(state, node) {
|
|
|
3139
4467
|
return word(state, 2657484800);
|
|
3140
4468
|
} else {
|
|
3141
4469
|
if (((name === "v64-from-u32") || (name === "v64-low") || (name === "bits64-low"))) {
|
|
3142
|
-
|
|
3143
|
-
|
|
4470
|
+
{
|
|
4471
|
+
let arg = ((((children) ?? [])[0]) ?? null);
|
|
4472
|
+
let atype = (arg)["type"];
|
|
4473
|
+
let r = ((!(__eliscript_truthy(((state)["debugRanges"] ?? null))) && (__eliscript_truthy(memory_word_type(atype)) || __eliscript_truthy(memory_wide_type(atype)))) ? local_register(state, arg, atype) : -1);
|
|
4474
|
+
if (__eliscript_numeric_relation(">=", r, 0)) {
|
|
4475
|
+
return word(state, (704644064 + __eliscript_numeric_mul(r, 65536)));
|
|
4476
|
+
} else {
|
|
4477
|
+
expression(state, arg);
|
|
4478
|
+
return word(state, 704644064);
|
|
4479
|
+
}
|
|
4480
|
+
}
|
|
3144
4481
|
} else {
|
|
3145
4482
|
if (((name === "v64-high") || (name === "bits64-high"))) {
|
|
3146
|
-
|
|
3147
|
-
|
|
4483
|
+
{
|
|
4484
|
+
let arg = ((((children) ?? [])[0]) ?? null);
|
|
4485
|
+
let r = ((!(__eliscript_truthy(((state)["debugRanges"] ?? null))) && __eliscript_truthy(memory_wide_type((arg)["type"]))) ? local_register(state, arg, "v64") : -1);
|
|
4486
|
+
if (__eliscript_numeric_relation(">=", r, 0)) {
|
|
4487
|
+
return word(state, (3546348544 + __eliscript_numeric_mul(r, 32)));
|
|
4488
|
+
} else {
|
|
4489
|
+
expression(state, arg);
|
|
4490
|
+
return word(state, 3546348544);
|
|
4491
|
+
}
|
|
4492
|
+
}
|
|
3148
4493
|
} else {
|
|
3149
4494
|
if ((name === "v64-encode-bits64")) {
|
|
3150
4495
|
expression(state, ((((children) ?? [])[0]) ?? null));
|
|
@@ -3182,22 +4527,75 @@ function memory_operation(state, node) {
|
|
|
3182
4527
|
if ((name === "memory-grow")) {
|
|
3183
4528
|
return memory_grow(state, node);
|
|
3184
4529
|
} else {
|
|
3185
|
-
expression(state, ((((children) ?? [])[0]) ?? null));
|
|
3186
4530
|
{
|
|
4531
|
+
let left = ((((children) ?? [])[0]) ?? null);
|
|
3187
4532
|
let right = ((((children) ?? [])[1]) ?? null);
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
4533
|
+
let rkind = (right)["kind"];
|
|
4534
|
+
let rlit = ((__eliscript_value_32) => (__eliscript_truthy(__eliscript_value_32) ? ((__eliscript_value_33) => (__eliscript_truthy(__eliscript_value_33) ? ((__eliscript_value_34) => (__eliscript_truthy(__eliscript_value_34) ? Number.isInteger((right)["value"]) : __eliscript_value_34))((__eliscript_value_type((right)["value"]) === "number")) : __eliscript_value_33))(((rkind === "literal") || (rkind === "int-literal"))) : __eliscript_value_32))(memory_word_type((right)["type"]));
|
|
4535
|
+
let rval = (__eliscript_truthy(rlit) ? __eliscript_numeric_uint32((right)["value"]) : null);
|
|
4536
|
+
let shift_k = ((__eliscript_truthy(rlit) && ((name === "word-shr") || (name === "word-shl")) && __eliscript_numeric_relation(">=", rval, 0) && __eliscript_numeric_relation("<", rval, 32)) ? rval : -1);
|
|
4537
|
+
let mask_bits = ((__eliscript_truthy(rlit) && (name === "word-and")) ? ((bits, mask) => {
|
|
4538
|
+
while ((__eliscript_numeric_relation("<", bits, 31) && __eliscript_numeric_relation("<", mask, rval))) {
|
|
4539
|
+
((mask = (__eliscript_numeric_mul(mask, 2) + 1)), (bits = (bits + 1)));
|
|
4540
|
+
}
|
|
4541
|
+
if ((mask === rval)) {
|
|
4542
|
+
return bits;
|
|
4543
|
+
} else {
|
|
4544
|
+
return 0;
|
|
4545
|
+
}
|
|
4546
|
+
})(0, 0) : 0);
|
|
4547
|
+
let rL = ((!(__eliscript_truthy(((state)["debugRanges"] ?? null))) && __eliscript_truthy(memory_word_type((left)["type"]))) ? local_register(state, left, "u32") : -1);
|
|
4548
|
+
if (((name === "word-shr") && __eliscript_numeric_relation(">", shift_k, 0) && ((left)["kind"] === "memory-op") && (((left)["value"] === "v64-high") || ((left)["value"] === "bits64-high")))) {
|
|
4549
|
+
{
|
|
4550
|
+
let inner = (((((left)["children"]) ?? [])[0]) ?? null);
|
|
4551
|
+
let rIn = ((!(__eliscript_truthy(((state)["debugRanges"] ?? null))) && __eliscript_truthy(memory_wide_type((inner)["type"]))) ? local_register(state, inner, "v64") : -1);
|
|
4552
|
+
if (__eliscript_numeric_relation("<", rIn, 0)) {
|
|
4553
|
+
expression(state, inner);
|
|
4554
|
+
}
|
|
4555
|
+
return word(state, (3544251392 + __eliscript_numeric_mul((32 + shift_k), 65536) + (__eliscript_numeric_relation(">=", rIn, 0) ? __eliscript_numeric_mul(rIn, 32) : 0)));
|
|
4556
|
+
}
|
|
3191
4557
|
} else {
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
4558
|
+
if (__eliscript_numeric_relation(">=", shift_k, 0)) {
|
|
4559
|
+
if (((shift_k === 0) || __eliscript_numeric_relation("<", rL, 0))) {
|
|
4560
|
+
expression(state, left);
|
|
4561
|
+
}
|
|
4562
|
+
if (__eliscript_numeric_relation(">", shift_k, 0)) {
|
|
4563
|
+
return word(state, ((name === "word-shr") ? (1392540672 + __eliscript_numeric_mul(shift_k, 65536) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)) : (1392508928 + __eliscript_numeric_mul(__eliscript_numeric_sub(32, shift_k), 65536) + __eliscript_numeric_mul(__eliscript_numeric_sub(31, shift_k), 1024) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0))));
|
|
4564
|
+
} else {
|
|
4565
|
+
return null;
|
|
4566
|
+
}
|
|
4567
|
+
} else {
|
|
4568
|
+
if (__eliscript_numeric_relation(">", mask_bits, 0)) {
|
|
4569
|
+
if (__eliscript_numeric_relation("<", rL, 0)) {
|
|
4570
|
+
expression(state, left);
|
|
4571
|
+
}
|
|
4572
|
+
return word(state, (301989888 + __eliscript_numeric_mul(__eliscript_numeric_decrement(mask_bits), 1024) + (__eliscript_numeric_relation(">=", rL, 0) ? __eliscript_numeric_mul(rL, 32) : 0)));
|
|
4573
|
+
} else {
|
|
4574
|
+
if ((__eliscript_numeric_relation(">=", rL, 0) && !(__eliscript_truthy(memory_expr_writes_reg_p(state, right, rL))))) {
|
|
4575
|
+
expression(state, right);
|
|
4576
|
+
if ((name === "word-div")) {
|
|
4577
|
+
memory_conditional_error(state, 889192448, 2);
|
|
4578
|
+
}
|
|
4579
|
+
return word(state, (((name === "word-div") ? 448792576 : ((name === "word-shr") ? 448799744 : ((name === "word-shl") ? 448798720 : ((name === "word-and") ? 167772160 : ((name === "word-or") ? 704643072 : ((name === "word-xor") ? 1241513984 : backend_fail(node, "unsupported native memory32 opcode"))))))) + __eliscript_numeric_mul(rL, 32)));
|
|
4580
|
+
} else {
|
|
4581
|
+
expression(state, left);
|
|
4582
|
+
if ((__eliscript_truthy(memory_word_type((right)["type"])) && ((rkind === "literal") || (rkind === "int-literal") || (rkind === "local")))) {
|
|
4583
|
+
word(state, 704644065);
|
|
4584
|
+
expression(state, right);
|
|
4585
|
+
} else {
|
|
4586
|
+
push_value(state, "u32");
|
|
4587
|
+
expression(state, right);
|
|
4588
|
+
pop_value(state, "u32");
|
|
4589
|
+
}
|
|
4590
|
+
if ((name === "word-div")) {
|
|
4591
|
+
memory_conditional_error(state, 889192448, 2);
|
|
4592
|
+
}
|
|
4593
|
+
return word(state, ((name === "word-div") ? 448792608 : ((name === "word-shr") ? 448799776 : ((name === "word-shl") ? 448798752 : ((name === "word-and") ? 167772192 : ((name === "word-or") ? 704643104 : ((name === "word-xor") ? 1241514016 : backend_fail(node, "unsupported native memory32 opcode"))))))));
|
|
4594
|
+
}
|
|
4595
|
+
}
|
|
4596
|
+
}
|
|
3195
4597
|
}
|
|
3196
4598
|
}
|
|
3197
|
-
if ((name === "word-div")) {
|
|
3198
|
-
memory_conditional_error(state, 889192448, 2);
|
|
3199
|
-
}
|
|
3200
|
-
return word(state, ((name === "word-div") ? 448792608 : ((name === "word-shr") ? 448799776 : ((name === "word-shl") ? 448798752 : ((name === "word-and") ? 167772192 : ((name === "word-or") ? 704643104 : ((name === "word-xor") ? 1241514016 : backend_fail(node, "unsupported native memory32 opcode"))))))));
|
|
3201
4599
|
}
|
|
3202
4600
|
}
|
|
3203
4601
|
}
|
|
@@ -3221,7 +4619,7 @@ function memory_wide_type(type) {
|
|
|
3221
4619
|
return ((type === "v64") || (type === "bits64"));
|
|
3222
4620
|
}
|
|
3223
4621
|
function memory_scalar_type(type) {
|
|
3224
|
-
return ((
|
|
4622
|
+
return ((__eliscript_value_35) => (__eliscript_truthy(__eliscript_value_35) ? __eliscript_value_35 : ((__eliscript_value_36) => (__eliscript_truthy(__eliscript_value_36) ? __eliscript_value_36 : (type === "f64")))(memory_wide_type(type))))(memory_word_type(type));
|
|
3225
4623
|
}
|
|
3226
4624
|
function memory_canonical_type(type) {
|
|
3227
4625
|
if (__eliscript_truthy(memory_word_type(type))) {
|
|
@@ -3384,13 +4782,29 @@ function emit_sp_store(state, type, reg, offset) {
|
|
|
3384
4782
|
}
|
|
3385
4783
|
function memory_move_to_reg(state, node, reg, wide) {
|
|
3386
4784
|
{
|
|
4785
|
+
let kind = (node)["kind"];
|
|
3387
4786
|
let type = (node)["type"];
|
|
3388
|
-
if (((
|
|
4787
|
+
if (((kind === "local") && (__eliscript_truthy(memory_word_type(type)) || __eliscript_truthy(memory_wide_type(type))))) {
|
|
3389
4788
|
return expression(state, node, null, reg);
|
|
3390
4789
|
} else {
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
4790
|
+
if ((!(__eliscript_truthy(((state)["debugRanges"] ?? null))) && ((kind === "literal") || (kind === "int-literal")) && __eliscript_truthy(memory_wide_type(type)))) {
|
|
4791
|
+
{
|
|
4792
|
+
let val = (node)["value"];
|
|
4793
|
+
if ((!((val === null)) && (__eliscript_value_type(val) === "object"))) {
|
|
4794
|
+
return memory_wide_register(state, reg, __eliscript_numeric_uint32((val)["low"]), __eliscript_numeric_uint32((val)["high"]));
|
|
4795
|
+
} else {
|
|
4796
|
+
return memory_wide_register(state, reg, __eliscript_numeric_uint32(val), 0);
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
} else {
|
|
4800
|
+
if ((!(__eliscript_truthy(((state)["debugRanges"] ?? null))) && ((kind === "literal") || (kind === "int-literal")) && __eliscript_truthy(memory_word_type(type)))) {
|
|
4801
|
+
return memory_integer_register(state, reg, (node)["value"]);
|
|
4802
|
+
} else {
|
|
4803
|
+
expression(state, node);
|
|
4804
|
+
return word(state, ((__eliscript_truthy(wide) ? 2852127712 : 704644064) + reg));
|
|
4805
|
+
}
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
3394
4808
|
}
|
|
3395
4809
|
}
|
|
3396
4810
|
function memory_call(state, node) {
|
|
@@ -3508,7 +4922,12 @@ function memory_call(state, node) {
|
|
|
3508
4922
|
{
|
|
3509
4923
|
let at = (((state)["words"]) ?? []).length;
|
|
3510
4924
|
word(state, 889192457);
|
|
3511
|
-
|
|
4925
|
+
((state)["memoryErrors"])["push"](at);
|
|
4926
|
+
}
|
|
4927
|
+
if ((__eliscript_truthy(((state)["pinMemory"] ?? null)) && (__eliscript_truthy(indirect) || !(__eliscript_truthy(((state)["mayGrow"] ?? null))) || __eliscript_truthy((((((state)["mayGrow"]) ?? [])[(node)["value"]]) ?? null))))) {
|
|
4928
|
+
return word(state, 4181722748);
|
|
4929
|
+
} else {
|
|
4930
|
+
return null;
|
|
3512
4931
|
}
|
|
3513
4932
|
}
|
|
3514
4933
|
}
|
|
@@ -3532,19 +4951,22 @@ function memory_host_call(state, node) {
|
|
|
3532
4951
|
{
|
|
3533
4952
|
let at = (((state)["words"]) ?? []).length;
|
|
3534
4953
|
word(state, 889192457);
|
|
3535
|
-
|
|
4954
|
+
((state)["memoryErrors"])["push"](at);
|
|
4955
|
+
}
|
|
4956
|
+
if (__eliscript_truthy(((state)["pinMemory"] ?? null))) {
|
|
4957
|
+
return word(state, 4181722748);
|
|
4958
|
+
} else {
|
|
4959
|
+
return null;
|
|
3536
4960
|
}
|
|
3537
4961
|
}
|
|
3538
4962
|
}
|
|
3539
4963
|
function native_phase(observer, phase, count, words, branches, calls) {
|
|
3540
4964
|
if ((__eliscript_value_type(observer) === "function")) {
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
}
|
|
3547
|
-
})();
|
|
4965
|
+
try {
|
|
4966
|
+
observer(phase, ({"count": count, "words": words, "branches": branches, "calls": calls}));
|
|
4967
|
+
} catch (ignored) {
|
|
4968
|
+
null;
|
|
4969
|
+
}
|
|
3548
4970
|
}
|
|
3549
4971
|
return null;
|
|
3550
4972
|
}
|
|
@@ -3569,98 +4991,711 @@ function native_memory_container(program, code, target, format, options, observe
|
|
|
3569
4991
|
}
|
|
3570
4992
|
}
|
|
3571
4993
|
}
|
|
3572
|
-
|
|
4994
|
+
const native_hot_leaf_names = new (globalThis.Set)(["heap-block", "rt-root-scope-set-abs", "rt-root-scope-get-abs", "heap-ro-block", "heap-value-valid", "value-number-bits", "heap-number-from-word", "heap-number-word", "heap-number-uint", "heap-check", "heap-object-init-cell", "heap-string-cached-hash", "heap-object-builtin", "heap-key-equal", "heap-slot-index", "heap-handle", "heap-note-allocation", "val64-dynamic-p", "val64-inline-number-p", "val64-singleton-p", "heap-free-tree-maximum", "heap-free-tree-height", "heap-value-check", "heap-kind-check", "heap-base"]);
|
|
4995
|
+
__eliscript_tdz_ready_2 = true;
|
|
4996
|
+
function memory_leaf_candidate(function$, self_index) {
|
|
3573
4997
|
{
|
|
3574
|
-
let
|
|
3575
|
-
let
|
|
3576
|
-
let
|
|
3577
|
-
let
|
|
3578
|
-
let
|
|
3579
|
-
let
|
|
3580
|
-
|
|
3581
|
-
|
|
4998
|
+
let body = (function$)["body"];
|
|
4999
|
+
let locals = (function$)["locals"];
|
|
5000
|
+
let fname = ((function$)["name"] ?? null);
|
|
5001
|
+
let hot_leaf = ((__eliscript_value_37) => (__eliscript_truthy(__eliscript_value_37) ? ((__eliscript_tdz_ready_2 === true ? native_hot_leaf_names : __eliscript_tdz_error("native_hot_leaf_names")))["has"](fname) : __eliscript_value_37))((__eliscript_value_type(fname) === "string"));
|
|
5002
|
+
let max_nodes = (__eliscript_truthy(hot_leaf) ? 120 : 52);
|
|
5003
|
+
let max_calls = (__eliscript_truthy(hot_leaf) ? 4 : 3);
|
|
5004
|
+
let pending = [body];
|
|
5005
|
+
let count = 0;
|
|
5006
|
+
let calls = 0;
|
|
5007
|
+
let valid = __eliscript_numeric_relation("<=", ((locals) ?? []).length, 12);
|
|
5008
|
+
while ((__eliscript_truthy(valid) && __eliscript_numeric_relation(">", ((pending) ?? []).length, 0))) {
|
|
3582
5009
|
{
|
|
3583
|
-
let
|
|
3584
|
-
let
|
|
3585
|
-
let
|
|
3586
|
-
let
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
((
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
((
|
|
3598
|
-
|
|
5010
|
+
let node = (pending)["pop"]();
|
|
5011
|
+
let kind = (node)["kind"];
|
|
5012
|
+
let children = (node)["children"];
|
|
5013
|
+
let i = 0;
|
|
5014
|
+
((count = (count + 1)));
|
|
5015
|
+
if ((kind === "call")) {
|
|
5016
|
+
((calls = (calls + 1)));
|
|
5017
|
+
if ((((node)["value"] === self_index) || __eliscript_numeric_relation(">", calls, max_calls))) {
|
|
5018
|
+
((valid = null));
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
if ((__eliscript_numeric_relation(">", count, max_nodes) || !(__eliscript_truthy(valid)) || (kind === "call-indirect") || (kind === "host-call") || (kind === "while") || (kind === "remainder-while") || (kind === "guarded-while") || (kind === "memory-data-copy"))) {
|
|
5022
|
+
((valid = null));
|
|
5023
|
+
} else {
|
|
5024
|
+
while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
|
|
5025
|
+
(pending)["push"](((((children) ?? [])[i]) ?? null));
|
|
5026
|
+
((i = (i + 1)));
|
|
5027
|
+
}
|
|
5028
|
+
}
|
|
5029
|
+
}
|
|
5030
|
+
}
|
|
5031
|
+
if (__eliscript_truthy(valid)) {
|
|
5032
|
+
return ({"function": function$, "size": count});
|
|
5033
|
+
} else {
|
|
5034
|
+
return null;
|
|
5035
|
+
}
|
|
5036
|
+
}
|
|
5037
|
+
}
|
|
5038
|
+
function memory_uses_linear_p(node) {
|
|
5039
|
+
{
|
|
5040
|
+
let pending = [node];
|
|
5041
|
+
let found = null;
|
|
5042
|
+
while ((!(__eliscript_truthy(found)) && __eliscript_numeric_relation(">", ((pending) ?? []).length, 0))) {
|
|
5043
|
+
{
|
|
5044
|
+
let item = (pending)["pop"]();
|
|
5045
|
+
let kind = (item)["kind"];
|
|
5046
|
+
if (((kind === "memory-op") && __eliscript_truthy(((op) => {
|
|
5047
|
+
return (__eliscript_numeric_relation(">", memory_width(op), 0) || (op === "memory-grow"));
|
|
5048
|
+
})((item)["value"])))) {
|
|
5049
|
+
((found = true));
|
|
5050
|
+
} else {
|
|
3599
5051
|
{
|
|
3600
|
-
let
|
|
3601
|
-
let
|
|
3602
|
-
((
|
|
3603
|
-
|
|
5052
|
+
let children = (item)["children"];
|
|
5053
|
+
let i = 0;
|
|
5054
|
+
if (__eliscript_truthy(Array.isArray(children))) {
|
|
5055
|
+
while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
|
|
5056
|
+
(pending)["push"](((((children) ?? [])[i]) ?? null));
|
|
5057
|
+
((i = (i + 1)));
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
3604
5060
|
}
|
|
3605
5061
|
}
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
return found;
|
|
5065
|
+
}
|
|
5066
|
+
}
|
|
5067
|
+
function memory_has_inline_site(node, candidates, self_index) {
|
|
5068
|
+
{
|
|
5069
|
+
let pending = [node];
|
|
5070
|
+
let found = null;
|
|
5071
|
+
while ((!(__eliscript_truthy(found)) && __eliscript_numeric_relation(">", ((pending) ?? []).length, 0))) {
|
|
5072
|
+
{
|
|
5073
|
+
let item = (pending)["pop"]();
|
|
5074
|
+
let kind = (item)["kind"];
|
|
5075
|
+
let children = (item)["children"];
|
|
5076
|
+
let i = 0;
|
|
5077
|
+
if (((kind === "call") && ((item)["value"] !== self_index) && !((((((candidates) ?? [])[(item)["value"]]) ?? null) === null)))) {
|
|
5078
|
+
((found = true));
|
|
5079
|
+
} else {
|
|
5080
|
+
while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
|
|
5081
|
+
(pending)["push"](((((children) ?? [])[i]) ?? null));
|
|
5082
|
+
((i = (i + 1)));
|
|
5083
|
+
}
|
|
5084
|
+
}
|
|
5085
|
+
}
|
|
5086
|
+
}
|
|
5087
|
+
return found;
|
|
5088
|
+
}
|
|
5089
|
+
}
|
|
5090
|
+
function memory_shift_clone(node, slot_map) {
|
|
5091
|
+
{
|
|
5092
|
+
let kind = (node)["kind"];
|
|
5093
|
+
let children = (node)["children"];
|
|
5094
|
+
let clen = ((children) ?? []).length;
|
|
5095
|
+
let is_local = ((kind === "local") || (kind === "set") || (kind === "initialize"));
|
|
5096
|
+
if (((clen === 0) && !(__eliscript_truthy(is_local)))) {
|
|
5097
|
+
return node;
|
|
5098
|
+
} else {
|
|
5099
|
+
{
|
|
5100
|
+
let new_children = null;
|
|
5101
|
+
let changed = false;
|
|
5102
|
+
let i = 0;
|
|
5103
|
+
while (__eliscript_numeric_relation("<", i, clen)) {
|
|
3612
5104
|
{
|
|
3613
|
-
let
|
|
3614
|
-
let
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
5105
|
+
let orig = ((((children) ?? [])[i]) ?? null);
|
|
5106
|
+
let cloned = memory_shift_clone(orig, slot_map);
|
|
5107
|
+
if (!((cloned === orig))) {
|
|
5108
|
+
if ((!__eliscript_truthy(new_children))) {
|
|
5109
|
+
((new_children = (children)["slice"]()));
|
|
5110
|
+
}
|
|
5111
|
+
((new_children)[i] = cloned);
|
|
5112
|
+
((changed = true));
|
|
5113
|
+
}
|
|
5114
|
+
}
|
|
5115
|
+
((i = (i + 1)));
|
|
5116
|
+
}
|
|
5117
|
+
if ((!(__eliscript_truthy(changed)) && !(__eliscript_truthy(is_local)))) {
|
|
5118
|
+
return node;
|
|
5119
|
+
} else {
|
|
5120
|
+
{
|
|
5121
|
+
let copy = Object.assign(({}), node);
|
|
5122
|
+
((copy)["children"] = ((__eliscript_value_38) => (__eliscript_truthy(__eliscript_value_38) ? __eliscript_value_38 : children))(new_children));
|
|
5123
|
+
if (__eliscript_truthy(is_local)) {
|
|
5124
|
+
((copy)["value"] = ((((slot_map) ?? [])[(node)["value"]]) ?? null));
|
|
5125
|
+
}
|
|
5126
|
+
return copy;
|
|
5127
|
+
}
|
|
5128
|
+
}
|
|
5129
|
+
}
|
|
5130
|
+
}
|
|
5131
|
+
}
|
|
5132
|
+
}
|
|
5133
|
+
function memory_rewrite_inline(node, candidates, self_index, locals, budget, pools, cursors) {
|
|
5134
|
+
{
|
|
5135
|
+
let kind = (node)["kind"];
|
|
5136
|
+
let children = (node)["children"];
|
|
5137
|
+
let clen = ((children) ?? []).length;
|
|
5138
|
+
let control_flow = ((kind === "sequence") || (kind === "if") || (kind === "while") || (kind === "remainder-while") || (kind === "guarded-while"));
|
|
5139
|
+
let new_children = null;
|
|
5140
|
+
let changed = false;
|
|
5141
|
+
let i = 0;
|
|
5142
|
+
if (__eliscript_truthy(control_flow)) {
|
|
5143
|
+
{
|
|
5144
|
+
let peak = Object.assign(({}), cursors);
|
|
5145
|
+
while (__eliscript_numeric_relation("<", i, clen)) {
|
|
5146
|
+
{
|
|
5147
|
+
let orig = ((((children) ?? [])[i]) ?? null);
|
|
5148
|
+
let child_cursors = Object.assign(({}), cursors);
|
|
5149
|
+
let rewritten = memory_rewrite_inline(orig, candidates, self_index, locals, budget, pools, child_cursors);
|
|
5150
|
+
let pkeys = Object.keys(child_cursors);
|
|
5151
|
+
let pi = 0;
|
|
5152
|
+
while (__eliscript_numeric_relation("<", pi, ((pkeys) ?? []).length)) {
|
|
5153
|
+
{
|
|
5154
|
+
let pk = ((((pkeys) ?? [])[pi]) ?? null);
|
|
5155
|
+
let pv = ((child_cursors)[pk] ?? 0);
|
|
5156
|
+
if (__eliscript_numeric_relation(">", pv, ((peak)[pk] ?? 0))) {
|
|
5157
|
+
((peak)[pk] = pv);
|
|
5158
|
+
}
|
|
5159
|
+
}
|
|
5160
|
+
((pi = (pi + 1)));
|
|
5161
|
+
}
|
|
5162
|
+
if (!((rewritten === orig))) {
|
|
5163
|
+
if ((!__eliscript_truthy(new_children))) {
|
|
5164
|
+
((new_children = (children)["slice"]()));
|
|
5165
|
+
}
|
|
5166
|
+
((new_children)[i] = rewritten);
|
|
5167
|
+
((changed = true));
|
|
5168
|
+
}
|
|
5169
|
+
}
|
|
5170
|
+
((i = (i + 1)));
|
|
5171
|
+
}
|
|
5172
|
+
{
|
|
5173
|
+
let pkeys = Object.keys(peak);
|
|
5174
|
+
let pi = 0;
|
|
5175
|
+
while (__eliscript_numeric_relation("<", pi, ((pkeys) ?? []).length)) {
|
|
5176
|
+
{
|
|
5177
|
+
let pk = ((((pkeys) ?? [])[pi]) ?? null);
|
|
5178
|
+
((cursors)[pk] = (peak)[pk]);
|
|
5179
|
+
}
|
|
5180
|
+
((pi = (pi + 1)));
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5183
|
+
}
|
|
5184
|
+
} else {
|
|
5185
|
+
while (__eliscript_numeric_relation("<", i, clen)) {
|
|
5186
|
+
{
|
|
5187
|
+
let orig = ((((children) ?? [])[i]) ?? null);
|
|
5188
|
+
let rewritten = memory_rewrite_inline(orig, candidates, self_index, locals, budget, pools, cursors);
|
|
5189
|
+
if (!((rewritten === orig))) {
|
|
5190
|
+
if ((!__eliscript_truthy(new_children))) {
|
|
5191
|
+
((new_children = (children)["slice"]()));
|
|
5192
|
+
}
|
|
5193
|
+
((new_children)[i] = rewritten);
|
|
5194
|
+
((changed = true));
|
|
5195
|
+
}
|
|
5196
|
+
}
|
|
5197
|
+
((i = (i + 1)));
|
|
5198
|
+
}
|
|
5199
|
+
}
|
|
5200
|
+
{
|
|
5201
|
+
let target_index = ((kind === "call") ? (node)["value"] : -1);
|
|
5202
|
+
let cand = (((kind === "call") && (target_index !== self_index)) ? ((((candidates) ?? [])[target_index]) ?? null) : null);
|
|
5203
|
+
let callee = (__eliscript_truthy(cand) ? (cand)["function"] : null);
|
|
5204
|
+
let callee_locals = (__eliscript_truthy(callee) ? (callee)["locals"] : null);
|
|
5205
|
+
if ((__eliscript_truthy(cand) && __eliscript_numeric_relation("<=", ((budget)["added"] + (cand)["size"]), (budget)["maxAdded"]))) {
|
|
5206
|
+
{
|
|
5207
|
+
let tmp_cursors = Object.assign(({}), cursors);
|
|
5208
|
+
let new_needed = 0;
|
|
5209
|
+
let k = 0;
|
|
5210
|
+
while (__eliscript_numeric_relation("<", k, ((callee_locals) ?? []).length)) {
|
|
5211
|
+
{
|
|
5212
|
+
let ltype = (((((callee_locals) ?? [])[k]) ?? null))["type"];
|
|
5213
|
+
let pool = (pools)[ltype];
|
|
5214
|
+
let pos = ((tmp_cursors)[ltype] ?? 0);
|
|
5215
|
+
((tmp_cursors)[ltype] = (pos + 1));
|
|
5216
|
+
if (((pool === null) || __eliscript_numeric_relation(">=", pos, ((pool) ?? []).length))) {
|
|
5217
|
+
((new_needed = (new_needed + 1)));
|
|
5218
|
+
}
|
|
5219
|
+
}
|
|
5220
|
+
((k = (k + 1)));
|
|
5221
|
+
}
|
|
5222
|
+
if (__eliscript_numeric_relation(">", (((locals) ?? []).length + new_needed), (budget)["maxLocals"])) {
|
|
5223
|
+
if (__eliscript_truthy(changed)) {
|
|
5224
|
+
{
|
|
5225
|
+
let copy = Object.assign(({}), node);
|
|
5226
|
+
((copy)["children"] = new_children);
|
|
5227
|
+
return copy;
|
|
5228
|
+
}
|
|
3618
5229
|
} else {
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
5230
|
+
return node;
|
|
5231
|
+
}
|
|
5232
|
+
} else {
|
|
5233
|
+
{
|
|
5234
|
+
let callee_arity = (callee)["arity"];
|
|
5235
|
+
let args = ((__eliscript_value_39) => (__eliscript_truthy(__eliscript_value_39) ? __eliscript_value_39 : children))(new_children);
|
|
5236
|
+
let slot_map = [];
|
|
5237
|
+
let seq_children = [];
|
|
5238
|
+
((k = 0));
|
|
5239
|
+
while (__eliscript_numeric_relation("<", k, ((callee_locals) ?? []).length)) {
|
|
5240
|
+
{
|
|
5241
|
+
let ltype = (((((callee_locals) ?? [])[k]) ?? null))["type"];
|
|
5242
|
+
let pool = (pools)[ltype];
|
|
5243
|
+
let pos = ((cursors)[ltype] ?? 0);
|
|
5244
|
+
let slot = null;
|
|
5245
|
+
if ((!__eliscript_truthy(pool))) {
|
|
5246
|
+
((pool = []));
|
|
5247
|
+
((pools)[ltype] = pool);
|
|
5248
|
+
}
|
|
5249
|
+
if (__eliscript_numeric_relation("<", pos, ((pool) ?? []).length)) {
|
|
5250
|
+
((slot = ((((pool) ?? [])[pos]) ?? null)));
|
|
5251
|
+
} else {
|
|
5252
|
+
((slot = ((locals) ?? []).length));
|
|
5253
|
+
(locals)["push"](({"name": (String("inline-") + String(slot)), "type": ltype, "index": slot, "noEntryInit": true}));
|
|
5254
|
+
(pool)["push"](slot);
|
|
5255
|
+
}
|
|
5256
|
+
((cursors)[ltype] = (pos + 1));
|
|
5257
|
+
(slot_map)["push"](slot);
|
|
5258
|
+
if (__eliscript_numeric_relation("<", k, callee_arity)) {
|
|
5259
|
+
(seq_children)["push"](({"kind": "set", "type": ltype, "value": slot, "children": [((((args) ?? [])[k]) ?? null)]}));
|
|
5260
|
+
} else {
|
|
5261
|
+
{
|
|
5262
|
+
let zero_node = ({"kind": "literal", "type": ltype, "value": (__eliscript_truthy(memory_wide_type(ltype)) ? ({"low": 0, "high": 0}) : 0), "children": []});
|
|
5263
|
+
(seq_children)["push"](({"kind": "set", "type": ltype, "value": slot, "children": [zero_node]}));
|
|
5264
|
+
}
|
|
5265
|
+
}
|
|
3622
5266
|
}
|
|
3623
|
-
|
|
3624
|
-
integer_register(state, 9, (16 + (slot)["offset"]), 0);
|
|
3625
|
-
word(state, 2332623785);
|
|
3626
|
-
word(state, ((local_type === "f64") ? 4248830240 : (__eliscript_truthy(memory_wide_type(local_type)) ? 4181721376 : 3107979552)));
|
|
5267
|
+
((k = (k + 1)));
|
|
3627
5268
|
}
|
|
5269
|
+
(seq_children)["push"](memory_shift_clone((callee)["body"], slot_map));
|
|
5270
|
+
((budget)["added"] = ((budget)["added"] + (cand)["size"]));
|
|
5271
|
+
return ({"kind": "sequence", "type": (node)["type"], "children": seq_children});
|
|
3628
5272
|
}
|
|
3629
|
-
local_access(state, j, local_type, true, ((kind === "gpr") ? (slot)["reg"] : 0));
|
|
3630
|
-
((j = (j + 1)));
|
|
3631
5273
|
}
|
|
3632
5274
|
}
|
|
3633
|
-
|
|
5275
|
+
} else {
|
|
5276
|
+
if (__eliscript_truthy(changed)) {
|
|
5277
|
+
{
|
|
5278
|
+
let copy = Object.assign(({}), node);
|
|
5279
|
+
((copy)["children"] = new_children);
|
|
5280
|
+
return copy;
|
|
5281
|
+
}
|
|
5282
|
+
} else {
|
|
5283
|
+
return node;
|
|
5284
|
+
}
|
|
5285
|
+
}
|
|
5286
|
+
}
|
|
5287
|
+
}
|
|
5288
|
+
}
|
|
5289
|
+
function inline_memory_function(self_index, raw_locals, raw_body, candidates) {
|
|
5290
|
+
if (__eliscript_truthy(memory_has_inline_site(raw_body, candidates, self_index))) {
|
|
5291
|
+
{
|
|
5292
|
+
let locals = (raw_locals)["slice"]();
|
|
5293
|
+
let budget = ({"added": 0, "maxAdded": 320, "maxLocals": 80});
|
|
5294
|
+
let pools = ({});
|
|
5295
|
+
let cursors = ({});
|
|
5296
|
+
let body = memory_rewrite_inline(raw_body, candidates, self_index, locals, budget, pools, cursors);
|
|
5297
|
+
return ({"locals": locals, "body": body});
|
|
5298
|
+
}
|
|
5299
|
+
} else {
|
|
5300
|
+
return null;
|
|
5301
|
+
}
|
|
5302
|
+
}
|
|
5303
|
+
function emit_memory_function_into(state, function$, i, raw_locals, raw_body, inline_candidates, linux, debug, offsets) {
|
|
5304
|
+
{
|
|
5305
|
+
let inlined = (__eliscript_truthy(inline_candidates) ? inline_memory_function(i, raw_locals, raw_body, inline_candidates) : null);
|
|
5306
|
+
let locals = (__eliscript_truthy(inlined) ? (inlined)["locals"] : raw_locals);
|
|
5307
|
+
let body = (__eliscript_truthy(inlined) ? (inlined)["body"] : raw_body);
|
|
5308
|
+
let arity = (function$)["arity"];
|
|
5309
|
+
let param_types = function_param_types(function$);
|
|
5310
|
+
let layout = compute_native_param_layout(param_types, linux);
|
|
5311
|
+
let slots = (layout)["slots"];
|
|
5312
|
+
let return_type = function_return_type(function$);
|
|
5313
|
+
let pin_memory = memory_uses_linear_p(body);
|
|
5314
|
+
let allocation = allocate_memory_registers(body, locals, pin_memory, arity);
|
|
5315
|
+
let saved = (allocation)["saved"];
|
|
5316
|
+
let spilled = (allocation)["spilled"];
|
|
5317
|
+
let no_init = (allocation)["noInit"];
|
|
5318
|
+
let frame = __eliscript_numeric_mul((globalThis.Math)["ceil"](__eliscript_numeric_div(((__eliscript_truthy(pin_memory) ? 3 : 1) + saved + spilled), 2)), 16);
|
|
5319
|
+
let j = 0;
|
|
5320
|
+
let save_regs = ((regs, si) => {
|
|
5321
|
+
while (__eliscript_numeric_relation("<", si, saved)) {
|
|
5322
|
+
(regs)["push"]((20 + si));
|
|
5323
|
+
((si = (si + 1)));
|
|
5324
|
+
}
|
|
5325
|
+
if (__eliscript_truthy(pin_memory)) {
|
|
5326
|
+
(regs)["push"](27);
|
|
5327
|
+
(regs)["push"](28);
|
|
5328
|
+
}
|
|
5329
|
+
return regs;
|
|
5330
|
+
})([19], 0);
|
|
5331
|
+
if (__eliscript_truthy(offsets)) {
|
|
5332
|
+
(offsets)["push"](__eliscript_numeric_mul((((state)["words"]) ?? []).length, 4));
|
|
5333
|
+
}
|
|
5334
|
+
((state)["registers"] = (allocation)["registers"]);
|
|
5335
|
+
((state)["localOffsets"] = (allocation)["offsets"]);
|
|
5336
|
+
((state)["depth"] = 0);
|
|
5337
|
+
((state)["memoryErrors"] = []);
|
|
5338
|
+
((state)["pinMemory"] = pin_memory);
|
|
5339
|
+
((state)["boundsErrors"] = []);
|
|
5340
|
+
if (__eliscript_truthy(debug)) {
|
|
5341
|
+
((state)["debugFunction"] = (function$)["name"]);
|
|
5342
|
+
((state)["debugFunctionIndex"] = i);
|
|
5343
|
+
((state)["debugDepth"] = 0);
|
|
5344
|
+
{
|
|
5345
|
+
let source = ((function$)["source"] ?? null);
|
|
5346
|
+
let range = ({"kind": "function", "function": (function$)["name"], "functionIndex": i, "depth": -1, "start": __eliscript_numeric_mul(4, (((state)["words"]) ?? []).length), "end": 0, "span": ((function$)["span"] ?? (__eliscript_truthy(source) ? ((source)["span"] ?? null) : null))});
|
|
5347
|
+
((state)["debugFunctionRange"] = range);
|
|
5348
|
+
((state)["debugRanges"])["push"](range);
|
|
5349
|
+
}
|
|
5350
|
+
}
|
|
5351
|
+
word(state, 2847898621);
|
|
5352
|
+
word(state, 2432697341);
|
|
5353
|
+
stack_adjust(state, frame, true);
|
|
5354
|
+
{
|
|
5355
|
+
let si = 0;
|
|
5356
|
+
let slen = ((save_regs) ?? []).length;
|
|
5357
|
+
while (__eliscript_numeric_relation("<", si, slen)) {
|
|
5358
|
+
if (__eliscript_numeric_relation("<", (si + 1), slen)) {
|
|
5359
|
+
word(state, (2835350496 + __eliscript_numeric_mul(si, 32768) + __eliscript_numeric_mul(((((save_regs) ?? [])[(si + 1)]) ?? null), 1024) + ((((save_regs) ?? [])[si]) ?? null)));
|
|
5360
|
+
((si = (si + 2)));
|
|
5361
|
+
} else {
|
|
5362
|
+
word(state, (4177527776 + __eliscript_numeric_mul(si, 1024) + ((((save_regs) ?? [])[si]) ?? null)));
|
|
5363
|
+
((si = (si + 1)));
|
|
5364
|
+
}
|
|
5365
|
+
}
|
|
5366
|
+
}
|
|
5367
|
+
word(state, 2852127731);
|
|
5368
|
+
if (__eliscript_truthy(pin_memory)) {
|
|
5369
|
+
word(state, 4181721723);
|
|
5370
|
+
word(state, 4181722748);
|
|
5371
|
+
}
|
|
5372
|
+
while (__eliscript_numeric_relation("<", j, arity)) {
|
|
5373
|
+
{
|
|
5374
|
+
let slot = ((((slots) ?? [])[j]) ?? null);
|
|
5375
|
+
let kind = (slot)["kind"];
|
|
5376
|
+
let local_type = (((((locals) ?? [])[j]) ?? null))["type"];
|
|
5377
|
+
if ((kind === "gpr")) {
|
|
5378
|
+
null;
|
|
5379
|
+
} else {
|
|
5380
|
+
if ((kind === "fpr")) {
|
|
5381
|
+
if ((!((slot)["reg"] === 0))) {
|
|
5382
|
+
word(state, (509624320 + __eliscript_numeric_mul((slot)["reg"], 32)));
|
|
5383
|
+
}
|
|
5384
|
+
} else {
|
|
5385
|
+
integer_register(state, 9, (16 + (slot)["offset"]), 0);
|
|
5386
|
+
word(state, 2332623785);
|
|
5387
|
+
word(state, ((local_type === "f64") ? 4248830240 : (__eliscript_truthy(memory_wide_type(local_type)) ? 4181721376 : 3107979552)));
|
|
5388
|
+
}
|
|
5389
|
+
}
|
|
5390
|
+
local_access(state, j, local_type, true, ((kind === "gpr") ? (slot)["reg"] : 0));
|
|
5391
|
+
((j = (j + 1)));
|
|
5392
|
+
}
|
|
5393
|
+
}
|
|
5394
|
+
while (__eliscript_numeric_relation("<", j, ((locals) ?? []).length)) {
|
|
5395
|
+
{
|
|
5396
|
+
let local = ((((locals) ?? [])[j]) ?? null);
|
|
5397
|
+
let type = (local)["type"];
|
|
5398
|
+
if ((!(__eliscript_truthy(((local)["noEntryInit"] ?? null)) || (__eliscript_truthy(no_init) && __eliscript_truthy(((((no_init) ?? [])[j]) ?? null)))))) {
|
|
5399
|
+
if ((type === "f64")) {
|
|
5400
|
+
word(state, 2657551328);
|
|
5401
|
+
local_access(state, j, type, true);
|
|
5402
|
+
} else {
|
|
5403
|
+
local_access(state, j, type, true, 31);
|
|
5404
|
+
}
|
|
5405
|
+
}
|
|
5406
|
+
}
|
|
5407
|
+
((j = (j + 1)));
|
|
5408
|
+
}
|
|
5409
|
+
expression(state, body);
|
|
5410
|
+
{
|
|
5411
|
+
let normal = jump(state, "jump");
|
|
5412
|
+
if (__eliscript_numeric_relation(">", (((state)["boundsErrors"]) ?? []).length, 0)) {
|
|
5413
|
+
patch_conditions(state, (state)["boundsErrors"], (((state)["words"]) ?? []).length);
|
|
5414
|
+
memory_integer_register(state, 9, 1);
|
|
5415
|
+
word(state, 3103791721);
|
|
5416
|
+
}
|
|
5417
|
+
patch_conditions(state, (state)["memoryErrors"], (((state)["words"]) ?? []).length);
|
|
5418
|
+
if ((return_type === "f64")) {
|
|
5419
|
+
word(state, 2657551328);
|
|
5420
|
+
} else {
|
|
5421
|
+
memory_integer_register(state, 0, 0);
|
|
5422
|
+
}
|
|
5423
|
+
patch_jump(state, normal, (((state)["words"]) ?? []).length);
|
|
5424
|
+
}
|
|
5425
|
+
if (__eliscript_numeric_relation("<=", frame, 4095)) {
|
|
5426
|
+
word(state, (3506439081 + __eliscript_numeric_mul(frame, 1024)));
|
|
5427
|
+
} else {
|
|
5428
|
+
integer_register(state, 9, frame, 0);
|
|
5429
|
+
word(state, 3406365609);
|
|
5430
|
+
}
|
|
5431
|
+
{
|
|
5432
|
+
let si = 0;
|
|
5433
|
+
let slen = ((save_regs) ?? []).length;
|
|
5434
|
+
while (__eliscript_numeric_relation("<", si, slen)) {
|
|
5435
|
+
if (__eliscript_numeric_relation("<", (si + 1), slen)) {
|
|
5436
|
+
word(state, (2839544096 + __eliscript_numeric_mul(si, 32768) + __eliscript_numeric_mul(((((save_regs) ?? [])[(si + 1)]) ?? null), 1024) + ((((save_regs) ?? [])[si]) ?? null)));
|
|
5437
|
+
((si = (si + 2)));
|
|
5438
|
+
} else {
|
|
5439
|
+
word(state, (4181721376 + __eliscript_numeric_mul(si, 1024) + ((((save_regs) ?? [])[si]) ?? null)));
|
|
5440
|
+
((si = (si + 1)));
|
|
5441
|
+
}
|
|
5442
|
+
}
|
|
5443
|
+
}
|
|
5444
|
+
word(state, 2432697279);
|
|
5445
|
+
word(state, 2831252477);
|
|
5446
|
+
word(state, 3596551104);
|
|
5447
|
+
if (__eliscript_truthy(debug)) {
|
|
5448
|
+
return (((state)["debugFunctionRange"])["end"] = __eliscript_numeric_mul(4, (((state)["words"]) ?? []).length));
|
|
5449
|
+
} else {
|
|
5450
|
+
return null;
|
|
5451
|
+
}
|
|
5452
|
+
}
|
|
5453
|
+
}
|
|
5454
|
+
function pack_native_function_cache(fn_state, fn_name = null, fn_arity = null, fn_locals_len = null) {
|
|
5455
|
+
if ((((((fn_state)["constants"]) ?? []).length === 0) && ((((fn_state)["tableUses"]) ?? []).length === 0))) {
|
|
5456
|
+
{
|
|
5457
|
+
let fn_branches = ((fn_state)["branches"] ?? []);
|
|
5458
|
+
let bcount = ((fn_branches) ?? []).length;
|
|
5459
|
+
let all_fit = true;
|
|
5460
|
+
let bi = 0;
|
|
5461
|
+
while ((__eliscript_truthy(all_fit) && __eliscript_numeric_relation("<", bi, bcount))) {
|
|
5462
|
+
{
|
|
5463
|
+
let b = ((((fn_branches) ?? [])[bi]) ?? null);
|
|
5464
|
+
if ((!__eliscript_truthy(branch_fits(__eliscript_numeric_sub((b)["target"], (b)["at"]), branch_limit((b)["kind"]))))) {
|
|
5465
|
+
((all_fit = false));
|
|
5466
|
+
}
|
|
5467
|
+
}
|
|
5468
|
+
((bi = (bi + 1)));
|
|
5469
|
+
}
|
|
5470
|
+
if (__eliscript_truthy(all_fit)) {
|
|
5471
|
+
{
|
|
5472
|
+
let fn_calls = (fn_state)["calls"];
|
|
5473
|
+
let ccount = ((fn_calls) ?? []).length;
|
|
5474
|
+
let packed_calls = new (globalThis.Uint32Array)(__eliscript_numeric_mul(ccount, 2));
|
|
5475
|
+
let packed_branches = new (globalThis.Uint32Array)(__eliscript_numeric_mul(bcount, 4));
|
|
5476
|
+
let ci = 0;
|
|
5477
|
+
let fn_ranges = ((fn_state)["debugRanges"] ?? null);
|
|
5478
|
+
while (__eliscript_numeric_relation("<", ci, ccount)) {
|
|
5479
|
+
{
|
|
5480
|
+
let c = ((((fn_calls) ?? [])[ci]) ?? null);
|
|
5481
|
+
let off = __eliscript_numeric_mul(ci, 2);
|
|
5482
|
+
((packed_calls)[off] = (c)["at"]);
|
|
5483
|
+
((packed_calls)[(off + 1)] = (c)["target"]);
|
|
5484
|
+
}
|
|
5485
|
+
((ci = (ci + 1)));
|
|
5486
|
+
}
|
|
5487
|
+
((bi = 0));
|
|
5488
|
+
while (__eliscript_numeric_relation("<", bi, bcount)) {
|
|
5489
|
+
{
|
|
5490
|
+
let b = ((((fn_branches) ?? [])[bi]) ?? null);
|
|
5491
|
+
let off = __eliscript_numeric_mul(bi, 4);
|
|
5492
|
+
((packed_branches)[off] = (b)["at"]);
|
|
5493
|
+
((packed_branches)[(off + 1)] = (b)["target"]);
|
|
5494
|
+
((packed_branches)[(off + 2)] = (b)["opcode"]);
|
|
5495
|
+
((packed_branches)[(off + 3)] = (b)["kind"]);
|
|
5496
|
+
}
|
|
5497
|
+
((bi = (bi + 1)));
|
|
5498
|
+
}
|
|
3634
5499
|
{
|
|
3635
|
-
let
|
|
3636
|
-
if ((
|
|
3637
|
-
|
|
3638
|
-
|
|
5500
|
+
let entry = ({"words": new (globalThis.Uint32Array)((fn_state)["words"]), "calls": packed_calls, "branches": packed_branches});
|
|
5501
|
+
if (__eliscript_truthy(fn_ranges)) {
|
|
5502
|
+
((entry)["debugRanges"] = fn_ranges);
|
|
5503
|
+
((entry)["functionName"] = fn_name);
|
|
5504
|
+
((entry)["arity"] = fn_arity);
|
|
5505
|
+
((entry)["localsLength"] = fn_locals_len);
|
|
5506
|
+
}
|
|
5507
|
+
return entry;
|
|
5508
|
+
}
|
|
5509
|
+
}
|
|
5510
|
+
} else {
|
|
5511
|
+
return null;
|
|
5512
|
+
}
|
|
5513
|
+
}
|
|
5514
|
+
} else {
|
|
5515
|
+
return null;
|
|
5516
|
+
}
|
|
5517
|
+
}
|
|
5518
|
+
function replay_native_function_cache(state, entry, offsets, function$ = null) {
|
|
5519
|
+
{
|
|
5520
|
+
let base = (((state)["words"]) ?? []).length;
|
|
5521
|
+
let packed_calls = (entry)["calls"];
|
|
5522
|
+
let call_len = ((packed_calls) ?? []).length;
|
|
5523
|
+
let calls = (state)["calls"];
|
|
5524
|
+
let ci = 0;
|
|
5525
|
+
let packed_branches = (entry)["branches"];
|
|
5526
|
+
let cached_ranges = ((entry)["debugRanges"] ?? null);
|
|
5527
|
+
let dst_ranges = ((state)["debugRanges"] ?? null);
|
|
5528
|
+
(offsets)["push"](__eliscript_numeric_mul(base, 4));
|
|
5529
|
+
native_word_append_u32((state)["words"], (entry)["words"]);
|
|
5530
|
+
while (__eliscript_numeric_relation("<", ci, call_len)) {
|
|
5531
|
+
(calls)["push"](({"at": (base + (packed_calls)[ci]), "target": (packed_calls)[(ci + 1)]}));
|
|
5532
|
+
((ci = (ci + 2)));
|
|
5533
|
+
}
|
|
5534
|
+
if (__eliscript_numeric_relation(">", ((packed_branches) ?? []).length, 0)) {
|
|
5535
|
+
((state)["cachedBranches"])["push"](({"base": base, "branches": packed_branches}));
|
|
5536
|
+
}
|
|
5537
|
+
if ((__eliscript_truthy(cached_ranges) && __eliscript_truthy(dst_ranges))) {
|
|
5538
|
+
{
|
|
5539
|
+
let base_bytes = __eliscript_numeric_mul(base, 4);
|
|
5540
|
+
let dst_sites = ((state)["trapSites"] ?? null);
|
|
5541
|
+
let source = (__eliscript_truthy(function$) ? ((function$)["source"] ?? null) : null);
|
|
5542
|
+
let fn_span = (__eliscript_truthy(function$) ? ((function$)["span"] ?? (__eliscript_truthy(source) ? ((source)["span"] ?? null) : null)) : null);
|
|
5543
|
+
let ri = 0;
|
|
5544
|
+
let rlen = ((cached_ranges) ?? []).length;
|
|
5545
|
+
while (__eliscript_numeric_relation("<", ri, rlen)) {
|
|
5546
|
+
{
|
|
5547
|
+
let r = ((((cached_ranges) ?? [])[ri]) ?? null);
|
|
5548
|
+
let cloned = (((ri === 0) && ((r)["kind"] === "function") && __eliscript_truthy(function$)) ? Object.assign(({}), r, ({"start": (base_bytes + (r)["start"]), "end": (base_bytes + (r)["end"]), "span": fn_span})) : Object.assign(({}), r, ({"start": (base_bytes + (r)["start"]), "end": (base_bytes + (r)["end"])})));
|
|
5549
|
+
(dst_ranges)["push"](cloned);
|
|
5550
|
+
if ((__eliscript_truthy(dst_sites) && ((cloned)["kind"] === "trap-site"))) {
|
|
5551
|
+
(dst_sites)["push"](cloned);
|
|
5552
|
+
}
|
|
5553
|
+
}
|
|
5554
|
+
((ri = (ri + 1)));
|
|
5555
|
+
}
|
|
5556
|
+
return null;
|
|
5557
|
+
}
|
|
5558
|
+
} else {
|
|
5559
|
+
return null;
|
|
5560
|
+
}
|
|
5561
|
+
}
|
|
5562
|
+
}
|
|
5563
|
+
function compute_memory_may_grow(functions) {
|
|
5564
|
+
{
|
|
5565
|
+
let count = ((functions) ?? []).length;
|
|
5566
|
+
let grow = (new (globalThis.Array)(count))["fill"](false);
|
|
5567
|
+
let edges = new (globalThis.Array)(count);
|
|
5568
|
+
let i = 0;
|
|
5569
|
+
while (__eliscript_numeric_relation("<", i, count)) {
|
|
5570
|
+
{
|
|
5571
|
+
let deps = [];
|
|
5572
|
+
let seen = new (globalThis.Set)();
|
|
5573
|
+
let pending = [(((((functions) ?? [])[i]) ?? null))["body"]];
|
|
5574
|
+
while (__eliscript_numeric_relation(">", ((pending) ?? []).length, 0)) {
|
|
5575
|
+
{
|
|
5576
|
+
let item = (pending)["pop"]();
|
|
5577
|
+
let kind = (item)["kind"];
|
|
5578
|
+
let children = (item)["children"];
|
|
5579
|
+
let j = 0;
|
|
5580
|
+
if (((kind === "host-call") || (kind === "call-indirect") || ((kind === "memory-op") && ((item)["value"] === "memory-grow")))) {
|
|
5581
|
+
((grow)[i] = true);
|
|
3639
5582
|
} else {
|
|
3640
|
-
|
|
5583
|
+
if ((kind === "call")) {
|
|
5584
|
+
{
|
|
5585
|
+
let callee = (item)["value"];
|
|
5586
|
+
if ((!((callee === i) || __eliscript_truthy((seen)["has"](callee))))) {
|
|
5587
|
+
(seen)["add"](callee);
|
|
5588
|
+
(deps)["push"](callee);
|
|
5589
|
+
}
|
|
5590
|
+
}
|
|
5591
|
+
} else {
|
|
5592
|
+
|
|
5593
|
+
}
|
|
5594
|
+
}
|
|
5595
|
+
if (__eliscript_truthy(Array.isArray(children))) {
|
|
5596
|
+
while (__eliscript_numeric_relation("<", j, ((children) ?? []).length)) {
|
|
5597
|
+
(pending)["push"](((((children) ?? [])[j]) ?? null));
|
|
5598
|
+
((j = (j + 1)));
|
|
5599
|
+
}
|
|
3641
5600
|
}
|
|
3642
5601
|
}
|
|
3643
|
-
((j = (j + 1)));
|
|
3644
5602
|
}
|
|
3645
|
-
|
|
5603
|
+
((edges)[i] = deps);
|
|
5604
|
+
}
|
|
5605
|
+
((i = (i + 1)));
|
|
5606
|
+
}
|
|
5607
|
+
{
|
|
5608
|
+
let changed = true;
|
|
5609
|
+
while (__eliscript_truthy(changed)) {
|
|
5610
|
+
((changed = false), (i = 0));
|
|
5611
|
+
while (__eliscript_numeric_relation("<", i, count)) {
|
|
5612
|
+
if ((!__eliscript_truthy(((((grow) ?? [])[i]) ?? null)))) {
|
|
5613
|
+
{
|
|
5614
|
+
let deps = ((((edges) ?? [])[i]) ?? null);
|
|
5615
|
+
let k = 0;
|
|
5616
|
+
while (__eliscript_numeric_relation("<", k, ((deps) ?? []).length)) {
|
|
5617
|
+
if (__eliscript_truthy(((((grow) ?? [])[((((deps) ?? [])[k]) ?? null)]) ?? null))) {
|
|
5618
|
+
((grow)[i] = true);
|
|
5619
|
+
((changed = true), (k = ((deps) ?? []).length));
|
|
5620
|
+
}
|
|
5621
|
+
((k = (k + 1)));
|
|
5622
|
+
}
|
|
5623
|
+
}
|
|
5624
|
+
}
|
|
5625
|
+
((i = (i + 1)));
|
|
5626
|
+
}
|
|
5627
|
+
}
|
|
5628
|
+
}
|
|
5629
|
+
return grow;
|
|
5630
|
+
}
|
|
5631
|
+
}
|
|
5632
|
+
function memory_code(program, target = null, options = null, observer = null) {
|
|
5633
|
+
{
|
|
5634
|
+
let linux = (target === "arm64-linux");
|
|
5635
|
+
let opts = ((__eliscript_value_40) => (__eliscript_truthy(__eliscript_value_40) ? __eliscript_value_40 : ({})))(options);
|
|
5636
|
+
let debug = ((opts)["debug"] ?? null);
|
|
5637
|
+
let functions = (program)["functions"];
|
|
5638
|
+
let rt_prefix_count = ((program)["rtPrefixCount"] ?? 0);
|
|
5639
|
+
let optimize_memory = ((!__eliscript_truthy(debug)) && __eliscript_numeric_relation(">=", ((functions) ?? []).length, 16));
|
|
5640
|
+
let may_grow = (__eliscript_truthy(optimize_memory) ? compute_memory_may_grow(functions) : null);
|
|
5641
|
+
let mode_key = (String((__eliscript_truthy(linux) ? "L" : "M")) + String(":") + String((__eliscript_truthy(optimize_memory) ? "O" : "N")));
|
|
5642
|
+
let packed_words = ((__eliscript_value_41) => (__eliscript_truthy(__eliscript_value_41) ? __eliscript_value_41 : (((opts)["binaryEncoding"] ?? null) === "u16le-chunks")))(((opts)["packedWords"] ?? null));
|
|
5643
|
+
let inline_candidates = (__eliscript_truthy(optimize_memory) ? ((arr, k) => {
|
|
5644
|
+
while (__eliscript_numeric_relation("<", k, ((functions) ?? []).length)) {
|
|
3646
5645
|
{
|
|
3647
|
-
let
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
5646
|
+
let fn = ((((functions) ?? [])[k]) ?? null);
|
|
5647
|
+
if (__eliscript_numeric_relation("<", k, rt_prefix_count)) {
|
|
5648
|
+
{
|
|
5649
|
+
let rc = runtime_body_cache_get((fn)["body"]);
|
|
5650
|
+
let leaf = ((__eliscript_truthy(rc) && __eliscript_truthy((rc)["frozen"])) ? (rc)["leafCandidate"] : -1);
|
|
5651
|
+
((arr)[k] = (__eliscript_numeric_relation(">=", leaf, 0) ? ({"function": fn, "size": leaf}) : null));
|
|
5652
|
+
}
|
|
3651
5653
|
} else {
|
|
3652
|
-
|
|
5654
|
+
((arr)[k] = memory_leaf_candidate(fn, k));
|
|
3653
5655
|
}
|
|
3654
|
-
patch_jump(state, normal, (((state)["words"]) ?? []).length);
|
|
3655
5656
|
}
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
5657
|
+
((k = (k + 1)));
|
|
5658
|
+
}
|
|
5659
|
+
return arr;
|
|
5660
|
+
})(new (globalThis.Array)(((functions) ?? []).length), 0) : null);
|
|
5661
|
+
let state = ({"words": (__eliscript_truthy(packed_words) ? native_word_buffer() : []), "calls": [], "constants": [], "branches": [], "cachedBranches": [], "compact": null, "leaf": null, "memory": true, "optimizeMemory": optimize_memory, "mayGrow": may_grow, "linux": linux, "registers": [], "localOffsets": null, "functions": functions, "signatureMap": ((program)["signatureMap"] ?? null), "debugRanges": (__eliscript_truthy(debug) ? [] : null), "trapSites": (__eliscript_truthy(debug) ? [] : null), "hostCapabilities": ((program)["hostCapabilities"] ?? []), "table": ((program)["table"] ?? null), "tableUses": []});
|
|
5662
|
+
let offsets = [];
|
|
5663
|
+
let i = 0;
|
|
5664
|
+
native_phase(observer, "native-code-start", 0, 0, 0, 0);
|
|
5665
|
+
while (__eliscript_numeric_relation("<", i, ((functions) ?? []).length)) {
|
|
5666
|
+
{
|
|
5667
|
+
let function$ = ((((functions) ?? [])[i]) ?? null);
|
|
5668
|
+
let raw_locals = (function$)["locals"];
|
|
5669
|
+
let raw_body = (function$)["body"];
|
|
5670
|
+
let cache_rec = (__eliscript_numeric_relation("<", i, rt_prefix_count) ? runtime_body_cache_get(raw_body) : null);
|
|
5671
|
+
let can_cache = ((__eliscript_value_42) => (__eliscript_truthy(__eliscript_value_42) ? ((__eliscript_value_43) => (__eliscript_truthy(__eliscript_value_43) ? ((!__eliscript_truthy((cache_rec)["hasIndirect"])) && (!__eliscript_truthy((cache_rec)["hasHostCall"])) && __eliscript_numeric_relation("<", (cache_rec)["maxCallTarget"], rt_prefix_count)) : __eliscript_value_43))((cache_rec)["frozen"]) : __eliscript_value_42))(cache_rec);
|
|
5672
|
+
if (__eliscript_truthy(can_cache)) {
|
|
5673
|
+
{
|
|
5674
|
+
let native_bodies = (cache_rec)["nativeBodies"];
|
|
5675
|
+
let fn_key = (__eliscript_truthy(debug) ? (String((__eliscript_truthy(linux) ? "L" : "M")) + String(":N:D:") + String(i) + String(":") + String((((state)["trapSites"]) ?? []).length)) : mode_key);
|
|
5676
|
+
let cached_entry = (native_bodies)["get"](fn_key);
|
|
5677
|
+
if ((__eliscript_truthy(cached_entry) && (!(__eliscript_truthy(debug)) || (((cached_entry)["functionName"] === (function$)["name"]) && ((cached_entry)["arity"] === (function$)["arity"]) && ((cached_entry)["localsLength"] === ((raw_locals) ?? []).length))))) {
|
|
5678
|
+
replay_native_function_cache(state, cached_entry, offsets, function$);
|
|
5679
|
+
} else {
|
|
5680
|
+
{
|
|
5681
|
+
let fn_state = ({"words": [], "calls": [], "branches": [], "constants": [], "compact": null, "leaf": null, "memory": true, "optimizeMemory": optimize_memory, "mayGrow": may_grow, "linux": linux, "registers": [], "localOffsets": null, "functions": functions, "signatureMap": ((program)["signatureMap"] ?? null), "debugRanges": (__eliscript_truthy(debug) ? [] : null), "trapSites": (__eliscript_truthy(debug) ? [] : null), "trapSiteBase": (__eliscript_truthy(debug) ? (((state)["trapSites"]) ?? []).length : 0), "hostCapabilities": ((program)["hostCapabilities"] ?? []), "table": ((program)["table"] ?? null), "tableUses": []});
|
|
5682
|
+
emit_memory_function_into(fn_state, function$, i, raw_locals, raw_body, inline_candidates, linux, debug, null);
|
|
5683
|
+
{
|
|
5684
|
+
let packed = (__eliscript_truthy(debug) ? pack_native_function_cache(fn_state, (function$)["name"], (function$)["arity"], ((raw_locals) ?? []).length) : pack_native_function_cache(fn_state));
|
|
5685
|
+
if (__eliscript_truthy(packed)) {
|
|
5686
|
+
if ((!__eliscript_truthy(cached_entry))) {
|
|
5687
|
+
(native_bodies)["set"](fn_key, packed);
|
|
5688
|
+
}
|
|
5689
|
+
replay_native_function_cache(state, packed, offsets, function$);
|
|
5690
|
+
} else {
|
|
5691
|
+
emit_memory_function_into(state, function$, i, raw_locals, raw_body, inline_candidates, linux, debug, offsets);
|
|
5692
|
+
}
|
|
5693
|
+
}
|
|
5694
|
+
}
|
|
5695
|
+
}
|
|
5696
|
+
}
|
|
5697
|
+
} else {
|
|
5698
|
+
emit_memory_function_into(state, function$, i, raw_locals, raw_body, inline_candidates, linux, debug, offsets);
|
|
3664
5699
|
}
|
|
3665
5700
|
}
|
|
3666
5701
|
((i = (i + 1)));
|
|
@@ -3756,7 +5791,7 @@ function memory_validate_node(node, function$, program, allowed_indirect, capabi
|
|
|
3756
5791
|
}
|
|
3757
5792
|
{
|
|
3758
5793
|
let param_types = (node)["parameterTypes"];
|
|
3759
|
-
let ret_type = ((
|
|
5794
|
+
let ret_type = ((__eliscript_value_44) => (__eliscript_truthy(__eliscript_value_44) ? __eliscript_value_44 : (node)["type"]))(((node)["resultType"] ?? null));
|
|
3760
5795
|
let k = 0;
|
|
3761
5796
|
if ((!((((param_types) ?? []).length === value) && __eliscript_truthy(memory_scalar_type(ret_type)) && __eliscript_truthy(memory_same_abi_type((node)["type"], ret_type))))) {
|
|
3762
5797
|
backend_fail(node, "indirect calls require a declared signature");
|
|
@@ -3817,6 +5852,18 @@ function memory_validate_node(node, function$, program, allowed_indirect, capabi
|
|
|
3817
5852
|
return null;
|
|
3818
5853
|
}
|
|
3819
5854
|
}
|
|
5855
|
+
function native_locals_sig(locals) {
|
|
5856
|
+
{
|
|
5857
|
+
let parts = [];
|
|
5858
|
+
let len = ((locals) ?? []).length;
|
|
5859
|
+
let i = 0;
|
|
5860
|
+
while (__eliscript_numeric_relation("<", i, len)) {
|
|
5861
|
+
(parts)["push"]((((((locals) ?? [])[i]) ?? null))["type"]);
|
|
5862
|
+
((i = (i + 1)));
|
|
5863
|
+
}
|
|
5864
|
+
return __eliscript_at_direct(parts, "join", ",");
|
|
5865
|
+
}
|
|
5866
|
+
}
|
|
3820
5867
|
function memory_prepare_program_core(program, fresh) {
|
|
3821
5868
|
if ((!((program)["abi"] === "memory-u32"))) {
|
|
3822
5869
|
backend_fail(program, "native memory emitter requires memory-u32 typed input");
|
|
@@ -3920,76 +5967,124 @@ function memory_prepare_program_core(program, fresh) {
|
|
|
3920
5967
|
((i = (i + 1)));
|
|
3921
5968
|
}
|
|
3922
5969
|
}
|
|
3923
|
-
((i = 0));
|
|
3924
|
-
while (__eliscript_numeric_relation("<", i, ((functions) ?? []).length)) {
|
|
3925
|
-
{
|
|
3926
|
-
let function$ = ((((functions) ?? [])[i]) ?? null);
|
|
3927
|
-
memory_validate_node((function$)["body"], function$, program, allowed_indirect, capabilities, (__eliscript_truthy(fresh) ? new (globalThis.WeakMap)() : null));
|
|
3928
|
-
}
|
|
3929
|
-
((i = (i + 1)));
|
|
3930
|
-
}
|
|
3931
5970
|
{
|
|
3932
|
-
let
|
|
3933
|
-
let
|
|
3934
|
-
let
|
|
3935
|
-
let
|
|
3936
|
-
if (
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
5971
|
+
let first_cached = (__eliscript_numeric_relation(">", ((functions) ?? []).length, 0) ? runtime_body_cache_get(((((((functions) ?? [])[0]) ?? null))["body"] ?? null)) : null);
|
|
5972
|
+
let rt_id = (__eliscript_truthy(first_cached) ? ((first_cached)["runtimeId"] ?? 0) : 0);
|
|
5973
|
+
let rt_count = (__eliscript_truthy(first_cached) ? ((first_cached)["runtimeFnCount"] ?? 0) : 0);
|
|
5974
|
+
let rt_prefix_ok = (__eliscript_numeric_relation(">", rt_id, 0) && __eliscript_numeric_relation(">", rt_count, 0) && __eliscript_numeric_relation("<=", rt_count, ((functions) ?? []).length));
|
|
5975
|
+
if (__eliscript_truthy(rt_prefix_ok)) {
|
|
5976
|
+
{
|
|
5977
|
+
let ri = 0;
|
|
5978
|
+
while ((__eliscript_truthy(rt_prefix_ok) && __eliscript_numeric_relation("<", ri, rt_count))) {
|
|
5979
|
+
{
|
|
5980
|
+
let rfn = ((((functions) ?? [])[ri]) ?? null);
|
|
5981
|
+
let rc = runtime_body_cache_get(((rfn)["body"] ?? null));
|
|
5982
|
+
if ((!(__eliscript_truthy(rc) && ((rc)["runtimeId"] === rt_id) && ((rc)["runtimeFnCount"] === rt_count) && ((rc)["fnIndex"] === ri) && ((rc)["arity"] === (rfn)["arity"]) && ((rc)["localsSig"] === native_locals_sig((rfn)["locals"]))))) {
|
|
5983
|
+
((rt_prefix_ok = false));
|
|
5984
|
+
}
|
|
5985
|
+
}
|
|
5986
|
+
((ri = (ri + 1)));
|
|
5987
|
+
}
|
|
3943
5988
|
}
|
|
3944
|
-
(seen)["push"](((((public$) ?? [])[i]) ?? null));
|
|
3945
|
-
((i = (i + 1)));
|
|
3946
5989
|
}
|
|
3947
5990
|
((i = 0));
|
|
3948
|
-
while (__eliscript_numeric_relation("<", i, ((
|
|
5991
|
+
while (__eliscript_numeric_relation("<", i, ((functions) ?? []).length)) {
|
|
3949
5992
|
{
|
|
3950
|
-
let
|
|
3951
|
-
let
|
|
3952
|
-
let
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
if ((name === (target)["name"])) {
|
|
3959
|
-
null;
|
|
3960
|
-
} else {
|
|
3961
|
-
if (__eliscript_truthy(find_function(functions, name))) {
|
|
3962
|
-
backend_fail(program, "native alias shadows a function");
|
|
3963
|
-
}
|
|
3964
|
-
{
|
|
3965
|
-
let locals = [];
|
|
3966
|
-
let arguments$ = [];
|
|
3967
|
-
let target_locals = (target)["locals"];
|
|
3968
|
-
let target_ret = ((target)["body"])["type"];
|
|
3969
|
-
let j = 0;
|
|
3970
|
-
while (__eliscript_numeric_relation("<", j, (target)["arity"])) {
|
|
3971
|
-
{
|
|
3972
|
-
let param_type = (((((target_locals) ?? [])[j]) ?? null))["type"];
|
|
3973
|
-
(locals)["push"](({"name": (String("argument-") + String(j)), "type": param_type, "index": j}));
|
|
3974
|
-
(arguments$)["push"](({"kind": "local", "type": param_type, "value": j, "children": []}));
|
|
3975
|
-
}
|
|
3976
|
-
((j = (j + 1)));
|
|
3977
|
-
}
|
|
3978
|
-
(combined)["push"](({"name": name, "index": ((combined) ?? []).length, "arity": (target)["arity"], "locals": locals, "parameterTypes": function_param_types(target), "resultType": function_return_type(target), "body": ({"kind": "call", "type": target_ret, "value": (target)["index"], "children": arguments$})}));
|
|
5993
|
+
let function$ = ((((functions) ?? [])[i]) ?? null);
|
|
5994
|
+
let fn_body = (function$)["body"];
|
|
5995
|
+
let c = ((__eliscript_truthy(rt_prefix_ok) && __eliscript_numeric_relation("<", i, rt_count)) ? runtime_body_cache_get(fn_body) : null);
|
|
5996
|
+
let can_cache = ((__eliscript_value_45) => (__eliscript_truthy(__eliscript_value_45) ? ((__eliscript_value_46) => (__eliscript_truthy(__eliscript_value_46) ? ((!__eliscript_truthy((c)["hasIndirect"])) && (!__eliscript_truthy((c)["hasHostCall"])) && __eliscript_numeric_relation("<", (c)["maxCallTarget"], rt_count)) : __eliscript_value_46))((c)["frozen"]) : __eliscript_value_45))(c);
|
|
5997
|
+
if (__eliscript_truthy(can_cache)) {
|
|
5998
|
+
if ((!__eliscript_truthy((c)["nativeValidated"]))) {
|
|
5999
|
+
memory_validate_node(fn_body, function$, program, allowed_indirect, capabilities, (__eliscript_truthy(fresh) ? new (globalThis.WeakMap)() : null));
|
|
6000
|
+
((c)["nativeValidated"] = true);
|
|
3979
6001
|
}
|
|
6002
|
+
} else {
|
|
6003
|
+
memory_validate_node(fn_body, function$, program, allowed_indirect, capabilities, (__eliscript_truthy(fresh) ? new (globalThis.WeakMap)() : null));
|
|
3980
6004
|
}
|
|
3981
6005
|
}
|
|
3982
6006
|
((i = (i + 1)));
|
|
3983
6007
|
}
|
|
3984
6008
|
{
|
|
3985
|
-
let
|
|
3986
|
-
|
|
3987
|
-
|
|
6009
|
+
let combined = (functions)["slice"]();
|
|
6010
|
+
let public$ = (exports)["slice"]();
|
|
6011
|
+
let aliases = ((program)["aliases"] ?? []);
|
|
6012
|
+
let seen = new (globalThis.Set)();
|
|
6013
|
+
let fn_by_name = new (globalThis.Map)();
|
|
6014
|
+
((i = 0));
|
|
6015
|
+
while (__eliscript_numeric_relation("<", i, ((functions) ?? []).length)) {
|
|
6016
|
+
{
|
|
6017
|
+
let fn = ((((functions) ?? [])[i]) ?? null);
|
|
6018
|
+
if ((!__eliscript_truthy((fn_by_name)["has"]((fn)["name"])))) {
|
|
6019
|
+
(fn_by_name)["set"]((fn)["name"], fn);
|
|
6020
|
+
}
|
|
6021
|
+
}
|
|
6022
|
+
((i = (i + 1)));
|
|
6023
|
+
}
|
|
6024
|
+
if ((!__eliscript_truthy(Array.isArray(aliases)))) {
|
|
6025
|
+
backend_fail(program, "invalid native aliases");
|
|
6026
|
+
}
|
|
6027
|
+
((i = 0));
|
|
6028
|
+
while (__eliscript_numeric_relation("<", i, ((public$) ?? []).length)) {
|
|
6029
|
+
{
|
|
6030
|
+
let pub_name = ((((public$) ?? [])[i]) ?? null);
|
|
6031
|
+
if ((!(__eliscript_truthy((fn_by_name)["get"](pub_name)) && !(__eliscript_truthy((seen)["has"](pub_name)))))) {
|
|
6032
|
+
backend_fail(program, "invalid or duplicate native export");
|
|
6033
|
+
}
|
|
6034
|
+
(seen)["add"](pub_name);
|
|
6035
|
+
}
|
|
6036
|
+
((i = (i + 1)));
|
|
3988
6037
|
}
|
|
3989
|
-
|
|
3990
|
-
|
|
6038
|
+
((i = 0));
|
|
6039
|
+
while (__eliscript_numeric_relation("<", i, ((aliases) ?? []).length)) {
|
|
6040
|
+
{
|
|
6041
|
+
let alias = ((((aliases) ?? [])[i]) ?? null);
|
|
6042
|
+
let name = (alias)["name"];
|
|
6043
|
+
let target = (fn_by_name)["get"]((alias)["function"]);
|
|
6044
|
+
if ((!(__eliscript_truthy(target) && (__eliscript_value_type(name) === "string") && !(__eliscript_truthy((seen)["has"](name)))))) {
|
|
6045
|
+
backend_fail(program, "invalid or duplicate native alias");
|
|
6046
|
+
}
|
|
6047
|
+
(seen)["add"](name);
|
|
6048
|
+
(public$)["push"](name);
|
|
6049
|
+
if ((name === (target)["name"])) {
|
|
6050
|
+
null;
|
|
6051
|
+
} else {
|
|
6052
|
+
if (__eliscript_truthy((fn_by_name)["get"](name))) {
|
|
6053
|
+
backend_fail(program, "native alias shadows a function");
|
|
6054
|
+
}
|
|
6055
|
+
{
|
|
6056
|
+
let locals = [];
|
|
6057
|
+
let arguments$ = [];
|
|
6058
|
+
let target_locals = (target)["locals"];
|
|
6059
|
+
let target_ret = ((target)["body"])["type"];
|
|
6060
|
+
let j = 0;
|
|
6061
|
+
while (__eliscript_numeric_relation("<", j, (target)["arity"])) {
|
|
6062
|
+
{
|
|
6063
|
+
let param_type = (((((target_locals) ?? [])[j]) ?? null))["type"];
|
|
6064
|
+
(locals)["push"](({"name": (String("argument-") + String(j)), "type": param_type, "index": j}));
|
|
6065
|
+
(arguments$)["push"](({"kind": "local", "type": param_type, "value": j, "children": []}));
|
|
6066
|
+
}
|
|
6067
|
+
((j = (j + 1)));
|
|
6068
|
+
}
|
|
6069
|
+
(combined)["push"](({"name": name, "index": ((combined) ?? []).length, "arity": (target)["arity"], "locals": locals, "parameterTypes": function_param_types(target), "resultType": function_return_type(target), "body": ({"kind": "call", "type": target_ret, "value": (target)["index"], "children": arguments$})}));
|
|
6070
|
+
}
|
|
6071
|
+
}
|
|
6072
|
+
}
|
|
6073
|
+
((i = (i + 1)));
|
|
6074
|
+
}
|
|
6075
|
+
{
|
|
6076
|
+
let prepared = ({"abi": "memory-u32", "filename": (program)["filename"], "functions": combined, "exports": public$, "table": table, "signatureMap": signature_map});
|
|
6077
|
+
if (__eliscript_truthy(rt_prefix_ok)) {
|
|
6078
|
+
((prepared)["rtPrefixCount"] = rt_count);
|
|
6079
|
+
}
|
|
6080
|
+
if (__eliscript_numeric_relation(">", ((capabilities) ?? []).length, 0)) {
|
|
6081
|
+
((prepared)["hostCapabilities"] = capabilities);
|
|
6082
|
+
}
|
|
6083
|
+
if (__eliscript_truthy(((program)["roData"] ?? null))) {
|
|
6084
|
+
((prepared)["roData"] = (program)["roData"]);
|
|
6085
|
+
}
|
|
6086
|
+
return prepared;
|
|
3991
6087
|
}
|
|
3992
|
-
return prepared;
|
|
3993
6088
|
}
|
|
3994
6089
|
}
|
|
3995
6090
|
}
|
|
@@ -4003,7 +6098,7 @@ function memory_prepare_fresh_program(program) {
|
|
|
4003
6098
|
function memory_indirect_target(state, node) {
|
|
4004
6099
|
{
|
|
4005
6100
|
let param_types = (node)["parameterTypes"];
|
|
4006
|
-
let ret_type = ((
|
|
6101
|
+
let ret_type = ((__eliscript_value_47) => (__eliscript_truthy(__eliscript_value_47) ? __eliscript_value_47 : (node)["type"]))(((node)["resultType"] ?? null));
|
|
4007
6102
|
let sig_id = ((state)["signatureMap"])["get"](native_signature_key(param_types, ret_type));
|
|
4008
6103
|
word(state, 704709612);
|
|
4009
6104
|
memory_integer_register(state, 0, (((state)["table"]) ?? []).length);
|
|
@@ -4032,7 +6127,7 @@ function memory_finish_table(state, program, offsets) {
|
|
|
4032
6127
|
let sig_map = (state)["signatureMap"];
|
|
4033
6128
|
let i = 0;
|
|
4034
6129
|
if (__eliscript_truthy(table)) {
|
|
4035
|
-
if ((
|
|
6130
|
+
if ((__eliscript_numeric_and((((state)["words"]) ?? []).length, 1) !== 0)) {
|
|
4036
6131
|
word(state, 3573751839);
|
|
4037
6132
|
}
|
|
4038
6133
|
{
|
|
@@ -4096,7 +6191,7 @@ function emit_observed_typed_native_memory_artifact(program, target, options, ob
|
|
|
4096
6191
|
backend_fail(program, "native memory target must be explicit arm64-macos or arm64-linux");
|
|
4097
6192
|
}
|
|
4098
6193
|
{
|
|
4099
|
-
let format = ((((
|
|
6194
|
+
let format = ((((__eliscript_value_48) => (__eliscript_truthy(__eliscript_value_48) ? __eliscript_value_48 : ({})))(options))["format"] ?? "library");
|
|
4100
6195
|
let prepared = native_memory_prepare(program, observer, fresh);
|
|
4101
6196
|
let code = memory_code(prepared, target, ({"debug": true, "packedWords": true}), observer);
|
|
4102
6197
|
let bytes = null;
|