We introduce Grid Programs, a novel model of computation in which programs are finite two-dimensional arrangements of instructions on an integer grid rather than linear sequences of statements. Three properties distinguish this model fundamentally from classical frameworks: (i) programs are planar structures through which an instruction pointer moves in the four cardinal directions; (ii) there are no syntax constraints, so any assignment of instructions to grid cells constitutes a valid program; and (iii) the model uses no named variables or explicit memory addresses. Program state is maintained through a data stack, an address stack, and a circularly doubly linked list accessed via three named pointers. Control flow is achieved spatially, with branching encoded as perpendicular turns of the instruction pointer. The address stack stores triplets (cell row, cell column, direction), enabling precise restoration of both position and heading after branches, loops, and function calls. We give a formal operational semantics, present a representative instruction set covering arithmetic, control flow, and linked-list manipulation, and work through several detailed examples, including an absolute-value function, a factorial computation, a linear-search algorithm, a string-reversal program, and a while-loop summation. We establish that Grid Programs are Turing-complete by simulating an arbitrary register machine, and we discuss their relationship to prior two-dimensional languages such as Befunge and Funge-98, to stack-based languages such as Forth and PostScript, and to dataflow and spatial computation models. Grid Programs offer a fresh vantage point for exploring the design space of computation, with potential applications in visual programming environments, cellular-automaton-inspired hardware, and obfuscation-resistant code.
翻译:我们提出网格程序(Grid Programs),这是一种新颖的计算模型,其中程序是整数网格上指令的二维排列,而非语句的线性序列。三个特性使其根本区别于经典框架:(i) 程序是平面结构,指令指针沿四个基本方向在其中移动;(ii) 无语法约束,因此任何对网格单元的指令赋值均构成有效程序;(iii) 该模型不使用命名变量或显式内存地址。程序状态通过数据栈、地址栈以及通过三个命名指针访问的循环双向链表来维护。控制流以空间方式实现,分支编码为指令指针的垂直转向。地址栈存储三元组(单元格行、单元格列、方向),从而能够在分支、循环和函数调用后精确恢复位置和朝向。我们给出了形式化操作语义,展示了涵盖算术、控制流和链表操作的典型指令集,并通过多个详细示例(包括绝对值函数、阶乘计算、线性搜索算法、字符串反转程序以及while循环求和)加以说明。我们通过模拟任意寄存器机证明了网格程序的图灵完备性,并讨论了其与先前二维语言(如Befunge和Funge-98)、基于栈的语言(如Forth和PostScript)以及数据流和空间计算模型的关系。网格程序为探索计算设计空间提供了全新视角,在可视化编程环境、受细胞自动机启发的硬件以及抗混淆代码中具有潜在应用。