[Python-checkins] CVS: python/dist/src/Tools/compiler/compiler pyassem.py,1.10,1.11 pycodegen.py,1.23,1.24

Jeremy Hylton python-dev@python.org
Fri, 1 Sep 2000 13:47:40 -0700


Update of /cvsroot/python/python/dist/src/Tools/compiler/compiler
In directory slayer.i.sourceforge.net:/tmp/cvs-serv6990/compiler

Modified Files:
	pyassem.py pycodegen.py 
Log Message:
patch by Neil Schemenauer to improve (fix?) line number generation


Index: pyassem.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/compiler/compiler/pyassem.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** pyassem.py	2000/08/12 20:32:46	1.10
--- pyassem.py	2000/09/01 20:47:37	1.11
***************
*** 420,438 ****
              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
  
      def getCode(self):
--- 420,449 ----
              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:
!                 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):

Index: pycodegen.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/compiler/compiler/pycodegen.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** pycodegen.py	2000/09/01 20:33:26	1.23
--- pycodegen.py	2000/09/01 20:47:37	1.24
***************
*** 71,74 ****
--- 71,75 ----
          self.curStack = 0
          self.maxStack = 0
+         self.last_lineno = None
          self._setupGraphDelegation()
  
***************
*** 108,112 ****
  
      def set_lineno(self, node):
!         """Emit SET_LINENO if node has lineno attribute
  
          Returns true if SET_LINENO was emitted.
--- 109,114 ----
  
      def set_lineno(self, node):
!         """Emit SET_LINENO if node has lineno attribute and it is 
!         different than the last lineno emitted.
  
          Returns true if SET_LINENO was emitted.
***************
*** 118,123 ****
          """
          lineno = getattr(node, 'lineno', None)
!         if lineno is not None:
              self.emit('SET_LINENO', lineno)
              return 1
          return 0
--- 120,126 ----
          """
          lineno = getattr(node, 'lineno', None)
!         if lineno is not None and lineno != self.last_lineno:
              self.emit('SET_LINENO', lineno)
+             self.last_lineno = lineno
              return 1
          return 0
***************
*** 415,418 ****
--- 418,422 ----
  
      def visitName(self, node):
+         self.set_lineno(node)
          self.loadName(node.name)