Jump to page: 1 2 3
Thread overview
DMD as a library package can now run through all semantic phases
Jan 26, 2018
Seb
Jan 27, 2018
timotheecour
Jan 27, 2018
Seb
Jan 27, 2018
timotheecour
Jan 27, 2018
timotheecour
Jan 27, 2018
Jacob Carlborg
Jan 27, 2018
timotheecour
Jan 27, 2018
Seb
Jan 27, 2018
timotheecour
Jan 27, 2018
rikki cattermole
Jan 29, 2018
rikki cattermole
Jan 29, 2018
Jacob Carlborg
Jan 30, 2018
rikki cattermole
Jan 27, 2018
Johan Engelen
Jan 30, 2018
Amorphorious
Jan 30, 2018
Bastiaan Veelo
Jan 30, 2018
H. S. Teoh
Jan 30, 2018
EntangledQuanta
Jan 30, 2018
rikki cattermole
Jan 30, 2018
Amorphorious
Jan 30, 2018
rikki cattermole
Jan 30, 2018
H. S. Teoh
Jan 30, 2018
Seb
January 26, 2018
In case someone wants to play with DMD as a library, it got a lot easier as of today.
Here's an example:

```
#!/usr/bin/env dub
/+dub.sdl:
dependency "dmd" version="~master"
+/
void main()
{
    import dmd.frontend;
    import std.algorithm : each;
    import std.stdio;

    // Sets DMD's global variables. Only required to be called once
    // In the future this might be done automatically (e.g. module constructor or initOnce)
    initDMD;

    // Search for the predefined import paths of your host compiler (DMD and LDC are supported)
    findImportPaths.each!addImport;

    // Load a module
    // (if no second argument is given, the file will be opened and read)
    auto m = parseModule("test.d", q{
        void foo()
        {
            foreach (i; 0..10) {}
        }
    });

    // Run through all semantic phases
    m.fullSemantic;
    m.prettyPrint.writeln;
}
```


Want to know what it prints? Run the file!
Spoiler: it's similar to new the AST feature at run.dlang.io:

https://run.dlang.io/is/mwU67O

__Warning__: the DMD DUB package is still experimental and at the moment should only be used by alpha warriors.

See also:

https://dlang.org/phobos-prerelease/dmd_frontend.html (will work soon)
https://dlang.org/library-prerelease/dmd/frontend.html (Ddox documentation, works already)

Huge thanks and credits goes to Jacob Carlborg and Razvan Nitu as well.
January 27, 2018
On Friday, 26 January 2018 at 18:40:23 UTC, Seb wrote:
> In case someone wants to play with DMD as a library, it got a lot easier as of today.
> Here's an example:
>
> ```
> #!/usr/bin/env dub
> /+dub.sdl:
> dependency "dmd" version="~master"
> +/
> void main()
> {
>     import dmd.frontend;
>     import std.algorithm : each;
>     import std.stdio;
>
>     // Sets DMD's global variables. Only required to be called once
>     // In the future this might be done automatically (e.g. module constructor or initOnce)
>     initDMD;
>
>     // Search for the predefined import paths of your host compiler (DMD and LDC are supported)
>     findImportPaths.each!addImport;
>
>     // Load a module
>     // (if no second argument is given, the file will be opened and read)
>     auto m = parseModule("test.d", q{
>         void foo()
>         {
>             foreach (i; 0..10) {}
>         }
>     });
>
>     // Run through all semantic phases
>     m.fullSemantic;
>     m.prettyPrint.writeln;
> }
> ```
>
>
> Want to know what it prints? Run the file!
> Spoiler: it's similar to new the AST feature at run.dlang.io:
>
> https://run.dlang.io/is/mwU67O
>
> __Warning__: the DMD DUB package is still experimental and at the moment should only be used by alpha warriors.
>
> See also:
>
> https://dlang.org/phobos-prerelease/dmd_frontend.html (will work soon)
> https://dlang.org/library-prerelease/dmd/frontend.html (Ddox documentation, works already)
>
> Huge thanks and credits goes to Jacob Carlborg and Razvan Nitu as well.

on OSX:
chmod u+x main.d
./main.d

WARNING: A deprecated branch based version specification is used for the dependency dmd. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
Invalid source/import path: /Users/timothee/.dub/packages/dmd-master/dmd/generated/dub
core.exception.AssertError@../../../../../.dub/packages/dmd-master/dmd/src/dmd/frontend.d(208): No valid config found.

January 27, 2018
On Saturday, 27 January 2018 at 00:47:01 UTC, timotheecour wrote:
> on OSX:
> chmod u+x main.d
> ./main.d
>
> WARNING: A deprecated branch based version specification is used for the dependency dmd. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.

That's expected, but well DMD doesn't use semantic versioning yet, so ~master is the only valid version out there.

> Invalid source/import path: /Users/timothee/.dub/packages/dmd-master/dmd/generated/dub
> core.exception.AssertError@../../../../../.dub/packages/dmd-master/dmd/src/dmd/frontend.d(208): No valid config found.

That's not expected (and before OSX went crazy on Travis there where tests for this).

What's your default compiler? How did you install it?

If it's dmd, then DMD's default detection is called: https://github.com/dlang/dmd/blob/master/src/dmd/frontend.d#L82
January 27, 2018
On Saturday, 27 January 2018 at 00:47:01 UTC, timotheecour wrote:
> on OSX:
> chmod u+x main.d
> ./main.d
>
> WARNING: A deprecated branch based version specification is used for the dependency dmd. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
> Invalid source/import path: /Users/timothee/.dub/packages/dmd-master/dmd/generated/dub
> core.exception.AssertError@../../../../../.dub/packages/dmd-master/dmd/src/dmd/frontend.d(208): No valid config found.

the bug is that homebrew dmd installs dmd.conf in /Users/timothee/homebrew/etc/dmd.conf; findDMDConfig should instead look for dmd.conf by calling `dmd -v|grep 'Config file'` (and caching result for each file+time_last_modified) which would be more robust

workaround: hardcode /Users/timothee/homebrew/etc/dmd.conf in findDMDConfig in dmd:src/dmd/frontend.d
January 27, 2018
On Friday, 26 January 2018 at 18:40:23 UTC, Seb wrote:
> Want to know what it prints? Run the file!
> Spoiler: it's similar to new the AST feature at run.dlang.io:


prettyPrint produces valid D code except for template instantiations:
```
writeln!int
 {
     @safe void writeln(int _param_0)
     {
         import std.traits : isAggregateType;
         ((File __tmpfordtor37 = trustedStdout();) , __tmpfordtor37).write(_param_0, '\x0a');
     }

 }
```

why not write something like:
```
template writeln(T:int)
{
...
}
```
or template writeln(T) if(is(T==int))
January 27, 2018
On Saturday, 27 January 2018 at 01:25:18 UTC, timotheecour wrote:
> On Friday, 26 January 2018 at 18:40:23 UTC, Seb wrote:
>> Want to know what it prints? Run the file!
>> Spoiler: it's similar to new the AST feature at run.dlang.io:
>
>
> prettyPrint produces valid D code except for template instantiations:
> ```
> writeln!int
>  {
>      @safe void writeln(int _param_0)
>      {
>          import std.traits : isAggregateType;
>          ((File __tmpfordtor37 = trustedStdout();) , __tmpfordtor37).write(_param_0, '\x0a');
>      }
>
>  }
> ```
>
> why not write something like:
> ```
> template writeln(T:int)
> {
> ...
> }
> ```
> or template writeln(T) if(is(T==int))


Agreed, but prettyPrint:

https://github.com/dlang/dmd/blob/master/src/dmd/frontend.d#L275

is just a nice wrapper around the existing PrettyPrintVisitor:


https://github.com/dlang/dmd/blob/master/src/dmd/hdrgen.d#L84
January 27, 2018
On Saturday, 27 January 2018 at 01:10:35 UTC, timotheecour wrote:
> On Saturday, 27 January 2018 at 00:47:01 UTC, timotheecour

> the bug is that homebrew dmd installs dmd.conf in /Users/timothee/homebrew/etc/dmd.conf; findDMDConfig should instead look for dmd.conf by calling `dmd -v|grep 'Config file'` (and caching result for each file+time_last_modified) which would be more robust
>
> workaround: hardcode /Users/timothee/homebrew/etc/dmd.conf in findDMDConfig in dmd:src/dmd/frontend.d


Actually an even more robust way to get the conf file:
call dmd -Xf=tempfile and get it from json output
doable once https://github.com/dlang/dmd/pull/7757  is accepted

January 27, 2018
On Saturday, 27 January 2018 at 01:36:17 UTC, Seb wrote:
> On Saturday, 27 January 2018 at 01:25:18 UTC, timotheecour Agreed, but prettyPrint:
>
> https://github.com/dlang/dmd/blob/master/src/dmd/frontend.d#L275
>
> is just a nice wrapper around the existing PrettyPrintVisitor:
>
>
> https://github.com/dlang/dmd/blob/master/src/dmd/hdrgen.d#L84

filed https://issues.dlang.org/show_bug.cgi?id=18311
January 27, 2018
On 26/01/2018 6:40 PM, Seb wrote:
> In case someone wants to play with DMD as a library, it got a lot easier as of today.
> Here's an example:
> 
> ```
> #!/usr/bin/env dub
> /+dub.sdl:
> dependency "dmd" version="~master"
> +/
> void main()
> {
>      import dmd.frontend;
>      import std.algorithm : each;
>      import std.stdio;
> 
>      // Sets DMD's global variables. Only required to be called once
>      // In the future this might be done automatically (e.g. module constructor or initOnce)
>      initDMD;
> 
>      // Search for the predefined import paths of your host compiler (DMD and LDC are supported)
>      findImportPaths.each!addImport;
> 
>      // Load a module
>      // (if no second argument is given, the file will be opened and read)
>      auto m = parseModule("test.d", q{
>          void foo()
>          {
>              foreach (i; 0..10) {}
>          }
>      });
> 
>      // Run through all semantic phases
>      m.fullSemantic;
>      m.prettyPrint.writeln;
> }
> ```
> 
> 
> Want to know what it prints? Run the file!
> Spoiler: it's similar to new the AST feature at run.dlang.io:
> 
> https://run.dlang.io/is/mwU67O
> 
> __Warning__: the DMD DUB package is still experimental and at the moment should only be used by alpha warriors.
> 
> See also:
> 
> https://dlang.org/phobos-prerelease/dmd_frontend.html (will work soon)
> https://dlang.org/library-prerelease/dmd/frontend.html (Ddox documentation, works already)
> 
> Huge thanks and credits goes to Jacob Carlborg and Razvan Nitu as well.

Is it possible to reset the compiler to the point of uninitialized/newly initialized?

For reuse in a single process.
January 27, 2018
On Friday, 26 January 2018 at 18:40:23 UTC, Seb wrote:
> In case someone wants to play with DMD as a library, it got a lot easier as of today.

Very cool.

*cough* fuzz target *ahem* *cough* continuous fuzzing *cough* .

;)
  Johan


« First   ‹ Prev
1 2 3