From dcc3b610e983496f714ac520f5f07c9a49584928 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Tue, 30 Jun 2026 20:04:27 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E8=87=AA=E5=8A=A8=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_compiler/src/emitter/expr/assignment.rs | 5 ++++- crates/oxide_compiler/src/emitter/expr/literal.rs | 5 ++++- crates/oxide_vm/src/dispatch/call.rs | 8 ++++++-- crates/oxide_vm/tests/scoping_tests.rs | 3 ++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/oxide_compiler/src/emitter/expr/assignment.rs b/crates/oxide_compiler/src/emitter/expr/assignment.rs index 367e8e78..8f5069d3 100644 --- a/crates/oxide_compiler/src/emitter/expr/assignment.rs +++ b/crates/oxide_compiler/src/emitter/expr/assignment.rs @@ -149,7 +149,10 @@ impl Compiler { } // Check if target is a captured cell if ctx.scopes.symbols.lookup_is_captured(name) { - let cell_idx = ctx.scopes.cell_registry.iter() + let cell_idx = ctx + .scopes + .cell_registry + .iter() .find(|(n, _)| n == name) .map(|(_, idx)| *idx) .unwrap_or(0); diff --git a/crates/oxide_compiler/src/emitter/expr/literal.rs b/crates/oxide_compiler/src/emitter/expr/literal.rs index c347c207..b16b9483 100644 --- a/crates/oxide_compiler/src/emitter/expr/literal.rs +++ b/crates/oxide_compiler/src/emitter/expr/literal.rs @@ -70,7 +70,10 @@ impl Compiler { // Check if the owner's binding is captured (cell access) if ctx.scopes.symbols.lookup_is_captured(name) { - let cell_idx = ctx.scopes.cell_registry.iter() + let cell_idx = ctx + .scopes + .cell_registry + .iter() .find(|(n, _)| n == name) .map(|(_, idx)| *idx) .unwrap_or(0); diff --git a/crates/oxide_vm/src/dispatch/call.rs b/crates/oxide_vm/src/dispatch/call.rs index dead8381..ff64e911 100644 --- a/crates/oxide_vm/src/dispatch/call.rs +++ b/crates/oxide_vm/src/dispatch/call.rs @@ -163,7 +163,9 @@ impl Vm { if cell_ptr.is_null() { return Ok(()); } - unsafe { (*cell_ptr).value = src_val; } + unsafe { + (*cell_ptr).value = src_val; + } Ok(()) } @@ -197,7 +199,9 @@ impl Vm { if uv_idx < upvals.len() { let cell = upvals[uv_idx]; if !cell.is_null() { - unsafe { (*cell).value = src_val; } + unsafe { + (*cell).value = src_val; + } } } } diff --git a/crates/oxide_vm/tests/scoping_tests.rs b/crates/oxide_vm/tests/scoping_tests.rs index efe1b7b1..39145b29 100644 --- a/crates/oxide_vm/tests/scoping_tests.rs +++ b/crates/oxide_vm/tests/scoping_tests.rs @@ -68,7 +68,8 @@ fn closure_nested_decl_reads_outer_var() { #[test] fn closure_counter_escape() { - let result = eval("function counter(){ var n=0; return function(){ return ++n; }; } var c=counter(); c(); c()").unwrap(); + let result = + eval("function counter(){ var n=0; return function(){ return ++n; }; } var c=counter(); c(); c()").unwrap(); assert_eq!(result.as_int(), 2); }