chore: 全仓 rustfmt 格式化归拢
This commit is contained in:
@@ -25,7 +25,14 @@ impl Emitter {
|
||||
}
|
||||
if matches!(method.key, PropertyKey::PrivateIdentifier(_)) {
|
||||
let home_reg = if method.r#static { ctor_reg } else { proto_reg };
|
||||
self.emit_private_method_init(Operand::Reg(home_reg), method, Operand::Reg(home_reg), self_binding, class_self_cell, ctx)?;
|
||||
self.emit_private_method_init(
|
||||
Operand::Reg(home_reg),
|
||||
method,
|
||||
Operand::Reg(home_reg),
|
||||
self_binding,
|
||||
class_self_cell,
|
||||
ctx,
|
||||
)?;
|
||||
continue;
|
||||
}
|
||||
let home_reg = if method.r#static { ctor_reg } else { proto_reg };
|
||||
@@ -39,8 +46,14 @@ impl Emitter {
|
||||
} else {
|
||||
self.class_property_name(&method.key)?
|
||||
};
|
||||
let accessor_reg =
|
||||
self.emit_class_method_function(method, &method_name, Operand::Reg(home_reg), ctx, self_binding, class_self_cell)?;
|
||||
let accessor_reg = self.emit_class_method_function(
|
||||
method,
|
||||
&method_name,
|
||||
Operand::Reg(home_reg),
|
||||
ctx,
|
||||
self_binding,
|
||||
class_self_cell,
|
||||
)?;
|
||||
match method.kind {
|
||||
MethodDefinitionKind::Method => {
|
||||
// class 方法按规范为非枚举数据属性(DefineMethod:writable/configurable,enumerable=false)。
|
||||
|
||||
@@ -410,8 +410,7 @@ impl Emitter {
|
||||
}
|
||||
}
|
||||
oxide_parser::Declaration::FunctionDeclaration(fd) => {
|
||||
let body: &[Statement] =
|
||||
fd.body.as_ref().map(|b| &b.statements[..]).unwrap_or(&[]);
|
||||
let body: &[Statement] = fd.body.as_ref().map(|b| &b.statements[..]).unwrap_or(&[]);
|
||||
let mut inner = shadow.clone();
|
||||
inner.extend(self.collect_fn_param_names(&fd.params));
|
||||
inner.extend(self.collect_own_binding_names(&[], body));
|
||||
|
||||
@@ -7,9 +7,7 @@ use oxide_ir::operand::Operand;
|
||||
use oxide_parser::AwaitExpression;
|
||||
|
||||
impl Emitter {
|
||||
pub(crate) fn emit_await_expression(
|
||||
&self, ae: &AwaitExpression, ctx: &mut CompileCtx,
|
||||
) -> Result<u32, String> {
|
||||
pub(crate) fn emit_await_expression(&self, ae: &AwaitExpression, ctx: &mut CompileCtx) -> Result<u32, String> {
|
||||
// 求值被等待的值(`await undefined` 时求值 undefined)。
|
||||
let value_reg = self.emit_expression(&ae.argument, ctx)?;
|
||||
ctx.inst(Inst::await_expr(Operand::Reg(value_reg)));
|
||||
|
||||
@@ -55,7 +55,9 @@ impl Emitter {
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
pub(crate) fn emit_function_expression(&self, fe: &oxide_parser::Function, ctx: &mut CompileCtx) -> Result<u32, String> {
|
||||
pub(crate) fn emit_function_expression(
|
||||
&self, fe: &oxide_parser::Function, ctx: &mut CompileCtx,
|
||||
) -> Result<u32, String> {
|
||||
// 函数表达式:编译函数体为子模块,create_closure 实例化闭包
|
||||
let mut param_names = Vec::new();
|
||||
for (idx, param) in fe.params.items.iter().enumerate() {
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
pub mod class;
|
||||
pub mod closure;
|
||||
pub mod module;
|
||||
pub mod emit;
|
||||
mod emit_log;
|
||||
pub mod emit_ctx;
|
||||
mod emit_log;
|
||||
pub mod expr;
|
||||
pub mod module;
|
||||
pub mod prepass;
|
||||
pub mod shared;
|
||||
pub mod stmt;
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
//! 支持提升语义。
|
||||
|
||||
use crate::{CompileCtx, Emitter};
|
||||
use oxide_parser::{BindingPattern, Declaration, ExportDefaultDeclarationKind, Expression, Statement, VariableDeclarationKind};
|
||||
use oxide_parser::{
|
||||
BindingPattern, Declaration, ExportDefaultDeclarationKind, Expression, Statement, VariableDeclarationKind,
|
||||
};
|
||||
|
||||
impl Emitter {
|
||||
/// 在临时寄存器池之前分配 builtin 槽位。
|
||||
@@ -390,12 +392,8 @@ impl Emitter {
|
||||
for d in &decl.declarations {
|
||||
if let oxide_parser::BindingPattern::BindingIdentifier(bi) = &d.id {
|
||||
let reg = ctx.alloc_reg();
|
||||
let _ = ctx.declare_initialized(
|
||||
bi.name.as_str(),
|
||||
reg,
|
||||
VariableDeclarationKind::Var,
|
||||
false,
|
||||
);
|
||||
let _ =
|
||||
ctx.declare_initialized(bi.name.as_str(), reg, VariableDeclarationKind::Var, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -547,33 +545,23 @@ impl Emitter {
|
||||
}
|
||||
}
|
||||
}
|
||||
Statement::ExportDefaultDeclaration(exp) => {
|
||||
match &exp.declaration {
|
||||
ExportDefaultDeclarationKind::ClassDeclaration(cd) => {
|
||||
if let Some(id) = &cd.id {
|
||||
let reg = ctx.alloc_reg();
|
||||
let _ = ctx.declare_predeclared(
|
||||
id.name.as_str(),
|
||||
reg,
|
||||
VariableDeclarationKind::Const,
|
||||
true,
|
||||
);
|
||||
}
|
||||
Statement::ExportDefaultDeclaration(exp) => match &exp.declaration {
|
||||
ExportDefaultDeclarationKind::ClassDeclaration(cd) => {
|
||||
if let Some(id) = &cd.id {
|
||||
let reg = ctx.alloc_reg();
|
||||
let _ =
|
||||
ctx.declare_predeclared(id.name.as_str(), reg, VariableDeclarationKind::Const, true);
|
||||
}
|
||||
ExportDefaultDeclarationKind::FunctionDeclaration(fd) => {
|
||||
if let Some(id) = &fd.id {
|
||||
let reg = ctx.alloc_reg();
|
||||
let _ = ctx.declare_predeclared(
|
||||
id.name.as_str(),
|
||||
reg,
|
||||
VariableDeclarationKind::Const,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
ExportDefaultDeclarationKind::FunctionDeclaration(fd) => {
|
||||
if let Some(id) = &fd.id {
|
||||
let reg = ctx.alloc_reg();
|
||||
let _ =
|
||||
ctx.declare_predeclared(id.name.as_str(), reg, VariableDeclarationKind::Const, true);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,12 +76,7 @@ impl Emitter {
|
||||
};
|
||||
if let Some(&cell_idx) = ctx.captured_bindings.get(name) {
|
||||
let op = if fresh_cell { OpCode::MAKE_CELL_FRESH } else { OpCode::MAKE_CELL };
|
||||
ctx.inst(Inst::new(
|
||||
op,
|
||||
Operand::Reg(src_reg),
|
||||
Operand::Imm(cell_idx as u16),
|
||||
Operand::None,
|
||||
));
|
||||
ctx.inst(Inst::new(op, Operand::Reg(src_reg), Operand::Imm(cell_idx as u16), Operand::None));
|
||||
} else if !ctx.with_stack.is_empty() && !ctx.is_with_internal_binding(name) {
|
||||
// with 内 var 初始化:对象有该属性则写对象,否则写提升槽(动态解析)。
|
||||
// ponytail: with 内顶层 var 不写全局对象属性,with 语句本身已是稀见用例。
|
||||
@@ -131,8 +126,8 @@ impl Emitter {
|
||||
}
|
||||
|
||||
pub(crate) fn emit_binding_pattern(
|
||||
&self, pattern: &BindingPattern, src_reg: u32, kind: VariableDeclarationKind, is_const: bool,
|
||||
fresh_cell: bool, ctx: &mut CompileCtx,
|
||||
&self, pattern: &BindingPattern, src_reg: u32, kind: VariableDeclarationKind, is_const: bool, fresh_cell: bool,
|
||||
ctx: &mut CompileCtx,
|
||||
) -> Result<(), String> {
|
||||
match pattern {
|
||||
BindingPattern::BindingIdentifier(bi) => {
|
||||
|
||||
@@ -56,14 +56,13 @@ impl Emitter {
|
||||
} else {
|
||||
// let/const 无初始化器:复用本块预声明槽位,否则新声明
|
||||
// (for 头等未预声明路径)。
|
||||
let var_reg =
|
||||
if let Some(reg) = ctx.scopes.symbols.consume_predeclared_slot(bi.name.as_str()) {
|
||||
reg
|
||||
} else {
|
||||
let r = ctx.alloc_reg();
|
||||
ctx.declare(bi.name.as_str(), r, decl.kind, is_const)?;
|
||||
r
|
||||
};
|
||||
let var_reg = if let Some(reg) = ctx.scopes.symbols.consume_predeclared_slot(bi.name.as_str()) {
|
||||
reg
|
||||
} else {
|
||||
let r = ctx.alloc_reg();
|
||||
ctx.declare(bi.name.as_str(), r, decl.kind, is_const)?;
|
||||
r
|
||||
};
|
||||
var_reg
|
||||
};
|
||||
if let Some(&cell_idx) = ctx.captured_bindings.get(bi.name.as_str()) {
|
||||
|
||||
Reference in New Issue
Block a user