knitout_interpreter.knitout_operations.knitout_instruction module
Structure for Instructions
- class Knitout_Instruction_Type(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumEnumeration of knitout instruction types.
- In = 'in'
- Inhook = 'inhook'
- Releasehook = 'releasehook'
- Out = 'out'
- Outhook = 'outhook'
- Stitch = 'stitch'
- Rack = 'rack'
- Knit = 'knit'
- Tuck = 'tuck'
- Split = 'split'
- Drop = 'drop'
- Xfer = 'xfer'
- Miss = 'miss'
- Kick = 'kick'
- Pause = 'pause'
- static get_instruction(inst_str)[source]
Get the instruction type from a string.
- Parameters:
inst_str (str) – Instruction string to convert.
- Returns:
The corresponding Knitout_Instruction_Type enum value.
- Return type:
- property is_carrier_instruction: bool
Check if instruction operates on yarn carriers.
- Returns:
True if instruction operates on yarn carriers.
- Return type:
- property is_needle_instruction: bool
Check if instruction operates on needles.
- Returns:
True if operation operates on needles.
- Return type:
- property is_loop_making_instruction: bool
Check if instruction operates on needles.
- Returns:
True if operation creates a loop on the first needle in the instruction.
- Return type:
- property is_miss_instruction: bool
Returns: bool: True if the operation is a miss and can occur in a miss instruction pass.
- property in_knitting_pass: bool
Returns: bool: True if instruction can be done in a knit pass. False otherwise.
- property all_needle_instruction: bool
Returns: bool: True if instruction is compatible with all-needle knitting. False, otherwise.
- property directed_pass: bool
Returns: bool: True if instruction requires a direction. False, otherwise.
- property requires_carrier: bool
Returns: bool: True if instruction requires a carrier. False, otherwise.
- property requires_second_needle: bool
Returns: bool: True if instruction requires a second needle. False, otherwise.
- property allow_sliders: bool
Returns: bool: True if this is a transfer instruction that can operate on sliders. False, otherwise.
- compatible_pass(other_instruction)[source]
Determine if instruction can share a machine pass with another instruction.
- Parameters:
other_instruction (Knitout_Instruction_Type) – The other instruction to check compatibility with.
- Returns:
True if both instructions could be executed in the same pass.
- Return type:
- classmethod __contains__(member)
Return True if member is a member of this enum raises TypeError if member is not an enum member
note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum
- classmethod __getitem__(name)
Return the member matching name.
- classmethod __iter__()
Return members in definition order.
- classmethod __len__()
Return the number of members (no aliases)
- class Knitout_Instruction(*args, **kwargs)[source]
Bases:
Knitout_LineSuperclass for knitout operations.
- instruction_type: ClassVar[Knitout_Instruction_Type]
- __init__(comment)[source]
- Parameters:
comment (str, optional) – The comment following this instruction. Defaults to no comment.
- will_update_machine_state(machine_state)[source]
- Parameters:
machine_state (Knitting_Machine) – The machine state to test if this instruction will update it.
- Returns:
True if this instruction will update the machine state. False, otherwise.
- Return type:
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The machine state to update.
- Returns:
True if the process completes an update to the machine state. False, otherwise.
- Return type:
- __hash__()
- Returns:
Unique integer based on the time that this instruction was created in the execution.
- Return type:
- classmethod __init_subclass__(**kwargs)
Automatically wrap execute() method in all subclasses.
- static __new__(cls, *args, **kwargs)
Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.
- property comment_str: str
Get the comment as a formatted string.
- Returns:
The comment formatted as a string with appropriate formatting.
- property follow_comments: list[Knitout_Comment_Line]
Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.
- property has_comment: bool
Check if this line has a comment.
- Returns:
True if comment is present. False, otherwise.
- Return type:
- property has_line_number: bool
Returns: bool: True if the original line number of this knitout line has been set.
- id_str()
Get string representation with original line number if present.
- Returns:
String with original line number added if present.
- Return type:
- property original_line_number: int
Returns: int: The original position of this line from the program it was parsed from.
- set_line(line_number, source=None)
Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.