knit_script.knit_script_interpreter.statements.return_statement module
Used for storing results of function returns.
This module provides the Return_Statement class, which handles function return operations in knit script programs. It evaluates return expressions and manages the return value propagation through the scope hierarchy.
- class Return_Statement(parser_node, exp)[source]
Bases:
Statement
Statement that breaks out of function scope with a returned value.
When executed, this statement evaluates an expression and sets it as the return value for the current function, then signals that execution should exit the function scope. The return statement provides the mechanism for functions to produce results and terminate execution early.
The return value is propagated through the scope hierarchy to reach the appropriate function scope, and execution of the current function terminates immediately after the return statement is processed.
- _exp
The expression to evaluate and return as the function result.
- Type:
- Parameters:
parser_node (
LRStackNode
)exp (
Expression
)
- __init__(parser_node, exp)[source]
Initialize a return statement.
- Parameters:
parser_node (LRStackNode) – The parser node from the abstract syntax tree.
exp (Expression) – The expression to evaluate and return as the function result.
- execute(context)[source]
Execute the return by setting the return value and return flag.
Evaluates the return expression and stores the result in the current variable scope, then sets the return flag to signal that function execution should terminate immediately.
- Parameters:
context (Knit_Script_Context) – The current execution context of the knit script interpreter.
- Return type:
- __str__()[source]
Return string representation of the return statement.
- Returns:
A string showing the return keyword and expression.
- Return type:
- __repr__()[source]
Return detailed string representation of the return statement.
- Returns:
Same as __str__ for this class.
- Return type:
- 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:
- 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