lua-users home
lua-l archive

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


>Interesting.  Well, how about an *optional* optimizer, which takes in Lua
>bytecode, looks for optimizations like that, and outputs the optimized
>bytecode.  I don't know much about Lua internals... does that sound
>feasible?

The main point is that there are no such things as tail recursions, because
global names are resolved at runtime.

More precisely, in the code below

 function f(x)
  if a(x) then return b(x) end
  return f(g(x))
 end

By the time f runs and tries to call "itself", the called f might not even be
the original one because a(x) might have changed the value of the global f.
Not likely, but it just shows that the dynamic nature of Lua does make things
more complicated.

>Re: tail calls... can the decision be made at the time of the recursive
>call rather than at compile time?

Now, this could work and we actually discussed this once. We never added it
to the main code because it would ruin debugging, but would it really?
Moreover, it would not do anything for mutually recursive functions.
--lhf