Download presentation
Presentation is loading. Please wait.
Published byHugo Lawson Modified over 9 years ago
1
Lecturers: Hesam Setareh Salar Moarref 1 Fall 2009 – Programming languages
2
Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 2
3
History and Motivation Alan Kay at the University of Utah in the late 1960s, suggested that it is possible to put the power of a room-sized, million dollar computer into a package. (Personal Computer) Personal computer needs a personal programming language. Older languages were designed for the scientific and commercial applications that occupy large computers. Kay designed a simulation and graphic-oriented programming language for nonspecialists. 3
4
History and Motivation Kay is a member of FLEX designer team. FLEX took the ideas of classes and objects from Simula. Kay wanted to provide a rich interactive environment for nonspecialists. Xerox came in: In the 1971 Xerox produced a personal computer, called Dynabook. 4
5
The born of Smalltalk Smalltalk first version, Smalltalk-72, was designed and implement for Dynabook by 1972. Smalltalk-74, Smalltalk-76, Smalltalk-78, and Smalltalk-80 are other versions of it. 5
6
Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 6
7
In Smalltalk everything is object, including variables, numbers, strings, etc. For example : x*2 Any object has two major parts: 7 Properties (Variables) Behaviors (Methods) Properties (Variables) Behaviors (Methods) Structural Organization
8
Scribe goto:500@500. 8 Example
9
Scribe goto:500@500. 9 Scribe go:300. Example
10
Scribe goto:500@500. 10 Scribe go:300. Scribe turn:90. Example
11
Scribe goto:500@500. 11 Scribe go:300. Scribe turn:90. Scribe go:300. Example
12
Scribe goto:500@500. 12 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Example
13
Scribe goto:500@500. 13 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Example
14
Scribe goto:500@500. 14 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Example
15
Scribe goto:500@500. 15 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Example
16
Scribe goto:500@500. 16 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90 Example
17
Scribe goto:500@500. 17 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90 4 timesRepeat: [Scribe go:300. Scribe turn:90] Example
18
Class A class is a plan, which objects are made from. Getting a new object from a class is called instantiation. 18 anotherScribe ← pen newAt:200@200
19
shape|| scribe penup;goto:loc;turnTo:tilt;pendn. 4 timesRepeat: [scribe go:size;turn:90] show || scribe color ink. self shape erase || scribe color background. self shape grow: amount || self erase. size ← size+amount. self show Class Definition 19 class namebox Instance variable nameLoc tilt size scribe Instance message and methods
20
newAt:initialLocation|newBox| newBox ← self new. newBox setLoc:initialLocation tilt:0 size:100 scribe:pen new. newBox show. ↑ newBox shape|| scribe penup;goto:loc;turnTo:tilt;pendn. 4 timesRepeat: [scribe go:size;turn:90] Class Definition 20 class namebox Instance variable nameLoc tilt size scribe Instance message and methods class message and methods
21
Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 21
22
Classes and Subclasses Smalltalk objects model Real-World! Some of objects have similar properties and behaviors. We can group classes of these objects and make superclass which has common variables and methods. 22 dispayObject boxpenwindow
23
Classes and Subclasses 23 class namebox Instance variable name displayObject Instance message and methods superclass Loc tilt size scribe
24
Classes and Subclasses A Superclass can be subclass of another class. 24 dispayObject boxpenwindow number… Object …
25
print || ↑ realPt print + “+” imagePt print + “i” Classes and Subclasses 25 class namecomplex Instance variable namerealPt imagePt Instance message and methods Subclasses can change the inherent method, this process is called Overriding
26
An Important Issue In Smalltalk a class can’t have several superclass. But, in the Real-World, an object can inherent from more than one object. 26 dispayObject box penbumper numberinventoryItem Object roof door
27
An Important Issue 27 dispayObject brakeenginebumper numberinventoryItem Object roof door
28
A simple solution 28 dispayObject box penbumper number inventoryItem Object roof door … ! !
29
AfricanS.AmericanN.American Another aspect of that issue The way of classification causes class grouping. It is possible for some classes to have several ways of classification. Orthogonal classification: 29 Pets Beasts of burden Source of food Pests
30
Multiple Inheritance raises difficult problem Multiple inheritance allows a class to be an immediate subclass of more than one class. It solve one problem but, brings many new problems. 30 C B A
31
Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 31
32
Dynamic versus Static, Strong versus weak Smalltalk uses dynamic type checking like LISP. Pascal and Ada use static type checking. Dynamic type checking does not imply weak type. 32
33
Forms of Message Template (Argument Passing) Message sending syntaxes: Object_namemethodname Object_namemethodname : argument Object_namemethodname : 1 st arg 2 nd arg_name:2 nd arg_val We have a problem with arithmetic expression: (x+2)*y (x plus : 2) times : y It became possible for one-parameter message to use an operation. 33
34
run || Keyboard read eval print The Smalltalk main loop is written in Smalltalk 34 class nameuserTask Instance message and methods Smalltalk is in a loop: read a command, execute the command, print the result and loop true whileTrue: [Display put: user run]
35
run || sched map: [: Task | Task run] Concurrency is easy to implement 35 class namescheduler Instance message and methods Sched is the name of a set that contains all of the objects that are scheduled to be run concurrently. S map: B, apply block B to every element of S.
36
Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 36
37
Implementation: Classes and objects Most of Smalltalk system is written in smalltalk Compiler, decompiler, debugger, editors,… 97% most of implementation data structures are smalltalk objects Smalltalk-80 VM:not portable 6~12KB assembly code One man-year to produce a fully debuged version 37
38
Implementation Smalltalk Virtual machine: Storage manager Encapsulate the representation of objects and organization of memory Fetch the class of an object Fetch and store the fields of objects Create new objects Interpreter Primitive subroutines 38
39
Implementation Smalltalk Virtual machine: Storage manager Interpreter Manager for methods Primitive subroutines Collection of methods For performance reasons are implemented in machine code basic I/O functions, integer arithmetic, basic screen graphics functions 39
40
Implementation There are three central ideas in Smalltalk Objects Classes Message sending 40
41
Object representation Representation of an object must contain just that information that varies from object to object Instance variables The information stored with the class includes the class methods and instance methods 41
42
Representation of objects Len6 c.d. loc Tilt Size scribe Len6 c.d. Loc Tilt Size Scribe Len4 c.d. X Y Box 500@600 200 500 point 42
43
Class representation everything in Smalltalk is an object Even classes! Classes are instances of the class named class Instances variables of a class object contain pointers to objects representing the information that is the same for all instances of the class What is this information? 43
44
Representation of class object Len8 c.d. name Super class Inst. Vars Class msgs. Inst. Msgs. Inst. Size4 class “box” DisplayObject “loc tilt size scribe” Message dict 44
45
Representation of class object(continued) inst. Size number of instance variables Needed by storage manager when it instantiates an object Message dictionaries A method identified by the keywords Scribe go:100 go: identifies the method Spinner newAt: 500@200 rate:1 newAt:rate: is method Message template For each message template acceptable to a class or its instances, one of the message dictionaries must contain an entry 45
46
Message dictionary How should method be represented? Too much slow if the interpreter had to decode the source form every time the method was executed Compile the code into some form of pseudo code that can be rapidly interpreted The source form is needed for editing and displaying class definition Message dictionaries contain two entries for each message template 46
47
Example of message dictionary. msgmethodsource. Message dictionary “grow:” “grow: amount || self release. Size<- size+amount. Self show” Push ‘slef’ Send ‘erase’,0 Pop Push ‘size’ Push ‘amount’ Send ‘+’,1 Send ‘<-’,1 pop method 47
48
Implementation of message sending There is a strong resemblance between message passing in Smalltalk and procedure calls in other languages Activation records: primary vehicle for procedure implementation The same is the case in Smalltalk Activation records hold all of the information relevant to one activation of a method 48
49
Structure of an activation record Environment part The context to be used for execution of the method Instruction part The instruction to be executed when this method is resumed Sender part The activation record of the method that sent the message invoking this method 49
50
Instruction part Must designate a particular instruction in a particular method Methods are themselves objects instances of class method Two coordinate system is used for identifying instructions: An object pointer defines the method-object A relative offset identifies the particular instruction within the method object 50
51
Environment part Local environment Parameters to method Temporary variables Hidden temporary variables such as the intermediate results of expressions Nonlocal environment: all other visible variables Instance variables Class variables 51
52
Parts of an activation record locals parameters Temporary vars intermediates Non localsStatic link Instruction part method instruction Sender partDynamic link Length c.d. Instance vars instance Length c.d. Superclass Class variable Class Length c.d. Superclass Super class variables 52
53
Message sending create an activation record for the receiver (callee) Identify the method being invoked by extracting the template form from the message and then looking it up in the message dictionary for the receiving object’s class or super class Transmit the parameters to the receiver’s activation records Suspend the sender(caller) by saving its state in its activation record. Establish a path(dynamic link) from the receiver back to the sender and establish the receiver’s activation record as the active one 53
54
Returning from a method transmit the returned object(if any) from the receiver back to sender Resume execution of the sender by restoring its state from its activation record 54
55
Returning from a method transmit the returned object(if any) from the receiver back to sender Resume execution of the sender by restoring its state from its activation record deallocation of the activation record??? The storage manager handles allocation and deallocation of all objects, this include AR objects We don’t explicitly deallocate activation records Smalltalk doesn’t allocate its activation records on a stack concurrency 55
56
Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 56
57
Object oriented extensions Many languages have been extended for object oriented programming Fifth generation languages such as LISP Third and fourth generation languages such as C and Ada83 Simula-67 is essentially an object-oriented extension to algol- 60 Programming by extension Suggested by object oriented languages Ability to extend and refine software systems without needing to recompile and retest the parts already implemented 57
58
Tagged types support programming by extension-Ada Package Display_Objects is type display_object is tagged [private] record loc: display_location; end record; Procedure Go_to ( The_object: display_object; new_loc: display_location); Procedure Show ( The_object:display_object); Procedure Erase ( The_object:display_object); End display_objects; 58
59
Tagged types support programming by extension-Ada With display_objects; Package Boxes is type Box is new display_objects.display_object with [private] record tilt, size :float; The_scribe: scribe; end record; procedure shape (The_Box: Box);. End Boxes; 59
60
Package All_Display_Objects type Display_Object is tagged private; … operations for Display_Object … type Box is new Display_Object with private; … operations for Box … type Window is new Display_Object with private; … operations for Window … …etc. … end All_Display_Objects 60 Types and Their Refinements Can be Defined is a Single Package
61
Abstract declarations in display_object: Procedure shape (The_object: display_Object) is abstract; In Box: Procedure shape (The_box:Box); In package body for display_objects: procedure show(The_object: display_object) is Begin Set_color(The_object); Shape(The_object); End show; 61
62
Ada’s support for object oriented programming is complex The complexity comes from grafting the object oriented features onto a type system that was designed for different trade-offs(e.g. efficiency on small embedded computers) 62
63
C++ extends C for object-oriented programming C++ is largely the work of Bjarne Stroustrup C++ supports: Class declaration Multiple inheritance Virtual abstract in Ada Template generic in Ada 63
64
Java is a more advanced object- oriented language derived from C Designed for networked and distributed programming environments Greater emphasis on security, robustness, machine independence, portability Java emits some C++ features: operator overloading, pointers,… Add others such as automatic garbage collection 64
65
Topics History and Motivation Structural Organization Classes aMessage Sending nd Subclasses Implementation Object-Oriented extensions Evaluation and Epilog 65
66
Evalution and epilog Smalltalk is small, flexible, and extensible Small, simple, regular language Small number of independent concepts easy to learn Has demonstrated its flexibility by being Used in a number of applications: simulations, graphics, artificial intelligence Design of Smalltalk has been dictated by several powerful principles: simplicity, regularity, abstraction, security and information hiding 66
67
Evalution and epilog Smalltalk is an example of a programming environment Has introduced important ideas other than language itself, like widows Is also an excellent example of an advanced programming environment Integration of graphics, windows and an advanced language 67
68
Evalution and epilog Smalltalk introduces a new programming paradigm Although most of its ideas have appeared in other languages, smalltalk’s integration of these ideas is novel The essence of the Smalltalk view is that programming is simulation programs model, sometimes in a very abstract form, some aspects of the real world 68
69
Evalution and epilog Smalltalk is small, flexible, and extensible Smalltalk is an example of a programming environment Smalltalk introduces a new programming paradigm 69
70
70
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.