mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-27 20:21:12 +08:00
refactor: 寄存器号 u8→u32 全链放宽,vreg 化去 checkpoint/reg_overflow
This commit is contained in:
@@ -10,19 +10,22 @@ impl Emitter {
|
||||
/// this.y = 1 } static z = this.y + 1` must run in that order). Emitting
|
||||
/// all fields before all blocks would make `z` read `y` before it is set.
|
||||
pub(crate) fn emit_class_static_elements(
|
||||
&self, elements: &[ClassElement], ctor_reg: u8, ctx: &mut CompileCtx,
|
||||
&self, elements: &[ClassElement], ctor_reg: u32, ctx: &mut CompileCtx,
|
||||
) -> Result<(), String> {
|
||||
let saved_static_this = ctx.static_block_this_reg;
|
||||
ctx.static_block_this_reg = Some(ctor_reg);
|
||||
// static_block_this_reg 保留 u8(this 槽语义,254 特判),ctor_reg 超 u8 界时报错而非静默截断。
|
||||
ctx.static_block_this_reg = Some(
|
||||
u8::try_from(ctor_reg).map_err(|_| format!("class constructor register {ctor_reg} exceeds u8 limit"))?,
|
||||
);
|
||||
for element in elements {
|
||||
match element {
|
||||
ClassElement::PropertyDefinition(prop) => {
|
||||
let prop = prop.as_ref();
|
||||
if prop.r#static {
|
||||
if let PropertyKey::PrivateIdentifier(private) = &prop.key {
|
||||
self.emit_private_field_init(Operand::Reg(ctor_reg as u32), private.name.as_str(), prop.value.as_ref(), ctx)?;
|
||||
self.emit_private_field_init(Operand::Reg(ctor_reg), private.name.as_str(), prop.value.as_ref(), ctx)?;
|
||||
} else {
|
||||
self.emit_public_field_init(Operand::Reg(ctor_reg as u32), &prop.key, prop.computed, prop.value.as_ref(), ctx)?;
|
||||
self.emit_public_field_init(Operand::Reg(ctor_reg), &prop.key, prop.computed, prop.value.as_ref(), ctx)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user