cfsolve 0.1.2 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +8 -3
- data/THIRD_PARTY_LICENSES/README.md +71 -254
- data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
- data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
- data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
- data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
- data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
- data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
- data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
- data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
- data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
- data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
- data/UPSTREAM.md +14 -6
- data/ext/cfsolve/Cargo.lock +534 -1727
- data/ext/cfsolve/Cargo.toml +4 -0
- data/ext/cfsolve/src/main.rs +1 -1
- data/lib/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
- data/lib/cfsolve/profiles/chrome-157-macos.json +613 -0
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
- data/lib/cfsolve/version.rb +2 -2
- data/lib/cfsolve.rb +1 -1
- data/vendor/cfsolve/Cargo.lock +561 -1729
- data/vendor/cfsolve/Cargo.toml +26 -8
- data/vendor/cfsolve/README.md +57 -5
- data/vendor/cfsolve/examples/check_answers.rs +2 -2
- data/vendor/cfsolve/examples/compare_session.rs +1 -2
- data/vendor/cfsolve/examples/solver_profile.rs +84 -0
- data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
- data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
- data/vendor/cfsolve/examples/tls_echo.rs +3 -3
- data/vendor/cfsolve/examples/turnstile_smoke.rs +58 -0
- data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
- data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
- data/vendor/cfsolve/profiles/chrome-157-macos.json +613 -0
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
- data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
- data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
- data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
- data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- data/vendor/cfsolve/src/capture/sessions.rs +4 -3
- data/vendor/cfsolve/src/capture/upstream.rs +1 -1
- data/vendor/cfsolve/src/challenge/codec.rs +4 -2
- data/vendor/cfsolve/src/challenge/expression.rs +161 -117
- data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
- data/vendor/cfsolve/src/challenge/installed.rs +13 -6
- data/vendor/cfsolve/src/challenge/merge.rs +120 -80
- data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
- data/vendor/cfsolve/src/challenge/payload.rs +69 -31
- data/vendor/cfsolve/src/challenge/program.rs +197 -178
- data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
- data/vendor/cfsolve/src/challenge/source.rs +151 -96
- data/vendor/cfsolve/src/challenge/state.rs +180 -148
- data/vendor/cfsolve/src/challenge/tally.rs +64 -50
- data/vendor/cfsolve/src/challenge.rs +1 -0
- data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
- data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
- data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
- data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
- data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
- data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
- data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
- data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
- data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
- data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
- data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
- data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
- data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
- data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
- data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
- data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
- data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
- data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
- data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
- data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
- data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
- data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
- data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
- data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
- data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
- data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
- data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
- data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
- data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
- data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
- data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
- data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
- data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
- data/vendor/cfsolve/src/deobfuscate.rs +15 -11
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +132 -24
- data/vendor/cfsolve/src/embedding_page/page.rs +41 -1
- data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
- data/vendor/cfsolve/src/error.rs +40 -5
- data/vendor/cfsolve/src/fingerprint.rs +8 -2
- data/vendor/cfsolve/src/http/client.rs +7 -10
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -263
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -9
- data/vendor/cfsolve/src/listing/query.rs +1 -47
- data/vendor/cfsolve/src/performance_clock.rs +20 -1
- data/vendor/cfsolve/src/profiling.rs +49 -0
- data/vendor/cfsolve/src/script.rs +35 -24
- data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
- data/vendor/cfsolve/src/session/channel.rs +2 -2
- data/vendor/cfsolve/src/session/initial.rs +12 -11
- data/vendor/cfsolve/src/session/probes.rs +1 -0
- data/vendor/cfsolve/src/session/sink.rs +26 -1
- data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +33 -4
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +13 -2
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
- data/vendor/cfsolve/src/stage2/benchmark.rs +113 -41
- data/vendor/cfsolve/src/stage2/call_stack.rs +1564 -1041
- data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
- data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +1 -0
- data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
- data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
- data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
- data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/dates.rs +44 -0
- data/vendor/cfsolve/src/stage2/probes/parent_info_array.rs +326 -0
- data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
- data/vendor/cfsolve/src/stage2/probes/stack.rs +117 -4
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +80 -2
- data/vendor/cfsolve/src/stage2/probes.rs +1 -0
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/reference.rs +5 -0
- data/vendor/cfsolve/src/stage2/registry.rs +8 -2
- data/vendor/cfsolve/src/stage2/replay.rs +34 -3
- data/vendor/cfsolve/src/stage2/stylesheets.rs +35 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +134 -108
- data/vendor/cfsolve/src/stage2/value_labels.rs +185 -0
- data/vendor/cfsolve/src/stage2/vocabulary.rs +112 -17
- data/vendor/cfsolve/src/stage2.rs +3 -0
- data/vendor/cfsolve/src/vm/disassemble.rs +75 -7
- data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
- data/vendor/cfsolve/src/vm/encoded_names.rs +635 -0
- data/vendor/cfsolve/src/vm/extract.rs +550 -250
- data/vendor/cfsolve/src/vm/fixtures/free_functions/README.md +9 -0
- data/vendor/cfsolve/src/vm/fixtures/free_functions/machine.js +7438 -0
- data/vendor/cfsolve/src/vm/fixtures/free_functions/program.base64 +1 -0
- data/vendor/cfsolve/src/vm/interpret/access.rs +71 -50
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
- data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
- data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
- data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
- data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +160 -58
- data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
- data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +1765 -0
- data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +392 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +120 -45
- data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
- data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
- data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
- data/vendor/cfsolve/src/vm/interpret.rs +9 -1
- data/vendor/cfsolve/src/vm/machine.rs +116 -51
- data/vendor/cfsolve/src/vm/output.rs +19 -6
- data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
- data/vendor/cfsolve/src/vm/registers.rs +35 -21
- data/vendor/cfsolve/src/vm/session.rs +189 -121
- data/vendor/cfsolve/src/vm/value.rs +22 -19
- data/vendor/cfsolve/src/vm.rs +3 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- metadata +106 -178
- data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
- data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
- data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
- data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
- data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
- data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
- data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
- data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
- data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
- data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
- /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
//! Runs compiled
|
|
1
|
+
//! Runs plans compiled by [`super::compile`]. Computes byte-dependent values and leaves
|
|
2
2
|
//! register-dependent values symbolic. Slot plans store locals in `locals`; scoped plans pass
|
|
3
3
|
//! no local slots.
|
|
4
4
|
|
|
5
|
-
use
|
|
6
|
-
use
|
|
7
|
-
use std::{mem, slice};
|
|
5
|
+
use oxc::ast::ast::{Expression as Expr, Statement as Stmt};
|
|
6
|
+
use oxc::syntax::operator::{BinaryOperator, LogicalOperator, UpdateOperator};
|
|
8
7
|
|
|
9
|
-
use
|
|
10
|
-
|
|
11
|
-
use super::
|
|
12
|
-
use super::
|
|
13
|
-
use super::
|
|
14
|
-
use super::{compile, semantics};
|
|
15
|
-
use crate::vm::HashMap;
|
|
8
|
+
use super::access::Key;
|
|
9
|
+
use super::compile::{self, Code};
|
|
10
|
+
use super::plan::{self, FunctionPlan, Name};
|
|
11
|
+
use super::run::{CallScope, Evaluation, Flow, Frame, Run, Stop};
|
|
12
|
+
use super::semantics;
|
|
16
13
|
use crate::vm::output::Term;
|
|
17
|
-
use crate::vm::value::{
|
|
18
|
-
|
|
19
|
-
/// Maximum handler loop count. Valid constants require fewer iterations; exceeding it indicates
|
|
20
|
-
/// invalid instruction bytes.
|
|
21
|
-
pub(super) const MAXIMUM_ITERATIONS: usize = 1 << 16;
|
|
14
|
+
use crate::vm::value::{Scope, Value};
|
|
22
15
|
|
|
23
16
|
impl<'ast> Run<'ast, '_> {
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
/// Runs `statement` through a scoped plan.
|
|
18
|
+
pub(super) fn statement(
|
|
19
|
+
&mut self,
|
|
20
|
+
statement: &'ast Stmt<'ast>,
|
|
21
|
+
) -> Evaluation<'ast, Flow<'ast>> {
|
|
22
|
+
compile::statement(&plan::scoped_statement(self.session.script, statement))(self, &mut [])
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
/// Evaluates `expression` through a scoped plan.
|
|
26
|
+
pub(in crate::vm) fn expression(
|
|
27
|
+
&mut self,
|
|
28
|
+
expression: &'ast Expr<'ast>,
|
|
29
|
+
) -> Evaluation<'ast, Value<'ast>> {
|
|
30
|
+
compile::compute(&plan::scoped_expression(self.session.script, expression))(self, &mut [])
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/// Calls a slot plan. Its scope holds the locals nested functions mention, inside `closed`,
|
|
@@ -74,20 +75,27 @@ impl<'ast> Run<'ast, '_> {
|
|
|
74
75
|
if let Some(slot) = plan.arguments {
|
|
75
76
|
locals[slot] = Some(Value::array(arguments.clone()));
|
|
76
77
|
}
|
|
77
|
-
let
|
|
78
|
+
let mut frame = Frame {
|
|
79
|
+
this,
|
|
80
|
+
scope: CallScope::Deferred(closed.cloned()),
|
|
81
|
+
};
|
|
78
82
|
let mut values = arguments.drain(..);
|
|
79
83
|
for parameter in &plan.parameters {
|
|
80
84
|
let value = values.next().unwrap_or(Value::Undefined);
|
|
81
85
|
match *parameter {
|
|
82
86
|
Name::Local(slot, _) => locals[slot] = Some(value),
|
|
83
|
-
Name::
|
|
84
|
-
|
|
87
|
+
Name::Scoped(binding) => {
|
|
88
|
+
frame
|
|
89
|
+
.own_scope()
|
|
90
|
+
.borrow_mut()
|
|
91
|
+
.variables
|
|
92
|
+
.insert(binding, value);
|
|
85
93
|
}
|
|
86
94
|
}
|
|
87
95
|
}
|
|
88
96
|
drop(values);
|
|
89
97
|
self.spare.arguments.push(arguments);
|
|
90
|
-
self.frames.push(
|
|
98
|
+
self.frames.push(frame);
|
|
91
99
|
locals
|
|
92
100
|
}
|
|
93
101
|
|
|
@@ -125,478 +133,21 @@ impl<'ast> Run<'ast, '_> {
|
|
|
125
133
|
pub(super) fn body(
|
|
126
134
|
&mut self,
|
|
127
135
|
frame: Frame<'ast>,
|
|
128
|
-
body: &[
|
|
136
|
+
body: &[Code<'ast>],
|
|
129
137
|
locals: &mut Locals<'ast>,
|
|
130
138
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
131
139
|
self.frames.push(frame);
|
|
132
|
-
let flow =
|
|
140
|
+
let flow = compile::run_all(body, self, locals);
|
|
133
141
|
self.frames.pop();
|
|
134
142
|
flow.map(returned)
|
|
135
143
|
}
|
|
136
144
|
|
|
137
|
-
fn execute_all(
|
|
138
|
-
&mut self,
|
|
139
|
-
statements: &[Statement<'ast>],
|
|
140
|
-
locals: &mut Locals<'ast>,
|
|
141
|
-
) -> Evaluation<'ast, Flow<'ast>> {
|
|
142
|
-
for statement in statements {
|
|
143
|
-
let flow = self.execute(statement, locals)?;
|
|
144
|
-
if !matches!(flow, Flow::Normal) {
|
|
145
|
-
return Ok(flow);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
Ok(Flow::Normal)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/// Checks whether `name` has already been declared in the current function.
|
|
152
|
-
pub(super) fn declared(&self, name: Name<'ast>, locals: &Locals<'ast>) -> bool {
|
|
153
|
-
match name {
|
|
154
|
-
Name::Local(slot, _) => locals[slot].is_some(),
|
|
155
|
-
Name::Global(name) => self.frame().scope.borrow().variables.contains_key(name),
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
145
|
/// Declares `name` with `value`.
|
|
160
146
|
pub(super) fn bind(&mut self, name: Name<'ast>, value: Value<'ast>, locals: &mut Locals<'ast>) {
|
|
161
147
|
match name {
|
|
162
148
|
Name::Local(slot, _) => locals[slot] = Some(value),
|
|
163
|
-
Name::
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
fn execute(
|
|
168
|
-
&mut self,
|
|
169
|
-
statement: &Statement<'ast>,
|
|
170
|
-
locals: &mut Locals<'ast>,
|
|
171
|
-
) -> Evaluation<'ast, Flow<'ast>> {
|
|
172
|
-
match statement {
|
|
173
|
-
Statement::Switch(discriminant, cases) => {
|
|
174
|
-
return self.switch(discriminant, cases, locals);
|
|
175
|
-
}
|
|
176
|
-
Statement::Empty => {}
|
|
177
|
-
Statement::Expression(expression) => self.evaluate(expression, locals)?.discard(),
|
|
178
|
-
Statement::Declare(declarations) => {
|
|
179
|
-
for declaration in declarations {
|
|
180
|
-
let value = match &declaration.init {
|
|
181
|
-
Some(expression) => self.evaluate(expression, locals)?,
|
|
182
|
-
None if declaration.keeps && self.declared(declaration.name, locals) => {
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
None => Value::Undefined,
|
|
186
|
-
};
|
|
187
|
-
self.bind(declaration.name, value, locals);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
Statement::Try {
|
|
191
|
-
block,
|
|
192
|
-
parameter,
|
|
193
|
-
handler,
|
|
194
|
-
finalizer,
|
|
195
|
-
} => {
|
|
196
|
-
return self.attempt(
|
|
197
|
-
block.as_slice(),
|
|
198
|
-
*parameter,
|
|
199
|
-
handler.as_deref(),
|
|
200
|
-
finalizer.as_deref(),
|
|
201
|
-
locals,
|
|
202
|
-
Self::execute_all,
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
Statement::Block(statements) => return self.execute_all(statements, locals),
|
|
206
|
-
Statement::If(test, yes, no) => {
|
|
207
|
-
let test = self.evaluate(test, locals)?;
|
|
208
|
-
if self.decide(&test) {
|
|
209
|
-
return self.execute(yes, locals);
|
|
210
|
-
}
|
|
211
|
-
if let Some(no) = no {
|
|
212
|
-
return self.execute(no, locals);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
Statement::Return(expression) => {
|
|
216
|
-
return Ok(Flow::Return(match expression {
|
|
217
|
-
Some(expression) => self.evaluate(expression, locals)?,
|
|
218
|
-
None => Value::Undefined,
|
|
219
|
-
}));
|
|
220
|
-
}
|
|
221
|
-
Statement::Throw(expression) => {
|
|
222
|
-
return Err(Stop::throw(self.evaluate(expression, locals)?));
|
|
223
|
-
}
|
|
224
|
-
Statement::Break(label) => return Ok(Flow::Break(label.cloned())),
|
|
225
|
-
Statement::Continue(label) => return Ok(Flow::Continue(label.cloned())),
|
|
226
|
-
Statement::Label(label, body) => {
|
|
227
|
-
return Ok(match self.execute(body, locals)? {
|
|
228
|
-
Flow::Break(Some(target)) if target == **label => Flow::Normal,
|
|
229
|
-
flow => flow,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
Statement::Loop {
|
|
233
|
-
init,
|
|
234
|
-
test,
|
|
235
|
-
update,
|
|
236
|
-
body,
|
|
237
|
-
body_first,
|
|
238
|
-
label,
|
|
239
|
-
} => {
|
|
240
|
-
if let Some(init) = init {
|
|
241
|
-
self.execute(init, locals)?;
|
|
242
|
-
}
|
|
243
|
-
let mut first = *body_first;
|
|
244
|
-
for _ in 0..MAXIMUM_ITERATIONS {
|
|
245
|
-
if !first && let Some(test) = test {
|
|
246
|
-
let condition = self.evaluate(test, locals)?;
|
|
247
|
-
let repeats = condition
|
|
248
|
-
.truthy()
|
|
249
|
-
.ok_or_else(|| Stop::unsupported("a loop over registers"))?;
|
|
250
|
-
if !repeats {
|
|
251
|
-
return Ok(Flow::Normal);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
first = false;
|
|
255
|
-
match self.execute(body, locals)? {
|
|
256
|
-
Flow::Normal | Flow::Continue(None) => {}
|
|
257
|
-
Flow::Continue(Some(target)) if Some(&target) == *label => {}
|
|
258
|
-
Flow::Break(None) => return Ok(Flow::Normal),
|
|
259
|
-
flow => return Ok(flow),
|
|
260
|
-
}
|
|
261
|
-
if let Some(update) = update {
|
|
262
|
-
self.evaluate(update, locals)?;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return Err(Stop::unsupported("a loop past the longest constant"));
|
|
266
|
-
}
|
|
149
|
+
Name::Scoped(binding) => self.declare(binding, value),
|
|
267
150
|
}
|
|
268
|
-
Ok(Flow::Normal)
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/// Runs a `try` statement whose bodies `run` executes: `block`, then `handler` with an
|
|
272
|
-
/// exception bound to `parameter`, then `finalizer`.
|
|
273
|
-
#[inline]
|
|
274
|
-
pub(super) fn attempt<Body: ?Sized>(
|
|
275
|
-
&mut self,
|
|
276
|
-
block: &Body,
|
|
277
|
-
parameter: Option<Name<'ast>>,
|
|
278
|
-
handler: Option<&Body>,
|
|
279
|
-
finalizer: Option<&Body>,
|
|
280
|
-
locals: &mut Locals<'ast>,
|
|
281
|
-
run: impl Fn(&mut Self, &Body, &mut Locals<'ast>) -> Evaluation<'ast, Flow<'ast>>,
|
|
282
|
-
) -> Evaluation<'ast, Flow<'ast>> {
|
|
283
|
-
let mut outcome = run(self, block, locals);
|
|
284
|
-
if let Some(handler) = handler
|
|
285
|
-
&& let Err(stop) = &mut outcome
|
|
286
|
-
&& let Stop::Throw(exception) = &mut **stop
|
|
287
|
-
{
|
|
288
|
-
let exception = mem::replace(exception, Value::Undefined);
|
|
289
|
-
if let Some(parameter) = parameter {
|
|
290
|
-
self.bind(parameter, exception, locals);
|
|
291
|
-
}
|
|
292
|
-
outcome = run(self, handler, locals);
|
|
293
|
-
}
|
|
294
|
-
// A jump from `finally` overrides the previous completion of the block.
|
|
295
|
-
if let Some(finalizer) = finalizer {
|
|
296
|
-
match run(self, finalizer, locals)? {
|
|
297
|
-
Flow::Normal => {}
|
|
298
|
-
flow => return Ok(flow),
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
outcome
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/// Runs from the first case strictly equal to `discriminant`, or else from the default.
|
|
305
|
-
fn switch(
|
|
306
|
-
&mut self,
|
|
307
|
-
discriminant: &Expression<'ast>,
|
|
308
|
-
cases: &[Case<'ast>],
|
|
309
|
-
locals: &mut Locals<'ast>,
|
|
310
|
-
) -> Evaluation<'ast, Flow<'ast>> {
|
|
311
|
-
let discriminant = self.evaluate(discriminant, locals)?;
|
|
312
|
-
let mut matched = None;
|
|
313
|
-
let mut default = None;
|
|
314
|
-
for (index, case) in cases.iter().enumerate() {
|
|
315
|
-
let Some(test) = &case.test else {
|
|
316
|
-
default = default.or(Some(index));
|
|
317
|
-
continue;
|
|
318
|
-
};
|
|
319
|
-
let test = self.evaluate(test, locals)?;
|
|
320
|
-
let equal = semantics::strict_equal(&discriminant, &test)
|
|
321
|
-
.ok_or_else(|| Stop::unsupported("a switch over registers"))?;
|
|
322
|
-
if equal {
|
|
323
|
-
matched = Some(index);
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
let Some(start) = matched.or(default) else {
|
|
328
|
-
return Ok(Flow::Normal);
|
|
329
|
-
};
|
|
330
|
-
for case in &cases[start..] {
|
|
331
|
-
match self.execute_all(&case.body, locals)? {
|
|
332
|
-
Flow::Normal => {}
|
|
333
|
-
Flow::Break(None) => return Ok(Flow::Normal),
|
|
334
|
-
flow => return Ok(flow),
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
Ok(Flow::Normal)
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
fn property(
|
|
341
|
-
&mut self,
|
|
342
|
-
property: &Property<'ast>,
|
|
343
|
-
locals: &mut Locals<'ast>,
|
|
344
|
-
) -> Evaluation<'ast, Key<'ast, 'ast>> {
|
|
345
|
-
Ok(match property {
|
|
346
|
-
Property::Name(name) => Key::name(name),
|
|
347
|
-
Property::Computed(expression) => Key::from(self.evaluate(expression, locals)?),
|
|
348
|
-
})
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/// Reads common constants and locals directly. Delegates other nodes to separate functions
|
|
352
|
-
/// to keep recursive stack frames small.
|
|
353
|
-
#[inline(always)]
|
|
354
|
-
fn evaluate(
|
|
355
|
-
&mut self,
|
|
356
|
-
expression: &Expression<'ast>,
|
|
357
|
-
locals: &mut Locals<'ast>,
|
|
358
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
359
|
-
match expression {
|
|
360
|
-
Expression::Constant(value) => Ok(copied(value)),
|
|
361
|
-
Expression::Name(Name::Local(slot, _)) if let Some(value) = &locals[*slot] => {
|
|
362
|
-
Ok(match value {
|
|
363
|
-
Value::Symbolic(_) => self.refined(value),
|
|
364
|
-
value => copied(value),
|
|
365
|
-
})
|
|
366
|
-
}
|
|
367
|
-
Expression::Binary(operator, left, right) => {
|
|
368
|
-
self.binary(*operator, left, right, locals)
|
|
369
|
-
}
|
|
370
|
-
Expression::Arithmetic { .. } => self.arithmetic(expression, locals),
|
|
371
|
-
Expression::Member(object, property) => self.member(object, property, locals),
|
|
372
|
-
Expression::Assign(target, operator, right) => {
|
|
373
|
-
self.assignment(target, *operator, right, locals)
|
|
374
|
-
}
|
|
375
|
-
Expression::Update {
|
|
376
|
-
target,
|
|
377
|
-
operator,
|
|
378
|
-
prefix,
|
|
379
|
-
} => self.update(target, *operator, *prefix, locals),
|
|
380
|
-
Expression::Call(callee, arguments) => self.call(callee, arguments, locals),
|
|
381
|
-
Expression::Logical {
|
|
382
|
-
operator,
|
|
383
|
-
left,
|
|
384
|
-
right,
|
|
385
|
-
pure,
|
|
386
|
-
} => self.logical(*operator, left, right, *pure, locals),
|
|
387
|
-
expression => self.other(expression, locals),
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
#[inline(never)]
|
|
392
|
-
fn binary(
|
|
393
|
-
&mut self,
|
|
394
|
-
operator: BinaryOp,
|
|
395
|
-
left: &Expression<'ast>,
|
|
396
|
-
right: &Expression<'ast>,
|
|
397
|
-
locals: &mut Locals<'ast>,
|
|
398
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
399
|
-
let left = self.evaluate(left, locals)?;
|
|
400
|
-
let right = self.evaluate(right, locals)?;
|
|
401
|
-
Ok(binary_value(operator, left, right))
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
#[inline(never)]
|
|
405
|
-
fn arithmetic(
|
|
406
|
-
&mut self,
|
|
407
|
-
expression: &Expression<'ast>,
|
|
408
|
-
locals: &mut Locals<'ast>,
|
|
409
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
410
|
-
Ok(number_value(self.number(expression, locals)?))
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/// Evaluates numeric arithmetic without wrapping intermediate results. If an operand is
|
|
414
|
-
/// nonnumeric, switches to general evaluation for that operator and its enclosing
|
|
415
|
-
/// operators, reusing evaluated operands. Returns that general result in `Err`.
|
|
416
|
-
fn number(
|
|
417
|
-
&mut self,
|
|
418
|
-
expression: &Expression<'ast>,
|
|
419
|
-
locals: &mut Locals<'ast>,
|
|
420
|
-
) -> Evaluation<'ast, Result<f64, Value<'ast>>> {
|
|
421
|
-
let Expression::Arithmetic {
|
|
422
|
-
operator,
|
|
423
|
-
operation,
|
|
424
|
-
left,
|
|
425
|
-
right,
|
|
426
|
-
} = expression
|
|
427
|
-
else {
|
|
428
|
-
return Ok(match self.evaluate(expression, locals)? {
|
|
429
|
-
Value::Number(number) => Ok(number),
|
|
430
|
-
value => Err(value),
|
|
431
|
-
});
|
|
432
|
-
};
|
|
433
|
-
let left = self.operand(left, locals)?;
|
|
434
|
-
let right = self.operand(right, locals)?;
|
|
435
|
-
Ok(match (left, right) {
|
|
436
|
-
(Ok(left), Ok(right)) => Ok(operation(left, right)),
|
|
437
|
-
(left, right) => Err(binary_value(
|
|
438
|
-
*operator,
|
|
439
|
-
number_value(left),
|
|
440
|
-
number_value(right),
|
|
441
|
-
)),
|
|
442
|
-
})
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/// An operand of arithmetic. Reads numeric constants and locals without a call.
|
|
446
|
-
#[inline(always)]
|
|
447
|
-
fn operand(
|
|
448
|
-
&mut self,
|
|
449
|
-
expression: &Expression<'ast>,
|
|
450
|
-
locals: &mut Locals<'ast>,
|
|
451
|
-
) -> Evaluation<'ast, Result<f64, Value<'ast>>> {
|
|
452
|
-
match expression {
|
|
453
|
-
Expression::Constant(Value::Number(number)) => Ok(Ok(*number)),
|
|
454
|
-
Expression::Name(Name::Local(slot, _))
|
|
455
|
-
if let Some(Value::Number(number)) = locals[*slot] =>
|
|
456
|
-
{
|
|
457
|
-
Ok(Ok(number))
|
|
458
|
-
}
|
|
459
|
-
expression => self.number(expression, locals),
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
#[inline(never)]
|
|
464
|
-
fn member(
|
|
465
|
-
&mut self,
|
|
466
|
-
object: &Expression<'ast>,
|
|
467
|
-
property: &Property<'ast>,
|
|
468
|
-
locals: &mut Locals<'ast>,
|
|
469
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
470
|
-
let object = self.evaluate(object, locals)?;
|
|
471
|
-
let key = self.property(property, locals)?;
|
|
472
|
-
self.get(&object, &key)
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
#[inline(never)]
|
|
476
|
-
fn other(
|
|
477
|
-
&mut self,
|
|
478
|
-
expression: &Expression<'ast>,
|
|
479
|
-
locals: &mut Locals<'ast>,
|
|
480
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
481
|
-
Ok(match expression {
|
|
482
|
-
Expression::Name(name) => self.lookup(name.atom())?,
|
|
483
|
-
Expression::This => self.frame().this.clone(),
|
|
484
|
-
Expression::Sequence(expressions) => {
|
|
485
|
-
let mut value = Value::Undefined;
|
|
486
|
-
for expression in expressions {
|
|
487
|
-
value = self.evaluate(expression, locals)?;
|
|
488
|
-
}
|
|
489
|
-
value
|
|
490
|
-
}
|
|
491
|
-
Expression::New(callee, arguments) => self.construction(callee, arguments, locals)?,
|
|
492
|
-
Expression::Unary(operator, argument) => {
|
|
493
|
-
let argument = self.evaluate(argument, locals)?;
|
|
494
|
-
semantics::unary_value(*operator, argument)
|
|
495
|
-
}
|
|
496
|
-
Expression::Conditional(test, yes, no) => {
|
|
497
|
-
let test = self.evaluate(test, locals)?;
|
|
498
|
-
let branch = if self.decide(&test) { yes } else { no };
|
|
499
|
-
self.evaluate(branch, locals)?
|
|
500
|
-
}
|
|
501
|
-
Expression::Array(elements) => {
|
|
502
|
-
let mut values = Vec::with_capacity(elements.len());
|
|
503
|
-
for element in elements {
|
|
504
|
-
values.push(match element {
|
|
505
|
-
Some(element) => self.evaluate(element, locals)?,
|
|
506
|
-
None => Value::Undefined,
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
Value::array(values)
|
|
510
|
-
}
|
|
511
|
-
Expression::Object(properties) => {
|
|
512
|
-
let mut entries = Vec::with_capacity(properties.len());
|
|
513
|
-
for (key, value) in properties {
|
|
514
|
-
let key = self.property(key, locals)?;
|
|
515
|
-
let name = key
|
|
516
|
-
.property()
|
|
517
|
-
.ok_or_else(|| access::unsupported("object key", &key))?;
|
|
518
|
-
entries.push((name, self.evaluate(value, locals)?));
|
|
519
|
-
}
|
|
520
|
-
Value::Object(Rc::new(RefCell::new(entries)))
|
|
521
|
-
}
|
|
522
|
-
Expression::Function(name, function) => self.function_value(name.cloned(), function),
|
|
523
|
-
Expression::Arrow(arrow) => self.arrow_value(arrow),
|
|
524
|
-
Expression::Unsupported(reason) => return Err(Stop::unsupported(reason)),
|
|
525
|
-
// Keep this list synchronized with the cases handled directly by `evaluate`.
|
|
526
|
-
Expression::Constant(_)
|
|
527
|
-
| Expression::Binary(..)
|
|
528
|
-
| Expression::Arithmetic { .. }
|
|
529
|
-
| Expression::Member(..)
|
|
530
|
-
| Expression::Assign(..)
|
|
531
|
-
| Expression::Update { .. }
|
|
532
|
-
| Expression::Call(..)
|
|
533
|
-
| Expression::Logical { .. } => unreachable!("dispatched by evaluate"),
|
|
534
|
-
})
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// Handle calls and writes separately because they keep several values and keys live. Avoid
|
|
538
|
-
// adding that storage to every recursive operand frame.
|
|
539
|
-
#[inline(never)]
|
|
540
|
-
fn call(
|
|
541
|
-
&mut self,
|
|
542
|
-
callee: &Expression<'ast>,
|
|
543
|
-
arguments: &[Expression<'ast>],
|
|
544
|
-
locals: &mut Locals<'ast>,
|
|
545
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
546
|
-
let (callee, this) = match callee {
|
|
547
|
-
Expression::Member(object, property) => {
|
|
548
|
-
let object = self.evaluate(object, locals)?;
|
|
549
|
-
let key = self.property(property, locals)?;
|
|
550
|
-
(self.get(&object, &key)?, object)
|
|
551
|
-
}
|
|
552
|
-
callee => (self.evaluate(callee, locals)?, Value::Undefined),
|
|
553
|
-
};
|
|
554
|
-
let arguments = self.arguments(arguments, locals)?;
|
|
555
|
-
self.apply(callee, this, arguments)
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/// Evaluates call arguments into a reused buffer.
|
|
559
|
-
fn arguments(
|
|
560
|
-
&mut self,
|
|
561
|
-
arguments: &[Expression<'ast>],
|
|
562
|
-
locals: &mut Locals<'ast>,
|
|
563
|
-
) -> Evaluation<'ast, Vec<Value<'ast>>> {
|
|
564
|
-
let mut values = self.spare.arguments.pop().unwrap_or_default();
|
|
565
|
-
for argument in arguments {
|
|
566
|
-
values.push(self.evaluate(argument, locals)?);
|
|
567
|
-
}
|
|
568
|
-
Ok(values)
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
#[inline(never)]
|
|
572
|
-
fn construction(
|
|
573
|
-
&mut self,
|
|
574
|
-
callee: &Expression<'ast>,
|
|
575
|
-
arguments: &[Expression<'ast>],
|
|
576
|
-
locals: &mut Locals<'ast>,
|
|
577
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
578
|
-
let callee = self.evaluate(callee, locals)?;
|
|
579
|
-
let arguments = self.arguments(arguments, locals)?;
|
|
580
|
-
self.construct(callee, arguments)
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
#[inline(never)]
|
|
584
|
-
fn assignment(
|
|
585
|
-
&mut self,
|
|
586
|
-
target: &Target<'ast>,
|
|
587
|
-
operator: Option<BinaryOp>,
|
|
588
|
-
right: &Expression<'ast>,
|
|
589
|
-
locals: &mut Locals<'ast>,
|
|
590
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
591
|
-
let target = self.locate(target, locals)?;
|
|
592
|
-
let Some(operator) = operator else {
|
|
593
|
-
let value = self.evaluate(right, locals)?;
|
|
594
|
-
self.write(target, value.clone(), locals)?;
|
|
595
|
-
return Ok(value);
|
|
596
|
-
};
|
|
597
|
-
self.compound(target, operator, locals, |run, locals| {
|
|
598
|
-
run.evaluate(right, locals)
|
|
599
|
-
})
|
|
600
151
|
}
|
|
601
152
|
|
|
602
153
|
/// Assigns to `target` with `operator`, as in `target += right`, where `right` evaluates
|
|
@@ -605,16 +156,10 @@ impl<'ast> Run<'ast, '_> {
|
|
|
605
156
|
pub(super) fn compound(
|
|
606
157
|
&mut self,
|
|
607
158
|
target: Location<'ast>,
|
|
608
|
-
operator:
|
|
159
|
+
operator: BinaryOperator,
|
|
609
160
|
locals: &mut Locals<'ast>,
|
|
610
161
|
right: impl FnOnce(&mut Self, &mut Locals<'ast>) -> Evaluation<'ast, Value<'ast>>,
|
|
611
162
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
612
|
-
if matches!(
|
|
613
|
-
operator,
|
|
614
|
-
BinaryOp::LogicalAnd | BinaryOp::LogicalOr | BinaryOp::NullishCoalescing
|
|
615
|
-
) {
|
|
616
|
-
return Err(Stop::unsupported("a logical assignment"));
|
|
617
|
-
}
|
|
618
163
|
// The script reapplies a new rolling mask to the program counter or key. The
|
|
619
164
|
// interpreter keeps that mask at zero; see `crate::vm::registers`.
|
|
620
165
|
if matches!(&target, Location::Member(Value::Registers, Key::Name(_))) {
|
|
@@ -630,7 +175,7 @@ impl<'ast> Run<'ast, '_> {
|
|
|
630
175
|
locals[*slot] = Some(Value::Undefined);
|
|
631
176
|
}
|
|
632
177
|
Location::Name(name) => {
|
|
633
|
-
|
|
178
|
+
self.frame().assign(name.binding(), Value::Undefined);
|
|
634
179
|
}
|
|
635
180
|
Location::Member(..) => {}
|
|
636
181
|
}
|
|
@@ -639,29 +184,11 @@ impl<'ast> Run<'ast, '_> {
|
|
|
639
184
|
Ok(value)
|
|
640
185
|
}
|
|
641
186
|
|
|
642
|
-
#[inline(never)]
|
|
643
|
-
fn update(
|
|
644
|
-
&mut self,
|
|
645
|
-
target: &Target<'ast>,
|
|
646
|
-
operator: UpdateOp,
|
|
647
|
-
prefix: bool,
|
|
648
|
-
locals: &mut Locals<'ast>,
|
|
649
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
650
|
-
// A counter: the local is read and written in place.
|
|
651
|
-
if let Target::Name(Name::Local(slot, _)) = target
|
|
652
|
-
&& let Some(Value::Number(number)) = &mut locals[*slot]
|
|
653
|
-
{
|
|
654
|
-
return Ok(Value::Number(step(operator, prefix, number)));
|
|
655
|
-
}
|
|
656
|
-
let target = self.locate(target, locals)?;
|
|
657
|
-
self.update_location(target, operator, prefix, locals)
|
|
658
|
-
}
|
|
659
|
-
|
|
660
187
|
/// Applies `++` or `--` to the number at `target`.
|
|
661
188
|
pub(super) fn update_location(
|
|
662
189
|
&mut self,
|
|
663
190
|
target: Location<'ast>,
|
|
664
|
-
operator:
|
|
191
|
+
operator: UpdateOperator,
|
|
665
192
|
prefix: bool,
|
|
666
193
|
locals: &mut Locals<'ast>,
|
|
667
194
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
@@ -674,28 +201,12 @@ impl<'ast> Run<'ast, '_> {
|
|
|
674
201
|
Ok(Value::Number(value))
|
|
675
202
|
}
|
|
676
203
|
|
|
677
|
-
/// Evaluates `&&`, `||`, or `??`, evaluating `right` only when needed.
|
|
678
|
-
#[inline(never)]
|
|
679
|
-
fn logical(
|
|
680
|
-
&mut self,
|
|
681
|
-
operator: BinaryOp,
|
|
682
|
-
left: &Expression<'ast>,
|
|
683
|
-
right: &Expression<'ast>,
|
|
684
|
-
pure: bool,
|
|
685
|
-
locals: &mut Locals<'ast>,
|
|
686
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
687
|
-
let left = self.evaluate(left, locals)?;
|
|
688
|
-
self.short_circuit(operator, left, pure, locals, |run, locals| {
|
|
689
|
-
run.evaluate(right, locals)
|
|
690
|
-
})
|
|
691
|
-
}
|
|
692
|
-
|
|
693
204
|
/// Finishes `&&`, `||`, or `??` after its left side, calling `right` to evaluate the right
|
|
694
205
|
/// side only when needed.
|
|
695
206
|
#[inline]
|
|
696
207
|
pub(super) fn short_circuit(
|
|
697
208
|
&mut self,
|
|
698
|
-
operator:
|
|
209
|
+
operator: LogicalOperator,
|
|
699
210
|
left: Value<'ast>,
|
|
700
211
|
pure: bool,
|
|
701
212
|
locals: &mut Locals<'ast>,
|
|
@@ -704,10 +215,10 @@ impl<'ast> Run<'ast, '_> {
|
|
|
704
215
|
// Condition controlling right-operand evaluation and the branch direction that
|
|
705
216
|
// evaluates it.
|
|
706
217
|
let (test, runs_right) = match operator {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
semantics::binary_value(
|
|
218
|
+
LogicalOperator::And => (left.clone(), true),
|
|
219
|
+
LogicalOperator::Or => (left.clone(), false),
|
|
220
|
+
LogicalOperator::Coalesce => (
|
|
221
|
+
semantics::binary_value(BinaryOperator::Equality, left.clone(), Value::Null),
|
|
711
222
|
true,
|
|
712
223
|
),
|
|
713
224
|
};
|
|
@@ -721,7 +232,7 @@ impl<'ast> Run<'ast, '_> {
|
|
|
721
232
|
self.effects.len(),
|
|
722
233
|
"a pure right side runs without effects"
|
|
723
234
|
);
|
|
724
|
-
return Ok(Value::symbolic(Term::
|
|
235
|
+
return Ok(Value::symbolic(Term::Logical(
|
|
725
236
|
operator,
|
|
726
237
|
Box::new(left.expr()),
|
|
727
238
|
Box::new(right.expr()),
|
|
@@ -735,38 +246,22 @@ impl<'ast> Run<'ast, '_> {
|
|
|
735
246
|
}
|
|
736
247
|
}
|
|
737
248
|
|
|
738
|
-
#[inline]
|
|
739
|
-
fn locate(
|
|
740
|
-
&mut self,
|
|
741
|
-
target: &Target<'ast>,
|
|
742
|
-
locals: &mut Locals<'ast>,
|
|
743
|
-
) -> Evaluation<'ast, Location<'ast>> {
|
|
744
|
-
Ok(match target {
|
|
745
|
-
Target::Name(name) => Location::Name(*name),
|
|
746
|
-
Target::Member(object, key) => {
|
|
747
|
-
let object = self.evaluate(object, locals)?;
|
|
748
|
-
let key = self.property(key, locals)?;
|
|
749
|
-
Location::Member(object, key)
|
|
750
|
-
}
|
|
751
|
-
})
|
|
752
|
-
}
|
|
753
|
-
|
|
754
249
|
pub(super) fn read(
|
|
755
250
|
&mut self,
|
|
756
251
|
target: &Location<'ast>,
|
|
757
252
|
locals: &Locals<'ast>,
|
|
758
253
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
759
254
|
match target {
|
|
760
|
-
Location::Name(Name::Local(slot,
|
|
255
|
+
Location::Name(Name::Local(slot, binding)) => match &locals[*slot] {
|
|
761
256
|
Some(value) => Ok(value.clone()),
|
|
762
|
-
None => self.lookup(
|
|
257
|
+
None => self.lookup(*binding),
|
|
763
258
|
},
|
|
764
|
-
Location::Name(Name::
|
|
259
|
+
Location::Name(Name::Scoped(binding)) => self.lookup(*binding),
|
|
765
260
|
Location::Member(object, key) => self.get(object, key),
|
|
766
261
|
}
|
|
767
262
|
}
|
|
768
263
|
|
|
769
|
-
/// Writes
|
|
264
|
+
/// Writes locals directly, since they are the most common assignment target.
|
|
770
265
|
#[inline]
|
|
771
266
|
pub(super) fn write(
|
|
772
267
|
&mut self,
|
|
@@ -775,17 +270,8 @@ impl<'ast> Run<'ast, '_> {
|
|
|
775
270
|
locals: &mut Locals<'ast>,
|
|
776
271
|
) -> Evaluation<'ast, ()> {
|
|
777
272
|
match target {
|
|
778
|
-
Location::Name(Name::Local(slot,
|
|
779
|
-
|
|
780
|
-
if locals[slot].is_none()
|
|
781
|
-
&& (self.globals.contains_key(name) || self.session.bindings.contains_key(name))
|
|
782
|
-
{
|
|
783
|
-
self.assign_name(name, value);
|
|
784
|
-
} else {
|
|
785
|
-
locals[slot] = Some(value);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
Location::Name(Name::Global(name)) => self.assign_name(name, value),
|
|
273
|
+
Location::Name(Name::Local(slot, _)) => locals[slot] = Some(value),
|
|
274
|
+
Location::Name(Name::Scoped(binding)) => self.assign(binding, value),
|
|
789
275
|
Location::Member(object, key) => return self.set(&object, &key, value),
|
|
790
276
|
}
|
|
791
277
|
Ok(())
|
|
@@ -801,7 +287,7 @@ pub(super) fn copied<'a>(value: &Value<'a>) -> Value<'a> {
|
|
|
801
287
|
}
|
|
802
288
|
}
|
|
803
289
|
|
|
804
|
-
///
|
|
290
|
+
/// Converts the result of compiled numeric evaluation to a value.
|
|
805
291
|
#[inline(always)]
|
|
806
292
|
pub(super) fn number_value(number: Result<f64, Value<'_>>) -> Value<'_> {
|
|
807
293
|
number.map_or_else(|value| value, Value::Number)
|
|
@@ -817,7 +303,11 @@ pub(super) enum Location<'ast> {
|
|
|
817
303
|
|
|
818
304
|
/// Applies [`semantics::binary_value`] to numeric operands without coercion or symbolic terms.
|
|
819
305
|
#[inline(always)]
|
|
820
|
-
pub(super) fn binary_value<'a>(
|
|
306
|
+
pub(super) fn binary_value<'a>(
|
|
307
|
+
operator: BinaryOperator,
|
|
308
|
+
left: Value<'a>,
|
|
309
|
+
right: Value<'a>,
|
|
310
|
+
) -> Value<'a> {
|
|
821
311
|
let (&Value::Number(a), &Value::Number(b)) = (&left, &right) else {
|
|
822
312
|
return semantics::binary_value(operator, left, right);
|
|
823
313
|
};
|
|
@@ -827,12 +317,12 @@ pub(super) fn binary_value<'a>(operator: BinaryOp, left: Value<'a>, right: Value
|
|
|
827
317
|
return Value::Number(operation(a, b));
|
|
828
318
|
}
|
|
829
319
|
Value::Bool(match operator {
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
320
|
+
BinaryOperator::Equality | BinaryOperator::StrictEquality => a == b,
|
|
321
|
+
BinaryOperator::Inequality | BinaryOperator::StrictInequality => a != b,
|
|
322
|
+
BinaryOperator::LessThan => a < b,
|
|
323
|
+
BinaryOperator::LessEqualThan => a <= b,
|
|
324
|
+
BinaryOperator::GreaterThan => a > b,
|
|
325
|
+
BinaryOperator::GreaterEqualThan => a >= b,
|
|
836
326
|
_ => return semantics::binary_value(operator, Value::Number(a), Value::Number(b)),
|
|
837
327
|
})
|
|
838
328
|
}
|
|
@@ -840,11 +330,11 @@ pub(super) fn binary_value<'a>(operator: BinaryOp, left: Value<'a>, right: Value
|
|
|
840
330
|
/// Applies `++` or `--` to `number` in place. Returns the expression's result: the new number
|
|
841
331
|
/// in prefix form, or the old number in postfix form.
|
|
842
332
|
#[inline(always)]
|
|
843
|
-
pub(super) fn step(operator:
|
|
333
|
+
pub(super) fn step(operator: UpdateOperator, prefix: bool, number: &mut f64) -> f64 {
|
|
844
334
|
let old = *number;
|
|
845
335
|
*number = match operator {
|
|
846
|
-
|
|
847
|
-
|
|
336
|
+
UpdateOperator::Increment => old + 1.0,
|
|
337
|
+
UpdateOperator::Decrement => old - 1.0,
|
|
848
338
|
};
|
|
849
339
|
if prefix { *number } else { old }
|
|
850
340
|
}
|