[Libre-soc-bugs] [Bug 980] Implement C-based Power ISA pseudocode compiler

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Thu Jan 4 08:43:53 GMT 2024


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

--- Comment #50 from Dmitry Selyutin <ghostmansd at gmail.com> ---
Whenever somebody attempts to instantiate Dataclass, all its fields are
__validated__ for isinstance. Same applies to typed sequences:


class Label(Literal):
    pass

class DefaultLabel(Label):
    def __new__(cls):
        return super().__new__(cls, "default")

class Labels(Sequence, typeid=Label):
    pass

class Case(Dataclass):
    labels: Labels
    body: Scope

class Cases(Sequence, typeid=Case):
    pass


If some weirdo ever tries to do Case(labels=(1, 2), body="ABC") or pass illegal
nodes not matching the description, an exception is raised. This helps to
diagnose what went wrong when attempt to establish the result of some rule.
Example:


    def p_cases(self, p):
        """
        cases   : switch_list switch_default
                | switch_default
        """
        if len(p) == 3:
            p[0] = pc_ast.Cases(p[1] + (p[2],))
        else:
            p[0] = pc_ast.Cases([p[1]])


This cuts off the cases when something in switchlist is NOT an instance of
Case. The Cases class takes care of it, checking anything it had, thus ensuring
the previous rules expanded correctly.

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


More information about the libre-soc-bugs mailing list