📄 objcmp.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* */ /*******************************************************//*************************************************************//* Purpose: Object System Construct Compiler Code *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//*************************************************************/ /* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if OBJECT_SYSTEM && CONSTRUCT_COMPILER && (! RUN_TIME)#include "conscomp.h"#include "classcom.h"#include "classfun.h"#include "classini.h"#include "cstrncmp.h"#define _OBJCMP_SOURCE_#include "objcmp.h"/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** */#define MODULEI 0#define CLASSI 1#define LINKI 2#define SLOTI 3#define TSLOTI 4#define OSLOTI 5#define HANDLERI 6#define OHANDLERI 7#define SAVE_ITEMS 8/* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** */#define ClassPrefix() ConstructPrefix(ObjectCodeItem)#define ClassLinkPrefix() ArbitraryPrefix(ObjectCodeItem,2)#define SlotPrefix() ArbitraryPrefix(ObjectCodeItem,3)#define TemplateSlotPrefix() ArbitraryPrefix(ObjectCodeItem,4)#define OrderedSlotPrefix() ArbitraryPrefix(ObjectCodeItem,5)#define HandlerPrefix() ArbitraryPrefix(ObjectCodeItem,6)#define OrderedHandlerPrefix() ArbitraryPrefix(ObjectCodeItem,7)#define SlotNamePrefix() ArbitraryPrefix(ObjectCodeItem,8)#define SlotNameHashPrefix() ArbitraryPrefix(ObjectCodeItem,9)#define ClassHashPrefix() ArbitraryPrefix(ObjectCodeItem,10)#define ClassIDPrefix() ArbitraryPrefix(ObjectCodeItem,11)#define MaxClassIDPrefix() ArbitraryPrefix(ObjectCodeItem,12)typedef struct { long classCount; int currentPartition; int slotCount; int maxIndices; } MARK_INFO;typedef union { struct { unsigned thePartition : 16; unsigned theOffset : 16; } theLocation; long theLong; } PACKED_LOCATION_INFO; /* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if ANSI_COMPILERstatic VOID ReadyObjectsForCode(void);static VOID MarkDefclassAndSlots(struct constructHeader *,VOID *);static VOID PrintSlotNameReference(FILE *,SLOT_NAME *,int,int);static VOID InitObjectsCode(FILE *,int,int);static int ObjectsToCode(char *,int,FILE *,int,int);static int ClassIDMapToCode(char *,int,FILE *,int,int,int *);static int ClassHashTableToCode(char *,int,FILE *,int,int,int *);static int SlotNameHashTableToCode(char *,int,FILE *,int,int,int *);static int SlotNameEntriesToCode(char *,int,FILE *,int,int,int *);static VOID CloseObjectFiles(FILE *[SAVE_ITEMS],int [SAVE_ITEMS], struct CodeGeneratorFile [SAVE_ITEMS],int); static VOID DefclassModuleToCode(FILE *,struct defmodule *,int,int);static VOID SingleDefclassToCode(FILE *,int,int,DEFCLASS *,int, int,int,int,int,int,int, int,int,int,int,int,int);static BOOLEAN InheritanceLinksToCode(FILE **,char *,int,int,FILE *, int *,int,DEFCLASS *,int *, int *,int *,struct CodeGeneratorFile *);static BOOLEAN SlotsToCode(FILE **,char *,int,int,FILE *, int *,int,DEFCLASS *,int *, int *,int *,struct CodeGeneratorFile *);static BOOLEAN TemplateSlotsToCode(FILE **,char *,int,int,FILE *, int *,int,DEFCLASS *,int *, int *,int *,struct CodeGeneratorFile *);static BOOLEAN OrderedSlotsToCode(FILE **,char *,int,int,FILE *, int *,int,DEFCLASS *,int *, int *,int *,struct CodeGeneratorFile *);static BOOLEAN HandlersToCode(FILE **,char *,int,int,FILE *, int *,int,DEFCLASS *,int *, int *,int *,struct CodeGeneratorFile *);static BOOLEAN OrderedHandlersToCode(FILE **,char *,int,int,FILE *, int *,int,DEFCLASS *,int *, int *,int *,struct CodeGeneratorFile *);#elsestatic VOID ReadyObjectsForCode();static VOID MarkDefclassAndSlots();static VOID PrintSlotNameReference();static VOID InitObjectsCode();static int ObjectsToCode();static int ClassIDMapToCode();static int ClassHashTableToCode();static int SlotNameHashTableToCode();static int SlotNameEntriesToCode();static VOID CloseObjectFiles(); static VOID DefclassModuleToCode();static VOID SingleDefclassToCode();static BOOLEAN InheritanceLinksToCode();static BOOLEAN SlotsToCode();static BOOLEAN TemplateSlotsToCode();static BOOLEAN OrderedSlotsToCode();static BOOLEAN HandlersToCode();static BOOLEAN OrderedHandlersToCode();#endif/* ========================================= ***************************************** INTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** */static struct CodeGeneratorItem *ObjectCodeItem;/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */ /*************************************************** NAME : SetupObjectsCompiler DESCRIPTION : Initializes the construct compiler item for defclasses & handlers INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Code generator item initialized NOTES : None ***************************************************/globle VOID SetupObjectsCompiler() { ObjectCodeItem = AddCodeGeneratorItem("objects",0,ReadyObjectsForCode, InitObjectsCode,ObjectsToCode,13); } /********************************************************* NAME : PrintClassReference DESCRIPTION : Writes out a reference to the class array INPUTS : 1) Output file pointer 2) Class address 3) Construct set image id 4) The maximum number of indices allowed in an array RETURNS : Nothing useful SIDE EFFECTS : Writes out class array reference to file NOTES : None *********************************************************/globle VOID PrintClassReference(fp,cls,imageID,maxIndices) FILE *fp; DEFCLASS *cls; int imageID,maxIndices; { if (cls == NULL) fprintf(fp,"NULL"); else fprintf(fp,"&%s%d_%d[%d]", ClassPrefix(), imageID, (int) ((cls->header.bsaveID / maxIndices) + 1), (int) (cls->header.bsaveID % maxIndices)); } /**************************************************** NAME : DefclassCModuleReference DESCRIPTION : Prints out a reference to a defclass module INPUTS : 1) The output file 2) The id of the module item 3) The id of the image 4) The maximum number of elements allowed in an array RETURNS : Nothing useful SIDE EFFECTS : Defclass module reference printed NOTES : None ****************************************************/globle VOID DefclassCModuleReference(theFile,count,imageID,maxIndices) FILE *theFile; int count; int imageID; int maxIndices; { fprintf(theFile,"MIHS &%s%d_%d[%d]", ModulePrefix(ObjectCodeItem), imageID, (count / maxIndices) + 1, (count % maxIndices)); }/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** *//******************************************************* NAME : ReadyObjectsForCode DESCRIPTION : Sets index of classes and slot name entries for use in compiled expressions INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : BsaveIndices set NOTES : None *******************************************************/static VOID ReadyObjectsForCode() { MARK_INFO markInfo; register long i; register int j; SLOT_NAME *snp; markInfo.classCount = 0L; markInfo.currentPartition = 1; markInfo.slotCount = 0; /* ===================================== Gets the value of MaxIndices directly from the global in CONSCOMP.C ===================================== */ markInfo.maxIndices = MaxIndices; DoForAllConstructs(MarkDefclassAndSlots,DefclassModuleIndex, CLIPS_FALSE,(VOID *) &markInfo); i = 0L; for (j = 0 ; j < SLOT_NAME_TABLE_HASH_SIZE ; j++) for (snp = SlotNameTable[j] ; snp != NULL ; snp = snp->nxt) snp->bsaveIndex = i++; }/************************************************************ NAME : MarkDefclassAndSlots DESCRIPTION : Sets the bsave indices of the classes for use in printing references to them later. Also, the partitions and offsets are predetermined for every slot and packed into a single long (the slot bsave index) for use in printing references to them later INPUTS : 1) The defclass 2) A buffer containing the info: a) Total number of classes counted so far b) The current partition # for slots c) The current offset in that partition d) The max # of elements in any array RETURNS : Nothing useful SIDE EFFECTS : Bsave indices of classes and slots set NOTES : The template slots are written at the same time as the real slots - thus the references must be predetermined ************************************************************/static VOID MarkDefclassAndSlots(vTheDefclass,vTheBuffer) struct constructHeader *vTheDefclass; VOID *vTheBuffer; { DEFCLASS *theDefclass = (DEFCLASS *) vTheDefclass; MARK_INFO *markInfo = (MARK_INFO *) vTheBuffer; register unsigned i; PACKED_LOCATION_INFO theLocationInfo; theDefclass->header.bsaveID = markInfo->classCount++; for (i = 0 ; i < theDefclass->slotCount ; i++) { theLocationInfo.theLocation.thePartition = markInfo->currentPartition; theLocationInfo.theLocation.theOffset = markInfo->slotCount; theDefclass->slots[i].bsaveIndex = theLocationInfo.theLong; markInfo->slotCount++; if (markInfo->slotCount >= markInfo->maxIndices) { markInfo->currentPartition++; markInfo->slotCount = 0; } } }/************************************************************* NAME : PrintSlotNameReference DESCRIPTION : Writes out a reference to the slot name array INPUTS : 1) Output file pointer 2) Slot name address 3) Construct set image id 4) The maximum number of indices allowed in an array RETURNS : Nothing useful SIDE EFFECTS : Writes out slot name array reference to file NOTES : None *************************************************************/static VOID PrintSlotNameReference(fp,snp,imageID,maxIndices) FILE *fp; SLOT_NAME *snp; int imageID,maxIndices; { if (snp == NULL) fprintf(fp,"NULL"); else fprintf(fp,"&%s%d_%d[%d]", SlotNamePrefix(), imageID, (int) ((snp->bsaveIndex / maxIndices) + 1), (int) (snp->bsaveIndex % maxIndices)); } /******************************************************* NAME : InitObjectsCode DESCRIPTION : Writes out initialization code for generic functions INPUTS : 1) The initialization code file pointer 2) The construct set image id
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -