object - interface compatibility
Pragma
ericanderton at yahoo.removeme.com
Tue Nov 14 11:29:32 PST 2006
BCS wrote:
> Actually I would like to see interface calling convention changed to use
> a fat pointer for interfaces. This would use a arbitrary context pointer
> welded to a pointer to a v-tbl. All sorts of cool things could be done
> with this.
>
> interface literals working like delegate literals
> 3rd party interface implementation for classes*
> interfaces from structs, arrays and any arbitrary pointers.
>
> In effect any reference can be used as a context and as the basis for an
> interface
So then the interface method call turns into:
//inf.test(a, b, c);
push c
push b
push a // push args
mov obj -> r1 // load pointer to object
mov vtbl -> r2 // load v-tbl (obj+vtbl = fat-pointer)
push r1 // push "this"
call r2[test] // use v-tbl to call test
So, this basically sacrifices stack space in favor of a few less opcodes
per interface-method call. :)
But doesn't this make cast() operations *longer* by one additional move
operation? Are method calls really more numerous than casts?
On the up-side, it would only make the ABI more consistent, since
delegates are pretty much doing the same thing when compared to their
function-pointer counterpart (as you already mentioned). A higher
degree of consistency there, could buy us a higher degree of consistency
with D's constructs, cleaner code, and possibly more-bug-free compiler
implementations.
--
- EricAnderton at yahoo
More information about the Digitalmars-d
mailing list