Постављена граница рекурзије за сложене процедуре

This commit is contained in:
kappa 2019-02-05 20:08:25 +01:00
parent 9edd06a2d5
commit 79ffe32866

11
eval.c
View file

@ -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;
}