arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 1906.03970cs.PL
收藏

一种将C库函数动态集成到$λ$ Prolog实现中的方案

A scheme for dynamically integrating C library functions into a $λ$Prolog implementation

Duanyang Jing

摘要:

Teyjus系统通过将程序编译成用于抽象机器的字节码并使用用于机器的模拟器执行该翻译形式来实现高阶逻辑程序设计语言$λ$ Prolog。Teyjus支持许多通过C代码实现的内置关系。在目前的计划中,这些关系是通过包括C程序,实现它们的模拟器和定制的编译器产生的指令调用这样的代码。这种方法有两个缺点。首先,整个库函数集合必须包含在系统中,从而导致比必要的内存占用更大。其次,增强内置谓词的集合需要改变模拟器和编译器的部分,完成这项任务需要这两个子系统的特定知识。该项目分三步解决这些问题。首先,内置函数的代码从模拟器移动到库中,在加载时,由字节码文件中的信息确定的相关部分从库链接到运行时系统。第二,将每个库函数的信息与如何从$λ$ Prolog程序中调用它以及在哪里可以找到它的C代码相关联。最后,修改编译器以使用前面的信息在字节码文件中包含相关的链接指令,并将对内建关系的调用转换为调用动态链接代码的特殊指令。更一般地说,这些想法是能够支持接口在$λ$ Prolog中的“外来功能”在C中实现,也讨论了可能性。

英文摘要:

The Teyjus system realizes the higher-order logic programming language$λ$Prolog by compiling programs into bytecode for an abstract machine and executing this translated form using a simulator for the machine. Teyjus supports a number of builtin relations that are realized through C code. In the current scheme, these relations are realized by including the C programs that implement them within the simulator and tailoring the compiler to produce instructions to invoke such code. There are two drawbacks to such an approach. First, the entire collection of library functions must be included within the system, thereby leading to a larger than necessary memory footprint. Second, enhancing the collection of built-in predicates requires changing parts of the simulator and compiler, a task whose accomplishment requires specific knowledge of these two subsystems. This project addresses these problems in three steps. First, the code for the builtin functions is moved from the simulator into a library from where relevant parts, determined by information in the bytecode file, are linked into the runtime system at load time. Second, information is associated with each library function about how it can be invoked from a $λ$Prolog program and where the C code for it is to be found. Finally, the compiler is modified to use the preceding information to include relevant linking instructions in the bytecode file and to translate invocations to builtin relations into a special instruction that calls the dynamically linked code. More generally, these ideas are capable of supporting an interface in $λ$Prolog to "foreign functions" implemented in C, a possibility that is also discussed.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑