Tcl Source Code

Check-in [65e5d46da8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:A bit more tidying...
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-e711ffb458
Files: files | file ages | folders
SHA1: 65e5d46da8c7eb694edae92e0cd244456f64d441
User & Date: dgp 2014-12-18 22:25:27
Context
2014-12-19
03:31
Narrow scope of numVars. check-in: 90eb0b4cbb user: dgp tags: bug-e711ffb458
2014-12-18
22:25
A bit more tidying... check-in: 65e5d46da8 user: dgp tags: bug-e711ffb458
22:13
No need for a loopIndex. check-in: f58fb59cab user: dgp tags: bug-e711ffb458
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclCompCmds.c.

1536
1537
1538
1539
1540
1541
1542

1543
1544
1545
1546
1547
1548
1549
    CompileEnv *envPtr)		/* Holds resulting instructions. */
{
    Proc *procPtr = envPtr->procPtr;
    ForeachInfo *infoPtr = NULL;/* Points to the structure describing this
				 * foreach command. Stored in a AuxData
				 * record in the ByteCode. */
    Tcl_Token *tokenPtr, *bodyTokenPtr;

    unsigned char *jumpPc;
    JumpFixup jumpFalseFixup;
    int jumpBackDist, jumpBackOffset, infoIndex, range;
    int numWords, numLists, numVars, tempVar, i, j, code = TCL_OK;
    int savedStackDepth = envPtr->currStackDepth;
    Tcl_Obj *varListObj = NULL;
    DefineLineInformation;	/* TIP #280 */







>







1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
    CompileEnv *envPtr)		/* Holds resulting instructions. */
{
    Proc *procPtr = envPtr->procPtr;
    ForeachInfo *infoPtr = NULL;/* Points to the structure describing this
				 * foreach command. Stored in a AuxData
				 * record in the ByteCode. */
    Tcl_Token *tokenPtr, *bodyTokenPtr;
    Tcl_Token token[2];
    unsigned char *jumpPc;
    JumpFixup jumpFalseFixup;
    int jumpBackDist, jumpBackOffset, infoIndex, range;
    int numWords, numLists, numVars, tempVar, i, j, code = TCL_OK;
    int savedStackDepth = envPtr->currStackDepth;
    Tcl_Obj *varListObj = NULL;
    DefineLineInformation;	/* TIP #280 */
1589
1590
1591
1592
1593
1594
1595


1596
1597
1598
1599
1600
1601
1602
    /*
     * Parse each var list into sequence of var names. Don't
     * compile the foreach inline if any var name needs substitutions or isn't
     * a scalar, or if any var list needs substitutions.
     */

    varListObj = Tcl_NewObj();


    for (i = 0, tokenPtr = parsePtr->tokenPtr;
	    i < numWords-1;
	    i++, tokenPtr = TokenAfter(tokenPtr)) {
	ForeachVarList *varListPtr;

	if (i%2 != 1) {
	    continue;







>
>







1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
    /*
     * Parse each var list into sequence of var names. Don't
     * compile the foreach inline if any var name needs substitutions or isn't
     * a scalar, or if any var list needs substitutions.
     */

    varListObj = Tcl_NewObj();
    token[0].type = TCL_TOKEN_SIMPLE_WORD;
    token[0].numComponents = 1;
    for (i = 0, tokenPtr = parsePtr->tokenPtr;
	    i < numWords-1;
	    i++, tokenPtr = TokenAfter(tokenPtr)) {
	ForeachVarList *varListPtr;

	if (i%2 != 1) {
	    continue;
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
		sizeof(ForeachVarList) + numVars*sizeof(int));
	varListPtr->numVars = numVars;
	infoPtr->varLists[i/2] = varListPtr;
	infoPtr->numLists++;

	for (j = 0;  j < numVars;  j++) {
	    Tcl_Obj *varNameObj;
	    Tcl_Token token[2];
	    int varIndex, isSimple, isScalar;

	    Tcl_ListObjIndex(NULL, varListObj, j, &varNameObj);
	    token[0].type = TCL_TOKEN_SIMPLE_WORD;
	    token[0].numComponents = 1;
	    token[1].start = Tcl_GetStringFromObj(varNameObj, &token[1].size);
	    PushVarNameWord(interp, token, envPtr, TCL_CREATE_VAR,
		&varIndex, &isSimple, &isScalar, 0 /* ignored */);
	    if (!isScalar || varIndex < 0) {
		code = TCL_ERROR;
		goto done;
	    }
	    varListPtr->varIndexes[j] = varIndex;
	}

	Tcl_SetObjLength(varListObj, 0);
    }

    /*
     * We will compile the foreach command. Reserve (numLists + 1) temporary
     * variables:
     *    - numLists temps to hold each value list
     *    - 1 temp for the loop counter (index of next element in each list)
     *
     * At this time we don't try to reuse temporaries; if there are two
     * nonoverlapping foreach loops, they don't share any temps.
     */








<



<
<









<




|
<







1622
1623
1624
1625
1626
1627
1628

1629
1630
1631


1632
1633
1634
1635
1636
1637
1638
1639
1640

1641
1642
1643
1644
1645

1646
1647
1648
1649
1650
1651
1652
		sizeof(ForeachVarList) + numVars*sizeof(int));
	varListPtr->numVars = numVars;
	infoPtr->varLists[i/2] = varListPtr;
	infoPtr->numLists++;

	for (j = 0;  j < numVars;  j++) {
	    Tcl_Obj *varNameObj;

	    int varIndex, isSimple, isScalar;

	    Tcl_ListObjIndex(NULL, varListObj, j, &varNameObj);


	    token[1].start = Tcl_GetStringFromObj(varNameObj, &token[1].size);
	    PushVarNameWord(interp, token, envPtr, TCL_CREATE_VAR,
		&varIndex, &isSimple, &isScalar, 0 /* ignored */);
	    if (!isScalar || varIndex < 0) {
		code = TCL_ERROR;
		goto done;
	    }
	    varListPtr->varIndexes[j] = varIndex;
	}

	Tcl_SetObjLength(varListObj, 0);
    }

    /*
     * Reserve (numLists + 1) temporary variables:

     *    - numLists temps to hold each value list
     *    - 1 temp for the loop counter (index of next element in each list)
     *
     * At this time we don't try to reuse temporaries; if there are two
     * nonoverlapping foreach loops, they don't share any temps.
     */