Start getting module loading working.
Right now, it uses a weird "import_" method on String which should either be replaced or at least hidden behind some syntax. But it does roughly the right thing. Still lots of corner cases to clean up and stuff to fix. In particular: - Need to handle compilation errors in imported modules. - Need to implicitly import all core and IO types into imported module. - Need to handle circular imports. (Just need to give entry module the right name for this to work.)
This commit is contained in:
@@ -246,6 +246,9 @@ struct WrenVM
|
||||
// to the function.
|
||||
int foreignCallNumArgs;
|
||||
|
||||
// The function used to load modules.
|
||||
WrenLoadModuleFn loadModule;
|
||||
|
||||
// Compiler and debugger data:
|
||||
|
||||
// The compiler that is currently compiling code. This is used so that heap
|
||||
@@ -308,6 +311,16 @@ void wrenPushRoot(WrenVM* vm, Obj* obj);
|
||||
// Remove the most recently pushed temporary root.
|
||||
void wrenPopRoot(WrenVM* vm);
|
||||
|
||||
// Imports the module with [name].
|
||||
//
|
||||
// If the module has already been imported (or is already in the middle of
|
||||
// being imported, in the case of a circular import), returns true. Otherwise,
|
||||
// returns a new fiber that will execute the module's code. That fiber should
|
||||
// be called before any variables are loaded from the module.
|
||||
//
|
||||
// If the module could not be found, returns false.
|
||||
Value wrenImportModule(WrenVM* vm, const char* name);
|
||||
|
||||
// Returns the class of [value].
|
||||
//
|
||||
// Defined here instead of in wren_value.h because it's critical that this be
|
||||
|
||||
Reference in New Issue
Block a user