SlideShare a Scribd company logo
First Class Variables
as
AST Annotations
Marcus Denker
Inria RMoD
Part I: The AST
• AST = Abstract Syntax Tree
• Tree Representation of the Method
• Based on the RB AST
• Used by all tools (refactoring, syntax-highlighting,…)
Smalltalk compiler parse: 'test ^(1+2)'
AST
• RBMethodNode Root
• RBVariableNode Variable (read and write)
• RBAssignmentNode Assignment
• RBMessageNode A Message (most of them)
• RBReturnNode Return
Inspect a simple AST
• A very simple Example
Smalltalk compiler parse: 'test ^(1+2)'
User: Tools
• Refactoring
• Breakpoints / Watchers
• Syntax Highlight / Code Completion
• AST based Menu in the Code Browser
User: The Compiler
Source AST
Annotated
AST
IR
Annotated
AST
Bytecode
RBParser OCSemanticAnalyzer
OCASTTranslator/
IRBuilder
IRBytecodeGenerator
Variables in the AST
• Example: (Point>>#x)
•
Problem: Kind of Variable?
• Example: SHRBTextStyler
• Syntax highlighting needs to know which kind
Variables in the AST
• Every de
fi
nition, read and write gets one new instance
of RBVariableNode (as we have to encode the parent
for each di
ff
erently)
• We just know the name
• SYNTAX, but no SEMANTICs
• Kind? (temp or ivar)
• Variables with same name can be di
ff
erent
variables
To the Rescue: Name
Analysis
• We have to annotate the AST with information about
Variables
• Block/Method: de
fi
ned Variables are put in a Scope
• Scopes know the parent Scope
• When we see a use, we loop up the variable in the Scope
Semantic Variables
• Every RBVariableNode gets a semantic variable
annotation
• Both the de
fi
nition and all uses
• There is one instance for each variable that models
• name
• scope it was de
fi
ned
Variables in the AST
• Example Again: (Point>>#x)
•
Variables and Compilation
• Compiler just delegates to the Variable, e.g for instance
Variables:
• emitStore/emitValue: de
fi
ned for each kind of Variables
(global/temp/ivar)
emitStore: methodBuilder
"generate store bytecode"
methodBuilder storeInstVar: index
Repeat:The AST
• AST = Abstract Syntax Tree
• Tree Representation of the Method
• Produced by the Parser (part of the Compiler)
• Used by all tools and the Compiler
• We need to model Variables semantically to make it useful
Now Step Back
Forget Part I
(for now)
Look at it from Re
fl
ective
Point of View
PartII
First Class Variables
First: Variables in ST80
Instance Variables
• De
fi
ned by the Class (list of variable names)
• Can be read via the object:
• instVarNamed:(put:), #instVarAt:(put:)
• Instance Variables have an o
ff
set in the Object
• De
fi
ned by the order of the de
fi
ned vars in the Hierarchy
1@2 instVarNamed: 'x'
Temporary Variable
• De
fi
ned by a method or Block
• Arguments are temps, too
• Can be read via the context
• #tempNamed:, tempNamed:put:
• With Closures this is more complex than you ever want to
know!
[| temp | temp := 1. thisContext tempNamed: 'temp' ] value
Globals
• Entries in the “Smalltalk globals” Dictionary
• Contain the value
• Can be read via the global Dictionary
• Access via #value / value: on the Association
• Class Vars and Pool Vars are just Associations from other
Dictionaries
Smalltalk globals at: #Object.
Object binding value.
“Everything is an Object”
For Variables… not really
Globals/Class Vars
• Here we have at least the Association (#binding):
• But there is no “GlobalVariable” class
• No API other than #value:/#value
• Classes de
fi
ne just names of variables
Object binding
Instance Variables
• The class just knows the names
• There is no Object representing instance variables
• Classes de
fi
ne just names of variables
• Bytecode accesses by o
ff
set
Point allInstVarNames
Temporary Variables
• The methods know nothing. Even to know the variable
name we need the compiler (and the source)
• There is no object representing temp Variables
• Re
fl
ective read and write is *hard* -> compiler needs to
create extensive meta-data
Why Not Do Better?
• Every de
fi
ned Variable is described a meta object
• Class Hierarchy: Variable
The Hierarchy
• Variable
• LiteralVariable
• ClassVariable
• GlobalVariable
• UndeclaredVariable
• WorkspaceVariable
• LocalVariable
• ArgumentVariable
• TemporaryVariable
• ReservedVariable
• SelfVariable
• SuperVariable
• ThisContextVariable
• Slot
Example: vars of a class
• Get all Variables of a class
• Inspect it
• #usingMethods
Point instanceVariables
Instance Variable
• Read x in a Point
• Write
• read/write without sending a message to the object!
(Point instanceVariables
fi
rst) read: (5@4)
point := 5@4.
(Point instanceVariables
fi
rst) write: 100 to: point.
Globals
• Object binding class
• Object binding read
• We keep the Association API so the Global Variables can
play the role of associations in the global dictionary.
Object binding usingMethods
Temporary Variables
• There are too many to allocate them all
• They are created on demand (with the AST)
((LinkedList>>#do:) temporaryVariableNamed: 'aLink')
#lookupVar:
• Every variable knows the scope is was de
fi
ned in
• Every scope know the outer scope
• #lookupVar: looks up names along the scope
[ | temp |thisContext lookupVar: 'temp' ] value.
[ | temp |thisContext lookupVar: ‘Object' ] value
(Point slotNamed: #x ) scope outerScope
Debugger: Read Vars
• In the Debugger we to be able to read Variables from a
DoIt.
• lookupVar, then readInContext works for all Variables!
• If you know the context, you can read any variable
• DoItVariable: Nice names in DoIts (—> Show Us)
[ | temp | temp :=1 . (thisContext lookupVar: 'temp')
readInContext: thisContext] value
Part III: Putting it Together
• We have seen how Semantic Variables are needed to
make the AST useful
• We have seen First Class Variables as part of the
Re
fl
ective Model
• Do we really need the two?
Solution: Scope
• What is needed? Add the concept of Scope
• Scope of a global is Smalltalk globals
• Scope of an instance variable is the class
• Scope of temp: method and block scope
Example: Point x
(Point slotNamed: #x) scope == Point
(Point lookupVar: #x) == (Point slotNamed: #x)
(Point>>#x) ast variableNodes
fi
rst variable == (Point slotNamed: #x)
What do we get?
• Simpli
fi
ed Name Analysis in the Compiler
• Open Compiler: De
fi
ne your own kinds of Variables
• While fully integrated in the Re
fl
ective Model
• Re
fl
ective Reading/Writing
• All tools work for you own kinds of Variables
What we did not see…
• De
fi
ne your own kinds of Variables (e.g. subclasses of
Slot / ClassVariable)
• Fluid Class De
fi
nitions: How to create classes that use
these variables
• How this enables DoIts with nice variable names
• Re
fl
ection: MetaLinks on Variables
Thanks…
• This is the work on *many* contributors from the Pharo
Community
• Thanks for lots of interesting discussions, ideas, and
code!
Questions?
• We have seen how the AST needs semantic variables to
be useful
• We have seen First Class Variables as part of the
Re
fl
ective model
• First Class Variables, with just adding the concept of a
Scope, can serve as semantic annotations on the AST

More Related Content

Similar to First Class Variables as AST Annotations

TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
Nascenia IT
 
Reference Semantics with C# and .NET Core
Reference Semantics with C# and .NET CoreReference Semantics with C# and .NET Core
Reference Semantics with C# and .NET Core
Christian Nagel
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019
Christian Nagel
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
Pharo
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are Databases
Martin Odersky
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3
mametter
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
GauravPatil318
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
Santosh Rajan
 
C language
C languageC language
C language
Robo India
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
Raleigh Code Camp 2103 - .Net Metaprogramming Essentials
Raleigh Code Camp 2103 - .Net Metaprogramming EssentialsRaleigh Code Camp 2103 - .Net Metaprogramming Essentials
Raleigh Code Camp 2103 - .Net Metaprogramming EssentialsSean McCarthy
 
c++ Unit III - PPT.pptx
c++ Unit III - PPT.pptxc++ Unit III - PPT.pptx
Java ce241
Java ce241Java ce241
Java ce241
Minal Maniar
 
C
CC
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5
Marcus Denker
 
Behavioral Reflection in Pharo
Behavioral Reflection in PharoBehavioral Reflection in Pharo
Behavioral Reflection in Pharo
ESUG
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
Emertxe Information Technologies Pvt Ltd
 
Type Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesType Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signatures
mametter
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++
Manzoor ALam
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 

Similar to First Class Variables as AST Annotations (20)

TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
 
Reference Semantics with C# and .NET Core
Reference Semantics with C# and .NET CoreReference Semantics with C# and .NET Core
Reference Semantics with C# and .NET Core
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are Databases
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
C language
C languageC language
C language
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
Raleigh Code Camp 2103 - .Net Metaprogramming Essentials
Raleigh Code Camp 2103 - .Net Metaprogramming EssentialsRaleigh Code Camp 2103 - .Net Metaprogramming Essentials
Raleigh Code Camp 2103 - .Net Metaprogramming Essentials
 
c++ Unit III - PPT.pptx
c++ Unit III - PPT.pptxc++ Unit III - PPT.pptx
c++ Unit III - PPT.pptx
 
Java ce241
Java ce241Java ce241
Java ce241
 
C
CC
C
 
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
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
 
Type Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signaturesType Profiler: An Analysis to guess type signatures
Type Profiler: An Analysis to guess type signatures
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 

More from Marcus Denker

Soil And Pharo
Soil And PharoSoil And Pharo
Soil And Pharo
Marcus Denker
 
ConstantBlocks in Pharo11
ConstantBlocks in Pharo11ConstantBlocks in Pharo11
ConstantBlocks in Pharo11
Marcus Denker
 
Demo: Improved DoIt
Demo: Improved DoItDemo: Improved DoIt
Demo: Improved DoIt
Marcus Denker
 
Supporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo SupportSupporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo Support
Marcus Denker
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
Marcus Denker
 
Improving code completion for Pharo
Improving code completion for PharoImproving code completion for Pharo
Improving code completion for Pharo
Marcus Denker
 
Slot Composition
Slot CompositionSlot Composition
Slot Composition
Marcus Denker
 
PHARO IOT
PHARO IOTPHARO IOT
PHARO IOT
Marcus Denker
 
Open-Source: An Infinite Game
Open-Source: An Infinite GameOpen-Source: An Infinite Game
Open-Source: An Infinite Game
Marcus Denker
 
Lecture: MetaLinks
Lecture: MetaLinksLecture: MetaLinks
Lecture: MetaLinks
Marcus Denker
 
PharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to PharoPharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to Pharo
Marcus Denker
 
Feedback Loops in Practice
Feedback Loops in PracticeFeedback Loops in Practice
Feedback Loops in Practice
Marcus Denker
 
Pharo6 - ESUG17
Pharo6 - ESUG17Pharo6 - ESUG17
Pharo6 - ESUG17
Marcus Denker
 
Pharo6
Pharo6Pharo6
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
Marcus Denker
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
Marcus 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 better
Marcus 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 Promises
Marcus Denker
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
Marcus Denker
 
How to Contribute to Pharo
How to Contribute to PharoHow to Contribute to Pharo
How to Contribute to Pharo
Marcus Denker
 

More from 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
 
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
 
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
 
Lecture: MetaLinks
Lecture: MetaLinksLecture: MetaLinks
Lecture: MetaLinks
 
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
 
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
 
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
 

Recently uploaded

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 

Recently uploaded (20)

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 

First Class Variables as AST Annotations

  • 1. First Class Variables as AST Annotations Marcus Denker Inria RMoD
  • 2. Part I: The AST • AST = Abstract Syntax Tree • Tree Representation of the Method • Based on the RB AST • Used by all tools (refactoring, syntax-highlighting,…) Smalltalk compiler parse: 'test ^(1+2)'
  • 3. AST • RBMethodNode Root • RBVariableNode Variable (read and write) • RBAssignmentNode Assignment • RBMessageNode A Message (most of them) • RBReturnNode Return
  • 4. Inspect a simple AST • A very simple Example Smalltalk compiler parse: 'test ^(1+2)'
  • 5. User: Tools • Refactoring • Breakpoints / Watchers • Syntax Highlight / Code Completion • AST based Menu in the Code Browser
  • 6. User: The Compiler Source AST Annotated AST IR Annotated AST Bytecode RBParser OCSemanticAnalyzer OCASTTranslator/ IRBuilder IRBytecodeGenerator
  • 7. Variables in the AST • Example: (Point>>#x) •
  • 8. Problem: Kind of Variable? • Example: SHRBTextStyler • Syntax highlighting needs to know which kind
  • 9. Variables in the AST • Every de fi nition, read and write gets one new instance of RBVariableNode (as we have to encode the parent for each di ff erently) • We just know the name • SYNTAX, but no SEMANTICs • Kind? (temp or ivar) • Variables with same name can be di ff erent variables
  • 10. To the Rescue: Name Analysis • We have to annotate the AST with information about Variables • Block/Method: de fi ned Variables are put in a Scope • Scopes know the parent Scope • When we see a use, we loop up the variable in the Scope
  • 11. Semantic Variables • Every RBVariableNode gets a semantic variable annotation • Both the de fi nition and all uses • There is one instance for each variable that models • name • scope it was de fi ned
  • 12. Variables in the AST • Example Again: (Point>>#x) •
  • 13. Variables and Compilation • Compiler just delegates to the Variable, e.g for instance Variables: • emitStore/emitValue: de fi ned for each kind of Variables (global/temp/ivar) emitStore: methodBuilder "generate store bytecode" methodBuilder storeInstVar: index
  • 14. Repeat:The AST • AST = Abstract Syntax Tree • Tree Representation of the Method • Produced by the Parser (part of the Compiler) • Used by all tools and the Compiler • We need to model Variables semantically to make it useful
  • 17. Look at it from Re fl ective Point of View
  • 20. Instance Variables • De fi ned by the Class (list of variable names) • Can be read via the object: • instVarNamed:(put:), #instVarAt:(put:) • Instance Variables have an o ff set in the Object • De fi ned by the order of the de fi ned vars in the Hierarchy 1@2 instVarNamed: 'x'
  • 21. Temporary Variable • De fi ned by a method or Block • Arguments are temps, too • Can be read via the context • #tempNamed:, tempNamed:put: • With Closures this is more complex than you ever want to know! [| temp | temp := 1. thisContext tempNamed: 'temp' ] value
  • 22. Globals • Entries in the “Smalltalk globals” Dictionary • Contain the value • Can be read via the global Dictionary • Access via #value / value: on the Association • Class Vars and Pool Vars are just Associations from other Dictionaries Smalltalk globals at: #Object. Object binding value.
  • 23. “Everything is an Object”
  • 25. Globals/Class Vars • Here we have at least the Association (#binding): • But there is no “GlobalVariable” class • No API other than #value:/#value • Classes de fi ne just names of variables Object binding
  • 26. Instance Variables • The class just knows the names • There is no Object representing instance variables • Classes de fi ne just names of variables • Bytecode accesses by o ff set Point allInstVarNames
  • 27. Temporary Variables • The methods know nothing. Even to know the variable name we need the compiler (and the source) • There is no object representing temp Variables • Re fl ective read and write is *hard* -> compiler needs to create extensive meta-data
  • 28. Why Not Do Better? • Every de fi ned Variable is described a meta object • Class Hierarchy: Variable
  • 29. The Hierarchy • Variable • LiteralVariable • ClassVariable • GlobalVariable • UndeclaredVariable • WorkspaceVariable • LocalVariable • ArgumentVariable • TemporaryVariable • ReservedVariable • SelfVariable • SuperVariable • ThisContextVariable • Slot
  • 30. Example: vars of a class • Get all Variables of a class • Inspect it • #usingMethods Point instanceVariables
  • 31. Instance Variable • Read x in a Point • Write • read/write without sending a message to the object! (Point instanceVariables fi rst) read: (5@4) point := 5@4. (Point instanceVariables fi rst) write: 100 to: point.
  • 32. Globals • Object binding class • Object binding read • We keep the Association API so the Global Variables can play the role of associations in the global dictionary. Object binding usingMethods
  • 33. Temporary Variables • There are too many to allocate them all • They are created on demand (with the AST) ((LinkedList>>#do:) temporaryVariableNamed: 'aLink')
  • 34. #lookupVar: • Every variable knows the scope is was de fi ned in • Every scope know the outer scope • #lookupVar: looks up names along the scope [ | temp |thisContext lookupVar: 'temp' ] value. [ | temp |thisContext lookupVar: ‘Object' ] value (Point slotNamed: #x ) scope outerScope
  • 35. Debugger: Read Vars • In the Debugger we to be able to read Variables from a DoIt. • lookupVar, then readInContext works for all Variables! • If you know the context, you can read any variable • DoItVariable: Nice names in DoIts (—> Show Us) [ | temp | temp :=1 . (thisContext lookupVar: 'temp') readInContext: thisContext] value
  • 36. Part III: Putting it Together • We have seen how Semantic Variables are needed to make the AST useful • We have seen First Class Variables as part of the Re fl ective Model • Do we really need the two?
  • 37. Solution: Scope • What is needed? Add the concept of Scope • Scope of a global is Smalltalk globals • Scope of an instance variable is the class • Scope of temp: method and block scope
  • 38. Example: Point x (Point slotNamed: #x) scope == Point (Point lookupVar: #x) == (Point slotNamed: #x) (Point>>#x) ast variableNodes fi rst variable == (Point slotNamed: #x)
  • 39. What do we get? • Simpli fi ed Name Analysis in the Compiler • Open Compiler: De fi ne your own kinds of Variables • While fully integrated in the Re fl ective Model • Re fl ective Reading/Writing • All tools work for you own kinds of Variables
  • 40. What we did not see… • De fi ne your own kinds of Variables (e.g. subclasses of Slot / ClassVariable) • Fluid Class De fi nitions: How to create classes that use these variables • How this enables DoIts with nice variable names • Re fl ection: MetaLinks on Variables
  • 41. Thanks… • This is the work on *many* contributors from the Pharo Community • Thanks for lots of interesting discussions, ideas, and code!
  • 42. Questions? • We have seen how the AST needs semantic variables to be useful • We have seen First Class Variables as part of the Re fl ective model • First Class Variables, with just adding the concept of a Scope, can serve as semantic annotations on the AST