[Libre-soc-bugs] [Bug 1094] insndb instruction database visitor-walker is needed

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Mon Jun 19 23:30:39 BST 2023


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

--- Comment #199 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Dmitry Selyutin from comment #181)
> I like option 1, because it's short and sweet, and users can just declare
> method as `method(self, instance, *_)`.

indeed.  or, it can be detected: functools can find out how many
arguments there are, whether there are *args and **kwargs.
we use it already somewhere, in soc or ah no nmigen, for detecting
if one of the function parameters is "name".

on detection of the number of arguments the *caller* can omit the
missing parameter.

> Also, yielding some object which
> wraps the original instance looks strange, because call gets not what was
> actually passed, but something else.

yes counter-intuitive.


(In reply to Dmitry Selyutin from comment #189)
> With a minor tweak in the visitor which accepts an additional argument:
> 
> class Visitor(mdis.visitor.ContextVisitor):
>     @mdis.dispatcher.Hook(object)
>     @contextlib.contextmanager
>     def dispatch_object(self, instance, *, path=[]):
                                                  ^^
this is a serious error, it is a singleton pattern.
it MUST be a tuple NOT a list.  (basically anything hashable
is fine, but unhashable is catastrophic. this is a very common
mistake)

i really do not like path as a mandatory argument for all visitors
(particularly leaf-nodes and especially the primitives int bool etc).
if it is optional (see above including *_)  i have no problem with it.

and if using the name "instance" i recommend correspondingly using
"instanceid".


(In reply to Jacob Lifshay from comment #182)
> (In reply to Luke Kenneth Casson Leighton from comment #180)
> > {3: A(5, [12, 3])}               path=[]
> > 
> > no that is not okay (path=[]).  ints do not have and do not need paths.
> 
> you misunderstood this: path is the list of all indexes/keys/field-names
> needed to get from the root object to the current value, 

ahh ok. good explanation.

> and, yes, ints *need* paths, so you can tell which int you're referring to,

no, you really don't.  primitive types (bool int float complex str bytes)
definitely do not need a path...

> like e.g. SelectableInt(123, 45)

... but types *derived* from int might: this depends on the implementor,
if there are any additional properties.

i.e. SelectableInt is no longer a leaf-node type, it is a tree-type
due to itself having two leaf-nodes: the value and the bit-width.

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


More information about the libre-soc-bugs mailing list