summaryrefslogtreecommitdiffstats
path: root/generic/tclExecute.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2011-03-26 11:53:59 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2011-03-26 11:53:59 (GMT)
commit77029bd1e96f8df35c93b67699e5aee7c4546d72 (patch)
treeab47b39e8bedb1021813e1161e79eb9a80359b53 /generic/tclExecute.c
parentb570644554e1dc8b3efeb2a54cd329b877e8a67c (diff)
downloadtcl-77029bd1e96f8df35c93b67699e5aee7c4546d72.zip
tcl-77029bd1e96f8df35c93b67699e5aee7c4546d72.tar.gz
tcl-77029bd1e96f8df35c93b67699e5aee7c4546d72.tar.bz2
Reduce the number of casts used to manage Tcl_Obj internal representations.
Diffstat (limited to 'generic/tclExecute.c')
-rw-r--r--generic/tclExecute.c147
1 files changed, 69 insertions, 78 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 26d3e04..f1b8504 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -189,7 +189,7 @@ typedef struct TEBCdata {
TclNRAddCallback(interp, TEBCresume, TD, \
INT2PTR(1), NULL, NULL)
-#define TEBC_DATA_DIG() \
+#define TEBC_DATA_DIG() \
pc = TD->pc; \
cleanup = TD->cleanup; \
tosPtr = esPtr->tosPtr
@@ -197,15 +197,15 @@ typedef struct TEBCdata {
#define PUSH_TAUX_OBJ(objPtr) \
do { \
- objPtr->internalRep.twoPtrValue.ptr2 = auxObjList; \
+ objPtr->internalRep.ptrAndLongRep.ptr = auxObjList; \
auxObjList = objPtr; \
} while (0)
#define POP_TAUX_OBJ() \
- do { \
- tmpPtr = auxObjList; \
- auxObjList = (Tcl_Obj *) tmpPtr->internalRep.twoPtrValue.ptr2; \
- Tcl_DecrRefCount(tmpPtr); \
+ do { \
+ tmpPtr = auxObjList; \
+ auxObjList = tmpPtr->internalRep.ptrAndLongRep.ptr; \
+ Tcl_DecrRefCount(tmpPtr); \
} while (0)
/*
@@ -1460,7 +1460,7 @@ CompileExprObj(
if (objPtr->typePtr == &exprCodeType) {
Namespace *namespacePtr = iPtr->varFramePtr->nsPtr;
- codePtr = (ByteCode *) objPtr->internalRep.otherValuePtr;
+ codePtr = objPtr->internalRep.otherValuePtr;
if (((Interp *) *codePtr->interpHandle != iPtr)
|| (codePtr->compileEpoch != iPtr->compileEpoch)
|| (codePtr->nsPtr != namespacePtr)
@@ -1500,7 +1500,7 @@ CompileExprObj(
TclInitByteCodeObj(objPtr, &compEnv);
objPtr->typePtr = &exprCodeType;
TclFreeCompileEnv(&compEnv);
- codePtr = (ByteCode *) objPtr->internalRep.otherValuePtr;
+ codePtr = objPtr->internalRep.otherValuePtr;
if (iPtr->varFramePtr->localCachePtr) {
codePtr->localCachePtr = iPtr->varFramePtr->localCachePtr;
codePtr->localCachePtr->refCount++;
@@ -1572,7 +1572,7 @@ static void
FreeExprCodeInternalRep(
Tcl_Obj *objPtr)
{
- ByteCode *codePtr = (ByteCode *) objPtr->internalRep.otherValuePtr;
+ ByteCode *codePtr = objPtr->internalRep.otherValuePtr;
objPtr->typePtr = NULL;
objPtr->internalRep.otherValuePtr = NULL;
@@ -1633,7 +1633,7 @@ TclCompileObj(
* here.
*/
- codePtr = (ByteCode *) objPtr->internalRep.otherValuePtr;
+ codePtr = objPtr->internalRep.otherValuePtr;
if (((Interp *) *codePtr->interpHandle != iPtr)
|| (codePtr->compileEpoch != iPtr->compileEpoch)
|| (codePtr->nsPtr != namespacePtr)
@@ -1691,67 +1691,59 @@ TclCompileObj(
{
Tcl_HashEntry *hePtr =
Tcl_FindHashEntry(iPtr->lineBCPtr, codePtr);
+ ExtCmdLoc *eclPtr;
+ CmdFrame *ctxPtr;
+ int redo;
- if (hePtr) {
- ExtCmdLoc *eclPtr = Tcl_GetHashValue(hePtr);
- int redo = 0;
-
- if (invoker) {
- CmdFrame *ctxPtr = TclStackAlloc(interp,sizeof(CmdFrame));
- *ctxPtr = *invoker;
+ if (!hePtr || !invoker) {
+ return codePtr;
+ }
- if (invoker->type == TCL_LOCATION_BC) {
- /*
- * Note: Type BC => ctx.data.eval.path is not used.
- * ctx.data.tebc.codePtr used instead
- */
+ eclPtr = Tcl_GetHashValue(hePtr);
+ redo = 0;
+ ctxPtr = TclStackAlloc(interp, sizeof(CmdFrame));
+ *ctxPtr = *invoker;
- TclGetSrcInfoForPc(ctxPtr);
- if (ctxPtr->type == TCL_LOCATION_SOURCE) {
- /*
- * The reference made by 'TclGetSrcInfoForPc' is
- * dead.
- */
+ if (invoker->type == TCL_LOCATION_BC) {
+ /*
+ * Note: Type BC => ctx.data.eval.path is not used.
+ * ctx.data.tebc.codePtr used instead
+ */
- Tcl_DecrRefCount(ctxPtr->data.eval.path);
- ctxPtr->data.eval.path = NULL;
- }
- }
+ TclGetSrcInfoForPc(ctxPtr);
+ if (ctxPtr->type == TCL_LOCATION_SOURCE) {
+ /*
+ * The reference made by 'TclGetSrcInfoForPc' is dead.
+ */
- if (word < ctxPtr->nline) {
- /*
- * Note: We do not care if the line[word] is -1. This
- * is a difference and requires a recompile (location
- * changed from absolute to relative, literal is used
- * fixed and through variable)
- *
- * Example:
- * test info-32.0 using literal of info-24.8
- * (dict with ... vs set body ...).
- */
+ Tcl_DecrRefCount(ctxPtr->data.eval.path);
+ ctxPtr->data.eval.path = NULL;
+ }
+ }
- redo = ((eclPtr->type == TCL_LOCATION_SOURCE)
- && (eclPtr->start != ctxPtr->line[word]))
- || ((eclPtr->type == TCL_LOCATION_BC)
- && (ctxPtr->type == TCL_LOCATION_SOURCE));
- }
+ if (word < ctxPtr->nline) {
+ /*
+ * Note: We do not care if the line[word] is -1. This is a
+ * difference and requires a recompile (location changed from
+ * absolute to relative, literal is used fixed and through
+ * variable)
+ *
+ * Example:
+ * test info-32.0 using literal of info-24.8
+ * (dict with ... vs set body ...).
+ */
- TclStackFree(interp, ctxPtr);
- }
+ redo = ((eclPtr->type == TCL_LOCATION_SOURCE)
+ && (eclPtr->start != ctxPtr->line[word]))
+ || ((eclPtr->type == TCL_LOCATION_BC)
+ && (ctxPtr->type == TCL_LOCATION_SOURCE));
+ }
- if (redo) {
- goto recompileObj;
- }
+ TclStackFree(interp, ctxPtr);
+ if (!redo) {
+ return codePtr;
}
}
-
- /*
- * Increment the code's ref count while it is being executed. If
- * afterwards no references to it remain, free the code.
- */
-
- runCompiledObj:
- return codePtr;
}
recompileObj:
@@ -1773,7 +1765,7 @@ TclCompileObj(
codePtr->localCachePtr = iPtr->varFramePtr->localCachePtr;
codePtr->localCachePtr->refCount++;
}
- goto runCompiledObj;
+ return codePtr;
}
/*
@@ -2121,8 +2113,8 @@ TEBCresume(
}
#endif
/*
- * Push the call's object result and continue execution with
- * the next instruction.
+ * Push the call's object result and continue execution with the
+ * next instruction.
*/
TRACE_WITH_OBJ(("%u => ... after \"%.20s\": TCL_OK, result=",
@@ -2132,15 +2124,13 @@ TEBCresume(
/*
* Reset the interp's result to avoid possible duplications of
- * large objects [Bug 781585]. We do not call Tcl_ResetResult
- * to avoid any side effects caused by the resetting of
- * errorInfo and errorCode [Bug 804681], which are not needed
- * here. We chose instead to manipulate the interp's object
- * result directly.
+ * large objects [Bug 781585]. We do not call Tcl_ResetResult to
+ * avoid any side effects caused by the resetting of errorInfo and
+ * errorCode [Bug 804681], which are not needed here. We chose
+ * instead to manipulate the interp's object result directly.
*
- * Note that the result object is now in objResultPtr, it
- * keeps the refCount it had in its role of
- * iPtr->objResultPtr.
+ * Note that the result object is now in objResultPtr, it keeps
+ * the refCount it had in its role of iPtr->objResultPtr.
*/
TclNewObj(objPtr);
@@ -2637,7 +2627,7 @@ TEBCresume(
*/
TclNewObj(objPtr);
- objPtr->internalRep.twoPtrValue.ptr1 = (void *) CURR_DEPTH;
+ objPtr->internalRep.ptrAndLongRep.value = CURR_DEPTH;
PUSH_TAUX_OBJ(objPtr);
NEXT_INST_F(1, 0, 0);
@@ -2727,8 +2717,7 @@ TEBCresume(
case INST_INVOKE_EXPANDED:
CLANG_ASSERT(auxObjList);
- objc = CURR_DEPTH
- - (ptrdiff_t) auxObjList->internalRep.twoPtrValue.ptr1;
+ objc = CURR_DEPTH - auxObjList->internalRep.ptrAndLongRep.value;
POP_TAUX_OBJ();
if (objc) {
pcAdjustment = 1;
@@ -4415,6 +4404,7 @@ TEBCresume(
* strings. We can use memcmp in all (n)eq cases because we
* don't need to worry about lexical LE/BE variance.
*/
+
typedef int (*memCmpFn_t)(const void*, const void*, size_t);
memCmpFn_t memCmpFn;
int checkEq = ((*pc == INST_EQ) || (*pc == INST_NEQ)
@@ -6259,7 +6249,8 @@ TEBCresume(
bytes = GetSrcInfoForPc(pc, codePtr, &length, &pcBeg);
DECACHE_STACK_INFO();
- TclLogCommandInfo(interp, codePtr->source, bytes, bytes ? length : 0, pcBeg, tosPtr);
+ TclLogCommandInfo(interp, codePtr->source, bytes,
+ bytes ? length : 0, pcBeg, tosPtr);
CACHE_STACK_INFO();
}
iPtr->flags &= ~ERR_ALREADY_LOGGED;
@@ -6270,8 +6261,8 @@ TEBCresume(
*/
while (auxObjList) {
- if ((catchTop != initCatchTop) && (*catchTop >
- (ptrdiff_t) auxObjList->internalRep.twoPtrValue.ptr1)) {
+ if ((catchTop != initCatchTop) &&
+ (*catchTop>auxObjList->internalRep.ptrAndLongRep.value)) {
break;
}
POP_TAUX_OBJ();