mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
fix: display opcode 3.7/3.9
This commit is contained in:
parent
dc86be1125
commit
3a01d71fe8
3 changed files with 52 additions and 11 deletions
|
@ -52,7 +52,7 @@ pub enum CommonOpcode {
|
|||
COMPARE_OP = 107,
|
||||
IMPORT_NAME = 108,
|
||||
IMPORT_FROM = 109,
|
||||
JUMP_FORWARD = 110,
|
||||
// JUMP_FORWARD = 110,
|
||||
JUMP_IF_FALSE_OR_POP = 111,
|
||||
JUMP_IF_TRUE_OR_POP = 112,
|
||||
// JUMP_ABSOLUTE = 113,
|
||||
|
@ -117,7 +117,7 @@ impl TryFrom<u8> for CommonOpcode {
|
|||
107 => COMPARE_OP,
|
||||
108 => IMPORT_NAME,
|
||||
109 => IMPORT_FROM,
|
||||
110 => JUMP_FORWARD,
|
||||
// 110 => JUMP_FORWARD,
|
||||
111 => JUMP_IF_FALSE_OR_POP,
|
||||
112 => JUMP_IF_TRUE_OR_POP,
|
||||
// 113 => JUMP_ABSOLUTE,
|
||||
|
|
|
@ -1780,7 +1780,7 @@ impl PyCodeGenerator {
|
|||
let idx_jump_forward = self.lasti();
|
||||
self.write_instr(EXTENDED_ARG);
|
||||
self.write_arg(0);
|
||||
self.write_instr(JUMP_FORWARD); // jump to end
|
||||
self.write_instr(Opcode308::JUMP_FORWARD); // jump to end
|
||||
self.write_arg(0);
|
||||
// else block
|
||||
let idx_else_begin = if self.py_version.minor >= Some(11) {
|
||||
|
@ -1805,7 +1805,7 @@ impl PyCodeGenerator {
|
|||
self.stack_dec();
|
||||
}
|
||||
} else {
|
||||
self.write_instr(JUMP_FORWARD);
|
||||
self.write_instr(Opcode308::JUMP_FORWARD);
|
||||
self.write_arg(1);
|
||||
// no else block
|
||||
let idx_end = if self.py_version.minor >= Some(11) {
|
||||
|
@ -1963,7 +1963,7 @@ impl PyCodeGenerator {
|
|||
jump_forward_points.push(self.lasti());
|
||||
self.write_instr(EXTENDED_ARG);
|
||||
self.write_arg(0);
|
||||
self.write_instr(JUMP_FORWARD); // jump to the end
|
||||
self.write_instr(Opcode308::JUMP_FORWARD); // jump to the end
|
||||
self.write_arg(0);
|
||||
}
|
||||
}
|
||||
|
@ -2128,7 +2128,7 @@ impl PyCodeGenerator {
|
|||
self.stack_dec_n((1 + 3) - 1);
|
||||
self.emit_pop_top();
|
||||
let idx_jump_forward = self.lasti();
|
||||
self.write_instr(JUMP_FORWARD);
|
||||
self.write_instr(Opcode310::JUMP_FORWARD);
|
||||
self.write_arg(0);
|
||||
self.edit_code(idx_setup_with + 1, (self.lasti() - idx_setup_with - 2) / 2);
|
||||
self.write_instr(Opcode310::WITH_EXCEPT_START);
|
||||
|
|
|
@ -541,9 +541,10 @@ impl CodeObj {
|
|||
arg
|
||||
};
|
||||
match py_ver.and_then(|pv| pv.minor) {
|
||||
Some(7) => self.read_instr_307(op, arg, idx, &mut instrs),
|
||||
Some(8) => self.read_instr_308(op, arg, idx, &mut instrs),
|
||||
// Some(9) => self.read_instr_3_9(op, arg, idx, &mut instrs),
|
||||
Some(10) => self.read_instr_310(op, arg, idx, &mut instrs),
|
||||
// Some(9) => self.read_instr_309(op, arg, idx, &mut instrs),
|
||||
Some(9 | 10) => self.read_instr_310(op, arg, idx, &mut instrs),
|
||||
Some(11) => self.read_instr_311(op, arg, idx, &mut instrs),
|
||||
_ => {}
|
||||
}
|
||||
|
@ -556,6 +557,40 @@ impl CodeObj {
|
|||
instrs
|
||||
}
|
||||
|
||||
fn read_instr_307(&self, op: &u8, arg: usize, idx: usize, instrs: &mut String) {
|
||||
let op307 = Opcode308::from(*op);
|
||||
let s_op = op307.to_string();
|
||||
write!(instrs, "{idx:>15} {s_op:<25}").unwrap();
|
||||
if let Ok(op) = CommonOpcode::try_from(*op) {
|
||||
self.dump_additional_info(op, arg, idx, instrs);
|
||||
}
|
||||
match op307 {
|
||||
Opcode308::STORE_DEREF | Opcode308::LOAD_DEREF => {
|
||||
write!(instrs, "{arg} ({})", self.freevars.get(arg).unwrap()).unwrap();
|
||||
}
|
||||
Opcode308::LOAD_CLOSURE => {
|
||||
write!(instrs, "{arg} ({})", self.cellvars.get(arg).unwrap()).unwrap();
|
||||
}
|
||||
Opcode308::JUMP_ABSOLUTE => {
|
||||
write!(instrs, "{arg} (to {})", arg).unwrap();
|
||||
}
|
||||
Opcode308::JUMP_FORWARD => {
|
||||
write!(instrs, "{arg} (to {})", idx + arg + 2).unwrap();
|
||||
}
|
||||
Opcode308::POP_JUMP_IF_FALSE | Opcode308::POP_JUMP_IF_TRUE => {
|
||||
write!(instrs, "{arg} (to {})", arg).unwrap();
|
||||
}
|
||||
Opcode308::BINARY_ADD
|
||||
| Opcode308::BINARY_SUBTRACT
|
||||
| Opcode308::BINARY_MULTIPLY
|
||||
| Opcode308::BINARY_TRUE_DIVIDE => {
|
||||
write!(instrs, "{arg} ({:?})", TypePair::from(arg as u8)).unwrap();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
instrs.push('\n');
|
||||
}
|
||||
|
||||
fn read_instr_308(&self, op: &u8, arg: usize, idx: usize, instrs: &mut String) {
|
||||
let op308 = Opcode308::from(*op);
|
||||
let s_op = op308.to_string();
|
||||
|
@ -573,6 +608,9 @@ impl CodeObj {
|
|||
Opcode308::JUMP_ABSOLUTE => {
|
||||
write!(instrs, "{arg} (to {})", arg * 2).unwrap();
|
||||
}
|
||||
Opcode308::JUMP_FORWARD => {
|
||||
write!(instrs, "{arg} (to {})", idx + arg * 2 + 2).unwrap();
|
||||
}
|
||||
// REVIEW: *2?
|
||||
Opcode308::POP_JUMP_IF_FALSE | Opcode308::POP_JUMP_IF_TRUE => {
|
||||
write!(instrs, "{arg} (to {})", arg * 2).unwrap();
|
||||
|
@ -605,6 +643,9 @@ impl CodeObj {
|
|||
Opcode310::JUMP_ABSOLUTE => {
|
||||
write!(instrs, "{arg} (to {})", arg * 2).unwrap();
|
||||
}
|
||||
Opcode310::JUMP_FORWARD => {
|
||||
write!(instrs, "{arg} (to {})", idx + arg * 2 + 2).unwrap();
|
||||
}
|
||||
Opcode310::POP_JUMP_IF_FALSE | Opcode310::POP_JUMP_IF_TRUE => {
|
||||
write!(instrs, "{arg} (to {})", arg * 2).unwrap();
|
||||
}
|
||||
|
@ -642,6 +683,9 @@ impl CodeObj {
|
|||
Opcode311::POP_JUMP_BACKWARD_IF_FALSE | Opcode311::POP_JUMP_BACKWARD_IF_TRUE => {
|
||||
write!(instrs, "{arg} (to {})", idx - arg * 2 + 2).unwrap();
|
||||
}
|
||||
Opcode311::JUMP_FORWARD => {
|
||||
write!(instrs, "{arg} (to {})", idx + arg * 2 + 2).unwrap();
|
||||
}
|
||||
Opcode311::JUMP_BACKWARD => {
|
||||
write!(instrs, "{arg} (to {})", idx - arg * 2 + 2).unwrap();
|
||||
}
|
||||
|
@ -697,9 +741,6 @@ impl CodeObj {
|
|||
CommonOpcode::FOR_ITER => {
|
||||
write!(instrs, "{arg} (to {})", idx + arg * 2 + 2).unwrap();
|
||||
}
|
||||
CommonOpcode::JUMP_FORWARD => {
|
||||
write!(instrs, "{arg} (to {})", idx + arg * 2 + 2).unwrap();
|
||||
}
|
||||
CommonOpcode::MAKE_FUNCTION => {
|
||||
let flag = match arg {
|
||||
8 => "(closure)",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue