Fix LOAD_GLOBAL and cell var references in Python 3.11+

This commit is contained in:
Michael Hansen
2023-01-19 13:05:06 -08:00
parent 379c0c94d0
commit 5d855f0bd2
4 changed files with 30 additions and 12 deletions

View File

@@ -363,7 +363,7 @@ void bc_disasm(PycRef<PycCode> code, PycModule* mod, int indent)
fprintf(pyc_output, "%-7d ", pos); // Current bytecode position
bc_next(source, mod, opcode, operand, pos);
fprintf(pyc_output, "%-24s", Pyc::OpcodeName(opcode));
fprintf(pyc_output, "%-30s", Pyc::OpcodeName(opcode));
if (opcode >= Pyc::PYC_HAVE_ARG) {
if (Pyc::IsConstArg(opcode)) {
@@ -374,6 +374,16 @@ void bc_disasm(PycRef<PycCode> code, PycModule* mod, int indent)
} catch (const std::out_of_range &) {
fprintf(pyc_output, "%d <INVALID>", operand);
}
} else if (opcode == Pyc::LOAD_GLOBAL_A) {
// Special case for Python 3.11+
try {
if (operand & 1)
fprintf(pyc_output, "%d: NULL + %s", operand, code->getName(operand >> 1)->value());
else
fprintf(pyc_output, "%d: %s", operand, code->getName(operand >> 1)->value());
} catch (const std::out_of_range &) {
fprintf(pyc_output, "%d <INVALID>", operand);
}
} else if (Pyc::IsNameArg(opcode)) {
try {
fprintf(pyc_output, "%d: %s", operand, code->getName(operand)->value());
@@ -388,7 +398,7 @@ void bc_disasm(PycRef<PycCode> code, PycModule* mod, int indent)
}
} else if (Pyc::IsCellArg(opcode)) {
try {
fprintf(pyc_output, "%d: %s", operand, code->getCellVar(operand)->value());
fprintf(pyc_output, "%d: %s", operand, code->getCellVar(mod, operand)->value());
} catch (const std::out_of_range &) {
fprintf(pyc_output, "%d <INVALID>", operand);
}