[Compiler-sig] Assign nodes

Jeremy Hylton jeremy@zope.com
Tue, 16 Apr 2002 12:47:11 -0400


It looks like the code generator, as you mentioned, has to distinguish
between store and del anyway.  So getting rid of the special case for
load, just means making it a three part default test.

As it happens, the case of names is handled by three separate methods
-- loadName(), storeName(), and delName() -- that are called from the
visitor.  So the separate node types doesn't really buy anything.

Does the following patch look good?

Jeremy

Index: python.asdl
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/ast/python.asdl,v
retrieving revision 1.12
diff -c -c -r1.12 python.asdl
*** python.asdl	16 Apr 2002 03:20:45 -0000	1.12
--- python.asdl	16 Apr 2002 16:43:55 -0000
***************
*** 8,16 ****
  	      | ClassDef(identifier name, expr* bases, stmt* body)
  	      | Return(expr value) | Yield(expr value)
  
! 	      | Del(assign* targets)
! 	      | Assign(assign* targets, expr value)
! 	      | AugAssign(assign target, operator op, expr value)
  
  	      -- not sure if bool is allowed, can always use int
   	      | Print(expr? dest, expr* value, bool nl)
--- 8,16 ----
  	      | ClassDef(identifier name, expr* bases, stmt* body)
  	      | Return(expr value) | Yield(expr value)
  
! 	      | Del(expr* targets)
! 	      | Assign(expr* targets, expr value)
! 	      | AugAssign(expr target, operator op, expr value)
  
  	      -- not sure if bool is allowed, can always use int
   	      | Print(expr? dest, expr* value, bool nl)
***************
*** 55,71 ****
  	     | Num(string n) -- string representation of a number
  	     | Str(string s) -- need to specify raw, unicode, etc?
  	     -- other literals? bools?
! 	     | Attribute(expr value, identifier attr)
! 	     | Subscript(expr value, slice slice)
! 	     | Name(identifier id)
! 	     | List(expr* elts) | Tuple(expr *elts)
! 
! 	-- the subset of expressions that are valid as the target of
! 	-- assignments. 
! 	assign = AssignAttribute(expr value, identifier attr)
! 	     | AssignSubscript(expr value, slice slice)
! 	     | AssignName(identifier id)
! 	     | AssignList(expr* elts) | AssignTuple(expr *elts)
  
          slice = Ellipsis | Slice(expr? lower, expr? upper) 
  	      -- maybe Slice and ExtSlice should be merged...
--- 55,69 ----
  	     | Num(string n) -- string representation of a number
  	     | Str(string s) -- need to specify raw, unicode, etc?
  	     -- other literals? bools?
! 
! 	     -- the following expression can appear in assignment context
! 	     | Attribute(expr value, identifier attr, expr_context ctx)
! 	     | Subscript(expr value, slice slice, expr_context ctx)
! 	     | Name(identifier id, expr_context ctx)
! 	     | List(expr* elts, expr_context ctx) 
! 	     | Tuple(expr *elts, expr_context ctx)
! 
! 	expr_context = Load | Store | Del
  
          slice = Ellipsis | Slice(expr? lower, expr? upper) 
  	      -- maybe Slice and ExtSlice should be merged...
***************
*** 84,90 ****
  
  	-- not sure what to call the first argument for raise and except
  
! 	except = (expr? type, assign? name, stmt* body)
  
  	-- XXX need to handle 'def f((a, b)):'
  	arguments = (identifier* args, identifier? vararg, 
--- 82,88 ----
  
  	-- not sure what to call the first argument for raise and except
  
! 	except = (expr? type, expr? name, stmt* body)
  
  	-- XXX need to handle 'def f((a, b)):'
  	arguments = (identifier* args, identifier? vararg,