Presentation is loading. Please wait.

Presentation is loading. Please wait.

JAOO 2002olm1 Early Experience with Language Interoperability Porting the BETA language to Java and.NET Peter Andersen Ole Lehrmann Madsen Center for Pervasive.

Similar presentations


Presentation on theme: "JAOO 2002olm1 Early Experience with Language Interoperability Porting the BETA language to Java and.NET Peter Andersen Ole Lehrmann Madsen Center for Pervasive."— Presentation transcript:

1 JAOO 2002olm1 Early Experience with Language Interoperability Porting the BETA language to Java and.NET Peter Andersen Ole Lehrmann Madsen Center for Pervasive Computing Aarhus University

2 JAOO 2002olm2 Content n Background & goals n Virtual machines u The Java- and.NET platforms n BETA n Mapping BETA to Java and.NET n Experience with the platforms n Language interoperability n Demo n Conclusion

3 JAOO 2002olm3 Background n Modern language implementations: u Virtual machines u Bytecode u Just-in-time compilers u Run-time type information u Verification of code before execution n Main stream platforms u Java virtual machines u Microsoft.NET

4 JAOO 2002olm4 Main stream OO languages n Java u The one and only language for the Java-platform n C# and VB.Net u The dominant languages for.NET n A family of languages u Java/C#-like languages u And many more

5 JAOO 2002olm5 Goals I n Implement BETA for u.NET u Java-VM n Investigate the suitability of Java and.NET as platforms for general language implementation

6 JAOO 2002olm6 Goals II n Investigate language interoperability n Traditional language interoperability for procedural languages u Procedure libraries in different languages u Common calling sequence for procedures n Language interoperability for OO languages u Uses of classes from different languages u Inheritance from classes in different languages u An explicit goal for.NET u No expectations for Java

7 JAOO 2002olm7 Goals III n Provide a common language for.NET and Java-VM n (Component architecture) u Web services – SOAP n (BETA for PDA’s) u.NET compact framework

8 JAOO 2002olm8 Challenges I Mapping of BETA to.NET & Java-VM n. NET & Java-VM are typed virtual machines modelled from Java and C# n BETA is much more general n One issue: just finding a mapping

9 JAOO 2002olm9 Challenges II Language interoperability n BETA should be able to uses classes from other languages n Other languages should be able to use BETA classes (patterns) n BETA should be able to inherit classes from other languages n Other languages should be able to inherit from BETA n The BETA mapping should be ’nice’ when seen from other languages

10 JAOO 2002olm10 Java/C# language model n A program is a collection of classes n A class defines u Data-items/attributes F an attribute has a type u Methods F a method has arguments and a possible result value n Classes may be nested u Java – real nesting u C# - only a scope mechanism n No nesting of methods n Dynamic exceptions n Concurrency in the form of threads

11 JAOO 2002olm11 BETA n Class and method unified into the pattern mechanism n General nesting of patterns n INNER instead of super n Genericity in the form of virtual patterns n Multiple return values n Active objects u Coroutines and concurrency u Basis for writing schedulers n No constructors n No dynamic exceptions (yet)

12 JAOO 2002olm12 Challenges with BETA mapping n Pattern mapping to class and methods n Nested patterns n Nested procedures n Enter-do –exit-semantics n Inner n Virtual patterns – class and procedure n Multiple return values n Leave/restart out of nested method activations n Coroutines and concurrency n Pattern variables n Basic values – signed/unsigned

13 JAOO 2002olm13 The mapping n Generating code for Java- and.NET corresponds to making a BETA source mapping into Java- and/or C#-source code n In the following the implementation of BETA is shown as a mapping into a Java/C#-like language

14 JAOO 2002olm14 BETA example Calc: (# R: @integer; set: (# V: @integer enter V do V  R #); add: (# V: @integer enter V do R+V  R exit R #); #); C: @Calc; X: @integer; 12  C.set; 5  C.add  X

15 JAOO 2002olm15 Naive mapping into Java/C# Class Calc extends Object { int R; void set(int V) { R = V; }; int add(int V) { R = R + V; return R;} } Calc C = new Calc(); int X; C.set(12); X = C.add(5);

16 JAOO 2002olm16 Instances of add C: @Calc; X: @integer; A: ^C.add; &C.add[]  A[]; 6  A  X More complex mapping needed Possible to create instances of pattern add Creation of an instance of C.add

17 JAOO 2002olm17 Class add class add extends Object { Calc origin ; int V; void add(Calc org) {origin = org; } void enter(int a) { V = a; } void do() { origin.R = origin.R + V }; int exit() { return origin.R; } } add A; int X; A = new add(C); A.enter(5); A.do() X = A.exit(); C: @Calc; X: @integer; 12  C.set; 5  C.add  X

18 JAOO 2002olm18 Calc with call-add operation Class Calc extends Object { int R; void set(int V) { R = V; }; int add(int V) { add A; A = new add(this); A.enter(V); A.do() return A.exit(); } Calc C = new Calc(); int X; C.set(12); X = C.add(5); We hope the JIT compilers inlines these calls!

19 JAOO 2002olm19 Calc with call-add & new-add Class Calc extends Object { int R; void set(int V) { R = V; }; int add(int V) {...; return A.exit(); } add add () { return new add(this); } } Calc C = new Calc(); int X; add C.A; C.set(12); X = C.add(5); A = C.add(); Call method for add New method for add

20 JAOO 2002olm20 General scheme myClass: (#...; f1: (#... #); f2: (#... #); f3: (#... #) #) class myClass extends Object {...; T1 f1(...) {... } // call f1 f1 f1() {... } // new f1 T2 f2(...) {... } // call f2 f2 f2() {... } // new f2 T3 f3(...) {... } // call f3 f3 f3() {... } // new f3 }

21 JAOO 2002olm21 With language restrictions myClass: class (#...; f1: proc(#... #); f2: proc(#... #); T: class(#... #) #) class myClass extends Object {...; T1 f1(...) {... } // call f1 T2 f2(...) {... } // call f2 T T() {... } // new T }

22 JAOO 2002olm22 Nested/inner classes in general A: (#... AA: (#... AAA: (#... #) #) class A extends Object {... }; class AA extends Object { A origin, void AA(A org) { origin = org; } } class AAA extends Object { AA origin; void AAA(AA org) { origin = org; } } origin A-object AA-object AAA-object origin

23 JAOO 2002olm23 Method combination with inner Calc: (#... add: (# V: @integer enter V do R+V  R; inner exit R #);... #) Xcalc: Calc (# xadd: add (# do R * V  R #) #)

24 JAOO 2002olm24 Semantics of inner D: @Xcalc; X: @integer 12  D.set; 5  D.xadd  X add: (# V: @integer enter V do R+V  R; inner exit R #); xadd: add (# do R * V  R #) 5  D.add.V R + V  R inner R * V  R return D.R  X

25 JAOO 2002olm25 Class add with inner class add extends Object {... void do() { origin.R = origin.R + V; do_1(); // inner }; void do_1(); } class xadd extends add {... void do_1() { origin.R = origin.R * V; };... }

26 JAOO 2002olm26 Inner at several levels A: (# do X1; inner; Y1 #); AA: A (# do X2; inner; Y2 #); AAA: AA(# do X3; inner; Y3 #) class A: extends Object { void do() { X1; do_1(); Y1; }; void do_1() } class AA: extends A { void do_1() { X2; do_2(); Y2; }; void do_2() } class AAA: b AA { void do_2() { X3; do_3(); Y3 }; void do_3() }

27 JAOO 2002olm27 Virtual patterns n BETA has virtual patterns n Virtual patterns used as virtual procedures u Like virtual methods in Java/C# n Virtual patterns used as virtual classes u A mechanism for defining a class parameterized by another class n No counter parts in Java/C# u Proposal on its way for Java

28 JAOO 2002olm28 Pattern List List: (# element:< Object; insert: (# e: ^element enter e[] do... #);... #) StudentList: List (# element::< Student; #) L: @List; aPerson[]  L.insert; aStudent[]  L.insert; S: @StudentList; aPerson[]  S.insert; aStudent[]  S.insert; Illegal Detected by the BETA compiler

29 JAOO 2002olm29 Virtual class in Java/C# class List extends Object {... void insert(Object e) {... } } class StudentList extends List {... void insert(Object e) { Student e1 = (Student) e;... }

30 JAOO 2002olm30 Multiple return values Calc: (# R,Rx: @integer;...; getReg: (# exit(R,Rx) #); #); C: @Calc; x,y: @integer; C.getReg  (x,y); A field is added to the class for each return value At the calling site, the exit fields are fetched

31 JAOO 2002olm31 Leave/restart of nested method calls To be implemented using dynamic exceptions foo: (# do L: (# bar: (# do leave L #); go: (# do restart L #) do (if b then bar else go if) #) #);

32 JAOO 2002olm32 Remaining issues n Active objects u Coroutines and concurrency n Pattern variables u Classes and methods as first-class values n Basic values – signed/unsigned n And lots of details

33 JAOO 2002olm33 Compiler organization n Frontend u Parser, abstract syntax trees, semantic checking, semantic analysis, abstract code generation u Platform independent n Backend u Code generation for a specific target u Platform dependent F Sun Solaris F Linux F Windows F Macintosh

34 JAOO 2002olm34 Compiler reorganization n Frontend u Generate (typed) stack code n Backend u Abstract stack code u Specific targets F.NET F Java-VM

35 JAOO 2002olm35 Platform issues I n No static link on stack frames u Nested procedures/methods cannot be implemented using the stack n Very rigid typing of class-fields u And method-locals on.NET n Constructor initialization u Impossible to make setups before calling super constructor n General exit out of nested method calls n No support for covariant arguments n No support for covariant return types n Active objects

36 JAOO 2002olm36 Platform issues II n.NET class references must be fully qualified, including location of binding u Problems with separate compilation n Large number of classes generated due to the generality of BETA patterns u Java class files can only contain one (non-static) class per file u Lots of class files are generated n.NET assemblies can contain any number of classes

37 JAOO 2002olm37 Platform issues III (minor) n No swap and dup_x1/x2 on.NET n Requirements for fully typed local variables in.NET. u Means that swap cannot be implemented in backend using local variables unless type of two top-of- stack objects are known. n Type of field: super/this class

38 JAOO 2002olm38 Platform advantages n Well-defined run-time format u More than just a calling convention for procedures n Memory management u Storage allocation u Object format & method activation format u Garbage collection n Efficient code generation n We will have BETA for all Java- and.NET platforms n Can this be utilized efficiently? u If simple and direct mapping – yes u If complex mapping – no? u Inlining may help F Can rely on generating methods that the JIT inlines

39 JAOO 2002olm39 Language interoperability I n Java/C# class inherited from BETA u Straight forward u Since name & type-based, F just specify the methods you will use u Simpler than for COM F COM uses offsets F All preceding methods must be declared n BETA pattern inherited from Java/C# class u Also straight forward u Issues with default constructor F BETA object requires surrounding object (origin)

40 JAOO 2002olm40 Language interoperability II n Issues u Libraries and frameworks in Java/C# u Java-string, C#-String, BETA-text F Automatic coercion implemented u Overloading u Constructors n External class interface u Interface syntax needed – currently clumsy u External name & location u Automatic include of interface files F.NET assemblies F Java class-files

41 JAOO 2002olm41 Demo n Inheritance in BETA of external class u Java Applet n Inheritance of BETA pattern in Java and C# n Implementation of program using Google web-service u In C# and Java n Debugging of Google search in Visual Studio.Net

42 JAOO 2002olm42 Conclusion n Not trivial to map all parts of BETA n We still need to measure efficiency n Generation of bytecode: straightforward u Java issue: no standard assembler n Generation of type information: a lot of work n No real problems in supporting both platforms n Use of Visual Studio to edit and debug BETA programs u Impressive u Source level debugging, breakpoints, object-inspection,...

43 JAOO 2002olm43 Language interoperability n. NET/C#: seems to work as promised u Class instance u Inheritance u Visual Studio n Java: works well too – to our surprise u Class instance u Inheritance u Has not found any (free) SDE’s that work as well as Visual Studio (which is expensive, but stand alone graphical debugger part of free.NET framework) n It seems realistic to mix libraries and frameworks from different languages n Easier to introduce new languages

44 JAOO 2002olm44 BETA Language changes n Constructors n Restricting a pattern as class or method n Add properties as in C# n Issue with super/inner call sequencing n Overloading?

45 JAOO 2002olm45 Status n Large subset of BETA has been implemented n To be done u General leave/restart u Active objects u Pattern variables u Lots of details u Porting BETA libraries and frameworks to Java and.NET

46 JAOO 2002olm46 Acknowledgements n Peter Andersen - datpete@daimi.au.dkdatpete@daimi.au.dk n Ole Lehrmann Madsen - olm@daimi.au.dkolm@daimi.au.dk n Project in u Center for Pervasive Computing u www.pervasive.dk www.pervasive.dk n Supported by u Microsoft Denmark u Sun Microsystems Denmark n Ideas borrowed from u Kresten Krab Thorup u Henry Michael Lassen u Kim Falk Jørgensen


Download ppt "JAOO 2002olm1 Early Experience with Language Interoperability Porting the BETA language to Java and.NET Peter Andersen Ole Lehrmann Madsen Center for Pervasive."

Similar presentations


Ads by Google