lua-users home
lua-l archive

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


On Tue, Mar 29, 2011 at 7:36 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> tuple[3] A,B  -> expands to local A_1,A_2,A_3,B_1,B_2,B_3

I too have been thinking about this type of solution [1].

[1] http://lua-users.org/wiki/SourcePreprocessing

On Tue, Mar 29, 2011 at 3:30 PM, Francesco Abbate
<francesco.bbt@gmail.com> wrote:
> I understood that what I proposed cannot work because in
> order to perform the right arithmetic operation the Lua VM inspect the
> TValue and there isn't any way it can figure out that the value is
> part of a vector or not.

I don't see why this is a problem.  In the following case:

  -- input
  local a[2], b[2], c[2], d = ...
  c = a + b * d + f()

you know at compile time which operations must be interpreted as
vector operations because the lexical variables are statically typed
as vector.  The above would be translated into

  -- output
  local a1,a2, b1,b2, c1,c2,  d = ...
  local _tmp1 = f()  -- assume scalar if not explicit
  c1 = a1 + b1 * d + _tmp1
  c2 = a2 + b2 * d + _tmp1