You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Merge branch 'come-from-type'
This commit is contained in:
@@ -9,7 +9,7 @@ e.g. 5, myvariable, "for", etc. they are CPython Bytecode tokens,
|
|||||||
e.g. "LOAD_CONST 5", "STORE NAME myvariable", "SETUP_LOOP", etc.
|
e.g. "LOAD_CONST 5", "STORE NAME myvariable", "SETUP_LOOP", etc.
|
||||||
|
|
||||||
If we succeed in creating a parse tree, then we have a Python program
|
If we succeed in creating a parse tree, then we have a Python program
|
||||||
that a later phase can tern into a sequence of ASCII text.
|
that a later phase can turn into a sequence of ASCII text.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
@@ -336,7 +336,7 @@ class Python2Parser(PythonParser):
|
|||||||
# always be the case.
|
# always be the case.
|
||||||
self.add_unique_rules([
|
self.add_unique_rules([
|
||||||
"stmt ::= tryfinallystmt_pypy",
|
"stmt ::= tryfinallystmt_pypy",
|
||||||
"tryfinallystmt_pypy ::= SETUP_FINALLY suite_stmts_opt COME_FROM "
|
"tryfinallystmt_pypy ::= SETUP_FINALLY suite_stmts_opt COME_FROM_FINALLY "
|
||||||
"suite_stmts_opt END_FINALLY"
|
"suite_stmts_opt END_FINALLY"
|
||||||
], customize)
|
], customize)
|
||||||
continue
|
continue
|
||||||
|
@@ -31,6 +31,10 @@ class Python27Parser(Python2Parser):
|
|||||||
|
|
||||||
def p_try27(self, args):
|
def p_try27(self, args):
|
||||||
"""
|
"""
|
||||||
|
tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt
|
||||||
|
POP_BLOCK LOAD_CONST
|
||||||
|
COME_FROM_FINALLY suite_stmts_opt END_FINALLY
|
||||||
|
|
||||||
tryelsestmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
tryelsestmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||||
try_middle else_suite COME_FROM
|
try_middle else_suite COME_FROM
|
||||||
|
|
||||||
@@ -77,11 +81,11 @@ class Python27Parser(Python2Parser):
|
|||||||
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2
|
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2
|
||||||
|
|
||||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||||
POP_BLOCK LOAD_CONST COME_FROM
|
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||||
WITH_CLEANUP END_FINALLY
|
WITH_CLEANUP END_FINALLY
|
||||||
|
|
||||||
withasstmt ::= expr SETUP_WITH designator suite_stmts_opt
|
withasstmt ::= expr SETUP_WITH designator suite_stmts_opt
|
||||||
POP_BLOCK LOAD_CONST COME_FROM
|
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||||
WITH_CLEANUP END_FINALLY
|
WITH_CLEANUP END_FINALLY
|
||||||
|
|
||||||
# Common with 2.6
|
# Common with 2.6
|
||||||
|
@@ -93,11 +93,6 @@ class Scanner2(scan.Scanner):
|
|||||||
for instr in bytecode.get_instructions(co):
|
for instr in bytecode.get_instructions(co):
|
||||||
print(instr._disassemble())
|
print(instr._disassemble())
|
||||||
|
|
||||||
# from xdis.bytecode import Bytecode
|
|
||||||
# bytecode = Bytecode(co, self.opc)
|
|
||||||
# for instr in bytecode.get_instructions(co):
|
|
||||||
# print(instr._disassemble())
|
|
||||||
|
|
||||||
# Container for tokens
|
# Container for tokens
|
||||||
tokens = []
|
tokens = []
|
||||||
|
|
||||||
@@ -166,8 +161,15 @@ class Scanner2(scan.Scanner):
|
|||||||
# properly. For example, a "loop" with an "if" nested in it should have the
|
# properly. For example, a "loop" with an "if" nested in it should have the
|
||||||
# "loop" tag last so the grammar rule matches that properly.
|
# "loop" tag last so the grammar rule matches that properly.
|
||||||
for jump_offset in sorted(jump_targets[offset], reverse=True):
|
for jump_offset in sorted(jump_targets[offset], reverse=True):
|
||||||
|
come_from_name = 'COME_FROM'
|
||||||
|
opname = self.opc.opname[self.code[jump_offset]]
|
||||||
|
if opname.startswith('SETUP_') and self.version == 2.7:
|
||||||
|
come_from_type = opname[len('SETUP_'):]
|
||||||
|
if come_from_type not in ('LOOP', 'EXCEPT'):
|
||||||
|
come_from_name = 'COME_FROM_%s' % come_from_type
|
||||||
|
pass
|
||||||
tokens.append(Token(
|
tokens.append(Token(
|
||||||
'COME_FROM', None, repr(jump_offset),
|
come_from_name, None, repr(jump_offset),
|
||||||
offset="%s_%d" % (offset, jump_idx),
|
offset="%s_%d" % (offset, jump_idx),
|
||||||
has_arg = True))
|
has_arg = True))
|
||||||
jump_idx += 1
|
jump_idx += 1
|
||||||
|
Reference in New Issue
Block a user