Skip to content

Functions

Functions

Import

import "_IVLS/std-library/ksp/functions.ksp"

Overview

Functions

LIBRARY MODULE

Subroutine and truefunc macros for creating KSP functions with true local scope.

  • subroutine(name) / end_subroutine() — void function pattern with local argument scope
  • truefunc(name) / end_truefunc(name) — function pattern that returns a value
  • Requires #name#.ARGS define list to enumerate parameter names at compile time
  • functions.MakeArgs / functions.ReceiveArgs — internal argument relay helpers

API

Macros

Name Description
end_subroutine Closes a subroutine definition opened by subroutine().
end_truefunc(#name#) Closes a truefunc definition opened by truefunc().
functions.MakeArgs(#name#) Declares global relay variables for each argument in #name#.ARGS.
functions.ReceiveArgs(#name#) Declares local copies of arguments from global relay variables.
subroutine(#name#) Opens a subroutine definition with true local scope.
truefunc(#name#) Opens a subroutine definition that returns a value.

Functions

Name Description
#name#(#name#.ARGS) Public entry point; marshals arguments and delegates to _#name#().
#name#(#name#.ARGS) -> out Public entry point; marshals arguments, calls _#name#(), and returns the relayed...

Macros

end_subroutine

Closes a subroutine definition opened by subroutine().

See also: subroutine


end_truefunc(#name#)

Closes a truefunc definition opened by truefunc().

Parameter Description
#name# the function name and namespace (must match the truefunc() call)

Side effects: | Name | Type | Purpose | |------|------|---------| | #name#.return | global int | Assigned from local return to relay value to outer function |

See also: truefunc


functions.MakeArgs(#name#)

Declares global relay variables for each argument in #name#.ARGS.

Preconditions: #name#.ARGS must be defined as a list of parameter names.

Parameter Description
#name# the function namespace whose .ARGS define lists the parameter names

Side effects: | Name | Type | Purpose | |------|------|---------| | #name#_args. | global int | One per entry in #name#.ARGS, initialized from caller's value |


functions.ReceiveArgs(#name#)

Declares local copies of arguments from global relay variables.

Preconditions: functions.MakeArgs must have been called first to populate the global argument variables.

Parameter Description
#name# the function namespace whose .ARGS define lists the parameter names

Side effects: | Name | Type | Purpose | |------|------|---------| | | local int | One per entry in #name#.ARGS, initialized from #name#_args. |


subroutine(#name#)

Opens a subroutine definition with true local scope.

Preconditions: #name#.ARGS must be defined as a list of parameter names before invoking this macro.

Parameter Description
#name# the function name and namespace

Side effects:

Name Type Purpose
#name# function Public entry point; marshals arguments and calls _#name#()
_#name# function Inner function with local argument copies and user body
#name#_args. global int Argument relay variables (via functions.MakeArgs)
define my_func.ARGS := x, y
subroutine(my_func)
    // function body with true local scope
end_subroutine()

See also: end_subroutine, truefunc


truefunc(#name#)

Opens a subroutine definition that returns a value.

Preconditions: #name#.ARGS must be defined as a list of parameter names before invoking this macro.

Parameter Description
#name# the function name and namespace

Side effects:

Name Type Purpose
#name# function Public entry point; marshals arguments, relays return, calls _#name#()
_#name# function Inner function with local return variable and user body
#name#_args. global int Argument relay variables (via functions.MakeArgs)
#name#.return global int Return value relay
define my_func.ARGS := x, y
truefunc(my_func)
    return := x + y
end_truefunc(my_func)

See also: end_truefunc, subroutine


Functions

#name#(#name#.ARGS)

Public entry point; marshals arguments and delegates to _#name#().

Parameter Description
#name#.ARGS

#name#(#name#.ARGS) -> out

Public entry point; marshals arguments, calls _#name#(), and returns the relayed value.

Parameter Description
#name#.ARGS

Returns: out


Example

// TODO: Add usage example

See Also