Mercurial > projects > ldc
comparison lphobos/std/format.d @ 131:5825d48b27d1 trunk
[svn r135] * Merged DMD 1.025 *
* Fixed a minor linking order mishap *
* Added an command line option -annotate *
* Fixed some problems with running optimizations *
* Added std.stdio and dependencies to lphobos (still not 100% working, but compiles and links) *
* Fixed problems with passing aggregate types to variadic functions *
* Added initial code towards full GC support, currently based on malloc and friends, not all the runtime calls the GC yet for memory *
* Fixed problems with resolving nested function context pointers for some heavily nested cases *
* Redid function argument passing + other minor code cleanups, still lots to do on this end... *
author | lindquist |
---|---|
date | Fri, 04 Jan 2008 01:38:42 +0100 |
parents | 5ce8ab11e75a |
children | 88e23f8c2354 |
comparison
equal
deleted
inserted
replaced
130:a7dfa0ed966c | 131:5825d48b27d1 |
---|---|
168 ti = typeid(ifloat);break; | 168 ti = typeid(ifloat);break; |
169 case Mangle.Tidouble: | 169 case Mangle.Tidouble: |
170 ti = typeid(idouble);break; | 170 ti = typeid(idouble);break; |
171 case Mangle.Tireal: | 171 case Mangle.Tireal: |
172 ti = typeid(ireal);break; | 172 ti = typeid(ireal);break; |
173 /+ | |
174 // No complex in LLVMDC yes | |
175 case Mangle.Tcfloat: | 173 case Mangle.Tcfloat: |
176 ti = typeid(cfloat);break; | 174 ti = typeid(cfloat);break; |
177 case Mangle.Tcdouble: | 175 case Mangle.Tcdouble: |
178 ti = typeid(cdouble);break; | 176 ti = typeid(cdouble);break; |
179 case Mangle.Tcreal: | 177 case Mangle.Tcreal: |
180 ti = typeid(creal);break; | 178 ti = typeid(creal);break; |
181 +/ | |
182 case Mangle.Tchar: | 179 case Mangle.Tchar: |
183 ti = typeid(char);break; | 180 ti = typeid(char);break; |
184 case Mangle.Twchar: | 181 case Mangle.Twchar: |
185 ti = typeid(wchar);break; | 182 ti = typeid(wchar);break; |
186 case Mangle.Tdchar: | 183 case Mangle.Tdchar: |
448 formattedPrint("The answer is %s:", x, 6); | 445 formattedPrint("The answer is %s:", x, 6); |
449 ------------------------ | 446 ------------------------ |
450 */ | 447 */ |
451 | 448 |
452 void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, void* argptr) | 449 void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, void* argptr) |
453 { int j; | 450 { //printf("doFormat(...)\n"); |
451 int j; | |
454 TypeInfo ti; | 452 TypeInfo ti; |
455 Mangle m; | 453 Mangle m; |
456 uint flags; | 454 uint flags; |
457 int field_width; | 455 int field_width; |
458 int precision; | 456 int precision; |
501 char* prefix = ""; | 499 char* prefix = ""; |
502 string s; | 500 string s; |
503 | 501 |
504 void putstr(char[] s) | 502 void putstr(char[] s) |
505 { | 503 { |
506 //printf("flags = x%x\n", flags); | 504 //printf("flags = 0x%x\n", flags); |
507 int prepad = 0; | 505 int prepad = 0; |
508 int postpad = 0; | 506 int postpad = 0; |
509 int padding = field_width - (strlen(prefix) + s.length); | 507 int padding = field_width - (strlen(prefix) + s.length); |
510 if (padding > 0) | 508 if (padding > 0) |
511 { | 509 { |
537 putc(' '); | 535 putc(' '); |
538 } | 536 } |
539 | 537 |
540 void putreal(real v) | 538 void putreal(real v) |
541 { | 539 { |
542 //printf("putreal %Lg\n", vreal); | 540 //printf("putreal %Lg\n", vreal); // no 80 bit float |
541 //printf("putreal %g\n", vreal); | |
543 | 542 |
544 switch (fc) | 543 switch (fc) |
545 { | 544 { |
546 case 's': | 545 case 's': |
547 fc = 'g'; | 546 fc = 'g'; |
591 if (flags & FL0pad) | 590 if (flags & FL0pad) |
592 format[i++] = '0'; | 591 format[i++] = '0'; |
593 format[i + 0] = '*'; | 592 format[i + 0] = '*'; |
594 format[i + 1] = '.'; | 593 format[i + 1] = '.'; |
595 format[i + 2] = '*'; | 594 format[i + 2] = '*'; |
596 format[i + 3] = 'L'; | 595 format[i + 3] = fc; |
597 format[i + 4] = fc; | 596 format[i + 4] = 0; |
598 format[i + 5] = 0; | 597 //format[i + 3] = 'L'; // no 80 bit yet |
598 //format[i + 4] = fc; | |
599 //format[i + 5] = 0; | |
599 if (!(flags & FLprecision)) | 600 if (!(flags & FLprecision)) |
600 precision = -1; | 601 precision = -1; |
601 while (1) | 602 while (1) |
602 { int n; | 603 { int n; |
603 | 604 |
636 size_t tsize = valti.tsize(); | 637 size_t tsize = valti.tsize(); |
637 auto argptrSave = argptr; | 638 auto argptrSave = argptr; |
638 auto tiSave = ti; | 639 auto tiSave = ti; |
639 auto mSave = m; | 640 auto mSave = m; |
640 ti = valti; | 641 ti = valti; |
641 //printf("\n%.*s\n", valti.classinfo.name); | 642 auto className = valti.classinfo.name; |
643 printf("\n%.*s\n", className.length, className.ptr); | |
642 m = getMan(valti); | 644 m = getMan(valti); |
643 while (len--) | 645 while (len--) |
644 { | 646 { |
645 //doFormat(putc, (&valti)[0 .. 1], p); | 647 //doFormat(putc, (&valti)[0 .. 1], p); |
646 argptr = p; | 648 argptr = p; |
829 case Mangle.Tcreal: | 831 case Mangle.Tcreal: |
830 vcreal = va_arg!(creal)(argptr); | 832 vcreal = va_arg!(creal)(argptr); |
831 goto Lcomplex; | 833 goto Lcomplex; |
832 | 834 |
833 case Mangle.Tsarray: | 835 case Mangle.Tsarray: |
836 //printf("static array\n"); | |
834 putArray(argptr, (cast(TypeInfo_StaticArray)ti).len, (cast(TypeInfo_StaticArray)ti).next); | 837 putArray(argptr, (cast(TypeInfo_StaticArray)ti).len, (cast(TypeInfo_StaticArray)ti).next); |
835 return; | 838 return; |
836 | 839 |
837 case Mangle.Tarray: | 840 case Mangle.Tarray: |
841 //printf("dynamic array\n"); | |
838 int mi = 10; | 842 int mi = 10; |
839 if (ti.classinfo.name.length == 14 && | 843 if (ti.classinfo.name.length == 14 && |
840 ti.classinfo.name[9..14] == "Array") | 844 ti.classinfo.name[9..14] == "Array") |
841 { // array of non-primitive types | 845 { // array of non-primitive types |
842 TypeInfo tn = (cast(TypeInfo_Array)ti).next; | 846 TypeInfo tn = (cast(TypeInfo_Array)ti).next; |
861 (cast(TypeInfo_AssociativeArray)ti).next, | 865 (cast(TypeInfo_AssociativeArray)ti).next, |
862 (cast(TypeInfo_AssociativeArray)ti).key); | 866 (cast(TypeInfo_AssociativeArray)ti).key); |
863 return; | 867 return; |
864 } | 868 } |
865 | 869 |
870 //printf("primitive type\n"); | |
866 while (1) | 871 while (1) |
867 { | 872 { |
868 m2 = cast(Mangle)ti.classinfo.name[mi]; | 873 m2 = cast(Mangle)ti.classinfo.name[mi]; |
869 switch (m2) | 874 switch (m2) |
870 { | 875 { |
895 case Mangle.Tinvariant: | 900 case Mangle.Tinvariant: |
896 mi++; | 901 mi++; |
897 continue; | 902 continue; |
898 | 903 |
899 default: | 904 default: |
905 //printf("primitive type default handling\n"); | |
900 TypeInfo ti2 = primitiveTypeInfo(m2); | 906 TypeInfo ti2 = primitiveTypeInfo(m2); |
901 if (!ti2) | 907 if (!ti2) |
902 goto Lerror; | 908 goto Lerror; |
903 void[] va = va_arg!(void[])(argptr); | 909 void[] va = va_arg!(void[])(argptr); |
904 putArray(va.ptr, va.length, ti2); | 910 putArray(va.ptr, va.length, ti2); |
1056 Lerror: | 1062 Lerror: |
1057 throw new FormatError("formatArg"); | 1063 throw new FormatError("formatArg"); |
1058 } | 1064 } |
1059 | 1065 |
1060 | 1066 |
1067 //printf("arguments length: %u\n", arguments.length); | |
1061 for (j = 0; j < arguments.length; ) | 1068 for (j = 0; j < arguments.length; ) |
1062 { ti = arguments[j++]; | 1069 { ti = arguments[j++]; |
1063 //printf("test1: '%.*s' %d\n", ti.classinfo.name, ti.classinfo.name.length); | 1070 //printf("test1: '%.*s' %d\n", ti.classinfo.name.length, ti.classinfo.name.ptr, ti.classinfo.name.length); |
1064 //ti.print(); | 1071 //ti.print(); |
1065 | 1072 |
1066 flags = 0; | 1073 flags = 0; |
1067 precision = 0; | 1074 precision = 0; |
1068 field_width = 0; | 1075 field_width = 0; |