+ All Categories
Home > Technology > Prototalk

Prototalk

Date post: 28-Nov-2014
Category:
Upload: esug
View: 644 times
Download: 0 times
Share this document with a friend
Description:
Prototalk: an Environment for Teaching, Understanding, Designing and Prototyping OO Languages. Alexandre Bergel, Christophe Dony, Stéphane Ducasse (ESUG 2004, Koethen)
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]
Transcript
Page 1: Prototalk

1

Prototalk: an Environment for Teaching, Understanding,

Designing and Prototyping OO Languages

Alexandre Bergel, Christophe Dony, Stéphane DucasseUniversity of Bern (Switzerland)

LIRMM, Montpellier (France)

[email protected]

Page 2: Prototalk

2

Outline

1. Prototype OO Languages

2. Expressing Different Languages

3. Prototalk

4. Example: Newtonscript

5. Conclusion

Page 3: 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: 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: Prototalk

5

Prototalk

Page 6: 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: 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: 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: 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: Prototalk

10

Example: NewtonScript

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

_parent

_proto

Page 11: 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: 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: 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: 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: Prototalk

15

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

[email protected]

Page 16: Prototalk

16

Page 17: 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: 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: Prototalk

19

Self, ObjectLisp, ...

Personage=26

name=Luceat=...

Studentnum=1234567

grade=2doExam=...

Personage=26

name=Luceat(...)

Studentnum=1234567

grade=2doExam(...)


Recommended