OOP_(re)

Tue, 27 May 1997 17:42:36 +0200 (MET DST)


According to Pierre Phaneuf:
> 
> If the VMT offset given is the same as the called constructor, then it is
> the first constructor called and the object is initialized. If the VMT
> parameter isn't the same as the called constructor, it is because it is
> being called from within another constructor and hence the object is
> already initialized. This is actually easy! ;-)

Sorry, but I don't understand this (perhaps it's too easy for me;).
How can the VMT offset be the same as a constructor?  AFAIK, BP passes a
VMT offset of zero to constructors which shall *not* initialize an object.

> [...]

> This doesn't give much information about the object apart from its size
> and the number of methods and where they are... What we'd need is
> something like from which class is another class derived from, its name,
> and so on...

So we should extend the VMT.  Okay, why not ...

BTW, somebody knows a reasonable way how to implement multiple inheritance?

> Hmm... Is it possible to have a function automatically generated by the
> compiler before going to the optimizing stage? It would contain a table
> translating VMT pointers into strings of the classes name

No problem.

> and would be
> optimized out of the program by the optimizer if unused, right?

True for a Program, false for a Unit.  While the GPC compiler is *much*
smarter than BP and would remove unused code and variables, the GNU linker
is not able to remove dead code, it only does so if a whole Unit is unused.

> [...]

> What I mean is (for example) a NewObject() function that would work just
> like New(), but instead of a typed pointer or an object type itself, it
> would take a VMT pointer as the first parameter. It would make the
> construction of an object from a stream as simple as calling
> "Get:=NewObject(TStreamRec.VMTLink, Load(@Self));" at the end of the 
> TStream.Get method.

It should not be difficult to implement this using `GetMem' and an explicit
assignment to `TypeOf'.

> BTW, how does New() work when it is passed an object type (say, PObject)
> as the first parameter?

The compiler picks up the (constant) size of the object, calls `GetMem',
initializes the VMT field and finally calls the constructor. (In BP, the
value for the VMT field is passed to the constructor which does the
assignment, but I see no reason for that.)

Greetings,

    Peter

  Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
 maintainer GNU Pascal [970510] - http://home.pages.de/~gnu-pascal/ [970125]


Peter Gerwinski (peter@agnes.dida.physik.uni-essen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es