Skip to content

Commit

Permalink
Merge pull request #167 from rocky/pypy38-support
Browse files Browse the repository at this point in the history
Pypy38 support
  • Loading branch information
rocky authored Mar 1, 2024
2 parents 56441a7 + 8a16214 commit 344bc3b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 24 deletions.
2 changes: 1 addition & 1 deletion decompyle3/bin/decompile_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from decompyle3.disas import disassemble_file
from decompyle3.version import __version__

program, ext = os.path.splitext(os.path.basename(__file__))
program = "decompile-tokens"

__doc__ = """
Usage:
Expand Down
12 changes: 8 additions & 4 deletions decompyle3/parsers/p38/lambda_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ def customize_grammar_rules_lambda38(self, tokens, customize):
expr ::= set_comp_async
func_async_middle ::= POP_BLOCK JUMP_FORWARD COME_FROM_EXCEPT
DUP_TOP LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
DUP_TOP LOAD_GLOBAL COMPARE_OP
POP_JUMP_IF_TRUE
END_FINALLY _come_froms
# async_iter ::= block_break SETUP_EXCEPT GET_ANEXT LOAD_CONST YIELD_FROM
# async_iter ::= block_break SETUP_EXCEPT GET_ANEXT
LOAD_CONST YIELD_FROM
get_aiter ::= expr GET_AITER
Expand Down Expand Up @@ -390,9 +392,11 @@ def customize_grammar_rules_lambda38(self, tokens, customize):
dict_comp_async ::= BUILD_MAP_0 genexpr_func_async
async_iter ::= _come_froms
SETUP_FINALLY GET_ANEXT LOAD_CONST YIELD_FROM POP_BLOCK
SETUP_FINALLY GET_ANEXT LOAD_CONST
YIELD_FROM POP_BLOCK
func_async_prefix ::= _come_froms SETUP_EXCEPT GET_ANEXT LOAD_CONST YIELD_FROM
func_async_prefix ::= _come_froms SETUP_EXCEPT GET_ANEXT
LOAD_CONST YIELD_FROM
genexpr_func_async ::= LOAD_ARG async_iter
store
Expand Down
33 changes: 20 additions & 13 deletions decompyle3/parsers/p38pypy/lambda_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,24 @@ def customize_grammar_rules_lambda38(self, tokens, customize):
expr ::= set_comp_async
func_async_middle ::= POP_BLOCK JUMP_FORWARD COME_FROM_EXCEPT
DUP_TOP LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
DUP_TOP LOAD_GLOBAL COMPARE_OP
POP_JUMP_IF_TRUE
END_FINALLY _come_froms
# async_iter ::= block_break SETUP_EXCEPT GET_ANEXT LOAD_CONST YIELD_FROM
# async_iter ::= block_break SETUP_EXCEPT GET_ANEXT
LOAD_CONST YIELD_FROM
get_aiter ::= expr GET_AITER
list_afor ::= get_aiter list_afor2
list_comp_async ::= BUILD_LIST_0 LOAD_ARG list_afor2
return_expr_lambda ::= list_comp_async
list_afor2 ::= async_iter store list_iter
JUMP_LOOP COME_FROM_EXCEPT
END_ASYNC_FOR
list_iter ::= list_afor
Expand All @@ -398,29 +406,28 @@ def customize_grammar_rules_lambda38(self, tokens, customize):
dict_comp_async ::= BUILD_MAP_0 genexpr_func_async
async_iter ::= _come_froms
SETUP_FINALLY GET_ANEXT LOAD_CONST YIELD_FROM POP_BLOCK
SETUP_EXCEPT
GET_ANEXT
LOAD_CONST
YIELD_FROM
POP_BLOCK
func_async_prefix ::= _come_froms SETUP_EXCEPT GET_ANEXT LOAD_CONST YIELD_FROM
func_async_prefix ::= _come_froms SETUP_EXCEPT GET_ANEXT
LOAD_CONST YIELD_FROM
genexpr_func_async ::= LOAD_ARG async_iter
store
comp_iter
JUMP_LOOP
COME_FROM_FINALLY
COME_FROM_EXCEPT
END_ASYNC_FOR
genexpr_func_async ::= LOAD_ARG func_async_prefix
store func_async_middle comp_iter
JUMP_LOOP COME_FROM
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP
list_afor2 ::= async_iter
store
list_iter
JUMP_LOOP
COME_FROM_FINALLY
END_ASYNC_FOR
list_comp_async ::= LOAD_ARG BUILD_LIST_FROM_ARG list_afor2
list_comp_async ::= BUILD_LIST_0 LOAD_ARG list_afor2
set_afor2 ::= async_iter
Expand Down
6 changes: 5 additions & 1 deletion decompyle3/parsers/p38pypy/lambda_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def p_38walrus(self, args):
def p_lambda_start(self, args):
"""
return_expr_lambda ::= genexpr_func LOAD_CONST RETURN_VALUE_LAMBDA
"""

def p_pypy38_comprehension(self, args):
Expand All @@ -47,6 +46,11 @@ def p_pypy38_comprehension(self, args):
store lc_body
JUMP_LOOP _come_froms
list_afor2 ::= async_iter store list_iter
JUMP_LOOP COME_FROM_EXCEPT
END_ASYNC_FOR
lc_body ::= expr LIST_APPEND
"""

Expand Down
20 changes: 15 additions & 5 deletions decompyle3/semantics/gencomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ def comprehension_walk_newer(
# list_comp_async ::= BUILD_LIST_0 LOAD_ARG list_afor2
if tree[0] == "expr" and tree[0][0] == "list_comp_async":
tree = tree[0][0]
if tree[0] == "BUILD_LIST_0":
# PyPy 3.8 has LOAD_ARG
if tree[0] in ("BUILD_LIST_0", "LOAD_ARG"):
list_afor2 = tree[2]
assert list_afor2 == "list_afor2"
store = list_afor2[1]
Expand Down Expand Up @@ -389,7 +390,13 @@ def comprehension_walk_newer(
elif node == "set_comp" and tree[1] == "set_iter":
n = tree[1]
else:
n = tree[iter_index]
for k in tree:
if k.kind in ("comp_iter", "list_iter", "set_iter", "lc_body"):
n = k
break
pass
else:
n = tree[iter_index]

if tree in (
"dict_comp_func",
Expand Down Expand Up @@ -497,7 +504,7 @@ def comprehension_walk_newer(
"comp_if_not",
):
if n in ("list_if37", "list_if37_not", "comp_if"):
if n == "comp_if":
if n in ("comp_if", "list_if37", "list_if"):
if_nodes.append(n[0])
n = n[1]
else:
Expand Down Expand Up @@ -631,7 +638,7 @@ def comprehension_walk_newer(
comp_store = None
pass

if tree == "set_comp_func":
elif tree == "set_comp_func":
# Handle nested comp_for iterations.
comp_iter = tree[4]
assert comp_iter in ("comp_iter", "await_expr")
Expand All @@ -652,6 +659,7 @@ def comprehension_walk_newer(
if if_node != "comp_if_or":
self.write(" if ")
if if_node in (
"c_compare_chained37_false",
"comp_if_not_and",
"comp_if_not_or",
"comp_if_or",
Expand Down Expand Up @@ -717,7 +725,9 @@ def get_comprehension_function(self, node, code_index: int):
if tree == "lambda_start":
tree = tree[0]

while len(tree) == 1 or (tree in ("stmt", "sstmt", "return", "return_expr")):
while len(tree) == 1 or (
tree in ("stmt", "sstmt", "return", "return_expr", "return_expr_lambda")
):
self.prec = 100
tree = tree[0]
return tree

0 comments on commit 344bc3b

Please sign in to comment.