Abstract
A unified language architecture for an advanced reversible object-oriented language is described. The design and implementation choices made for a tree-walking interpreter and source-language inverter are discussed, as well as the integration with an existing monadic parser, type checker and PISA compiler backend. A demonstration of the web interface and the interactions required to interpret, compile and invert reversible object-oriented programs is given. Our aim is that this platform will make reversible programming approachable to a wider community.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Source code host: https://github.com/haysch/ROOPLPP.
- 2.
Web interface: https://topps.di.ku.dk/pirc/roopl-playground.
- 3.
Source code [3, 10] rehosted at: https://github.com/TueHaulund/PendVM.
- 4.
References
Cservenka, M.H.: Design and implementation of dynamic memory management in a reversible OO programming lang. Master’s thesis, University of Copenhagen (2018)
Cservenka, M.H., Glück, R., Haulund, T., Mogensen, T.Æ.: Data structures and dynamic memory management in reversible languages. In: Kari, J., Ulidowski, I. (eds.) RC 2018. LNCS, vol. 11106, pp. 269–285. Springer, Cham (2018). https://doi.org/10.1007/978-3-319-99498-7_19
Frank, M.P.: Reversibility for efficient computing. Ph.D. thesis, MIT (1999)
Glück, R., Yokoyama, T.: A linear-time self-interpreter of a reversible imperative language. Comput. Softw. 33(3), 108–128 (2016)
Haulund, T.: Design and implementation of a reversible object-oriented programming language. Master’s thesis, University of Copenhagen (2016)
Haulund, T., Mogensen, T.Æ., Glück, R.: Implementing reversible object-oriented language features on reversible machines. In: Phillips, I., Rahaman, H. (eds.) RC 2017. LNCS, vol. 10301, pp. 66–73. Springer, Cham (2017). https://doi.org/10.1007/978-3-319-59936-6_5
Mezzina, C.A., et al.: Software and reversible systems: a survey of recent activities. In: Ulidowski, I., Lanese, I., Schultz, U.P., Ferreira, C. (eds.) RC 2020. LNCS, vol. 12070, pp. 41–59. Springer, Cham (2020). https://doi.org/10.1007/978-3-030-47361-7_2
Schultz, U.P., Axelsen, H.B.: Elements of a reversible object-oriented language. In: Devitt, S., Lanese, I. (eds.) RC 2016. LNCS, vol. 9720, pp. 153–159. Springer, Cham (2016). https://doi.org/10.1007/978-3-319-40578-0_10
Thomsen, M.K., Axelsen, H.B., Glück, R.: A reversible processor architecture and its reversible logic design. In: De. Vos, A., Wille, R. (eds.) RC 2011. LNCS, vol. 7165, pp. 30–42. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-29517-1_3
Vieri, C.J.: Rev. computer engineering and architecture. Ph.D. thesis, MIT (1999)
Yokoyama, T., Axelsen, H.B., Glück, R.: Towards a reversible functional language. In: De. Vos, A., Wille, R. (eds.) RC 2011. LNCS, vol. 7165, pp. 14–29. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-29517-1_2
Yokoyama, T., Glück, R.: A reversible programming language and its invertible self-interpreter. In: PEPM Proceedings, pp. 144–153. ACM (2007)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
A Binary Search Tree Example
A Binary Search Tree Example
The ROOPL example program in this appendix is provided for the interested reader. It is based on a binary search tree example [2] and accessible in the Examples tab of the web interface as Binary Tree using Array. A binary search tree allows fast look up of data items given a node value (the key). The example constructs a binary search tree by inserting new nodes while preserving the invariant that all node values in a node’s left subtree are smaller and those in the node’s right subtree are not smaller than the node’s value. In our example, the node values are stored in an array and then iteratively inserted into the tree. Given the node values 3, 4, 2, 1, the resulting tree can be seen in Fig. 3.
1.1 A.1 Example Program
Appendix A.2 contains the complete source code for the example program. The class Program defines the main method of our program (lines 40–63). The method main is the program’s entry point and creates a new binary search tree. A new object of class Tree is created by statement new Tree tree, which sets variable tree to the new object’s reference (line 46). Similarly, a new array nodeVals is created and initialized with our four example values (lines 47–52).
The iteration over the example array is performed by a reversible loop (lines 54–62). It asserts that the initial value of index variable x is 0 and its final value is nodeCount. The control-flow operators in ROOPL are those of Janus; e.g. see [12]. The paired statements local and delocal open and close the scope of a variable by specifying its initial and final value, e.g. x has the initial value 0 (line 53). All method calls and uncalls refer to an object, e.g. call node::setValue(nodeVals[x]) sends method setValue to object node with a parameter being the value of an element in array nodeVals (line 58).
Class Node defines a labeled node as containing an integer value and links to the roots of its left and right subtree (lines 2–4). Usually, this class also defines the variables for the data items stored in a node. If there is no subtree then the corresponding link is nil. The class defines two methods: setValue reversibly updates the label of a node and insertNode recursively inserts a new node with a value newValue. The latter performs a recursive descent over the left or right subtree depending on the node value to be inserted.
A reversible conditional has two predicates that are evaluated at run time: an entry test at if (e.g., nodeValue< value at line 10) and an exit assertion at fi (e.g., left != nil at line 17). After executing the then-branch, the assertion must evaluate to true, and after executing the else-branch, it must evaluate to false; otherwise, an error occurs and an exception is raised.
Finally, class Tree defines the root of a binary search tree and provides a method for inserting nodes into the search tree. More variables can be added to this class, e.g. the number of nodes in a tree. Which of the two insert methods defined in the classes Node and Tree is invoked depends on the class of the object to which it is sent (e.g. root::insertNode(...) vs. tree::insertNode(...)).
1.2 A.2 Source Code
Rights and permissions
Copyright information
© 2021 Springer Nature Switzerland AG
About this paper
Cite this paper
Hay-Schmidt, L., Glück, R., Cservenka, M.H., Haulund, T. (2021). Towards a Unified Language Architecture for Reversible Object-Oriented Programming. In: Yamashita, S., Yokoyama, T. (eds) Reversible Computation. RC 2021. Lecture Notes in Computer Science(), vol 12805. Springer, Cham. https://doi.org/10.1007/978-3-030-79837-6_6
Download citation
DOI: https://doi.org/10.1007/978-3-030-79837-6_6
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-79836-9
Online ISBN: 978-3-030-79837-6
eBook Packages: Computer ScienceComputer Science (R0)