cfsolve 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +10 -9
- 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 +10 -8
- 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/safari-26-ios/answers.json +2570 -1894
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
- data/lib/cfsolve/profiles/safari-26-ios.json +102 -156
- data/lib/cfsolve/version.rb +2 -2
- data/vendor/cfsolve/Cargo.lock +561 -1729
- data/vendor/cfsolve/Cargo.toml +26 -8
- data/vendor/cfsolve/README.md +4 -35
- data/vendor/cfsolve/examples/build_profile.rs +17 -15
- data/vendor/cfsolve/examples/capture_session.rs +37 -0
- data/vendor/cfsolve/examples/check_answers.rs +66 -0
- data/vendor/cfsolve/examples/compare_session.rs +189 -0
- 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 +6 -3
- data/vendor/cfsolve/examples/tls_echo.rs +3 -3
- data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +2570 -1894
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
- data/vendor/cfsolve/profiles/safari-26-ios.json +102 -156
- data/vendor/cfsolve/scripts/capture_cssom.mjs +42 -0
- data/vendor/cfsolve/scripts/serve_cssom.py +111 -0
- 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/profile.rs +7 -18
- data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- data/vendor/cfsolve/src/capture/recorded.rs +42 -7
- 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 +132 -0
- data/vendor/cfsolve/src/challenge/installed.rs +127 -269
- 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 +175 -35
- 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 +236 -122
- 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 +201 -205
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +346 -536
- 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 +361 -322
- 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 +23 -32
- data/vendor/cfsolve/src/embedding_page/page.rs +28 -2
- 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 +9 -1
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -254
- data/vendor/cfsolve/src/js/objects.rs +9 -2
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -92
- data/vendor/cfsolve/src/listing/query.rs +26 -291
- data/vendor/cfsolve/src/listing.rs +0 -1
- 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 +19 -10
- data/vendor/cfsolve/src/session/probes.rs +160 -125
- 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/timing.rs +58 -53
- data/vendor/cfsolve/src/session/widget.rs +5 -6
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +50 -33
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +61 -66
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +33 -22
- data/vendor/cfsolve/src/stage2/analysis/recognize.rs +3 -5
- data/vendor/cfsolve/src/stage2/analysis.rs +0 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +378 -0
- data/vendor/cfsolve/src/stage2/benchmark.rs +66 -38
- data/vendor/cfsolve/src/stage2/call_stack.rs +1463 -1017
- data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
- 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/native.rs +2 -1
- data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -7
- data/vendor/cfsolve/src/stage2/payload/recover.rs +56 -25
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/ice.rs +11 -10
- data/vendor/cfsolve/src/stage2/probes/media.rs +47 -33
- data/vendor/cfsolve/src/stage2/probes/performance.rs +13 -8
- data/vendor/cfsolve/src/stage2/probes/rects.rs +12 -17
- data/vendor/cfsolve/src/stage2/probes/stack.rs +50 -103
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +17 -86
- data/vendor/cfsolve/src/stage2/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/records.rs +4 -13
- data/vendor/cfsolve/src/stage2/reference.json +1 -1
- data/vendor/cfsolve/src/stage2/reference.rs +98 -100
- data/vendor/cfsolve/src/stage2/registry.rs +41 -34
- data/vendor/cfsolve/src/stage2/replay.rs +182 -254
- data/vendor/cfsolve/src/stage2/stylesheets.rs +176 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +152 -108
- data/vendor/cfsolve/src/stage2/vocabulary.rs +103 -403
- data/vendor/cfsolve/src/stage2.rs +4 -1
- data/vendor/cfsolve/src/vm/disassemble.rs +46 -13
- data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
- data/vendor/cfsolve/src/vm/extract.rs +347 -250
- data/vendor/cfsolve/src/vm/interpret/access.rs +67 -68
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +16 -63
- data/vendor/cfsolve/src/vm/interpret/call.rs +192 -51
- data/vendor/cfsolve/src/vm/interpret/compile.rs +643 -0
- data/vendor/cfsolve/src/vm/interpret/copies.rs +232 -120
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +149 -40
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +189 -572
- data/vendor/cfsolve/src/vm/interpret/explore.rs +159 -46
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +169 -0
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +414 -0
- 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 +1736 -0
- data/vendor/cfsolve/src/vm/interpret/plan.rs +605 -330
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +314 -54
- 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 +16 -3
- data/vendor/cfsolve/src/vm/machine.rs +58 -47
- data/vendor/cfsolve/src/vm/output.rs +13 -5
- data/vendor/cfsolve/src/vm/packed_names.rs +311 -0
- data/vendor/cfsolve/src/vm/session.rs +197 -110
- data/vendor/cfsolve/src/vm/value.rs +35 -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
- data/vendor/cfsolve/vendor/btls-sys/src/lib.rs +3 -0
- metadata +106 -183
- 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/vendor/cfsolve/src/listing/normalize.rs +0 -264
- data/vendor/cfsolve/src/stage2/analysis/outputs.rs +0 -327
- data/vendor/cfsolve/src/stage2/probes/stylesheets.rs +0 -249
- data/vendor/cfsolve/src/stage2/reference-expanded.json +0 -42
- data/vendor/cfsolve/src/stage2/session_names.rs +0 -470
- /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,586 +1,224 @@
|
|
|
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::run::{Evaluation, Flow, Frame, Run, Stop};
|
|
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};
|
|
14
12
|
use super::semantics;
|
|
15
13
|
use crate::vm::output::Term;
|
|
16
|
-
use crate::vm::value::{
|
|
17
|
-
|
|
18
|
-
/// Maximum handler loop count. Valid constants require fewer iterations; exceeding it indicates
|
|
19
|
-
/// invalid instruction bytes.
|
|
20
|
-
const MAXIMUM_ITERATIONS: usize = 1 << 16;
|
|
14
|
+
use crate::vm::value::{Scope, Value};
|
|
21
15
|
|
|
22
16
|
impl<'ast> Run<'ast, '_> {
|
|
23
|
-
|
|
24
|
-
|
|
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 [])
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
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 [])
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
/// Calls a slot plan. Its scope holds the locals nested functions mention, inside `closed`,
|
|
34
|
+
/// the scope the function captured, if any.
|
|
31
35
|
pub(super) fn call_plan(
|
|
32
36
|
&mut self,
|
|
33
37
|
plan: &FunctionPlan<'ast>,
|
|
38
|
+
closed: Option<&Scope<'ast>>,
|
|
34
39
|
this: Value<'ast>,
|
|
35
|
-
|
|
40
|
+
arguments: Vec<Value<'ast>>,
|
|
36
41
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
37
|
-
let mut locals = self.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
let mut values = arguments.drain(..);
|
|
43
|
-
for &slot in &plan.parameters {
|
|
44
|
-
locals[slot] = Some(values.next().unwrap_or(Value::Undefined));
|
|
45
|
-
}
|
|
46
|
-
drop(values);
|
|
47
|
-
self.spare.arguments.push(arguments);
|
|
48
|
-
let result = self.body(Frame::new(this), &plan.body, &mut locals);
|
|
49
|
-
// Numeric locals need no destructor call.
|
|
50
|
-
let assigned = locals.drain(..).flatten();
|
|
51
|
-
for local in assigned {
|
|
52
|
-
local.discard();
|
|
53
|
-
}
|
|
54
|
-
self.spare.locals.push(locals);
|
|
42
|
+
let mut locals = self.enter_plan(plan, closed, this, arguments);
|
|
43
|
+
let result = compile::run_all(&plan.code, self, &mut locals).map(returned);
|
|
44
|
+
self.frames.pop();
|
|
45
|
+
self.release_locals(locals);
|
|
55
46
|
result
|
|
56
47
|
}
|
|
57
48
|
|
|
58
|
-
///
|
|
59
|
-
|
|
49
|
+
/// Calls a handler's slot plan as [`Run::call_plan`] does, with no captured scope. Before
|
|
50
|
+
/// each top-level statement, `before` sees the statement's index and the locals.
|
|
51
|
+
pub(super) fn call_handler(
|
|
60
52
|
&mut self,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
plan: &FunctionPlan<'ast>,
|
|
54
|
+
this: Value<'ast>,
|
|
55
|
+
arguments: Vec<Value<'ast>>,
|
|
56
|
+
before: &mut dyn FnMut(&Self, usize, &Locals<'ast>),
|
|
64
57
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
65
|
-
self.
|
|
66
|
-
let
|
|
67
|
-
self.
|
|
68
|
-
|
|
69
|
-
Flow::Return(value) => Ok(value),
|
|
70
|
-
_ => Ok(Value::Undefined),
|
|
71
|
-
}
|
|
58
|
+
let mut locals = self.enter_plan(plan, None, this, arguments);
|
|
59
|
+
let result = self.handler_statements(plan, 0, &mut locals, before);
|
|
60
|
+
self.release_locals(locals);
|
|
61
|
+
result
|
|
72
62
|
}
|
|
73
63
|
|
|
74
|
-
|
|
64
|
+
/// Binds a slot plan's parameters and pushes its frame. Returns the call's locals.
|
|
65
|
+
#[inline]
|
|
66
|
+
fn enter_plan(
|
|
75
67
|
&mut self,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
Ok(Flow::Normal)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/// Checks whether `name` has already been declared in the current function.
|
|
89
|
-
fn declared(&self, name: Name<'ast>, locals: &Locals<'ast>) -> bool {
|
|
90
|
-
match name {
|
|
91
|
-
Name::Local(slot, _) => locals[slot].is_some(),
|
|
92
|
-
Name::Global(name) => self.frame().scope.borrow().variables.contains_key(name),
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/// Declares `name` with `value`.
|
|
97
|
-
fn bind(&mut self, name: Name<'ast>, value: Value<'ast>, locals: &mut Locals<'ast>) {
|
|
98
|
-
match name {
|
|
99
|
-
Name::Local(slot, _) => locals[slot] = Some(value),
|
|
100
|
-
Name::Global(name) => self.declare(name.clone(), value),
|
|
68
|
+
plan: &FunctionPlan<'ast>,
|
|
69
|
+
closed: Option<&Scope<'ast>>,
|
|
70
|
+
this: Value<'ast>,
|
|
71
|
+
mut arguments: Vec<Value<'ast>>,
|
|
72
|
+
) -> Vec<Option<Value<'ast>>> {
|
|
73
|
+
let mut locals = self.spare.locals.pop().unwrap_or_default();
|
|
74
|
+
locals.resize(plan.locals, None);
|
|
75
|
+
if let Some(slot) = plan.arguments {
|
|
76
|
+
locals[slot] = Some(Value::array(arguments.clone()));
|
|
101
77
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
let value = match &declaration.init {
|
|
118
|
-
Some(expression) => self.evaluate(expression, locals)?,
|
|
119
|
-
None if declaration.keeps && self.declared(declaration.name, locals) => {
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
None => Value::Undefined,
|
|
123
|
-
};
|
|
124
|
-
self.bind(declaration.name, value, locals);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
Statement::Try {
|
|
128
|
-
block,
|
|
129
|
-
parameter,
|
|
130
|
-
handler,
|
|
131
|
-
finalizer,
|
|
132
|
-
} => {
|
|
133
|
-
let mut outcome = self.execute_all(block, locals);
|
|
134
|
-
if let Some(handler) = handler
|
|
135
|
-
&& let Err(stop) = &mut outcome
|
|
136
|
-
&& let Stop::Throw(exception) = &mut **stop
|
|
137
|
-
{
|
|
138
|
-
let exception = mem::replace(exception, Value::Undefined);
|
|
139
|
-
if let Some(parameter) = parameter {
|
|
140
|
-
self.bind(*parameter, exception, locals);
|
|
141
|
-
}
|
|
142
|
-
outcome = self.execute_all(handler, locals);
|
|
143
|
-
}
|
|
144
|
-
// A jump from `finally` overrides the previous completion of the block.
|
|
145
|
-
if let Some(finalizer) = finalizer {
|
|
146
|
-
match self.execute_all(finalizer, locals)? {
|
|
147
|
-
Flow::Normal => {}
|
|
148
|
-
flow => return Ok(flow),
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return outcome;
|
|
152
|
-
}
|
|
153
|
-
Statement::Block(statements) => return self.execute_all(statements, locals),
|
|
154
|
-
Statement::If(test, yes, no) => {
|
|
155
|
-
let test = self.evaluate(test, locals)?;
|
|
156
|
-
if self.decide(&test) {
|
|
157
|
-
return self.execute(yes, locals);
|
|
158
|
-
}
|
|
159
|
-
if let Some(no) = no {
|
|
160
|
-
return self.execute(no, locals);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
Statement::Return(expression) => {
|
|
164
|
-
return Ok(Flow::Return(match expression {
|
|
165
|
-
Some(expression) => self.evaluate(expression, locals)?,
|
|
166
|
-
None => Value::Undefined,
|
|
167
|
-
}));
|
|
168
|
-
}
|
|
169
|
-
Statement::Throw(expression) => {
|
|
170
|
-
return Err(Stop::throw(self.evaluate(expression, locals)?));
|
|
171
|
-
}
|
|
172
|
-
Statement::Break(label) => return Ok(Flow::Break(label.cloned())),
|
|
173
|
-
Statement::Continue(label) => return Ok(Flow::Continue(label.cloned())),
|
|
174
|
-
Statement::Label(label, body) => {
|
|
175
|
-
return Ok(match self.execute(body, locals)? {
|
|
176
|
-
Flow::Break(Some(target)) if target == **label => Flow::Normal,
|
|
177
|
-
flow => flow,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
Statement::Loop {
|
|
181
|
-
init,
|
|
182
|
-
test,
|
|
183
|
-
update,
|
|
184
|
-
body,
|
|
185
|
-
body_first,
|
|
186
|
-
label,
|
|
187
|
-
} => {
|
|
188
|
-
if let Some(init) = init {
|
|
189
|
-
self.execute(init, locals)?;
|
|
190
|
-
}
|
|
191
|
-
let mut first = *body_first;
|
|
192
|
-
for _ in 0..MAXIMUM_ITERATIONS {
|
|
193
|
-
if !first && let Some(test) = test {
|
|
194
|
-
let condition = self.evaluate(test, locals)?;
|
|
195
|
-
let repeats = condition
|
|
196
|
-
.truthy()
|
|
197
|
-
.ok_or_else(|| Stop::unsupported("a loop over registers"))?;
|
|
198
|
-
if !repeats {
|
|
199
|
-
return Ok(Flow::Normal);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
first = false;
|
|
203
|
-
match self.execute(body, locals)? {
|
|
204
|
-
Flow::Normal | Flow::Continue(None) => {}
|
|
205
|
-
Flow::Continue(Some(target)) if Some(&target) == *label => {}
|
|
206
|
-
Flow::Break(None) => return Ok(Flow::Normal),
|
|
207
|
-
flow => return Ok(flow),
|
|
208
|
-
}
|
|
209
|
-
if let Some(update) = update {
|
|
210
|
-
self.evaluate(update, locals)?;
|
|
211
|
-
}
|
|
78
|
+
let mut frame = Frame {
|
|
79
|
+
this,
|
|
80
|
+
scope: CallScope::Deferred(closed.cloned()),
|
|
81
|
+
};
|
|
82
|
+
let mut values = arguments.drain(..);
|
|
83
|
+
for parameter in &plan.parameters {
|
|
84
|
+
let value = values.next().unwrap_or(Value::Undefined);
|
|
85
|
+
match *parameter {
|
|
86
|
+
Name::Local(slot, _) => locals[slot] = Some(value),
|
|
87
|
+
Name::Scoped(binding) => {
|
|
88
|
+
frame
|
|
89
|
+
.own_scope()
|
|
90
|
+
.borrow_mut()
|
|
91
|
+
.variables
|
|
92
|
+
.insert(binding, value);
|
|
212
93
|
}
|
|
213
|
-
return Err(Stop::unsupported("a loop past the longest constant"));
|
|
214
94
|
}
|
|
215
95
|
}
|
|
216
|
-
|
|
96
|
+
drop(values);
|
|
97
|
+
self.spare.arguments.push(arguments);
|
|
98
|
+
self.frames.push(frame);
|
|
99
|
+
locals
|
|
217
100
|
}
|
|
218
101
|
|
|
219
|
-
/// Runs
|
|
220
|
-
|
|
102
|
+
/// Runs a handler's top-level statements from `start` in the frame the run holds, then
|
|
103
|
+
/// leaves that frame, as [`Run::body`] does.
|
|
104
|
+
pub(super) fn handler_statements(
|
|
221
105
|
&mut self,
|
|
222
|
-
|
|
223
|
-
|
|
106
|
+
plan: &FunctionPlan<'ast>,
|
|
107
|
+
start: usize,
|
|
224
108
|
locals: &mut Locals<'ast>,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
let mut
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
continue;
|
|
233
|
-
};
|
|
234
|
-
let test = self.evaluate(test, locals)?;
|
|
235
|
-
let equal = semantics::strict_equal(&discriminant, &test)
|
|
236
|
-
.ok_or_else(|| Stop::unsupported("a switch over registers"))?;
|
|
237
|
-
if equal {
|
|
238
|
-
matched = Some(index);
|
|
109
|
+
before: &mut dyn FnMut(&Self, usize, &Locals<'ast>),
|
|
110
|
+
) -> Evaluation<'ast, Value<'ast>> {
|
|
111
|
+
let mut flow = Ok(Flow::Normal);
|
|
112
|
+
for (index, statement) in plan.code.iter().enumerate().skip(start) {
|
|
113
|
+
before(self, index, locals);
|
|
114
|
+
flow = statement(self, locals);
|
|
115
|
+
if !matches!(flow, Ok(Flow::Normal)) {
|
|
239
116
|
break;
|
|
240
117
|
}
|
|
241
118
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
};
|
|
245
|
-
for case in &cases[start..] {
|
|
246
|
-
match self.execute_all(&case.body, locals)? {
|
|
247
|
-
Flow::Normal => {}
|
|
248
|
-
Flow::Break(None) => return Ok(Flow::Normal),
|
|
249
|
-
flow => return Ok(flow),
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
Ok(Flow::Normal)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
fn property(
|
|
256
|
-
&mut self,
|
|
257
|
-
property: &Property<'ast>,
|
|
258
|
-
locals: &mut Locals<'ast>,
|
|
259
|
-
) -> Evaluation<'ast, Key<'ast, 'ast>> {
|
|
260
|
-
Ok(match property {
|
|
261
|
-
Property::Name(name) => Key::name(name),
|
|
262
|
-
Property::Computed(expression) => Key::from(self.evaluate(expression, locals)?),
|
|
263
|
-
})
|
|
119
|
+
self.frames.pop();
|
|
120
|
+
flow.map(returned)
|
|
264
121
|
}
|
|
265
122
|
|
|
266
|
-
///
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
expression: &Expression<'ast>,
|
|
272
|
-
locals: &mut Locals<'ast>,
|
|
273
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
274
|
-
match expression {
|
|
275
|
-
Expression::Constant(value) => Ok(copied(value)),
|
|
276
|
-
Expression::Name(Name::Local(slot, _)) if let Some(value) = &locals[*slot] => {
|
|
277
|
-
Ok(match value {
|
|
278
|
-
Value::Symbolic(_) => self.refined(value),
|
|
279
|
-
value => copied(value),
|
|
280
|
-
})
|
|
281
|
-
}
|
|
282
|
-
Expression::Binary(operator, left, right) => {
|
|
283
|
-
self.binary(*operator, left, right, locals)
|
|
284
|
-
}
|
|
285
|
-
Expression::Arithmetic { .. } => self.arithmetic(expression, locals),
|
|
286
|
-
Expression::Member(object, property) => self.member(object, property, locals),
|
|
287
|
-
Expression::Assign(target, operator, right) => {
|
|
288
|
-
self.assignment(target, *operator, right, locals)
|
|
289
|
-
}
|
|
290
|
-
Expression::Update {
|
|
291
|
-
target,
|
|
292
|
-
operator,
|
|
293
|
-
prefix,
|
|
294
|
-
} => self.update(target, *operator, *prefix, locals),
|
|
295
|
-
Expression::Call(callee, arguments) => self.call(callee, arguments, locals),
|
|
296
|
-
Expression::Logical {
|
|
297
|
-
operator,
|
|
298
|
-
left,
|
|
299
|
-
right,
|
|
300
|
-
pure,
|
|
301
|
-
} => self.logical(*operator, left, right, *pure, locals),
|
|
302
|
-
expression => self.other(expression, locals),
|
|
123
|
+
/// Returns a call's locals to the spare buffers.
|
|
124
|
+
fn release_locals(&mut self, mut locals: Vec<Option<Value<'ast>>>) {
|
|
125
|
+
// Numeric locals need no destructor call.
|
|
126
|
+
for local in locals.drain(..).flatten() {
|
|
127
|
+
local.discard();
|
|
303
128
|
}
|
|
129
|
+
self.spare.locals.push(locals);
|
|
304
130
|
}
|
|
305
131
|
|
|
306
|
-
|
|
307
|
-
fn
|
|
308
|
-
&mut self,
|
|
309
|
-
operator: BinaryOp,
|
|
310
|
-
left: &Expression<'ast>,
|
|
311
|
-
right: &Expression<'ast>,
|
|
312
|
-
locals: &mut Locals<'ast>,
|
|
313
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
314
|
-
let left = self.evaluate(left, locals)?;
|
|
315
|
-
let right = self.evaluate(right, locals)?;
|
|
316
|
-
Ok(binary_value(operator, left, right))
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
#[inline(never)]
|
|
320
|
-
fn arithmetic(
|
|
132
|
+
/// Runs a function body in `frame`.
|
|
133
|
+
pub(super) fn body(
|
|
321
134
|
&mut self,
|
|
322
|
-
|
|
135
|
+
frame: Frame<'ast>,
|
|
136
|
+
body: &[Code<'ast>],
|
|
323
137
|
locals: &mut Locals<'ast>,
|
|
324
138
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
/// nonnumeric, switches to general evaluation for that operator and its enclosing
|
|
330
|
-
/// operators, reusing evaluated operands. Returns that general result in `Err`.
|
|
331
|
-
fn number(
|
|
332
|
-
&mut self,
|
|
333
|
-
expression: &Expression<'ast>,
|
|
334
|
-
locals: &mut Locals<'ast>,
|
|
335
|
-
) -> Evaluation<'ast, Result<f64, Value<'ast>>> {
|
|
336
|
-
let Expression::Arithmetic {
|
|
337
|
-
operator,
|
|
338
|
-
operation,
|
|
339
|
-
left,
|
|
340
|
-
right,
|
|
341
|
-
} = expression
|
|
342
|
-
else {
|
|
343
|
-
return Ok(match self.evaluate(expression, locals)? {
|
|
344
|
-
Value::Number(number) => Ok(number),
|
|
345
|
-
value => Err(value),
|
|
346
|
-
});
|
|
347
|
-
};
|
|
348
|
-
let left = self.operand(left, locals)?;
|
|
349
|
-
let right = self.operand(right, locals)?;
|
|
350
|
-
Ok(match (left, right) {
|
|
351
|
-
(Ok(left), Ok(right)) => Ok(operation(left, right)),
|
|
352
|
-
(left, right) => Err(binary_value(
|
|
353
|
-
*operator,
|
|
354
|
-
number_value(left),
|
|
355
|
-
number_value(right),
|
|
356
|
-
)),
|
|
357
|
-
})
|
|
139
|
+
self.frames.push(frame);
|
|
140
|
+
let flow = compile::run_all(body, self, locals);
|
|
141
|
+
self.frames.pop();
|
|
142
|
+
flow.map(returned)
|
|
358
143
|
}
|
|
359
144
|
|
|
360
|
-
///
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
locals: &mut Locals<'ast>,
|
|
366
|
-
) -> Evaluation<'ast, Result<f64, Value<'ast>>> {
|
|
367
|
-
match expression {
|
|
368
|
-
Expression::Constant(Value::Number(number)) => Ok(Ok(*number)),
|
|
369
|
-
Expression::Name(Name::Local(slot, _))
|
|
370
|
-
if let Some(Value::Number(number)) = locals[*slot] =>
|
|
371
|
-
{
|
|
372
|
-
Ok(Ok(number))
|
|
373
|
-
}
|
|
374
|
-
expression => self.number(expression, locals),
|
|
145
|
+
/// Declares `name` with `value`.
|
|
146
|
+
pub(super) fn bind(&mut self, name: Name<'ast>, value: Value<'ast>, locals: &mut Locals<'ast>) {
|
|
147
|
+
match name {
|
|
148
|
+
Name::Local(slot, _) => locals[slot] = Some(value),
|
|
149
|
+
Name::Scoped(binding) => self.declare(binding, value),
|
|
375
150
|
}
|
|
376
151
|
}
|
|
377
152
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
property: &Property<'ast>,
|
|
383
|
-
locals: &mut Locals<'ast>,
|
|
384
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
385
|
-
let object = self.evaluate(object, locals)?;
|
|
386
|
-
let key = self.property(property, locals)?;
|
|
387
|
-
self.get(&object, &key)
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
#[inline(never)]
|
|
391
|
-
fn other(
|
|
392
|
-
&mut self,
|
|
393
|
-
expression: &Expression<'ast>,
|
|
394
|
-
locals: &mut Locals<'ast>,
|
|
395
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
396
|
-
Ok(match expression {
|
|
397
|
-
Expression::Name(name) => self.lookup(name.atom())?,
|
|
398
|
-
Expression::This => self.frame().this.clone(),
|
|
399
|
-
Expression::Sequence(expressions) => {
|
|
400
|
-
let mut value = Value::Undefined;
|
|
401
|
-
for expression in expressions {
|
|
402
|
-
value = self.evaluate(expression, locals)?;
|
|
403
|
-
}
|
|
404
|
-
value
|
|
405
|
-
}
|
|
406
|
-
Expression::New(callee, arguments) => self.construction(callee, arguments, locals)?,
|
|
407
|
-
Expression::Unary(operator, argument) => {
|
|
408
|
-
let argument = self.evaluate(argument, locals)?;
|
|
409
|
-
semantics::unary_value(*operator, argument)
|
|
410
|
-
}
|
|
411
|
-
Expression::Conditional(test, yes, no) => {
|
|
412
|
-
let test = self.evaluate(test, locals)?;
|
|
413
|
-
let branch = if self.decide(&test) { yes } else { no };
|
|
414
|
-
self.evaluate(branch, locals)?
|
|
415
|
-
}
|
|
416
|
-
Expression::Array(elements) => {
|
|
417
|
-
let mut values = Vec::with_capacity(elements.len());
|
|
418
|
-
for element in elements {
|
|
419
|
-
values.push(match element {
|
|
420
|
-
Some(element) => self.evaluate(element, locals)?,
|
|
421
|
-
None => Value::Undefined,
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
Value::array(values)
|
|
425
|
-
}
|
|
426
|
-
Expression::Object(properties) => {
|
|
427
|
-
let mut entries = Vec::with_capacity(properties.len());
|
|
428
|
-
for (key, value) in properties {
|
|
429
|
-
let key = self.property(key, locals)?;
|
|
430
|
-
let name = key
|
|
431
|
-
.property()
|
|
432
|
-
.ok_or_else(|| access::unsupported("object key", &key))?;
|
|
433
|
-
entries.push((name, self.evaluate(value, locals)?));
|
|
434
|
-
}
|
|
435
|
-
Value::Object(Rc::new(RefCell::new(entries)))
|
|
436
|
-
}
|
|
437
|
-
Expression::Function(name, function) => self.function_value(name.cloned(), function),
|
|
438
|
-
Expression::Arrow(arrow) => self.arrow_value(arrow),
|
|
439
|
-
Expression::Unsupported(reason) => return Err(Stop::unsupported(reason)),
|
|
440
|
-
// Keep this list synchronized with the cases handled directly by `evaluate`.
|
|
441
|
-
Expression::Constant(_)
|
|
442
|
-
| Expression::Binary(..)
|
|
443
|
-
| Expression::Arithmetic { .. }
|
|
444
|
-
| Expression::Member(..)
|
|
445
|
-
| Expression::Assign(..)
|
|
446
|
-
| Expression::Update { .. }
|
|
447
|
-
| Expression::Call(..)
|
|
448
|
-
| Expression::Logical { .. } => unreachable!("dispatched by evaluate"),
|
|
449
|
-
})
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// Handle calls and writes separately because they keep several values and keys live. Avoid
|
|
453
|
-
// adding that storage to every recursive operand frame.
|
|
454
|
-
#[inline(never)]
|
|
455
|
-
fn call(
|
|
153
|
+
/// Assigns to `target` with `operator`, as in `target += right`, where `right` evaluates
|
|
154
|
+
/// the right side.
|
|
155
|
+
#[inline]
|
|
156
|
+
pub(super) fn compound(
|
|
456
157
|
&mut self,
|
|
457
|
-
|
|
458
|
-
|
|
158
|
+
target: Location<'ast>,
|
|
159
|
+
operator: BinaryOperator,
|
|
459
160
|
locals: &mut Locals<'ast>,
|
|
161
|
+
right: impl FnOnce(&mut Self, &mut Locals<'ast>) -> Evaluation<'ast, Value<'ast>>,
|
|
460
162
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
467
|
-
callee => (self.evaluate(callee, locals)?, Value::Undefined),
|
|
468
|
-
};
|
|
469
|
-
let arguments = self.arguments(arguments, locals)?;
|
|
470
|
-
self.apply(callee, this, arguments)
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/// Evaluates call arguments into a reused buffer.
|
|
474
|
-
fn arguments(
|
|
475
|
-
&mut self,
|
|
476
|
-
arguments: &[Expression<'ast>],
|
|
477
|
-
locals: &mut Locals<'ast>,
|
|
478
|
-
) -> Evaluation<'ast, Vec<Value<'ast>>> {
|
|
479
|
-
let mut values = self.spare.arguments.pop().unwrap_or_default();
|
|
480
|
-
for argument in arguments {
|
|
481
|
-
values.push(self.evaluate(argument, locals)?);
|
|
163
|
+
// The script reapplies a new rolling mask to the program counter or key. The
|
|
164
|
+
// interpreter keeps that mask at zero; see `crate::vm::registers`.
|
|
165
|
+
if matches!(&target, Location::Member(Value::Registers, Key::Name(_))) {
|
|
166
|
+
right(self, locals)?;
|
|
167
|
+
return self.read(&target, locals);
|
|
482
168
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
arguments: &[Expression<'ast>],
|
|
491
|
-
locals: &mut Locals<'ast>,
|
|
492
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
493
|
-
let callee = self.evaluate(callee, locals)?;
|
|
494
|
-
let arguments = self.arguments(arguments, locals)?;
|
|
495
|
-
self.construct(callee, arguments)
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
#[inline(never)]
|
|
499
|
-
fn assignment(
|
|
500
|
-
&mut self,
|
|
501
|
-
target: &Target<'ast>,
|
|
502
|
-
operator: Option<BinaryOp>,
|
|
503
|
-
right: &Expression<'ast>,
|
|
504
|
-
locals: &mut Locals<'ast>,
|
|
505
|
-
) -> Evaluation<'ast, Value<'ast>> {
|
|
506
|
-
let target = self.locate(target, locals)?;
|
|
507
|
-
let value = match operator {
|
|
508
|
-
None => self.evaluate(right, locals)?,
|
|
509
|
-
Some(BinaryOp::LogicalAnd | BinaryOp::LogicalOr | BinaryOp::NullishCoalescing) => {
|
|
510
|
-
return Err(Stop::unsupported("a logical assignment"));
|
|
511
|
-
}
|
|
512
|
-
// The script reapplies a new rolling mask to the program counter or key. The
|
|
513
|
-
// interpreter keeps that mask at zero; see `crate::vm::registers`.
|
|
514
|
-
Some(_) if matches!(&target, Location::Member(Value::Registers, Key::Name(_))) => {
|
|
515
|
-
self.evaluate(right, locals)?;
|
|
516
|
-
return self.read(&target, locals);
|
|
169
|
+
// The target's old value is read before the right side runs.
|
|
170
|
+
let old = self.read(&target, locals)?;
|
|
171
|
+
let right = right(self, locals)?;
|
|
172
|
+
// Release the old value before overwriting it, allowing `s += c` to append in place.
|
|
173
|
+
match &target {
|
|
174
|
+
Location::Name(Name::Local(slot, _)) if locals[*slot].is_some() => {
|
|
175
|
+
locals[*slot] = Some(Value::Undefined);
|
|
517
176
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
let old = self.read(&target, locals)?;
|
|
521
|
-
let right = self.evaluate(right, locals)?;
|
|
522
|
-
// Release the old value before overwriting it, allowing `s += c` to append in
|
|
523
|
-
// place.
|
|
524
|
-
match &target {
|
|
525
|
-
Location::Name(Name::Local(slot, _)) if locals[*slot].is_some() => {
|
|
526
|
-
locals[*slot] = Some(Value::Undefined);
|
|
527
|
-
}
|
|
528
|
-
Location::Name(name) => {
|
|
529
|
-
Env::assign(&self.frame().scope, name.atom(), Value::Undefined);
|
|
530
|
-
}
|
|
531
|
-
Location::Member(..) => {}
|
|
532
|
-
}
|
|
533
|
-
binary_value(operator, old, right)
|
|
177
|
+
Location::Name(name) => {
|
|
178
|
+
self.frame().assign(name.binding(), Value::Undefined);
|
|
534
179
|
}
|
|
535
|
-
|
|
180
|
+
Location::Member(..) => {}
|
|
181
|
+
}
|
|
182
|
+
let value = binary_value(operator, old, right);
|
|
536
183
|
self.write(target, value.clone(), locals)?;
|
|
537
184
|
Ok(value)
|
|
538
185
|
}
|
|
539
186
|
|
|
540
|
-
|
|
541
|
-
fn
|
|
187
|
+
/// Applies `++` or `--` to the number at `target`.
|
|
188
|
+
pub(super) fn update_location(
|
|
542
189
|
&mut self,
|
|
543
|
-
target:
|
|
544
|
-
operator:
|
|
190
|
+
target: Location<'ast>,
|
|
191
|
+
operator: UpdateOperator,
|
|
545
192
|
prefix: bool,
|
|
546
193
|
locals: &mut Locals<'ast>,
|
|
547
194
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
548
|
-
// A counter: the local is read and written in place.
|
|
549
|
-
if let Target::Name(Name::Local(slot, _)) = target
|
|
550
|
-
&& let Some(Value::Number(number)) = &mut locals[*slot]
|
|
551
|
-
{
|
|
552
|
-
let change = updated(operator, prefix, *number);
|
|
553
|
-
*number = change.written;
|
|
554
|
-
return Ok(Value::Number(change.value));
|
|
555
|
-
}
|
|
556
|
-
let target = self.locate(target, locals)?;
|
|
557
195
|
let old = self.read(&target, locals)?;
|
|
558
|
-
let
|
|
196
|
+
let mut number = old
|
|
559
197
|
.number()
|
|
560
198
|
.ok_or_else(|| Stop::unsupported(&format!("incrementing {}", old.expr())))?;
|
|
561
|
-
let
|
|
562
|
-
self.write(target, Value::Number(
|
|
563
|
-
Ok(Value::Number(
|
|
199
|
+
let value = step(operator, prefix, &mut number);
|
|
200
|
+
self.write(target, Value::Number(number), locals)?;
|
|
201
|
+
Ok(Value::Number(value))
|
|
564
202
|
}
|
|
565
203
|
|
|
566
|
-
///
|
|
567
|
-
|
|
568
|
-
|
|
204
|
+
/// Finishes `&&`, `||`, or `??` after its left side, calling `right` to evaluate the right
|
|
205
|
+
/// side only when needed.
|
|
206
|
+
#[inline]
|
|
207
|
+
pub(super) fn short_circuit(
|
|
569
208
|
&mut self,
|
|
570
|
-
operator:
|
|
571
|
-
left:
|
|
572
|
-
right: &Expression<'ast>,
|
|
209
|
+
operator: LogicalOperator,
|
|
210
|
+
left: Value<'ast>,
|
|
573
211
|
pure: bool,
|
|
574
212
|
locals: &mut Locals<'ast>,
|
|
213
|
+
right: impl Fn(&mut Self, &mut Locals<'ast>) -> Evaluation<'ast, Value<'ast>>,
|
|
575
214
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
576
|
-
let left = self.evaluate(left, locals)?;
|
|
577
215
|
// Condition controlling right-operand evaluation and the branch direction that
|
|
578
216
|
// evaluates it.
|
|
579
217
|
let (test, runs_right) = match operator {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
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),
|
|
584
222
|
true,
|
|
585
223
|
),
|
|
586
224
|
};
|
|
@@ -588,13 +226,13 @@ impl<'ast> Run<'ast, '_> {
|
|
|
588
226
|
// An effect-free right operand may become a symbolic term only if evaluating it
|
|
589
227
|
// cannot introduce an exception on a skipped path.
|
|
590
228
|
let effects = self.effects.len();
|
|
591
|
-
if let Ok(right) = self
|
|
229
|
+
if let Ok(right) = right(self, locals) {
|
|
592
230
|
debug_assert_eq!(
|
|
593
231
|
effects,
|
|
594
232
|
self.effects.len(),
|
|
595
233
|
"a pure right side runs without effects"
|
|
596
234
|
);
|
|
597
|
-
return Ok(Value::symbolic(Term::
|
|
235
|
+
return Ok(Value::symbolic(Term::Logical(
|
|
598
236
|
operator,
|
|
599
237
|
Box::new(left.expr()),
|
|
600
238
|
Box::new(right.expr()),
|
|
@@ -602,63 +240,38 @@ impl<'ast> Run<'ast, '_> {
|
|
|
602
240
|
}
|
|
603
241
|
}
|
|
604
242
|
if self.decide(&test) == runs_right {
|
|
605
|
-
self
|
|
243
|
+
right(self, locals)
|
|
606
244
|
} else {
|
|
607
245
|
Ok(left)
|
|
608
246
|
}
|
|
609
247
|
}
|
|
610
248
|
|
|
611
|
-
|
|
612
|
-
fn locate(
|
|
613
|
-
&mut self,
|
|
614
|
-
target: &Target<'ast>,
|
|
615
|
-
locals: &mut Locals<'ast>,
|
|
616
|
-
) -> Evaluation<'ast, Location<'ast>> {
|
|
617
|
-
Ok(match target {
|
|
618
|
-
Target::Name(name) => Location::Name(*name),
|
|
619
|
-
Target::Member(object, key) => {
|
|
620
|
-
let object = self.evaluate(object, locals)?;
|
|
621
|
-
let key = self.property(key, locals)?;
|
|
622
|
-
Location::Member(object, key)
|
|
623
|
-
}
|
|
624
|
-
})
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
fn read(
|
|
249
|
+
pub(super) fn read(
|
|
628
250
|
&mut self,
|
|
629
251
|
target: &Location<'ast>,
|
|
630
252
|
locals: &Locals<'ast>,
|
|
631
253
|
) -> Evaluation<'ast, Value<'ast>> {
|
|
632
254
|
match target {
|
|
633
|
-
Location::Name(Name::Local(slot,
|
|
255
|
+
Location::Name(Name::Local(slot, binding)) => match &locals[*slot] {
|
|
634
256
|
Some(value) => Ok(value.clone()),
|
|
635
|
-
None => self.lookup(
|
|
257
|
+
None => self.lookup(*binding),
|
|
636
258
|
},
|
|
637
|
-
Location::Name(Name::
|
|
259
|
+
Location::Name(Name::Scoped(binding)) => self.lookup(*binding),
|
|
638
260
|
Location::Member(object, key) => self.get(object, key),
|
|
639
261
|
}
|
|
640
262
|
}
|
|
641
263
|
|
|
642
|
-
/// Writes
|
|
264
|
+
/// Writes locals directly, since they are the most common assignment target.
|
|
643
265
|
#[inline]
|
|
644
|
-
fn write(
|
|
266
|
+
pub(super) fn write(
|
|
645
267
|
&mut self,
|
|
646
268
|
target: Location<'ast>,
|
|
647
269
|
value: Value<'ast>,
|
|
648
270
|
locals: &mut Locals<'ast>,
|
|
649
271
|
) -> Evaluation<'ast, ()> {
|
|
650
272
|
match target {
|
|
651
|
-
Location::Name(Name::Local(slot,
|
|
652
|
-
|
|
653
|
-
if locals[slot].is_none()
|
|
654
|
-
&& (self.globals.contains_key(name) || self.session.bindings.contains_key(name))
|
|
655
|
-
{
|
|
656
|
-
self.assign_name(name, value);
|
|
657
|
-
} else {
|
|
658
|
-
locals[slot] = Some(value);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
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),
|
|
662
275
|
Location::Member(object, key) => return self.set(&object, &key, value),
|
|
663
276
|
}
|
|
664
277
|
Ok(())
|
|
@@ -667,30 +280,34 @@ impl<'ast> Run<'ast, '_> {
|
|
|
667
280
|
|
|
668
281
|
/// Clones a value, using a fast path for numbers.
|
|
669
282
|
#[inline(always)]
|
|
670
|
-
fn copied<'a>(value: &Value<'a>) -> Value<'a> {
|
|
283
|
+
pub(super) fn copied<'a>(value: &Value<'a>) -> Value<'a> {
|
|
671
284
|
match value {
|
|
672
285
|
Value::Number(number) => Value::Number(*number),
|
|
673
286
|
value => value.clone(),
|
|
674
287
|
}
|
|
675
288
|
}
|
|
676
289
|
|
|
677
|
-
///
|
|
290
|
+
/// Converts the result of compiled numeric evaluation to a value.
|
|
678
291
|
#[inline(always)]
|
|
679
|
-
fn number_value(number: Result<f64, Value<'_>>) -> Value<'_> {
|
|
292
|
+
pub(super) fn number_value(number: Result<f64, Value<'_>>) -> Value<'_> {
|
|
680
293
|
number.map_or_else(|value| value, Value::Number)
|
|
681
294
|
}
|
|
682
295
|
|
|
683
296
|
/// Slot-indexed call locals; `None` until declared or written.
|
|
684
|
-
type Locals<'ast> = [Option<Value<'ast>>];
|
|
297
|
+
pub(super) type Locals<'ast> = [Option<Value<'ast>>];
|
|
685
298
|
|
|
686
|
-
enum Location<'ast> {
|
|
299
|
+
pub(super) enum Location<'ast> {
|
|
687
300
|
Name(Name<'ast>),
|
|
688
301
|
Member(Value<'ast>, Key<'ast, 'ast>),
|
|
689
302
|
}
|
|
690
303
|
|
|
691
304
|
/// Applies [`semantics::binary_value`] to numeric operands without coercion or symbolic terms.
|
|
692
305
|
#[inline(always)]
|
|
693
|
-
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> {
|
|
694
311
|
let (&Value::Number(a), &Value::Number(b)) = (&left, &right) else {
|
|
695
312
|
return semantics::binary_value(operator, left, right);
|
|
696
313
|
};
|
|
@@ -700,34 +317,34 @@ fn binary_value<'a>(operator: BinaryOp, left: Value<'a>, right: Value<'a>) -> Va
|
|
|
700
317
|
return Value::Number(operation(a, b));
|
|
701
318
|
}
|
|
702
319
|
Value::Bool(match operator {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
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,
|
|
709
326
|
_ => return semantics::binary_value(operator, Value::Number(a), Value::Number(b)),
|
|
710
327
|
})
|
|
711
328
|
}
|
|
712
329
|
|
|
713
|
-
///
|
|
714
|
-
|
|
715
|
-
/// The number written back.
|
|
716
|
-
written: f64,
|
|
717
|
-
/// Expression result: the new number for prefix form, or the old number for postfix form.
|
|
718
|
-
value: f64,
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
/// Computes the result and stored value for `++` or `--` applied to `old`.
|
|
330
|
+
/// Applies `++` or `--` to `number` in place. Returns the expression's result: the new number
|
|
331
|
+
/// in prefix form, or the old number in postfix form.
|
|
722
332
|
#[inline(always)]
|
|
723
|
-
fn
|
|
724
|
-
let
|
|
725
|
-
|
|
726
|
-
|
|
333
|
+
pub(super) fn step(operator: UpdateOperator, prefix: bool, number: &mut f64) -> f64 {
|
|
334
|
+
let old = *number;
|
|
335
|
+
*number = match operator {
|
|
336
|
+
UpdateOperator::Increment => old + 1.0,
|
|
337
|
+
UpdateOperator::Decrement => old - 1.0,
|
|
727
338
|
};
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
339
|
+
if prefix { *number } else { old }
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/// The result of a call whose body completed with `flow`.
|
|
343
|
+
#[inline]
|
|
344
|
+
fn returned(flow: Flow<'_>) -> Value<'_> {
|
|
345
|
+
match flow {
|
|
346
|
+
Flow::Return(value) => value,
|
|
347
|
+
_ => Value::Undefined,
|
|
731
348
|
}
|
|
732
349
|
}
|
|
733
350
|
|