📄 classini.c
字号:
if (DefclassData(theEnv)->ClassTable != NULL)
{
for (j = 0 ; j < CLASS_TABLE_HASH_SIZE ; j++)
for (cls = DefclassData(theEnv)->ClassTable[j] ; cls != NULL ; cls = cls->nxtHash)
{
for (i = 0 ; i < cls->slotCount ; i++)
{
if ((cls->slots[i].defaultValue != NULL) && (cls->slots[i].dynamicDefault == 0))
{
tmpexp = ((DATA_OBJECT *) cls->slots[i].defaultValue)->supplementalInfo;
rtn_struct(theEnv,dataObject,cls->slots[i].defaultValue);
cls->slots[i].defaultValue = tmpexp;
}
}
}
}
#endif
}
#if ! RUN_TIME
/*********************************************************/
/* DestroyDefclassAction: Action used to remove defclass */
/* as a result of DestroyEnvironment. */
/*********************************************************/
#if IBM_TBC
#pragma argsused
#endif
static void DestroyDefclassAction(
void *theEnv,
struct constructHeader *theConstruct,
void *buffer)
{
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(buffer)
#endif
struct defclass *theDefclass = (struct defclass *) theConstruct;
if (theDefclass == NULL) return;
#if (! BLOAD_ONLY)
DestroyDefclass(theEnv,theDefclass);
#else
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theEnv)
#endif
#endif
}
#endif
#if RUN_TIME
/***************************************************
NAME : ObjectsRunTimeInitialize
DESCRIPTION : Initializes objects system lists
in a run-time module
INPUTS : 1) Pointer to new class hash table
2) Pointer to new slot name table
RETURNS : Nothing useful
SIDE EFFECTS : Global pointers set
NOTES : None
***************************************************/
globle void ObjectsRunTimeInitialize(
void *theEnv,
DEFCLASS *ctable[],
SLOT_NAME *sntable[],
DEFCLASS **cidmap,
unsigned mid)
{
DEFCLASS *cls;
void *tmpexp;
register unsigned int i,j;
if (DefclassData(theEnv)->ClassTable != NULL)
{
for (j = 0 ; j < CLASS_TABLE_HASH_SIZE ; j++)
for (cls = DefclassData(theEnv)->ClassTable[j] ; cls != NULL ; cls = cls->nxtHash)
{
for (i = 0 ; i < cls->slotCount ; i++)
{
/* =====================================================================
For static default values, the data object value needs to deinstalled
and deallocated, and the expression needs to be restored (which was
temporarily stored in the supplementalInfo field of the data object)
===================================================================== */
if ((cls->slots[i].defaultValue != NULL) && (cls->slots[i].dynamicDefault == 0))
{
tmpexp = ((DATA_OBJECT *) cls->slots[i].defaultValue)->supplementalInfo;
ValueDeinstall(theEnv,(DATA_OBJECT *) cls->slots[i].defaultValue);
rtn_struct(theEnv,dataObject,cls->slots[i].defaultValue);
cls->slots[i].defaultValue = tmpexp;
}
}
}
}
InstanceQueryData(theEnv)->QUERY_DELIMETER_SYMBOL = FindSymbolHN(theEnv,QUERY_DELIMETER_STRING);
MessageHandlerData(theEnv)->INIT_SYMBOL = FindSymbolHN(theEnv,INIT_STRING);
MessageHandlerData(theEnv)->DELETE_SYMBOL = FindSymbolHN(theEnv,DELETE_STRING);
MessageHandlerData(theEnv)->CREATE_SYMBOL = FindSymbolHN(theEnv,CREATE_STRING);
DefclassData(theEnv)->ISA_SYMBOL = FindSymbolHN(theEnv,SUPERCLASS_RLN);
DefclassData(theEnv)->NAME_SYMBOL = FindSymbolHN(theEnv,NAME_RLN);
#if DEFRULE_CONSTRUCT
DefclassData(theEnv)->INITIAL_OBJECT_SYMBOL = FindSymbolHN(theEnv,INITIAL_OBJECT_NAME);
#endif
DefclassData(theEnv)->ClassTable = (DEFCLASS **) ctable;
DefclassData(theEnv)->SlotNameTable = (SLOT_NAME **) sntable;
DefclassData(theEnv)->ClassIDMap = (DEFCLASS **) cidmap;
DefclassData(theEnv)->MaxClassID = (unsigned short) mid;
DefclassData(theEnv)->PrimitiveClassMap[FLOAT] =
LookupDefclassByMdlOrScope(theEnv,FLOAT_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[INTEGER] =
LookupDefclassByMdlOrScope(theEnv,INTEGER_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[STRING] =
LookupDefclassByMdlOrScope(theEnv,STRING_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[SYMBOL] =
LookupDefclassByMdlOrScope(theEnv,SYMBOL_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[MULTIFIELD] =
LookupDefclassByMdlOrScope(theEnv,MULTIFIELD_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[EXTERNAL_ADDRESS] =
LookupDefclassByMdlOrScope(theEnv,EXTERNAL_ADDRESS_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[FACT_ADDRESS] =
LookupDefclassByMdlOrScope(theEnv,FACT_ADDRESS_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_NAME] =
LookupDefclassByMdlOrScope(theEnv,INSTANCE_NAME_TYPE_NAME);
DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS] =
LookupDefclassByMdlOrScope(theEnv,INSTANCE_ADDRESS_TYPE_NAME);
for (j = 0 ; j < CLASS_TABLE_HASH_SIZE ; j++)
for (cls = DefclassData(theEnv)->ClassTable[j] ; cls != NULL ; cls = cls->nxtHash)
{
for (i = 0 ; i < cls->slotCount ; i++)
{
if ((cls->slots[i].defaultValue != NULL) && (cls->slots[i].dynamicDefault == 0))
{
tmpexp = cls->slots[i].defaultValue;
cls->slots[i].defaultValue = (void *) get_struct(theEnv,dataObject);
EvaluateAndStoreInDataObject(theEnv,(int) cls->slots[i].multiple,(EXPRESSION *) tmpexp,
(DATA_OBJECT *) cls->slots[i].defaultValue,TRUE);
ValueInstall(theEnv,(DATA_OBJECT *) cls->slots[i].defaultValue);
((DATA_OBJECT *) cls->slots[i].defaultValue)->supplementalInfo = tmpexp;
}
}
}
}
#else
/***************************************************************
NAME : CreateSystemClasses
DESCRIPTION : Creates the built-in system classes
INPUTS : None
RETURNS : Nothing useful
SIDE EFFECTS : System classes inserted in the
class hash table
NOTES : The binary/load save indices for the primitive
types (integer, float, symbol and string,
multifield, external-address and fact-address)
are very important. Need to be able to refer
to types with the same index regardless of
whether the object system is installed or
not. Thus, the bsave/blaod indices of these
classes match their integer codes.
WARNING!!: Assumes no classes exist yet!
***************************************************************/
globle void CreateSystemClasses(
void *theEnv)
{
DEFCLASS *user,*any,*primitive,*number,*lexeme,*address,*instance;
#if DEFRULE_CONSTRUCT
DEFCLASS *initialObject;
#endif
/* ===================================
Add canonical slot name entries for
the is-a and name fields - used for
object patterns
=================================== */
AddSlotName(theEnv,DefclassData(theEnv)->ISA_SYMBOL,ISA_ID,TRUE);
AddSlotName(theEnv,DefclassData(theEnv)->NAME_SYMBOL,NAME_ID,TRUE);
/* =========================================================
Bsave Indices for non-primitive classes start at 9
Object is 9, Primitive is 10, Number is 11,
Lexeme is 12, Address is 13, and Instance is 14.
because: float = 0, integer = 1, symbol = 2, string = 3,
multifield = 4, and external-address = 5 and
fact-address = 6, instance-adress = 7 and
instance-name = 8.
========================================================= */
any = AddSystemClass(theEnv,OBJECT_TYPE_NAME,NULL);
primitive = AddSystemClass(theEnv,PRIMITIVE_TYPE_NAME,any);
user = AddSystemClass(theEnv,USER_TYPE_NAME,any);
number = AddSystemClass(theEnv,NUMBER_TYPE_NAME,primitive);
DefclassData(theEnv)->PrimitiveClassMap[INTEGER] = AddSystemClass(theEnv,INTEGER_TYPE_NAME,number);
DefclassData(theEnv)->PrimitiveClassMap[FLOAT] = AddSystemClass(theEnv,FLOAT_TYPE_NAME,number);
lexeme = AddSystemClass(theEnv,LEXEME_TYPE_NAME,primitive);
DefclassData(theEnv)->PrimitiveClassMap[SYMBOL] = AddSystemClass(theEnv,SYMBOL_TYPE_NAME,lexeme);
DefclassData(theEnv)->PrimitiveClassMap[STRING] = AddSystemClass(theEnv,STRING_TYPE_NAME,lexeme);
DefclassData(theEnv)->PrimitiveClassMap[MULTIFIELD] = AddSystemClass(theEnv,MULTIFIELD_TYPE_NAME,primitive);
address = AddSystemClass(theEnv,ADDRESS_TYPE_NAME,primitive);
DefclassData(theEnv)->PrimitiveClassMap[EXTERNAL_ADDRESS] = AddSystemClass(theEnv,EXTERNAL_ADDRESS_TYPE_NAME,address);
DefclassData(theEnv)->PrimitiveClassMap[FACT_ADDRESS] = AddSystemClass(theEnv,FACT_ADDRESS_TYPE_NAME,address);
instance = AddSystemClass(theEnv,INSTANCE_TYPE_NAME,primitive);
DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS] = AddSystemClass(theEnv,INSTANCE_ADDRESS_TYPE_NAME,instance);
DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_NAME] = AddSystemClass(theEnv,INSTANCE_NAME_TYPE_NAME,instance);
#if DEFRULE_CONSTRUCT
initialObject = AddSystemClass(theEnv,INITIAL_OBJECT_CLASS_NAME,user);
initialObject->abstract = 0;
initialObject->reactive = 1;
#endif
/* ================================================================================
INSTANCE-ADDRESS is-a INSTANCE and ADDRESS. The links between INSTANCE-ADDRESS
and ADDRESS still need to be made.
=============================================================================== */
AddClassLink(theEnv,&DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS]->directSuperclasses,address,-1);
AddClassLink(theEnv,&DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS]->allSuperclasses,address,2);
AddClassLink(theEnv,&address->directSubclasses,DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS],-1);
/* =======================================================================
The order of the class in the list MUST correspond to their type codes!
See CONSTANT.H
======================================================================= */
AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[FLOAT]);
AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[INTEGER]);
AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[SYMBOL]);
AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[STRING]);
AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[MULTIFIELD]);
AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[EXTERNAL_ADDRESS]);
AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[FACT_ADDRESS]);
AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS]);
AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_NAME]);
AddConstructToModule((struct constructHeader *) any);
AddConstructToModule((struct constructHeader *) primitive);
AddConstructToModule((struct constructHeader *) number);
AddConstructToModule((struct constructHeader *) lexeme);
AddConstructToModule((struct constructHeader *) address);
AddConstructToModule((struct constructHeader *) instance);
AddConstructToModule((struct constructHeader *) user);
#if DEFRULE_CONSTRUCT
AddConstructToModule((struct constructHeader *) initialObject);
#endif
for (any = (DEFCLASS *) EnvGetNextDefclass(theEnv,NULL) ;
any != NULL ;
any = (DEFCLASS *) EnvGetNextDefclass(theEnv,(void *) any))
AssignClassID(theEnv,any);
}
#endif
/* =========================================
*****************************************
INTERNALLY VISIBLE FUNCTIONS
=========================================
***************************************** */
/*********************************************************
NAME : SetupDefclasses
DESCRIPTION : Initializes Class Hash Table,
Function Parsers, and Data Structures
INPUTS : None
RETURNS : Nothing useful
SIDE EFFECTS :
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -