Variables in Pharo

Marcus Denker
Marcus DenkerResearch Scientist at INRIA
Variables in Pharo
Marcus Denker, Inria
http://marcusdenker.de
Plan for an interactive
Exploration
• These Slides where done as an outline / plan for an
interactive exploration

• They might therefore be not exactly the same as the
content of the Demo
Variables in ST80
• Temporary Variable

• Instance Variable, Class Instance Variable

• Class Variable (and Pool Variable)

• Globals

• Pseudo Variables: self, super, thisContext
Instance Variables
• De
fi
ned by the Class (or Trait)

• 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?
• Of course memory was a concern in 1980, but today we
should be able to do better!

• Why not have objects (and a class Hierarchy) that
describes all Variables in the system?
Variables
• Every de
fi
ned Variable is described a meta object

• Class Hierarchy: Variable

• GlobalVariable

• ClassVariable

• Temporary Variables

• Instance Variables (aka Slots)
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!

• DoItIn: uses this:
[ | temp | temp :=1 . (thisContext lookupVar: 'temp')
readInContext: thisContext] value
Context>>readVariableNamed: aName
^ (self lookupVar: aName) readInContext: self
Variables as AST
Annotations
• Pharo uses the RB AST

• RBVariableNode instance for every use of a Variable

• Annotated with subclasses of Variables:
(Point>>#x) ast variableNodes
fi
rst variable == (Point slotNamed: #x)
OCASTSemanticAnalyzer
• OCASTSemanticAnalyzer is the visitor that does the name
analysis

• Adds a scope for each block/the method

• Adds de
fi
ned variables to the scope

• Every RBVariableNode use will get annotated with the
variable that #lookUpVar:
fi
nds
Variables and Bytecode
• Compiler just delegates to the Variable

• InstanceVariableSlot>>#emitStore:

• emitStore/emitValue:
emitStore: methodBuilder
"generate store bytecode"
methodBuilder storeInstVar: index
Does that mean…
• If variables are de
fi
ned by a class, could we not make a
subclass?

• And even override the code generation methods ?!
Now let’s create our own
kind of Variable!
Lazy Variables
• Two ways to initialize instance state in ST80

• implement #initialize method (#new calls it)

• use accessors and lazy init pattern

• Can we not do better? Can the Variable not initialize
itself?
Lazy Variables
InstanceVariableSlot subclass: #LazyInitializedInstanceVariabl
e

instanceVariableNames: 'default
'

classVariableNames: '
'

package: ‘CompilerTalk
'

printOn: aStrea
m

aStream
 

store: self name
;

nextPutAll: ' => '
;

nextPutAll: self class name
;

nextPutAll: ' default: '
.

default printOn: aStrea
m
Lazy Variables
read: anObjec
t

"if the value is nil, we write the default value
"

^ (super read: anObject) ifNil: [
 

self write: default to: anObject
]

emitValue: aMethodBuilde
r

"generate bytecode for '<varname> ifNil: [<varname> := default]'
"

aMethodBuilde
r

pushInstVar: index
;

pushDup
;

pushLiteral: nil
;

send: #==
;

jumpAheadTo: #target if: false
;

popTop
;

pushLiteral: default
;

storeInstVar: index
;

jumpAheadTarget: #targe
t
Let’s use it
Object subclass: #MyClas
s

instanceVariableNames: 'var
'

classVariableNames: '
'

package: ‘CompilerTalk'
?
How can we make ‘var’ to be a LazyInitializedInstanceVariable?
Class De
fi
nition
• We need a new way to de
fi
ne classes: Fluid Class
De
fi
nition

• uses cascade for extensibility

• no string, but {} arrays for variables
Fluid Class De
fi
nition
Object << #Poin
t

slots: { #x . #y }
;

tag: 'BasicObjects'
;

package: 'Kernel'
Fluid Class De
fi
nition
• Pharo9: Default is the ST80 style class de
fi
nition

• Fluid can be enabled

• It is used automatically when needed (when using a self
de
fi
ned Variable, for example)

• Goal: Default for Pharo 10
Let’s use it
Object << #MyClas
s

slots: { #var }
;

package: ‘CompilerTalk'
#notation for normal instance Variables
Let’s use it
Object << #MyClas
s

slots: { #var => LazyInitializedInstanceVariable default: 5 }
;

package: ‘CompilerTalk'
For de
fi
ning other variables: use =>
MyClass new var
.

(MyClass new var: 8) var
Inspect method to see bytecode
put halt in read: method of Slot
thisProcess
• To get the current Process we use a message send to a
global variable. But we could use a variable like
thisProces
s

• This avoids a message send (and possible interrupt
check) as we can emit a bytecode
self, thisContext…
• (Object lookupVar: ‘thisContext’) usingMethods
• See classes

• ThisContextVariable

• SelfVariable

• SuperVariable
The Code
ReservedVariable << #ThisProcessVariable
slots: {};
tag: 'Variables';
package: 'Kernel'
emitValue: methodBuilder
methodBuilder pushThisProcess
======
class side:
variableName
^ 'thisProcess'
======
Smalltalk globals resetReservedVariables
Compatibility
• Fully backward compatible: we can load ST80 style class
de
fi
nitions (and Pharo9 just shows this view by default)

• Re
fl
ective API is compatible: “instVarAt:”… still exist

• If you want to restrict yourself to ST80, a checker could
be easily created
Compatibility
• But if you start to use your own kind of Variables, you
code will not be “ST80” compatible anymore

• But you will be able to use the power of the new
abstraction provided

• Was this not the original idea behind Smalltalk? That a
Programming System is a Medium?
Where do we use it?
• We are careful! We use Pharo ourselves… 

• We need a stable system to work with

• We need to learn about how to use Variables best

• Variables are used by the Compiler internally

• Every instance variable is an InstanceVariableSlot (Globals, class vars)

• Variables are used by the Debugging infrastructure to read/write

• replaced the DebuggerMethodMap

• The Spec UI Framework uses ObservableSlot
Next Steps Variables
• DoitVariable for nicer code in #DoItIn: methods 

• Undeclared Variables

• programmer interaction in read/write, not compile!

• better behaviour for test-
fi
rst development

• Implement ThisProcessVariable in Pharo10

• Use WeakSlot to simplify some code
Next Steps Fluid Classes
• Finish the last problems (see issue tracker), make it the
default

• Experiments with Meta Data for Classes

• Tag abstract classes

• Experiment with Pragmas for classes

• Compiler, compiler plugging, compiler options
More..
• Extend the MetaLink Model to allow MetaLinks on
Variables (
fi
rst code is there already)

• More Experiments about Slot Composition 

• Implement Default value once, use it on ClassVariable,
InstanceVariableSlot and WeakSlot

• First prototype, but it turned out to be too complex
Thanks…
• This is the work on *many* contributors from the Pharo
Community

• Thanks for lots of interesting discussions, ideas, and
code!
Help Wanted
• We are always interested in improvements!

• Pharo 10 is under active development

• 30-40 Pull Requests integrated per week

• Your Improvements are Welcome!
https://github.com/pharo-project/pharo
Questions?
1 of 45

Recommended

Unixfs by
UnixfsUnixfs
UnixfsLinh Nguyễn Thanh
427 views24 slides
ApresentaçãO Mpls by
ApresentaçãO MplsApresentaçãO Mpls
ApresentaçãO MplsUniversidade do Parlamento do Ceará.
5.5K views71 slides
“見てわかる” ファイバーチャネルSAN基礎講座(第5弾)~さあ、いよいよ、運用です!~ by
“見てわかる” ファイバーチャネルSAN基礎講座(第5弾)~さあ、いよいよ、運用です!~“見てわかる” ファイバーチャネルSAN基礎講座(第5弾)~さあ、いよいよ、運用です!~
“見てわかる” ファイバーチャネルSAN基礎講座(第5弾)~さあ、いよいよ、運用です!~Brocade
11.1K views30 slides
きっと今すぐ使えるハッシュの基礎知識 by
きっと今すぐ使えるハッシュの基礎知識きっと今すぐ使えるハッシュの基礎知識
きっと今すぐ使えるハッシュの基礎知識Ryo Sasaki
879 views36 slides
Hostile Environments: Wireless LAN Design for Warehouse WLPC by
Hostile Environments: Wireless LAN Design for Warehouse WLPCHostile Environments: Wireless LAN Design for Warehouse WLPC
Hostile Environments: Wireless LAN Design for Warehouse WLPCAruba, a Hewlett Packard Enterprise company
9.7K views32 slides
Simulating Networks Using Cisco Modeling Labs (TechWiseTV Workshop) by
Simulating Networks Using Cisco Modeling Labs (TechWiseTV Workshop)Simulating Networks Using Cisco Modeling Labs (TechWiseTV Workshop)
Simulating Networks Using Cisco Modeling Labs (TechWiseTV Workshop)Robb Boyd
2.2K views32 slides

More Related Content

What's hot

DNS and BIND, 5th Edition.pdf by
DNS and BIND, 5th Edition.pdfDNS and BIND, 5th Edition.pdf
DNS and BIND, 5th Edition.pdfviditsir
256 views642 slides
“見てわかる” ファイバーチャネルSAN基礎講座(第2弾)~FC SAN設計における勘所とは?~ by
“見てわかる” ファイバーチャネルSAN基礎講座(第2弾)~FC SAN設計における勘所とは?~“見てわかる” ファイバーチャネルSAN基礎講座(第2弾)~FC SAN設計における勘所とは?~
“見てわかる” ファイバーチャネルSAN基礎講座(第2弾)~FC SAN設計における勘所とは?~Brocade
17.8K views35 slides
はまる!!JPA #glassfish_jp #javaee by
はまる!!JPA #glassfish_jp #javaeeはまる!!JPA #glassfish_jp #javaee
はまる!!JPA #glassfish_jp #javaeeToshiaki Maki
9.4K views120 slides
Access Network Evolution by
Access Network Evolution Access Network Evolution
Access Network Evolution Cisco Canada
4K views55 slides
It certification-roadmap by
It certification-roadmapIt certification-roadmap
It certification-roadmapGabbar Singh
660 views2 slides
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF by
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETFDhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETFzarigatongy
347 views30 slides

What's hot(20)

DNS and BIND, 5th Edition.pdf by viditsir
DNS and BIND, 5th Edition.pdfDNS and BIND, 5th Edition.pdf
DNS and BIND, 5th Edition.pdf
viditsir256 views
“見てわかる” ファイバーチャネルSAN基礎講座(第2弾)~FC SAN設計における勘所とは?~ by Brocade
“見てわかる” ファイバーチャネルSAN基礎講座(第2弾)~FC SAN設計における勘所とは?~“見てわかる” ファイバーチャネルSAN基礎講座(第2弾)~FC SAN設計における勘所とは?~
“見てわかる” ファイバーチャネルSAN基礎講座(第2弾)~FC SAN設計における勘所とは?~
Brocade17.8K views
はまる!!JPA #glassfish_jp #javaee by Toshiaki Maki
はまる!!JPA #glassfish_jp #javaeeはまる!!JPA #glassfish_jp #javaee
はまる!!JPA #glassfish_jp #javaee
Toshiaki Maki9.4K views
Access Network Evolution by Cisco Canada
Access Network Evolution Access Network Evolution
Access Network Evolution
Cisco Canada4K views
It certification-roadmap by Gabbar Singh
It certification-roadmapIt certification-roadmap
It certification-roadmap
Gabbar Singh660 views
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF by zarigatongy
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETFDhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
Dhcpv6 Tutorial Overview, DHCP for Ipv6 ,RFC 3315 - IETF
zarigatongy347 views
Fibre Channel 基礎講座 by Brocade
Fibre Channel 基礎講座Fibre Channel 基礎講座
Fibre Channel 基礎講座
Brocade65.1K views
さわってみようTOPPERS/SSP by NSaitoNmiri
さわってみようTOPPERS/SSPさわってみようTOPPERS/SSP
さわってみようTOPPERS/SSP
NSaitoNmiri3.2K views
What Are Virtual Chassis and Virtual Chassis Fabric? by Juniper Networks
What Are Virtual Chassis and Virtual Chassis Fabric?What Are Virtual Chassis and Virtual Chassis Fabric?
What Are Virtual Chassis and Virtual Chassis Fabric?
Juniper Networks9.8K views
“見てわかる” ファイバーチャネルSAN基礎講座(第1弾)~まず理解しよう! 基本の “キ”~ by Brocade
“見てわかる” ファイバーチャネルSAN基礎講座(第1弾)~まず理解しよう! 基本の “キ”~“見てわかる” ファイバーチャネルSAN基礎講座(第1弾)~まず理解しよう! 基本の “キ”~
“見てわかる” ファイバーチャネルSAN基礎講座(第1弾)~まず理解しよう! 基本の “キ”~
Brocade17.8K views
IxVM on CML by npsg
IxVM on CMLIxVM on CML
IxVM on CML
npsg2.6K views
“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~ by Brocade
“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~
“見てわかる” ファイバーチャネルSAN基礎講座(第4弾)~続・間違わない!FC SAN導入のヒントとコツ~
Brocade8.1K views
IBM i client partitions concepts and implementation by COMMON Europe
IBM i client partitions concepts and implementationIBM i client partitions concepts and implementation
IBM i client partitions concepts and implementation
COMMON Europe9.7K views
SRv6 study by Hiro Mura
SRv6 studySRv6 study
SRv6 study
Hiro Mura7.7K views
SAN デザイン講座 by Brocade
SAN デザイン講座SAN デザイン講座
SAN デザイン講座
Brocade10.8K views
Wifiにつながるデバイス(ESP8266EX, ESP-WROOM-02, ESPr Developerなど) by nishio
Wifiにつながるデバイス(ESP8266EX, ESP-WROOM-02, ESPr Developerなど)Wifiにつながるデバイス(ESP8266EX, ESP-WROOM-02, ESPr Developerなど)
Wifiにつながるデバイス(ESP8266EX, ESP-WROOM-02, ESPr Developerなど)
nishio9.5K views
PharoJS: Pharo-Based TDD for Javascript Applications by ESUG
PharoJS: Pharo-Based TDD for Javascript ApplicationsPharoJS: Pharo-Based TDD for Javascript Applications
PharoJS: Pharo-Based TDD for Javascript Applications
ESUG7K views

Similar to Variables in Pharo

First Class Variables as AST Annotations by
 First Class Variables as AST Annotations First Class Variables as AST Annotations
First Class Variables as AST AnnotationsESUG
59 views42 slides
First Class Variables as AST Annotations by
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST AnnotationsMarcus Denker
5 views42 slides
Java by
JavaJava
JavaZeeshan Khan
84 views33 slides
Learning core java by
Learning core javaLearning core java
Learning core javaAbhay Bharti
1K views42 slides
Javascript classes and scoping by
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scopingPatrick Sheridan
672 views59 slides
Advanced Reflection in Pharo by
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in PharoPharo
918 views46 slides

Similar to Variables in Pharo(20)

First Class Variables as AST Annotations by ESUG
 First Class Variables as AST Annotations First Class Variables as AST Annotations
First Class Variables as AST Annotations
ESUG59 views
First Class Variables as AST Annotations by Marcus Denker
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST Annotations
Marcus Denker5 views
Advanced Reflection in Pharo by Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
Pharo918 views
Android webinar class_java_review by Edureka!
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!505 views
Lecture: "Advanced Reflection: MetaLinks" by Marcus Denker
Lecture: "Advanced Reflection: MetaLinks"Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"
Marcus Denker11 views
Learning from "Effective Scala" by Kazuhiro Sera
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"
Kazuhiro Sera1.9K views
Lecture. Advanced Reflection: MetaLinks by Marcus Denker
Lecture. Advanced Reflection: MetaLinksLecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinks
Marcus Denker11 views
33rd degree talk: open and automatic coding conventions with walkmod by walkmod
33rd degree talk: open and automatic coding conventions with walkmod33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod
walkmod807 views
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks by Marcus Denker
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksVUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
Marcus Denker213 views
Slot Composition by ESUG
Slot CompositionSlot Composition
Slot Composition
ESUG368 views
Scala, Play 2.0 & Cloud Foundry by Pray Desai
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai3.3K views
Advanced Reflection in Pharo by Marcus Denker
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
Marcus Denker4.6K views

More from Marcus Denker

Soil And Pharo by
Soil And PharoSoil And Pharo
Soil And PharoMarcus Denker
47 views12 slides
ConstantBlocks in Pharo11 by
ConstantBlocks in Pharo11ConstantBlocks in Pharo11
ConstantBlocks in Pharo11Marcus Denker
50 views26 slides
Demo: Improved DoIt by
Demo: Improved DoItDemo: Improved DoIt
Demo: Improved DoItMarcus Denker
4 views3 slides
Supporting Pharo / Getting Pharo Support by
Supporting Pharo / Getting Pharo SupportSupporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo SupportMarcus Denker
8 views19 slides
thisContext in the Debugger by
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerMarcus Denker
413 views7 slides
Improving code completion for Pharo by
Improving code completion for PharoImproving code completion for Pharo
Improving code completion for PharoMarcus Denker
292 views19 slides

More from Marcus Denker(20)

Supporting Pharo / Getting Pharo Support by Marcus Denker
Supporting Pharo / Getting Pharo SupportSupporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo Support
Marcus Denker8 views
thisContext in the Debugger by Marcus Denker
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
Marcus Denker413 views
Improving code completion for Pharo by Marcus Denker
Improving code completion for PharoImproving code completion for Pharo
Improving code completion for Pharo
Marcus Denker292 views
Lecture: Advanced Reflection. MetaLinks by Marcus Denker
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinks
Marcus Denker1.4K views
Open-Source: An Infinite Game by Marcus Denker
Open-Source: An Infinite GameOpen-Source: An Infinite Game
Open-Source: An Infinite Game
Marcus Denker1.2K views
PharoTechTalk: Contributing to Pharo by Marcus Denker
PharoTechTalk: Contributing to PharoPharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to Pharo
Marcus Denker684 views
Feedback Loops in Practice by Marcus Denker
Feedback Loops in PracticeFeedback Loops in Practice
Feedback Loops in Practice
Marcus Denker860 views
Reflection in Pharo: Beyond Smalltak by Marcus Denker
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
Marcus Denker1.2K views
Reflection in Pharo: Beyond Smalltak by Marcus Denker
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
Marcus Denker746 views
Perfection & Feedback Loops or: why worse is better by Marcus Denker
Perfection & Feedback Loops or: why worse is betterPerfection & Feedback Loops or: why worse is better
Perfection & Feedback Loops or: why worse is better
Marcus Denker7.5K views
Dynamically Composing Collection Operations through Collection Promises by Marcus Denker
Dynamically Composing Collection Operations through Collection PromisesDynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection Promises
Marcus Denker727 views

Recently uploaded

Digital Personal Data Protection (DPDP) Practical Approach For CISOs by
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOsPriyanka Aash
103 views59 slides
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O... by
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...ShapeBlue
59 views13 slides
"Surviving highload with Node.js", Andrii Shumada by
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
49 views29 slides
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...ShapeBlue
93 views13 slides
Business Analyst Series 2023 - Week 4 Session 7 by
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7DianaGray10
110 views31 slides
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueShapeBlue
147 views20 slides

Recently uploaded(20)

Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash103 views
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O... by ShapeBlue
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
ShapeBlue59 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays49 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue93 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10110 views
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue147 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue75 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue69 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue191 views
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue178 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue149 views
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue by ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
ShapeBlue134 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu287 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue86 views
DRBD Deep Dive - Philipp Reisner - LINBIT by ShapeBlue
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBIT
ShapeBlue110 views

Variables in Pharo

  • 1. Variables in Pharo Marcus Denker, Inria http://marcusdenker.de
  • 2. Plan for an interactive Exploration • These Slides where done as an outline / plan for an interactive exploration • They might therefore be not exactly the same as the content of the Demo
  • 3. Variables in ST80 • Temporary Variable • Instance Variable, Class Instance Variable • Class Variable (and Pool Variable) • Globals • Pseudo Variables: self, super, thisContext
  • 4. Instance Variables • De fi ned by the Class (or Trait) • 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'
  • 5. 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
  • 6. 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.
  • 7. “Everything is an Object” • For Variables… not really
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. Why Not Do Better? • Of course memory was a concern in 1980, but today we should be able to do better! • Why not have objects (and a class Hierarchy) that describes all Variables in the system?
  • 12. Variables • Every de fi ned Variable is described a meta object • Class Hierarchy: Variable • GlobalVariable • ClassVariable • Temporary Variables • Instance Variables (aka Slots)
  • 13. The Hierarchy • Variable • LiteralVariable • ClassVariable • GlobalVariable • UndeclaredVariable • WorkspaceVariable • LocalVariable • ArgumentVariable • TemporaryVariable • ReservedVariable • SelfVariable • SuperVariable • ThisContextVariable • Slot
  • 14. Example: vars of a class • Get all Variables of a class • Inspect it • #usingMethods Point instanceVariables
  • 15. 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.
  • 16. 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
  • 17. Temporary Variables • There are too many to allocate them all • They are created on demand (with the AST) ((LinkedList>>#do:) temporaryVariableNamed: 'aLink')
  • 18. #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
  • 19. Debugger: Read Vars • In the Debugger we to be able to read Variables from a DoIt. • lookupVar, then readInContext works for all Variables! • DoItIn: uses this: [ | temp | temp :=1 . (thisContext lookupVar: 'temp') readInContext: thisContext] value Context>>readVariableNamed: aName ^ (self lookupVar: aName) readInContext: self
  • 20. Variables as AST Annotations • Pharo uses the RB AST • RBVariableNode instance for every use of a Variable • Annotated with subclasses of Variables: (Point>>#x) ast variableNodes fi rst variable == (Point slotNamed: #x)
  • 21. OCASTSemanticAnalyzer • OCASTSemanticAnalyzer is the visitor that does the name analysis • Adds a scope for each block/the method • Adds de fi ned variables to the scope • Every RBVariableNode use will get annotated with the variable that #lookUpVar: fi nds
  • 22. Variables and Bytecode • Compiler just delegates to the Variable • InstanceVariableSlot>>#emitStore: • emitStore/emitValue: emitStore: methodBuilder "generate store bytecode" methodBuilder storeInstVar: index
  • 23. Does that mean… • If variables are de fi ned by a class, could we not make a subclass? • And even override the code generation methods ?!
  • 24. Now let’s create our own kind of Variable!
  • 25. Lazy Variables • Two ways to initialize instance state in ST80 • implement #initialize method (#new calls it) • use accessors and lazy init pattern • Can we not do better? Can the Variable not initialize itself?
  • 26. Lazy Variables InstanceVariableSlot subclass: #LazyInitializedInstanceVariabl e instanceVariableNames: 'default ' classVariableNames: ' ' package: ‘CompilerTalk ' printOn: aStrea m aStream store: self name ; nextPutAll: ' => ' ; nextPutAll: self class name ; nextPutAll: ' default: ' . default printOn: aStrea m
  • 27. Lazy Variables read: anObjec t "if the value is nil, we write the default value " ^ (super read: anObject) ifNil: [ self write: default to: anObject ] emitValue: aMethodBuilde r "generate bytecode for '<varname> ifNil: [<varname> := default]' " aMethodBuilde r pushInstVar: index ; pushDup ; pushLiteral: nil ; send: #== ; jumpAheadTo: #target if: false ; popTop ; pushLiteral: default ; storeInstVar: index ; jumpAheadTarget: #targe t
  • 28. Let’s use it Object subclass: #MyClas s instanceVariableNames: 'var ' classVariableNames: ' ' package: ‘CompilerTalk' ? How can we make ‘var’ to be a LazyInitializedInstanceVariable?
  • 29. Class De fi nition • We need a new way to de fi ne classes: Fluid Class De fi nition • uses cascade for extensibility • no string, but {} arrays for variables
  • 30. Fluid Class De fi nition Object << #Poin t slots: { #x . #y } ; tag: 'BasicObjects' ; package: 'Kernel'
  • 31. Fluid Class De fi nition • Pharo9: Default is the ST80 style class de fi nition • Fluid can be enabled • It is used automatically when needed (when using a self de fi ned Variable, for example) • Goal: Default for Pharo 10
  • 32. Let’s use it Object << #MyClas s slots: { #var } ; package: ‘CompilerTalk' #notation for normal instance Variables
  • 33. Let’s use it Object << #MyClas s slots: { #var => LazyInitializedInstanceVariable default: 5 } ; package: ‘CompilerTalk' For de fi ning other variables: use => MyClass new var . (MyClass new var: 8) var Inspect method to see bytecode put halt in read: method of Slot
  • 34. thisProcess • To get the current Process we use a message send to a global variable. But we could use a variable like thisProces s • This avoids a message send (and possible interrupt check) as we can emit a bytecode
  • 35. self, thisContext… • (Object lookupVar: ‘thisContext’) usingMethods • See classes • ThisContextVariable • SelfVariable • SuperVariable
  • 36. The Code ReservedVariable << #ThisProcessVariable slots: {}; tag: 'Variables'; package: 'Kernel' emitValue: methodBuilder methodBuilder pushThisProcess ====== class side: variableName ^ 'thisProcess' ====== Smalltalk globals resetReservedVariables
  • 37. Compatibility • Fully backward compatible: we can load ST80 style class de fi nitions (and Pharo9 just shows this view by default) • Re fl ective API is compatible: “instVarAt:”… still exist • If you want to restrict yourself to ST80, a checker could be easily created
  • 38. Compatibility • But if you start to use your own kind of Variables, you code will not be “ST80” compatible anymore • But you will be able to use the power of the new abstraction provided • Was this not the original idea behind Smalltalk? That a Programming System is a Medium?
  • 39. Where do we use it? • We are careful! We use Pharo ourselves… • We need a stable system to work with • We need to learn about how to use Variables best • Variables are used by the Compiler internally • Every instance variable is an InstanceVariableSlot (Globals, class vars) • Variables are used by the Debugging infrastructure to read/write • replaced the DebuggerMethodMap • The Spec UI Framework uses ObservableSlot
  • 40. Next Steps Variables • DoitVariable for nicer code in #DoItIn: methods • Undeclared Variables • programmer interaction in read/write, not compile! • better behaviour for test- fi rst development • Implement ThisProcessVariable in Pharo10 • Use WeakSlot to simplify some code
  • 41. Next Steps Fluid Classes • Finish the last problems (see issue tracker), make it the default • Experiments with Meta Data for Classes • Tag abstract classes • Experiment with Pragmas for classes • Compiler, compiler plugging, compiler options
  • 42. More.. • Extend the MetaLink Model to allow MetaLinks on Variables ( fi rst code is there already) • More Experiments about Slot Composition • Implement Default value once, use it on ClassVariable, InstanceVariableSlot and WeakSlot • First prototype, but it turned out to be too complex
  • 43. Thanks… • This is the work on *many* contributors from the Pharo Community • Thanks for lots of interesting discussions, ideas, and code!
  • 44. Help Wanted • We are always interested in improvements! • Pharo 10 is under active development • 30-40 Pull Requests integrated per week • Your Improvements are Welcome! https://github.com/pharo-project/pharo