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 
used.

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?

[1] 
https://github.com/jacob-carlborg/dmd/commit/9d9f6c9a5edc455b066ec77c5f1373b2886860a6
[2] 
https://github.com/jacob-carlborg/dmd/blob/9d9f6c9a5edc455b066ec77c5f1373b2886860a6/src/e2ir.c#L3664-L3674
[3] 
https://github.com/jacob-carlborg/dmd/blob/9d9f6c9a5edc455b066ec77c5f1373b2886860a6/src/backend/cod1.c#L1487
[4] 
https://github.com/jacob-carlborg/dmd/blob/9d9f6c9a5edc455b066ec77c5f1373b2886860a6/src/objc.c#L1629

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

-- 
/Jacob Carlborg
Mar 31 2014