Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ce12d58fa67a
Choose a base ref
...
head repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d494ace23fc8
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Jan 2, 2020

  1. Copy the full SHA
    d494ace View commit details
Showing with 5 additions and 5 deletions.
  1. +5 −5 software/glasgow/support/bitstruct.py
10 changes: 5 additions & 5 deletions software/glasgow/support/bitstruct.py
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ def _define_fields_(cls, declared_bits, fields):
cls["_layout_"][name] = (offset, width)
offset += width

cls["__slots__"] = tuple("_{}".format(field) for field in cls["_layout_"])
cls["__slots__"] = tuple("_f_{}".format(field) for field in cls["_layout_"])

code = textwrap.dedent(f"""
def __init__(self, {", ".join(f"{field}=0" for field in cls["_named_fields_"])}):
@@ -70,13 +70,13 @@ def __init__(self, {", ".join(f"{field}=0" for field in cls["_named_fields_"])})
def from_bits(cls, value):
cls._check_bits_("initialization", cls._size_bits_, value)
self = object.__new__(cls)
{"; ".join(f"self._{field} = int(value[{offset}:{offset+width}])"
{"; ".join(f"self._f_{field} = int(value[{offset}:{offset+width}])"
for field, (offset, width) in cls["_layout_"].items())}
return self
def to_bits(self):
value = 0
{"; ".join(f"value |= self._{field} << {offset}"
{"; ".join(f"value |= self._f_{field} << {offset}"
for field, (offset, width) in cls["_layout_"].items())}
return bits(value, self._size_bits_)
""")
@@ -85,15 +85,15 @@ def to_bits(self):
code += textwrap.dedent(f"""
@property
def {field}(self):
return self._{field}
return self._f_{field}
@{field}.setter
def {field}(self, value):
if isinstance(value, bits):
self._check_bits_("field assignment", {width}, value)
else:
self._check_int_("field assignment", {width}, value)
self._{field} = int(value)
self._f_{field} = int(value)
""")

methods = {}