Diff
Not logged in

Differences From Artifact [fbab94c570]:

To Artifact [44232465b2]:


1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892

1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916

1917
1918
1919


1920
1921
1922
1923
1924
1925

1926

1927

1928







1929
1930
1931
1932
1933
1934
1935
}

static int 
CompileCmdCompileProc(
    Tcl_Interp *interp,
    Tcl_Parse *parsePtr,
    Command *cmdPtr,
    int startCodeOffset,
    CompileEnv *envPtr)
{
    int savedNumCmds = envPtr->numCommands;
    int startStackDepth = envPtr->currStackDepth;

    int update = 0;
    DefineLineInformation;

    /*
     * Mark the start of the command; the proper bytecode
     * length will be updated later. There is no need to
     * do this for the first bytecode in the compile env,
     * as the check is done before calling
     * TclNRExecuteByteCode(). Do emit an INST_START_CMD
     * in special cases where the first bytecode is in a
     * loop, to insure that the corresponding command is
     * counted properly. Compilers for commands able to
     * produce such a beast (currently 'while 1' only) set
     * envPtr->atCmdStart to 0 in order to signal this
     * case. [Bug 1752146]
     *
     * Note that the environment is initialised with
     * atCmdStart=1 to avoid emitting ISC for the first
     * command.
     */

    if (envPtr->atCmdStart == 1) {
	if (startCodeOffset) {
	    /*

	     * Increase the number of commands being
	     * started at the current point. Note that
	     * this depends on the exact layout of the


	     * INST_START_CMD's operands, so be careful!
	     */

	    TclIncrUInt4AtPtr(envPtr->codeNext - 4, 1)
	}
    } else if (envPtr->atCmdStart == 0) {

	TclEmitInstInt4(INST_START_CMD, 0, envPtr);

	TclEmitInt4(1, envPtr);

	update = 1;







    }

    if (TCL_OK == cmdPtr->compileProc(interp, parsePtr, cmdPtr, envPtr)) {

#ifdef TCL_COMPILE_DEBUG
	/*
	 * Confirm that the command compiler generated a







<




>
|



<
<
<
<
|
<
<
<
<
|
<

<
<
<
<
|
|
<
<
>
|
<
<
>
>
|
|

<
<
|
>

>
|
>
|
>
>
>
>
>
>
>







1881
1882
1883
1884
1885
1886
1887

1888
1889
1890
1891
1892
1893
1894
1895
1896




1897




1898

1899




1900
1901


1902
1903


1904
1905
1906
1907
1908


1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
}

static int 
CompileCmdCompileProc(
    Tcl_Interp *interp,
    Tcl_Parse *parsePtr,
    Command *cmdPtr,

    CompileEnv *envPtr)
{
    int savedNumCmds = envPtr->numCommands;
    int startStackDepth = envPtr->currStackDepth;
    int startCodeOffset = envPtr->codeNext - envPtr->codeStart;
    int incrOffset = -1;
    DefineLineInformation;

    /*




     * Emit of the INST_START_CMD instruction is controlled by




     * the value of envPtr->atCmdStart:

     *




     * atCmdStart == 2	: We are not using the INST_START_CMD instruction.
     * atCmdStart == 1	: INST_START_CMD was the last instruction emitted.


     *			: We do not need to emit another.  Instead we
     *			: increment the number of cmds started at it (except


     *			: for the special case at the start of a script.)
     * atCmdStart == 0	: The last instruction was something else.  We need
     *			: to emit INST_START_CMD here.
     */



    switch (envPtr->atCmdStart) {
    case 0:
	TclEmitInstInt4(INST_START_CMD, 0, envPtr);
	incrOffset = envPtr->codeNext - envPtr->codeStart;
	TclEmitInt4(0, envPtr);
	break;
    case 1:
	if (envPtr->codeNext > envPtr->codeStart) {
	    incrOffset = envPtr->codeNext - 4 - envPtr->codeStart;
	}
	break;
    case 2:
	/* Nothing to do */
	;
    }

    if (TCL_OK == cmdPtr->compileProc(interp, parsePtr, cmdPtr, envPtr)) {

#ifdef TCL_COMPILE_DEBUG
	/*
	 * Confirm that the command compiler generated a
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952

1953
1954
1955
1956
1957

1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978

	if (diff != 1) {
	    Tcl_Panic("bad stack adjustment when compiling"
		    " %.*s (was %d instead of 1)", parsePtr->tokenPtr->size,
		    parsePtr->tokenPtr->start, diff);
	}
#endif
	if (update) {
	    /*
	     * Fix the bytecode length.

	     */

	    unsigned char *fixPtr = envPtr->codeStart + startCodeOffset + 1;
	    unsigned fixLen = envPtr->codeNext - fixPtr + 1;


	    TclStoreInt4AtPtr(fixLen, fixPtr);
	}
	return TCL_OK;
    }

    if (envPtr->atCmdStart == 1 && startCodeOffset != 0) {
	/*
	 * Decrease the number of commands being started
	 * at the current point. Note that this depends on
	 * the exact layout of the INST_START_CMD's
	 * operands, so be careful!
	 */

	TclIncrUInt4AtPtr(envPtr->codeNext - 4, -1);
    }

    /*
     * Restore numCommands, codeNext, and currStackDepth  to their
     * correct values, removing any commands compiled before the
     * failure to produce bytecode got reported.
     * [Bugs 705406, 735055, 3614102]







|

|
>

<
|
|

>
|


<
<
<
<
<
<
<
<
<
<
<







1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948

1949
1950
1951
1952
1953
1954
1955











1956
1957
1958
1959
1960
1961
1962

	if (diff != 1) {
	    Tcl_Panic("bad stack adjustment when compiling"
		    " %.*s (was %d instead of 1)", parsePtr->tokenPtr->size,
		    parsePtr->tokenPtr->start, diff);
	}
#endif
	if (incrOffset >= 0) {
	    /*
	     * We successfully compiled a command.  Increment the number
	     * of commands that start at the currently active INST_START_CMD.
	     */

	    unsigned char *incrPtr = envPtr->codeStart + incrOffset;
	    unsigned char *startPtr = incrPtr - 5;

	    TclIncrUInt4AtPtr(incrPtr, 1);
	    TclStoreInt4AtPtr(envPtr->codeNext - startPtr, startPtr + 1);
	}
	return TCL_OK;











    }

    /*
     * Restore numCommands, codeNext, and currStackDepth  to their
     * correct values, removing any commands compiled before the
     * failure to produce bytecode got reported.
     * [Bugs 705406, 735055, 3614102]
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
		cmdPtr = NULL;
	    }
	}
    }

    /* If cmdPtr != NULL, we will try to call cmdPtr->compileProc */
    if (cmdPtr) {
	code = CompileCmdCompileProc(interp, parsePtr, cmdPtr,
		startCodeOffset, envPtr);
    }

    if (code == TCL_ERROR) {
	if (expand < 0) {
	    expand = ExpandRequested(parsePtr->tokenPtr, parsePtr->numWords);
	}








|
<







2049
2050
2051
2052
2053
2054
2055
2056

2057
2058
2059
2060
2061
2062
2063
		cmdPtr = NULL;
	    }
	}
    }

    /* If cmdPtr != NULL, we will try to call cmdPtr->compileProc */
    if (cmdPtr) {
	code = CompileCmdCompileProc(interp, parsePtr, cmdPtr, envPtr);

    }

    if (code == TCL_ERROR) {
	if (expand < 0) {
	    expand = ExpandRequested(parsePtr->tokenPtr, parsePtr->numWords);
	}