knit_script.knit_script_interpreter.expressions.function_expressions module

Expressions associated with functions.

This module provides the Function_Call class, which handles function call expressions in knit script programs. It supports both knit script user-defined functions and Python callable objects, with parameter passing through positional and keyword arguments.

class Function_Call(parser_node, func_name, args, kwargs)[source]

Bases: Expression

A call to a function which must return a value or result in None.

The Function_Call class handles the execution of function calls in knit script programs. It supports both user-defined knit script functions (represented by Function_Signature objects) and Python callable objects. The class manages parameter passing through both positional arguments and keyword arguments, evaluating them in the current context before passing them to the target function.

This class provides the bridge between knit script function call syntax and the underlying function execution mechanisms, whether they are knit script functions with their own scopes or Python functions integrated into the knit script environment.

kwargs

The list of assignments used to set keyword arguments.

Type:

list[Assignment]

args

The list of expressions to fill in positional arguments.

Type:

list[Expression]

func_name

The name of the function to call.

Type:

Variable_Expression

Parameters:
__init__(parser_node, func_name, args, kwargs)[source]

Initialize the Function_Call.

Parameters:
  • parser_node (LRStackNode) – The parser node from the parse tree.

  • func_name (Variable_Expression) – Name of the function to call.

  • args (list[Expression]) – The list of argument expressions to evaluate and pass as positional parameters.

  • kwargs (list[Assignment]) – The list of assignments to evaluate and pass as keyword parameters.

evaluate(context)[source]

Find function in scope, fill parameters and then execute.

Locates the function in the current variable scope, evaluates all arguments, and executes the function with the provided parameters.

Handles both knit script functions and Python callable objects.

Parameters:

context (Knit_Script_Context) – The current context of the knit_script_interpreter.

Returns:

Return value set at function scope before closing, or the result of the Python function call.

Return type:

Any

Raises:

NameError – If the function name is not defined in the current scope.

property line_number: int

Get the line number of the symbol that generated this statement.

Returns:

The line number where this element appears in the source file.

Return type:

int

property location: Location

Get the location of this symbol in KnitScript file.

Returns:

The location of this symbol in the source file, including file name, line number, and position information.

Return type:

Location