On Wednesday, 13 June 2018 at 05:57:31 UTC, Stefan Koch wrote:
Good day ladies and gentleman,

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


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.


That's very nice! Out of curiosity, what was the reason to avoid a conventional stack? Or was it a consequence more than a design decision? (If you've explained it before, feel free to just throw the old post at me)

Reply via email to