lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


One of the reasons is that each new operator would require a new
overload metamethod. In Python for example, you need
separate overloads for x = x + y and x += y (__add__ and __iadd__).
Python has 13 of these extra, largely redundant overload methods.
Each new operator also needs a new opcode and makes the
VM larger.

This is why my preference is to implement compound assignment as a strict parser patch --  essentially just making:

  <lvalue> += <expr> syntax sugar for 
  <lvalue> = <lvalue> + (<expr>)

The semantics do get complicated when the lvalue is a complex _expression_; i.e.

  get_object(name).v.x+=2

In that case, you probably want to put get_object(name).v in a temporary register, so the semantics become:

 do
    local temp =get_object(name).v
    temp.x = temp.x + 2
 end

But, writing a parser mod that does this is doable -- if a little tricky.

Ian's 5.1 compound assignment patch is quite different than mine, in that it works by adding Python-like mutation operations to the VM.  It's a heavier weight approach, but one that avoids the need for any temporary register nonsense related to complex lvalues.

-Sven