Skip to content

Commit 2d84bfd

Browse files
committed
Type hints added
1 parent a1ccecb commit 2d84bfd

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed
215 Bytes
Binary file not shown.

riscv_assembler/convert.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
class AssemblyConverter:
2121

22-
def __init__(self, output_mode = 'a', nibble_mode = False, hex_mode = False):
22+
def __init__(self, output_mode : str = 'a', nibble_mode : bool = False, hex_mode : bool = False) -> None:
2323
self.__output_mode = self.__check_output_mode(output_mode)
2424
self.__nibble_mode = self.__check_nibble_mode(nibble_mode)
2525
self.__hex_mode = self.__check_hex_mode(hex_mode)
@@ -45,16 +45,16 @@ def clone(self):
4545
hex_mode = self.__hex_mode
4646
)
4747

48-
def __check_output_mode(self, x):
48+
def __check_output_mode(self, x) -> str:
4949
mod = ''.join(sorted(x.split()))
5050
assert mod in ['a', 'f', 'p', None], "Output Mode needs to be one of a(rray), f(ile), p(rint), or None."
5151
return x
5252

53-
def __check_nibble_mode(self, x):
53+
def __check_nibble_mode(self, x) -> str:
5454
assert type(x) == bool, "Nibble mode needs to be a boolean."
5555
return x
5656

57-
def __check_hex_mode(self, x):
57+
def __check_hex_mode(self, x) -> str:
5858
assert type(x) == bool, "Hex mode needs to be a boolean."
5959
return x
6060

@@ -63,11 +63,11 @@ def __check_hex_mode(self, x):
6363
Options: 'a', 'f', 'p'
6464
'''
6565
@property
66-
def output_mode(self):
66+
def output_mode(self) -> str:
6767
return self.__output_mode
6868

6969
@output_mode.setter
70-
def output_mode(self, x):
70+
def output_mode(self, x : str) -> None:
7171
self.__output_mode = x
7272

7373
'''
@@ -76,11 +76,11 @@ def output_mode(self, x):
7676
False = full number
7777
'''
7878
@property
79-
def nibble_mode(self):
79+
def nibble_mode(self) -> str:
8080
return self.__nibble_mode
8181

8282
@nibble_mode.setter
83-
def nibble_mode(self, x):
83+
def nibble_mode(self, x : str) -> None:
8484
self.__nibble_mode = x
8585

8686
'''
@@ -89,19 +89,19 @@ def nibble_mode(self, x):
8989
False = binary
9090
'''
9191
@property
92-
def hex_mode(self):
92+
def hex_mode(self) -> str:
9393
return self.__hex_mode
9494

9595
@hex_mode.setter
96-
def hex_mode(self, x):
96+
def hex_mode(self, x : str) -> None:
9797
self.__hex_mode = x
9898

9999
'''
100100
Put it all together. Need to modify for output type.
101101
102102
Input is either a file name or string of assembly.
103103
'''
104-
def convert(self, input, file = None):
104+
def convert(self, input : str, file : str = None):
105105
output = Parser(input)
106106
assert len(output) > 0, "Provided input yielded nothing from parser. Check input."
107107
output = self.mod(output) # apply nibble mode, hex mode
@@ -118,7 +118,7 @@ def convert(self, input, file = None):
118118

119119
raise NotImplementedError()
120120

121-
def write_to_file(self, output, file):
121+
def write_to_file(self, output : list, file : str) -> None:
122122
extension = file[-4:]
123123

124124
if extension == '.bin':
@@ -144,19 +144,19 @@ def write_to_file(self, output, file):
144144

145145
raise NotImplementedError()
146146

147-
def mod(self, output):
147+
def mod(self, output : list) -> list:
148148
if self.__nibble_mode:
149149
output = AssemblyConverter.apply_nibble(output)
150150
elif self.__hex_mode:
151151
output = AssemblyConverter.apply_hex(output)
152152
return output
153153

154154
@staticmethod
155-
def apply_nibble(output):
155+
def apply_nibble(output : list) -> list:
156156
return ['\t'.join([elem[i:i+4] for i in range(0, len(elem), 4)]) for elem in output]
157157

158158
@staticmethod
159-
def apply_hex(output):
159+
def apply_hex(output : list) -> list:
160160
raise NotImplementedError()
161161
return ...
162162

0 commit comments

Comments
 (0)