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