[Compiler-sig] Re: Lvalue

Jeremy Hylton jeremy@zope.com
Sun, 14 Apr 2002 00:04:33 -0400


>>>>> "FB" == Finn Bock <bckfnn@worldonline.dk> writes:

  FB> [Jeremy]
  >> The Lvalue node captures the notion that a limited subset of
  >> expressions can occur in two contexts -- as an expression or as
  >> the target of an assignment.

  FB> Ok, but is it important to express that notion in the AST
  FB> typesystem?  I'm sure you have given this more though than I
  FB> have, but I tend to disagree. Maybe it is just that I loath to
  FB> see AST like:

  FB> :
  FB> Expr[value=Lvalue[lvalue=Attribute[value=Lvalue[lvalue=Name[id=A]],
  FB> attr=b]]]

  FB> to capture the expression "A.b".

I was (am?) undecided about whether the typesystem should express the
limitation on expressions that are targets of assignments.  The
example above seems a strong argument against an explicit lvalue
type. 

I wonder, though, if we might have a separate set of constructors for
the assign type.  Perhaps instead of LValue we have AssignAttribute,
AssignName, etc.  The AST from the compiler package in the std library
uses this approach, although I don't like the names it uses.  (I don't
like the names I just used either.)

It seems useful to distinguish the two cases, because they are handled
differently inside the compiler.  The bytecode generated is
different, and there needs to be some way for the code generator to
distinguish the cases.  Using LValue or just Expr means that the code
generator needs to track context explicitly to see if the LValue is
being used as an expression or an assignment.  If the constructor is
different for the two cases, there is no need to track the context
separately. 

Jeremy