Presentation is loading. Please wait.

Presentation is loading. Please wait.

Generative Programming. Automated Assembly Lines.

Similar presentations


Presentation on theme: "Generative Programming. Automated Assembly Lines."— Presentation transcript:

1 Generative Programming

2 Automated Assembly Lines

3 Interchangeable Parts

4 Software Engineering Expectations Expectations –Master high complexity –Achieve high productivity and quality –Facilitate effective maintenance and evolution Current situations Current situations –Lag more than a century in development behind manufacturing –Be more like cottage industry handcrafting one-of-a-kind solutions than engineering

5 Generative Programming A software engineering paradigm on modeling software system families A software engineering paradigm on modeling software system families –Problem space: requirements specification –Solution space: customized and optimized product A direct consequence of the “automation assumption”: If you can compose components manually, you can also automate this process. A direct consequence of the “automation assumption”: If you can compose components manually, you can also automate this process.

6 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

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

8 Specification Levels UnspecificSpecific Client’s own format Direct format specification Precise format specification Format selected based on optimization flags Format selected based on default settings Storage

9 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

10 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

11 Type of transformations Vertical Vertical Horizontal Horizontal

12 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

13 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

14 Kind of transformations Compiler transformations Compiler transformations Source to source transformations Source to source transformations

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

16 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

17 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;

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

19 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

20 Implementation Technologies Generic Programming Generic Programming Metaprogramming Metaprogramming Static Metaprogramming in C++ Static Metaprogramming in C++ Reflection in C# Reflection in C# Aspect Oriented Programming Aspect Oriented Programming Generators Generators Runtime Code Generation in LINQ Runtime Code Generation in LINQ Intentional Programming Intentional Programming 20

21 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

22 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

23 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

24 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

25 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

26 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

27 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); }

28 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

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

30 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. Automated Assembly Lines."

Similar presentations


Ads by Google