Re: OO in Forth
- From: Doug Hoffman <no.spam>
- Date: Wed, 23 Jul 2008 11:42:46 -0400
Thomas Pornin wrote:
According to Doug Hoffman <dhoffman@xxxxxxxxxxxxxxx>:No. Whether or not there are subclasses with overriding methods has
no bearing at all on the compiler's ability to decide to early or late
bind.
I beg to disagree. If the compiler can prove, through static analysis,
that the value on which it is calling a method named "foo" relates to
class C or a subclass thereof, and if the compiler simultaneously has
knowledge of all subclasses of C that may exist at runtime, and none
of them overrides "foo", then the compiler can safely convert the method
call to a direct function call, i.e. perform early binding.
I think we must be talking apples and oranges. You clipped important parts of my statement. I said:
"No. Whether or not there are subclasses with overriding methods has no bearing at all on the compiler's ability to decide to early or late bind. All the compiler need know is the *class* of *that particular object* at compile time. The class of that object could have 100 subclasses with or without method overriding, or no subclasses at all. It makes no difference."
Perhaps it's because Neon uses Smalltalk-like binding.
Here's an example to illustrate my point:
:class foo1
:m draw: ." foo1" ;m
;class
:class foo2
:m draw: ." foo2" ;m
;class
Now, let's instantiate two objects and send each the draw: message:
foo1 obj1
foo2 obj2
draw: obj1 foo1 ok \ an early bind
draw: obj2 foo2 ok \ an early bind
The compiler will use early binding in both cases because it knows the classes of each object at compile time.
Now let's create a subclass that overrides the draw: method:
:class foo3 <super foo1
:m draw: ." foo3" ;m
;class
foo3 obj3
draw: obj3 foo3 ok \ an early bind
Now if we go back and instantiate another foo1 object we get the following:
foo1 obj1a
draw: obj1a foo1 ok \ this will again be an early bind
The existence of the subclass foo3 and/or its draw: method overriding had *no bearing* on the compiler's decision to early bind or late bind to the foo1 object.
Analogous results would be achieved had we defined draw: to be a late bind in classes foo1 foo2 and foo3 or mixed it up (the late bind of course is not necessary in this example). The compiler will use the binding (late or early) prescribed by the class. The existence of subclasses and what they do with that selector has no bearing.
QED
Again, I have to think that you, Andrew, and I are not talking about the same thing or are mis-communicating somehow.
-Doug
.
- Follow-Ups:
- Re: OO in Forth
- From: Thomas Pornin
- Re: OO in Forth
- References:
- OO in Forth
- From: DavidM
- Re: OO in Forth
- From: Celime
- Re: OO in Forth
- From: Andrew Haley
- Re: OO in Forth
- From: Doug Hoffman
- Re: OO in Forth
- From: Thomas Pornin
- OO in Forth
- Prev by Date: Re: Tiny CPUs in programmable logic
- Next by Date: Re: OO in Forth
- Previous by thread: Re: OO in Forth
- Next by thread: Re: OO in Forth
- Index(es):
Relevant Pages
|