summaryrefslogtreecommitdiffstats
path: root/generic/tclCompCmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclCompCmds.c')
-rw-r--r--generic/tclCompCmds.c60
1 files changed, 22 insertions, 38 deletions
diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c
index e0dee13..33598e7 100644
--- a/generic/tclCompCmds.c
+++ b/generic/tclCompCmds.c
@@ -707,20 +707,31 @@ TclCompileDictIncrCmd(
* compiled. */
CompileEnv *envPtr) /* Holds resulting instructions. */
{
- Proc *procPtr = envPtr->procPtr;
- DefineLineInformation; /* TIP #280 */
Tcl_Token *varTokenPtr, *keyTokenPtr;
- int dictVarIndex, nameChars, incrAmount;
- const char *name;
+ int dictVarIndex, incrAmount, isScalar, isSimple;
+ DefineLineInformation; /* TIP #280 */
/*
* There must be at least two arguments after the command.
*/
- if (parsePtr->numWords < 3 || parsePtr->numWords > 4 || procPtr == NULL) {
+ if (parsePtr->numWords < 3 || parsePtr->numWords > 4) {
return TCL_ERROR;
}
+
+ /*
+ * The dictionary variable must be a local scalar that is knowable at
+ * compile time; anything else exceeds the complexity of the opcode. So
+ * discover what the index is.
+ */
+
varTokenPtr = TokenAfter(parsePtr->tokenPtr);
+ PushVarNameWord(interp, varTokenPtr, envPtr, TCL_CREATE_VAR,
+ &dictVarIndex, &isSimple, &isScalar, 1);
+ if (!isScalar || dictVarIndex < 0) {
+ return TCL_ERROR;
+ }
+
keyTokenPtr = TokenAfter(varTokenPtr);
/*
@@ -728,23 +739,12 @@ TclCompileDictIncrCmd(
*/
if (parsePtr->numWords == 4) {
- const char *word;
- int numBytes, code;
- Tcl_Token *incrTokenPtr;
- Tcl_Obj *intObj;
-
- incrTokenPtr = TokenAfter(keyTokenPtr);
- if (incrTokenPtr->type != TCL_TOKEN_SIMPLE_WORD) {
- return TCL_ERROR;
- }
- word = incrTokenPtr[1].start;
- numBytes = incrTokenPtr[1].size;
-
- intObj = Tcl_NewStringObj(word, numBytes);
- Tcl_IncrRefCount(intObj);
- code = TclGetIntFromObj(NULL, intObj, &incrAmount);
- TclDecrRefCount(intObj);
- if (code != TCL_OK) {
+ Tcl_Token *incrTokenPtr = TokenAfter(keyTokenPtr);
+ Tcl_Obj *intObj = Tcl_NewObj();
+ int fail = (!TclWordKnownAtCompileTime(incrTokenPtr, intObj)
+ || TCL_ERROR == TclGetIntFromObj(NULL, intObj, &incrAmount));
+ Tcl_DecrRefCount(intObj);
+ if (fail) {
return TCL_ERROR;
}
} else {
@@ -752,22 +752,6 @@ TclCompileDictIncrCmd(
}
/*
- * The dictionary variable must be a local scalar that is knowable at
- * compile time; anything else exceeds the complexity of the opcode. So
- * discover what the index is.
- */
-
- if (varTokenPtr->type != TCL_TOKEN_SIMPLE_WORD) {
- return TCL_ERROR;
- }
- name = varTokenPtr[1].start;
- nameChars = varTokenPtr[1].size;
- if (!TclIsLocalScalar(name, nameChars)) {
- return TCL_ERROR;
- }
- dictVarIndex = TclFindCompiledLocal(name, nameChars, 1, procPtr);
-
- /*
* Emit the key and the code to actually do the increment.
*/