Skip to content

Commit

Permalink
LOAD_ATTR operand changes in 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Nenad Čaklović committed Jan 5, 2024
1 parent 2da061f commit 5f225ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ASTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,8 +1473,11 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
{
PycRef<ASTNode> name = stack.top();
if (name.type() != ASTNode::NODE_IMPORT) {
auto arg = operand;
if (mod->verCompare(3, 12) >= 0 && (arg & 1))
arg >>= 1;
stack.pop();
stack.push(new ASTBinary(name, new ASTName(code->getName(operand)), ASTBinary::BIN_ATTR));
stack.push(new ASTBinary(name, new ASTName(code->getName(arg)), ASTBinary::BIN_ATTR));
}
}
break;
Expand Down
5 changes: 4 additions & 1 deletion bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,10 @@ void bc_disasm(std::ostream& pyc_output, PycRef<PycCode> code, PycModule* mod,
case Pyc::LOAD_METHOD_A:
case Pyc::LOAD_FROM_DICT_OR_GLOBALS_A:
try {
formatted_print(pyc_output, "%d: %s", operand, code->getName(operand)->value());
auto arg = operand;
if (opcode == Pyc::LOAD_ATTR_A && mod->verCompare(3, 12) >= 0 && (arg & 1))
arg >>= 1;
formatted_print(pyc_output, "%d: %s", operand, code->getName(arg)->value());
} catch (const std::out_of_range &) {
formatted_print(pyc_output, "%d <INVALID>", operand);
}
Expand Down

0 comments on commit 5f225ca

Please sign in to comment.