diff options
author | dgp <dgp@users.sourceforge.net> | 2005-08-17 15:45:12 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2005-08-17 15:45:12 (GMT) |
commit | 62674303e6bf1dead3698ea303ce186e36924d84 (patch) | |
tree | 49aa807b7f5c10d700372d877be5e461da6c4eb7 | |
parent | 4438f4e3ed8706d7cb3bce3d727587104588797a (diff) | |
download | tcl-62674303e6bf1dead3698ea303ce186e36924d84.zip tcl-62674303e6bf1dead3698ea303ce186e36924d84.tar.gz tcl-62674303e6bf1dead3698ea303ce186e36924d84.tar.bz2 |
[kennykb_numerics_branch]
* generic/tclExecute.c: New routine TclIncrObj to centralize the
increment operation needed in many places. Updated
INST_DICT_INCR_IMM to make use of it.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | generic/tclExecute.c | 83 |
2 files changed, 64 insertions, 27 deletions
@@ -1,3 +1,11 @@ +2005-08-17 Don Porter <dgp@users.sourceforge.net> + + [kennykb_numerics_branch] + + * generic/tclExecute.c: New routine TclIncrObj to centralize the + increment operation needed in many places. Updated + INST_DICT_INCR_IMM to make use of it. + 2005-08-16 Don Porter <dgp@users.sourceforge.net> [kennykb_numerics_branch] diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 2c0a675..5e16ff4 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -12,7 +12,7 @@ * 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.167.2.24 2005/08/17 04:57:49 dgp Exp $ + * RCS: @(#) $Id: tclExecute.c,v 1.167.2.25 2005/08/17 15:45:13 dgp Exp $ */ #include "tclInt.h" @@ -374,6 +374,8 @@ static Tcl_ObjType dictIteratorType = { static int TclExecuteByteCode _ANSI_ARGS_((Tcl_Interp *interp, ByteCode *codePtr)); +static int TclIncrObj _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *valuePtr, Tcl_Obj *incrPtr)); #ifdef TCL_COMPILE_STATS static int EvalStatsCmd _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int objc, @@ -1044,6 +1046,50 @@ TclCompEvalObj(interp, objPtr) /* *---------------------------------------------------------------------- * + * TclIncrObj -- + * + * Increment an integeral value in a Tcl_Obj by an integeral value + * held in another Tcl_Obj. Caller is responsible for making sure + * we can update the first object. + * + * Results: + * TCL_ERROR if either object is non-integer, and TCL_OK otherwise. On + * error, an error message is left in the interpreter (if it is not NULL, + * of course). + * + * Side effects: + * valuePtr gets the new incrmented value. + * + *---------------------------------------------------------------------- + */ + +static int +TclIncrObj(interp, valuePtr, incrPtr) + Tcl_Interp *interp; + Tcl_Obj *valuePtr; + Tcl_Obj *incrPtr; +{ + mp_int value, incr; + + if (Tcl_IsShared(valuePtr)) { + Tcl_Panic("shared object passed to TclIncrObj"); + } + + if (Tcl_GetBignumFromObj(interp, valuePtr, &value) != TCL_OK) { + return TCL_ERROR; + } + if (Tcl_GetBignumFromObj(interp, incrPtr, &incr) != TCL_OK) { + return TCL_ERROR; + } + mp_add(&value, &incr, &value); + mp_clear(&incr); + Tcl_SetBignumObj(valuePtr, &value); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * * TclExecuteByteCode -- * * This procedure executes the instructions of a ByteCode structure. It @@ -5529,6 +5575,7 @@ TclExecuteByteCode(interp, codePtr) TRACE_WITH_OBJ(("=> "), objResultPtr); NEXT_INST_F(1, 0, 1); +/* TODO: normalize "valPtr" to "valuePtr" */ { int opnd, opnd2, allocateDict; Tcl_Obj *dictPtr, *valPtr; @@ -5615,34 +5662,16 @@ TclExecuteByteCode(interp, codePtr) break; } if (valPtr == NULL) { - Tcl_DictObjPut(NULL, dictPtr, *tosPtr, Tcl_NewLongObj(opnd)); - } else if (valPtr->typePtr == &tclWideIntType) { - Tcl_WideInt wvalue; - - Tcl_GetWideIntFromObj(NULL, valPtr, &wvalue); - Tcl_DictObjPut(NULL, dictPtr, *tosPtr, - Tcl_NewWideIntObj(wvalue + opnd)); - } else if (valPtr->typePtr == &tclIntType) { - long value; - - Tcl_GetLongFromObj(NULL, valPtr, &value); - Tcl_DictObjPut(NULL, dictPtr, *tosPtr, - Tcl_NewLongObj(value + opnd)); + Tcl_DictObjPut(NULL, dictPtr, *tosPtr, Tcl_NewIntObj(opnd)); } else { - long value = 0; /* stop compiler warning */ - Tcl_WideInt wvalue; - - REQUIRE_WIDE_OR_INT(result, valPtr, value, wvalue); - if (result != TCL_OK) { - break; - } - if (valPtr->typePtr == &tclWideIntType) { - Tcl_DictObjPut(NULL, dictPtr, *tosPtr, - Tcl_NewWideIntObj(wvalue + opnd)); - } else { - Tcl_DictObjPut(NULL, dictPtr, *tosPtr, - Tcl_NewLongObj(value + opnd)); + Tcl_Obj *incrPtr = Tcl_NewIntObj(opnd); + Tcl_IncrRefCount(incrPtr); + if (Tcl_IsShared(valPtr)) { + valPtr = Tcl_DuplicateObj(valPtr); + Tcl_DictObjPut(NULL, dictPtr, *tosPtr, valPtr); } + result = TclIncrObj(interp, valPtr, incrPtr); + Tcl_DecrRefCount(incrPtr); } break; case INST_DICT_UNSET: |