Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any ways to compile C++ code during runtime?

I have written a complex math library for JavaScript that features the ability to generate functions from strings of human-readable math expressions. Is there a way to achieve an equivalent of runtime-generated functions in C++?

like image 740
Patrick Roberts Avatar asked Mar 12 '23 00:03

Patrick Roberts


1 Answers

FUZxxl's answer is right, and I recommend looking at the Clang/LLVM facility.

There is a basic (not so helpful) tutorial file here. And a broad tutorial on writing your Language on LLVM. You can load your generated library in your C++ App.

Unless, you have a performance critical component, you can employ the use of ChaiScript (NB: I am in no way affiliated to it or the authors)

like image 92
WhiZTiM Avatar answered Mar 20 '23 23:03

WhiZTiM