summaryrefslogtreecommitdiffstats
path: root/generic/tclExecute.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2000-05-09 00:00:34 (GMT)
committerhobbs <hobbs>2000-05-09 00:00:34 (GMT)
commit427c904742d9d5aec8068fce38a28be9ae65af08 (patch)
tree1e3bab60e826e937b67fa7d70d97f4f352fe315a /generic/tclExecute.c
parent9f7b9b72befea46deb71233146973eea88223af0 (diff)
downloadtcl-427c904742d9d5aec8068fce38a28be9ae65af08.zip
tcl-427c904742d9d5aec8068fce38a28be9ae65af08.tar.gz
tcl-427c904742d9d5aec8068fce38a28be9ae65af08.tar.bz2
* doc/expr.n:
* tests/expr.test: * tests/expr-old.test: added tests for 'eq' and 'ne' * generic/tclExecute.c: * generic/tclCompile.h: added INST_STREQ and INST_STRNEQ opcodes that do strict string comparisons. * generic/tclCompExpr.c: added 'eq' and 'ne' string comparison operators. * generic/tclParseExpr.c (GetLexeme): added 'eq' and 'ne' expr parse terms (string (in)equality check).
Diffstat (limited to 'generic/tclExecute.c')
-rw-r--r--generic/tclExecute.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index bc026b3..f19a968 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -5,11 +5,12 @@
* commands.
*
* Copyright (c) 1996-1997 Sun Microsystems, Inc.
+ * Copyright (c) 1998-2000 by Scriptics Corporation.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclExecute.c,v 1.10 2000/03/27 22:18:55 hobbs Exp $
+ * RCS: @(#) $Id: tclExecute.c,v 1.11 2000/05/09 00:00:34 hobbs Exp $
*/
#include "tclInt.h"
@@ -98,7 +99,8 @@ int (*tclMatherrPtr)() = matherr;
static char *operatorStrings[] = {
"||", "&&", "|", "^", "&", "==", "!=", "<", ">", "<=", ">=", "<<", ">>",
"+", "-", "*", "/", "%", "+", "-", "~", "!",
- "BUILTIN FUNCTION", "FUNCTION"
+ "BUILTIN FUNCTION", "FUNCTION",
+ "", "", "", "", "", "", "", "", "eq", "ne",
};
/*
@@ -1755,6 +1757,55 @@ TclExecuteByteCode(interp, codePtr)
}
ADJUST_PC(1);
+ case INST_STREQ:
+ case INST_STRNEQ:
+ {
+ /*
+ * String (in)equality check
+ */
+ char *s1, *s2;
+ int s1len, s2len;
+ long iResult;
+
+ value2Ptr = POP_OBJECT();
+ valuePtr = POP_OBJECT();
+
+ s1 = Tcl_GetStringFromObj(valuePtr, &s1len);
+ s2 = Tcl_GetStringFromObj(value2Ptr, &s2len);
+ if (s1len == s2len) {
+ /*
+ * We only need to check (in)equality when we have equal
+ * length strings.
+ */
+ if (*pc == INST_STRNEQ) {
+ iResult = (strcmp(s1, s2) != 0);
+ } else {
+ /* INST_STREQ */
+ iResult = (strcmp(s1, s2) == 0);
+ }
+ } else {
+ iResult = (*pc == INST_STRNEQ);
+ }
+
+ /*
+ * Reuse the valuePtr object already on stack if possible.
+ */
+
+ if (Tcl_IsShared(valuePtr)) {
+ PUSH_OBJECT(Tcl_NewLongObj(iResult));
+ TRACE(("%.20s %.20s => %ld\n",
+ O2S(valuePtr), O2S(value2Ptr), iResult));
+ TclDecrRefCount(valuePtr);
+ } else { /* reuse the valuePtr object */
+ TRACE(("%.20s %.20s => %ld\n",
+ O2S(valuePtr), O2S(value2Ptr), iResult));
+ Tcl_SetLongObj(valuePtr, iResult);
+ ++stackTop; /* valuePtr now on stk top has right r.c. */
+ }
+ TclDecrRefCount(value2Ptr);
+ }
+ ADJUST_PC(1);
+
case INST_EQ:
case INST_NEQ:
case INST_LT: