Reduct  v4.1.3-1-gd06c383
A functional and immutable language.
Loading...
Searching...
No Matches
Module

Detailed Description

The modules keep track of which file an item originates from for error reporting, or tracks resources such as open shared libraries.

Data Structures

struct  reduct_module_t
 Module structure. More...
 
struct  reduct_module_global_t
 Global module state structure. More...
 
struct  reduct_module_flags_t
 Module flags. More...
 

Macros

#define REDUCT_MODULE_ENTRY   "reduct_module_init"
 The name of the entry symbol for a Reduct module.
 
#define REDUCT_MODULE_PATHS_INITIAL   4
 Initial size of the module path array.
 
#define REDUCT_MODULE_PATHS_GROWTH   2
 Growth factor of the module path array.
 
#define REDUCT_MODULE_ID_NONE   ((reduct_module_id_t) - 1)
 Invalid handle value.
 

Typedefs

typedef reduct_handle_t(* reduct_module_init_fn) (struct reduct *reduct)
 Module initialization function type.
 
typedef uint16_t reduct_module_id_t
 Identifies a reduct_module_t within a Reduct structure.
 

Enumerations

enum  reduct_module_flags_t { REDUCT_MODULE_FLAG_NONE = 0 , REDUCT_MODULE_FLAG_BUFFER_OWNED = 1 << 0 , REDUCT_MODULE_FLAG_IS_LIBRARY = 1 << 1 }
 

Functions

REDUCT_API void reduct_module_global_init (reduct_module_global_t *global)
 Initialize the global module state.
 
REDUCT_API void reduct_module_global_deinit (reduct_module_global_t *global)
 Deinitialize the global module state.
 
REDUCT_API reduct_module_treduct_module_new (struct reduct *reduct, const char *buffer, size_t length, const char *path, reduct_module_flags_t flags)
 Create a new module to track a buffer.
 
REDUCT_API reduct_module_treduct_module_lookup (struct reduct *reduct, reduct_module_id_t id)
 Lookup a module structure by its ID.
 
REDUCT_API void reduct_module_add_path (struct reduct *reduct, const char *path)
 Add a path to search when importing modules.
 
REDUCT_API void reduct_module_resolve_path (struct reduct *reduct, const char *path, size_t pathLen, char *outPath, size_t maxLen, bool checkExistence)
 Resolve a path relative to the current execution frame or import paths.
 
REDUCT_API reduct_handle_t reduct_module_import (struct reduct *reduct, reduct_handle_t path, reduct_handle_t compiler, reduct_handle_t compilerArgs)
 Import a module from a given path.
 

Macro Definition Documentation

◆ REDUCT_MODULE_ENTRY

#define REDUCT_MODULE_ENTRY   "reduct_module_init"

The name of the entry symbol for a Reduct module.

Definition at line 26 of file module.h.

◆ REDUCT_MODULE_PATHS_INITIAL

#define REDUCT_MODULE_PATHS_INITIAL   4

Initial size of the module path array.

Definition at line 28 of file module.h.

◆ REDUCT_MODULE_PATHS_GROWTH

#define REDUCT_MODULE_PATHS_GROWTH   2

Growth factor of the module path array.

Definition at line 29 of file module.h.

◆ REDUCT_MODULE_ID_NONE

#define REDUCT_MODULE_ID_NONE   ((reduct_module_id_t) - 1)

Invalid handle value.

Definition at line 41 of file module.h.

Typedef Documentation

◆ reduct_module_init_fn

typedef reduct_handle_t(* reduct_module_init_fn) (struct reduct *reduct)

Module initialization function type.

Definition at line 24 of file module.h.

◆ reduct_module_id_t

typedef uint16_t reduct_module_id_t

Identifies a reduct_module_t within a Reduct structure.

Avoids the need to store a reduct_module_t* within a reduct_item_t saving space.

Definition at line 36 of file module.h.

Enumeration Type Documentation

◆ reduct_module_flags_t

Enumerator
REDUCT_MODULE_FLAG_NONE 
REDUCT_MODULE_FLAG_BUFFER_OWNED 

The buffer is owned by the module structure and should be freed.

REDUCT_MODULE_FLAG_IS_LIBRARY 

The module is a loaded shared library.

Definition at line 47 of file module.h.

Function Documentation

◆ reduct_module_global_init()

REDUCT_API void reduct_module_global_init ( reduct_module_global_t global)

Initialize the global module state.

Parameters
globalPointer to the global module state structure.

◆ reduct_module_global_deinit()

REDUCT_API void reduct_module_global_deinit ( reduct_module_global_t global)

Deinitialize the global module state.

Parameters
globalPointer to the global module state structure.

◆ reduct_module_new()

REDUCT_API reduct_module_t * reduct_module_new ( struct reduct *  reduct,
const char *  buffer,
size_t  length,
const char *  path,
reduct_module_flags_t  flags 
)

Create a new module to track a buffer.

Parameters
reductPointer to the Reduct structure.
bufferThe input buffer containing source code.
lengthThe length of the input buffer.
pathThe path to the input file (for error reporting and relative imports).
flagsInput flags (e.g., REDUCT_MODULE_FLAG_BUFFER_OWNED).
Returns
A pointer to the newly created module structure.

◆ reduct_module_lookup()

REDUCT_API reduct_module_t * reduct_module_lookup ( struct reduct *  reduct,
reduct_module_id_t  id 
)

Lookup a module structure by its ID.

Parameters
reductPointer to the Reduct structure.
idThe ID of the module structure.
Returns
A pointer to the module structure, or NULL if not found.

◆ reduct_module_add_path()

REDUCT_API void reduct_module_add_path ( struct reduct *  reduct,
const char *  path 
)

Add a path to search when importing modules.

Parameters
reductPointer to the Reduct structure.
pathThe directory path, will be copied.

◆ reduct_module_resolve_path()

REDUCT_API void reduct_module_resolve_path ( struct reduct *  reduct,
const char *  path,
size_t  pathLen,
char *  outPath,
size_t  maxLen,
bool  checkExistence 
)

Resolve a path relative to the current execution frame or import paths.

Parameters
reductPointer to the Reduct structure.
pathThe path string to resolve.
pathLenThe length of the path string.
outPathPointer to the buffer where the resolved path will be stored.
maxLenThe maximum length of the output buffer.
checkExistenceWhether to check if the file exists when resolving relative paths.

◆ reduct_module_import()

REDUCT_API reduct_handle_t reduct_module_import ( struct reduct *  reduct,
reduct_handle_t  path,
reduct_handle_t  compiler,
reduct_handle_t  compilerArgs 
)

Import a module from a given path.

Parameters
reductPointer to the Reduct structure.
pathThe path to the module file.
compilerHandle to an atom storing the name of the compiler to use.
compilerArgsHandle to an atom storing the compiler arguments.
Returns
A handle to the root of the parsed module AST.