summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2007-08-28 16:24:25 (GMT)
committerdgp <dgp@users.sourceforge.net>2007-08-28 16:24:25 (GMT)
commit7ea40c818db9bc2997da24992b2a40ef4a84d49a (patch)
treec8bea2a07ec8649d5d772a266ac94e7953061109
parentd3ff1482b1385c013d986d55057ff030df30e4ac (diff)
downloadtcl-7ea40c818db9bc2997da24992b2a40ef4a84d49a.zip
tcl-7ea40c818db9bc2997da24992b2a40ef4a84d49a.tar.gz
tcl-7ea40c818db9bc2997da24992b2a40ef4a84d49a.tar.bz2
* generic/tclBasic.c: Used unions to better clarify overloading of
* generic/tclCompExpr.c: the fields of the OpCmdInfo and * generic/tclCompile.h: TclOpCmdClientData structs.
-rw-r--r--ChangeLog6
-rw-r--r--generic/tclBasic.c81
-rw-r--r--generic/tclCompExpr.c16
-rw-r--r--generic/tclCompile.h7
4 files changed, 72 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index e4109ca..90b375a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-08-28 Don Porter <dgp@users.sourceforge.net>
+
+ * generic/tclBasic.c: Used unions to better clarify overloading of
+ * generic/tclCompExpr.c: the fields of the OpCmdInfo and
+ * generic/tclCompile.h: TclOpCmdClientData structs.
+
2007-08-27 Don Porter <dgp@users.sourceforge.net>
* generic/tclCompExpr.c: Call TclCompileSyntaxError() when
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 4605847..cea8816 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclBasic.c,v 1.265 2007/08/14 15:17:49 dgp Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.266 2007/08/28 16:24:28 dgp Exp $
*/
#include "tclInt.h"
@@ -273,36 +273,63 @@ typedef struct {
const char *name; /* Name of object-based command. */
Tcl_ObjCmdProc *objProc; /* Object-based function for command. */
CompileProc *compileProc; /* Function called to compile command. */
- int numArgs;
+ union {
+ int numArgs;
+ int identity;
+ } i;
const char *expected; /* For error message, what argument(s)
* were expected. */
} OpCmdInfo;
static const OpCmdInfo mathOpCmds[] = {
- { "~", TclSingleOpCmd, TclCompileInvertOpCmd, 1, "integer" },
- { "!", TclSingleOpCmd, TclCompileNotOpCmd, 1, "boolean" },
- { "+", TclVariadicOpCmd, TclCompileAddOpCmd, 0, NULL },
- { "*", TclVariadicOpCmd, TclCompileMulOpCmd, 1, NULL },
- { "&", TclVariadicOpCmd, TclCompileAndOpCmd, -1, NULL },
- { "|", TclVariadicOpCmd, TclCompileOrOpCmd, 0, NULL },
- { "^", TclVariadicOpCmd, TclCompileXorOpCmd, 0, NULL },
- { "**", TclVariadicOpCmd, TclCompilePowOpCmd, 1, NULL },
- { "<<", TclSingleOpCmd, TclCompileLshiftOpCmd, 2, "integer shift" },
- { ">>", TclSingleOpCmd, TclCompileRshiftOpCmd, 2, "integer shift" },
- { "%", TclSingleOpCmd, TclCompileModOpCmd, 2, "integer integer" },
- { "!=", TclSingleOpCmd, TclCompileNeqOpCmd, 2, "value value"},
- { "ne", TclSingleOpCmd, TclCompileStrneqOpCmd, 2, "value value" },
- { "in", TclSingleOpCmd, TclCompileInOpCmd, 2, "value list"},
- { "ni", TclSingleOpCmd, TclCompileNiOpCmd, 2, "value list"},
- { "-", TclNoIdentOpCmd, TclCompileMinusOpCmd, 0, "value ?value ...?"},
- { "/", TclNoIdentOpCmd, TclCompileDivOpCmd, 0, "value ?value ...?"},
- { "<", TclSortingOpCmd, TclCompileLessOpCmd, 0, NULL },
- { "<=", TclSortingOpCmd, TclCompileLeqOpCmd, 0, NULL },
- { ">", TclSortingOpCmd, TclCompileGreaterOpCmd, 0, NULL },
- { ">=", TclSortingOpCmd, TclCompileGeqOpCmd, 0, NULL },
- { "==", TclSortingOpCmd, TclCompileEqOpCmd, 0, NULL },
- { "eq", TclSortingOpCmd, TclCompileStreqOpCmd, 0, NULL },
- { NULL, NULL, NULL, 0, NULL }
+ { "~", TclSingleOpCmd, TclCompileInvertOpCmd,
+ /* numArgs */ {1}, "integer" },
+ { "!", TclSingleOpCmd, TclCompileNotOpCmd,
+ /* numArgs */ {1}, "boolean" },
+ { "+", TclVariadicOpCmd, TclCompileAddOpCmd,
+ /* identity */ {0}, NULL },
+ { "*", TclVariadicOpCmd, TclCompileMulOpCmd,
+ /* identity */ {1}, NULL },
+ { "&", TclVariadicOpCmd, TclCompileAndOpCmd,
+ /* identity */ {-1}, NULL },
+ { "|", TclVariadicOpCmd, TclCompileOrOpCmd,
+ /* identity */ {0}, NULL },
+ { "^", TclVariadicOpCmd, TclCompileXorOpCmd,
+ /* identity */ {0}, NULL },
+ { "**", TclVariadicOpCmd, TclCompilePowOpCmd,
+ /* identity */ {1}, NULL },
+ { "<<", TclSingleOpCmd, TclCompileLshiftOpCmd,
+ /* numArgs */ {2}, "integer shift" },
+ { ">>", TclSingleOpCmd, TclCompileRshiftOpCmd,
+ /* numArgs */ {2}, "integer shift" },
+ { "%", TclSingleOpCmd, TclCompileModOpCmd,
+ /* numArgs */ {2}, "integer integer" },
+ { "!=", TclSingleOpCmd, TclCompileNeqOpCmd,
+ /* numArgs */ {2}, "value value"},
+ { "ne", TclSingleOpCmd, TclCompileStrneqOpCmd,
+ /* numArgs */ {2}, "value value" },
+ { "in", TclSingleOpCmd, TclCompileInOpCmd,
+ /* numArgs */ {2}, "value list"},
+ { "ni", TclSingleOpCmd, TclCompileNiOpCmd,
+ /* numArgs */ {2}, "value list"},
+ { "-", TclNoIdentOpCmd, TclCompileMinusOpCmd,
+ /* unused */ {0}, "value ?value ...?"},
+ { "/", TclNoIdentOpCmd, TclCompileDivOpCmd,
+ /* unused */ {0}, "value ?value ...?"},
+ { "<", TclSortingOpCmd, TclCompileLessOpCmd,
+ /* unused */ {0}, NULL },
+ { "<=", TclSortingOpCmd, TclCompileLeqOpCmd,
+ /* unused */ {0}, NULL },
+ { ">", TclSortingOpCmd, TclCompileGreaterOpCmd,
+ /* unused */ {0}, NULL },
+ { ">=", TclSortingOpCmd, TclCompileGeqOpCmd,
+ /* unused */ {0}, NULL },
+ { "==", TclSortingOpCmd, TclCompileEqOpCmd,
+ /* unused */ {0}, NULL },
+ { "eq", TclSortingOpCmd, TclCompileStreqOpCmd,
+ /* unused */ {0}, NULL },
+ { NULL, NULL, NULL,
+ {0}, NULL }
};
/*
@@ -660,7 +687,7 @@ Tcl_CreateInterp(void)
TclOpCmdClientData *occdPtr = (TclOpCmdClientData *)
ckalloc(sizeof(TclOpCmdClientData));
occdPtr->operator = opcmdInfoPtr->name;
- occdPtr->numArgs = opcmdInfoPtr->numArgs;
+ occdPtr->i.numArgs = opcmdInfoPtr->i.numArgs;
occdPtr->expected = opcmdInfoPtr->expected;
strcpy(mathFuncName + MATH_OP_PREFIX_LEN, opcmdInfoPtr->name);
cmdPtr = (Command *) Tcl_CreateObjCommand(interp, mathFuncName,
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c
index eed1e9b..96ff49c 100644
--- a/generic/tclCompExpr.c
+++ b/generic/tclCompExpr.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCompExpr.c,v 1.84 2007/08/27 23:30:28 das Exp $
+ * RCS: @(#) $Id: tclCompExpr.c,v 1.85 2007/08/28 16:24:29 dgp Exp $
*/
#include "tclInt.h"
@@ -2005,9 +2005,7 @@ ParseLexeme(
* bytecodes.
*
* Results:
- * The return value is TCL_OK on a successful compilation and TCL_ERROR
- * on failure (which must be a syntax error). If TCL_ERROR is returned,
- * then the interpreter's result contains an error message.
+ * None.
*
* Side effects:
* Adds instructions to envPtr to evaluate the expression at runtime.
@@ -2391,7 +2389,7 @@ TclSingleOpCmd(
OpNode nodes[2];
Tcl_Obj *const *litObjv = objv + 1;
- if (objc != 1+occdPtr->numArgs) {
+ if (objc != 1+occdPtr->i.numArgs) {
Tcl_WrongNumArgs(interp, 1, objv, occdPtr->expected);
return TCL_ERROR;
}
@@ -2502,7 +2500,7 @@ TclSortingOpCmd(
* in the ::tcl::mathop namespace. These commands are defined for
* arbitrary number of arguments by repeatedly applying the base
* operator with suitable associative rules. When fewer than two
- * arguments are provided, suitable basis answers are returned.
+ * arguments are provided, suitable identity values are returned.
*
* Results:
* A standard Tcl return code and result left in interp.
@@ -2525,7 +2523,7 @@ TclVariadicOpCmd(
int code;
if (objc < 2) {
- Tcl_SetObjResult(interp, Tcl_NewIntObj(occdPtr->numArgs));
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(occdPtr->i.identity));
return TCL_OK;
}
@@ -2539,7 +2537,7 @@ TclVariadicOpCmd(
Tcl_Obj *const *litObjPtrPtr = litObjv;
if (lexeme == EXPON) {
- litObjv[1] = Tcl_NewIntObj(occdPtr->numArgs);
+ litObjv[1] = Tcl_NewIntObj(occdPtr->i.identity);
Tcl_IncrRefCount(litObjv[1]);
decrMe = 1;
litObjv[0] = objv[1];
@@ -2555,7 +2553,7 @@ TclVariadicOpCmd(
if (lexeme == DIVIDE) {
litObjv[0] = Tcl_NewDoubleObj(1.0);
} else {
- litObjv[0] = Tcl_NewIntObj(occdPtr->numArgs);
+ litObjv[0] = Tcl_NewIntObj(occdPtr->i.identity);
}
Tcl_IncrRefCount(litObjv[0]);
litObjv[1] = objv[1];
diff --git a/generic/tclCompile.h b/generic/tclCompile.h
index 0dc8eef..ea975f9 100644
--- a/generic/tclCompile.h
+++ b/generic/tclCompile.h
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCompile.h,v 1.76 2007/08/27 19:56:51 dgp Exp $
+ * RCS: @(#) $Id: tclCompile.h,v 1.77 2007/08/28 16:24:31 dgp Exp $
*/
#ifndef _TCLCOMPILATION
@@ -803,7 +803,10 @@ MODULE_SCOPE AuxDataType tclDictUpdateInfoType;
typedef struct {
const char *operator;
const char *expected;
- int numArgs;
+ union {
+ int numArgs;
+ int identity;
+ } i;
} TclOpCmdClientData;
/*