The purpose of research is to analyze and use metaprogramming in the Common Lisp language when designing and implementing emulators that simulate computer system hardware. The metaprogramming, the macro tools of the Common Lisp language and the use of macros for metaprogramming are considered.Methods. The Lisp language is characterized by its use of uniform S-expressions to represent data and programs. Thus, data can be part of a program and vice versa: a program can be data. Common Lisp macro tools allow you to directly modify the abstract syntax tree of a program, and thus it is possible to create new syntactic constructs to solve a given problem. When implementing emulator functions, macro tools of the Common Lisp language can be used to generate functions, where the common part of the functions is included in the macro, and the differences between the functions are specified in the parameters when calling the macros. Examples of this macros are: bit status register macros, generation of ariphmetic commands, comparation commands, memory commands. Using that you can significantly reduce the size of the program.Results. As a result of computer modeling, a simulator of the NES architecture (MOS 6502 processor) was developed and implemented in the conventional object-orientied C# programming language and in the Common Lisp metaprogramming language. As a result, the simulator written in a language with metaprogramming support turned out to be more than 2 times smaller than the simulator written in C#.Conclusion. The use of metaprogramming (using the example of creating emulators) can significantly reduce the size of a program, simplify and improve the program architecture, reduce the number of errors and improve the quality of programs. The use of domain specific languages lets reduce code size even more.
Read full abstract