ANALYSIS OF METAPROGRAMMING CAPABILITIES IN GENERAL-PURPOSE PROGRAMMING LANGUAGES
DOI:
https://doi.org/10.31649/1999-9941-2022-55-3-44-50Keywords:
metaprogramming, code generation, preprocessor directives, macros, Java, Kotlin, C, C , MetaOCaml, Scala, quoting, splicingAbstract
Modern methods of metaprogramming used in general-purpose languages are considered and analyzed. The metaprogramming approach is used for many scenarios of working with program code, but one of them is source code generation. Each programming language includes a unique set of tools for solving metaprogramming tasks. One of the methods of metaprogramming is the construction of annotation processors, however, they do not define the specifics of code generation. Another method is writing compiler plugins, which is possible in programming languages like Kotlin. The plugin interface can provide access to many stages of program compilation, but their disadvantage is the increased complexity of programs, which significantly affects the speed of development and the performance of the resulting software. Technologies such as KotlinPoet and JavaPoet allow generating the text of source programs with partial type safety at the level of statements. The disadvantage of such technologies is the significant difference between the code of the program that performs the generation and the original generated code, which increases the complexity of working with this tool and the overall cognitive load. In contrast to them, it is possible to use strings with an interpolation mechanism that provides declarativeness, but at the cost of type validation. Programming languages such as MetaOCaml and Scala implement mechanisms of metaprogramming and multi-stage programming, in particular, at the syntax level using quoting and splicing constructions and mechanisms of inlining and macros. Macros are also present in the C and C++ languages, they allow preprocessor directives to perform pre-transformation of the code before the main stage of compilation. The correct combination of metaprogramming elements will allow creating a universal approach to the use of a declarative metaprogramming functionality, which will provide a powerful toolkit for scaling the amount of generated code and increase the quality of the final software product.
References
Juárez-Martínez, Ulises and José Oscar Olmedo-Aguirre, Annotation Processing as Local Variable Crosscutting. 2008.
Grégory Lureau, Ktlint: a great 1st experience. 2020. [Online]. Available: https://www.glureau.com/2020/05/26/Ktlint-Moshi-Introduction/. Accessed on: Sept. 4, 2022.
Theodoros Theodoridis, Tobias Grosser, and Zhendong Su. “Understanding and exploiting optimal function inlining,” 27th ACM International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS '22) (2022). Association for Computing Machinery, New York, NY, USA, 977–989.
Medeiros, Flávio M., Márcio Ribeiro, Rohit Gheyi, Sven Apel, Christian Kästner, Bruno Ferreira, Luiz Carvalho and Baldoino Fonseca, “Discipline Matters: Refactoring of Preprocessor Directives in the #ifdef Hell,” IEEE Transactions on Software Engineering, 44 (2018), рр. 453-469.
Oleg Kiselyov, “The Design and Implementation of BER MetaOCaml − System Description,” FLOPS (2014).
Pouya Larjani, “On Meta Programming and Code Generation in F#,” 2010/4/2.
Downloads
-
PDF (Українська)
Downloads: 128