Inter-Language Reflection

582 views

Published on

Inter-Language Reflection. Kris Gybels, Roel Wuyts, Maja D’Hondt, Stéphane Ducasse. ESUG 2005, Bruessels

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
582
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Inter-Language Reflection

  1. 1. Brussels ESUG 2005 Inter-Language Reflection Stéphane Ducasse Maja D’Hondt Roel Wuyts Kris Gybels
  2. 2. Executive Summary 2 Inter-Language Reflection = Linguistic Symbiosis + Reflection SOUL ↭ Smalltalk Agora ↭ Java
  3. 3. Meta-Programming: A Review 3 Programming Tools ▾ Meta Programming = “Programs about programs”
  4. 4. Base Program Different Base and Meta Languages 4 Meta Program TyRuBa Java
  5. 5. No Causal Connection 5 class Leaf extends Node { void accept(Visitor v) { v.visitLeaf(this); } } class Visitor { void visitLeaf(Leaf l); void visitBranch(Branch b); } class(Leaf, Node). class(Branch, Node). class(Visitor, Object). method(Leaf,accept, ...). method(Node,visitLeaf, ...). ... doubleDispatch(Class,Method) :- ... visitor(Class) :- ...
  6. 6. Reflection 6 MyOwnClass>>makeNewMethod: unarySelector MyOwnClass compile: unarySelector asString ^ MyOwnClass selectors size MyOwnClass class>>compile: ... MyOwnClass class>>selectors ...
  7. 7. Introducing Inter-Language Reflection 7 Inter-Language Reflection Different Languages Causal Connection Multi-Paradigm Meta Programming Different Languages No Causal Connection TyRuBa ↭ Java Reflection Single Language Causal Connection Smalltalk
  8. 8. SOUL 8 MyOwnClass class(?c) if var(?c), member(?c, [ Class allInstances ]). class(?c) if nonvar(?c) [ ?c isKindOf: Class ] sends(?c, ?rec, ?sends) if class(?c), method(?c, ?m), sendsTo(?m, ?rec, ?sends). generateEmptyMethod(?class, ?name) if emptyMethodSource(?name, ?source), [(?class compile: ?source) = nil]
  9. 9. Understanding Inter-Language Reflection? 9 Smalltalk SOUL Java Agora C++ RBCL Implementation ??? SOUL Smalltalk Conceptual Model ↻ ↻ = Data Mapping Protocol Mapping ▾
  10. 10. Data Mapping in Agora: Example 10 frame VARIABLE: ("java.awt.Frame" JAVA) new; ok VARIABLE: ("java.awt.Button" JAVA) newString: "OK"; frame addComponent: ok; okListener VARIABLE: [ implements METHOD: (1 ARRAY: ("java.awt.event.ActionListener" JAVA)); replaces METHOD: ("java.lang.Object" JAVA); actionPerformedActionEvent: e METHOD: { ("java.lang.System" JAVA) out printlnString: "Button Pressed!"; frame setVisibleboolean: false } ]; ok addActionListenerActionListener: okListener
  11. 11. Data Mapping in SOUL 11 productcustomer if customer is loyal then customer has 10% discount customer is loyal if customer has charge card business rules business objects cross-language method / rule triggering cross-language value exchange
  12. 12. Data Mapping in SOUL 12 Product>>priceFor: aCustomer | discounts | discounts := (SOULEvaluator evaluate: 'discount(?customer, ?product, ?discount)' withArguments: (Array with: #customer -> aCustomer with: #product -> self)) valuesForVariable: #discount. ^ price * (100 - discounts max) / 100 discount(?customer, ?product, 10) if loyal(?customer). discount(?customer, ?product, 15) if student(?customer), educationalProduct(?product). loyal(?customer) if [ ?customer hasChargeCard ]. educationalProduct(?product) if equals(?sectionitems, [ Section education products ]), [ ?sectionitems includes: ?product ]
  13. 13. Protocol Mappings 13 Common Implementation Language Language A Language B right left left right
  14. 14. Agora ↭ Java 14 send(“message”, {type1, ... typen}, {arg1, ... argn}) ⇕ == result == left[result] send(“messageType1Name:...TypenName:”, {right[arg1], ... right[argn]}) actionPerformedActionEvent: actionPerformed left[right[x]] = x
  15. 15. SOUL ↭ Smalltalk 15 lo1 unify: lo2 right[lo1] send: #= withArguments: { right[lo2] } ⇕
  16. 16. Implementation Mapping 16 Language B Language A
  17. 17. Implementation Protocol Mapping 17 receiver.name(argument1, … argumentn) == right[result] left[receiver].send("nameType1Name:…typenName", {left[argument1], …left[argumentn]}) == result
  18. 18. Conclusion 18 Multi-Paradigm Meta Programming Reflection Inter-Language Reflection Different Languages Causal Connection = Reflection + Linguistic Symbiosis Data Mapping Protocol Mapping ▾

×