开发者

Dynamic Dispatch Implementations

I am currently looking for various ways to impl开发者_如何学Cement dynamic dispatch.

As far as I know, there are two "easy" ways to implement this:

  • Virtual Function Tables, like in C++
  • Message Dispatcher, like in SmallTalk (which is somewhat akin to Python's idea of storing methods as attributes in __dict__)

I would note that as far as I know VFT have been chosen because they were performing reasonably and easy to implement (and also because they were well-suited with C++ separate compilation model), not because they were the fastest possible methods.

I have read a couple of articles and publications already, however most are "old" (the last I read(*) mentioned using a Pentium 200MHz ... hum), so I doubt that they represent the state-of-the-art unless research came to a stall.

I am interested in:

  • Dynamic Dispatch strategies, the better if they support multi-methods.
  • Benchmarks of the various strategies

I am particularly interested in recent articles and out-of-the-ordinary strategies (even if they did not prove efficient).

Publications are welcome, it would be better if they were freely available, and otherwise a summary of the technic presented and the result would be great.

Technical articles of real compiler implementations are also welcome.

(*) This article about Eiffel illustrates how whole program analysis can help remove virtual call sites.


I came across the following multi-method strategy while reading about the implementation of prototype-based object systems. It is written with that domain in mind, but it would not be difficult to adapt to a more traditional class-based language.

Section 3 details it, and figure 5 is a useful diagram. The idea is that each object (or class, perhaps) that can be dispatched on has its own method table. (In that sense, it is comparable to C++.) Each method that dispatches on that object (or class) is put into the table. The clever part is that the table is separated into subsections, which correspond to parameter positions.

To clarify: imagine that you have a method that specializes on class "Foo" for the first argument, and class "Quux" for the second argument. Section 1 of class Foo's dispatch table would contain a pointer to the method. And, section two for class Quux's dispatch table would also have a pointer to the method. To do dispatch, then, the arguments' classes' dispatch tables are consulted. If the method pointers match (like in our example), that is the method to call.

The paper is called "Prototypes with Multiple Dispatch". http://lee.fov120.com/ecoop.pdf

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜