Skip to content

Commit e1e5e2a

Browse files
authored
Add some helpful exception wrappers
These make errors easier to fix.
1 parent d43cdd0 commit e1e5e2a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

adafruit_pioasm.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ def assemble(text_program):
103103
raise SyntaxError(f"Invalid jmp target {repr(target)}")
104104

105105
if len(instruction) > 2:
106-
assembled[-1] |= CONDITIONS.index(instruction[1]) << 5
106+
try:
107+
assembled[-1] |= CONDITIONS.index(instruction[1]) << 5
108+
raise SyntaxError(f"Invalid jmp condition {instruction[1]}")
107109

108110
elif instruction[0] == "wait":
109111
# instr delay p sr index
@@ -183,7 +185,10 @@ def assemble(text_program):
183185
elif instruction[0] == "set":
184186
# instr delay dst data
185187
assembled.append(0b111_00000_000_00000)
186-
assembled[-1] |= SET_DESTINATIONS.index(instruction[1]) << 5
188+
try:
189+
assembled[-1] |= SET_DESTINATIONS.index(instruction[1]) << 5
190+
except ValueError:
191+
raise RuntimeError(f"Uknnown set destination {instruction[1]}")
187192
value = int(instruction[-1])
188193
if not 0 <= value <= 31:
189194
raise RuntimeError("Set value out of range")

0 commit comments

Comments
 (0)