/***************************************************** NAME : ObjectCmpConstantFunction DESCRIPTION : Used to compare object slot values against a constant INPUTS : 1) The constant test bitmap 2) Data object buffer to hold result RETURNS : TRUE if test successful, FALSE otherwise SIDE EFFECTS : Buffer set to symbol TRUE if test successful, FALSE otherwise NOTES : Called directly by EvaluatePatternExpression() *****************************************************/ globle intBool ObjectCmpConstantFunction( void *theEnv, void *theValue, DATA_OBJECT *theResult) { struct ObjectCmpPNConstant *hack; DATA_OBJECT theVar; EXPRESSION *constantExp; int rv; SEGMENT *theSegment; hack = (struct ObjectCmpPNConstant *) ValueToBitMap(theValue); if (hack->general) { EvaluateExpression(theEnv,GetFirstArgument(),&theVar); constantExp = GetFirstArgument()->nextArg; } else { constantExp = GetFirstArgument(); if (ObjectReteData(theEnv)->CurrentPatternObjectSlot->type == MULTIFIELD) { theSegment = (struct multifield *) ObjectReteData(theEnv)->CurrentPatternObjectSlot->value; if (hack->fromBeginning) { theVar.type = theSegment->theFields[hack->offset].type; theVar.value = theSegment->theFields[hack->offset].value; } else { theVar.type = theSegment->theFields[theSegment->multifieldLength - (hack->offset + 1)].type; theVar.value = theSegment->theFields[theSegment->multifieldLength - (hack->offset + 1)].value; } } else { theVar.type = (unsigned short) ObjectReteData(theEnv)->CurrentPatternObjectSlot->type; theVar.value = ObjectReteData(theEnv)->CurrentPatternObjectSlot->value; } } if (theVar.type != constantExp->type) rv = hack->fail; else if (theVar.value != constantExp->value) rv = hack->fail; else rv = hack->pass; theResult->type = SYMBOL; theResult->value = rv ? EnvTrueSymbol(theEnv) : EnvFalseSymbol(theEnv); return(rv); }
/*************************************************** NAME : ObjectPatternsCompilerSetup DESCRIPTION : Sets up interface for object patterns to construct compiler INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Code generator item added NOTES : None ***************************************************/ globle void ObjectPatternsCompilerSetup( void *theEnv) { ObjectReteData(theEnv)->ObjectPatternCodeItem = AddCodeGeneratorItem(theEnv,"object-patterns",0,BeforeObjectPatternsToCode, InitObjectPatternsCode,ObjectPatternsToCode,2); }
static intBool SlotLengthTestFunction( void *theEnv, void *theValue, DATA_OBJECT *theResult) { struct ObjectMatchLength *hack; theResult->type = SYMBOL; theResult->value = EnvFalseSymbol(theEnv); hack = (struct ObjectMatchLength *) ValueToBitMap(theValue); if (ObjectReteData(theEnv)->CurrentObjectSlotLength < hack->minLength) return(FALSE); if (hack->exactly && (ObjectReteData(theEnv)->CurrentObjectSlotLength > hack->minLength)) return(FALSE); theResult->value = EnvTrueSymbol(theEnv); return(TRUE); }
static intBool ObjectGetVarPNFunction2( void *theEnv, void *theValue, DATA_OBJECT *theResult) { struct ObjectMatchVar2 *hack; hack = (struct ObjectMatchVar2 *) ValueToBitMap(theValue); GetObjectValueSimple(theEnv,theResult,ObjectReteData(theEnv)->CurrentPatternObject,hack); return(TRUE); }
static CLIPS_BOOLEAN ObjectGetVarPNFunction1( void *theEnv, void *theValue, DATA_OBJECT *theResult) { struct ObjectMatchVar1 *hack; hack = (struct ObjectMatchVar1 *) ValueToBitMap(theValue); GetObjectValueGeneral(theEnv,theResult,ObjectReteData(theEnv)->CurrentPatternObject,ObjectReteData(theEnv)->CurrentPatternObjectMarks,hack); return(TRUE); }
static void DeallocateObjectReteData( void *theEnv) { OBJECT_PATTERN_NODE *theNetwork; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) return; #endif theNetwork = ObjectReteData(theEnv)->ObjectPatternNetworkPointer; DestroyObjectPatternNetwork(theEnv,theNetwork); }
static intBool PNSimpleCompareFunction1( void *theEnv, void *theValue, DATA_OBJECT *theResult) { struct ObjectCmpPNSingleSlotVars1 *hack; INSTANCE_SLOT *is1,*is2; int rv; hack = (struct ObjectCmpPNSingleSlotVars1 *) ValueToBitMap(theValue); is1 = GetInsSlot(ObjectReteData(theEnv)->CurrentPatternObject,hack->firstSlot); is2 = GetInsSlot(ObjectReteData(theEnv)->CurrentPatternObject,hack->secondSlot); if (is1->type != is2->type) rv = hack->fail; else if (is1->value != is2->value) rv = hack->fail; else rv = hack->pass; theResult->type = SYMBOL; theResult->value = rv ? EnvTrueSymbol(theEnv) : EnvFalseSymbol(theEnv); return(rv); }
static intBool PNSimpleCompareFunction3( void *theEnv, void *theValue, DATA_OBJECT *theResult) { struct ObjectCmpPNSingleSlotVars3 *hack; int rv; FIELD f1,f2; hack = (struct ObjectCmpPNSingleSlotVars3 *) ValueToBitMap(theValue); GetInsMultiSlotField(&f1,ObjectReteData(theEnv)->CurrentPatternObject,(unsigned) hack->firstSlot, (unsigned) hack->firstFromBeginning,(unsigned) hack->firstOffset); GetInsMultiSlotField(&f2,ObjectReteData(theEnv)->CurrentPatternObject,(unsigned) hack->secondSlot, (unsigned) hack->secondFromBeginning,(unsigned) hack->secondOffset); if (f1.type != f2.type) rv = hack->fail; else if (f1.value != f2.value) rv = hack->fail; else rv = hack->pass; theResult->type = SYMBOL; theResult->value = rv ? EnvTrueSymbol(theEnv) : EnvFalseSymbol(theEnv); return(rv); }
static CLIPS_BOOLEAN PNSimpleCompareFunction2( void *theEnv, void *theValue, DATA_OBJECT *theResult) { struct ObjectCmpPNSingleSlotVars2 *hack; int rv; FIELD f1; INSTANCE_SLOT *is2; hack = (struct ObjectCmpPNSingleSlotVars2 *) ValueToBitMap(theValue); GetInsMultiSlotField(&f1,ObjectReteData(theEnv)->CurrentPatternObject,(unsigned) hack->firstSlot, (unsigned) hack->fromBeginning,(unsigned) hack->offset); is2 = GetInsSlot(ObjectReteData(theEnv)->CurrentPatternObject,hack->secondSlot); if (f1.type != is2->type) rv = hack->fail; else if (f1.value != is2->value) rv = hack->fail; else rv = hack->pass; theResult->type = SYMBOL; theResult->value = rv ? EnvTrueSymbol(theEnv) : EnvFalseSymbol(theEnv); return(rv); }
/*************************************************** NAME : InstallObjectPrimitives DESCRIPTION : Installs all the entity records associated with object pattern matching operations INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Primitive operations installed NOTES : None ***************************************************/ globle void InstallObjectPrimitives( void *theEnv) { struct entityRecord objectGVInfo1 = { "OBJ_GET_SLOT_JNVAR1", OBJ_GET_SLOT_JNVAR1,0,1,0, PrintObjectGetVarJN1, PrintObjectGetVarJN1,NULL, ObjectGetVarJNFunction1, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord objectGVInfo2 = { "OBJ_GET_SLOT_JNVAR2", OBJ_GET_SLOT_JNVAR2,0,1,0, PrintObjectGetVarJN2, PrintObjectGetVarJN2,NULL, ObjectGetVarJNFunction2, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord objectGVPNInfo1 = { "OBJ_GET_SLOT_PNVAR1", OBJ_GET_SLOT_PNVAR1,0,1,0, PrintObjectGetVarPN1, PrintObjectGetVarPN1,NULL, ObjectGetVarPNFunction1, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord objectGVPNInfo2 = { "OBJ_GET_SLOT_PNVAR2", OBJ_GET_SLOT_PNVAR2,0,1,0, PrintObjectGetVarPN2, PrintObjectGetVarPN2,NULL, ObjectGetVarPNFunction2, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord objectCmpConstantInfo = { "OBJ_PN_CONSTANT", OBJ_PN_CONSTANT,0,1,1, PrintObjectCmpConstant, PrintObjectCmpConstant,NULL, ObjectCmpConstantFunction, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord lengthTestInfo = { "OBJ_SLOT_LENGTH", OBJ_SLOT_LENGTH,0,1,0, PrintSlotLengthTest, PrintSlotLengthTest,NULL, SlotLengthTestFunction, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord pNSimpleCompareInfo1 = { "OBJ_PN_CMP1", OBJ_PN_CMP1,0,1,1, PrintPNSimpleCompareFunction1, PrintPNSimpleCompareFunction1,NULL, PNSimpleCompareFunction1, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord pNSimpleCompareInfo2 = { "OBJ_PN_CMP2", OBJ_PN_CMP2,0,1,1, PrintPNSimpleCompareFunction2, PrintPNSimpleCompareFunction2,NULL, PNSimpleCompareFunction2, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord pNSimpleCompareInfo3 = { "OBJ_PN_CMP3", OBJ_PN_CMP3,0,1,1, PrintPNSimpleCompareFunction3, PrintPNSimpleCompareFunction3,NULL, PNSimpleCompareFunction3, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord jNSimpleCompareInfo1 = { "OBJ_JN_CMP1", OBJ_JN_CMP1,0,1,1, PrintJNSimpleCompareFunction1, PrintJNSimpleCompareFunction1,NULL, JNSimpleCompareFunction1, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord jNSimpleCompareInfo2 = { "OBJ_JN_CMP2", OBJ_JN_CMP2,0,1,1, PrintJNSimpleCompareFunction2, PrintJNSimpleCompareFunction2,NULL, JNSimpleCompareFunction2, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord jNSimpleCompareInfo3 = { "OBJ_JN_CMP3", OBJ_JN_CMP3,0,1,1, PrintJNSimpleCompareFunction3, PrintJNSimpleCompareFunction3,NULL, JNSimpleCompareFunction3, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL }; AllocateEnvironmentData(theEnv,OBJECT_RETE_DATA,sizeof(struct objectReteData),DeallocateObjectReteData); ObjectReteData(theEnv)->CurrentObjectSlotLength = 1; memcpy(&ObjectReteData(theEnv)->ObjectGVInfo1,&objectGVInfo1,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->ObjectGVInfo2,&objectGVInfo2,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->ObjectGVPNInfo1,&objectGVPNInfo1,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->ObjectGVPNInfo2,&objectGVPNInfo2,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->ObjectCmpConstantInfo,&objectCmpConstantInfo,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->LengthTestInfo,&lengthTestInfo,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->PNSimpleCompareInfo1,&pNSimpleCompareInfo1,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->PNSimpleCompareInfo2,&pNSimpleCompareInfo2,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->PNSimpleCompareInfo3,&pNSimpleCompareInfo3,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->JNSimpleCompareInfo1,&jNSimpleCompareInfo1,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->JNSimpleCompareInfo2,&jNSimpleCompareInfo2,sizeof(struct entityRecord)); memcpy(&ObjectReteData(theEnv)->JNSimpleCompareInfo3,&jNSimpleCompareInfo3,sizeof(struct entityRecord)); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->ObjectGVInfo1,OBJ_GET_SLOT_JNVAR1); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->ObjectGVInfo2,OBJ_GET_SLOT_JNVAR2); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->ObjectGVPNInfo1,OBJ_GET_SLOT_PNVAR1); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->ObjectGVPNInfo2,OBJ_GET_SLOT_PNVAR2); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->ObjectCmpConstantInfo,OBJ_PN_CONSTANT); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->LengthTestInfo,OBJ_SLOT_LENGTH); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->PNSimpleCompareInfo1,OBJ_PN_CMP1); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->PNSimpleCompareInfo2,OBJ_PN_CMP2); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->PNSimpleCompareInfo3,OBJ_PN_CMP3); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->JNSimpleCompareInfo1,OBJ_JN_CMP1); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->JNSimpleCompareInfo2,OBJ_JN_CMP2); InstallPrimitive(theEnv,&ObjectReteData(theEnv)->JNSimpleCompareInfo3,OBJ_JN_CMP3); }
/*************************************************** 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; } } } SearchForHashedPatternNodes(theEnv,ObjectReteData(theEnv)->ObjectPatternNetworkPointer); }