What is a MANAGED OBJECT ?
The micro-kernel links the "C"
library theKernel with a target-language. The basics of the micro-kernel are implemented as MANAGED OBJECT.
The aim of managed-object technology is that a class defined in "C"
is automatically available as a class in the target-language.
This requires three technologies:
"C"
into code that can be used as a native class in the target-language."C"
class and the target-language class.Example: The managed-object class MkBufferStreamC in "C"
is available as MkBufferStreamC (C, C++, Java, Python, Tcl) in all target-languages.
Each class in the target-language that supports managed-objects uses a base-class that supports managed-objects and has a shadow-class in the micro-kernel.
A managed-object class has two or three sections:
superclass | This is the section that defines the class hierarchy |
instance attributes | This is the section used by the programmer to define the attributes |
ILS storage | This is an optional section that is used as a predefined memory for dynamic instance attributes |
One design-goal of the micro-kernel was type-safty, this mean that never a HARD cast should be required:
Example from kernel_mk.h
→ The abstract class MkBufferStreamS managed-object struct
The class MkBufferStreamS is an abstract class, since the instant-local-storage MkBufferStreamS_ils_size is "0".
The abstract class implements all of the methods, but have to be superordinated to the final-class.
In the case of MkBufferStreamS the final-classes are:
MkBufferStream16384S, MkBufferStream256S and MkBufferStream64S
Example from kernel_mk.h
→ The superclass definition is a union over all base-classes up to MkObjectC
Two compile-time-casts from the abstract class MkBufferStreamS are valid:
&BufferStreamPtr->super.obj
== MkOBJ(BufferStreamPtr)
&BufferStreamPtr->super.buf
== MkBUF(BufferStreamPtr)
There is also a redundant cast:
&BufferStreamPtr->super.obj
== &BufferStreamPtr->super.buf.super.obj
The reason is that MkBufferS is also an managed-object and has the attribute super.obj
.
For every managed-object the cast
&pointer->super.obj
always exists.
The both names obj and buf are no concidence, the MANAGED OBJECT uses for class-lookup the short-name from the defined-namespace.
C-struct | class | class-prefix | C-short | runtime-cast | compile-time-cast | short-name | long-name |
---|---|---|---|---|---|---|---|
void* | MK_MNG | mng | |||||
struct MkObjectS | MkObjectC | Object | MK_OBJ | MkObj | MkOBJ | obj | object |
struct MkBufferS | MkBufferC | Buffer | MK_BUF | MkBuf | MkBUF | buf | buffer |
struct MkBufferStreamS | MkBufferStreamC | BufferStream | MK_BUS | MkBus | MkBUS | bus | stream |
struct MkBufferListS | MkBufferListC | BufferList | MK_BFL | MkBfl | MkBFL | bfl | buffer-list |
struct MkLogFileS | MkLogFileC | LogFile | MK_LFL | MkLfl | MkLFL | lfl | log-file |
struct MkErrorS | MkErrorC | Error | MK_ERR | MkErr | MkERR | err | error |
struct MkRuntimeS | MkRuntimeC | Runtime | MK_RT | MkRt | MkRT | rt | runtime |
The MK_MNG is a special pointer, and is used to store a managed-object pointer to a location outside the kernel with its garanteed validity.
The goal is to always soft-cast an MK_MNG pointer to a valid managed-object pointer.