exportFunction (inputsSchema output options callable name --)
Inputs
inputsSchema: Descriptor of the exported function input stack.output: Descriptor of the exported function output stack.options: Descriptor of the exported function calling options.callable:Blockcompiled as the exported body.name: Known exported function name.
Outputs
- None.
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
inputsSchema,output, andoptionsare interpreted through the same signature-building logic ascodeRef. In that logic,inputsSchemaandoptionsare Dict descriptors or the empty Tuple(). The recognized option fields areconvention(Text) andvariadic(Cond); see Options descriptor on thecodeRefpage for the full specification.namemust be known, non-NIL, non-empty Text.- Input order on the data stack follows the stack-order rule of Code signatures.
- The compiled block must consume every declared input and finish with exactly the declared output on its data stack.
- Valid only at module level.
- If the function name was already declared with a different signature, compilation fails.
- If the function name was already defined, compilation fails.
- The function body is compiled immediately, so compile-time effects inside the block happen while the module is compiled.
- The created exported Code name is immediately usable in the current module.
- The created exported name is usable and non-
NIL, butknown?still reportsFALSEfor it. - Pending
overloadandprivatemodifiers apply to the exported name. A pendingvirtualmodifier is invalid here.
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
NAME: ...;node—Pushes a name onto the name stack and creates a local by consuming that name and one data-stack object.codeRefbuiltin(inputsSchema output options -- code)Constructs a Code schema and pushes a knownNILCode object of that schema.defbuiltin(object name --)Creates a named local or field using a known Text name.importFunctionbuiltin(inputsSchema output options name --)Declares or imports a named function with the supplied signature and binds it in the current scope as a Code local.importVariablebuiltin(schema name --)Creates a local that refers to an external variable of the requested non-Meta schema; the created local is treated as unknown.usebuiltin(moduleDescriptor --)Imports public names from a module path named by known Text, or imports one selected public name when the last dot after the last path separator separates the module path from that name.