[Libre-soc-bugs] [Bug 1094] insndb instruction database visitor-walker is needed
bugzilla-daemon at libre-soc.org
bugzilla-daemon at libre-soc.org
Tue Jun 20 20:39:00 BST 2023
https://bugs.libre-soc.org/show_bug.cgi?id=1094
--- Comment #216 from Dmitry Selyutin <ghostmansd at gmail.com> ---
(In reply to Jacob Lifshay from comment #212)
> (In reply to Dmitry Selyutin from comment #211)
> > Also, on paths. If we yield the parent (which I assumed is the original
> > instance), perhaps the path should point to this parent, and not to the
> > root? We currently keep the whole path.
>
> you still need to know which child of the parent you are...
cf. below (#213 I think?). I think if we have both parent and path to this
parent we could reconstructthe whole path... Or not?
> also, if you use a list for path, and just push and pop indexes from the end
> rather than making a new object every time then you don't need to constantly
> allocate as much, which is a bit faster.
I just don't like APIs which modify builtins in-place. This can sometimes
strike back.
> also, i think the library should provide a function that has the top-level
> for loop running both walker and visitor
I'm intentionally leaving this task to caller because:
1. It's up to caller what to pass from walker to visitor.
2. It's up to caller what to pass else.
3. It's up to caller which kind of visitor to choose.
4. It's up to caller which action to after the hook was called or yielded back
to caller.
The best form I could think of is:
def visit(root, walker, visitor, wrapper=lambda rv: rv,*args, **kwargs):
if isinstance(visitor, ContextVisitor):
for (node, parent, path) in walker(root):
with visitor(node, parent=parent, path=path, *args, **kwargs):
wrapper(rv)
else:
for (node, parent, path) in walker(root):
wrapper(visitor(node, parent=parent, path=path, *args, **kwargs))
This seems complex and clumsy to use. Perhaps you have other ideas?
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the libre-soc-bugs
mailing list