Reflection: Stack as an Object

Damien Cassou, St├ęphane Ducasse and Luc Fabresse

Just to Reveal a Bit of It

To let you know that it exists

Coding in the Debugger

Operation Supporting Coding in the Debugger

Stack Frame as an Object


Example: Better Deprecated Message

We declare deprecation

A >> foo
   self deprecated: 'Use bar.' on: '31/12/2015' in: 'Pharo50'.
   self bar

should print: 'Message foo is deprecated in Pharo50. Use bar'

Example: Better Deprecated Message

deprecated: anExplanationString on: date in: version
	"Warn that the sending method has been deprecated"
		method: thisContext sender method
		explanation: anExplanationString
		on: date
		in: version) signal

thisContext sender method returns compiled method A>>#foo

Example: Conditional Halt and Test

  Halt if: #testSetInitialized

Only halt if executed from testSetInitialized

if: Implementation

Halt class >> if: condition
  "This is the typical message to use for inserting breakpoints during debugging.
  The argument can be one of the following:
    - a block: if the Block has one arg, the calling object is bound to that.
    - an expression
    - a selector: Halt if found in the call chain"

  condition isSymbol ifTrue: [ ^ self haltIfCallChainContains: condition ].
  condition isBlock ifTrue: [ ^ self haltIfBlockWithCallingObject: condition].
  condition ifTrue: [self signal].

How if: is implemented?

Halt class >> haltIfCallChainContains: aSelector
  | cntxt |
  cntxt := thisContext.
  [ cntxt sender isNil ] whileFalse: [
    cntxt := cntxt sender. 
    (cntxt selector = aSelector) ifTrue: [ self signal ] ].

Foundation for Innovation