knitout_interpreter.knitout_operations.Knitout_Line module
Base class for Knitout Lines of code
- capture_execution_context(func)[source]
Decorator that adds execution context to exceptions raised during execution of knitout lines.
- Parameters:
func (Callable[[Concatenate[Knitout_Line, ~P]], R]) – Function to be decorated (method taking self as first parameter).
- Returns:
The decorated function with the same signature.
- Return type:
Callable[[Concatenate[Knitout_Line, ~P]], R]
- class Knitout_Line(*args, **kwargs)[source]
Bases:
objectGeneral class for lines of knitout.
- comment
The comment that follows the knitout instruction. None if there is no comment.
- Type:
str | None
- static __new__(cls, *args, **kwargs)[source]
Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.
- classmethod __init_subclass__(**kwargs)[source]
Automatically wrap execute() method in all subclasses.
- __init__(comment=None)[source]
- Parameters:
comment (str, optional) – The comment following this instruction. Defaults to no comment.
- property has_line_number: bool
Returns: bool: True if the original line number of this knitout line has been set.
- property original_line_number: int
Returns: int: The original position of this line from the program it was parsed from.
- property source_program: str | None
Returns: str | None: The name of the program this was parsed from or None if that value is unknown.
- 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 comment_str: str
Get the comment as a formatted string.
- Returns:
The comment formatted as a string with appropriate formatting.
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The knitting machine state to update.
- Returns:
True if the process completes an update. False, otherwise.
- Return type:
- id_str()[source]
Get string representation with original line number if present.
- Returns:
String with original line number added if present.
- Return type:
- class Knitout_Comment_Line(*args, **kwargs)[source]
Bases:
Knitout_LineRepresents a comment line in knitout.
- __init__(comment)[source]
Initialize a comment line.
- Parameters:
comment (None | str | Knitout_Line | Knitout_Comment_Line) – The comment text, or a Knitout_Line to convert to a comment.
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The knitting machine state to update.
- Returns:
True if the process completes an update. 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.
- class Knitout_No_Op(*args, **kwargs)[source]
Bases:
Knitout_Comment_LineRepresents a comment line in knitout.
- original_instruction
The original instruction that was commented out by this no-op.
- Type:
- __init__(no_op_operation, additional_comment=None)[source]
Initialize a comment line.
- Parameters:
no_op_operation (Knitout_Line) – The operation with no effect on the machine state to convert to a no-op comment.
additional_comment (str, optional) – Additional details to include with the no-op. Defaults to no additional details.
- execute(machine_state)[source]
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The knitting machine state to update.
- Returns:
True if the process completes an update. 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.
- class Knitout_BreakPoint(*args, **kwargs)[source]
Bases:
Knitout_Comment_Line- __init__(additional_comment=None)[source]
Initialize a comment line.
- Parameters:
comment (None | str | Knitout_Line | Knitout_Comment_Line) – The comment text, or a Knitout_Line to convert to a comment.
- __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.
- execute(machine_state)
Execute the instruction on the machine state.
- Parameters:
machine_state (Knitting_Machine) – The knitting machine state to update.
- Returns:
True if the process completes an update. False, otherwise.
- Return type:
- 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.