159 Views

Download Presentation
##### Generative Programming

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Generic vs Generative**• Generic Programming focuses on representing families of domain concepts • Generative Programming also includes the process of creating concrete instances of concepts**Overview**Translator Generative Component Finished Configuration Specification in a configuration DSL Implementation components**Why Generators?**• Raise the intentionality of system descriptions • E.g. using domain specific notation • Produce an efficient implementation • Nontrivial mapping into implementation concepts • Avoid the library scaling problem • Library built as concrete component double in size for each new added feature**Transformation Model**System Requirements System Requirements System Requirements Manually implement Manually implement Manually implement High Level System Specification Implement with tools Source in DSL Source in DSL Source Code (C++, Java) Source Code (C++, Java) Source Code (C++, Java) compile compile compile System Implementation System Implementation System Implementation**Type of transformations**• Vertical • Horizontal**Vertical Transformation**• Refines higher-level structure into lower level, preserving structure • Typical of step-wise refinement and CASE or GUI builders**Horizontal Transformation**• Modifies modular structure at the same level • Merges, deletes or modifies existing modules**Kind of transformations**• Compiler transformations • Source to source transformations**Compiler Transformations**• Refinements • Decomposition • Choice of representation • Choice of algorithm • Specialization • Concretization • Optimizations**Compiler Optimizations**• Inlining • Constant folding • Data caching • Loop fusion • Adding matrixes A+B+C • Loop unrolling • When number of iterations is small • Code motion • Move invariant code outside of loop**Compiler Optimizations (2)**• Common subexpression elimination • Dead-code elimination • Partial evaluation • Partially evaluate a function based on knowledge of some of its parameters to be constants in a special context • Finite differencing x = x + 2 x = x + 2; y = x * 3; y = y + 6;**y = x * 3**dy/dx = 3 dx = 2 yi+1 = yi + 3 dx**Source to source Transformations**• Editing transformations • Refactoring • Abstraction and generalization • Introducing new variant points • Simplification**Approaches**• Aspect-Oriented Programming • Subject-Oriented Programming • Software Transformation Technologies • Intentional Programming • Domain Engineering • Generative Programming**Aspect Oriented Programming**• To improve the modularity of designs and implementations by allowing a better encapsulation of cross-cutting concerns: • synchronization, distribution, authentication, data traversal, memory allocation, tracing, caching, etc. • New kind of modularity called “aspect” • Aspects represent an orthogonal parameterization concept compared to what's available in current languages**Subject Oriented Programming**• Related to AOP • Focuses on capturing different subjective perspectives on a single object model • It allows composing applications out of "subjects" (partial object models) by means of declarative composition rules**Software Transformations**• aid software development activities by providing mechanized support for manipulating program representations • Examples: • extracting views • Refinement • Refactoring • optimizations of program representations**Intentional Programming**• an extendible programming environment based on transformation technology and direct manipulation of active program representations • New programming notations and transformations can be distributed and used as plug-ins • The system replaces parsing technology with the direct entry and editing of resolved ASTs**Domain Engineering**• Domain engineering comprises the development of a common model and concrete components, generators, and reuse infrastructures for a family of software systems**Goals of Generative Programming**• Each language implements its own libraries: types are hard to match • Problem: int add(int i, int j) { return i+j; } add(1, x); int inc(int x) { return add(1, x); } class Complex { double r, i; } Complex add(Complex x, Complex y) { return Complex(x.r + y.r, x.i + y.i); }**Complex inc(Complex x) {**return add(Complex(1, 0), x); } • Compiler can’t optimize, since it does not know the Complex type • Class used to represent concepts in domain, but semantics of domain is not conveyed to compiler**Partial Evaluation**Matrix A, B, C, D; D = A.add(B.add(C)); Requires allocation of temporary intermediate matrix and two loops Compiler is not capable, DSL for algebra could incorporate, e.g. write Matrix.add(A, B, C);**C++**• Using template metaprogramming one can produce specialized code • BLITZ matrix library: faster than Fortran