290 likes | 426 Views
Aspect-Oriented Action Semantics Descriptions. Luis Menezes University of Pernambuco (lcsm@dsc.upe.br). Agenda. Action Semantics Aspect-oriented Programming Aspect-oriented Action Semantics Conclusions. Action Semantics. Formalism to describe programming languages Action Notation
E N D
Aspect-Oriented Action Semantics Descriptions Luis Menezes University of Pernambuco (lcsm@dsc.upe.br)
Agenda • Action Semantics • Aspect-oriented Programming • Aspect-oriented Action Semantics • Conclusions
Action Semantics • Formalism to describe programming languages • Action Notation • concepts of programming languages • Based on English terms (intuitive) • Hides the modeled concepts complexity
Action Semantics • 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
Action Semantics Descriptions • Originally AS descriptions are formed by: • Abstract Syntax • Semantic Functions • Semantic Entities • This organization separates the description of each PL concept in these modules.
Modular Extensions • Proposed to increase the modularity of AS descriptions • Object Oriented AS, Component AS, Modular AS • Descriptions formed by a set of language elements • Each element has syntax and semantics. • Facilitates the identification where the PL elements are defined.
Syntax-less Concepts • Action Semantics descriptions translates syntactical elements into action notation. • Some programming language concepts are not represented by textual code in programs. • For example: • The code: • f(1 + x) / y • can be used by lazy or eager programming language • Action Semantics Descriptions can not isolate their descriptions in separated modules • The semantics is described inside other features semantics
Example • Expressions language: component Constant is Exp where syntax = [[ n:number ]] semantics = give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] semantics = (evaluate a and then evaluate b) then give sum of them
Example • Lazy Expressions Language: component LazyConstant is Exp where syntax = [[ number ]] semantics = give abstraction of give n component LazySum is Exp where syntax = [[ a:Expression “+” b:Expression ]] semantics = give abstraction of ( (evaluate a and then evaluate b) then (enact the given abstraction # 1 and then enact the given abstraction #2) then give sum of them )
Traditional object-oriented system developing has a similar problem….
Crosscutting Concern • Crosscutting concern is a system feature that affects other concerns • They can not be implemented in a separated module • Difficult to insert/remove in complex systems
Crosscutting Concern • Example: Remote Databases: void transfer(Account src, Account dest, int amount) { if (!src.avaliable(amount)) throw new TransferError(); src.whitdraw(amount); dest.deposit(amount); }
Crosscutting Concern • Example: Remote Databases void transfer(Account src, Account dest, int amount) { try { DataBase d = connect(); d.openTransaction(); if (!src.avaliable(amount)) throw new TransferError(); d.rpc(whitdraw,src,amount); d.rpc(deposit,dest,amount); d.closeTransaction(); } catch (CommunicationError e) { d.undo(); throw new TransferError(); } }
Aspect-oriented Programming • Methodology designed to modularize the definition of crosscutting concerns • Aspects: • Identify points in the system code • Specify how these points are affected by the crosscutting concern implementation • Weaving Operation • Perform the modifications described by aspects
Weaving Operation • void transfer(Account src, Account dest, int amount) { • if (!src.avaliable(amount)) • throw new TransferError(); • src.whitdraw(amount); • dest.deposit(amount); • } aspect RemoteDataBase { ….. } Weaving • void transfer(Account src, Account dest, int amount) { • try { • DataBase d = connect(); • d.openTransaction(); • if (!src.avaliable(amount)) • throw new TransferError(); • d.rpc(whitdraw,src,amount); • d.rpc(deposit,dest,amount); • d.closeTransaction(); • } catch (CommunicationError e) { • d.undo(); • throw new TransferError(); • } • }
Aspect-oriented Action SemanticsDescriptions • Motivation: • Use aspects to improve the modularity of action semantics descriptions • Operators designed to support aspect-oriented concepts in action semantics
Advices • Specifies a modification in the specification • An advice can: • Modify the whole component semantics • change semantics from x to y • Rewrite a subterm inside the component semantics • rewrite t1 to t2
Advices aspect A { change semantics x to | complete and then | x } component Constant is Exp where syntax = [[ n:number ]] semantics = give n Weaving component Constant is Exp where syntax [[ n:number ]] semantics | complete and then | give n
Pointcuts • Constrains the advices • Examples of pointcuts: • The advice acts in specific components inside c do a • The advice needs a runtime condition to be enabled. a when c
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
Example 1Lazy Evaluation Aspect compoent Constant is Exp where syntax = [[ number ]] semantics = give closure abstraction of give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] semantics = give closure abstraction of ( (evaluate a and then evaluate b) then (enact the given abstraction # 1 and then enact the given abstraction #2) then give sum of them ) Advice 1: Expressions gives functions instead values
Example 1Lazy Evaluation Aspect compoent Constant is Exp where syntax = [[ number ]] semantics = give closure abstraction of give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] semantics = give closure abstraction of ( (evaluate a and then evaluate b) then (enact the given abstraction # 1 and then enact the given abstraction #2) then give sum of them ) Advice 1: Inside Exp do change semantics from x to give closure abstraction of x
Example 1Lazy Evaluation Aspect compoent Constant is Exp where syntax = [[ number ]] semantics = give closure abstraction of give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] semantics = give closure abstraction of ( (evaluate a and then evaluate b) then (enact the given abstraction # 1 and then enact the given abstraction #2) then give sum of them ) Advice 2: Evaluate the abstraction before to execute data operations
Example 1Lazy Evaluation Aspect compoent Constant is Exp where syntax = [[ number ]] semantics = give closure abstraction of give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] semantics = give closure abstraction of ( (evaluate a and then evaluate b) then (enact the given abstraction # 1 and then enact the given abstraction #2) then give sum of them ) Advice 2: inside Exp do rewrite give op(a) to evaluateLazyData in a then give op(them)
compoent Constant is Exp where syntax = [[ number ]] semantics = give n component Sum is Exp where syntax = [[ a:Expression “+” b:Expression ]] semantics = (evaluate a and then evaluate b) then 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) } Example 1Lazy Evaluation Aspect weaving Lazy Expressions Language
Static Bindings component SB_FDecl is Decl where syntax [[ i:Id “()” c:Com ]] semantics bind i to closure abstraction of | semantics of c component SB_FCall is Com where syntax [[ i :Id “()” ]] semantics enact the abstraction bound to i Dynamic Bindings component DB_FDecl is Decl where syntax [[ i:Id “()” c:Com ]] semantics bind i to abstraction of | semantics of c component DB_FCall is Com where syntax [[ i :Id “()” ]] semantics enact closure the abstraction bound to i Example 2Static x Dynamic Binding aspect DynBind { rewrite enact ~x to enact closure ~x } aspect StaBind { rewrite abstraction of x to closure abstraction of x }
Example 2Static 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 weaving Language with Static Bindings Language with Dynamic Bindings
Conclusions • Aspects are useful to describe some programming language concepts improve the modularity describe • Component libraries become more generic • Future research in this topic includes • Implementation of tools • Define new aspect operators and applications to programming language research • Design an aspect-oriented library of PL concepts
Aspect-Oriented Action Semantics Descriptions Luis Menezes University of Pernambuco (lcsm@dsc.upe.br)