On Aug 8, 4:05Â am, Mike Hore OVE.invalid.aapt.net.au>
wrote:
> I wrote:
>> So to get back to the idea of standardization, I like the idea of
>> low-level primitives on which anybody can build their own syntax. vtable
>> and Smalltalk-style method dispatch are fundamentally different
>> semantically, and as we've seen in this discussion there are plenty of
>> valid uses for both. Â So we probably need to provide primitives for
>> both. Â I don't know whether there should be optional sets of primitives
>> depending on the kind of dispatch, or whether the standard should simply
>> lump all of them into a "Base OO wordset". Â I'd prefer the latter, myself.
>
>> Another question is class-based or prototype-based OO. Â I'm most
>> comfortable with class-based myself, but I'm sure there are some avid
>> prototype people around. Â The worrying thing is that again the semantics
>> are so different we're faced with including both of them. Â But I'm less
>> comfortable with that than with method dispatching. Â I'd like to think
>> about ways we could standardize specifying classes, maybe with
>> structures as a starting point?
>
>> This is all just off the top of my head, but I think it would be good to
>> try thinking about what primitives we could come up with that would be
>> capable of implementing all the common OO paradigms that are in use.
>
> Nobody's replied yet (maybe everyone's kill-filed the OO syntax thread?)
> so I'm renaming the topic and going to do some rambling about possible
> standardizable primitives. Â Let me state categorically that this is just
> rambling at this stage. Â I have no experience in formally proposing
> words for a standard, and as we're going on holiday fairly soon I don't
> have much time anyway. Â I just want to throw around some initial ideas
> and hope that a profitable discussion might follow.
>
> I'll start with method invocation since I've got to start somewhere.
>
> Messages need to be sent to objects, so we seem to need something like
>
> SEND Â ( ^obj selector -- ?? )
>
> which takes the address of an object and *something* representing a
> selector. Â I don't care what it is. Â This word invokes a method and
> returns whatever the method returns. Â The stack order of parameters
> isn't important.
>
> Now this can be decomposed into binding, and execution. Â So we need
> something like
>
> BIND Â ( ^obj selector -- xt )
>
> which takes the object address and selector and returns the xt of the
> method to be invoked. Â Then we can have
>
Win32Forth has
GETMETHOD ( " sel: obj/class" -- xt ) \ Intepreting
[GETMETHOD] ( " sel: obj/class -- ) \ Compile xt as literal
so BIND would be a useful factor.
> EXECUTE-METHOD Â ( ^obj xt -- ?? )
>
> which takes the xt we got from BIND, and invokes the method. Â Notice we
> don't simply use EXECUTE since the method, when running, needs the base
> address of the object somewhere (hopefully in a register but that's an
> implementation detail). Â I suppose EXECUTE could be made clever enough
> to realize that it's a method we're calling, but it seems more
> straightforward to just specify EXECUTE-METHOD and let the compiler
> decide how best to implement it.
>
In Win32Forth (ITC) the xt of a method expects the object address on
the stack so EXECUTE-METHOD would just be an alias of EXECUTE, though
in the STC version the xt is a :NONAME definition that expects the
current object pointer to already contain the object. We have a word
METHODEXECUTE (which in the ITC version is just an alias of EXECUTE)
to hide the details (so it's just a name change).
There is also METHODCATCH which works like CATCH except there's an
extra cell (which might or might not be the original ^obj) on the
stack (again the ITC version just defines an alias of CATCH, while
the STC version does extra work). I think CATCH-METHOD would be a
useful addition.
> So now, conceptually, we can have
>
> : SEND Â ( ^obj selector -- ?? )
>     over swap bind  execute-method  ;
>
> Now BIND probably isn't good enough, since there are different kinds of
> bindings. Â I'm familiar with three, and we're going to hit a terminology
> problem.
>
> 1. Â Early binding. Â This is OK - I think everybody understands what this
> means.
Except users of COM (MS insists that early binding is vtable binding
while late binding is dispatch binding (i.e. even later).
>
> 2. Â vtable binding. Â Also called "late binding" by some. Â This requires
> the method name to be already declared in the class, though the binding
> can be to a subclass that hasn't yet been declared at the time the
> binding is done. Â I prefer to call this vtable-binding to distinguish it
> from 3. below.
>
> 3. Â Smalltalk-style late binding. Â Commonly this uses a hashed selector
> which is resolved at run time. Â The method need not be already declared
> anywhere when the binding is done.
>
> So I think BIND actually needs to be three words, though I'm not sure
> what to call them. Â Let me, for now, call them
>
> EARLY-BIND
> VTABLE-BIND
> LATE-BIND
>
There's also DISPATCH-BIND where a the actual selector name is
passed as a string at run-time(though it's slower than the
others, since it's basically interpreting).
> OK, I'll leave it there for now -- comments, anyone?
>
> Cheers, Â Mike.
>
> ---------------------------------------------------------------
>    Mike Hore   mike_hore...@
OVE.invalid.aapt.net.au
> ---------------------------------------------------------------
> ** Posted
fromhttp://www.teranews.com**- Hide quoted text -
>
> - Show quoted text -
George Hubert