QT command line + JIT compile
-
wrote on 9 Aug 2022, 20:54 last edited by
Hello,
I am trying to write a command line widget in QT, where inserted codes should be compiled in runtime (something similar to Matlab). Is there any such built-in functionality in QT? I have found C++ JIT compilation libraries which are mainly used for game development and run under debug mode. I am wondering how Matlab for instance compiles C++ in runtime. -
wrote on 10 Aug 2022, 02:04 last edited by
AFAICT Matlab doesn't "compile C++ in runtime". Matlab has an interpreted scripting language that is not C++. Matlab scripts that can interface with custom functions authored in C or C++ (and vice versa).
To implement your own interpreted language will require defining a language grammar and producing a parser that can recognise that and trigger appropriate behaviour in response. Tools like Yacc can help with this. There's nothing in Qt like Yacc.
Qt Script and QJSEngine provide some scriptability to Qt programs.
-
wrote on 10 Aug 2022, 12:12 last edited by
Or, maybe, just ship a g++ with your program and call it with pipes, like what Autoconf and OJ/fiddler do.
-
AFAICT Matlab doesn't "compile C++ in runtime". Matlab has an interpreted scripting language that is not C++. Matlab scripts that can interface with custom functions authored in C or C++ (and vice versa).
To implement your own interpreted language will require defining a language grammar and producing a parser that can recognise that and trigger appropriate behaviour in response. Tools like Yacc can help with this. There's nothing in Qt like Yacc.
Qt Script and QJSEngine provide some scriptability to Qt programs.
wrote on 10 Aug 2022, 20:57 last edited by@ChrisW67 thanks for your answer, I know that Matlab has a scripting language interfacing with core c++ functions, but it also does JIT compilation (I suppose in c++)
https://nl.mathworks.com/products/matlab/matlab-execution-engine.html -
wrote on 11 Aug 2022, 04:21 last edited by
The JIT process is summed up fairly well in What does a just-in-time (JIT) compiler do? and how a JIT process executes code. Once a bit of p-code is executed the JIT compiler can cache the machine instructions to make subsequent executions faster. With intelligence, a JIT compiler can choose not to compile some p-code for which the overhead exceeds to run time.
MATLAB converts its script language code into an internal p-code that is independent of the physical platform on which it runs. This is effectively what the MATLAB parser generates.
The p-code can be executed on a software VM (and remain platform agnostic) or converted on-the-fly (the JIT compiler) into machine instructions for the actual hardware platform.To make your own JIT compiler you either need to invent all these pieces or generate an existing p-code for something like the Java JVM or Microsoft CLR. If your source high level language is C++ then you can probably use LLVM to some of the heavy lifting.
-
@ChrisW67 thanks for your answer, I know that Matlab has a scripting language interfacing with core c++ functions, but it also does JIT compilation (I suppose in c++)
https://nl.mathworks.com/products/matlab/matlab-execution-engine.htmlwrote on 11 Aug 2022, 07:50 last edited by SimonSchroeder 8 Nov 2022, 07:51@mhsgoud said in QT command line + JIT compile:
but it also does JIT compilation (I suppose in c++)
How should it do JIT compilation in C++ if you write MATLAB code and not C++? From the link you provided:
The improved architecture uses just-in-time (JIT) compilation of all MATLAB code [emphasis mine]
1/6