From 381cd0bed1a0ed9421eb1f5a0d368ec95024fd23 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Fri, 3 Jan 2014 09:46:40 +1000 Subject: tailcall: properly merge tailcall frames Resolve the tailcall command immediately in [tailcall] and stash it. If a tailcall is currently being evaluated, new tailcalls in the same frame are merged/deferred to evaluate in the same C stack frame. Can't merge tailcall evaluations across uplevel. Add some tests for these cases Signed-off-by: Steve Bennett --- jim.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'jim.h') diff --git a/jim.h b/jim.h index 60a24a2..27c1e53 100644 --- a/jim.h +++ b/jim.h @@ -443,6 +443,9 @@ typedef struct Jim_CallFrame { Jim_Obj *fileNameObj; /* file and line of caller of this proc (if available) */ int line; Jim_Stack *localCommands; /* commands to be destroyed when the call frame is destroyed */ + int tailcall; /* non-zero if a tailcall is being evaluated at this level */ + struct Jim_Obj *tailcallObj; /* Pending tailcall invocation */ + struct Jim_Cmd *tailcallCmd; /* Resolved command for pending tailcall invocation */ } Jim_CallFrame; /* The var structure. It just holds the pointer of the referenced @@ -524,7 +527,6 @@ typedef struct Jim_Interp { int (*signal_set_result)(struct Jim_Interp *interp, jim_wide sigmask); /* Set a result for the sigmask */ Jim_CallFrame *framePtr; /* Pointer to the current call frame */ Jim_CallFrame *topFramePtr; /* toplevel/global frame pointer. */ - Jim_Obj *resolveNsObj; /* If not NULL, resolve the next command in this namespace - for tailcall */ struct Jim_HashTable commands; /* Commands hash table */ unsigned long procEpoch; /* Incremented every time the result of procedures names lookup caching -- cgit v1.1