summaryrefslogtreecommitdiffstats
path: root/Lib/compiler/pyassem.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-09-01 20:47:37 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-09-01 20:47:37 (GMT)
commit92f397209055a0ae7599e5a7ea202f19fae8fd7b (patch)
treeb9d2a72d6e90c065cc7fa7ff6351fa7dd39424ff /Lib/compiler/pyassem.py
parent3620857d60e000300d5fa475fa9404bc535b536f (diff)
downloadcpython-92f397209055a0ae7599e5a7ea202f19fae8fd7b.zip
cpython-92f397209055a0ae7599e5a7ea202f19fae8fd7b.tar.gz
cpython-92f397209055a0ae7599e5a7ea202f19fae8fd7b.tar.bz2
patch by Neil Schemenauer to improve (fix?) line number generation
Diffstat (limited to 'Lib/compiler/pyassem.py')
-rw-r--r--Lib/compiler/pyassem.py41
1 files changed, 26 insertions, 15 deletions
diff --git a/Lib/compiler/pyassem.py b/Lib/compiler/pyassem.py
index c8d9e90..74ea562 100644
--- a/Lib/compiler/pyassem.py
+++ b/Lib/compiler/pyassem.py
@@ -419,21 +419,32 @@ class LineAddrTable:
# compute deltas
addr = self.codeOffset - self.lastoff
line = lineno - self.lastline
- while addr > 0 or line > 0:
- # write the values in 1-byte chunks that sum
- # to desired value
- trunc_addr = addr
- trunc_line = line
- if trunc_addr > 255:
- trunc_addr = 255
- if trunc_line > 255:
- trunc_line = 255
- self.lnotab.append(trunc_addr)
- self.lnotab.append(trunc_line)
- addr = addr - trunc_addr
- line = line - trunc_line
- self.lastline = lineno
- self.lastoff = self.codeOffset
+ # 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:
+ while addr > 0 or line > 0:
+ # write the values in 1-byte chunks that sum
+ # to desired value
+ trunc_addr = addr
+ trunc_line = line
+ if trunc_addr > 255:
+ trunc_addr = 255
+ if trunc_line > 255:
+ trunc_line = 255
+ self.lnotab.append(trunc_addr)
+ self.lnotab.append(trunc_line)
+ addr = addr - trunc_addr
+ line = line - trunc_line
+ self.lastline = lineno
+ self.lastoff = self.codeOffset
def getCode(self):
return string.join(self.code, '')