On Wednesday, 29 April 2015 at 13:58:14 UTC, Artur Skawina wrote:
On 04/27/15 19:49, Jens Bauer via Digitalmars-d-learn wrote:
I was wondering if there's a way to reduce my bulky startup files a bit.
{snip}

Just create a helper module, which the startup files can all
use to generate the data from a dsl. Eg
{snip}

I've experimented a little with the code, but ran into two minor problems.

code ~= `@weakalias("`~M.n~`") extern (C) void ` ~ __traits(identifier, A.tupleof[I]) ~ "();\n";

The above part gives me some problems; I do not know how to create the @weakalias. I can make a @exc (which defaults to defaultExceptionVector) and @rst (which defaults to defaultResetHandler), but I have not yet succeeded in making a universal @weakalias.

alias Tuple(A...) = A;
alias rst = Tuple!(weak, gcc.attribute.attribute("alias", "defaultResetHandler")); alias exc = Tuple!(weak, gcc.attribute.attribute("alias", "defaultExceptionHandler"));

... I tried messing with changing the above code, but no luck so far:

code ~= `@weak @gcc.attribute.attribute("alias", "`~M.n~`") extern (C) void ` ~ __traits(identifier, A.tupleof[I]) ~ "();\n";


If I modify the above to ...
        foreach (I, M; A.init.tupleof)
        {
                static if (is(typeof(M)==A.RST))
code ~= `@rst extern (C) void ` ~ __traits(identifier, A.tupleof[I]) ~ "();\n";
                static if (is(typeof(M)==A.EXC))
code ~= `@exc extern (C) void ` ~ __traits(identifier, A.tupleof[I]) ~ "();\n";
        }
... then it will build and produce the expected results. That requires replacing the EXC for the ResetHandler by RST, I like the original code much better, though. :)


I also had some trouble with the exception vectors not being generated, and it turned out that my array was dynamic instead of static.

For now, I've just made the array a constant size (100 elements); eg. changed ...
    code ~= "\n@isr_vector VectorFunc[] g_pfnVectors = [\n";
... to ...
    code ~= "\n@isr_vector VectorFunc[100] g_pfnVectors = [\n";
... Is it possible to generate a static array without specifying a fixed array size ?

Apart from the above two mentioned problems, the code builds and produces the expected results. I even started to understand some parts of it, and I find it pretty awesome. ;)

Reply via email to