-
Notifications
You must be signed in to change notification settings - Fork 1
MDL Extension | Objects
This MDL extension provides the capability for describing classes, and hence the objects they in turn describe. This extension is meant to provide the widest range of features, for more specific features, look to other extensions, including:
- Fast Member Variables.
- Private Member Variable Space.
- Methods.
- Class methods.
- Static class methods.
- Constructors.
- Destructors.
- Casting. (Up and down)
- Reflection.
- Inheritance.
- Multiple Inheritance (with separated, or shared, base class).
- Interfaces. (abstract classes)
- Meta-objects.
It is up to plugin language extension writers to work with (or provide) these features in the language they implement. Like all extensions, an expansion function is provided to expand the extension into base MDL.
An object, an instance of a class, is a pointer to a struct, while in reality the pointed at struct contains the majority of information for the object, the pointer represents the conceptual object.
The object struct contains the following fields:
- Class (Pointer) - This is a pointer to an object struct of type class providing methods for the object.
- Private (Void Pointer) - This is where the plugin language wrapper that created the object can store a pointer to the actual representation of the object.
- Parent Objects (Array[#parents] Pointers) - This is a pointer to the objects representing this objects parents (since the may be provided by other plugins).
- Public struct data (Varies) - Public fast access data.
Below are implementation details for each specific feature.
Each object struct contains as its last values public struct data, followed by private data. This is a variable sized portion of the struct (allocated after the standard 2 pointer object header). Public data is automatically calculated by language wrappers and access provided by language extensions. Private data is declared in an attribute.
A pointer is provided for arbitrary private member space in the standard part of the object header.
Methods are public (but name mangled if expanded) variables on the class object which accept the object header as the first argument.
Class methods are public (but name mangled if expanded) variables on the class object which accept a class object header as the first argument. This class should derive from, or be somehow related to, the class on which this method is found.
Static methods are public (but name mangled if expanded) variables on the class object which accept no special first argument. These are there primarily for name spacing purposes.
Constructors are class methods with a specific signature and the constructor attribute, specifically the signature must indicate the return of the current class, it is also responsible for allocating said memory. (The attribute is superfluous but is useful for some programming languages, the attribute can also mark a constructor as the "primary" one)
Destructors are class methods with a specific signature and the destructor attribute, specifically the signature must return void and guarantee to free the memory of the object pointer it is given. (The attribute is superfluous but is useful for some programming languages, the attribute can also mark a destructor as the "primary" one)
Casting is done by simply extracting the parent pointer of the correct type and passing it along. This works because the private data in each object of the parent hierarchy is the same, merely the fast public and class change.
The root class object provides methods for reflection, since every object should in some way derive from it (either via oftype or inheritance relationships) it provides a core set of reflection functionality. Objects can of course become new root nodes in the tree by being of their own class, this is, however, not recommended as the root class also provides a large set of the core functionality.
Inheritance is the extension of an existing class. When a class is derived from a base class the derived class contains all of the base classes attributes. There are two approches
- Inheritance.
- Multiple Inheritance (with separated, or shared, base class).
- Interfaces. (abstract classes)
- Meta-objects.