summaryrefslogtreecommitdiffstats
path: root/generic/tclCompExpr.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2006-12-08 20:48:08 (GMT)
committerdgp <dgp@users.sourceforge.net>2006-12-08 20:48:08 (GMT)
commit737023909817fcc30432c33881868b521a3661d9 (patch)
tree2ec0dbf630fbc773ffa1f75145aba1677f457a21 /generic/tclCompExpr.c
parentc31a5d22b7398ccaa6b9d0e17e4865563253b0f5 (diff)
downloadtcl-737023909817fcc30432c33881868b521a3661d9.zip
tcl-737023909817fcc30432c33881868b521a3661d9.tar.gz
tcl-737023909817fcc30432c33881868b521a3661d9.tar.bz2
* generic/tclBasic.c: Another step down the path of re-using
* generic/tclCompExpr.c: TclExecuteByteCode to implement the TIP 174 * generic/tclCompile.h: commands instead of using a mass of code * generic/tclMathOp.c: duplication. Now all operator commands that * tests/mathop.test: demand exactly one operation are implemented via TclSingleOpCmd and a call to TEBC.
Diffstat (limited to 'generic/tclCompExpr.c')
-rw-r--r--generic/tclCompExpr.c60
1 files changed, 37 insertions, 23 deletions
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c
index 146c3c4..195f67e 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.41 2006/12/08 18:08:33 dgp Exp $
+ * RCS: @(#) $Id: tclCompExpr.c,v 1.42 2006/12/08 20:48:09 dgp Exp $
*/
#include "tclInt.h"
@@ -2584,38 +2584,23 @@ CompileExprTree(
}
}
-int
-TclInvertOpCmd(
- ClientData clientData,
+static int
+OpCmd(
Tcl_Interp *interp,
- int objc,
- Tcl_Obj *const objv[])
+ OpNode *nodes,
+ Tcl_Obj * const litObjv[])
{
CompileEnv compEnv;
ByteCode *byteCodePtr;
- OpNode nodes[2];
- int code, tmp = 1;
- Tcl_Obj *byteCodeObj;
-
- if (objc != 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "number");
- return TCL_ERROR;
- }
+ int code, tmp=1;
+ Tcl_Obj *byteCodeObj = Tcl_NewObj();
/* Note we are compiling an expression with literal arguments.
* This means there can be no [info frame] calls when we execute
* the resulting bytecode, so there's no need to tend to TIP 280 issues */
TclInitCompileEnv(interp, &compEnv, NULL, 0, NULL, 0);
-
- nodes[0].lexeme = START;
- nodes[0].right = 1;
- nodes[1].lexeme = BIT_NOT;
- nodes[1].right = OT_LITERAL;
- nodes[1].parent = 0;
-
- CompileExprTree(interp, nodes, objv+1, NULL, NULL, &tmp, &compEnv);
+ CompileExprTree(interp, nodes, litObjv, NULL, NULL, &tmp, &compEnv);
TclEmitOpcode(INST_DONE, &compEnv);
- byteCodeObj = Tcl_NewObj();
Tcl_IncrRefCount(byteCodeObj);
TclInitByteCodeObj(byteCodeObj, &compEnv);
TclFreeCompileEnv(&compEnv);
@@ -2624,6 +2609,35 @@ TclInvertOpCmd(
Tcl_DecrRefCount(byteCodeObj);
return code;
}
+
+int
+TclSingleOpCmd(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *const objv[])
+{
+ TclOpCmdClientData *occdPtr = (TclOpCmdClientData *)clientData;
+ unsigned char lexeme;
+ OpNode nodes[2];
+
+ if (objc != 1+occdPtr->numArgs) {
+ Tcl_WrongNumArgs(interp, 1, objv, occdPtr->expected);
+ return TCL_ERROR;
+ }
+
+ ParseLexeme(occdPtr->operator, strlen(occdPtr->operator), &lexeme, NULL);
+ nodes[0].lexeme = START;
+ nodes[0].right = 1;
+ nodes[1].lexeme = lexeme;
+ nodes[1].left = OT_LITERAL;
+ nodes[1].right = OT_LITERAL;
+ nodes[1].parent = 0;
+
+ return OpCmd(interp, nodes, objv+1);
+}
+
+
/*
*----------------------------------------------------------------------