On 03/11/2014 02:18 PM, Patrick Walton wrote: > You need: > 1. One-word pointers to each DOM node, not two... > 2. Access to fields common to every instance of a trait without > virtual dispatch... > 3. Downcasting and upcasting.
Let's look at what C++ virtual functions F and the classes T they operate on really amount to. At runtime, class T is just a const global array V of pointers to those functions F. A T instance is just a struct with &V in it. The functions F are notable only for having a T* first argument, but that is really just a C++ convention. You can field those with no difficulty in C, as indeed GTK+ does. A derived class T2 is another const global array V2 of pointers to functions F2, the first N of which are stack-frame compatible with F, and, each, optionally identical. The T2 instance is another struct, with its first member an instance of T. Nothing there conflicts with the Rust we know. Compile time support is only a little more specialized. We need some representation-preserving type coercions for the various pointers. (For multiple inheritance, some of the coercions would add a compile- time constant.) The only type-compatibility enforcement needed is for the function-argument lists. The const-global-array-of-function-pointers has been called a driver, and the struct-with-a-pointer-to-it has been a file (or FILE, or FCB to old-timers) for longer than I have been alive. Syntactic sugar to extend T and V, and enforcing F2 compatibility with F, takes us all the way to "object-oriented". It would be a good demonstration of Rust expressiveness to make object orientation a library construct. Having that in the standard library would suffice for interoperability. Language primitives just sufficient to enable such a library would be more useful than wired-in support. Given such primitives, esoteric constructions like virtual inheritance could be left to ambitious users. Nathan Myers _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
