comparison lphobos/object.d @ 1:c53b6e3fe49a trunk

[svn r5] Initial commit. Most things are very rough.
author lindquist
date Sat, 01 Sep 2007 21:43:27 +0200
parents
children 2841234d2aea
comparison
equal deleted inserted replaced
0:a9e71648e74d 1:c53b6e3fe49a
1
2 // Implementation is in internal\object.d
3
4 module object;
5
6 //alias bit bool;
7 alias bool bit;
8
9 alias typeof(int.sizeof) size_t;
10 alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t;
11 alias size_t hash_t;
12
13 extern (C)
14 { int printf(char *, ...);
15 }
16
17 class Object
18 {
19 void print();
20 char[] toString();
21 hash_t toHash();
22 int opCmp(Object o);
23 int opEquals(Object o);
24
25 final void notifyRegister(void delegate(Object) dg);
26 final void notifyUnRegister(void delegate(Object) dg);
27 }
28
29 struct Interface
30 {
31 ClassInfo classinfo;
32 void *[] vtbl;
33 ptrdiff_t offset; // offset to Interface 'this' from Object 'this'
34 }
35
36 class ClassInfo : Object
37 {
38 byte[] init; // class static initializer
39 char[] name; // class name
40 void *[] vtbl; // virtual function pointer table
41 Interface[] interfaces;
42 ClassInfo base;
43 void *destructor;
44 void (*classInvariant)(Object);
45 uint flags;
46 // 1: // IUnknown
47 // 2: // has no possible pointers into GC memory
48 // 4: // has offTi[] member
49 void *deallocator;
50 OffsetTypeInfo[] offTi;
51 }
52
53 struct OffsetTypeInfo
54 {
55 size_t offset;
56 TypeInfo ti;
57 }
58
59 class TypeInfo
60 {
61 hash_t getHash(void *p);
62 int equals(void *p1, void *p2);
63 int compare(void *p1, void *p2);
64 size_t tsize();
65 void swap(void *p1, void *p2);
66 TypeInfo next();
67 void[] init();
68 uint flags();
69 // 1: // has possible pointers into GC memory
70 OffsetTypeInfo[] offTi();
71 }
72
73 class TypeInfo_Typedef : TypeInfo
74 {
75 TypeInfo base;
76 char[] name;
77 void[] m_init;
78 }
79
80 class TypeInfo_Enum : TypeInfo_Typedef
81 {
82 }
83
84 class TypeInfo_Pointer : TypeInfo
85 {
86 TypeInfo m_next;
87 }
88
89 class TypeInfo_Array : TypeInfo
90 {
91 TypeInfo value;
92 }
93
94 class TypeInfo_StaticArray : TypeInfo
95 {
96 TypeInfo value;
97 size_t len;
98 }
99
100 class TypeInfo_AssociativeArray : TypeInfo
101 {
102 TypeInfo value;
103 TypeInfo key;
104 }
105
106 class TypeInfo_Function : TypeInfo
107 {
108 TypeInfo next;
109 }
110
111 class TypeInfo_Delegate : TypeInfo
112 {
113 TypeInfo next;
114 }
115
116 class TypeInfo_Class : TypeInfo
117 {
118 ClassInfo info;
119 }
120
121 class TypeInfo_Interface : TypeInfo
122 {
123 ClassInfo info;
124 }
125
126 class TypeInfo_Struct : TypeInfo
127 {
128 char[] name;
129 void[] m_init;
130
131 uint function(void*) xtoHash;
132 int function(void*,void*) xopEquals;
133 int function(void*,void*) xopCmp;
134 char[] function(void*) xtoString;
135
136 uint m_flags;
137 }
138
139 class TypeInfo_Tuple : TypeInfo
140 {
141 TypeInfo[] elements;
142 }
143
144 // Recoverable errors
145
146 class Exception : Object
147 {
148 char[] msg;
149
150 this(char[] msg);
151 void print();
152 char[] toString();
153 }
154
155 // Non-recoverable errors
156
157 class Error : Exception
158 {
159 Error next;
160
161 this(char[] msg);
162 this(char[] msg, Error next);
163 }
164