@@ -65,13 +65,21 @@ #ifdef HAVE_BACKTRACE #include #endif -/*#define DEBUG_SHOW_SCRIPT*/ -/*#define DEBUG_SHOW_TOKENS*/ - /* For INFINITY, even if math functions are not enabled */ #include + +/*#define DEBUG_SHOW_SCRIPT*/ +/*#define DEBUG_SHOW_SCRIPT_TOKENS*/ +/*#define DEBUG_SHOW_SUBST*/ +/*#define DEBUG_SHOW_EXPR*/ +/*#define JIM_DEBUG_GC*/ +/*#define JIM_DEBUG_COMMAND*/ + +#if defined(DEBUG_SHOW_SCRIPT) || defined(DEBUG_SHOW_SCRIPT_TOKENS) || defined(DEBUG_SHOW_EXPR) || defined(DEBUG_SHOW_SUBST) +static const char *tt_name(int type); +#endif /* ----------------------------------------------------------------------------- * Global variables * ---------------------------------------------------------------------------*/ @@ -99,10 +107,8 @@ static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr); static const Jim_HashTableType JimVariablesHashTableType; -const char *tt_name(int type); - /* ----------------------------------------------------------------------------- * Utility functions * ---------------------------------------------------------------------------*/ @@ -3043,9 +3049,9 @@ /* This is the first token for the current command */ ScriptToken *linefirst; int count; -#ifdef DEBUG_SHOW_TOKENS +#ifdef DEBUG_SHOW_SCRIPT_TOKENS printf("==== Tokens ====\n"); for (i = 0; i < tokenlist->count; i++) { printf("[%2d]@%d %s '%.*s'\n", i, tokenlist->list[i].line, tt_name(tokenlist->list[i].type), tokenlist->list[i].len, tokenlist->list[i].token); @@ -3081,9 +3087,13 @@ if (wordtokens == 0) { /* None, so at end of line */ if (lineargs) { linefirst->type = JIM_TT_LINE; +#ifdef DEBUG_SHOW_SCRIPT linefirst->objPtr = Jim_NewIntObj(interp, lineargs); +#else + linefirst->objPtr = interp->emptyObj; +#endif /* Cheat and store the value in the unused 'linenr' for quick access */ linefirst->linenr = lineargs; Jim_IncrRefCount(linefirst->objPtr); @@ -3096,9 +3106,13 @@ } else if (wordtokens != 1) { /* More than 1, or {expand}, so insert a WORD token */ token->type = JIM_TT_WORD; +#ifdef DEBUG_SHOW_SCRIPT token->objPtr = Jim_NewIntObj(interp, wordtokens); +#else + token->objPtr = interp->emptyObj; +#endif /* Cheat and store the value in the unused 'linenr' for quick access */ token->linenr = wordtokens; Jim_IncrRefCount(token->objPtr); token++; @@ -4453,10 +4467,8 @@ JimReferencesHTKeyDestructor, /* key destructor */ NULL /* val destructor */ }; -/* #define JIM_DEBUG_GC 1 */ - /* Performs the garbage collection. */ int Jim_Collect(Jim_Interp *interp) { Jim_HashTable marks; @@ -5652,9 +5664,8 @@ static int ListSortInteger(Jim_Obj **lhsObj, Jim_Obj **rhsObj) { jim_wide lhs = 0, rhs = 0; - /* REVISIT: If these are not valid integers, bogus results ... */ if (Jim_GetWide(sort_interp, *lhsObj, &lhs) != JIM_OK || Jim_GetWide(sort_interp, *rhsObj, &rhs) != JIM_OK) { longjmp(sort_jmpbuf, JIM_ERR); } @@ -7431,40 +7442,8 @@ Jim_DecrRefCount(interp, A); return rc; } - -static int JimExprOpColon(Jim_Interp *interp, struct JimExprState *e) -{ - int rc = JIM_OK; - -#if 0 - Jim_Obj *C = ExprPop(e); - Jim_Obj *B = ExprPop(e); - Jim_Obj *A = ExprPop(e); - - switch (ExprBool(interp, A)) { - case 0: - ExprPush(e, C); - break; - - case 1: - ExprPush(e, B); - break; - - case -1: - /* Invalid */ - rc = JIM_ERR; - break; - } - Jim_DecrRefCount(interp, A); - Jim_DecrRefCount(interp, B); - Jim_DecrRefCount(interp, C); - -#endif - return rc; -} - static int JimExprOpTernaryLeft(Jim_Interp *interp, struct JimExprState *e) { Jim_Obj *skip = ExprPop(e); @@ -7595,9 +7574,9 @@ [JIM_EXPROP_LOGICAND] = {"&&", 10, 2, NULL, LAZY_OP}, [JIM_EXPROP_LOGICOR] = {"||", 9, 2, NULL, LAZY_OP}, [JIM_EXPROP_TERNARY] = {"?", 5, 2, JimExprOpNull, LAZY_OP}, - [JIM_EXPROP_COLON] = {":", 5, 2, JimExprOpColon, LAZY_OP}, + [JIM_EXPROP_COLON] = {":", 5, 2, JimExprOpNull, LAZY_OP}, /* private operators */ [JIM_EXPROP_TERNARY_LEFT] = {NULL, 5, 2, JimExprOpTernaryLeft, LAZY_LEFT}, [JIM_EXPROP_TERNARY_RIGHT] = {NULL, 5, 2, JimExprOpNull, LAZY_RIGHT}, @@ -7792,10 +7771,10 @@ { return &Jim_ExprOperators[opcode]; } -/* debugging */ -const char *tt_name(int type) +#if defined(DEBUG_SHOW_SCRIPT) || defined(DEBUG_SHOW_SCRIPT_TOKENS) || defined(DEBUG_SHOW_EXPR) || defined(DEBUG_SHOW_SUBST) +static const char *tt_name(int type) { static const char * const tt_names[JIM_TT_EXPR_OP] = { "NIL", "STR", "ESC", "VAR", "ARY", "CMD", "SEP", "EOL", "EOF", "LIN", "WRD", "(((", ")))", "INT", "DBL" }; @@ -7812,8 +7791,9 @@ sprintf(buf, "(%d)", type); return buf; } } +#endif /* ----------------------------------------------------------------------------- * Expression Object * ---------------------------------------------------------------------------*/ @@ -8187,16 +8167,18 @@ if (!expr) { goto err; } -#if 0 - int i; +#ifdef DEBUG_SHOW_EXPR + { + int i; - printf("==== Expr ====\n"); - for (i = 0; i < expr->len; i++) { - ScriptToken *t = &expr->token[i]; + printf("==== Expr ====\n"); + for (i = 0; i < expr->len; i++) { + ScriptToken *t = &expr->token[i]; - printf("[%2d] %s '%s'\n", i, tt_name(t->type), Jim_GetString(t->objPtr, NULL)); + printf("[%2d] %s '%s'\n", i, tt_name(t->type), Jim_GetString(t->objPtr, NULL)); + } } #endif /* Check program correctness. */ @@ -8206,17 +8188,8 @@ } rc = JIM_OK; -#if 0 - printf("==== Expr ====\n"); - for (i = 0; i < expr->len; i++) { - ScriptToken *t = &expr->token[i]; - - printf("[%2d] %s '%s'\n", i, tt_name(t->type), Jim_GetString(t->objPtr, NULL)); - } -#endif - err: /* Free the old internal rep and set the new one. */ Jim_FreeIntRep(interp, objPtr); Jim_SetIntRepPtr(objPtr, expr); @@ -9099,9 +9072,9 @@ /* Initialize the sbox with the numbers from 0 to 255 */ static void JimPrngInit(Jim_Interp *interp) { int i; - /* REVISIT: Move off stack */ + /* XXX: Move off stack */ unsigned int seed[256]; interp->prngState = Jim_Alloc(sizeof(Jim_PrngState)); for (i = 0; i < 256; i++) @@ -9135,9 +9108,9 @@ /* Re-seed the generator with user-provided bytes */ static void JimPrngSeed(Jim_Interp *interp, const unsigned char *seed, int seedLen) { int i; - /* REVISIT: Move off stack */ + /* XXX: Move off stack */ unsigned char buf[256]; Jim_PrngState *prng; /* initialization, only needed the first time */ @@ -10126,15 +10099,17 @@ /* No longer need the token list */ ScriptTokenListFree(&tokenlist); -#if 0 - int i; +#ifdef DEBUG_SHOW_SUBST + { + int i; - printf("==== Subst ====\n"); - for (i = 0; i < script->len; i++) { - printf("[%2d] %s (%d)'%s'\n", i, tt_name(script->token[i].type), - script->token[i].objPtr->length, script->token[i].objPtr->bytes); + printf("==== Subst ====\n"); + for (i = 0; i < script->len; i++) { + printf("[%2d] %s '%s'\n", i, tt_name(script->token[i].type), + Jim_GetString(script->token[i].objPtr, NULL)); + } } #endif /* Free the old internal rep and set the new one. */ @@ -11621,8 +11596,9 @@ /* [debug] */ static int Jim_DebugCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { +#ifdef JIM_DEBUG_COMMAND const char *options[] = { "refcount", "objcount", "objects", "invstr", "scriptlen", "exprlen", "exprbc", NULL @@ -11649,9 +11625,8 @@ return JIM_OK; } else if (option == OPT_OBJCOUNT) { int freeobj = 0, liveobj = 0; - /* REVISIT: Move off stack */ char buf[256]; Jim_Obj *objPtr; if (argc != 2) { @@ -11681,9 +11656,8 @@ /* Count the number of live objects. */ objPtr = interp->liveList; listObjPtr = Jim_NewListObj(interp, NULL, 0); while (objPtr) { - /* REVISIT: Move off stack */ char buf[128]; const char *type = objPtr->typePtr ? objPtr->typePtr->name : ""; subListObjPtr = Jim_NewListObj(interp, NULL, 0); @@ -11796,9 +11770,13 @@ Jim_SetResultString(interp, "bad option. Valid options are refcount, " "objcount, objects, invstr", -1); return JIM_ERR; } - return JIM_OK; /* unreached */ + /* unreached */ +#else + Jim_SetResultString(interp, "unsupported", -1); + return JIM_ERR; +#endif } /* [eval] */ static int Jim_EvalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)