SlideShare a Scribd company logo
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
2 instance variables

Object subclass: #Point!
! instanceVariableNames: 'x y'!
! classVariableNames: ''!
! poolDictionaries: ''!
! category: 'Kernel-BasicObjects'
•

Ask the class:
Point instVarNames

•

read:
3@4 instVarNamed: #x

•

write:
3@4 instVarNamed: #x put: 5
Great!
But…
This is just a String!

Object subclass: #Point!
! instanceVariableNames: 'x y'!
! classVariableNames: ''!
! poolDictionaries: ''!
! category: 'Kernel-BasicObjects'
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
•

•

Array layout
•

•

a Normal Object

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
Can we modify the behaviour of code?
>

Annotate the AST with meta-links
Method
Meta
Link
Why?
•

Change behaviour for selected AST Nodes

•

“All assignments”

•

“this message send”
But without changing the program code!
Breakpoints
DEMO: Atoms
Behavioral Reflection

meta-object
links

activation
condition
source code
(AST)

© Marcus Denker
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, MetaLinks
Questions???

More Related Content

PDF
Reflection in Pharo: Beyond Smalltak
PDF
#Pharo Days 2016 Reflectivity
PDF
Reflection in Pharo: Beyond Smalltak
PDF
Dynamically Composing Collection Operations through Collection Promises
PDF
#Pharo Days 2016 Data Formats and Protocols
PDF
Reflection in Pharo5
PDF
Pharo Status ESUG 2014
PDF
PharoDAYS 2015: Pharo Status - by Markus Denker
Reflection in Pharo: Beyond Smalltak
#Pharo Days 2016 Reflectivity
Reflection in Pharo: Beyond Smalltak
Dynamically Composing Collection Operations through Collection Promises
#Pharo Days 2016 Data Formats and Protocols
Reflection in Pharo5
Pharo Status ESUG 2014
PharoDAYS 2015: Pharo Status - by Markus Denker

What's hot (19)

ODP
How to start using Scala
PPTX
Intro to Ruby on Rails
PPTX
Actor-based concurrency and Akka Fundamentals
PDF
A Type-level Ruby Interpreter for Testing and Understanding
PDF
Variables in Pharo5
ODP
Getting started with typescript and angular 2
PDF
JavaScript Essentials for Ember development
PPTX
Functional programming with Java 8
PDF
The dark side of Akka and the remedy
PDF
使用.NET构建轻量级分布式框架
PDF
Swift, a quick overview
PPTX
TypeScript - Silver Bullet for the Full-stack Developers
PPTX
Overview of CoffeeScript
PDF
Functional programming with Java 8
PDF
How we migrated Zalando app to Swift3?
PDF
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
PDF
java8-patterns
PDF
Xtend - better java with -less- noise
How to start using Scala
Intro to Ruby on Rails
Actor-based concurrency and Akka Fundamentals
A Type-level Ruby Interpreter for Testing and Understanding
Variables in Pharo5
Getting started with typescript and angular 2
JavaScript Essentials for Ember development
Functional programming with Java 8
The dark side of Akka and the remedy
使用.NET构建轻量级分布式框架
Swift, a quick overview
TypeScript - Silver Bullet for the Full-stack Developers
Overview of CoffeeScript
Functional programming with Java 8
How we migrated Zalando app to Swift3?
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
java8-patterns
Xtend - better java with -less- noise
Ad

Viewers also liked (20)

PDF
Canary Islands Hub tax incentives by Price Waterhouse Cooper
PDF
Datos inmuebles estandar xml urbaniza
PDF
Precise Fluid Control - Diener Precision Pumps
PDF
Ventajas de las baterias zinc aire
PPT
Seminario Sobre Datasets Consorcio Madrono
PDF
Siete días. La estabilidad marcan los presupuestos del 2011
PPT
Citi Ae Training
PDF
Anton Saputro Portfolio March 2012
PDF
Euro rscg millennials+socialmedia
PDF
Congreso de presupuesto y finanzas públicas
PDF
Casadeco
PPT
Openid Presentation - A Quick Introduction
PPT
Programa Para Regiones Bs As Catedra Uupp
PDF
Www zenparaopositores com
PDF
Presentación CAC, Consultoría en Ahorro de Costes
PDF
Live Communication as value added factor in marketing
PDF
Aprenda servlets de java como si estuviera en segundo
PPT
Mein Traumurlaub
PPT
EL ARRAYÁN EN LA ALHAMBRA
Canary Islands Hub tax incentives by Price Waterhouse Cooper
Datos inmuebles estandar xml urbaniza
Precise Fluid Control - Diener Precision Pumps
Ventajas de las baterias zinc aire
Seminario Sobre Datasets Consorcio Madrono
Siete días. La estabilidad marcan los presupuestos del 2011
Citi Ae Training
Anton Saputro Portfolio March 2012
Euro rscg millennials+socialmedia
Congreso de presupuesto y finanzas públicas
Casadeco
Openid Presentation - A Quick Introduction
Programa Para Regiones Bs As Catedra Uupp
Www zenparaopositores com
Presentación CAC, Consultoría en Ahorro de Costes
Live Communication as value added factor in marketing
Aprenda servlets de java como si estuviera en segundo
Mein Traumurlaub
EL ARRAYÁN EN LA ALHAMBRA
Ad

Similar to Advanced Reflection in Pharo (20)

PDF
Advanced Reflection in Pharo
PDF
Pharo Status ESUG 2014
PDF
Behavioral Reflection in Pharo
PDF
Pharo: A Reflective System
PDF
Pharo: A Reflective System
PDF
Pharo Status ESUG 2014
PDF
First class Variables in Pharo
PDF
Runtime Type Collection and its usage in Code Transpiling
PDF
Pharo: a reflective language A first systematic analysis of reflective APIs
PDF
Towards a flexible Pharo Compiler
PDF
Towards a flexible Pharo Compiler
PDF
Towards a flexible Pharo Compiler
PDF
Variables in Pharo
PDF
Pharo: Objects at your Fingertips
PDF
Pharo Status
PDF
Pharo Status (Fosdem 2015)
PDF
Pharo Status Fosdem 2015
PDF
Understanding And Using Reflection
PDF
Pharo: Objects at your Fingertips
PPT
Stoop 305-reflective programming5
Advanced Reflection in Pharo
Pharo Status ESUG 2014
Behavioral Reflection in Pharo
Pharo: A Reflective System
Pharo: A Reflective System
Pharo Status ESUG 2014
First class Variables in Pharo
Runtime Type Collection and its usage in Code Transpiling
Pharo: a reflective language A first systematic analysis of reflective APIs
Towards a flexible Pharo Compiler
Towards a flexible Pharo Compiler
Towards a flexible Pharo Compiler
Variables in Pharo
Pharo: Objects at your Fingertips
Pharo Status
Pharo Status (Fosdem 2015)
Pharo Status Fosdem 2015
Understanding And Using Reflection
Pharo: Objects at your Fingertips
Stoop 305-reflective programming5

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
Lecture: "Advanced Reflection: MetaLinks"
PDF
thisContext in the Debugger
PDF
Lecture. Advanced Reflection: MetaLinks
PDF
Improving code completion for Pharo
PDF
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
PDF
Slot Composition
PDF
Lecture: Advanced Reflection. MetaLinks
PDF
PHARO IOT
PDF
Open-Source: An Infinite Game
PDF
Lecture: MetaLinks
PDF
PharoTechTalk: Contributing to Pharo
PDF
Feedback Loops in Practice
PDF
Pharo6 - ESUG17
PDF
PDF
Perfection & Feedback Loops or: why worse is better
Soil And Pharo
ConstantBlocks in Pharo11
Demo: Improved DoIt
First Class Variables as AST Annotations
Supporting Pharo / Getting Pharo Support
Lecture: "Advanced Reflection: MetaLinks"
thisContext in the Debugger
Lecture. Advanced Reflection: MetaLinks
Improving code completion for Pharo
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
Slot Composition
Lecture: Advanced Reflection. MetaLinks
PHARO IOT
Open-Source: An Infinite Game
Lecture: MetaLinks
PharoTechTalk: Contributing to Pharo
Feedback Loops in Practice
Pharo6 - ESUG17
Perfection & Feedback Loops or: why worse is better

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Big Data Technologies - Introduction.pptx
PDF
KodekX | Application Modernization Development
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
Teaching material agriculture food technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
MYSQL Presentation for SQL database connectivity
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Big Data Technologies - Introduction.pptx
KodekX | Application Modernization Development
Chapter 3 Spatial Domain Image Processing.pdf
Teaching material agriculture food technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectral efficient network and resource selection model in 5G networks
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
MYSQL Presentation for SQL database connectivity

Advanced Reflection in Pharo