Translating Prolog to C: a WAM-based approach
暂无分享,去创建一个
A translator from Prolog to C (or C++) can be used as a very e ective tool for performing multiparadigm programming. In [4], we have argued in favour of translation-based multi-paradigm programming. We illustrated how C++ and Prolog could be used advantageously together to build a demonstration compiler. We are now directing our e orts to improving the quality of the translation. Many Prolog systems do allow the use of \foreign" code. For example, SICSTUS Prolog allows C modules to be dynamically loaded and then executed. However the translator based approach o ers certain advantages, including portability plus a greater degree of control of the overall system. The question we wanted to address was this: Is C an appropriate target for Prolog compilation? By appropriate, we mean that the resultant code is competitive in speed and space with the best-known Prolog compilation strategies. Furthermore, because the objective is to use the translated code in larger systems, we certainly require the ability to create separate modules, each containing the C code equivalent of one or more Prolog predicates. Although C is sometimes regarded as a high-level assembler language, its implicit run-time structure is not compatible with e cient implementation of Prolog's backtracking. In this paper, we report on experiments we have conducted on translating Prolog to C using a WAM-based approach[5, 1]. There are a few advantages to using WAM, the main one being that we can bene t from a fairly extensive amount of research that has been done on WAM-based Prolog optimizations, both for storage and execution speed. We will show that it is possible to produce C code whose execution time lies somewhere between byte-code compiled Prolog and native-code compiled Prolog. (Byte-code is something of a misnomer: it refers to the approach that encodes the WAM version of a program in a data array, and then interpretively executes the contents of the array. A native-code compiler translates predicates into the machine instructions of a target computer.)
[1] R. Nigel Horspool,et al. Translator-based multiparadigm programming , 1993, J. Syst. Softw..
[2] Hassan Aït-Kaci. Warren's Abstract Machine , 1991, ICLP.
[3] Joanne L. Boyd,et al. Prolog in ‘C’ , 1990, SIGP.
[4] S. Ramakrishnan,et al. A piggy-back compiler for Prolog , 1988, PLDI '88.
[5] Eric Charles Roy Hehner,et al. Matching program and data representations to a computing environment. , 1974 .