SlideShare a Scribd company logo
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 ?

More Related Content

PDF
Dynamically Composing Collection Operations through Collection Promises
PDF
Reflection in Pharo: Beyond Smalltak
PDF
Advanced Reflection in Pharo
PDF
Reflection in Pharo5
PDF
#Pharo Days 2016 Reflectivity
PDF
#Pharo Days 2016 Data Formats and Protocols
PDF
Pharo Status ESUG 2014
PDF
Lecture: MetaLinks
Dynamically Composing Collection Operations through Collection Promises
Reflection in Pharo: Beyond Smalltak
Advanced Reflection in Pharo
Reflection in Pharo5
#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Data Formats and Protocols
Pharo Status ESUG 2014
Lecture: MetaLinks

What's hot (19)

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

Viewers also liked (17)

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

Similar to Reflection in Pharo: Beyond Smalltak (20)

PDF
Behavioral Reflection in Pharo
PDF
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
PDF
Lecture: Advanced Reflection. MetaLinks
PDF
Lecture: "Advanced Reflection: MetaLinks"
PDF
Lecture. Advanced Reflection: MetaLinks
PDF
Advanced Reflection in Pharo
PPT
10 reflection
PDF
Pharo: a reflective language A first systematic analysis of reflective APIs
PPT
Stoop 305-reflective programming5
PDF
Reflection and Context
PDF
Refactoring
PDF
First class Variables in Pharo
PPT
Lecture: Refactoring
PDF
Lecture: Reflection
PDF
Pharo: A Reflective System
PPTX
Meta Object Protocols
PDF
Lecture: Reflection
PDF
The Reflectivity
PDF
Demo: Reflectivity
PDF
Ad-hoc Runtime Object Structure Visualizations with MetaLinks
Behavioral Reflection in Pharo
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
Lecture: Advanced Reflection. MetaLinks
Lecture: "Advanced Reflection: MetaLinks"
Lecture. Advanced Reflection: MetaLinks
Advanced Reflection in Pharo
10 reflection
Pharo: a reflective language A first systematic analysis of reflective APIs
Stoop 305-reflective programming5
Reflection and Context
Refactoring
First class Variables in Pharo
Lecture: Refactoring
Lecture: Reflection
Pharo: A Reflective System
Meta Object Protocols
Lecture: Reflection
The Reflectivity
Demo: Reflectivity
Ad-hoc Runtime Object Structure Visualizations with MetaLinks

More from Marcus Denker (20)

PDF
Soil And Pharo
PDF
ConstantBlocks in Pharo11
PDF
Demo: Improved DoIt
PDF
First Class Variables as AST Annotations
PDF
Supporting Pharo / Getting Pharo Support
PDF
thisContext in the Debugger
PDF
Variables in Pharo
PDF
Improving code completion for Pharo
PDF
Slot Composition
PDF
PHARO IOT
PDF
Open-Source: An Infinite Game
PDF
PharoTechTalk: Contributing to Pharo
PDF
Feedback Loops in Practice
PDF
Pharo6 - ESUG17
PDF
PDF
Perfection & Feedback Loops or: why worse is better
PDF
How to Contribute to Pharo
PDF
Pharo Status (from PharoDays 2015)
PDF
Pharo Status Fosdem 2015
PDF
Nomads do not build Cathedrals
Soil And Pharo
ConstantBlocks in Pharo11
Demo: Improved DoIt
First Class Variables as AST Annotations
Supporting Pharo / Getting Pharo Support
thisContext in the Debugger
Variables in Pharo
Improving code completion for Pharo
Slot Composition
PHARO IOT
Open-Source: An Infinite Game
PharoTechTalk: Contributing to Pharo
Feedback Loops in Practice
Pharo6 - ESUG17
Perfection & Feedback Loops or: why worse is better
How to Contribute to Pharo
Pharo Status (from PharoDays 2015)
Pharo Status Fosdem 2015
Nomads do not build Cathedrals

Recently uploaded (20)

PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
Transform Your Business with a Software ERP System
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
System and Network Administraation Chapter 3
PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Nekopoi APK 2025 free lastest update
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
top salesforce developer skills in 2025.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
Digital Strategies for Manufacturing Companies
PDF
System and Network Administration Chapter 2
Why Generative AI is the Future of Content, Code & Creativity?
Transform Your Business with a Software ERP System
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PTS Company Brochure 2025 (1).pdf.......
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
System and Network Administraation Chapter 3
Designing Intelligence for the Shop Floor.pdf
Operating system designcfffgfgggggggvggggggggg
Nekopoi APK 2025 free lastest update
iTop VPN Free 5.6.0.5262 Crack latest version 2025
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
top salesforce developer skills in 2025.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Odoo POS Development Services by CandidRoot Solutions
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Digital Strategies for Manufacturing Companies
System and Network Administration Chapter 2

Reflection in Pharo: Beyond Smalltak