According to Bernhard Tschirren:
Are there any ways of calling procedures written in GPC from GCC. Now, heres the clinch: The pascal source is object oriented!!
That's not a real problem. :-)
Now, I have a pointer to the object (in C). The object contains both data
There is an implicit `vmt' field, a pointer, in each object. Apart from that, it is just an ordinary `record' (or `struct' for that matter).
and ONLY virtual methods (That makes things simpler!) So, I could easily get the address of the function that I want to call.
Non-virtual methods are even easier: They are called `Myobject_Mymethod' internally and differ from ordinary procedures only by the additional implicit `Self' parameter.
To call a virtual method from C you must dig it out: The `vmt' field in the object points to a structure which contains
* the size of the object (a `size_type' variable in C), * its negative (another `size_type' variable), * and pointers to the methods in the same order as they appeared in the declaration of the object.
To initialize an object, it is not enough to call the constructor, but you must explicitly assign the correct value to the `vmt' field, i.e. let it point to the correct VMT structure. (GPC does this "inline" when a constructor is called.)
When you call a method, don't forget to pass the implicit `self' parameter.
So, the question is: How does GPC handle virtual methods? Looking at numerous assembly listing I have deduced the following:
GPC passes a pointer to the parent object
Why "parent"??? No - that's a pointer to the object itself!
(@Self) NOT on the stack, but in ECX. Is that true, and how is it implemented on other platforms?
This is just by chance and depends on the optimization level. If you declare the `self' parameter as an ordinary (pointer) parameter, it should work just fine because this is exactly what GPC does internally.
Good luck,
Peter -- Peter Gerwinski, Essen, Germany, free physicist and programmer Maintainer GNU Pascal - http://home.pages.de/~GNU-Pascal/ - 1 Oct 1997 PGP key fingerprint: AC 6C 94 45 BE 28 A4 96 0E CC E9 12 47 25 82 75 Fight the SPAM! - http://maps.vix.com/