Pragmas:
Literal Messages as Powerful
Method Annotations
Stéphane Ducasse, Eliot Miranda and Alain Plantec
Eliot Miranda/Steve Dahl/Vassili Bykov
Smalltalk

has: #unary , #binary
and: #(keyword messages)

and: $A
rich: ‘literal’

syntax: 12345678 who do we appreciate
size
"Primitive. Answer the number of indexable variables in the
receiver. This value is the same as the largest legal subscript.
Essential. See Object documentation whatIsAPrimitive."
<primitive: 62>
self class isVariable ifFalse: [self errorNotIndexable].
^ 0
Behavior methods for creating method dictionary
addSelector: selector withMethod: compiledMethod
"Add the message selector with the corresponding compiled
method to the receiver’s method dictionary."
methodDict at: selector put:

(self validateMethod: compiledMethod forSelector: selector).
self flushVMmethodCacheEntriesFor: selector
BlockClosure class methods for private
validateMethod: compiledMethod forSelector: selector
"Intercept this so we can mark unwind method"
| method |
method := super validateMethod: compiledMethod

forSelector: selector.
^((selector == #valueOnUnwindDo: or: [selector ==
#valueNowOrOnUnwindDo:])
ifTrue: [method asUnwindMethod]
ifFalse: [method])
inspectUndeclared
<menuItem: ‘Inspect Undeclared’

nameKey: nil

menu: #(#menuBar #browse #inspect)

position: 15.1>
Undeclared inspect
inspectUndeclared
<menuItem: ‘Inspect Undeclared’

nameKey: nil

menu: #(#menuBar #browse #inspect)

position: 15.1>
Undeclared inspect
[Smalltalk hasMetaObjects]

on: MessageNotUnderstood

do: [:ex| ex message]
inspectUndeclared
<menuItem: ‘Inspect Undeclared’

nameKey: nil

menu: #(#menuBar #browse #inspect)

position: 15.1>
Undeclared inspect
[Smalltalk hasMetaObjects]

on: MessageNotUnderstood

do: [:ex| ex message]
Smalltalk perform: #hasMetaObjects withArguments: #()
inspectUndeclared
<menuItem: ‘Inspect Undeclared’

nameKey: nil

menu: #(#menuBar #browse #inspect)

position: 15.1>
Undeclared inspect
[Smalltalk hasMetaObjects]

on: MessageNotUnderstood

do: [:ex| ex message]
Smalltalk perform: #hasMetaObjects withArguments: #()
add/remove => select/collect => visit & apply => update
integrat|ed/ion
• subset of language
• senders/implementors browsing works
• Convenient access (Vassili)

Pragma allNamed: symbol from: subclass to: superclass
more generally useful
• COM server

api method pragma vs class side config
• Preferences
AboutVisualWorksPage class

pagePragma
<pragmas: #class>
^#(pageOrder:)
systemPragma
<pragmas: #class>
^#(systemInformation:)


ApplicationModel class

menuMethodPragmas
<pragmas: #instance>
^Menu pragmas
BlockClosure class

exceptionPragmas
<pragmas: #instance>
^#(exception:)
L
e
g
a
l

i

t
y
more generally useful
• Trippy/GlamourousToolkit inspector pages
• Examples
• …?

Pragmas: Literal Messages as Powerful Method Annotations

  • 1.
    Pragmas: Literal Messages asPowerful Method Annotations Stéphane Ducasse, Eliot Miranda and Alain Plantec Eliot Miranda/Steve Dahl/Vassili Bykov
  • 2.
    Smalltalk
 has: #unary ,#binary and: #(keyword messages)
 and: $A rich: ‘literal’
 syntax: 12345678 who do we appreciate size "Primitive. Answer the number of indexable variables in the receiver. This value is the same as the largest legal subscript. Essential. See Object documentation whatIsAPrimitive." <primitive: 62> self class isVariable ifFalse: [self errorNotIndexable]. ^ 0
  • 3.
    Behavior methods forcreating method dictionary addSelector: selector withMethod: compiledMethod "Add the message selector with the corresponding compiled method to the receiver’s method dictionary." methodDict at: selector put:
 (self validateMethod: compiledMethod forSelector: selector). self flushVMmethodCacheEntriesFor: selector BlockClosure class methods for private validateMethod: compiledMethod forSelector: selector "Intercept this so we can mark unwind method" | method | method := super validateMethod: compiledMethod
 forSelector: selector. ^((selector == #valueOnUnwindDo: or: [selector == #valueNowOrOnUnwindDo:]) ifTrue: [method asUnwindMethod] ifFalse: [method])
  • 5.
    inspectUndeclared <menuItem: ‘Inspect Undeclared’
 nameKey:nil
 menu: #(#menuBar #browse #inspect)
 position: 15.1> Undeclared inspect
  • 6.
    inspectUndeclared <menuItem: ‘Inspect Undeclared’
 nameKey:nil
 menu: #(#menuBar #browse #inspect)
 position: 15.1> Undeclared inspect [Smalltalk hasMetaObjects]
 on: MessageNotUnderstood
 do: [:ex| ex message]
  • 7.
    inspectUndeclared <menuItem: ‘Inspect Undeclared’
 nameKey:nil
 menu: #(#menuBar #browse #inspect)
 position: 15.1> Undeclared inspect [Smalltalk hasMetaObjects]
 on: MessageNotUnderstood
 do: [:ex| ex message] Smalltalk perform: #hasMetaObjects withArguments: #()
  • 8.
    inspectUndeclared <menuItem: ‘Inspect Undeclared’
 nameKey:nil
 menu: #(#menuBar #browse #inspect)
 position: 15.1> Undeclared inspect [Smalltalk hasMetaObjects]
 on: MessageNotUnderstood
 do: [:ex| ex message] Smalltalk perform: #hasMetaObjects withArguments: #() add/remove => select/collect => visit & apply => update
  • 9.
    integrat|ed/ion • subset oflanguage • senders/implementors browsing works • Convenient access (Vassili)
 Pragma allNamed: symbol from: subclass to: superclass
  • 10.
    more generally useful •COM server
 api method pragma vs class side config • Preferences
  • 11.
    AboutVisualWorksPage class
 pagePragma <pragmas: #class> ^#(pageOrder:) systemPragma <pragmas:#class> ^#(systemInformation:) 
 ApplicationModel class
 menuMethodPragmas <pragmas: #instance> ^Menu pragmas BlockClosure class
 exceptionPragmas <pragmas: #instance> ^#(exception:) L e g a l
 i
 t y
  • 12.
    more generally useful •Trippy/GlamourousToolkit inspector pages • Examples • …?