
5057200f59263a8a283c6889425b42d3.ppt
- Количество слайдов: 30
Generative Programming
Automated Assembly Lines 1901 Assembly Lines 1826 Interchangeable Parts 1980 s Automated Assembly Lines
Interchangeable Parts
Software Engineering l Expectations – Master high complexity – Achieve high productivity and quality – Facilitate effective maintenance and evolution l Current situations – Lag more than a century in development behind manufacturing – Be more like cottage industry handcrafting one-of-a-kind solutions than engineering
Generative Programming l A software engineering paradigm on modeling software system families – Problem space: requirements specification – Solution space: customized and optimized product l A direct consequence of the “automation assumption”: If you can compose components manually, you can also automate this process.
Generic vs Generative l Generic Programming focuses on representing families of domain concepts l 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
Specification Levels Storage Unspecific Not Specified Use Profile More Precisely Specific Client. Provided Direct Client’s own format Direct format specification Precise format specification Format selected based on optimization flags Format selected based on default settings
Why Generators? l Raise the intentionality of system descriptions – E. g. using domain specific notation l Produce an efficient implementation – Nontrivial mapping into implementation concepts l Avoid the library scaling problem – Library built as concrete component double in size for each new added feature
Transformation Model System Requirements Manually implement High Level System Specification Source in DSL Source Code (C++, Java) compile System Implementation Implement with tools
Type of transformations l Vertical l Horizontal
Vertical Transformation Refines higher-level structure into lower level, preserving structure l Typical of step-wise refinement and CASE or GUI builders l
Horizontal Transformation Modifies modular structure at the same level l Merges, deletes or modifies existing modules l
Kind of transformations l Compiler transformations l Source to source transformations
Compiler Transformations l Refinements – Decomposition – Choice of representation – Choice of algorithm – Specialization – Concretization l Optimizations
Compiler Optimizations l Inlining l Constant folding l Data caching l Loop fusion – Adding matrixes A+B+C l Loop unrolling – When number of iterations is small l Code motion – Move invariant code outside of loop
Compiler Optimizations (2) l Common subexpression elimination l Dead-code elimination l Partial evaluation – Partially evaluate a function based on knowledge of some of its parameters to be constants in a special context l Finite differencing x=x+2 y = x * 3; x = x + 2; y = y + 6;
y=x*3 dy/dx = 3 dx = 2 yi+1 = yi + 3 dx
Source to source Transformations l Editing transformations l Refactoring l Abstraction and generalization l Introducing new variant points l Simplification
Implementation Technologies l Generic Programming l Metaprogramming l Static Metaprogramming in C++ l Reflection in C# l Aspect Oriented Programming l Generators l Runtime Code Generation in LINQ l Intentional Programming 20
Approaches l Aspect-Oriented Programming l Subject-Oriented Programming l Software Transformation Technologies l Intentional Programming l Domain Engineering l Generative Programming
Aspect Oriented Programming l 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” l Aspects represent an orthogonal parameterization concept compared to what's available in current languages l
Subject Oriented Programming l Related to AOP l Focuses on capturing different subjective perspectives on a single object model l It allows composing applications out of "subjects" (partial object models) by means of declarative composition rules
Software Transformations l aid software development activities by providing mechanized support for manipulating program representations l 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 l New programming notations and transformations can be distributed and used as plug-ins l The system replaces parsing technology with the direct entry and editing of resolved ASTs l
Domain Engineering l 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 l Each language implements its own libraries: types are hard to match l 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); } l Compiler can’t optimize, since it does not know the Complex type l 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++ l Using template metaprogramming one can produce specialized code l BLITZ matrix library: faster than Fortran
5057200f59263a8a283c6889425b42d3.ppt