[Libre-soc-bugs] [Bug 906] New: change HDL code to not use type annotations even for dataclasses

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Wed Aug 10 08:59:57 BST 2022


https://bugs.libre-soc.org/show_bug.cgi?id=906

            Bug ID: 906
           Summary: change HDL code to not use type annotations even for
                    dataclasses
           Product: Libre-SOC's first SoC
           Version: unspecified
          Hardware: Other
                OS: Linux
            Status: CONFIRMED
          Severity: enhancement
          Priority: ---
         Component: Source Code
          Assignee: programmerjake at gmail.com
          Reporter: programmerjake at gmail.com
                CC: libre-soc-bugs at lists.libre-soc.org
   NLnet milestone: ---

https://lists.libre-soc.org/pipermail/libre-soc-dev/2022-August/005183.html

type/other assertions are TBD, so should not be removed until we decide what to
do.

TODO:
* nmigen-gf/src/nmigen_gf/hdl/cldivrem.py
* nmutil/src/nmutil/prefix_sum.py
* nmutil/src/nmutil/lut.py
* ieee754fpu/src/ieee754/part_swizzle/swizzle.py
* soc/src/soc/fu/div/experiment/goldschmidt_div_sqrt.py

Plan:
* create annotation function in nmutil that reads __slots__ and creates eq,
hash, compare, and repr, and maybe init (maybe not so you can see how the
fields are set), as well as allowing freezing like dataclasses.

use like:
@plaindata() # always use paren, makes impl simpler
class A:
    __slots__ = ("a", "b")
    def __init__(self, a, b):
        self.a = a
        self.b = b

# Usage demo:
assert repr(A(1, 2)) == "A(a=1, b=2)" # repr works
assert A(3, 4) == A(3, 4) # eq works

# Another example:
@plaindata(hash=True, frozen=True)
class B:
    __slots__ = ("c", "d")
    def __init__(self, c, d):
        self.c = c
        self.d = d

# Usage demo:
d = {B(3, 4): 1, B(5, 6): 2} # works because hash and frozen set

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list