Re: Dynamic Typing Efficiency

Alex Colvin <alexc@TheWorld.com>
13 May 2005 17:57:27 -0400

          From comp.compilers

Related articles
[3 earlier articles]
Re: Dynamic Typing Efficiency gah@ugcs.caltech.edu (glen herrmannsfeldt) (2005-05-08)
Re: Dynamic Typing Efficiency loic@fejoz.net (Yermat) (2005-05-09)
Re: Dynamic Typing Efficiency mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2005-05-09)
Re: Dynamic Typing Efficiency eliotm@pacbell.net (Eliot Miranda) (2005-05-09)
Re: Dynamic Typing Efficiency jeffrey.kenton@comcast.net (Jeff Kenton) (2005-05-09)
Re: Dynamic Typing Efficiency clearm@comcast.net (2005-05-13)
Re: Dynamic Typing Efficiency alexc@TheWorld.com (Alex Colvin) (2005-05-13)
Re: Dynamic Typing Efficiency calumg@onetel.com (Calum Grant) (2005-05-13)
Re: Dynamic Typing Efficiency angray@beeb.net (Aaron Gray) (2005-05-16)
Re: Dynamic Typing Efficiency DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2005-05-18)
Re: Dynamic Typing Efficiency jeffrey.kenton@comcast.net (Jeff Kenton) (2005-05-22)
| List of all articles for this month |

From: Alex Colvin <alexc@TheWorld.com>
Newsgroups: comp.compilers
Date: 13 May 2005 17:57:27 -0400
Organization: The World : www.TheWorld.com : Since 1989
References: 05-05-041
Keywords: types, practice
Posted-Date: 13 May 2005 17:57:27 EDT

>The problem I have is that dynamic typing seems to be extremely
>inefficient when you have a large number of types. For example, if I


  Why is this so inefficient?


>have integers, doubles, strings, booleans, and various compound types,
>then an ADD instruction would have to look like this:


>...
> else if (operand1->type == INTEGER && operand2->type == DOUBLE)
> {
> value.d = (double)operand1->val.i + operand2->val.d;
> type = DOUBLE;
> }




Your example just shows that you choose the wider of the two operand types
and widen the narrower That ought to be straightforward, if you define a
"width" for each numeric type.


Once you add user types things can get more complicated. If you use C++
style single-dispatch you have one dispatch for the object type (in C++
this is simply an indirection) followed by another method lookup for the
argument type.


I have no idea how Dylan implements multiple-dispatch. SOme sort of
runtime mattern-matching?


--
mac the naf


Post a followup to this message

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