Skip to content

Commit

Permalink
Fix precommit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
iafisher committed Dec 22, 2020
1 parent 4926ccd commit d0a2552
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
15 changes: 8 additions & 7 deletions hera/debugger/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
import functools
import textwrap

from hera.assembler import assemble_and_print
from hera.data import DataLabel, HERAError, Label, Location, Program, Settings
from hera.loader import load_program
from hera.op import LABEL, OPCODE, Branch, DataOperation, disassemble, name_to_class
from hera.parser import parse
from hera.utils import format_int, out_of_range, pad

from . import miniparser
from .debugger import Debugger
from .miniparser import (
Expand All @@ -19,12 +26,6 @@
RegisterNode,
SymbolNode,
)
from hera.assembler import assemble_and_print
from hera.data import DataLabel, HERAError, Label, Location, Program, Settings
from hera.loader import load_program
from hera.op import Branch, DataOperation, disassemble, LABEL, name_to_class, OPCODE
from hera.parser import parse
from hera.utils import format_int, out_of_range, pad


def debug(program: Program, settings: Settings) -> None:
Expand Down Expand Up @@ -919,7 +920,7 @@ def evaluate_node(self, node: AbstractNode) -> int:
"""
vm = self.debugger.vm
if isinstance(node, IntNode):
if node.value >= 2 ** 16 or node.value < -2 ** 15:
if node.value >= 2 ** 16 or node.value < -(2 ** 15):
raise HERAError("integer literal exceeds 16 bits")
return node.value
elif isinstance(node, RegisterNode):
Expand Down
10 changes: 6 additions & 4 deletions hera/op.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ def arg_to_string(arg):
REGISTER_OR_LABEL = "REGISTER_OR_LABEL"
STRING = "STRING"
LABEL_TYPE = "LABEL_TYPE"
I16 = range(-2 ** 15, 2 ** 16)
I16 = range(-(2 ** 15), 2 ** 16)
I16_OR_LABEL = "I16_OR_LABEL"
U16 = range(2 ** 16)
I8 = range(-2 ** 7, 2 ** 8)
I8 = range(-(2 ** 7), 2 ** 8)
I8_OR_LABEL = "I8_OR_LABEL"
U5 = range(2 ** 5)
U4 = range(2 ** 4)
Expand Down Expand Up @@ -1961,10 +1961,12 @@ def check_arglist(argtypes, args, symbol_table):
err = check_string(got)
elif expected == I16_OR_LABEL:
err = check_in_range(
got, symbol_table, lo=-2 ** 15, hi=2 ** 16, labels=True
got, symbol_table, lo=-(2 ** 15), hi=2 ** 16, labels=True
)
elif expected == I8_OR_LABEL:
err = check_in_range(got, symbol_table, lo=-2 ** 7, hi=2 ** 8, labels=True)
err = check_in_range(
got, symbol_table, lo=-(2 ** 7), hi=2 ** 8, labels=True
)
elif isinstance(expected, range):
err = check_in_range(got, symbol_table, lo=expected.start, hi=expected.stop)
else:
Expand Down
4 changes: 2 additions & 2 deletions hera/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def to_u16(n: int) -> int:
"""
# Note that we allow positive values up to 2**16, but negative values only
# down to -2**15.
if n >= 2 ** 16 or n < -2 ** 15:
if n >= 2 ** 16 or n < -(2 ** 15):
raise HERAError("signed integer too large for 16 bits")

if n < 0:
Expand All @@ -42,7 +42,7 @@ def to_u32(n: int) -> int:
"""
# Note that we allow positive values up to 2**32, but negative values only
# down to -2**31.
if n >= 2 ** 32 or n < -2 ** 31:
if n >= 2 ** 32 or n < -(2 ** 31):
raise HERAError("signed integer too large for 16 bits")

if n < 0:
Expand Down

0 comments on commit d0a2552

Please sign in to comment.