Skip to content

Transitive Module Design #786

@bvssvni

Description

@bvssvni

Dyon supports transitive modules by default.

About transitive modules

A transitive module is a loaded module that behaves a bit similar to external functions.

The most common usage of transitive modules is in libraries that use preloaded Dyon modules. In normal Dyon scripting, transitive modules are rarely used, unless you are creating some kind of framework.

External functions are global within all loaded modules, stored in a module for the Runtime.

Transitivity can be turned off when loading a module.

Both transitive and transitivity are controlled at the same place, when loading modules.

  • Transitive module, opt-in, (tr, false by default): A module where all functions are transitive
  • Transitivity, opt-out, (usetr, true by default): Whether to use transitive functions from runtime
tr usetr Result
false false No transitive functions
false true Inherits from runtime module
true false Overrides transitive functions
true true Inherits, but also adds more

Relevant functions in Dyon's standard library:

  • load__source_imports_tr_usetr
  • module__in_string_imports_tr_usetr
  • check__in_string_imports_usetr

Internal structure

Every loaded module has an internal length transitive_functions_len where lower loaded function indices are transitive.

This internal length transitive_functions_len is used to inherit loaded functions from the runtime module.

Dependencies are not affect, only the functions that are below this internal length when the runtime uses it.

When a module is loaded as transitive, transitive_functions_len is set equal to the length of all loaded functions. It means, all its loaded functions, including those from its dependencies, will be injected by default, when the Dyon runtime uses the module to load new functions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions