Hi all,
I'm trying to reduce the gap between traditional Mac Pascal object models and GPC's current object model.
Frank's already added an option in to turn virtual on for all methods automatically, so that's reduced one major incompatibility. The other one is that in Mac Pascals, object is implicitly a pointer and implicitly dereferenced. That is:
type myobject = object v: Integer; procedure method; end; var obj: myobject; begin New( obj ); obj.v := 5; obj.method; end.
In GPC, object is more like a record, and typically you create a pointer to it an New that, ie:
type myobject = object v: Integer; procedure method; end; myobjectptr = ^myobject; var obj: myobjectptr; begin New( obj ); obj^.v := 5; obj^.method; end.
What I'd like added to GPC is a compiler switch like {$implicit-object-dereference} which allows
obj.field to be a synonym for obj^.field in the case where obj is a pointer to an object.
This would remove most of the incompatibilities, particularly it would remove all the ones in normal use of code (at least as far as I can see).
The only remaining issue would be when defining an object you need define an explicit pointer. Ideally this could be handled by another option, or perhaps the same option perhaps renamed {$implicit-object-pointers}, which would convert:
type myobject = object...
in to defining myobject as a pointer to that object, and allow the cases like
type mysubobject = object(myobject)...
However, that latter half is not absolutely required as there are relatively few object definitions and they can be conditionalized otherwise. The primary issue is the first one since otherwise every single object access would have to be conditionalized which would be unpleasant to say the least.
I can't see any real drawback with an option to allow implicit dereferencing of an object pointer, it looks to be unambiguous since otherwise objp.field will just give an error complaining about the lack of ^. This also has no compatibility issues with GPC objects.
Making all objects implicitly pointers is a somewhat larger change, and this would be incompatible with GPC objects, so it is not so clearly a good idea. I think it'd still be helpful to enable source code compatibility, but it can at least be worked around with a finite amount of conditionalizing or macro hacks.
So, and thoughts on this, one way or the other?
Thanks, Peter. PS: I've currently got 35 files with around 15,000 lines compiling in GPC, most of it compiling also in CW. So objects aside, it's currently relatively straight forward to get CW/GPC compatible source code which is wonderful!