Implementing G-Machine in HyperLMNtal

Jin Sano
DOI: https://doi.org/10.48550/arXiv.2103.14698
2021-03-02
Abstract:Since language processing systems generally allocate/discard memory with complex reference relationships, including circular and indirect references, their implementation is often not trivial. Here, the allocated memory and the references can be abstracted to the labeled vertices and edges of a graph. And there exists a graph rewriting language, a programming language or a calculation model that can handle graph intuitively, safely and efficiently. Therefore, the implementation of a language processing system can be highly expected as an application field of graph rewriting language. To show this, in this research, we implemented G-machine, the virtual machine for lazy evaluation, in hypergraph rewriting language, HyperLMNtal.
Programming Languages
What problem does this paper attempt to address?
The main problem that this paper attempts to solve is the implementation complexity of language processing systems, especially those systems that need to handle complex data structures containing circular references and indirect references. The paper points out that the implementation of these systems is usually not simple because they involve the allocation and release of dynamic memory, and these memory areas and their references can be abstracted as vertices and edges in a graph. Therefore, using programming languages or computing models that can handle graphs intuitively, safely and efficiently, such as graph - rewriting languages, is a very promising application area for the implementation of language processing systems. Specifically, the main contributions of the paper are as follows: 1. **Formalize the syntax and semantics of HyperLMNtal**: HyperLMNtal is extended from the graph - rewriting language/computing model LMNtal. However, HyperLMNtal lacks a strict definition and is more of an implementation - based extension rather than based on a computing model. By introducing the concept of a scope (link creation) and defining the locality of hyperlinks, the paper successfully formalizes the syntax and semantics of HyperLMNtal. This makes HyperLMNtal not only a programming language extended from the basic computing model, but also a concurrent computing model based on strict and formal definitions. 2. **Implement the G - Machine in HyperLMNtal**: The G - Machine is a virtual machine that performs lazy evaluation and is the basis for implementing lazy functional programming languages such as Haskell. The implementation of the G - Machine requires a heap, which is a more general graph than a tree and can share sub - graphs. Therefore, HyperLMNtal is very suitable for implementing the G - Machine. In the research, the author implemented a compiler that compiles the source language (core language) into G - Machine execution code and implemented the G - Machine in HyperLMNtal. The results show that the compiler can be implemented in 404 lines of code, the G - Machine can be implemented in 570 lines of code, and the behavior of the G - Machine can be visualized using HyperLMNtal's visualization tools. Through the above contributions, the paper shows how to use graph - rewriting languages to concisely implement language processing systems that can handle complex data structures and provides new directions for future research.