On 05/01/15 22:29, Jens Bauer via Digitalmars-d-learn wrote: > 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.
My fault; I only looked at the generated code, but never actually tested it. Use `@weakalias!"blah"` instead: enum weakalias(string A) = gcc.attribute.attribute("alias", A); @weakalias!"defaultResetHandler" extern (C) void Reset_Handler(); > 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 ? No, but you can just do: code ~= "\n@isr_vector VectorFunc[" ~ A.tupleof.length.stringof ~ "] g_pfnVectors = [\n"; > 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. ;) (Ab)using the compiler for the DSL parsing gets really awesome once you use other D features like multiple named member initializers, lambdas and/or static-ifs etc /inside/ the DSL. Next thing you know you'll be using DSLs that generate other DSLs that emit plain D code, with a few layers of expression templates in between... :) artur