Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Better diagnose the incorrect lines like "side 1" or "[5]" #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions adafruit_pioasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def __init__(self, text_program: str, *, build_debuginfo: bool = False) -> None:
for line in instructions:
instruction = splitter(line.strip())
delay = 0
if instruction[-1].endswith("]"): # Delay
if len(instruction) > 1 and instruction[-1].endswith("]"): # Delay
delay = int(instruction[-1].strip("[]"), 0)
if delay < 0:
raise RuntimeError("Delay negative:", delay)
if delay > max_delay:
raise RuntimeError("Delay too long:", delay)
instruction.pop()
if len(instruction) > 1 and instruction[-2] == "side":
if len(instruction) > 2 and instruction[-2] == "side":
if sideset_count == 0:
raise RuntimeError("No side_set count set")
sideset_value = int(instruction[-1], 0)
Expand Down Expand Up @@ -236,7 +236,7 @@ def __init__(self, text_program: str, *, build_debuginfo: bool = False) -> None:
raise RuntimeError("Set value out of range")
assembled[-1] |= value
else:
raise RuntimeError("Unknown instruction:" + instruction[0])
raise RuntimeError(f"Unknown instruction: {instruction[0]}")
assembled[-1] |= delay << 8
# print(bin(assembled[-1]))

Expand Down
39 changes: 39 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# SPDX-FileCopyrightText: KB Sriram
#
# SPDX-License-Identifier: MIT

"""
Tests out
"""

from pytest_helpers import assert_assembly_fails


def test_invalid_sideset() -> None:
source = [
".side_set 2",
"side 2 [5]",
]
assert_assembly_fails(
"\n".join(source), match="Unknown instruction: side", errtype=RuntimeError
)

source = [
".side_set 2",
"side 2",
]
assert_assembly_fails(
"\n".join(source), match="Unknown instruction: side", errtype=RuntimeError
)


def test_invalid_delay() -> None:
assert_assembly_fails(
"[5]", match=r"Unknown instruction: \[5\]", errtype=RuntimeError
)


def test_invalid_instruction() -> None:
assert_assembly_fails(
"bad", match=r"Unknown instruction: bad", errtype=RuntimeError
)
Loading