knit_script.knit_script_interpreter.expressions.instruction_expression module
Instructions Expressions.
- This module provides expression classes for handling knitting machine instructions in knit script programs.
It includes classes for needle-specific instructions and general machine instructions, with proper type checking and validation.
- class Needle_Instruction_Exp(parser_node, instruction, needles)[source]
Bases:
Expression
Instructions that happen on a needle.
- The Needle_Instruction_Exp class represents instructions that are applied to specific needles on the knitting machine.
It combines an instruction type with a set of target needles, ensuring that the instruction is valid for needle operations and that all targets are proper Needle objects.
This class is essential for carriage pass operations where specific instructions (like knit, tuck, miss, etc.) need to be applied to particular needles. It provides validation to ensure instruction types are appropriate for needle operations.
- _needles
List of expressions that evaluate to needles.
- Type:
- _instruction_type
The instruction type to apply to the needles.
- Type:
Expression | Knitout_Instruction_Type
- Parameters:
parser_node (
LRStackNode
)instruction (
Expression
|Knitout_Instruction_Type
)needles (
list
[Expression
] |Expression
)
- __init__(parser_node, instruction, needles)[source]
Initialize the Needle_Instruction_Exp.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
instruction (Expression | Knitout_Instruction_Type) – The instruction to apply to the needle set, either as a direct instruction type or an expression that evaluates to one.
needles (list[Expression] | Expression) – The needles to apply the instruction to, either as a list of expressions or a single expression that may evaluate to multiple needles.
- evaluate(context)[source]
Evaluate the expression to get the instruction and target needles.
Evaluates the instruction type and needle expressions, validates that the instruction is appropriate for needle operations, and ensures all targets are valid Needle objects.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter.
- Returns:
A tuple containing the validated instruction type and the list of target needles.
- Return type:
- Raises:
TypeError – If the instruction type is not a Knitout_Instruction_Type or if any needle is not a Needle object.
Needle_Instruction_Type_Exception – If the instruction type is not valid for needle operations.
- 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
- class Machine_Instruction_Exp(parser_node, inst_str)[source]
Bases:
Expression
Expression evaluates to machine instructions.
- The Machine_Instruction_Exp class represents general machine instruction expressions that are not specific to individual needles.
It converts instruction string identifiers into the corresponding Knitout_Instruction_Type objects.
This class is used for machine-level operations that don’t target specific needles but rather control overall machine behavior or state.
- Parameters:
parser_node (
LRStackNode
)inst_str (
str
)
- __init__(parser_node, inst_str)[source]
Initialize the Machine_Instruction_Exp.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
inst_str (str) – The instruction string identifier to convert to an instruction type.
- evaluate(context)[source]
Evaluate the expression to get the machine instruction type.
Converts the instruction string identifier into the corresponding Knitout_Instruction_Type object.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter.
- Returns:
The instruction type matching the string identifier.
- Return type:
Knitout_Instruction_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