[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 10:35:32 BST 2023


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

--- Comment #180 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Luke Kenneth Casson Leighton from comment #178)
> and (in walker.py)
> 
>   22     @dispatcher.Hook(dict)
>   23     def dispatch_mapping(self, instance):
>   24         for (key, value) in instance.items():
>   25             yield (value, key) <--- value (instance) comes first
>   26             yield from self((key, value))
> 
> value comes first so that it is picked up as instance by dispatch.__call__
> 
>   84     def __call__(self, instance, *args):

from comment #177 (!!) if the above is not done (passing instance 1st and *args
which can accept a non-argument - rather than a mandatory argument defaulting
to e.g. None - you have to do this awful/broken-ness:

  83 class Dispatcher(metaclass=DispatcherMeta):
  84     def __call__(self, instance):
             if isinstance(instance, tuple):
                  # extract the index
                  (instance, index) = instane
             else
                  index = errr some value indicating "non-iterable leaf node"
  85         for typeid in instance.__class__.__mro__:
  86             hook = self.__class__.dispatch(typeid=typeid)
  87             if hook is not None:

which doesn't work because there is no way to discern an *actual* tuple
from the "case where passing a tuple of (instance, index)

whatever is passed to Dispatcher *has* to be orthogonal, but also *has*
to be able to discern "iterable" from "non-iterable".  None as a path
*does not do this*, jacob:

{3: A(5, [12, 3])}               path=[]

no that is not okay (path=[]).  ints do not have and do not need paths.

there are two solutions i can think of:

1) instance, *args - and for non-iterables *args would be empty
2) always yield a (new) "Instance" object, which contains a
   mandatory "instance" and an **OPTIONAL** index (which you
   call "path" jacob)

i greatly prefer (1) because (2) forces walkers to always have
"node.instance"

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


More information about the libre-soc-bugs mailing list