Commit 23b6ae3a authored by Shane Hathaway's avatar Shane Hathaway
parent b96890a7
...@@ -613,16 +613,16 @@ def twobyte(val): ...@@ -613,16 +613,16 @@ def twobyte(val):
class LineAddrTable: class LineAddrTable:
"""lnotab """lnotab
This class builds the lnotab, which is undocumented but described This class builds the lnotab, which is documented in compile.c.
by com_set_lineno in compile.c. Here's an attempt at explanation: Here's a brief recap:
For each SET_LINENO instruction after the first one, two bytes are For each SET_LINENO instruction after the first one, two bytes are
added to lnotab. (In some cases, multiple two-byte entries are added to lnotab. (In some cases, multiple two-byte entries are
added.) The first byte is the distance in bytes between the added.) The first byte is the distance in bytes between the
instruction for the last SET_LINENO and the current SET_LINENO. instruction for the last SET_LINENO and the current SET_LINENO.
The second byte is offset in line numbers. If either offset is The second byte is offset in line numbers. If either offset is
greater than 255, multiple two-byte entries are added -- one entry greater than 255, multiple two-byte entries are added -- see
for each factor of 255. compile.c for the delicate details.
""" """
def __init__(self): def __init__(self):
...@@ -657,19 +657,16 @@ class LineAddrTable: ...@@ -657,19 +657,16 @@ class LineAddrTable:
# compiler because it only generates a SET_LINENO instruction # compiler because it only generates a SET_LINENO instruction
# for the assignment. # for the assignment.
if line > 0: if line > 0:
while addr > 0 or line > 0: push = self.lnotab.append
# write the values in 1-byte chunks that sum while addr > 255:
# to desired value push(255); push(0)
trunc_addr = addr addr -= 255
trunc_line = line while line > 255:
if trunc_addr > 255: push(addr); push(255)
trunc_addr = 255 line -= 255
if trunc_line > 255: addr = 0
trunc_line = 255 if addr > 0 or line > 0:
self.lnotab.append(trunc_addr) push(addr); push(line)
self.lnotab.append(trunc_line)
addr = addr - trunc_addr
line = line - trunc_line
self.lastline = lineno self.lastline = lineno
self.lastoff = self.codeOffset self.lastoff = self.codeOffset
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment