Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Variables in Pharo5

2,031 views

Published on

Variables in Pharo5. ESUG 2015

Published in: Technology
  • Hi there! Get Your Professional Job-Winning Resume Here - Check our website! http://bit.ly/resumpro
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Video Part1: https://www.youtube.com/watch?v=hEWKV9eWAGY Video Part2: https://www.youtube.com/watch?v=fWo1V_C0cu8
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Variables in Pharo5

  1. 1. Variables in Pharo5 ESUG 2015 Marcus Denker http://www.pharo.org
  2. 2. Everything is an Object
  3. 3. Everything?
  4. 4. Classes, yes.
  5. 5. Methods, yes
  6. 6. But Variables?
  7. 7. Everything is an object? SmalltalkImage classVarNamed: #CompilerClass ==> returns value Object binding class ==> Association
  8. 8. Why not an Object?
  9. 9. Globals/ClassVariables • We are close: bindings are associations • Add sublass “LiteralVariable” • Sublasses GlobalVariable, ClassVariable • Enhance API
  10. 10. Globals/ClassVariables SmalltalkImage classVariableNamed: #CompilerClass Object binding class
  11. 11. Globals: Reflective APi global := SmalltalkImage classVariableNamed: #CompilerClass global read global write: someObject + helper methods + compatibility methods
  12. 12. Everything is an object? • Point instanceVariables • 5@3 instVarNamed: ‘x’ • 5@3 instVarNamed: ‘y’ put: 6
  13. 13. Why not an Object?
  14. 14. Slots Point slots (Point slotNamed: #x) read: (3@4) (Point slotNamed: #x) write: 7 to: (3@4)
  15. 15. Variables+MetaLink • Helper methods • But: can’t we annotate variables directly? Point assignmentNodes
  16. 16. Variables + Links • Object binding link: myMetaLink • (Point slotNamed: #x) link: myMetaLink (not yet in Pharo5)
  17. 17. Opal Compiler • Uses RB AST • Based on Visitors Text AST AST +vars IR CM Parser Semantic Analysis AST Translator+ IRBuilder BytecodeBuilder+ Encoder
  18. 18. Opal Compiler • Name analysis finds the variables • Code generator can delegate to them Text AST AST +vars IR CM Parser Semantic Analysis AST Translator+ IRBuilder BytecodeBuilder+ Encoder
  19. 19. Gobals: code read • By default compile reflective read emitValue: aMethodBuilder aMethodBuilder pushLiteralVariable: #slot->self; send: #read
  20. 20. Gobals: code write • By default compile reflective write emitStore: aMethodBuilder | tempName | tempName := Object new. aMethodBuilder addTemp: tempName; storeTemp: tempName; popTop; pushLiteralVariable: #global -> self; pushTemp: tempName; send: #write:
  21. 21. Gobals: code write • ClassVariable and GlobalVariable override emitStore: methodBuilder methodBuilder storeIntoLiteralVariable: self.
  22. 22. Same for Slots • Slot generates reflective read/write • InstanceVariableSlot overrides for fast instance access via byte code
  23. 23. What does that mean? • Slots and Globals are instances of a class • The compiler delegates code generation to the variable meta object • Which means: We can define our own variables!
  24. 24. Class Template Object subclass: #Point slots: { #x. #y } classVariables: { } category: 'Kernel-BasicObjects'
  25. 25. Class Template Object subclass: #MyClass slots: { #x => WeakSlot } classVariables: { } category: 'Example'
  26. 26. Examples: DEMO • Simple Slot • WeakSlot • Property Slot • Boolean
  27. 27. RoadMap • Pharo3: • Layout+Slots (hidden), Opal • Pharo4 • Slots: Monticello support, class template • Pharo5 • Remove old Compiler/AST • Slots + Reflectivity: First finished version
  28. 28. RoadMap • Pharo6: • Library of useful Slots • Use e.g. Property Slots in Bloc/Morphic
  29. 29. Future • Can’t we model bit patterns and bind them to named virtual slots? • How to model Array-like layouts better?
  30. 30. Thanks! • Work of many people… • special thanks to… Toon Verwaest, Camillo Bruni, Martin Dias, Stephane Ducasse, Max Mattone and Camille Teruel
  31. 31. Questions ?

×