exportFunction (inputsSchema output options callable name --)

Inputs

Outputs

exportFunction constructs a function signature, compiles the supplied Block, records the resulting function declaration, and creates the exported function name in the current module.

Known issue: an export of a Block already processed for another use — for example written into a Code local or exported before, whatever the options — can give C no symbol to call: compilation succeeds, but linking a C caller fails because the symbol is undefined. Export a separately written Block.

The stack contract follows the declared signature. When the exported function starts at runtime, its declared inputs are on the data stack. Named access inside the body still requires explicit binding. Names written inside inputsSchema do not create locals in the surrounding scope.

Behavior

Example

exportExample.mpl

{} 0 {} [
  "-- zero-input body compiled --" printCompilerMessage
  7
] "seven" exportFunction

{ value: 0; } 0 {} [
  value:;
  "-- one-input body compiled --" printCompilerMessage
  value 1 +
] "addOne" exportFunction

"-- exported name immediately usable here --" printCompilerMessage
@addOne printStack _:;
@addOne known? printStack _:;

test.mpl

"String"               use
"exportExample.addOne" use
"exportExample.seven"  use

{} 0 {} [
  ("-- zero-input function -- " seven "\n") printList
  ("-- one-input function -- " 5 addOne "\n") printList
  @addOne known? printStack _:;
  0
] "main" exportFunction

Expected Output During Compilation

-- zero-input body compiled --
-- one-input body compiled --
-- exported name immediately usable here --
{value: Int32;} Int32 {} codeRef
FALSE
FALSE

Expected Output

-- zero-input function -- 7
-- one-input function -- 6

See also