feat: rest 参数(function f(...args)),实参区收集数组

This commit is contained in:
爱特每羊队
2026-08-10 00:33:25 +08:00
parent 9b2a56c1fa
commit da586082cc
10 changed files with 184 additions and 8 deletions
+1
View File
@@ -242,6 +242,7 @@ impl Inst {
| OpCode::NEW_OBJECT
| OpCode::NEW_ARRAY
| OpCode::CREATE_ARGUMENTS
| OpCode::CREATE_REST_ARRAY
| OpCode::NOP => {}
// 变量读写:LOAD_VAR/STORE_VAR/CELL_GET 读 a(None→0)
OpCode::LOAD_VAR | OpCode::STORE_VAR | OpCode::CELL_GET => {
+7
View File
@@ -267,6 +267,13 @@ impl Inst {
Self::new(OpCode::CREATE_ARGUMENTS, dst, Operand::None, Operand::None)
}
/// 创建 rest 参数数组:`dst = 当前帧实参区中下标 ≥ fixed_count 的实参组成的数组`。
/// `fixed_count` 为 rest 之前的固定形参数,编码进 b 槽(Imm 单字节),运行时
/// 与 CREATE_ARGUMENTS 同源读实参区,无寄存器 use。
pub fn create_rest_array(dst: Operand, fixed_count: u32) -> Self {
Self::new(OpCode::CREATE_REST_ARRAY, dst, Operand::None, Operand::Imm(fixed_count as u16))
}
/// 生成器让出:`rd` 为被让出的值;恢复时 `next(v)` 的 `v` 经 reg 0 交付
/// (与 CALL 同协议,emit 用 `LOAD_VAR(None)` 读取)。
pub fn yield_value(src: Operand) -> Self {