Chapter 9. Code Generation

In this chapter, we will explore D's code generation capabilities and cover the following recipes:

  • Creating user-defined literals
  • Parsing a domain-specific language
  • Generating data structures from text diagrams
  • Automating dynamic calls with multiple dispatch
  • Building a lookup table
  • Using string parameters to change functions
  • Wrapping instance methods
  • Using opDispatch to generate properties
  • Duck typing to a statically-defined interface

Introduction

Code generation is a central feature of the D programming language. In fact, it is so important that we've already used it extensively throughout this book! Templates perform code generation. They are a block of code with placeholders which are filled in to form the generated code. With compile-time function evaluation and the mixin expression, we can build D code out of strings and have them compiled.

Here, we'll look at some specific examples of how to use these techniques to generate code from various inputs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.144.56