knit_script.knit_script_interpreter.scope package
Subpackages
Submodules
- knit_script.knit_script_interpreter.scope.global_scope module
- knit_script.knit_script_interpreter.scope.local_scope module
Knit_Script_Scope
Knit_Script_Scope._context
Knit_Script_Scope._is_module
Knit_Script_Scope._is_function
Knit_Script_Scope._returned
Knit_Script_Scope._name
Knit_Script_Scope._parent
Knit_Script_Scope._module_scope
Knit_Script_Scope._globals
Knit_Script_Scope._machine_scope
Knit_Script_Scope._child_scope
Knit_Script_Scope._return_value
Knit_Script_Scope.__init__()
Knit_Script_Scope.machine_scope
Knit_Script_Scope.variables
Knit_Script_Scope.returned
Knit_Script_Scope.machine_state
Knit_Script_Scope.direction
Knit_Script_Scope.Carrier
Knit_Script_Scope.Rack
Knit_Script_Scope.Racking
Knit_Script_Scope.Gauge
Knit_Script_Scope.Sheet
Knit_Script_Scope.get_value_from_python_scope()
Knit_Script_Scope.is_module
Knit_Script_Scope.is_function
Knit_Script_Scope.return_value
Knit_Script_Scope.set_local()
Knit_Script_Scope.set_global()
Knit_Script_Scope.get_local()
Knit_Script_Scope.add_local_by_path()
Knit_Script_Scope.has_local()
Knit_Script_Scope.delete_local()
Knit_Script_Scope.delete_global()
Knit_Script_Scope.enter_new_scope()
Knit_Script_Scope.collapse_lower_scope()
Knit_Script_Scope.exit_current_scope()
Knit_Script_Scope.__contains__()
Knit_Script_Scope.__getitem__()
Knit_Script_Scope.__setitem__()
- knit_script.knit_script_interpreter.scope.machine_scope module
Machine_Scope
Machine_Scope._context
Machine_Scope._direction
Machine_Scope._working_carrier
Machine_Scope._working_racking
Machine_Scope._gauge
Machine_Scope._sheet
Machine_Scope._gauged_sheet_record
Machine_Scope.__init__()
Machine_Scope.inherit_from_scope()
Machine_Scope.update_parent_machine_scope()
Machine_Scope.machine_state
Machine_Scope.direction
Machine_Scope.Carrier
Machine_Scope.Rack
Machine_Scope.Racking
Machine_Scope.gauged_sheet_record
Machine_Scope.Gauge
Machine_Scope.Sheet
Module contents
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.