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