SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
Scoped Dynamic Rewrite Rules
Program Transformation 2004–2005

Eelco Visser
Institute of Information & Computing Sciences
Utrecht University,
The Netherlands

February 29, 2005
Limitations of Rewriting
Lack of control over application of rules
Non-termination
Non-confluence
Common solution: encode with extra rules
Stratego: programmable rewriting strategies

Context-free nature of rewrite rules
Inlining
Bound variable renaming
Dead code elimination
Common solution: encode with extra rules
Stratego: scoped dynamic rewrite rules

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Limitations of Rewriting
Lack of control over application of rules
Non-termination
Non-confluence
Common solution: encode with extra rules
Stratego: programmable rewriting strategies

Context-free nature of rewrite rules
Inlining
Bound variable renaming
Dead code elimination
Common solution: encode with extra rules
Stratego: scoped dynamic rewrite rules

For details see paper:
Program Transformation with Scoped Dynamic Rewrite Rules

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Contextual Rules
UnfoldCall :
| let function f(x) = e1 in e2[f(e3)] end ] ->
[
|
| let function f(x) = e1
[
in e2[let var x := e3 in e1 end] end ]
|

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Contextual Rules
UnfoldCall :
| let function f(x) = e1 in e2[f(e3)] end ] ->
[
|
| let function f(x) = e1
[
in e2[let var x := e3 in e1 end] end ]
|

Implementation
UnfoldCall :
| let function f(x) = e1 in e2 end ] ->
[
|
| let function f(x) = e1 in e2’ end ]
[
|
where <oncetd({e3 :
(|
[f(e3)] -> |
|
[let var x := e3 in e1 end]
|)
})> e2 => e2’

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Contextual Rules
UnfoldCall :
| let function f(x) = e1 in e2[f(e3)] end ] ->
[
|
| let function f(x) = e1
[
in e2[let var x := e3 in e1 end] end ]
|

Implementation
UnfoldCall :
| let function f(x) = e1 in e2 end ] ->
[
|
| let function f(x) = e1 in e2’ end ]
[
|
where <oncetd({e3 :
(|
[f(e3)] -> |
|
[let var x := e3 in e1 end]
|)
})> e2 => e2’

Problems
Local traversal
One rule at a time
http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Idea
Contextual Rule
UnfoldCall :
| let function f(x) = e1 in e2 end ] ->
[
|
| let function f(x) = e1 in e2’ end ]
[
|
where <oncetd({e3 :
(|
[f(e3)] -> |
|
[let var x := e3 in e1 end]
|)
})> e2 => e2’

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Idea
Contextual Rule
UnfoldCall :
| let function f(x) = e1 in e2 end ] ->
[
|
| let function f(x) = e1 in e2’ end ]
[
|
where <oncetd({e3 :
(|
[f(e3)] -> |
|
[let var x := e3 in e1 end]
|)
})> e2 => e2’

Observation: Local rule inherits variable bindings from context

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Idea
Contextual Rule
UnfoldCall :
| let function f(x) = e1 in e2 end ] ->
[
|
| let function f(x) = e1 in e2’ end ]
[
|
where <oncetd({e3 :
(|
[f(e3)] -> |
|
[let var x := e3 in e1 end]
|)
})> e2 => e2’

Observation: Local rule inherits variable bindings from context
Dynamic Rule
define-unfold =
?| let function f(x) = e1 in e2 end ]
[
|
; rules(
UnfoldCall : |
[f(e3)] -> |
|
[let var x := e3 in e1 end]
|
)
http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Dynamic Rewrite Rules

Properties
Defined at run-time
Multiple rules with the same name can be defined
Rules can be redefined
Rules can be undefined
The scope in which a rule is applicable can be limited
Scope labels provide fine grained control over the scope in
which a rule is defined
Rules can be extended to rewrite to multiple right-hand sides
Rule sets can be forked and later joined again with
intersection or union operations

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Example: Constant Propagation
(b
c
b
b
a

:=
:=
:=
:=
:=

1;
b +
b +
z +
b +

3;
1;
b;
c)

⇒

http://www.strategoxt.org

⇒

(b
c
b
b
a

Scoped Dynamic Rewrite Rules

:=
:=
:=
:=
:=

1;
4;
2;
z + 2;
b + 4)
Example: Constant Propagation
(b
c
b
b
a

:=
:=
:=
:=
:=

1;
b +
b +
z +
b +

3;
1;
b;
c)

⇒

b -> 1
b -> 1,
b -> 2,
b-,
b-,

c
c
c
c

->
->
->
->

4
4
4
4, a-

⇒

(b
c
b
b
a

:=
:=
:=
:=
:=

prop-const =
PropConst
<+ prop-const-assign
<+ (all(prop-const); try(EvalBinOp <+ EvalRelOp))
prop-const-assign =
|[ x := <prop-const => e> ]|
; if <is-value> e then
rules( PropConst : |[ x ]| -> |[ e ]| )
else
rules( PropConst :- |[ x ]| ) end
http://www.strategoxt.org

Scoped Dynamic Rewrite Rules

1;
4;
2;
z + 2;
b + 4)
Bound Variable Renaming
let var a : int :=
function foo(a
let var a :=
var z :=
in for a :=
z := z
in foo(a) end

x
:
a
0
a
+

int) : int =
+ 3
to a + 100 do
a end

⇓
let var a : int := x
function foo(b : int) : int =
let var c := b + 3
var z := 0
in for d := c to c + 100 do
z := z + d end
in foo(a) end
http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Bound Variable Renaming

exprename = rec rn(
RenameVar
<+ RenameVarDec
<+ |[ let <*id> in <*id> end ]|
; {| RenameVar : all(rn) |}
<+ |[ for <id> := <rn> to <rn> do <id> ]|
; {| RenameVar: RenameFor
; |[ for <id> := <id> to <id> do <rn> ]| |}
<+ |[ function <id>(<*id>) <id> = <id> ]|
; {| RenameVar :
RenameArgs
; |[ function <id>(<*id>) <id> = <rn> ]| |}
<+ all(rn))

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Bound Variable Renaming
RenameVarDec :
|[ var x ta := e ]| -> |[ var y ta := e ]|
where <NewVar> x => y
RenameFor :
|[ for x := e1 to e2 do e3 ]| ->
|[ for y := e1 to e2 do e3 ]|
where <NewVar> x => y
RenameArgs :
|[ function f(x1*) ta = e ]| ->
|[ function f(x2*) ta = e ]|
where <map(FArg|[ <NewVar> : <id> ]|)> x1* => x2*
NewVar :
x -> y where new => y
; rules( RenameVar : |[ x ]| -> |[ y ]| )
http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Function Inlining
let function fact(n : int) : int =
let function f(n : int, acc : int) : int =
(while n > 0 do
(acc := acc * n; n := n - 1)
; acc)
in f(n, 1) end
in fact(10) end

⇓
let var n : int := 10
var b : int := n
var acc : int := 1
in while b > 0 do
(acc := acc * b;
b := b - 1);
acc end
http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Function Inlining
inline = inline-call <+ inline-let <+ inline-fundecs
<+ all(inline)
inline-call = UnfoldCall; exprename; inline
inline-let = |[ let <*id> in <*id> end ]|
; {| UnfoldCall : all(inline) |}
inline-fundecs =
|[ <fd*: map(if is-inlineable
then define-unfold
else undefine-unfold end)
; map(inline)
; filter(if is-inlineable
then define-fold; fail
else undefine-unfold end)> ]|

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Function Inlining

define-unfold =
?|[ function f(x*) ta = e ]|
; rules(
UnfoldCall :
|[ f(a*) ]| -> |[ let d* in e end ]|
where <zip(bind-arg)> (x*, a*) => d* )
bind-arg :
(FArg|[ x ta ]|, e) -> |[ var x ta := e ]|
undefine-unfold =
?|[ function f(x*) ta = e ]|
; rules( UnfoldCall :- |[ f(a*) ]|)

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Scope Labels – Constant Propagation with Local Variables
let var a := 1 var b := 2 var c := 3
in a := b + c;
let var c := a + 1
in b := b + c;
a := a + b;
b := z + b end;
a := c + b + a end

⇓
let var a := 1 var b := 2 var c := 3
in a := 5;
let var c := 6
in b := 8;
a := 13;
b := z + 8 end;
a := 3 + b + 13 end
http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Constant Propagation with Local Variables
prop-const = PropConst <+ prop-const-assign
<+ prop-const-let <+ prop-const-vardec
<+ all(prop-const); try(EvalBinOp <+ EvalRelOp)
prop-const-let =
|[ let <*id> in <*id> end ]|
; {| PropConst : all(prop-const) |}
prop-const-vardec =
|[ var x ta := <prop-const => e> ]|
; if <is-value> e
then rules( PropConst+x : |[ x ]| -> |[ e ]| )
else rules( PropConst+x :- |[ x ]| ) end
prop-const-assign =
|[ x := <prop-const => e> ]|
; if <is-value> e
then rules( PropConst.x : |[ x ]| -> |[ e ]| )
else rules( PropConst.x :- |[ x ]| ) end
http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Common-Subexpression Elimination

(x
y
z
a
z

:=
:=
:=
:=
:=

a + b;
a + b;
a + c;
1;
(a + c) + (a + b))

http://www.strategoxt.org

⇒

(x
y
z
a
z

:=
:=
:=
:=
:=

a + b;
x;
a + c;
1;
(a + c) + (a + b))

Scoped Dynamic Rewrite Rules
Common-Subexpression Elimination
cse = cse-assign <+ (all(cse); try(ReplaceExp))
cse-assign =
|[ x := <cse => e> ]|
; where(<undefine-subexpressions> |[ x ]|)
; if <not(is-subterm(||[ x ]|))> |[ e ]| then
rules(ReplaceExp : |[ e ]| -> |[ x ]|)
; where(<register-subexpressions(|e)> |[ x := e ]|)
end
register-subexpressions(|e) =
get-vars; map({y : ?|[ y ]|
; rules(UsedInExp :+ |[ y ]| -> e)})
undefine-subexpressions =
bagof-UsedInExp; map({?e; rules(ReplaceExp :- |[ e ]|)})
get-vars = collect({?|[ x ]|})
http://www.strategoxt.org

Scoped Dynamic Rewrite Rules
Next

Flow-sensitive data-flow transformation
Intersection and union of rule sets
Dependent dynamic rules

http://www.strategoxt.org

Scoped Dynamic Rewrite Rules

Contenu connexe

Tendances

zkStudy Club: Subquadratic SNARGs in the Random Oracle Model
zkStudy Club: Subquadratic SNARGs in the Random Oracle ModelzkStudy Club: Subquadratic SNARGs in the Random Oracle Model
zkStudy Club: Subquadratic SNARGs in the Random Oracle ModelAlex Pruden
 
Martin Fowler's Refactoring Techniques Quick Reference
Martin Fowler's Refactoring Techniques Quick ReferenceMartin Fowler's Refactoring Techniques Quick Reference
Martin Fowler's Refactoring Techniques Quick ReferenceSeung-Bum Lee
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語Kiyotaka Oku
 
benpresentation_django
benpresentation_djangobenpresentation_django
benpresentation_djangoiiilx
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J ScriptRoman Agaev
 
Python profiling
Python profilingPython profiling
Python profilingdreampuf
 
Advanced latex
Advanced latexAdvanced latex
Advanced latexawverret
 
Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Jonathan Katz
 
Gradient boosting in practice: a deep dive into xgboost
Gradient boosting in practice: a deep dive into xgboostGradient boosting in practice: a deep dive into xgboost
Gradient boosting in practice: a deep dive into xgboostJaroslaw Szymczak
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoKim Phillips
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory ManagementAlan Uthoff
 
SevillaR meetup: dplyr and magrittr
SevillaR meetup: dplyr and magrittrSevillaR meetup: dplyr and magrittr
SevillaR meetup: dplyr and magrittrRomain Francois
 
Company_X_Data_Analyst_Challenge
Company_X_Data_Analyst_ChallengeCompany_X_Data_Analyst_Challenge
Company_X_Data_Analyst_ChallengeMark Yashar
 
CrystalBall - Compute Relative Frequency in Hadoop
CrystalBall - Compute Relative Frequency in Hadoop CrystalBall - Compute Relative Frequency in Hadoop
CrystalBall - Compute Relative Frequency in Hadoop Suvash Shah
 

Tendances (20)

Lec2
Lec2Lec2
Lec2
 
Lec2&3_DataStructure
Lec2&3_DataStructureLec2&3_DataStructure
Lec2&3_DataStructure
 
zkStudy Club: Subquadratic SNARGs in the Random Oracle Model
zkStudy Club: Subquadratic SNARGs in the Random Oracle ModelzkStudy Club: Subquadratic SNARGs in the Random Oracle Model
zkStudy Club: Subquadratic SNARGs in the Random Oracle Model
 
Concurrency in Python4k
Concurrency in Python4kConcurrency in Python4k
Concurrency in Python4k
 
Martin Fowler's Refactoring Techniques Quick Reference
Martin Fowler's Refactoring Techniques Quick ReferenceMartin Fowler's Refactoring Techniques Quick Reference
Martin Fowler's Refactoring Techniques Quick Reference
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語
 
benpresentation_django
benpresentation_djangobenpresentation_django
benpresentation_django
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J Script
 
Python profiling
Python profilingPython profiling
Python profiling
 
Advanced latex
Advanced latexAdvanced latex
Advanced latex
 
Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)
 
Gradient boosting in practice: a deep dive into xgboost
Gradient boosting in practice: a deep dive into xgboostGradient boosting in practice: a deep dive into xgboost
Gradient boosting in practice: a deep dive into xgboost
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
 
SevillaR meetup: dplyr and magrittr
SevillaR meetup: dplyr and magrittrSevillaR meetup: dplyr and magrittr
SevillaR meetup: dplyr and magrittr
 
Mpibhseguranca3
Mpibhseguranca3Mpibhseguranca3
Mpibhseguranca3
 
Company_X_Data_Analyst_Challenge
Company_X_Data_Analyst_ChallengeCompany_X_Data_Analyst_Challenge
Company_X_Data_Analyst_Challenge
 
Efficient Programs
Efficient ProgramsEfficient Programs
Efficient Programs
 
CrystalBall - Compute Relative Frequency in Hadoop
CrystalBall - Compute Relative Frequency in Hadoop CrystalBall - Compute Relative Frequency in Hadoop
CrystalBall - Compute Relative Frequency in Hadoop
 

En vedette

En vedette (9)

Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Term Rewriting
Term RewritingTerm Rewriting
Term Rewriting
 
Formal Grammars
Formal GrammarsFormal Grammars
Formal Grammars
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Static Analysis
Static AnalysisStatic Analysis
Static Analysis
 
Dataflow Analysis
Dataflow AnalysisDataflow Analysis
Dataflow Analysis
 
Register Allocation
Register AllocationRegister Allocation
Register Allocation
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Syntax Definition
Syntax DefinitionSyntax Definition
Syntax Definition
 

Similaire à Scoped dynamic rewrite rules

Dependent dynamic rules
Dependent dynamic rulesDependent dynamic rules
Dependent dynamic rulesEelco Visser
 
Composing Source-to-Source Data-Flow Transformations with Rewriting Strategie...
Composing Source-to-Source Data-Flow Transformations with Rewriting Strategie...Composing Source-to-Source Data-Flow Transformations with Rewriting Strategie...
Composing Source-to-Source Data-Flow Transformations with Rewriting Strategie...Eelco Visser
 
Online partial evaluation
Online partial evaluationOnline partial evaluation
Online partial evaluationEelco Visser
 
MuVM: Higher Order Mutation Analysis Virtual Machine for C
MuVM: Higher Order Mutation Analysis Virtual Machine for CMuVM: Higher Order Mutation Analysis Virtual Machine for C
MuVM: Higher Order Mutation Analysis Virtual Machine for CSusumu Tokumoto
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a ElixirSvet Ivantchev
 
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...openCypher
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingEelco Visser
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойSigma Software
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITEgor Bogatov
 
computer notes - Data Structures - 9
computer notes - Data Structures - 9computer notes - Data Structures - 9
computer notes - Data Structures - 9ecomputernotes
 
NSC #2 - D2 06 - Richard Johnson - SAGEly Advice
NSC #2 - D2 06 - Richard Johnson - SAGEly AdviceNSC #2 - D2 06 - Richard Johnson - SAGEly Advice
NSC #2 - D2 06 - Richard Johnson - SAGEly AdviceNoSuchCon
 
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
 Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at... Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...Big Data Spain
 
Asynchronous programming with java script and node.js
Asynchronous programming with java script and node.jsAsynchronous programming with java script and node.js
Asynchronous programming with java script and node.jsTimur Shemsedinov
 
Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Ruslan Shevchenko
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015Michiel Borkent
 
yield and return (poor English ver)
yield and return (poor English ver)yield and return (poor English ver)
yield and return (poor English ver)bleis tift
 

Similaire à Scoped dynamic rewrite rules (20)

Dependent dynamic rules
Dependent dynamic rulesDependent dynamic rules
Dependent dynamic rules
 
Composing Source-to-Source Data-Flow Transformations with Rewriting Strategie...
Composing Source-to-Source Data-Flow Transformations with Rewriting Strategie...Composing Source-to-Source Data-Flow Transformations with Rewriting Strategie...
Composing Source-to-Source Data-Flow Transformations with Rewriting Strategie...
 
Online partial evaluation
Online partial evaluationOnline partial evaluation
Online partial evaluation
 
MuVM: Higher Order Mutation Analysis Virtual Machine for C
MuVM: Higher Order Mutation Analysis Virtual Machine for CMuVM: Higher Order Mutation Analysis Virtual Machine for C
MuVM: Higher Order Mutation Analysis Virtual Machine for C
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 
computer notes - Data Structures - 9
computer notes - Data Structures - 9computer notes - Data Structures - 9
computer notes - Data Structures - 9
 
NSC #2 - D2 06 - Richard Johnson - SAGEly Advice
NSC #2 - D2 06 - Richard Johnson - SAGEly AdviceNSC #2 - D2 06 - Richard Johnson - SAGEly Advice
NSC #2 - D2 06 - Richard Johnson - SAGEly Advice
 
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
 Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at... Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
 
Asynchronous programming with java script and node.js
Asynchronous programming with java script and node.jsAsynchronous programming with java script and node.js
Asynchronous programming with java script and node.js
 
Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version]
 
Eta
EtaEta
Eta
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
OpenMP
OpenMPOpenMP
OpenMP
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
yield and return (poor English ver)
yield and return (poor English ver)yield and return (poor English ver)
yield and return (poor English ver)
 

Plus de Eelco Visser

CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingEelco Visser
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesEelco Visser
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingEelco Visser
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionEelco Visser
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionEelco Visser
 
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesEelco Visser
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with StatixEelco Visser
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionEelco Visser
 
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Eelco Visser
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementEelco Visser
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersEelco Visser
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationEelco Visser
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesEelco Visser
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksEelco Visser
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisEelco Visser
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionEelco Visser
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsEelco Visser
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingEelco Visser
 
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisEelco Visser
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingEelco Visser
 

Plus de Eelco Visser (20)

CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
 
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation Rules
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
 
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
 
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static Analysis
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
 

Dernier

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 

Dernier (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Scoped dynamic rewrite rules

  • 1. Scoped Dynamic Rewrite Rules Program Transformation 2004–2005 Eelco Visser Institute of Information & Computing Sciences Utrecht University, The Netherlands February 29, 2005
  • 2. Limitations of Rewriting Lack of control over application of rules Non-termination Non-confluence Common solution: encode with extra rules Stratego: programmable rewriting strategies Context-free nature of rewrite rules Inlining Bound variable renaming Dead code elimination Common solution: encode with extra rules Stratego: scoped dynamic rewrite rules http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 3. Limitations of Rewriting Lack of control over application of rules Non-termination Non-confluence Common solution: encode with extra rules Stratego: programmable rewriting strategies Context-free nature of rewrite rules Inlining Bound variable renaming Dead code elimination Common solution: encode with extra rules Stratego: scoped dynamic rewrite rules For details see paper: Program Transformation with Scoped Dynamic Rewrite Rules http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 4. Contextual Rules UnfoldCall : | let function f(x) = e1 in e2[f(e3)] end ] -> [ | | let function f(x) = e1 [ in e2[let var x := e3 in e1 end] end ] | http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 5. Contextual Rules UnfoldCall : | let function f(x) = e1 in e2[f(e3)] end ] -> [ | | let function f(x) = e1 [ in e2[let var x := e3 in e1 end] end ] | Implementation UnfoldCall : | let function f(x) = e1 in e2 end ] -> [ | | let function f(x) = e1 in e2’ end ] [ | where <oncetd({e3 : (| [f(e3)] -> | | [let var x := e3 in e1 end] |) })> e2 => e2’ http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 6. Contextual Rules UnfoldCall : | let function f(x) = e1 in e2[f(e3)] end ] -> [ | | let function f(x) = e1 [ in e2[let var x := e3 in e1 end] end ] | Implementation UnfoldCall : | let function f(x) = e1 in e2 end ] -> [ | | let function f(x) = e1 in e2’ end ] [ | where <oncetd({e3 : (| [f(e3)] -> | | [let var x := e3 in e1 end] |) })> e2 => e2’ Problems Local traversal One rule at a time http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 7. Idea Contextual Rule UnfoldCall : | let function f(x) = e1 in e2 end ] -> [ | | let function f(x) = e1 in e2’ end ] [ | where <oncetd({e3 : (| [f(e3)] -> | | [let var x := e3 in e1 end] |) })> e2 => e2’ http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 8. Idea Contextual Rule UnfoldCall : | let function f(x) = e1 in e2 end ] -> [ | | let function f(x) = e1 in e2’ end ] [ | where <oncetd({e3 : (| [f(e3)] -> | | [let var x := e3 in e1 end] |) })> e2 => e2’ Observation: Local rule inherits variable bindings from context http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 9. Idea Contextual Rule UnfoldCall : | let function f(x) = e1 in e2 end ] -> [ | | let function f(x) = e1 in e2’ end ] [ | where <oncetd({e3 : (| [f(e3)] -> | | [let var x := e3 in e1 end] |) })> e2 => e2’ Observation: Local rule inherits variable bindings from context Dynamic Rule define-unfold = ?| let function f(x) = e1 in e2 end ] [ | ; rules( UnfoldCall : | [f(e3)] -> | | [let var x := e3 in e1 end] | ) http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 10. Dynamic Rewrite Rules Properties Defined at run-time Multiple rules with the same name can be defined Rules can be redefined Rules can be undefined The scope in which a rule is applicable can be limited Scope labels provide fine grained control over the scope in which a rule is defined Rules can be extended to rewrite to multiple right-hand sides Rule sets can be forked and later joined again with intersection or union operations http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 11. Example: Constant Propagation (b c b b a := := := := := 1; b + b + z + b + 3; 1; b; c) ⇒ http://www.strategoxt.org ⇒ (b c b b a Scoped Dynamic Rewrite Rules := := := := := 1; 4; 2; z + 2; b + 4)
  • 12. Example: Constant Propagation (b c b b a := := := := := 1; b + b + z + b + 3; 1; b; c) ⇒ b -> 1 b -> 1, b -> 2, b-, b-, c c c c -> -> -> -> 4 4 4 4, a- ⇒ (b c b b a := := := := := prop-const = PropConst <+ prop-const-assign <+ (all(prop-const); try(EvalBinOp <+ EvalRelOp)) prop-const-assign = |[ x := <prop-const => e> ]| ; if <is-value> e then rules( PropConst : |[ x ]| -> |[ e ]| ) else rules( PropConst :- |[ x ]| ) end http://www.strategoxt.org Scoped Dynamic Rewrite Rules 1; 4; 2; z + 2; b + 4)
  • 13. Bound Variable Renaming let var a : int := function foo(a let var a := var z := in for a := z := z in foo(a) end x : a 0 a + int) : int = + 3 to a + 100 do a end ⇓ let var a : int := x function foo(b : int) : int = let var c := b + 3 var z := 0 in for d := c to c + 100 do z := z + d end in foo(a) end http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 14. Bound Variable Renaming exprename = rec rn( RenameVar <+ RenameVarDec <+ |[ let <*id> in <*id> end ]| ; {| RenameVar : all(rn) |} <+ |[ for <id> := <rn> to <rn> do <id> ]| ; {| RenameVar: RenameFor ; |[ for <id> := <id> to <id> do <rn> ]| |} <+ |[ function <id>(<*id>) <id> = <id> ]| ; {| RenameVar : RenameArgs ; |[ function <id>(<*id>) <id> = <rn> ]| |} <+ all(rn)) http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 15. Bound Variable Renaming RenameVarDec : |[ var x ta := e ]| -> |[ var y ta := e ]| where <NewVar> x => y RenameFor : |[ for x := e1 to e2 do e3 ]| -> |[ for y := e1 to e2 do e3 ]| where <NewVar> x => y RenameArgs : |[ function f(x1*) ta = e ]| -> |[ function f(x2*) ta = e ]| where <map(FArg|[ <NewVar> : <id> ]|)> x1* => x2* NewVar : x -> y where new => y ; rules( RenameVar : |[ x ]| -> |[ y ]| ) http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 16. Function Inlining let function fact(n : int) : int = let function f(n : int, acc : int) : int = (while n > 0 do (acc := acc * n; n := n - 1) ; acc) in f(n, 1) end in fact(10) end ⇓ let var n : int := 10 var b : int := n var acc : int := 1 in while b > 0 do (acc := acc * b; b := b - 1); acc end http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 17. Function Inlining inline = inline-call <+ inline-let <+ inline-fundecs <+ all(inline) inline-call = UnfoldCall; exprename; inline inline-let = |[ let <*id> in <*id> end ]| ; {| UnfoldCall : all(inline) |} inline-fundecs = |[ <fd*: map(if is-inlineable then define-unfold else undefine-unfold end) ; map(inline) ; filter(if is-inlineable then define-fold; fail else undefine-unfold end)> ]| http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 18. Function Inlining define-unfold = ?|[ function f(x*) ta = e ]| ; rules( UnfoldCall : |[ f(a*) ]| -> |[ let d* in e end ]| where <zip(bind-arg)> (x*, a*) => d* ) bind-arg : (FArg|[ x ta ]|, e) -> |[ var x ta := e ]| undefine-unfold = ?|[ function f(x*) ta = e ]| ; rules( UnfoldCall :- |[ f(a*) ]|) http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 19. Scope Labels – Constant Propagation with Local Variables let var a := 1 var b := 2 var c := 3 in a := b + c; let var c := a + 1 in b := b + c; a := a + b; b := z + b end; a := c + b + a end ⇓ let var a := 1 var b := 2 var c := 3 in a := 5; let var c := 6 in b := 8; a := 13; b := z + 8 end; a := 3 + b + 13 end http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 20. Constant Propagation with Local Variables prop-const = PropConst <+ prop-const-assign <+ prop-const-let <+ prop-const-vardec <+ all(prop-const); try(EvalBinOp <+ EvalRelOp) prop-const-let = |[ let <*id> in <*id> end ]| ; {| PropConst : all(prop-const) |} prop-const-vardec = |[ var x ta := <prop-const => e> ]| ; if <is-value> e then rules( PropConst+x : |[ x ]| -> |[ e ]| ) else rules( PropConst+x :- |[ x ]| ) end prop-const-assign = |[ x := <prop-const => e> ]| ; if <is-value> e then rules( PropConst.x : |[ x ]| -> |[ e ]| ) else rules( PropConst.x :- |[ x ]| ) end http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 21. Common-Subexpression Elimination (x y z a z := := := := := a + b; a + b; a + c; 1; (a + c) + (a + b)) http://www.strategoxt.org ⇒ (x y z a z := := := := := a + b; x; a + c; 1; (a + c) + (a + b)) Scoped Dynamic Rewrite Rules
  • 22. Common-Subexpression Elimination cse = cse-assign <+ (all(cse); try(ReplaceExp)) cse-assign = |[ x := <cse => e> ]| ; where(<undefine-subexpressions> |[ x ]|) ; if <not(is-subterm(||[ x ]|))> |[ e ]| then rules(ReplaceExp : |[ e ]| -> |[ x ]|) ; where(<register-subexpressions(|e)> |[ x := e ]|) end register-subexpressions(|e) = get-vars; map({y : ?|[ y ]| ; rules(UsedInExp :+ |[ y ]| -> e)}) undefine-subexpressions = bagof-UsedInExp; map({?e; rules(ReplaceExp :- |[ e ]|)}) get-vars = collect({?|[ x ]|}) http://www.strategoxt.org Scoped Dynamic Rewrite Rules
  • 23. Next Flow-sensitive data-flow transformation Intersection and union of rule sets Dependent dynamic rules http://www.strategoxt.org Scoped Dynamic Rewrite Rules