Adding fields support to foreign class #994 by adding ObjMemorySegment
Before it can be applied, this patch set requires to solve the question of the behavior when inheriting from a foreign, when no constructor/destructor are provided, while the parent class had some.
This patch set allow foreign class to have member variables with some restrictions. It still must inherit from a regular class without member variables (should we check that there is no static member variables ?) or from another foreign class.
It does that by adding an ObjMemorySegment which is the fusion of ObjForeign and ObjInstance. The name comes from the fact that such object can technically be used hold any object the VM can produce, and therefore represent a memory segment of the VM.
should we check that there is no static member variables ?
On the face of it, there seems no need as static methods are not inherited anyway.
True, but you end up in a situation where declaring a generic constructor in wren, results in the in a crash if you call a method from the super class expecting the defined constructor memory. And I don't see a way to ASSERT on this properly.
Just check there are no instance or static fields then.
As it's a technical requirement that the foreign class needs to inherit from a regular class, the latter may just be invented for this sole purpose and not need any kind of state anyway.
I think we don't understand each other, the problem is in the subclass possibly not providing foreign user data to the parent class because of the default behavior when NULL is passed.
I can see there is a problem with static fields now you've explained it.
However, I'm trying to look at it from a practical point of view.
In other words do you think it would be a major impediment if the regular super-class couldn't have either instance or static fields?
The problem lies in the fact that the constructor cannot be called in a re-entrant manner, leading to an improperly constructed regular object. But that issue can be circumvented in C, for foreign inheritance.