[Python-checkins] r65758 - in python/branches/tlee-ast-optimize/Lib: compiler/pyassem.py dis.py
thomas.lee
python-checkins at python.org
Sun Aug 17 14:39:26 CEST 2008
Author: thomas.lee
Date: Sun Aug 17 14:39:25 2008
New Revision: 65758
Log:
Fix a couple of tests broken by the lnotab changes.
Modified:
python/branches/tlee-ast-optimize/Lib/compiler/pyassem.py
python/branches/tlee-ast-optimize/Lib/dis.py
Modified: python/branches/tlee-ast-optimize/Lib/compiler/pyassem.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/compiler/pyassem.py (original)
+++ python/branches/tlee-ast-optimize/Lib/compiler/pyassem.py Sun Aug 17 14:39:25 2008
@@ -662,8 +662,6 @@
self.code = []
self.codeOffset = 0
self.firstline = 0
- self.lastline = 0
- self.lastoff = 0
self.lnotab = []
def addCode(self, *args):
@@ -674,40 +672,14 @@
def nextLine(self, lineno):
if self.firstline == 0:
self.firstline = lineno
- self.lastline = lineno
else:
- # compute deltas
- addr = self.codeOffset - self.lastoff
- line = lineno - self.lastline
- # Python assumes that lineno always increases with
- # increasing bytecode address (lnotab is unsigned char).
- # Depending on when SET_LINENO instructions are emitted
- # this is not always true. Consider the code:
- # a = (1,
- # b)
- # In the bytecode stream, the assignment to "a" occurs
- # 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:
- push = self.lnotab.append
- while addr > 255:
- push(255); push(0)
- addr -= 255
- while line > 255:
- push(addr); push(255)
- line -= 255
- addr = 0
- if addr > 0 or line > 0:
- push(addr); push(line)
- self.lastline = lineno
- self.lastoff = self.codeOffset
+ self.lnotab.append((self.codeOffset, lineno))
def getCode(self):
return ''.join(self.code)
def getTable(self):
- return ''.join(map(chr, self.lnotab))
+ return self.lnotab
class StackDepthTracker:
# XXX 1. need to keep track of stack depth on jumps
Modified: python/branches/tlee-ast-optimize/Lib/dis.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/dis.py (original)
+++ python/branches/tlee-ast-optimize/Lib/dis.py Sun Aug 17 14:39:25 2008
@@ -180,21 +180,11 @@
Generate pairs (offset, lineno) as described in Python/compile.c.
"""
- byte_increments = [ord(c) for c in code.co_lnotab[0::2]]
- line_increments = [ord(c) for c in code.co_lnotab[1::2]]
-
- lastlineno = None
- lineno = code.co_firstlineno
- addr = 0
- for byte_incr, line_incr in zip(byte_increments, line_increments):
- if byte_incr:
- if lineno != lastlineno:
- yield (addr, lineno)
- lastlineno = lineno
- addr += byte_incr
- lineno += line_incr
- if lineno != lastlineno:
- yield (addr, lineno)
+ lastline = None
+ for addr, line in code.co_lnotab:
+ if line != lastline:
+ yield (addr, line)
+ lastline = line
def _test():
"""Simple test program to disassemble a file."""
More information about the Python-checkins
mailing list