diff --git a/Lib/compiler/pyassem.py b/Lib/compiler/pyassem.py index 10a8dbde7c4..0547eeb068a 100644 --- a/Lib/compiler/pyassem.py +++ b/Lib/compiler/pyassem.py @@ -6,15 +6,8 @@ import types from compiler import misc -from compiler.consts import CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, \ - CO_VARKEYWORDS - -def xxx_sort(l): - l = l[:] - def sorter(a, b): - return cmp(a.bid, b.bid) - l.sort(sorter) - return l +from compiler.consts \ + import CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS class FlowGraph: def __init__(self): @@ -77,7 +70,7 @@ def _disable_debug(self): def emit(self, *inst): if self._debug: print "\t", inst - if inst[0] == 'RETURN_VALUE': + if inst[0] in ['RETURN_VALUE', 'YIELD_VALUE']: self.current.addOutEdge(self.exit) if len(inst) == 2 and isinstance(inst[1], Block): self.current.addOutEdge(inst[1]) @@ -266,7 +259,7 @@ def addNext(self, block): self.next.append(block) assert len(self.next) == 1, map(str, self.next) - _uncond_transfer = ('RETURN_VALUE', 'RAISE_VARARGS', + _uncond_transfer = ('RETURN_VALUE', 'RAISE_VARARGS', 'YIELD_VALUE', 'JUMP_ABSOLUTE', 'JUMP_FORWARD', 'CONTINUE_LOOP') def pruneNext(self): @@ -443,7 +436,7 @@ def flattenGraph(self): insts.append(inst) if len(inst) == 1: pc = pc + 1 - else: + elif inst[0] != "SET_LINENO": # arg takes 2 bytes pc = pc + 3 end[b] = pc @@ -452,7 +445,7 @@ def flattenGraph(self): inst = insts[i] if len(inst) == 1: pc = pc + 1 - else: + elif inst[0] != "SET_LINENO": pc = pc + 3 opname = inst[0] if self.hasjrel.has_elt(opname): @@ -580,6 +573,7 @@ def makeByteCode(self): oparg = t[1] if opname == "SET_LINENO": lnotab.nextLine(oparg) + continue hi, lo = twobyte(oparg) try: lnotab.addCode(self.opnum[opname], lo, hi) @@ -697,7 +691,7 @@ def nextLine(self, lineno): # after the loading of "b". This works with the C Python # compiler because it only generates a SET_LINENO instruction # for the assignment. - if line > 0: + if line >= 0: push = self.lnotab.append while addr > 255: push(255); push(0) @@ -768,6 +762,7 @@ def findDepth(self, insts, debug=0): # PRINT_EXPR? 'PRINT_ITEM': -1, 'RETURN_VALUE': -1, + 'YIELD_VALUE': -1, 'EXEC_STMT': -3, 'BUILD_CLASS': -2, 'STORE_NAME': -1, diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py index ac978c088e6..a3518d292cd 100644 --- a/Lib/compiler/pycodegen.py +++ b/Lib/compiler/pycodegen.py @@ -13,6 +13,7 @@ CO_NESTED, CO_GENERATOR, CO_GENERATOR_ALLOWED, CO_FUTURE_DIVISION from compiler.pyassem import TupleArg +# XXX The version-specific code can go, since this code only works with 2.x. # Do we have Python 1.x or Python 2.x? try: VERSION = sys.version_info[0] @@ -32,22 +33,14 @@ TRY_FINALLY = 3 END_FINALLY = 4 -# XXX this doesn't seem to be used -class BlockStack(misc.Stack): - __super_init = misc.Stack.__init__ - - def __init__(self): - self.__super_init(self) - self.loop = None - def compileFile(filename, display=0): - f = open(filename) + f = open(filename, 'U') buf = f.read() f.close() mod = Module(buf, filename) try: mod.compile(display) - except SyntaxError, err: + except SyntaxError: raise else: f = open(filename + "c", "wb") @@ -134,7 +127,7 @@ def getPycHeader(self): # to indicate the type of the value. simplest way to get the # same effect is to call marshal and then skip the code. mtime = os.path.getmtime(self.filename) - mtime = struct.pack('i', mtime) + mtime = struct.pack('