diff options
Diffstat (limited to 'generic/tclCompCmds.c')
-rw-r--r-- | generic/tclCompCmds.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c index d1d7a80..2140789 100644 --- a/generic/tclCompCmds.c +++ b/generic/tclCompCmds.c @@ -2209,6 +2209,70 @@ TclCompileErrorCmd( /* *---------------------------------------------------------------------- * + * TclCompileEvalCmd -- + * + * Procedure called to compile the "eval" command. + * + * Results: + * Returns TCL_OK for a successful compile. Returns TCL_ERROR to defer + * evaluation to runtime. + * + * Side effects: + * Instructions are added to envPtr to execute the "eval" command at + * runtime. + * + *---------------------------------------------------------------------- + */ + +int +TclCompileEvalCmd( + Tcl_Interp *interp, /* Used for context. */ + Tcl_Parse *parsePtr, /* Points to a parse structure for the command + * created by Tcl_ParseCommand. */ + Command *cmdPtr, /* Points to defintion of command being + * compiled. */ + CompileEnv *envPtr) /* Holds resulting instructions. */ +{ + Tcl_Token *tokenPtr; + DefineLineInformation; /* TIP #280 */ + int i; + + /* + * Error case: no arguments at all. + */ + + if (parsePtr->numWords < 2) { + return TCL_ERROR; + } + + tokenPtr = TokenAfter(parsePtr->tokenPtr); + + /* + * Must push, concatenate (when more than one word) and eval. Note that + * when we evaluate, we must first duplicate to ensure that a reference to + * the script is kept for the duration of the evaluation. + */ + + for (i=1 ; i<parsePtr->numWords ; i++) { + CompileWord(envPtr, tokenPtr, interp, i); + tokenPtr = TokenAfter(tokenPtr); + } + + if (i > 2) { + TclEmitInstInt4( INST_CONCAT_STK, i-1, envPtr); + } + + TclEmitOpcode( INST_DUP, envPtr); + TclEmitOpcode( INST_EVAL_STK, envPtr); + TclEmitInstInt4( INST_REVERSE, 2, envPtr); + TclEmitOpcode( INST_POP, envPtr); + + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * * TclCompileExprCmd -- * * Procedure called to compile the "expr" command. |