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 #include "setup.h"
00028
00029 #if DEFFUNCTION_CONSTRUCT
00030
00031 #ifndef _STDIO_INCLUDED_
00032 #define _STDIO_INCLUDED_
00033 #include <stdio.h>
00034 #endif
00035
00036 #include "constrct.h"
00037 #include "envrnmnt.h"
00038 #include "prcdrfun.h"
00039 #include "prccode.h"
00040 #include "proflfun.h"
00041 #include "router.h"
00042 #include "utility.h"
00043 #include "watch.h"
00044
00045 #define _DFFNXEXE_SOURCE_
00046 #include "dffnxexe.h"
00047
00048
00049
00050
00051
00052
00053 #define BEGIN_TRACE ">> "
00054 #define END_TRACE "<< "
00055
00056
00057
00058
00059
00060
00061
00062 static void UnboundDeffunctionErr(void *);
00063
00064 #if DEBUGGING_FUNCTIONS
00065 static void WatchDeffunction(void *,char *);
00066 #endif
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 globle void CallDeffunction(
00086 void *theEnv,
00087 DEFFUNCTION *dptr,
00088 EXPRESSION *args,
00089 DATA_OBJECT *result)
00090 {
00091 int oldce;
00092 DEFFUNCTION *previouslyExecutingDeffunction;
00093 #if PROFILING_FUNCTIONS
00094 struct profileFrameInfo profileFrame;
00095 #endif
00096
00097 result->type = SYMBOL;
00098 result->value = EnvFalseSymbol(theEnv);
00099 EvaluationData(theEnv)->EvaluationError = FALSE;
00100 if (EvaluationData(theEnv)->HaltExecution)
00101 return;
00102 oldce = ExecutingConstruct(theEnv);
00103 SetExecutingConstruct(theEnv,TRUE);
00104 previouslyExecutingDeffunction = DeffunctionData(theEnv)->ExecutingDeffunction;
00105 DeffunctionData(theEnv)->ExecutingDeffunction = dptr;
00106 EvaluationData(theEnv)->CurrentEvaluationDepth++;
00107 dptr->executing++;
00108 PushProcParameters(theEnv,args,CountArguments(args),EnvGetDeffunctionName(theEnv,(void *) dptr),
00109 "deffunction",UnboundDeffunctionErr);
00110 if (EvaluationData(theEnv)->EvaluationError)
00111 {
00112 dptr->executing--;
00113 DeffunctionData(theEnv)->ExecutingDeffunction = previouslyExecutingDeffunction;
00114 EvaluationData(theEnv)->CurrentEvaluationDepth--;
00115 PeriodicCleanup(theEnv,FALSE,TRUE);
00116 SetExecutingConstruct(theEnv,oldce);
00117 return;
00118 }
00119
00120 #if DEBUGGING_FUNCTIONS
00121 if (dptr->trace)
00122 WatchDeffunction(theEnv,BEGIN_TRACE);
00123 #endif
00124
00125 #if PROFILING_FUNCTIONS
00126 StartProfile(theEnv,&profileFrame,
00127 &dptr->header.usrData,
00128 ProfileFunctionData(theEnv)->ProfileConstructs);
00129 #endif
00130
00131 EvaluateProcActions(theEnv,dptr->header.whichModule->theModule,
00132 dptr->code,dptr->numberOfLocalVars,
00133 result,UnboundDeffunctionErr);
00134
00135 #if PROFILING_FUNCTIONS
00136 EndProfile(theEnv,&profileFrame);
00137 #endif
00138
00139 #if DEBUGGING_FUNCTIONS
00140 if (dptr->trace)
00141 WatchDeffunction(theEnv,END_TRACE);
00142 #endif
00143 ProcedureFunctionData(theEnv)->ReturnFlag = FALSE;
00144
00145 dptr->executing--;
00146 PopProcParameters(theEnv);
00147 DeffunctionData(theEnv)->ExecutingDeffunction = previouslyExecutingDeffunction;
00148 EvaluationData(theEnv)->CurrentEvaluationDepth--;
00149 PropagateReturnValue(theEnv,result);
00150 PeriodicCleanup(theEnv,FALSE,TRUE);
00151 SetExecutingConstruct(theEnv,oldce);
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 static void UnboundDeffunctionErr(
00171 void *theEnv)
00172 {
00173 EnvPrintRouter(theEnv,WERROR,"deffunction ");
00174 EnvPrintRouter(theEnv,WERROR,EnvGetDeffunctionName(theEnv,(void *) DeffunctionData(theEnv)->ExecutingDeffunction));
00175 EnvPrintRouter(theEnv,WERROR,".\n");
00176 }
00177
00178 #if DEBUGGING_FUNCTIONS
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 static void WatchDeffunction(
00193 void *theEnv,
00194 char *tstring)
00195 {
00196 EnvPrintRouter(theEnv,WTRACE,"DFN ");
00197 EnvPrintRouter(theEnv,WTRACE,tstring);
00198 if (DeffunctionData(theEnv)->ExecutingDeffunction->header.whichModule->theModule != ((struct defmodule *) EnvGetCurrentModule(theEnv)))
00199 {
00200 EnvPrintRouter(theEnv,WTRACE,EnvGetDefmoduleName(theEnv,(void *)
00201 DeffunctionData(theEnv)->ExecutingDeffunction->header.whichModule->theModule));
00202 EnvPrintRouter(theEnv,WTRACE,"::");
00203 }
00204 EnvPrintRouter(theEnv,WTRACE,ValueToString(DeffunctionData(theEnv)->ExecutingDeffunction->header.name));
00205 EnvPrintRouter(theEnv,WTRACE," ED:");
00206 PrintLongInteger(theEnv,WTRACE,(long long) EvaluationData(theEnv)->CurrentEvaluationDepth);
00207 PrintProcParamArray(theEnv,WTRACE);
00208 }
00209
00210 #endif
00211 #endif