added maximum nested call limit

This commit is contained in:
cozis
2021-11-02 13:34:23 +00:00
parent 273adc90eb
commit acc8cbd75f
2 changed files with 14 additions and 0 deletions
+5
View File
@@ -1,4 +1,9 @@
fun k(k)
return k();
k(k);
fun x(a, b, c)
print(a, b, c);
+9
View File
@@ -4,6 +4,7 @@
#include "runtime.h"
#define MAX_FRAME_STACK 16
#define MAX_FRAMES 1024
typedef struct Frame Frame;
@@ -675,6 +676,14 @@ Object *run(Runtime *runtime, Error *error, Executable *exe, int index, Object *
assert(index >= 0);
assert(argc >= 0);
if(runtime->depth == MAX_FRAMES)
{
Error_Report(error, 1, "Maximum nested call limit of %d was reached", MAX_FRAMES);
return NULL;
}
assert(runtime->depth < MAX_FRAMES);
// Initialize the frame.
Frame frame;
{