knit_script.knit_script_interpreter.scope package
Knit Script Interpreter Scope Management Package
- This package provides comprehensive scope and variable management for the Knit Script interpreter,
handling global variables, local scopes, machine state, and module imports.
The scope system manages a hierarchical variable structure that supports: - Global variable tracking across the entire program execution. - Local scopes for functions and control structures. - Machine-specific variables (gauge, carrier, racking, sheet, direction). - Module import and namespace management. - Python scope integration for built-in functions and variables.
Classes Overview
- Global Scope Management:
Knit_Script_Globals: Tracks global variables and program exit values.
- Local Scope Management:
Knit_Script_Scope: Main scope manager handling variable hierarchy, function scopes, module scopes, and machine state. Variable_Scope: Legacy variable scope implementation for function-level variable management.
- Machine State Management:
Machine_Scope: Manages machine-specific variables and state. Machine_Variables: Enumeration of machine variable names and accessors.
- Module Management:
Knit_Script_Module: Handles module imports and namespace organization.
- Supporting Classes:
Gauged_Sheet_Record: Manages sheet configurations for different gauge settings
Key Features
- Hierarchical Scoping:
Parent-child scope relationships.
Variable shadowing with warnings.
Scope-specific variable resolution.
- Machine Integration:
Direct machine state management.
Automatic validation of machine parameters.
Integration with virtual knitting machine components.
- Module System:
Python module integration.
Knit script module imports.
Namespace path resolution.
- Error Handling:
Custom exceptions for invalid gauge/sheet values.
Comprehensive warning system for scope conflicts.
Graceful handling of undefined variables.
Architecture Notes
The scope system follows a tree-like hierarchy where: - Root scope contains global variables and machine state. - Function scopes can return values and have isolated local variables. - Module scopes persist in the variable namespace for later access. - Machine scopes provide direct access to knitting machine state.
Variable resolution follows Python-like semantics: 1. Check local scope (current and parent scopes). 2. Check module scope if available. 3. Check global scope. 4. Check Python built-in scope. 5. Raise NameError if not found.
Subpackages
Submodules
- knit_script.knit_script_interpreter.scope.local_scope module
Knit_Script_ScopeKnit_Script_Scope.__init__()Knit_Script_Scope.is_moduleKnit_Script_Scope.is_functionKnit_Script_Scope.scope_nameKnit_Script_Scope.function_nameKnit_Script_Scope.module_nameKnit_Script_Scope.machine_scopeKnit_Script_Scope.module_scopeKnit_Script_Scope.returnedKnit_Script_Scope.return_valueKnit_Script_Scope.machine_stateKnit_Script_Scope.directionKnit_Script_Scope.CarrierKnit_Script_Scope.RackKnit_Script_Scope.RackingKnit_Script_Scope.GaugeKnit_Script_Scope.SheetKnit_Script_Scope.enter_new_scope()Knit_Script_Scope.collapse_descendant_scopes()Knit_Script_Scope.exit_current_scope()Knit_Script_Scope.get_value_from_python_scope()Knit_Script_Scope.set_global()Knit_Script_Scope.add_local_by_path()Knit_Script_Scope.has_local()Knit_Script_Scope.delete_local()Knit_Script_Scope.__contains__()Knit_Script_Scope.__getitem__()Knit_Script_Scope.__setitem__()Knit_Script_Scope.__str__()
- knit_script.knit_script_interpreter.scope.machine_scope module
Machine_ScopeMachine_Scope.__init__()Machine_Scope.machine_stateMachine_Scope.directionMachine_Scope.CarrierMachine_Scope.last_working_carrierMachine_Scope.RackingMachine_Scope.RackMachine_Scope.gauged_sheet_recordMachine_Scope.GaugeMachine_Scope.SheetMachine_Scope.inherit_from_scope()Machine_Scope.update_parent_machine_scope()Machine_Scope.__contains__()Machine_Scope.__getitem__()Machine_Scope.__setitem__()
- knit_script.knit_script_interpreter.scope.variable_space module