SlideShare une entreprise Scribd logo
1  sur  48
Télécharger pour lire hors ligne
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 ?

Contenu connexe

Tendances

How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
Ngoc Dao
 
End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
vfabro
 
Async in .NET
Async in .NETAsync in .NET
Async in .NET
RTigger
 

Tendances (19)

#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols
 
Pharo Status Fosdem 2015
Pharo Status Fosdem 2015Pharo Status Fosdem 2015
Pharo Status Fosdem 2015
 
Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013
 
java8-patterns
java8-patternsjava8-patterns
java8-patterns
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
 
Pharo Status ESUG 2014
Pharo Status ESUG 2014Pharo Status ESUG 2014
Pharo Status ESUG 2014
 
Java 8 concurrency abstractions
Java 8 concurrency abstractionsJava 8 concurrency abstractions
Java 8 concurrency abstractions
 
How we migrated Zalando app to Swift3?
How we migrated Zalando app to Swift3?How we migrated Zalando app to Swift3?
How we migrated Zalando app to Swift3?
 
Async Programming in C# 5
Async Programming in C# 5Async Programming in C# 5
Async Programming in C# 5
 
Lecture: MetaLinks
Lecture: MetaLinksLecture: MetaLinks
Lecture: MetaLinks
 
Load test REST APIs using gatling
Load test REST APIs using gatlingLoad test REST APIs using gatling
Load test REST APIs using gatling
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
 
End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
 
Async in .NET
Async in .NETAsync in .NET
Async in .NET
 
Maccro Strikes Back
Maccro Strikes BackMaccro Strikes Back
Maccro Strikes Back
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New features
 
Invitation to the dark side of Ruby
Invitation to the dark side of RubyInvitation to the dark side of Ruby
Invitation to the dark side of Ruby
 
C# 8 in Libraries and Applications
C# 8 in Libraries and ApplicationsC# 8 in Libraries and Applications
C# 8 in Libraries and Applications
 
SF Front End Developers - Ember + D3
SF Front End Developers - Ember + D3SF Front End Developers - Ember + D3
SF Front End Developers - Ember + D3
 

En vedette

En vedette (6)

Perfection & Feedback Loops or: why worse is better
Perfection & Feedback Loops or: why worse is betterPerfection & Feedback Loops or: why worse is better
Perfection & Feedback Loops or: why worse is better
 
Type Feedback for Bytecode Interpreters
Type Feedback for Bytecode InterpretersType Feedback for Bytecode Interpreters
Type Feedback for Bytecode Interpreters
 
Talk: The Present and Future of Pharo
Talk: The Present and Future of PharoTalk: The Present and Future of Pharo
Talk: The Present and Future of Pharo
 
Practical, Pluggable Types
Practical, Pluggable TypesPractical, Pluggable Types
Practical, Pluggable Types
 
Pharo Status (from PharoDays 2015)
Pharo Status (from PharoDays 2015)Pharo Status (from PharoDays 2015)
Pharo Status (from PharoDays 2015)
 
How to Contribute to Pharo
How to Contribute to PharoHow to Contribute to Pharo
How to Contribute to Pharo
 

Similaire à Reflection in Pharo5

Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)
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)
Build a game with javascript (may 21 atlanta)
Thinkful
 

Similaire à Reflection in Pharo5 (20)

Lecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinksLecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinks
 
Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"
 
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksVUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
 
Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinks
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
 
Behavioral Reflection
Behavioral ReflectionBehavioral Reflection
Behavioral Reflection
 
Opal compiler
Opal compilerOpal compiler
Opal compiler
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
 
Angular4 kickstart
Angular4 kickstartAngular4 kickstart
Angular4 kickstart
 
Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
 
First class Variables in Pharo
First class Variables in PharoFirst class Variables in Pharo
First class Variables in Pharo
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
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, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
 
First Class Variables as AST Annotations
 First Class Variables as AST Annotations First Class Variables as AST Annotations
First Class Variables as AST Annotations
 

Plus de Marcus Denker

Plus de Marcus Denker (16)

Soil And Pharo
Soil And PharoSoil And Pharo
Soil And Pharo
 
ConstantBlocks in Pharo11
ConstantBlocks in Pharo11ConstantBlocks in Pharo11
ConstantBlocks in Pharo11
 
Demo: Improved DoIt
Demo: Improved DoItDemo: Improved DoIt
Demo: Improved DoIt
 
First Class Variables as AST Annotations
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST Annotations
 
Supporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo SupportSupporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo Support
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Variables in Pharo
Variables in PharoVariables in Pharo
Variables in Pharo
 
Improving code completion for Pharo
Improving code completion for PharoImproving code completion for Pharo
Improving code completion for Pharo
 
Slot Composition
Slot CompositionSlot Composition
Slot Composition
 
PHARO IOT
PHARO IOTPHARO IOT
PHARO IOT
 
Open-Source: An Infinite Game
Open-Source: An Infinite GameOpen-Source: An Infinite Game
Open-Source: An Infinite Game
 
PharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to PharoPharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to Pharo
 
Feedback Loops in Practice
Feedback Loops in PracticeFeedback Loops in Practice
Feedback Loops in Practice
 
Pharo6 - ESUG17
Pharo6 - ESUG17Pharo6 - ESUG17
Pharo6 - ESUG17
 
Pharo6
Pharo6Pharo6
Pharo6
 
Nomads do not build Cathedrals
Nomads do not build CathedralsNomads do not build Cathedrals
Nomads do not build Cathedrals
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Reflection in Pharo5