Modeling of functional language interpreter with metaprogramming
https://doi.org/10.21869/2223-1536-2024-14-2-181-193
Abstract
The purpose of the research consists of modeling an interpreter for a functional programming language with metaprogramming capabilities and analyzing ways to implement primitive operators based on macros.
Methods. A formal model of a functional language interpreter, which is a subset of Common Lisp, was developed with denotational semantics, which allows you to accurately describe the behavior of the interpreter when calculating language elements such as quoting, accessing variables, sequence of actions, branching, assignment, abstraction, application.
Results. Based on denotational semantics, the architecture of a functional language interpreter with metaprogramming capabilities was developed. Numbers, symbols, pairs, strings and arrays were chosen as the basic types of objects. To store objects, a tag architecture was used, where the low-order bits of the object address are always zero, so they can store the object type code and the tag bit. Objects are allocated and freed automatically: a mark and cleanup algorithm is used for garbage collection. Using macros, branching operators, complete and incomplete, selection operator, and block operators of related variables were implemented.
Conclusion. As a result of the work, a functional language interpreter with metaprogramming capabilities was implemented. Using macros, primitive operators of condition, selection, and a block of related variables were implemented. Using these operators as an example, it is shown that using metaprogramming, only basic forms and primitives can be built into the interpreter, and the other operators can be implemented using metaprogramming, which makes it possible to simplify and reduce the amount of interpreter code.
About the Author
A. A. ChaplyginRussian Federation
Aleksandr A. Chaplygin, Candidate of Sciences (Engeneering), Associate Professor of the Department of Software Engeneering
50 Let Oktyabrya Str. 94, Kursk 305040, Russian Federation
References
1. Seibel P. Practical use of Common Lisp. Moscow: DMK Press; 2017. 488 p. (In Russ.)
2. Dushkin R.V. Functional programming in Haskell. Moscow: DMK Press; 2016. 608 p. (In Russ.)
3. Uzkikh G.Y. Functional programming and its impact on code quality and maintainability. Vestnik nauki = Bulletin of Science. 2023;4(8):316–318. (In Russ.) EDN TQONQF
4. Telegin V.A. The influence of functional programming on modern programming languages. Innovatsii i investitsii = Innovations and Investments. 2023;(7):189–192. (In Russ.) EDN VQEXEK
5. Gorodnyaya L.V. Prospects for functional programming of parallel computing. Elektronnye biblioteki = Electronic Libraries. 2021;24(6):1090–1116. (In Russ.) https://doi.org/10.26907/1562-5419-2021-24-6-1090-1116. EDN LOGTRU
6. Bilukha I.N. Relevance of functional programming. Student Bulletin. 2020;(5-4):60–61. (In Russ.) EDN VTDJGN
7. Krasnov M.M., Feodoritova O.B. Using the functional programming library for solving numerical problems on graphics accelerators with CUDA technology. Proceedings of the Institute for System Programming of the RAS. 2021;33(5):167–180. https://doi.org/10.15514/ISPRAS-2021-33(5)-10. EDN WXDIFI
8. Domkin V. Programming Algorithms in Lisp. Berkeley: Apress; 2021. 377 p.
9. Graham P. ANSI Common LISP. Moscow: Symvol-Plus; 2020. 448 p. (In Russ.)
10. Malov A.V., Rodionov S.V. Implementation of the simplified Bayes algorithm in the COMMON LISP functional programming environment. Proceedings of Saint Petersburg Electrotechnical University = Proceedings of St. Petersburg Electrotechnical University "LETI". 2015;(2):32–37. (In Russ.) EDN TKJVLJ
11. Vtornikov A. Lisp: a little giant. Sistemnyi administrator = System Administrator. 2016;(6):64–69. (In Russ.) EDN VZGXVD
12. Nystrom R. Crafting interpreters. Moscow: Nobel Press; 2024. 640 p.
13. Ullman Jeffrey D., Ravi Networks. Compilers: principles, technologies and tools. Moscow: Dialectics-Williams; 2018. 1184 p. (In Russ.)
14. Khalilov E.R. Development of an interpreter for a video game programming language. Informatsionno-komp'yuternye tekhnologii v ekonomike, obrazovanii i sotsial'noi sfere = Information and Computer Technologies in Economics, Education and Social Sphere. 2020;(1):79–89. (In Russ.) EDN KNIRUT
15. Abelson H., Sussman D. Structure and interpretation of computer programs. Moscow: KDU; 2022. 608 p. (In Russ.)
16. Grigoriev E.A., Klimov N.S. Using Ahead-Of-Time compilation in the .NET platform as an alternative to Just-In-Time compilation. E-Scio. 2019;11:364–371. (In Russ.) EDN EOMDHH
17. Kharin I.A., Raskatova M.V. Analysis of algorithms for compiler components and its optimization. Computational Nanotechnology. 2023;10(2):26–35. (In Russ.) https://doi.org/10.33693/2313-223X-2023-10-2-26-35. EDN BDGKMA
18. Steinberg B.Y., Steinberg O.B. Program transformations are the fundamental basis for creating optimizing parallelizing compilers. Programmnye sistemy: teoriya i prilozheniya = Software Systems: Theory and Applications. 2021;12(1):21–113. (In Russ.) https://doi.org/10.25209/2079-3316-2021-12-1-21-113. EDN FZFEPX
19. Chaplygin A.A. Using metaprogramming tools of the Common Lisp language to develop emulator systems. Izvestiya Yugo-Zapadnogo gosudarstvennogo universiteta. Seriya: Upravlenie, vy-chislitel'naya tekhnika, informatika. Meditsinskoe priborostroenie = Proceedings of the Southwest State University. Series: Control, Computer Engineering, Information Science. Medical Instruments Engineering. 2023;13(3):135–145. (In Russ.)
20. Krishnamurthi Sh. Programming Languages: Application and Interpretation. Providence: Brown University; 2022. 376 p.
Review
For citations:
Chaplygin A.A. Modeling of functional language interpreter with metaprogramming. Proceedings of the Southwest State University. Series: IT Management, Computer Science, Computer Engineering. Medical Equipment Engineering. 2024;14(2):181-193. (In Russ.) https://doi.org/10.21869/2223-1536-2024-14-2-181-193