[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Confused about proper tail calls
- From: "Tai Meng" <tmeng@...>
- Date: Wed, 1 Oct 2003 11:41:55 -0700
Thanks for the pointers. I actually did step through that particular function during its execution, and got confused when I got to that line.
If function B made a tail call, Lua seems to skip over its activation record in two different ways (when calling lua_getstack()).
Case 1: If function A called (not a tail call) function B, and function B made tail calls, info about function B is lost. However, lua_getstack() returns 1 for function B anyway, so that we can eventually get to the activation record of A.
Case 2: On the other hand, if B was the main chunk (and no function called it), and B made a tail call, lua_getstack() will return 0 for B because there are no more functions to return to after we come back to B.
Am I making sense so far?
I still wonder if there is a known patch to treat both cases like case 1. Case 1 allows the display of a complete call stack (though missing information), which is good to have in a debugger.
From: RLake@oxfam.org.uk [mailto:RLake@oxfam.org.uk]
Sent: Tuesday, September 30, 2003 12:37 PM
To: Tai Meng
Subject: RE: Confused about proper tail calls
> Do you know if chunks behave differently when making tail calls?
I was going to say "no", but I checked the code (always an option for you
The loop at ldebug.c line 103, and in particular that line, lead me to
believe that the first call frame is handled differently. Now, what the
first call frame is depends on how you are calling the script, so I don't
really have enough information to say one way or another.
A chunk is just a function, though. That is clear enough.
You might want to use luac -l to take a look at the VM code generated for
your test script, in order to convince yourself (or not) that it is a
tailcall. You can tell because the opcode will be TAILCALL :)