This commit is contained in:
rocky
2016-12-24 07:45:02 -05:00
parent 7d58dcf6dd
commit e3f4beeb74
11 changed files with 21 additions and 26 deletions

View File

@@ -28,9 +28,9 @@ class AST(spark_AST):
i = 0
for node in self:
if hasattr(node, '__repr1__'):
if enumerate_children:
if enumerate_children:
child = node.__repr1__(indent, i)
else:
else:
child = node.__repr1__(indent, None)
else:
inst = node.format(line_prefix='L.')

View File

@@ -282,7 +282,7 @@ class Python2Parser(PythonParser):
opname_base, v, customize)
self.seen1024 = True
rule = ('build_list ::= ' + 'expr1024 '*thousands +
'expr32 '*thirty32s + 'expr '*(v%32) + opname)
'expr32 '*thirty32s + 'expr '*(v % 32) + opname)
elif opname == 'LOOKUP_METHOD':
# A PyPy speciality - DRY with parse3
self.add_unique_rule("load_attr ::= expr LOOKUP_METHOD",

View File

@@ -177,8 +177,8 @@ class Python26Parser(Python2Parser):
list_iter ::= list_if JUMP_BACK
list_iter ::= list_if JUMP_BACK COME_FROM POP_TOP
list_compr ::= BUILD_LIST_0 DUP_TOP
designator list_iter del_stmt
list_compr ::= BUILD_LIST_0 DUP_TOP
designator list_iter del_stmt
list_compr ::= BUILD_LIST_0 DUP_TOP
designator list_iter JUMP_BACK del_stmt
lc_body ::= LOAD_NAME expr LIST_APPEND

View File

@@ -550,7 +550,8 @@ class Python3Parser(PythonParser):
elif opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
v = token.attr
rule = ('build_list ::= ' + 'expr1024 ' * int(v//1024) +
'expr32 ' * int((v//32)%32) + 'expr '*(v % 32) + opname)
'expr32 ' * int((v//32) % 32) +
'expr ' * (v % 32) + opname)
self.add_unique_rule(rule, opname, token.attr, customize)
if opname_base == 'BUILD_TUPLE':
rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname))

View File

@@ -69,8 +69,8 @@ if __name__ == '__main__':
""".split()))
remain_tokens = set(tokens) - opcode_set
import re
remain_tokens = set([re.sub('_\d+$','', t) for t in remain_tokens])
remain_tokens = set([re.sub('_CONT$','', t) for t in remain_tokens])
remain_tokens = set([re.sub('_\d+$', '', t) for t in remain_tokens])
remain_tokens = set([re.sub('_CONT$', '', t) for t in remain_tokens])
remain_tokens = set(remain_tokens) - opcode_set
print(remain_tokens)
# print(sorted(p.rule2name.items()))

View File

@@ -23,5 +23,5 @@ class Scanner15(scan.Scanner21):
self.opc = opcode_15
self.opname = opcode_15.opname
self.version = 1.5
self.genexpr_name = '<generator expression>';
self.genexpr_name = '<generator expression>'
return

View File

@@ -97,7 +97,7 @@ class Scanner2(scan.Scanner):
customize = {}
if self.is_pypy:
customize['PyPy'] = 1;
customize['PyPy'] = 1
Token = self.Token # shortcut
@@ -458,7 +458,6 @@ class Scanner2(scan.Scanner):
self.ignore_if.add(except_match)
return None
self.ignore_if.add(except_match)
self.not_continue.add(jmp)
return jmp
@@ -903,8 +902,8 @@ class Scanner2(scan.Scanner):
if label is None:
if op in self.opc.hasjrel and self.opc.opname[op] != 'FOR_ITER':
# if (op in self.opc.hasjrel and
# (self.version < 2.0 or op != self.opc.FOR_ITER)):
# if (op in self.opc.hasjrel and
# (self.version < 2.0 or op != self.opc.FOR_ITER)):
label = offset + 3 + oparg
elif self.version == 2.7 and op in self.opc.hasjabs:
if op in (self.opc.JUMP_IF_FALSE_OR_POP,

View File

@@ -23,5 +23,5 @@ class Scanner21(scan.Scanner22):
self.opc = opcode_21
self.opname = opcode_21.opname
self.version = 2.1
self.genexpr_name = '<generator expression>';
self.genexpr_name = '<generator expression>'
return

View File

@@ -23,7 +23,7 @@ class Scanner22(scan.Scanner23):
self.opc = opcode_22
self.opname = opcode_22.opname
self.version = 2.2
self.genexpr_name = '<generator expression>';
self.genexpr_name = '<generator expression>'
self.parent_ingest = self.ingest
self.ingest = self.ingest22
return

View File

@@ -97,14 +97,14 @@ TABLE_DIRECT_FRAGMENT = {
'importstmt': ( '%|import %c%x\n', 2, (2, (0, 1)), ),
'importfrom': ( '%|from %[2]{pattr}%x import %c\n', (2, (0, 1)), 3),
'importmultiple': ( '%|import%b %c%c\n', 0, 2, 3 ),
'list_for': (' for %c%x in %c%c', 2, (2,(1,)), 0, 3 ),
'forstmt': ( '%|for%b %c%x in %c:\n%+%c%-\n\n', 0, 3, (3, (2,)), 1, 4 ),
'list_for': (' for %c%x in %c%c', 2, (2, (1, )), 0, 3 ),
'forstmt': ( '%|for%b %c%x in %c:\n%+%c%-\n\n', 0, 3, (3, (2, )), 1, 4 ),
'forelsestmt': (
'%|for %c in %c%x:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2),
'forelselaststmt': (
'%|for %c%x in %c:\n%+%c%-%|else:\n%+%c%-', 3, (3, (2,)), 1, 4, -2),
'forelselaststmtl': (
'%|for %c%x in %c:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2),
'%|for %c%x in %c:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2, )), 1, 4, -2),
'whilestmt': ( '%|while%b %c:\n%+%c%-\n\n', 0, 1, 2 ),
'whileelsestmt': ( '%|while%b %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 2, -2 ),
@@ -163,7 +163,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
None)
def set_pos_info(self, node, start, finish, name=None):
if name == None: name = self.name
if name is None: name = self.name
if hasattr(node, 'offset'):
self.offsets[name, node.offset] = \
NodeInfo(node = node, start = start, finish = finish)
@@ -622,7 +622,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
n = ast[iter_index]
assert n == 'list_iter'
## FIXME: I'm not totally sure this is right.
# FIXME: I'm not totally sure this is right.
# find innermost node
if_node = None

View File

@@ -492,7 +492,6 @@ class SourceWalker(GenericASTTraversal, object):
self.write("\n" + self.indent + INDENT_PER_LEVEL[:-1])
return self.line_number
def customize_for_version(self, is_pypy, version):
if is_pypy:
########################
@@ -537,7 +536,6 @@ class SourceWalker(GenericASTTraversal, object):
'raise_stmt2': ( '%|raise %c from %c\n', 0, 1),
})
if version < 2.0:
TABLE_DIRECT.update({
'importlist': ( '%C', (0, maxint, ', ') ),
@@ -622,7 +620,6 @@ class SourceWalker(GenericASTTraversal, object):
self.prune() # stop recursing
self.n_mkfunc_annotate = n_mkfunc_annotate
if version >= 3.4:
########################
# Python 3.4+ Additions
@@ -1149,7 +1146,6 @@ class SourceWalker(GenericASTTraversal, object):
assert n == 'lc_body'
self.write( '[ ')
if self.version >= 2.7:
expr = n[0]
list_iter = node[-1]
@@ -1337,7 +1333,7 @@ class SourceWalker(GenericASTTraversal, object):
n = ast[iter_index]
assert n == 'list_iter', n
## FIXME: I'm not totally sure this is right.
# FIXME: I'm not totally sure this is right.
# find innermost node
if_node = None
@@ -2139,7 +2135,6 @@ class SourceWalker(GenericASTTraversal, object):
self.println()
del ast[i]
# the function defining a class normally returns locals(); we
# don't want this to show up in the source, thus remove the node
if len(ast) > 0 and ast[-1][0] == RETURN_LOCALS: