Presentation is loading. Please wait.

Presentation is loading. Please wait.

Generative Programming. Generic vs Generative Generic Programming focuses on representing families of domain concepts Generic Programming focuses on representing.

Similar presentations


Presentation on theme: "Generative Programming. Generic vs Generative Generic Programming focuses on representing families of domain concepts Generic Programming focuses on representing."— Presentation transcript:

1 Generative Programming

2 Generic vs Generative Generic Programming focuses on representing families of domain concepts Generic Programming focuses on representing families of domain concepts Generative Programming also includes the process of creating concrete instances of concepts Generative Programming also includes the process of creating concrete instances of concepts

3 Overview Translator Generative Component Specification in a configuration DSL Implementation components Finished Configuration

4 Why Generators? Raise the intentionality of system descriptions Raise the intentionality of system descriptions –E.g. using domain specific notation Produce an efficient implementation Produce an efficient implementation –Nontrivial mapping into implementation concepts Avoid the library scaling problem Avoid the library scaling problem –Library built as concrete component double in size for each new added feature

5 Transformation Model System Requirements Source Code (C++, Java) System Implementation High Level System Specification System Requirements compile Source Code (C++, Java) compile Source Code (C++, Java) Source in DSL System Implementation Source in DSL Manually implement Implement with tools

6 Type of transformations Vertical Vertical Horizontal Horizontal

7 Vertical Transformation Refines higher-level structure into lower level, preserving structure Refines higher-level structure into lower level, preserving structure Typical of step-wise refinement and CASE or GUI builders Typical of step-wise refinement and CASE or GUI builders

8 Horizontal Transformation Modifies modular structure at the same level Modifies modular structure at the same level Merges, deletes or modifies existing modules Merges, deletes or modifies existing modules

9 Kind of transformations Compiler transformations Compiler transformations Source to source transformations Source to source transformations

10 Compiler Transformations Refinements Refinements –Decomposition –Choice of representation –Choice of algorithm –Specialization –Concretization Optimizations Optimizations

11 Compiler Optimizations Inlining Inlining Constant folding Constant folding Data caching Data caching Loop fusion Loop fusion –Adding matrixes A+B+C Loop unrolling Loop unrolling –When number of iterations is small Code motion Code motion –Move invariant code outside of loop

12 Compiler Optimizations (2) Common subexpression elimination Common subexpression elimination Dead-code elimination Dead-code elimination Partial evaluation Partial evaluation –Partially evaluate a function based on knowledge of some of its parameters to be constants in a special context Finite differencing Finite differencing x = x + 2x = x + 2; y = x * 3;y = y + 6;

13 y = x * 3 dy/dx = 3 dx = 2 y i+1 = y i + 3 dx

14 Source to source Transformations Editing transformations Editing transformations Refactoring Refactoring Abstraction and generalization Abstraction and generalization Introducing new variant points Introducing new variant points Simplification Simplification

15 Approaches Aspect-Oriented Programming Aspect-Oriented Programming Subject-Oriented Programming Subject-Oriented Programming Software Transformation Technologies Software Transformation Technologies Intentional Programming Intentional Programming Domain Engineering Domain Engineering Generative Programming Generative Programming

16 Aspect Oriented Programming To improve the modularity of designs and implementations by allowing a better encapsulation of cross-cutting concerns: 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” New kind of modularity called “aspect” Aspects represent an orthogonal parameterization concept compared to what's available in current languages Aspects represent an orthogonal parameterization concept compared to what's available in current languages

17 Subject Oriented Programming Related to AOP Related to AOP Focuses on capturing different subjective perspectives on a single object model 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 It allows composing applications out of "subjects" (partial object models) by means of declarative composition rules

18 Software Transformations aid software development activities by providing mechanized support for manipulating program representations aid software development activities by providing mechanized support for manipulating program representations Examples: Examples: –extracting views –Refinement –Refactoring –optimizations of program representations

19 Intentional Programming an extendible programming environment based on transformation technology and direct manipulation of active program representations 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 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 The system replaces parsing technology with the direct entry and editing of resolved ASTs

20 Domain Engineering Domain engineering comprises the development of a common model and concrete components, generators, and reuse infrastructures for a family of software systems Domain engineering comprises the development of a common model and concrete components, generators, and reuse infrastructures for a family of software systems

21 Goals of Generative Programming Each language implements its own libraries: types are hard to match Each language implements its own libraries: types are hard to match Problem: 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); }

22 Complex inc(Complex x) { return add(Complex(1, 0), x); } Compiler can’t optimize, since it does not know the Complex type 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 Class used to represent concepts in domain, but semantics of domain is not conveyed to compiler

23 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);

24 C++ Using template metaprogramming one can produce specialized code Using template metaprogramming one can produce specialized code BLITZ matrix library: faster than Fortran BLITZ matrix library: faster than Fortran


Download ppt "Generative Programming. Generic vs Generative Generic Programming focuses on representing families of domain concepts Generic Programming focuses on representing."

Similar presentations


Ads by Google