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.
Files changed (404) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/README.md +10 -9
  4. data/THIRD_PARTY_LICENSES/README.md +71 -254
  5. data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
  6. data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
  7. data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
  8. data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
  9. data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
  10. data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
  11. data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
  12. data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
  13. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
  14. data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
  15. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
  16. data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
  17. data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
  18. data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
  19. data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
  20. data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
  21. data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
  22. data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
  23. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
  24. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
  25. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
  26. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
  27. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
  28. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
  29. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
  30. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
  31. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
  32. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
  33. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
  34. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
  35. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
  36. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
  37. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
  38. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
  39. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
  40. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
  41. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
  42. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
  43. data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
  44. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
  45. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
  46. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
  47. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
  48. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
  49. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
  50. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
  51. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
  52. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
  53. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
  54. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
  55. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
  56. data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
  57. data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
  58. data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
  59. data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
  60. data/UPSTREAM.md +10 -8
  61. data/ext/cfsolve/Cargo.lock +534 -1727
  62. data/ext/cfsolve/Cargo.toml +4 -0
  63. data/ext/cfsolve/src/main.rs +1 -1
  64. data/lib/cfsolve/profiles/safari-26-ios/answers.json +2570 -1894
  65. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
  66. data/lib/cfsolve/profiles/safari-26-ios.json +102 -156
  67. data/lib/cfsolve/version.rb +2 -2
  68. data/vendor/cfsolve/Cargo.lock +561 -1729
  69. data/vendor/cfsolve/Cargo.toml +26 -8
  70. data/vendor/cfsolve/README.md +4 -35
  71. data/vendor/cfsolve/examples/build_profile.rs +17 -15
  72. data/vendor/cfsolve/examples/capture_session.rs +37 -0
  73. data/vendor/cfsolve/examples/check_answers.rs +66 -0
  74. data/vendor/cfsolve/examples/compare_session.rs +189 -0
  75. data/vendor/cfsolve/examples/solver_profile.rs +84 -0
  76. data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
  77. data/vendor/cfsolve/examples/stage2_snapshot.rs +6 -3
  78. data/vendor/cfsolve/examples/tls_echo.rs +3 -3
  79. data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
  80. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +2570 -1894
  81. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
  82. data/vendor/cfsolve/profiles/safari-26-ios.json +102 -156
  83. data/vendor/cfsolve/scripts/capture_cssom.mjs +42 -0
  84. data/vendor/cfsolve/scripts/serve_cssom.py +111 -0
  85. data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
  86. data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
  87. data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
  88. data/vendor/cfsolve/src/capture/profile.rs +7 -18
  89. data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
  90. data/vendor/cfsolve/src/capture/proxy.rs +44 -13
  91. data/vendor/cfsolve/src/capture/recorded.rs +42 -7
  92. data/vendor/cfsolve/src/capture/sessions.rs +4 -3
  93. data/vendor/cfsolve/src/capture/upstream.rs +1 -1
  94. data/vendor/cfsolve/src/challenge/codec.rs +4 -2
  95. data/vendor/cfsolve/src/challenge/expression.rs +161 -117
  96. data/vendor/cfsolve/src/challenge/installed/audit.rs +132 -0
  97. data/vendor/cfsolve/src/challenge/installed.rs +127 -269
  98. data/vendor/cfsolve/src/challenge/merge.rs +120 -80
  99. data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
  100. data/vendor/cfsolve/src/challenge/payload.rs +175 -35
  101. data/vendor/cfsolve/src/challenge/program.rs +197 -178
  102. data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
  103. data/vendor/cfsolve/src/challenge/source.rs +151 -96
  104. data/vendor/cfsolve/src/challenge/state.rs +236 -122
  105. data/vendor/cfsolve/src/challenge/tally.rs +64 -50
  106. data/vendor/cfsolve/src/challenge.rs +1 -0
  107. data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
  108. data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
  109. data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
  110. data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
  111. data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
  112. data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
  113. data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
  114. data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
  115. data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
  116. data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
  117. data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
  118. data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
  119. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
  120. data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
  121. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
  122. data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
  123. data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
  124. data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +201 -205
  125. data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
  126. data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +346 -536
  127. data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
  128. data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
  129. data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
  130. data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
  131. data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
  132. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
  133. data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
  134. data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +361 -322
  135. data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
  136. data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
  137. data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
  138. data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
  139. data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
  140. data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
  141. data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
  142. data/vendor/cfsolve/src/deobfuscate.rs +15 -11
  143. data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -32
  144. data/vendor/cfsolve/src/embedding_page/page.rs +28 -2
  145. data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
  146. data/vendor/cfsolve/src/error.rs +40 -5
  147. data/vendor/cfsolve/src/fingerprint.rs +8 -2
  148. data/vendor/cfsolve/src/http/client.rs +9 -1
  149. data/vendor/cfsolve/src/http/requests.rs +2 -2
  150. data/vendor/cfsolve/src/js/ast.rs +479 -254
  151. data/vendor/cfsolve/src/js/objects.rs +9 -2
  152. data/vendor/cfsolve/src/lib.rs +1 -0
  153. data/vendor/cfsolve/src/listing/fold.rs +19 -92
  154. data/vendor/cfsolve/src/listing/query.rs +26 -291
  155. data/vendor/cfsolve/src/listing.rs +0 -1
  156. data/vendor/cfsolve/src/performance_clock.rs +20 -1
  157. data/vendor/cfsolve/src/profiling.rs +49 -0
  158. data/vendor/cfsolve/src/script.rs +35 -24
  159. data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
  160. data/vendor/cfsolve/src/session/channel.rs +2 -2
  161. data/vendor/cfsolve/src/session/initial.rs +19 -10
  162. data/vendor/cfsolve/src/session/probes.rs +160 -125
  163. data/vendor/cfsolve/src/session/sink.rs +26 -1
  164. data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
  165. data/vendor/cfsolve/src/session/timing.rs +58 -53
  166. data/vendor/cfsolve/src/session/widget.rs +5 -6
  167. data/vendor/cfsolve/src/session.rs +1 -1
  168. data/vendor/cfsolve/src/solver.rs +3 -1
  169. data/vendor/cfsolve/src/stage2/analysis/analyze.rs +50 -33
  170. data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
  171. data/vendor/cfsolve/src/stage2/analysis/discovery.rs +61 -66
  172. data/vendor/cfsolve/src/stage2/analysis/envelope.rs +33 -22
  173. data/vendor/cfsolve/src/stage2/analysis/recognize.rs +3 -5
  174. data/vendor/cfsolve/src/stage2/analysis.rs +0 -1
  175. data/vendor/cfsolve/src/stage2/audit_globals.rs +378 -0
  176. data/vendor/cfsolve/src/stage2/benchmark.rs +66 -38
  177. data/vendor/cfsolve/src/stage2/call_stack.rs +1463 -1017
  178. data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
  179. data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
  180. data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
  181. data/vendor/cfsolve/src/stage2/interaction/native.rs +2 -1
  182. data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -7
  183. data/vendor/cfsolve/src/stage2/payload/recover.rs +56 -25
  184. data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
  185. data/vendor/cfsolve/src/stage2/probes/ice.rs +11 -10
  186. data/vendor/cfsolve/src/stage2/probes/media.rs +47 -33
  187. data/vendor/cfsolve/src/stage2/probes/performance.rs +13 -8
  188. data/vendor/cfsolve/src/stage2/probes/rects.rs +12 -17
  189. data/vendor/cfsolve/src/stage2/probes/stack.rs +50 -103
  190. data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +17 -86
  191. data/vendor/cfsolve/src/stage2/probes.rs +0 -1
  192. data/vendor/cfsolve/src/stage2/queries.rs +50 -0
  193. data/vendor/cfsolve/src/stage2/records.rs +4 -13
  194. data/vendor/cfsolve/src/stage2/reference.json +1 -1
  195. data/vendor/cfsolve/src/stage2/reference.rs +98 -100
  196. data/vendor/cfsolve/src/stage2/registry.rs +41 -34
  197. data/vendor/cfsolve/src/stage2/replay.rs +182 -254
  198. data/vendor/cfsolve/src/stage2/stylesheets.rs +176 -0
  199. data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
  200. data/vendor/cfsolve/src/stage2/trace.rs +152 -108
  201. data/vendor/cfsolve/src/stage2/vocabulary.rs +103 -403
  202. data/vendor/cfsolve/src/stage2.rs +4 -1
  203. data/vendor/cfsolve/src/vm/disassemble.rs +46 -13
  204. data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
  205. data/vendor/cfsolve/src/vm/extract.rs +347 -250
  206. data/vendor/cfsolve/src/vm/interpret/access.rs +67 -68
  207. data/vendor/cfsolve/src/vm/interpret/builtin.rs +16 -63
  208. data/vendor/cfsolve/src/vm/interpret/call.rs +192 -51
  209. data/vendor/cfsolve/src/vm/interpret/compile.rs +643 -0
  210. data/vendor/cfsolve/src/vm/interpret/copies.rs +232 -120
  211. data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +149 -40
  212. data/vendor/cfsolve/src/vm/interpret/evaluate.rs +189 -572
  213. data/vendor/cfsolve/src/vm/interpret/explore.rs +159 -46
  214. data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
  215. data/vendor/cfsolve/src/vm/interpret/frozen.rs +169 -0
  216. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +414 -0
  217. data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
  218. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
  219. data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
  220. data/vendor/cfsolve/src/vm/interpret/plan.rs +605 -330
  221. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
  222. data/vendor/cfsolve/src/vm/interpret/run.rs +314 -54
  223. data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
  224. data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
  225. data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
  226. data/vendor/cfsolve/src/vm/interpret.rs +16 -3
  227. data/vendor/cfsolve/src/vm/machine.rs +58 -47
  228. data/vendor/cfsolve/src/vm/output.rs +13 -5
  229. data/vendor/cfsolve/src/vm/packed_names.rs +311 -0
  230. data/vendor/cfsolve/src/vm/session.rs +197 -110
  231. data/vendor/cfsolve/src/vm/value.rs +35 -19
  232. data/vendor/cfsolve/src/vm.rs +3 -1
  233. data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
  234. data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
  235. data/vendor/cfsolve/vendor/btls-sys/src/lib.rs +3 -0
  236. metadata +106 -183
  237. data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
  238. data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
  239. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
  240. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
  241. data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
  242. data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
  243. data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
  244. data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
  245. data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
  246. data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
  247. data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
  248. data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
  249. data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
  250. data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
  251. data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
  252. data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
  253. data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
  254. data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
  255. data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
  256. data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
  257. data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
  258. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
  259. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
  260. data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
  261. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
  262. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
  263. data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
  264. data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
  265. data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
  266. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
  267. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
  268. data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
  269. data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
  270. data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
  271. data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
  272. data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
  273. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
  274. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
  275. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
  276. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
  277. data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
  278. data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
  279. data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
  280. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
  281. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
  282. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
  283. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
  284. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
  285. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
  286. data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
  287. data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
  288. data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
  289. data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
  290. data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
  291. data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
  292. data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
  293. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
  294. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
  295. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
  296. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
  297. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
  298. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
  299. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
  300. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
  301. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
  302. data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
  303. data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
  304. data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
  305. data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
  306. data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
  307. data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
  308. data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
  309. data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
  310. data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
  311. data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
  312. data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
  313. data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
  314. data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
  315. data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
  316. data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
  317. data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
  318. data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
  319. data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
  320. data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
  321. data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
  322. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
  323. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
  324. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
  325. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
  326. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
  327. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
  328. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
  329. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
  330. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
  331. data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
  332. data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
  333. data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
  334. data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
  335. data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
  336. data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
  337. data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
  338. data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
  339. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
  340. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
  341. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
  342. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
  343. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
  344. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
  345. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
  346. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
  347. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
  348. data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
  349. data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
  350. data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
  351. data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
  352. data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
  353. data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
  354. data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
  355. data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
  356. data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
  357. data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
  358. data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
  359. data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
  360. data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
  361. data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
  362. data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
  363. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
  364. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
  365. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
  366. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
  367. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
  368. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
  369. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
  370. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
  371. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
  372. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
  373. data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
  374. data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
  375. data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
  376. data/vendor/cfsolve/src/listing/normalize.rs +0 -264
  377. data/vendor/cfsolve/src/stage2/analysis/outputs.rs +0 -327
  378. data/vendor/cfsolve/src/stage2/probes/stylesheets.rs +0 -249
  379. data/vendor/cfsolve/src/stage2/reference-expanded.json +0 -42
  380. data/vendor/cfsolve/src/stage2/session_names.rs +0 -470
  381. /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
  382. /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
  383. /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
  384. /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
  385. /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
  386. /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
  387. /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
  388. /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
  389. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
  390. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
  391. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
  392. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
  393. /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
  394. /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
  395. /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
  396. /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
  397. /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
  398. /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
  399. /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
  400. /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
  401. /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
  402. /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
  403. /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
  404. /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 plans from [`super::plan`]. Computes byte-dependent values and leaves
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 std::cell::RefCell;
6
- use std::rc::Rc;
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 swc_core::ecma::ast::{BinaryOp, Expr, Stmt, UpdateOp};
10
-
11
- use super::access::{self, Key};
12
- use super::plan::{self, Case, Expression, FunctionPlan, Name, Property, Statement, Target};
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::{Env, 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
- pub(super) fn statement(&mut self, statement: &'ast Stmt) -> Evaluation<'ast, Flow<'ast>> {
24
- self.execute_all(&plan::scoped(slice::from_ref(statement)), &mut [])
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
- pub(in crate::vm) fn expression(&mut self, expr: &'ast Expr) -> Evaluation<'ast, Value<'ast>> {
28
- self.evaluate(&plan::scoped_expression(expr), &mut [])
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
- mut arguments: Vec<Value<'ast>>,
40
+ arguments: Vec<Value<'ast>>,
36
41
  ) -> Evaluation<'ast, Value<'ast>> {
37
- let mut locals = self.spare.locals.pop().unwrap_or_default();
38
- locals.resize(plan.locals, None);
39
- if let Some(slot) = plan.arguments {
40
- locals[slot] = Some(Value::array(arguments.clone()));
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
- /// Runs a function body in `frame`.
59
- pub(super) fn body(
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
- frame: Frame<'ast>,
62
- body: &[Statement<'ast>],
63
- locals: &mut Locals<'ast>,
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.frames.push(frame);
66
- let flow = self.execute_all(body, locals);
67
- self.frames.pop();
68
- match flow? {
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
- fn execute_all(
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
- statements: &[Statement<'ast>],
77
- locals: &mut Locals<'ast>,
78
- ) -> Evaluation<'ast, Flow<'ast>> {
79
- for statement in statements {
80
- let flow = self.execute(statement, locals)?;
81
- if !matches!(flow, Flow::Normal) {
82
- return Ok(flow);
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
- fn execute(
105
- &mut self,
106
- statement: &Statement<'ast>,
107
- locals: &mut Locals<'ast>,
108
- ) -> Evaluation<'ast, Flow<'ast>> {
109
- match statement {
110
- Statement::Switch(discriminant, cases) => {
111
- return self.switch(discriminant, cases, locals);
112
- }
113
- Statement::Empty => {}
114
- Statement::Expression(expression) => self.evaluate(expression, locals)?.discard(),
115
- Statement::Declare(declarations) => {
116
- for declaration in declarations {
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
- Ok(Flow::Normal)
96
+ drop(values);
97
+ self.spare.arguments.push(arguments);
98
+ self.frames.push(frame);
99
+ locals
217
100
  }
218
101
 
219
- /// Runs from the first case strictly equal to `discriminant`, or else from the default.
220
- fn switch(
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
- discriminant: &Expression<'ast>,
223
- cases: &[Case<'ast>],
106
+ plan: &FunctionPlan<'ast>,
107
+ start: usize,
224
108
  locals: &mut Locals<'ast>,
225
- ) -> Evaluation<'ast, Flow<'ast>> {
226
- let discriminant = self.evaluate(discriminant, locals)?;
227
- let mut matched = None;
228
- let mut default = None;
229
- for (index, case) in cases.iter().enumerate() {
230
- let Some(test) = &case.test else {
231
- default = default.or(Some(index));
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
- let Some(start) = matched.or(default) else {
243
- return Ok(Flow::Normal);
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
- /// Reads common constants and locals directly. Delegates other nodes to separate functions
267
- /// to keep recursive stack frames small.
268
- #[inline(always)]
269
- fn evaluate(
270
- &mut self,
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
- #[inline(never)]
307
- fn binary(
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
- expression: &Expression<'ast>,
135
+ frame: Frame<'ast>,
136
+ body: &[Code<'ast>],
323
137
  locals: &mut Locals<'ast>,
324
138
  ) -> Evaluation<'ast, Value<'ast>> {
325
- Ok(number_value(self.number(expression, locals)?))
326
- }
327
-
328
- /// Evaluates numeric arithmetic without wrapping intermediate results. If an operand is
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
- /// An operand of arithmetic. Reads numeric constants and locals without a call.
361
- #[inline(always)]
362
- fn operand(
363
- &mut self,
364
- expression: &Expression<'ast>,
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
- #[inline(never)]
379
- fn member(
380
- &mut self,
381
- object: &Expression<'ast>,
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
- callee: &Expression<'ast>,
458
- arguments: &[Expression<'ast>],
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
- let (callee, this) = match callee {
462
- Expression::Member(object, property) => {
463
- let object = self.evaluate(object, locals)?;
464
- let key = self.property(property, locals)?;
465
- (self.get(&object, &key)?, object)
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
- Ok(values)
484
- }
485
-
486
- #[inline(never)]
487
- fn construction(
488
- &mut self,
489
- callee: &Expression<'ast>,
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
- // The target's old value is read before the right side runs.
519
- Some(operator) => {
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
- #[inline(never)]
541
- fn update(
187
+ /// Applies `++` or `--` to the number at `target`.
188
+ pub(super) fn update_location(
542
189
  &mut self,
543
- target: &Target<'ast>,
544
- operator: UpdateOp,
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 old = old
196
+ let mut number = old
559
197
  .number()
560
198
  .ok_or_else(|| Stop::unsupported(&format!("incrementing {}", old.expr())))?;
561
- let change = updated(operator, prefix, old);
562
- self.write(target, Value::Number(change.written), locals)?;
563
- Ok(Value::Number(change.value))
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
- /// Evaluates `&&`, `||`, or `??`, evaluating `right` only when needed.
567
- #[inline(never)]
568
- fn logical(
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: BinaryOp,
571
- left: &Expression<'ast>,
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
- BinaryOp::LogicalAnd => (left.clone(), true),
581
- BinaryOp::LogicalOr => (left.clone(), false),
582
- _ => (
583
- semantics::binary_value(BinaryOp::EqEq, left.clone(), Value::Null),
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.evaluate(right, locals) {
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::Binary(
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.evaluate(right, locals)
243
+ right(self, locals)
606
244
  } else {
607
245
  Ok(left)
608
246
  }
609
247
  }
610
248
 
611
- #[inline]
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, name)) => match &locals[*slot] {
255
+ Location::Name(Name::Local(slot, binding)) => match &locals[*slot] {
634
256
  Some(value) => Ok(value.clone()),
635
- None => self.lookup(name),
257
+ None => self.lookup(*binding),
636
258
  },
637
- Location::Name(Name::Global(name)) => self.lookup(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 declared locals directly, since they are the most common assignment target.
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, name)) => {
652
- // Until its declaration runs, a local's name still assigns a session binding.
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
- /// Extracts the value from a [`Run::number`] result.
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>(operator: BinaryOp, left: Value<'a>, right: Value<'a>) -> 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
- BinaryOp::EqEq | BinaryOp::EqEqEq => a == b,
704
- BinaryOp::NotEq | BinaryOp::NotEqEq => a != b,
705
- BinaryOp::Lt => a < b,
706
- BinaryOp::LtEq => a <= b,
707
- BinaryOp::Gt => a > b,
708
- BinaryOp::GtEq => a >= b,
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
- /// Values produced and stored by an increment or decrement.
714
- struct Updated {
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 updated(operator: UpdateOp, prefix: bool, old: f64) -> Updated {
724
- let new = match operator {
725
- UpdateOp::PlusPlus => old + 1.0,
726
- UpdateOp::MinusMinus => old - 1.0,
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
- Updated {
729
- written: new,
730
- value: if prefix { new } else { old },
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