Gary recently voiced concern over dict-based visitor lookups perhaps
giving a speed penalty
Now, I might be wrong, but vtables can only be used if classes or
methods are declared as "cdef", right? And on the other hand, I think we
definitely want Cython to be runnable in Python, so that we don't have
to ship Cython in .c-form to people who don't already have Cython
installed, not to mention having to "bootstrap" any new Cython feature
using the current Cython features (agreed or not?)
Is there going to be a way to have this (i.e., vtable-based Cython) in
the foreseeable future? Using decorators certainly comes to mind,
however that breaks 2.3 support. Perhaps special comments?
#cython: cdef Visitor:
class Visitor:
#cython: cdef object pre_FuncDefNode(FuncDefNode node):
def pre_FuncDefNode(node):
...
Because if this is never going to happen, I think we might as well go
for nice, dict-based visitors. If it is going to happen though, it is a
case for vtable-based visitors.
Dag Sverre
Appendix 1:
For people who haven't followed that discussion, dict-based visitors
refers to writing visitors in a way similar to this:
class MyVisitor(Visitor):
def make_function_scope(node):
...
matches = [
pre(FuncDefNode, make_function_scope)
]
with no changes to existing node classes, while vtable-bases would be
like this:
class MyVisitor(Visitor):
def pre_FuncDefNode(self, node):
# make function scope
....
and each node class must have something like this added (*no*, this
can't be done magically some other place like you're used to, that would
break the vtable-ness of it):
class FuncDefNode(Node):
def accept(self, v):
v.visit_FuncDefNode(self)
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev