Source Generators

Introduction

Source generators take an individual and produce source code from it. For some representations, such as the classic tree representation when evolving S-Expressions, the structure used to represent the individual is directly equivalent to the source code. In this case a source generator has an easy job. However, with more complex representations where there is more of a disconnect between the representation and the program code, source generators provide a convenient and modularised solution. Custom source generators could also be used to perform further processing, such as program simplification before execution or caching.

Source generators are generally representation based. They know how to convert any individual of a certain representation into source code.

Caching the Source

If the source generation process is computationally expensive then it is worth considering caching. A CachedSourceGenerator will take another source generator as a delegate to perform the actual source generation, but it will only be used if the source code for a matching individual does not already exist in its cache. More advanced representation specific caching source generators may be possible, that can cache parts of an individual (rather than just whole solutions). If performance is of real significance in your application then this is something to consider.