Custom PyPy rules for tryfinallysmt, assign{2,3}

This commit is contained in:
rocky 2016-07-26 15:56:49 -04:00
parent 6c5bd6289f
commit ecbbc7dfea
8 changed files with 41 additions and 4 deletions

Binary file not shown.

View File

@ -0,0 +1,4 @@
# From PyPy 2.6.1 datetime
# PyPy has simpler handling of assign3 and assign2
i, n = 0, 1
a, b, c = 1, 2, 3

View File

@ -7,3 +7,10 @@ def call(self, string):
return open(string, self, self._bufsize)
except IOError:
pass
# From PyPy 2.6.1 function.py
def _call_funcptr(self, funcptr, *newargs):
try:
return self._build_result(self._restype_, result)
finally:
funcptr.free_temp_buffers()

View File

@ -16,7 +16,6 @@ def uncompyle(
"""
disassembles and deparses a given code block 'co'
"""
assert iscode(co)
# store final output stream for case of error

View File

@ -251,7 +251,15 @@ class Python2Parser(PythonParser):
'''
for opname, v in list(customize.items()):
opname_base = opname[:opname.rfind('_')]
if opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
if opname == 'PyPy':
self.add_unique_rules([
'stmt ::= assign3_pypy',
'stmt ::= assign2_pypy',
'assign3_pypy ::= expr expr expr designator designator designator',
'assign2_pypy ::= expr expr designator designator'
], customize)
continue
elif opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
thousands = (v//1024)
thirty32s = ((v//32)%32)
if thirty32s > 0:
@ -308,6 +316,16 @@ class Python2Parser(PythonParser):
"try_middle_pypy ::= COME_FROM except_stmts END_FINALLY COME_FROM"
], customize)
continue
elif opname == 'SETUP_FINALLY':
# FIXME: have a way here to detect PyPy. Right now we
# only have SETUP_EXCEPT customization for PyPy, but that might not
# always be the case.
self.add_unique_rules([
"stmt ::= tryfinallystmt_pypy",
"tryfinallystmt_pypy ::= SETUP_FINALLY suite_stmts_opt COME_FROM "
"suite_stmts_opt END_FINALLY"
], customize)
continue
elif opname_base in ('UNPACK_TUPLE', 'UNPACK_SEQUENCE'):
rule = 'unpack ::= ' + opname + ' designator'*v
elif opname_base == 'UNPACK_LIST':
@ -321,7 +339,7 @@ class Python2Parser(PythonParser):
('pos_arg '*v, opname), nop_func)
rule = 'mkfunc ::= %s LOAD_CONST %s' % ('expr '*v, opname)
elif opname_base == 'MAKE_CLOSURE':
# FIXME: use add_uniqe_rules to tidy this up.
# FIXME: use add_unique_rules to tidy this up.
self.addRule('mklambda ::= %s load_closure LOAD_LAMBDA %s' %
('expr '*v, opname), nop_func)
self.addRule('genexpr ::= %s load_closure LOAD_GENEXPR %s expr GET_ITER CALL_FUNCTION_1' %

View File

@ -67,6 +67,9 @@ class Scanner2(scan.Scanner):
tokens = []
customize = {}
if self.is_pypy:
customize['PyPy'] = 1;
Token = self.Token # shortcut
n = self.setup_code(co)
@ -208,7 +211,8 @@ class Scanner2(scan.Scanner):
customize[opname] = oparg
elif self.is_pypy and opname in ('LOOKUP_METHOD',
'JUMP_IF_NOT_DEBUG',
'SETUP_EXCEPT'):
'SETUP_EXCEPT',
'SETUP_FINALLY'):
# The value in the dict is in special cases in semantic actions, such
# as CALL_FUNCTION. The value is not used in these cases, so we put
# in arbitrary value 0.

View File

@ -383,10 +383,15 @@ TABLE_DIRECT = {
########################
# PyPy Additions
# FIXME: we could remove the corresponding
# rules without _pypy if we have pypy
#######################
'assert_pypy': ( '%|assert %c\n' , 1 ),
'assert2_pypy': ( '%|assert %c, %c\n' , 1, 4 ),
'trystmt_pypy': ( '%|try:\n%+%c%-%c\n\n', 1, 2 ),
'tryfinallystmt_pypy': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 3 ),
'assign3_pypy': ( '%|%c, %c, %c = %c, %c, %c\n', 5, 4, 3, 0, 1, 2 ),
'assign2_pypy': ( '%|%c, %c = %c, %c\n', 3, 2, 0, 1),
}