[Python-checkins] CVS: python/dist/src/Tools/compiler/compiler consts.py,1.2,1.3 pyassem.py,1.25,1.26 pycodegen.py,1.48,1.49

Jeremy Hylton jhylton@users.sourceforge.net
Thu, 30 Aug 2001 13:25:57 -0700


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

Modified Files:
	consts.py pyassem.py pycodegen.py 
Log Message:
Fix _convert_NAME() so that it doesn't store locals for class bodies.

Fix list comp code generation -- emit GET_ITER instead of Const(0)
after the list.

Add CO_GENERATOR flag to generators.

Get CO_xxx flags from the new module



Index: consts.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/compiler/compiler/consts.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** consts.py	2001/04/12 06:39:24	1.2
--- consts.py	2001/08/30 20:25:54	1.3
***************
*** 1,5 ****
! # code flags
! CO_VARARGS = 1
! CO_VARKEYWORDS = 2
  
  # operation flags
--- 1,4 ----
! from new import * # import all the CO_xxx flags
! del classobj, code, function, instance, instancemethod, module
  
  # operation flags

Index: pyassem.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/compiler/compiler/pyassem.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** pyassem.py	2001/08/29 22:27:14	1.25
--- pyassem.py	2001/08/30 20:25:54	1.26
***************
*** 8,11 ****
--- 8,13 ----
  
  from compiler import misc
+ from compiler.consts import CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, \
+      CO_VARKEYWORDS
  
  def xxx_sort(l):
***************
*** 312,320 ****
  
  # flags for code objects
- CO_OPTIMIZED = 0x0001
- CO_NEWLOCALS = 0x0002
- CO_VARARGS = 0x0004
- CO_VARKEYWORDS = 0x0008
- CO_NESTED = 0x0010
  
  # the FlowGraph is transformed in place; it exists in one of these states
--- 314,317 ----
***************
*** 504,508 ****
  
      def _convert_NAME(self, arg):
!         self._lookupName(arg, self.varnames)
          return self._lookupName(arg, self.names)
      _convert_STORE_NAME = _convert_NAME
--- 501,506 ----
  
      def _convert_NAME(self, arg):
!         if self.klass is None:
!             self._lookupName(arg, self.varnames)
          return self._lookupName(arg, self.names)
      _convert_STORE_NAME = _convert_NAME
***************
*** 740,746 ****
          # PRINT_EXPR?
          'PRINT_ITEM': -1,
-         'LOAD_LOCALS': 1,
          'RETURN_VALUE': -1,
!         'EXEC_STMT': -2,
          'BUILD_CLASS': -2,
          'STORE_NAME': -1,
--- 738,743 ----
          # PRINT_EXPR?
          'PRINT_ITEM': -1,
          'RETURN_VALUE': -1,
!         'EXEC_STMT': -3,
          'BUILD_CLASS': -2,
          'STORE_NAME': -1,
***************
*** 757,760 ****
--- 754,758 ----
          'SETUP_EXCEPT': 3,
          'SETUP_FINALLY': 3,
+         'FOR_ITER': 1,
          }
      # use pattern match

Index: pycodegen.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/compiler/compiler/pycodegen.py,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** pycodegen.py	2001/08/30 15:50:34	1.48
--- pycodegen.py	2001/08/30 20:25:55	1.49
***************
*** 12,17 ****
  from compiler import pyassem, misc, future, symbols
  from compiler.consts import SC_LOCAL, SC_GLOBAL, SC_FREE, SC_CELL
! from compiler.pyassem import CO_VARARGS, CO_VARKEYWORDS, CO_NEWLOCALS,\
!      CO_NESTED, TupleArg
  
  # Do we have Python 1.x or Python 2.x?
--- 12,18 ----
  from compiler import pyassem, misc, future, symbols
  from compiler.consts import SC_LOCAL, SC_GLOBAL, SC_FREE, SC_CELL
! from compiler.consts import CO_VARARGS, CO_VARKEYWORDS, CO_NEWLOCALS,\
!      CO_NESTED, CO_GENERATOR
! from compiler.pyassem import TupleArg
  
  # Do we have Python 1.x or Python 2.x?
***************
*** 496,503 ****
  
          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()
          self.visit(node.assign)
--- 497,504 ----
  
          self.visit(node.list)
!         self.emit('GET_ITER')
          self.nextBlock(start)
          self.emit('SET_LINENO', node.lineno)
!         self.emit('FOR_ITER', anchor)
          self.nextBlock()
          self.visit(node.assign)
***************
*** 1200,1203 ****
--- 1201,1206 ----
          self.graph.setFreeVars(self.scope.get_free_vars())
          self.graph.setCellVars(self.scope.get_cell_vars())
+         if self.scope.generator is not None:
+             self.graph.setFlag(CO_GENERATOR)
  ##        self.graph.setFlag(CO_NESTED)