Is it possible to use DMD as a library to compile strings at runtime?

Basile B. b2.temp at gmx.com
Mon Feb 10 12:31:03 UTC 2020


On Friday, 31 January 2020 at 14:25:30 UTC, Basile B. wrote:
> On Friday, 31 January 2020 at 11:19:37 UTC, Saurabh Das wrote:
>> I see that DUB has DMD as a library package, but I was not 
>> able to understand how to use it.
>>
>> Is it possible to use DMD as a library within a D program to 
>> compile a string to machine code and run the compiled code at 
>> runtime?
>>
>> Thanks,
>> Saurabh
>
> Fundamentally DMD as a library is a front-end. Jitting is to 
> the backend side.
> You'll be able to lex and parse the source to get an AST, to 
> perform the semantic passes on this AST and that's all.
>
> Then to run this code you would need to make an AST visitor 
> that will generate the binary code to execute. Even using a 
> specialized library with jitting abilities, such as LLVM-d [1] 
> or libfirm-d [2], this would be *quite* a journey.
>
> [1] https://github.com/MoritzMaxeiner/llvm-d
> [2] https://gitlab.com/basile.b/libfirm-d

about [1] (llvm) I've made a better binding this weekend:

https://gitlab.com/basile.b/llvmd-d

Seriouly I cant believe that at some point in the past I 
translated by hand. dstep can handle big C libraries.


More information about the Digitalmars-d-learn mailing list