Documentation
¶
Overview ¶
pkg/module/loader.go Module loading functionality with caching and cycle detection.
pkg/module/module.go Package module provides module loading and management for Xxlang.
pkg/module/resolver.go Module path resolution functionality.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrModuleNotFound is returned when a module cannot be found. ErrModuleNotFound = errors.New("module not found") // ErrInvalidImportPath is returned when an import path is invalid. ErrInvalidImportPath = errors.New("invalid import path") // ErrBareImportNotSupported is returned when a bare import path is used (not yet supported). ErrBareImportNotSupported = errors.New("bare imports not supported yet") )
Functions ¶
func Resolve ¶
Resolve resolves an import path relative to the importer. It handles:
- Standard library modules (e.g., "os", "json") -> returns as-is
- Plugin paths starting with "plugin/" -> returns as-is
- Absolute paths and relative paths -> resolves to file path
- .wasm extension -> returns as-is (WASM plugin)
- Other paths -> adds .xxl extension if not present (Xxlang module)
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles module loading with caching and cycle detection. It maintains a cache of loaded modules and tracks which modules are currently being loaded to detect circular dependencies.
func (*Loader) IsLoading ¶
IsLoading checks if a module is currently being loaded. This is used for cycle detection during module resolution.
func (*Loader) MarkDone ¶
MarkDone marks a module as done loading. Call this after a module has been successfully loaded and cached.
func (*Loader) MarkLoading ¶
MarkLoading marks a module as being loaded. Call this before starting to load a module to enable cycle detection.
type Module ¶
type Module struct {
// Name is the module's identifier (e.g., "./math", "stdlib/json")
Name string
// Exports maps exported symbol names to their values
Exports map[string]objects.Object
// Globals stores the module's global variables for exported functions to access
Globals []objects.Object
}
Module represents a compiled module with exported symbols. A module is created when a source file is loaded and compiled, and its exported symbols are available for import by other modules.
func NewModule ¶
NewModule creates a new module with the given name. The exports map is initialized to an empty map.
func (*Module) Export ¶
Export adds an export to the module. If an export with the same name already exists, it is overwritten.