From 6cb7964764316b52cdc428e63ec4632ada430ba7 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Mon, 5 Oct 2026 17:05:08 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8D=95=E8=8E=B7=20cell=20=E6=8D=A2?= =?UTF-8?q?=E9=94=AE=E2=80=94=E2=80=94=E7=B1=BB=E5=90=88=E6=88=90=20cell?= =?UTF-8?q?=20=E5=88=87=E8=AE=A1=E6=95=B0=E5=99=A8=E5=88=86=E9=85=8D?= =?UTF-8?q?=EF=BC=8C=E7=B1=BB=E5=90=8D=E4=B8=8E=E5=87=BD=E6=95=B0=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E6=94=B9=E5=8F=AF=E8=A7=81=E7=BB=91=E5=AE=9A=E7=B4=A2?= =?UTF-8?q?=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 36 +++++++++---------- Cargo.toml | 2 +- crates/oxide_emit/src/class/emit.rs | 17 ++++----- .../src/stmt/declaration/function_decl.rs | 2 +- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7070048f..e917358a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1095,7 +1095,7 @@ dependencies = [ [[package]] name = "oxide_builtins" -version = "0.8.9" +version = "0.8.10" dependencies = [ "chrono", "fast-float", @@ -1120,7 +1120,7 @@ dependencies = [ [[package]] name = "oxide_bytecode" -version = "0.8.9" +version = "0.8.10" dependencies = [ "num-bigint", "oxide_log", @@ -1128,7 +1128,7 @@ dependencies = [ [[package]] name = "oxide_cfg" -version = "0.8.9" +version = "0.8.10" dependencies = [ "oxide_bytecode", "oxide_emit", @@ -1139,7 +1139,7 @@ dependencies = [ [[package]] name = "oxide_cli" -version = "0.8.9" +version = "0.8.10" dependencies = [ "ansi_term", "bumpalo", @@ -1159,7 +1159,7 @@ dependencies = [ [[package]] name = "oxide_code_cache" -version = "0.8.9" +version = "0.8.10" dependencies = [ "lru", "oxide_bytecode", @@ -1168,7 +1168,7 @@ dependencies = [ [[package]] name = "oxide_compiler" -version = "0.8.9" +version = "0.8.10" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1187,7 +1187,7 @@ dependencies = [ [[package]] name = "oxide_dce" -version = "0.8.9" +version = "0.8.10" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1201,7 +1201,7 @@ dependencies = [ [[package]] name = "oxide_emit" -version = "0.8.9" +version = "0.8.10" dependencies = [ "num-bigint", "oxc_allocator", @@ -1216,7 +1216,7 @@ dependencies = [ [[package]] name = "oxide_ir" -version = "0.8.9" +version = "0.8.10" dependencies = [ "oxide_bytecode", "oxide_log", @@ -1225,7 +1225,7 @@ dependencies = [ [[package]] name = "oxide_kernel" -version = "0.8.9" +version = "0.8.10" dependencies = [ "bumpalo", "dashmap", @@ -1240,7 +1240,7 @@ dependencies = [ [[package]] name = "oxide_liveness" -version = "0.8.9" +version = "0.8.10" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1252,7 +1252,7 @@ dependencies = [ [[package]] name = "oxide_log" -version = "0.8.9" +version = "0.8.10" dependencies = [ "tracing", "tracing-appender", @@ -1261,7 +1261,7 @@ dependencies = [ [[package]] name = "oxide_parser" -version = "0.8.9" +version = "0.8.10" dependencies = [ "oxc_allocator", "oxc_ast", @@ -1276,7 +1276,7 @@ dependencies = [ [[package]] name = "oxide_regalloc" -version = "0.8.9" +version = "0.8.10" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1292,7 +1292,7 @@ dependencies = [ [[package]] name = "oxide_runtime_api" -version = "0.8.9" +version = "0.8.10" dependencies = [ "num-bigint", "num-traits", @@ -1304,7 +1304,7 @@ dependencies = [ [[package]] name = "oxide_test262" -version = "0.8.9" +version = "0.8.10" dependencies = [ "oxide_bytecode", "oxide_compiler", @@ -1321,7 +1321,7 @@ dependencies = [ [[package]] name = "oxide_types" -version = "0.8.9" +version = "0.8.10" dependencies = [ "bumpalo", "hashbrown 0.14.5", @@ -1333,7 +1333,7 @@ dependencies = [ [[package]] name = "oxide_vm" -version = "0.8.9" +version = "0.8.10" dependencies = [ "bumpalo", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 5ffc69c8..d9e72cc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ members = [ ] [workspace.package] -version = "0.8.9" +version = "0.8.10" edition = "2021" license = "MIT" rust-version = "1.80" diff --git a/crates/oxide_emit/src/class/emit.rs b/crates/oxide_emit/src/class/emit.rs index 62019865..bf3cbc3d 100644 --- a/crates/oxide_emit/src/class/emit.rs +++ b/crates/oxide_emit/src/class/emit.rs @@ -138,7 +138,7 @@ impl Emitter { // (会改写 cell 值)与内联 accessor 调用(会清空寄存器文件)之后仍保持 identity // 一致;合成键 @@class_self_N 不影响外层作用域的同名用户绑定。 let class_self_cell: Option = ctor_name.as_deref().map(|_| { - let cell_idx = ctx.captured_bindings.values().copied().max().map_or(0, |m| m.saturating_add(1)); + let cell_idx = ctx.alloc_cell_idx(); ctx.captured_bindings.insert(format!("@@class_self_{cell_idx}"), cell_idx); cell_idx }); @@ -167,13 +167,14 @@ impl Emitter { ctx.scopes.private_brand_id = private_brand_id; // 实例公有字段 computed key 求值于构造器帧外,须类定义期存入数组。构造器以 - // upvalue 捕获该数组:父作用域登记 `@@field_keys`(cell_idx 取现有最大 +1)。 + // upvalue 捕获该数组:父作用域登记 `@@field_keys`(索引经共享计数器追加, + // 与块级遮蔽绑定的追加索引不碰撞)。 let has_computed_instance = instance_field_indices.iter().any(|&i| { let ClassElement::PropertyDefinition(p) = &elements[i] else { return false }; p.computed && !matches!(p.key, PropertyKey::PrivateIdentifier(_)) }); let field_key_cell: Option = if has_computed_instance { - let cell_idx = ctx.captured_bindings.values().copied().max().map_or(0, |m| m.saturating_add(1)); + let cell_idx = ctx.alloc_cell_idx(); ctx.captured_bindings.insert("@@field_keys".to_string(), cell_idx); Some(cell_idx) } else { @@ -181,7 +182,7 @@ impl Emitter { }; // 类 brand 对象(= proto)由类定义期 MAKE_CELL 写入,构造器经 upvalue 捕获。 let brand_cell: Option = private_brand_id.map(|_| { - let cell_idx = ctx.captured_bindings.values().copied().max().map_or(0, |m| m.saturating_add(1)); + let cell_idx = ctx.alloc_cell_idx(); ctx.captured_bindings.insert("@@class_brand".to_string(), cell_idx); cell_idx }); @@ -419,11 +420,11 @@ impl Emitter { } // 类名被外层嵌套函数捕获时,真实名 cell 同样须初始化(类元素自引用走 // @@class_self_* 合成 cell,二者 cell_idx 不同则各发一次)。 - // 仅类声明:类名是本作用域绑定,captured_bindings 按名命中的才是 - // 它的 cell;类表达式名是类体内独立 const 绑定,按名查询只会命中 - // 外层同名绑定 cell,MAKE_CELL 会把类值误写进外层绑定。 + // 仅类声明:类名是本作用域绑定,可见绑定解析到的是它的 cell;类表达式 + // 名是类体内独立 const 绑定,按名解析只会命中外层同名绑定 cell, + // MAKE_CELL 会把类值误写进外层绑定。 if is_class_decl { - if let Some(&cell_idx) = ctx.captured_bindings.get(name) { + if let Some((cell_idx, _)) = ctx.visible_cell(name) { ctx.inst(Inst::new( OpCode::MAKE_CELL, Operand::Reg(binding_reg), diff --git a/crates/oxide_emit/src/stmt/declaration/function_decl.rs b/crates/oxide_emit/src/stmt/declaration/function_decl.rs index 006031db..beb94783 100644 --- a/crates/oxide_emit/src/stmt/declaration/function_decl.rs +++ b/crates/oxide_emit/src/stmt/declaration/function_decl.rs @@ -164,7 +164,7 @@ impl Emitter { ctx.nested.push(sub_module); ctx.inst(Inst::create_closure(Operand::Reg(reg), ctx.nested.len() as u16)); if write_slot { - if let Some(&cell_idx) = ctx.captured_bindings.get(name) { + if let Some((cell_idx, _)) = ctx.visible_cell(name) { ctx.inst(Inst::new( OpCode::MAKE_CELL, Operand::Reg(reg),