Function

Single-callable wrapper schemas with stored callable context and one declared call signature.


Use

"Function" use exposes the module's public names. Name-specific imports such as "Function.Function" use, "Function.Function2" use, or "Function.makeFunction" use expose only selected names.


Construction forms


Function2 (signature dataSize -- function)

Constructs one function-wrapper schema with explicit callable-context storage size and one declared call signature.

Fields

Methods

Example: explicit context size

"Function.Function2" use
"control" use

{} () {} [
  ({value: Int32;} () {}) 48 Function2 .DATA_SIZE printStack _:;
] "main" exportFunction

Expected Output During Compilation

48

Runtime example: call through one explicit-size wrapper

"Function.Function2" use
"String" use
"control" use

{} Int32 {} [
  code: {value1: Int64; value0: Int32;} Real32 {} codeRef;
  [swap drop Int32 cast 5 + Real32 cast] !code
  function: ({value1: Int64; value0: Int32;} Real32 {}) 48 Function2;
  @code @function.assign
  ("has=" @function.hasContext LF
   "call=" 7 11i64 function 12.0r32 same LF) printList
  0
] "main" exportFunction

Expected Output

has=TRUE
call=TRUE

Stored state and call validity


Function (signature -- function)

Constructs one function-wrapper schema with the default 32-byte callable-context storage.

Lifecycle and call result

"Function.Function" use
"Function.makeFunction" use
"String" use
"control" use

{} Int32 {} [
  code: {value1: Int64; value0: Int32;} Real32 {} codeRef;
  [swap drop Int32 cast 11 + Real32 cast] !code

  function: ({value1: Int64; value0: Int32;} Real32 {}) Function;
  ("has0=" @function.hasContext LF) printList
  @code @function.assign
  ("has1=" @function.hasContext LF
   "call1=" 17 19i64 function 30.0r32 same LF) printList
  @function.release
  ("has2=" @function.hasContext LF) printList

  function2: @code ({value1: Int64; value0: Int32;} Real32 {}) makeFunction;
  ("has3=" @function2.hasContext LF
   "call2=" 23 29i64 function2 40.0r32 same LF) printList
  0
] "main" exportFunction

Expected Output

has0=FALSE
has1=TRUE
call1=TRUE
has2=FALSE
has3=TRUE
call2=TRUE

Copy from another wrapper

"Function.Function" use
"String" use
"control" use

{} Int32 {} [
  function0: ({value1: Int64; value0: Int32;} Real32 {}) Function;
  function1: ({value1: Int64; value0: Int32;} Real32 {}) Function;

  code0: {value1: Int64; value0: Int32;} Real32 {} codeRef;
  [swap drop Int32 cast 11 + Real32 cast] !code0
  @code0 @function0.assign

  code1: {value1: Int64; value0: Int32;} Real32 {} codeRef;
  [swap drop Int32 cast 13 + Real32 cast] !code1
  @code1 @function1.assign

  @function0 const @function1 set
  ("call0=" 17 19i64 function0 30.0r32 same LF
   "call1=" 23 29i64 function1 34.0r32 same LF
   "has0=" @function0.hasContext LF
   "has1=" @function1.hasContext LF) printList
  0
] "main" exportFunction

Expected Output

call0=TRUE
call1=TRUE
has0=TRUE
has1=TRUE

makeFunction (callable signature -- function)

Constructs one Function value from one callable and one signature in a single step.


See also