tailcall: Fix to avoid tailcalls consuming C stack frames
commit0d5a208e9240218757e0d4658f9b0d14a4263831
authorSteve Bennett <steveb@workware.net.au>
Thu, 2 Apr 2020 10:43:55 +0000 (2 20:43 +1000)
committerSteve Bennett <steveb@workware.net.au>
Thu, 2 Apr 2020 11:52:20 +0000 (2 21:52 +1000)
tree769fb1ab1a54ae9bd67d5f5d85012f29704b18c9
parentbd7037fdd108729999cfb32a1304abd0eec1d1ad
tailcall: Fix to avoid tailcalls consuming C stack frames

The purpose of a tailcall is to avoid using additional stack frames,
however although were were not creating an extra Tcl callframe we were
using C stack frames through the call sequence:

JimCallProcedure -> Jim_EvalObjList -> JimInvokeCommand -> JimCallProcedure

This meant that a large number of tailcalls would overflow the stack.
Instead we need to have JimCallProcedure return to JimInvokeCommand
where the tailcall can be handled by a subsequent call to JimCallProcedure.

Signed-off-by: Steve Bennett <steveb@workware.net.au>
jim.c
tests/apply.test
tests/tailcall.test