summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdAH.c
diff options
context:
space:
mode:
authorandreas_kupries <akupries@shaw.ca>2009-07-14 16:34:08 (GMT)
committerandreas_kupries <akupries@shaw.ca>2009-07-14 16:34:08 (GMT)
commit08604cad04da0d67c84406f99bda814f6a416386 (patch)
tree96331345b305a3ee61ad9c1dfa7f37983ab71540 /generic/tclCmdAH.c
parent02457f7d6507f76fac8b308899e6592ab8214cb3 (diff)
downloadtcl-08604cad04da0d67c84406f99bda814f6a416386.zip
tcl-08604cad04da0d67c84406f99bda814f6a416386.tar.gz
tcl-08604cad04da0d67c84406f99bda814f6a416386.tar.bz2
* generic/tclCompile.c (TclInitCompileEnv, EnterCmdWordIndex,
TclCleanupByteCode, TclCompileScript): * generic/tclExecute.c (TclCompileObj, TclExecuteByteCode): * tclCompile.h (ExtCmdLoc): * tclInt.h (ExtIndex, CFWordBC, CmdFrame): * tclBasic.c (DeleteInterpProc, TclArgumentBCEnter, TclArgumentBCRelease, TclArgumentGet, SAVE_CONTEXT, RESTORE_CONTEXT, NRCoroutineExitCallback, TclNRCoroutineObjCmd): * generic/tclCmdAH.c (TclNRForObjCmd, TclNRForIterCallback, ForNextCallback): * generic/tclCmdMZ.c (TclNRWhileObjCmd): Extended the bytecode compiler initialization to recognize the compilation of whole files (NRE enabled 'source' command) and switch to the counting of absolute lines in that case. Further extended the bytecode compiler to track the start line in the generated information, and modified the bytecode execution to recompile an object if the location as per the calling context doesn't match the location saved in the bytecode. This part could be optimized more by using more memory to keep all possibilities which occur around, or by just adjusting the location information instead of a total recompile. Reworked the handling of literal command arguments in bytecode to be saved (compiler) and used (execution) per command (See the TCL_INVOKE_STK* instructions), and not per the whole bytecode. This, and the previous change remove the problems with location data caused by literal sharing (across whole files, but also proc bodies). Simplified the associated datastructures (ExtIndex is gone, as is the function EnterCmdWordIndex). The last change causes the hashtable 'lineLABCPtr' to be state which has to be kept per coroutine, like the CmdFrame stack. Reworked the coroutine support code to create, delete and switch the information as needed. Further reworked the tailcall command as well, it has to pop its own arguments when run in a bytecode context to keep a proper stack in 'lineLABCPtr'. Fixed the mishandling of line information in the NRE-enabled 'for' and 'while' commands introduced when both were made to share their iteration callbacks without taking into account that the loop body is found in different words of the command. Introduced a separate data structure to hold all the callback information, as we went over the limit of 4 direct client-data values for NRE callbacks. The above fixes [Bug 1605269].
Diffstat (limited to 'generic/tclCmdAH.c')
-rw-r--r--generic/tclCmdAH.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index a00fff8..a3a5841 100644
--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCmdAH.c,v 1.116 2009/03/21 09:42:06 msofer Exp $
+ * RCS: @(#) $Id: tclCmdAH.c,v 1.117 2009/07/14 16:34:08 andreas_kupries Exp $
*/
#include "tclInt.h"
@@ -1852,6 +1852,7 @@ TclNRForObjCmd(
{
int result;
Interp *iPtr = (Interp *) interp;
+ ForIterData* iterPtr;
if (objc != 5) {
Tcl_WrongNumArgs(interp, 1, objv, "start test next command");
@@ -1870,8 +1871,15 @@ TclNRForObjCmd(
return result;
}
- TclNRAddCallback(interp, TclNRForIterCallback, objv[2], objv[4],
- objv[3], "\n (\"for\" body line %d)");
+ TclSmallAllocEx (interp, sizeof(ForIterData), iterPtr);
+ iterPtr->cond = objv[2];
+ iterPtr->body = objv[4];
+ iterPtr->next = objv[3];
+ iterPtr->msg = "\n (\"for\" body line %d)";
+ iterPtr->word = 4;
+
+ TclNRAddCallback(interp, TclNRForIterCallback, iterPtr, NULL,
+ NULL, NULL);
return TCL_OK;
}
@@ -1882,10 +1890,11 @@ TclNRForIterCallback(
int result)
{
Interp *iPtr = (Interp *) interp;
- Tcl_Obj *cond = data[0];
- Tcl_Obj *body = data[1];
- Tcl_Obj *next = data[2];
- char *msg = data[3];
+ ForIterData* iterPtr = data[0];
+ Tcl_Obj *cond = iterPtr->cond;
+ Tcl_Obj *body = iterPtr->body;
+ Tcl_Obj *next = iterPtr->next;
+ char *msg = iterPtr->msg;
int value;
if ((result != TCL_OK) && (result != TCL_CONTINUE)) {
@@ -1901,17 +1910,19 @@ TclNRForIterCallback(
Tcl_ResetResult(interp);
result = Tcl_ExprBooleanObj(interp, cond, &value);
if (result != TCL_OK) {
+ TclSmallFreeEx (interp, iterPtr);
return result;
}
if (value) {
/* TIP #280. */
if (next) {
- TclNRAddCallback(interp, ForNextCallback, cond, body, next, msg);
+ TclNRAddCallback(interp, ForNextCallback, iterPtr, NULL, NULL,
+ NULL);
} else {
- TclNRAddCallback(interp, TclNRForIterCallback, cond, body, NULL,
- msg);
+ TclNRAddCallback(interp, TclNRForIterCallback, iterPtr, NULL, NULL,
+ NULL);
}
- return TclNREvalObjEx(interp, body, 0, iPtr->cmdFramePtr, 2);
+ return TclNREvalObjEx(interp, body, 0, iPtr->cmdFramePtr, iterPtr->word);
}
done:
@@ -1925,6 +1936,7 @@ TclNRForIterCallback(
Tcl_AppendObjToErrorInfo(interp,
Tcl_ObjPrintf(msg, Tcl_GetErrorLine(interp)));
}
+ TclSmallFreeEx (interp, iterPtr);
return result;
}
@@ -1935,10 +1947,8 @@ ForNextCallback(
int result)
{
Interp *iPtr = (Interp *) interp;
- Tcl_Obj *cond = data[0];
- Tcl_Obj *body = data[1];
- Tcl_Obj *next = data[2];
- char *msg = data[3];
+ ForIterData* iterPtr = data[0];
+ Tcl_Obj *next = iterPtr->next;
if ((result == TCL_OK) || (result == TCL_CONTINUE)) {
/*
@@ -1952,12 +1962,13 @@ ForNextCallback(
if ((result != TCL_BREAK) && (result != TCL_OK)) {
if (result == TCL_ERROR) {
Tcl_AddErrorInfo(interp, "\n (\"for\" loop-end command)");
+ TclSmallFreeEx (interp, iterPtr);
}
return result;
}
}
- TclNRAddCallback(interp, TclNRForIterCallback, cond, body, next, msg);
+ TclNRAddCallback(interp, TclNRForIterCallback, iterPtr, NULL, NULL, NULL);
return result;
}