Compare commits

...
4 changed files with 96 additions and 0 deletions
+1
View File
@@ -224,6 +224,7 @@ static const CmdInfo builtInCmds[] = {
{"if", Tcl_IfObjCmd, TclCompileIfCmd, TclNRIfObjCmd, CMD_IS_SAFE},
{"incr", Tcl_IncrObjCmd, TclCompileIncrCmd, NULL, CMD_IS_SAFE},
{"join", Tcl_JoinObjCmd, NULL, NULL, CMD_IS_SAFE},
{"K", Tcl_KObjCmd, TclCompileKCmd, NULL, CMD_IS_SAFE},
{"lappend", Tcl_LappendObjCmd, TclCompileLappendCmd, NULL, CMD_IS_SAFE},
{"lassign", Tcl_LassignObjCmd, TclCompileLassignCmd, NULL, CMD_IS_SAFE},
{"lindex", Tcl_LindexObjCmd, TclCompileLindexCmd, NULL, CMD_IS_SAFE},
+38
View File
@@ -188,6 +188,44 @@ static const EnsembleImplMap defaultInfoMap[] = {
{NULL, NULL, NULL, NULL, NULL, 0}
};
/*
*----------------------------------------------------------------------
*
* Tcl_KObjCmd --
*
* This procedure is invoked to process the "K" Tcl command. See the
* user documentation for details on what it does.
*
* With the bytecode compiler, this procedure is only called when the
* #args is not known at compile time (expand operator).
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
int
Tcl_KObjCmd(
ClientData dummy, /* Not used. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
if (objc>=2) {
Tcl_SetObjResult(interp, objv[1]);
} else {
Tcl_Obj *empty;
TclNewObj(empty);
Tcl_SetObjResult(interp, empty);
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
+51
View File
@@ -160,6 +160,57 @@ TclCompileGlobalCmd(
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* TclCompileKCmd --
*
* Procedure called to compile the "K" combinator 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 "K" command at
* runtime.
*
*----------------------------------------------------------------------
*/
int
TclCompileKCmd(
Tcl_Interp *interp, /* Used for error reporting. */
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. */
{
/*
* General syntax: [K ?value ...?]
*/
int numWords = parsePtr->numWords;
Tcl_Token *wordTokenPtr = TokenAfter(parsePtr->tokenPtr);
DefineLineInformation; /* TIP #280 */
if (numWords>=2) {
int i;
for (i = 1; i < numWords; i++) {
CompileWord(envPtr, wordTokenPtr, interp, i);
wordTokenPtr = TokenAfter(wordTokenPtr);
if (i>1) {
TclEmitOpcode(INST_POP, envPtr);
}
}
} else {
PushStringLiteral(envPtr, "");
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
+6
View File
@@ -3307,6 +3307,9 @@ MODULE_SCOPE int Tcl_InterpObjCmd(ClientData clientData,
MODULE_SCOPE int Tcl_JoinObjCmd(ClientData clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
MODULE_SCOPE int Tcl_KObjCmd(ClientData clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
MODULE_SCOPE int Tcl_LappendObjCmd(ClientData clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
@@ -3571,6 +3574,9 @@ MODULE_SCOPE int TclCompileInfoObjectNamespaceCmd(Tcl_Interp *interp,
MODULE_SCOPE int TclCompileIncrCmd(Tcl_Interp *interp,
Tcl_Parse *parsePtr, Command *cmdPtr,
struct CompileEnv *envPtr);
MODULE_SCOPE int TclCompileKCmd(Tcl_Interp *interp,
Tcl_Parse *parsePtr, Command *cmdPtr,
struct CompileEnv *envPtr);
MODULE_SCOPE int TclCompileLappendCmd(Tcl_Interp *interp,
Tcl_Parse *parsePtr, Command *cmdPtr,
struct CompileEnv *envPtr);