📄 exprnbin.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* EXPRESSION BSAVE/BLOAD MODULE */ /*******************************************************//*************************************************************//* Purpose: Implements the binary save/load feature for the *//* expression data structure. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* Brian L. Donnell *//* *//* Revision History: *//* *//*************************************************************/#define _EXPRNBIN_SOURCE_#include "setup.h"#if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)#include <stdio.h>#define _CLIPS_STDIO_#include "clipsmem.h"#include "dffctdef.h"#include "moduldef.h"#include "constrct.h"#include "extnfunc.h"#include "bload.h"#include "bsave.h"#if DEFRULE_CONSTRUCT#include "network.h"#endif#if DEFGENERIC_CONSTRUCT#include "genrcbin.h"#endif#if DEFFUNCTION_CONSTRUCT#include "dffnxbin.h"#endif#if DEFTEMPLATE_CONSTRUCT#include "tmpltbin.h"#endif#if DEFGLOBAL_CONSTRUCT#include "globlbin.h"#endif#if OBJECT_SYSTEM#include "objbin.h"#include "insfun.h"#include "inscom.h"#endif#include "exprnbin.h"/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/ static long NumberOfExpressions; /****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/ globle struct expr HUGE_ADDR *ExpressionArray; globle long int ExpressionCount; /***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER static VOID UpdateExpression(VOID *,long);#else static VOID UpdateExpression();#endif/***********************************************************//* AllocateExpressions: Determines the amount of space *//* required for loading the binary image of expressions *//* and allocates that amount of space. *//***********************************************************/globle VOID AllocateExpressions() { unsigned long space; GenRead((VOID *) &NumberOfExpressions,(unsigned long) sizeof(long)); if (NumberOfExpressions == 0L) ExpressionArray = NULL; else { space = NumberOfExpressions * sizeof(struct expr); ExpressionArray = (struct expr HUGE_ADDR *) genlongalloc(space); } } /**********************************************//* RefreshExpressions: Refreshes the pointers *//* used by the expression binary image. *//**********************************************/globle VOID RefreshExpressions() { if (ExpressionArray == NULL) return; BloadandRefresh(NumberOfExpressions, (unsigned) sizeof(BSAVE_EXPRESSION),UpdateExpression); } /********************************************************* NAME : UpdateExpression DESCRIPTION : Given a bloaded expression buffer, this routine refreshes the pointers in the expression array INPUTS : 1) a bloaded expression buffer 2) the index of the expression to refresh RETURNS : Nothing useful SIDE EFFECTS : Expression updated NOTES : None *********************************************************/static VOID UpdateExpression(buf,obji) VOID *buf; long obji; { BSAVE_EXPRESSION *bexp; long index; bexp = (BSAVE_EXPRESSION *) buf; ExpressionArray[obji].type = bexp->type; switch(bexp->type) { case FCALL: ExpressionArray[obji].value = (VOID *) FunctionArray[bexp->value]; break; case GCALL:#if DEFGENERIC_CONSTRUCT ExpressionArray[obji].value = (VOID *) GenericPointer(bexp->value);#else ExpressionArray[obji].value = NULL;#endif break; case PCALL:#if DEFFUNCTION_CONSTRUCT ExpressionArray[obji].value = (VOID *) DeffunctionPointer(bexp->value);#else ExpressionArray[obji].value = NULL;#endif break; case DEFTEMPLATE_PTR:#if DEFTEMPLATE_CONSTRUCT ExpressionArray[obji].value = (VOID *) DeftemplatePointer(bexp->value);#else ExpressionArray[obji].value = NULL;#endif break; case DEFCLASS_PTR:#if OBJECT_SYSTEM ExpressionArray[obji].value = (VOID *) DefclassPointer(bexp->value);#else ExpressionArray[obji].value = NULL;#endif break; case DEFGLOBAL_PTR: #if DEFGLOBAL_CONSTRUCT ExpressionArray[obji].value = (VOID *) DefglobalPointer(bexp->value);#else ExpressionArray[obji].value = NULL;#endif break; case INTEGER: ExpressionArray[obji].value = (VOID *) IntegerArray[bexp->value]; IncrementIntegerCount((INTEGER_HN *) ExpressionArray[obji].value); break; case FLOAT: ExpressionArray[obji].value = (VOID *) FloatArray[bexp->value]; IncrementFloatCount((FLOAT_HN *) ExpressionArray[obji].value); break; case INSTANCE_NAME:#if ! OBJECT_SYSTEM ExpressionArray[obji].type = SYMBOL;#endif case GBL_VARIABLE: case SYMBOL: case STRING: ExpressionArray[obji].value = (VOID *) SymbolArray[bexp->value]; IncrementSymbolCount((SYMBOL_HN *) ExpressionArray[obji].value); break;#if DEFTEMPLATE_CONSTRUCT case FACT_ADDRESS: ExpressionArray[obji].value = (VOID *) &DummyFact; IncrementFactCount(ExpressionArray[obji].value); break;#endif#if OBJECT_SYSTEM case INSTANCE_ADDRESS: ExpressionArray[obji].value = (VOID *) &DummyInstance; IncrementInstanceCount(ExpressionArray[obji].value); break;#endif case EXTERNAL_ADDRESS: ExpressionArray[obji].value = NULL; break; case RVOID: break; default: if (PrimitivesArray[bexp->type] == NULL) break; if (PrimitivesArray[bexp->type]->bitMap) { ExpressionArray[obji].value = (VOID *) BitMapArray[bexp->value]; IncrementBitMapCount((BITMAP_HN *) ExpressionArray[obji].value); } break; } index = (long int) bexp->nextArg; if (index == -1L) { ExpressionArray[obji].nextArg = NULL; } else { ExpressionArray[obji].nextArg = (struct expr *) &ExpressionArray[index]; } index = (long int) bexp->argList; if (index == -1L) { ExpressionArray[obji].argList = NULL; } else { ExpressionArray[obji].argList = (struct expr *) &ExpressionArray[index]; } }/*********************************************//* ClearBloadedExpressions: Clears the space *//* utilized by an expression binary image. *//*********************************************/globle VOID ClearBloadedExpressions() { unsigned long int i, space; /*===============================================*/ /* Update the busy counts of atomic data values. */ /*===============================================*/ for (i = 0; i < NumberOfExpressions; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -