Skip to content
Snippets Groups Projects
Commit 70613260 authored by Jacob Wahlman's avatar Jacob Wahlman :ok_hand:
Browse files

Removed final to support < 3.8, spacing between classes

parent a5069646
No related branches found
No related tags found
3 merge requests!67WIP: B-ASIC version 1.0.0 hotfix,!65B-ASIC version 1.0.0,!15Add changes from sprint 1 and 2 to master
Pipeline #9674 passed
...@@ -8,9 +8,10 @@ from b_asic.signal import SignalSource, SignalDestination ...@@ -8,9 +8,10 @@ from b_asic.signal import SignalSource, SignalDestination
from b_asic.operation import OperationId, Operation from b_asic.operation import OperationId, Operation
from b_asic.simulation import SimulationState, OperationState from b_asic.simulation import SimulationState, OperationState
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import List, Dict, Optional, Any, final from typing import List, Dict, Optional, Any
from numbers import Number from numbers import Number
class BasicOperation(Operation): class BasicOperation(Operation):
""" """
Generic abstract operation class which most implementations will derive from. Generic abstract operation class which most implementations will derive from.
...@@ -38,43 +39,33 @@ class BasicOperation(Operation): ...@@ -38,43 +39,33 @@ class BasicOperation(Operation):
""" """
pass pass
@final
def id(self) -> OperationId: def id(self) -> OperationId:
return self._identifier return self._identifier
@final
def inputs(self) -> List[InputPort]: def inputs(self) -> List[InputPort]:
return self._input_ports.copy() return self._input_ports.copy()
@final
def outputs(self) -> List[OutputPort]: def outputs(self) -> List[OutputPort]:
return self._output_ports.copy() return self._output_ports.copy()
@final
def input_count(self) -> int: def input_count(self) -> int:
return len(self._input_ports) return len(self._input_ports)
@final
def output_count(self) -> int: def output_count(self) -> int:
return len(self._output_ports) return len(self._output_ports)
@final
def input(self, i: int) -> InputPort: def input(self, i: int) -> InputPort:
return self._input_ports[i] return self._input_ports[i]
@final
def output(self, i: int) -> OutputPort: def output(self, i: int) -> OutputPort:
return self._output_ports[i] return self._output_ports[i]
@final
def params(self) -> Dict[str, Optional[Any]]: def params(self) -> Dict[str, Optional[Any]]:
return self._parameters.copy() return self._parameters.copy()
@final
def param(self, name: str) -> Optional[Any]: def param(self, name: str) -> Optional[Any]:
return self._parameters.get(name) return self._parameters.get(name)
@final
def set_param(self, name: str, value: Any) -> None: def set_param(self, name: str, value: Any) -> None:
assert name in self._parameters # TODO: Error message. assert name in self._parameters # TODO: Error message.
self._parameters[name] = value self._parameters[name] = value
...@@ -110,5 +101,5 @@ class BasicOperation(Operation): ...@@ -110,5 +101,5 @@ class BasicOperation(Operation):
if all(isinstance(e, Operation) for e in results): if all(isinstance(e, Operation) for e in results):
return results return results
return [self] return [self]
# TODO: More stuff. # TODO: More stuff.
\ No newline at end of file
...@@ -7,7 +7,7 @@ from b_asic.port import InputPort, OutputPort ...@@ -7,7 +7,7 @@ from b_asic.port import InputPort, OutputPort
from b_asic.operation import OperationId, Operation from b_asic.operation import OperationId, Operation
from b_asic.basic_operation import BasicOperation from b_asic.basic_operation import BasicOperation
from numbers import Number from numbers import Number
from typing import final
class Input(Operation): class Input(Operation):
""" """
...@@ -18,6 +18,7 @@ class Input(Operation): ...@@ -18,6 +18,7 @@ class Input(Operation):
# TODO: Implement. # TODO: Implement.
pass pass
class Constant(BasicOperation): class Constant(BasicOperation):
""" """
Constant value operation. Constant value operation.
...@@ -32,10 +33,10 @@ class Constant(BasicOperation): ...@@ -32,10 +33,10 @@ class Constant(BasicOperation):
self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports. self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports.
self._parameters["value"] = value self._parameters["value"] = value
@final
def evaluate(self, inputs: list) -> list: def evaluate(self, inputs: list) -> list:
return [self.param("value")] return [self.param("value")]
class Addition(BasicOperation): class Addition(BasicOperation):
""" """
Binary addition operation. Binary addition operation.
...@@ -50,7 +51,6 @@ class Addition(BasicOperation): ...@@ -50,7 +51,6 @@ class Addition(BasicOperation):
self._input_ports = [InputPort(), InputPort()] # TODO: Generate appropriate ID for ports. self._input_ports = [InputPort(), InputPort()] # TODO: Generate appropriate ID for ports.
self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports. self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports.
@final
def evaluate(self, inputs: list) -> list: def evaluate(self, inputs: list) -> list:
return [inputs[0] + inputs[1]] return [inputs[0] + inputs[1]]
...@@ -70,8 +70,7 @@ class ConstantMultiplication(BasicOperation): ...@@ -70,8 +70,7 @@ class ConstantMultiplication(BasicOperation):
self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports. self._output_ports = [OutputPort()] # TODO: Generate appropriate ID for ports.
self._parameters["coefficient"] = coefficient self._parameters["coefficient"] = coefficient
@final
def evaluate(self, inputs: list) -> list: def evaluate(self, inputs: list) -> list:
return [inputs[0] * self.param("coefficient")] return [inputs[0] * self.param("coefficient")]
# TODO: More operations. # TODO: More operations.
\ No newline at end of file
...@@ -13,6 +13,7 @@ if TYPE_CHECKING: ...@@ -13,6 +13,7 @@ if TYPE_CHECKING:
OperationId = NewType("OperationId", int) OperationId = NewType("OperationId", int)
class Operation(ABC): class Operation(ABC):
""" """
Operation interface. Operation interface.
...@@ -107,6 +108,6 @@ class Operation(ABC): ...@@ -107,6 +108,6 @@ class Operation(ABC):
If splitting is not possible, this may return a list containing only the operation itself. If splitting is not possible, this may return a list containing only the operation itself.
""" """
pass pass
# TODO: More stuff. # TODO: More stuff.
...@@ -5,10 +5,11 @@ TODO: More info. ...@@ -5,10 +5,11 @@ TODO: More info.
from b_asic.signal import Signal from b_asic.signal import Signal
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import NewType, Optional, List, Dict, final from typing import NewType, Optional, List, Dict
PortId = NewType("PortId", int) PortId = NewType("PortId", int)
class Port(ABC): class Port(ABC):
""" """
Abstract port class. Abstract port class.
...@@ -22,8 +23,7 @@ class Port(ABC): ...@@ -22,8 +23,7 @@ class Port(ABC):
Construct a Port. Construct a Port.
""" """
self._identifier = identifier self._identifier = identifier
@final
def identifier(self) -> PortId: def identifier(self) -> PortId:
""" """
Get the unique identifier. Get the unique identifier.
...@@ -36,7 +36,7 @@ class Port(ABC): ...@@ -36,7 +36,7 @@ class Port(ABC):
Get a list of all connected signals. Get a list of all connected signals.
""" """
pass pass
@abstractmethod @abstractmethod
def signal_count(self) -> int: def signal_count(self) -> int:
""" """
...@@ -67,6 +67,7 @@ class Port(ABC): ...@@ -67,6 +67,7 @@ class Port(ABC):
# TODO: More stuff. # TODO: More stuff.
class InputPort(Port): class InputPort(Port):
""" """
Input port. Input port.
...@@ -81,31 +82,27 @@ class InputPort(Port): ...@@ -81,31 +82,27 @@ class InputPort(Port):
super().__init__(identifier) super().__init__(identifier)
self._source_signal = None self._source_signal = None
@final
def signals(self) -> List[Signal]: def signals(self) -> List[Signal]:
return [] if self._source_signal == None else [self._source_signal] return [] if self._source_signal == None else [self._source_signal]
@final
def signal_count(self) -> int: def signal_count(self) -> int:
return 0 if self._source_signal == None else 1 return 0 if self._source_signal == None else 1
@final
def signal(self, i: int = 0) -> Signal: def signal(self, i: int = 0) -> Signal:
assert i >= 0 and i < self.signal_count() # TODO: Error message. assert i >= 0 and i < self.signal_count() # TODO: Error message.
assert self._source_signal != None # TODO: Error message. assert self._source_signal != None # TODO: Error message.
return self._source_signal return self._source_signal
@final
def connect(self, signal: Signal) -> None: def connect(self, signal: Signal) -> None:
self._source_signal = signal self._source_signal = signal
@final
def disconnect(self, i: int = 0) -> None: def disconnect(self, i: int = 0) -> None:
assert i >= 0 and i < self.signal_count() # TODO: Error message. assert i >= 0 and i < self.signal_count() # TODO: Error message.
self._source_signal = None self._source_signal = None
# TODO: More stuff. # TODO: More stuff.
class OutputPort(Port): class OutputPort(Port):
""" """
Output port. Output port.
...@@ -121,27 +118,22 @@ class OutputPort(Port): ...@@ -121,27 +118,22 @@ class OutputPort(Port):
super().__init__(identifier) super().__init__(identifier)
self._destination_signals = [] self._destination_signals = []
@final
def signals(self) -> List[Signal]: def signals(self) -> List[Signal]:
return self._destination_signals.copy() return self._destination_signals.copy()
@final
def signal_count(self) -> int: def signal_count(self) -> int:
return len(self._destination_signals) return len(self._destination_signals)
@final
def signal(self, i: int = 0) -> Signal: def signal(self, i: int = 0) -> Signal:
assert i >= 0 and i < self.signal_count() # TODO: Error message. assert i >= 0 and i < self.signal_count() # TODO: Error message.
return self._destination_signals[i] return self._destination_signals[i]
@final
def connect(self, signal: Signal) -> None: def connect(self, signal: Signal) -> None:
assert signal not in self._destination_signals # TODO: Error message. assert signal not in self._destination_signals # TODO: Error message.
self._destination_signals.append(signal) self._destination_signals.append(signal)
@final
def disconnect(self, i: int = 0) -> None: def disconnect(self, i: int = 0) -> None:
assert i >= 0 and i < self.signal_count() # TODO: Error message. assert i >= 0 and i < self.signal_count() # TODO: Error message.
del self._destination_signals[i] del self._destination_signals[i]
# TODO: More stuff. # TODO: More stuff.
\ No newline at end of file
...@@ -5,6 +5,7 @@ TODO: More info. ...@@ -5,6 +5,7 @@ TODO: More info.
from b_asic.signal_flow_graph import SFG from b_asic.signal_flow_graph import SFG
class PrecedenceChart: class PrecedenceChart:
""" """
Precedence chart constructed from a signal flow graph. Precedence chart constructed from a signal flow graph.
...@@ -21,4 +22,4 @@ class PrecedenceChart: ...@@ -21,4 +22,4 @@ class PrecedenceChart:
self.sfg = sfg self.sfg = sfg
# TODO: Implement. # TODO: Implement.
# TODO: More stuff. # TODO: More stuff.
\ No newline at end of file
...@@ -5,6 +5,7 @@ TODO: More info. ...@@ -5,6 +5,7 @@ TODO: More info.
from b_asic.precedence_chart import PrecedenceChart from b_asic.precedence_chart import PrecedenceChart
class Schema: class Schema:
""" """
Schema constructed from a precedence chart. Schema constructed from a precedence chart.
...@@ -21,4 +22,4 @@ class Schema: ...@@ -21,4 +22,4 @@ class Schema:
self.pc = pc self.pc = pc
# TODO: Implement. # TODO: Implement.
# TODO: More stuff. # TODO: More stuff.
\ No newline at end of file
...@@ -8,6 +8,7 @@ from typing import NewType ...@@ -8,6 +8,7 @@ from typing import NewType
SignalId = NewType("SignalId", int) SignalId = NewType("SignalId", int)
class SignalSource: class SignalSource:
""" """
Handle to a signal source. Handle to a signal source.
...@@ -25,6 +26,7 @@ class SignalSource: ...@@ -25,6 +26,7 @@ class SignalSource:
# TODO: More stuff. # TODO: More stuff.
class SignalDestination: class SignalDestination:
""" """
Handle to a signal destination. Handle to a signal destination.
...@@ -42,6 +44,7 @@ class SignalDestination: ...@@ -42,6 +44,7 @@ class SignalDestination:
# TODO: More stuff. # TODO: More stuff.
class Signal: class Signal:
""" """
A connection between two operations consisting of a source and destination handle. A connection between two operations consisting of a source and destination handle.
...@@ -65,4 +68,4 @@ class Signal: ...@@ -65,4 +68,4 @@ class Signal:
""" """
return self._identifier return self._identifier
# TODO: More stuff. # TODO: More stuff.
\ No newline at end of file
...@@ -7,7 +7,8 @@ from b_asic.operation import OperationId, Operation ...@@ -7,7 +7,8 @@ from b_asic.operation import OperationId, Operation
from b_asic.basic_operation import BasicOperation from b_asic.basic_operation import BasicOperation
from b_asic.signal import SignalSource, SignalDestination from b_asic.signal import SignalSource, SignalDestination
from b_asic.simulation import SimulationState, OperationState from b_asic.simulation import SimulationState, OperationState
from typing import List, final from typing import List
class SFG(BasicOperation): class SFG(BasicOperation):
""" """
...@@ -27,12 +28,10 @@ class SFG(BasicOperation): ...@@ -27,12 +28,10 @@ class SFG(BasicOperation):
# TODO: Traverse the graph between the inputs/outputs and add to self._operations. # TODO: Traverse the graph between the inputs/outputs and add to self._operations.
# TODO: Connect ports with signals with appropriate IDs. # TODO: Connect ports with signals with appropriate IDs.
@final
def evaluate(self, inputs: list) -> list: def evaluate(self, inputs: list) -> list:
return [] # TODO: Implement return [] # TODO: Implement
@final
def split(self) -> List[Operation]: def split(self) -> List[Operation]:
return self._operations return self._operations
# TODO: More stuff. # TODO: More stuff.
\ No newline at end of file
...@@ -7,6 +7,7 @@ from b_asic.operation import OperationId ...@@ -7,6 +7,7 @@ from b_asic.operation import OperationId
from numbers import Number from numbers import Number
from typing import List, Dict from typing import List, Dict
class OperationState: class OperationState:
""" """
Simulation state of an operation. Simulation state of an operation.
...@@ -23,6 +24,7 @@ class OperationState: ...@@ -23,6 +24,7 @@ class OperationState:
self.output_values = [] self.output_values = []
self.iteration = 0 self.iteration = 0
class SimulationState: class SimulationState:
""" """
Simulation state. Simulation state.
...@@ -39,4 +41,4 @@ class SimulationState: ...@@ -39,4 +41,4 @@ class SimulationState:
self.operation_states = {} self.operation_states = {}
self.iteration = 0 self.iteration = 0
# TODO: More stuff. # TODO: More stuff.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment