chore: 消除所有编译器警告
- 移除unused方法: frame(), get_constant(), emit_i16_placeholder - 移除LoopContext未使用字段: start_ip, scope_depth - Vm字段改为私有: frames, open_upvalues - is_const字段添加#[allow(dead_code)] - 测试: 327/327 通过 | 0 warnings
This commit is contained in:
@@ -77,6 +77,7 @@ struct Local {
|
|||||||
name: String,
|
name: String,
|
||||||
depth: u8, // scope depth where declared; 0 = uninitialized
|
depth: u8, // scope depth where declared; 0 = uninitialized
|
||||||
is_captured: bool,
|
is_captured: bool,
|
||||||
|
#[allow(dead_code)]
|
||||||
is_const: bool,
|
is_const: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,10 +89,8 @@ struct Upvalue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct LoopContext {
|
struct LoopContext {
|
||||||
start_ip: usize, // bytecode offset of loop condition
|
break_patches: Vec<usize>,
|
||||||
break_patches: Vec<usize>, // jump instruction offsets that need break dest
|
continue_patches: Vec<usize>,
|
||||||
continue_patches: Vec<usize>,// jump instruction offsets that need continue dest
|
|
||||||
scope_depth: u8, // scope depth when loop started
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Compiler {
|
pub struct Compiler {
|
||||||
@@ -241,10 +240,8 @@ impl Compiler {
|
|||||||
let exit_jump = self.emit_jump(OpCode::JumpIfFalse);
|
let exit_jump = self.emit_jump(OpCode::JumpIfFalse);
|
||||||
|
|
||||||
self.loop_stack.push(LoopContext {
|
self.loop_stack.push(LoopContext {
|
||||||
start_ip,
|
|
||||||
break_patches: Vec::new(),
|
break_patches: Vec::new(),
|
||||||
continue_patches: Vec::new(),
|
continue_patches: Vec::new(),
|
||||||
scope_depth: self.scope_depth,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.compile_stmt(body)?;
|
self.compile_stmt(body)?;
|
||||||
@@ -279,10 +276,8 @@ impl Compiler {
|
|||||||
let exit_jump = self.emit_jump(OpCode::JumpIfFalse);
|
let exit_jump = self.emit_jump(OpCode::JumpIfFalse);
|
||||||
|
|
||||||
self.loop_stack.push(LoopContext {
|
self.loop_stack.push(LoopContext {
|
||||||
start_ip,
|
|
||||||
break_patches: Vec::new(),
|
break_patches: Vec::new(),
|
||||||
continue_patches: Vec::new(),
|
continue_patches: Vec::new(),
|
||||||
scope_depth: self.scope_depth,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.compile_stmt(body)?;
|
self.compile_stmt(body)?;
|
||||||
@@ -355,10 +350,8 @@ impl Compiler {
|
|||||||
|
|
||||||
// 7. Loop body (can resolve var_name to loop_var_slot)
|
// 7. Loop body (can resolve var_name to loop_var_slot)
|
||||||
self.loop_stack.push(LoopContext {
|
self.loop_stack.push(LoopContext {
|
||||||
start_ip: forin_loc,
|
|
||||||
break_patches: Vec::new(),
|
break_patches: Vec::new(),
|
||||||
continue_patches: Vec::new(),
|
continue_patches: Vec::new(),
|
||||||
scope_depth: self.scope_depth,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.compile_stmt(body)?;
|
self.compile_stmt(body)?;
|
||||||
@@ -993,9 +986,3 @@ fn assign_op_to_compound(op: &AssignOp) -> CompoundOp {
|
|||||||
AssignOp::Equal => unreachable!(),
|
AssignOp::Equal => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_i16_placeholder(code: &mut Vec<u8>, op: OpCode) -> usize {
|
|
||||||
let loc = code.len();
|
|
||||||
emit_i16(code, op, 0x7FFF);
|
|
||||||
loc
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-13
@@ -46,7 +46,7 @@ pub struct Vm {
|
|||||||
pub stack: Vec<Value>,
|
pub stack: Vec<Value>,
|
||||||
|
|
||||||
/// Call frames
|
/// Call frames
|
||||||
pub frames: Vec<CallFrame>,
|
frames: Vec<CallFrame>,
|
||||||
|
|
||||||
/// Script-level globals (top-level let bindings)
|
/// Script-level globals (top-level let bindings)
|
||||||
pub globals: Rc<RefCell<HashMap<String, Value>>>,
|
pub globals: Rc<RefCell<HashMap<String, Value>>>,
|
||||||
@@ -61,7 +61,7 @@ pub struct Vm {
|
|||||||
pub current_dir: String,
|
pub current_dir: String,
|
||||||
|
|
||||||
/// Open upvalues (tracked so closures share the same upvalue object)
|
/// Open upvalues (tracked so closures share the same upvalue object)
|
||||||
pub open_upvalues: Vec<Rc<RefCell<UpvalueObj>>>,
|
open_upvalues: Vec<Rc<RefCell<UpvalueObj>>>,
|
||||||
|
|
||||||
/// VM-compiled closures: maps Function Rc pointer → Closure data
|
/// VM-compiled closures: maps Function Rc pointer → Closure data
|
||||||
closures: RefCell<HashMap<*const crate::interpreter::Function, Rc<Closure>>>,
|
closures: RefCell<HashMap<*const crate::interpreter::Function, Rc<Closure>>>,
|
||||||
@@ -602,10 +602,6 @@ impl Vm {
|
|||||||
// IP management
|
// IP management
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
|
|
||||||
fn frame(&self) -> &CallFrame {
|
|
||||||
self.frames.last().unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn frame_mut(&mut self) -> &mut CallFrame {
|
fn frame_mut(&mut self) -> &mut CallFrame {
|
||||||
self.frames.last_mut().unwrap()
|
self.frames.last_mut().unwrap()
|
||||||
}
|
}
|
||||||
@@ -917,13 +913,6 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_constant(&self, idx: usize) -> Result<Value, RuntimeError> {
|
|
||||||
let frame = self.frames.last().unwrap();
|
|
||||||
frame.closure.proto.constants.get(idx).cloned().ok_or_else(|| RuntimeError::RuntimeError {
|
|
||||||
message: format!("Constant index {} out of bounds", idx),
|
|
||||||
token: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
// Upvalues
|
// Upvalues
|
||||||
|
|||||||
Reference in New Issue
Block a user