The syntax
Some examples
For a more elaborate example see taipan_cpp.c (C++ style multiple inheritance) and taipan_objc.c (single inheritance and Java/objective-C style interfaces) in the examples subdirectory.
Some guidelines
Constructors
Destructor
Internal operation
Some notes on the internal operation:
-
Static and normal (not virtual) methods are bound directly to the corresponding function call. The object is autmatically converted, i.e. the call switches to the appropriate base class (the class where to method was defined or last attached when redefining normal/static methods). This automatic conversion does not short-cut any type checking.
-
Virtual methods use a vtbl for their dispatching. The object is again autmatically converted, i.e. the call switches to the appropriate base class, i.e. the class where to method was last attached.
-
Virtual methods known only from their interface use dynamic binding for their dispatching. Type checking on the object is however short-cutted. The remaining arguments are still fully type-checked.
Naming conventions:
-
item names with on ore more '__' in it are reserved for internal use
-
class and method dependent items have names of the following format:
prefix__class__method
-
class dependent but method independent items have names of the following format:
prefix__class
-
class and method independent items have names of the following format:
prefix__
-
'prefix'
does not contain a '__'
(nor does it end with a '_'
) and prefix follows the normal spraak rules, i.e. dependent on the item type, prefix starts with 'spr_'
, 'SPR_'
, 'Spr'
, ...)
Automatically generated types, variables and defines:
- SprRTTI__class__method
- typedef function pointer for each method (static of virtual); used by SprMethodPtr()
- SprRTTI__class spr_rttid__class,spr_rttis__class;
- typedef + variable: the run-time information contains run-time type information and the virtual functions dispatch table; the structure mimics the hierarchical structure of the class (base classes)
- const char spr_rtti_mid__class__method[]
- unique name of the method (given the class in which the method was defined)
- const char spr_rtti_cid__class[]
- unique name of the class
- const char *const *spr_rtti_method__class[]
- array containing the names of the virtual methods
- SPR_DO__class__method
- macro that does that provides the necessary information for the combination of class and method for SPR_DO(), SPR_DO_FPTR() and SPR_DO_OPTR()
- SPR_CAST__class__base
- macro that does that actual combination of class and base for SPR_CAST()
- SPR_INIT__class
- macro that does the actual initialisation; used by SPR_OBJECT_INIT() and SPR_LVAR_OBJECT_INIT()
Planned extensions:
- SPR_DYNCAST(object,class_id)
- cast the type of the object to the class with the given class id; this is a slow function; returns NULL if the cast fails
- SPR_CLASSID_FROM_OBJ(object)
- get the id (a pointer to a unique string) of the class the object belongs to
- SPR_CLASSID_FORM_CLASS(class)
- get the id (a pointer to a unique string) for the given class
- SPR_OBJ_ISINSTANCE_OF(object,class_id)
- check if the object can be casted the class with the given id; is a slow function
- SPR_OBJ_DYN_ROOT(object)
- convert the object to its root object (go all the way up in the hierarchy)