Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compile prolog code+C code into binary using swi-prolog

I just have a question which I can't find a accurate answer online ..

Using swipl-ld can help to combine Prolog and C code together, and eventually generating one signal executable binary.

But there is one thing I am confused with...

In the generated binary, does the Prolog Interpreter (Virtual Machine or others) still exist?

If so, then probably the original Prolog code is stored as string in the .rodata section of ELF binary, but after a searching inside this section, I didn't find the code.. But perhaps the original code has been transformed into bytecode, and that's why I just can't find it at all..

If not, then how can Prolog code directly translate into semantic equivalent asm code based on SWI-Prolog? I have read some materials about the implementation of GNU-Prolog, based on WAM virtual machine, however, I haven't found any materials about the implementation of SWI-Prolog...

Could anyone give me some help?

like image 978
lllllllllllll Avatar asked Sep 02 '25 15:09

lllllllllllll


1 Answers

The compiled binary does not contain your original source code nor the whole Prolog interpreter. However it does contain your program in form of bytecode compiled by the qsave_program/2 predicate. This bytecode is executed by Prolog emulator, which is a subset of the Prolog interpreter used during a normal interactive dialog, and which is also included in the compiled binary.

All relevant information can be found in the Generating Runtime Applications section of the SWI-Prolog documentation.

like image 117
liori Avatar answered Sep 05 '25 15:09

liori