On Wednesday, 10 May 2017 at 14:03:58 UTC, Biotronic wrote:

As for making the code faster right now, could this be done with mixin templates instead?

Something like:

import functions = llvm.functions.link;
import std.meta, std.traits;

template isCFunction(alias member)
{
    static if (isFunction!(member) &&
               (functionLinkage!(member) == "C" ||
                functionLinkage!(member) == "Windows")) {
        enum isCFunction = true;
    } else {
        enum isCFunction = false;
    }
}

template CFunctions(alias scope_)
{
alias GetSymbol(string member) = AliasSeq!(__traits(getMember, scope_, member)); alias CFunctions = Filter!(isCFunction, staticMap!(GetSymbol, __traits(allMembers, scope_)));
}

mixin template declareStubsImpl(T...)
{
    static if (T.length == 0) {
    } else {
mixin("extern (C) typeof(T[0])* "~__traits(identifier, T[0])~";");
        mixin declareStubsImpl!(T[1..$]);
    }
}

mixin template declareStubs(alias scope_)
{
    mixin declareStubsImpl!(CFunctions!scope_);
}

mixin declareStubs!functions;

After testing this approach out, I couldn't even time it. Why? Because the compiler pretty much immediately hits the (I think fixed) recursive template expansion limit. The LLVM C API has too many functions for this :/

Reply via email to