Diff
Not logged in

Differences From Artifact [6410ac943a]:

To Artifact [90a5c9bbad]:


177
178
179
180
181
182
183
184

185
186

187
188
189
190
191

192
193

194
195
196
197
198
199
200
177
178
179
180
181
182
183

184
185

186
187
188
189
190

191
192

193
194
195
196
197
198
199
200







-
+

-
+




-
+

-
+







     */

    procName = TclGetString(objv[1]);
    TclGetNamespaceForQualName(interp, procName, NULL, 0,
	    &nsPtr, &altNsPtr, &cxtNsPtr, &simpleName);

    if (nsPtr == NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"can't create procedure \"%s\": unknown namespace",
		procName));
		procName);
	Tcl_SetErrorCode(interp, "TCL", "VALUE", "COMMAND", (void *)NULL);
	return TCL_ERROR;
    }
    if (simpleName == NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"can't create procedure \"%s\": bad procedure name",
		procName));
		procName);
	Tcl_SetErrorCode(interp, "TCL", "VALUE", "COMMAND", (void *)NULL);
	return TCL_ERROR;
    }

    /*
     * Create the data structure to represent the procedure.
     */
490
491
492
493
494
495
496
497

498
499
500

501
502
503
504
505
506
507
490
491
492
493
494
495
496

497
498
499

500
501
502
503
504
505
506
507







-
+


-
+







    result = TclListObjGetElements(interp, argsPtr, &numArgs, &argArray);
    if (result != TCL_OK) {
	goto procError;
    }

    if (precompiled) {
	if (numArgs > procPtr->numArgs) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    TclPrintfResult(interp,
		    "procedure \"%s\": arg list contains %" TCL_SIZE_MODIFIER "d entries, "
		    "precompiled header expects %" TCL_SIZE_MODIFIER "d", procName, numArgs,
		    procPtr->numArgs));
		    procPtr->numArgs);
	    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC",
		    "BYTECODELIES", (void *)NULL);
	    goto procError;
	}
	localPtr = procPtr->firstLocalPtr;
    } else {
	procPtr->numArgs = numArgs;
519
520
521
522
523
524
525
526
527
528



529
530
531
532
533
534
535
536
537

538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554

555
556

557
558
559
560
561
562
563
564



565
566
567
568
569
570
571
572
573
519
520
521
522
523
524
525



526
527
528


529
530
531
532
533


534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550

551
552

553
554
555
556
557
558



559
560
561


562
563
564
565
566
567
568







-
-
-
+
+
+
-
-





-
-
+
















-
+

-
+





-
-
-
+
+
+
-
-








	result = TclListObjGetElements(interp, argArray[i], &fieldCount,
		&fieldValues);
	if (result != TCL_OK) {
	    goto procError;
	}
	if (fieldCount > 2) {
	    Tcl_Obj *errorObj = Tcl_NewStringObj(
		"too many fields in argument specifier \"", -1);
	    Tcl_AppendObjToObj(errorObj, argArray[i]);
	    TclPrintfResult(interp,
		    "too many fields in argument specifier \"%s\"",
		    TclGetString(argArray[i]));
	    Tcl_AppendToObj(errorObj, "\"", -1);
	    Tcl_SetObjResult(interp, errorObj);
	    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC",
		    "FORMALARGUMENTFORMAT", (void *)NULL);
	    goto procError;
	}
	if ((fieldCount == 0) || (Tcl_GetCharLength(fieldValues[0]) == 0)) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "argument with no name", -1));
	    TclSetResult(interp, "argument with no name");
	    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC",
		    "FORMALARGUMENTFORMAT", (void *)NULL);
	    goto procError;
	}

	argname = TclGetStringFromObj(fieldValues[0], &nameLength);

	/*
	 * Check that the formal parameter name is a scalar.
	 */

	argnamei = argname;
	argnamelast = (nameLength > 0) ? (argname + nameLength - 1) : argname;
	while (argnamei < argnamelast) {
	    if (*argnamei == '(') {
		if (*argnamelast == ')') { /* We have an array element. */
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    TclPrintfResult(interp,
			    "formal parameter \"%s\" is an array element",
			    TclGetString(fieldValues[0])));
			    TclGetString(fieldValues[0]));
		    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC",
			    "FORMALARGUMENTFORMAT", (void *)NULL);
		    goto procError;
		}
	    } else if (argnamei[0] == ':' && argnamei[1] == ':') {
		Tcl_Obj *errorObj = Tcl_NewStringObj(
			"formal parameter \"", -1);
		Tcl_AppendObjToObj(errorObj, fieldValues[0]);
		TclPrintfResult(interp,
			"formal parameter \"%s\" is not a simple name",
			TclGetString(fieldValues[0]));
		Tcl_AppendToObj(errorObj, "\" is not a simple name", -1);
		Tcl_SetObjResult(interp, errorObj);
		Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC",
			"FORMALARGUMENTFORMAT", (void *)NULL);
		goto procError;
	    }
	    argnamei++;
	}

585
586
587
588
589
590
591
592

593
594

595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612


613
614
615

616

617
618
619
620
621
622
623
580
581
582
583
584
585
586

587
588

589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605


606
607



608

609
610
611
612
613
614
615
616







-
+

-
+
















-
-
+
+
-
-
-
+
-
+








	    if ((localPtr->nameLength != nameLength)
		    || (memcmp(localPtr->name, argname, nameLength) != 0)
		    || (localPtr->frameIndex != i)
		    || !(localPtr->flags & VAR_ARGUMENT)
		    || (localPtr->defValuePtr == NULL && fieldCount == 2)
		    || (localPtr->defValuePtr != NULL && fieldCount != 2)) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		TclPrintfResult(interp,
			"procedure \"%s\": formal parameter %" TCL_SIZE_MODIFIER "d is "
			"inconsistent with precompiled body", procName, i));
			"inconsistent with precompiled body", procName, i);
		Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC",
			"BYTECODELIES", (void *)NULL);
		goto procError;
	    }

	    /*
	     * Compare the default value if any.
	     */

	    if (localPtr->defValuePtr != NULL) {
		Tcl_Size tmpLength, valueLength;
		const char *tmpPtr = TclGetStringFromObj(localPtr->defValuePtr, &tmpLength);
		const char *value = TclGetStringFromObj(fieldValues[1], &valueLength);

		if ((valueLength != tmpLength)
			|| memcmp(value, tmpPtr, tmpLength) != 0) {
		    Tcl_Obj *errorObj = Tcl_ObjPrintf(
			    "procedure \"%s\": formal parameter \"", procName);
		    TclPrintfResult(interp,
			    "procedure \"%s\": formal parameter \"%s\" has "
		    Tcl_AppendObjToObj(errorObj, fieldValues[0]);
		    Tcl_AppendToObj(errorObj, "\" has "
			"default value inconsistent with precompiled body", -1);
			    "default value inconsistent with precompiled body",
		    Tcl_SetObjResult(interp, errorObj);
			    procName, TclGetString(fieldValues[0]));
		    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC",
			    "BYTECODELIES", (void *)NULL);
		    goto procError;
		}
	    }
	    if ((i == numArgs - 1)
		    && (localPtr->nameLength == 4)
838
839
840
841
842
843
844
845

846
847
848
849
850
851
852
831
832
833
834
835
836
837

838
839
840
841
842
843
844
845







-
+







	    }
	}
    }
badLevel:
    if (name == NULL) {
	name = objPtr ? TclGetString(objPtr) : "1" ;
    }
    Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad level \"%s\"", name));
    TclPrintfResult(interp, "bad level \"%s\"", name);
    Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LEVEL", name, (void *)NULL);
    return -1;
}

/*
 *----------------------------------------------------------------------
 *
1850
1851
1852
1853
1854
1855
1856
1857

1858
1859

1860
1861
1862
1863
1864
1865
1866
1843
1844
1845
1846
1847
1848
1849

1850
1851

1852
1853
1854
1855
1856
1857
1858
1859







-
+

-
+







    case TCL_CONTINUE:
    case TCL_BREAK:
	/*
	 * It's an error to get to this point from a 'break' or 'continue', so
	 * transform to an error now.
	 */

	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"invoked \"%s\" outside of a loop",
		((result == TCL_BREAK) ? "break" : "continue")));
		((result == TCL_BREAK) ? "break" : "continue"));
	Tcl_SetErrorCode(interp, "TCL", "RESULT", "UNEXPECTED", (void *)NULL);
	result = TCL_ERROR;

	/* FALLTHRU */

    case TCL_ERROR:
	/*
1933
1934
1935
1936
1937
1938
1939
1940
1941

1942
1943
1944
1945
1946
1947
1948
1926
1927
1928
1929
1930
1931
1932


1933
1934
1935
1936
1937
1938
1939
1940







-
-
+







		&& (codePtr->nsEpoch == nsPtr->resolverEpoch)
		&& ((codePtr->procPtr == procPtr) || !bodyPtr->bytes)) {
	    return TCL_OK;
	}

	if (codePtr->flags & TCL_BYTECODE_PRECOMPILED) {
	    if ((Interp *) *codePtr->interpHandle != iPtr) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(
			"a precompiled script jumped interps", -1));
		TclSetResult(interp, "a precompiled script jumped interps");
		Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC",
			"CROSSINTERPBYTECODE", (void *)NULL);
		return TCL_ERROR;
	    }
	    codePtr->compileEpoch = iPtr->compileEpoch;
	    codePtr->nsPtr = nsPtr;
	} else {
2451
2452
2453
2454
2455
2456
2457
2458

2459
2460

2461
2462
2463
2464
2465
2466

2467
2468

2469
2470
2471
2472
2473
2474
2475
2443
2444
2445
2446
2447
2448
2449

2450
2451

2452
2453
2454
2455
2456
2457

2458
2459

2460
2461
2462
2463
2464
2465
2466
2467







-
+

-
+





-
+

-
+







    /*
     * Convert objPtr to list type first; if it cannot be converted, or if its
     * length is not 2, then it cannot be converted to lambdaType.
     */

    result = TclListObjLength(NULL, objPtr, &objc);
    if ((result != TCL_OK) || ((objc != 2) && (objc != 3))) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"can't interpret \"%s\" as a lambda expression",
		Tcl_GetString(objPtr)));
		Tcl_GetString(objPtr));
	Tcl_SetErrorCode(interp, "TCL", "VALUE", "LAMBDA", (void *)NULL);
	return TCL_ERROR;
    }
    result = TclListObjGetElements(NULL, objPtr, &objc, &objv);
    if ((result != TCL_OK) || ((objc != 2) && (objc != 3))) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"can't interpret \"%s\" as a lambda expression",
		TclGetString(objPtr)));
		TclGetString(objPtr));
	Tcl_SetErrorCode(interp, "TCL", "VALUE", "LAMBDA", (void *)NULL);
	return TCL_ERROR;
    }

    argsPtr = objv[0];
    bodyPtr = objv[1];