SlideShare uma empresa Scribd logo
1 de 56
Baixar para ler offline
Reflection in Pharo:
Beyond Smalltak
Marcus Denker
http://www.pharo.org
Talk held at SOFT, VUB, Brussels
Jan 2016
Everything is an Object
Classes
Methods
The Stack
Everything is an Object
Code?
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
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].
Users
• BreakPoints Pharo5
• Coverage Kernel
• ….
Everything is an Object
Everything is an object?
SmalltalkImage classVarNamed: #CompilerClass
==> returns value
Object binding class
==> Association
Why not an Object?
Globals/ClassVariables
• We are close: bindings are associations
• Add sublass “LiteralVariable”
• Sublasses GlobalVariable, ClassVariable
• Enhance API
Globals/ClassVariables
SmalltalkImage classVariableNamed: #CompilerClass
Object binding class
Globals: Reflective APi
global := SmalltalkImage classVariableNamed:
#CompilerClass
global read
global write: someObject
+ helper methods + compatibility methods
Everything is an object?
• Point instanceVariables
• 5@3 instVarNamed: ‘x’
• 5@3 instVarNamed: ‘y’ put: 6
Why not an Object?
Slots
Point slots
(Point slotNamed: #x) read: (3@4)
(Point slotNamed: #x) write: 7 to: (3@4)
Variables+MetaLink
• Helper methods
• But: can’t we annotate variables directly?
Point assignmentNodes
Variables + Links
• Object binding link: myMetaLink
• (Point slotNamed: #x) link: myMetaLink
(not yet in Pharo5)
Class Template
Object subclass: #MyClass
slots: { #x => WeakSlot }
classVariables: { }
category: 'Example'
Future
• Can’t we model bit patterns and bind them to
named virtual slots?
• How to model Array-like layouts better?
Questions ?

Mais conteúdo relacionado

Mais procurados

Actor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka FundamentalsActor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka Fundamentals
Ngoc Dao
 
使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架
jeffz
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
Ngoc Dao
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
Thinkful
 

Mais procurados (19)

Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 
Intro to Ruby on Rails
Intro to Ruby on RailsIntro to Ruby on Rails
Intro to Ruby on Rails
 
Roslyn
RoslynRoslyn
Roslyn
 
Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013
 
Model with actors and implement with Akka
Model with actors and implement with AkkaModel with actors and implement with Akka
Model with actors and implement with Akka
 
Load test REST APIs using gatling
Load test REST APIs using gatlingLoad test REST APIs using gatling
Load test REST APIs using gatling
 
Swift, a quick overview
Swift, a quick overviewSwift, a quick overview
Swift, a quick overview
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedy
 
Actor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka FundamentalsActor-based concurrency and Akka Fundamentals
Actor-based concurrency and Akka Fundamentals
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
 
使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
 
Xtend - better java with -less- noise
Xtend - better java with -less- noiseXtend - better java with -less- noise
Xtend - better java with -less- noise
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScript
 
JavaScript operators
JavaScript operatorsJavaScript operators
JavaScript operators
 
C# 8 in Libraries and Applications
C# 8 in Libraries and ApplicationsC# 8 in Libraries and Applications
C# 8 in Libraries and Applications
 
Introduction to Elm
Introduction to ElmIntroduction to Elm
Introduction to Elm
 

Destaque

ZAIRA ROCHA
ZAIRA ROCHAZAIRA ROCHA
ZAIRA ROCHA
zaii1
 

Destaque (17)

Marjori gordon
Marjori gordonMarjori gordon
Marjori gordon
 
Redes sociales en la educacion
Redes sociales en la educacionRedes sociales en la educacion
Redes sociales en la educacion
 
Generosidade na pratica (Pr. Rubens C. Ioricci)
Generosidade na pratica   (Pr. Rubens C. Ioricci)Generosidade na pratica   (Pr. Rubens C. Ioricci)
Generosidade na pratica (Pr. Rubens C. Ioricci)
 
Energía eléctrica
Energía eléctricaEnergía eléctrica
Energía eléctrica
 
Las vegas city fc sponsor
Las vegas city fc sponsorLas vegas city fc sponsor
Las vegas city fc sponsor
 
ZAIRA ROCHA
ZAIRA ROCHAZAIRA ROCHA
ZAIRA ROCHA
 
hussain2-1
hussain2-1hussain2-1
hussain2-1
 
Lecture 1 - Intro to Computer Vision, historical context.
Lecture 1 - Intro to Computer Vision, historical context.Lecture 1 - Intro to Computer Vision, historical context.
Lecture 1 - Intro to Computer Vision, historical context.
 
Control net
Control netControl net
Control net
 
Planificación y Control de Mantenimiento
Planificación y Control de MantenimientoPlanificación y Control de Mantenimiento
Planificación y Control de Mantenimiento
 
Ciutat del Vaticà
Ciutat del VaticàCiutat del Vaticà
Ciutat del Vaticà
 
Germany M.A.B 2 eso a
Germany M.A.B 2 eso aGermany M.A.B 2 eso a
Germany M.A.B 2 eso a
 
Instalaciones electricas
Instalaciones electricasInstalaciones electricas
Instalaciones electricas
 
06 Interfacing Keypad 4x4.2016
06 Interfacing Keypad 4x4.201606 Interfacing Keypad 4x4.2016
06 Interfacing Keypad 4x4.2016
 
Apostila de sociologia - Volume 2 (2° ano do EM)
Apostila de sociologia - Volume 2 (2° ano do EM)Apostila de sociologia - Volume 2 (2° ano do EM)
Apostila de sociologia - Volume 2 (2° ano do EM)
 
2010 Playboy Golf Finals Jp
2010 Playboy Golf Finals   Jp2010 Playboy Golf Finals   Jp
2010 Playboy Golf Finals Jp
 
Guía tailandia para instagram
Guía tailandia para instagramGuía tailandia para instagram
Guía tailandia para instagram
 

Semelhante a Reflection in Pharo: Beyond Smalltak

Working Effectively With Legacy Perl Code
Working Effectively With Legacy Perl CodeWorking Effectively With Legacy Perl Code
Working Effectively With Legacy Perl Code
erikmsp
 

Semelhante a Reflection in Pharo: Beyond Smalltak (20)

Behavioral Reflection in Pharo
Behavioral Reflection in PharoBehavioral Reflection in Pharo
Behavioral Reflection in Pharo
 
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
 
Behavioral Reflection
Behavioral ReflectionBehavioral Reflection
Behavioral Reflection
 
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
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
Sanity on Rails
Sanity on RailsSanity on Rails
Sanity on Rails
 
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
 
Lecture: Refactoring
Lecture: RefactoringLecture: Refactoring
Lecture: Refactoring
 
Working Effectively With Legacy Perl Code
Working Effectively With Legacy Perl CodeWorking Effectively With Legacy Perl Code
Working Effectively With Legacy Perl Code
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
 
First class Variables in Pharo
First class Variables in PharoFirst class Variables in Pharo
First class Variables in Pharo
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1
 
Opal compiler
Opal compilerOpal compiler
Opal compiler
 
SF Elixir Meetup - RethinkDB
SF Elixir Meetup - RethinkDBSF Elixir Meetup - RethinkDB
SF Elixir Meetup - RethinkDB
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) Roundup
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
 

Mais de Marcus Denker

Mais de Marcus Denker (20)

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
 
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
 
How to Contribute to Pharo
How to Contribute to PharoHow to Contribute to Pharo
How to Contribute to Pharo
 
Pharo Status (from PharoDays 2015)
Pharo Status (from PharoDays 2015)Pharo Status (from PharoDays 2015)
Pharo Status (from PharoDays 2015)
 
Pharo Status Fosdem 2015
Pharo Status Fosdem 2015Pharo Status Fosdem 2015
Pharo Status Fosdem 2015
 
Nomads do not build Cathedrals
Nomads do not build CathedralsNomads do not build Cathedrals
Nomads do not build Cathedrals
 

Último

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
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
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 

Reflection in Pharo: Beyond Smalltak