mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-26 11:41:13 +08:00
docs: 统一中间表示与契约测试注释措辞
This commit is contained in:
@@ -13,16 +13,16 @@ use crate::inst::Inst;
|
|||||||
use crate::operand::Operand;
|
use crate::operand::Operand;
|
||||||
use crate::IRFunction;
|
use crate::IRFunction;
|
||||||
|
|
||||||
/// IRFunction → CompiledModule 等价转换。溢出/标签错误消息为既有格式,逐字保持一致。
|
/// IRFunction → CompiledModule 等价转换。溢出/标签错误消息串是下游解析的契约键,改动须同步更新下游匹配。
|
||||||
pub fn lower(f: &IRFunction) -> Result<CompiledModule, String> {
|
pub fn lower(f: &IRFunction) -> Result<CompiledModule, String> {
|
||||||
crate::ir_debug!("lower: {} insts", f.insts.len());
|
crate::ir_debug!("lower: {} insts", f.insts.len());
|
||||||
// 溢出检查 1:常量池(先于寄存器——超大常量池伴生的海量 vreg 会使后续检查的
|
// 常量池检查(先于寄存器——超大常量池伴生的海量 vreg 会使后续检查的
|
||||||
// 稠密 bitset 表示爆内存;常量池超限是更基础的失效,先报它)
|
// 稠密 bitset 表示爆内存;常量池超限是更基础的失效,先报它)
|
||||||
if f.const_overflow || f.constants.len() > u16::MAX as usize {
|
if f.const_overflow || f.constants.len() > u16::MAX as usize {
|
||||||
return Err("RangeError: too many constants".into());
|
return Err("RangeError: too many constants".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 溢出检查 2:寄存器(仅 Operand::Reg 变体;This/NewTarget 是语义操作数,映射 254/255 合法)
|
// 寄存器检查(仅 Operand::Reg 变体;This/NewTarget 是语义操作数,映射 254/255 合法)
|
||||||
for inst in &f.insts {
|
for inst in &f.insts {
|
||||||
for o in [&inst.rd, &inst.a, &inst.b] {
|
for o in [&inst.rd, &inst.a, &inst.b] {
|
||||||
if let Operand::Reg(r) = o {
|
if let Operand::Reg(r) = o {
|
||||||
@@ -33,7 +33,7 @@ pub fn lower(f: &IRFunction) -> Result<CompiledModule, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 溢出检查 2b:n_registers(u32 → CompiledModule u8 前的显式截断检查)。
|
// n_registers 计数检查(u32 → CompiledModule u8 前的显式截断检查)。
|
||||||
// n_registers = max_regs = 最高分配号 + 1,合法上限 254(reg 0..253)。
|
// n_registers = max_regs = 最高分配号 + 1,合法上限 254(reg 0..253)。
|
||||||
// 纯参数/空体函数可能无指令引用最高号寄存器,逐指令检查漏掉,计数检查兜底防 u8 静默截断。
|
// 纯参数/空体函数可能无指令引用最高号寄存器,逐指令检查漏掉,计数检查兜底防 u8 静默截断。
|
||||||
if f.n_registers > 254 {
|
if f.n_registers > 254 {
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ fn load_var_this_derived_constructor_special_case() {
|
|||||||
assert!(reg_load.is_pure(&derived));
|
assert!(reg_load.is_pure(&derived));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 表驱动解析 vs 老 match 的一致性(Phase B1 迁移校验)──
|
// ── 表驱动解析与逐 opcode 手写 match 分支的一致性回归 ──
|
||||||
|
|
||||||
/// 每个 opcode 构造一条规范指令:rd/a/b 置 Reg(1/2/3),ext 按族填真实布局。
|
/// 每个 opcode 构造一条规范指令:rd/a/b 置 Reg(1/2/3),ext 按族填真实布局。
|
||||||
fn canonical_inst(op: OpCode) -> Inst {
|
fn canonical_inst(op: OpCode) -> Inst {
|
||||||
|
|||||||
Reference in New Issue
Block a user