Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
Names and Bindings.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Written by: Dr. JJ Shepherd
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Compiler Construction Rina Zviel-Girshin and Ohad Shacham School of Computer Science Tel-Aviv University.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Prof. Fateman CS 164 Lecture 41 Overview of MiniJava Lecture 4.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
Run time vs. Compile time
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Compiler Construction Ran Shaham and Ohad Shacham School of Computer Science Tel-Aviv University.
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
Types in programming languages What are types, and why do we need them? Types in programming languages1.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
Review of C++ Programming Part II Sheng-Fang Huang.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Object Oriented Programming: Java Edition By: Samuel Robinson.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
Introduction to Object Oriented Programming CMSC 331.
Basic Semantics Associating meaning with language entities.
CS112: Structure of Programming Languages A smorgasbord of topics in programming languages including programming paradigms and syntax, semantics, implementation.
Compiler Construction Dr. Noam Rinetzky and Orr Tamir School of Computer Science Tel Aviv University
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
COMP3190: Principle of Programming Languages
Types in programming languages1 What are types, and why do we need them?
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Object-Oriented Programming Chapter Chapter
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
Winter Compiler Construction Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University.
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Memory Management in Java Mr. Gerb Computer Science 4.
FASTFAST All rights reserved © MEP Make programming fun again.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Functional Programming
Names and Attributes Names are a key programming language feature
Object-oriented Programming in Java
CS 326 Programming Languages, Concepts and Implementation
Winter Compiler Construction
CS230 Tutorial Week 3.
Object Oriented Programming
Conditional Statements
The Procedure Abstraction Part V: Run-time Structures for OOLs
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Introduction to Data Structure
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
Presentation transcript:

Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS 1642 Lecture Outline Cool The Course Project Programming Assignment 1 ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS 1643 Cool Overview Classroom Object Oriented Language Designed to –Be implementable in one semester –Give a taste of implementation of modern Abstraction Static typing Reuse (inheritance) Memory management And more … But many things are left out ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS 1644 A Simple Example Cool programs are sets of class definitions –A special class Main with a special method main –No separate notion of subroutine class = a collection of attributes and methods Instances of a class are objects class Point { x : Int  0; y : Int  0; }; ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS 1645 Cool Objects An object can be thought of as a record with a slot for each attribute class Point { x : Int  0; y : Int; (* use default value *) }; x y 00 The expression “new Point” creates a new object of class Point ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS 1646 Methods Methods can refer to the current object using self class Point { x : Int  0; y : Int  0; movePoint(newx : Int, newy : Int): Point { { x  newx; y  newy; self; } -- close block expression }; -- close method }; -- close class A class can also define methods for manipulating the attributes ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS 1647 Information Hiding in Cool Methods are global Attributes are local to a class –They can only be accessed by the class’s methods Example: class Point {... x () : Int { x }; setx (newx : Int) : Int { x  newx }; }; ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS 1648 Methods Each object knows how to access the code of a method As if the object contains a slot pointing to the code In reality implementations save space by sharing these pointers among instances of the same class xy 00 movePoint * xy 00 methods movePoint * ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS 1649 Inheritance We can extend points to colored points using subclassing => class hierarchy class ColorPoint inherits Point { color : Int  0; movePoint(newx : Int, newy : Int): Point { { color  0; x  newx; y  newy; self; } }; xy 00 color 0 movePoint * ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS Cool Types Every class is a type Base classes: –Int for integers –Bool for boolean values: true, false –String for strings –Object root of the class hierarchy All variables must be declared –compiler infers types for expressions ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS Cool Type Checking Is well typed if P is an ancestor of C in the class hierarchy –Anywhere an P is expected a C can be used Type safety: –A well-typed program cannot result in runtime type errors x : P; x  new C; ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS Method Invocation and Inheritance Methods are invoked by dispatch Understanding dispatch in the presence of inheritance is a subtle aspect of OO languages p : Point; p  new ColorPoint; p.movePoint(1,2);  p has static type Point  p has dynamic type ColorPoint  p.movePoint must invoke the ColorPoint version ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS Method Invocation Example: invoke one-argument method m e.m(e’) … 2 … 1 m: self  x  Eval. argum e’ 3. Find class of e 4. Find code of m 2. Eval. e 5. Bind self and x 6. Run method … … 3 method table ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS Other Expressions Expression language (every expression has a type and a value) –Conditionals if E then E else E fi –Loops: while E loop E pool –Case statement case E of x : Type  E; … esac –Arithmetic, logical operations –Assignment x  E –Primitive I/O out_string(s), in_string(), … Missing features: –Arrays, Floating point operations, Interfaces, Exceptions,… ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS Cool Memory Management Memory is allocated every time new is invoked Memory is deallocated automatically when an object is not reachable anymore –Done by the garbage collector (GC) –There is a Cool GC ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS Course Project A complete compiler –Cool ==> MIPS assembly language –No optimizations Split in 5 programming assignments (PAs) There is adequate time to complete assignments –But start early and please follow directions –Turn in early to test the turn-in procedure Team (max. 2 students) ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS Programming Assignment I Write an interpreter for a stack machine … … in Cool Due in 2 weeks Must be completed individually ICOM 4029 Fall 2008

Adapted from Prof. Necula UCB CS Homework for Next Week Work on Programming Assignment I Read Chapters 1-2 of Textbook Continue learning Jlex ICOM 4029 Fall 2008