summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-03-11 13:34:58 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-03-11 13:34:58 (GMT)
commite5fe428a4336e7ec7bf809c207bbf610877bb21e (patch)
treef71782055f7c14e54ddda6c49f0f4cc3718a1180
parent3eba98913e01126f1d8215c1bf6dbca778a273cb (diff)
downloadtcl-e5fe428a4336e7ec7bf809c207bbf610877bb21e.zip
tcl-e5fe428a4336e7ec7bf809c207bbf610877bb21e.tar.gz
tcl-e5fe428a4336e7ec7bf809c207bbf610877bb21e.tar.bz2
clarify 'yieldparameter'. Eliminate variable 'unused', reduce coroutine stackspace
-rw-r--r--generic/tclBasic.c25
-rw-r--r--generic/tclExecute.c4
2 files changed, 13 insertions, 16 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index ae7a3dc..1131a09 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -233,8 +233,8 @@ MODULE_SCOPE const TclStubs tclStubs;
* after particular kinds of [yield].
*/
-#define CORO_ACTIVATE_YIELD PTR2INT(NULL)
-#define CORO_ACTIVATE_YIELDM PTR2INT(NULL)+1
+#define CORO_ACTIVATE_YIELD (0)
+#define CORO_ACTIVATE_YIELDM (1)
#define COROUTINE_ARGUMENTS_SINGLE_OPTIONAL (-1)
#define COROUTINE_ARGUMENTS_ARBITRARY (-2)
@@ -9724,9 +9724,6 @@ TclNRCoroutineActivateCallback(
TCL_UNUSED(int) /*result*/)
{
CoroutineData *corPtr = (CoroutineData *)data[0];
- int type = PTR2INT(data[1]);
- int numLevels, unused;
- int *stackLevel = &unused;
if (!corPtr->stackLevel) {
/*
@@ -9743,8 +9740,8 @@ TclNRCoroutineActivateCallback(
* the interp's environment to make it suitable to run this coroutine.
*/
- corPtr->stackLevel = stackLevel;
- numLevels = corPtr->auxNumLevels;
+ corPtr->stackLevel = &corPtr;
+ int numLevels = corPtr->auxNumLevels;
corPtr->auxNumLevels = iPtr->numLevels;
SAVE_CONTEXT(corPtr->caller);
@@ -9757,7 +9754,7 @@ TclNRCoroutineActivateCallback(
* Coroutine is active: yield
*/
- if (corPtr->stackLevel != stackLevel) {
+ if (corPtr->stackLevel != &corPtr) {
NRE_callback *runPtr;
iPtr->execEnvPtr = corPtr->callerEEPtr;
@@ -9781,6 +9778,7 @@ TclNRCoroutineActivateCallback(
return TCL_ERROR;
}
+ int type = PTR2INT(data[1]);
if (type == CORO_ACTIVATE_YIELD) {
corPtr->nargs = COROUTINE_ARGUMENTS_SINGLE_OPTIONAL;
} else if (type == CORO_ACTIVATE_YIELDM) {
@@ -9792,7 +9790,7 @@ TclNRCoroutineActivateCallback(
corPtr->yieldPtr = NULL;
corPtr->stackLevel = NULL;
- numLevels = iPtr->numLevels;
+ int numLevels = iPtr->numLevels;
iPtr->numLevels = corPtr->auxNumLevels;
corPtr->auxNumLevels = numLevels - corPtr->auxNumLevels;
@@ -9939,7 +9937,6 @@ TclNRCoroInjectObjCmd(
Tcl_Obj *const objv[])
{
CoroutineData *corPtr;
- ExecEnv *savedEEPtr = iPtr->execEnvPtr;
/*
* Usage more or less like tailcall:
@@ -9968,6 +9965,7 @@ TclNRCoroInjectObjCmd(
* to happen when the coro is resumed.
*/
+ ExecEnv *savedEEPtr = iPtr->execEnvPtr;
iPtr->execEnvPtr = corPtr->eePtr;
TclNRAddCallback(interp, InjectHandler, corPtr,
Tcl_NewListObj(objc - 2, objv + 2), INT2PTR(corPtr->nargs), NULL);
@@ -9983,10 +9981,9 @@ TclNRCoroProbeObjCmd(
int objc,
Tcl_Obj *const objv[])
{
- CoroutineData *corPtr;
ExecEnv *savedEEPtr = iPtr->execEnvPtr;
- int numLevels, unused;
- int *stackLevel = &unused;
+ int numLevels;
+ CoroutineData *corPtr;
/*
* Usage more or less like tailcall:
@@ -10036,7 +10033,7 @@ TclNRCoroProbeObjCmd(
* the interp's environment to make it suitable to run this coroutine.
*/
- corPtr->stackLevel = stackLevel;
+ corPtr->stackLevel = &corPtr;
numLevels = corPtr->auxNumLevels;
corPtr->auxNumLevels = iPtr->numLevels;
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 0279218..a890d83 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -2453,7 +2453,7 @@ TEBCresume(
fflush(stdout);
}
#endif
- yieldParameter = 0;
+ yieldParameter = PTR2INT(NULL); /*==CORO_ACTIVATE_YIELD*/
Tcl_SetObjResult(interp, OBJ_AT_TOS);
goto doYield;
@@ -2508,7 +2508,7 @@ TEBCresume(
TclSetTailcall(interp, valuePtr);
corPtr->yieldPtr = valuePtr;
iPtr->execEnvPtr = corPtr->eePtr;
- yieldParameter = (PTR2INT(NULL)+1); /*==CORO_ACTIVATE_YIELDM*/
+ yieldParameter = PTR2INT(NULL)+1; /*==CORO_ACTIVATE_YIELDM*/
doYield:
/* TIP #280: Record the last piece of info needed by