PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/runtime/object.d

http://github.com/wilkie/djehuty
D | 63 lines | 34 code | 12 blank | 17 comment | 0 complexity | 1f40afdda2dd674bdb8cb30b5fcefe31 MD5 | raw file
 1/*
 2 * object.d
 3 *
 4 * This module implements the Object class.
 5 *
 6 */
 7
 8module object;
 9
10// Imports necessary routines used by the runtime
11import runtime.util;
12import runtime.dstatic;
13import runtime.dstubs;
14import runtime.exception;
15import runtime.error;
16
17public import runtime.types;
18public import runtime.classinfo;
19public import runtime.typeinfo;
20
21// Description: The base class inherited by all classes.
22class Object {
23
24	// Description: Returns a string representing this object.
25	char[] toString() {
26		return this.classinfo.name;
27	}
28
29	// Description: Computes a hash representing this object
30	hash_t toHash() {
31		string hashStr = (toStr(&this) ~ this.classinfo.name);
32
33		hash_t hash = 0;
34		foreach(chr; hashStr) {
35			hash *= 9;
36			hash += cast(ubyte)chr;
37		}
38	}
39
40	// Will compare two Object classes
41	// Returns: 0 if equal, -1 if o is greater, 1 if o is smaller.
42	int opCmp(Object o) {
43		// BUG: this prevents a compacting GC from working, needs to be fixed
44		//return cast(int)cast(void *)this - cast(int)cast(void *)o;
45
46		throw new Error("need opCmp for class " ~ this.classinfo.name);
47	}
48
49	// Will compare two Object classes for equality.
50	// Returns: 0 if not equal.
51	int opEquals(Object o) {
52		return cast(int)(this is o);
53	}
54}
55
56// Description: This is the information stored for an interface.
57struct Interface {
58	ClassInfo classinfo;		// .classinfo for this interface (not for containing class)
59	void *[] vtbl;
60	int offset; 				// offset to Interface 'this' from Object 'this'
61}
62
63public import djehuty;