module

package
v0.4.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 6 Imported by: 0

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

View Source
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

func Resolve(importerPath, importPath string) (string, error)

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 NewLoader

func NewLoader() *Loader

NewLoader creates a new module loader with empty caches.

func (*Loader) Get

func (l *Loader) Get(path string) (*Module, error)

Get retrieves a cached module or returns error if not cached.

func (*Loader) HasModule

func (l *Loader) HasModule(path string) bool

HasModule checks if a module is cached.

func (*Loader) IsLoading

func (l *Loader) IsLoading(path string) bool

IsLoading checks if a module is currently being loaded. This is used for cycle detection during module resolution.

func (*Loader) MarkDone

func (l *Loader) MarkDone(path string)

MarkDone marks a module as done loading. Call this after a module has been successfully loaded and cached.

func (*Loader) MarkLoading

func (l *Loader) MarkLoading(path string)

MarkLoading marks a module as being loaded. Call this before starting to load a module to enable cycle detection.

func (*Loader) Set

func (l *Loader) Set(path string, m *Module)

Set caches a module with the given path as key.

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

func NewModule(name string) *Module

NewModule creates a new module with the given name. The exports map is initialized to an empty map.

func (*Module) Export

func (m *Module) Export(name string, value objects.Object)

Export adds an export to the module. If an export with the same name already exists, it is overwritten.

func (*Module) GetExport

func (m *Module) GetExport(name string) (objects.Object, bool)

GetExport retrieves an export by name. Returns the exported object and true if found, or nil and false otherwise.

func (*Module) HasExport

func (m *Module) HasExport(name string) bool

HasExport checks if an export with the given name exists.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL