diff --git a/lang/module.c b/lang/module.c index 1c825d8..d41a550 100644 --- a/lang/module.c +++ b/lang/module.c @@ -124,13 +124,36 @@ abort_print("Couldn't find module by info"); } -// Creates modules and stores them in a mapping +// Creates a module and stores it in a mapping +Object create_module( + VmState state, struct module_mapping *mapping, const ModuleInfo *info) { + static Object args[16]; + unsigned int args_next = 0; + const char **use = info->uses; + while (*use) { + const ModuleInfo *use_info = info_by_name(*use); + if (info == NULL) + abort_print("Couldn't find module"); + Object use_module = get_module_by_info(mapping, use_info); + args[args_next++] = use_module; + // Check there's enough room left for this and an object_none + if (ARRAY_SIZE(args) < (args_next + 1)) + abort_print("Too many module args"); + use++; + } + args[args_next++] = object_none(); + Object module = info->create(state); + (void)args; // Unused for now + return module; +} + +// Creates modules for a mapping void create_modules(VmState state, struct module_mapping *mapping) { struct module_stack *infos = &mapping->infos; struct object_stack *objs = &mapping->objects; for (int i = objs->next; i < infos->next; ++i) { ModuleInfo *info = infos->elems[i]; - Object module = info->create(state); + Object module = create_module(state, mapping, info); objs->elems[objs->next++] = module; } }