Преглед на файлове

Added fields offset to BBClass.

Brucey преди 5 години
родител
ревизия
ad062a7499
променени са 5 файла, в които са добавени 39 реда и са изтрити 2 реда
  1. 6 0
      blitz.mod/blitz.bmx
  2. 1 0
      blitz.mod/blitz_array.c
  3. 20 2
      blitz.mod/blitz_object.c
  4. 11 0
      blitz.mod/blitz_object.h
  5. 1 0
      blitz.mod/blitz_string.c

+ 6 - 0
blitz.mod/blitz.bmx

@@ -569,6 +569,12 @@ returns: #True if @obj is an empty #String, or #False otherwise.
 End Rem
 End Rem
 Function IsEmptyString:Int(obj:Object)="int bbObjectIsEmptyString(BBOBJECT)!"
 Function IsEmptyString:Int(obj:Object)="int bbObjectIsEmptyString(BBOBJECT)!"
 
 
+Rem
+bbdoc: Determines whether the #Object @obj is a #String.
+returns: #True if @obj is a #String, or #False otherwise.
+End Rem
+Function ObjectIsString:Int(obj:Object)="int bbObjectIsString(BBOBJECT)!"
+
 Function DumpObjectCounts(buffer:Byte Ptr, size:Int, includeZeros:Int)="bbObjectDumpInstanceCounts"
 Function DumpObjectCounts(buffer:Byte Ptr, size:Int, includeZeros:Int)="bbObjectDumpInstanceCounts"
 Global CountObjectInstances:Int="bbCountInstances"
 Global CountObjectInstances:Int="bbCountInstances"
 
 

+ 1 - 0
blitz.mod/blitz_array.c

@@ -26,6 +26,7 @@ BBClass bbArrayClass={
 	0,          //extra
 	0,          //extra
 	0,          //obj_size
 	0,          //obj_size
 	0,          //instance_count
 	0,          //instance_count
+	offsetof(BBArray, type), //fields_offset
 	
 	
 	bbArraySort,
 	bbArraySort,
 	bbArrayDimensions
 	bbArrayDimensions

+ 20 - 2
blitz.mod/blitz_object.c

@@ -27,7 +27,9 @@ BBClass bbObjectClass={
 	bbObjectSendMessage,
 	bbObjectSendMessage,
 	0,             //interface
 	0,             //interface
 	0,             //extra
 	0,             //extra
-	0              //obj_size
+	0,             //obj_size
+	0,             //instance_count
+	sizeof(void*)  //fields_offset
 };
 };
 
 
 BBObject bbNullObject={
 BBObject bbNullObject={
@@ -104,6 +106,10 @@ BBObject *bbObjectStringcast( BBObject *o ){
 	}
 	}
 }
 }
 
 
+int bbObjectIsString( BBObject *o ){
+	return o->clas == &bbStringClass;
+}
+
 BBObject *bbObjectArraycast( BBObject *o ){
 BBObject *bbObjectArraycast( BBObject *o ){
 	if (o->clas == &bbArrayClass) {
 	if (o->clas == &bbArrayClass) {
 		return o;
 		return o;
@@ -112,6 +118,10 @@ BBObject *bbObjectArraycast( BBObject *o ){
 	}
 	}
 }
 }
 
 
+int bbObjectIsArray( BBObject *o ){
+	return o->clas == &bbArrayClass;
+}
+
 BBObject *bbObjectDowncast( BBObject *o,BBClass *t ){
 BBObject *bbObjectDowncast( BBObject *o,BBClass *t ){
 	BBClass *p=o->clas;
 	BBClass *p=o->clas;
 	while( p && p!=t ) p=p->super;
 	while( p && p!=t ) p=p->super;
@@ -299,4 +309,12 @@ BBDebugScope * bbObjectEnumInfo( char * name ) {
 	}
 	}
 	
 	
 	return 0;
 	return 0;
-}
+}
+
+#if __STDC_VERSION__ >= 199901L
+extern void * bbObjectToFieldOffset(BBOBJECT o);
+#else
+void * bbObjectToFieldOffset(BBOBJECT o) {
+	return (void*)(((unsigned char*)o) + o->clas->fields_offset);
+}
+#endif

+ 11 - 0
blitz.mod/blitz_object.h

@@ -32,6 +32,7 @@ struct BBClass{
 	void*   extra;
 	void*   extra;
 	unsigned int obj_size;
 	unsigned int obj_size;
 	unsigned int instance_count;
 	unsigned int instance_count;
+	unsigned int fields_offset;
 
 
 	void*	vfns[32];
 	void*	vfns[32];
 };
 };
@@ -78,6 +79,8 @@ void		bbObjectReserved();
 BBObject*	bbObjectDowncast( BBObject *o,BBClass *t );
 BBObject*	bbObjectDowncast( BBObject *o,BBClass *t );
 BBObject*	bbObjectStringcast( BBObject *o );
 BBObject*	bbObjectStringcast( BBObject *o );
 BBObject*	bbObjectArraycast( BBObject *o );
 BBObject*	bbObjectArraycast( BBObject *o );
+int bbObjectIsString( BBObject *o );
+int bbObjectIsArray( BBObject *o );
 
 
 void		bbObjectRegisterType( BBClass *clas );
 void		bbObjectRegisterType( BBClass *clas );
 BBClass**	bbObjectRegisteredTypes( int *count );
 BBClass**	bbObjectRegisteredTypes( int *count );
@@ -109,6 +112,14 @@ struct enum_node {
 void bbObjectRegisterEnum( BBDebugScope *p );
 void bbObjectRegisterEnum( BBDebugScope *p );
 BBDebugScope * bbObjectEnumInfo( char * name );
 BBDebugScope * bbObjectEnumInfo( char * name );
 
 
+#if __STDC_VERSION__ >= 199901L
+inline void * bbObjectToFieldOffset(BBOBJECT o) {
+	return (void*)(((unsigned char*)o) + o->clas->fields_offset);
+}
+#else
+void * bbObjectToFieldOffset(BBOBJECT o);
+#endif
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 1 - 0
blitz.mod/blitz_string.c

@@ -28,6 +28,7 @@ BBClass bbStringClass={
 	0,              //extra
 	0,              //extra
 	0,
 	0,
 	0,          //instance_count
 	0,          //instance_count
+	offsetof(BBString, length), //fields_offset
 	
 	
 	bbStringFind,
 	bbStringFind,
 	bbStringFindLast,
 	bbStringFindLast,