codeRef

codeRef (inputsSchema output options -- code)

Inputs

Outputs

codeRef is a Code schema constructor. A callable signature is formed from an input descriptor, an output descriptor, an options descriptor, and codeRef.

codeRef does not compile a body and does not create locals from the names written inside inputsSchema. Those names only describe the callable signature; they do not become locals in the surrounding scope. The result is a known NIL Code value of that signature.

Behavior

Options descriptor

The options input is a Dict whose fields configure the resulting Code schema, or the empty Tuple () when no options are needed. The empty Dict {} is also valid and equivalent to (). Every option field must be non-static and known. Unrecognized field names are invalid.

Two option fields are recognized:

Name Schema Default Meaning
convention Text absent = LLVM default LLVM calling-convention keyword applied to the function declaration or definition. An empty Text "" also selects the LLVM default. Typical values include "ccc" (C calling convention) and "x86_stdcallcc". The Standard Library module conventions exports portable names cdecl and stdcall that resolve to the correct string for the current target.
variadic Cond absent = FALSE When TRUE, the function accepts additional arguments after its declared inputs. At call sites the additional arguments are passed as a List or Tuple placed on the data stack below the declared inputs. Each item of that Struct must be non-Meta.

Example

{} 0 {} [
  "-- empty signature --" printCompilerMessage
  {} () {} codeRef printStack _:;

  "-- non-empty signature is still only a signature value --" printCompilerMessage
  { value: 0; } 0 {} codeRef printStack _:;

  "-- family checks --" printCompilerMessage
  { value: 0; } 0 {} codeRef codeRef? printStack _:;
  { value: 0; } 0 {} codeRef code? printStack _:;
  { value: 0; } 0 {} codeRef known? printStack _:;
  { value: 0; } 0 {} codeRef isConst printStack _:;

  "-- convention option --" printCompilerMessage
  {} () {convention: "ccc";} codeRef printStack _:;

  "-- variadic option --" printCompilerMessage
  {format: 0nx;} 0 {convention: "ccc"; variadic: TRUE;} codeRef printStack _:;

  0
] "main" exportFunction

Expected Output During Compilation

-- empty signature --
{} () {} codeRef CNIL
-- non-empty signature is still only a signature value --
{value: Int32;} Int32 {} codeRef CNIL
-- family checks --
TRUE
FALSE
FALSE
TRUE
-- convention option --
{} () {convention: "ccc";} codeRef CNIL
-- variadic option --
{format: Natx;} Int32 {convention: "ccc"; variadic: TRUE;} codeRef CNIL

See also