generative programming. automated assembly lines

30
Generative Programming Generative Programming

Upload: lorin-booker

Post on 02-Jan-2016

229 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Generative Programming. Automated Assembly Lines

Generative ProgrammingGenerative Programming

Page 2: Generative Programming. Automated Assembly Lines

Automated Assembly LinesAutomated Assembly Lines

Page 3: Generative Programming. Automated Assembly Lines

Interchangeable PartsInterchangeable Parts

Page 4: Generative Programming. Automated Assembly Lines

Software EngineeringSoftware Engineering

ExpectationsExpectations– Master high complexity

– Achieve high productivity and quality

– Facilitate effective maintenance and evolution

Current situationsCurrent situations– Lag more than a century in development

behind manufacturing

– Be more like cottage industry handcrafting one-of-a-kind solutions than engineering

Page 5: Generative Programming. Automated Assembly Lines

Generative ProgrammingGenerative Programming

A software engineering paradigm on A software engineering paradigm on modeling software system familiesmodeling software system families– Problem space: requirements specification

– Solution space: customized and optimized product

A direct consequence of the A direct consequence of the “automation assumption”:“automation assumption”:If you can compose components If you can compose components manually, you can also automate this manually, you can also automate this process.process.

Page 6: Generative Programming. Automated Assembly Lines

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 7: Generative Programming. Automated Assembly Lines

OverviewOverview

Translator

Generative Component

Specification in a

configuration DSL

Implementation components

Finished Configuration

Page 8: Generative Programming. Automated Assembly Lines

Specification LevelsSpecification Levels

Unspecific Specific

Client’s own format

Direct format specification

Precise format specification

Format selected based on optimization flags

Format selected based on default settings

StorageStorage

Page 9: Generative Programming. Automated Assembly Lines

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 10: Generative Programming. Automated Assembly Lines

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 11: Generative Programming. Automated Assembly Lines

Type of transformationsType of transformations

VerticalVerticalHorizontalHorizontal

Page 12: Generative Programming. Automated Assembly Lines

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 13: Generative Programming. Automated Assembly Lines

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 14: Generative Programming. Automated Assembly Lines

Kind of transformationsKind of transformations

Compiler transformationsCompiler transformationsSource to source transformationsSource to source transformations

Page 15: Generative Programming. Automated Assembly Lines

Compiler TransformationsCompiler Transformations

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

OptimizationsOptimizations

Page 16: Generative Programming. Automated Assembly Lines

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 17: Generative Programming. Automated Assembly Lines

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 18: Generative Programming. Automated Assembly Lines

y = x * 3y = x * 3

dy/dx = 3dy/dx = 3

dx = 2dx = 2

yyi+1i+1 = y = yii + 3 dx + 3 dx

Page 19: Generative Programming. Automated Assembly Lines

Source to source TransformationsSource to source Transformations

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

Page 20: Generative Programming. Automated Assembly Lines

Implementation TechnologiesImplementation Technologies

Generic ProgrammingGeneric ProgrammingMetaprogrammingMetaprogrammingStatic Metaprogramming in C++Static Metaprogramming in C++Reflection in C#Reflection in C#Aspect Oriented ProgrammingAspect Oriented ProgrammingGeneratorsGeneratorsRuntime Code Generation in LINQRuntime Code Generation in LINQ Intentional ProgrammingIntentional Programming

20

Page 21: Generative Programming. Automated Assembly Lines

ApproachesApproaches

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

TechnologiesTechnologies Intentional ProgrammingIntentional ProgrammingDomain EngineeringDomain EngineeringGenerative ProgrammingGenerative Programming

Page 22: Generative Programming. Automated Assembly Lines

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 23: Generative Programming. Automated Assembly Lines

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 24: Generative Programming. Automated Assembly Lines

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 25: Generative Programming. Automated Assembly Lines

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 26: Generative Programming. Automated Assembly Lines

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 27: Generative Programming. Automated Assembly Lines

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 28: Generative Programming. Automated Assembly Lines

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 typeClass 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 29: Generative Programming. Automated Assembly Lines

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 30: Generative Programming. Automated Assembly Lines

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