What is COP Problem description COP formalization A Semantics for Context-Oriented Programming with Layers Dave Clarke and Ilya Sergey Katholieke Universiteit Leuven {Dave.Clarke,Ilya.Sergey}@cs.kuleuven.be International workshop on Context-Oriented Programming at ECOOP’09 7 July 2009 Ilya Sergey COP with Layers
What is COP Problem description COP formalization Why yet another semantics for COP? Ilya Sergey COP with Layers
What is COP COP definition Problem description Some of COP implementations COP formalization COP definition Context-oriented programming (COP) is a programming approach whereby the context in which expressions evaluate can be adapted as a program runs Ilya Sergey COP with Layers
What is COP COP definition Problem description Some of COP implementations COP formalization COP key features Context-dependent evaluation Explicit context Context manipulation Ilya Sergey COP with Layers
What is COP COP definition Problem description Some of COP implementations COP formalization COP key features Context-dependent evaluation Explicit context Context manipulation Ilya Sergey COP with Layers
What is COP COP definition Problem description Some of COP implementations COP formalization COP key features Context-dependent evaluation Explicit context Context manipulation Ilya Sergey COP with Layers
What is COP COP definition Problem description Some of COP implementations COP formalization COP is implicitly (or explicitly) assumed in... Groovy LISP/Clojure Ruby Objective C ContextJ, ContextL Lasagne Ambience CaesarJ Ilya Sergey COP with Layers
What is COP COP definition Problem description Some of COP implementations COP formalization Example: with , without and proceed in action Enhanced ContextJ class Actor { without (Logging) { stealth(); } void act () { ... without(Logging) { stealth (); } class D void act() {...} void stealth() {...} } } procced() layer Logging { class Actor { void act () { layer Logging void act() {...} proceed (); println( "Acted" ); } act() } } with (Logging){ new Actor().act()} with (Logging) { (new Actor ()). act (); } Ilya Sergey COP with Layers
What is COP Problem description Possible pitfalls COP formalization Problems to solve What is the order of expression evaluation for COP language? There is a big step semantics (Schippers et al.) How to ensure that all method invocations are resolved at runtime? Are statically-defined methods overridden correctly at runtime? Ilya Sergey COP with Layers
What is COP Problem description Possible pitfalls COP formalization Problems to solve What is the order of expression evaluation for COP language? There is a big step semantics (Schippers et al.) How to ensure that all method invocations are resolved at runtime? Are statically-defined methods overridden correctly at runtime? Ilya Sergey COP with Layers
What is COP Problem description Possible pitfalls COP formalization Problems to solve What is the order of expression evaluation for COP language? There is a big step semantics (Schippers et al.) How to ensure that all method invocations are resolved at runtime? Are statically-defined methods overridden correctly at runtime? Ilya Sergey COP with Layers
What is COP Problem description Possible pitfalls COP formalization Problems to solve What is the order of expression evaluation for COP language? There is a big step semantics (Schippers et al.) How to ensure that all method invocations are resolved at runtime? Are statically-defined methods overridden correctly at runtime? Ilya Sergey COP with Layers
What is COP Problem description Possible pitfalls COP formalization Problems to solve What is the order of expression evaluation for COP language? There is a big step semantics (Schippers et al.) How to ensure that all method invocations are resolved at runtime? Are statically-defined methods overridden correctly at runtime? Ilya Sergey COP with Layers
What is COP Problem description Possible pitfalls COP formalization We need an operational semantics with the sound type system ! Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A What is ContextFJ ContextFJ is a language to describe core features of the Context-Oriented programming Based on Featherweight Java Has layers as dedicated language constructs Includes proceed , with and without statements Has no inheritance and subtyping Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A ContextFJ syntax: Terms and Contexts Terms t ::= x | t.f | t.m L ( t ) | new C ( t ) | with ( l ) t | without ( l ) t | proceed ( t ) Values v ::= new C ( v ) Evaluation Contexts E [ ] ::= [ ] | E [[ ] .f ] | E [[ ] .m L ( t )] | E [ v.m L ( v, [ ] , t )] | E [ new C ( v, [ ] , t )] | E [ with ( l )[ ]] | E [ without ( l )[ ]] Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A ContextFJ syntax: layers and method bindings Layer definition L layer l { B } ::= Method bindings ( m, C 0 ) �→ M B ::= Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A Evaluation: bound methods Bound methods ∅ BM L ([ ]) = 9 BM L ( E [[ ] .f ]) > BM L ( E [[ ] .m ( t )]) = = BM L ( E ) BM L ( E [ v.m ( v, [ ] , t )]) > BM L ( E [ new C ( v, [ ] , t )]) ; ( BM L ( E ) , if l ∈ L BM L ( E [ with ( l )[ ]]) = BM L ( E ) ∪ dom( l ) , otherwise BM L ( E [ without ( l )[ ]]) = BM L ∪{ l } ( E ) Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A Evaluation: excluded layers Excluded layers XL ([ ]) = ∅ XL ( E [[ ] .f ]) 9 XL ( E [[ ] .m ( t )]) > > = XL ( E [ v.m ( v, [ ] , t )]) = XL ( E ) XL ( E [ new C ( v, [ ] , t )]) > > ; XL ( E [ with ( l )[ ]]) XL ( E [ without ( l )[ ]]) = { l } ∪ XL ( E ) Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A Reduction rules (1) (E-With) E [ with ( l ) v ] → E [ v ] (E-Without) E [ without ( l ) v ] → E [ v ] Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A Reduction rules (2) (E-InvkLayer) lmbody ( l, m, C ) = ( x, t ) ∈ BM L ( E ′ ) ∈ XL ( E ′ ) ( m, C ) / l / E [ with ( l ) E ′ [( new C ( v )) .m L ( u )]] → E [ with ( l ) E ′ [ { x �→ u, proceed �→ this .m L ∪{ l } , this �→ new C ( v ) } t ]] (E-InvkClass) ( m, C ) / ∈ BM L ( E ) mbody ( m, C ) = ( x, t ) E [ new C ( v )) .m L ( u )] → E [ { x �→ u, this �→ new C ( v ) } t ] Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A Example: evaluation layer l 1 { class C { D m () { return proceed (); } }} layer l 2 { class D { C n () { return new C (); } }} class C { D m () { return new D (); }} class D {} with ( l 1 ) { with ( l 2 ) { new C () .m () .n () }} → with ( l 1 ) { with ( l 2 ) { new C () .m { l 1 } () .n () }} → with ( l 1 ) { with ( l 2 ) { new D () .n () }} → with ( l 1 ) { with ( l 2 ) { new C () } } → with ( l 1 ) { new C () } → new C () Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A Type system outline Some methods need other undefined methods of specific types to be evaluated - requirements Before invoke method we should satisfy its requirements Layers provide new methods and require some other ones Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A Type system outline Some methods need other undefined methods of specific types to be evaluated - requirements Before invoke method we should satisfy its requirements Layers provide new methods and require some other ones Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A Type system outline Some methods need other undefined methods of specific types to be evaluated - requirements Before invoke method we should satisfy its requirements Layers provide new methods and require some other ones Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A ContextFJ syntax again: method definitions Method definition M ::= C [Ψ] m ( C x ) { return t ; } Method requirements Ψ ::= ǫ | MT, Ψ Method types MT ::= ( m, C 0 ) �→ [Ψ] C → C • L Excluded layers L ::= a set of layer names | ⊤ ( ∀ L.L ⊆ ⊤ ) Ilya Sergey COP with Layers
ContextFJ What is COP Syntax Problem description Dynamic semantics COP formalization Type system Q&A Method types demystified ( m, C 0 ) �→ [Ψ] C → C • L m is a method’s name; C 0 is a receiver class type; C are parameter types; and C is the result type; L is the set of excluded layers Ψ is a set of method requirements Ilya Sergey COP with Layers
Recommend
More recommend