Changeset 37845 in webkit for trunk/JavaScriptCore/kjs/JSImmediate.h
- Timestamp:
- Oct 24, 2008, 9:22:51 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/JSImmediate.h
r37812 r37845 40 40 class UString; 41 41 42 typedef JSValue* JSValuePtr; 43 44 inline JSValuePtr noValue() { return static_cast<JSValue*>(0); } 45 inline void* asPointer(JSValuePtr value) { return value; } 42 inline JSValue* noValue() { return 0; } 43 inline void* asPointer(JSValue* value) { return value; } 46 44 47 45 /* 48 * A JSValue Ptris either a pointer to a cell (a heap-allocated object) or an immediate (a type-tagged49 * value masquerading as a pointer). The low two bits in a JSValue Ptrare available for type tagging46 * A JSValue* is either a pointer to a cell (a heap-allocated object) or an immediate (a type-tagged 47 * value masquerading as a pointer). The low two bits in a JSValue* are available for type tagging 50 48 * because allocator alignment guarantees they will be 00 in cell pointers. 51 49 * … … 110 108 111 109 public: 112 static ALWAYS_INLINE bool isImmediate(JSValue Ptrv)110 static ALWAYS_INLINE bool isImmediate(JSValue* v) 113 111 { 114 112 return rawValue(v) & TagMask; 115 113 } 116 114 117 static ALWAYS_INLINE bool isNumber(JSValue Ptrv)115 static ALWAYS_INLINE bool isNumber(JSValue* v) 118 116 { 119 117 return rawValue(v) & TagBitTypeInteger; 120 118 } 121 119 122 static ALWAYS_INLINE bool isPositiveNumber(JSValue Ptrv)120 static ALWAYS_INLINE bool isPositiveNumber(JSValue* v) 123 121 { 124 122 // A single mask to check for the sign bit and the number tag all at once. … … 126 124 } 127 125 128 static ALWAYS_INLINE bool isBoolean(JSValue Ptrv)126 static ALWAYS_INLINE bool isBoolean(JSValue* v) 129 127 { 130 128 return (rawValue(v) & FullTagTypeMask) == FullTagTypeBool; 131 129 } 132 130 133 static ALWAYS_INLINE bool isUndefinedOrNull(JSValue Ptrv)131 static ALWAYS_INLINE bool isUndefinedOrNull(JSValue* v) 134 132 { 135 133 // Undefined and null share the same value, bar the 'undefined' bit in the extended tag. … … 137 135 } 138 136 139 static bool isNegative(JSValue Ptrv)137 static bool isNegative(JSValue* v) 140 138 { 141 139 ASSERT(isNumber(v)); … … 143 141 } 144 142 145 static JSValue Ptrfrom(char);146 static JSValue Ptrfrom(signed char);147 static JSValue Ptrfrom(unsigned char);148 static JSValue Ptrfrom(short);149 static JSValue Ptrfrom(unsigned short);150 static JSValue Ptrfrom(int);151 static JSValue Ptrfrom(unsigned);152 static JSValue Ptrfrom(long);153 static JSValue Ptrfrom(unsigned long);154 static JSValue Ptrfrom(long long);155 static JSValue Ptrfrom(unsigned long long);156 static JSValue Ptrfrom(double);157 158 static ALWAYS_INLINE bool isEitherImmediate(JSValue Ptr v1, JSValuePtrv2)143 static JSValue* from(char); 144 static JSValue* from(signed char); 145 static JSValue* from(unsigned char); 146 static JSValue* from(short); 147 static JSValue* from(unsigned short); 148 static JSValue* from(int); 149 static JSValue* from(unsigned); 150 static JSValue* from(long); 151 static JSValue* from(unsigned long); 152 static JSValue* from(long long); 153 static JSValue* from(unsigned long long); 154 static JSValue* from(double); 155 156 static ALWAYS_INLINE bool isEitherImmediate(JSValue* v1, JSValue* v2) 159 157 { 160 158 return (rawValue(v1) | rawValue(v2)) & TagMask; 161 159 } 162 160 163 static ALWAYS_INLINE bool isAnyImmediate(JSValue Ptr v1, JSValuePtr v2, JSValuePtrv3)161 static ALWAYS_INLINE bool isAnyImmediate(JSValue* v1, JSValue* v2, JSValue* v3) 164 162 { 165 163 return (rawValue(v1) | rawValue(v2) | rawValue(v3)) & TagMask; 166 164 } 167 165 168 static ALWAYS_INLINE bool areBothImmediate(JSValue Ptr v1, JSValuePtrv2)166 static ALWAYS_INLINE bool areBothImmediate(JSValue* v1, JSValue* v2) 169 167 { 170 168 return isImmediate(v1) & isImmediate(v2); 171 169 } 172 170 173 static ALWAYS_INLINE bool areBothImmediateNumbers(JSValue Ptr v1, JSValuePtrv2)171 static ALWAYS_INLINE bool areBothImmediateNumbers(JSValue* v1, JSValue* v2) 174 172 { 175 173 return rawValue(v1) & rawValue(v2) & TagBitTypeInteger; 176 174 } 177 175 178 static ALWAYS_INLINE JSValue Ptr andImmediateNumbers(JSValuePtr v1, JSValuePtrv2)176 static ALWAYS_INLINE JSValue* andImmediateNumbers(JSValue* v1, JSValue* v2) 179 177 { 180 178 ASSERT(areBothImmediateNumbers(v1, v2)); … … 182 180 } 183 181 184 static ALWAYS_INLINE JSValue Ptr xorImmediateNumbers(JSValuePtr v1, JSValuePtrv2)182 static ALWAYS_INLINE JSValue* xorImmediateNumbers(JSValue* v1, JSValue* v2) 185 183 { 186 184 ASSERT(areBothImmediateNumbers(v1, v2)); … … 188 186 } 189 187 190 static ALWAYS_INLINE JSValue Ptr orImmediateNumbers(JSValuePtr v1, JSValuePtrv2)188 static ALWAYS_INLINE JSValue* orImmediateNumbers(JSValue* v1, JSValue* v2) 191 189 { 192 190 ASSERT(areBothImmediateNumbers(v1, v2)); … … 194 192 } 195 193 196 static ALWAYS_INLINE JSValue Ptr rightShiftImmediateNumbers(JSValuePtr val, JSValuePtrshift)194 static ALWAYS_INLINE JSValue* rightShiftImmediateNumbers(JSValue* val, JSValue* shift) 197 195 { 198 196 ASSERT(areBothImmediateNumbers(val, shift)); … … 200 198 } 201 199 202 static ALWAYS_INLINE bool canDoFastAdditiveOperations(JSValue Ptrv)200 static ALWAYS_INLINE bool canDoFastAdditiveOperations(JSValue* v) 203 201 { 204 202 // Number is non-negative and an operation involving two of these can't overflow. … … 207 205 } 208 206 209 static ALWAYS_INLINE JSValue Ptr addImmediateNumbers(JSValuePtr v1, JSValuePtrv2)207 static ALWAYS_INLINE JSValue* addImmediateNumbers(JSValue* v1, JSValue* v2) 210 208 { 211 209 ASSERT(canDoFastAdditiveOperations(v1)); … … 214 212 } 215 213 216 static ALWAYS_INLINE JSValue Ptr subImmediateNumbers(JSValuePtr v1, JSValuePtrv2)214 static ALWAYS_INLINE JSValue* subImmediateNumbers(JSValue* v1, JSValue* v2) 217 215 { 218 216 ASSERT(canDoFastAdditiveOperations(v1)); … … 221 219 } 222 220 223 static ALWAYS_INLINE JSValue Ptr incImmediateNumber(JSValuePtrv)221 static ALWAYS_INLINE JSValue* incImmediateNumber(JSValue* v) 224 222 { 225 223 ASSERT(canDoFastAdditiveOperations(v)); … … 227 225 } 228 226 229 static ALWAYS_INLINE JSValue Ptr decImmediateNumber(JSValuePtrv)227 static ALWAYS_INLINE JSValue* decImmediateNumber(JSValue* v) 230 228 { 231 229 ASSERT(canDoFastAdditiveOperations(v)); … … 233 231 } 234 232 235 static double toDouble(JSValue Ptr);236 static bool toBoolean(JSValue Ptr);237 static JSObject* toObject(JSValue Ptr, ExecState*);238 static UString toString(JSValue Ptr);239 240 static bool getUInt32(JSValue Ptr, uint32_t&);241 static bool getTruncatedInt32(JSValue Ptr, int32_t&);242 static bool getTruncatedUInt32(JSValue Ptr, uint32_t&);243 244 static int32_t getTruncatedInt32(JSValue Ptr);245 static uint32_t getTruncatedUInt32(JSValue Ptr);246 247 static JSValue PtrtrueImmediate();248 static JSValue PtrfalseImmediate();249 static JSValue PtrundefinedImmediate();250 static JSValue PtrnullImmediate();251 static JSValue PtrzeroImmediate();252 static JSValue PtroneImmediate();253 254 static JSValue PtrimpossibleValue();255 256 static JSObject* prototype(JSValue Ptr, ExecState*);233 static double toDouble(JSValue*); 234 static bool toBoolean(JSValue*); 235 static JSObject* toObject(JSValue*, ExecState*); 236 static UString toString(JSValue*); 237 238 static bool getUInt32(JSValue*, uint32_t&); 239 static bool getTruncatedInt32(JSValue*, int32_t&); 240 static bool getTruncatedUInt32(JSValue*, uint32_t&); 241 242 static int32_t getTruncatedInt32(JSValue*); 243 static uint32_t getTruncatedUInt32(JSValue*); 244 245 static JSValue* trueImmediate(); 246 static JSValue* falseImmediate(); 247 static JSValue* undefinedImmediate(); 248 static JSValue* nullImmediate(); 249 static JSValue* zeroImmediate(); 250 static JSValue* oneImmediate(); 251 252 static JSValue* impossibleValue(); 253 254 static JSObject* prototype(JSValue*, ExecState*); 257 255 258 256 private: … … 261 259 static const unsigned maxImmediateUInt = maxImmediateInt; 262 260 263 static ALWAYS_INLINE JSValue PtrmakeValue(uintptr_t integer)261 static ALWAYS_INLINE JSValue* makeValue(uintptr_t integer) 264 262 { 265 263 return reinterpret_cast<JSValue*>(integer); 266 264 } 267 265 268 static ALWAYS_INLINE JSValue PtrmakeInt(int32_t value)266 static ALWAYS_INLINE JSValue* makeInt(int32_t value) 269 267 { 270 268 return makeValue((value << IntegerPayloadShift) | TagBitTypeInteger); 271 269 } 272 270 273 static ALWAYS_INLINE JSValue PtrmakeBool(bool b)271 static ALWAYS_INLINE JSValue* makeBool(bool b) 274 272 { 275 273 return makeValue((static_cast<uintptr_t>(b) << ExtendedPayloadShift) | FullTagTypeBool); 276 274 } 277 275 278 static ALWAYS_INLINE JSValue PtrmakeUndefined()276 static ALWAYS_INLINE JSValue* makeUndefined() 279 277 { 280 278 return makeValue(FullTagTypeUndefined); 281 279 } 282 280 283 static ALWAYS_INLINE JSValue PtrmakeNull()281 static ALWAYS_INLINE JSValue* makeNull() 284 282 { 285 283 return makeValue(FullTagTypeNull); 286 284 } 287 285 288 static ALWAYS_INLINE int32_t intValue(JSValue Ptrv)286 static ALWAYS_INLINE int32_t intValue(JSValue* v) 289 287 { 290 288 return static_cast<int32_t>(static_cast<intptr_t>(rawValue(v)) >> IntegerPayloadShift); 291 289 } 292 290 293 static ALWAYS_INLINE uint32_t uintValue(JSValue Ptrv)291 static ALWAYS_INLINE uint32_t uintValue(JSValue* v) 294 292 { 295 293 return static_cast<uint32_t>(rawValue(v) >> IntegerPayloadShift); 296 294 } 297 295 298 static ALWAYS_INLINE bool boolValue(JSValue Ptrv)296 static ALWAYS_INLINE bool boolValue(JSValue* v) 299 297 { 300 298 return rawValue(v) & ExtendedPayloadBitBoolValue; 301 299 } 302 300 303 static ALWAYS_INLINE uintptr_t rawValue(JSValue Ptrv)301 static ALWAYS_INLINE uintptr_t rawValue(JSValue* v) 304 302 { 305 303 return reinterpret_cast<uintptr_t>(v); … … 309 307 }; 310 308 311 ALWAYS_INLINE JSValue PtrJSImmediate::trueImmediate() { return makeBool(true); }312 ALWAYS_INLINE JSValue PtrJSImmediate::falseImmediate() { return makeBool(false); }313 ALWAYS_INLINE JSValue PtrJSImmediate::undefinedImmediate() { return makeUndefined(); }314 ALWAYS_INLINE JSValue PtrJSImmediate::nullImmediate() { return makeNull(); }315 ALWAYS_INLINE JSValue PtrJSImmediate::zeroImmediate() { return makeInt(0); }316 ALWAYS_INLINE JSValue PtrJSImmediate::oneImmediate() { return makeInt(1); }309 ALWAYS_INLINE JSValue* JSImmediate::trueImmediate() { return makeBool(true); } 310 ALWAYS_INLINE JSValue* JSImmediate::falseImmediate() { return makeBool(false); } 311 ALWAYS_INLINE JSValue* JSImmediate::undefinedImmediate() { return makeUndefined(); } 312 ALWAYS_INLINE JSValue* JSImmediate::nullImmediate() { return makeNull(); } 313 ALWAYS_INLINE JSValue* JSImmediate::zeroImmediate() { return makeInt(0); } 314 ALWAYS_INLINE JSValue* JSImmediate::oneImmediate() { return makeInt(1); } 317 315 318 316 // This value is impossible because 0x4 is not a valid pointer but a tag of 0 would indicate non-immediate 319 ALWAYS_INLINE JSValue PtrJSImmediate::impossibleValue() { return makeValue(0x4); }320 321 ALWAYS_INLINE bool JSImmediate::toBoolean(JSValue Ptrv)317 ALWAYS_INLINE JSValue* JSImmediate::impossibleValue() { return makeValue(0x4); } 318 319 ALWAYS_INLINE bool JSImmediate::toBoolean(JSValue* v) 322 320 { 323 321 ASSERT(isImmediate(v)); … … 328 326 } 329 327 330 ALWAYS_INLINE uint32_t JSImmediate::getTruncatedUInt32(JSValue Ptrv)328 ALWAYS_INLINE uint32_t JSImmediate::getTruncatedUInt32(JSValue* v) 331 329 { 332 330 ASSERT(isNumber(v)); … … 334 332 } 335 333 336 ALWAYS_INLINE JSValue PtrJSImmediate::from(char i)337 { 338 return makeInt(i); 339 } 340 341 ALWAYS_INLINE JSValue PtrJSImmediate::from(signed char i)342 { 343 return makeInt(i); 344 } 345 346 ALWAYS_INLINE JSValue PtrJSImmediate::from(unsigned char i)347 { 348 return makeInt(i); 349 } 350 351 ALWAYS_INLINE JSValue PtrJSImmediate::from(short i)352 { 353 return makeInt(i); 354 } 355 356 ALWAYS_INLINE JSValue PtrJSImmediate::from(unsigned short i)357 { 358 return makeInt(i); 359 } 360 361 ALWAYS_INLINE JSValue PtrJSImmediate::from(int i)334 ALWAYS_INLINE JSValue* JSImmediate::from(char i) 335 { 336 return makeInt(i); 337 } 338 339 ALWAYS_INLINE JSValue* JSImmediate::from(signed char i) 340 { 341 return makeInt(i); 342 } 343 344 ALWAYS_INLINE JSValue* JSImmediate::from(unsigned char i) 345 { 346 return makeInt(i); 347 } 348 349 ALWAYS_INLINE JSValue* JSImmediate::from(short i) 350 { 351 return makeInt(i); 352 } 353 354 ALWAYS_INLINE JSValue* JSImmediate::from(unsigned short i) 355 { 356 return makeInt(i); 357 } 358 359 ALWAYS_INLINE JSValue* JSImmediate::from(int i) 362 360 { 363 361 if ((i < minImmediateInt) | (i > maxImmediateInt)) … … 366 364 } 367 365 368 ALWAYS_INLINE JSValue PtrJSImmediate::from(unsigned i)366 ALWAYS_INLINE JSValue* JSImmediate::from(unsigned i) 369 367 { 370 368 if (i > maxImmediateUInt) … … 373 371 } 374 372 375 ALWAYS_INLINE JSValue PtrJSImmediate::from(long i)373 ALWAYS_INLINE JSValue* JSImmediate::from(long i) 376 374 { 377 375 if ((i < minImmediateInt) | (i > maxImmediateInt)) … … 380 378 } 381 379 382 ALWAYS_INLINE JSValue PtrJSImmediate::from(unsigned long i)380 ALWAYS_INLINE JSValue* JSImmediate::from(unsigned long i) 383 381 { 384 382 if (i > maxImmediateUInt) … … 387 385 } 388 386 389 ALWAYS_INLINE JSValue PtrJSImmediate::from(long long i)387 ALWAYS_INLINE JSValue* JSImmediate::from(long long i) 390 388 { 391 389 if ((i < minImmediateInt) | (i > maxImmediateInt)) … … 394 392 } 395 393 396 ALWAYS_INLINE JSValue PtrJSImmediate::from(unsigned long long i)394 ALWAYS_INLINE JSValue* JSImmediate::from(unsigned long long i) 397 395 { 398 396 if (i > maxImmediateUInt) … … 401 399 } 402 400 403 ALWAYS_INLINE JSValue PtrJSImmediate::from(double d)401 ALWAYS_INLINE JSValue* JSImmediate::from(double d) 404 402 { 405 403 const int intVal = static_cast<int>(d); … … 415 413 } 416 414 417 ALWAYS_INLINE int32_t JSImmediate::getTruncatedInt32(JSValue Ptrv)415 ALWAYS_INLINE int32_t JSImmediate::getTruncatedInt32(JSValue* v) 418 416 { 419 417 ASSERT(isNumber(v)); … … 421 419 } 422 420 423 ALWAYS_INLINE double JSImmediate::toDouble(JSValue Ptrv)421 ALWAYS_INLINE double JSImmediate::toDouble(JSValue* v) 424 422 { 425 423 ASSERT(isImmediate(v)); … … 434 432 } 435 433 436 ALWAYS_INLINE bool JSImmediate::getUInt32(JSValue Ptrv, uint32_t& i)434 ALWAYS_INLINE bool JSImmediate::getUInt32(JSValue* v, uint32_t& i) 437 435 { 438 436 i = uintValue(v); … … 440 438 } 441 439 442 ALWAYS_INLINE bool JSImmediate::getTruncatedInt32(JSValue Ptrv, int32_t& i)440 ALWAYS_INLINE bool JSImmediate::getTruncatedInt32(JSValue* v, int32_t& i) 443 441 { 444 442 i = intValue(v); … … 446 444 } 447 445 448 ALWAYS_INLINE bool JSImmediate::getTruncatedUInt32(JSValue Ptrv, uint32_t& i)446 ALWAYS_INLINE bool JSImmediate::getTruncatedUInt32(JSValue* v, uint32_t& i) 449 447 { 450 448 return getUInt32(v, i); 451 449 } 452 450 453 ALWAYS_INLINE JSValue PtrjsUndefined()451 ALWAYS_INLINE JSValue* jsUndefined() 454 452 { 455 453 return JSImmediate::undefinedImmediate(); 456 454 } 457 455 458 inline JSValue PtrjsNull()456 inline JSValue* jsNull() 459 457 { 460 458 return JSImmediate::nullImmediate(); 461 459 } 462 460 463 inline JSValue PtrjsBoolean(bool b)461 inline JSValue* jsBoolean(bool b) 464 462 { 465 463 return b ? JSImmediate::trueImmediate() : JSImmediate::falseImmediate();
Note:
See TracChangeset
for help on using the changeset viewer.