Diff
Not logged in

Differences From Artifact [74acb1ffae]:

To Artifact [f50bc7b399]:


1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20












-
+







/*
 * tclCompExpr.c --
 *
 *	This file contains the code to parse and compile Tcl expressions
 *	and implementations of the Tcl commands corresponding to expression
 *	operators, such as the command ::tcl::mathop::+ .
 *
 * Contributions from Don Porter, NIST, 2006-2007. (not subject to US copyright)
 *
 * 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.79 2007/08/23 17:20:07 dgp Exp $
 * RCS: @(#) $Id: tclCompExpr.c,v 1.80 2007/08/24 21:34:19 dgp Exp $
 */

#include "tclInt.h"
#include "tclCompile.h"		/* CompileEnv */

/*
 * Expression parsing takes place in the routine ParseExpr().  It takes a
757
758
759
760
761
762
763
764















765
766
767
768
769

770
771
772
773
774
775
776
757
758
759
760
761
762
763

764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791







-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





+







		    Tcl_DecrRefCount(literal);
		}
		goto error;
	    }

	    switch (lexeme) {
	    case NUMBER:
	    case BOOLEAN:
	    case BOOLEAN: {
		if (interp) {
		    int new;
		    LiteralEntry *lePtr;
		    Tcl_Obj *objPtr = TclCreateLiteral((Interp *)interp,
			    (char *)start, scanned,
			    /* hash */ (unsigned int) -1, &new,
			    /* nsPtr */ NULL, /* flags */ 0, &lePtr);
		    if (new) {
			lePtr->objPtr = literal;
			Tcl_IncrRefCount(literal);
			Tcl_DecrRefCount(objPtr);
		    }
		}

		Tcl_ListObjAppendElement(NULL, litList, literal);
		complete = lastParsed = OT_LITERAL;
		start += scanned;
		numBytes -= scanned;
		continue;
	    }
	    default:
		break;
	    }

	    /*
	     * Remaining LEAF cases may involve filling Tcl_Tokens, so
	     * make room for at least 2 more tokens.
2063
2064
2065
2066
2067
2068
2069



2070
2071
2072
2073
2074
2075
2076
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094







+
+
+







    envPtr = (CompileEnv *) TclStackAlloc(interp, sizeof(CompileEnv));
    TclInitCompileEnv(interp, envPtr, NULL, 0, NULL, 0);
    CompileExprTree(interp, nodes, index, litObjvPtr, NULL, NULL, envPtr,
	    0 /* optimize */);
    TclEmitOpcode(INST_DONE, envPtr);
    Tcl_IncrRefCount(byteCodeObj);
    TclInitByteCodeObj(byteCodeObj, envPtr);
    if (envPtr->localLitTable.buckets != envPtr->localLitTable.staticBuckets) {
	ckfree((char *) envPtr->localLitTable.buckets);
    }
    TclFreeCompileEnv(envPtr);
    TclStackFree(interp, envPtr);
    byteCodePtr = (ByteCode *) byteCodeObj->internalRep.otherValuePtr;
    code = TclExecuteByteCode(interp, byteCodePtr);
    Tcl_DecrRefCount(byteCodeObj);
    return code;
}
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298








2299

2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313



2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330







-
-
-
+
+
+
+
+
+
+
+

+







	}

	nodePtr->mark++;
	switch (next) {
	case OT_EMPTY:
	    numWords = 1;	/* No arguments, so just the command */
	    break;
	case OT_LITERAL:
	    TclEmitPush(TclAddLiteralObj(envPtr, *(*litObjvPtr)++, NULL),
		    envPtr);
	case OT_LITERAL: {
	    Tcl_Obj *const *litObjv = *litObjvPtr;
	    Tcl_Obj *literal = *litObjv;
	    int length;
	    const char *bytes = Tcl_GetStringFromObj(literal, &length);

	    TclEmitPush(TclRegisterNewLiteral(envPtr, bytes, length), envPtr);
	    (*litObjvPtr)++;
	    break;
	}
	case OT_TOKENS:
	    TclCompileTokens(interp, tokenPtr+1, tokenPtr->numComponents,
		    envPtr);
	    tokenPtr += tokenPtr->numComponents + 1;
	    break;
	default:
	    if (optimize && nodes[next].constant) {