CTFE and -betterC

Xavier Bigand flamaros.xavier at gmail.com
Fri Mar 16 23:15:04 UTC 2018


Le 16/03/2018 à 22:58, Xavier Bigand a écrit :
> Le 15/03/2018 à 01:09, Flamaros a écrit :
>> On Wednesday, 14 March 2018 at 01:17:54 UTC, rikki cattermole wrote:
>>> You will still need DllMain, that is a platform requirement.
>>
>> I am not sure about that because when DllAnalyser don't see it in the opengl32.dll from the system32 directory. And the documentation indicate that it is optional.
>>
>> I finally choose to put the entry points generation in a sub-project that put them in a d file, like that it is easier to make the CTFE working and will be much better for the debugging and compilation time.
>>
>> So I have also some few other questions :
>>  - Is it a bug that ctRegex doesn't with the return of allMembers?
>>  - What is the status of the new CTFE engine?
>>  - Will CTFE be able to write files or expose a way to see to resulting generated code for a debug purpose?
>>  - Is there a reason why CTFE is impacted by the -betterC option?
>>
>
>
> I actually found token strings, but I can't figure out how to cascade them, it is even possible?
> I tried things like that :
>
> enum loadSystemSymbolsCode = q{
> version (Windows)
> {
>     extern (Windows)
>     void loadSytemSymbols()
>     {
>         import core.sys.windows.windows;
>
>         immutable string dllFilePath = "C:/Windows/System32/opengl32.dll";
>
>         auto hModule = LoadLibraryEx(dllFilePath, null, 0);
>         if (hModule == null)
>         {
>             return;
>         }
>         writeln(dllFilePath ~ " loaded.");
>
>         "%SYSTEM_BINDINGS%"
>     }
> }
> };
>
> enum moduleCode = q{
> module api_entry;
>
> import std.stdio : writeln;
> import derelict.util.wintypes;
>
> export extern (C)
> {
>     mixin(loadSystemSymbolsCode);
> }
> };
>
> string getLoadSystemSymbolsCode(string bindinsCode)()
> {
>     return loadSystemSymbolsCode.replace("%SYSTEM_BINDINGS%", bindinsCode);
> }
>
> string getModuleCode(string loadSystemSymbolsCode)()
> {
>     return moduleCode.replace("%LOAD_SYSTEM_SYMBOLS%", loadSystemSymbolsCode);
> }
>
> void    main()
> {
>     import std.stdio : File;
>
>     auto file = File("../opengl32/src/api_entry.d", "w");
>
>     file.writeln(
>         getModuleCode!(
>             getLoadSystemSymbolsCode!("test;")())
>         );
> }
>
> Is there some materials for learning to do this kind of things with CTFE?

I feel my self little stupid, I don't need the " in the token string with the %WordToReplace%. So I think that the magic will happen.



More information about the Digitalmars-d-learn mailing list