Skip to content

Commit

Permalink
Add basic bytecode and disassembly support for Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed Nov 9, 2023
1 parent b32f231 commit c359f0b
Show file tree
Hide file tree
Showing 11 changed files with 455 additions and 188 deletions.
10 changes: 9 additions & 1 deletion ASTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,12 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
}
}
break;
case Pyc::RETURN_CONST_A:
{
PycRef<ASTObject> value = new ASTObject(code->getConst(operand));
curblock->append(new ASTReturn(value.cast<ASTNode>()));
}
break;
case Pyc::ROT_TWO:
{
PycRef<ASTNode> one = stack.top();
Expand Down Expand Up @@ -3347,7 +3353,9 @@ void decompyle(PycRef<PycCode> code, PycModule* mod, std::ostream& pyc_output)
if (clean->nodes().back().type() == ASTNode::NODE_RETURN) {
PycRef<ASTReturn> ret = clean->nodes().back().cast<ASTReturn>();

if (ret->value() == NULL || ret->value().type() == ASTNode::NODE_LOCALS) {
PycRef<ASTObject> retObj = ret->value().try_cast<ASTObject>();
if (ret->value() == NULL || ret->value().type() == ASTNode::NODE_LOCALS ||
(retObj && retObj->object().type() == PycObject::TYPE_NONE)) {
clean->removeLast(); // Always an extraneous return statement
}
}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endif()
set(PYTHON_VERSIONS
10 11 13 14 15 16 # Python 1.1 and 1.2 are marshal-identical
20 21 22 23 24 25 26 27
30 31 32 33 34 35 36 37 38 39 310 311
30 31 32 33 34 35 36 37 38 39 310 311 312
)

foreach(ver ${PYTHON_VERSIONS})
Expand Down
Loading

0 comments on commit c359f0b

Please sign in to comment.