Reflection in Pharo5

Marcus Denker
Marcus DenkerResearch Scientist at INRIA
Reflection in Pharo5
ESUG 2015
Marcus Denker
http://www.pharo.org
Everything is an Object
Everything?
Classes, yes.
Methods, yes
But Code?
Code is a String!
AST: Abstract Syntax Tree
AST in Pharo5
• AST of the Refactoring browser
• Transformation
• Visitors
• Annotations (properties)
• Deeper integrated:
• Pretty Printing, Syntax Highlight, Suggestions
• Compiler uses RB AST
AST in Pharo5
• Easy access
• #ast
• Demo: method and block
DEMO
(OrderedCollection>>#do:) ast.
[ 1 + 2 ] sourceNode == thisContext method ast blockNodes first
• ASTCache: as twice, get the same answer
(flushed on image save for now)
AST + Tools
Opal Compiler
• Uses RB AST
• Based on Visitors
Text AST
AST
+vars
IR CM
Parser Semantic
Analysis
AST Translator+
IRBuilder
BytecodeBuilder+
Encoder
Opal: API
• All staged are Pluggable
• e.g Semantic Analyzer or Code Generator can
be changed.
• compiler options
Opal: Bytecode editing
• IR can be used to manipulate methods on a
bytecode level
Text AST
AST
+vars
IR CM
Parser Semantic
Analysis
AST Translator+
IRBuilder
BytecodeBuilder+
Encoder
Too complicated
Too low level
Can we do better?
AST Meta Annotation
• We have an AST with properties
• We have Opal with Pluggable API
Can’t we use that?
Basis: the Evil Twin
CompiledMethod ReflectiveMethod
Know
each
other
Bytecode AST
Basis: the Evil Twin
ReflectiveMethod
AST
run: aSelector with: anArray in: aReceiver
self installCompiledMethod.
self recompileAST.
self installCompiledMethod.
^compiledMethod
valueWithReceiver: aReceiver
arguments: anArray
Demo: Morph
• Morph methods do: #createTwin
• Morph methods do: #invalidate
• inspect “Morph methods”
Putting it together
• Annotate the AST
• Create Twin if needed
• Invalidate method
• Next call: generate code changed by annotation
recompileAST
ast compilationContext
semanticAnalyzerClass: RFSemanticAnalyzer;
astTranslatorClass: RFASTTranslator.
ast doSemanticAnalysis. "force semantic analysis"
compiledMethod := ast generate: compiledMethod trailer.
compiledMethod reflectiveMethod: self.
Annotations?
MetaLink
DEMO: Simple Link
node := (ReflectivityExamples>>#exampleMethod) ast.
link := MetaLink
new metaObject: (Object new);
selector: #halt.
node link: link.
ReflectivityExamples new exampleMethod
Meta Link
• When setting link:
• create twin if needed
• install reflective method
• On execution
• generate code and execute, install CM
Twin Switch
CompiledMethod ReflectiveMethod
Know
each
other
Bytecode AST
Link: metaobject
The object to send
a message to
link := MetaLink new
metaObject: [self halt]
Link: selector
The selector to send
link := MetaLink new
…..
selector: #value
Link: control
before, after, instead
link := MetaLink new
…..
control: #after
Link: control
after: #ensure: wrap
link := MetaLink new
…..
control: #after
Link: control
instead: last link wins
(for now no AOP around)
link := MetaLink new
…..
control: #instead
Link: condition
boolean or block
link := MetaLink new
…..
condition: [self someCheck]
Link: arguments
what to pass to the meta?
Reifications
• Every operation has data that it works on
• Send: #arguments, #receiver, #selector
• Assignment: #newValue, #name
• All: #node, #object, #context
Link: arguments
what to pass to the meta?
link := MetaLink new
…..
arguments: #(name newValue)
Reifications: condition
link := MetaLink new
condition: [: object | object == 1];
Virtual meta
• Reifications can be the meta object
link := MetaLink new
metaObject: #receiver;
selector: #perform:withArguments:;
arguments: #(selector arguments).
Statement Coverage
link := MetaLink new
metaObject: #node;
selector: #tagExecuted.
“set this link on all the AST nodes"
(ReflectivityExamples>>#exampleMethod) ast
nodesDo: [:node | node link: link].
Variables
• Helper methods
• But: can’t we annotate variables directly?
Point assignmentNodes
Friday: Slots+Globals
RoadMap
• Pharo4: Opal is default
• Pharo5
• Remove old Compiler/AST
• Reflectivity: First finished version
• Pharo6: Object specific links
Users
• Tools of ObjectProfile are being ported
• BreakPoints Pharo5
• Coverage Kernel by Pavel
• ….
Thanks!
• Work of many people…
• Too many to list here. (And I would forget for
sure someone)
Questions ?
1 of 48

Recommended

Variables in Pharo5 by
Variables in Pharo5Variables in Pharo5
Variables in Pharo5Marcus Denker
2.4K views31 slides
Reflection in Pharo: Beyond Smalltak by
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakMarcus Denker
1.2K views56 slides
PharoDAYS 2015: Pharo Status - by Markus Denker by
PharoDAYS 2015: Pharo Status - by Markus DenkerPharoDAYS 2015: Pharo Status - by Markus Denker
PharoDAYS 2015: Pharo Status - by Markus DenkerPharo
811 views13 slides
Dynamically Composing Collection Operations through Collection Promises by
Dynamically Composing Collection Operations through Collection PromisesDynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection PromisesMarcus Denker
727 views15 slides
Advanced Reflection in Pharo by
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in PharoMarcus Denker
4.6K views46 slides
Reflection in Pharo: Beyond Smalltak by
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakMarcus Denker
746 views56 slides

More Related Content

What's hot

#Pharo Days 2016 Data Formats and Protocols by
#Pharo Days 2016 Data Formats and Protocols#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and ProtocolsPhilippe Back
656 views106 slides
Pharo Status Fosdem 2015 by
Pharo Status Fosdem 2015Pharo Status Fosdem 2015
Pharo Status Fosdem 2015Marcus Denker
6.9K views40 slides
Gatling @ Scala.Io 2013 by
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013slandelle
6.1K views43 slides
java8-patterns by
java8-patternsjava8-patterns
java8-patternsJustin Lin
15.3K views44 slides
Rethinking the debugger by
Rethinking the debuggerRethinking the debugger
Rethinking the debuggerIulian Dragos
632 views34 slides
Pharo Status ESUG 2014 by
Pharo Status ESUG 2014Pharo Status ESUG 2014
Pharo Status ESUG 2014Marcus Denker
1.2K views43 slides

What's hot(19)

#Pharo Days 2016 Data Formats and Protocols by Philippe Back
#Pharo Days 2016 Data Formats and Protocols#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols
Philippe Back656 views
Pharo Status Fosdem 2015 by Marcus Denker
Pharo Status Fosdem 2015Pharo Status Fosdem 2015
Pharo Status Fosdem 2015
Marcus Denker6.9K views
Gatling @ Scala.Io 2013 by slandelle
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013
slandelle6.1K views
java8-patterns by Justin Lin
java8-patternsjava8-patterns
java8-patterns
Justin Lin15.3K views
Pharo Status ESUG 2014 by Marcus Denker
Pharo Status ESUG 2014Pharo Status ESUG 2014
Pharo Status ESUG 2014
Marcus Denker1.2K views
How to start using Scala by Ngoc Dao
How to start using ScalaHow to start using Scala
How to start using Scala
Ngoc Dao2.2K views
End to-end async and await by vfabro
End to-end async and awaitEnd to-end async and await
End to-end async and await
vfabro1.5K views
Async in .NET by RTigger
Async in .NETAsync in .NET
Async in .NET
RTigger1.8K views
Java 8 New features by Son Nguyen
Java 8 New featuresJava 8 New features
Java 8 New features
Son Nguyen1.2K views
Invitation to the dark side of Ruby by SATOSHI TAGOMORI
Invitation to the dark side of RubyInvitation to the dark side of Ruby
Invitation to the dark side of Ruby
SATOSHI TAGOMORI15.4K views
C# 8 in Libraries and Applications by Christian Nagel
C# 8 in Libraries and ApplicationsC# 8 in Libraries and Applications
C# 8 in Libraries and Applications
Christian Nagel202 views
SF Front End Developers - Ember + D3 by Ben Lesh
SF Front End Developers - Ember + D3SF Front End Developers - Ember + D3
SF Front End Developers - Ember + D3
Ben Lesh725 views

Viewers also liked

Perfection & Feedback Loops or: why worse is better by
Perfection & Feedback Loops or: why worse is betterPerfection & Feedback Loops or: why worse is better
Perfection & Feedback Loops or: why worse is betterMarcus Denker
7.5K views106 slides
Type Feedback for Bytecode Interpreters by
Type Feedback for Bytecode InterpretersType Feedback for Bytecode Interpreters
Type Feedback for Bytecode InterpretersMarcus Denker
700 views11 slides
Talk: The Present and Future of Pharo by
Talk: The Present and Future of PharoTalk: The Present and Future of Pharo
Talk: The Present and Future of PharoMarcus Denker
1.1K views44 slides
Practical, Pluggable Types by
Practical, Pluggable TypesPractical, Pluggable Types
Practical, Pluggable TypesMarcus Denker
586 views20 slides
Pharo Status (from PharoDays 2015) by
Pharo Status (from PharoDays 2015)Pharo Status (from PharoDays 2015)
Pharo Status (from PharoDays 2015)Marcus Denker
1.3K views13 slides
How to Contribute to Pharo by
How to Contribute to PharoHow to Contribute to Pharo
How to Contribute to PharoMarcus Denker
1.3K views14 slides

Viewers also liked(6)

Perfection & Feedback Loops or: why worse is better by Marcus Denker
Perfection & Feedback Loops or: why worse is betterPerfection & Feedback Loops or: why worse is better
Perfection & Feedback Loops or: why worse is better
Marcus Denker7.5K views
Type Feedback for Bytecode Interpreters by Marcus Denker
Type Feedback for Bytecode InterpretersType Feedback for Bytecode Interpreters
Type Feedback for Bytecode Interpreters
Marcus Denker700 views
Talk: The Present and Future of Pharo by Marcus Denker
Talk: The Present and Future of PharoTalk: The Present and Future of Pharo
Talk: The Present and Future of Pharo
Marcus Denker1.1K views
Practical, Pluggable Types by Marcus Denker
Practical, Pluggable TypesPractical, Pluggable Types
Practical, Pluggable Types
Marcus Denker586 views
Pharo Status (from PharoDays 2015) by Marcus Denker
Pharo Status (from PharoDays 2015)Pharo Status (from PharoDays 2015)
Pharo Status (from PharoDays 2015)
Marcus Denker1.3K views
How to Contribute to Pharo by Marcus Denker
How to Contribute to PharoHow to Contribute to Pharo
How to Contribute to Pharo
Marcus Denker1.3K views

Similar to Reflection in Pharo5

Lecture. Advanced Reflection: MetaLinks by
Lecture. Advanced Reflection: MetaLinksLecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinksMarcus Denker
11 views54 slides
Lecture: "Advanced Reflection: MetaLinks" by
Lecture: "Advanced Reflection: MetaLinks"Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Marcus Denker
11 views54 slides
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks by
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksVUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksMarcus Denker
213 views52 slides
Lecture: Advanced Reflection. MetaLinks by
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksMarcus Denker
1.4K views47 slides
Runtime Bytecode Transformation for Smalltalk by
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkMarcus Denker
410 views14 slides
Behavioral Reflection by
Behavioral ReflectionBehavioral Reflection
Behavioral ReflectionMarcus Denker
1.9K views32 slides

Similar to Reflection in Pharo5(20)

Lecture. Advanced Reflection: MetaLinks by Marcus Denker
Lecture. Advanced Reflection: MetaLinksLecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinks
Marcus Denker11 views
Lecture: "Advanced Reflection: MetaLinks" by Marcus Denker
Lecture: "Advanced Reflection: MetaLinks"Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"
Marcus Denker11 views
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks by Marcus Denker
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksVUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
Marcus Denker213 views
Lecture: Advanced Reflection. MetaLinks by Marcus Denker
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinks
Marcus Denker1.4K views
Runtime Bytecode Transformation for Smalltalk by Marcus Denker
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Marcus Denker410 views
Behavioral Reflection by Marcus Denker
Behavioral ReflectionBehavioral Reflection
Behavioral Reflection
Marcus Denker1.9K views
Runtime Bytecode Transformation for Smalltalk by ESUG
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
ESUG390 views
Build a game with javascript (april 2017) by Thinkful
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)
Thinkful352 views
Spring Day | Spring and Scala | Eberhard Wolff by JAX London
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
JAX London1.5K views
Build a game with javascript (may 21 atlanta) by Thinkful
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
Thinkful209 views
First class Variables in Pharo by ESUG
First class Variables in PharoFirst class Variables in Pharo
First class Variables in Pharo
ESUG617 views
2011-02-03 LA RubyConf Rails3 TDD Workshop by Wolfram Arnold
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
Wolfram Arnold708 views
The Many Ways to Test Your React App by All Things Open
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open2.1K views
Compiler Construction by Ahmed Raza
Compiler ConstructionCompiler Construction
Compiler Construction
Ahmed Raza1K views
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ... by AboutYouGmbH
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
AboutYouGmbH1.8K views
First Class Variables as AST Annotations by ESUG
 First Class Variables as AST Annotations First Class Variables as AST Annotations
First Class Variables as AST Annotations
ESUG58 views

More from Marcus Denker

Soil And Pharo by
Soil And PharoSoil And Pharo
Soil And PharoMarcus Denker
47 views12 slides
ConstantBlocks in Pharo11 by
ConstantBlocks in Pharo11ConstantBlocks in Pharo11
ConstantBlocks in Pharo11Marcus Denker
50 views26 slides
Demo: Improved DoIt by
Demo: Improved DoItDemo: Improved DoIt
Demo: Improved DoItMarcus Denker
4 views3 slides
First Class Variables as AST Annotations by
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST AnnotationsMarcus Denker
5 views42 slides
Supporting Pharo / Getting Pharo Support by
Supporting Pharo / Getting Pharo SupportSupporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo SupportMarcus Denker
8 views19 slides
thisContext in the Debugger by
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerMarcus Denker
413 views7 slides

More from Marcus Denker(16)

Recently uploaded

GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...James Anderson
85 views32 slides
PharoJS - Zürich Smalltalk Group Meetup November 2023 by
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023Noury Bouraqadi
127 views17 slides
Democratising digital commerce in India-Report by
Democratising digital commerce in India-ReportDemocratising digital commerce in India-Report
Democratising digital commerce in India-ReportKapil Khandelwal (KK)
15 views161 slides
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
80 views25 slides
Voice Logger - Telephony Integration Solution at Aegis by
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at AegisNirmal Sharma
39 views1 slide
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院IttrainingIttraining
52 views8 slides

Recently uploaded(20)

GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson85 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi127 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada127 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 views

Reflection in Pharo5