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) |
[5 later articles] |
From: | Luke McCarthy <luke@iogopro.co.uk> |
Newsgroups: | comp.compilers |
Date: | 8 May 2005 22:55:28 -0400 |
Organization: | Leeds University |
References: | 05-05-041 |
Keywords: | types, interpreter |
Posted-Date: | 08 May 2005 22:55:28 EDT |
In Python a value would have a pointer to a dictionary with members like
__add__, __sub__, etc. (try dir(0)) which would be called to do the
appropriate operations. So, for example, 5+5 is equivalent to x.__add__(y).
This also allows the methods to be overloaded by the user to add new types
to the language.
Lua does something very similar and is much simpler (faster?) than Python.
See "The Implementation of Lua 5.0":
http://www.tecgraf.puc-rio.br/~lhf/ftp/doc/sblp2005.pdf
You might consider an array of function pointers, indexed by the op-code,
rather than using a switch/case statement. You may also consider having
different op-codes for built-in types (IADD, FADD, etc.).
Another trick is for the "type" of a value to be a pointer to a static type
descriptor rather than a special number. That way there is no possibility
of number clashes and reflection is much easier.
Luke McCarthy
Return to the
comp.compilers page.
Search the
comp.compilers archives again.