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

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Feb 1 20:37:03 UTC 2020


On Sat, Feb 01, 2020 at 08:01:34PM +0000, Andre Pany via Digitalmars-d-learn wrote:
[...]
> Another approach:
> - include the dmd compiler package with your application
> - within your app call the compiler executable and compile the source
> code to a dll / so
> - call the dll / so function
[...]

I've actually done this before in an equation grapher program: the user
inputs an equation, the program generates D code to compute the
equation, then runs dmd to compile it into a shared library, and opens
the shared library and looks up the symbol to execute the compiled code.
Dmd is fast enough that this actually works fairly well. When the input
to dmd is small, it's so fast you don't even notice it.


T

-- 
An imaginary friend squared is a real enemy.


More information about the Digitalmars-d-learn mailing list