use (moduleDescriptor --)

Inputs

Outputs

The input moduleDescriptor is known Text. It names a module path without the trailing .mpl. If it contains no dot after the last path separator, it names one module path. If it contains a dot after the last / or \, only that rightmost post-separator dot has special meaning: the text before it names the module path, and the text after it names one selected public name. Earlier dots, and any dots before the last path separator, remain part of the module path.

Loading a module with use also enables same-name lookup of that module's overload names. The whole-module form directly imports public non-overload names. The single-symbol form loads the module and directly imports only the selected public non-overload name. If the selected public name is an overload, loading the module makes its public overloads available through same-name lookup. A private overload cannot be selected directly, but it still participates in same-name lookup after the module has been loaded.

Behavior

Known issue: importing names inside a constructed Dict ({ "m" use … }) can produce invalid LLVM IR; Clang reports constant expression type mismatch. Import the names in the enclosing scope before constructing the Dict.

Example

useExample.mpl

overload virtual helper: 3;
virtual first: 1;
virtual second: 2;

test.mpl

"useExample" use

{} 0 {} [
  "-- whole module imports public non-overload names --" printCompilerMessage
  first printStack _:;
  second printStack _:;

  "-- overload still participates in lookup after whole-module load --" printCompilerMessage
  helper printStack _:;

  0
] "main" exportFunction

Expected Output During Compilation

-- whole module imports public non-overload names --
1
2
-- overload still participates in lookup after whole-module load --
3

selectedNameExample.mpl

"useExample.second" use

{} 0 {} [
  "-- selected public name --" printCompilerMessage
  second printStack _:;

  "-- overload still participates in lookup after selected-name load --" printCompilerMessage
  helper printStack _:;

  0
] "main" exportFunction

Expected Output During Compilation

-- selected public name --
2
-- overload still participates in lookup after selected-name load --
3

See also