Mercurial > projects > ldc
diff lphobos/internal/objectimpl.d @ 52:0c77619e803b trunk
[svn r56] Initial support for TypeInfo.
Enums not work.
Several other bugfixes.
author | lindquist |
---|---|
date | Tue, 23 Oct 2007 05:55:12 +0200 |
parents | 0b9b286b67b6 |
children | 28e99b04a132 |
line wrap: on
line diff
--- a/lphobos/internal/objectimpl.d Mon Oct 22 17:25:44 2007 +0200 +++ b/lphobos/internal/objectimpl.d Tue Oct 23 05:55:12 2007 +0200 @@ -37,9 +37,28 @@ //import std.outofmemory; +/** + * An unsigned integral type large enough to span the memory space. Use for + * array indices and pointer offsets for maximal portability to + * architectures that have different memory address ranges. This is + * analogous to C's size_t. + */ +alias typeof(int.sizeof) size_t; + +/** + * A signed integral type large enough to span the memory space. Use for + * pointer differences and for size_t differences for maximal portability to + * architectures that have different memory address ranges. This is + * analogous to C's ptrdiff_t. + */ +alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t; + +alias size_t hash_t; + extern (C) { /// C's printf function. int printf(char *, ...); + void trace_term(); int memcmp(void *, void *, size_t); void* memcpy(void *, void *, size_t); @@ -53,34 +72,12 @@ /// Standard boolean type. alias bool bit; -version (LLVM64) -{ - /** - * An unsigned integral type large enough to span the memory space. Use for - * array indices and pointer offsets for maximal portability to - * architectures that have different memory address ranges. This is - * analogous to C's size_t. - */ - alias ulong size_t; - - /** - * A signed integral type large enough to span the memory space. Use for - * pointer differences and for size_t differences for maximal portability to - * architectures that have different memory address ranges. This is - * analogous to C's ptrdiff_t. - */ - alias long ptrdiff_t; - - alias ulong hash_t; -} -else -{ - alias uint size_t; - alias int ptrdiff_t; - alias uint hash_t; -} +alias char[] string; +alias wchar[] wstring; +alias dchar[] dstring; /+ + /* ************************* * Internal struct pointed to by the hidden .monitor member. */ @@ -90,6 +87,7 @@ /* More stuff goes here defined by internal/monitor.c */ } + +/ /****************** @@ -109,7 +107,7 @@ char[] toString() { //return this.classinfo.name; - return "Object.toString: classinfo not yet implemented"; + return "object.Object (no classinfo yet)"; } /** @@ -118,7 +116,7 @@ hash_t toHash() { // BUG: this prevents a compacting GC from working, needs to be fixed - return cast(uint)cast(void *)this; + return cast(hash_t)cast(void *)this; } /** @@ -135,8 +133,8 @@ // BUG: this prevents a compacting GC from working, needs to be fixed //return cast(int)cast(void *)this - cast(int)cast(void *)o; - assert(0, "need opCmp for class <no classinfo yet>"); //throw new Error("need opCmp for class " ~ this.classinfo.name); + throw new Error("need opCmp for class unknown object.Object (no classinfo yet)"); } /** @@ -158,8 +156,9 @@ */ final void notifyRegister(void delegate(Object) dg) { + /+ //printf("notifyRegister(dg = %llx, o = %p)\n", dg, this); - /+synchronized (this) + synchronized (this) { Monitor* m = cast(Monitor*)(cast(void**)this)[1]; foreach (inout x; m.delegates) @@ -191,7 +190,8 @@ m.delegates[startlen .. len] = null; } m.delegates[startlen] = dg; - }+/ + } + +/ } /* ** @@ -201,7 +201,8 @@ */ final void notifyUnRegister(void delegate(Object) dg) { - /+synchronized (this) + /+ + synchronized (this) { Monitor* m = cast(Monitor*)(cast(void**)this)[1]; foreach (inout x; m.delegates) @@ -209,7 +210,8 @@ if (x == dg) x = null; } - }+/ + } + +/ } /****** @@ -219,15 +221,17 @@ * Returns: * null if failed */ - /+static Object factory(char[] classname) + static Object factory(char[] classname) { + /+ auto ci = ClassInfo.find(classname); if (ci) { return ci.create(); } + +/ return null; - }+/ + } } /+ @@ -330,6 +334,8 @@ private import std.string; ++/ + /** * Array of pairs giving the offset and type information for each * member in an aggregate. @@ -340,6 +346,17 @@ TypeInfo ti; /// TypeInfo for this member } +private int string_cmp(char[] s1, char[] s2) +{ + auto len = s1.length; + if (s2.length < len) + len = s2.length; + int result = memcmp(s1.ptr, s2.ptr, len); + if (result == 0) + result = cast(int)(cast(ptrdiff_t)s1.length - cast(ptrdiff_t)s2.length); + return result; +} + /** * Runtime type information about a type. * Can be retrieved for any type using a @@ -362,7 +379,7 @@ TypeInfo ti = cast(TypeInfo)o; if (ti is null) return 1; - return std.string.cmp(this.toString(), ti.toString()); + return string_cmp(this.toString(), ti.toString()); } int opEquals(Object o) @@ -416,6 +433,8 @@ OffsetTypeInfo[] offTi() { return null; } } +/+ + class TypeInfo_Typedef : TypeInfo { char[] toString() { return name; } @@ -1021,6 +1040,30 @@ assert(0); } } + +class TypeInfo_Const : TypeInfo +{ + char[] toString() { return "const " ~ base.toString(); } + + int opEquals(Object o) { return base.opEquals(o); } + hash_t getHash(void *p) { return base.getHash(p); } + int equals(void *p1, void *p2) { return base.equals(p1, p2); } + int compare(void *p1, void *p2) { return base.compare(p1, p2); } + size_t tsize() { return base.tsize(); } + void swap(void *p1, void *p2) { return base.swap(p1, p2); } + + TypeInfo next() { return base.next(); } + uint flags() { return base.flags(); } + void[] init() { return base.init(); } + + TypeInfo base; +} + +class TypeInfo_Invariant : TypeInfo_Const +{ + char[] toString() { return "invariant " ~ base.toString(); } +} + +/ /** @@ -1038,12 +1081,6 @@ this.msg = msg; } - void print() - { - auto str = toString(); - printf("%.*s\n", str.length, str.ptr); - } - char[] toString() { return msg; } } @@ -1070,3 +1107,4 @@ } //extern (C) int nullext = 0; +