|How to implement dynamic typing? firstname.lastname@example.org (David Belier) (2010-04-02)|
|Re: How to implement dynamic typing? email@example.com (glen herrmannsfeldt) (2010-04-06)|
|Re: How to implement dynamic typing? firstname.lastname@example.org (andy johnson) (2010-04-06)|
|Re: How to implement dynamic typing? email@example.com (2010-04-06)|
|Re: How to implement dynamic typing? firstname.lastname@example.org (bartc) (2010-04-06)|
|Re: How to implement dynamic typing? email@example.com (Paul Biggar) (2010-04-06)|
|Re: How to implement dynamic typing? firstname.lastname@example.org (Ian Lance Taylor) (2010-04-06)|
|Re: How to implement dynamic typing? email@example.com (Barry Kelly) (2010-04-07)|
|Re: How to implement dynamic typing? firstname.lastname@example.org (2010-04-07)|
|Re: How to implement dynamic typing? email@example.com (Ctalk Project) (2010-04-07)|
|Re: How to implement dynamic typing? firstname.lastname@example.org (George Neuner) (2010-04-07)|
|[20 later articles]|
|Date:||Tue, 6 Apr 2010 16:38:56 -0000|
|Posted-Date:||07 Apr 2010 01:53:13 EDT|
"David Belier" <email@example.com> wrote in message
> Recently I finished chapter 7 of the dragon book (2nd edition) but I
> still don't understand how to implement dynamic typing. I don't get
> how you are supposed to store the type information with each variable
> and check it every time using an acceptable amount of resources and
What would be acceptable?
>Can someone please name papers or websites to read?
I quite liked a paper called The Implementation of Lua (I think here:
(Although it claims Lua to be fast, I didn't find it that fast.)
> Note: I have a strong C++ background and know x86 assembler. I can
> imagine a way to implement it doubling memory requirements and making
> the program dead slow in the process so there must be better ways.
It sounds like you already have a good idea of what's involved. Often
dynamic typing is linked to interpreted languages, and you would expect the
combination to be a magnitude at least slower than statically typed and
fully compiled code.
The way I do it, dynamic typing involves adding an extra tag to every value.
This could be a pointer to a table (of function pointers; indexed by
whatever operation you want to do on it). Binary operations then need yet
more testing. However I tend to just use an index or handle to the type
I don't see that a tag will double memory, assuming that you include
homogeneous arrays in your type system (you don't need to tag every
element), strings, structures, and so on. The total overhead then should be
It is true that you frequently have to check these tags, but there are ways
to speed that up (tables of jumps and pointers as mentioned). And if the
operations you're performing are high-level (on a whole array, string, or
structure), then again the overhead should be small.
Dynamic typing can work well (which is why I'm switching to static typing
:-) (but mixed with dynamic types)
> the past I have also used Java and Python for small programs (CS
> course and writing file converters). They seemed to show reasonable
If you think that Python is fast enough, then you're not going to have any
Return to the
Search the comp.compilers archives again.