From b874af0a9f7998ad6655716f58d4b126d0b687d4 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson <oscar.gustafsson@gmail.com> Date: Tue, 23 Apr 2024 14:54:01 +0200 Subject: [PATCH] Add __slots__ to some classes --- b_asic/operation.py | 3 ++- b_asic/port.py | 3 +++ b_asic/process.py | 21 +++++++++++++++++++++ b_asic/resources.py | 5 +++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/b_asic/operation.py b/b_asic/operation.py index 5cda2ed7..02995d3f 100644 --- a/b_asic/operation.py +++ b/b_asic/operation.py @@ -454,9 +454,10 @@ class AbstractOperation(Operation, AbstractGraphComponent): behavior. """ + __slots__ = ("_input_ports", "_output_ports", "_execution_time") _input_ports: List[InputPort] _output_ports: List[OutputPort] - _execution_time: Union[int, None] = None + _execution_time: Optional[int] def __init__( self, diff --git a/b_asic/port.py b/b_asic/port.py index 25400df2..b3b3ccfb 100644 --- a/b_asic/port.py +++ b/b_asic/port.py @@ -130,6 +130,7 @@ class AbstractPort(Port): behavior. """ + __slots__ = ("_operation", "_index", "_latency_offset") _operation: "Operation" _index: int _latency_offset: Optional[int] @@ -276,6 +277,7 @@ class InputPort(AbstractPort): May have one or zero signals connected to it. """ + __slots__ = ("_source_signal",) _source_signal: Optional[Signal] def __init__(self, operation: "Operation", index: int): @@ -372,6 +374,7 @@ class OutputPort(AbstractPort, SignalSourceProvider): May have zero or more signals connected to it. """ + __slots__ = ("_destination_signals",) _destination_signals: List[Signal] def __init__(self, operation: "Operation", index: int): diff --git a/b_asic/process.py b/b_asic/process.py index 74ca40b4..e51fc31e 100644 --- a/b_asic/process.py +++ b/b_asic/process.py @@ -24,6 +24,11 @@ class Process: The name of the process. """ + __slots__ = ("_start_time", "_execution_time", "_name") + _start_time: int + _execution_time: int + _name: str + def __init__(self, start_time: int, execution_time: int, name: str = ""): self._start_time = start_time self._execution_time = execution_time @@ -82,6 +87,9 @@ class OperatorProcess(Process): The name of the process. """ + __slots__ = ("_operation",) + _operation: Operation + def __init__( self, start_time: int, @@ -131,6 +139,9 @@ class MemoryProcess(Process): Name of the process. """ + __slots__ = ("_life_times",) + _life_times: List[int] + def __init__( self, write_time: int, @@ -274,6 +285,11 @@ class MemoryVariable(MemoryProcess): The name of the process. """ + __slots__ = ("_reads", "_read_ports", "_write_port") + _reads: Dict[InputPort, int] + _read_ports: List[InputPort] + _write_port: OutputPort + def __init__( self, write_time: int, @@ -359,6 +375,11 @@ class PlainMemoryVariable(MemoryProcess): The name of the process. """ + __slots__ = ("_reads", "_read_ports", "_write_port") + _reads: Dict[int, int] + _read_ports: List[int] + _write_port: OutputPort + def __init__( self, write_time: int, diff --git a/b_asic/resources.py b/b_asic/resources.py index 1fad9dba..97dffb68 100644 --- a/b_asic/resources.py +++ b/b_asic/resources.py @@ -449,6 +449,11 @@ class ProcessCollection: .. math:: t = t \bmod T_{\textrm{schedule}}. """ + __slots__ = ("_collection", "_schedule_time", "_cyclic") + _collection: List[Process] + _schedule_time: int + _cyclic: bool + def __init__( self, collection: Iterable[Process], -- GitLab