From 0b5d833e0947d44cd5bee6562c22ed4a14ca23bb Mon Sep 17 00:00:00 2001 From: sean Date: Sat, 20 Sep 2008 02:53:43 +0000 Subject: [PATCH] The next batch of updates towards D2 support. The lib should be pretty close to compiling with D2 now, and the D2 runtime changes have been reduced to a compact set of pure additions (few/no alterations). Next update will be aimed at finishing the process of getting the lib to build with -w set under D2, which will mean adding "override" where necessary to the compiler runtime as well as figuring out how to deal with the use of 'volatile' in the thread code. git-svn-id: http://svn.dsource.org/projects/druntime/trunk@6 4a9d5153-6564-4b3f-b5e1-7e8e9dac548f --- import/object.di | 18 +-- src/compiler/dmd/adi.d | 7 +- src/compiler/dmd/object_.d | 173 ++++++++++++------------ src/compiler/dmd/typeinfo/ti_AC.d | 6 +- src/compiler/dmd/typeinfo/ti_Acdouble.d | 9 +- src/compiler/dmd/typeinfo/ti_Acfloat.d | 9 +- src/compiler/dmd/typeinfo/ti_Acreal.d | 7 +- src/compiler/dmd/typeinfo/ti_Adouble.d | 7 +- src/compiler/dmd/typeinfo/ti_Afloat.d | 7 +- src/compiler/dmd/typeinfo/ti_Aint.d | 11 ++ src/compiler/dmd/typeinfo/ti_Areal.d | 9 +- 11 files changed, 136 insertions(+), 127 deletions(-) diff --git a/import/object.di b/import/object.di index 1360687..9508fef 100644 --- a/import/object.di +++ b/import/object.di @@ -62,7 +62,7 @@ struct OffsetTypeInfo class TypeInfo { hash_t getHash(in void* p); - int equals(in void* p1, in void* p2); + equals_t equals(in void* p1, in void* p2); int compare(in void* p1, in void* p2); size_t tsize(); void swap(void* p1, void* p2); @@ -131,10 +131,10 @@ class TypeInfo_Struct : TypeInfo string name; void[] m_init; - uint function(in void*) xtoHash; - equals_t function(in void*,in void*) xopEquals; - int function(in void*,in void*) xopCmp; - string function(in void*) xtoString; + uint function(in void*) xtoHash; + equals_t function(in void*, in void*) xopEquals; + int function(in void*, in void*) xopCmp; + string function(in void*) xtoString; uint m_flags; @@ -167,13 +167,13 @@ class Exception : Object string toString(); } - char[] msg; - char[] file; + string msg; + string file; size_t line; TraceInfo info; Exception next; - this(char[] msg, Exception next = null); - this(char[] msg, char[] file, size_t line, Exception next = null); + this(string msg, Exception next = null); + this(string msg, string file, size_t line, Exception next = null); string toString(); } diff --git a/src/compiler/dmd/adi.d b/src/compiler/dmd/adi.d index 908841b..11d3ab4 100644 --- a/src/compiler/dmd/adi.d +++ b/src/compiler/dmd/adi.d @@ -228,9 +228,8 @@ extern (C) long _adReverseWchar(wchar[] a) unittest { wstring a = "abcd"; - wstring r; - r = a.dup.reverse; + auto r = a.dup.reverse; assert(r == "dcba"); a = "a\U00012356\U00012346c"; @@ -337,7 +336,7 @@ extern (C) long _adSortChar(char[] a) { if (a.length > 1) { - dchar[] da = toUTF32(a); + dstring da = toUTF32(a); da.sort; size_t i = 0; foreach (dchar d; da) @@ -359,7 +358,7 @@ extern (C) long _adSortWchar(wchar[] a) { if (a.length > 1) { - dchar[] da = toUTF32(a); + dstring da = toUTF32(a); da.sort; size_t i = 0; foreach (dchar d; da) diff --git a/src/compiler/dmd/object_.d b/src/compiler/dmd/object_.d index 3f9ddd2..a0ac2a0 100644 --- a/src/compiler/dmd/object_.d +++ b/src/compiler/dmd/object_.d @@ -108,8 +108,8 @@ class Object // BUG: this prevents a compacting GC from working, needs to be fixed //return cast(int)cast(void*)this - cast(int)cast(void*)o; - //throw new Exception("need opCmp for class " ~ this.classinfo.name); - return this !is o; + throw new Exception("need opCmp for class " ~ this.classinfo.name); + //return this !is o; } /** @@ -250,7 +250,7 @@ class TypeInfo hash_t getHash(in void* p) { return cast(hash_t)p; } /// Compares two instances for equality. - equals_t equals(in void* p1, in void* p2) { return cast(int)(p1 == p2); } + equals_t equals(in void* p1, in void* p2) { return p1 == p2; } /// Compares two instances for <, ==, or >. int compare(in void* p1, in void* p2) { return 0; } @@ -263,11 +263,10 @@ class TypeInfo { size_t n = tsize(); for (size_t i = 0; i < n; i++) - { byte t; - - t = (cast(byte *)p1)[i]; - (cast(byte *)p1)[i] = (cast(byte *)p2)[i]; - (cast(byte *)p2)[i] = t; + { + byte t = (cast(byte *)p1)[i]; + (cast(byte*)p1)[i] = (cast(byte*)p2)[i]; + (cast(byte*)p2)[i] = t; } } @@ -290,8 +289,8 @@ class TypeInfo_Typedef : TypeInfo string toString() { return name; } equals_t opEquals(Object o) - { TypeInfo_Typedef c; - + { + TypeInfo_Typedef c; return this is o || ((c = cast(TypeInfo_Typedef)o) !is null && this.name == c.name && @@ -309,12 +308,13 @@ class TypeInfo_Typedef : TypeInfo void[] init() { return m_init.length ? m_init : base.init(); } TypeInfo base; - string name; - void[] m_init; + string name; + void[] m_init; } class TypeInfo_Enum : TypeInfo_Typedef { + } class TypeInfo_Pointer : TypeInfo @@ -322,8 +322,8 @@ class TypeInfo_Pointer : TypeInfo string toString() { return m_next.toString() ~ "*"; } equals_t opEquals(Object o) - { TypeInfo_Pointer c; - + { + TypeInfo_Pointer c; return this is o || ((c = cast(TypeInfo_Pointer)o) !is null && this.m_next == c.m_next); @@ -336,14 +336,14 @@ class TypeInfo_Pointer : TypeInfo equals_t equals(in void* p1, in void* p2) { - return cast(int)(*cast(void* *)p1 == *cast(void* *)p2); + return *cast(void**)p1 == *cast(void**)p2; } int compare(in void* p1, in void* p2) { - if (*cast(void* *)p1 < *cast(void* *)p2) + if (*cast(void**)p1 < *cast(void**)p2) return -1; - else if (*cast(void* *)p1 > *cast(void* *)p2) + else if (*cast(void**)p1 > *cast(void**)p2) return 1; else return 0; @@ -355,8 +355,8 @@ class TypeInfo_Pointer : TypeInfo } void swap(void* p1, void* p2) - { void* tmp; - tmp = *cast(void**)p1; + { + void* tmp = *cast(void**)p1; *cast(void**)p1 = *cast(void**)p2; *cast(void**)p2 = tmp; } @@ -372,15 +372,16 @@ class TypeInfo_Array : TypeInfo string toString() { return value.toString() ~ "[]"; } equals_t opEquals(Object o) - { TypeInfo_Array c; - + { + TypeInfo_Array c; return this is o || ((c = cast(TypeInfo_Array)o) !is null && this.value == c.value); } hash_t getHash(in void* p) - { size_t sz = value.tsize(); + { + size_t sz = value.tsize(); hash_t hash = 0; void[] a = *cast(void[]*)p; for (size_t i = 0; i < a.length; i++) @@ -393,14 +394,14 @@ class TypeInfo_Array : TypeInfo void[] a1 = *cast(void[]*)p1; void[] a2 = *cast(void[]*)p2; if (a1.length != a2.length) - return 0; + return false; size_t sz = value.tsize(); for (size_t i = 0; i < a1.length; i++) { if (!value.equals(a1.ptr + i * sz, a2.ptr + i * sz)) - return 0; + return false; } - return 1; + return true; } int compare(in void* p1, in void* p2) @@ -427,8 +428,8 @@ class TypeInfo_Array : TypeInfo } void swap(void* p1, void* p2) - { void[] tmp; - tmp = *cast(void[]*)p1; + { + void[] tmp = *cast(void[]*)p1; *cast(void[]*)p1 = *cast(void[]*)p2; *cast(void[]*)p2 = tmp; } @@ -438,7 +439,7 @@ class TypeInfo_Array : TypeInfo TypeInfo next() { return value; -} + } uint flags() { return 1; } } @@ -452,8 +453,8 @@ class TypeInfo_StaticArray : TypeInfo } equals_t opEquals(Object o) - { TypeInfo_StaticArray c; - + { + TypeInfo_StaticArray c; return this is o || ((c = cast(TypeInfo_StaticArray)o) !is null && this.len == c.len && @@ -461,7 +462,8 @@ class TypeInfo_StaticArray : TypeInfo } hash_t getHash(in void* p) - { size_t sz = value.tsize(); + { + size_t sz = value.tsize(); hash_t hash = 0; for (size_t i = 0; i < len; i++) hash += value.getHash(p + i * sz); @@ -475,9 +477,9 @@ class TypeInfo_StaticArray : TypeInfo for (size_t u = 0; u < len; u++) { if (!value.equals(p1 + u * sz, p2 + u * sz)) - return 0; + return false; } - return 1; + return true; } int compare(in void* p1, in void* p2) @@ -499,7 +501,8 @@ class TypeInfo_StaticArray : TypeInfo } void swap(void* p1, void* p2) - { void* tmp; + { + void* tmp; size_t sz = value.tsize(); ubyte[16] buffer; void* pbuffer; @@ -524,7 +527,7 @@ class TypeInfo_StaticArray : TypeInfo uint flags() { return value.flags(); } TypeInfo value; - size_t len; + size_t len; } class TypeInfo_AssociativeArray : TypeInfo @@ -535,8 +538,8 @@ class TypeInfo_AssociativeArray : TypeInfo } equals_t opEquals(Object o) - { TypeInfo_AssociativeArray c; - + { + TypeInfo_AssociativeArray c; return this is o || ((c = cast(TypeInfo_AssociativeArray)o) !is null && this.key == c.key && @@ -565,8 +568,8 @@ class TypeInfo_Function : TypeInfo } equals_t opEquals(Object o) - { TypeInfo_Function c; - + { + TypeInfo_Function c; return this is o || ((c = cast(TypeInfo_Function)o) !is null && this.next == c.next); @@ -590,8 +593,8 @@ class TypeInfo_Delegate : TypeInfo } equals_t opEquals(Object o) - { TypeInfo_Delegate c; - + { + TypeInfo_Delegate c; return this is o || ((c = cast(TypeInfo_Delegate)o) !is null && this.next == c.next); @@ -600,7 +603,8 @@ class TypeInfo_Delegate : TypeInfo // BUG: need to add the rest of the functions size_t tsize() - { alias int delegate() dg; + { + alias int delegate() dg; return dg.sizeof; } @@ -614,8 +618,8 @@ class TypeInfo_Class : TypeInfo string toString() { return info.name; } equals_t opEquals(Object o) - { TypeInfo_Class c; - + { + TypeInfo_Class c; return this is o || ((c = cast(TypeInfo_Class)o) !is null && this.info.name == c.classinfo.name); @@ -645,7 +649,8 @@ class TypeInfo_Class : TypeInfo if (o1 !is o2) { if (o1) - { if (!o2) + { + if (!o2) c = 1; else c = o1.opCmp(o2); @@ -676,8 +681,8 @@ class TypeInfo_Interface : TypeInfo string toString() { return info.name; } equals_t opEquals(Object o) - { TypeInfo_Interface c; - + { + TypeInfo_Interface c; return this is o || ((c = cast(TypeInfo_Interface)o) !is null && this.info.name == c.classinfo.name); @@ -713,7 +718,8 @@ class TypeInfo_Interface : TypeInfo if (o1 != o2) { if (o1) - { if (!o2) + { + if (!o2) c = 1; else c = o1.opCmp(o2); @@ -739,8 +745,8 @@ class TypeInfo_Struct : TypeInfo string toString() { return name; } equals_t opEquals(Object o) - { TypeInfo_Struct s; - + { + TypeInfo_Struct s; return this is o || ((s = cast(TypeInfo_Struct)o) !is null && this.name == s.name && @@ -748,62 +754,62 @@ class TypeInfo_Struct : TypeInfo } hash_t getHash(in void* p) - { hash_t h; - + { assert(p); if (xtoHash) - { debug(PRINTF) printf("getHash() using xtoHash\n"); - h = (*xtoHash)(p); + { + debug(PRINTF) printf("getHash() using xtoHash\n"); + return (*xtoHash)(p); } else { + hash_t h; debug(PRINTF) printf("getHash() using default hash\n"); // A sorry hash algorithm. // Should use the one for strings. // BUG: relies on the GC not moving objects + auto q = cast(ubyte*)p; for (size_t i = 0; i < init.length; i++) - { h = h * 9 + *cast(ubyte*)p; - p++; + { + h = h * 9 + *q; + q++; } + return h; } - return h; } equals_t equals(in void* p1, in void* p2) - { int c; - + { if (p1 == p2) - c = 1; + return true; else if (!p1 || !p2) - c = 0; + return false; else if (xopEquals) - c = (*xopEquals)(p1, p2); + return (*xopEquals)(p1, p2); else // BUG: relies on the GC not moving objects - c = (memcmp(p1, p2, init.length) == 0); - return c; + return memcmp(p1, p2, init.length) == 0; } int compare(in void* p1, in void* p2) { - int c = 0; - // Regard null references as always being "less than" if (p1 != p2) { if (p1) - { if (!p2) - c = 1; + { + if (!p2) + return true; else if (xopCmp) - c = (*xopCmp)(p2, p1); + return (*xopCmp)(p2, p1); else // BUG: relies on the GC not moving objects - c = memcmp(p1, p2, init.length); + return memcmp(p1, p2, init.length); } else - c = -1; + return -1; } - return c; + return 0; } size_t tsize() @@ -818,10 +824,10 @@ class TypeInfo_Struct : TypeInfo string name; void[] m_init; // initializer; init.ptr == null if 0 initialize - hash_t function(void*) xtoHash; - int function(void*,void*) xopEquals; - int function(void*,void*) xopCmp; - char[] function(void*) xtoString; + hash_t function(in void*) xtoHash; + equals_t function(in void*, in void*) xopEquals; + int function(in void*, in void*) xopCmp; + char[] function(in void*) xtoString; uint m_flags; } @@ -832,8 +838,7 @@ class TypeInfo_Tuple : TypeInfo string toString() { - char[] s; - s = "("; + string s = "("; foreach (i, element; elements) { if (i) @@ -898,23 +903,23 @@ class Exception : Object { interface TraceInfo { - int opApply( int delegate( inout char[] ) ); + int opApply( int delegate(inout char[]) ); } - char[] msg; - char[] file; + string msg; + string file; size_t line; TraceInfo info; Exception next; - this( char[] msg, Exception next = null ) + this( string msg, Exception next = null ) { this.msg = msg; this.next = next; this.info = traceContext(); } - this( char[] msg, char[] file, size_t line, Exception next = null ) + this( string msg, string file, size_t line, Exception next = null ) { this(msg, next); this.file = file; @@ -997,7 +1002,7 @@ class ModuleInfo void function() ictor; // module static constructor (order independent) - static int opApply( int delegate( inout ModuleInfo ) dg ) + static int opApply( int delegate(inout ModuleInfo) dg ) { int ret = 0; diff --git a/src/compiler/dmd/typeinfo/ti_AC.d b/src/compiler/dmd/typeinfo/ti_AC.d index 522f9ea..47b9074 100644 --- a/src/compiler/dmd/typeinfo/ti_AC.d +++ b/src/compiler/dmd/typeinfo/ti_AC.d @@ -31,11 +31,11 @@ class TypeInfo_AC : TypeInfo if (o1 is o2 || (!(o1 is null) && !(o2 is null) && o1.opEquals(o2))) continue; - return 0; + return false; } - return 1; + return true; } - return 0; + return false; } int compare(in void* p1, in void* p2) diff --git a/src/compiler/dmd/typeinfo/ti_Acdouble.d b/src/compiler/dmd/typeinfo/ti_Acdouble.d index e2f1bbf..b844926 100644 --- a/src/compiler/dmd/typeinfo/ti_Acdouble.d +++ b/src/compiler/dmd/typeinfo/ti_Acdouble.d @@ -58,14 +58,13 @@ class TypeInfo_Ar : TypeInfo size_t len = s1.length; if (len != s2.length) - return 0; + return false; for (size_t u = 0; u < len; u++) { - int c = TypeInfo_r._equals(s1[u], s2[u]); - if (c == 0) - return 0; + if (!TypeInfo_r._equals(s1[u], s2[u])) + return false; } - return 1; + return true; } int compare(in void* p1, in void* p2) diff --git a/src/compiler/dmd/typeinfo/ti_Acfloat.d b/src/compiler/dmd/typeinfo/ti_Acfloat.d index c9a4b0c..f15a507 100644 --- a/src/compiler/dmd/typeinfo/ti_Acfloat.d +++ b/src/compiler/dmd/typeinfo/ti_Acfloat.d @@ -56,14 +56,13 @@ class TypeInfo_Aq : TypeInfo size_t len = s1.length; if (len != s2.length) - return 0; + return false; for (size_t u = 0; u < len; u++) { - int c = TypeInfo_q._equals(s1[u], s2[u]); - if (c == 0) - return 0; + if (!TypeInfo_q._equals(s1[u], s2[u])) + return false; } - return 1; + return true; } int compare(in void* p1, in void* p2) diff --git a/src/compiler/dmd/typeinfo/ti_Acreal.d b/src/compiler/dmd/typeinfo/ti_Acreal.d index 3abbbff..576a0cd 100644 --- a/src/compiler/dmd/typeinfo/ti_Acreal.d +++ b/src/compiler/dmd/typeinfo/ti_Acreal.d @@ -62,11 +62,10 @@ class TypeInfo_Ac : TypeInfo return 0; for (size_t u = 0; u < len; u++) { - int c = TypeInfo_c._equals(s1[u], s2[u]); - if (c == 0) - return 0; + if (!TypeInfo_c._equals(s1[u], s2[u])) + return false; } - return 1; + return true; } int compare(in void* p1, in void* p2) diff --git a/src/compiler/dmd/typeinfo/ti_Adouble.d b/src/compiler/dmd/typeinfo/ti_Adouble.d index c6321c4..785f166 100644 --- a/src/compiler/dmd/typeinfo/ti_Adouble.d +++ b/src/compiler/dmd/typeinfo/ti_Adouble.d @@ -59,11 +59,10 @@ class TypeInfo_Ad : TypeInfo return 0; for (size_t u = 0; u < len; u++) { - int c = TypeInfo_d._equals(s1[u], s2[u]); - if (c == 0) - return 0; + if (!TypeInfo_d._equals(s1[u], s2[u])) + return false; } - return 1; + return true; } int compare(in void* p1, in void* p2) diff --git a/src/compiler/dmd/typeinfo/ti_Afloat.d b/src/compiler/dmd/typeinfo/ti_Afloat.d index 49625d9..cb937cd 100644 --- a/src/compiler/dmd/typeinfo/ti_Afloat.d +++ b/src/compiler/dmd/typeinfo/ti_Afloat.d @@ -58,11 +58,10 @@ class TypeInfo_Af : TypeInfo return 0; for (size_t u = 0; u < len; u++) { - int c = TypeInfo_f._equals(s1[u], s2[u]); - if (c == 0) - return 0; + if (!TypeInfo_f._equals(s1[u], s2[u])) + return false; } - return 1; + return true; } int compare(in void* p1, in void* p2) diff --git a/src/compiler/dmd/typeinfo/ti_Aint.d b/src/compiler/dmd/typeinfo/ti_Aint.d index d888bed..32b940f 100644 --- a/src/compiler/dmd/typeinfo/ti_Aint.d +++ b/src/compiler/dmd/typeinfo/ti_Aint.d @@ -72,6 +72,17 @@ class TypeInfo_Ai : TypeInfo } } +unittest +{ + int[][] a = [[5,3,8,7], [2,5,3,8,7]]; + a.sort; + assert(a == [[2,5,3,8,7], [5,3,8,7]]); + + a = [[5,3,8,7], [5,3,8]]; + a.sort; + assert(a == [[5,3,8], [5,3,8,7]]); +} + // uint[] class TypeInfo_Ak : TypeInfo_Ai diff --git a/src/compiler/dmd/typeinfo/ti_Areal.d b/src/compiler/dmd/typeinfo/ti_Areal.d index afeb531..93040d9 100644 --- a/src/compiler/dmd/typeinfo/ti_Areal.d +++ b/src/compiler/dmd/typeinfo/ti_Areal.d @@ -57,14 +57,13 @@ class TypeInfo_Ae : TypeInfo size_t len = s1.length; if (len != s2.length) - return 0; + return false; for (size_t u = 0; u < len; u++) { - int c = TypeInfo_e._equals(s1[u], s2[u]); - if (c == 0) - return 0; + if (!TypeInfo_e._equals(s1[u], s2[u])) + return false; } - return 1; + return true; } int compare(in void* p1, in void* p2) -- 2.43.0