diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-12-31 18:17:44 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-12-31 18:17:44 (GMT) |
commit | accb62b28e1d592733b2f678d5737ca3e8c64fc2 (patch) | |
tree | 0b892dc477d250aba141fbf29f63004ac027c8c7 /Lib/compiler/pyassem.py | |
parent | 436eadd4555b3172ab366b5a2381085ffc941614 (diff) | |
download | cpython-accb62b28e1d592733b2f678d5737ca3e8c64fc2.zip cpython-accb62b28e1d592733b2f678d5737ca3e8c64fc2.tar.gz cpython-accb62b28e1d592733b2f678d5737ca3e8c64fc2.tar.bz2 |
SF patch [ 597919 ] compiler package and SET_LINENO
A variety of changes from Michael Hudson to get the compiler working
with 2.3. The primary change is the handling of SET_LINENO:
# The set_lineno() function and the explicit emit() calls for
# SET_LINENO below are only used to generate the line number table.
# As of Python 2.3, the interpreter does not have a SET_LINENO
# instruction. pyassem treats SET_LINENO opcodes as a special case.
A few other small changes:
- Remove unused code from pycodegen and pyassem.
- Fix error handling in parsermodule. When PyParser_SimplerParseString()
fails, it sets an exception with detailed info. The parsermodule
was clobbering that exception and replacing it was a generic
"could not parse string" exception. Keep the original exception.
Diffstat (limited to 'Lib/compiler/pyassem.py')
-rw-r--r-- | Lib/compiler/pyassem.py | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/Lib/compiler/pyassem.py b/Lib/compiler/pyassem.py index 10a8dbd..0547eeb 100644 --- a/Lib/compiler/pyassem.py +++ b/Lib/compiler/pyassem.py @@ -6,15 +6,8 @@ import sys 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 @@ class FlowGraph: 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 @@ class 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 @@ class PyFlowGraph(FlowGraph): 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 @@ class PyFlowGraph(FlowGraph): 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 @@ class PyFlowGraph(FlowGraph): 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 @@ class LineAddrTable: # 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 @@ class StackDepthTracker: # PRINT_EXPR? 'PRINT_ITEM': -1, 'RETURN_VALUE': -1, + 'YIELD_VALUE': -1, 'EXEC_STMT': -3, 'BUILD_CLASS': -2, 'STORE_NAME': -1, |