00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #define _DFFCTBSC_SOURCE_
00029
00030 #include "setup.h"
00031
00032 #if DEFFACTS_CONSTRUCT
00033
00034 #include <stdio.h>
00035 #define _STDIO_INCLUDED_
00036 #include <string.h>
00037
00038 #include "envrnmnt.h"
00039 #include "argacces.h"
00040 #include "memalloc.h"
00041 #include "scanner.h"
00042 #include "router.h"
00043 #include "extnfunc.h"
00044 #include "constrct.h"
00045 #include "cstrccom.h"
00046 #include "factrhs.h"
00047 #include "tmpltdef.h"
00048 #include "cstrcpsr.h"
00049 #include "dffctpsr.h"
00050 #include "dffctdef.h"
00051 #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
00052 #include "dffctbin.h"
00053 #endif
00054 #if CONSTRUCT_COMPILER && (! RUN_TIME)
00055 #include "dffctcmp.h"
00056 #endif
00057
00058 #include "dffctbsc.h"
00059
00060
00061
00062
00063
00064 static void ResetDeffacts(void *);
00065 static void ClearDeffacts(void *);
00066 static void SaveDeffacts(void *,void *,char *);
00067 static void ResetDeffactsAction(void *,struct constructHeader *,void *);
00068
00069
00070
00071
00072 globle void DeffactsBasicCommands(
00073 void *theEnv)
00074 {
00075 EnvAddResetFunction(theEnv,"deffacts",ResetDeffacts,0);
00076 EnvAddClearFunction(theEnv,"deffacts",ClearDeffacts,0);
00077 AddSaveFunction(theEnv,"deffacts",SaveDeffacts,10);
00078
00079 #if ! RUN_TIME
00080 EnvDefineFunction2(theEnv,"get-deffacts-list",'m',PTIEF GetDeffactsListFunction,"GetDeffactsListFunction","01w");
00081 EnvDefineFunction2(theEnv,"undeffacts",'v',PTIEF UndeffactsCommand,"UndeffactsCommand","11w");
00082 EnvDefineFunction2(theEnv,"deffacts-module",'w',PTIEF DeffactsModuleFunction,"DeffactsModuleFunction","11w");
00083
00084 #if DEBUGGING_FUNCTIONS
00085 EnvDefineFunction2(theEnv,"list-deffacts",'v', PTIEF ListDeffactsCommand,"ListDeffactsCommand","01w");
00086 EnvDefineFunction2(theEnv,"ppdeffacts",'v',PTIEF PPDeffactsCommand,"PPDeffactsCommand","11w");
00087 #endif
00088
00089 #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)
00090 DeffactsBinarySetup(theEnv);
00091 #endif
00092
00093 #if CONSTRUCT_COMPILER && (! RUN_TIME)
00094 DeffactsCompilerSetup(theEnv);
00095 #endif
00096
00097 #endif
00098 }
00099
00100
00101
00102
00103
00104
00105 static void ResetDeffacts(
00106 void *theEnv)
00107 {
00108 DoForAllConstructs(theEnv,ResetDeffactsAction,DeffactsData(theEnv)->DeffactsModuleIndex,TRUE,NULL);
00109 }
00110
00111
00112
00113
00114
00115 #if WIN_BTC
00116 #pragma argsused
00117 #endif
00118 static void ResetDeffactsAction(
00119 void *theEnv,
00120 struct constructHeader *theConstruct,
00121 void *buffer)
00122 {
00123 #if MAC_MCW || WIN_MCW || MAC_XCD
00124 #pragma unused(buffer)
00125 #endif
00126 DATA_OBJECT result;
00127 struct deffacts *theDeffacts = (struct deffacts *) theConstruct;
00128
00129 if (theDeffacts->assertList == NULL) return;
00130
00131 SetEvaluationError(theEnv,FALSE);
00132
00133 EvaluateExpression(theEnv,theDeffacts->assertList,&result);
00134 }
00135
00136
00137
00138
00139
00140 static void ClearDeffacts(
00141 void *theEnv)
00142 {
00143 #if (! RUN_TIME) && (! BLOAD_ONLY)
00144 struct expr *stub;
00145 struct deffacts *newDeffacts;
00146
00147
00148
00149
00150
00151
00152 stub = GenConstant(theEnv,FCALL,FindFunction(theEnv,"assert"));
00153 stub->argList = GenConstant(theEnv,DEFTEMPLATE_PTR,EnvFindDeftemplate(theEnv,"initial-fact"));
00154 ExpressionInstall(theEnv,stub);
00155
00156
00157
00158
00159
00160
00161 newDeffacts = get_struct(theEnv,deffacts);
00162 newDeffacts->header.whichModule =
00163 (struct defmoduleItemHeader *) GetDeffactsModuleItem(theEnv,NULL);
00164 newDeffacts->header.name = (SYMBOL_HN *) EnvAddSymbol(theEnv,"initial-fact");
00165 IncrementSymbolCount(newDeffacts->header.name);
00166 newDeffacts->assertList = PackExpression(theEnv,stub);
00167 newDeffacts->header.next = NULL;
00168 newDeffacts->header.ppForm = NULL;
00169 newDeffacts->header.usrData = NULL;
00170 ReturnExpression(theEnv,stub);
00171
00172
00173
00174
00175
00176 AddConstructToModule(&newDeffacts->header);
00177 #else
00178 #if MAC_MCW || WIN_MCW || MAC_XCD
00179 #pragma unused(theEnv)
00180 #endif
00181 #endif
00182 }
00183
00184
00185
00186
00187
00188 static void SaveDeffacts(
00189 void *theEnv,
00190 void *theModule,
00191 char *logicalName)
00192 {
00193 SaveConstruct(theEnv,theModule,logicalName,DeffactsData(theEnv)->DeffactsConstruct);
00194 }
00195
00196
00197
00198
00199
00200 globle void UndeffactsCommand(
00201 void *theEnv)
00202 {
00203 UndefconstructCommand(theEnv,"undeffacts",DeffactsData(theEnv)->DeffactsConstruct);
00204 }
00205
00206
00207
00208
00209
00210 globle intBool EnvUndeffacts(
00211 void *theEnv,
00212 void *theDeffacts)
00213 {
00214 return(Undefconstruct(theEnv,theDeffacts,DeffactsData(theEnv)->DeffactsConstruct));
00215 }
00216
00217
00218
00219
00220
00221 globle void GetDeffactsListFunction(
00222 void *theEnv,
00223 DATA_OBJECT_PTR returnValue)
00224 {
00225 GetConstructListFunction(theEnv,"get-deffacts-list",returnValue,DeffactsData(theEnv)->DeffactsConstruct);
00226 }
00227
00228
00229
00230
00231
00232 globle void EnvGetDeffactsList(
00233 void *theEnv,
00234 DATA_OBJECT_PTR returnValue,
00235 void *theModule)
00236 {
00237 GetConstructList(theEnv,returnValue,DeffactsData(theEnv)->DeffactsConstruct,(struct defmodule *) theModule);
00238 }
00239
00240
00241
00242
00243
00244 globle void *DeffactsModuleFunction(
00245 void *theEnv)
00246 {
00247 return(GetConstructModuleCommand(theEnv,"deffacts-module",DeffactsData(theEnv)->DeffactsConstruct));
00248 }
00249
00250 #if DEBUGGING_FUNCTIONS
00251
00252
00253
00254
00255
00256 globle void PPDeffactsCommand(
00257 void *theEnv)
00258 {
00259 PPConstructCommand(theEnv,"ppdeffacts",DeffactsData(theEnv)->DeffactsConstruct);
00260 }
00261
00262
00263
00264
00265
00266 globle int PPDeffacts(
00267 void *theEnv,
00268 char *deffactsName,
00269 char *logicalName)
00270 {
00271 return(PPConstruct(theEnv,deffactsName,logicalName,DeffactsData(theEnv)->DeffactsConstruct));
00272 }
00273
00274
00275
00276
00277
00278 globle void ListDeffactsCommand(
00279 void *theEnv)
00280 {
00281 ListConstructCommand(theEnv,"list-deffacts",DeffactsData(theEnv)->DeffactsConstruct);
00282 }
00283
00284
00285
00286
00287
00288 globle void EnvListDeffacts(
00289 void *theEnv,
00290 char *logicalName,
00291 void *theModule)
00292 {
00293 ListConstruct(theEnv,DeffactsData(theEnv)->DeffactsConstruct,logicalName,(struct defmodule *) theModule);
00294 }
00295
00296 #endif
00297
00298 #endif
00299
00300