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