blitz_object.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef BLITZ_OBJECT_H
  2. #define BLITZ_OBJECT_H
  3. #include "blitz_types.h"
  4. #ifdef __cplusplus
  5. extern "C"{
  6. #endif
  7. #define BBNULL (&bbNullObject)
  8. #define BBNULLOBJECT (&bbNullObject)
  9. struct BBClass{
  10. //extends BBGCPool
  11. BBClass* super;
  12. void (*free)( BBObject *o );
  13. BBDebugScope*debug_scope;
  14. unsigned int instance_size;
  15. void (*ctor)( BBObject *o );
  16. void (*dtor)( BBObject *o );
  17. BBString* (*ToString)( BBObject *x );
  18. int (*Compare)( BBObject *x,BBObject *y );
  19. BBObject* (*SendMessage)( BBObject * o, BBObject *m,BBObject *s );
  20. BBINTERFACETABLE itable;
  21. void* extra;
  22. unsigned int obj_size;
  23. unsigned int instance_count;
  24. unsigned int fields_offset;
  25. void* vfns[40];
  26. };
  27. struct BBObject{
  28. //extends BBGCMem
  29. BBClass* clas;
  30. //int refs;
  31. };
  32. struct BBInterface {
  33. BBClass* clas;
  34. const char *name;
  35. };
  36. struct BBInterfaceOffsets {
  37. BBINTERFACE ifc;
  38. int offset;
  39. };
  40. struct BBInterfaceTable {
  41. BBINTERFACEOFFSETS ifc_offsets;
  42. void * ifc_vtable;
  43. int ifc_size;
  44. };
  45. extern BBClass bbObjectClass;
  46. extern BBObject bbNullObject;
  47. BBObject* bbObjectNew( BBClass *t );
  48. BBObject* bbObjectAtomicNew( BBClass *t );
  49. BBObject* bbObjectNewNC( BBClass *t );
  50. BBObject* bbObjectAtomicNewNC( BBClass *t );
  51. void bbObjectFree( BBObject *o );
  52. void bbObjectCtor( BBObject *o );
  53. void bbObjectDtor( BBObject *o );
  54. BBString* bbObjectToString( BBObject *o );
  55. int bbObjectCompare( BBObject *x,BBObject *y );
  56. BBObject* bbObjectSendMessage( BBObject * o, BBObject *m,BBObject *s );
  57. void bbObjectReserved();
  58. BBObject* bbObjectDowncast( BBObject *o,BBClass *t );
  59. BBObject* bbObjectStringcast( BBObject *o );
  60. BBObject* bbObjectArraycast( BBObject *o );
  61. int bbObjectIsString( BBObject *o );
  62. int bbObjectIsArray( BBObject *o );
  63. void bbObjectRegisterType( BBClass *clas );
  64. BBClass** bbObjectRegisteredTypes( int *count );
  65. void bbObjectDumpInstanceCounts(char * buf, int size, int includeZeros);
  66. extern int bbCountInstances;
  67. void bbObjectRegisterInterface( BBInterface * ifc );
  68. BBInterface **bbObjectRegisteredInterfaces( int *count );
  69. BBObject * bbInterfaceDowncast(BBOBJECT o, BBINTERFACE ifc);
  70. void * bbObjectInterface(BBOBJECT o, BBINTERFACE ifc);
  71. struct struct_node {
  72. struct avl_root link;
  73. BBDebugScope * scope;
  74. };
  75. void bbObjectRegisterStruct( BBDebugScope *p );
  76. BBDebugScope * bbObjectStructInfo( char * name );
  77. BBObject * bbNullObjectTest( BBObject *o );
  78. struct enum_node {
  79. struct avl_root link;
  80. BBDebugScope * scope;
  81. };
  82. void bbObjectRegisterEnum( BBDebugScope *p );
  83. BBDebugScope * bbObjectEnumInfo( char * name );
  84. #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  85. inline void * bbObjectToFieldOffset(BBOBJECT o) {
  86. if ( !o->clas ) {
  87. return &bbNullObject;
  88. }
  89. return (void*)(((unsigned char*)o) + o->clas->fields_offset);
  90. }
  91. #else
  92. void * bbObjectToFieldOffset(BBOBJECT o);
  93. #endif
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif