Re: Dynamic Typing Efficiency

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
9 May 2005 22:30:48 -0400

          From comp.compilers

Related articles
Dynamic Typing Efficiency clearm@comcast.net (2005-05-08)
Re: Dynamic Typing Efficiency bobduff@shell01.TheWorld.com (Robert A Duff) (2005-05-08)
Re: Dynamic Typing Efficiency luke@iogopro.co.uk (Luke McCarthy) (2005-05-08)
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)
[2 later articles]
| List of all articles for this month |
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Newsgroups: comp.compilers
Date: 9 May 2005 22:30:48 -0400
Organization: cbb software GmbH
References: 05-05-041
Keywords: types, interpreter
Posted-Date: 09 May 2005 22:30:48 EDT

On 8 May 2005 17:02:05 -0400, clearm@comcast.net wrote:
> 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
> have integers, doubles, strings, booleans, and various compound types,
> then an ADD instruction would have to look like this: ...


Why don't you do:


switch (operand1->type)
{
      case INTEGER :
            switch (operand2->type)
            {
                  case INTEGER :
                  case DOUBLE :
                  ...
            }
      case DOUBLE :
            ...
}


> The only way to avoid this that I can think of is to create a
> statically typed language. That way I can use instructions like IADD,
> DADD, ILOAD, DLOAD, etc, sort of like the JVM. But I don't want a
> statically typed language!


The above does not look like a dynamically (or statically) typed
language with ADTs. Where are the user-defined types? You don't know
them in advance (at compile-time of the compiler!)


Anyway, if you have to implement dispatch, you can use a hash
table. The types of the operands and of the result (the signature)
will be the key to search in the hash table of the function's
signatures (the dispatch table). If you find a way to enumerate types
using a dense index, then you can replace hash table with a
n-dimensional array, where n-1 is the number of arguments.


--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


Post a followup to this message

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