SlideShare uma empresa Scribd logo
1 de 37
Baixar para ler offline
Advanced Reflection:
MetaLinks
Marcus Denker, Inria
http://marcusdenker.de
Lecture at VUB Brussels, March 22, 2018
What we know…
• Smalltalk is reflective

• Classes, Methods, Stack-Frames… are Objects

• Reflective API on all Objects
Take home message
• Reflection is based on the meta-class model, thus
inherently structural.
• Behavioural reflection limited to:
• Method lookup upon failure ( doesNotUnderstand:
message)
• Current execution reified (thisContext)
61
Can we do better?
• A more fine-grained reflective mechanism seems to be
missing

• Let’s look again at a Method in the Inspector
Inspector on a Method
The AST
• AST = Abstract Syntax Tree

• Tree Representation of the Method

• Produced by the Parser (part of the Compiler)

• Used by all tools (refactoring, syntax-highlighting,…)
Smalltalk compiler parse: 'test ^(1+2)'
The Compiler
• Smalltalk compiler -> Compiler Facade 

• Classes define the compiler to use

• You can override method #compiler

• Behind: Compiler Chain
The Compiler
Source AST
Annotated
AST
IR
Annotated
AST
Bytecode
RBParser OCSemanticAnalyzer
OCASTTranslator/
IRBuilder
IRBytecodeGenerator
AST
• RBMethodNode Root

• RBVariableNode Variable (read and write)

• RBAssignmentNode Assignment

• RBMessageNode A Message (most of them)

• RBReturnNode Return
AST: Navigation
• To make it easy to find and enumerate nodes, there are
some helper methods

• CompiledMethod has: #sendNodes,
#variableNodes, #assignmentNodes
• Every AST node has #nodesDo: and #allChildren
Inspect a simple AST
• A very simple Example
Smalltalk compiler parse: 'test ^(1+2)'
Integration
• Originally just internal to the compiler

• Pharo: 

• send #ast to a method to get the AST

• Cached for persistency.
(Point>>#x) ast == (Point>>#x) ast
—> true
Wouldn’t it be nice..
• With the AST, wouldn’t it be nice if we could use this
structure for Behavioural Reflection?

• If we could somehow attach a “arrow to the code” that
points to a meta-object
test
^( 1 + 2 )
meta-object
for this Send
We have all pieces…
• We have the AST for each method

• It is quite simple

• We have a compiler in the system

• So this should be possible…
The MetaLink
• MetaLink points to metaObject

• Defines a selector to call

• And a control attribute: #before, #after, #instead

• Installed on a AST node:
link := MetaLink new
metaObject: Halt;
selector: #once;
control: #before.
(Number>>#sin) ast link: link
The MetaLink
• Can be installed on any AST Node

• Methods will be re-compiled on the fly just before next
execution

• Link installation is very fast

• Changing a method removes all links from this method

• Managing link re-installation has to be done by the user
MetaLink: MetaObject
• MetaObject can be any object

• Even a Block: [Transcript show ‘hello’]
• Install on any Node with #link:

• de-install a link with #uninstall
MetaLink: Selector
• MetaLink defines a message send to the MetaObject

• #selector defines which one

• Default is #value

• Yes, a selector with arguments is supported 

• We can pass information to the meta-object
MetaLink: Argument
• The arguments define which arguments to pass

• We support a number of reifications
Reifications
• Reifications define data to be passed as arguments

• Reify —> Make something into an object that is not one
normally

• Example: “All arguments of this message”
Reifications: examples
• All nodes: #object #context #class #node
#link
• Sends: #arguments #receiver #selector
• Method: #arguments #selector 

• Variable: #value

They are defined as subclasses of class RFReification
Reifications as MetaObject
• We support some special metaObjects:

• #node The AST Node we are installed on

• #object self at runtime

• #class The class the links is installed in
MetaLink: Condition
• We can specify a condition for the MetaLink

• Link is active if the condition evaluates to true
• We can pass reifications as arguments
link := MetaLink new
metaObject: Halt;
selector: #once;
condition: [:object | object == 5] arguments: #(object).
(Number>>#sin) ast link: link.
MetaLink: control
• We can specify when to call the meta-object

• We support #before, #after and #instead
• The instead is very simple: last one wins
Example: Log
• We want to just print something to the Transcript
link := MetaLink new
metaObject: [Transcript show: 'Reached Here'].
(Number>>#sin) ast link: link
Recursion Problem
• Before we see more examples: There is a problem

• Imagine we put a MetaLink on some method deep in the
System (e.g new, +, do: ).

• Our Meta-Object might use exactly that method, too
Endless Loop!!
Recursion Problem
• Solution: Meta-Level

• We encode the a level in the execution of the system

• Every Link Activation increases the level

• A meta-link is just active for one level. (e.g. 0)
link := MetaLink new
metaObject: [ Object new ];
level: 0.
(Behavior>>#new) ast link: link.
Example: Log
• Better use #level: 0

• Nevertheless: be careful! If you add this to method called
often it can be very slow.
link := MetaLink new
metaObject: [Transcript show: 'Reached Here’];
level: 0.
Example: Counter
• In the Browser you can add a “counter” to the AST

• See class ExecutionCounter
install
link := MetaLink new
metaObject: self;
selector: #increase.
node link: link.
Example: Breakpoint
• “Add Breakpoint” in AST (Suggestions) Menu

• See class Breakpoint

• Break Once 

• Conditional Break breakLink
^ MetaLink new
metaObject: Break;
selector: #break;
options: options
Example: WatchPoint
• Watchpoint: Record Value at a point in the AST

• Example: Watch event in WorldMorph>>#mouseDown:
Click on background
-> value recorded
Example: WatchPoint
• Implementation: class Watchpoint, method install

• example of a #after link with a condition
link := MetaLink new
metaObject: self;
selector: #addValue:;
arguments: #(value);
control: #after;
condition: [ recording ].
Example: Code Coverage
• Small Demo.

• Start with CoverageDemo new openWithSpec
Example: Code Coverage
• Example of a MetaLink with a #node MetObject

• Meta-Object is the node that the link is installed on
link := MetaLink new
metaObject: #node;
selector: #tagExecuted.
Interesting Properties
• Cross Cutting

• One Link can be installed multiple times

• Over multiple methods and even Classes

• And across operations (e.g., Send and Assignment) as
long as all reifications requested are compatible

• Fully Dynamic: Links can be added and removed at runtime

• Even by the meta-object of another meta-link!
Limitations
• Better use Pharo7 (we are improving it still)

• Still some bugs with #after on MethodNode

• Loops: next execution of a method. Need to restart long
running loops (no on-stack replacement).

• Keep in mind: next metaLink taken into account for next
method activation 

• Take care with long running loops!
Help Wanted
• We are always interested in improvements!

• Pharo7 is under active development. 

• Pull Requests Welcome!

Mais conteúdo relacionado

Mais procurados

Dimensional Tolerances
Dimensional TolerancesDimensional Tolerances
Dimensional Tolerancess2francetrip
 
Tool engineering by McGRAW HILL
Tool engineering by McGRAW HILLTool engineering by McGRAW HILL
Tool engineering by McGRAW HILLParthiv Panchal
 
Lifting Presentation.
Lifting Presentation.Lifting Presentation.
Lifting Presentation.paul doherty
 
Safety in mechanical maintenance
Safety in mechanical  maintenanceSafety in mechanical  maintenance
Safety in mechanical maintenancePrasadroshan Mythin
 
Safety bulletin 031 ring finger injuries
Safety bulletin 031 ring finger injuriesSafety bulletin 031 ring finger injuries
Safety bulletin 031 ring finger injuriesAlan Bassett
 
Manufacturing tools and Safety precautions
Manufacturing tools and Safety precautionsManufacturing tools and Safety precautions
Manufacturing tools and Safety precautionsvigyanashram
 
Crimping Tool, Cembre Crimpstar Ratchet Tool 0.25-6sqmm - Cembre HP3
Crimping Tool, Cembre Crimpstar Ratchet Tool 0.25-6sqmm - Cembre HP3Crimping Tool, Cembre Crimpstar Ratchet Tool 0.25-6sqmm - Cembre HP3
Crimping Tool, Cembre Crimpstar Ratchet Tool 0.25-6sqmm - Cembre HP3Thorne & Derrick International
 
Lifting Equipment
Lifting Equipment Lifting Equipment
Lifting Equipment Manish Yadav
 
Lock Out Tag Out Safe Work Procedure
Lock Out Tag Out Safe Work Procedure Lock Out Tag Out Safe Work Procedure
Lock Out Tag Out Safe Work Procedure Julian Kalac P.Eng
 
Lifting Equipment Inspection
Lifting Equipment InspectionLifting Equipment Inspection
Lifting Equipment InspectionSchilling s
 
Machine Shop Presentation
Machine Shop PresentationMachine Shop Presentation
Machine Shop PresentationMichael Nuschke
 
Hot Work Permit Program Safety Training by UNC
Hot Work Permit Program Safety Training by UNCHot Work Permit Program Safety Training by UNC
Hot Work Permit Program Safety Training by UNCAtlantic Training, LLC.
 

Mais procurados (20)

Dimensional Tolerances
Dimensional TolerancesDimensional Tolerances
Dimensional Tolerances
 
Webbing Sling
Webbing SlingWebbing Sling
Webbing Sling
 
Tool engineering by McGRAW HILL
Tool engineering by McGRAW HILLTool engineering by McGRAW HILL
Tool engineering by McGRAW HILL
 
Gi2011machineguard
Gi2011machineguardGi2011machineguard
Gi2011machineguard
 
Lifting Presentation.
Lifting Presentation.Lifting Presentation.
Lifting Presentation.
 
Safety in mechanical maintenance
Safety in mechanical  maintenanceSafety in mechanical  maintenance
Safety in mechanical maintenance
 
Safety bulletin 031 ring finger injuries
Safety bulletin 031 ring finger injuriesSafety bulletin 031 ring finger injuries
Safety bulletin 031 ring finger injuries
 
Workshop safety
Workshop safetyWorkshop safety
Workshop safety
 
Weekly welding machine checklist
Weekly welding machine checklistWeekly welding machine checklist
Weekly welding machine checklist
 
Manufacturing tools and Safety precautions
Manufacturing tools and Safety precautionsManufacturing tools and Safety precautions
Manufacturing tools and Safety precautions
 
LOTO 2
LOTO 2LOTO 2
LOTO 2
 
Crimping Tool, Cembre Crimpstar Ratchet Tool 0.25-6sqmm - Cembre HP3
Crimping Tool, Cembre Crimpstar Ratchet Tool 0.25-6sqmm - Cembre HP3Crimping Tool, Cembre Crimpstar Ratchet Tool 0.25-6sqmm - Cembre HP3
Crimping Tool, Cembre Crimpstar Ratchet Tool 0.25-6sqmm - Cembre HP3
 
Hand and Power Tools by OSHAX.org
Hand and Power Tools by OSHAX.orgHand and Power Tools by OSHAX.org
Hand and Power Tools by OSHAX.org
 
Lifting Equipment
Lifting Equipment Lifting Equipment
Lifting Equipment
 
스팀트랩
스팀트랩스팀트랩
스팀트랩
 
Lock Out Tag Out Safe Work Procedure
Lock Out Tag Out Safe Work Procedure Lock Out Tag Out Safe Work Procedure
Lock Out Tag Out Safe Work Procedure
 
Safety In Gas Cutting.
Safety In Gas Cutting.Safety In Gas Cutting.
Safety In Gas Cutting.
 
Lifting Equipment Inspection
Lifting Equipment InspectionLifting Equipment Inspection
Lifting Equipment Inspection
 
Machine Shop Presentation
Machine Shop PresentationMachine Shop Presentation
Machine Shop Presentation
 
Hot Work Permit Program Safety Training by UNC
Hot Work Permit Program Safety Training by UNCHot Work Permit Program Safety Training by UNC
Hot Work Permit Program Safety Training by UNC
 

Semelhante a Lecture: MetaLinks

Lecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinksLecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinksMarcus Denker
 
Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Marcus Denker
 
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: MetaLinksMarcus Denker
 
Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksMarcus Denker
 
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5Marcus Denker
 
Behavioral Reflection in Pharo
Behavioral Reflection in PharoBehavioral Reflection in Pharo
Behavioral Reflection in PharoESUG
 
#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity#Pharo Days 2016 Reflectivity
#Pharo Days 2016 ReflectivityPhilippe Back
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakMarcus Denker
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakMarcus Denker
 
Behavioral Reflection
Behavioral ReflectionBehavioral Reflection
Behavioral ReflectionMarcus Denker
 
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 WolffJAX London
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkMarcus Denker
 
How to use UseContext Hook in React.pptx
How to use UseContext Hook in React.pptxHow to use UseContext Hook in React.pptx
How to use UseContext Hook in React.pptxBOSC Tech Labs
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkESUG
 
react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryjanet736113
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template LibraryGauravPatil318
 

Semelhante a Lecture: MetaLinks (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
 
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5
 
Behavioral Reflection in Pharo
Behavioral Reflection in PharoBehavioral Reflection in Pharo
Behavioral Reflection in Pharo
 
#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 
Behavioral Reflection
Behavioral ReflectionBehavioral Reflection
Behavioral Reflection
 
KnockoutJS and MVVM
KnockoutJS and MVVMKnockoutJS and MVVM
KnockoutJS and MVVM
 
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
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
 
How to use UseContext Hook in React.pptx
How to use UseContext Hook in React.pptxHow to use UseContext Hook in React.pptx
How to use UseContext Hook in React.pptx
 
Intro to Rails 4
Intro to Rails 4Intro to Rails 4
Intro to Rails 4
 
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for SmalltalkRuntime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
 
react-slides.pdf
react-slides.pdfreact-slides.pdf
react-slides.pdf
 
react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react library
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 

Mais de Marcus Denker

ConstantBlocks in Pharo11
ConstantBlocks in Pharo11ConstantBlocks in Pharo11
ConstantBlocks in Pharo11Marcus Denker
 
First Class Variables as AST Annotations
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST AnnotationsMarcus Denker
 
Supporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo SupportSupporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo SupportMarcus Denker
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerMarcus Denker
 
Improving code completion for Pharo
Improving code completion for PharoImproving code completion for Pharo
Improving code completion for PharoMarcus Denker
 
Open-Source: An Infinite Game
Open-Source: An Infinite GameOpen-Source: An Infinite Game
Open-Source: An Infinite GameMarcus Denker
 
PharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to PharoPharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to PharoMarcus Denker
 
Feedback Loops in Practice
Feedback Loops in PracticeFeedback Loops in Practice
Feedback Loops in PracticeMarcus Denker
 
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 betterMarcus Denker
 
Dynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection PromisesDynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection PromisesMarcus Denker
 
How to Contribute to Pharo
How to Contribute to PharoHow to Contribute to Pharo
How to Contribute to PharoMarcus Denker
 
Pharo Status (from PharoDays 2015)
Pharo Status (from PharoDays 2015)Pharo Status (from PharoDays 2015)
Pharo Status (from PharoDays 2015)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
 
Dynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection PromisesDynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection Promises
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 
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)
 

Último

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
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.pdfproinshot.com
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
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.pdfkalichargn70th171
 
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 AidPhilip Schwarz
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 

Último (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
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
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
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
 
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
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 

Lecture: MetaLinks

  • 1. Advanced Reflection: MetaLinks Marcus Denker, Inria http://marcusdenker.de Lecture at VUB Brussels, March 22, 2018
  • 2. What we know… • Smalltalk is reflective • Classes, Methods, Stack-Frames… are Objects • Reflective API on all Objects
  • 3. Take home message • Reflection is based on the meta-class model, thus inherently structural. • Behavioural reflection limited to: • Method lookup upon failure ( doesNotUnderstand: message) • Current execution reified (thisContext) 61
  • 4. Can we do better? • A more fine-grained reflective mechanism seems to be missing • Let’s look again at a Method in the Inspector
  • 5. Inspector on a Method
  • 6. The AST • AST = Abstract Syntax Tree • Tree Representation of the Method • Produced by the Parser (part of the Compiler) • Used by all tools (refactoring, syntax-highlighting,…) Smalltalk compiler parse: 'test ^(1+2)'
  • 7. The Compiler • Smalltalk compiler -> Compiler Facade • Classes define the compiler to use • You can override method #compiler • Behind: Compiler Chain
  • 8. The Compiler Source AST Annotated AST IR Annotated AST Bytecode RBParser OCSemanticAnalyzer OCASTTranslator/ IRBuilder IRBytecodeGenerator
  • 9. AST • RBMethodNode Root • RBVariableNode Variable (read and write) • RBAssignmentNode Assignment • RBMessageNode A Message (most of them) • RBReturnNode Return
  • 10. AST: Navigation • To make it easy to find and enumerate nodes, there are some helper methods • CompiledMethod has: #sendNodes, #variableNodes, #assignmentNodes • Every AST node has #nodesDo: and #allChildren
  • 11. Inspect a simple AST • A very simple Example Smalltalk compiler parse: 'test ^(1+2)'
  • 12. Integration • Originally just internal to the compiler • Pharo: • send #ast to a method to get the AST • Cached for persistency. (Point>>#x) ast == (Point>>#x) ast —> true
  • 13. Wouldn’t it be nice.. • With the AST, wouldn’t it be nice if we could use this structure for Behavioural Reflection? • If we could somehow attach a “arrow to the code” that points to a meta-object test ^( 1 + 2 ) meta-object for this Send
  • 14. We have all pieces… • We have the AST for each method • It is quite simple • We have a compiler in the system • So this should be possible…
  • 15. The MetaLink • MetaLink points to metaObject • Defines a selector to call • And a control attribute: #before, #after, #instead • Installed on a AST node: link := MetaLink new metaObject: Halt; selector: #once; control: #before. (Number>>#sin) ast link: link
  • 16. The MetaLink • Can be installed on any AST Node • Methods will be re-compiled on the fly just before next execution • Link installation is very fast • Changing a method removes all links from this method • Managing link re-installation has to be done by the user
  • 17. MetaLink: MetaObject • MetaObject can be any object • Even a Block: [Transcript show ‘hello’] • Install on any Node with #link: • de-install a link with #uninstall
  • 18. MetaLink: Selector • MetaLink defines a message send to the MetaObject • #selector defines which one • Default is #value • Yes, a selector with arguments is supported • We can pass information to the meta-object
  • 19. MetaLink: Argument • The arguments define which arguments to pass • We support a number of reifications
  • 20. Reifications • Reifications define data to be passed as arguments • Reify —> Make something into an object that is not one normally • Example: “All arguments of this message”
  • 21. Reifications: examples • All nodes: #object #context #class #node #link • Sends: #arguments #receiver #selector • Method: #arguments #selector • Variable: #value
 They are defined as subclasses of class RFReification
  • 22. Reifications as MetaObject • We support some special metaObjects: • #node The AST Node we are installed on • #object self at runtime • #class The class the links is installed in
  • 23. MetaLink: Condition • We can specify a condition for the MetaLink • Link is active if the condition evaluates to true • We can pass reifications as arguments link := MetaLink new metaObject: Halt; selector: #once; condition: [:object | object == 5] arguments: #(object). (Number>>#sin) ast link: link.
  • 24. MetaLink: control • We can specify when to call the meta-object • We support #before, #after and #instead • The instead is very simple: last one wins
  • 25. Example: Log • We want to just print something to the Transcript link := MetaLink new metaObject: [Transcript show: 'Reached Here']. (Number>>#sin) ast link: link
  • 26. Recursion Problem • Before we see more examples: There is a problem • Imagine we put a MetaLink on some method deep in the System (e.g new, +, do: ). • Our Meta-Object might use exactly that method, too Endless Loop!!
  • 27. Recursion Problem • Solution: Meta-Level • We encode the a level in the execution of the system • Every Link Activation increases the level • A meta-link is just active for one level. (e.g. 0) link := MetaLink new metaObject: [ Object new ]; level: 0. (Behavior>>#new) ast link: link.
  • 28. Example: Log • Better use #level: 0 • Nevertheless: be careful! If you add this to method called often it can be very slow. link := MetaLink new metaObject: [Transcript show: 'Reached Here’]; level: 0.
  • 29. Example: Counter • In the Browser you can add a “counter” to the AST • See class ExecutionCounter install link := MetaLink new metaObject: self; selector: #increase. node link: link.
  • 30. Example: Breakpoint • “Add Breakpoint” in AST (Suggestions) Menu • See class Breakpoint • Break Once • Conditional Break breakLink ^ MetaLink new metaObject: Break; selector: #break; options: options
  • 31. Example: WatchPoint • Watchpoint: Record Value at a point in the AST • Example: Watch event in WorldMorph>>#mouseDown: Click on background -> value recorded
  • 32. Example: WatchPoint • Implementation: class Watchpoint, method install • example of a #after link with a condition link := MetaLink new metaObject: self; selector: #addValue:; arguments: #(value); control: #after; condition: [ recording ].
  • 33. Example: Code Coverage • Small Demo. • Start with CoverageDemo new openWithSpec
  • 34. Example: Code Coverage • Example of a MetaLink with a #node MetObject • Meta-Object is the node that the link is installed on link := MetaLink new metaObject: #node; selector: #tagExecuted.
  • 35. Interesting Properties • Cross Cutting • One Link can be installed multiple times • Over multiple methods and even Classes • And across operations (e.g., Send and Assignment) as long as all reifications requested are compatible • Fully Dynamic: Links can be added and removed at runtime • Even by the meta-object of another meta-link!
  • 36. Limitations • Better use Pharo7 (we are improving it still) • Still some bugs with #after on MethodNode • Loops: next execution of a method. Need to restart long running loops (no on-stack replacement). • Keep in mind: next metaLink taken into account for next method activation • Take care with long running loops!
  • 37. Help Wanted • We are always interested in improvements! • Pharo7 is under active development. • Pull Requests Welcome!