lua-users home
lua-l archive

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


Hi.

> Now, about OP_TAILCALL. As I mentioned earlier I managed to avoid 
recursive
> calls to luaD_call in the cases Bret calls "direct" invocations, 
but in the
> process I discovered a nasty surprise: OP_TAILCALL as implemented 
in the
> original luaV_execute is not a tail-call at all (as normally 
intended in
> functional programming languages), since it grows the C-stack. I 
thought I
> could make it a real tail call but I did not manage to even in my 
version
> which does not use the C stack. I could have made a big mistake, 
but it
> would appear that the Lua compiler (!?!?) actually expects 
OP_TAILCALL to
> create an extra frame in the calling stack, therefore invalidating 
all my
> attempts at reusing the current one, as customary when dealing with 
tail
> calls. Can anybody comment on this?

Well, tailcalls have been my worst case in making Lua stackless. 
Since they basicly do the job of a call and a return in the same 
opcode, this tends to go agains making lua stackless. So what i did, 
was to add a flag fiels to the state of the Lua VM, that i push on 
calls. One of thoes flags indicate, that we are on a tailcall, so 
when i return from the call, i then see the flag indicating that it 
was not an ordinary call but a tailcall, so i simulate another 
function return to carry down the parameters.

I could always post my code. But it's messy modified Lua code, so i 
don't know if anyone wants to see that. :)

> 
> 
> Now Sebby:
> 
> > 		_asm
> > 		{
> > 			mov esp, Stack;
> > 		}
> >
> 
> Thanks a lot for your sample. It's really inspiring. Alas, this 
little trick
> it's the reason why I cannot use the strategy then: the code must be
> platform independent and I am not sure how to change this for the 
port to
> Risc machines. Anyway, I'll keep in mind that this is a possibility.

Tnx. 

Well, unless there is some Ansi-C compatible way of changing the 
stack pointer, i don't think there is a cross-platform way of doing 
this. On Risc, it should be as easy to do however, it should look 
something like

asm { mov sp, Stack }

or something like that. 

Sebastien St-Laurent
Software Engineer, Z-Axis ltd.
sebby@z-axis.com