[Python-checkins] CVS: python/dist/src/Tools/compiler/compiler pycodegen.py,1.37,1.38

Jeremy Hylton jhylton@users.sourceforge.net
Thu, 12 Apr 2001 14:04:45 -0700


Update of /cvsroot/python/python/dist/src/Tools/compiler/compiler
In directory usw-pr-cvs1:/tmp/cvs-serv15065/compiler

Modified Files:
	pycodegen.py 
Log Message:
Use new _implicitNameOp() to generate name op code for list comprehensions.

Always emit a SET_LINENO 0 at the beginning of the module.  The
builtin compiler does this, and it's much easier to compare bytecode
generated by the two compilers if they both do.

Move the SET_LINENO inside the FOR_LOOP block for list
comprehensions.  Also for compat. with builtin compiler.


Index: pycodegen.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/compiler/compiler/pycodegen.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -r1.37 -r1.38
*** pycodegen.py	2001/04/12 20:24:26	1.37
--- pycodegen.py	2001/04/12 21:04:43	1.38
***************
*** 194,197 ****
--- 194,209 ----
              self.emit(prefix + '_GLOBAL', name)
  
+     def _implicitNameOp(self, prefix, name):
+         """Emit name ops for names generated implicitly by for loops
+ 
+         The interpreter generates names that start with a period or
+         dollar sign.  The symbol table ignores these names because
+         they aren't present in the program text.
+         """
+         if self.optimized:
+             self.emit(prefix + '_FAST', name)
+         else:
+             self.emit(prefix + '_NAME', name)
+ 
      def set_lineno(self, node, force=0):
          """Emit SET_LINENO if node has lineno attribute and it is 
***************
*** 222,225 ****
--- 234,238 ----
  
      def visitModule(self, node):
+         self.emit('SET_LINENO', 0)
          lnf = walk(node.node, self.NameFinder(), 0)
          self.locals.push(lnf.getLocals())
***************
*** 422,426 ****
          self.emit('DUP_TOP')
          self.emit('LOAD_ATTR', 'append')
!         self.emit('STORE_FAST', append)
          
          stack = []
--- 435,439 ----
          self.emit('DUP_TOP')
          self.emit('LOAD_ATTR', 'append')
!         self._implicitNameOp('STORE', append)
          
          stack = []
***************
*** 434,438 ****
              stack.insert(0, (start, cont, anchor))
  
!         self.emit('LOAD_FAST', append)
          self.visit(node.expr)
          self.emit('CALL_FUNCTION', 1)
--- 447,451 ----
              stack.insert(0, (start, cont, anchor))
  
!         self._implicitNameOp('LOAD', append)
          self.visit(node.expr)
          self.emit('CALL_FUNCTION', 1)
***************
*** 448,452 ****
              self.emit('JUMP_ABSOLUTE', start)
              self.startBlock(anchor)
!         self.emit('DELETE_FAST', append)
          
          self.__list_count = self.__list_count - 1
--- 461,465 ----
              self.emit('JUMP_ABSOLUTE', start)
              self.startBlock(anchor)
!         self._implicitNameOp('DELETE', append)
          
          self.__list_count = self.__list_count - 1
***************
*** 458,463 ****
          self.visit(node.list)
          self.visit(ast.Const(0))
-         self.emit('SET_LINENO', node.lineno)
          self.nextBlock(start)
          self.emit('FOR_LOOP', anchor)
          self.nextBlock()
--- 471,476 ----
          self.visit(node.list)
          self.visit(ast.Const(0))
          self.nextBlock(start)
+         self.emit('SET_LINENO', node.lineno)
          self.emit('FOR_LOOP', anchor)
          self.nextBlock()