A reference implementation is a separate, small, functional software system that serves as a focused example or template for a larger Runtime. It follows the Runtime’s chosen architecture, technological layers, coding style, conventions, build configuration, and representative functionality, while remaining independent from the Runtime itself. section 8.2
Build it before the code generator. This separates two difficult tasks: first establish how the Runtime is organized and which business-knowledge code can come from the AST; then turn the established implementation into generated code. The reference implementation becomes the starting point for the build system and for iteratively deriving code templates. section 8.2 section 8.5
A useful reference implementation is:
- Functional and separate from the Runtime. section 8.2
- Complete enough to work through the selected architecture and technological layers. section 8.2
- Consistent with defined coding style and conventions. section 8.2
- Representative of the functionality the Runtime must support. section 8.2
- Small enough to understand, build, run, deploy, change, and validate quickly. section 8.2
For DSL-based generation, the business-knowledge portion must be expressible as DSL content. If that content can generate all corresponding business-knowledge code in the reference implementation, the same approach is likely suitable for the Runtime. Hand-written code remains for concerns the DSL cannot specify, alongside build configuration that assembles a deployable or runnable artifact. section 8.0 section 8.2
Rental Runtime
A compact Rental Runtime demonstrates the approach with a React form for one rental record. Its four fields represent a rental period, price before discount, discount, and price after discount. DSL amount and percentage values map to JavaScript Number values; a DateRange class represents the date range and prevents an end date before its start date. This working implementation supplies concrete code to parameterize later from AST information. section 8.3 section 8.5
Figure 8.4 The relation between the Runtime and reference implementation
Compare the small reference implementation with the Runtime and identify the business-knowledge code intended for generation. section 8.2
Once the reference implementation is stable, derive template functions gradually by replacing fixed code fragments with expressions supplied from pieces of the AST. JavaScript ES2015 template literals and nested strings support template composition and readable, properly indented generated code. section 8.5
