style: 全 workspace 格式订正,消除 fmt 漂移

This commit is contained in:
2026-10-09 23:58:34 +00:00
parent dbdc5556c6
commit c7f7588b81
23 changed files with 172 additions and 218 deletions
+1 -4
View File
@@ -974,10 +974,7 @@ impl CompileCtx {
) -> IRFunction {
// 编译期不变式:每个 DISPOSE_MARK 都有配对的 DISPOSE_POP,函数体收尾
// 释放作用域全部关闭(早 return 跳过 POP 归穿越面,不在此列)。
debug_assert!(
self.labels.dispose_depth == 0,
"函数体收尾释放作用域深度须归零(mark/pop 未配对)"
);
debug_assert!(self.labels.dispose_depth == 0, "函数体收尾释放作用域深度须归零(mark/pop 未配对)");
let upvalue_captures = self
.current_upvalue_captures
.iter()
+2 -1
View File
@@ -120,7 +120,8 @@ impl Emitter {
// 被捕获参数经 visible_cell 回退命中 CELL_GET,判定后置即漏判。
if ctx.param_tdz_names.contains(name) {
let _ = self.emit_tdz_throw(&format!("Cannot access '{name}' before initialization"), ctx);
} else if let Some((uv_idx, _)) = ctx.current_upvalue_captures.iter().enumerate().find(|(_, u)| u.name == name) {
} else if let Some((uv_idx, _)) = ctx.current_upvalue_captures.iter().enumerate().find(|(_, u)| u.name == name)
{
ctx.inst(Inst::new(
OpCode::LOAD_UPVALUE,
Operand::Reg(result_reg),
+26 -25
View File
@@ -163,8 +163,8 @@ impl Emitter {
/// 编译函数体并显式指定生成器标志(`function*` 走此入口)。
pub(crate) fn compile_generator_body<'a>(
&self, param_specs: &[ParamSpec<'a>], body_stmts: &[Statement<'a>], parent_ctx: &CompileCtx,
own_strict: bool, name: Option<&str>,
&self, param_specs: &[ParamSpec<'a>], body_stmts: &[Statement<'a>], parent_ctx: &CompileCtx, own_strict: bool,
name: Option<&str>,
) -> Result<IRFunction, String> {
self.compile_function_body_with_flags(
param_specs,
@@ -183,11 +183,19 @@ impl Emitter {
/// 同时标记 `is_generator` 与 `is_async`,VM 调用时按异步生成器协议执行
/// (next 返回 Promise,yield 挂起与 await 挂起共存)。
pub(crate) fn compile_async_generator_body<'a>(
&self, param_specs: &[ParamSpec<'a>], body_stmts: &[Statement<'a>], parent_ctx: &CompileCtx,
own_strict: bool, name: Option<&str>,
&self, param_specs: &[ParamSpec<'a>], body_stmts: &[Statement<'a>], parent_ctx: &CompileCtx, own_strict: bool,
name: Option<&str>,
) -> Result<IRFunction, String> {
self.compile_function_body_with_flags(
param_specs, body_stmts, parent_ctx, false, false, true, true, own_strict, name,
param_specs,
body_stmts,
parent_ctx,
false,
false,
true,
true,
own_strict,
name,
)
}
@@ -300,8 +308,7 @@ impl Emitter {
&self, param_specs: &[ParamSpec<'a>], body_stmts: &[Statement<'a>], parent_ctx: &CompileCtx,
is_expression_body: bool, extra_bindings: &[(&str, u32)], body_context: FunctionBodyContext,
mut emit_fields: Option<E>, fields_after_super: bool, extra_capture_exprs: &[&'a Expression<'a>],
extra_upvalue_names: &[(&str, u8)], is_generator: bool, is_async: bool, own_strict: bool,
name: Option<&str>,
extra_upvalue_names: &[(&str, u8)], is_generator: bool, is_async: bool, own_strict: bool, name: Option<&str>,
) -> Result<IRFunction, String>
where
E: FnMut(&Emitter, &mut CompileCtx) -> Result<(), String>,
@@ -708,24 +715,18 @@ impl Emitter {
|| (fn_name == "arguments" && arguments_reg.is_some());
if !suppressed {
let reg = ctx.alloc_reg();
ctx.scopes
.symbols
.scopes
.last_mut()
.expect("函数作用域已压入")
.bindings
.insert(
fn_name.to_string(),
Binding {
reg,
initialized: true,
is_const: false,
lexical: false,
predeclared: false,
cell_idx: None,
non_writable: true,
},
);
ctx.scopes.symbols.scopes.last_mut().expect("函数作用域已压入").bindings.insert(
fn_name.to_string(),
Binding {
reg,
initialized: true,
is_const: false,
lexical: false,
predeclared: false,
cell_idx: None,
non_writable: true,
},
);
ctx.own_bindings.insert(fn_name.to_string());
ctx.function_name = Some(fn_name.to_string());
ctx.function_name_reg = Some(reg);
+7 -7
View File
@@ -24,8 +24,7 @@ use oxide_ir::operand::Operand;
use oxide_ir::{IRFunction, ParamLayout};
use oxide_parser::{
BindingPattern, Declaration, ExportDefaultDeclarationKind, Expression, ImportAttributeKey,
ImportDeclarationSpecifier, ImportPhase, ModuleExportName, Statement, VariableDeclarationKind,
WithClause,
ImportDeclarationSpecifier, ImportPhase, ModuleExportName, Statement, VariableDeclarationKind, WithClause,
};
use oxide_types::MODULE_NAMESPACE_BINDING;
@@ -501,9 +500,11 @@ impl Emitter {
_ => continue,
};
let is_new = !phase_map.contains_key(&spec);
let entry = phase_map
.entry(spec.clone())
.or_insert_with(|| DepPhase { eager: false, defer: false, attrs });
let entry = phase_map.entry(spec.clone()).or_insert_with(|| DepPhase {
eager: false,
defer: false,
attrs,
});
if is_new {
defer_order.push(spec.clone());
}
@@ -772,8 +773,7 @@ impl Emitter {
);
}
let bind_reg = if is_defer {
*ctx
.module_defer_ns_regs
*ctx.module_defer_ns_regs
.get(&dep_spec)
.ok_or_else(|| format!("module dependency missing: {dep_spec}"))?
} else {
@@ -87,33 +87,34 @@ impl Emitter {
pub(crate) fn emit_continue_statement(
&self, stmt: &oxide_parser::ContinueStatement, ctx: &mut CompileCtx,
) -> Result<Option<u32>, String> {
let (continue_label, fd_at_open, fod_at_open, fid_at_open, dd_at_open, target_v_reg) =
if let Some(label) = &stmt.label {
let name = label.name.as_str();
let scope = ctx
.find_label(name)
.ok_or_else(|| format!("SyntaxError: Undefined label '{name}'"))?;
(
scope.continue_label.ok_or_else(|| {
format!("SyntaxError: Illegal continue statement: '{name}' does not denote an iteration statement")
})?,
scope.finally_depth_at_open,
scope.for_of_depth_at_open,
scope.for_in_depth_at_open,
scope.dispose_depth_at_open,
scope.completion_reg,
)
} else {
let entry = ctx.current_loop().ok_or("continue outside loop".to_string())?;
(
entry.continue_label,
entry.finally_depth_at_open,
entry.for_of_depth_at_open,
entry.for_in_depth_at_open,
entry.dispose_depth_at_open,
Some(entry.v_reg),
)
};
let (continue_label, fd_at_open, fod_at_open, fid_at_open, dd_at_open, target_v_reg) = if let Some(label) =
&stmt.label
{
let name = label.name.as_str();
let scope = ctx
.find_label(name)
.ok_or_else(|| format!("SyntaxError: Undefined label '{name}'"))?;
(
scope.continue_label.ok_or_else(|| {
format!("SyntaxError: Illegal continue statement: '{name}' does not denote an iteration statement")
})?,
scope.finally_depth_at_open,
scope.for_of_depth_at_open,
scope.for_in_depth_at_open,
scope.dispose_depth_at_open,
scope.completion_reg,
)
} else {
let entry = ctx.current_loop().ok_or("continue outside loop".to_string())?;
(
entry.continue_label,
entry.finally_depth_at_open,
entry.for_of_depth_at_open,
entry.for_in_depth_at_open,
entry.dispose_depth_at_open,
Some(entry.v_reg),
)
};
if let Some(target_v_reg) = target_v_reg {
self.emit_completion_carry(ctx, target_v_reg);
}
@@ -6,8 +6,7 @@ use oxide_bytecode::opcode::OpCode;
use oxide_ir::inst::Inst;
use oxide_ir::operand::Operand;
use oxide_parser::{
BindingPattern, ForStatementInit, ForStatementLeft, Statement, VariableDeclaration,
VariableDeclarationKind,
BindingPattern, ForStatementInit, ForStatementLeft, Statement, VariableDeclaration, VariableDeclarationKind,
};
impl Emitter {
@@ -137,9 +136,7 @@ impl Emitter {
/// using/await using 声明登记释放栈:把资源值(val_reg)压入释放栈。非
/// using/await using 声明不登记。a 槽为释放提示(0 = 同步、1 = 异步)。
pub(crate) fn emit_dispose_register(
&self, val_reg: u32, kind: VariableDeclarationKind, ctx: &mut CompileCtx,
) {
pub(crate) fn emit_dispose_register(&self, val_reg: u32, kind: VariableDeclarationKind, ctx: &mut CompileCtx) {
if !matches!(kind, VariableDeclarationKind::Using | VariableDeclarationKind::AwaitUsing) {
return;
}