knitout_interpreter.knitout_language.Knitout_Context module
Module used to manage the context of a knitout interpreter.
- knitout_interpreter.knitout_language.Knitout_Context.process_knitout_instructions(knitout_lines)[source]
Separate list of knitout codes into components of a program for execution.
- Parameters:
knitout_lines (list[Knitout_Line]) – List of knitout instructions to separate into program components.
- Returns:
Version line for the knitout program
List of header lines
List of instruction lines
List of comment lines
- Return type:
tuple[Knitout_Version_Line, list[Knitout_Header_Line], list[Knitout_Instruction], list[Knitout_Comment_Line]]
- class knitout_interpreter.knitout_language.Knitout_Context.Knitout_Context[source]
Bases:
object
Maintains information about the state of a knitting process as knitout instructions are executed.
- machine_state
State of the knitting machine that the context is executing on.
- Type:
Knitting_Machine
- executed_header
The ordered list of header lines that have been executed in this context.
- Type:
- executed_instructions
The ordered list of instructions executed in this context.
- Type:
- property version: int
Get the knitout version of the current context.
- Returns:
The knitout version number, defaults to 2 if no version is set.
- execute_header(header_declarations)[source]
Update the machine state based on the given header values.
Header declarations that do not change the current context can optionally be converted to comments.
- Parameters:
header_declarations (list[Knitout_Header_Line]) – The header lines to update based on.
- execute_instructions(instructions)[source]
Execute the instruction set on the machine state defined by the current header.
- Parameters:
instructions (list[Knitout_Line]) – Instructions to execute on the knitting machine.
- execute_knitout(version_line, header_declarations, instructions)[source]
Execute the given knitout organized by version, header, and instructions.
- Parameters:
version_line (Knitout_Version_Line) – The version of knitout to use.
header_declarations (list[Knitout_Header_Line]) – The header to define the knitout file.
instructions (list[Knitout_Instruction]) – The instructions to execute on the machine.
- Returns:
List of knitout instructions that were executed
Machine state after execution
Knit graph created by execution
- Return type:
A tuple containing
- process_knitout_file(knitout_file_name)[source]
Parse and process a file of knitout code.
- Parameters:
knitout_file_name (str) – File path containing knitout code to process.
- Returns:
List of executed knitout lines
Knitting machine state after execution
Knit graph formed by execution
- Return type:
A tuple containing
- execute_knitout_instructions(codes)[source]
Execute given knitout instructions.
- Parameters:
codes (list[Knitout_Line]) – List of knitout lines to execute.
- Returns:
List of executed knitout lines
Machine state after execution
Knit graph created by execution
- Return type:
A tuple containing