diff --git a/lang/compile.py b/lang/compile.py index a8b3183..d80b7ca 100755 --- a/lang/compile.py +++ b/lang/compile.py @@ -802,8 +802,9 @@ header += """ static struct object_class module_class; -static Object module_create(VmState state) { - (void)state; +static Object module_create(VmState state, Object *args) { + for(Object *o = args; *o != object_none(); ++o) + object_drop(state, o); 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 389ffd5..07d9a0a 100644 --- a/lang/module.c +++ b/lang/module.c @@ -133,14 +133,15 @@ if (info == NULL) abort_print("Couldn't find module"); Object use_module = get_module_by_info(mapping, use_info); + // Create a new reference for the module + object_hold(state, use_module); 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"); } args[args_next++] = object_none(); - Object module = info->create(state); - (void)args; // Unused for now + Object module = info->create(state, args); return module; } diff --git a/lang/module.h b/lang/module.h index 330509c..688d57b 100644 --- a/lang/module.h +++ b/lang/module.h @@ -23,7 +23,7 @@ struct module_info { const char *name; const char **uses; - Object (*create)(VmState state); + Object (*create)(VmState state, Object *args); }; typedef const struct module_info ModuleInfo;