On Tue, Sep 9, 2014 at 2:01 AM, Nick Wellnhofer <[email protected]> wrote:
> On 09/09/2014 04:04, Marvin Humphrey wrote:
>> I think we can make that check redundant using DSO-style lazy loading
>> techniques: have each class start off with a dummy interface table
>> populated with stubs which lazily build the interface table, replacing
>> themselves and reinvoking on success or throwing an exception on failure.
>
> I can't see how this would work. The interfaces a class could implement
> aren't known at compile time.
Each interface gets:
* A unique integer id.
* A stub interface table filled with stub methods.
Each Class gets:
* An array of interfaces, initialized to the stub interface tables for each
interface.
Interface method dispatch would look something like this:
static inline void
Futzer_Futz(Futzer *self) {
Interface *interface = self->klass->itables[Futzer_INTERFACE_ID];
char *ptr = (char*)interface + Futzer_Futz_OFFSET;
Futzer_Futz_t method = (Futzer_Futz_t)ptr;
method(self);
}
If we add many interfaces dynamically, we'll have to reallocate, at a cost
proportional to O(M*N) for M classes and N interfaces. Thread safety when
modifying Class data will be tricky but ought to be manageable.
Marvin Humphrey