theKernel 10.0 NHI1 - theKernel - theLink - theConfig - theSq3Lite - theCompiler - theBrain - theGuard
c - tcl - py - rb - jv - cc
Loading...
Searching...
No Matches
MkTypeC_TOR_C_API

MkTypeS - various functions to create, initialize and destroy a typeMore...

+ Collaboration diagram for MkTypeC_TOR_C_API:

Macros

#define MkTypeCreate(clsV, basicV, identV)
 

Functions

MK_TYP MkTypeCreate (MK_MACRO_TYP const clsV, MK_MACRO_TYP const basicV, MK_STRN const identV)
 create a new type …
 
MK_EXTERN MK_TYP MkTypeDup2_RT (MK_RT mkrt, MK_TYPN const typ, MK_STRN const ident)
 duplicate a type-type as duplicate from an existing type but with a new name …
 
MK_EXTERN MK_OBJ MkTypeAlloc_RT (MK_RT mkrt, MK_TYPN const typ)
 alloc instance-memory for MkTypeS
 
MK_EXTERN MK_TYP MkTypeResolve_RT (MK_RT mkrt, MK_TYPN const typ)
 resolve a new type
 
MK_EXTERN void MkTypeDelete_RT (MK_RT mkrt, MK_TYP const typ)
 delete a type object
 

MkTypeC - MkTypeC_TOR_C_API - overload

#define MkTypeAlloc_NULL(...)
 
#define MkTypeAlloc(...)
 
#define MkTypeDup2_NULL(...)
 
#define MkTypeDup2(...)
 
#define MkTypeResolve_NULL(...)
 
#define MkTypeResolve(...)
 
#define MkTypeDelete_NULL(...)
 
#define MkTypeDelete(...)
 

Detailed Description

MkTypeS - various functions to create, initialize and destroy a type

Macro Definition Documentation

◆ MkTypeAlloc

#define MkTypeAlloc ( ...)
Value:
#define MK_RT_CALL
MK_EXTERN MK_OBJ MkTypeAlloc_RT(MK_RT mkrt, MK_TYPN const typ)
alloc instance-memory for MkTypeS …

Definition at line 1835 of file kernel_overload_mk.h.

◆ MkTypeAlloc_NULL

#define MkTypeAlloc_NULL ( ...)
Value:
#define MK_RT_CALL_NULL

Definition at line 1834 of file kernel_overload_mk.h.

◆ MkTypeCreate

#define MkTypeCreate ( clsV,
basicV,
identV )
Value:
({ \
MK_TYP ret = MkTypeDup2(basicV ## _TT,identV); \
ret->objsig = clsV ## _SIGNATURE; \
ret->objmask = clsV ## _MASK; \
ret->objsize = sizeof(clsV##R); \
ret ; \
})
#define MkTypeDup2(...)
MkTypeS - class known as typ or type is used as class-base for a Managed-Object-Technology (MOT) type...
size_t objsize
the size of the new object created with this type, used in malloc
MK_SIG objsig
public st signatur of the type-instance
MK_SIG objmask
public object signatur-mask of the type-instance

Definition at line 4630 of file LibMkKernel_mk.h.

4630#define MkTypeCreate(clsV, basicV, identV) ({ \
4631 MK_TYP ret = MkTypeDup2(basicV ## _TT,identV); \
4632 ret->objsig = clsV ## _SIGNATURE; \
4633 ret->objmask = clsV ## _MASK; \
4634 ret->objsize = sizeof(clsV##R); \
4635 ret ; \
4636})

◆ MkTypeDelete

#define MkTypeDelete ( ...)
Value:
MK_EXTERN void MkTypeDelete_RT(MK_RT mkrt, MK_TYP const typ)
delete a type object

Definition at line 1843 of file kernel_overload_mk.h.

◆ MkTypeDelete_NULL

#define MkTypeDelete_NULL ( ...)
Value:

Definition at line 1842 of file kernel_overload_mk.h.

◆ MkTypeDup2

#define MkTypeDup2 ( ...)
Value:
MK_EXTERN MK_TYP MkTypeDup2_RT(MK_RT mkrt, MK_TYPN const typ, MK_STRN const ident)
duplicate a type-type as duplicate from an existing type but with a new name …

Definition at line 1837 of file kernel_overload_mk.h.

◆ MkTypeDup2_NULL

#define MkTypeDup2_NULL ( ...)
Value:

Definition at line 1836 of file kernel_overload_mk.h.

◆ MkTypeResolve

#define MkTypeResolve ( ...)
Value:
MK_EXTERN MK_TYP MkTypeResolve_RT(MK_RT mkrt, MK_TYPN const typ)
resolve a new type

Definition at line 1839 of file kernel_overload_mk.h.

◆ MkTypeResolve_NULL

#define MkTypeResolve_NULL ( ...)
Value:

Definition at line 1838 of file kernel_overload_mk.h.

Function Documentation

◆ MkTypeAlloc_RT()

MK_EXTERN MK_OBJ MkTypeAlloc_RT ( MK_RT mkrt,
MK_TYPN const typ )

alloc instance-memory for MkTypeS

The following steps are done:

  1. resolve the type to fit into MkRuntimeC
  2. allocate the memory using the allocator from the type -> (MkTypeS::objalloc)
  3. initialize the memory to zero
  4. initialize the instance
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]typthe MkTypeS instance to work on (nonnull)

◆ MkTypeCreate()

MK_TYP MkTypeCreate ( MK_MACRO_TYP const clsV,
MK_MACRO_TYP const basicV,
MK_STRN const identV )

create a new type …

Ther are three scenarios in which a new type is created:

  1. when a new c-library is created and the new c-library creates a c-library-specific type.
    → this is called full-weight-type
  2. when a new type is created as an extension of an already existing type but without signature and mask.
    → this is called light-weight-type
  3. when a Target-Programming-Language (TPL) is linked to an existing meta-code-c-library.
    → this is called shadow-type

shadow-type

The shadow-type is used to link a Target-Programming-Language (TPL) with a meta-library. The goal is not to create a new-type but to map an already-existing-type into the Target-Programming-Language (TPL).

‍A shadow-type is just the already-existing-type extended with MkTypeS::selfCreate and MkTypeS::selfDelete and a link of the TPL-Class-Pointer into MkObjectS::self. The shadow-type has not its own memory and all changes to the shadow-type will change the already-existing-type.


light-weight-type

The light-weight-type is created from an already-existing-type and a specific-instance-struct but without an own signature and mask. This type reuse all features of the already-existing-type without replaceing the already-existing-type.
The light-weight-type has its own memory and all changes to the light-weight-type will not change the already-existing-type.

Example: the "acut" tool
struct CutCtxS {
struct MqContextS mqctx;
MK_I32 fields[256];
};
...
static MK_TYP CutTT = NULL;
#define CutT ( (typeof(MqContextC_T)) CutTT )
static enum MkErrorE
CutFactory ( MQ_CALLBACK_FACTORY_CTOR_ARGS )
{
MQ_CTX const mqctx = MqContextCreate(CutTT,tmpl);
MqConfigSetName(mqctx, "cut");
MqConfigSetIsServer(mqctx, true);
*contextP = mqctx;
return MK_OK;
}
void CutInit( MQ_RT_ARGS_ONLY ) {
CutTT = MkTypeDup2(MqContextC_TT,"CutC");
CutTT->objsize = sizeof(struct CutCtxS);
CutT->Parent.fCreate = CutCreate;
CutT->fHelp = CutHelp;
MqFactoryAdd (MK_ERROR_PANIC, CutFactory, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "cut");
}

full-weight-type

The full-weight-type is created using the MkTypeCreate with a type-class, class-base, type-name.

The type is created as MkTypeDup2 from the basic type followed by an update of the type specific fields objsig, objmask and objsize.

This kind of type is called a full-weight-type, because this type does provide a new signature and mask. In difference to MkTypeCreate the MkTypeDup2 create a lightweight-type.

The fullweight-type is defined by the tool c_Class.tcl and is able to operate independent from any other type.

Parameters
[in]clsVthe real type-name in "C" (usually the same as identV), the type-name who was registerd with the c_CLS.tcl tool. (syntax: NsClassC, Ns=namespace)
[in]basicVthe basic-type, have to be MkObjectC or a decend of this
[in]identVthe display-name (MkTypeS::type_name), default is the name of the base-class (basicV->type_name).
Attention
The newType MkTypeS::base is set to basicType and the MkObjectS::refCount of basicType is incremented.

example - create a NEW type

// the new type "LcConfigC" is thread-local
SQ3_EXTERN_DATA MkThreadLocal MK_TYP LcConfigC_TT;
// setup the NEW type with name "LcConfigC" using the base class "MkObjectC"
void LcConfig_Setup (MK_RT mkrt) {
LcConfigC_TT = MkTypeCreate(LcConfigC, MkObjectC, "LcConfigC");
...
}
// every NEW runtime call sLcRuntimeInitCallback and create the NEW type "LcConfigC"
static void sLcRuntimeInitCallback ( struct MkRuntimeS * mkrt ) {
// BEGIN-Class-Setup - created by 'c_Class.tcl -i NHI1_HOME/theConfig/c/.liblcconfig.meta' - DO NOT change
LcConfig_Setup (mkrt);
LcSetting_Setup (mkrt);
// END-Class-Setup - created by 'c_Class.tcl -i NHI1_HOME/theConfig/c/.liblcconfig.meta' - DO NOT change
...
}
// the library-constructor register the runtime-setup-callback: sLcRuntimeInitCallback
void LcSetup(void)
{
...
MkRuntimeCallbackAdd( &sLcRuntimeCallback, MK_RT_PTR, sLcRuntimeInitCallback, "LcConfig" );
...
}
// the library-constructor have to be called FIRST
LC_EXTERN void MK_DECL LcSetup (void) __attribute__ ((constructor(1000)));
#define MK_DECL
MK_EXTERN void MkSetup(void)
setup libmkkernel internal memory …
#define MkThreadLocal
#define MK_RT_PTR
MK_EXTERN void MkRuntimeCallbackAdd(struct MkRuntimeCallbackS *cbdata, MK_RT mkrt, MkRuntimeInitF rt_callback, MK_STRN ident)
add a callback to the runtime …
#define MkTypeCreate(clsV, basicV, identV)
The MkRuntimeS provide a per-thread environment for LibMkKernel …

definition - of the macro

#define MkTypeCreate(clsV, basicV, identV) ({ \
MK_TYP ret = MkTypeDup2(basicV ## _TT,identV); \
ret->objsig = clsV ## _SIGNATURE; \
ret->objmask = clsV ## _MASK; \
ret->objsize = sizeof(clsV##R); \
ret ; \
})
See also
MkTypeDup2

◆ MkTypeDelete_RT()

MK_EXTERN void MkTypeDelete_RT ( MK_RT mkrt,
MK_TYP const typ )

delete a type object

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]typthe MkTypeS instance to work on - (nonnull)

◆ MkTypeDup2_RT()

MK_EXTERN MK_TYP MkTypeDup2_RT ( MK_RT mkrt,
MK_TYPN const typ,
MK_STRN const ident )

duplicate a type-type as duplicate from an existing type but with a new name …

This kind of type is called a lightweight-type, because this type does not provide a new signature and mask. In difference to MkTypeDup2 the MkTypeCreate create a fullweight-type.

call the Dup2-Constructor from the object

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]typthe MkTypeS instance to work on
[in]identthe display-name (MkTypeS::type_name) of the new type
Attention
The newType MkTypeS::base is set to srcType and the MkObjectS::refCount of srcType is incremented.

◆ MkTypeResolve_RT()

MK_EXTERN MK_TYP MkTypeResolve_RT ( MK_RT mkrt,
MK_TYPN const typ )

resolve a new type

Every NEW runtime require a new Type, This code is called in a callback registered with MkRuntimeCallbackAdd TODO: htmlcode{mqsetting,resolve_example,create a new type and resolve}

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]typthe MkTypeS instance to work on - (nonnull)