24
Generative Programming Generative Programming

Generative Programming

  • Upload
    wilmet

  • View
    85

  • Download
    2

Embed Size (px)

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 Presentation

Citation preview

Page 1: Generative Programming

Generative ProgrammingGenerative Programming

Page 2: Generative 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

Page 3: Generative Programming

OverviewOverview

Translator

Generative Component

Specification in a

configuration DSL

Implementation components

Finished Configuration

Page 4: Generative Programming

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

Page 5: Generative Programming

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

Page 6: Generative Programming

Type of transformationsType of transformations

VerticalVerticalHorizontalHorizontal

Page 7: Generative Programming

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

Page 8: Generative Programming

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

Page 9: Generative Programming

Kind of transformationsKind of transformations

Compiler transformationsCompiler transformationsSource to source transformationsSource to source transformations

Page 10: Generative Programming

Compiler TransformationsCompiler Transformations

RefinementsRefinements– Decomposition– Choice of representation– Choice of algorithm– Specialization– Concretization

OptimizationsOptimizations

Page 11: Generative Programming

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

Page 12: Generative Programming

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;

Page 13: Generative Programming

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

Page 14: Generative Programming

Source to source TransformationsSource to source Transformations

Editing transformationsEditing transformationsRefactoringRefactoringAbstraction and generalizationAbstraction and generalization Introducing new variant pointsIntroducing new variant pointsSimplificationSimplification

Page 15: Generative Programming

ApproachesApproaches

Aspect-Oriented ProgrammingAspect-Oriented ProgrammingSubject-Oriented ProgrammingSubject-Oriented ProgrammingSoftware Transformation Software Transformation

TechnologiesTechnologies Intentional ProgrammingIntentional ProgrammingDomain EngineeringDomain EngineeringGenerative ProgrammingGenerative Programming

Page 16: Generative 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

Page 17: Generative Programming

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

Page 18: Generative Programming

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

Page 19: Generative Programming

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

Page 20: Generative Programming

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

Page 21: Generative Programming

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

Page 22: Generative Programming

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

Page 23: Generative Programming

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

Page 24: Generative Programming

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