| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "tclInt.h" |
| 18 |
#include "tclCompile.h" |
| 19 |
|
| 20 |
#ifndef TCL_NO_MATH |
| 21 |
# include "tclMath.h" |
| 22 |
#endif |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#ifndef TCL_GENERIC_ONLY |
| 31 |
# include "tclPort.h" |
| 32 |
#else |
| 33 |
# ifndef NO_FLOAT_H |
| 34 |
# include <float.h> |
| 35 |
# else |
| 36 |
# ifndef NO_VALUES_H |
| 37 |
# include <values.h> |
| 38 |
# endif |
| 39 |
# endif |
| 40 |
# define NO_ERRNO_H |
| 41 |
#endif |
| 42 |
|
| 43 |
#ifdef NO_ERRNO_H |
| 44 |
int errno; |
| 45 |
# define EDOM 33 |
| 46 |
# define ERANGE 34 |
| 47 |
#endif |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
#ifndef DBL_MAX |
| 53 |
# ifdef MAXDOUBLE |
| 54 |
# define DBL_MAX MAXDOUBLE |
| 55 |
# else |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
# define DBL_MAX 1.79769313486231570e+308 |
| 61 |
# endif |
| 62 |
#endif |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
static int execInitialized = 0; |
| 70 |
TCL_DECLARE_MUTEX(execMutex) |
| 71 |
|
| 72 |
#ifdef TCL_COMPILE_DEBUG |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
int tclTraceExec = 0; |
| 84 |
#endif |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
static char *operatorStrings[] = { |
| 93 |
"||", "&&", "|", "^", "&", "==", "!=", "<", ">", "<=", ">=", "<<", ">>", |
| 94 |
"+", "-", "*", "/", "%", "+", "-", "~", "!", |
| 95 |
"BUILTIN FUNCTION", "FUNCTION", |
| 96 |
"", "", "", "", "", "", "", "", "eq", "ne", |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
#ifdef TCL_COMPILE_DEBUG |
| 105 |
static char *resultStrings[] = { |
| 106 |
"TCL_OK", "TCL_ERROR", "TCL_RETURN", "TCL_BREAK", "TCL_CONTINUE" |
| 107 |
}; |
| 108 |
#endif |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
#ifdef TCL_COMPILE_STATS |
| 115 |
long tclObjsAlloced = 0; |
| 116 |
long tclObjsFreed = 0; |
| 117 |
#define TCL_MAX_SHARED_OBJ_STATS 5 |
| 118 |
long tclObjsShared[TCL_MAX_SHARED_OBJ_STATS] = { 0, 0, 0, 0, 0 }; |
| 119 |
#endif |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
#define IS_NAN(v) ((v) != (v)) |
| 128 |
#define IS_INF(v) (((v) > DBL_MAX) || ((v) < -DBL_MAX)) |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
#define NEXT_INST_F(pcAdjustment, nCleanup, result) \ |
| 146 |
if (nCleanup == 0) {\ |
| 147 |
if (result != 0) {\ |
| 148 |
if ((result) > 0) {\ |
| 149 |
PUSH_OBJECT(objResultPtr);\ |
| 150 |
} else {\ |
| 151 |
stackPtr[++stackTop] = objResultPtr;\ |
| 152 |
}\ |
| 153 |
} \ |
| 154 |
pc += (pcAdjustment);\ |
| 155 |
goto cleanup0;\ |
| 156 |
} else if (result != 0) {\ |
| 157 |
if ((result) > 0) {\ |
| 158 |
Tcl_IncrRefCount(objResultPtr);\ |
| 159 |
}\ |
| 160 |
pc += (pcAdjustment);\ |
| 161 |
switch (nCleanup) {\ |
| 162 |
case 1: goto cleanup1_pushObjResultPtr;\ |
| 163 |
case 2: goto cleanup2_pushObjResultPtr;\ |
| 164 |
default: panic("ERROR: bad usage of macro NEXT_INST_F");\ |
| 165 |
}\ |
| 166 |
} else {\ |
| 167 |
pc += (pcAdjustment);\ |
| 168 |
switch (nCleanup) {\ |
| 169 |
case 1: goto cleanup1;\ |
| 170 |
case 2: goto cleanup2;\ |
| 171 |
default: panic("ERROR: bad usage of macro NEXT_INST_F");\ |
| 172 |
}\ |
| 173 |
} |
| 174 |
|
| 175 |
#define NEXT_INST_V(pcAdjustment, nCleanup, result) \ |
| 176 |
pc += (pcAdjustment);\ |
| 177 |
cleanup = (nCleanup);\ |
| 178 |
if (result) {\ |
| 179 |
if ((result) > 0) {\ |
| 180 |
Tcl_IncrRefCount(objResultPtr);\ |
| 181 |
}\ |
| 182 |
goto cleanupV_pushObjResultPtr;\ |
| 183 |
} else {\ |
| 184 |
goto cleanupV;\ |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
#define CACHE_STACK_INFO() \ |
| 197 |
stackPtr = eePtr->stackPtr; \ |
| 198 |
stackTop = eePtr->stackTop |
| 199 |
|
| 200 |
#define DECACHE_STACK_INFO() \ |
| 201 |
eePtr->stackTop = stackTop |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
#define PUSH_OBJECT(objPtr) \ |
| 220 |
Tcl_IncrRefCount(stackPtr[++stackTop] = (objPtr)) |
| 221 |
|
| 222 |
#define POP_OBJECT() \ |
| 223 |
(stackPtr[stackTop--]) |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
#ifdef TCL_COMPILE_DEBUG |
| 232 |
# define TRACE(a) \ |
| 233 |
if (traceInstructions) { \ |
| 234 |
fprintf(stdout, "%2d: %2d (%u) %s ", iPtr->numLevels, stackTop, \ |
| 235 |
(unsigned int)(pc - codePtr->codeStart), \ |
| 236 |
GetOpcodeName(pc)); \ |
| 237 |
printf a; \ |
| 238 |
} |
| 239 |
# define TRACE_APPEND(a) \ |
| 240 |
if (traceInstructions) { \ |
| 241 |
printf a; \ |
| 242 |
} |
| 243 |
# define TRACE_WITH_OBJ(a, objPtr) \ |
| 244 |
if (traceInstructions) { \ |
| 245 |
fprintf(stdout, "%2d: %2d (%u) %s ", iPtr->numLevels, stackTop, \ |
| 246 |
(unsigned int)(pc - codePtr->codeStart), \ |
| 247 |
GetOpcodeName(pc)); \ |
| 248 |
printf a; \ |
| 249 |
TclPrintObject(stdout, objPtr, 30); \ |
| 250 |
fprintf(stdout, "\n"); \ |
| 251 |
} |
| 252 |
# define O2S(objPtr) \ |
| 253 |
(objPtr ? TclGetString(objPtr) : "") |
| 254 |
#else |
| 255 |
# define TRACE(a) |
| 256 |
# define TRACE_APPEND(a) |
| 257 |
# define TRACE_WITH_OBJ(a, objPtr) |
| 258 |
# define O2S(objPtr) |
| 259 |
#endif |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
#define REQUIRE_WIDE_OR_INT(resultVar, objPtr, longVar, wideVar) \ |
| 272 |
(resultVar) = Tcl_GetWideIntFromObj(interp, (objPtr), &(wideVar)); \ |
| 273 |
if ((resultVar) == TCL_OK && (wideVar) >= Tcl_LongAsWide(LONG_MIN) \ |
| 274 |
&& (wideVar) <= Tcl_LongAsWide(LONG_MAX)) { \ |
| 275 |
(objPtr)->typePtr = &tclIntType; \ |
| 276 |
(objPtr)->internalRep.longValue = (longVar) \ |
| 277 |
= Tcl_WideAsLong(wideVar); \ |
| 278 |
} |
| 279 |
#define GET_WIDE_OR_INT(resultVar, objPtr, longVar, wideVar) \ |
| 280 |
(resultVar) = Tcl_GetWideIntFromObj((Tcl_Interp *) NULL, (objPtr), \ |
| 281 |
&(wideVar)); \ |
| 282 |
if ((resultVar) == TCL_OK && (wideVar) >= Tcl_LongAsWide(LONG_MIN) \ |
| 283 |
&& (wideVar) <= Tcl_LongAsWide(LONG_MAX)) { \ |
| 284 |
(objPtr)->typePtr = &tclIntType; \ |
| 285 |
(objPtr)->internalRep.longValue = (longVar) \ |
| 286 |
= Tcl_WideAsLong(wideVar); \ |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
#define FORCE_LONG(objPtr, longVar, wideVar) \ |
| 293 |
if ((objPtr)->typePtr == &tclWideIntType) { \ |
| 294 |
(longVar) = Tcl_WideAsLong(wideVar); \ |
| 295 |
} |
| 296 |
#define IS_INTEGER_TYPE(typePtr) \ |
| 297 |
((typePtr) == &tclIntType || (typePtr) == &tclWideIntType) |
| 298 |
#define IS_NUMERIC_TYPE(typePtr) \ |
| 299 |
(IS_INTEGER_TYPE(typePtr) || (typePtr) == &tclDoubleType) |
| 300 |
|
| 301 |
#define W0 Tcl_LongAsWide(0) |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
#define LLD "%" TCL_LL_MODIFIER "d" |
| 306 |
|
| 307 |
#ifndef TCL_WIDE_INT_IS_LONG |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
#define GET_DOUBLE_VALUE(doubleVar, objPtr, typePtr) \ |
| 312 |
if ((typePtr) == &tclIntType) { \ |
| 313 |
(doubleVar) = (double) (objPtr)->internalRep.longValue; \ |
| 314 |
} else if ((typePtr) == &tclWideIntType) { \ |
| 315 |
(doubleVar) = Tcl_WideAsDouble((objPtr)->internalRep.wideValue);\ |
| 316 |
} else { \ |
| 317 |
(doubleVar) = (objPtr)->internalRep.doubleValue; \ |
| 318 |
} |
| 319 |
#else |
| 320 |
#define GET_DOUBLE_VALUE(doubleVar, objPtr, typePtr) \ |
| 321 |
if (((typePtr) == &tclIntType) || ((typePtr) == &tclWideIntType)) { \ |
| 322 |
(doubleVar) = (double) (objPtr)->internalRep.longValue; \ |
| 323 |
} else { \ |
| 324 |
(doubleVar) = (objPtr)->internalRep.doubleValue; \ |
| 325 |
} |
| 326 |
#endif |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
static int TclExecuteByteCode _ANSI_ARGS_((Tcl_Interp *interp, |
| 333 |
ByteCode *codePtr)); |
| 334 |
static int ExprAbsFunc _ANSI_ARGS_((Tcl_Interp *interp, |
| 335 |
ExecEnv *eePtr, ClientData clientData)); |
| 336 |
static int ExprBinaryFunc _ANSI_ARGS_((Tcl_Interp *interp, |
| 337 |
ExecEnv *eePtr, ClientData clientData)); |
| 338 |
static int ExprCallMathFunc _ANSI_ARGS_((Tcl_Interp *interp, |
| 339 |
ExecEnv *eePtr, int objc, Tcl_Obj **objv)); |
| 340 |
static int ExprDoubleFunc _ANSI_ARGS_((Tcl_Interp *interp, |
| 341 |
ExecEnv *eePtr, ClientData clientData)); |
| 342 |
static int ExprIntFunc _ANSI_ARGS_((Tcl_Interp *interp, |
| 343 |
ExecEnv *eePtr, ClientData clientData)); |
| 344 |
static int ExprRandFunc _ANSI_ARGS_((Tcl_Interp *interp, |
| 345 |
ExecEnv *eePtr, ClientData clientData)); |
| 346 |
static int ExprRoundFunc _ANSI_ARGS_((Tcl_Interp *interp, |
| 347 |
ExecEnv *eePtr, ClientData clientData)); |
| 348 |
static int ExprSrandFunc _ANSI_ARGS_((Tcl_Interp *interp, |
| 349 |
ExecEnv *eePtr, ClientData clientData)); |
| 350 |
static int ExprUnaryFunc _ANSI_ARGS_((Tcl_Interp *interp, |
| 351 |
ExecEnv *eePtr, ClientData clientData)); |
| 352 |
static int ExprWideFunc _ANSI_ARGS_((Tcl_Interp *interp, |
| 353 |
ExecEnv *eePtr, ClientData clientData)); |
| 354 |
#ifdef TCL_COMPILE_STATS |
| 355 |
static int EvalStatsCmd _ANSI_ARGS_((ClientData clientData, |
| 356 |
Tcl_Interp *interp, int objc, |
| 357 |
Tcl_Obj *CONST objv[])); |
| 358 |
#endif |
| 359 |
#ifdef TCL_COMPILE_DEBUG |
| 360 |
static char * GetOpcodeName _ANSI_ARGS_((unsigned char *pc)); |
| 361 |
#endif |
| 362 |
static ExceptionRange * GetExceptRangeForPc _ANSI_ARGS_((unsigned char *pc, |
| 363 |
int catchOnly, ByteCode* codePtr)); |
| 364 |
static char * GetSrcInfoForPc _ANSI_ARGS_((unsigned char *pc, |
| 365 |
ByteCode* codePtr, int *lengthPtr)); |
| 366 |
static void GrowEvaluationStack _ANSI_ARGS_((ExecEnv *eePtr)); |
| 367 |
static void IllegalExprOperandType _ANSI_ARGS_(( |
| 368 |
Tcl_Interp *interp, unsigned char *pc, |
| 369 |
Tcl_Obj *opndPtr)); |
| 370 |
static void InitByteCodeExecution _ANSI_ARGS_(( |
| 371 |
Tcl_Interp *interp)); |
| 372 |
#ifdef TCL_COMPILE_DEBUG |
| 373 |
static void PrintByteCodeInfo _ANSI_ARGS_((ByteCode *codePtr)); |
| 374 |
static char * StringForResultCode _ANSI_ARGS_((int result)); |
| 375 |
static void ValidatePcAndStackTop _ANSI_ARGS_(( |
| 376 |
ByteCode *codePtr, unsigned char *pc, |
| 377 |
int stackTop, int stackLowerBound)); |
| 378 |
#endif |
| 379 |
static int VerifyExprObjType _ANSI_ARGS_((Tcl_Interp *interp, |
| 380 |
Tcl_Obj *objPtr)); |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
BuiltinFunc tclBuiltinFuncTable[] = { |
| 389 |
#ifndef TCL_NO_MATH |
| 390 |
{"acos", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) acos}, |
| 391 |
{"asin", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) asin}, |
| 392 |
{"atan", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) atan}, |
| 393 |
{"atan2", 2, {TCL_DOUBLE, TCL_DOUBLE}, ExprBinaryFunc, (ClientData) atan2}, |
| 394 |
{"ceil", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) ceil}, |
| 395 |
{"cos", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) cos}, |
| 396 |
{"cosh", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) cosh}, |
| 397 |
{"exp", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) exp}, |
| 398 |
{"floor", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) floor}, |
| 399 |
{"fmod", 2, {TCL_DOUBLE, TCL_DOUBLE}, ExprBinaryFunc, (ClientData) fmod}, |
| 400 |
{"hypot", 2, {TCL_DOUBLE, TCL_DOUBLE}, ExprBinaryFunc, (ClientData) hypot}, |
| 401 |
{"log", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) log}, |
| 402 |
{"log10", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) log10}, |
| 403 |
{"pow", 2, {TCL_DOUBLE, TCL_DOUBLE}, ExprBinaryFunc, (ClientData) pow}, |
| 404 |
{"sin", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) sin}, |
| 405 |
{"sinh", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) sinh}, |
| 406 |
{"sqrt", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) sqrt}, |
| 407 |
{"tan", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) tan}, |
| 408 |
{"tanh", 1, {TCL_DOUBLE}, ExprUnaryFunc, (ClientData) tanh}, |
| 409 |
#endif |
| 410 |
{"abs", 1, {TCL_EITHER}, ExprAbsFunc, 0}, |
| 411 |
{"double", 1, {TCL_EITHER}, ExprDoubleFunc, 0}, |
| 412 |
{"int", 1, {TCL_EITHER}, ExprIntFunc, 0}, |
| 413 |
{"rand", 0, {TCL_EITHER}, ExprRandFunc, 0}, |
| 414 |
{"round", 1, {TCL_EITHER}, ExprRoundFunc, 0}, |
| 415 |
{"srand", 1, {TCL_INT}, ExprSrandFunc, 0}, |
| 416 |
{"wide", 1, {TCL_EITHER}, ExprWideFunc, 0}, |
| 417 |
{0}, |
| 418 |
}; |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
static void |
| 442 |
InitByteCodeExecution(interp) |
| 443 |
Tcl_Interp *interp; |
| 444 |
|
| 445 |
|
| 446 |
{ |
| 447 |
#ifdef TCL_COMPILE_DEBUG |
| 448 |
if (Tcl_LinkVar(interp, "tcl_traceExec", (char *) &tclTraceExec, |
| 449 |
TCL_LINK_INT) != TCL_OK) { |
| 450 |
panic("InitByteCodeExecution: can't create link for tcl_traceExec variable"); |
| 451 |
} |
| 452 |
#endif |
| 453 |
#ifdef TCL_COMPILE_STATS |
| 454 |
Tcl_CreateObjCommand(interp, "evalstats", EvalStatsCmd, |
| 455 |
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); |
| 456 |
#endif |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
#define TCL_STACK_INITIAL_SIZE 2000 |
| 482 |
|
| 483 |
ExecEnv * |
| 484 |
TclCreateExecEnv(interp) |
| 485 |
Tcl_Interp *interp; |
| 486 |
|
| 487 |
{ |
| 488 |
ExecEnv *eePtr = (ExecEnv *) ckalloc(sizeof(ExecEnv)); |
| 489 |
Tcl_Obj **stackPtr; |
| 490 |
|
| 491 |
stackPtr = (Tcl_Obj **) |
| 492 |
ckalloc((size_t) (TCL_STACK_INITIAL_SIZE * sizeof(Tcl_Obj *))); |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
stackPtr++; |
| 500 |
eePtr->stackPtr = stackPtr; |
| 501 |
stackPtr[-1] = (Tcl_Obj *) ((char *) 1); |
| 502 |
|
| 503 |
eePtr->stackTop = -1; |
| 504 |
eePtr->stackEnd = (TCL_STACK_INITIAL_SIZE - 2); |
| 505 |
|
| 506 |
eePtr->errorInfo = Tcl_NewStringObj("::errorInfo", -1); |
| 507 |
Tcl_IncrRefCount(eePtr->errorInfo); |
| 508 |
|
| 509 |
eePtr->errorCode = Tcl_NewStringObj("::errorCode", -1); |
| 510 |
Tcl_IncrRefCount(eePtr->errorCode); |
| 511 |
|
| 512 |
Tcl_MutexLock(&execMutex); |
| 513 |
if (!execInitialized) { |
| 514 |
TclInitAuxDataTypeTable(); |
| 515 |
InitByteCodeExecution(interp); |
| 516 |
execInitialized = 1; |
| 517 |
} |
| 518 |
Tcl_MutexUnlock(&execMutex); |
| 519 |
|
| 520 |
return eePtr; |
| 521 |
} |
| 522 |
#undef TCL_STACK_INITIAL_SIZE |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
void |
| 542 |
TclDeleteExecEnv(eePtr) |
| 543 |
ExecEnv *eePtr; |
| 544 |
{ |
| 545 |
if (eePtr->stackPtr[-1] == (Tcl_Obj *) ((char *) 1)) { |
| 546 |
ckfree((char *) (eePtr->stackPtr-1)); |
| 547 |
} else { |
| 548 |
panic("ERROR: freeing an execEnv whose stack is still in use.\n"); |
| 549 |
} |
| 550 |
TclDecrRefCount(eePtr->errorInfo); |
| 551 |
TclDecrRefCount(eePtr->errorCode); |
| 552 |
ckfree((char *) eePtr); |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
void |
| 574 |
TclFinalizeExecution() |
| 575 |
{ |
| 576 |
Tcl_MutexLock(&execMutex); |
| 577 |
execInitialized = 0; |
| 578 |
Tcl_MutexUnlock(&execMutex); |
| 579 |
TclFinalizeAuxDataTypeTable(); |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
static void |
| 599 |
GrowEvaluationStack(eePtr) |
| 600 |
register ExecEnv *eePtr; |
| 601 |
|
| 602 |
{ |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
int currElems = (eePtr->stackEnd + 1); |
| 609 |
int newElems = 2*currElems; |
| 610 |
int currBytes = currElems * sizeof(Tcl_Obj *); |
| 611 |
int newBytes = 2*currBytes; |
| 612 |
Tcl_Obj **newStackPtr = (Tcl_Obj **) ckalloc((unsigned) newBytes); |
| 613 |
Tcl_Obj **oldStackPtr = eePtr->stackPtr; |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
char *refCount = (char *) oldStackPtr[-1]; |
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
newStackPtr++; |
| 629 |
memcpy((VOID *) newStackPtr, (VOID *) oldStackPtr, |
| 630 |
(size_t) currBytes); |
| 631 |
|
| 632 |
if (refCount == (char *) 1) { |
| 633 |
ckfree((VOID *) (oldStackPtr-1)); |
| 634 |
} else { |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
oldStackPtr[-1] = (Tcl_Obj *) (refCount-1); |
| 641 |
} |
| 642 |
|
| 643 |
eePtr->stackPtr = newStackPtr; |
| 644 |
eePtr->stackEnd = (newElems - 2); |
| 645 |
newStackPtr[-1] = (Tcl_Obj *) ((char *) 1); |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
int |
| 673 |
Tcl_ExprObj(interp, objPtr, resultPtrPtr) |
| 674 |
Tcl_Interp *interp; |
| 675 |
|
| 676 |
register Tcl_Obj *objPtr; |
| 677 |
|
| 678 |
Tcl_Obj **resultPtrPtr; |
| 679 |
|
| 680 |
{ |
| 681 |
Interp *iPtr = (Interp *) interp; |
| 682 |
CompileEnv compEnv; |
| 683 |
|
| 684 |
LiteralTable *localTablePtr = &(compEnv.localLitTable); |
| 685 |
register ByteCode *codePtr = NULL; |
| 686 |
|
| 687 |
|
| 688 |
AuxData *auxDataPtr; |
| 689 |
LiteralEntry *entryPtr; |
| 690 |
Tcl_Obj *saveObjPtr; |
| 691 |
char *string; |
| 692 |
int length, i, result; |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
string = Tcl_GetStringFromObj(objPtr, &length); |
| 699 |
if (length == 1) { |
| 700 |
if (*string == '0') { |
| 701 |
*resultPtrPtr = Tcl_NewLongObj(0); |
| 702 |
Tcl_IncrRefCount(*resultPtrPtr); |
| 703 |
return TCL_OK; |
| 704 |
} else if (*string == '1') { |
| 705 |
*resultPtrPtr = Tcl_NewLongObj(1); |
| 706 |
Tcl_IncrRefCount(*resultPtrPtr); |
| 707 |
return TCL_OK; |
| 708 |
} |
| 709 |
} else if ((length == 2) && (*string == '!')) { |
| 710 |
if (*(string+1) == '0') { |
| 711 |
*resultPtrPtr = Tcl_NewLongObj(1); |
| 712 |
Tcl_IncrRefCount(*resultPtrPtr); |
| 713 |
return TCL_OK; |
| 714 |
} else if (*(string+1) == '1') { |
| 715 |
*resultPtrPtr = Tcl_NewLongObj(0); |
| 716 |
Tcl_IncrRefCount(*resultPtrPtr); |
| 717 |
return TCL_OK; |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
if (objPtr->typePtr == &tclByteCodeType) { |
| 735 |
codePtr = (ByteCode *) objPtr->internalRep.otherValuePtr; |
| 736 |
if (((Interp *) *codePtr->interpHandle != iPtr) |
| 737 |
|| (codePtr->compileEpoch != iPtr->compileEpoch)) { |
| 738 |
if (codePtr->flags & TCL_BYTECODE_PRECOMPILED) { |
| 739 |
if ((Interp *) *codePtr->interpHandle != iPtr) { |
| 740 |
panic("Tcl_ExprObj: compiled expression jumped interps"); |
| 741 |
} |
| 742 |
codePtr->compileEpoch = iPtr->compileEpoch; |
| 743 |
} else { |
| 744 |
(*tclByteCodeType.freeIntRepProc)(objPtr); |
| 745 |
objPtr->typePtr = (Tcl_ObjType *) NULL; |
| 746 |
} |
| 747 |
} |
| 748 |
} |
| 749 |
if (objPtr->typePtr != &tclByteCodeType) { |
| 750 |
TclInitCompileEnv(interp, &compEnv, string, length); |
| 751 |
result = TclCompileExpr(interp, string, length, &compEnv); |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
if (localTablePtr->buckets != localTablePtr->staticBuckets) { |
| 759 |
ckfree((char *) localTablePtr->buckets); |
| 760 |
} |
| 761 |
|
| 762 |
if (result != TCL_OK) { |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
#ifdef TCL_COMPILE_DEBUG |
| 768 |
TclVerifyLocalLiteralTable(&compEnv); |
| 769 |
#endif |
| 770 |
entryPtr = compEnv.literalArrayPtr; |
| 771 |
for (i = 0; i < compEnv.literalArrayNext; i++) { |
| 772 |
TclReleaseLiteral(interp, entryPtr->objPtr); |
| 773 |
entryPtr++; |
| 774 |
} |
| 775 |
#ifdef TCL_COMPILE_DEBUG |
| 776 |
TclVerifyGlobalLiteralTable(iPtr); |
| 777 |
#endif |
| 778 |
|
| 779 |
auxDataPtr = compEnv.auxDataArrayPtr; |
| 780 |
for (i = 0; i < compEnv.auxDataArrayNext; i++) { |
| 781 |
if (auxDataPtr->type->freeProc != NULL) { |
| 782 |
auxDataPtr->type->freeProc(auxDataPtr->clientData); |
| 783 |
} |
| 784 |
auxDataPtr++; |
| 785 |
} |
| 786 |
TclFreeCompileEnv(&compEnv); |
| 787 |
return result; |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
if (compEnv.codeNext == compEnv.codeStart) { |
| 796 |
TclEmitPush(TclRegisterLiteral(&compEnv, "0", 1, 0), |
| 797 |
&compEnv); |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
compEnv.numSrcBytes = iPtr->termOffset; |
| 807 |
TclEmitOpcode(INST_DONE, &compEnv); |
| 808 |
TclInitByteCodeObj(objPtr, &compEnv); |
| 809 |
TclFreeCompileEnv(&compEnv); |
| 810 |
codePtr = (ByteCode *) objPtr->internalRep.otherValuePtr; |
| 811 |
#ifdef TCL_COMPILE_DEBUG |
| 812 |
if (tclTraceCompile == 2) { |
| 813 |
TclPrintByteCodeObj(interp, objPtr); |
| 814 |
} |
| 815 |
#endif |
| 816 |
} |
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
saveObjPtr = Tcl_GetObjResult(interp); |
| 823 |
Tcl_IncrRefCount(saveObjPtr); |
| 824 |
Tcl_ResetResult(interp); |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
codePtr->refCount++; |
| 832 |
result = TclExecuteByteCode(interp, codePtr); |
| 833 |
codePtr->refCount--; |
| 834 |
if (codePtr->refCount <= 0) { |
| 835 |
TclCleanupByteCode(codePtr); |
| 836 |
objPtr->typePtr = NULL; |
| 837 |
objPtr->internalRep.otherValuePtr = NULL; |
| 838 |
} |
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
if (result == TCL_OK) { |
| 850 |
*resultPtrPtr = iPtr->objResultPtr; |
| 851 |
Tcl_IncrRefCount(iPtr->objResultPtr); |
| 852 |
|
| 853 |
Tcl_SetObjResult(interp, saveObjPtr); |
| 854 |
} |
| 855 |
TclDecrRefCount(saveObjPtr); |
| 856 |
return result; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
int |
| 880 |
TclCompEvalObj(interp, objPtr) |
| 881 |
Tcl_Interp *interp; |
| 882 |
Tcl_Obj *objPtr; |
| 883 |
{ |
| 884 |
register Interp *iPtr = (Interp *) interp; |
| 885 |
register ByteCode* codePtr; |
| 886 |
int oldCount = iPtr->cmdCount; |
| 887 |
|
| 888 |
char *script; |
| 889 |
int numSrcBytes; |
| 890 |
int result; |
| 891 |
Namespace *namespacePtr; |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
iPtr->numLevels++; |
| 899 |
if (TclInterpReady(interp) == TCL_ERROR) { |
| 900 |
iPtr->numLevels--; |
| 901 |
return TCL_ERROR; |
| 902 |
} |
| 903 |
|
| 904 |
if (iPtr->varFramePtr != NULL) { |
| 905 |
namespacePtr = iPtr->varFramePtr->nsPtr; |
| 906 |
} else { |
| 907 |
namespacePtr = iPtr->globalNsPtr; |
| 908 |
} |
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
if (objPtr->typePtr != &tclByteCodeType) { |
| 918 |
recompileObj: |
| 919 |
iPtr->errorLine = 1; |
| 920 |
result = tclByteCodeType.setFromAnyProc(interp, objPtr); |
| 921 |
if (result != TCL_OK) { |
| 922 |
iPtr->numLevels--; |
| 923 |
return result; |
| 924 |
} |
| 925 |
iPtr->evalFlags = 0; |
| 926 |
codePtr = (ByteCode *) objPtr->internalRep.otherValuePtr; |
| 927 |
} else { |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
codePtr = (ByteCode *) objPtr->internalRep.otherValuePtr; |
| 946 |
if (((Interp *) *codePtr->interpHandle != iPtr) |
| 947 |
|| (codePtr->compileEpoch != iPtr->compileEpoch) |
| 948 |
#ifdef CHECK_PROC_ORIGINATION |
| 949 |
|| (codePtr->procPtr != NULL && !(iPtr->varFramePtr && |
| 950 |
iPtr->varFramePtr->procPtr == codePtr->procPtr)) |
| 951 |
#endif |
| 952 |
|| (codePtr->nsPtr != namespacePtr) |
| 953 |
|| (codePtr->nsEpoch != namespacePtr->resolverEpoch)) { |
| 954 |
if (codePtr->flags & TCL_BYTECODE_PRECOMPILED) { |
| 955 |
if ((Interp *) *codePtr->interpHandle != iPtr) { |
| 956 |
panic("Tcl_EvalObj: compiled script jumped interps"); |
| 957 |
} |
| 958 |
codePtr->compileEpoch = iPtr->compileEpoch; |
| 959 |
} else { |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
tclByteCodeType.freeIntRepProc(objPtr); |
| 964 |
goto recompileObj; |
| 965 |
} |
| 966 |
} |
| 967 |
} |
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
numSrcBytes = codePtr->numSrcBytes; |
| 975 |
if ((numSrcBytes > 0) || (codePtr->flags & TCL_BYTECODE_PRECOMPILED)) { |
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
codePtr->refCount++; |
| 982 |
result = TclExecuteByteCode(interp, codePtr); |
| 983 |
codePtr->refCount--; |
| 984 |
if (codePtr->refCount <= 0) { |
| 985 |
TclCleanupByteCode(codePtr); |
| 986 |
} |
| 987 |
} else { |
| 988 |
result = TCL_OK; |
| 989 |
} |
| 990 |
iPtr->numLevels--; |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
if ((oldCount == iPtr->cmdCount) && Tcl_AsyncReady()) { |
| 1001 |
result = Tcl_AsyncInvoke(interp, result); |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
if ((result == TCL_ERROR) && !(iPtr->flags & ERR_ALREADY_LOGGED)) { |
| 1010 |
script = Tcl_GetStringFromObj(objPtr, &numSrcBytes); |
| 1011 |
Tcl_LogCommandInfo(interp, script, script, numSrcBytes); |
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
iPtr->termOffset = numSrcBytes; |
| 1023 |
iPtr->flags &= ~ERR_ALREADY_LOGGED; |
| 1024 |
|
| 1025 |
return result; |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
static int |
| 1049 |
TclExecuteByteCode(interp, codePtr) |
| 1050 |
Tcl_Interp *interp; |
| 1051 |
ByteCode *codePtr; |
| 1052 |
{ |
| 1053 |
Interp *iPtr = (Interp *) interp; |
| 1054 |
ExecEnv *eePtr = iPtr->execEnvPtr; |
| 1055 |
|
| 1056 |
register Tcl_Obj **stackPtr = eePtr->stackPtr; |
| 1057 |
|
| 1058 |
register int stackTop = eePtr->stackTop; |
| 1059 |
|
| 1060 |
register unsigned char *pc = codePtr->codeStart; |
| 1061 |
|
| 1062 |
int opnd; |
| 1063 |
int pcAdjustment; |
| 1064 |
int initStackTop = stackTop; |
| 1065 |
ExceptionRange *rangePtr; |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
int result = TCL_OK; |
| 1070 |
int storeFlags; |
| 1071 |
Tcl_Obj *valuePtr, *value2Ptr, *objPtr; |
| 1072 |
char *bytes; |
| 1073 |
int length; |
| 1074 |
long i = 0; |
| 1075 |
Tcl_WideInt w; |
| 1076 |
register int cleanup; |
| 1077 |
Tcl_Obj *objResultPtr; |
| 1078 |
char *part1, *part2; |
| 1079 |
Var *varPtr, *arrayPtr; |
| 1080 |
CallFrame *varFramePtr = iPtr->varFramePtr; |
| 1081 |
#ifdef TCL_COMPILE_DEBUG |
| 1082 |
int traceInstructions = (tclTraceExec == 3); |
| 1083 |
char cmdNameBuf[21]; |
| 1084 |
#endif |
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
#define STATIC_CATCH_STACK_SIZE 4 |
| 1094 |
int (catchStackStorage[STATIC_CATCH_STACK_SIZE]); |
| 1095 |
int *catchStackPtr = catchStackStorage; |
| 1096 |
int catchTop = -1; |
| 1097 |
|
| 1098 |
#ifdef TCL_COMPILE_DEBUG |
| 1099 |
if (tclTraceExec >= 2) { |
| 1100 |
PrintByteCodeInfo(codePtr); |
| 1101 |
fprintf(stdout, " Starting stack top=%d\n", eePtr->stackTop); |
| 1102 |
fflush(stdout); |
| 1103 |
} |
| 1104 |
opnd = 0; |
| 1105 |
#endif |
| 1106 |
|
| 1107 |
#ifdef TCL_COMPILE_STATS |
| 1108 |
iPtr->stats.numExecutions++; |
| 1109 |
#endif |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
if (codePtr->maxExceptDepth > STATIC_CATCH_STACK_SIZE) { |
| 1118 |
catchStackPtr = (int *) |
| 1119 |
ckalloc(codePtr->maxExceptDepth * sizeof(int)); |
| 1120 |
} |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
while ((stackTop + codePtr->maxStackDepth) > eePtr->stackEnd) { |
| 1127 |
GrowEvaluationStack(eePtr); |
| 1128 |
stackPtr = eePtr->stackPtr; |
| 1129 |
} |
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
goto cleanup0; |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
cleanupV_pushObjResultPtr: |
| 1149 |
switch (cleanup) { |
| 1150 |
case 0: |
| 1151 |
stackPtr[++stackTop] = (objResultPtr); |
| 1152 |
goto cleanup0; |
| 1153 |
default: |
| 1154 |
cleanup -= 2; |
| 1155 |
while (cleanup--) { |
| 1156 |
valuePtr = POP_OBJECT(); |
| 1157 |
TclDecrRefCount(valuePtr); |
| 1158 |
} |
| 1159 |
case 2: |
| 1160 |
cleanup2_pushObjResultPtr: |
| 1161 |
valuePtr = POP_OBJECT(); |
| 1162 |
TclDecrRefCount(valuePtr); |
| 1163 |
case 1: |
| 1164 |
cleanup1_pushObjResultPtr: |
| 1165 |
valuePtr = stackPtr[stackTop]; |
| 1166 |
TclDecrRefCount(valuePtr); |
| 1167 |
} |
| 1168 |
stackPtr[stackTop] = objResultPtr; |
| 1169 |
goto cleanup0; |
| 1170 |
|
| 1171 |
cleanupV: |
| 1172 |
switch (cleanup) { |
| 1173 |
default: |
| 1174 |
cleanup -= 2; |
| 1175 |
while (cleanup--) { |
| 1176 |
valuePtr = POP_OBJECT(); |
| 1177 |
TclDecrRefCount(valuePtr); |
| 1178 |
} |
| 1179 |
case 2: |
| 1180 |
cleanup2: |
| 1181 |
valuePtr = POP_OBJECT(); |
| 1182 |
TclDecrRefCount(valuePtr); |
| 1183 |
case 1: |
| 1184 |
cleanup1: |
| 1185 |
valuePtr = POP_OBJECT(); |
| 1186 |
TclDecrRefCount(valuePtr); |
| 1187 |
case 0: |
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
break; |
| 1193 |
} |
| 1194 |
|
| 1195 |
cleanup0: |
| 1196 |
|
| 1197 |
#ifdef TCL_COMPILE_DEBUG |
| 1198 |
ValidatePcAndStackTop(codePtr, pc, stackTop, initStackTop); |
| 1199 |
if (traceInstructions) { |
| 1200 |
fprintf(stdout, "%2d: %2d ", iPtr->numLevels, stackTop); |
| 1201 |
TclPrintInstruction(codePtr, pc); |
| 1202 |
fflush(stdout); |
| 1203 |
} |
| 1204 |
#endif |
| 1205 |
|
| 1206 |
#ifdef TCL_COMPILE_STATS |
| 1207 |
iPtr->stats.instructionCount[*pc]++; |
| 1208 |
#endif |
| 1209 |
switch (*pc) { |
| 1210 |
case INST_DONE: |
| 1211 |
if (stackTop <= initStackTop) { |
| 1212 |
stackTop--; |
| 1213 |
goto abnormalReturn; |
| 1214 |
} |
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
valuePtr = stackPtr[stackTop]; |
| 1224 |
Tcl_SetObjResult(interp, valuePtr); |
| 1225 |
#ifdef TCL_COMPILE_DEBUG |
| 1226 |
TRACE_WITH_OBJ(("=> return code=%d, result=", result), |
| 1227 |
iPtr->objResultPtr); |
| 1228 |
if (traceInstructions) { |
| 1229 |
fprintf(stdout, "\n"); |
| 1230 |
} |
| 1231 |
#endif |
| 1232 |
goto checkForCatch; |
| 1233 |
|
| 1234 |
case INST_PUSH1: |
| 1235 |
objResultPtr = codePtr->objArrayPtr[TclGetUInt1AtPtr(pc+1)]; |
| 1236 |
TRACE_WITH_OBJ(("%u => ", TclGetInt1AtPtr(pc+1)), objResultPtr); |
| 1237 |
NEXT_INST_F(2, 0, 1); |
| 1238 |
|
| 1239 |
case INST_PUSH4: |
| 1240 |
objResultPtr = codePtr->objArrayPtr[TclGetUInt4AtPtr(pc+1)]; |
| 1241 |
TRACE_WITH_OBJ(("%u => ", TclGetUInt4AtPtr(pc+1)), objResultPtr); |
| 1242 |
NEXT_INST_F(5, 0, 1); |
| 1243 |
|
| 1244 |
case INST_POP: |
| 1245 |
TRACE_WITH_OBJ(("=> discarding "), stackPtr[stackTop]); |
| 1246 |
valuePtr = POP_OBJECT(); |
| 1247 |
TclDecrRefCount(valuePtr); |
| 1248 |
NEXT_INST_F(1, 0, 0); |
| 1249 |
|
| 1250 |
case INST_DUP: |
| 1251 |
objResultPtr = stackPtr[stackTop]; |
| 1252 |
TRACE_WITH_OBJ(("=> "), objResultPtr); |
| 1253 |
NEXT_INST_F(1, 0, 1); |
| 1254 |
|
| 1255 |
case INST_OVER: |
| 1256 |
opnd = TclGetUInt4AtPtr( pc+1 ); |
| 1257 |
objResultPtr = stackPtr[ stackTop - opnd ]; |
| 1258 |
TRACE_WITH_OBJ(("=> "), objResultPtr); |
| 1259 |
NEXT_INST_F(5, 0, 1); |
| 1260 |
|
| 1261 |
case INST_CONCAT1: |
| 1262 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1263 |
{ |
| 1264 |
int totalLen = 0; |
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
for (i = (stackTop - (opnd-1)); i <= stackTop; i++) { |
| 1273 |
bytes = Tcl_GetStringFromObj(stackPtr[i], &length); |
| 1274 |
if (bytes != NULL) { |
| 1275 |
totalLen += length; |
| 1276 |
} |
| 1277 |
} |
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
TclNewObj(objResultPtr); |
| 1285 |
if (totalLen > 0) { |
| 1286 |
char *p = (char *) ckalloc((unsigned) (totalLen + 1)); |
| 1287 |
objResultPtr->bytes = p; |
| 1288 |
objResultPtr->length = totalLen; |
| 1289 |
for (i = (stackTop - (opnd-1)); i <= stackTop; i++) { |
| 1290 |
valuePtr = stackPtr[i]; |
| 1291 |
bytes = Tcl_GetStringFromObj(valuePtr, &length); |
| 1292 |
if (bytes != NULL) { |
| 1293 |
memcpy((VOID *) p, (VOID *) bytes, |
| 1294 |
(size_t) length); |
| 1295 |
p += length; |
| 1296 |
} |
| 1297 |
} |
| 1298 |
*p = '\0'; |
| 1299 |
} |
| 1300 |
|
| 1301 |
TRACE_WITH_OBJ(("%u => ", opnd), objResultPtr); |
| 1302 |
NEXT_INST_V(2, opnd, 1); |
| 1303 |
} |
| 1304 |
|
| 1305 |
case INST_INVOKE_STK4: |
| 1306 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 1307 |
pcAdjustment = 5; |
| 1308 |
goto doInvocation; |
| 1309 |
|
| 1310 |
case INST_INVOKE_STK1: |
| 1311 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1312 |
pcAdjustment = 2; |
| 1313 |
|
| 1314 |
doInvocation: |
| 1315 |
{ |
| 1316 |
int objc = opnd; |
| 1317 |
Tcl_Obj **objv; |
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
char **preservedStackRefCountPtr; |
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
objv = &(stackPtr[stackTop - (objc-1)]); |
| 1333 |
|
| 1334 |
#ifdef TCL_COMPILE_DEBUG |
| 1335 |
if (tclTraceExec >= 2) { |
| 1336 |
if (traceInstructions) { |
| 1337 |
strncpy(cmdNameBuf, TclGetString(objv[0]), 20); |
| 1338 |
TRACE(("%u => call ", objc)); |
| 1339 |
} else { |
| 1340 |
fprintf(stdout, "%d: (%u) invoking ", |
| 1341 |
iPtr->numLevels, |
| 1342 |
(unsigned int)(pc - codePtr->codeStart)); |
| 1343 |
} |
| 1344 |
for (i = 0; i < objc; i++) { |
| 1345 |
TclPrintObject(stdout, objv[i], 15); |
| 1346 |
fprintf(stdout, " "); |
| 1347 |
} |
| 1348 |
fprintf(stdout, "\n"); |
| 1349 |
fflush(stdout); |
| 1350 |
} |
| 1351 |
#endif |
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
bytes = NULL; |
| 1361 |
length = 0; |
| 1362 |
if (iPtr->tracePtr != NULL) { |
| 1363 |
Trace *tracePtr, *nextTracePtr; |
| 1364 |
|
| 1365 |
for (tracePtr = iPtr->tracePtr; tracePtr != NULL; |
| 1366 |
tracePtr = nextTracePtr) { |
| 1367 |
nextTracePtr = tracePtr->nextPtr; |
| 1368 |
if (tracePtr->level == 0 || |
| 1369 |
iPtr->numLevels <= tracePtr->level) { |
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
bytes = GetSrcInfoForPc(pc, codePtr, &length); |
| 1375 |
break; |
| 1376 |
} |
| 1377 |
} |
| 1378 |
} else { |
| 1379 |
Command *cmdPtr; |
| 1380 |
cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, objv[0]); |
| 1381 |
if ((cmdPtr != NULL) && (cmdPtr->flags & CMD_HAS_EXEC_TRACES)) { |
| 1382 |
bytes = GetSrcInfoForPc(pc, codePtr, &length); |
| 1383 |
} |
| 1384 |
} |
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
preservedStackRefCountPtr = (char **) (stackPtr-1); |
| 1396 |
++*preservedStackRefCountPtr; |
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
DECACHE_STACK_INFO(); |
| 1403 |
Tcl_ResetResult(interp); |
| 1404 |
result = TclEvalObjvInternal(interp, objc, objv, bytes, length, 0); |
| 1405 |
CACHE_STACK_INFO(); |
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
--*preservedStackRefCountPtr; |
| 1414 |
if (*preservedStackRefCountPtr == (char *) 0) { |
| 1415 |
ckfree((VOID *) preservedStackRefCountPtr); |
| 1416 |
} |
| 1417 |
|
| 1418 |
if (result == TCL_OK) { |
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
TRACE_WITH_OBJ(("%u => ... after \"%.20s\": TCL_OK, result=", |
| 1425 |
objc, cmdNameBuf), Tcl_GetObjResult(interp)); |
| 1426 |
|
| 1427 |
objResultPtr = Tcl_GetObjResult(interp); |
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
{ |
| 1441 |
Tcl_Obj *newObjResultPtr; |
| 1442 |
TclNewObj(newObjResultPtr); |
| 1443 |
Tcl_IncrRefCount(newObjResultPtr); |
| 1444 |
iPtr->objResultPtr = newObjResultPtr; |
| 1445 |
} |
| 1446 |
|
| 1447 |
NEXT_INST_V(pcAdjustment, opnd, -1); |
| 1448 |
} else { |
| 1449 |
cleanup = opnd; |
| 1450 |
goto processExceptionReturn; |
| 1451 |
} |
| 1452 |
} |
| 1453 |
|
| 1454 |
case INST_EVAL_STK: |
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
objPtr = stackPtr[stackTop]; |
| 1462 |
DECACHE_STACK_INFO(); |
| 1463 |
result = TclCompEvalObj(interp, objPtr); |
| 1464 |
CACHE_STACK_INFO(); |
| 1465 |
if (result == TCL_OK) { |
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
objResultPtr = Tcl_GetObjResult(interp); |
| 1471 |
TRACE_WITH_OBJ(("\"%.30s\" => ", O2S(objPtr)), |
| 1472 |
Tcl_GetObjResult(interp)); |
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
{ |
| 1486 |
Tcl_Obj *newObjResultPtr; |
| 1487 |
TclNewObj(newObjResultPtr); |
| 1488 |
Tcl_IncrRefCount(newObjResultPtr); |
| 1489 |
iPtr->objResultPtr = newObjResultPtr; |
| 1490 |
} |
| 1491 |
|
| 1492 |
NEXT_INST_F(1, 1, -1); |
| 1493 |
} else { |
| 1494 |
cleanup = 1; |
| 1495 |
goto processExceptionReturn; |
| 1496 |
} |
| 1497 |
|
| 1498 |
case INST_EXPR_STK: |
| 1499 |
objPtr = stackPtr[stackTop]; |
| 1500 |
DECACHE_STACK_INFO(); |
| 1501 |
Tcl_ResetResult(interp); |
| 1502 |
result = Tcl_ExprObj(interp, objPtr, &valuePtr); |
| 1503 |
CACHE_STACK_INFO(); |
| 1504 |
if (result != TCL_OK) { |
| 1505 |
TRACE_WITH_OBJ(("\"%.30s\" => ERROR: ", |
| 1506 |
O2S(objPtr)), Tcl_GetObjResult(interp)); |
| 1507 |
goto checkForCatch; |
| 1508 |
} |
| 1509 |
objResultPtr = valuePtr; |
| 1510 |
TRACE_WITH_OBJ(("\"%.30s\" => ", O2S(objPtr)), valuePtr); |
| 1511 |
NEXT_INST_F(1, 1, -1); |
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
case INST_LOAD_SCALAR1: |
| 1523 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1524 |
varPtr = &(varFramePtr->compiledLocals[opnd]); |
| 1525 |
part1 = varPtr->name; |
| 1526 |
while (TclIsVarLink(varPtr)) { |
| 1527 |
varPtr = varPtr->value.linkPtr; |
| 1528 |
} |
| 1529 |
TRACE(("%u => ", opnd)); |
| 1530 |
if (TclIsVarScalar(varPtr) && !TclIsVarUndefined(varPtr) |
| 1531 |
&& (varPtr->tracePtr == NULL)) { |
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
objResultPtr = varPtr->value.objPtr; |
| 1536 |
TRACE_APPEND(("%.30s\n", O2S(objResultPtr))); |
| 1537 |
NEXT_INST_F(2, 0, 1); |
| 1538 |
} |
| 1539 |
pcAdjustment = 2; |
| 1540 |
cleanup = 0; |
| 1541 |
arrayPtr = NULL; |
| 1542 |
part2 = NULL; |
| 1543 |
goto doCallPtrGetVar; |
| 1544 |
|
| 1545 |
case INST_LOAD_SCALAR4: |
| 1546 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 1547 |
varPtr = &(varFramePtr->compiledLocals[opnd]); |
| 1548 |
part1 = varPtr->name; |
| 1549 |
while (TclIsVarLink(varPtr)) { |
| 1550 |
varPtr = varPtr->value.linkPtr; |
| 1551 |
} |
| 1552 |
TRACE(("%u => ", opnd)); |
| 1553 |
if (TclIsVarScalar(varPtr) && !TclIsVarUndefined(varPtr) |
| 1554 |
&& (varPtr->tracePtr == NULL)) { |
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
objResultPtr = varPtr->value.objPtr; |
| 1559 |
TRACE_APPEND(("%.30s\n", O2S(objResultPtr))); |
| 1560 |
NEXT_INST_F(5, 0, 1); |
| 1561 |
} |
| 1562 |
pcAdjustment = 5; |
| 1563 |
cleanup = 0; |
| 1564 |
arrayPtr = NULL; |
| 1565 |
part2 = NULL; |
| 1566 |
goto doCallPtrGetVar; |
| 1567 |
|
| 1568 |
case INST_LOAD_ARRAY_STK: |
| 1569 |
cleanup = 2; |
| 1570 |
part2 = Tcl_GetString(stackPtr[stackTop]); |
| 1571 |
objPtr = stackPtr[stackTop-1]; |
| 1572 |
TRACE(("\"%.30s(%.30s)\" => ", O2S(objPtr), part2)); |
| 1573 |
goto doLoadStk; |
| 1574 |
|
| 1575 |
case INST_LOAD_STK: |
| 1576 |
case INST_LOAD_SCALAR_STK: |
| 1577 |
cleanup = 1; |
| 1578 |
part2 = NULL; |
| 1579 |
objPtr = stackPtr[stackTop]; |
| 1580 |
TRACE(("\"%.30s\" => ", O2S(objPtr))); |
| 1581 |
|
| 1582 |
doLoadStk: |
| 1583 |
part1 = TclGetString(objPtr); |
| 1584 |
varPtr = TclObjLookupVar(interp, objPtr, part2, |
| 1585 |
TCL_LEAVE_ERR_MSG, "read", |
| 1586 |
0, |
| 1587 |
1, &arrayPtr); |
| 1588 |
if (varPtr == NULL) { |
| 1589 |
TRACE_APPEND(("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp)))); |
| 1590 |
result = TCL_ERROR; |
| 1591 |
goto checkForCatch; |
| 1592 |
} |
| 1593 |
if (TclIsVarScalar(varPtr) && !TclIsVarUndefined(varPtr) |
| 1594 |
&& (varPtr->tracePtr == NULL) |
| 1595 |
&& ((arrayPtr == NULL) |
| 1596 |
|| (arrayPtr->tracePtr == NULL))) { |
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
objResultPtr = varPtr->value.objPtr; |
| 1601 |
TRACE_APPEND(("%.30s\n", O2S(objResultPtr))); |
| 1602 |
NEXT_INST_V(1, cleanup, 1); |
| 1603 |
} |
| 1604 |
pcAdjustment = 1; |
| 1605 |
goto doCallPtrGetVar; |
| 1606 |
|
| 1607 |
case INST_LOAD_ARRAY4: |
| 1608 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 1609 |
pcAdjustment = 5; |
| 1610 |
goto doLoadArray; |
| 1611 |
|
| 1612 |
case INST_LOAD_ARRAY1: |
| 1613 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1614 |
pcAdjustment = 2; |
| 1615 |
|
| 1616 |
doLoadArray: |
| 1617 |
part2 = TclGetString(stackPtr[stackTop]); |
| 1618 |
arrayPtr = &(varFramePtr->compiledLocals[opnd]); |
| 1619 |
part1 = arrayPtr->name; |
| 1620 |
while (TclIsVarLink(arrayPtr)) { |
| 1621 |
arrayPtr = arrayPtr->value.linkPtr; |
| 1622 |
} |
| 1623 |
TRACE(("%u \"%.30s\" => ", opnd, part2)); |
| 1624 |
varPtr = TclLookupArrayElement(interp, part1, part2, |
| 1625 |
TCL_LEAVE_ERR_MSG, "read", 0, 1, arrayPtr); |
| 1626 |
if (varPtr == NULL) { |
| 1627 |
TRACE_APPEND(("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp)))); |
| 1628 |
result = TCL_ERROR; |
| 1629 |
goto checkForCatch; |
| 1630 |
} |
| 1631 |
if (TclIsVarScalar(varPtr) && !TclIsVarUndefined(varPtr) |
| 1632 |
&& (varPtr->tracePtr == NULL) |
| 1633 |
&& ((arrayPtr == NULL) |
| 1634 |
|| (arrayPtr->tracePtr == NULL))) { |
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
objResultPtr = varPtr->value.objPtr; |
| 1639 |
TRACE_APPEND(("%.30s\n", O2S(objResultPtr))); |
| 1640 |
NEXT_INST_F(pcAdjustment, 1, 1); |
| 1641 |
} |
| 1642 |
cleanup = 1; |
| 1643 |
goto doCallPtrGetVar; |
| 1644 |
|
| 1645 |
doCallPtrGetVar: |
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
DECACHE_STACK_INFO(); |
| 1652 |
objResultPtr = TclPtrGetVar(interp, varPtr, arrayPtr, part1, |
| 1653 |
part2, TCL_LEAVE_ERR_MSG); |
| 1654 |
CACHE_STACK_INFO(); |
| 1655 |
if (objResultPtr == NULL) { |
| 1656 |
TRACE_APPEND(("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp)))); |
| 1657 |
result = TCL_ERROR; |
| 1658 |
goto checkForCatch; |
| 1659 |
} |
| 1660 |
TRACE_APPEND(("%.30s\n", O2S(objResultPtr))); |
| 1661 |
NEXT_INST_V(pcAdjustment, cleanup, 1); |
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
case INST_LAPPEND_STK: |
| 1678 |
valuePtr = stackPtr[stackTop]; |
| 1679 |
part2 = NULL; |
| 1680 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE |
| 1681 |
| TCL_LIST_ELEMENT | TCL_TRACE_READS); |
| 1682 |
goto doStoreStk; |
| 1683 |
|
| 1684 |
case INST_LAPPEND_ARRAY_STK: |
| 1685 |
valuePtr = stackPtr[stackTop]; |
| 1686 |
part2 = TclGetString(stackPtr[stackTop - 1]); |
| 1687 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE |
| 1688 |
| TCL_LIST_ELEMENT | TCL_TRACE_READS); |
| 1689 |
goto doStoreStk; |
| 1690 |
|
| 1691 |
case INST_APPEND_STK: |
| 1692 |
valuePtr = stackPtr[stackTop]; |
| 1693 |
part2 = NULL; |
| 1694 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE); |
| 1695 |
goto doStoreStk; |
| 1696 |
|
| 1697 |
case INST_APPEND_ARRAY_STK: |
| 1698 |
valuePtr = stackPtr[stackTop]; |
| 1699 |
part2 = TclGetString(stackPtr[stackTop - 1]); |
| 1700 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE); |
| 1701 |
goto doStoreStk; |
| 1702 |
|
| 1703 |
case INST_STORE_ARRAY_STK: |
| 1704 |
valuePtr = stackPtr[stackTop]; |
| 1705 |
part2 = TclGetString(stackPtr[stackTop - 1]); |
| 1706 |
storeFlags = TCL_LEAVE_ERR_MSG; |
| 1707 |
goto doStoreStk; |
| 1708 |
|
| 1709 |
case INST_STORE_STK: |
| 1710 |
case INST_STORE_SCALAR_STK: |
| 1711 |
valuePtr = stackPtr[stackTop]; |
| 1712 |
part2 = NULL; |
| 1713 |
storeFlags = TCL_LEAVE_ERR_MSG; |
| 1714 |
|
| 1715 |
doStoreStk: |
| 1716 |
objPtr = stackPtr[stackTop - 1 - (part2 != NULL)]; |
| 1717 |
part1 = TclGetString(objPtr); |
| 1718 |
#ifdef TCL_COMPILE_DEBUG |
| 1719 |
if (part2 == NULL) { |
| 1720 |
TRACE(("\"%.30s\" <- \"%.30s\" =>", |
| 1721 |
part1, O2S(valuePtr))); |
| 1722 |
} else { |
| 1723 |
TRACE(("\"%.30s(%.30s)\" <- \"%.30s\" => ", |
| 1724 |
part1, part2, O2S(valuePtr))); |
| 1725 |
} |
| 1726 |
#endif |
| 1727 |
varPtr = TclObjLookupVar(interp, objPtr, part2, |
| 1728 |
TCL_LEAVE_ERR_MSG, "set", |
| 1729 |
1, |
| 1730 |
1, &arrayPtr); |
| 1731 |
if (varPtr == NULL) { |
| 1732 |
TRACE_APPEND(("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp)))); |
| 1733 |
result = TCL_ERROR; |
| 1734 |
goto checkForCatch; |
| 1735 |
} |
| 1736 |
cleanup = ((part2 == NULL)? 2 : 3); |
| 1737 |
pcAdjustment = 1; |
| 1738 |
goto doCallPtrSetVar; |
| 1739 |
|
| 1740 |
case INST_LAPPEND_ARRAY4: |
| 1741 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 1742 |
pcAdjustment = 5; |
| 1743 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE |
| 1744 |
| TCL_LIST_ELEMENT | TCL_TRACE_READS); |
| 1745 |
goto doStoreArray; |
| 1746 |
|
| 1747 |
case INST_LAPPEND_ARRAY1: |
| 1748 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1749 |
pcAdjustment = 2; |
| 1750 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE |
| 1751 |
| TCL_LIST_ELEMENT | TCL_TRACE_READS); |
| 1752 |
goto doStoreArray; |
| 1753 |
|
| 1754 |
case INST_APPEND_ARRAY4: |
| 1755 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 1756 |
pcAdjustment = 5; |
| 1757 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE); |
| 1758 |
goto doStoreArray; |
| 1759 |
|
| 1760 |
case INST_APPEND_ARRAY1: |
| 1761 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1762 |
pcAdjustment = 2; |
| 1763 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE); |
| 1764 |
goto doStoreArray; |
| 1765 |
|
| 1766 |
case INST_STORE_ARRAY4: |
| 1767 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 1768 |
pcAdjustment = 5; |
| 1769 |
storeFlags = TCL_LEAVE_ERR_MSG; |
| 1770 |
goto doStoreArray; |
| 1771 |
|
| 1772 |
case INST_STORE_ARRAY1: |
| 1773 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1774 |
pcAdjustment = 2; |
| 1775 |
storeFlags = TCL_LEAVE_ERR_MSG; |
| 1776 |
|
| 1777 |
doStoreArray: |
| 1778 |
valuePtr = stackPtr[stackTop]; |
| 1779 |
part2 = TclGetString(stackPtr[stackTop - 1]); |
| 1780 |
arrayPtr = &(varFramePtr->compiledLocals[opnd]); |
| 1781 |
part1 = arrayPtr->name; |
| 1782 |
TRACE(("%u \"%.30s\" <- \"%.30s\" => ", |
| 1783 |
opnd, part2, O2S(valuePtr))); |
| 1784 |
while (TclIsVarLink(arrayPtr)) { |
| 1785 |
arrayPtr = arrayPtr->value.linkPtr; |
| 1786 |
} |
| 1787 |
varPtr = TclLookupArrayElement(interp, part1, part2, |
| 1788 |
TCL_LEAVE_ERR_MSG, "set", 1, 1, arrayPtr); |
| 1789 |
if (varPtr == NULL) { |
| 1790 |
TRACE_APPEND(("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp)))); |
| 1791 |
result = TCL_ERROR; |
| 1792 |
goto checkForCatch; |
| 1793 |
} |
| 1794 |
cleanup = 2; |
| 1795 |
goto doCallPtrSetVar; |
| 1796 |
|
| 1797 |
case INST_LAPPEND_SCALAR4: |
| 1798 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 1799 |
pcAdjustment = 5; |
| 1800 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE |
| 1801 |
| TCL_LIST_ELEMENT | TCL_TRACE_READS); |
| 1802 |
goto doStoreScalar; |
| 1803 |
|
| 1804 |
case INST_LAPPEND_SCALAR1: |
| 1805 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1806 |
pcAdjustment = 2; |
| 1807 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE |
| 1808 |
| TCL_LIST_ELEMENT | TCL_TRACE_READS); |
| 1809 |
goto doStoreScalar; |
| 1810 |
|
| 1811 |
case INST_APPEND_SCALAR4: |
| 1812 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 1813 |
pcAdjustment = 5; |
| 1814 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE); |
| 1815 |
goto doStoreScalar; |
| 1816 |
|
| 1817 |
case INST_APPEND_SCALAR1: |
| 1818 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1819 |
pcAdjustment = 2; |
| 1820 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE); |
| 1821 |
goto doStoreScalar; |
| 1822 |
|
| 1823 |
case INST_STORE_SCALAR4: |
| 1824 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 1825 |
pcAdjustment = 5; |
| 1826 |
storeFlags = TCL_LEAVE_ERR_MSG; |
| 1827 |
goto doStoreScalar; |
| 1828 |
|
| 1829 |
case INST_STORE_SCALAR1: |
| 1830 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1831 |
pcAdjustment = 2; |
| 1832 |
storeFlags = TCL_LEAVE_ERR_MSG; |
| 1833 |
|
| 1834 |
doStoreScalar: |
| 1835 |
valuePtr = stackPtr[stackTop]; |
| 1836 |
varPtr = &(varFramePtr->compiledLocals[opnd]); |
| 1837 |
part1 = varPtr->name; |
| 1838 |
TRACE(("%u <- \"%.30s\" => ", opnd, O2S(valuePtr))); |
| 1839 |
while (TclIsVarLink(varPtr)) { |
| 1840 |
varPtr = varPtr->value.linkPtr; |
| 1841 |
} |
| 1842 |
cleanup = 1; |
| 1843 |
arrayPtr = NULL; |
| 1844 |
part2 = NULL; |
| 1845 |
|
| 1846 |
doCallPtrSetVar: |
| 1847 |
if ((storeFlags == TCL_LEAVE_ERR_MSG) |
| 1848 |
&& !((varPtr->flags & VAR_IN_HASHTABLE) |
| 1849 |
&& (varPtr->hPtr == NULL)) |
| 1850 |
&& (varPtr->tracePtr == NULL) |
| 1851 |
&& (TclIsVarScalar(varPtr) |
| 1852 |
|| TclIsVarUndefined(varPtr)) |
| 1853 |
&& ((arrayPtr == NULL) |
| 1854 |
|| (arrayPtr->tracePtr == NULL))) { |
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
valuePtr = varPtr->value.objPtr; |
| 1861 |
objResultPtr = stackPtr[stackTop]; |
| 1862 |
if (valuePtr != objResultPtr) { |
| 1863 |
if (valuePtr != NULL) { |
| 1864 |
TclDecrRefCount(valuePtr); |
| 1865 |
} else { |
| 1866 |
TclSetVarScalar(varPtr); |
| 1867 |
TclClearVarUndefined(varPtr); |
| 1868 |
} |
| 1869 |
varPtr->value.objPtr = objResultPtr; |
| 1870 |
Tcl_IncrRefCount(objResultPtr); |
| 1871 |
} |
| 1872 |
#ifndef TCL_COMPILE_DEBUG |
| 1873 |
if (*(pc+pcAdjustment) == INST_POP) { |
| 1874 |
NEXT_INST_V((pcAdjustment+1), cleanup, 0); |
| 1875 |
} |
| 1876 |
#else |
| 1877 |
TRACE_APPEND(("%.30s\n", O2S(objResultPtr))); |
| 1878 |
#endif |
| 1879 |
NEXT_INST_V(pcAdjustment, cleanup, 1); |
| 1880 |
} else { |
| 1881 |
DECACHE_STACK_INFO(); |
| 1882 |
objResultPtr = TclPtrSetVar(interp, varPtr, arrayPtr, |
| 1883 |
part1, part2, valuePtr, storeFlags); |
| 1884 |
CACHE_STACK_INFO(); |
| 1885 |
if (objResultPtr == NULL) { |
| 1886 |
TRACE_APPEND(("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp)))); |
| 1887 |
result = TCL_ERROR; |
| 1888 |
goto checkForCatch; |
| 1889 |
} |
| 1890 |
} |
| 1891 |
#ifndef TCL_COMPILE_DEBUG |
| 1892 |
if (*(pc+pcAdjustment) == INST_POP) { |
| 1893 |
NEXT_INST_V((pcAdjustment+1), cleanup, 0); |
| 1894 |
} |
| 1895 |
#endif |
| 1896 |
TRACE_APPEND(("%.30s\n", O2S(objResultPtr))); |
| 1897 |
NEXT_INST_V(pcAdjustment, cleanup, 1); |
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
case INST_INCR_SCALAR1: |
| 1915 |
case INST_INCR_ARRAY1: |
| 1916 |
case INST_INCR_ARRAY_STK: |
| 1917 |
case INST_INCR_SCALAR_STK: |
| 1918 |
case INST_INCR_STK: |
| 1919 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1920 |
valuePtr = stackPtr[stackTop]; |
| 1921 |
if (valuePtr->typePtr == &tclIntType) { |
| 1922 |
i = valuePtr->internalRep.longValue; |
| 1923 |
} else if (valuePtr->typePtr == &tclWideIntType) { |
| 1924 |
TclGetLongFromWide(i,valuePtr); |
| 1925 |
} else { |
| 1926 |
REQUIRE_WIDE_OR_INT(result, valuePtr, i, w); |
| 1927 |
if (result != TCL_OK) { |
| 1928 |
TRACE_WITH_OBJ(("%u (by %s) => ERROR converting increment amount to int: ", |
| 1929 |
opnd, O2S(valuePtr)), Tcl_GetObjResult(interp)); |
| 1930 |
DECACHE_STACK_INFO(); |
| 1931 |
Tcl_AddErrorInfo(interp, "\n (reading increment)"); |
| 1932 |
CACHE_STACK_INFO(); |
| 1933 |
goto checkForCatch; |
| 1934 |
} |
| 1935 |
FORCE_LONG(valuePtr, i, w); |
| 1936 |
} |
| 1937 |
stackTop--; |
| 1938 |
TclDecrRefCount(valuePtr); |
| 1939 |
switch (*pc) { |
| 1940 |
case INST_INCR_SCALAR1: |
| 1941 |
pcAdjustment = 2; |
| 1942 |
goto doIncrScalar; |
| 1943 |
case INST_INCR_ARRAY1: |
| 1944 |
pcAdjustment = 2; |
| 1945 |
goto doIncrArray; |
| 1946 |
default: |
| 1947 |
pcAdjustment = 1; |
| 1948 |
goto doIncrStk; |
| 1949 |
} |
| 1950 |
|
| 1951 |
case INST_INCR_ARRAY_STK_IMM: |
| 1952 |
case INST_INCR_SCALAR_STK_IMM: |
| 1953 |
case INST_INCR_STK_IMM: |
| 1954 |
i = TclGetInt1AtPtr(pc+1); |
| 1955 |
pcAdjustment = 2; |
| 1956 |
|
| 1957 |
doIncrStk: |
| 1958 |
if ((*pc == INST_INCR_ARRAY_STK_IMM) |
| 1959 |
|| (*pc == INST_INCR_ARRAY_STK)) { |
| 1960 |
part2 = TclGetString(stackPtr[stackTop]); |
| 1961 |
objPtr = stackPtr[stackTop - 1]; |
| 1962 |
TRACE(("\"%.30s(%.30s)\" (by %ld) => ", |
| 1963 |
O2S(objPtr), part2, i)); |
| 1964 |
} else { |
| 1965 |
part2 = NULL; |
| 1966 |
objPtr = stackPtr[stackTop]; |
| 1967 |
TRACE(("\"%.30s\" (by %ld) => ", O2S(objPtr), i)); |
| 1968 |
} |
| 1969 |
part1 = TclGetString(objPtr); |
| 1970 |
|
| 1971 |
varPtr = TclObjLookupVar(interp, objPtr, part2, |
| 1972 |
TCL_LEAVE_ERR_MSG, "read", 0, 1, &arrayPtr); |
| 1973 |
if (varPtr == NULL) { |
| 1974 |
DECACHE_STACK_INFO(); |
| 1975 |
Tcl_AddObjErrorInfo(interp, |
| 1976 |
"\n (reading value of variable to increment)", -1); |
| 1977 |
CACHE_STACK_INFO(); |
| 1978 |
TRACE_APPEND(("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp)))); |
| 1979 |
result = TCL_ERROR; |
| 1980 |
goto checkForCatch; |
| 1981 |
} |
| 1982 |
cleanup = ((part2 == NULL)? 1 : 2); |
| 1983 |
goto doIncrVar; |
| 1984 |
|
| 1985 |
case INST_INCR_ARRAY1_IMM: |
| 1986 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 1987 |
i = TclGetInt1AtPtr(pc+2); |
| 1988 |
pcAdjustment = 3; |
| 1989 |
|
| 1990 |
doIncrArray: |
| 1991 |
part2 = TclGetString(stackPtr[stackTop]); |
| 1992 |
arrayPtr = &(varFramePtr->compiledLocals[opnd]); |
| 1993 |
part1 = arrayPtr->name; |
| 1994 |
while (TclIsVarLink(arrayPtr)) { |
| 1995 |
arrayPtr = arrayPtr->value.linkPtr; |
| 1996 |
} |
| 1997 |
TRACE(("%u \"%.30s\" (by %ld) => ", |
| 1998 |
opnd, part2, i)); |
| 1999 |
varPtr = TclLookupArrayElement(interp, part1, part2, |
| 2000 |
TCL_LEAVE_ERR_MSG, "read", 0, 1, arrayPtr); |
| 2001 |
if (varPtr == NULL) { |
| 2002 |
TRACE_APPEND(("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp)))); |
| 2003 |
result = TCL_ERROR; |
| 2004 |
goto checkForCatch; |
| 2005 |
} |
| 2006 |
cleanup = 1; |
| 2007 |
goto doIncrVar; |
| 2008 |
|
| 2009 |
case INST_INCR_SCALAR1_IMM: |
| 2010 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 2011 |
i = TclGetInt1AtPtr(pc+2); |
| 2012 |
pcAdjustment = 3; |
| 2013 |
|
| 2014 |
doIncrScalar: |
| 2015 |
varPtr = &(varFramePtr->compiledLocals[opnd]); |
| 2016 |
part1 = varPtr->name; |
| 2017 |
while (TclIsVarLink(varPtr)) { |
| 2018 |
varPtr = varPtr->value.linkPtr; |
| 2019 |
} |
| 2020 |
arrayPtr = NULL; |
| 2021 |
part2 = NULL; |
| 2022 |
cleanup = 0; |
| 2023 |
TRACE(("%u %ld => ", opnd, i)); |
| 2024 |
|
| 2025 |
|
| 2026 |
doIncrVar: |
| 2027 |
objPtr = varPtr->value.objPtr; |
| 2028 |
if (TclIsVarScalar(varPtr) |
| 2029 |
&& !TclIsVarUndefined(varPtr) |
| 2030 |
&& (varPtr->tracePtr == NULL) |
| 2031 |
&& ((arrayPtr == NULL) |
| 2032 |
|| (arrayPtr->tracePtr == NULL)) |
| 2033 |
&& (objPtr->typePtr == &tclIntType)) { |
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
i += objPtr->internalRep.longValue; |
| 2040 |
if (Tcl_IsShared(objPtr)) { |
| 2041 |
objResultPtr = Tcl_NewLongObj(i); |
| 2042 |
TclDecrRefCount(objPtr); |
| 2043 |
Tcl_IncrRefCount(objResultPtr); |
| 2044 |
varPtr->value.objPtr = objResultPtr; |
| 2045 |
} else { |
| 2046 |
Tcl_SetLongObj(objPtr, i); |
| 2047 |
objResultPtr = objPtr; |
| 2048 |
} |
| 2049 |
TRACE_APPEND(("%.30s\n", O2S(objResultPtr))); |
| 2050 |
} else { |
| 2051 |
DECACHE_STACK_INFO(); |
| 2052 |
objResultPtr = TclPtrIncrVar(interp, varPtr, arrayPtr, part1, |
| 2053 |
part2, i, TCL_LEAVE_ERR_MSG); |
| 2054 |
CACHE_STACK_INFO(); |
| 2055 |
if (objResultPtr == NULL) { |
| 2056 |
TRACE_APPEND(("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp)))); |
| 2057 |
result = TCL_ERROR; |
| 2058 |
goto checkForCatch; |
| 2059 |
} |
| 2060 |
} |
| 2061 |
TRACE_APPEND(("%.30s\n", O2S(objResultPtr))); |
| 2062 |
#ifndef TCL_COMPILE_DEBUG |
| 2063 |
if (*(pc+pcAdjustment) == INST_POP) { |
| 2064 |
NEXT_INST_V((pcAdjustment+1), cleanup, 0); |
| 2065 |
} |
| 2066 |
#endif |
| 2067 |
NEXT_INST_V(pcAdjustment, cleanup, 1); |
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
case INST_JUMP1: |
| 2076 |
opnd = TclGetInt1AtPtr(pc+1); |
| 2077 |
TRACE(("%d => new pc %u\n", opnd, |
| 2078 |
(unsigned int)(pc + opnd - codePtr->codeStart))); |
| 2079 |
NEXT_INST_F(opnd, 0, 0); |
| 2080 |
|
| 2081 |
case INST_JUMP4: |
| 2082 |
opnd = TclGetInt4AtPtr(pc+1); |
| 2083 |
TRACE(("%d => new pc %u\n", opnd, |
| 2084 |
(unsigned int)(pc + opnd - codePtr->codeStart))); |
| 2085 |
NEXT_INST_F(opnd, 0, 0); |
| 2086 |
|
| 2087 |
case INST_JUMP_FALSE4: |
| 2088 |
opnd = 5; |
| 2089 |
pcAdjustment = TclGetInt4AtPtr(pc+1); |
| 2090 |
goto doJumpTrue; |
| 2091 |
|
| 2092 |
case INST_JUMP_TRUE4: |
| 2093 |
opnd = TclGetInt4AtPtr(pc+1); |
| 2094 |
pcAdjustment = 5; |
| 2095 |
goto doJumpTrue; |
| 2096 |
|
| 2097 |
case INST_JUMP_FALSE1: |
| 2098 |
opnd = 2; |
| 2099 |
pcAdjustment = TclGetInt1AtPtr(pc+1); |
| 2100 |
goto doJumpTrue; |
| 2101 |
|
| 2102 |
case INST_JUMP_TRUE1: |
| 2103 |
opnd = TclGetInt1AtPtr(pc+1); |
| 2104 |
pcAdjustment = 2; |
| 2105 |
|
| 2106 |
doJumpTrue: |
| 2107 |
{ |
| 2108 |
int b; |
| 2109 |
|
| 2110 |
valuePtr = stackPtr[stackTop]; |
| 2111 |
if (valuePtr->typePtr == &tclIntType) { |
| 2112 |
b = (valuePtr->internalRep.longValue != 0); |
| 2113 |
} else if (valuePtr->typePtr == &tclDoubleType) { |
| 2114 |
b = (valuePtr->internalRep.doubleValue != 0.0); |
| 2115 |
} else if (valuePtr->typePtr == &tclWideIntType) { |
| 2116 |
TclGetWide(w,valuePtr); |
| 2117 |
b = (w != W0); |
| 2118 |
} else { |
| 2119 |
result = Tcl_GetBooleanFromObj(interp, valuePtr, &b); |
| 2120 |
if (result != TCL_OK) { |
| 2121 |
TRACE_WITH_OBJ(("%d => ERROR: ", opnd), Tcl_GetObjResult(interp)); |
| 2122 |
goto checkForCatch; |
| 2123 |
} |
| 2124 |
} |
| 2125 |
#ifndef TCL_COMPILE_DEBUG |
| 2126 |
NEXT_INST_F((b? opnd : pcAdjustment), 1, 0); |
| 2127 |
#else |
| 2128 |
if (b) { |
| 2129 |
if ((*pc == INST_JUMP_TRUE1) || (*pc == INST_JUMP_TRUE1)) { |
| 2130 |
TRACE(("%d => %.20s true, new pc %u\n", opnd, O2S(valuePtr), |
| 2131 |
(unsigned int)(pc+opnd - codePtr->codeStart))); |
| 2132 |
} else { |
| 2133 |
TRACE(("%d => %.20s true\n", pcAdjustment, O2S(valuePtr))); |
| 2134 |
} |
| 2135 |
NEXT_INST_F(opnd, 1, 0); |
| 2136 |
} else { |
| 2137 |
if ((*pc == INST_JUMP_TRUE1) || (*pc == INST_JUMP_TRUE1)) { |
| 2138 |
TRACE(("%d => %.20s false\n", opnd, O2S(valuePtr))); |
| 2139 |
} else { |
| 2140 |
opnd = pcAdjustment; |
| 2141 |
TRACE(("%d => %.20s false, new pc %u\n", opnd, O2S(valuePtr), |
| 2142 |
(unsigned int)(pc + opnd - codePtr->codeStart))); |
| 2143 |
} |
| 2144 |
NEXT_INST_F(pcAdjustment, 1, 0); |
| 2145 |
} |
| 2146 |
#endif |
| 2147 |
} |
| 2148 |
|
| 2149 |
case INST_LOR: |
| 2150 |
case INST_LAND: |
| 2151 |
{ |
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
int i1, i2; |
| 2158 |
int iResult; |
| 2159 |
char *s; |
| 2160 |
Tcl_ObjType *t1Ptr, *t2Ptr; |
| 2161 |
|
| 2162 |
value2Ptr = stackPtr[stackTop]; |
| 2163 |
valuePtr = stackPtr[stackTop - 1];; |
| 2164 |
t1Ptr = valuePtr->typePtr; |
| 2165 |
t2Ptr = value2Ptr->typePtr; |
| 2166 |
|
| 2167 |
if ((t1Ptr == &tclIntType) || (t1Ptr == &tclBooleanType)) { |
| 2168 |
i1 = (valuePtr->internalRep.longValue != 0); |
| 2169 |
} else if (t1Ptr == &tclWideIntType) { |
| 2170 |
TclGetWide(w,valuePtr); |
| 2171 |
i1 = (w != W0); |
| 2172 |
} else if (t1Ptr == &tclDoubleType) { |
| 2173 |
i1 = (valuePtr->internalRep.doubleValue != 0.0); |
| 2174 |
} else { |
| 2175 |
s = Tcl_GetStringFromObj(valuePtr, &length); |
| 2176 |
if (TclLooksLikeInt(s, length)) { |
| 2177 |
GET_WIDE_OR_INT(result, valuePtr, i, w); |
| 2178 |
if (valuePtr->typePtr == &tclIntType) { |
| 2179 |
i1 = (i != 0); |
| 2180 |
} else { |
| 2181 |
i1 = (w != W0); |
| 2182 |
} |
| 2183 |
} else { |
| 2184 |
result = Tcl_GetBooleanFromObj((Tcl_Interp *) NULL, |
| 2185 |
valuePtr, &i1); |
| 2186 |
i1 = (i1 != 0); |
| 2187 |
} |
| 2188 |
if (result != TCL_OK) { |
| 2189 |
TRACE(("\"%.20s\" => ILLEGAL TYPE %s \n", O2S(valuePtr), |
| 2190 |
(t1Ptr? t1Ptr->name : "null"))); |
| 2191 |
DECACHE_STACK_INFO(); |
| 2192 |
IllegalExprOperandType(interp, pc, valuePtr); |
| 2193 |
CACHE_STACK_INFO(); |
| 2194 |
goto checkForCatch; |
| 2195 |
} |
| 2196 |
} |
| 2197 |
|
| 2198 |
if ((t2Ptr == &tclIntType) || (t2Ptr == &tclBooleanType)) { |
| 2199 |
i2 = (value2Ptr->internalRep.longValue != 0); |
| 2200 |
} else if (t2Ptr == &tclWideIntType) { |
| 2201 |
TclGetWide(w,value2Ptr); |
| 2202 |
i2 = (w != W0); |
| 2203 |
} else if (t2Ptr == &tclDoubleType) { |
| 2204 |
i2 = (value2Ptr->internalRep.doubleValue != 0.0); |
| 2205 |
} else { |
| 2206 |
s = Tcl_GetStringFromObj(value2Ptr, &length); |
| 2207 |
if (TclLooksLikeInt(s, length)) { |
| 2208 |
GET_WIDE_OR_INT(result, value2Ptr, i, w); |
| 2209 |
if (value2Ptr->typePtr == &tclIntType) { |
| 2210 |
i2 = (i != 0); |
| 2211 |
} else { |
| 2212 |
i2 = (w != W0); |
| 2213 |
} |
| 2214 |
} else { |
| 2215 |
result = Tcl_GetBooleanFromObj((Tcl_Interp *) NULL, value2Ptr, &i2); |
| 2216 |
} |
| 2217 |
if (result != TCL_OK) { |
| 2218 |
TRACE(("\"%.20s\" => ILLEGAL TYPE %s \n", O2S(value2Ptr), |
| 2219 |
(t2Ptr? t2Ptr->name : "null"))); |
| 2220 |
DECACHE_STACK_INFO(); |
| 2221 |
IllegalExprOperandType(interp, pc, value2Ptr); |
| 2222 |
CACHE_STACK_INFO(); |
| 2223 |
goto checkForCatch; |
| 2224 |
} |
| 2225 |
} |
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
|
| 2231 |
if (*pc == INST_LOR) { |
| 2232 |
iResult = (i1 || i2); |
| 2233 |
} else { |
| 2234 |
iResult = (i1 && i2); |
| 2235 |
} |
| 2236 |
if (Tcl_IsShared(valuePtr)) { |
| 2237 |
objResultPtr = Tcl_NewLongObj(iResult); |
| 2238 |
TRACE(("%.20s %.20s => %d\n", O2S(valuePtr), O2S(value2Ptr), iResult)); |
| 2239 |
NEXT_INST_F(1, 2, 1); |
| 2240 |
} else { |
| 2241 |
TRACE(("%.20s %.20s => %d\n", O2S(valuePtr), O2S(value2Ptr), iResult)); |
| 2242 |
Tcl_SetLongObj(valuePtr, iResult); |
| 2243 |
NEXT_INST_F(1, 1, 0); |
| 2244 |
} |
| 2245 |
} |
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
case INST_LIST: |
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 2259 |
objResultPtr = Tcl_NewListObj(opnd, &(stackPtr[stackTop - (opnd-1)])); |
| 2260 |
TRACE_WITH_OBJ(("%u => ", opnd), objResultPtr); |
| 2261 |
NEXT_INST_V(5, opnd, 1); |
| 2262 |
|
| 2263 |
case INST_LIST_LENGTH: |
| 2264 |
valuePtr = stackPtr[stackTop]; |
| 2265 |
|
| 2266 |
result = Tcl_ListObjLength(interp, valuePtr, &length); |
| 2267 |
if (result != TCL_OK) { |
| 2268 |
TRACE_WITH_OBJ(("%.30s => ERROR: ", O2S(valuePtr)), |
| 2269 |
Tcl_GetObjResult(interp)); |
| 2270 |
goto checkForCatch; |
| 2271 |
} |
| 2272 |
objResultPtr = Tcl_NewIntObj(length); |
| 2273 |
TRACE(("%.20s => %d\n", O2S(valuePtr), length)); |
| 2274 |
NEXT_INST_F(1, 1, 1); |
| 2275 |
|
| 2276 |
case INST_LIST_INDEX: |
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
value2Ptr = stackPtr[stackTop]; |
| 2283 |
valuePtr = stackPtr[stackTop- 1]; |
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
objResultPtr = TclLindexList(interp, valuePtr, value2Ptr); |
| 2289 |
if (objResultPtr == NULL) { |
| 2290 |
TRACE_WITH_OBJ(("%.30s %.30s => ERROR: ", O2S(valuePtr), O2S(value2Ptr)), |
| 2291 |
Tcl_GetObjResult(interp)); |
| 2292 |
result = TCL_ERROR; |
| 2293 |
goto checkForCatch; |
| 2294 |
} |
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
TRACE(("%.20s %.20s => %s\n", |
| 2300 |
O2S(valuePtr), O2S(value2Ptr), O2S(objResultPtr))); |
| 2301 |
NEXT_INST_F(1, 2, -1); |
| 2302 |
|
| 2303 |
case INST_LIST_INDEX_MULTI: |
| 2304 |
{ |
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
int numIdx; |
| 2312 |
|
| 2313 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 2314 |
numIdx = opnd-1; |
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
objResultPtr = TclLindexFlat(interp, stackPtr[stackTop - numIdx], |
| 2320 |
numIdx, stackPtr + stackTop - numIdx + 1); |
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
if (objResultPtr == NULL) { |
| 2326 |
TRACE_WITH_OBJ(("%d => ERROR: ", opnd), Tcl_GetObjResult(interp)); |
| 2327 |
result = TCL_ERROR; |
| 2328 |
goto checkForCatch; |
| 2329 |
} |
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
TRACE(("%d => %s\n", opnd, O2S(objResultPtr))); |
| 2335 |
NEXT_INST_V(5, opnd, -1); |
| 2336 |
} |
| 2337 |
|
| 2338 |
case INST_LSET_FLAT: |
| 2339 |
{ |
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
int numIdx; |
| 2345 |
|
| 2346 |
opnd = TclGetUInt4AtPtr( pc + 1 ); |
| 2347 |
numIdx = opnd - 2; |
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
value2Ptr = POP_OBJECT(); |
| 2355 |
TclDecrRefCount(value2Ptr); |
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
valuePtr = stackPtr[stackTop]; |
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
objResultPtr = TclLsetFlat(interp, value2Ptr, numIdx, |
| 2366 |
stackPtr + stackTop - numIdx, valuePtr); |
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
if (objResultPtr == NULL) { |
| 2373 |
TRACE_WITH_OBJ(("%d => ERROR: ", opnd), Tcl_GetObjResult(interp)); |
| 2374 |
result = TCL_ERROR; |
| 2375 |
goto checkForCatch; |
| 2376 |
} |
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
TRACE(("%d => %s\n", opnd, O2S(objResultPtr))); |
| 2382 |
NEXT_INST_V(5, (numIdx+1), -1); |
| 2383 |
} |
| 2384 |
|
| 2385 |
case INST_LSET_LIST: |
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
objPtr = POP_OBJECT(); |
| 2394 |
TclDecrRefCount(objPtr); |
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
valuePtr = stackPtr[stackTop]; |
| 2400 |
value2Ptr = stackPtr[stackTop - 1]; |
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
objResultPtr = TclLsetList(interp, objPtr, value2Ptr, valuePtr); |
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
if (objResultPtr == NULL) { |
| 2411 |
TRACE_WITH_OBJ(("\"%.30s\" => ERROR: ", O2S(value2Ptr)), |
| 2412 |
Tcl_GetObjResult(interp)); |
| 2413 |
result = TCL_ERROR; |
| 2414 |
goto checkForCatch; |
| 2415 |
} |
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
TRACE(("=> %s\n", O2S(objResultPtr))); |
| 2421 |
NEXT_INST_F(1, 2, -1); |
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
case INST_STR_EQ: |
| 2429 |
case INST_STR_NEQ: |
| 2430 |
{ |
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
int iResult; |
| 2435 |
|
| 2436 |
value2Ptr = stackPtr[stackTop]; |
| 2437 |
valuePtr = stackPtr[stackTop - 1]; |
| 2438 |
|
| 2439 |
if (valuePtr == value2Ptr) { |
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
iResult = (*pc == INST_STR_EQ); |
| 2445 |
} else { |
| 2446 |
char *s1, *s2; |
| 2447 |
int s1len, s2len; |
| 2448 |
|
| 2449 |
s1 = Tcl_GetStringFromObj(valuePtr, &s1len); |
| 2450 |
s2 = Tcl_GetStringFromObj(value2Ptr, &s2len); |
| 2451 |
if (s1len == s2len) { |
| 2452 |
|
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
if (*pc == INST_STR_NEQ) { |
| 2457 |
iResult = (strcmp(s1, s2) != 0); |
| 2458 |
} else { |
| 2459 |
|
| 2460 |
iResult = (strcmp(s1, s2) == 0); |
| 2461 |
} |
| 2462 |
} else { |
| 2463 |
iResult = (*pc == INST_STR_NEQ); |
| 2464 |
} |
| 2465 |
} |
| 2466 |
|
| 2467 |
TRACE(("%.20s %.20s => %d\n", O2S(valuePtr), O2S(value2Ptr), iResult)); |
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
pc++; |
| 2475 |
#ifndef TCL_COMPILE_DEBUG |
| 2476 |
switch (*pc) { |
| 2477 |
case INST_JUMP_FALSE1: |
| 2478 |
NEXT_INST_F((iResult? 2 : TclGetInt1AtPtr(pc+1)), 2, 0); |
| 2479 |
case INST_JUMP_TRUE1: |
| 2480 |
NEXT_INST_F((iResult? TclGetInt1AtPtr(pc+1) : 2), 2, 0); |
| 2481 |
case INST_JUMP_FALSE4: |
| 2482 |
NEXT_INST_F((iResult? 5 : TclGetInt4AtPtr(pc+1)), 2, 0); |
| 2483 |
case INST_JUMP_TRUE4: |
| 2484 |
NEXT_INST_F((iResult? TclGetInt4AtPtr(pc+1) : 5), 2, 0); |
| 2485 |
} |
| 2486 |
#endif |
| 2487 |
objResultPtr = Tcl_NewIntObj(iResult); |
| 2488 |
NEXT_INST_F(0, 2, 1); |
| 2489 |
} |
| 2490 |
|
| 2491 |
case INST_STR_CMP: |
| 2492 |
{ |
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
CONST char *s1, *s2; |
| 2497 |
int s1len, s2len, iResult; |
| 2498 |
|
| 2499 |
value2Ptr = stackPtr[stackTop]; |
| 2500 |
valuePtr = stackPtr[stackTop - 1]; |
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
if (valuePtr == value2Ptr) { |
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
iResult = s1len = s2len = 0; |
| 2512 |
} else if ((valuePtr->typePtr == &tclByteArrayType) |
| 2513 |
&& (value2Ptr->typePtr == &tclByteArrayType)) { |
| 2514 |
s1 = (char *) Tcl_GetByteArrayFromObj(valuePtr, &s1len); |
| 2515 |
s2 = (char *) Tcl_GetByteArrayFromObj(value2Ptr, &s2len); |
| 2516 |
iResult = memcmp(s1, s2, |
| 2517 |
(size_t) ((s1len < s2len) ? s1len : s2len)); |
| 2518 |
} else if (((valuePtr->typePtr == &tclStringType) |
| 2519 |
&& (value2Ptr->typePtr == &tclStringType))) { |
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
s1len = Tcl_GetCharLength(valuePtr); |
| 2528 |
s2len = Tcl_GetCharLength(value2Ptr); |
| 2529 |
if ((s1len == valuePtr->length) && (s2len == value2Ptr->length)) { |
| 2530 |
iResult = memcmp(valuePtr->bytes, value2Ptr->bytes, |
| 2531 |
(unsigned) ((s1len < s2len) ? s1len : s2len)); |
| 2532 |
} else { |
| 2533 |
iResult = TclUniCharNcmp(Tcl_GetUnicode(valuePtr), |
| 2534 |
Tcl_GetUnicode(value2Ptr), |
| 2535 |
(unsigned) ((s1len < s2len) ? s1len : s2len)); |
| 2536 |
} |
| 2537 |
} else { |
| 2538 |
|
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
s1 = Tcl_GetStringFromObj(valuePtr, &s1len); |
| 2543 |
s2 = Tcl_GetStringFromObj(value2Ptr, &s2len); |
| 2544 |
iResult = TclpUtfNcmp2(s1, s2, |
| 2545 |
(size_t) ((s1len < s2len) ? s1len : s2len)); |
| 2546 |
} |
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
if (iResult == 0) { |
| 2552 |
iResult = s1len - s2len; |
| 2553 |
} |
| 2554 |
if (iResult < 0) { |
| 2555 |
iResult = -1; |
| 2556 |
} else if (iResult > 0) { |
| 2557 |
iResult = 1; |
| 2558 |
} |
| 2559 |
|
| 2560 |
objResultPtr = Tcl_NewIntObj(iResult); |
| 2561 |
TRACE(("%.20s %.20s => %d\n", O2S(valuePtr), O2S(value2Ptr), iResult)); |
| 2562 |
NEXT_INST_F(1, 2, 1); |
| 2563 |
} |
| 2564 |
|
| 2565 |
case INST_STR_LEN: |
| 2566 |
{ |
| 2567 |
int length1; |
| 2568 |
|
| 2569 |
valuePtr = stackPtr[stackTop]; |
| 2570 |
|
| 2571 |
if (valuePtr->typePtr == &tclByteArrayType) { |
| 2572 |
(void) Tcl_GetByteArrayFromObj(valuePtr, &length1); |
| 2573 |
} else { |
| 2574 |
length1 = Tcl_GetCharLength(valuePtr); |
| 2575 |
} |
| 2576 |
objResultPtr = Tcl_NewIntObj(length1); |
| 2577 |
TRACE(("%.20s => %d\n", O2S(valuePtr), length1)); |
| 2578 |
NEXT_INST_F(1, 1, 1); |
| 2579 |
} |
| 2580 |
|
| 2581 |
case INST_STR_INDEX: |
| 2582 |
{ |
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
int index; |
| 2587 |
bytes = NULL; |
| 2588 |
|
| 2589 |
value2Ptr = stackPtr[stackTop]; |
| 2590 |
valuePtr = stackPtr[stackTop - 1]; |
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
if (valuePtr->typePtr == &tclByteArrayType) { |
| 2600 |
bytes = (char *)Tcl_GetByteArrayFromObj(valuePtr, &length); |
| 2601 |
} else { |
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
length = Tcl_GetCharLength(valuePtr); |
| 2606 |
} |
| 2607 |
|
| 2608 |
result = TclGetIntForIndex(interp, value2Ptr, length - 1, &index); |
| 2609 |
if (result != TCL_OK) { |
| 2610 |
goto checkForCatch; |
| 2611 |
} |
| 2612 |
|
| 2613 |
if ((index >= 0) && (index < length)) { |
| 2614 |
if (valuePtr->typePtr == &tclByteArrayType) { |
| 2615 |
objResultPtr = Tcl_NewByteArrayObj((unsigned char *) |
| 2616 |
(&bytes[index]), 1); |
| 2617 |
} else if (valuePtr->bytes && length == valuePtr->length) { |
| 2618 |
objResultPtr = Tcl_NewStringObj((CONST char *) |
| 2619 |
(&valuePtr->bytes[index]), 1); |
| 2620 |
} else { |
| 2621 |
char buf[TCL_UTF_MAX]; |
| 2622 |
Tcl_UniChar ch; |
| 2623 |
|
| 2624 |
ch = Tcl_GetUniChar(valuePtr, index); |
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
length = Tcl_UniCharToUtf(ch, buf); |
| 2632 |
objResultPtr = Tcl_NewStringObj(buf, length); |
| 2633 |
} |
| 2634 |
} else { |
| 2635 |
TclNewObj(objResultPtr); |
| 2636 |
} |
| 2637 |
|
| 2638 |
TRACE(("%.20s %.20s => %s\n", O2S(valuePtr), O2S(value2Ptr), |
| 2639 |
O2S(objResultPtr))); |
| 2640 |
NEXT_INST_F(1, 2, 1); |
| 2641 |
} |
| 2642 |
|
| 2643 |
case INST_STR_MATCH: |
| 2644 |
{ |
| 2645 |
int nocase, match; |
| 2646 |
|
| 2647 |
nocase = TclGetInt1AtPtr(pc+1); |
| 2648 |
valuePtr = stackPtr[stackTop]; |
| 2649 |
value2Ptr = stackPtr[stackTop - 1]; |
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
if ((valuePtr->typePtr == &tclStringType) |
| 2657 |
|| (value2Ptr->typePtr == &tclStringType)) { |
| 2658 |
Tcl_UniChar *ustring1, *ustring2; |
| 2659 |
int length1, length2; |
| 2660 |
|
| 2661 |
ustring1 = Tcl_GetUnicodeFromObj(valuePtr, &length1); |
| 2662 |
ustring2 = Tcl_GetUnicodeFromObj(value2Ptr, &length2); |
| 2663 |
match = TclUniCharMatch(ustring1, length1, ustring2, length2, |
| 2664 |
nocase); |
| 2665 |
} else { |
| 2666 |
match = Tcl_StringCaseMatch(TclGetString(valuePtr), |
| 2667 |
TclGetString(value2Ptr), nocase); |
| 2668 |
} |
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
TRACE(("%.20s %.20s => %d\n", O2S(valuePtr), O2S(value2Ptr), match)); |
| 2676 |
if (Tcl_IsShared(value2Ptr)) { |
| 2677 |
objResultPtr = Tcl_NewIntObj(match); |
| 2678 |
NEXT_INST_F(2, 2, 1); |
| 2679 |
} else { |
| 2680 |
Tcl_SetIntObj(value2Ptr, match); |
| 2681 |
NEXT_INST_F(2, 1, 0); |
| 2682 |
} |
| 2683 |
} |
| 2684 |
|
| 2685 |
case INST_EQ: |
| 2686 |
case INST_NEQ: |
| 2687 |
case INST_LT: |
| 2688 |
case INST_GT: |
| 2689 |
case INST_LE: |
| 2690 |
case INST_GE: |
| 2691 |
{ |
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
Tcl_ObjType *t1Ptr, *t2Ptr; |
| 2698 |
char *s1 = NULL; |
| 2699 |
char *s2 = NULL; |
| 2700 |
long i2 = 0; |
| 2701 |
double d1 = 0.0; |
| 2702 |
double d2 = 0.0; |
| 2703 |
long iResult = 0; |
| 2704 |
|
| 2705 |
value2Ptr = stackPtr[stackTop]; |
| 2706 |
valuePtr = stackPtr[stackTop - 1]; |
| 2707 |
|
| 2708 |
if (valuePtr == value2Ptr) { |
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
switch (*pc) { |
| 2713 |
case INST_EQ: |
| 2714 |
case INST_LE: |
| 2715 |
case INST_GE: |
| 2716 |
iResult = 1; |
| 2717 |
break; |
| 2718 |
case INST_NEQ: |
| 2719 |
case INST_LT: |
| 2720 |
case INST_GT: |
| 2721 |
iResult = 0; |
| 2722 |
break; |
| 2723 |
} |
| 2724 |
goto foundResult; |
| 2725 |
} |
| 2726 |
|
| 2727 |
t1Ptr = valuePtr->typePtr; |
| 2728 |
t2Ptr = value2Ptr->typePtr; |
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
if (!( (!t1Ptr && !valuePtr->bytes) |
| 2736 |
|| (valuePtr->bytes && !valuePtr->length) |
| 2737 |
|| (!t2Ptr && !value2Ptr->bytes) |
| 2738 |
|| (value2Ptr->bytes && !value2Ptr->length))) { |
| 2739 |
if (!IS_NUMERIC_TYPE(t1Ptr)) { |
| 2740 |
s1 = Tcl_GetStringFromObj(valuePtr, &length); |
| 2741 |
if (TclLooksLikeInt(s1, length)) { |
| 2742 |
GET_WIDE_OR_INT(iResult, valuePtr, i, w); |
| 2743 |
} else { |
| 2744 |
(void) Tcl_GetDoubleFromObj((Tcl_Interp *) NULL, |
| 2745 |
valuePtr, &d1); |
| 2746 |
} |
| 2747 |
t1Ptr = valuePtr->typePtr; |
| 2748 |
} |
| 2749 |
if (!IS_NUMERIC_TYPE(t2Ptr)) { |
| 2750 |
s2 = Tcl_GetStringFromObj(value2Ptr, &length); |
| 2751 |
if (TclLooksLikeInt(s2, length)) { |
| 2752 |
GET_WIDE_OR_INT(iResult, value2Ptr, i2, w); |
| 2753 |
} else { |
| 2754 |
(void) Tcl_GetDoubleFromObj((Tcl_Interp *) NULL, |
| 2755 |
value2Ptr, &d2); |
| 2756 |
} |
| 2757 |
t2Ptr = value2Ptr->typePtr; |
| 2758 |
} |
| 2759 |
} |
| 2760 |
if (!IS_NUMERIC_TYPE(t1Ptr) || !IS_NUMERIC_TYPE(t2Ptr)) { |
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
int s1len, s2len; |
| 2768 |
s1 = Tcl_GetStringFromObj(valuePtr, &s1len); |
| 2769 |
s2 = Tcl_GetStringFromObj(value2Ptr, &s2len); |
| 2770 |
switch (*pc) { |
| 2771 |
case INST_EQ: |
| 2772 |
if (s1len == s2len) { |
| 2773 |
iResult = (strcmp(s1, s2) == 0); |
| 2774 |
} else { |
| 2775 |
iResult = 0; |
| 2776 |
} |
| 2777 |
break; |
| 2778 |
case INST_NEQ: |
| 2779 |
if (s1len == s2len) { |
| 2780 |
iResult = (strcmp(s1, s2) != 0); |
| 2781 |
} else { |
| 2782 |
iResult = 1; |
| 2783 |
} |
| 2784 |
break; |
| 2785 |
case INST_LT: |
| 2786 |
iResult = (strcmp(s1, s2) < 0); |
| 2787 |
break; |
| 2788 |
case INST_GT: |
| 2789 |
iResult = (strcmp(s1, s2) > 0); |
| 2790 |
break; |
| 2791 |
case INST_LE: |
| 2792 |
iResult = (strcmp(s1, s2) <= 0); |
| 2793 |
break; |
| 2794 |
case INST_GE: |
| 2795 |
iResult = (strcmp(s1, s2) >= 0); |
| 2796 |
break; |
| 2797 |
} |
| 2798 |
} else if ((t1Ptr == &tclDoubleType) |
| 2799 |
|| (t2Ptr == &tclDoubleType)) { |
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
if (t1Ptr == &tclDoubleType) { |
| 2804 |
d1 = valuePtr->internalRep.doubleValue; |
| 2805 |
GET_DOUBLE_VALUE(d2, value2Ptr, t2Ptr); |
| 2806 |
} else { |
| 2807 |
GET_DOUBLE_VALUE(d1, valuePtr, t1Ptr); |
| 2808 |
d2 = value2Ptr->internalRep.doubleValue; |
| 2809 |
} |
| 2810 |
switch (*pc) { |
| 2811 |
case INST_EQ: |
| 2812 |
iResult = d1 == d2; |
| 2813 |
break; |
| 2814 |
case INST_NEQ: |
| 2815 |
iResult = d1 != d2; |
| 2816 |
break; |
| 2817 |
case INST_LT: |
| 2818 |
iResult = d1 < d2; |
| 2819 |
break; |
| 2820 |
case INST_GT: |
| 2821 |
iResult = d1 > d2; |
| 2822 |
break; |
| 2823 |
case INST_LE: |
| 2824 |
iResult = d1 <= d2; |
| 2825 |
break; |
| 2826 |
case INST_GE: |
| 2827 |
iResult = d1 >= d2; |
| 2828 |
break; |
| 2829 |
} |
| 2830 |
} else if ((t1Ptr == &tclWideIntType) |
| 2831 |
|| (t2Ptr == &tclWideIntType)) { |
| 2832 |
Tcl_WideInt w2; |
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
if (t1Ptr == &tclIntType) { |
| 2837 |
w = Tcl_LongAsWide(valuePtr->internalRep.longValue); |
| 2838 |
TclGetWide(w2,value2Ptr); |
| 2839 |
} else if (t2Ptr == &tclIntType) { |
| 2840 |
TclGetWide(w,valuePtr); |
| 2841 |
w2 = Tcl_LongAsWide(value2Ptr->internalRep.longValue); |
| 2842 |
} else { |
| 2843 |
TclGetWide(w,valuePtr); |
| 2844 |
TclGetWide(w2,value2Ptr); |
| 2845 |
} |
| 2846 |
switch (*pc) { |
| 2847 |
case INST_EQ: |
| 2848 |
iResult = w == w2; |
| 2849 |
break; |
| 2850 |
case INST_NEQ: |
| 2851 |
iResult = w != w2; |
| 2852 |
break; |
| 2853 |
case INST_LT: |
| 2854 |
iResult = w < w2; |
| 2855 |
break; |
| 2856 |
case INST_GT: |
| 2857 |
iResult = w > w2; |
| 2858 |
break; |
| 2859 |
case INST_LE: |
| 2860 |
iResult = w <= w2; |
| 2861 |
break; |
| 2862 |
case INST_GE: |
| 2863 |
iResult = w >= w2; |
| 2864 |
break; |
| 2865 |
} |
| 2866 |
} else { |
| 2867 |
|
| 2868 |
|
| 2869 |
|
| 2870 |
i = valuePtr->internalRep.longValue; |
| 2871 |
i2 = value2Ptr->internalRep.longValue; |
| 2872 |
switch (*pc) { |
| 2873 |
case INST_EQ: |
| 2874 |
iResult = i == i2; |
| 2875 |
break; |
| 2876 |
case INST_NEQ: |
| 2877 |
iResult = i != i2; |
| 2878 |
break; |
| 2879 |
case INST_LT: |
| 2880 |
iResult = i < i2; |
| 2881 |
break; |
| 2882 |
case INST_GT: |
| 2883 |
iResult = i > i2; |
| 2884 |
break; |
| 2885 |
case INST_LE: |
| 2886 |
iResult = i <= i2; |
| 2887 |
break; |
| 2888 |
case INST_GE: |
| 2889 |
iResult = i >= i2; |
| 2890 |
break; |
| 2891 |
} |
| 2892 |
} |
| 2893 |
|
| 2894 |
foundResult: |
| 2895 |
TRACE(("%.20s %.20s => %ld\n", O2S(valuePtr), O2S(value2Ptr), iResult)); |
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
|
| 2900 |
|
| 2901 |
|
| 2902 |
pc++; |
| 2903 |
#ifndef TCL_COMPILE_DEBUG |
| 2904 |
switch (*pc) { |
| 2905 |
case INST_JUMP_FALSE1: |
| 2906 |
NEXT_INST_F((iResult? 2 : TclGetInt1AtPtr(pc+1)), 2, 0); |
| 2907 |
case INST_JUMP_TRUE1: |
| 2908 |
NEXT_INST_F((iResult? TclGetInt1AtPtr(pc+1) : 2), 2, 0); |
| 2909 |
case INST_JUMP_FALSE4: |
| 2910 |
NEXT_INST_F((iResult? 5 : TclGetInt4AtPtr(pc+1)), 2, 0); |
| 2911 |
case INST_JUMP_TRUE4: |
| 2912 |
NEXT_INST_F((iResult? TclGetInt4AtPtr(pc+1) : 5), 2, 0); |
| 2913 |
} |
| 2914 |
#endif |
| 2915 |
objResultPtr = Tcl_NewIntObj(iResult); |
| 2916 |
NEXT_INST_F(0, 2, 1); |
| 2917 |
} |
| 2918 |
|
| 2919 |
case INST_MOD: |
| 2920 |
case INST_LSHIFT: |
| 2921 |
case INST_RSHIFT: |
| 2922 |
case INST_BITOR: |
| 2923 |
case INST_BITXOR: |
| 2924 |
case INST_BITAND: |
| 2925 |
{ |
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
long i2 = 0, rem, negative; |
| 2931 |
long iResult = 0; |
| 2932 |
Tcl_WideInt w2, wResult = W0; |
| 2933 |
int doWide = 0; |
| 2934 |
|
| 2935 |
value2Ptr = stackPtr[stackTop]; |
| 2936 |
valuePtr = stackPtr[stackTop - 1]; |
| 2937 |
if (valuePtr->typePtr == &tclIntType) { |
| 2938 |
i = valuePtr->internalRep.longValue; |
| 2939 |
} else if (valuePtr->typePtr == &tclWideIntType) { |
| 2940 |
TclGetWide(w,valuePtr); |
| 2941 |
} else { |
| 2942 |
REQUIRE_WIDE_OR_INT(result, valuePtr, i, w); |
| 2943 |
if (result != TCL_OK) { |
| 2944 |
TRACE(("%.20s %.20s => ILLEGAL 1st TYPE %s\n", |
| 2945 |
O2S(valuePtr), O2S(value2Ptr), |
| 2946 |
(valuePtr->typePtr? |
| 2947 |
valuePtr->typePtr->name : "null"))); |
| 2948 |
DECACHE_STACK_INFO(); |
| 2949 |
IllegalExprOperandType(interp, pc, valuePtr); |
| 2950 |
CACHE_STACK_INFO(); |
| 2951 |
goto checkForCatch; |
| 2952 |
} |
| 2953 |
} |
| 2954 |
if (value2Ptr->typePtr == &tclIntType) { |
| 2955 |
i2 = value2Ptr->internalRep.longValue; |
| 2956 |
} else if (value2Ptr->typePtr == &tclWideIntType) { |
| 2957 |
TclGetWide(w2,value2Ptr); |
| 2958 |
} else { |
| 2959 |
REQUIRE_WIDE_OR_INT(result, value2Ptr, i2, w2); |
| 2960 |
if (result != TCL_OK) { |
| 2961 |
TRACE(("%.20s %.20s => ILLEGAL 2nd TYPE %s\n", |
| 2962 |
O2S(valuePtr), O2S(value2Ptr), |
| 2963 |
(value2Ptr->typePtr? |
| 2964 |
value2Ptr->typePtr->name : "null"))); |
| 2965 |
DECACHE_STACK_INFO(); |
| 2966 |
IllegalExprOperandType(interp, pc, value2Ptr); |
| 2967 |
CACHE_STACK_INFO(); |
| 2968 |
goto checkForCatch; |
| 2969 |
} |
| 2970 |
} |
| 2971 |
|
| 2972 |
switch (*pc) { |
| 2973 |
case INST_MOD: |
| 2974 |
|
| 2975 |
|
| 2976 |
|
| 2977 |
|
| 2978 |
|
| 2979 |
|
| 2980 |
if (value2Ptr->typePtr == &tclWideIntType && w2 == W0) { |
| 2981 |
if (valuePtr->typePtr == &tclIntType) { |
| 2982 |
TRACE(("%ld "LLD" => DIVIDE BY ZERO\n", i, w2)); |
| 2983 |
} else { |
| 2984 |
TRACE((LLD" "LLD" => DIVIDE BY ZERO\n", w, w2)); |
| 2985 |
} |
| 2986 |
goto divideByZero; |
| 2987 |
} |
| 2988 |
if (value2Ptr->typePtr == &tclIntType && i2 == 0) { |
| 2989 |
if (valuePtr->typePtr == &tclIntType) { |
| 2990 |
TRACE(("%ld %ld => DIVIDE BY ZERO\n", i, i2)); |
| 2991 |
} else { |
| 2992 |
TRACE((LLD" %ld => DIVIDE BY ZERO\n", w, i2)); |
| 2993 |
} |
| 2994 |
goto divideByZero; |
| 2995 |
} |
| 2996 |
negative = 0; |
| 2997 |
if (valuePtr->typePtr == &tclWideIntType |
| 2998 |
|| value2Ptr->typePtr == &tclWideIntType) { |
| 2999 |
Tcl_WideInt wRemainder; |
| 3000 |
|
| 3001 |
|
| 3002 |
|
| 3003 |
if (valuePtr->typePtr == &tclIntType) { |
| 3004 |
w = Tcl_LongAsWide(i); |
| 3005 |
} else if (value2Ptr->typePtr == &tclIntType) { |
| 3006 |
w2 = Tcl_LongAsWide(i2); |
| 3007 |
} |
| 3008 |
if (w2 < 0) { |
| 3009 |
w2 = -w2; |
| 3010 |
w = -w; |
| 3011 |
negative = 1; |
| 3012 |
} |
| 3013 |
wRemainder = w % w2; |
| 3014 |
if (wRemainder < 0) { |
| 3015 |
wRemainder += w2; |
| 3016 |
} |
| 3017 |
if (negative) { |
| 3018 |
wRemainder = -wRemainder; |
| 3019 |
} |
| 3020 |
wResult = wRemainder; |
| 3021 |
doWide = 1; |
| 3022 |
break; |
| 3023 |
} |
| 3024 |
if (i2 < 0) { |
| 3025 |
i2 = -i2; |
| 3026 |
i = -i; |
| 3027 |
negative = 1; |
| 3028 |
} |
| 3029 |
rem = i % i2; |
| 3030 |
if (rem < 0) { |
| 3031 |
rem += i2; |
| 3032 |
} |
| 3033 |
if (negative) { |
| 3034 |
rem = -rem; |
| 3035 |
} |
| 3036 |
iResult = rem; |
| 3037 |
break; |
| 3038 |
case INST_LSHIFT: |
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
FORCE_LONG(value2Ptr, i2, w2); |
| 3043 |
if (valuePtr->typePtr == &tclWideIntType) { |
| 3044 |
#ifdef TCL_COMPILE_DEBUG |
| 3045 |
w2 = Tcl_LongAsWide(i2); |
| 3046 |
#endif |
| 3047 |
wResult = w << i2; |
| 3048 |
doWide = 1; |
| 3049 |
break; |
| 3050 |
} |
| 3051 |
iResult = i << i2; |
| 3052 |
break; |
| 3053 |
case INST_RSHIFT: |
| 3054 |
|
| 3055 |
|
| 3056 |
|
| 3057 |
|
| 3058 |
|
| 3059 |
|
| 3060 |
|
| 3061 |
|
| 3062 |
FORCE_LONG(value2Ptr, i2, w2); |
| 3063 |
if (valuePtr->typePtr == &tclWideIntType) { |
| 3064 |
#ifdef TCL_COMPILE_DEBUG |
| 3065 |
w2 = Tcl_LongAsWide(i2); |
| 3066 |
#endif |
| 3067 |
if (w < 0) { |
| 3068 |
wResult = ~((~w) >> i2); |
| 3069 |
} else { |
| 3070 |
wResult = w >> i2; |
| 3071 |
} |
| 3072 |
doWide = 1; |
| 3073 |
break; |
| 3074 |
} |
| 3075 |
if (i < 0) { |
| 3076 |
iResult = ~((~i) >> i2); |
| 3077 |
} else { |
| 3078 |
iResult = i >> i2; |
| 3079 |
} |
| 3080 |
break; |
| 3081 |
case INST_BITOR: |
| 3082 |
if (valuePtr->typePtr == &tclWideIntType |
| 3083 |
|| value2Ptr->typePtr == &tclWideIntType) { |
| 3084 |
|
| 3085 |
|
| 3086 |
|
| 3087 |
if (valuePtr->typePtr == &tclIntType) { |
| 3088 |
w = Tcl_LongAsWide(i); |
| 3089 |
} else if (value2Ptr->typePtr == &tclIntType) { |
| 3090 |
w2 = Tcl_LongAsWide(i2); |
| 3091 |
} |
| 3092 |
wResult = w | w2; |
| 3093 |
doWide = 1; |
| 3094 |
break; |
| 3095 |
} |
| 3096 |
iResult = i | i2; |
| 3097 |
break; |
| 3098 |
case INST_BITXOR: |
| 3099 |
if (valuePtr->typePtr == &tclWideIntType |
| 3100 |
|| value2Ptr->typePtr == &tclWideIntType) { |
| 3101 |
|
| 3102 |
|
| 3103 |
|
| 3104 |
if (valuePtr->typePtr == &tclIntType) { |
| 3105 |
w = Tcl_LongAsWide(i); |
| 3106 |
} else if (value2Ptr->typePtr == &tclIntType) { |
| 3107 |
w2 = Tcl_LongAsWide(i2); |
| 3108 |
} |
| 3109 |
wResult = w ^ w2; |
| 3110 |
doWide = 1; |
| 3111 |
break; |
| 3112 |
} |
| 3113 |
iResult = i ^ i2; |
| 3114 |
break; |
| 3115 |
case INST_BITAND: |
| 3116 |
if (valuePtr->typePtr == &tclWideIntType |
| 3117 |
|| value2Ptr->typePtr == &tclWideIntType) { |
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
if (valuePtr->typePtr == &tclIntType) { |
| 3122 |
w = Tcl_LongAsWide(i); |
| 3123 |
} else if (value2Ptr->typePtr == &tclIntType) { |
| 3124 |
w2 = Tcl_LongAsWide(i2); |
| 3125 |
} |
| 3126 |
wResult = w & w2; |
| 3127 |
doWide = 1; |
| 3128 |
break; |
| 3129 |
} |
| 3130 |
iResult = i & i2; |
| 3131 |
break; |
| 3132 |
} |
| 3133 |
|
| 3134 |
|
| 3135 |
|
| 3136 |
|
| 3137 |
|
| 3138 |
if (Tcl_IsShared(valuePtr)) { |
| 3139 |
if (doWide) { |
| 3140 |
objResultPtr = Tcl_NewWideIntObj(wResult); |
| 3141 |
TRACE((LLD" "LLD" => "LLD"\n", w, w2, wResult)); |
| 3142 |
} else { |
| 3143 |
objResultPtr = Tcl_NewLongObj(iResult); |
| 3144 |
TRACE(("%ld %ld => %ld\n", i, i2, iResult)); |
| 3145 |
} |
| 3146 |
NEXT_INST_F(1, 2, 1); |
| 3147 |
} else { |
| 3148 |
if (doWide) { |
| 3149 |
TRACE((LLD" "LLD" => "LLD"\n", w, w2, wResult)); |
| 3150 |
Tcl_SetWideIntObj(valuePtr, wResult); |
| 3151 |
} else { |
| 3152 |
TRACE(("%ld %ld => %ld\n", i, i2, iResult)); |
| 3153 |
Tcl_SetLongObj(valuePtr, iResult); |
| 3154 |
} |
| 3155 |
NEXT_INST_F(1, 1, 0); |
| 3156 |
} |
| 3157 |
} |
| 3158 |
|
| 3159 |
case INST_ADD: |
| 3160 |
case INST_SUB: |
| 3161 |
case INST_MULT: |
| 3162 |
case INST_DIV: |
| 3163 |
{ |
| 3164 |
|
| 3165 |
|
| 3166 |
|
| 3167 |
|
| 3168 |
|
| 3169 |
Tcl_ObjType *t1Ptr, *t2Ptr; |
| 3170 |
long i2 = 0, quot, rem; |
| 3171 |
double d1, d2; |
| 3172 |
long iResult = 0; |
| 3173 |
double dResult = 0.0; |
| 3174 |
int doDouble = 0; |
| 3175 |
Tcl_WideInt w2, wquot, wrem; |
| 3176 |
Tcl_WideInt wResult = W0; |
| 3177 |
int doWide = 0; |
| 3178 |
|
| 3179 |
value2Ptr = stackPtr[stackTop]; |
| 3180 |
valuePtr = stackPtr[stackTop - 1]; |
| 3181 |
t1Ptr = valuePtr->typePtr; |
| 3182 |
t2Ptr = value2Ptr->typePtr; |
| 3183 |
|
| 3184 |
if (t1Ptr == &tclIntType) { |
| 3185 |
i = valuePtr->internalRep.longValue; |
| 3186 |
} else if (t1Ptr == &tclWideIntType) { |
| 3187 |
TclGetWide(w,valuePtr); |
| 3188 |
} else if ((t1Ptr == &tclDoubleType) |
| 3189 |
&& (valuePtr->bytes == NULL)) { |
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
d1 = valuePtr->internalRep.doubleValue; |
| 3197 |
} else { |
| 3198 |
char *s = Tcl_GetStringFromObj(valuePtr, &length); |
| 3199 |
if (TclLooksLikeInt(s, length)) { |
| 3200 |
GET_WIDE_OR_INT(result, valuePtr, i, w); |
| 3201 |
} else { |
| 3202 |
result = Tcl_GetDoubleFromObj((Tcl_Interp *) NULL, |
| 3203 |
valuePtr, &d1); |
| 3204 |
} |
| 3205 |
if (result != TCL_OK) { |
| 3206 |
TRACE(("%.20s %.20s => ILLEGAL 1st TYPE %s\n", |
| 3207 |
s, O2S(valuePtr), |
| 3208 |
(valuePtr->typePtr? |
| 3209 |
valuePtr->typePtr->name : "null"))); |
| 3210 |
DECACHE_STACK_INFO(); |
| 3211 |
IllegalExprOperandType(interp, pc, valuePtr); |
| 3212 |
CACHE_STACK_INFO(); |
| 3213 |
goto checkForCatch; |
| 3214 |
} |
| 3215 |
t1Ptr = valuePtr->typePtr; |
| 3216 |
} |
| 3217 |
|
| 3218 |
if (t2Ptr == &tclIntType) { |
| 3219 |
i2 = value2Ptr->internalRep.longValue; |
| 3220 |
} else if (t2Ptr == &tclWideIntType) { |
| 3221 |
TclGetWide(w2,value2Ptr); |
| 3222 |
} else if ((t2Ptr == &tclDoubleType) |
| 3223 |
&& (value2Ptr->bytes == NULL)) { |
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
d2 = value2Ptr->internalRep.doubleValue; |
| 3231 |
} else { |
| 3232 |
char *s = Tcl_GetStringFromObj(value2Ptr, &length); |
| 3233 |
if (TclLooksLikeInt(s, length)) { |
| 3234 |
GET_WIDE_OR_INT(result, value2Ptr, i2, w2); |
| 3235 |
} else { |
| 3236 |
result = Tcl_GetDoubleFromObj((Tcl_Interp *) NULL, |
| 3237 |
value2Ptr, &d2); |
| 3238 |
} |
| 3239 |
if (result != TCL_OK) { |
| 3240 |
TRACE(("%.20s %.20s => ILLEGAL 2nd TYPE %s\n", |
| 3241 |
O2S(value2Ptr), s, |
| 3242 |
(value2Ptr->typePtr? |
| 3243 |
value2Ptr->typePtr->name : "null"))); |
| 3244 |
DECACHE_STACK_INFO(); |
| 3245 |
IllegalExprOperandType(interp, pc, value2Ptr); |
| 3246 |
CACHE_STACK_INFO(); |
| 3247 |
goto checkForCatch; |
| 3248 |
} |
| 3249 |
t2Ptr = value2Ptr->typePtr; |
| 3250 |
} |
| 3251 |
|
| 3252 |
if ((t1Ptr == &tclDoubleType) || (t2Ptr == &tclDoubleType)) { |
| 3253 |
|
| 3254 |
|
| 3255 |
|
| 3256 |
doDouble = 1; |
| 3257 |
if (t1Ptr == &tclIntType) { |
| 3258 |
d1 = i; |
| 3259 |
} else if (t2Ptr == &tclIntType) { |
| 3260 |
d2 = i2; |
| 3261 |
} else if (t1Ptr == &tclWideIntType) { |
| 3262 |
d1 = Tcl_WideAsDouble(w); |
| 3263 |
} else if (t2Ptr == &tclWideIntType) { |
| 3264 |
d2 = Tcl_WideAsDouble(w2); |
| 3265 |
} |
| 3266 |
switch (*pc) { |
| 3267 |
case INST_ADD: |
| 3268 |
dResult = d1 + d2; |
| 3269 |
break; |
| 3270 |
case INST_SUB: |
| 3271 |
dResult = d1 - d2; |
| 3272 |
break; |
| 3273 |
case INST_MULT: |
| 3274 |
dResult = d1 * d2; |
| 3275 |
break; |
| 3276 |
case INST_DIV: |
| 3277 |
if (d2 == 0.0) { |
| 3278 |
TRACE(("%.6g %.6g => DIVIDE BY ZERO\n", d1, d2)); |
| 3279 |
goto divideByZero; |
| 3280 |
} |
| 3281 |
dResult = d1 / d2; |
| 3282 |
break; |
| 3283 |
} |
| 3284 |
|
| 3285 |
|
| 3286 |
|
| 3287 |
|
| 3288 |
|
| 3289 |
if (IS_NAN(dResult) || IS_INF(dResult)) { |
| 3290 |
TRACE(("%.20s %.20s => IEEE FLOATING PT ERROR\n", |
| 3291 |
O2S(valuePtr), O2S(value2Ptr))); |
| 3292 |
DECACHE_STACK_INFO(); |
| 3293 |
TclExprFloatError(interp, dResult); |
| 3294 |
CACHE_STACK_INFO(); |
| 3295 |
result = TCL_ERROR; |
| 3296 |
goto checkForCatch; |
| 3297 |
} |
| 3298 |
} else if ((t1Ptr == &tclWideIntType) |
| 3299 |
|| (t2Ptr == &tclWideIntType)) { |
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
doWide = 1; |
| 3304 |
if (t1Ptr == &tclIntType) { |
| 3305 |
w = Tcl_LongAsWide(i); |
| 3306 |
} else if (t2Ptr == &tclIntType) { |
| 3307 |
w2 = Tcl_LongAsWide(i2); |
| 3308 |
} |
| 3309 |
switch (*pc) { |
| 3310 |
case INST_ADD: |
| 3311 |
wResult = w + w2; |
| 3312 |
break; |
| 3313 |
case INST_SUB: |
| 3314 |
wResult = w - w2; |
| 3315 |
break; |
| 3316 |
case INST_MULT: |
| 3317 |
wResult = w * w2; |
| 3318 |
break; |
| 3319 |
case INST_DIV: |
| 3320 |
|
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
|
| 3325 |
|
| 3326 |
if (w2 == W0) { |
| 3327 |
TRACE((LLD" "LLD" => DIVIDE BY ZERO\n", w, w2)); |
| 3328 |
goto divideByZero; |
| 3329 |
} |
| 3330 |
if (w2 < 0) { |
| 3331 |
w2 = -w2; |
| 3332 |
w = -w; |
| 3333 |
} |
| 3334 |
wquot = w / w2; |
| 3335 |
wrem = w % w2; |
| 3336 |
if (wrem < W0) { |
| 3337 |
wquot -= 1; |
| 3338 |
} |
| 3339 |
wResult = wquot; |
| 3340 |
break; |
| 3341 |
} |
| 3342 |
} else { |
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
switch (*pc) { |
| 3347 |
case INST_ADD: |
| 3348 |
iResult = i + i2; |
| 3349 |
break; |
| 3350 |
case INST_SUB: |
| 3351 |
iResult = i - i2; |
| 3352 |
break; |
| 3353 |
case INST_MULT: |
| 3354 |
iResult = i * i2; |
| 3355 |
break; |
| 3356 |
case INST_DIV: |
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
|
| 3363 |
if (i2 == 0) { |
| 3364 |
TRACE(("%ld %ld => DIVIDE BY ZERO\n", i, i2)); |
| 3365 |
goto divideByZero; |
| 3366 |
} |
| 3367 |
if (i2 < 0) { |
| 3368 |
i2 = -i2; |
| 3369 |
i = -i; |
| 3370 |
} |
| 3371 |
quot = i / i2; |
| 3372 |
rem = i % i2; |
| 3373 |
if (rem < 0) { |
| 3374 |
quot -= 1; |
| 3375 |
} |
| 3376 |
iResult = quot; |
| 3377 |
break; |
| 3378 |
} |
| 3379 |
} |
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
|
| 3384 |
|
| 3385 |
if (Tcl_IsShared(valuePtr)) { |
| 3386 |
if (doDouble) { |
| 3387 |
objResultPtr = Tcl_NewDoubleObj(dResult); |
| 3388 |
TRACE(("%.6g %.6g => %.6g\n", d1, d2, dResult)); |
| 3389 |
} else if (doWide) { |
| 3390 |
objResultPtr = Tcl_NewWideIntObj(wResult); |
| 3391 |
TRACE((LLD" "LLD" => "LLD"\n", w, w2, wResult)); |
| 3392 |
} else { |
| 3393 |
objResultPtr = Tcl_NewLongObj(iResult); |
| 3394 |
TRACE(("%ld %ld => %ld\n", i, i2, iResult)); |
| 3395 |
} |
| 3396 |
NEXT_INST_F(1, 2, 1); |
| 3397 |
} else { |
| 3398 |
if (doDouble) { |
| 3399 |
TRACE(("%.6g %.6g => %.6g\n", d1, d2, dResult)); |
| 3400 |
Tcl_SetDoubleObj(valuePtr, dResult); |
| 3401 |
} else if (doWide) { |
| 3402 |
TRACE((LLD" "LLD" => "LLD"\n", w, w2, wResult)); |
| 3403 |
Tcl_SetWideIntObj(valuePtr, wResult); |
| 3404 |
} else { |
| 3405 |
TRACE(("%ld %ld => %ld\n", i, i2, iResult)); |
| 3406 |
Tcl_SetLongObj(valuePtr, iResult); |
| 3407 |
} |
| 3408 |
NEXT_INST_F(1, 1, 0); |
| 3409 |
} |
| 3410 |
} |
| 3411 |
|
| 3412 |
case INST_UPLUS: |
| 3413 |
{ |
| 3414 |
|
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
double d; |
| 3419 |
Tcl_ObjType *tPtr; |
| 3420 |
|
| 3421 |
valuePtr = stackPtr[stackTop]; |
| 3422 |
tPtr = valuePtr->typePtr; |
| 3423 |
if (!IS_INTEGER_TYPE(tPtr) && ((tPtr != &tclDoubleType) |
| 3424 |
|| (valuePtr->bytes != NULL))) { |
| 3425 |
char *s = Tcl_GetStringFromObj(valuePtr, &length); |
| 3426 |
if (TclLooksLikeInt(s, length)) { |
| 3427 |
GET_WIDE_OR_INT(result, valuePtr, i, w); |
| 3428 |
} else { |
| 3429 |
result = Tcl_GetDoubleFromObj((Tcl_Interp *) NULL, valuePtr, &d); |
| 3430 |
} |
| 3431 |
if (result != TCL_OK) { |
| 3432 |
TRACE(("\"%.20s\" => ILLEGAL TYPE %s \n", |
| 3433 |
s, (tPtr? tPtr->name : "null"))); |
| 3434 |
DECACHE_STACK_INFO(); |
| 3435 |
IllegalExprOperandType(interp, pc, valuePtr); |
| 3436 |
CACHE_STACK_INFO(); |
| 3437 |
goto checkForCatch; |
| 3438 |
} |
| 3439 |
tPtr = valuePtr->typePtr; |
| 3440 |
} |
| 3441 |
|
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
|
| 3447 |
|
| 3448 |
|
| 3449 |
|
| 3450 |
|
| 3451 |
if (Tcl_IsShared(valuePtr)) { |
| 3452 |
if (tPtr == &tclIntType) { |
| 3453 |
i = valuePtr->internalRep.longValue; |
| 3454 |
objResultPtr = Tcl_NewLongObj(i); |
| 3455 |
} else if (tPtr == &tclWideIntType) { |
| 3456 |
TclGetWide(w,valuePtr); |
| 3457 |
objResultPtr = Tcl_NewWideIntObj(w); |
| 3458 |
} else { |
| 3459 |
d = valuePtr->internalRep.doubleValue; |
| 3460 |
objResultPtr = Tcl_NewDoubleObj(d); |
| 3461 |
} |
| 3462 |
TRACE_WITH_OBJ(("%s => ", O2S(objResultPtr)), objResultPtr); |
| 3463 |
NEXT_INST_F(1, 1, 1); |
| 3464 |
} else { |
| 3465 |
Tcl_InvalidateStringRep(valuePtr); |
| 3466 |
TRACE_WITH_OBJ(("%s => ", O2S(valuePtr)), valuePtr); |
| 3467 |
NEXT_INST_F(1, 0, 0); |
| 3468 |
} |
| 3469 |
} |
| 3470 |
|
| 3471 |
case INST_UMINUS: |
| 3472 |
case INST_LNOT: |
| 3473 |
{ |
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
|
| 3482 |
|
| 3483 |
double d; |
| 3484 |
int boolvar; |
| 3485 |
Tcl_ObjType *tPtr; |
| 3486 |
|
| 3487 |
valuePtr = stackPtr[stackTop]; |
| 3488 |
tPtr = valuePtr->typePtr; |
| 3489 |
if (!IS_INTEGER_TYPE(tPtr) && ((tPtr != &tclDoubleType) |
| 3490 |
|| (valuePtr->bytes != NULL))) { |
| 3491 |
if ((tPtr == &tclBooleanType) && (valuePtr->bytes == NULL)) { |
| 3492 |
valuePtr->typePtr = &tclIntType; |
| 3493 |
} else { |
| 3494 |
char *s = Tcl_GetStringFromObj(valuePtr, &length); |
| 3495 |
if (TclLooksLikeInt(s, length)) { |
| 3496 |
GET_WIDE_OR_INT(result, valuePtr, i, w); |
| 3497 |
} else { |
| 3498 |
result = Tcl_GetDoubleFromObj((Tcl_Interp *) NULL, |
| 3499 |
valuePtr, &d); |
| 3500 |
} |
| 3501 |
if (result == TCL_ERROR && *pc == INST_LNOT) { |
| 3502 |
result = Tcl_GetBooleanFromObj((Tcl_Interp *)NULL, |
| 3503 |
valuePtr, &boolvar); |
| 3504 |
i = (long)boolvar; |
| 3505 |
} |
| 3506 |
if (result != TCL_OK) { |
| 3507 |
TRACE(("\"%.20s\" => ILLEGAL TYPE %s\n", |
| 3508 |
s, (tPtr? tPtr->name : "null"))); |
| 3509 |
DECACHE_STACK_INFO(); |
| 3510 |
IllegalExprOperandType(interp, pc, valuePtr); |
| 3511 |
CACHE_STACK_INFO(); |
| 3512 |
goto checkForCatch; |
| 3513 |
} |
| 3514 |
} |
| 3515 |
tPtr = valuePtr->typePtr; |
| 3516 |
} |
| 3517 |
|
| 3518 |
if (Tcl_IsShared(valuePtr)) { |
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
if ((tPtr == &tclIntType) || (tPtr == &tclBooleanType)) { |
| 3523 |
i = valuePtr->internalRep.longValue; |
| 3524 |
objResultPtr = Tcl_NewLongObj( |
| 3525 |
(*pc == INST_UMINUS)? -i : !i); |
| 3526 |
TRACE_WITH_OBJ(("%ld => ", i), objResultPtr); |
| 3527 |
} else if (tPtr == &tclWideIntType) { |
| 3528 |
TclGetWide(w,valuePtr); |
| 3529 |
if (*pc == INST_UMINUS) { |
| 3530 |
objResultPtr = Tcl_NewWideIntObj(-w); |
| 3531 |
} else { |
| 3532 |
objResultPtr = Tcl_NewLongObj(w == W0); |
| 3533 |
} |
| 3534 |
TRACE_WITH_OBJ((LLD" => ", w), objResultPtr); |
| 3535 |
} else { |
| 3536 |
d = valuePtr->internalRep.doubleValue; |
| 3537 |
if (*pc == INST_UMINUS) { |
| 3538 |
objResultPtr = Tcl_NewDoubleObj(-d); |
| 3539 |
} else { |
| 3540 |
|
| 3541 |
|
| 3542 |
|
| 3543 |
|
| 3544 |
objResultPtr = Tcl_NewLongObj((d==0.0)? 1 : 0); |
| 3545 |
} |
| 3546 |
TRACE_WITH_OBJ(("%.6g => ", d), objResultPtr); |
| 3547 |
} |
| 3548 |
NEXT_INST_F(1, 1, 1); |
| 3549 |
} else { |
| 3550 |
|
| 3551 |
|
| 3552 |
|
| 3553 |
if ((tPtr == &tclIntType) || (tPtr == &tclBooleanType)) { |
| 3554 |
i = valuePtr->internalRep.longValue; |
| 3555 |
Tcl_SetLongObj(valuePtr, |
| 3556 |
(*pc == INST_UMINUS)? -i : !i); |
| 3557 |
TRACE_WITH_OBJ(("%ld => ", i), valuePtr); |
| 3558 |
} else if (tPtr == &tclWideIntType) { |
| 3559 |
TclGetWide(w,valuePtr); |
| 3560 |
if (*pc == INST_UMINUS) { |
| 3561 |
Tcl_SetWideIntObj(valuePtr, -w); |
| 3562 |
} else { |
| 3563 |
Tcl_SetLongObj(valuePtr, w == W0); |
| 3564 |
} |
| 3565 |
TRACE_WITH_OBJ((LLD" => ", w), valuePtr); |
| 3566 |
} else { |
| 3567 |
d = valuePtr->internalRep.doubleValue; |
| 3568 |
if (*pc == INST_UMINUS) { |
| 3569 |
Tcl_SetDoubleObj(valuePtr, -d); |
| 3570 |
} else { |
| 3571 |
|
| 3572 |
|
| 3573 |
|
| 3574 |
|
| 3575 |
Tcl_SetLongObj(valuePtr, (d==0.0)? 1 : 0); |
| 3576 |
} |
| 3577 |
TRACE_WITH_OBJ(("%.6g => ", d), valuePtr); |
| 3578 |
} |
| 3579 |
NEXT_INST_F(1, 0, 0); |
| 3580 |
} |
| 3581 |
} |
| 3582 |
|
| 3583 |
case INST_BITNOT: |
| 3584 |
{ |
| 3585 |
|
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
Tcl_ObjType *tPtr; |
| 3593 |
|
| 3594 |
valuePtr = stackPtr[stackTop]; |
| 3595 |
tPtr = valuePtr->typePtr; |
| 3596 |
if (!IS_INTEGER_TYPE(tPtr)) { |
| 3597 |
REQUIRE_WIDE_OR_INT(result, valuePtr, i, w); |
| 3598 |
if (result != TCL_OK) { |
| 3599 |
TRACE(("\"%.20s\" => ILLEGAL TYPE %s\n", |
| 3600 |
O2S(valuePtr), (tPtr? tPtr->name : "null"))); |
| 3601 |
DECACHE_STACK_INFO(); |
| 3602 |
IllegalExprOperandType(interp, pc, valuePtr); |
| 3603 |
CACHE_STACK_INFO(); |
| 3604 |
goto checkForCatch; |
| 3605 |
} |
| 3606 |
} |
| 3607 |
|
| 3608 |
if (valuePtr->typePtr == &tclWideIntType) { |
| 3609 |
TclGetWide(w,valuePtr); |
| 3610 |
if (Tcl_IsShared(valuePtr)) { |
| 3611 |
objResultPtr = Tcl_NewWideIntObj(~w); |
| 3612 |
TRACE(("0x%llx => (%llu)\n", w, ~w)); |
| 3613 |
NEXT_INST_F(1, 1, 1); |
| 3614 |
} else { |
| 3615 |
|
| 3616 |
|
| 3617 |
|
| 3618 |
Tcl_SetWideIntObj(valuePtr, ~w); |
| 3619 |
TRACE(("0x%llx => (%llu)\n", w, ~w)); |
| 3620 |
NEXT_INST_F(1, 0, 0); |
| 3621 |
} |
| 3622 |
} else { |
| 3623 |
i = valuePtr->internalRep.longValue; |
| 3624 |
if (Tcl_IsShared(valuePtr)) { |
| 3625 |
objResultPtr = Tcl_NewLongObj(~i); |
| 3626 |
TRACE(("0x%lx => (%lu)\n", i, ~i)); |
| 3627 |
NEXT_INST_F(1, 1, 1); |
| 3628 |
} else { |
| 3629 |
|
| 3630 |
|
| 3631 |
|
| 3632 |
Tcl_SetLongObj(valuePtr, ~i); |
| 3633 |
TRACE(("0x%lx => (%lu)\n", i, ~i)); |
| 3634 |
NEXT_INST_F(1, 0, 0); |
| 3635 |
} |
| 3636 |
} |
| 3637 |
} |
| 3638 |
|
| 3639 |
case INST_CALL_BUILTIN_FUNC1: |
| 3640 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 3641 |
{ |
| 3642 |
|
| 3643 |
|
| 3644 |
|
| 3645 |
|
| 3646 |
BuiltinFunc *mathFuncPtr; |
| 3647 |
|
| 3648 |
if ((opnd < 0) || (opnd > LAST_BUILTIN_FUNC)) { |
| 3649 |
TRACE(("UNRECOGNIZED BUILTIN FUNC CODE %d\n", opnd)); |
| 3650 |
panic("TclExecuteByteCode: unrecognized builtin function code %d", opnd); |
| 3651 |
} |
| 3652 |
mathFuncPtr = &(tclBuiltinFuncTable[opnd]); |
| 3653 |
DECACHE_STACK_INFO(); |
| 3654 |
result = (*mathFuncPtr->proc)(interp, eePtr, |
| 3655 |
mathFuncPtr->clientData); |
| 3656 |
CACHE_STACK_INFO(); |
| 3657 |
if (result != TCL_OK) { |
| 3658 |
goto checkForCatch; |
| 3659 |
} |
| 3660 |
TRACE_WITH_OBJ(("%d => ", opnd), stackPtr[stackTop]); |
| 3661 |
} |
| 3662 |
NEXT_INST_F(2, 0, 0); |
| 3663 |
|
| 3664 |
case INST_CALL_FUNC1: |
| 3665 |
opnd = TclGetUInt1AtPtr(pc+1); |
| 3666 |
{ |
| 3667 |
|
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
|
| 3672 |
int objc = opnd; |
| 3673 |
|
| 3674 |
Tcl_Obj **objv; |
| 3675 |
|
| 3676 |
|
| 3677 |
objv = &(stackPtr[stackTop - (objc-1)]); |
| 3678 |
DECACHE_STACK_INFO(); |
| 3679 |
result = ExprCallMathFunc(interp, eePtr, objc, objv); |
| 3680 |
CACHE_STACK_INFO(); |
| 3681 |
if (result != TCL_OK) { |
| 3682 |
goto checkForCatch; |
| 3683 |
} |
| 3684 |
TRACE_WITH_OBJ(("%d => ", objc), stackPtr[stackTop]); |
| 3685 |
} |
| 3686 |
NEXT_INST_F(2, 0, 0); |
| 3687 |
|
| 3688 |
case INST_TRY_CVT_TO_NUMERIC: |
| 3689 |
{ |
| 3690 |
|
| 3691 |
|
| 3692 |
|
| 3693 |
|
| 3694 |
|
| 3695 |
|
| 3696 |
|
| 3697 |
double d; |
| 3698 |
char *s; |
| 3699 |
Tcl_ObjType *tPtr; |
| 3700 |
int converted, needNew; |
| 3701 |
|
| 3702 |
valuePtr = stackPtr[stackTop]; |
| 3703 |
tPtr = valuePtr->typePtr; |
| 3704 |
converted = 0; |
| 3705 |
if (!IS_INTEGER_TYPE(tPtr) && ((tPtr != &tclDoubleType) |
| 3706 |
|| (valuePtr->bytes != NULL))) { |
| 3707 |
if ((tPtr == &tclBooleanType) && (valuePtr->bytes == NULL)) { |
| 3708 |
valuePtr->typePtr = &tclIntType; |
| 3709 |
converted = 1; |
| 3710 |
} else { |
| 3711 |
s = Tcl_GetStringFromObj(valuePtr, &length); |
| 3712 |
if (TclLooksLikeInt(s, length)) { |
| 3713 |
GET_WIDE_OR_INT(result, valuePtr, i, w); |
| 3714 |
} else { |
| 3715 |
result = Tcl_GetDoubleFromObj((Tcl_Interp *) NULL, |
| 3716 |
valuePtr, &d); |
| 3717 |
} |
| 3718 |
if (result == TCL_OK) { |
| 3719 |
converted = 1; |
| 3720 |
} |
| 3721 |
result = TCL_OK; |
| 3722 |
} |
| 3723 |
tPtr = valuePtr->typePtr; |
| 3724 |
} |
| 3725 |
|
| 3726 |
|
| 3727 |
|
| 3728 |
|
| 3729 |
|
| 3730 |
|
| 3731 |
|
| 3732 |
|
| 3733 |
|
| 3734 |
|
| 3735 |
|
| 3736 |
|
| 3737 |
objResultPtr = valuePtr; |
| 3738 |
needNew = 0; |
| 3739 |
if (IS_NUMERIC_TYPE(tPtr)) { |
| 3740 |
if (Tcl_IsShared(valuePtr)) { |
| 3741 |
if (valuePtr->bytes != NULL) { |
| 3742 |
|
| 3743 |
|
| 3744 |
|
| 3745 |
|
| 3746 |
needNew = 1; |
| 3747 |
if (tPtr == &tclIntType) { |
| 3748 |
i = valuePtr->internalRep.longValue; |
| 3749 |
objResultPtr = Tcl_NewLongObj(i); |
| 3750 |
} else if (tPtr == &tclWideIntType) { |
| 3751 |
TclGetWide(w,valuePtr); |
| 3752 |
objResultPtr = Tcl_NewWideIntObj(w); |
| 3753 |
} else { |
| 3754 |
d = valuePtr->internalRep.doubleValue; |
| 3755 |
objResultPtr = Tcl_NewDoubleObj(d); |
| 3756 |
} |
| 3757 |
tPtr = objResultPtr->typePtr; |
| 3758 |
} |
| 3759 |
} else { |
| 3760 |
Tcl_InvalidateStringRep(valuePtr); |
| 3761 |
} |
| 3762 |
|
| 3763 |
if (tPtr == &tclDoubleType) { |
| 3764 |
d = objResultPtr->internalRep.doubleValue; |
| 3765 |
if (IS_NAN(d) || IS_INF(d)) { |
| 3766 |
TRACE(("\"%.20s\" => IEEE FLOATING PT ERROR\n", |
| 3767 |
O2S(objResultPtr))); |
| 3768 |
DECACHE_STACK_INFO(); |
| 3769 |
TclExprFloatError(interp, d); |
| 3770 |
CACHE_STACK_INFO(); |
| 3771 |
result = TCL_ERROR; |
| 3772 |
goto checkForCatch; |
| 3773 |
} |
| 3774 |
} |
| 3775 |
converted = converted; |
| 3776 |
TRACE(("\"%.20s\" => numeric, %s, %s\n", O2S(valuePtr), |
| 3777 |
(converted? "converted" : "not converted"), |
| 3778 |
(needNew? "new Tcl_Obj" : "same Tcl_Obj"))); |
| 3779 |
} else { |
| 3780 |
TRACE(("\"%.20s\" => not numeric\n", O2S(valuePtr))); |
| 3781 |
} |
| 3782 |
if (needNew) { |
| 3783 |
NEXT_INST_F(1, 1, 1); |
| 3784 |
} else { |
| 3785 |
NEXT_INST_F(1, 0, 0); |
| 3786 |
} |
| 3787 |
} |
| 3788 |
|
| 3789 |
case INST_BREAK: |
| 3790 |
DECACHE_STACK_INFO(); |
| 3791 |
Tcl_ResetResult(interp); |
| 3792 |
CACHE_STACK_INFO(); |
| 3793 |
result = TCL_BREAK; |
| 3794 |
cleanup = 0; |
| 3795 |
goto processExceptionReturn; |
| 3796 |
|
| 3797 |
case INST_CONTINUE: |
| 3798 |
DECACHE_STACK_INFO(); |
| 3799 |
Tcl_ResetResult(interp); |
| 3800 |
CACHE_STACK_INFO(); |
| 3801 |
result = TCL_CONTINUE; |
| 3802 |
cleanup = 0; |
| 3803 |
goto processExceptionReturn; |
| 3804 |
|
| 3805 |
case INST_FOREACH_START4: |
| 3806 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 3807 |
{ |
| 3808 |
|
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
ForeachInfo *infoPtr = (ForeachInfo *) |
| 3814 |
codePtr->auxDataArrayPtr[opnd].clientData; |
| 3815 |
int iterTmpIndex = infoPtr->loopCtTemp; |
| 3816 |
Var *compiledLocals = iPtr->varFramePtr->compiledLocals; |
| 3817 |
Var *iterVarPtr = &(compiledLocals[iterTmpIndex]); |
| 3818 |
Tcl_Obj *oldValuePtr = iterVarPtr->value.objPtr; |
| 3819 |
|
| 3820 |
if (oldValuePtr == NULL) { |
| 3821 |
iterVarPtr->value.objPtr = Tcl_NewLongObj(-1); |
| 3822 |
Tcl_IncrRefCount(iterVarPtr->value.objPtr); |
| 3823 |
} else { |
| 3824 |
Tcl_SetLongObj(oldValuePtr, -1); |
| 3825 |
} |
| 3826 |
TclSetVarScalar(iterVarPtr); |
| 3827 |
TclClearVarUndefined(iterVarPtr); |
| 3828 |
TRACE(("%u => loop iter count temp %d\n", |
| 3829 |
opnd, iterTmpIndex)); |
| 3830 |
} |
| 3831 |
|
| 3832 |
#ifndef TCL_COMPILE_DEBUG |
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
pc += 5; |
| 3840 |
#else |
| 3841 |
NEXT_INST_F(5, 0, 0); |
| 3842 |
#endif |
| 3843 |
case INST_FOREACH_STEP4: |
| 3844 |
opnd = TclGetUInt4AtPtr(pc+1); |
| 3845 |
{ |
| 3846 |
|
| 3847 |
|
| 3848 |
|
| 3849 |
|
| 3850 |
|
| 3851 |
ForeachInfo *infoPtr = (ForeachInfo *) |
| 3852 |
codePtr->auxDataArrayPtr[opnd].clientData; |
| 3853 |
ForeachVarList *varListPtr; |
| 3854 |
int numLists = infoPtr->numLists; |
| 3855 |
Var *compiledLocals = iPtr->varFramePtr->compiledLocals; |
| 3856 |
Tcl_Obj *listPtr; |
| 3857 |
List *listRepPtr; |
| 3858 |
Var *iterVarPtr, *listVarPtr; |
| 3859 |
int iterNum, listTmpIndex, listLen, numVars; |
| 3860 |
int varIndex, valIndex, continueLoop, j; |
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
|
| 3866 |
iterVarPtr = &(compiledLocals[infoPtr->loopCtTemp]); |
| 3867 |
valuePtr = iterVarPtr->value.objPtr; |
| 3868 |
iterNum = (valuePtr->internalRep.longValue + 1); |
| 3869 |
Tcl_SetLongObj(valuePtr, iterNum); |
| 3870 |
|
| 3871 |
|
| 3872 |
|
| 3873 |
|
| 3874 |
|
| 3875 |
|
| 3876 |
continueLoop = 0; |
| 3877 |
listTmpIndex = infoPtr->firstValueTemp; |
| 3878 |
for (i = 0; i < numLists; i++) { |
| 3879 |
varListPtr = infoPtr->varLists[i]; |
| 3880 |
numVars = varListPtr->numVars; |
| 3881 |
|
| 3882 |
listVarPtr = &(compiledLocals[listTmpIndex]); |
| 3883 |
listPtr = listVarPtr->value.objPtr; |
| 3884 |
result = Tcl_ListObjLength(interp, listPtr, &listLen); |
| 3885 |
if (result != TCL_OK) { |
| 3886 |
TRACE_WITH_OBJ(("%u => ERROR converting list %ld, \"%s\": ", |
| 3887 |
opnd, i, O2S(listPtr)), Tcl_GetObjResult(interp)); |
| 3888 |
goto checkForCatch; |
| 3889 |
} |
| 3890 |
if (listLen > (iterNum * numVars)) { |
| 3891 |
continueLoop = 1; |
| 3892 |
} |
| 3893 |
listTmpIndex++; |
| 3894 |
} |
| 3895 |
|
| 3896 |
|
| 3897 |
|
| 3898 |
|
| 3899 |
|
| 3900 |
|
| 3901 |
|
| 3902 |
|
| 3903 |
if (continueLoop) { |
| 3904 |
listTmpIndex = infoPtr->firstValueTemp; |
| 3905 |
for (i = 0; i < numLists; i++) { |
| 3906 |
varListPtr = infoPtr->varLists[i]; |
| 3907 |
numVars = varListPtr->numVars; |
| 3908 |
|
| 3909 |
listVarPtr = &(compiledLocals[listTmpIndex]); |
| 3910 |
listPtr = listVarPtr->value.objPtr; |
| 3911 |
listRepPtr = (List *) listPtr->internalRep.twoPtrValue.ptr1; |
| 3912 |
listLen = listRepPtr->elemCount; |
| 3913 |
|
| 3914 |
valIndex = (iterNum * numVars); |
| 3915 |
for (j = 0; j < numVars; j++) { |
| 3916 |
int setEmptyStr = 0; |
| 3917 |
if (valIndex >= listLen) { |
| 3918 |
setEmptyStr = 1; |
| 3919 |
TclNewObj(valuePtr); |
| 3920 |
} else { |
| 3921 |
valuePtr = listRepPtr->elements[valIndex]; |
| 3922 |
} |
| 3923 |
|
| 3924 |
varIndex = varListPtr->varIndexes[j]; |
| 3925 |
varPtr = &(varFramePtr->compiledLocals[varIndex]); |
| 3926 |
part1 = varPtr->name; |
| 3927 |
while (TclIsVarLink(varPtr)) { |
| 3928 |
varPtr = varPtr->value.linkPtr; |
| 3929 |
} |
| 3930 |
if (!((varPtr->flags & VAR_IN_HASHTABLE) && (varPtr->hPtr == NULL)) |
| 3931 |
&& (varPtr->tracePtr == NULL) |
| 3932 |
&& (TclIsVarScalar(varPtr) || TclIsVarUndefined(varPtr))) { |
| 3933 |
value2Ptr = varPtr->value.objPtr; |
| 3934 |
if (valuePtr != value2Ptr) { |
| 3935 |
if (value2Ptr != NULL) { |
| 3936 |
TclDecrRefCount(value2Ptr); |
| 3937 |
} else { |
| 3938 |
TclSetVarScalar(varPtr); |
| 3939 |
TclClearVarUndefined(varPtr); |
| 3940 |
} |
| 3941 |
varPtr->value.objPtr = valuePtr; |
| 3942 |
Tcl_IncrRefCount(valuePtr); |
| 3943 |
} |
| 3944 |
} else { |
| 3945 |
DECACHE_STACK_INFO(); |
| 3946 |
value2Ptr = TclPtrSetVar(interp, varPtr, NULL, part1, |
| 3947 |
NULL, valuePtr, TCL_LEAVE_ERR_MSG); |
| 3948 |
CACHE_STACK_INFO(); |
| 3949 |
if (value2Ptr == NULL) { |
| 3950 |
TRACE_WITH_OBJ(("%u => ERROR init. index temp %d: ", |
| 3951 |
opnd, varIndex), |
| 3952 |
Tcl_GetObjResult(interp)); |
| 3953 |
if (setEmptyStr) { |
| 3954 |
TclDecrRefCount(valuePtr); |
| 3955 |
} |
| 3956 |
result = TCL_ERROR; |
| 3957 |
goto checkForCatch; |
| 3958 |
} |
| 3959 |
} |
| 3960 |
valIndex++; |
| 3961 |
} |
| 3962 |
listTmpIndex++; |
| 3963 |
} |
| 3964 |
} |
| 3965 |
TRACE(("%u => %d lists, iter %d, %s loop\n", opnd, numLists, |
| 3966 |
iterNum, (continueLoop? "continue" : "exit"))); |
| 3967 |
|
| 3968 |
|
| 3969 |
|
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
|
| 3974 |
pc += 5; |
| 3975 |
if (*pc == INST_JUMP_FALSE1) { |
| 3976 |
NEXT_INST_F((continueLoop? 2 : TclGetInt1AtPtr(pc+1)), 0, 0); |
| 3977 |
} else { |
| 3978 |
NEXT_INST_F((continueLoop? 5 : TclGetInt4AtPtr(pc+1)), 0, 0); |
| 3979 |
} |
| 3980 |
} |
| 3981 |
|
| 3982 |
case INST_BEGIN_CATCH4: |
| 3983 |
|
| 3984 |
|
| 3985 |
|
| 3986 |
|
| 3987 |
|
| 3988 |
catchStackPtr[++catchTop] = stackTop; |
| 3989 |
TRACE(("%u => catchTop=%d, stackTop=%d\n", |
| 3990 |
TclGetUInt4AtPtr(pc+1), catchTop, stackTop)); |
| 3991 |
NEXT_INST_F(5, 0, 0); |
| 3992 |
|
| 3993 |
case INST_END_CATCH: |
| 3994 |
catchTop--; |
| 3995 |
result = TCL_OK; |
| 3996 |
TRACE(("=> catchTop=%d\n", catchTop)); |
| 3997 |
NEXT_INST_F(1, 0, 0); |
| 3998 |
|
| 3999 |
case INST_PUSH_RESULT: |
| 4000 |
objResultPtr = Tcl_GetObjResult(interp); |
| 4001 |
TRACE_WITH_OBJ(("=> "), Tcl_GetObjResult(interp)); |
| 4002 |
|
| 4003 |
|
| 4004 |
|
| 4005 |
|
| 4006 |
{ |
| 4007 |
Tcl_Obj *newObjResultPtr; |
| 4008 |
TclNewObj(newObjResultPtr); |
| 4009 |
Tcl_IncrRefCount(newObjResultPtr); |
| 4010 |
iPtr->objResultPtr = newObjResultPtr; |
| 4011 |
} |
| 4012 |
|
| 4013 |
NEXT_INST_F(1, 0, -1); |
| 4014 |
|
| 4015 |
case INST_PUSH_RETURN_CODE: |
| 4016 |
objResultPtr = Tcl_NewLongObj(result); |
| 4017 |
TRACE(("=> %u\n", result)); |
| 4018 |
NEXT_INST_F(1, 0, 1); |
| 4019 |
|
| 4020 |
default: |
| 4021 |
panic("TclExecuteByteCode: unrecognized opCode %u", *pc); |
| 4022 |
} |
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
|
| 4027 |
|
| 4028 |
|
| 4029 |
divideByZero: |
| 4030 |
DECACHE_STACK_INFO(); |
| 4031 |
Tcl_ResetResult(interp); |
| 4032 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), "divide by zero", -1); |
| 4033 |
Tcl_SetErrorCode(interp, "ARITH", "DIVZERO", "divide by zero", |
| 4034 |
(char *) NULL); |
| 4035 |
CACHE_STACK_INFO(); |
| 4036 |
|
| 4037 |
result = TCL_ERROR; |
| 4038 |
goto checkForCatch; |
| 4039 |
|
| 4040 |
|
| 4041 |
|
| 4042 |
|
| 4043 |
|
| 4044 |
|
| 4045 |
|
| 4046 |
processExceptionReturn: |
| 4047 |
#if TCL_COMPILE_DEBUG |
| 4048 |
switch (*pc) { |
| 4049 |
case INST_INVOKE_STK1: |
| 4050 |
case INST_INVOKE_STK4: |
| 4051 |
TRACE(("%u => ... after \"%.20s\": ", opnd, cmdNameBuf)); |
| 4052 |
break; |
| 4053 |
case INST_EVAL_STK: |
| 4054 |
|
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
|
| 4059 |
TRACE(("\"%.30s\" => ", O2S(stackPtr[stackTop]))); |
| 4060 |
break; |
| 4061 |
default: |
| 4062 |
TRACE(("=> ")); |
| 4063 |
} |
| 4064 |
#endif |
| 4065 |
if ((result == TCL_CONTINUE) || (result == TCL_BREAK)) { |
| 4066 |
rangePtr = GetExceptRangeForPc(pc, 0, codePtr); |
| 4067 |
if (rangePtr == NULL) { |
| 4068 |
TRACE_APPEND(("no encl. loop or catch, returning %s\n", |
| 4069 |
StringForResultCode(result))); |
| 4070 |
goto abnormalReturn; |
| 4071 |
} |
| 4072 |
if (rangePtr->type == CATCH_EXCEPTION_RANGE) { |
| 4073 |
TRACE_APPEND(("%s ...\n", StringForResultCode(result))); |
| 4074 |
goto processCatch; |
| 4075 |
} |
| 4076 |
while (cleanup--) { |
| 4077 |
valuePtr = POP_OBJECT(); |
| 4078 |
TclDecrRefCount(valuePtr); |
| 4079 |
} |
| 4080 |
if (result == TCL_BREAK) { |
| 4081 |
result = TCL_OK; |
| 4082 |
pc = (codePtr->codeStart + rangePtr->breakOffset); |
| 4083 |
TRACE_APPEND(("%s, range at %d, new pc %d\n", |
| 4084 |
StringForResultCode(result), |
| 4085 |
rangePtr->codeOffset, rangePtr->breakOffset)); |
| 4086 |
NEXT_INST_F(0, 0, 0); |
| 4087 |
} else { |
| 4088 |
if (rangePtr->continueOffset == -1) { |
| 4089 |
TRACE_APPEND(("%s, loop w/o continue, checking for catch\n", |
| 4090 |
StringForResultCode(result))); |
| 4091 |
goto checkForCatch; |
| 4092 |
} |
| 4093 |
result = TCL_OK; |
| 4094 |
pc = (codePtr->codeStart + rangePtr->continueOffset); |
| 4095 |
TRACE_APPEND(("%s, range at %d, new pc %d\n", |
| 4096 |
StringForResultCode(result), |
| 4097 |
rangePtr->codeOffset, rangePtr->continueOffset)); |
| 4098 |
NEXT_INST_F(0, 0, 0); |
| 4099 |
} |
| 4100 |
#if TCL_COMPILE_DEBUG |
| 4101 |
} else if (traceInstructions) { |
| 4102 |
if ((result != TCL_ERROR) && (result != TCL_RETURN)) { |
| 4103 |
objPtr = Tcl_GetObjResult(interp); |
| 4104 |
TRACE_APPEND(("OTHER RETURN CODE %d, result= \"%s\"\n ", |
| 4105 |
result, O2S(objPtr))); |
| 4106 |
} else { |
| 4107 |
objPtr = Tcl_GetObjResult(interp); |
| 4108 |
TRACE_APPEND(("%s, result= \"%s\"\n", |
| 4109 |
StringForResultCode(result), O2S(objPtr))); |
| 4110 |
} |
| 4111 |
#endif |
| 4112 |
} |
| 4113 |
|
| 4114 |
|
| 4115 |
|
| 4116 |
|
| 4117 |
|
| 4118 |
|
| 4119 |
|
| 4120 |
|
| 4121 |
|
| 4122 |
checkForCatch: |
| 4123 |
if ((result == TCL_ERROR) && !(iPtr->flags & ERR_ALREADY_LOGGED)) { |
| 4124 |
bytes = GetSrcInfoForPc(pc, codePtr, &length); |
| 4125 |
if (bytes != NULL) { |
| 4126 |
DECACHE_STACK_INFO(); |
| 4127 |
Tcl_LogCommandInfo(interp, codePtr->source, bytes, length); |
| 4128 |
CACHE_STACK_INFO(); |
| 4129 |
iPtr->flags |= ERR_ALREADY_LOGGED; |
| 4130 |
} |
| 4131 |
} |
| 4132 |
if (catchTop == -1) { |
| 4133 |
#ifdef TCL_COMPILE_DEBUG |
| 4134 |
if (traceInstructions) { |
| 4135 |
fprintf(stdout, " ... no enclosing catch, returning %s\n", |
| 4136 |
StringForResultCode(result)); |
| 4137 |
} |
| 4138 |
#endif |
| 4139 |
goto abnormalReturn; |
| 4140 |
} |
| 4141 |
rangePtr = GetExceptRangeForPc(pc, 1, codePtr); |
| 4142 |
if (rangePtr == NULL) { |
| 4143 |
|
| 4144 |
|
| 4145 |
|
| 4146 |
|
| 4147 |
|
| 4148 |
#ifdef TCL_COMPILE_DEBUG |
| 4149 |
if (traceInstructions) { |
| 4150 |
fprintf(stdout, " ... no enclosing catch, returning %s\n", |
| 4151 |
StringForResultCode(result)); |
| 4152 |
} |
| 4153 |
#endif |
| 4154 |
goto abnormalReturn; |
| 4155 |
} |
| 4156 |
|
| 4157 |
|
| 4158 |
|
| 4159 |
|
| 4160 |
|
| 4161 |
|
| 4162 |
|
| 4163 |
|
| 4164 |
|
| 4165 |
|
| 4166 |
processCatch: |
| 4167 |
while (stackTop > catchStackPtr[catchTop]) { |
| 4168 |
valuePtr = POP_OBJECT(); |
| 4169 |
TclDecrRefCount(valuePtr); |
| 4170 |
} |
| 4171 |
#ifdef TCL_COMPILE_DEBUG |
| 4172 |
if (traceInstructions) { |
| 4173 |
fprintf(stdout, " ... found catch at %d, catchTop=%d, unwound to %d, new pc %u\n", |
| 4174 |
rangePtr->codeOffset, catchTop, catchStackPtr[catchTop], |
| 4175 |
(unsigned int)(rangePtr->catchOffset)); |
| 4176 |
} |
| 4177 |
#endif |
| 4178 |
pc = (codePtr->codeStart + rangePtr->catchOffset); |
| 4179 |
NEXT_INST_F(0, 0, 0); |
| 4180 |
|
| 4181 |
|
| 4182 |
|
| 4183 |
|
| 4184 |
|
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
|
| 4190 |
abnormalReturn: |
| 4191 |
while (stackTop > initStackTop) { |
| 4192 |
valuePtr = POP_OBJECT(); |
| 4193 |
TclDecrRefCount(valuePtr); |
| 4194 |
} |
| 4195 |
if (stackTop < initStackTop) { |
| 4196 |
fprintf(stderr, "\nTclExecuteByteCode: abnormal return at pc %u: stack top %d < entry stack top %d\n", |
| 4197 |
(unsigned int)(pc - codePtr->codeStart), |
| 4198 |
(unsigned int) stackTop, |
| 4199 |
(unsigned int) initStackTop); |
| 4200 |
panic("TclExecuteByteCode execution failure: end stack top < start stack top"); |
| 4201 |
} |
| 4202 |
|
| 4203 |
|
| 4204 |
|
| 4205 |
|
| 4206 |
|
| 4207 |
if (catchStackPtr != catchStackStorage) { |
| 4208 |
ckfree((char *) catchStackPtr); |
| 4209 |
} |
| 4210 |
eePtr->stackTop = initStackTop; |
| 4211 |
return result; |
| 4212 |
#undef STATIC_CATCH_STACK_SIZE |
| 4213 |
} |
| 4214 |
|
| 4215 |
#ifdef TCL_COMPILE_DEBUG |
| 4216 |
|
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
|
| 4223 |
|
| 4224 |
|
| 4225 |
|
| 4226 |
|
| 4227 |
|
| 4228 |
|
| 4229 |
|
| 4230 |
|
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
static void |
| 4235 |
PrintByteCodeInfo(codePtr) |
| 4236 |
register ByteCode *codePtr; |
| 4237 |
|
| 4238 |
{ |
| 4239 |
Proc *procPtr = codePtr->procPtr; |
| 4240 |
Interp *iPtr = (Interp *) *codePtr->interpHandle; |
| 4241 |
|
| 4242 |
fprintf(stdout, "\nExecuting ByteCode 0x%x, refCt %u, epoch %u, interp 0x%x (epoch %u)\n", |
| 4243 |
(unsigned int) codePtr, codePtr->refCount, |
| 4244 |
codePtr->compileEpoch, (unsigned int) iPtr, |
| 4245 |
iPtr->compileEpoch); |
| 4246 |
|
| 4247 |
fprintf(stdout, " Source: "); |
| 4248 |
TclPrintSource(stdout, codePtr->source, 60); |
| 4249 |
|
| 4250 |
fprintf(stdout, "\n Cmds %d, src %d, inst %u, litObjs %u, aux %d, stkDepth %u, code/src %.2f\n", |
| 4251 |
codePtr->numCommands, codePtr->numSrcBytes, |
| 4252 |
codePtr->numCodeBytes, codePtr->numLitObjects, |
| 4253 |
codePtr->numAuxDataItems, codePtr->maxStackDepth, |
| 4254 |
#ifdef TCL_COMPILE_STATS |
| 4255 |
(codePtr->numSrcBytes? |
| 4256 |
((float)codePtr->structureSize)/((float)codePtr->numSrcBytes) : 0.0)); |
| 4257 |
#else |
| 4258 |
0.0); |
| 4259 |
#endif |
| 4260 |
#ifdef TCL_COMPILE_STATS |
| 4261 |
fprintf(stdout, " Code %d = header %d+inst %d+litObj %d+exc %d+aux %d+cmdMap %d\n", |
| 4262 |
codePtr->structureSize, |
| 4263 |
(sizeof(ByteCode) - (sizeof(size_t) + sizeof(Tcl_Time))), |
| 4264 |
codePtr->numCodeBytes, |
| 4265 |
(codePtr->numLitObjects * sizeof(Tcl_Obj *)), |
| 4266 |
(codePtr->numExceptRanges * sizeof(ExceptionRange)), |
| 4267 |
(codePtr->numAuxDataItems * sizeof(AuxData)), |
| 4268 |
codePtr->numCmdLocBytes); |
| 4269 |
#endif |
| 4270 |
if (procPtr != NULL) { |
| 4271 |
fprintf(stdout, |
| 4272 |
" Proc 0x%x, refCt %d, args %d, compiled locals %d\n", |
| 4273 |
(unsigned int) procPtr, procPtr->refCount, |
| 4274 |
procPtr->numArgs, procPtr->numCompiledLocals); |
| 4275 |
} |
| 4276 |
} |
| 4277 |
#endif |
| 4278 |
|
| 4279 |
|
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
|
| 4284 |
|
| 4285 |
|
| 4286 |
|
| 4287 |
|
| 4288 |
|
| 4289 |
|
| 4290 |
|
| 4291 |
|
| 4292 |
|
| 4293 |
|
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
|
| 4298 |
#ifdef TCL_COMPILE_DEBUG |
| 4299 |
static void |
| 4300 |
ValidatePcAndStackTop(codePtr, pc, stackTop, stackLowerBound) |
| 4301 |
register ByteCode *codePtr; |
| 4302 |
|
| 4303 |
unsigned char *pc; |
| 4304 |
|
| 4305 |
int stackTop; |
| 4306 |
|
| 4307 |
|
| 4308 |
int stackLowerBound; |
| 4309 |
{ |
| 4310 |
int stackUpperBound = stackLowerBound + codePtr->maxStackDepth; |
| 4311 |
|
| 4312 |
unsigned int relativePc = (unsigned int) (pc - codePtr->codeStart); |
| 4313 |
unsigned int codeStart = (unsigned int) codePtr->codeStart; |
| 4314 |
unsigned int codeEnd = (unsigned int) |
| 4315 |
(codePtr->codeStart + codePtr->numCodeBytes); |
| 4316 |
unsigned char opCode = *pc; |
| 4317 |
|
| 4318 |
if (((unsigned int) pc < codeStart) || ((unsigned int) pc > codeEnd)) { |
| 4319 |
fprintf(stderr, "\nBad instruction pc 0x%x in TclExecuteByteCode\n", |
| 4320 |
(unsigned int) pc); |
| 4321 |
panic("TclExecuteByteCode execution failure: bad pc"); |
| 4322 |
} |
| 4323 |
if ((unsigned int) opCode > LAST_INST_OPCODE) { |
| 4324 |
fprintf(stderr, "\nBad opcode %d at pc %u in TclExecuteByteCode\n", |
| 4325 |
(unsigned int) opCode, relativePc); |
| 4326 |
panic("TclExecuteByteCode execution failure: bad opcode"); |
| 4327 |
} |
| 4328 |
if ((stackTop < stackLowerBound) || (stackTop > stackUpperBound)) { |
| 4329 |
int numChars; |
| 4330 |
char *cmd = GetSrcInfoForPc(pc, codePtr, &numChars); |
| 4331 |
char *ellipsis = ""; |
| 4332 |
|
| 4333 |
fprintf(stderr, "\nBad stack top %d at pc %u in TclExecuteByteCode (min %i, max %i)", |
| 4334 |
stackTop, relativePc, stackLowerBound, stackUpperBound); |
| 4335 |
if (cmd != NULL) { |
| 4336 |
if (numChars > 100) { |
| 4337 |
numChars = 100; |
| 4338 |
ellipsis = "..."; |
| 4339 |
} |
| 4340 |
fprintf(stderr, "\n executing %.*s%s\n", numChars, cmd, |
| 4341 |
ellipsis); |
| 4342 |
} else { |
| 4343 |
fprintf(stderr, "\n"); |
| 4344 |
} |
| 4345 |
panic("TclExecuteByteCode execution failure: bad stack top"); |
| 4346 |
} |
| 4347 |
} |
| 4348 |
#endif |
| 4349 |
|
| 4350 |
|
| 4351 |
|
| 4352 |
|
| 4353 |
|
| 4354 |
|
| 4355 |
|
| 4356 |
|
| 4357 |
|
| 4358 |
|
| 4359 |
|
| 4360 |
|
| 4361 |
|
| 4362 |
|
| 4363 |
|
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
static void |
| 4369 |
IllegalExprOperandType(interp, pc, opndPtr) |
| 4370 |
Tcl_Interp *interp; |
| 4371 |
|
| 4372 |
unsigned char *pc; |
| 4373 |
|
| 4374 |
Tcl_Obj *opndPtr; |
| 4375 |
|
| 4376 |
{ |
| 4377 |
unsigned char opCode = *pc; |
| 4378 |
|
| 4379 |
Tcl_ResetResult(interp); |
| 4380 |
if ((opndPtr->bytes == NULL) || (opndPtr->length == 0)) { |
| 4381 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 4382 |
"can't use empty string as operand of \"", |
| 4383 |
operatorStrings[opCode - INST_LOR], "\"", (char *) NULL); |
| 4384 |
} else { |
| 4385 |
char *msg = "non-numeric string"; |
| 4386 |
char *s, *p; |
| 4387 |
int length; |
| 4388 |
int looksLikeInt = 0; |
| 4389 |
|
| 4390 |
s = Tcl_GetStringFromObj(opndPtr, &length); |
| 4391 |
p = s; |
| 4392 |
|
| 4393 |
|
| 4394 |
|
| 4395 |
|
| 4396 |
if (length == 3) { |
| 4397 |
if ((s[0]=='n' || s[0]=='N') && (s[1]=='a' || s[1]=='A') && |
| 4398 |
(s[2]=='n' || s[2]=='N')) { |
| 4399 |
msg = "non-numeric floating-point value"; |
| 4400 |
goto makeErrorMessage; |
| 4401 |
} |
| 4402 |
if ((s[0]=='i' || s[0]=='I') && (s[1]=='n' || s[1]=='N') && |
| 4403 |
(s[2]=='f' || s[2]=='F')) { |
| 4404 |
msg = "infinite floating-point value"; |
| 4405 |
goto makeErrorMessage; |
| 4406 |
} |
| 4407 |
} |
| 4408 |
|
| 4409 |
|
| 4410 |
|
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
|
| 4415 |
|
| 4416 |
while (length && isspace(UCHAR(*p))) { |
| 4417 |
length--; |
| 4418 |
p++; |
| 4419 |
} |
| 4420 |
if (length && ((*p == '+') || (*p == '-'))) { |
| 4421 |
length--; |
| 4422 |
p++; |
| 4423 |
} |
| 4424 |
if (length) { |
| 4425 |
if ((*p == '0') && ((*(p+1) == 'x') || (*(p+1) == 'X'))) { |
| 4426 |
p += 2; |
| 4427 |
length -= 2; |
| 4428 |
looksLikeInt = ((length > 0) && isxdigit(UCHAR(*p))); |
| 4429 |
if (looksLikeInt) { |
| 4430 |
length--; |
| 4431 |
p++; |
| 4432 |
while (length && isxdigit(UCHAR(*p))) { |
| 4433 |
length--; |
| 4434 |
p++; |
| 4435 |
} |
| 4436 |
} |
| 4437 |
} else { |
| 4438 |
looksLikeInt = (length && isdigit(UCHAR(*p))); |
| 4439 |
if (looksLikeInt) { |
| 4440 |
length--; |
| 4441 |
p++; |
| 4442 |
while (length && isdigit(UCHAR(*p))) { |
| 4443 |
length--; |
| 4444 |
p++; |
| 4445 |
} |
| 4446 |
} |
| 4447 |
} |
| 4448 |
while (length && isspace(UCHAR(*p))) { |
| 4449 |
length--; |
| 4450 |
p++; |
| 4451 |
} |
| 4452 |
looksLikeInt = !length; |
| 4453 |
} |
| 4454 |
if (looksLikeInt) { |
| 4455 |
|
| 4456 |
|
| 4457 |
|
| 4458 |
|
| 4459 |
|
| 4460 |
|
| 4461 |
if (TclCheckBadOctal(NULL, s)) { |
| 4462 |
msg = "invalid octal number"; |
| 4463 |
} else { |
| 4464 |
msg = "integer value too large to represent"; |
| 4465 |
Tcl_SetErrorCode(interp, "ARITH", "IOVERFLOW", |
| 4466 |
"integer value too large to represent", (char *) NULL); |
| 4467 |
} |
| 4468 |
} else { |
| 4469 |
|
| 4470 |
|
| 4471 |
|
| 4472 |
|
| 4473 |
|
| 4474 |
double d; |
| 4475 |
|
| 4476 |
if (Tcl_GetDouble((Tcl_Interp *) NULL, s, &d) == TCL_OK) { |
| 4477 |
msg = "floating-point value"; |
| 4478 |
} |
| 4479 |
} |
| 4480 |
makeErrorMessage: |
| 4481 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "can't use ", |
| 4482 |
msg, " as operand of \"", operatorStrings[opCode - INST_LOR], |
| 4483 |
"\"", (char *) NULL); |
| 4484 |
} |
| 4485 |
} |
| 4486 |
|
| 4487 |
|
| 4488 |
|
| 4489 |
|
| 4490 |
|
| 4491 |
|
| 4492 |
|
| 4493 |
|
| 4494 |
|
| 4495 |
|
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
|
| 4501 |
|
| 4502 |
|
| 4503 |
|
| 4504 |
|
| 4505 |
|
| 4506 |
|
| 4507 |
|
| 4508 |
|
| 4509 |
|
| 4510 |
|
| 4511 |
static char * |
| 4512 |
GetSrcInfoForPc(pc, codePtr, lengthPtr) |
| 4513 |
unsigned char *pc; |
| 4514 |
|
| 4515 |
|
| 4516 |
|
| 4517 |
ByteCode *codePtr; |
| 4518 |
|
| 4519 |
int *lengthPtr; |
| 4520 |
|
| 4521 |
|
| 4522 |
{ |
| 4523 |
register int pcOffset = (pc - codePtr->codeStart); |
| 4524 |
int numCmds = codePtr->numCommands; |
| 4525 |
unsigned char *codeDeltaNext, *codeLengthNext; |
| 4526 |
unsigned char *srcDeltaNext, *srcLengthNext; |
| 4527 |
int codeOffset, codeLen, codeEnd, srcOffset, srcLen, delta, i; |
| 4528 |
int bestDist = INT_MAX; |
| 4529 |
int bestSrcOffset = -1; |
| 4530 |
int bestSrcLength = -1; |
| 4531 |
|
| 4532 |
if ((pcOffset < 0) || (pcOffset >= codePtr->numCodeBytes)) { |
| 4533 |
return NULL; |
| 4534 |
} |
| 4535 |
|
| 4536 |
|
| 4537 |
|
| 4538 |
|
| 4539 |
|
| 4540 |
|
| 4541 |
|
| 4542 |
codeDeltaNext = codePtr->codeDeltaStart; |
| 4543 |
codeLengthNext = codePtr->codeLengthStart; |
| 4544 |
srcDeltaNext = codePtr->srcDeltaStart; |
| 4545 |
srcLengthNext = codePtr->srcLengthStart; |
| 4546 |
codeOffset = srcOffset = 0; |
| 4547 |
for (i = 0; i < numCmds; i++) { |
| 4548 |
if ((unsigned int) (*codeDeltaNext) == (unsigned int) 0xFF) { |
| 4549 |
codeDeltaNext++; |
| 4550 |
delta = TclGetInt4AtPtr(codeDeltaNext); |
| 4551 |
codeDeltaNext += 4; |
| 4552 |
} else { |
| 4553 |
delta = TclGetInt1AtPtr(codeDeltaNext); |
| 4554 |
codeDeltaNext++; |
| 4555 |
} |
| 4556 |
codeOffset += delta; |
| 4557 |
|
| 4558 |
if ((unsigned int) (*codeLengthNext) == (unsigned int) 0xFF) { |
| 4559 |
codeLengthNext++; |
| 4560 |
codeLen = TclGetInt4AtPtr(codeLengthNext); |
| 4561 |
codeLengthNext += 4; |
| 4562 |
} else { |
| 4563 |
codeLen = TclGetInt1AtPtr(codeLengthNext); |
| 4564 |
codeLengthNext++; |
| 4565 |
} |
| 4566 |
codeEnd = (codeOffset + codeLen - 1); |
| 4567 |
|
| 4568 |
if ((unsigned int) (*srcDeltaNext) == (unsigned int) 0xFF) { |
| 4569 |
srcDeltaNext++; |
| 4570 |
delta = TclGetInt4AtPtr(srcDeltaNext); |
| 4571 |
srcDeltaNext += 4; |
| 4572 |
} else { |
| 4573 |
delta = TclGetInt1AtPtr(srcDeltaNext); |
| 4574 |
srcDeltaNext++; |
| 4575 |
} |
| 4576 |
srcOffset += delta; |
| 4577 |
|
| 4578 |
if ((unsigned int) (*srcLengthNext) == (unsigned int) 0xFF) { |
| 4579 |
srcLengthNext++; |
| 4580 |
srcLen = TclGetInt4AtPtr(srcLengthNext); |
| 4581 |
srcLengthNext += 4; |
| 4582 |
} else { |
| 4583 |
srcLen = TclGetInt1AtPtr(srcLengthNext); |
| 4584 |
srcLengthNext++; |
| 4585 |
} |
| 4586 |
|
| 4587 |
if (codeOffset > pcOffset) { |
| 4588 |
break; |
| 4589 |
} else if (pcOffset <= codeEnd) { |
| 4590 |
int dist = (pcOffset - codeOffset); |
| 4591 |
if (dist <= bestDist) { |
| 4592 |
bestDist = dist; |
| 4593 |
bestSrcOffset = srcOffset; |
| 4594 |
bestSrcLength = srcLen; |
| 4595 |
} |
| 4596 |
} |
| 4597 |
} |
| 4598 |
|
| 4599 |
if (bestDist == INT_MAX) { |
| 4600 |
return NULL; |
| 4601 |
} |
| 4602 |
|
| 4603 |
if (lengthPtr != NULL) { |
| 4604 |
*lengthPtr = bestSrcLength; |
| 4605 |
} |
| 4606 |
return (codePtr->source + bestSrcOffset); |
| 4607 |
} |
| 4608 |
|
| 4609 |
|
| 4610 |
|
| 4611 |
|
| 4612 |
|
| 4613 |
|
| 4614 |
|
| 4615 |
|
| 4616 |
|
| 4617 |
|
| 4618 |
|
| 4619 |
|
| 4620 |
|
| 4621 |
|
| 4622 |
|
| 4623 |
|
| 4624 |
|
| 4625 |
|
| 4626 |
|
| 4627 |
|
| 4628 |
|
| 4629 |
|
| 4630 |
|
| 4631 |
|
| 4632 |
|
| 4633 |
|
| 4634 |
static ExceptionRange * |
| 4635 |
GetExceptRangeForPc(pc, catchOnly, codePtr) |
| 4636 |
unsigned char *pc; |
| 4637 |
|
| 4638 |
|
| 4639 |
|
| 4640 |
int catchOnly; |
| 4641 |
|
| 4642 |
|
| 4643 |
|
| 4644 |
ByteCode* codePtr; |
| 4645 |
|
| 4646 |
{ |
| 4647 |
ExceptionRange *rangeArrayPtr; |
| 4648 |
int numRanges = codePtr->numExceptRanges; |
| 4649 |
register ExceptionRange *rangePtr; |
| 4650 |
int pcOffset = (pc - codePtr->codeStart); |
| 4651 |
register int start; |
| 4652 |
|
| 4653 |
if (numRanges == 0) { |
| 4654 |
return NULL; |
| 4655 |
} |
| 4656 |
|
| 4657 |
|
| 4658 |
|
| 4659 |
|
| 4660 |
|
| 4661 |
|
| 4662 |
|
| 4663 |
|
| 4664 |
rangeArrayPtr = codePtr->exceptArrayPtr; |
| 4665 |
rangePtr = rangeArrayPtr + numRanges; |
| 4666 |
while (--rangePtr >= rangeArrayPtr) { |
| 4667 |
start = rangePtr->codeOffset; |
| 4668 |
if ((start <= pcOffset) && |
| 4669 |
(pcOffset < (start + rangePtr->numCodeBytes))) { |
| 4670 |
if ((!catchOnly) |
| 4671 |
|| (rangePtr->type == CATCH_EXCEPTION_RANGE)) { |
| 4672 |
return rangePtr; |
| 4673 |
} |
| 4674 |
} |
| 4675 |
} |
| 4676 |
return NULL; |
| 4677 |
} |
| 4678 |
|
| 4679 |
|
| 4680 |
|
| 4681 |
|
| 4682 |
|
| 4683 |
|
| 4684 |
|
| 4685 |
|
| 4686 |
|
| 4687 |
|
| 4688 |
|
| 4689 |
|
| 4690 |
|
| 4691 |
|
| 4692 |
|
| 4693 |
|
| 4694 |
|
| 4695 |
|
| 4696 |
|
| 4697 |
#ifdef TCL_COMPILE_DEBUG |
| 4698 |
static char * |
| 4699 |
GetOpcodeName(pc) |
| 4700 |
unsigned char *pc; |
| 4701 |
|
| 4702 |
{ |
| 4703 |
unsigned char opCode = *pc; |
| 4704 |
|
| 4705 |
return tclInstructionTable[opCode].name; |
| 4706 |
} |
| 4707 |
#endif |
| 4708 |
|
| 4709 |
|
| 4710 |
|
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
|
| 4716 |
|
| 4717 |
|
| 4718 |
|
| 4719 |
|
| 4720 |
|
| 4721 |
|
| 4722 |
|
| 4723 |
|
| 4724 |
|
| 4725 |
|
| 4726 |
|
| 4727 |
|
| 4728 |
|
| 4729 |
static int |
| 4730 |
VerifyExprObjType(interp, objPtr) |
| 4731 |
Tcl_Interp *interp; |
| 4732 |
|
| 4733 |
Tcl_Obj *objPtr; |
| 4734 |
{ |
| 4735 |
if (IS_NUMERIC_TYPE(objPtr->typePtr)) { |
| 4736 |
return TCL_OK; |
| 4737 |
} else { |
| 4738 |
int length, result = TCL_OK; |
| 4739 |
char *s = Tcl_GetStringFromObj(objPtr, &length); |
| 4740 |
|
| 4741 |
if (TclLooksLikeInt(s, length)) { |
| 4742 |
Tcl_WideInt w; |
| 4743 |
result = Tcl_GetWideIntFromObj((Tcl_Interp *) NULL, objPtr, &w); |
| 4744 |
} else { |
| 4745 |
double d; |
| 4746 |
result = Tcl_GetDoubleFromObj((Tcl_Interp *) NULL, objPtr, &d); |
| 4747 |
} |
| 4748 |
if ((result != TCL_OK) && (interp != NULL)) { |
| 4749 |
Tcl_ResetResult(interp); |
| 4750 |
if (TclCheckBadOctal((Tcl_Interp *) NULL, s)) { |
| 4751 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 4752 |
"argument to math function was an invalid octal number", |
| 4753 |
-1); |
| 4754 |
} else { |
| 4755 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 4756 |
"argument to math function didn't have numeric value", |
| 4757 |
-1); |
| 4758 |
} |
| 4759 |
} |
| 4760 |
return result; |
| 4761 |
} |
| 4762 |
} |
| 4763 |
|
| 4764 |
|
| 4765 |
|
| 4766 |
|
| 4767 |
|
| 4768 |
|
| 4769 |
|
| 4770 |
|
| 4771 |
|
| 4772 |
|
| 4773 |
|
| 4774 |
|
| 4775 |
|
| 4776 |
|
| 4777 |
|
| 4778 |
|
| 4779 |
|
| 4780 |
|
| 4781 |
|
| 4782 |
|
| 4783 |
static int |
| 4784 |
ExprUnaryFunc(interp, eePtr, clientData) |
| 4785 |
Tcl_Interp *interp; |
| 4786 |
|
| 4787 |
ExecEnv *eePtr; |
| 4788 |
|
| 4789 |
ClientData clientData; |
| 4790 |
|
| 4791 |
|
| 4792 |
{ |
| 4793 |
Tcl_Obj **stackPtr; |
| 4794 |
register int stackTop; |
| 4795 |
register Tcl_Obj *valuePtr; |
| 4796 |
double d, dResult; |
| 4797 |
int result; |
| 4798 |
|
| 4799 |
double (*func) _ANSI_ARGS_((double)) = |
| 4800 |
(double (*)_ANSI_ARGS_((double))) clientData; |
| 4801 |
|
| 4802 |
|
| 4803 |
|
| 4804 |
|
| 4805 |
|
| 4806 |
result = TCL_OK; |
| 4807 |
CACHE_STACK_INFO(); |
| 4808 |
|
| 4809 |
|
| 4810 |
|
| 4811 |
|
| 4812 |
|
| 4813 |
|
| 4814 |
valuePtr = POP_OBJECT(); |
| 4815 |
|
| 4816 |
if (VerifyExprObjType(interp, valuePtr) != TCL_OK) { |
| 4817 |
result = TCL_ERROR; |
| 4818 |
goto done; |
| 4819 |
} |
| 4820 |
|
| 4821 |
GET_DOUBLE_VALUE(d, valuePtr, valuePtr->typePtr); |
| 4822 |
|
| 4823 |
errno = 0; |
| 4824 |
dResult = (*func)(d); |
| 4825 |
if ((errno != 0) || IS_NAN(dResult) || IS_INF(dResult)) { |
| 4826 |
TclExprFloatError(interp, dResult); |
| 4827 |
result = TCL_ERROR; |
| 4828 |
goto done; |
| 4829 |
} |
| 4830 |
|
| 4831 |
|
| 4832 |
|
| 4833 |
|
| 4834 |
|
| 4835 |
PUSH_OBJECT(Tcl_NewDoubleObj(dResult)); |
| 4836 |
|
| 4837 |
|
| 4838 |
|
| 4839 |
|
| 4840 |
|
| 4841 |
done: |
| 4842 |
TclDecrRefCount(valuePtr); |
| 4843 |
DECACHE_STACK_INFO(); |
| 4844 |
return result; |
| 4845 |
} |
| 4846 |
|
| 4847 |
static int |
| 4848 |
ExprBinaryFunc(interp, eePtr, clientData) |
| 4849 |
Tcl_Interp *interp; |
| 4850 |
|
| 4851 |
ExecEnv *eePtr; |
| 4852 |
|
| 4853 |
ClientData clientData; |
| 4854 |
|
| 4855 |
|
| 4856 |
{ |
| 4857 |
Tcl_Obj **stackPtr; |
| 4858 |
register int stackTop; |
| 4859 |
register Tcl_Obj *valuePtr, *value2Ptr; |
| 4860 |
double d1, d2, dResult; |
| 4861 |
int result; |
| 4862 |
|
| 4863 |
double (*func) _ANSI_ARGS_((double, double)) |
| 4864 |
= (double (*)_ANSI_ARGS_((double, double))) clientData; |
| 4865 |
|
| 4866 |
|
| 4867 |
|
| 4868 |
|
| 4869 |
|
| 4870 |
result = TCL_OK; |
| 4871 |
CACHE_STACK_INFO(); |
| 4872 |
|
| 4873 |
|
| 4874 |
|
| 4875 |
|
| 4876 |
|
| 4877 |
|
| 4878 |
value2Ptr = POP_OBJECT(); |
| 4879 |
valuePtr = POP_OBJECT(); |
| 4880 |
|
| 4881 |
if ((VerifyExprObjType(interp, valuePtr) != TCL_OK) || |
| 4882 |
(VerifyExprObjType(interp, value2Ptr) != TCL_OK)) { |
| 4883 |
result = TCL_ERROR; |
| 4884 |
goto done; |
| 4885 |
} |
| 4886 |
|
| 4887 |
GET_DOUBLE_VALUE(d1, valuePtr, valuePtr->typePtr); |
| 4888 |
GET_DOUBLE_VALUE(d2, value2Ptr, value2Ptr->typePtr); |
| 4889 |
|
| 4890 |
errno = 0; |
| 4891 |
dResult = (*func)(d1, d2); |
| 4892 |
if ((errno != 0) || IS_NAN(dResult) || IS_INF(dResult)) { |
| 4893 |
TclExprFloatError(interp, dResult); |
| 4894 |
result = TCL_ERROR; |
| 4895 |
goto done; |
| 4896 |
} |
| 4897 |
|
| 4898 |
|
| 4899 |
|
| 4900 |
|
| 4901 |
|
| 4902 |
PUSH_OBJECT(Tcl_NewDoubleObj(dResult)); |
| 4903 |
|
| 4904 |
|
| 4905 |
|
| 4906 |
|
| 4907 |
|
| 4908 |
done: |
| 4909 |
TclDecrRefCount(valuePtr); |
| 4910 |
TclDecrRefCount(value2Ptr); |
| 4911 |
DECACHE_STACK_INFO(); |
| 4912 |
return result; |
| 4913 |
} |
| 4914 |
|
| 4915 |
static int |
| 4916 |
ExprAbsFunc(interp, eePtr, clientData) |
| 4917 |
Tcl_Interp *interp; |
| 4918 |
|
| 4919 |
ExecEnv *eePtr; |
| 4920 |
|
| 4921 |
ClientData clientData; |
| 4922 |
{ |
| 4923 |
Tcl_Obj **stackPtr; |
| 4924 |
register int stackTop; |
| 4925 |
register Tcl_Obj *valuePtr; |
| 4926 |
long i, iResult; |
| 4927 |
double d, dResult; |
| 4928 |
int result; |
| 4929 |
|
| 4930 |
|
| 4931 |
|
| 4932 |
|
| 4933 |
|
| 4934 |
result = TCL_OK; |
| 4935 |
CACHE_STACK_INFO(); |
| 4936 |
|
| 4937 |
|
| 4938 |
|
| 4939 |
|
| 4940 |
|
| 4941 |
valuePtr = POP_OBJECT(); |
| 4942 |
|
| 4943 |
if (VerifyExprObjType(interp, valuePtr) != TCL_OK) { |
| 4944 |
result = TCL_ERROR; |
| 4945 |
goto done; |
| 4946 |
} |
| 4947 |
|
| 4948 |
|
| 4949 |
|
| 4950 |
|
| 4951 |
if (valuePtr->typePtr == &tclIntType) { |
| 4952 |
i = valuePtr->internalRep.longValue; |
| 4953 |
if (i < 0) { |
| 4954 |
iResult = -i; |
| 4955 |
if (iResult < 0) { |
| 4956 |
Tcl_ResetResult(interp); |
| 4957 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 4958 |
"integer value too large to represent", -1); |
| 4959 |
Tcl_SetErrorCode(interp, "ARITH", "IOVERFLOW", |
| 4960 |
"integer value too large to represent", (char *) NULL); |
| 4961 |
result = TCL_ERROR; |
| 4962 |
goto done; |
| 4963 |
} |
| 4964 |
} else { |
| 4965 |
iResult = i; |
| 4966 |
} |
| 4967 |
PUSH_OBJECT(Tcl_NewLongObj(iResult)); |
| 4968 |
} else if (valuePtr->typePtr == &tclWideIntType) { |
| 4969 |
Tcl_WideInt wResult, w; |
| 4970 |
TclGetWide(w,valuePtr); |
| 4971 |
if (w < W0) { |
| 4972 |
wResult = -w; |
| 4973 |
if (wResult < 0) { |
| 4974 |
Tcl_ResetResult(interp); |
| 4975 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 4976 |
"integer value too large to represent", -1); |
| 4977 |
Tcl_SetErrorCode(interp, "ARITH", "IOVERFLOW", |
| 4978 |
"integer value too large to represent", (char *) NULL); |
| 4979 |
result = TCL_ERROR; |
| 4980 |
goto done; |
| 4981 |
} |
| 4982 |
} else { |
| 4983 |
wResult = w; |
| 4984 |
} |
| 4985 |
PUSH_OBJECT(Tcl_NewWideIntObj(wResult)); |
| 4986 |
} else { |
| 4987 |
d = valuePtr->internalRep.doubleValue; |
| 4988 |
if (d < 0.0) { |
| 4989 |
dResult = -d; |
| 4990 |
} else { |
| 4991 |
dResult = d; |
| 4992 |
} |
| 4993 |
if (IS_NAN(dResult) || IS_INF(dResult)) { |
| 4994 |
TclExprFloatError(interp, dResult); |
| 4995 |
result = TCL_ERROR; |
| 4996 |
goto done; |
| 4997 |
} |
| 4998 |
PUSH_OBJECT(Tcl_NewDoubleObj(dResult)); |
| 4999 |
} |
| 5000 |
|
| 5001 |
|
| 5002 |
|
| 5003 |
|
| 5004 |
|
| 5005 |
done: |
| 5006 |
TclDecrRefCount(valuePtr); |
| 5007 |
DECACHE_STACK_INFO(); |
| 5008 |
return result; |
| 5009 |
} |
| 5010 |
|
| 5011 |
static int |
| 5012 |
ExprDoubleFunc(interp, eePtr, clientData) |
| 5013 |
Tcl_Interp *interp; |
| 5014 |
|
| 5015 |
ExecEnv *eePtr; |
| 5016 |
|
| 5017 |
ClientData clientData; |
| 5018 |
{ |
| 5019 |
Tcl_Obj **stackPtr; |
| 5020 |
register int stackTop; |
| 5021 |
register Tcl_Obj *valuePtr; |
| 5022 |
double dResult; |
| 5023 |
int result; |
| 5024 |
|
| 5025 |
|
| 5026 |
|
| 5027 |
|
| 5028 |
|
| 5029 |
result = TCL_OK; |
| 5030 |
CACHE_STACK_INFO(); |
| 5031 |
|
| 5032 |
|
| 5033 |
|
| 5034 |
|
| 5035 |
|
| 5036 |
valuePtr = POP_OBJECT(); |
| 5037 |
|
| 5038 |
if (VerifyExprObjType(interp, valuePtr) != TCL_OK) { |
| 5039 |
result = TCL_ERROR; |
| 5040 |
goto done; |
| 5041 |
} |
| 5042 |
|
| 5043 |
GET_DOUBLE_VALUE(dResult, valuePtr, valuePtr->typePtr); |
| 5044 |
|
| 5045 |
|
| 5046 |
|
| 5047 |
|
| 5048 |
|
| 5049 |
PUSH_OBJECT(Tcl_NewDoubleObj(dResult)); |
| 5050 |
|
| 5051 |
|
| 5052 |
|
| 5053 |
|
| 5054 |
|
| 5055 |
done: |
| 5056 |
TclDecrRefCount(valuePtr); |
| 5057 |
DECACHE_STACK_INFO(); |
| 5058 |
return result; |
| 5059 |
} |
| 5060 |
|
| 5061 |
static int |
| 5062 |
ExprIntFunc(interp, eePtr, clientData) |
| 5063 |
Tcl_Interp *interp; |
| 5064 |
|
| 5065 |
ExecEnv *eePtr; |
| 5066 |
|
| 5067 |
ClientData clientData; |
| 5068 |
{ |
| 5069 |
Tcl_Obj **stackPtr; |
| 5070 |
register int stackTop; |
| 5071 |
register Tcl_Obj *valuePtr; |
| 5072 |
long iResult; |
| 5073 |
double d; |
| 5074 |
int result; |
| 5075 |
|
| 5076 |
|
| 5077 |
|
| 5078 |
|
| 5079 |
|
| 5080 |
result = TCL_OK; |
| 5081 |
CACHE_STACK_INFO(); |
| 5082 |
|
| 5083 |
|
| 5084 |
|
| 5085 |
|
| 5086 |
|
| 5087 |
valuePtr = POP_OBJECT(); |
| 5088 |
|
| 5089 |
if (VerifyExprObjType(interp, valuePtr) != TCL_OK) { |
| 5090 |
result = TCL_ERROR; |
| 5091 |
goto done; |
| 5092 |
} |
| 5093 |
|
| 5094 |
if (valuePtr->typePtr == &tclIntType) { |
| 5095 |
iResult = valuePtr->internalRep.longValue; |
| 5096 |
} else if (valuePtr->typePtr == &tclWideIntType) { |
| 5097 |
TclGetLongFromWide(iResult,valuePtr); |
| 5098 |
} else { |
| 5099 |
d = valuePtr->internalRep.doubleValue; |
| 5100 |
if (d < 0.0) { |
| 5101 |
if (d < (double) (long) LONG_MIN) { |
| 5102 |
tooLarge: |
| 5103 |
Tcl_ResetResult(interp); |
| 5104 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 5105 |
"integer value too large to represent", -1); |
| 5106 |
Tcl_SetErrorCode(interp, "ARITH", "IOVERFLOW", |
| 5107 |
"integer value too large to represent", (char *) NULL); |
| 5108 |
result = TCL_ERROR; |
| 5109 |
goto done; |
| 5110 |
} |
| 5111 |
} else { |
| 5112 |
if (d > (double) LONG_MAX) { |
| 5113 |
goto tooLarge; |
| 5114 |
} |
| 5115 |
} |
| 5116 |
if (IS_NAN(d) || IS_INF(d)) { |
| 5117 |
TclExprFloatError(interp, d); |
| 5118 |
result = TCL_ERROR; |
| 5119 |
goto done; |
| 5120 |
} |
| 5121 |
iResult = (long) d; |
| 5122 |
} |
| 5123 |
|
| 5124 |
|
| 5125 |
|
| 5126 |
|
| 5127 |
|
| 5128 |
PUSH_OBJECT(Tcl_NewLongObj(iResult)); |
| 5129 |
|
| 5130 |
|
| 5131 |
|
| 5132 |
|
| 5133 |
|
| 5134 |
done: |
| 5135 |
TclDecrRefCount(valuePtr); |
| 5136 |
DECACHE_STACK_INFO(); |
| 5137 |
return result; |
| 5138 |
} |
| 5139 |
|
| 5140 |
static int |
| 5141 |
ExprWideFunc(interp, eePtr, clientData) |
| 5142 |
Tcl_Interp *interp; |
| 5143 |
|
| 5144 |
ExecEnv *eePtr; |
| 5145 |
|
| 5146 |
ClientData clientData; |
| 5147 |
{ |
| 5148 |
Tcl_Obj **stackPtr; |
| 5149 |
register int stackTop; |
| 5150 |
register Tcl_Obj *valuePtr; |
| 5151 |
Tcl_WideInt wResult; |
| 5152 |
double d; |
| 5153 |
int result; |
| 5154 |
|
| 5155 |
|
| 5156 |
|
| 5157 |
|
| 5158 |
|
| 5159 |
result = TCL_OK; |
| 5160 |
CACHE_STACK_INFO(); |
| 5161 |
|
| 5162 |
|
| 5163 |
|
| 5164 |
|
| 5165 |
|
| 5166 |
valuePtr = POP_OBJECT(); |
| 5167 |
|
| 5168 |
if (VerifyExprObjType(interp, valuePtr) != TCL_OK) { |
| 5169 |
result = TCL_ERROR; |
| 5170 |
goto done; |
| 5171 |
} |
| 5172 |
|
| 5173 |
if (valuePtr->typePtr == &tclWideIntType) { |
| 5174 |
TclGetWide(wResult,valuePtr); |
| 5175 |
} else if (valuePtr->typePtr == &tclIntType) { |
| 5176 |
wResult = Tcl_LongAsWide(valuePtr->internalRep.longValue); |
| 5177 |
} else { |
| 5178 |
d = valuePtr->internalRep.doubleValue; |
| 5179 |
if (d < 0.0) { |
| 5180 |
if (d < Tcl_WideAsDouble(LLONG_MIN)) { |
| 5181 |
tooLarge: |
| 5182 |
Tcl_ResetResult(interp); |
| 5183 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 5184 |
"integer value too large to represent", -1); |
| 5185 |
Tcl_SetErrorCode(interp, "ARITH", "IOVERFLOW", |
| 5186 |
"integer value too large to represent", (char *) NULL); |
| 5187 |
result = TCL_ERROR; |
| 5188 |
goto done; |
| 5189 |
} |
| 5190 |
} else { |
| 5191 |
if (d > Tcl_WideAsDouble(LLONG_MAX)) { |
| 5192 |
goto tooLarge; |
| 5193 |
} |
| 5194 |
} |
| 5195 |
if (IS_NAN(d) || IS_INF(d)) { |
| 5196 |
TclExprFloatError(interp, d); |
| 5197 |
result = TCL_ERROR; |
| 5198 |
goto done; |
| 5199 |
} |
| 5200 |
wResult = Tcl_DoubleAsWide(d); |
| 5201 |
} |
| 5202 |
|
| 5203 |
|
| 5204 |
|
| 5205 |
|
| 5206 |
|
| 5207 |
PUSH_OBJECT(Tcl_NewWideIntObj(wResult)); |
| 5208 |
|
| 5209 |
|
| 5210 |
|
| 5211 |
|
| 5212 |
|
| 5213 |
done: |
| 5214 |
TclDecrRefCount(valuePtr); |
| 5215 |
DECACHE_STACK_INFO(); |
| 5216 |
return result; |
| 5217 |
} |
| 5218 |
|
| 5219 |
static int |
| 5220 |
ExprRandFunc(interp, eePtr, clientData) |
| 5221 |
Tcl_Interp *interp; |
| 5222 |
|
| 5223 |
ExecEnv *eePtr; |
| 5224 |
|
| 5225 |
ClientData clientData; |
| 5226 |
{ |
| 5227 |
Tcl_Obj **stackPtr; |
| 5228 |
register int stackTop; |
| 5229 |
Interp *iPtr = (Interp *) interp; |
| 5230 |
double dResult; |
| 5231 |
long tmp; |
| 5232 |
|
| 5233 |
|
| 5234 |
if (!(iPtr->flags & RAND_SEED_INITIALIZED)) { |
| 5235 |
iPtr->flags |= RAND_SEED_INITIALIZED; |
| 5236 |
|
| 5237 |
|
| 5238 |
|
| 5239 |
|
| 5240 |
|
| 5241 |
|
| 5242 |
iPtr->randSeed = TclpGetClicks() + ((long)Tcl_GetCurrentThread()<<12); |
| 5243 |
|
| 5244 |
|
| 5245 |
|
| 5246 |
|
| 5247 |
|
| 5248 |
iPtr->randSeed &= (unsigned long) 0x7fffffff; |
| 5249 |
if ((iPtr->randSeed == 0) || (iPtr->randSeed == 0x7fffffff)) { |
| 5250 |
iPtr->randSeed ^= 123459876; |
| 5251 |
} |
| 5252 |
} |
| 5253 |
|
| 5254 |
|
| 5255 |
|
| 5256 |
|
| 5257 |
|
| 5258 |
CACHE_STACK_INFO(); |
| 5259 |
|
| 5260 |
|
| 5261 |
|
| 5262 |
|
| 5263 |
|
| 5264 |
|
| 5265 |
|
| 5266 |
|
| 5267 |
|
| 5268 |
|
| 5269 |
|
| 5270 |
|
| 5271 |
|
| 5272 |
|
| 5273 |
|
| 5274 |
|
| 5275 |
|
| 5276 |
|
| 5277 |
|
| 5278 |
|
| 5279 |
|
| 5280 |
|
| 5281 |
|
| 5282 |
|
| 5283 |
|
| 5284 |
|
| 5285 |
|
| 5286 |
|
| 5287 |
#define RAND_IA 16807 |
| 5288 |
#define RAND_IM 2147483647 |
| 5289 |
#define RAND_IQ 127773 |
| 5290 |
#define RAND_IR 2836 |
| 5291 |
#define RAND_MASK 123459876 |
| 5292 |
|
| 5293 |
tmp = iPtr->randSeed/RAND_IQ; |
| 5294 |
iPtr->randSeed = RAND_IA*(iPtr->randSeed - tmp*RAND_IQ) - RAND_IR*tmp; |
| 5295 |
if (iPtr->randSeed < 0) { |
| 5296 |
iPtr->randSeed += RAND_IM; |
| 5297 |
} |
| 5298 |
|
| 5299 |
|
| 5300 |
|
| 5301 |
|
| 5302 |
|
| 5303 |
|
| 5304 |
dResult = iPtr->randSeed * (1.0/RAND_IM); |
| 5305 |
|
| 5306 |
|
| 5307 |
|
| 5308 |
|
| 5309 |
|
| 5310 |
PUSH_OBJECT(Tcl_NewDoubleObj(dResult)); |
| 5311 |
|
| 5312 |
|
| 5313 |
|
| 5314 |
|
| 5315 |
|
| 5316 |
DECACHE_STACK_INFO(); |
| 5317 |
return TCL_OK; |
| 5318 |
} |
| 5319 |
|
| 5320 |
static int |
| 5321 |
ExprRoundFunc(interp, eePtr, clientData) |
| 5322 |
Tcl_Interp *interp; |
| 5323 |
|
| 5324 |
ExecEnv *eePtr; |
| 5325 |
|
| 5326 |
ClientData clientData; |
| 5327 |
{ |
| 5328 |
Tcl_Obj **stackPtr; |
| 5329 |
register int stackTop; |
| 5330 |
Tcl_Obj *valuePtr; |
| 5331 |
long iResult; |
| 5332 |
double d, temp; |
| 5333 |
int result; |
| 5334 |
|
| 5335 |
|
| 5336 |
|
| 5337 |
|
| 5338 |
|
| 5339 |
result = TCL_OK; |
| 5340 |
CACHE_STACK_INFO(); |
| 5341 |
|
| 5342 |
|
| 5343 |
|
| 5344 |
|
| 5345 |
|
| 5346 |
valuePtr = POP_OBJECT(); |
| 5347 |
|
| 5348 |
if (VerifyExprObjType(interp, valuePtr) != TCL_OK) { |
| 5349 |
result = TCL_ERROR; |
| 5350 |
goto done; |
| 5351 |
} |
| 5352 |
|
| 5353 |
if (valuePtr->typePtr == &tclIntType) { |
| 5354 |
iResult = valuePtr->internalRep.longValue; |
| 5355 |
} else if (valuePtr->typePtr == &tclWideIntType) { |
| 5356 |
Tcl_WideInt w; |
| 5357 |
TclGetWide(w,valuePtr); |
| 5358 |
PUSH_OBJECT(Tcl_NewWideIntObj(w)); |
| 5359 |
goto done; |
| 5360 |
} else { |
| 5361 |
d = valuePtr->internalRep.doubleValue; |
| 5362 |
if (d < 0.0) { |
| 5363 |
if (d <= (((double) (long) LONG_MIN) - 0.5)) { |
| 5364 |
tooLarge: |
| 5365 |
Tcl_ResetResult(interp); |
| 5366 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), |
| 5367 |
"integer value too large to represent", -1); |
| 5368 |
Tcl_SetErrorCode(interp, "ARITH", "IOVERFLOW", |
| 5369 |
"integer value too large to represent", |
| 5370 |
(char *) NULL); |
| 5371 |
result = TCL_ERROR; |
| 5372 |
goto done; |
| 5373 |
} |
| 5374 |
temp = (long) (d - 0.5); |
| 5375 |
} else { |
| 5376 |
if (d >= (((double) LONG_MAX + 0.5))) { |
| 5377 |
goto tooLarge; |
| 5378 |
} |
| 5379 |
temp = (long) (d + 0.5); |
| 5380 |
} |
| 5381 |
if (IS_NAN(temp) || IS_INF(temp)) { |
| 5382 |
TclExprFloatError(interp, temp); |
| 5383 |
result = TCL_ERROR; |
| 5384 |
goto done; |
| 5385 |
} |
| 5386 |
iResult = (long) temp; |
| 5387 |
} |
| 5388 |
|
| 5389 |
|
| 5390 |
|
| 5391 |
|
| 5392 |
|
| 5393 |
PUSH_OBJECT(Tcl_NewLongObj(iResult)); |
| 5394 |
|
| 5395 |
|
| 5396 |
|
| 5397 |
|
| 5398 |
|
| 5399 |
done: |
| 5400 |
TclDecrRefCount(valuePtr); |
| 5401 |
DECACHE_STACK_INFO(); |
| 5402 |
return result; |
| 5403 |
} |
| 5404 |
|
| 5405 |
static int |
| 5406 |
ExprSrandFunc(interp, eePtr, clientData) |
| 5407 |
Tcl_Interp *interp; |
| 5408 |
|
| 5409 |
ExecEnv *eePtr; |
| 5410 |
|
| 5411 |
ClientData clientData; |
| 5412 |
{ |
| 5413 |
Tcl_Obj **stackPtr; |
| 5414 |
register int stackTop; |
| 5415 |
Interp *iPtr = (Interp *) interp; |
| 5416 |
Tcl_Obj *valuePtr; |
| 5417 |
long i = 0; |
| 5418 |
|
| 5419 |
|
| 5420 |
|
| 5421 |
|
| 5422 |
|
| 5423 |
CACHE_STACK_INFO(); |
| 5424 |
|
| 5425 |
|
| 5426 |
|
| 5427 |
|
| 5428 |
|
| 5429 |
|
| 5430 |
valuePtr = POP_OBJECT(); |
| 5431 |
|
| 5432 |
if (VerifyExprObjType(interp, valuePtr) != TCL_OK) { |
| 5433 |
goto badValue; |
| 5434 |
} |
| 5435 |
|
| 5436 |
if (valuePtr->typePtr == &tclIntType) { |
| 5437 |
i = valuePtr->internalRep.longValue; |
| 5438 |
} else if (valuePtr->typePtr == &tclWideIntType) { |
| 5439 |
TclGetLongFromWide(i,valuePtr); |
| 5440 |
} else { |
| 5441 |
|
| 5442 |
|
| 5443 |
|
| 5444 |
Tcl_ResetResult(interp); |
| 5445 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 5446 |
"can't use floating-point value as argument to srand", |
| 5447 |
(char *) NULL); |
| 5448 |
badValue: |
| 5449 |
TclDecrRefCount(valuePtr); |
| 5450 |
DECACHE_STACK_INFO(); |
| 5451 |
return TCL_ERROR; |
| 5452 |
} |
| 5453 |
|
| 5454 |
|
| 5455 |
|
| 5456 |
|
| 5457 |
|
| 5458 |
|
| 5459 |
iPtr->flags |= RAND_SEED_INITIALIZED; |
| 5460 |
iPtr->randSeed = i; |
| 5461 |
iPtr->randSeed &= (unsigned long) 0x7fffffff; |
| 5462 |
if ((iPtr->randSeed == 0) || (iPtr->randSeed == 0x7fffffff)) { |
| 5463 |
iPtr->randSeed ^= 123459876; |
| 5464 |
} |
| 5465 |
|
| 5466 |
|
| 5467 |
|
| 5468 |
|
| 5469 |
|
| 5470 |
|
| 5471 |
|
| 5472 |
TclDecrRefCount(valuePtr); |
| 5473 |
DECACHE_STACK_INFO(); |
| 5474 |
|
| 5475 |
ExprRandFunc(interp, eePtr, clientData); |
| 5476 |
return TCL_OK; |
| 5477 |
} |
| 5478 |
|
| 5479 |
|
| 5480 |
|
| 5481 |
|
| 5482 |
|
| 5483 |
|
| 5484 |
|
| 5485 |
|
| 5486 |
|
| 5487 |
|
| 5488 |
|
| 5489 |
|
| 5490 |
|
| 5491 |
|
| 5492 |
|
| 5493 |
|
| 5494 |
|
| 5495 |
|
| 5496 |
|
| 5497 |
|
| 5498 |
|
| 5499 |
|
| 5500 |
static int |
| 5501 |
ExprCallMathFunc(interp, eePtr, objc, objv) |
| 5502 |
Tcl_Interp *interp; |
| 5503 |
|
| 5504 |
ExecEnv *eePtr; |
| 5505 |
|
| 5506 |
int objc; |
| 5507 |
|
| 5508 |
Tcl_Obj **objv; |
| 5509 |
|
| 5510 |
{ |
| 5511 |
Interp *iPtr = (Interp *) interp; |
| 5512 |
Tcl_Obj **stackPtr; |
| 5513 |
register int stackTop; |
| 5514 |
char *funcName; |
| 5515 |
Tcl_HashEntry *hPtr; |
| 5516 |
MathFunc *mathFuncPtr; |
| 5517 |
Tcl_Value args[MAX_MATH_ARGS]; |
| 5518 |
Tcl_Value funcResult; |
| 5519 |
register Tcl_Obj *valuePtr; |
| 5520 |
long i; |
| 5521 |
double d; |
| 5522 |
int j, k, result; |
| 5523 |
|
| 5524 |
Tcl_ResetResult(interp); |
| 5525 |
|
| 5526 |
|
| 5527 |
|
| 5528 |
|
| 5529 |
|
| 5530 |
CACHE_STACK_INFO(); |
| 5531 |
|
| 5532 |
|
| 5533 |
|
| 5534 |
|
| 5535 |
|
| 5536 |
funcName = TclGetString(objv[0]); |
| 5537 |
hPtr = Tcl_FindHashEntry(&iPtr->mathFuncTable, funcName); |
| 5538 |
if (hPtr == NULL) { |
| 5539 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 5540 |
"unknown math function \"", funcName, "\"", (char *) NULL); |
| 5541 |
result = TCL_ERROR; |
| 5542 |
goto done; |
| 5543 |
} |
| 5544 |
mathFuncPtr = (MathFunc *) Tcl_GetHashValue(hPtr); |
| 5545 |
if (mathFuncPtr->numArgs != (objc-1)) { |
| 5546 |
panic("ExprCallMathFunc: expected number of args %d != actual number %d", |
| 5547 |
mathFuncPtr->numArgs, objc); |
| 5548 |
result = TCL_ERROR; |
| 5549 |
goto done; |
| 5550 |
} |
| 5551 |
|
| 5552 |
|
| 5553 |
|
| 5554 |
|
| 5555 |
|
| 5556 |
|
| 5557 |
|
| 5558 |
for (j = 1, k = 0; j < objc; j++, k++) { |
| 5559 |
valuePtr = objv[j]; |
| 5560 |
|
| 5561 |
if (VerifyExprObjType(interp, valuePtr) != TCL_OK) { |
| 5562 |
result = TCL_ERROR; |
| 5563 |
goto done; |
| 5564 |
} |
| 5565 |
|
| 5566 |
|
| 5567 |
|
| 5568 |
|
| 5569 |
|
| 5570 |
|
| 5571 |
if (valuePtr->typePtr == &tclIntType) { |
| 5572 |
i = valuePtr->internalRep.longValue; |
| 5573 |
if (mathFuncPtr->argTypes[k] == TCL_DOUBLE) { |
| 5574 |
args[k].type = TCL_DOUBLE; |
| 5575 |
args[k].doubleValue = i; |
| 5576 |
} else if (mathFuncPtr->argTypes[k] == TCL_WIDE_INT) { |
| 5577 |
args[k].type = TCL_WIDE_INT; |
| 5578 |
args[k].wideValue = Tcl_LongAsWide(i); |
| 5579 |
} else { |
| 5580 |
args[k].type = TCL_INT; |
| 5581 |
args[k].intValue = i; |
| 5582 |
} |
| 5583 |
} else if (valuePtr->typePtr == &tclWideIntType) { |
| 5584 |
Tcl_WideInt w; |
| 5585 |
TclGetWide(w,valuePtr); |
| 5586 |
if (mathFuncPtr->argTypes[k] == TCL_DOUBLE) { |
| 5587 |
args[k].type = TCL_DOUBLE; |
| 5588 |
args[k].doubleValue = Tcl_WideAsDouble(w); |
| 5589 |
} else if (mathFuncPtr->argTypes[k] == TCL_INT) { |
| 5590 |
args[k].type = TCL_INT; |
| 5591 |
args[k].intValue = Tcl_WideAsLong(w); |
| 5592 |
} else { |
| 5593 |
args[k].type = TCL_WIDE_INT; |
| 5594 |
args[k].wideValue = w; |
| 5595 |
} |
| 5596 |
} else { |
| 5597 |
d = valuePtr->internalRep.doubleValue; |
| 5598 |
if (mathFuncPtr->argTypes[k] == TCL_INT) { |
| 5599 |
args[k].type = TCL_INT; |
| 5600 |
args[k].intValue = (long) d; |
| 5601 |
} else if (mathFuncPtr->argTypes[k] == TCL_WIDE_INT) { |
| 5602 |
args[k].type = TCL_WIDE_INT; |
| 5603 |
args[k].wideValue = Tcl_DoubleAsWide(d); |
| 5604 |
} else { |
| 5605 |
args[k].type = TCL_DOUBLE; |
| 5606 |
args[k].doubleValue = d; |
| 5607 |
} |
| 5608 |
} |
| 5609 |
} |
| 5610 |
|
| 5611 |
|
| 5612 |
|
| 5613 |
|
| 5614 |
|
| 5615 |
result = (*mathFuncPtr->proc)(mathFuncPtr->clientData, interp, args, |
| 5616 |
&funcResult); |
| 5617 |
if (result != TCL_OK) { |
| 5618 |
goto done; |
| 5619 |
} |
| 5620 |
|
| 5621 |
|
| 5622 |
|
| 5623 |
|
| 5624 |
|
| 5625 |
k = (stackTop - (objc-1)); |
| 5626 |
while (stackTop >= k) { |
| 5627 |
valuePtr = POP_OBJECT(); |
| 5628 |
TclDecrRefCount(valuePtr); |
| 5629 |
} |
| 5630 |
|
| 5631 |
|
| 5632 |
|
| 5633 |
|
| 5634 |
|
| 5635 |
if (funcResult.type == TCL_INT) { |
| 5636 |
PUSH_OBJECT(Tcl_NewLongObj(funcResult.intValue)); |
| 5637 |
} else if (funcResult.type == TCL_WIDE_INT) { |
| 5638 |
PUSH_OBJECT(Tcl_NewWideIntObj(funcResult.wideValue)); |
| 5639 |
} else { |
| 5640 |
d = funcResult.doubleValue; |
| 5641 |
if (IS_NAN(d) || IS_INF(d)) { |
| 5642 |
TclExprFloatError(interp, d); |
| 5643 |
result = TCL_ERROR; |
| 5644 |
goto done; |
| 5645 |
} |
| 5646 |
PUSH_OBJECT(Tcl_NewDoubleObj(d)); |
| 5647 |
} |
| 5648 |
|
| 5649 |
|
| 5650 |
|
| 5651 |
|
| 5652 |
|
| 5653 |
done: |
| 5654 |
DECACHE_STACK_INFO(); |
| 5655 |
return result; |
| 5656 |
} |
| 5657 |
|
| 5658 |
|
| 5659 |
|
| 5660 |
|
| 5661 |
|
| 5662 |
|
| 5663 |
|
| 5664 |
|
| 5665 |
|
| 5666 |
|
| 5667 |
|
| 5668 |
|
| 5669 |
|
| 5670 |
|
| 5671 |
|
| 5672 |
|
| 5673 |
|
| 5674 |
|
| 5675 |
|
| 5676 |
void |
| 5677 |
TclExprFloatError(interp, value) |
| 5678 |
Tcl_Interp *interp; |
| 5679 |
double value; |
| 5680 |
|
| 5681 |
{ |
| 5682 |
char *s; |
| 5683 |
|
| 5684 |
Tcl_ResetResult(interp); |
| 5685 |
if ((errno == EDOM) || IS_NAN(value)) { |
| 5686 |
s = "domain error: argument not in valid range"; |
| 5687 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), s, -1); |
| 5688 |
Tcl_SetErrorCode(interp, "ARITH", "DOMAIN", s, (char *) NULL); |
| 5689 |
} else if ((errno == ERANGE) || IS_INF(value)) { |
| 5690 |
if (value == 0.0) { |
| 5691 |
s = "floating-point value too small to represent"; |
| 5692 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), s, -1); |
| 5693 |
Tcl_SetErrorCode(interp, "ARITH", "UNDERFLOW", s, (char *) NULL); |
| 5694 |
} else { |
| 5695 |
s = "floating-point value too large to represent"; |
| 5696 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), s, -1); |
| 5697 |
Tcl_SetErrorCode(interp, "ARITH", "OVERFLOW", s, (char *) NULL); |
| 5698 |
} |
| 5699 |
} else { |
| 5700 |
char msg[64 + TCL_INTEGER_SPACE]; |
| 5701 |
|
| 5702 |
sprintf(msg, "unknown floating-point error, errno = %d", errno); |
| 5703 |
Tcl_AppendToObj(Tcl_GetObjResult(interp), msg, -1); |
| 5704 |
Tcl_SetErrorCode(interp, "ARITH", "UNKNOWN", msg, (char *) NULL); |
| 5705 |
} |
| 5706 |
} |
| 5707 |
|
| 5708 |
#ifdef TCL_COMPILE_STATS |
| 5709 |
|
| 5710 |
|
| 5711 |
|
| 5712 |
|
| 5713 |
|
| 5714 |
|
| 5715 |
|
| 5716 |
|
| 5717 |
|
| 5718 |
|
| 5719 |
|
| 5720 |
|
| 5721 |
|
| 5722 |
|
| 5723 |
|
| 5724 |
|
| 5725 |
|
| 5726 |
|
| 5727 |
int |
| 5728 |
TclLog2(value) |
| 5729 |
register int value; |
| 5730 |
|
| 5731 |
{ |
| 5732 |
register int n = value; |
| 5733 |
register int result = 0; |
| 5734 |
|
| 5735 |
while (n > 1) { |
| 5736 |
n = n >> 1; |
| 5737 |
result++; |
| 5738 |
} |
| 5739 |
return result; |
| 5740 |
} |
| 5741 |
|
| 5742 |
|
| 5743 |
|
| 5744 |
|
| 5745 |
|
| 5746 |
|
| 5747 |
|
| 5748 |
|
| 5749 |
|
| 5750 |
|
| 5751 |
|
| 5752 |
|
| 5753 |
|
| 5754 |
|
| 5755 |
|
| 5756 |
|
| 5757 |
|
| 5758 |
|
| 5759 |
static int |
| 5760 |
EvalStatsCmd(unused, interp, objc, objv) |
| 5761 |
ClientData unused; |
| 5762 |
Tcl_Interp *interp; |
| 5763 |
int objc; |
| 5764 |
Tcl_Obj *CONST objv[]; |
| 5765 |
{ |
| 5766 |
Interp *iPtr = (Interp *) interp; |
| 5767 |
LiteralTable *globalTablePtr = &(iPtr->literalTable); |
| 5768 |
ByteCodeStats *statsPtr = &(iPtr->stats); |
| 5769 |
double totalCodeBytes, currentCodeBytes; |
| 5770 |
double totalLiteralBytes, currentLiteralBytes; |
| 5771 |
double objBytesIfUnshared, strBytesIfUnshared, sharingBytesSaved; |
| 5772 |
double strBytesSharedMultX, strBytesSharedOnce; |
| 5773 |
double numInstructions, currentHeaderBytes; |
| 5774 |
long numCurrentByteCodes, numByteCodeLits; |
| 5775 |
long refCountSum, literalMgmtBytes, sum; |
| 5776 |
int numSharedMultX, numSharedOnce; |
| 5777 |
int decadeHigh, minSizeDecade, maxSizeDecade, length, i; |
| 5778 |
char *litTableStats; |
| 5779 |
LiteralEntry *entryPtr; |
| 5780 |
|
| 5781 |
numInstructions = 0.0; |
| 5782 |
for (i = 0; i < 256; i++) { |
| 5783 |
if (statsPtr->instructionCount[i] != 0) { |
| 5784 |
numInstructions += statsPtr->instructionCount[i]; |
| 5785 |
} |
| 5786 |
} |
| 5787 |
|
| 5788 |
totalLiteralBytes = sizeof(LiteralTable) |
| 5789 |
+ iPtr->literalTable.numBuckets * sizeof(LiteralEntry *) |
| 5790 |
+ (statsPtr->numLiteralsCreated * sizeof(LiteralEntry)) |
| 5791 |
+ (statsPtr->numLiteralsCreated * sizeof(Tcl_Obj)) |
| 5792 |
+ statsPtr->totalLitStringBytes; |
| 5793 |
totalCodeBytes = statsPtr->totalByteCodeBytes + totalLiteralBytes; |
| 5794 |
|
| 5795 |
numCurrentByteCodes = |
| 5796 |
statsPtr->numCompilations - statsPtr->numByteCodesFreed; |
| 5797 |
currentHeaderBytes = numCurrentByteCodes |
| 5798 |
* (sizeof(ByteCode) - (sizeof(size_t) + sizeof(Tcl_Time))); |
| 5799 |
literalMgmtBytes = sizeof(LiteralTable) |
| 5800 |
+ (iPtr->literalTable.numBuckets * sizeof(LiteralEntry *)) |
| 5801 |
+ (iPtr->literalTable.numEntries * sizeof(LiteralEntry)); |
| 5802 |
currentLiteralBytes = literalMgmtBytes |
| 5803 |
+ iPtr->literalTable.numEntries * sizeof(Tcl_Obj) |
| 5804 |
+ statsPtr->currentLitStringBytes; |
| 5805 |
currentCodeBytes = statsPtr->currentByteCodeBytes + currentLiteralBytes; |
| 5806 |
|
| 5807 |
|
| 5808 |
|
| 5809 |
|
| 5810 |
|
| 5811 |
fprintf(stdout, "\n----------------------------------------------------------------\n"); |
| 5812 |
fprintf(stdout, |
| 5813 |
"Compilation and execution statistics for interpreter 0x%x\n", |
| 5814 |
(unsigned int) iPtr); |
| 5815 |
|
| 5816 |
fprintf(stdout, "\nNumber ByteCodes executed %ld\n", |
| 5817 |
statsPtr->numExecutions); |
| 5818 |
fprintf(stdout, "Number ByteCodes compiled %ld\n", |
| 5819 |
statsPtr->numCompilations); |
| 5820 |
fprintf(stdout, " Mean executions/compile %.1f\n", |
| 5821 |
((float)statsPtr->numExecutions) / ((float)statsPtr->numCompilations)); |
| 5822 |
|
| 5823 |
fprintf(stdout, "\nInstructions executed %.0f\n", |
| 5824 |
numInstructions); |
| 5825 |
fprintf(stdout, " Mean inst/compile %.0f\n", |
| 5826 |
numInstructions / statsPtr->numCompilations); |
| 5827 |
fprintf(stdout, " Mean inst/execution %.0f\n", |
| 5828 |
numInstructions / statsPtr->numExecutions); |
| 5829 |
|
| 5830 |
fprintf(stdout, "\nTotal ByteCodes %ld\n", |
| 5831 |
statsPtr->numCompilations); |
| 5832 |
fprintf(stdout, " Source bytes %.6g\n", |
| 5833 |
statsPtr->totalSrcBytes); |
| 5834 |
fprintf(stdout, " Code bytes %.6g\n", |
| 5835 |
totalCodeBytes); |
| 5836 |
fprintf(stdout, " ByteCode bytes %.6g\n", |
| 5837 |
statsPtr->totalByteCodeBytes); |
| 5838 |
fprintf(stdout, " Literal bytes %.6g\n", |
| 5839 |
totalLiteralBytes); |
| 5840 |
fprintf(stdout, " table %d + bkts %d + entries %ld + objects %ld + strings %.6g\n", |
| 5841 |
sizeof(LiteralTable), |
| 5842 |
iPtr->literalTable.numBuckets * sizeof(LiteralEntry *), |
| 5843 |
statsPtr->numLiteralsCreated * sizeof(LiteralEntry), |
| 5844 |
statsPtr->numLiteralsCreated * sizeof(Tcl_Obj), |
| 5845 |
statsPtr->totalLitStringBytes); |
| 5846 |
fprintf(stdout, " Mean code/compile %.1f\n", |
| 5847 |
totalCodeBytes / statsPtr->numCompilations); |
| 5848 |
fprintf(stdout, " Mean code/source %.1f\n", |
| 5849 |
totalCodeBytes / statsPtr->totalSrcBytes); |
| 5850 |
|
| 5851 |
fprintf(stdout, "\nCurrent (active) ByteCodes %ld\n", |
| 5852 |
numCurrentByteCodes); |
| 5853 |
fprintf(stdout, " Source bytes %.6g\n", |
| 5854 |
statsPtr->currentSrcBytes); |
| 5855 |
fprintf(stdout, " Code bytes %.6g\n", |
| 5856 |
currentCodeBytes); |
| 5857 |
fprintf(stdout, " ByteCode bytes %.6g\n", |
| 5858 |
statsPtr->currentByteCodeBytes); |
| 5859 |
fprintf(stdout, " Literal bytes %.6g\n", |
| 5860 |
currentLiteralBytes); |
| 5861 |
fprintf(stdout, " table %d + bkts %d + entries %d + objects %d + strings %.6g\n", |
| 5862 |
sizeof(LiteralTable), |
| 5863 |
iPtr->literalTable.numBuckets * sizeof(LiteralEntry *), |
| 5864 |
iPtr->literalTable.numEntries * sizeof(LiteralEntry), |
| 5865 |
iPtr->literalTable.numEntries * sizeof(Tcl_Obj), |
| 5866 |
statsPtr->currentLitStringBytes); |
| 5867 |
fprintf(stdout, " Mean code/source %.1f\n", |
| 5868 |
currentCodeBytes / statsPtr->currentSrcBytes); |
| 5869 |
fprintf(stdout, " Code + source bytes %.6g (%0.1f mean code/src)\n", |
| 5870 |
(currentCodeBytes + statsPtr->currentSrcBytes), |
| 5871 |
(currentCodeBytes / statsPtr->currentSrcBytes) + 1.0); |
| 5872 |
|
| 5873 |
|
| 5874 |
|
| 5875 |
|
| 5876 |
|
| 5877 |
|
| 5878 |
|
| 5879 |
|
| 5880 |
|
| 5881 |
numSharedMultX = 0; |
| 5882 |
fprintf(stdout, "\nTcl_IsShared object check (all objects):\n"); |
| 5883 |
fprintf(stdout, " Object had refcount <=1 (not shared) %ld\n", |
| 5884 |
tclObjsShared[1]); |
| 5885 |
for (i = 2; i < TCL_MAX_SHARED_OBJ_STATS; i++) { |
| 5886 |
fprintf(stdout, " refcount ==%d %ld\n", |
| 5887 |
i, tclObjsShared[i]); |
| 5888 |
numSharedMultX += tclObjsShared[i]; |
| 5889 |
} |
| 5890 |
fprintf(stdout, " refcount >=%d %ld\n", |
| 5891 |
i, tclObjsShared[0]); |
| 5892 |
numSharedMultX += tclObjsShared[0]; |
| 5893 |
fprintf(stdout, " Total shared objects %d\n", |
| 5894 |
numSharedMultX); |
| 5895 |
|
| 5896 |
|
| 5897 |
|
| 5898 |
|
| 5899 |
|
| 5900 |
numByteCodeLits = 0; |
| 5901 |
refCountSum = 0; |
| 5902 |
numSharedMultX = 0; |
| 5903 |
numSharedOnce = 0; |
| 5904 |
objBytesIfUnshared = 0.0; |
| 5905 |
strBytesIfUnshared = 0.0; |
| 5906 |
strBytesSharedMultX = 0.0; |
| 5907 |
strBytesSharedOnce = 0.0; |
| 5908 |
for (i = 0; i < globalTablePtr->numBuckets; i++) { |
| 5909 |
for (entryPtr = globalTablePtr->buckets[i]; entryPtr != NULL; |
| 5910 |
entryPtr = entryPtr->nextPtr) { |
| 5911 |
if (entryPtr->objPtr->typePtr == &tclByteCodeType) { |
| 5912 |
numByteCodeLits++; |
| 5913 |
} |
| 5914 |
(void) Tcl_GetStringFromObj(entryPtr->objPtr, &length); |
| 5915 |
refCountSum += entryPtr->refCount; |
| 5916 |
objBytesIfUnshared += (entryPtr->refCount * sizeof(Tcl_Obj)); |
| 5917 |
strBytesIfUnshared += (entryPtr->refCount * (length+1)); |
| 5918 |
if (entryPtr->refCount > 1) { |
| 5919 |
numSharedMultX++; |
| 5920 |
strBytesSharedMultX += (length+1); |
| 5921 |
} else { |
| 5922 |
numSharedOnce++; |
| 5923 |
strBytesSharedOnce += (length+1); |
| 5924 |
} |
| 5925 |
} |
| 5926 |
} |
| 5927 |
sharingBytesSaved = (objBytesIfUnshared + strBytesIfUnshared) |
| 5928 |
- currentLiteralBytes; |
| 5929 |
|
| 5930 |
fprintf(stdout, "\nTotal objects (all interps) %ld\n", |
| 5931 |
tclObjsAlloced); |
| 5932 |
fprintf(stdout, "Current objects %ld\n", |
| 5933 |
(tclObjsAlloced - tclObjsFreed)); |
| 5934 |
fprintf(stdout, "Total literal objects %ld\n", |
| 5935 |
statsPtr->numLiteralsCreated); |
| 5936 |
|
| 5937 |
fprintf(stdout, "\nCurrent literal objects %d (%0.1f%% of current objects)\n", |
| 5938 |
globalTablePtr->numEntries, |
| 5939 |
(globalTablePtr->numEntries * 100.0) / (tclObjsAlloced-tclObjsFreed)); |
| 5940 |
fprintf(stdout, " ByteCode literals %ld (%0.1f%% of current literals)\n", |
| 5941 |
numByteCodeLits, |
| 5942 |
(numByteCodeLits * 100.0) / globalTablePtr->numEntries); |
| 5943 |
fprintf(stdout, " Literals reused > 1x %d\n", |
| 5944 |
numSharedMultX); |
| 5945 |
fprintf(stdout, " Mean reference count %.2f\n", |
| 5946 |
((double) refCountSum) / globalTablePtr->numEntries); |
| 5947 |
fprintf(stdout, " Mean len, str reused >1x %.2f\n", |
| 5948 |
(numSharedMultX? (strBytesSharedMultX/numSharedMultX) : 0.0)); |
| 5949 |
fprintf(stdout, " Mean len, str used 1x %.2f\n", |
| 5950 |
(numSharedOnce? (strBytesSharedOnce/numSharedOnce) : 0.0)); |
| 5951 |
fprintf(stdout, " Total sharing savings %.6g (%0.1f%% of bytes if no sharing)\n", |
| 5952 |
sharingBytesSaved, |
| 5953 |
(sharingBytesSaved * 100.0) / (objBytesIfUnshared + strBytesIfUnshared)); |
| 5954 |
fprintf(stdout, " Bytes with sharing %.6g\n", |
| 5955 |
currentLiteralBytes); |
| 5956 |
fprintf(stdout, " table %d + bkts %d + entries %d + objects %d + strings %.6g\n", |
| 5957 |
sizeof(LiteralTable), |
| 5958 |
iPtr->literalTable.numBuckets * sizeof(LiteralEntry *), |
| 5959 |
iPtr->literalTable.numEntries * sizeof(LiteralEntry), |
| 5960 |
iPtr->literalTable.numEntries * sizeof(Tcl_Obj), |
| 5961 |
statsPtr->currentLitStringBytes); |
| 5962 |
fprintf(stdout, " Bytes if no sharing %.6g = objects %.6g + strings %.6g\n", |
| 5963 |
(objBytesIfUnshared + strBytesIfUnshared), |
| 5964 |
objBytesIfUnshared, strBytesIfUnshared); |
| 5965 |
fprintf(stdout, " String sharing savings %.6g = unshared %.6g - shared %.6g\n", |
| 5966 |
(strBytesIfUnshared - statsPtr->currentLitStringBytes), |
| 5967 |
strBytesIfUnshared, statsPtr->currentLitStringBytes); |
| 5968 |
fprintf(stdout, " Literal mgmt overhead %ld (%0.1f%% of bytes with sharing)\n", |
| 5969 |
literalMgmtBytes, |
| 5970 |
(literalMgmtBytes * 100.0) / currentLiteralBytes); |
| 5971 |
fprintf(stdout, " table %d + buckets %d + entries %d\n", |
| 5972 |
sizeof(LiteralTable), |
| 5973 |
iPtr->literalTable.numBuckets * sizeof(LiteralEntry *), |
| 5974 |
iPtr->literalTable.numEntries * sizeof(LiteralEntry)); |
| 5975 |
|
| 5976 |
|
| 5977 |
|
| 5978 |
|
| 5979 |
|
| 5980 |
fprintf(stdout, "\nBreakdown of current ByteCode requirements:\n"); |
| 5981 |
fprintf(stdout, " Bytes Pct of Avg per\n"); |
| 5982 |
fprintf(stdout, " total ByteCode\n"); |
| 5983 |
fprintf(stdout, "Total %12.6g 100.00%% %8.1f\n", |
| 5984 |
statsPtr->currentByteCodeBytes, |
| 5985 |
statsPtr->currentByteCodeBytes / numCurrentByteCodes); |
| 5986 |
fprintf(stdout, "Header %12.6g %8.1f%% %8.1f\n", |
| 5987 |
currentHeaderBytes, |
| 5988 |
((currentHeaderBytes * 100.0) / statsPtr->currentByteCodeBytes), |
| 5989 |
currentHeaderBytes / numCurrentByteCodes); |
| 5990 |
fprintf(stdout, "Instructions %12.6g %8.1f%% %8.1f\n", |
| 5991 |
statsPtr->currentInstBytes, |
| 5992 |
((statsPtr->currentInstBytes * 100.0) / statsPtr->currentByteCodeBytes), |
| 5993 |
statsPtr->currentInstBytes / numCurrentByteCodes); |
| 5994 |
fprintf(stdout, "Literal ptr array %12.6g %8.1f%% %8.1f\n", |
| 5995 |
statsPtr->currentLitBytes, |
| 5996 |
((statsPtr->currentLitBytes * 100.0) / statsPtr->currentByteCodeBytes), |
| 5997 |
statsPtr->currentLitBytes / numCurrentByteCodes); |
| 5998 |
fprintf(stdout, "Exception table %12.6g %8.1f%% %8.1f\n", |
| 5999 |
statsPtr->currentExceptBytes, |
| 6000 |
((statsPtr->currentExceptBytes * 100.0) / statsPtr->currentByteCodeBytes), |
| 6001 |
statsPtr->currentExceptBytes / numCurrentByteCodes); |
| 6002 |
fprintf(stdout, "Auxiliary data %12.6g %8.1f%% %8.1f\n", |
| 6003 |
statsPtr->currentAuxBytes, |
| 6004 |
((statsPtr->currentAuxBytes * 100.0) / statsPtr->currentByteCodeBytes), |
| 6005 |
statsPtr->currentAuxBytes / numCurrentByteCodes); |
| 6006 |
fprintf(stdout, "Command map %12.6g %8.1f%% %8.1f\n", |
| 6007 |
statsPtr->currentCmdMapBytes, |
| 6008 |
((statsPtr->currentCmdMapBytes * 100.0) / statsPtr->currentByteCodeBytes), |
| 6009 |
statsPtr->currentCmdMapBytes / numCurrentByteCodes); |
| 6010 |
|
| 6011 |
|
| 6012 |
|
| 6013 |
|
| 6014 |
|
| 6015 |
fprintf(stdout, "\nLiteral string sizes:\n"); |
| 6016 |
fprintf(stdout, " Up to length Percentage\n"); |
| 6017 |
maxSizeDecade = 0; |
| 6018 |
for (i = 31; i >= 0; i--) { |
| 6019 |
if (statsPtr->literalCount[i] > 0) { |
| 6020 |
maxSizeDecade = i; |
| 6021 |
break; |
| 6022 |
} |
| 6023 |
} |
| 6024 |
sum = 0; |
| 6025 |
for (i = 0; i <= maxSizeDecade; i++) { |
| 6026 |
decadeHigh = (1 << (i+1)) - 1; |
| 6027 |
sum += statsPtr->literalCount[i]; |
| 6028 |
fprintf(stdout, " %10d %8.0f%%\n", |
| 6029 |
decadeHigh, (sum * 100.0) / statsPtr->numLiteralsCreated); |
| 6030 |
} |
| 6031 |
|
| 6032 |
litTableStats = TclLiteralStats(globalTablePtr); |
| 6033 |
fprintf(stdout, "\nCurrent literal table statistics:\n%s\n", |
| 6034 |
litTableStats); |
| 6035 |
ckfree((char *) litTableStats); |
| 6036 |
|
| 6037 |
|
| 6038 |
|
| 6039 |
|
| 6040 |
|
| 6041 |
fprintf(stdout, "\nSource sizes:\n"); |
| 6042 |
fprintf(stdout, " Up to size Percentage\n"); |
| 6043 |
minSizeDecade = maxSizeDecade = 0; |
| 6044 |
for (i = 0; i < 31; i++) { |
| 6045 |
if (statsPtr->srcCount[i] > 0) { |
| 6046 |
minSizeDecade = i; |
| 6047 |
break; |
| 6048 |
} |
| 6049 |
} |
| 6050 |
for (i = 31; i >= 0; i--) { |
| 6051 |
if (statsPtr->srcCount[i] > 0) { |
| 6052 |
maxSizeDecade = i; |
| 6053 |
break; |
| 6054 |
} |
| 6055 |
} |
| 6056 |
sum = 0; |
| 6057 |
for (i = minSizeDecade; i <= maxSizeDecade; i++) { |
| 6058 |
decadeHigh = (1 << (i+1)) - 1; |
| 6059 |
sum += statsPtr->srcCount[i]; |
| 6060 |
fprintf(stdout, " %10d %8.0f%%\n", |
| 6061 |
decadeHigh, (sum * 100.0) / statsPtr->numCompilations); |
| 6062 |
} |
| 6063 |
|
| 6064 |
fprintf(stdout, "\nByteCode sizes:\n"); |
| 6065 |
fprintf(stdout, " Up to size Percentage\n"); |
| 6066 |
minSizeDecade = maxSizeDecade = 0; |
| 6067 |
for (i = 0; i < 31; i++) { |
| 6068 |
if (statsPtr->byteCodeCount[i] > 0) { |
| 6069 |
minSizeDecade = i; |
| 6070 |
break; |
| 6071 |
} |
| 6072 |
} |
| 6073 |
for (i = 31; i >= 0; i--) { |
| 6074 |
if (statsPtr->byteCodeCount[i] > 0) { |
| 6075 |
maxSizeDecade = i; |
| 6076 |
break; |
| 6077 |
} |
| 6078 |
} |
| 6079 |
sum = 0; |
| 6080 |
for (i = minSizeDecade; i <= maxSizeDecade; i++) { |
| 6081 |
decadeHigh = (1 << (i+1)) - 1; |
| 6082 |
sum += statsPtr->byteCodeCount[i]; |
| 6083 |
fprintf(stdout, " %10d %8.0f%%\n", |
| 6084 |
decadeHigh, (sum * 100.0) / statsPtr->numCompilations); |
| 6085 |
} |
| 6086 |
|
| 6087 |
fprintf(stdout, "\nByteCode longevity (excludes Current ByteCodes):\n"); |
| 6088 |
fprintf(stdout, " Up to ms Percentage\n"); |
| 6089 |
minSizeDecade = maxSizeDecade = 0; |
| 6090 |
for (i = 0; i < 31; i++) { |
| 6091 |
if (statsPtr->lifetimeCount[i] > 0) { |
| 6092 |
minSizeDecade = i; |
| 6093 |
break; |
| 6094 |
} |
| 6095 |
} |
| 6096 |
for (i = 31; i >= 0; i--) { |
| 6097 |
if (statsPtr->lifetimeCount[i] > 0) { |
| 6098 |
maxSizeDecade = i; |
| 6099 |
break; |
| 6100 |
} |
| 6101 |
} |
| 6102 |
sum = 0; |
| 6103 |
for (i = minSizeDecade; i <= maxSizeDecade; i++) { |
| 6104 |
decadeHigh = (1 << (i+1)) - 1; |
| 6105 |
sum += statsPtr->lifetimeCount[i]; |
| 6106 |
fprintf(stdout, " %12.3f %8.0f%%\n", |
| 6107 |
decadeHigh / 1000.0, |
| 6108 |
(sum * 100.0) / statsPtr->numByteCodesFreed); |
| 6109 |
} |
| 6110 |
|
| 6111 |
|
| 6112 |
|
| 6113 |
|
| 6114 |
|
| 6115 |
fprintf(stdout, "\nInstruction counts:\n"); |
| 6116 |
for (i = 0; i <= LAST_INST_OPCODE; i++) { |
| 6117 |
if (statsPtr->instructionCount[i]) { |
| 6118 |
fprintf(stdout, "%20s %8ld %6.1f%%\n", |
| 6119 |
tclInstructionTable[i].name, |
| 6120 |
statsPtr->instructionCount[i], |
| 6121 |
(statsPtr->instructionCount[i]*100.0) / numInstructions); |
| 6122 |
} |
| 6123 |
} |
| 6124 |
|
| 6125 |
fprintf(stdout, "\nInstructions NEVER executed:\n"); |
| 6126 |
for (i = 0; i <= LAST_INST_OPCODE; i++) { |
| 6127 |
if (statsPtr->instructionCount[i] == 0) { |
| 6128 |
fprintf(stdout, "%20s\n", tclInstructionTable[i].name); |
| 6129 |
} |
| 6130 |
} |
| 6131 |
|
| 6132 |
#ifdef TCL_MEM_DEBUG |
| 6133 |
fprintf(stdout, "\nHeap Statistics:\n"); |
| 6134 |
TclDumpMemoryInfo(stdout); |
| 6135 |
#endif |
| 6136 |
fprintf(stdout, "\n----------------------------------------------------------------\n"); |
| 6137 |
return TCL_OK; |
| 6138 |
} |
| 6139 |
#endif |
| 6140 |
|
| 6141 |
#ifdef TCL_COMPILE_DEBUG |
| 6142 |
|
| 6143 |
|
| 6144 |
|
| 6145 |
|
| 6146 |
|
| 6147 |
|
| 6148 |
|
| 6149 |
|
| 6150 |
|
| 6151 |
|
| 6152 |
|
| 6153 |
|
| 6154 |
|
| 6155 |
|
| 6156 |
|
| 6157 |
|
| 6158 |
|
| 6159 |
|
| 6160 |
|
| 6161 |
|
| 6162 |
|
| 6163 |
static char * |
| 6164 |
StringForResultCode(result) |
| 6165 |
int result; |
| 6166 |
|
| 6167 |
{ |
| 6168 |
static char buf[TCL_INTEGER_SPACE]; |
| 6169 |
|
| 6170 |
if ((result >= TCL_OK) && (result <= TCL_CONTINUE)) { |
| 6171 |
return resultStrings[result]; |
| 6172 |
} |
| 6173 |
TclFormatInt(buf, result); |
| 6174 |
return buf; |
| 6175 |
} |
| 6176 |
#endif |