// SPDX-License-Identifier: MIT // Copyright (c) 2024 John Watts and the LuminaSensum contributors #ifndef MODULE_H #define MODULE_H #include "object.h" #include "types.h" // Finds a module by its name // This internally loads the module and dependencies // A new reference is created for the caller Object module_find(VmState state, const char *name); // Frees all modules loaded internally // You must call this at the end of your program void modules_free(VmState state); // The following section is an internal API for use only with // the compiler's C code generator. Do not use for regular C code. #ifdef MODULE_INTERNAL_API // A call the module class can make struct module_class_call { const char *name; const int bytecode_index; }; typedef struct module_class_call ModuleClassCall; // A class in a module struct module_class { const int fields_count; const unsigned char **bytecodes; const ModuleClassCall *calls; }; typedef struct module_class ModuleClass; // Data structure for creating a module struct module_info { const char *name; const char **uses; const ModuleClass **classes; Object (*create)(VmState state, Object use_modules); }; typedef struct module_info ModuleInfo; // Gets another module from a module's runtime data Object module_runtime_use(VmState state, Object module, int index); #endif #endif