www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Using symbol for instance variable offset

As a part of implementing D/Objective-C I need to implement non-fragile 
instance variables for 64bit. Non-fragile instance variables work like 
regular instance variables except that instead of using a compile time 
known offset, a symbol containing the offset is used. The compiler 
outputs these symbols with the compile time known offset. Then at load 
time the offset can be replaced with something else. At runtime when 
accessing an instance variable the offset stored in the symbol should be 

I hit a problem trying to implement this. This is how the implementation 
currently looks like [1]. If I output the offset symbol for an instance 
variable in DotVarExp::toElem [2] I get a duplicate symbol error when 
compiling an application. If I don't output the offset symbol I get an 
assertion failure here instead [3]. Note that I'm currently always 
outputting the offset symbol when outputting the metadata for a class [4].

Any ideas how to solve this?


Note, the code is not up to date with upstream HEAD, but it's fairly recent.

/Jacob Carlborg
Mar 31 2014