Browse Source

Refactored class interfaces.

woollybah 10 years ago
parent
commit
c53b147daf

+ 2 - 3
blitz.mod/blitz_array.c

@@ -16,15 +16,14 @@ BBClass bbArrayClass={
 	bbArrayFree,	//free
 	&debugScope,	//DebugScope
 	0,			//instance_size
-	0,          //extra
 	0,			//ctor
 	0,			//dtor
 	
 	bbObjectToString,
 	bbObjectCompare,
 	bbObjectSendMessage,
-	0,
-	0,
+	0,          //interface
+	0,          //extra
 	0,
 	
 	bbArraySort,

+ 12 - 11
blitz.mod/blitz_object.c

@@ -17,16 +17,15 @@ BBClass bbObjectClass={
 	bbObjectFree,   //free
 	&debugScope,	//debug_scope
 	8,				//instance_size
-	0,             //extra
 	
 	bbObjectCtor,
 	bbObjectDtor,
 	bbObjectToString,
 	bbObjectCompare,
 	bbObjectSendMessage,
-	0,
-	0,
-	0,
+	0,             //interface
+	0,             //extra
+	0,             //reserved
 };
 
 BBObject bbNullObject={
@@ -139,9 +138,10 @@ BBObject * bbInterfaceDowncast(BBOBJECT o, BBINTERFACE ifc) {
 		BBCLASS clas = superclas;
 		superclas = clas->super;
 
-		BBINTERFACEOFFSETS offsets      = clas->ifc_offsets;
-		if (offsets) {
-			for (i = clas->ifc_size; i; i--) {
+		BBINTERFACETABLE table = clas->itable;
+		if (table) {
+			BBINTERFACEOFFSETS offsets = table->ifc_offsets;
+			for (i = table->ifc_size; i; i--) {
 				if (offsets->ifc == ifc) {
 					return o;
 				}
@@ -162,11 +162,12 @@ void * bbObjectInterface(BBOBJECT o, BBINTERFACE ifc) {
 		BBCLASS clas = superclas;
 		superclas = clas->super;
 
-		BBINTERFACEOFFSETS offsets      = clas->ifc_offsets;
-		if (offsets) {
-			for (i = clas->ifc_size; i; i--) {
+		BBINTERFACETABLE table = clas->itable;
+		if (table) {
+			BBINTERFACEOFFSETS offsets = table->ifc_offsets;
+			for (i = table->ifc_size; i; i--) {
 				if (offsets->ifc == ifc) {
-					return (char*) clas->ifc_vtable + offsets->offset;
+					return (char*) table->ifc_vtable + offsets->offset;
 				}
 				offsets++;
 			}

+ 9 - 4
blitz.mod/blitz_object.h

@@ -20,7 +20,6 @@ struct BBClass{
 	BBDebugScope*debug_scope;
 
 	int		instance_size;
-	void*   extra;
 
 	void		(*ctor)( BBObject *o );
 	void		(*dtor)( BBObject *o );
@@ -29,9 +28,9 @@ struct BBClass{
 	int		(*Compare)( BBObject *x,BBObject *y );
 	BBObject*	(*SendMessage)( BBObject *m,BBObject *s );
 
-	BBINTERFACEOFFSETS ifc_offsets;
-	void * ifc_vtable;
-	int ifc_size;
+	BBINTERFACETABLE itable;
+	void*   extra;
+	void*   reserved;
 
 	void*	vfns[32];
 };
@@ -52,6 +51,12 @@ struct BBInterfaceOffsets {
     int offset;
 };
 
+struct BBInterfaceTable {
+	BBINTERFACEOFFSETS ifc_offsets;
+	void * ifc_vtable;
+	int ifc_size;
+};
+
 extern	BBClass bbObjectClass;
 extern	BBObject bbNullObject;
 

+ 2 - 3
blitz.mod/blitz_string.c

@@ -18,15 +18,14 @@ BBClass bbStringClass={
 	bbStringFree,   //free
 	&debugScope,	//DebugScope
 	0,				//instance_size
-	0,              //extra
 	0,				//ctor
 	0,				//dtor
 
 	(BBString*(*)(BBObject*))bbStringToString,
 	(int(*)(BBObject*,BBObject*))bbStringCompare,
 	bbObjectSendMessage,
-	0,
-	0,
+	0,              //interface
+	0,              //extra
 	0,
 	
 	bbStringFind,

+ 2 - 0
blitz.mod/blitz_types.h

@@ -20,6 +20,7 @@ typedef struct BBClass	BBClass;
 typedef struct BBObject	BBObject;
 typedef struct BBString	BBString;
 typedef struct BBArray	BBArray;
+typedef struct BBInterfaceTable BBInterfaceTable;
 typedef struct BBInterface BBInterface;
 typedef struct BBInterfaceOffsets BBInterfaceOffsets;
 
@@ -33,6 +34,7 @@ typedef BBClass*		BBCLASS;
 typedef BBObject*		BBOBJECT;
 typedef BBString*		BBSTRING;
 typedef BBArray*		BBARRAY;
+typedef BBInterfaceTable*	BBINTERFACETABLE;
 typedef BBInterface*	BBINTERFACE;
 typedef BBInterfaceOffsets * BBINTERFACEOFFSETS;
 

+ 9 - 5
reflection.mod/reflection.bmx

@@ -69,6 +69,7 @@ Function bbRefArrayNull:Object()
 
 Function bbInterfaceName:Byte Ptr(ifc:Byte Ptr)
 Function bbInterfaceClass:Byte Ptr(ifc:Byte Ptr)
+Function bbObjectImplementsInterfaces:Int(class:Byte Ptr)
 Function bbObjectImplementedCount:Int(class:Byte Ptr)
 Function bbObjectImplementedInterface:Byte Ptr(class:Byte Ptr, index:Int)
 
@@ -2028,11 +2029,14 @@ Type TTypeId
 			p = bbDebugDeclNext(p)
 		Wend
 		' implemented interfaces ?
-		Local imps:Int = bbObjectImplementedCount(_class)
-		If imps > 0 Then
-			For Local i:Int = 0 Until imps
-				_interfaces.AddLast(_interfaceMap.ValueForKey(bbObjectImplementedInterface(_class, i)))
-			Next
+		Local impInt:Int = bbObjectImplementsInterfaces(_class)
+		If impInt Then
+			Local imps:Int = bbObjectImplementedCount(_class)
+			If imps > 0 Then
+				For Local i:Int = 0 Until imps
+					_interfaces.AddLast(_interfaceMap.ValueForKey(bbObjectImplementedInterface(_class, i)))
+				Next
+			End If
 		End If
 	End Method
 	

+ 6 - 2
reflection.mod/reflection.c

@@ -136,11 +136,15 @@ BBClass * bbInterfaceClass(BBInterface * ifc) {
 	return ifc->clas;
 }
 
+int bbObjectImplementsInterfaces(BBClass *clas) {
+	return clas->itable != 0;
+}
+
 int bbObjectImplementedCount(BBClass *clas) {
-	return clas->ifc_size;
+	return clas->itable->ifc_size;
 }
 
 BBInterface * bbObjectImplementedInterface(BBClass * clas, int index) {
-	return clas->ifc_offsets[index].ifc;
+	return clas->itable->ifc_offsets[index].ifc;
 }