arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1104.2293cs.PL
收藏

带有数据流约束的反应式命令式编程

Reactive Imperative Programming with Dataflow Constraints

Camil Demetrescu, Irene Finocchi, Andrea Ribichini

摘要:

数据流语言为动态应用程序中指定对象之间的约束提供了自然支持,其中程序需要有效地对环境的变化做出反应。研究人员长期以来一直在研究如何通过将它们嵌入到过程语言中来利用Challow-constraints。然而,以前的混合命令式/并行系统需要语法扩展或专门的数据类型库来将命令式程序绑定到并行求解器。在本文中,我们提出了一种新的方法,顺利地结合了这两种范式,而不会给程序员带来不必要的负担。在我们的框架中,程序员可以定义主机命令式语言的普通命令,这些命令强制执行存储在“反应式”内存位置中的对象之间的约束。反应对象可以是宿主语言中的任何合法类型,包括基本数据类型、指针、数组和结构。约束在每次输入内存位置改变时自动重新执行,让程序表现得像电子表格,其中某些变量的值取决于其他变量的值。通过改变宿主语言的基本操作的语义来读取和修改对象,从而透明地处理约束求解机制。我们提供了一个正式的语义和描述我们的技术到C/C++的一个具体实施例,展示了如何有效地实现它在传统的平台上使用现成的编译器。我们讨论了相关的应用反应的情况下,包括增量计算,观察者设计模式,和数据结构修复。我们的实现的性能相比,特设问题特定的变化传播算法和以语言为中心的方法,如自调整计算和主体/观察者通信机制,表明所提出的方法是有效的,在实践中。

英文摘要:

Dataflow languages provide natural support for specifying constraints between objects in dynamic applications, where programs need to react efficiently to changes of their environment. Researchers have long investigated how to take advantage of dataflow constraints by embedding them into procedural languages. Previous mixed imperative/dataflow systems, however, require syntactic extensions or libraries of ad hoc data types for binding the imperative program to the dataflow solver. In this paper we propose a novel approach that smoothly combines the two paradigms without placing undue burden on the programmer. In our framework, programmers can define ordinary commands of the host imperative language that enforce constraints between objects stored in "reactive" memory locations. Reactive objects can be of any legal type in the host language, including primitive data types, pointers, arrays, and structures. Constraints are automatically re-executed every time their input memory locations change, letting a program behave like a spreadsheet where the values of some variables depend upon the values of other variables. The constraint solving mechanism is handled transparently by altering the semantics of elementary operations of the host language for reading and modifying objects. We provide a formal semantics and describe a concrete embodiment of our technique into C/C++, showing how to implement it efficiently in conventional platforms using off-the-shelf compilers. We discuss relevant applications to reactive scenarios, including incremental computation, observer design pattern, and data structure repair. The performance of our implementation is compared to ad hoc problem-specific change propagation algorithms and to language-centric approaches such as self-adjusting computation and subject/observer communication mechanisms, showing that the proposed approach is efficient in practice.

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

↑