Presentation is loading. Please wait.

Presentation is loading. Please wait.

Aspect-Oriented Action Semantics Descriptions Luis Menezes University of Pernambuco

Similar presentations


Presentation on theme: "Aspect-Oriented Action Semantics Descriptions Luis Menezes University of Pernambuco"— Presentation transcript:

1 Aspect-Oriented Action Semantics Descriptions Luis Menezes University of Pernambuco (lcsm@dsc.upe.br)

2 Agenda Action Semantics Action Semantics Aspect-oriented Programming Aspect-oriented Programming Aspect-oriented Action Semantics Aspect-oriented Action Semantics Conclusions Conclusions

3 Action Semantics Formalism to describe programming languages Formalism to describe programming languages Action Notation Action Notation concepts of programming languages concepts of programming languages Based on English terms (intuitive) Based on English terms (intuitive) Hides the modeled concepts complexity Hides the modeled concepts complexity

4 Action Semantics Examples of actions: Examples of actions: | give 1 then | give product(2,the given integer) | bind “x” to 10 hence | give sum(1,the integer bound to “x”) | allocate a cell then | store 10 in the given cell

5 Action Semantics Descriptions Originally AS descriptions are formed by: Originally AS descriptions are formed by: Abstract Syntax Abstract Syntax Semantic Functions Semantic Functions Semantic Entities Semantic Entities This organization separates the description of each PL concept in these modules. This organization separates the description of each PL concept in these modules.

6 Modular Extensions Proposed to increase the modularity of AS descriptions Proposed to increase the modularity of AS descriptions Object Oriented AS, Component AS, Modular AS Object Oriented AS, Component AS, Modular AS Descriptions formed by a set of language elements Descriptions formed by a set of language elements Each element has syntax and semantics. Each element has syntax and semantics. Facilitates the identification where the PL elements are defined. Facilitates the identification where the PL elements are defined.

7 Syntax-less Concepts Action Semantics descriptions translates syntactical elements into action notation. Action Semantics descriptions translates syntactical elements into action notation. Some programming language concepts are not represented by textual code in programs. Some programming language concepts are not represented by textual code in programs. For example: For example: The code: The code: f(1 + x) / y f(1 + x) / y can be used by lazy or eager programming language can be used by lazy or eager programming language Action Semantics Descriptions can not isolate their descriptions in separated modules Action Semantics Descriptions can not isolate their descriptions in separated modules The semantics is described inside other features semantics The semantics is described inside other features semantics

8 Example Expressions language: Expressions language: component Constant is Exp where syntax = [[ n:number ]] syntax = [[ n:number ]] semantics = give n semantics = give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] syntax = [[ a:Expression “+” b:Expression ]] semantics = semantics = (evaluate a and then evaluate b) (evaluate a and then evaluate b) then then give sum of them give sum of them

9 Example Lazy Expressions Language: Lazy Expressions Language: component LazyConstant is Exp where syntax = [[ number ]] syntax = [[ number ]] semantics = give abstraction of give n semantics = give abstraction of give n component LazySum is Exp where syntax = [[ a:Expression “+” b:Expression ]] syntax = [[ a:Expression “+” b:Expression ]] semantics = semantics = give abstraction of ( give abstraction of ( (evaluate a and then evaluate b) (evaluate a and then evaluate b) then then (enact the given abstraction # 1 and then enact the given abstraction #2) (enact the given abstraction # 1 and then enact the given abstraction #2) then then give sum of them give sum of them )

10 Traditional object-oriented system developing has a similar problem….

11 Crosscutting Concern Crosscutting concern is a system feature that affects other concerns Crosscutting concern is a system feature that affects other concerns They can not be implemented in a separated module They can not be implemented in a separated module Difficult to insert/remove in complex systems Difficult to insert/remove in complex systems

12 Crosscutting Concern Example: Remote Databases: Example: Remote Databases: void transfer(Account src, Account dest, int amount) { if (!src.avaliable(amount)) if (!src.avaliable(amount)) throw new TransferError(); throw new TransferError(); src.whitdraw(amount); src.whitdraw(amount); dest.deposit(amount); dest.deposit(amount);}

13 Crosscutting Concern Example: Remote Databases Example: Remote Databases void transfer(Account src, Account dest, int amount) { try { try { DataBase d = connect(); DataBase d = connect(); d.openTransaction(); d.openTransaction(); if (!src.avaliable(amount)) if (!src.avaliable(amount)) throw new TransferError(); throw new TransferError(); d.rpc(whitdraw,src,amount); d.rpc(whitdraw,src,amount); d.rpc(deposit,dest,amount); d.rpc(deposit,dest,amount); d.closeTransaction(); d.closeTransaction(); } catch (CommunicationError e) { } catch (CommunicationError e) { d.undo(); d.undo(); throw new TransferError(); throw new TransferError(); }}

14 Aspect-oriented Programming Methodology designed to modularize the definition of crosscutting concerns Methodology designed to modularize the definition of crosscutting concerns Aspects: Aspects: Identify points in the system code Identify points in the system code Specify how these points are affected by the crosscutting concern implementation Specify how these points are affected by the crosscutting concern implementation Weaving Operation Weaving Operation Perform the modifications described by aspects Perform the modifications described by aspects

15 Weaving Operation void transfer(Account src, Account dest, int amount) { if (!src.avaliable(amount)) if (!src.avaliable(amount)) throw new TransferError(); throw new TransferError(); src.whitdraw(amount); src.whitdraw(amount); dest.deposit(amount); dest.deposit(amount);} aspect RemoteDataBase { ….. } Weaving void transfer(Account src, Account dest, int amount) { try { try { DataBase d = connect(); DataBase d = connect(); d.openTransaction(); d.openTransaction(); if (!src.avaliable(amount)) if (!src.avaliable(amount)) throw new TransferError(); throw new TransferError(); d.rpc(whitdraw,src,amount); d.rpc(whitdraw,src,amount); d.rpc(deposit,dest,amount); d.rpc(deposit,dest,amount); d.closeTransaction(); d.closeTransaction(); } catch (CommunicationError e) { } catch (CommunicationError e) { d.undo(); d.undo(); throw new TransferError(); throw new TransferError(); }}

16 Aspect-oriented Action Semantics Descriptions Motivation: Motivation: Use aspects to improve the modularity of action semantics descriptions Use aspects to improve the modularity of action semantics descriptions Operators designed to support aspect- oriented concepts in action semantics Operators designed to support aspect- oriented concepts in action semantics

17 Advices Specifies a modification in the specification Specifies a modification in the specification An advice can: An advice can: Modify the whole component semantics Modify the whole component semantics change semantics from x to y change semantics from x to y Rewrite a subterm inside the component semantics Rewrite a subterm inside the component semantics rewrite t 1 to t 2 rewrite t 1 to t 2

18 Advices component Constant is Exp where syntax = [[ n:number ]] semantics = give n aspect A { change semantics x to | complete and then | x } Weaving component Constant is Exp where syntax [[ n:number ]] semantics | complete and then | give n

19 Pointcuts Constrains the advices Constrains the advices Examples of pointcuts: Examples of pointcuts: The advice acts in specific components The advice acts in specific components inside c do a The advice needs a runtime condition to be enabled. The advice needs a runtime condition to be enabled. a when c

20 Advices component Constant is Exp where syntax = [[ n:number ]] semantics = give n component Identifier is Exp where syntax = [[ i:Identifier ]] semantic = give the integer bound to i aspect A { inside Identifier change semantics x to | complete and then | x } Weaving component Constant is Exp where syntax = [[ n:number ]] semantics = give n component Identifier is Exp where syntax = [[ i:Identifier ]] semantic = | complete then | give the integer bound to i

21 Example 1 Lazy Evaluation Aspect compoent Constant is Exp where syntax = [[ number ]] syntax = [[ number ]] semantics = give closure abstraction of give n semantics = give closure abstraction of give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] syntax = [[ a:Expression “+” b:Expression ]] semantics = semantics = give closure abstraction of ( give closure abstraction of ( (evaluate a and then evaluate b) (evaluate a and then evaluate b) then then (enact the given abstraction # 1 and then (enact the given abstraction # 1 and then enact the given abstraction #2) enact the given abstraction #2) then then give sum of them give sum of them ) Advice 1: Expressions gives functions instead values

22 Example 1 Lazy Evaluation Aspect compoent Constant is Exp where syntax = [[ number ]] syntax = [[ number ]] semantics = give closure abstraction of give n semantics = give closure abstraction of give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] syntax = [[ a:Expression “+” b:Expression ]] semantics = semantics = give closure abstraction of ( give closure abstraction of ( (evaluate a and then evaluate b) (evaluate a and then evaluate b) then then (enact the given abstraction # 1 and then (enact the given abstraction # 1 and then enact the given abstraction #2) enact the given abstraction #2) then then give sum of them give sum of them ) Advice 1: Inside Exp do change semantics from x to give closure abstraction of x

23 Example 1 Lazy Evaluation Aspect compoent Constant is Exp where syntax = [[ number ]] syntax = [[ number ]] semantics = give closure abstraction of give n semantics = give closure abstraction of give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] syntax = [[ a:Expression “+” b:Expression ]] semantics = semantics = give closure abstraction of ( give closure abstraction of ( (evaluate a and then evaluate b) (evaluate a and then evaluate b) then then (enact the given abstraction # 1 and then (enact the given abstraction # 1 and then enact the given abstraction #2) enact the given abstraction #2) then then give sum of them give sum of them ) Advice 2: Evaluate the abstraction before to execute data operations

24 Example 1 Lazy Evaluation Aspect compoent Constant is Exp where syntax = [[ number ]] syntax = [[ number ]] semantics = give closure abstraction of give n semantics = give closure abstraction of give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] syntax = [[ a:Expression “+” b:Expression ]] semantics = semantics = give closure abstraction of ( give closure abstraction of ( (evaluate a and then evaluate b) (evaluate a and then evaluate b) then then (enact the given abstraction # 1 and then (enact the given abstraction # 1 and then enact the given abstraction #2) enact the given abstraction #2) then then give sum of them give sum of them ) Advice 2: inside Exp do rewrite give op(a) to evaluateLazyData in a then give op(them)

25 Example 1 Lazy Evaluation Aspect compoent Constant is Exp where syntax = [[ number ]] syntax = [[ number ]] semantics = give n semantics = give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] syntax = [[ a:Expression “+” b:Expression ]] semantics = semantics = (evaluate a and then evaluate b) (evaluate a and then evaluate b) then then give sum of them give sum of them aspect LazyEvaluation { Inside Exp do change semantics from x to give closure abstraction of x inside Exp do rewrite give op(a) to evaluateLazyData in a then give op(them)} weaving Lazy Expressions Language

26 Example 2 Static x Dynamic Binding Static Bindings Static Bindings component SB_FDecl is Decl where syntax [[ i:Id “()” c:Com ]] syntax [[ i:Id “()” c:Com ]] semantics semantics bind i to closure abstraction of bind i to closure abstraction of | semantics of c | semantics of c component SB_FCall is Com where syntax [[ i :Id “()” ]] syntax [[ i :Id “()” ]] semantics semantics enact the abstraction bound to i enact the abstraction bound to i Dynamic Bindings Dynamic Bindings component DB_FDecl is Decl where syntax [[ i:Id “()” c:Com ]] syntax [[ i:Id “()” c:Com ]] semantics semantics bind i to abstraction of bind i to abstraction of | semantics of c | semantics of c component DB_FCall is Com where syntax [[ i :Id “()” ]] syntax [[ i :Id “()” ]] semantics semantics enact closure the abstraction bound to i enact closure the abstraction bound to i aspect StaBind { rewrite abstraction of x to closure abstraction of x } aspect DynBind { rewrite enact ~x to enact closure ~x }

27 Example 2 Static x Dynamic Binding component FDecl is Decl where syntax [[ i:Id “()” c:Com ]] semantics bind i to abstraction of | semantics of c component FCall is Com where syntax [[ i :Id “() ]] semantics enact the abstraction bound to i aspect StaBind { rewrite abstraction of x to closure abstraction of x } aspect DynBind { rewrite enact ~x to enact closure ~x } weaving Language with Static Bindings Language with Dynamic Bindings

28 Conclusions Aspects are useful to describe some programming language concepts improve the modularity describe Aspects are useful to describe some programming language concepts improve the modularity describe Component libraries become more generic Component libraries become more generic Future research in this topic includes Future research in this topic includes Implementation of tools Implementation of tools Define new aspect operators and applications to programming language research Define new aspect operators and applications to programming language research Design an aspect-oriented library of PL concepts Design an aspect-oriented library of PL concepts

29 Aspect-Oriented Action Semantics Descriptions Luis Menezes University of Pernambuco (lcsm@dsc.upe.br)


Download ppt "Aspect-Oriented Action Semantics Descriptions Luis Menezes University of Pernambuco"

Similar presentations


Ads by Google