[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: augmented operators (was: implicit parameters)
- From: "Nick Trout" <nick@...>
- Date: Tue, 13 Feb 2001 11:15:22 -0000
Nick Trout wrote:
>
> Have you though about adding augmented operators eg. +=, -= etc in Sol?
>>One may think that it could be faster to execute. But it isn't
if you want the semantic of "a += b" is "a = a + b" (with "a"
evaluated only once). There are two types of storage in Lua/Sol:
tables and locals. For tables you have to perform the two
accesses to the table (read and write) because of possible tag-
methods (get/settable). Nothing to optimize here. Locals could
be optimized with a special instruction but again you have to
consider tag methods for "+" and that reduces the possible
optimization to <numlocvar>+=<num> [1].
One could try to make += and co special operators (ie "incr_by",
"mul_by", ...) with appropriate tag methods. But that requires
references to objects and these only exist for tables, not for
locals. (Btw, the same problem exists for "++" and "--".)
Beside that it would make the language more complicated.
>>Result: you would only get some very expensive syntactic sugar ;)
I hadnt really though about the tag methods complication. From your
description of the implementation I agree it would be quite complicated for
little gain. I had thought it might be faster, but not necessary so it
seems.
Cheers,
Nick.