On Friday, 21 July 2017 at 08:06:09 UTC, Stefan Koch wrote:
My pleasure :)

// ...

mixin((){
    // ...

    enum Y = [
        //  id   reg  mask   ty
        X("AH",   4, mAX, TYuchar),
        X("AL",   0, mAX, TYuchar),
        X("AX",   8, mAX, TYushort),
        X("BH",   7, mBX, TYuchar),
        X("BL",   3, mBX, TYuchar),
        // ...
        X("ESI", 22, mSI, TYulong),
        X("ESP", 20,   0, TYulong),
        X("SI",  14, mSI, TYushort),
        X("SP",  12,   0, TYushort),
    ];


    enum lns = itos(Y.length);

string pseudotab = "\nprivate __gshared static immutable string[" ~ lns ~ "] pseudotab = [";

    foreach(i, r; Y)
    {
        pseudotab ~= `"` ~ r.id ~ `", `;
    }

    pseudotab ~= "];\n";

}());

Quick questions: isn't it possible to do

private __gshared const(char)*[24] pseudotab = Y.map!(x => x.id);

instead? That seems like the most obvious and easy to read option; and in contrast to the other solutions proposed, it's closer to the Rule of Least Power.

Reply via email to