event type polymorphism
play

Event Type Polymorphism Rex D. Fernando Robert Dyer Hridesh Rajan - PowerPoint PPT Presentation

Event Type Polymorphism Rex D. Fernando Robert Dyer Hridesh Rajan Department of Computer Science Iowa State University { fernanre,rdyer,hridesh } @iastate.edu This work was supported in part by NSF grant CCF-10-17334. Overview Motivation


  1. Event Type Polymorphism Rex D. Fernando Robert Dyer Hridesh Rajan Department of Computer Science Iowa State University { fernanre,rdyer,hridesh } @iastate.edu This work was supported in part by NSF grant CCF-10-17334.

  2. Overview Motivation Language Summary ◮ Motivation: Code re-use and specialization for event-based separation of concerns ◮ Approach: Event Type Polymorphism in Ptolemy ◮ Technical Contributions: ◮ Formal semantics for event type polymorphism ◮ Simpler semantics, when compared to earlier work Rex D. Fernando, Robert Dyer and Hridesh Rajan 1 Event Type Polymorphism

  3. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary AST MultExp DivExp NumExp NumExp NumExp Rex D. Fernando, Robert Dyer and Hridesh Rajan 2 Event Type Polymorphism

  4. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary AST Events MultExp MultVisited DivExp NumExp NumExp NumExp C E class C announces event E Rex D. Fernando, Robert Dyer and Hridesh Rajan 2 Event Type Polymorphism

  5. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary AST Events MultExp MultVisited DivVisited DivExp NumExp NumExp NumExp C E class C announces event E Rex D. Fernando, Robert Dyer and Hridesh Rajan 2 Event Type Polymorphism

  6. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary AST Events MultExp MultVisited DivVisited DivExp NumExp NumVisited NumExp NumExp C E class C announces event E Rex D. Fernando, Robert Dyer and Hridesh Rajan 2 Event Type Polymorphism

  7. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary AST Events Handlers MultExp MultVisited Tracing DivVisited DivExp TypeCheck NumExp Evaluation NumVisited NumExp NumExp C E class C announces event E E H event E's announcement invokes handler H Rex D. Fernando, Robert Dyer and Hridesh Rajan 2 Event Type Polymorphism

  8. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary AST Events Handlers MultExp MultVisited Tracing DivVisited DivExp TypeCheck NumExp Evaluation NumVisited NumExp NumExp C E class C announces event E E H event E's announcement invokes handler H Rex D. Fernando, Robert Dyer and Hridesh Rajan 2 Event Type Polymorphism

  9. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary AST Events Handlers MultExp MultVisited Tracing DivVisited DivExp TypeCheck NumExp Evaluation NumVisited NumExp NumExp C E class C announces event E E H event E's announcement invokes handler H Rex D. Fernando, Robert Dyer and Hridesh Rajan 2 Event Type Polymorphism

  10. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary MultVisited DivVisited PlusVisited <event> <event> <event> + node : MultExp + node : DivExp + node : PlusExp + left : Exp + left : Exp + left : Exp + right : Exp + right : Exp + right : Exp Rex D. Fernando, Robert Dyer and Hridesh Rajan 3 Event Type Polymorphism

  11. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary MultVisited DivVisited PlusVisited <event> <event> <event> + node : MultExp + node : DivExp + node : PlusExp + left : Exp + left : Exp + left : Exp + right : Exp + right : Exp + right : Exp Rex D. Fernando, Robert Dyer and Hridesh Rajan 3 Event Type Polymorphism

  12. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary MultVisited DivVisited PlusVisited <event> <event> <event> + node : MultExp + node : DivExp + node : PlusExp + left : Exp + left : Exp + left : Exp + right : Exp + right : Exp + right : Exp Rex D. Fernando, Robert Dyer and Hridesh Rajan 3 Event Type Polymorphism

  13. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary class ASTTracer { void printMult(MultVisited next) { logVisitBegin(next.node ().getClass ()); next.invoke (); logVisitEnd(next.node ().getClass ()); } when MultVisited do printMult; void printDiv(DivVisited next) { logVisitBegin(next.node ().getClass ()); next.invoke (); logVisitEnd(next.node ().getClass ()); } when DivVisited do printDiv; void printPlus(PlusVisited next) { logVisitBegin(next.node ().getClass ()); next.invoke (); logVisitEnd(next.node ().getClass ()); } when PlusVisited do printPlus; } Rex D. Fernando, Robert Dyer and Hridesh Rajan 4 Event Type Polymorphism

  14. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary class ASTTracer { void printMult(MultVisited next) { logVisitBegin(next.node ().getClass ()); next.invoke (); logVisitEnd(next.node ().getClass ()); } when MultVisited do printMult; void printDiv(DivVisited next) { logVisitBegin(next.node ().getClass ()); next.invoke (); logVisitEnd(next.node ().getClass ()); } when DivVisited do printDiv; void printPlus(PlusVisited next) { logVisitBegin(next.node ().getClass ()); next.invoke (); logVisitEnd(next.node ().getClass ()); } when PlusVisited do printPlus; } Rex D. Fernando, Robert Dyer and Hridesh Rajan 5 Event Type Polymorphism

  15. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary ◮ Can we re-use code here? ◮ What happens if a new AST type is added? ◮ What happens if an AST type is removed? Rex D. Fernando, Robert Dyer and Hridesh Rajan 6 Event Type Polymorphism

  16. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary ◮ Can we re-use code here? ◮ No! Passing event closures ( next ) as argument is illegal. (to simplify reasoning about invoke /proceed functionality) ◮ What happens if a new AST type is added? ◮ What happens if an AST type is removed? Rex D. Fernando, Robert Dyer and Hridesh Rajan 6 Event Type Polymorphism

  17. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary ◮ Can we re-use code here? ◮ No! Passing event closures ( next ) as argument is illegal. (to simplify reasoning about invoke /proceed functionality) ◮ What happens if a new AST type is added? ◮ Must update all handlers to support that node type! ◮ What happens if an AST type is removed? Rex D. Fernando, Robert Dyer and Hridesh Rajan 6 Event Type Polymorphism

  18. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary ◮ Can we re-use code here? ◮ No! Passing event closures ( next ) as argument is illegal. (to simplify reasoning about invoke /proceed functionality) ◮ What happens if a new AST type is added? ◮ Must update all handlers to support that node type! ◮ What happens if an AST type is removed? ◮ Must update all handlers and remove that node type! Rex D. Fernando, Robert Dyer and Hridesh Rajan 6 Event Type Polymorphism

  19. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary ◮ Can we re-use code here? ◮ No! Passing event closures ( next ) as argument is illegal. (to simplify reasoning about invoke /proceed functionality) ◮ What happens if a new AST type is added? ◮ Must update all handlers to support that node type! ◮ What happens if an AST type is removed? ◮ Must update all handlers and remove that node type! Polymorphism can help us here! Rex D. Fernando, Robert Dyer and Hridesh Rajan 6 Event Type Polymorphism

  20. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary ExpVisited <event> + node : Exp BinArithVisited <event> + node : BinArith + left : Exp + right : Exp MultVisited DivVisited PlusVisited <event> <event> <event> + node : MultExp + node : DivExp + node : PlusExp Rex D. Fernando, Robert Dyer and Hridesh Rajan 7 Event Type Polymorphism

  21. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary ExpVisited <event> + node : Exp BinArithVisited <event> + node : BinArith + left : Exp + right : Exp MultVisited DivVisited PlusVisited <event> <event> <event> + node : MultExp + node : DivExp + node : PlusExp Rex D. Fernando, Robert Dyer and Hridesh Rajan 7 Event Type Polymorphism

  22. Overview Motivation An Example - No Event Type Polymorphism Language Example Revisited - With Event Type Polymorphism Summary ExpVisited <event> + node : Exp BinArithVisited <event> + node : BinArith + left : Exp + right : Exp MultVisited DivVisited PlusVisited <event> <event> <event> + node : MultExp + node : DivExp + node : PlusExp Rex D. Fernando, Robert Dyer and Hridesh Rajan 7 Event Type Polymorphism

Recommend


More recommend