Re: Multi-method

Joachim Durchholz <joachim_d@gmx.de>
6 Apr 2002 23:29:16 -0500

          From comp.compilers

Related articles
Multi-method jm@bourguet.org (Jean-Marc Bourguet) (2002-03-31)
Re: Multi-method haberg@matematik.su.se (2002-04-06)
Re: Multi-method vbdis@aol.com (2002-04-06)
Re: Multi-method joachim_d@gmx.de (Joachim Durchholz) (2002-04-06)
Re: Multi-method jm@bourguet.org (Jean-Marc Bourguet) (2002-04-07)
Re: Multi-method jm@bourguet.org (Jean-Marc Bourguet) (2002-04-07)
Re: Multi-method mailbox@dmitry-kazakov.de (Dmitry A.Kazakov) (2002-04-07)
Re: Multi-method joachim_d@gmx.de (Joachim Durchholz) (2002-04-07)
Re: Multi-method rprogers@seanet.com (Richard Rogers) (2002-04-10)
| List of all articles for this month |

From: Joachim Durchholz <joachim_d@gmx.de>
Newsgroups: comp.compilers
Date: 6 Apr 2002 23:29:16 -0500
Organization: Compilers Central
References: 02-03-190
Keywords: OOP
Posted-Date: 06 Apr 2002 23:29:16 EST

Jean-Marc Bourguet wrote:
> Is there such a technique allowing to dispatch on the type of several
> parameters
> - in time proportionnal to the number of dispatching parameter
> - in such a way that independant compilation is possible.


Base technique: Do a cascading dispatch, using a vtable for every
dispatching parameter.
I.e. for
      foo(x, y)
you'll have a dispatch table for x, then, for every entry in that table,
another dispatch table for y.
This will give a polynomial growth in the number of parameters, but you
can exploit that programmers try to arrange stuff so that the actual
number of routines is linear. IOW arrange your table compression scheme
so that it mimicks the ways programmers organize their multiple dispatch.


Note that independent compilation and multiple dispatch are at odds
conceptually. If you have
      function foo(Animal, Animal)
and
      function foo(Animal, Cow)
      function foo(Cow, Animal)
a call with a run-time type combination giving
      foo(Cow, Cow)
will be ambiguous. If all these code snippets are in different modules,
you'll need a link-time check anyway (IOW you don't have separate
compilation anymore, unless you write your own linker - in which case
the linker could in principle do anything that's traditionally
associated with the compiler's tasks, such as dataflow analysis to
determine which calls could go directly to a routine instead of through
a vtable, with subsequent inlining - that's one of the most important
optimizations for OO languages, and you can't do it before link time ina
multi-dispatch language).




Just my 2c.
Joachim


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.