[Vm-dev] Direct pointer vs pointerForOop()
K K Subbu
kksubbu.ml at gmail.com
Sat Apr 7 17:58:38 UTC 2018
On Saturday 07 April 2018 08:02 PM, David T. Lewis wrote:
> I have long thought that it would be a good idea for purposes of clarity
> to have a separate "sqObjectPointer" data type distinct from sqInt and
> usqInt. This would make the intentions clear, and I think it would make
> the VM code easier to read and understand. But it would probably be a
> lot of work to do this throughout the VM.
While I realize OOP is strongly entrenched in literature, terms like
pointer, address have strong connotations of machine architecture. If
you are going to introduce a new type, I would suggest neutral terms
like sqObjectId, sqObjectIndex or sqObjectHandle.
How about using a union to pass them across Object and Memory layers and
avoid all those horrid casts?
typedef union {
u32 asId;
void *asAddress;
unsigned int asWord;
unsigned long asLongWord;
unsigned char asBytes[sizeof(void *)];
...
} sqObjectId;
Object layer can access it as oop.asId and the Memory layer can use
asWord or asAddress after suitable conversion:
sqObjectId pointerForOop(sqObjectId oop)
{return (oop.asAddress = oop.asId + sqMemoryBase, oop);}
sqObjectId oopFromPointer(sqObjectId oop)
{return (oop.asId = sqMemoryBase - oop.asAddr, oop); }
Regards .. Subbu
More information about the Vm-dev
mailing list