[Vm-dev] Direct pointer vs pointerForOop()

K K Subbu kksubbu.ml at gmail.com
Sun Apr 8 10:30:45 UTC 2018


On Sunday 08 April 2018 02:34 AM, David T. Lewis wrote:

> I was unclear in my meaning when I said "data type" for object pointers.
> I really only meant something like "#typedef usqInt sqObjectPointer" such
> that "sqObjectPointer" could be used when the intent is an object pointer,
> and "usqInt" could be used when the intent is an unsigned integer. Nothing
> would actually change, but it might make the VM code a bit easier to read
> and understand.

Your mail was very clear. But the new type is insufficient to handle all 
platform variations or suppress compiler warnings. An object pointer 
implementation could use direct address (void *), address offset 
(size_t) or table index (unsigned int). Compilers warn if we mix these 
in the same expression.

> With respect to defining data types, I think that Nicolas has already
> handled the most important case with the introduction of sqIntptr and
> usqIntptr. This clarifies the usage a lot, and cleans up a lot of problems
> across different compilers and platforms.

This is a really good fix, but it won't stop compilers warning about 
mixing ints/pointers :-(. sqMemoryAccess.h has many comments like:
-----
sqInt is a signed integer with size adequate for holding an Object 
Oriented Pointer (or immediate value) ....
---

Such intents can be captured in directly in a single union. 
Arch-independent code could use oop or oop.asOop while different 
implementations could choose different representations (oop.asAddr, 
oop.asOffset, oop.asInt, etc) without having to use casts. I have tried 
using both casts and unions in my other projects, and the ones with 
unions proved to be compact, readable and compiled without type warnings.

> You are right that "object pointer" is a confusing term for people who may
> be thinking in terms of C pointers. We also have a fair amount of confusion
> in the use of term "word". But in a very real sense, an object pointer
> really is a pointer (not just an identifier), even if that does mean
> something different from the term "pointer" in C. I don't know, maybe
> "object reference" instead of "object pointer"?
Excellent suggestion! sqObjectRef fits neatly into object graph model.

Members like word, byte etc. are only used within platform 
implementation code where their meaning would be clear. Higher layers 
would only use oop.

Regards .. Subbu


More information about the Vm-dev mailing list