Related articles |
---|
Jump tables and OOP in Oberon rmeenaks@bfm.com (1996-07-13) |
Re: Jump tables and OOP in Oberon tim@xinotech.com (Tim Dwyer) (1996-07-18) |
Re: Jump tables and OOP in Oberon bobduff@world.std.com (1996-07-22) |
Re: Jump tables and OOP in Oberon paulh@harlequin.co.uk (1996-07-23) |
Re: Jump tables and OOP in Oberon darius@phidani.be (Darius Blasband) (1996-07-23) |
From: | bobduff@world.std.com (Robert A Duff) |
Newsgroups: | comp.compilers |
Date: | 22 Jul 1996 10:49:51 -0400 |
Organization: | The World Public Access UNIX, Brookline, MA |
References: | 96-07-083 |
Keywords: | code |
Ram Meenakshisundaram <rmeenaks@bfm.com> wrote:
>... Can someone clearly define how jump tables are used in
>pascal-type CASE statements?
The compiler first checks that the case labels are "reasonably" close
together. If so, generate an array, indexed by the case expression, of
code addresses to jump to.
If the case labels are not reasonably close together, it's better to
generate a table of code addresses that can be binary-searched.
And if there are just a couple of case labels, treating it like a series
of if-then-else's makes sense.
> IS(x, A)
>
>How can this be implemented the most efficent way? I was think about creating
>a pointer for each Object. Each pointer Object will point to its parent.
>Each Object variable would have a pointer to its Object pointer. To determine
>if a variable is of type X, one only needs to traverse through the object
>tree and see if the variable's object pointer is the same as the one specified
>in the IS command.
The technique I've seen Ada compilers do is: For each type, keep an
array of (pointers to) all the ancestors of that type. Also keep an
integer number representing the depth of that type in the hierarchy.
Then, you can check whether a given type is in another type in constant
time -- no need to loop through all the parents. Just do:
if this type is deeper than that type then
check if the N'th element of the array is that type;
else
false.
end if;
or something like that.
Each object points to its type descriptor, which contains the above
info.
- Bob
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.