| 1 |
// REQUIRED_ARGS: |
| 2 |
|
| 3 |
import core.stdc.stdarg; |
| 4 |
|
| 5 |
extern(C) |
| 6 |
{ |
| 7 |
int printf(const char*, ...); |
| 8 |
version(Windows) |
| 9 |
{ |
| 10 |
int _snprintf(char*, size_t, const char*, ...); |
| 11 |
alias _snprintf snprintf; |
| 12 |
} |
| 13 |
else |
| 14 |
int snprintf(char*, size_t, const char*, ...); |
| 15 |
} |
| 16 |
|
| 17 |
/*************************************/ |
| 18 |
|
| 19 |
// https://www.digitalmars.com/d/archives/digitalmars/D/bugs/4766.html |
| 20 |
// Only with -O |
| 21 |
|
| 22 |
real randx() |
| 23 |
{ |
| 24 |
return 1.2; |
| 25 |
} |
| 26 |
|
| 27 |
void test1() |
| 28 |
{ |
| 29 |
float x10=randx(); |
| 30 |
float x11=randx(); |
| 31 |
float x20=randx(); |
| 32 |
float x21=randx(); |
| 33 |
float y10=randx(); |
| 34 |
float y11=randx(); |
| 35 |
float y20=randx(); |
| 36 |
float y21=randx(); |
| 37 |
|
| 38 |
float tmp=( |
| 39 |
x20*x21 + y10*y10 + y10*y11 + y11*y11 + |
| 40 |
y11*y20 + y20*y20 + y10*y21 + y11*y21 + |
| 41 |
y21*y21); |
| 42 |
assert(tmp > 0); |
| 43 |
} |
| 44 |
|
| 45 |
/*************************************/ |
| 46 |
|
| 47 |
void test2() |
| 48 |
{ |
| 49 |
double x10=randx(); |
| 50 |
double x11=randx(); |
| 51 |
double x20=randx(); |
| 52 |
double x21=randx(); |
| 53 |
double y10=randx(); |
| 54 |
double y11=randx(); |
| 55 |
double y20=randx(); |
| 56 |
double y21=randx(); |
| 57 |
|
| 58 |
double tmp=( |
| 59 |
x20*x21 + y10*y10 + y10*y11 + y11*y11 + |
| 60 |
y11*y20 + y20*y20 + y10*y21 + y11*y21 + |
| 61 |
y21*y21); |
| 62 |
assert(tmp > 0); |
| 63 |
} |
| 64 |
|
| 65 |
/*************************************/ |
| 66 |
|
| 67 |
void test3() |
| 68 |
{ |
| 69 |
real x10=randx(); |
| 70 |
real x11=randx(); |
| 71 |
real x20=randx(); |
| 72 |
real x21=randx(); |
| 73 |
real y10=randx(); |
| 74 |
real y11=randx(); |
| 75 |
real y20=randx(); |
| 76 |
real y21=randx(); |
| 77 |
|
| 78 |
real tmp=( |
| 79 |
x20*x21 + y10*y10 + y10*y11 + y11*y11 + |
| 80 |
y11*y20 + y20*y20 + y10*y21 + y11*y21 + |
| 81 |
y21*y21); |
| 82 |
assert(tmp > 0); |
| 83 |
} |
| 84 |
|
| 85 |
/*************************************/ |
| 86 |
|
| 87 |
void test4() |
| 88 |
{ |
| 89 |
printf("main() : (-128 >= 0)=%s, (-128 <= 0)=%s\n", |
| 90 |
cast(char*)(-128 >= 0 ? "true" : "false"), |
| 91 |
cast(char*)(-128 <= 0 ? "true" : "false")); |
| 92 |
|
| 93 |
printf("main() : (128 >= 0)=%s, (128 <= 0)=%s\n", |
| 94 |
cast(char*)(128 >= 0 ? "true" : "false"), |
| 95 |
cast(char*)(128 <= 0 ? "true" : "false")); |
| 96 |
|
| 97 |
assert((-128 >= 0 ? "true" : "false") == "false"), |
| 98 |
assert((-128 <= 0 ? "true" : "false") == "true"); |
| 99 |
assert((+128 >= 0 ? "true" : "false") == "true"), |
| 100 |
assert((+128 <= 0 ? "true" : "false") == "false"); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
/*************************************/ |
| 105 |
|
| 106 |
int foo5() { assert(0); } // No return. |
| 107 |
|
| 108 |
int abc5() |
| 109 |
{ |
| 110 |
printf("foo = %d\n", foo5()); |
| 111 |
return 0; |
| 112 |
} |
| 113 |
|
| 114 |
void test5() |
| 115 |
{ |
| 116 |
} |
| 117 |
|
| 118 |
/*************************************/ |
| 119 |
|
| 120 |
class A9 |
| 121 |
{ |
| 122 |
this(int[] params ...) |
| 123 |
{ |
| 124 |
for (int i = 0; i < params.length; i++) |
| 125 |
{ |
| 126 |
assert(params[i] == i + 1); |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
class B9 |
| 132 |
{ |
| 133 |
this() |
| 134 |
{ |
| 135 |
init(); |
| 136 |
} |
| 137 |
|
| 138 |
private void init() |
| 139 |
{ |
| 140 |
A9 test1 = new A9(1, 2, 3); |
| 141 |
A9 test2 = new A9(1, 2, 3, 4); |
| 142 |
int[3] arg; |
| 143 |
arg[0]=1, arg[1]=2, arg[2]=3; |
| 144 |
A9 test3 = new A9(arg); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
void test9() |
| 149 |
{ |
| 150 |
B9 test2 = new B9(); |
| 151 |
} |
| 152 |
|
| 153 |
/*************************************/ |
| 154 |
|
| 155 |
void test10() |
| 156 |
{ |
| 157 |
auto i = 5u; |
| 158 |
auto s = typeid(typeof(i)).toString; |
| 159 |
printf("%.*s\n", cast(int)s.length, s.ptr); |
| 160 |
assert(typeid(typeof(i)) == typeid(uint)); |
| 161 |
} |
| 162 |
|
| 163 |
/*************************************/ |
| 164 |
|
| 165 |
void test11() |
| 166 |
{ |
| 167 |
printf("%d\n", 3); |
| 168 |
printf("xhello world!\n"); |
| 169 |
} |
| 170 |
|
| 171 |
/*************************************/ |
| 172 |
|
| 173 |
real x16; |
| 174 |
|
| 175 |
void foo16() |
| 176 |
{ |
| 177 |
x16 = -x16; |
| 178 |
} |
| 179 |
|
| 180 |
void bar16() |
| 181 |
{ |
| 182 |
return foo16(); |
| 183 |
} |
| 184 |
|
| 185 |
void test16() |
| 186 |
{ |
| 187 |
x16=2; |
| 188 |
bar16(); |
| 189 |
assert(x16==-2); |
| 190 |
} |
| 191 |
|
| 192 |
/*************************************/ |
| 193 |
|
| 194 |
class Bar17 |
| 195 |
{ |
| 196 |
this(...) {} |
| 197 |
} |
| 198 |
|
| 199 |
class Foo17 |
| 200 |
{ |
| 201 |
void opBinary(string op : "+") (Bar17 b) {} |
| 202 |
} |
| 203 |
|
| 204 |
void test17() |
| 205 |
{ |
| 206 |
auto f = new Foo17; |
| 207 |
f + new Bar17; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
/*************************************/ |
| 212 |
|
| 213 |
template u18(int n) |
| 214 |
{ |
| 215 |
static if (n==1) { |
| 216 |
int a = 1; |
| 217 |
} else |
| 218 |
int b = 4; |
| 219 |
} |
| 220 |
|
| 221 |
void test18() |
| 222 |
{ |
| 223 |
mixin u18!(2); |
| 224 |
assert(b == 4); |
| 225 |
} |
| 226 |
|
| 227 |
/*************************************/ |
| 228 |
|
| 229 |
class DP |
| 230 |
{ |
| 231 |
private: |
| 232 |
void I(char[] p) |
| 233 |
{ |
| 234 |
I(p[1..p.length]); |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
void test19() |
| 239 |
{ |
| 240 |
} |
| 241 |
|
| 242 |
/*************************************/ |
| 243 |
|
| 244 |
struct Struct20 |
| 245 |
{ |
| 246 |
int i; |
| 247 |
} |
| 248 |
|
| 249 |
void test20() |
| 250 |
{ |
| 251 |
auto s = new Struct20; |
| 252 |
s.i = 7; |
| 253 |
} |
| 254 |
|
| 255 |
/*************************************/ |
| 256 |
|
| 257 |
class C21(float f) |
| 258 |
{ |
| 259 |
float ff = f; |
| 260 |
} |
| 261 |
|
| 262 |
void test21() |
| 263 |
{ |
| 264 |
auto a = new C21!(1.2); |
| 265 |
C21!(1.2) b = new C21!(1.2); |
| 266 |
} |
| 267 |
|
| 268 |
/*************************************/ |
| 269 |
|
| 270 |
const int c23 = b23 * b23; |
| 271 |
const int a23 = 1; |
| 272 |
const int b23 = a23 * 3; |
| 273 |
|
| 274 |
template T23(int n) |
| 275 |
{ |
| 276 |
int[n] x23; |
| 277 |
} |
| 278 |
|
| 279 |
mixin T23!(c23); |
| 280 |
|
| 281 |
void test23() |
| 282 |
{ |
| 283 |
assert(x23.length==9); |
| 284 |
} |
| 285 |
|
| 286 |
/*************************************/ |
| 287 |
|
| 288 |
template cat(int n) |
| 289 |
{ |
| 290 |
const int dog = n; |
| 291 |
} |
| 292 |
|
| 293 |
const char [] bird = "canary"; |
| 294 |
|
| 295 |
const int sheep = cat!(bird.length).dog; |
| 296 |
|
| 297 |
void test25() |
| 298 |
{ |
| 299 |
assert(sheep == 6); |
| 300 |
} |
| 301 |
|
| 302 |
/*************************************/ |
| 303 |
|
| 304 |
void test27() |
| 305 |
{ int x; |
| 306 |
|
| 307 |
string s = (int*function(int ...)[]).mangleof; |
| 308 |
printf("%.*s\n", cast(int)s.length, s.ptr); |
| 309 |
assert((int*function(int ...)[]).mangleof == "APFiXPi"); |
| 310 |
assert(typeof(x).mangleof == "i"); |
| 311 |
assert(x.mangleof == "_D6test226test27FZ1xi"); |
| 312 |
} |
| 313 |
|
| 314 |
/*************************************/ |
| 315 |
|
| 316 |
void test29() |
| 317 |
{ |
| 318 |
ulong a = 10_000_000_000_000_000, |
| 319 |
b = 1_000_000_000_000_000; |
| 320 |
|
| 321 |
printf("test29\n%llx\n%llx\n%llx\n", a, b, a / b); |
| 322 |
assert((a / b) == 10); |
| 323 |
} |
| 324 |
|
| 325 |
static assert((10_000_000_000_000_000 / 1_000_000_000_000_000) == 10); |
| 326 |
|
| 327 |
/*************************************/ |
| 328 |
|
| 329 |
template chook(int n) |
| 330 |
{ |
| 331 |
const int chook = 3; |
| 332 |
} |
| 333 |
|
| 334 |
template dog(alias f) { |
| 335 |
const int dog = chook!(f.mangleof.length); |
| 336 |
} |
| 337 |
|
| 338 |
class pig {} |
| 339 |
|
| 340 |
const int goose = dog!(pig); |
| 341 |
|
| 342 |
void test30() |
| 343 |
{ |
| 344 |
printf("%d\n", goose); |
| 345 |
assert(goose == 3); |
| 346 |
} |
| 347 |
|
| 348 |
/*************************************/ |
| 349 |
|
| 350 |
template dog31(string sheep) |
| 351 |
{ |
| 352 |
immutable string dog31 = "daschund"; |
| 353 |
} |
| 354 |
|
| 355 |
void test31() |
| 356 |
{ |
| 357 |
string duck = dog31!("bird"[1..3]); |
| 358 |
|
| 359 |
assert(duck == "daschund"); |
| 360 |
} |
| 361 |
|
| 362 |
/*************************************/ |
| 363 |
|
| 364 |
struct particle |
| 365 |
{ |
| 366 |
int active; /* Active (Yes/No) */ |
| 367 |
float life; /* Particle Life */ |
| 368 |
float fade; /* Fade Speed */ |
| 369 |
|
| 370 |
float r; /* Red Value */ |
| 371 |
float g; /* Green Value */ |
| 372 |
float b; /* Blue Value */ |
| 373 |
|
| 374 |
float x; /* X Position */ |
| 375 |
float y; /* Y Position */ |
| 376 |
|
| 377 |
float xi; /* X Direction */ |
| 378 |
float yi; /* Y Direction */ |
| 379 |
|
| 380 |
float xg; /* X Gravity */ |
| 381 |
float yg; /* Y Gravity */ |
| 382 |
} |
| 383 |
|
| 384 |
particle[10000] particles; |
| 385 |
|
| 386 |
void test32() |
| 387 |
{ |
| 388 |
} |
| 389 |
|
| 390 |
/*************************************/ |
| 391 |
|
| 392 |
class Foo33 |
| 393 |
{ |
| 394 |
template foo() |
| 395 |
{ |
| 396 |
int foo() { return 6; } |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
void test33() |
| 402 |
{ |
| 403 |
Foo33 f = new Foo33; |
| 404 |
|
| 405 |
assert(f.foo!()() == 6); |
| 406 |
with (f) |
| 407 |
assert(foo!()() == 6); |
| 408 |
} |
| 409 |
|
| 410 |
/*************************************/ |
| 411 |
|
| 412 |
template dog34(string duck) |
| 413 |
{ |
| 414 |
const int dog34 = 2; |
| 415 |
} |
| 416 |
|
| 417 |
void test34() |
| 418 |
{ |
| 419 |
int aardvark = dog34!("cat" ~ "pig"); |
| 420 |
|
| 421 |
assert(aardvark == 2); |
| 422 |
} |
| 423 |
|
| 424 |
/*************************************/ |
| 425 |
|
| 426 |
class A35 |
| 427 |
{ |
| 428 |
private bool quit; |
| 429 |
void halt() {quit = true;} |
| 430 |
bool isHalted() {return quit;} |
| 431 |
} |
| 432 |
|
| 433 |
void test35() |
| 434 |
{ |
| 435 |
auto a = new A35; |
| 436 |
|
| 437 |
a.halt; // error here |
| 438 |
a.halt(); |
| 439 |
|
| 440 |
a.isHalted; // error here |
| 441 |
bool done = a.isHalted; |
| 442 |
if (a.isHalted) |
| 443 |
{ |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
/*************************************/ |
| 449 |
|
| 450 |
void test36() |
| 451 |
{ |
| 452 |
bool q = (0.9 + 3.5L == 0.9L + 3.5L); |
| 453 |
assert(q); |
| 454 |
static assert(0.9 + 3.5L == 0.9L + 3.5L); |
| 455 |
assert(0.9 + 3.5L == 0.9L + 3.5L); |
| 456 |
} |
| 457 |
|
| 458 |
/*************************************/ |
| 459 |
|
| 460 |
abstract class Foo37(T) |
| 461 |
{ |
| 462 |
void bar () { } |
| 463 |
} |
| 464 |
|
| 465 |
class Bar37 : Foo37!(int) |
| 466 |
{ |
| 467 |
} |
| 468 |
|
| 469 |
void test37() |
| 470 |
{ |
| 471 |
auto f = new Bar37; |
| 472 |
} |
| 473 |
|
| 474 |
/*************************************/ |
| 475 |
|
| 476 |
void test38() |
| 477 |
{ |
| 478 |
auto s=`hello`; |
| 479 |
assert(s.length==5); |
| 480 |
assert(s[0]=='h'); |
| 481 |
assert(s[1]=='e'); |
| 482 |
assert(s[2]=='l'); |
| 483 |
assert(s[3]=='l'); |
| 484 |
assert(s[4]=='o'); |
| 485 |
} |
| 486 |
|
| 487 |
/*************************************/ |
| 488 |
|
| 489 |
void test39() |
| 490 |
{ |
| 491 |
int value=1; |
| 492 |
string key = "eins"; |
| 493 |
int[char[]] array; |
| 494 |
|
| 495 |
array[key]=value; |
| 496 |
int* ptr = key in array; |
| 497 |
|
| 498 |
assert(value == *ptr); |
| 499 |
} |
| 500 |
|
| 501 |
/*************************************/ |
| 502 |
|
| 503 |
void test40() |
| 504 |
{ |
| 505 |
auto s=r"hello"; |
| 506 |
assert(s.length==5); |
| 507 |
assert(s[0]=='h'); |
| 508 |
assert(s[1]=='e'); |
| 509 |
assert(s[2]=='l'); |
| 510 |
assert(s[3]=='l'); |
| 511 |
assert(s[4]=='o'); |
| 512 |
} |
| 513 |
|
| 514 |
/*************************************/ |
| 515 |
|
| 516 |
void test41() |
| 517 |
{ |
| 518 |
version (Windows) |
| 519 |
{ |
| 520 |
version(D_InlineAsm){ |
| 521 |
double a = 1.2; |
| 522 |
double b = 0.2; |
| 523 |
double c = 1.4; |
| 524 |
|
| 525 |
asm{ |
| 526 |
movq XMM0, a; |
| 527 |
movq XMM1, b; |
| 528 |
addsd XMM1, XMM0; |
| 529 |
movq c, XMM1; |
| 530 |
} |
| 531 |
|
| 532 |
a += b; |
| 533 |
|
| 534 |
b = a-c; |
| 535 |
b = (b>0) ? b : (-1 * b); |
| 536 |
|
| 537 |
assert(b < b.epsilon*4); |
| 538 |
} |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
/*************************************/ |
| 543 |
|
| 544 |
const char[] tapir = "some horned animal"; |
| 545 |
|
| 546 |
const byte[] antelope = cast(byte []) tapir; |
| 547 |
|
| 548 |
void test42() |
| 549 |
{ |
| 550 |
} |
| 551 |
|
| 552 |
/*************************************/ |
| 553 |
|
| 554 |
void test43() |
| 555 |
{ |
| 556 |
string armadillo = "abc" ~ 'a'; |
| 557 |
assert(armadillo == "abca"); |
| 558 |
string armadillo2 = 'b' ~ "abc"; |
| 559 |
assert(armadillo2 == "babc"); |
| 560 |
} |
| 561 |
|
| 562 |
/*************************************/ |
| 563 |
|
| 564 |
const uint baboon44 = 3; |
| 565 |
|
| 566 |
const int monkey44 = 4; |
| 567 |
|
| 568 |
const ape44 = monkey44 * baboon44; |
| 569 |
|
| 570 |
void test44() |
| 571 |
{ |
| 572 |
assert(ape44 == 12); |
| 573 |
} |
| 574 |
|
| 575 |
/*************************************/ |
| 576 |
|
| 577 |
class A45 |
| 578 |
{ |
| 579 |
this() |
| 580 |
{ |
| 581 |
b = new B(); |
| 582 |
b.x = 5; // illegal |
| 583 |
} |
| 584 |
|
| 585 |
class B |
| 586 |
{ |
| 587 |
protected int x; |
| 588 |
} |
| 589 |
|
| 590 |
B b; |
| 591 |
} |
| 592 |
|
| 593 |
void test45() |
| 594 |
{ |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
/*************************************/ |
| 599 |
|
| 600 |
class C46(T) |
| 601 |
{ |
| 602 |
private T i; // or protected or package |
| 603 |
} |
| 604 |
|
| 605 |
void test46() |
| 606 |
{ |
| 607 |
C46!(int) c = new C46!(int); // class t4.C46!(int).C46 member i is not accessible |
| 608 |
c.i = 10; |
| 609 |
} |
| 610 |
|
| 611 |
/*************************************/ |
| 612 |
|
| 613 |
void bug5809() |
| 614 |
{ |
| 615 |
ushort[2] x = void; |
| 616 |
x[0] = 0; |
| 617 |
x[1] = 0x1234; |
| 618 |
ushort *px = &x[0]; |
| 619 |
|
| 620 |
uint b = px[0]; |
| 621 |
|
| 622 |
assert(px[0] == 0); |
| 623 |
} |
| 624 |
|
| 625 |
/*************************************/ |
| 626 |
|
| 627 |
void bug7546() |
| 628 |
{ |
| 629 |
double p = -0.0; |
| 630 |
assert(p == 0); |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
/*************************************/ |
| 635 |
|
| 636 |
real poly_asm(real x, real[] A) |
| 637 |
in |
| 638 |
{ |
| 639 |
assert(A.length > 0); |
| 640 |
} |
| 641 |
do |
| 642 |
{ |
| 643 |
version (D_InlineAsm_X86) |
| 644 |
{ |
| 645 |
version (linux) |
| 646 |
{ |
| 647 |
asm // assembler by W. Bright |
| 648 |
{ |
| 649 |
// EDX = (A.length - 1) * real.sizeof |
| 650 |
mov ECX,A[EBP] ; // ECX = A.length |
| 651 |
dec ECX ; |
| 652 |
lea EDX,[ECX][ECX*8] ; |
| 653 |
add EDX,ECX ; |
| 654 |
add EDX,ECX ; |
| 655 |
add EDX,ECX ; |
| 656 |
add EDX,A+4[EBP] ; |
| 657 |
fld real ptr [EDX] ; // ST0 = coeff[ECX] |
| 658 |
jecxz return_ST ; |
| 659 |
fld x[EBP] ; // ST0 = x |
| 660 |
fxch ST(1) ; // ST1 = x, ST0 = r |
| 661 |
align 4 ; |
| 662 |
L2: fmul ST,ST(1) ; // r *= x |
| 663 |
fld real ptr -12[EDX] ; |
| 664 |
sub EDX,12 ; // deg-- |
| 665 |
faddp ST(1),ST ; |
| 666 |
dec ECX ; |
| 667 |
jne L2 ; |
| 668 |
fxch ST(1) ; // ST1 = r, ST0 = x |
| 669 |
fstp ST(0) ; // dump x |
| 670 |
align 4 ; |
| 671 |
return_ST: ; |
| 672 |
; |
| 673 |
} |
| 674 |
} |
| 675 |
else version (OSX) |
| 676 |
{ |
| 677 |
asm // assembler by W. Bright |
| 678 |
{ |
| 679 |
// EDX = (A.length - 1) * real.sizeof |
| 680 |
mov ECX,A[EBP] ; // ECX = A.length |
| 681 |
dec ECX ; |
| 682 |
lea EDX,[ECX*8] ; |
| 683 |
add EDX,EDX ; |
| 684 |
add EDX,A+4[EBP] ; |
| 685 |
fld real ptr [EDX] ; // ST0 = coeff[ECX] |
| 686 |
jecxz return_ST ; |
| 687 |
fld x[EBP] ; // ST0 = x |
| 688 |
fxch ST(1) ; // ST1 = x, ST0 = r |
| 689 |
align 4 ; |
| 690 |
L2: fmul ST,ST(1) ; // r *= x |
| 691 |
fld real ptr -16[EDX] ; |
| 692 |
sub EDX,16 ; // deg-- |
| 693 |
faddp ST(1),ST ; |
| 694 |
dec ECX ; |
| 695 |
jne L2 ; |
| 696 |
fxch ST(1) ; // ST1 = r, ST0 = x |
| 697 |
fstp ST(0) ; // dump x |
| 698 |
align 4 ; |
| 699 |
return_ST: ; |
| 700 |
; |
| 701 |
} |
| 702 |
} |
| 703 |
else version (FreeBSD) |
| 704 |
{ |
| 705 |
asm // assembler by W. Bright |
| 706 |
{ |
| 707 |
// EDX = (A.length - 1) * real.sizeof |
| 708 |
mov ECX,A[EBP] ; // ECX = A.length |
| 709 |
dec ECX ; |
| 710 |
lea EDX,[ECX][ECX*8] ; |
| 711 |
add EDX,ECX ; |
| 712 |
add EDX,ECX ; |
| 713 |
add EDX,ECX ; |
| 714 |
add EDX,A+4[EBP] ; |
| 715 |
fld real ptr [EDX] ; // ST0 = coeff[ECX] |
| 716 |
jecxz return_ST ; |
| 717 |
fld x[EBP] ; // ST0 = x |
| 718 |
fxch ST(1) ; // ST1 = x, ST0 = r |
| 719 |
align 4 ; |
| 720 |
L2: fmul ST,ST(1) ; // r *= x |
| 721 |
fld real ptr -12[EDX] ; |
| 722 |
sub EDX,12 ; // deg-- |
| 723 |
faddp ST(1),ST ; |
| 724 |
dec ECX ; |
| 725 |
jne L2 ; |
| 726 |
fxch ST(1) ; // ST1 = r, ST0 = x |
| 727 |
fstp ST(0) ; // dump x |
| 728 |
align 4 ; |
| 729 |
return_ST: ; |
| 730 |
; |
| 731 |
} |
| 732 |
} |
| 733 |
else version (Solaris) |
| 734 |
{ |
| 735 |
asm // assembler by W. Bright |
| 736 |
{ |
| 737 |
// EDX = (A.length - 1) * real.sizeof |
| 738 |
mov ECX,A[EBP] ; // ECX = A.length |
| 739 |
dec ECX ; |
| 740 |
lea EDX,[ECX][ECX*8] ; |
| 741 |
add EDX,ECX ; |
| 742 |
add EDX,ECX ; |
| 743 |
add EDX,ECX ; |
| 744 |
add EDX,A+4[EBP] ; |
| 745 |
fld real ptr [EDX] ; // ST0 = coeff[ECX] |
| 746 |
jecxz return_ST ; |
| 747 |
fld x[EBP] ; // ST0 = x |
| 748 |
fxch ST(1) ; // ST1 = x, ST0 = r |
| 749 |
align 4 ; |
| 750 |
L2: fmul ST,ST(1) ; // r *= x |
| 751 |
fld real ptr -12[EDX] ; |
| 752 |
sub EDX,12 ; // deg-- |
| 753 |
faddp ST(1),ST ; |
| 754 |
dec ECX ; |
| 755 |
jne L2 ; |
| 756 |
fxch ST(1) ; // ST1 = r, ST0 = x |
| 757 |
fstp ST(0) ; // dump x |
| 758 |
align 4 ; |
| 759 |
return_ST: ; |
| 760 |
; |
| 761 |
} |
| 762 |
} |
| 763 |
else |
| 764 |
{ |
| 765 |
asm // assembler by W. Bright |
| 766 |
{ |
| 767 |
// EDX = (A.length - 1) * real.sizeof |
| 768 |
mov ECX,A[EBP] ; // ECX = A.length |
| 769 |
dec ECX ; |
| 770 |
lea EDX,[ECX][ECX*8] ; |
| 771 |
add EDX,ECX ; |
| 772 |
add EDX,A+4[EBP] ; |
| 773 |
fld real ptr [EDX] ; // ST0 = coeff[ECX] |
| 774 |
jecxz return_ST ; |
| 775 |
fld x[EBP] ; // ST0 = x |
| 776 |
fxch ST(1) ; // ST1 = x, ST0 = r |
| 777 |
align 4 ; |
| 778 |
L2: fmul ST,ST(1) ; // r *= x |
| 779 |
fld real ptr -10[EDX] ; |
| 780 |
sub EDX,10 ; // deg-- |
| 781 |
faddp ST(1),ST ; |
| 782 |
dec ECX ; |
| 783 |
jne L2 ; |
| 784 |
fxch ST(1) ; // ST1 = r, ST0 = x |
| 785 |
fstp ST(0) ; // dump x |
| 786 |
align 4 ; |
| 787 |
return_ST: ; |
| 788 |
; |
| 789 |
} |
| 790 |
} |
| 791 |
} |
| 792 |
else |
| 793 |
{ |
| 794 |
printf("Sorry, you don't seem to have InlineAsm_X86\n"); |
| 795 |
return 0; |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
real poly_c(real x, real[] A) |
| 800 |
in |
| 801 |
{ |
| 802 |
assert(A.length > 0); |
| 803 |
} |
| 804 |
do |
| 805 |
{ |
| 806 |
ptrdiff_t i = A.length - 1; |
| 807 |
real r = A[i]; |
| 808 |
while (--i >= 0) |
| 809 |
{ |
| 810 |
r *= x; |
| 811 |
r += A[i]; |
| 812 |
} |
| 813 |
return r; |
| 814 |
} |
| 815 |
|
| 816 |
void test47() |
| 817 |
{ |
| 818 |
real x = 3.1; |
| 819 |
static real[] pp = [56.1, 32.7, 6]; |
| 820 |
real r; |
| 821 |
|
| 822 |
printf("The result should be %Lf\n",(56.1L + (32.7L + 6L * x) * x)); |
| 823 |
printf("The C version outputs %Lf\n", poly_c(x, pp)); |
| 824 |
printf("The asm version outputs %Lf\n", poly_asm(x, pp)); |
| 825 |
|
| 826 |
r = (56.1L + (32.7L + 6L * x) * x); |
| 827 |
assert(r == poly_c(x, pp)); |
| 828 |
version (D_InlineAsm_X86) |
| 829 |
assert(r == poly_asm(x, pp)); |
| 830 |
} |
| 831 |
|
| 832 |
/*************************************/ |
| 833 |
|
| 834 |
const c48 = 1uL-1; |
| 835 |
|
| 836 |
void test48() |
| 837 |
{ |
| 838 |
assert(c48 == 0); |
| 839 |
} |
| 840 |
|
| 841 |
/*************************************/ |
| 842 |
|
| 843 |
template cat49() |
| 844 |
{ |
| 845 |
static assert(1); // OK |
| 846 |
static if (1) |
| 847 |
{ |
| 848 |
static assert(1); // doesn't work |
| 849 |
static if (1) |
| 850 |
{ |
| 851 |
static assert(1); // OK |
| 852 |
const int cat49 = 3; |
| 853 |
} |
| 854 |
} |
| 855 |
} |
| 856 |
|
| 857 |
void test49() |
| 858 |
{ |
| 859 |
const int a = cat49!(); |
| 860 |
assert(a == 3); |
| 861 |
} |
| 862 |
|
| 863 |
/*************************************/ |
| 864 |
|
| 865 |
void test50() |
| 866 |
{ |
| 867 |
if (auto x = 1) |
| 868 |
{ |
| 869 |
assert(typeid(typeof(x)) == typeid(int)); |
| 870 |
assert(x == 1); |
| 871 |
} |
| 872 |
else |
| 873 |
assert(0); |
| 874 |
|
| 875 |
if (int x = 1) |
| 876 |
{ |
| 877 |
assert(typeid(typeof(x)) == typeid(int)); |
| 878 |
assert(x == 1); |
| 879 |
} |
| 880 |
else |
| 881 |
assert(0); |
| 882 |
|
| 883 |
if (1) |
| 884 |
{ |
| 885 |
} |
| 886 |
else |
| 887 |
assert(0); |
| 888 |
} |
| 889 |
|
| 890 |
/*************************************/ |
| 891 |
|
| 892 |
void test51() |
| 893 |
{ |
| 894 |
bool b; |
| 895 |
assert(b == false); |
| 896 |
b &= 1; |
| 897 |
assert(b == false); |
| 898 |
b |= 1; |
| 899 |
assert(b == true); |
| 900 |
b ^= 1; |
| 901 |
assert(b == false); |
| 902 |
b = b | true; |
| 903 |
assert(b == true); |
| 904 |
b = b & false; |
| 905 |
assert(b == false); |
| 906 |
b = b ^ true; |
| 907 |
assert(b == true); |
| 908 |
b = !b; |
| 909 |
assert(b == false); |
| 910 |
} |
| 911 |
|
| 912 |
/*************************************/ |
| 913 |
|
| 914 |
alias int function (int) x52; |
| 915 |
|
| 916 |
template T52(string str){ |
| 917 |
const int T52 = 1; |
| 918 |
} |
| 919 |
|
| 920 |
static assert(T52!(x52.mangleof)); |
| 921 |
|
| 922 |
void test52() |
| 923 |
{ |
| 924 |
} |
| 925 |
|
| 926 |
/*************************************/ |
| 927 |
|
| 928 |
void myfunc(int a1, ...) { |
| 929 |
va_list argument_list; |
| 930 |
TypeInfo argument_type; |
| 931 |
string sa; int ia; double da; |
| 932 |
assert(_arguments.length == 9); |
| 933 |
|
| 934 |
va_start(argument_list, a1); |
| 935 |
for (int i = 0; i < _arguments.length; ) { |
| 936 |
if ((argument_type=_arguments[i++]) == typeid(string)) { |
| 937 |
va_arg(argument_list, sa); |
| 938 |
switch (i) |
| 939 |
{ |
| 940 |
case 1: assert(sa == "2"); break; |
| 941 |
case 7: assert(sa == "8"); break; |
| 942 |
case 8: assert(sa == "9"); break; |
| 943 |
case 9: assert(sa == "10"); break; |
| 944 |
default: |
| 945 |
printf("i = %d\n", i); |
| 946 |
assert(false); |
| 947 |
} |
| 948 |
} else if (argument_type == typeid(int)) { |
| 949 |
va_arg(argument_list, ia); |
| 950 |
assert(ia == i+1); |
| 951 |
} else if (argument_type == typeid(double)) { |
| 952 |
va_arg(argument_list, da); |
| 953 |
const e = i+1; |
| 954 |
assert((e - 0.0001) < da && da < (e + 0.0001)); |
| 955 |
} else { |
| 956 |
assert(false, argument_type.toString()); |
| 957 |
} |
| 958 |
} |
| 959 |
va_end(argument_list); |
| 960 |
} |
| 961 |
|
| 962 |
void test6758() { |
| 963 |
myfunc(1, 2, 3, 4, 5, 6, 7, 8, "9", "10"); // Fails. |
| 964 |
myfunc(1, 2.0, 3, 4, 5, 6, 7, 8, "9", "10"); // Works OK. |
| 965 |
myfunc(1, 2, 3, 4, 5, 6, 7, "8", "9", "10"); // Works OK. |
| 966 |
myfunc(1, "2", 3, 4, 5, 6, 7, 8, "9", "10"); // Works OK. |
| 967 |
} |
| 968 |
|
| 969 |
|
| 970 |
/*************************************/ |
| 971 |
|
| 972 |
real f18573() { return 1; } |
| 973 |
|
| 974 |
void test18573() |
| 975 |
{ |
| 976 |
cast(void) f18573(); |
| 977 |
cast(void) f18573(); |
| 978 |
cast(void) f18573(); |
| 979 |
cast(void) f18573(); |
| 980 |
cast(void) f18573(); |
| 981 |
cast(void) f18573(); |
| 982 |
cast(void) f18573(); |
| 983 |
|
| 984 |
real b = 2; |
| 985 |
assert(b == 2); /* fails; should pass */ |
| 986 |
} |
| 987 |
|
| 988 |
/*************************************/ |
| 989 |
|
| 990 |
int main() |
| 991 |
{ |
| 992 |
test1(); |
| 993 |
test2(); |
| 994 |
test3(); |
| 995 |
test4(); |
| 996 |
test5(); |
| 997 |
test9(); |
| 998 |
test10(); |
| 999 |
test11(); |
| 1000 |
test16(); |
| 1001 |
test17(); |
| 1002 |
test18(); |
| 1003 |
test19(); |
| 1004 |
test20(); |
| 1005 |
test21(); |
| 1006 |
test23(); |
| 1007 |
test25(); |
| 1008 |
test27(); |
| 1009 |
test29(); |
| 1010 |
test30(); |
| 1011 |
test31(); |
| 1012 |
test32(); |
| 1013 |
test33(); |
| 1014 |
test34(); |
| 1015 |
test35(); |
| 1016 |
test36(); |
| 1017 |
test37(); |
| 1018 |
test38(); |
| 1019 |
test39(); |
| 1020 |
test40(); |
| 1021 |
test41(); |
| 1022 |
test42(); |
| 1023 |
test43(); |
| 1024 |
test44(); |
| 1025 |
test45(); |
| 1026 |
test46(); |
| 1027 |
bug5809(); |
| 1028 |
bug7546(); |
| 1029 |
test47(); |
| 1030 |
test48(); |
| 1031 |
test49(); |
| 1032 |
test50(); |
| 1033 |
test51(); |
| 1034 |
test52(); |
| 1035 |
test6758(); |
| 1036 |
test18573(); |
| 1037 |
|
| 1038 |
printf("Success\n"); |
| 1039 |
return 0; |
| 1040 |
} |