Make function's closure scope optional

This commit is contained in:
Laria 2023-02-26 16:57:02 +01:00
parent 4d840fd817
commit 07655c31bd
2 changed files with 5 additions and 3 deletions

View file

@ -856,7 +856,9 @@ apfl_gc_func_traverse(struct function* function, gc_visitor cb, void *opaque)
cb(opaque, GC_OBJECT_FROM(sub->matcher, GC_TYPE_MATCHER));
}
}
cb(opaque, GC_OBJECT_FROM(function->scope, GC_TYPE_SCOPE));
if (function->scope != NULL) {
cb(opaque, GC_OBJECT_FROM(function->scope, GC_TYPE_SCOPE));
}
if (function->name != NULL) {
cb(opaque, GC_OBJECT_FROM(function->name, GC_TYPE_STRING));
}

View file

@ -51,7 +51,7 @@ struct function {
struct subfunction *subfunctions;
size_t subfunctions_len;
size_t subfunctions_cap;
struct scope *scope;
struct scope *scope; // Can be NULL
struct apfl_string *name;
int line_defined;
struct apfl_string *filename;
@ -148,7 +148,7 @@ void apfl_dict_deinit(struct dict_header *);
struct function *apfl_func_new(
struct gc *,
size_t cap,
struct scope *,
struct scope *, // Can be NULL
int line_defined,
struct apfl_string *filename
);