Re: How to implement dynamic typing?

Ctalk Project <ctalk@ctalklang.org>
Wed, 07 Apr 2010 17:14:02 -0400

          From comp.compilers

Related articles
[3 earlier articles]
Re: How to implement dynamic typing? rpw3@rpw3.org (2010-04-06)
Re: How to implement dynamic typing? bartc@freeuk.com (bartc) (2010-04-06)
Re: How to implement dynamic typing? paul.biggar@gmail.com (Paul Biggar) (2010-04-06)
Re: How to implement dynamic typing? iant@google.com (Ian Lance Taylor) (2010-04-06)
Re: How to implement dynamic typing? barry.j.kelly@gmail.com (Barry Kelly) (2010-04-07)
Re: How to implement dynamic typing? torbenm@diku.dk (2010-04-07)
Re: How to implement dynamic typing? ctalk@ctalklang.org (Ctalk Project) (2010-04-07)
Re: How to implement dynamic typing? gneuner2@comcast.net (George Neuner) (2010-04-07)
Re: How to implement dynamic typing? cr88192@hotmail.com (BGB / cr88192) (2010-04-10)
Re: How to implement dynamic typing? bartc@freeuk.com (bartc) (2010-04-11)
Re: How to implement dynamic typing? harold.aptroot@gmail.com (Harold Aptroot) (2010-04-11)
Re: How to implement dynamic typing? cr88192@hotmail.com (BGB / cr88192) (2010-04-11)
Re: How to implement dynamic typing? cr88192@hotmail.com (BGB / cr88192) (2010-04-12)
[15 later articles]
| List of all articles for this month |
From: Ctalk Project <ctalk@ctalklang.org>
Newsgroups: comp.compilers
Date: Wed, 07 Apr 2010 17:14:02 -0400
Organization: Compilers Central
References: 10-04-009 10-04-024
Keywords: types
Posted-Date: 10 Apr 2010 00:08:35 EDT

torbenm@diku.dk (Torben Fgidius Mogensen) writes:


> David Belier <davidbleier@hotmail.com> writes:
>
>> 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
>> time. Can someone please name papers or websites to read?
>
> Combining each value (not variable) with a type tag is the most common
> way to implement dynamic types. If the number of possible types is
> fixed at compile time, the tags can be small integers (one for each
> possible type) and you would typically test the tag before each
> operation (where an operation would only allow a small number of
> different types). If you can dynamically create types or add operations
> to types, the tag can be a pointer to a descriptor, which itself can be
> a table of the possible operations. This is typical for OO languages,
> which have dynamic types to some degree (due to dynamic subtyping) even
> when they are nominally statically typed (such as Java).


Typically, a type tag can point to an operator method, where the
program would actually need the type information. The operator could
perform whatever operations the type needed; often the operation is of
the switch-statement type, depending on the types of the operands and
the needs of the operator, but not always.


It might be more useful, if you're not looking to implement a complete
class structure, to use bit fields instead of small integers for a
type tag, so that the compiler or interpreter could subdivide further,
for example, between ints and then their word length, like 16, 32, 64
or however many bits long, or floats of single, double, or long float
different precisions.


I'm not sure if this helps clarify what the OP wanted, but it should
be more efficient to hold off on unneeded operations until performing
an actual operation on the variables.


--
Ctalk Home Page: http://www.ctalklang.org



Post a followup to this message

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