19
1 Prototalk: an Environment for Teaching, Understanding, Designing and Prototyping OO Languages Alexandre Bergel, Christophe Dony, Stéphane Ducasse University of Bern (Switzerland) LIRMM, Montpellier (France) [email protected]

2004 Esug Prototalk

  • Upload
    bergel

  • View
    2.799

  • Download
    1

Embed Size (px)

DESCRIPTION

With prototype-based languages, concretization and abstraction are unified into a single concept a prototype. Prototype-based languages are based on a simple set of principles: object-centered representation, dynamic reshape of objects, cloning and possibly message delegation. However, they all differ in the interpretation and combination of these principles. Therefore there is a need to compare and understand. In this paper we present Prototalk, a research and teaching vehicle to understand, implement and compare prototype-based languages. Prototalk is a framework that offers a predefined set of language data structures and mechanisms that can be composed and extended to generate various prototype-based language interpreters. It presents a classification of languages based on different mechanisms in an operational manner.

Citation preview

Page 1: 2004 Esug Prototalk

1

Prototalk: an Environment for Teaching, Understanding, Designing

and Prototyping OO Languages Alexandre Bergel, Christophe Dony, Stéphane Ducasse

University of Bern (Switzerland)LIRMM, Montpellier (France)

[email protected]

Page 2: 2004 Esug Prototalk

2

Outline

1. Prototype OO Languages

2. Expressing Different Languages

3. Prototalk

4. Example: Newtonscript

5. Conclusion

Page 3: 2004 Esug Prototalk

3

Prototype OO Languages

• Classless paradigm

• A prototype contains its state and behavior

• Link between prototypes is usually done using:

• Delegation

• Composition

Page 4: 2004 Esug Prototalk

4

Different Languages

• Self: Unification of variables and methods and multiple parents

• ObjectLisp: variables distinct from methods

• NewtonScript: two kinds of delegation over two links

Page 5: 2004 Esug Prototalk

5

Prototalk

Page 6: 2004 Esug Prototalk

6

Goal and Design Decisions

• Uniformity: same syntax for all the languages

• Minimality: minimal kernel to express the most general semantics

• Extensibility: new languages has to be implemented efficiently and easily

• Usability: integrated in the environment

Page 7: 2004 Esug Prototalk

7

Prototalk

• Language represented by a subclass of AbstractProto

• Execution of program by sending evaluate: to it

• The AST is built using a ProgramNodeBuilder

• It is composed of subclass of the Smalltalk AST nodes

Page 8: 2004 Esug Prototalk

8

Architecture

AbstractObjectModel

evaluate: sourceCodecompileMethodAt: namecompile: codeSourceglobalVar: varName put: aValuenodeBuilder

NodeBuilder

newVariableName: namenewMessageReceiver: rcvr...

ProgramNode

eval: context

MethodNodeselectorblockeval: contextapplyWith: args in: context

VariableNodevariableNameeval: context

MessageNodeselectoreval: context

Language1variablesmethodsmethodOwner: nameclone...

Language1NodeBuilder

newVariableName: namenewMessageReceiver:...

Language1VariableNode

eval: context

Language1MessageNode

eval: context

Prototalk Base

Implementation of Language1

Page 9: 2004 Esug Prototalk

9

Language1

• Language1 is a subclass of AbstractProto

• Ability to execute programs

• Prototypes are represented by its instances

• Provides primitives like clone, addVar: addMethod:, hasVar:, ...

Page 10: 2004 Esug Prototalk

10

Example: NewtonScript

• It has a double inheritance: _proto is searched prior to _parent

_parent

_proto

Page 11: 2004 Esug Prototalk

11

Double Inheritance

f := {getX: funct() x, _proto: {_proto: {x: 10}}};f._parent := {x: 20};

f getX x: 10

x: 20

_parent

_protof.getX() ==> 10

Page 12: 2004 Esug Prototalk

12

In Prototalk

f := {getX: funct() x, _proto: {_proto: {x: 10}}};f._parent := {x: 20};f.getX() ==> 10

The same program in Prototalk:NewtonScriptLike evaluate: ‘ f := PRoot clone. f proto: (PRoot clone; proto: (PRoot clone; addSlot: ‘‘x = 10’’)). f addSlot: ‘‘getX x’’. f parent: (PRoot clone; addSlot: ‘x = 20’). f getX.’

Page 13: 2004 Esug Prototalk

13

In PrototalkAbstractProto

NewtonScriptLike parentproto

methodOwner: namemethodOwnerInProto: name

t := self methodOwnerInProto: name.^ t isNil ifTrue: [ parent isNil ifTrue: [nil] ifFalse: [parent methodOwner: name]] ifFalse: [t]]

^ (slots includesKey: name) ifTrue: [self] ifFalse: [ proto isNil ifTrue: [nil] ifFalse: [proto methodOwnerInProto: name]]

slots

Page 14: 2004 Esug Prototalk

14

Conclusion

• Platform to design and experiment prototypes-based OO language

• Pure interpretation of programs

• Pedagogical tool: used at University Paris VI, Montpellier and Berne

Page 15: 2004 Esug Prototalk

15

• Prototalk: an Environment for Teaching, Understanding, Designing and Prototyping OO languages

[email protected]

Page 16: 2004 Esug Prototalk

16

Page 17: 2004 Esug Prototalk

17

Hierarchy of Object ModelAbstractProto

newEmpty

SlotProtoslotscloneaddSlot: namemethod: codemethodNamed: name

L11

initInitials: slotsnewInitials: slots

L11AndImplicitDelegationparentclonemethodLookup: nameparentson

L16

ModifiableSlot

L7

L7AndImplicitDelegationparentinitializeParent: parentclose

SelfLike

addSlot: slotassignmentMethod: code

L7AndExplicitDelegation

Page 18: 2004 Esug Prototalk

18

ProgramNodeBuilder

SelfLikeAssignmentMethodBuilder

Smalltalk ProgramNodeBuilder

Prototalk ProgramNodeBuilder

ProgramNodeBuilder

newCondition(cond, then, else)newLiteralValue(literal)newMessageReceiver(object)newMethodSelector(methName)newVariable(varName)newAssignmentVariable(name)

ImplicitDelegationPNB

newMessageReceiver: object

ImplicitDelegationEncapsulationPNB

newMessageReceiver: objectnewAssignmentVariable: name

ObjectLispLikePNB

newMessageReceiver: object

SelfLikePNB

newVariable: varName

EncapsulationPNB

newVariable: varNamenewAssignmentVariable: name

ExplicitDelegationPNB

newMessageReceiver: object

ExplicitDelegationEncapsulationPNB

newVariable: varNamenewAssignmentVariable: name

AbstractProto

nodeBuilder

Page 19: 2004 Esug Prototalk

19

Self, ObjectLisp, ...

Personage=26

name=Luceat=...

Studentnum=1234567

grade=2doExam=...

Personage=26

name=Luceat(...)

Studentnum=1234567

grade=2doExam(...)