mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 03:01:12 +08:00
feat: 逐指令 trace 补 pc 并加 eval/run --trace 旗标
This commit is contained in:
@@ -202,12 +202,19 @@ impl Vm {
|
||||
return Err("program counter out of bounds".into());
|
||||
}
|
||||
|
||||
let instr = self.bytecode[self.pc];
|
||||
let pc = self.pc;
|
||||
let instr = self.bytecode[pc];
|
||||
let op = opcode::opcode(instr);
|
||||
let rd = opcode::rd(instr) as usize;
|
||||
let a = opcode::a(instr) as usize;
|
||||
let b = opcode::b(instr) as usize;
|
||||
self.pc += 1;
|
||||
self.pc = pc + 1;
|
||||
|
||||
// 逐指令 trace:运行时开关短路(默认关闭,零输出零分配);
|
||||
// pc 为字节码 word 序号,与反汇编 offset 列同单位。
|
||||
if self.trace_instructions {
|
||||
eprintln!("pc={pc:4} {op:>16} rd={rd} a={a} b={b}");
|
||||
}
|
||||
|
||||
match op {
|
||||
OpCode::NOP => {}
|
||||
|
||||
@@ -350,6 +350,10 @@ pub struct Vm {
|
||||
pub(crate) saved_flat_id_stack: Vec<u32>,
|
||||
/// 帧切换时暂存调用方表代际的栈(与 saved_flat_id_stack 同步 push/pop)。
|
||||
pub(crate) saved_table_gen_stack: Vec<u32>,
|
||||
/// 逐指令 trace 开关:开启时 dispatch 主循环对每条指令向 stderr 写一行
|
||||
/// `pc + opcode + 操作数`。运行时开关,旁路 tracing 级别上限(release
|
||||
/// 构建可用);默认关闭,关闭时热路径仅一次 bool 比较,零输出零分配。
|
||||
pub trace_instructions: bool,
|
||||
}
|
||||
|
||||
impl Drop for Vm {
|
||||
@@ -413,6 +417,12 @@ impl Vm {
|
||||
self.regs[idx as usize] = val;
|
||||
}
|
||||
|
||||
/// 设置逐指令 trace 开关(开启后 dispatch 主循环逐指令向 stderr 写
|
||||
/// `pc + opcode + 操作数` 行,pc 为字节码 word 序号,与反汇编 offset 同单位)。
|
||||
pub fn set_instruction_trace(&mut self, on: bool) {
|
||||
self.trace_instructions = on;
|
||||
}
|
||||
|
||||
/// 只读访问 VM 的 epoch arena。
|
||||
pub fn epoch(&self) -> &Epoch {
|
||||
&self.epoch
|
||||
|
||||
@@ -157,6 +157,7 @@ impl Vm {
|
||||
active_table_gen: 0,
|
||||
saved_flat_id_stack: Vec::new(),
|
||||
saved_table_gen_stack: Vec::new(),
|
||||
trace_instructions: false,
|
||||
};
|
||||
vm.init_generator_intrinsics();
|
||||
vm.init_promise_intrinsics();
|
||||
@@ -291,6 +292,7 @@ impl Vm {
|
||||
active_table_gen: 0,
|
||||
saved_flat_id_stack: Vec::new(),
|
||||
saved_table_gen_stack: Vec::new(),
|
||||
trace_instructions: false,
|
||||
};
|
||||
vm.init_generator_intrinsics();
|
||||
vm.init_promise_intrinsics();
|
||||
|
||||
Reference in New Issue
Block a user