Good day ladies and gentleman,

it is my distinct please to announce that a new feature just landed in newCTFE.

!!! DELEGATES !!!

this means the following code will now work:
int square_of_x_plus_x(int x) pure
{
    int passThrough(int y) pure
    {
        assert(x == y);
        int y2 = x;
        assert(y2 == y);

        int fnC() pure
        {
            auto z = (x * y);
            assert(y2 == x);
            assert(x == y);
            return z;
        }
        return fnC();
    }
    return x + passThrough(x);
}

pragma(msg, square_of_x_plus_x(7));
static assert(square_of_x_plus_x(5) == (5*5)+5);

the reason why this was quite tricky to implement is that
in the newCTFE architecture there is no concept of a function touching
the stack-frame of another function _at all_.
(Infact there is no conventional stack, rather the virtual registers themselves stack) Sharing of the stack frames gets emulated via a hidden parameter and a linked-list structure.

Cheers,
Stefan


Reply via email to