Changeset 476
- Timestamp:
- 01/06/11 07:04:31 (14 years ago)
- Files:
-
- trunk/import/object.di (modified) (1 diff)
- trunk/posix.mak (modified) (1 diff)
- trunk/src/object_.d (modified) (1 diff)
- trunk/src/rt/aaA.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/import/object.di
r473 r476 330 330 extern (C) 331 331 { 332 332 // from druntime/src/compiler/dmd/aaA.d 333 333 334 334 size_t _aaLen(void* p); 335 335 void* _aaGet(void** pp, TypeInfo keyti, size_t valuesize, ...); 336 336 void* _aaGetRvalue(void* p, TypeInfo keyti, size_t valuesize, ...); 337 337 void* _aaIn(void* p, TypeInfo keyti); 338 338 void _aaDel(void* p, TypeInfo keyti, ...); 339 339 void[] _aaValues(void* p, size_t keysize, size_t valuesize); 340 void[] _aaKeys(void* p, size_t keysize , size_t valuesize);340 void[] _aaKeys(void* p, size_t keysize); 341 341 void* _aaRehash(void** pp, TypeInfo keyti); 342 342 343 343 extern (D) typedef scope int delegate(void *) _dg_t; 344 344 int _aaApply(void* aa, size_t keysize, _dg_t dg); 345 345 346 346 extern (D) typedef scope int delegate(void *, void *) _dg2_t; 347 347 int _aaApply2(void* aa, size_t keysize, _dg2_t dg); 348 348 349 349 void* _d_assocarrayliteralT(TypeInfo_AssociativeArray ti, size_t length, ...); 350 350 } 351 351 352 352 struct AssociativeArray(Key, Value) 353 353 { 354 354 void* p; 355 355 356 size_t aligntsize(size_t tsize)357 {358 version (X86_64)359 // Size of key needed to align value on 16 bytes360 return (tsize + 15) & ~(15);361 else362 return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1);363 }364 365 356 size_t length() @property { return _aaLen(p); } 366 357 367 358 Value[Key] rehash() @property 368 359 { 369 360 auto p = _aaRehash(&p, typeid(Value[Key])); 370 361 return *cast(Value[Key]*)(&p); 371 362 } 372 363 373 364 Value[] values() @property 374 365 { 375 auto a = _aaValues(p, aligntsize(Key.sizeof), Value.sizeof);366 auto a = _aaValues(p, Key.sizeof, Value.sizeof); 376 367 return *cast(Value[]*) &a; 377 368 } 378 369 379 370 Key[] keys() @property 380 371 { 381 auto a = _aaKeys(p, aligntsize(Key.sizeof), Value.sizeof);372 auto a = _aaKeys(p, Key.sizeof); 382 373 return *cast(Key[]*) &a; 383 374 } 384 375 385 376 int opApply(scope int delegate(ref Key, ref Value) dg) 386 377 { 387 return _aaApply2(p, aligntsize(Key.sizeof), cast(_dg2_t)dg);378 return _aaApply2(p, Key.sizeof, cast(_dg2_t)dg); 388 379 } 389 380 390 381 int opApply(scope int delegate(ref Value) dg) 391 382 { 392 return _aaApply(p, aligntsize(Key.sizeof), cast(_dg_t)dg);383 return _aaApply(p, Key.sizeof, cast(_dg_t)dg); 393 384 } 394 385 395 386 int delegate(int delegate(ref Key) dg) byKey() 396 387 { 397 388 int foo(int delegate(ref Key) dg) 398 389 { 399 390 int byKeydg(ref Key key, ref Value value) 400 391 { 401 392 return dg(key); 402 393 } 403 394 404 return _aaApply2(p, aligntsize(Key.sizeof), cast(_dg2_t)&byKeydg);395 return _aaApply2(p, Key.sizeof, cast(_dg2_t)&byKeydg); 405 396 } 406 397 407 398 return &foo; 408 399 } 409 400 410 401 int delegate(int delegate(ref Value) dg) byValue() 411 402 { 412 403 return &opApply; 413 404 } 414 405 trunk/posix.mak
r469 r476 391 391 $(DRUNTIME): $(OBJS) $(SRCS) win32.mak 392 392 $(DMD) -lib -of$(DRUNTIME) -Xfdruntime.json $(DFLAGS) $(SRCS) $(OBJS) 393 393 394 394 unittest : $(addprefix $(OBJDIR)/,$(SRC_D_MODULES)) $(DRUNTIME) $(OBJDIR)/emptymain.d 395 395 @echo done 396 396 397 397 ifeq ($(MODEL),64) 398 398 DISABLED_TESTS = \ 399 399 core/sync/barrier \ 400 400 core/sync/condition \ 401 core/sync/mutex \402 401 core/sync/rwmutex \ 403 402 core/sync/semaphore \ 404 403 rt/adi \ 405 404 rt/dmain2 406 405 else 407 406 DISABLED_TESTS = \ 408 407 rt/dmain2 409 408 endif 410 409 411 410 $(addprefix $(OBJDIR)/,$(DISABLED_TESTS)) : trunk/src/object_.d
r473 r476 2375 2375 extern (C) 2376 2376 { 2377 2377 // from druntime/src/compiler/dmd/aaA.d 2378 2378 2379 2379 size_t _aaLen(void* p); 2380 2380 void* _aaGet(void** pp, TypeInfo keyti, size_t valuesize, ...); 2381 2381 void* _aaGetRvalue(void* p, TypeInfo keyti, size_t valuesize, ...); 2382 2382 void* _aaIn(void* p, TypeInfo keyti); 2383 2383 void _aaDel(void* p, TypeInfo keyti, ...); 2384 2384 void[] _aaValues(void* p, size_t keysize, size_t valuesize); 2385 void[] _aaKeys(void* p, size_t keysize , size_t valuesize);2385 void[] _aaKeys(void* p, size_t keysize); 2386 2386 void* _aaRehash(void** pp, TypeInfo keyti); 2387 2387 2388 2388 extern (D) typedef scope int delegate(void *) _dg_t; 2389 2389 int _aaApply(void* aa, size_t keysize, _dg_t dg); 2390 2390 2391 2391 extern (D) typedef scope int delegate(void *, void *) _dg2_t; 2392 2392 int _aaApply2(void* aa, size_t keysize, _dg2_t dg); 2393 2393 2394 2394 void* _d_assocarrayliteralT(TypeInfo_AssociativeArray ti, size_t length, ...); 2395 2395 } 2396 2396 2397 2397 struct AssociativeArray(Key, Value) 2398 2398 { 2399 2399 void* p; 2400 2400 2401 size_t aligntsize(size_t tsize)2402 {2403 version (X86_64)2404 // Size of key needed to align value on 16 bytes2405 return (tsize + 15) & ~(15);2406 else2407 return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1);2408 }2409 2410 2401 size_t length() @property { return _aaLen(p); } 2411 2402 2412 2403 Value[Key] rehash() @property 2413 2404 { 2414 2405 auto p = _aaRehash(&p, typeid(Value[Key])); 2415 2406 return *cast(Value[Key]*)(&p); 2416 2407 } 2417 2408 2418 2409 Value[] values() @property 2419 2410 { 2420 auto a = _aaValues(p, aligntsize(Key.sizeof), Value.sizeof);2411 auto a = _aaValues(p, Key.sizeof, Value.sizeof); 2421 2412 return *cast(Value[]*) &a; 2422 2413 } 2423 2414 2424 2415 Key[] keys() @property 2425 2416 { 2426 auto a = _aaKeys(p, aligntsize(Key.sizeof), Value.sizeof);2417 auto a = _aaKeys(p, Key.sizeof); 2427 2418 return *cast(Key[]*) &a; 2428 2419 } 2429 2420 2430 2421 int opApply(scope int delegate(ref Key, ref Value) dg) 2431 2422 { 2432 return _aaApply2(p, aligntsize(Key.sizeof), cast(_dg2_t)dg);2423 return _aaApply2(p, Key.sizeof, cast(_dg2_t)dg); 2433 2424 } 2434 2425 2435 2426 int opApply(scope int delegate(ref Value) dg) 2436 2427 { 2437 return _aaApply(p, aligntsize(Key.sizeof), cast(_dg_t)dg);2428 return _aaApply(p, Key.sizeof, cast(_dg_t)dg); 2438 2429 } 2439 2430 2440 2431 int delegate(int delegate(ref Key) dg) byKey() 2441 2432 { 2442 2433 // Discard the Value part and just do the Key 2443 2434 int foo(int delegate(ref Key) dg) 2444 2435 { 2445 2436 int byKeydg(ref Key key, ref Value value) 2446 2437 { 2447 2438 return dg(key); 2448 2439 } 2449 2440 2450 return _aaApply2(p, aligntsize(Key.sizeof), cast(_dg2_t)&byKeydg);2441 return _aaApply2(p, Key.sizeof, cast(_dg2_t)&byKeydg); 2451 2442 } 2452 2443 2453 2444 return &foo; 2454 2445 } 2455 2446 2456 2447 int delegate(int delegate(ref Value) dg) byValue() 2457 2448 { 2458 2449 return &opApply; 2459 2450 } 2460 2451 trunk/src/rt/aaA.d
r474 r476 255 255 if (c == 0) 256 256 goto Lret; 257 257 } 258 258 pe = &e.next; 259 259 } 260 260 261 261 // Not found, create new elem 262 262 //printf("create new one\n"); 263 263 size_t size = aaA.sizeof + keysize + valuesize; 264 264 e = cast(aaA *) gc_calloc(size); 265 memcpy(e + 1, pkey, keysize); 265 memcpy(e + 1, pkey, keyti.tsize); 266 memset(cast(byte*)(e + 1) + keyti.tsize, 0, keysize - keyti.tsize); 266 267 e.hash = key_hash; 267 268 *pe = e; 268 269 269 270 auto nodes = ++aa.a.nodes; 270 271 //printf("length = %d, nodes = %d\n", aa.a.b.length, nodes); 271 272 if (nodes > aa.a.b.length * 4) 272 273 { 273 274 //printf("rehash\n"); 274 275 _aaRehash(aa,keyti); 275 276 } … … 406 407 } 407 408 } 408 409 } 409 410 410 411 411 412 /******************************************** 412 413 * Produce array of values from aa. 413 414 */ 414 415 415 416 ArrayRet_t _aaValues(AA aa, size_t keysize, size_t valuesize) 416 in417 {418 assert(keysize == aligntsize(keysize));419 }420 body421 417 { 422 418 size_t resi; 423 419 Array a; 420 421 auto alignsize = aligntsize(keysize); 424 422 425 423 if (aa.a) 426 424 { 427 425 a.length = _aaLen(aa); 428 426 a.ptr = cast(byte*) gc_malloc(a.length * valuesize, 429 427 valuesize < (void*).sizeof ? BlkAttr.NO_SCAN : 0); 430 428 resi = 0; 431 429 foreach (e; aa.a.b) 432 430 { 433 431 while (e) 434 432 { 435 433 memcpy(a.ptr + resi * valuesize, 436 cast(byte*)e + aaA.sizeof + keysize,434 cast(byte*)e + aaA.sizeof + alignsize, 437 435 valuesize); 438 436 resi++; 439 437 e = e.next; 440 438 } 441 439 } 442 440 assert(resi == a.length); 443 441 } 444 442 return *cast(ArrayRet_t*)(&a); 445 443 } 446 444 … … 556 554 557 555 558 556 /********************************************** 559 557 * 'apply' for associative arrays - to support foreach 560 558 */ 561 559 562 560 // dg is D, but _aaApply() is C 563 561 extern (D) typedef int delegate(void *) dg_t; 564 562 565 563 int _aaApply(AA aa, size_t keysize, dg_t dg) 566 in567 {568 assert(aligntsize(keysize) == keysize);569 }570 body571 564 { int result; 572 565 573 566 //printf("_aaApply(aa = x%llx, keysize = %d, dg = x%llx)\n", aa.a, keysize, dg); 567 568 auto alignsize = aligntsize(keysize); 574 569 575 570 if (aa.a) 576 571 { 577 572 Loop: 578 573 foreach (e; aa.a.b) 579 574 { 580 575 while (e) 581 576 { 582 result = dg(cast(void *)(e + 1) + keysize);577 result = dg(cast(void *)(e + 1) + alignsize); 583 578 if (result) 584 579 break Loop; 585 580 e = e.next; 586 581 } 587 582 } 588 583 } 589 584 return result; 590 585 } 591 586 592 587 // dg is D, but _aaApply2() is C 593 588 extern (D) typedef int delegate(void *, void *) dg2_t; 594 589 595 590 int _aaApply2(AA aa, size_t keysize, dg2_t dg) 596 in597 {598 assert(aligntsize(keysize) == keysize);599 }600 body601 591 { int result; 602 592 603 593 //printf("_aaApply(aa = x%llx, keysize = %d, dg = x%llx)\n", aa.a, keysize, dg); 594 595 auto alignsize = aligntsize(keysize); 604 596 605 597 if (aa.a) 606 598 { 607 599 Loop: 608 600 foreach (e; aa.a.b) 609 601 { 610 602 while (e) 611 603 { 612 result = dg(cast(void *)(e + 1), cast(void *)(e + 1) + keysize);604 result = dg(cast(void *)(e + 1), cast(void *)(e + 1) + alignsize); 613 605 if (result) 614 606 break Loop; 615 607 e = e.next; 616 608 } 617 609 } 618 610 } 619 611 return result; 620 612 } 621 613 622 614
