SlideShare uma empresa Scribd logo
1 de 46
Baixar para ler offline
Advanced Reflection
in Pharo
Marcus Denker
http://rmod.lille.inria.fr
What you know…
• Smalltalk is reflective
• e.g. Classes and Methods are Objects
• Reflective API on all Objects
Instance Variables
Object subclass: #Point!
! instanceVariableNames: 'x y'!
! classVariableNames: ''!
! poolDictionaries: ''!
! category: 'Kernel-BasicObjects'
2 instance variables
• Ask the class:
Point instVarNames
• read:
3@4 instVarNamed: #x
• write:
3@4 instVarNamed: #x put: 5
Great!
But…
Object subclass: #Point!
! instanceVariableNames: 'x y'!
! classVariableNames: ''!
! poolDictionaries: ''!
! category: 'Kernel-BasicObjects'
This is just a String!
• returns an Array of Strings:
!
Point instVarNames
Why not Objects?
We can do better!
• All classes have a Layout
!
• Describes the memory layout defined by a
class
!
• Layout and all the description are Objects
• Point layout
• a Normal Object
• Array layout
• an Array of Pointers
• ByteArray layout
• an Array of Bytes
Point layout allSlots
!
==> an OrderedCollection(x => Slot y => Slot)
• Slots know how to read values from Objects
!
mySlot := Point layout resolveSlot: #x.
mySlot read: 3@4.
Why?
Typed Slots
Slot subclass: #TypedSlot
layout: PointerLayout
slots: {#x => TypedSlot type: Integer}.
!
!
TypedSlot >> write: aValue to: anInstance
(aValue isNil or: [aValue isKindOf: type])
ifFalse: [ InvalidTypeError signal ].
super write: aValue to: anInstance.
Property Slots
Object
subclass: #PropertyObject
layout: PointerLayout
slots: {
field => Slot
property1 => PropertySlot.
property2 => PropertySlot.
...
propertyN => PropertySlot.
}
Others
• BitSlot
• BooleanSlot
• Alias
• Relationships (e.g. one-one, one-many)
• …. Your Domain level Slot!
More in Paper from OOPSLA
Status
• Slots are in Pharo3, but hidden
!
• In Pharo4: un-hide and introduce some Special
Slots (e.g. Boolean, Property)
• e.g. for Morphic (user interface objects)
Help Wanted!!!
So this worked well…
Lets do it again!
Turn another String
into
Objects
:-)
Methods
Lets have a look
• Method are Objects, but…
!
• No high-level model for sub-method elements
• Message sends
• Assignments
• Variable access
!
• Structural reflection stops at the granularity of methods!
Can we do better?
Compilers have ASTs
Abstract Syntax Trees
• Lets have a look at an example
(Object>>#halt) ast
• Encodes the method as
a tree of node-objects
• Visitor Pattern
• Transformations
• Refactoring tool
uses this!
RBProgramNode
RBDoItNode
RBMethodNode
RBReturnNode
RBSequenceNode
RBValueNode
RBArrayNode
RBAssignmentNode
RBBlockNode
RBCascadeNode
RBLiteralNode
RBMessageNode
RBVariableNode
In Pharo3
• AST based Navigation in the Editor
• “Suggestions”
• Debugger uses AST for pc->code mapping
• AST Interpreter for experiments
Future
• AST everywhere!
• Do we need to store strings?
• Can we have an AST based editor?
• Sub-Method Reflection: The MetaLink
Method
Can we modify the behaviour of code?
Meta
Link
> Annotate the AST with meta-links
Why?
• Change behaviour for selected AST Nodes
• “All assignments”
• “this message send”
But without changing the program code!
Breakpoints
DEMO: Atoms
© Marcus Denker
Behavioral Reflection
source code
(AST)
meta-object
activation
condition
links
Uses…
• Debugger
• BreakPoints, WatchPoints
• Profilers
• Coverage Analysis
• AOP
Will be in Pharo4
Will be in Pharo4
!!help wanted!!
What did we see?
• Slots!
• Instance variables are just described with strings
• We can do better! Layout, Slots
• ASTs Everywhere!
• Methods are objects, but internal structure not
modelled
• We can do better! AST, Sub-Method Reflection, Meta-
Links
Questions???

Mais conteúdo relacionado

Mais procurados

Real-World Scala Design Patterns
Real-World Scala Design PatternsReal-World Scala Design Patterns
Real-World Scala Design Patterns
NLJUG
 

Mais procurados (20)

Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes
 
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
 
Javascript for Intermediates
Javascript for IntermediatesJavascript for Intermediates
Javascript for Intermediates
 
Learn Ruby 2011 - Session 2
Learn Ruby 2011 - Session 2Learn Ruby 2011 - Session 2
Learn Ruby 2011 - Session 2
 
Typescript
TypescriptTypescript
Typescript
 
Scala
ScalaScala
Scala
 
Real-World Scala Design Patterns
Real-World Scala Design PatternsReal-World Scala Design Patterns
Real-World Scala Design Patterns
 
Week3
Week3Week3
Week3
 
String interpolation
String interpolationString interpolation
String interpolation
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-parts
 
chubbyphp de/serialization
chubbyphp de/serializationchubbyphp de/serialization
chubbyphp de/serialization
 
JS - Basics
JS - BasicsJS - Basics
JS - Basics
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
Intro Ruby Classes Part I
Intro Ruby Classes Part IIntro Ruby Classes Part I
Intro Ruby Classes Part I
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
 
Pass by value and pass by reference
Pass by value and pass by reference Pass by value and pass by reference
Pass by value and pass by reference
 
Overview of CoffeeScript
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
 

Destaque (9)

Pedagogical and logistical preparation
Pedagogical and logistical preparationPedagogical and logistical preparation
Pedagogical and logistical preparation
 
Presentation by boarding school
Presentation by boarding schoolPresentation by boarding school
Presentation by boarding school
 
Project presentation
Project presentationProject presentation
Project presentation
 
Pharo: A Reflective System
Pharo: A Reflective SystemPharo: A Reflective System
Pharo: A Reflective System
 
Infopack ukraine, 2013 11-21 October 2013
Infopack ukraine, 2013 11-21 October 2013Infopack ukraine, 2013 11-21 October 2013
Infopack ukraine, 2013 11-21 October 2013
 
PharoDAYS 2015: Consortium Message: Get involved, you can get an impact by St...
PharoDAYS 2015: Consortium Message: Get involved, you can get an impact by St...PharoDAYS 2015: Consortium Message: Get involved, you can get an impact by St...
PharoDAYS 2015: Consortium Message: Get involved, you can get an impact by St...
 
Smalltalks13 pharo techoverview
Smalltalks13   pharo techoverviewSmalltalks13   pharo techoverview
Smalltalks13 pharo techoverview
 
2013 pharo is yours revisited. Santiago DCC University of Chile Presentation.
2013 pharo is yours revisited. Santiago DCC University of Chile Presentation.2013 pharo is yours revisited. Santiago DCC University of Chile Presentation.
2013 pharo is yours revisited. Santiago DCC University of Chile Presentation.
 
Towards a flexible Pharo Compiler
Towards a flexible Pharo CompilerTowards a flexible Pharo Compiler
Towards a flexible Pharo Compiler
 

Semelhante a Advanced Reflection in Pharo

Pharo Status ESUG 2014
Pharo Status ESUG 2014Pharo Status ESUG 2014
Pharo Status ESUG 2014
Pharo
 

Semelhante a Advanced Reflection in Pharo (20)

Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
 
Variables in Pharo
Variables in PharoVariables in Pharo
Variables in Pharo
 
About Python
About PythonAbout Python
About Python
 
Slot Composition
Slot CompositionSlot Composition
Slot Composition
 
Slot Composition
Slot CompositionSlot Composition
Slot Composition
 
First Class Variables as AST Annotations
 First Class Variables as AST Annotations First Class Variables as AST Annotations
First Class Variables as AST Annotations
 
First Class Variables as AST Annotations
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST Annotations
 
Reference Semantics with C# and .NET Core
Reference Semantics with C# and .NET CoreReference Semantics with C# and .NET Core
Reference Semantics with C# and .NET Core
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3
 
Pharo Status ESUG 2014
Pharo Status ESUG 2014Pharo Status ESUG 2014
Pharo Status ESUG 2014
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Javascript
JavascriptJavascript
Javascript
 
#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Javascript classes and scoping
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scoping
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 

Mais de Pharo

Mais de Pharo (20)

Yesplan: 10 Years later
Yesplan: 10 Years laterYesplan: 10 Years later
Yesplan: 10 Years later
 
Object-Centric Debugging: a preview
Object-Centric Debugging: a previewObject-Centric Debugging: a preview
Object-Centric Debugging: a preview
 
The future of testing in Pharo
The future of testing in PharoThe future of testing in Pharo
The future of testing in Pharo
 
Spec 2.0: The next step on desktop UI
Spec 2.0: The next step on desktop UI Spec 2.0: The next step on desktop UI
Spec 2.0: The next step on desktop UI
 
UI Testing with Spec
 UI Testing with Spec UI Testing with Spec
UI Testing with Spec
 
Pharo 7.0 and 8.0 alpha
Pharo 7.0 and 8.0 alphaPharo 7.0 and 8.0 alpha
Pharo 7.0 and 8.0 alpha
 
PHARO IoT: Installation Improvements and Continuous Integration
PHARO IoT: Installation Improvements and Continuous IntegrationPHARO IoT: Installation Improvements and Continuous Integration
PHARO IoT: Installation Improvements and Continuous Integration
 
Easy REST with OpenAPI
Easy REST with OpenAPIEasy REST with OpenAPI
Easy REST with OpenAPI
 
Comment soup with a pinch of types, served in a leaky bowl
Comment soup with a pinch of types, served in a leaky bowlComment soup with a pinch of types, served in a leaky bowl
Comment soup with a pinch of types, served in a leaky bowl
 
apart Framework: Porting from VisualWorks
apart Framework: Porting from VisualWorksapart Framework: Porting from VisualWorks
apart Framework: Porting from VisualWorks
 
XmppTalk
XmppTalkXmppTalk
XmppTalk
 
A living programming environment for blockchain
A living programming environment for blockchainA living programming environment for blockchain
A living programming environment for blockchain
 
Raspberry and Pharo
Raspberry and PharoRaspberry and Pharo
Raspberry and Pharo
 
Welcome: PharoDays 2017
Welcome: PharoDays 2017Welcome: PharoDays 2017
Welcome: PharoDays 2017
 
Pharo 6
Pharo 6Pharo 6
Pharo 6
 
Robotic Exploration and Mapping with Pharo
Robotic Exploration and Mapping with PharoRobotic Exploration and Mapping with Pharo
Robotic Exploration and Mapping with Pharo
 
Pharo 64bits
Pharo 64bitsPharo 64bits
Pharo 64bits
 
Smack: Behind the Refactorings
Smack: Behind the RefactoringsSmack: Behind the Refactorings
Smack: Behind the Refactorings
 
Pharo VM Performance
Pharo VM PerformancePharo VM Performance
Pharo VM Performance
 
Git with Style
Git with StyleGit with Style
Git with Style
 

Último

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Último (20)

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 

Advanced Reflection in Pharo