diff options
author | sebres <sebres@users.sourceforge.net> | 2024-03-13 00:01:26 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2024-03-13 00:01:26 (GMT) |
commit | 8be245967eba0ad8e86faa8f6a4c0adb4ead6a6a (patch) | |
tree | b554bd34be32cb30f894a93533a78cdaf6b29b75 /generic | |
parent | d0afd28715ccfb7545af9a63b1ec8fe68b6adec5 (diff) | |
download | tcl-8be245967eba0ad8e86faa8f6a4c0adb4ead6a6a.zip tcl-8be245967eba0ad8e86faa8f6a4c0adb4ead6a6a.tar.gz tcl-8be245967eba0ad8e86faa8f6a4c0adb4ead6a6a.tar.bz2 |
partially revert f665afd65ee7a5f9 (INST_INVOKE_REPLACE/CMD_COMPILE_TO_INVOKED), ensemble compiled in configure -init-complete (only for clock)
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclClock.c | 95 | ||||
-rw-r--r-- | generic/tclEnsemble.c | 48 | ||||
-rw-r--r-- | generic/tclInt.h | 3 |
3 files changed, 67 insertions, 79 deletions
diff --git a/generic/tclClock.c b/generic/tclClock.c index b7ca81c..cc990a6 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -133,43 +133,28 @@ struct ClockCommand { * will always have the ClockClientData sent * to it, but may well ignore this data. */ CompileProc *compileProc; /* The compiler for the command. */ - void *clientData; /* Any clientData to give the command (if NULL + void *clientData; /* Any clientData to give the command (if NULL * a reference to ClockClientData will be sent) */ - int compFlags; /* Command compile flags */ }; static const struct ClockCommand clockCommands[] = { - {"add", ClockAddObjCmd, TclCompileBasicMin1ArgCmd, NULL, - CMD_COMPILE_TO_INVOKED}, - {"clicks", ClockClicksObjCmd, TclCompileClockClicksCmd, NULL, - 0}, - {"format", ClockFormatObjCmd, TclCompileBasicMin1ArgCmd, NULL, - CMD_COMPILE_TO_INVOKED}, - {"getenv", ClockGetenvObjCmd, TclCompileBasicMin1ArgCmd, NULL, - 0}, - {"microseconds", ClockMicrosecondsObjCmd,TclCompileClockReadingCmd,INT2PTR(1), - 0}, - {"milliseconds", ClockMillisecondsObjCmd,TclCompileClockReadingCmd, INT2PTR(2), - 0}, - {"scan", ClockScanObjCmd, TclCompileBasicMin1ArgCmd, NULL, - CMD_COMPILE_TO_INVOKED}, - {"seconds", ClockSecondsObjCmd, TclCompileClockReadingCmd, INT2PTR(3), - 0}, - {"configure", ClockConfigureObjCmd, NULL, NULL, - CMD_COMPILE_TO_INVOKED}, - {"ConvertLocalToUTC", ClockConvertlocaltoutcObjCmd, NULL, NULL, - 0}, - {"GetDateFields", ClockGetdatefieldsObjCmd, NULL, NULL, - 0}, + {"add", ClockAddObjCmd, TclCompileBasicMin1ArgCmd, NULL}, + {"clicks", ClockClicksObjCmd, TclCompileClockClicksCmd, NULL}, + {"format", ClockFormatObjCmd, TclCompileBasicMin1ArgCmd, NULL}, + {"getenv", ClockGetenvObjCmd, TclCompileBasicMin1ArgCmd, NULL}, + {"microseconds", ClockMicrosecondsObjCmd,TclCompileClockReadingCmd, INT2PTR(1)}, + {"milliseconds", ClockMillisecondsObjCmd,TclCompileClockReadingCmd, INT2PTR(2)}, + {"scan", ClockScanObjCmd, TclCompileBasicMin1ArgCmd, NULL}, + {"seconds", ClockSecondsObjCmd, TclCompileClockReadingCmd, INT2PTR(3)}, + {"configure", ClockConfigureObjCmd, NULL, NULL}, + {"ConvertLocalToUTC", ClockConvertlocaltoutcObjCmd, NULL, NULL}, + {"GetDateFields", ClockGetdatefieldsObjCmd, NULL, NULL}, {"GetJulianDayFromEraYearMonthDay", - ClockGetjuliandayfromerayearmonthdayObjCmd, NULL, NULL, - 0}, + ClockGetjuliandayfromerayearmonthdayObjCmd, NULL, NULL}, {"GetJulianDayFromEraYearWeekDay", - ClockGetjuliandayfromerayearweekdayObjCmd, NULL, NULL, - 0}, - {"catch", ClockSafeCatchCmd, TclCompileBasicMin1ArgCmd, NULL, - 0}, - {NULL, NULL, NULL, NULL, 0} + ClockGetjuliandayfromerayearweekdayObjCmd, NULL, NULL}, + {"catch", ClockSafeCatchCmd, TclCompileBasicMin1ArgCmd, NULL}, + {NULL, NULL, NULL, NULL} }; /* @@ -281,7 +266,6 @@ TclClockInit( clockCmdPtr->clientData ? NULL : ClockDeleteCmdProc); cmdPtr->compileProc = clockCmdPtr->compileProc ? clockCmdPtr->compileProc : TclCompileBasicMin0ArgCmd; - cmdPtr->flags |= clockCmdPtr->compFlags; } } @@ -983,13 +967,15 @@ ClockConfigureObjCmd( "-clear", "-year-century", "-century-switch", "-min-year", "-max-year", "-max-jdn", "-validate", + "-init-complete", NULL }; enum optionInd { CLOCK_SYSTEM_TZ, CLOCK_SETUP_TZ, CLOCK_DEFAULT_LOCALE, CLOCK_CURRENT_LOCALE, CLOCK_CLEAR_CACHE, CLOCK_YEAR_CENTURY, CLOCK_CENTURY_SWITCH, - CLOCK_MIN_YEAR, CLOCK_MAX_YEAR, CLOCK_MAX_JDN, CLOCK_VALIDATE + CLOCK_MIN_YEAR, CLOCK_MAX_YEAR, CLOCK_MAX_JDN, CLOCK_VALIDATE, + CLOCK_INIT_COMPLETE }; int optionIndex; /* Index of an option. */ int i; @@ -1153,6 +1139,27 @@ ClockConfigureObjCmd( case CLOCK_CLEAR_CACHE: ClockConfigureClear(dataPtr); break; + case CLOCK_INIT_COMPLETE: + { + /* + * Init completed. + * Compile clock ensemble (performance purposes). + */ + Tcl_Command token = Tcl_FindCommand(interp, "::clock", + NULL, TCL_GLOBAL_ONLY); + if (!token) { + return TCL_ERROR; + } + int ensFlags = 0; + if (Tcl_GetEnsembleFlags(interp, token, &ensFlags) != TCL_OK) { + return TCL_ERROR; + } + ensFlags |= ENSEMBLE_COMPILE; + if (Tcl_SetEnsembleFlags(interp, token, ensFlags) != TCL_OK) { + return TCL_ERROR; + } + } + break; } } @@ -3157,7 +3164,7 @@ ClockClicksObjCmd( } break; default: - Tcl_WrongNumArgs(interp, 1, objv, "?-switch?"); + Tcl_WrongNumArgs(interp, 0, objv, "clock clicks ?-switch?"); return TCL_ERROR; } @@ -3211,7 +3218,7 @@ ClockMillisecondsObjCmd( Tcl_Obj *timeObj; if (objc != 1) { - Tcl_WrongNumArgs(interp, 1, objv, NULL); + Tcl_WrongNumArgs(interp, 0, objv, "clock milliseconds"); return TCL_ERROR; } Tcl_GetTime(&now); @@ -3247,7 +3254,7 @@ ClockMicrosecondsObjCmd( Tcl_Obj *const *objv) /* Parameter values */ { if (objc != 1) { - Tcl_WrongNumArgs(interp, 1, objv, NULL); + Tcl_WrongNumArgs(interp, 0, objv, "clock microseconds"); return TCL_ERROR; } Tcl_SetObjResult(interp, Tcl_NewWideIntObj(TclpGetMicroseconds())); @@ -3545,7 +3552,7 @@ ClockFormatObjCmd( { ClockClientData *dataPtr = (ClockClientData *)clientData; - static const char *syntax = "clockval|-now " + static const char *syntax = "clock format clockval|-now " "?-format string? " "?-gmt boolean? " "?-locale LOCALE? ?-timezone ZONE?"; @@ -3555,7 +3562,7 @@ ClockFormatObjCmd( /* even number of arguments */ if ((objc & 1) == 1) { - Tcl_WrongNumArgs(interp, 1, objv, syntax); + Tcl_WrongNumArgs(interp, 0, objv, syntax); Tcl_SetErrorCode(interp, "CLOCK", "wrongNumArgs", (char *)NULL); return TCL_ERROR; } @@ -3620,7 +3627,7 @@ ClockScanObjCmd( int objc, /* Parameter count */ Tcl_Obj *const objv[]) /* Parameter values */ { - static const char *syntax = "string " + static const char *syntax = "clock scan string " "?-base seconds? " "?-format string? " "?-gmt boolean? " @@ -3632,7 +3639,7 @@ ClockScanObjCmd( /* even number of arguments */ if ((objc & 1) == 1) { - Tcl_WrongNumArgs(interp, 1, objv, syntax); + Tcl_WrongNumArgs(interp, 0, objv, syntax); Tcl_SetErrorCode(interp, "CLOCK", "wrongNumArgs", (char *)NULL); return TCL_ERROR; } @@ -4365,7 +4372,7 @@ ClockAddObjCmd( int objc, /* Parameter count */ Tcl_Obj *const objv[]) /* Parameter values */ { - static const char *syntax = "clockval|-now ?number units?..." + static const char *syntax = "clock add clockval|-now ?number units?..." "?-gmt boolean? " "?-locale LOCALE? ?-timezone ZONE?"; ClockClientData *dataPtr = (ClockClientData *)clientData; @@ -4392,7 +4399,7 @@ ClockAddObjCmd( /* even number of arguments */ if ((objc & 1) == 1) { - Tcl_WrongNumArgs(interp, 1, objv, syntax); + Tcl_WrongNumArgs(interp, 0, objv, syntax); Tcl_SetErrorCode(interp, "CLOCK", "wrongNumArgs", (char *)NULL); return TCL_ERROR; } @@ -4405,7 +4412,7 @@ ClockAddObjCmd( ClockInitFmtScnArgs(clientData, interp, &opts); ret = ClockParseFmtScnArgs(&opts, &yy.date, objc, objv, - CLC_ADD_ARGS, syntax); + CLC_ADD_ARGS, "-gmt, -locale, or -timezone"); if (ret != TCL_OK) { goto done; } @@ -4551,7 +4558,7 @@ ClockSecondsObjCmd( Tcl_Obj *timeObj; if (objc != 1) { - Tcl_WrongNumArgs(interp, 1, objv, NULL); + Tcl_WrongNumArgs(interp, 0, objv, "clock seconds"); return TCL_ERROR; } Tcl_GetTime(&now); diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c index 2ae966f..ad6ced3 100644 --- a/generic/tclEnsemble.c +++ b/generic/tclEnsemble.c @@ -196,7 +196,7 @@ TclNamespaceEnsembleCmd( */ Tcl_Obj *subcmdObj = NULL; Tcl_Obj *mapObj = NULL; - int ensFlags = TCL_ENSEMBLE_PREFIX; + int permitPrefix = 1; Tcl_Obj *unknownObj = NULL; Tcl_Obj *paramObj = NULL; @@ -330,8 +330,7 @@ TclNamespaceEnsembleCmd( } continue; } - case CRT_PREFIX: { - int permitPrefix; + case CRT_PREFIX: if (Tcl_GetBooleanFromObj(interp, objv[1], &permitPrefix) != TCL_OK) { if (allocatedMapFlag) { @@ -339,10 +338,7 @@ TclNamespaceEnsembleCmd( } return TCL_ERROR; } - ensFlags &= ~TCL_ENSEMBLE_PREFIX; - ensFlags |= permitPrefix ? TCL_ENSEMBLE_PREFIX : 0; continue; - } case CRT_UNKNOWN: if (TclListObjLength(interp, objv[1], &len) != TCL_OK) { if (allocatedMapFlag) { @@ -360,15 +356,6 @@ TclNamespaceEnsembleCmd( &actualCxtPtr, &simpleName); /* - * Ensemble should be compiled if it has map (performance purposes) - * Currently only for internal using namespace (like ::tcl::clock). - * (An enhancement for completelly compile-feature is in work.) - */ - if (mapObj != NULL && strncmp("::tcl::", nsPtr->fullName, 7) == 0) { - ensFlags |= ENSEMBLE_COMPILE; - } - - /* * Create the ensemble. Note that this might delete another ensemble * linked to the same namespace, so we must be careful. However, we * should be OK because we only link the namespace into the list once @@ -377,7 +364,7 @@ TclNamespaceEnsembleCmd( token = TclCreateEnsembleInNs(interp, simpleName, (Tcl_Namespace *) foundNsPtr, (Tcl_Namespace *) nsPtr, - ensFlags); + (permitPrefix ? TCL_ENSEMBLE_PREFIX : 0)); Tcl_SetEnsembleSubcommandList(interp, token, subcmdObj); Tcl_SetEnsembleMappingDict(interp, token, mapObj); Tcl_SetEnsembleUnknownHandler(interp, token, unknownObj); @@ -2947,14 +2934,14 @@ TclCompileEnsemble( TclNewObj(replaced); Tcl_IncrRefCount(replaced); if (parsePtr->numWords <= depth) { - goto tryCompileToInv; + goto failed; } if (tokenPtr->type != TCL_TOKEN_SIMPLE_WORD) { /* * Too hard. */ - goto tryCompileToInv; + goto failed; } /* @@ -2979,7 +2966,7 @@ TclCompileEnsemble( * to proceed. */ - goto tryCompileToInv; + goto failed; } /* @@ -2993,7 +2980,7 @@ TclCompileEnsemble( * Figuring out how to compile this has become too much. Bail out. */ - goto tryCompileToInv; + goto failed; } /* @@ -3016,7 +3003,7 @@ TclCompileEnsemble( Tcl_Obj *matchObj = NULL; if (TclListObjGetElements(NULL, listObj, &len, &elems) != TCL_OK) { - goto tryCompileToInv; + goto failed; } for (i=0 ; i<len ; i++) { str = Tcl_GetStringFromObj(elems[i], &sclen); @@ -3027,7 +3014,7 @@ TclCompileEnsemble( result = Tcl_DictObjGet(NULL, mapObj,elems[i], &targetCmdObj); if (result != TCL_OK || targetCmdObj == NULL) { - goto tryCompileToInv; + goto failed; } replacement = elems[i]; goto doneMapLookup; @@ -3045,17 +3032,17 @@ TclCompileEnsemble( if ((flags & TCL_ENSEMBLE_PREFIX) && strncmp(word, str, numBytes) == 0) { if (matchObj != NULL) { - goto tryCompileToInv; + goto failed; } matchObj = elems[i]; } } if (matchObj == NULL) { - goto tryCompileToInv; + goto failed; } result = Tcl_DictObjGet(NULL, mapObj, matchObj, &targetCmdObj); if (result != TCL_OK || targetCmdObj == NULL) { - goto tryCompileToInv; + goto failed; } replacement = matchObj; } else { @@ -3085,7 +3072,7 @@ TclCompileEnsemble( */ if (!(flags & TCL_ENSEMBLE_PREFIX)) { - goto tryCompileToInv; + goto failed; } /* @@ -3120,7 +3107,7 @@ TclCompileEnsemble( if (matched != 1) { invokeAnyway = 1; - goto tryCompileToInv; + goto failed; } } @@ -3136,7 +3123,7 @@ TclCompileEnsemble( doneMapLookup: Tcl_ListObjAppendElement(NULL, replaced, replacement); if (TclListObjGetElements(NULL, targetCmdObj, &len, &elems) != TCL_OK) { - goto tryCompileToInv; + goto failed; } else if (len != 1) { /* * Note that at this point we know we can't issue any special @@ -3166,9 +3153,6 @@ TclCompileEnsemble( cmdPtr = newCmdPtr; depth++; - if (cmdPtr->flags & CMD_COMPILE_TO_INVOKED) { - goto tryCompileToInv; - } /* * See whether we have a nested ensemble. If we do, we can go round the * mulberry bush again, consuming the next word. @@ -3227,7 +3211,7 @@ TclCompileEnsemble( * instead of going through the ensemble lookup process again. */ - tryCompileToInv: + failed: if (depth < 250) { if (depth > 1) { if (!invokeAnyway) { diff --git a/generic/tclInt.h b/generic/tclInt.h index d218a20..d3e8989 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -1850,8 +1850,6 @@ typedef struct Command { * CMD_COMPILES_EXPANDED - If 1 this command has a compiler that * can handle expansion (provided it is not the * first word). - * CMD_COMPILE_TO_INVOKED - If 1 this command prefers a compilation with - * INST_INVOKE_REPLACE (in ensemble only). * TCL_TRACE_RENAME - A rename trace is in progress. Further * recursive renames will not be traced. * TCL_TRACE_DELETE - A delete trace is in progress. Further @@ -1866,7 +1864,6 @@ typedef struct Command { #define CMD_REDEF_IN_PROGRESS 0x10 #define CMD_VIA_RESOLVER 0x20 #define CMD_DEAD 0x40 -#define CMD_COMPILE_TO_INVOKED 0x80 /* |