Python 2.4 generator expressions and gen_comp_body

This commit is contained in:
rocky
2016-07-08 18:00:13 -04:00
parent 61535a010d
commit e31f829a56
4 changed files with 9 additions and 2 deletions

View File

@@ -27,6 +27,9 @@ class Python24Parser(Python25Parser):
while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_TOP POP_BLOCK COME_FROM
call_stmt ::= yield
# Python 2.5+ adds POP_TOP
gen_comp_body ::= expr YIELD_VALUE
'''
class Python24ParserSingle(Python25Parser, PythonParserSingle):

View File

@@ -36,6 +36,9 @@ class Scanner2(scan.Scanner):
scan.Scanner.__init__(self, version, show_asm)
self.pop_jump_if = frozenset([self.opc.PJIF, self.opc.PJIT])
self.jump_forward = frozenset([self.opc.JA, self.opc.JF])
# This is the 2.5+ default
# For <2.5 it is <generator expression>
self.genexpr_name = '<genexpr>';
def disassemble(self, co, classname=None, code_objects={}, show_asm=None):
"""
@@ -143,7 +146,7 @@ class Scanner2(scan.Scanner):
if const.co_name == '<lambda>':
assert opname == 'LOAD_CONST'
opname = 'LOAD_LAMBDA'
elif const.co_name == '<genexpr>':
elif const.co_name == self.genexpr_name:
opname = 'LOAD_GENEXPR'
elif const.co_name == '<dictcomp>':
opname = 'LOAD_DICTCOMP'

View File

@@ -65,4 +65,5 @@ class Scanner24(scan.Scanner25):
# Python 2.7 has POP_JUMP_IF_{TRUE,FALSE}_OR_POP but < 2.7 doesn't
# Add an empty set make processing more uniform.
self.pop_jump_if_or_pop = frozenset([])
self.genexpr_name = '<generator expression>';
return

View File

@@ -199,7 +199,7 @@ class Scanner26(scan.Scanner2):
if const.co_name == '<lambda>':
assert op_name == 'LOAD_CONST'
op_name = 'LOAD_LAMBDA'
elif const.co_name == '<genexpr>':
elif const.co_name == self.genexpr_name:
op_name = 'LOAD_GENEXPR'
elif const.co_name == '<dictcomp>':
op_name = 'LOAD_DICTCOMP'