--- a/generic/tclProc.c
+++ b/generic/tclProc.c
@@ -35,6 +35,7 @@
Tcl_Obj *copyPtr);
static void FreeLambdaInternalRep(Tcl_Obj *objPtr);
static int InitArgsAndLocals(Tcl_Interp *interp, int skip);
+static void AddTypedLocals(Proc *procPtr, void *sig);
static void InitResolvedLocals(Tcl_Interp *interp,
ByteCode *codePtr, Var *defPtr,
Namespace *nsPtr);
@@ -403,6 +404,55 @@
}
/*
+ * v16s : les champs d'une signature typée deviennent des variables locales
+ * compilées (après « args »), à chaque compilation du corps
+ * (TclProcCompileProc) : la liaison les trouve par leur indice, sans
+ * recherche par le nom ni table de variables du cadre.
+ */
+static void
+AddTypedLocals(
+ Proc *procPtr,
+ void *sig)
+{
+ Tcl_Obj **names;
+ Tcl_Size n = TclTypedSigLocals(sig, &names), i;
+
+ for (i = 0; i < n; i++) {
+ Tcl_Size len;
+ const char *name = TclGetStringFromObj(names[i], &len);
+ CompiledLocal *localPtr;
+
+ for (localPtr = procPtr->firstLocalPtr; localPtr != NULL;
+ localPtr = localPtr->nextPtr) {
+ if (localPtr->nameLength == len
+ && memcmp(localPtr->name, name, len) == 0) {
+ break;
+ }
+ }
+ if (localPtr != NULL) {
+ continue; /* déjà là (args) */
+ }
+ localPtr = (CompiledLocal *)Tcl_Alloc(offsetof(CompiledLocal, name)
+ + 1U + len);
+ localPtr->nextPtr = NULL;
+ localPtr->nameLength = len;
+ localPtr->frameIndex = procPtr->numCompiledLocals;
+ localPtr->flags = 0;
+ localPtr->defValuePtr = NULL;
+ localPtr->resolveInfo = NULL;
+ memcpy(localPtr->name, name, len);
+ localPtr->name[len] = '\0';
+ if (procPtr->firstLocalPtr == NULL) {
+ procPtr->firstLocalPtr = procPtr->lastLocalPtr = localPtr;
+ } else {
+ procPtr->lastLocalPtr->nextPtr = localPtr;
+ procPtr->lastLocalPtr = localPtr;
+ }
+ procPtr->numCompiledLocals++;
+ }
+}
+
+/*
*----------------------------------------------------------------------
*
* TclCreateProc --
@@ -1480,10 +1530,18 @@
varPtr->flags = 0;
if (defPtr && defPtr->flags & VAR_IS_ARGS) {
- Tcl_Obj *listPtr = Tcl_NewListObj((argCt>i)? argCt-i : 0, argObjs+i);
+ if (procPtr->typedSig != NULL && numArgs == 1
+ && TclTypedSigTakesWords(procPtr->typedSig)) {
+ /* v16s : une signature typée lit les mots dans le cadre ;
+ * pas de liste « args » à faire puis défaire */
+ varPtr->value.objPtr = NULL;
+ } else {
+ Tcl_Obj *listPtr = Tcl_NewListObj((argCt>i)? argCt-i : 0,
+ argObjs+i);
- varPtr->value.objPtr = listPtr;
- Tcl_IncrRefCount(listPtr); /* Local var is a reference. */
+ varPtr->value.objPtr = listPtr;
+ Tcl_IncrRefCount(listPtr); /* Local var is a reference. */
+ }
} else if (argCt == numArgs) {
Tcl_Obj *objPtr = argObjs[i];
@@ -2084,6 +2142,9 @@
}
procPtr->numCompiledLocals = procPtr->numArgs;
}
+ if (procPtr->typedSig != NULL) {
+ AddTypedLocals(procPtr, procPtr->typedSig); /* v16s */
+ }
(void) TclPushStackFrame(interp, &framePtr, (Tcl_Namespace *) nsPtr,
/* isProcCallFrame */ 0);