Object file questions

Johannes Pfau via D.gnu d.gnu at puremagic.com
Sun Aug 17 01:49:58 PDT 2014


Am Sat, 16 Aug 2014 11:58:49 +0200
schrieb "Artur Skawina via D.gnu" <d.gnu at puremagic.com>:

> On 08/16/14 09:33, Johannes Pfau via D.gnu wrote:
> > https://github.com/D-Programming-GDC/GDC/pull/82
> 
> [Only noticed this accidentally; using a mailing list
> instead of some web forum would increase visibility...]
> 
> >  enum var = Volatile!(T,addr)(): doesn't allow |= on enum literals,
> > even if the type implements opAssign as there's no this pointer
> 
>    T volatile_load(T)(ref T v) nothrow {
>       asm { "" : "+m" v; }
>       T res = v;
>       asm { "" : "+g" res; }
>       return res;
>    }
> 
>    void volatile_store(T)(ref T v, const T a) nothrow {
>       asm { "" : : "m" v; }
>       v = a;
>       asm { "" : "+m" v; }
>    }
>       
>    struct Volatile(T, alias /* T* */ A) {
>        void opOpAssign(string OP)(const T rhs) nothrow {
>            auto v = volatile_load(*A);
>            mixin("v " ~ OP ~ "= rhs;");
>            volatile_store(*A, v);
>        }
>    }
> 
>    enum TimerB = Volatile!(uint, cast(uint*)0xDEADBEEF)();
> 
>    void main() {
>       TimerB |= 0b1;
>       TimerB += 1;
>    }

That's a good start. Can you also get unary operators working?
e.g
TimerB++;

Do you think it's possible to combine this with the other solution you
posted for struct fields? Or do we need separate Volatile!T and
VolatileField!T types?


More information about the D.gnu mailing list