generative programming
DESCRIPTION
Generative Programming. 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. - PowerPoint PPT PresentationTRANSCRIPT
Generative ProgrammingGenerative Programming
Generic vs GenerativeGeneric vs Generative
Generic Programming focuses on Generic Programming focuses on representing families of domain representing families of domain conceptsconcepts
Generative Programming also Generative Programming also includes the process of creating includes the process of creating concrete instances of conceptsconcrete instances of concepts
OverviewOverview
Translator
Generative Component
Specification in a
configuration DSL
Implementation components
Finished Configuration
Why Generators?Why Generators?
Raise the intentionality of system Raise the intentionality of system descriptionsdescriptions– E.g. using domain specific notation
Produce an efficient implementationProduce an efficient implementation– Nontrivial mapping into implementation
conceptsAvoid the library scaling problemAvoid the library scaling problem
– Library built as concrete component double in size for each new added feature
Transformation ModelTransformation Model
System Requirements
Source Code
(C++, Java)
System Implementation
High LevelSystem
Specification
System Requirements
System Requirements
compile
Source Code
(C++, Java)
compile compile
Source Code
(C++, Java)
Source in
DSL
System Implementation
System Implementation
Source in
DSL
Manually implement
Manually implement
Manually implement
Implement with tools
Type of transformationsType of transformations
VerticalVerticalHorizontalHorizontal
Vertical TransformationVertical Transformation
Refines higher-level structure into lower level, Refines higher-level structure into lower level, preserving structurepreserving structure
Typical of step-wise refinement and CASE or GUI Typical of step-wise refinement and CASE or GUI buildersbuilders
Horizontal TransformationHorizontal Transformation
Modifies modular structure at the same levelModifies modular structure at the same level Merges, deletes or modifies existing modulesMerges, deletes or modifies existing modules
Kind of transformationsKind of transformations
Compiler transformationsCompiler transformationsSource to source transformationsSource to source transformations
Compiler TransformationsCompiler Transformations
RefinementsRefinements– Decomposition– Choice of representation– Choice of algorithm– Specialization– Concretization
OptimizationsOptimizations
Compiler OptimizationsCompiler Optimizations
InliningInliningConstant foldingConstant foldingData cachingData cachingLoop fusionLoop fusion
– Adding matrixes A+B+CLoop unrollingLoop unrolling
– When number of iterations is smallCode motionCode motion
– Move invariant code outside of loop
Compiler Optimizations (2)Compiler Optimizations (2)
Common subexpression eliminationCommon subexpression eliminationDead-code eliminationDead-code eliminationPartial evaluationPartial evaluation
– Partially evaluate a function based on knowledge of some of its parameters to be constants in a special context
Finite differencingFinite differencingx = x + 2 x = x + 2;y = x * 3; y = y + 6;
y = x * 3y = x * 3dy/dx = 3dy/dx = 3dx = 2dx = 2yyi+1i+1 = y = yii + 3 dx + 3 dx
Source to source TransformationsSource to source Transformations
Editing transformationsEditing transformationsRefactoringRefactoringAbstraction and generalizationAbstraction and generalization Introducing new variant pointsIntroducing new variant pointsSimplificationSimplification
ApproachesApproaches
Aspect-Oriented ProgrammingAspect-Oriented ProgrammingSubject-Oriented ProgrammingSubject-Oriented ProgrammingSoftware Transformation Software Transformation
TechnologiesTechnologies Intentional ProgrammingIntentional ProgrammingDomain EngineeringDomain EngineeringGenerative ProgrammingGenerative Programming
Aspect Oriented ProgrammingAspect Oriented Programming
To improve the modularity of designs and To improve the modularity of designs and implementations by allowing a better implementations by allowing a better encapsulation of cross-cutting concerns: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 Aspects represent an orthogonal
parameterization concept compared to parameterization concept compared to what's available in current languageswhat's available in current languages
Subject Oriented ProgrammingSubject Oriented Programming
Related to AOPRelated to AOPFocuses on capturing different Focuses on capturing different
subjective perspectives on a single subjective perspectives on a single object modelobject model
It allows composing applications out It allows composing applications out of "subjects" (partial object models) of "subjects" (partial object models) by means of declarative composition by means of declarative composition rulesrules
Software TransformationsSoftware Transformations
aid software development activities aid software development activities by providing mechanized support for by providing mechanized support for manipulating program manipulating program representationsrepresentations
Examples:Examples:– extracting views– Refinement– Refactoring– optimizations of program
representations
Intentional ProgrammingIntentional Programming
an extendible programming environment an extendible programming environment based on transformation technology and based on transformation technology and direct manipulation of active program direct manipulation of active program representationsrepresentations
New programming notations and New programming notations and transformations can be distributed and transformations can be distributed and used as plug-insused as plug-ins
The system replaces parsing technology The system replaces parsing technology with the direct entry and editing of with the direct entry and editing of resolved ASTsresolved ASTs
Domain EngineeringDomain Engineering
Domain engineering comprises the Domain engineering comprises the development of a common model development of a common model and concrete components, and concrete components, generators, and reuse infrastructures generators, and reuse infrastructures for a family of software systemsfor a family of software systems
Goals of Generative ProgrammingGoals of Generative Programming
Each language implements its own Each language implements its own libraries: types are hard to matchlibraries: 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);}
Complex inc(Complex x) {return add(Complex(1, 0), x); }
Compiler can’t optimize, since it Compiler can’t optimize, since it does not know the Complex typedoes not know the Complex type
Class used to represent concepts in Class used to represent concepts in domain, but semantics of domain is domain, but semantics of domain is not conveyed to compilernot conveyed to compiler
Partial EvaluationPartial 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++C++
Using template metaprogramming Using template metaprogramming one can produce specialized codeone can produce specialized code
BLITZ matrix library: faster than BLITZ matrix library: faster than FortranFortran