now variables can access the global scope

This commit is contained in:
Francesco Cozzuto
2021-11-30 23:34:16 +01:00
parent c6387154b0
commit cbb8ac4337
7 changed files with 72 additions and 52 deletions
+4 -2
View File
@@ -9,6 +9,7 @@ typedef struct {
Runtime *runtime;
Executable *exe;
int index, argc;
Object *globals;
} FunctionObject;
static Object *call(Object *self, Object **argv, unsigned int argc, Heap *heap, Error *error);
@@ -73,7 +74,7 @@ static Object *call(Object *self, Object **argv, unsigned int argc, Heap *heap,
// The right amount of arguments was provided.
argv2 = argv;
Object *result = run(func->runtime, error, func->exe, func->index, argv2, expected_argc);
Object *result = run(func->runtime, error, func->exe, func->index, func->globals, 0, argv2, expected_argc);
if(argv2 != argv)
free(argv2);
@@ -81,7 +82,7 @@ static Object *call(Object *self, Object **argv, unsigned int argc, Heap *heap,
return result;
}
Object *Object_FromNojaFunction(Runtime *runtime, Executable *exe, int index, int argc, Heap *heap, Error *error)
Object *Object_FromNojaFunction(Runtime *runtime, Executable *exe, int index, int argc, Object *globals, Heap *heap, Error *error)
{
assert(runtime != NULL);
assert(exe != NULL);
@@ -107,6 +108,7 @@ Object *Object_FromNojaFunction(Runtime *runtime, Executable *exe, int index, in
func->exe = exe_copy;
func->index = index;
func->argc = argc;
func->globals = globals;
return (Object*) func;
}