You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Bang on version 1.0-1.4 Python
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Copyright (c) 2018, 2022 Rocky Bernstein
|
||||
|
||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||
from uncompyle6.parser import PythonParserSingle
|
||||
from uncompyle6.parser import PythonParserSingle, nop_func
|
||||
from uncompyle6.parsers.parse15 import Python15Parser
|
||||
|
||||
class Python14Parser(Python15Parser):
|
||||
@@ -11,6 +11,8 @@ class Python14Parser(Python15Parser):
|
||||
# Not much here yet, but will probably need to add UNARY_CALL,
|
||||
# LOAD_LOCAL, SET_FUNC_ARGS
|
||||
|
||||
args ::= RESERVE_FAST UNPACK_ARG args_store
|
||||
args_store ::= STORE_FAST*
|
||||
call ::= expr tuple BINARY_CALL
|
||||
expr ::= call
|
||||
kv ::= DUP_TOP expr ROT_TWO LOAD_CONST STORE_SUBSCR
|
||||
@@ -18,11 +20,11 @@ class Python14Parser(Python15Parser):
|
||||
print_expr_stmt ::= expr PRINT_EXPR
|
||||
raise_stmt2 ::= expr expr RAISE_EXCEPTION
|
||||
star_args ::= RESERVE_FAST UNPACK_VARARG_1 args_store
|
||||
args ::= RESERVE_FAST UNPACK_ARG args_store
|
||||
stmt ::= print_expr_stmt
|
||||
args_store ::= STORE_FAST+
|
||||
stmt ::= args
|
||||
stmt ::= print_expr_stmt
|
||||
stmt ::= star_args
|
||||
stmt ::= varargs
|
||||
varargs ::= RESERVE_FAST UNPACK_VARARG_0 args_store
|
||||
|
||||
# Not strictly needed, but tidies up output
|
||||
|
||||
@@ -55,7 +57,14 @@ class Python14Parser(Python15Parser):
|
||||
jb_pop
|
||||
POP_BLOCK else_suitel COME_FROM
|
||||
""")
|
||||
self.check_reduce['doc_junk'] = 'tokens'
|
||||
self.check_reduce["doc_junk"] = "tokens"
|
||||
for i, token in enumerate(tokens):
|
||||
opname = token.kind
|
||||
opname_base = opname[:opname.rfind("_")]
|
||||
|
||||
if opname_base == "UNPACK_VARARG":
|
||||
if token.attr > 1:
|
||||
self.addRule(f"star_args ::= RESERVE_FAST {opname} args_store", nop_func)
|
||||
|
||||
|
||||
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
||||
|
@@ -45,12 +45,12 @@ def make_function1(self, node, is_lambda, nested=1, code_node=None):
|
||||
args = tree[0]
|
||||
del tree[0]
|
||||
params = []
|
||||
assert args.kind in ("star_args", "args")
|
||||
has_star_arg = args.kind == "star_args"
|
||||
assert args.kind in ("star_args", "args", "varargs")
|
||||
has_star_arg = args.kind in ("star_args", "varargs")
|
||||
args_store = args[2]
|
||||
assert args_store == "args_store"
|
||||
for arg in args_store:
|
||||
params.append(param_names[arg.attr])
|
||||
if args_store == "args_store":
|
||||
for arg in args_store:
|
||||
params.append(param_names[arg.attr])
|
||||
return has_star_arg, params
|
||||
|
||||
# MAKE_FUNCTION_... or MAKE_CLOSURE_...
|
||||
@@ -118,16 +118,16 @@ def make_function1(self, node, is_lambda, nested=1, code_node=None):
|
||||
# to have something to after the yield finishes.
|
||||
# FIXME: this is a bit hoaky and not general
|
||||
if (
|
||||
len(ast) > 1
|
||||
and self.traverse(ast[-1]) == "None"
|
||||
and self.traverse(ast[-2]).strip().startswith("yield")
|
||||
len(tree) > 1
|
||||
and self.traverse(tree[-1]) == "None"
|
||||
and self.traverse(tree[-2]).strip().startswith("yield")
|
||||
):
|
||||
del ast[-1]
|
||||
del tree[-1]
|
||||
# Now pick out the expr part of the last statement
|
||||
ast_expr = ast[-1]
|
||||
while ast_expr.kind != "expr":
|
||||
ast_expr = ast_expr[0]
|
||||
ast[-1] = ast_expr
|
||||
tree_expr = tree[-1]
|
||||
while tree_expr.kind != "expr":
|
||||
tree_expr = tree_expr[0]
|
||||
tree[-1] = tree_expr
|
||||
pass
|
||||
else:
|
||||
self.write("(", ", ".join(params))
|
||||
|
Reference in New Issue
Block a user