Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Classroom Object Oriented Language (COOL)

780 views

Published on

Dec 26, 2016
Sharif University of Technology

Published in: Software
  • There is a useful site for you that will help you to write a perfect. And valuable essay and so on. Check out, please ⇒ www.HelpWriting.net ⇐
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Classroom Object Oriented Language (COOL)

  1. 1. Classroom Object Oriented Language: COOL S. M. M. Sadrnezhaad, R. Yazdanian, S. Karimi
  2. 2. Design goals  Taught in compiler course in some universities  Designed to be implementable in a short time (one semester)  Give students an idea of many features of OO languages, including:  Abstraction  Static Typing  Inheritance  Memory management  Simple reflection  Leaves many features out which are common to other languages
  3. 3. The not so COOL parts  No arrays  No floating point operations  No “static” modifier  No interfaces  No method overloading (but still allow overriding)  No exceptions  No packages
  4. 4. The reference compiler  Built with C++  Generates code for MIPS simulator named SPIM
  5. 5. Where does execution start?  A class “Main” must be defined  Containing a no-args “main” method  Starts program execution
  6. 6. Expressions  Expression language  every expression has a type and a value  Loops: while E loop E pool  Conditionals: if E then E else E fi  Case statement: case E of x: Type  E; esac  Arithmetic operations  Logical operations  Assignment x  E
  7. 7. Basic structure and classes  Basically, a COOL program is a set of classes  Similar to Java  Almost every type is a class (next slide)  Blocks defined using { and }.  Each COOL class has a set of features  Methods  No explicit return  Attributes (variables)
  8. 8. Classes and types: continued  Primitive types: Boolean, Int, String  Built-in types: The above, + Null, Nothing, Unit, Any  Every type except Null and Nothing is a class  Int, Boolean, Unit cannot be superclass  “Any” class is the root of class hierarchy  Similar to “Object” in Java  Each type “conforms” to ancestors  “Nothing” conforms to all  “Null” conforms to all but Int, Boolean, Unit  Null and Nothing cannot be superclass (obviously)
  9. 9. Information hiding  Attributes only accessed through methods of same class (“Information hiding”)  Methods are global (public)  Getters and Setters necessary  Example class Point { … getx () : Int { x }; setx (newx : Int) : Int { x  newx }; };
  10. 10. 18 Inheritance  We can extend points to colored points using subclass (class hierarchy) class ColorPoint inherits Points { color : Int  0; movePoint(newx : Int, newy : Int) : Point { { color  0; x  newx; y  newy; self; } }; }; 0 0 y color * movePoint 0 x
  11. 11. Classes: behind the scenes  An instance of a class has pointer to method  All instances of a class point to single instance of method  Example: 0 0 x y * movePointmethods
  12. 12. The “new” command  Explicit class Main { i : IO <- new IO; main():Int { i.out_string("Hello World!n"); 1; }; };  Anonymous class Main { main():Object { (new IO).out_string((new IO).in_string().concat("n"))}; };
  13. 13. Typing  Static typing: Type defined at variable definition time  Static type inferred at compile time for each expression  Bottom-up  Dynamic, exec time type may differ  But dynamic type “conforms” to static type  Errs on the conservative side  Attributes of classes initialized  Boolean: false, Unit: (), Int: 0  Others: Null
  14. 14. Method invocation  Dynamic type may differ from static  Methods invoked instead of calling -> Late binding  Invoked by dispatch  Find class of the instance  Find the method  Eval args  Bind the method and the object  Run method
  15. 15. Memory Management: Environment and Store  Environment: Mapping of identifiers to locations  i.e. symbol table  Store: Where the values are stored -> Heap  Looking up a variable’s value:  Look its location up in environment  Look up the value at location in store  When new is invoked  New env. and store created, new identifier added to them  Dynamic allocation w/ Garbage Collector
  16. 16. Conclusion  Object oriented  Objects, virtual method calls, but no overloading  Strongly typed  Primitives for int, boolean, string  Reference types  Dynamic allocation and Garbage Collection  Heap allocation, automatic deallocation  Many things are left out  short time implementation
  17. 17. Question time!
  18. 18. Thank you for (if) your attention! :)

×