2004-06-16pa 1 Porting BETA to ROTOR ROTOR Projects Presentation Day, June 16 2004 by Peter Andersen.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Delegates and Events.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
More about classes and objects Classes in Visual Basic.NET.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.
mbe/pa/olm 1 Integration of BETA with Eclipse eTX presentation Barcelona 2004 Peter Andersen Mads Brøgger Enevoldsen Ole Lehrmann Madsen.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Advanced Object-Oriented Programming Features
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Ch 13. Features Found Only in Java Timothy Budd Oregon State University.
2. Developing in.NET and C#. 2 Microsoft Objectives “Microsoft.NET development is based on an underlying framework of tools and classes. These tools and.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
C++ fundamentals.
Abstraction: Polymorphism, pt. 1 Abstracting Objects.
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
A Free sample background from © 2001 By Default!Slide 1.NET Overview BY: Pinkesh Desai.
+ Java vs. Javascript Jessi Style. + Java Compiled Can stand on its own Written once, run anywhere Two-stage debugging Java is an Object Oriented Programming.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
.NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Introduction to Java Prepared by: Ahmed Hefny. Outline Classes Access Levels Member Initialization Inheritance and Polymorphism Interfaces Inner Classes.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
2000 Jordan Anastasiade. All rights reserved. 1 Class In this lesson you will be learning about: Class. Inheritance. Polymorphism. Nested and.
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
We will talking about story of JAVA language. By Kristsada Songpartom.
Creational Pattern: Factory Method At times, a framework is needed to standardize the behavior of objects that are used in a range of applications, while.
C# Programming: From Problem Analysis to Program Design1 10 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Object Oriented Programming
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
Object Oriented Software Development 4. C# data types, objects and references.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
Classes, Interfaces and Packages
Wel come To Seminar On C#.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
2.7 Inheritance Types of inheritance
Inheritance and Polymorphism
Internet and Java Foundations, Programming and Practice
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Programming Language Concepts (CIS 635)
CS360 Windows Programming
Conditional Statements
Chapter 14 Abstract Classes and Interfaces
IS 135 Business Programming
Presentation transcript:

pa 1 Porting BETA to ROTOR ROTOR Projects Presentation Day, June by Peter Andersen

Rotor Presentation DayPeter Andersen The BETA programming language Object-oriented programming language  Scandinavian school of OO, starting with the Simula languages  Simple example: Calculator: (# set: (# enter V do V  R #); add: (# enter V do R+V  R exit R #); #); A pattern named Calculator Static instance variable named R Internal pattern named set with an input variable V Internal pattern named add with an input variable V and a return value named R

Rotor Presentation DayPeter Andersen BETA example use Calculator: (# set: (# enter V do V  R #); add: (# enter V do R+V  R exit R #); #); 5  C.add  X Use of add as a method: A: ^C.add; &C.add[]  A[]; 5  A  X Use of add as a class: Creation of an instance of C.add Execution of the C.add instance

Rotor Presentation DayPeter Andersen BETA vs. CLR/CLS Class and method unified in pattern General nesting of patterns, i.e. also of methods  Uplevel access to fields of outer patterns INNER instead of super Enter-Do-Exit semantics Genericity in the form of virtual patterns Multiple return values Active objects in the form of Coroutines No constructors, no overloading No dynamic exceptions

Rotor Presentation DayPeter Andersen BETA.Net/Rotor Challenges Mapping must be complete and semantically correct BETA should be able to uses classes from other languages Other languages should be able to use classes generated from BETA source code BETA should be able to inherit classes from other languages Other languages should be able to inherit from BETA The BETA mapping should be ’nice’ when seen from other languages In.NET terminology:  BETA compliant with Common Language Specification (CLS)  BETA should be a CLS Extender

Rotor Presentation DayPeter Andersen The mapping Generating bytecode for CLR mostly corresponds to making a BETA source mapping into C# source code C# used here for presentation purpose But we do generate IL (intermediate language bytecodes) directly into IL files IL files assembled with ilasm

Rotor Presentation DayPeter Andersen Mapping patterns: nested classes public class Calculator: System.Object { public int R; public class add: System.Object { public int V; … } … } public class Calculator: System.Object { public int R; public class add: System.Object { public int V; public void Enter(int a) { V = a; } public void Do() { R = R + V; } public int Exit() { return R; } } … } Error: Outer R cannot be accessed from nested class! public class Calculator: System.Object { public int R; public class add: System.Object { public int V; Calculator origin; public add(Calculator outer) { origin = outer; } public void Enter(int a) { V = a; } public void Do() { origin.R = origin.R + V; } public int Exit() { return origin.R; } } … } public class Calculator: System.Object { public int R; public class add: System.Object { public int V; Calculator origin; public add(Calculator outer) { origin = outer; } public void Enter(int a) { V = a; } public void Do() { origin.R = origin.R + V; } public int Exit() { return origin.R; } } public int call_add(int V){ add A = new add(this); A.Enter(V); A.Do(); return A.Exit(); } … } Calculator: (# … add: (# enter V do R+V  R exit R #); CLS does not allow for this to be called just add()

Rotor Presentation DayPeter Andersen Use of add as a class: A: ^C.add; &C.add[]  A[]; 5  A  X Calculator C = new Calculator() int X; Calculator.add A; A = new Calculator.add(C); A.Enter(5); A.Do() X = A.Exit();

Rotor Presentation DayPeter Andersen Use of add as a method 5  C.add  X Calculator C = new Calculator() int X; X = C.call_add(5);

Rotor Presentation DayPeter Andersen Interface to external classes etc. Pt. in a declarative manner Ex: Rudimentary support for overloading, constructors etc. Offline batch tool dotnet2beta implemented using reflection (generates BETA source files); should be part of BETA compiler System.String vs. BETA text: Automatic coercion String: ExternalClass (# _init_ArrayOfChar: cons (* constructor *) (# result: ^String; arg1: enter (arg1[]) exit result[] #);... CompareTo_Object: proc (* overloaded CompareTo *) (# arg1: ^Object; enter (arg1[]) do 'CompareTo' -> procname; exit result #);... do '[mscorlib]System.String' -> className; #);

Rotor Presentation DayPeter Andersen Not described here… Virtual classes – corresponding to generics (.NET 2.0 – “ Whidbey”) – implemented with virtual instantiation methods and a lot of (unnecessary) casting. Coroutines and concurrency – implemented with threads. More on this later… Pattern variables: Classes and methods as first-class values – implemented with reflection Leave/restart out of nested method activations – implemented with exceptions Multiple return values – implemented with extra fields Numerous minor details!

Rotor Presentation DayPeter Andersen Status 95% of BETA language implemented  Leave/restart across component border missing  Coroutines and leave/restart not ideally implemented Some things need to be more ‘nice’ Not yet 100% CLS compliant  E.g. custom attributes and consumption of value types Optimizations needed  Large number of classes generated due to the generality of BETA

Rotor Presentation DayPeter Andersen Major missing details Value types consumption Enumeration consumption Throw and handling of CLR exceptions Consumption of static fields Support for custom attributes Maybe proc, class etc. as attributes? Leave/restart over coroutine border Support for multiple interfaces 64 bit arithmetic Boot-strapped compiler (needs some of above) Implementation of BETA class libraries Direct compiler support for reading external classes Visual Studio.NET language extension

Rotor Presentation DayPeter Andersen Plans for ROTOR 1. Simple hello-world and complete compiler test suite Hello-world and most of compiler test suite up-and-running; clix script generation added 2. Implement (some of) above mentioned missing details 3. Bootstrapping the BETA compiler to ROTOR and.NET Currently ongoing 4. Develop a GUI framework on top of ROTOR and.NET. System.Windows.Forms and System.Drawing not available on ROTOR BETA traditional GUI library Lidskjalv and new OpenGL based GUI library Octopus considered 5. Investigate support for Simula/BETA-style coroutines Modify ROTOR bytecodes/jitter/GC/class libraries?

Rotor Presentation DayPeter Andersen Coroutines in C# Imagine: Do() is action part of coroutine S.call() will invoke Do() suspend() in S.Do() (or methods called from S.Do()) will return to the point of S.call() and resume execution after S.call() abstract class Coroutine { // Similar to Thread... public void call() {... } protected void suspend() {... } abstract void Do(); // Similar to Run() } SpecificCoroutine: Coroutine{ … } Coroutine S = new SpecificCoroutine();

Rotor Presentation DayPeter Andersen Example: Adder Produces sequence start + start, (start+1)+(start+1) … By using (infinite) recursion Suspends after each computation class Adder: Coroutine { public int res; int start; public Adder(int s) { start = s; } void compute(int V){ res = V+V; suspend(); compute(V+1); } public override void Do() { compute(start); }

Rotor Presentation DayPeter Andersen Example: Multiplier Produces sequence start * start, (start+1) * (start+1) … By using (infinite) recursion Suspends after each computation class Multiplier: Coroutine { public int res; int start; public Multiplier(int s) { start = s; } void compute(int V){ res = V*V; suspend(); compute(V+1); } public override void Do() { compute(start); }

Rotor Presentation DayPeter Andersen Merger Merge sequences produced by Adder instance and Multiplier instance Sort in ascending order First 6 values class Merger: Coroutine { Adder A = new Adder(3); Multiplier M = new Multiplier(2); public override void Do() { A.call(); M.call(); for (int i=0; i<6; i++){ if (A.res < M.res) { Console.WriteLine("A: " + A.res); A.call(); } else { Console.WriteLine("M: " + M.res); M.call(); } public static void Main(String[] args) { (new Merger()).call() }

Rotor Presentation DayPeter Andersen class Merger: Coroutine { Adder A = new Adder(3); Multiplier M = new Multiplier(2); public override void Do() { A.call(); M.call(); for (int i=0; i<6; i++){ if (A.res < M.res) { Console.WriteLine("A: " + A.res); A.call(); } else { Console.WriteLine("M: " + M.res); M.call(); } public static void Main(String[] args) { (new Merger()).call() } Adder Multiplier Merger MA merger* Do Coroutine Method invocation Caller link – initially self

Rotor Presentation DayPeter Andersen MA merger* Do class Adder: Coroutine { public int res; int start; public Adder(int s) { start = s; } void compute(int V){ res = V+V; suspend(); compute(V+1); } public override void Do() { compute(start); } Adder Multiplier Merger Do Compute Call() is basically just a swap of two pointers

Rotor Presentation DayPeter Andersen MA merger* Do Compute class Merger: Coroutine { Adder A = new Adder(3); Multiplier M = new Multiplier(2); public override void Do() { A.call(); M.call(); for (int i=0; i<6; i++){ if (A.res < M.res) { Console.WriteLine("A: " + A.res); A.call(); } else { Console.WriteLine("M: " + M.res); M.call(); } public static void Main(String[] args) { (new Merger()).call() } Adder Multiplier Merger suspend() is also basically just a swap of two pointers

Rotor Presentation DayPeter Andersen MA merger* Do Compute class Multiplier: Coroutine { public int res; int start; public Multiplier(int s) { start = s; } void compute(int V){ res = V*V; suspend(); compute(V+1); } public override void Do() { compute(start); } Adder Multiplier Merger Do Compute

Rotor Presentation DayPeter Andersen MA merger* Do Compute Do Compute class Merger: Coroutine { Adder A = new Adder(3); Multiplier M = new Multiplier(2); public override void Do() { A.call(); M.call(); for (int i=0; i<6; i++){ if (A.res < M.res) { Console.WriteLine("A: " + A.res); A.call(); } else { Console.WriteLine("M: " + M.res); M.call(); } public static void Main(String[] args) { (new Merger()).call() } Adder Multiplier Merger

Rotor Presentation DayPeter Andersen MA merger* Do Compute Do Compute class Adder: Coroutine { public int res; int start; public Adder(int s) { start = s; } void compute(int V){ res = V+V; suspend(); compute(V+1); } public override void Do() { compute(start); } Adder Multiplier Merger Compute

Rotor Presentation DayPeter Andersen MA merger* Do Compute Do Compute class Merger: Coroutine { Adder A = new Adder(3); Multiplier M = new Multiplier(2); public override void Do() { A.call(); M.call(); for (int i=0; i<6; i++){ if (A.res < M.res) { Console.WriteLine("A: " + A.res); A.call(); } else { Console.WriteLine("M: " + M.res); M.call(); } public static void Main(String[] args) { (new Merger()).call() } Adder Multiplier Merger … and so on

Rotor Presentation DayPeter Andersen Implementation of class Coroutine class Coroutine implemented by means of another class Component : public abstract class Coroutine { internal Component _comp; public Coroutine(){ _comp = new Component(this); } public void call() { _comp.swap(); } protected void suspend() { _comp.swap(); } public abstract void Do(); } call() and suspend() implemented using a single swap method

Rotor Presentation DayPeter Andersen Implementation of class Component class Component implemented by means of System.Threading.Thread and System.Threading.Monitor public class Component { public static Component current; private Component caller; // == this when suspended private Coroutine body; private System.Threading.Thread myThread; // notice private public Component(Coroutine b) {... Constructor: allocate myThread starting in run ; set up caller etc. } private void run() {... Thread entry point: call body.Do() and then terminate myThread … } public void swap() {... Main call() / suspend() handling; next slide … } }

Rotor Presentation DayPeter Andersen Implementation of Component.swap() public void swap() { lock (this){ Component old_current = current; current = caller; caller = old_current; if (!myThread.IsAlive) { myThread.Start(); } else { System.Threading.Monitor.Pulse(this); } System.Threading.Monitor.Wait(this); } Currently executing Component/Coroutine Swap pointers Start or resume new current Suspend old current Used asymmetrically:  Call: this == callee;this.caller == this  Suspend: this == current;this.caller to be resumed

Rotor Presentation DayPeter Andersen Implementation of Components in BETA.Net Any pattern in BETA may be used as a coroutine Implemented as shown for C#, with class BetaObject used instead of class Coroutine class BetaObject is common superclass for all BETA objects Same class Component used

Rotor Presentation DayPeter Andersen Comparison with C# 2.0 yield Coming C# 2.0 has new feature called yield return Used for implementing enumerator pattern May be considered ”poor mans coroutine” Can only ”save” one stack frame

Rotor Presentation DayPeter Andersen public class List { public IEnumerator GetEnumerator() { public IEnumerator GetEnumerator() { for (int i = 0; i < count; i++) { yield return elements[i]; for (int i = 0; i < count; i++) { yield return elements[i]; } }} Iterators (slide borrowed from Erik Meijer) Method that incrementally computes and returns a sequence of values  yield return and yield break  Must return IEnumerator or IEnumerable Method that incrementally computes and returns a sequence of values  yield return and yield break  Must return IEnumerator or IEnumerable public IEnumerator GetEnumerator() { return new __Enumerator(this); return new __Enumerator(this);} private class __Enumerator: IEnumerator { object current; object current; int state; int state; public bool MoveNext() { public bool MoveNext() { switch (state) { switch (state) { case 0: … case 0: … case 1: … case 1: … case 2: … case 2: … … } } public object Current { public object Current { get { return current; } get { return current; } }}

Rotor Presentation DayPeter Andersen Coroutine support in.NET/ROTOR? Thread synchronization seems clumsy and inefficient (benchmarking pending, though) Direct user defined scheduling desirable  P/Invoke of WIN32 Fibers?  ROTOR extension with e.g. coswap bytecode? Addition of bytecode straight-forward Managing of thread stacks?  No idea how hard that would be in ROTOR  Our coming research!!

Rotor Presentation DayPeter Andersen Contacts: Peter Andersen (that’s me) Ole Lehrmann Madsen Download: Questions?