knit_script.knit_script_interpreter.knit_script_context module
Manages variable scope and machine state of knit pass during execution.
This module provides the Knit_Script_Context class, which serves as the primary execution context for knit script programs. It manages variable scoping, machine state, and provides convenient access to machine configuration parameters. The context integrates scope management with machine operations to provide a unified execution environment for knit script programs.
- class Knit_Script_Context(parent_scope=None, machine_specification=Knitting_Machine_Specification(machine=SWG091N2, gauge=15, position=Right, carrier_count=10, needle_count=540, maximum_rack=4, maximum_float=20, maximum_loop_hold=4, hook_size=5), ks_file=None, parser=None)[source]
Bases:
_Context_Base
Manages the state of the Knitting machine during program execution.
The Knit_Script_Context class serves as the primary execution context for knit script programs. It extends the base context with variable scoping capabilities and provides convenient access to machine configuration parameters. The context manages the integration between variable scopes and machine state, ensuring that machine settings are properly maintained across different execution scopes.
This class provides the execution environment for knit script programs, handling variable management, scope transitions, and machine state coordination. It offers convenient properties for accessing and modifying machine parameters while maintaining proper scope isolation and inheritance.
- variable_scope
The current variable scope for the execution context.
- Type:
- last_carriage_pass_result
Results from the most recent carriage pass operation.
- Parameters:
parent_scope (
Knit_Script_Scope
|None
)machine_specification (
Knitting_Machine_Specification
)parser (
_Parser_Base
|None
)
- __init__(parent_scope=None, machine_specification=Knitting_Machine_Specification(machine=SWG091N2, gauge=15, position=Right, carrier_count=10, needle_count=540, maximum_rack=4, maximum_float=20, maximum_loop_hold=4, hook_size=5), ks_file=None, parser=None)[source]
Initialize the knit script context.
- Parameters:
parent_scope (Knit_Script_Scope | None, optional) – Parent scope for variable management inheritance. Defaults to None.
machine_specification (Knitting_Machine_Specification, optional) – Specification for the knitting machine configuration. Defaults to Knitting_Machine_Specification().
ks_file (str | None, optional) – Path to the knit script file being executed. Defaults to None.
parser (Knit_Script_Parser | None, optional) – Parser instance for processing knit script syntax. Defaults to None.
- property gauged_sheet_record: <module 'knit_script.knit_script_interpreter.scope.gauged_sheet_schema.Gauged_Sheet_Record' from '/home/runner/work/knit_script/knit_script/src/knit_script/knit_script_interpreter/scope/gauged_sheet_schema/Gauged_Sheet_Record.py'>
Get the current record of loops stored on each sheet in the current gauge.
- Returns:
The current record of loops stored on each sheet in the current gauge configuration.
- Return type:
- enter_sub_scope(function_name=None, module_name=None, module_scope=None)[source]
Create a child scope and set it as the current variable scope.
- Parameters:
function_name (str | None, optional) – The name of the function owning this scope. Defaults to None.
module_name (str | None, optional) – The name of the module owning this scope. Defaults to None.
module_scope (Knit_Script_Scope | None, optional) – The scope of the function declaration context. Defaults to None.
- Returns:
The scope that was entered and is now active.
- Return type:
- exit_current_scope(collapse_into_parent=False)[source]
Exit the lowest level variable scope and reset the current variable scope up a level.
- property direction: Carriage_Pass_Direction
Get the carriage pass direction at current scope.
- Returns:
The current carriage pass direction.
- Return type:
Carriage_Pass_Direction
- property carrier: Yarn_Carrier_Set | None
Get the carrier in use at current scope.
- Returns:
The current carrier set or None if no carrier is active.
- Return type:
Yarn_Carrier_Set | None
- property racking: float
Get the racking at current scope.
- Returns:
The current racking value.
- Return type:
- property sheet: Sheet_Identifier
Get the current sheet at current scope.
- Returns:
The current sheet identifier.
- Return type:
- property version: int
Get the knitout version being written.
- Returns:
The knitout version number currently in use for output generation.
- Return type:
- property gauge: int
Get the gauge (number of layers) that is being worked.
Note
Resetting gauge will cause the machine state to forget all current layer records.
- Returns:
The current gauge value.
- Return type:
- execute_statements(statements)[source]
Execute the list of statements on current context.
- Parameters:
statements (list) – Statements to execute in the current context.
- Raises:
AssertionError – If assertions in the script fail during execution.
Knit_Script_Exception – If knit script specific errors occur during interpretation or execution.
Knitting_Machine_Exception – If machine operation errors occur during the knitting process.
- Return type:
- get_needle(is_front, pos, is_slider=False, global_needle=False, sheet=None, gauge=None)[source]
Get a needle based on current gauging configuration.
- Parameters:
is_front (bool) – Whether this is a front needle.
pos (int) – Position within the current layer.
is_slider (bool, optional) – Whether this is a slider needle. Defaults to False.
global_needle (bool, optional) – If true, ignore the gauging scheme. Defaults to False.
sheet (int | None, optional) – Specify the sheet to get needles from, defaults to the current sheet. Defaults to None.
gauge (int | None, optional) – Specify gauging to get needles from, defaults to current gauge. Defaults to None.
- Returns:
Needle based on current gauging configuration.
- Return type:
Needle
- get_machine_needle(is_front, pos, is_slider=False, global_needle=False, sheet=None, gauge=None)[source]
Get the exact needle instance in use on the machine state.
- Parameters:
is_front (bool) – Whether this is a front needle.
pos (int) – Position in current layer.
is_slider (bool, optional) – Whether this is a slider needle. Defaults to False.
global_needle (bool, optional) – If true, ignore the gauging scheme. Defaults to False.
sheet (int | None, optional) – Specify the sheet to get needles from, defaults to the current sheet. Defaults to None.
gauge (int | None, optional) – Specify gauging to get needles from, defaults to current gauge. Defaults to None.
- Returns:
The exact needle instance in use on the machine state.
- Return type:
Needle