summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorferrieux <ferrieux@users.sourceforge.net>2014-08-01 16:34:11 (GMT)
committerferrieux <ferrieux@users.sourceforge.net>2014-08-01 16:34:11 (GMT)
commit28c803e0587a6f34716420ed9a3e63dea93b2255 (patch)
treeb111aed5eb37ab357fc42b097745869da90c996a
parent5d6c006a2ce1195737c5d8ce05d7b53e41389005 (diff)
downloadtcl-tip429_only_id.zip
tcl-tip429_only_id.tar.gz
tcl-tip429_only_id.tar.bz2
Recognize that "id" is the K combinator in disguise. Rename it as "K" and extend its semantics accordingly.tip429_only_id
-rw-r--r--generic/tclBasic.c2
-rw-r--r--generic/tclCmdIL.c22
-rw-r--r--generic/tclCompCmdsGR.c31
-rw-r--r--generic/tclInt.h12
4 files changed, 35 insertions, 32 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index edf127d..38c0de3 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -221,10 +221,10 @@ static const CmdInfo builtInCmds[] = {
{"foreach", Tcl_ForeachObjCmd, TclCompileForeachCmd, TclNRForeachCmd, CMD_IS_SAFE},
{"format", Tcl_FormatObjCmd, TclCompileFormatCmd, NULL, CMD_IS_SAFE},
{"global", Tcl_GlobalObjCmd, TclCompileGlobalCmd, NULL, CMD_IS_SAFE},
- {"id", Tcl_IdObjCmd, TclCompileIdCmd, NULL, CMD_IS_SAFE},
{"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},
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index ec6ad14..8b4b859 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.c
@@ -191,14 +191,13 @@ static const EnsembleImplMap defaultInfoMap[] = {
/*
*----------------------------------------------------------------------
*
- * Tcl_IdObjCmd --
+ * Tcl_KObjCmd --
*
- * This procedure is invoked to process the "id" Tcl command. See the
+ * 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 in case of
- * wrong #args, or if the #args is not known at compile time (expand
- * operator).
+ * 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.
@@ -210,17 +209,20 @@ static const EnsembleImplMap defaultInfoMap[] = {
*/
int
-Tcl_IdObjCmd(
+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_WrongNumArgs(interp, 0, objv, "id value");
- return TCL_ERROR;
+ if (objc>=2) {
+ Tcl_SetObjResult(interp, objv[1]);
+ } else {
+ Tcl_Obj *empty;
+
+ TclNewObj(empty);
+ Tcl_SetObjResult(interp, empty);
}
- Tcl_SetObjResult(interp, objv[1]);
return TCL_OK;
}
diff --git a/generic/tclCompCmdsGR.c b/generic/tclCompCmdsGR.c
index 620c2ff..345c19e 100644
--- a/generic/tclCompCmdsGR.c
+++ b/generic/tclCompCmdsGR.c
@@ -163,23 +163,23 @@ TclCompileGlobalCmd(
/*
*----------------------------------------------------------------------
*
- * TclCompileIdCmd --
+ * TclCompileKCmd --
*
- * Procedure called to compile the "id" command.
+ * 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 "id" command at
+ * Instructions are added to envPtr to execute the "K" command at
* runtime.
*
*----------------------------------------------------------------------
*/
int
-TclCompileIdCmd(
+TclCompileKCmd(
Tcl_Interp *interp, /* Used for error reporting. */
Tcl_Parse *parsePtr, /* Points to a parse structure for the command
* created by Tcl_ParseCommand. */
@@ -188,24 +188,25 @@ TclCompileIdCmd(
CompileEnv *envPtr) /* Holds resulting instructions. */
{
/*
- * General syntax: [id value]
+ * General syntax: [K ?value ...?]
*/
int numWords = parsePtr->numWords;
Tcl_Token *wordTokenPtr = TokenAfter(parsePtr->tokenPtr);
DefineLineInformation; /* TIP #280 */
- if (numWords!=2) {
- /*
- * Wrong #args. Clear the error message,
- * and report back to the compiler that this must be interpreted at
- * runtime.
- */
+ if (numWords>=2) {
+ int i;
- Tcl_ResetResult(interp);
- return TCL_ERROR;
+ for (i = 1; i < numWords; i++) {
+ CompileWord(envPtr, wordTokenPtr, interp, i);
+ wordTokenPtr = TokenAfter(wordTokenPtr);
+ if (i>1) {
+ TclEmitOpcode(INST_POP, envPtr);
+ }
+ }
+ } else {
+ PushStringLiteral(envPtr, "");
}
-
- CompileWord(envPtr, wordTokenPtr, interp, numWords-1);
return TCL_OK;
}
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 119b22e..872761e 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3294,9 +3294,6 @@ MODULE_SCOPE int Tcl_GlobalObjCmd(ClientData clientData,
MODULE_SCOPE int Tcl_GlobObjCmd(ClientData clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
-MODULE_SCOPE int Tcl_IdObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc,
- Tcl_Obj *const objv[]);
MODULE_SCOPE int Tcl_IfObjCmd(ClientData clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
@@ -3310,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[]);
@@ -3547,9 +3547,6 @@ MODULE_SCOPE int TclCompileFormatCmd(Tcl_Interp *interp,
MODULE_SCOPE int TclCompileGlobalCmd(Tcl_Interp *interp,
Tcl_Parse *parsePtr, Command *cmdPtr,
struct CompileEnv *envPtr);
-MODULE_SCOPE int TclCompileIdCmd(Tcl_Interp *interp,
- Tcl_Parse *parsePtr, Command *cmdPtr,
- struct CompileEnv *envPtr);
MODULE_SCOPE int TclCompileIfCmd(Tcl_Interp *interp,
Tcl_Parse *parsePtr, Command *cmdPtr,
struct CompileEnv *envPtr);
@@ -3577,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);