📄 objcmp.c
字号:
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.24 06/05/06 */
/* */
/* */
/*******************************************************/
/*************************************************************/
/* Purpose: Object System Construct Compiler Code */
/* */
/* Principal Programmer(s): */
/* Brian L. Donnell */
/* */
/* Contributing Programmer(s): */
/* */
/* Revision History: */
/* */
/* 6.24: Renamed BOOLEAN macro type to intBool. */
/* */
/* Added environment parameter to GenClose. */
/* */
/*************************************************************/
/* =========================================
*****************************************
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"
#include "envrnmnt.h"
#include "objrtfnx.h"
#include "sysdep.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(ObjectCompilerData(theEnv)->ObjectCodeItem)
#define ClassLinkPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,2)
#define SlotPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,3)
#define TemplateSlotPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,4)
#define OrderedSlotPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,5)
#define HandlerPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,6)
#define OrderedHandlerPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,7)
#define SlotNamePrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,8)
#define SlotNameHashPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,9)
#define ClassHashPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,10)
#define ClassIDPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,11)
#define MaxClassIDPrefix() ArbitraryPrefix(ObjectCompilerData(theEnv)->ObjectCodeItem,12)
typedef struct
{
long classCount;
unsigned short currentPartition;
unsigned short slotCount;
int maxIndices;
} MARK_INFO;
typedef union
{
struct
{
unsigned thePartition : 16;
unsigned theOffset : 16;
} theLocation;
long theLong;
} PACKED_LOCATION_INFO;
/* =========================================
*****************************************
INTERNALLY VISIBLE FUNCTION HEADERS
=========================================
***************************************** */
static void ReadyObjectsForCode(void *);
static void MarkDefclassAndSlots(void *,struct constructHeader *,void *);
static void PrintSlotNameReference(void *,FILE *,SLOT_NAME *,int,int);
static void InitObjectsCode(void *,FILE *,int,int);
static int ObjectsToCode(void *,char *,int,FILE *,int,int);
static int ClassIDMapToCode(void *,char *,int,FILE *,int,int,int *);
static int ClassHashTableToCode(void *,char *,int,FILE *,int,int,int *);
static int SlotNameHashTableToCode(void *,char *,int,FILE *,int,int,int *);
static int SlotNameEntriesToCode(void *,char *,int,FILE *,int,int,int *);
static void CloseObjectFiles(void *,FILE *[SAVE_ITEMS],int [SAVE_ITEMS],
struct CodeGeneratorFile [SAVE_ITEMS],int);
static void DefclassModuleToCode(void *,FILE *,struct defmodule *,int,int);
static void SingleDefclassToCode(void *,FILE *,int,int,DEFCLASS *,int,
int,int,int,int,int,int,
int,int,int,int,int,int);
static intBool InheritanceLinksToCode(void *,FILE **,char *,int,int,FILE *,
int *,int,DEFCLASS *,int *,
int *,int *,struct CodeGeneratorFile *);
static intBool SlotsToCode(void *,FILE **,char *,int,int,FILE *,
int *,int,DEFCLASS *,int *,
int *,int *,struct CodeGeneratorFile *);
static intBool TemplateSlotsToCode(void *,FILE **,char *,int,int,FILE *,
int *,int,DEFCLASS *,int *,
int *,int *,struct CodeGeneratorFile *);
static intBool OrderedSlotsToCode(void *,FILE **,char *,int,int,FILE *,
int *,int,DEFCLASS *,int *,
int *,int *,struct CodeGeneratorFile *);
static intBool HandlersToCode(void *,FILE **,char *,int,int,FILE *,
int *,int,DEFCLASS *,int *,
int *,int *,struct CodeGeneratorFile *);
static intBool OrderedHandlersToCode(void *,FILE **,char *,int,int,FILE *,
int *,int,DEFCLASS *,int *,
int *,int *,struct CodeGeneratorFile *);
/* =========================================
*****************************************
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(
void *theEnv)
{
AllocateEnvironmentData(theEnv,OBJECT_COMPILER_DATA,sizeof(struct objectCompilerData),NULL);
ObjectCompilerData(theEnv)->ObjectCodeItem = AddCodeGeneratorItem(theEnv,"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(
void *theEnv,
FILE *fp,
DEFCLASS *cls,
int imageID,
int 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(
void *theEnv,
FILE *theFile,
int count,
int imageID,
int maxIndices)
{
fprintf(theFile,"MIHS &%s%d_%d[%d]",
ModulePrefix(ObjectCompilerData(theEnv)->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(
void *theEnv)
{
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 = ConstructCompilerData(theEnv)->MaxIndices;
DoForAllConstructs(theEnv,MarkDefclassAndSlots,DefclassData(theEnv)->DefclassModuleIndex,
FALSE,(void *) &markInfo);
i = 0L;
for (j = 0 ; j < SLOT_NAME_TABLE_HASH_SIZE ; j++)
for (snp = DefclassData(theEnv)->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
************************************************************/
#if IBM_TBC
#pragma argsused
#endif
static void MarkDefclassAndSlots(
void *theEnv,
struct constructHeader *vTheDefclass,
void *vTheBuffer)
{
DEFCLASS *theDefclass = (DEFCLASS *) vTheDefclass;
MARK_INFO *markInfo = (MARK_INFO *) vTheBuffer;
register unsigned i;
PACKED_LOCATION_INFO theLocationInfo;
#if MAC_MCW || IBM_MCW || MAC_XCD
#pragma unused(theEnv)
#endif
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(
void *theEnv,
FILE *fp,
SLOT_NAME *snp,
int imageID,
int 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
3) The max number of indices allowed in
an array for this construct set
RETURNS : Nothing useful
SIDE EFFECTS : Writes out initialization code
NOTES : None
*******************************************************/
#if IBM_TBC
#pragma argsused
#endif
static void InitObjectsCode(
void *theEnv,
FILE *initFP,
int imageID,
int maxIndices)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -