diff --git a/lang/compile.py b/lang/compile.py index 8601148..ca99e3e 100755 --- a/lang/compile.py +++ b/lang/compile.py @@ -802,9 +802,9 @@ header += """ static struct object_class module_class; -static Object module_create(VmState state, Object *use_modules) { - for(Object *o = use_modules; *o != object_none(); ++o) - object_drop(state, o); +static Object module_create(VmState state, struct object_list *use_modules) { + for(int i = 0; i < use_modules->length; ++i) + object_drop(state, &use_modules->elems[i]); Object obj = object_create(state, &module_class, 1); vm_abort_if(state, !obj, "unable to allocate module"); return obj; diff --git a/lang/module.c b/lang/module.c index 985fe2f..308c5b8 100644 --- a/lang/module.c +++ b/lang/module.c @@ -127,8 +127,8 @@ // Creates a module and stores it in a mapping Object create_module( VmState state, struct module_mapping *mapping, const ModuleInfo *info) { - static Object use_modules[16]; - unsigned int use_modules_next = 0; + struct object_list *use_modules = object_list_create(16); + int use_modules_next = 0; for (const char **use = info->uses; *use != NULL; ++use) { const ModuleInfo *use_info = info_by_name(*use); if (info == NULL) @@ -136,13 +136,13 @@ Object use_module = get_module_by_info(mapping, use_info); // Create a new reference for the module object_hold(state, use_module); - use_modules[use_modules_next++] = use_module; - // Check there's enough room left for this and an object_none - if (ARRAY_SIZE(use_modules) < (use_modules_next + 1)) + use_modules->elems[use_modules_next++] = use_module; + // Check there's enough room left for this + if (use_modules->length < use_modules_next) abort_print("Too many module use_modules"); } - use_modules[use_modules_next++] = object_none(); Object module = info->create(state, use_modules); + object_list_free(&use_modules); return module; } diff --git a/lang/module.h b/lang/module.h index 1c9b588..46cff97 100644 --- a/lang/module.h +++ b/lang/module.h @@ -4,6 +4,7 @@ #ifndef MODULE_H #define MODULE_H +#include "object.h" #include "types.h" // Finds a module by its name @@ -23,7 +24,7 @@ struct module_info { const char *name; const char **uses; - Object (*create)(VmState state, Object *use_modules); + Object (*create)(VmState state, struct object_list *use_modules); }; typedef struct module_info ModuleInfo;