Постављена граница рекурзије за сложене процедуре
This commit is contained in:
parent
9edd06a2d5
commit
79ffe32866
1 changed files with 10 additions and 1 deletions
11
eval.c
11
eval.c
|
@ -5,6 +5,9 @@
|
|||
#include "util.h"
|
||||
#include "internals.h"
|
||||
|
||||
int currentRecursionDepth = 0;
|
||||
#define MAXRECURSIONDEPTH 1000
|
||||
|
||||
object apply(object function, object parameters, env currentEnv);
|
||||
|
||||
object eval(object input, env currentEnv)
|
||||
|
@ -97,6 +100,11 @@ object apply(object procedure, object parameters, env currentEnv)
|
|||
return result;
|
||||
}
|
||||
|
||||
if (++currentRecursionDepth > MAXRECURSIONDEPTH)
|
||||
{
|
||||
--currentRecursionDepth;
|
||||
SIGERR(maxRecursionDepthError);
|
||||
}
|
||||
object args = copyObject(PROC_COMP_ARGS(procedure));
|
||||
object body = copyObject(PROC_COMP_BODY(procedure));
|
||||
env definitionEnv = PROC_COMP_ENV(procedure);
|
||||
|
@ -123,13 +131,14 @@ object apply(object procedure, object parameters, env currentEnv)
|
|||
CAR(*currentSubProc) = eval(CAR(*currentSubProc), procEnv);
|
||||
if (TYPE(CDR(*currentSubProc)) == nilObject)
|
||||
{
|
||||
result = CAR(*currentSubProc);
|
||||
result = copyObject(CAR(*currentSubProc));
|
||||
}
|
||||
currentSubProc = &CDR(*currentSubProc);
|
||||
}
|
||||
deleteObject(args);
|
||||
deleteObject(body);
|
||||
removeEnvironment(procEnv);
|
||||
--currentRecursionDepth;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue