[Pharo4][Slots] Small progress of the day: Example 1st class Globals
Hi, The Slots project contains not only Slots, but in addition âFirst classâ Globals, too, Pharo4 now contains an example: ExampleClassVariable, this class defines the ivar (slot) âstateâ. read ^state write: anObject state := anObject we can create a class defining a class var like that: Object subclass: #TT slots: { } classVariables: { #ClassVar => ExampleClassVariable } category: âPlayGround' Like with slots, the variable reads and write generate code to call the reflective read and write methods: 21 <20> pushConstant: ##ClassVar 22 <D1> send: read 23 <7C> returnTop and the write: 21 <10> pushTemp: 0 22 <69> popIntoTemp: 1 23 <20> pushConstant: ##ClassVar 24 <11> pushTemp: 1 25 <E1> send: write: 26 <87> pop 27 <78> returnSelf Full list of changes: - cleanup: moving all Reflectivity related code from Slot package to Reflectivity package - fix code generation to not use Object>>#writeToGlobal: but instead the idea with the temp as seen above - add example for Class Variable Marcus
marcus I would love to see how we can use slots to have first class caches as described in guillermo paper. Why do we need to have a reflective call when it is not needed? Could not we late bound such behavior? Stef Le 5/3/15 18:20, Marcus Denker a écrit :
Hi,
The Slots project contains not only Slots, but in addition âFirst classâ Globals, too,
Pharo4 now contains an example:
ExampleClassVariable, this class defines the ivar (slot) âstateâ.
read ^state
write: anObject state := anObject
we can create a class defining a class var like that:
Object subclass: #TT slots: { } classVariables: { #ClassVar => ExampleClassVariable } category: âPlayGround'
Like with slots, the variable reads and write generate code to call the reflective read and write methods:
21 <20> pushConstant: ##ClassVar 22 <D1> send: read 23 <7C> returnTop
and the write:
21 <10> pushTemp: 0 22 <69> popIntoTemp: 1 23 <20> pushConstant: ##ClassVar 24 <11> pushTemp: 1 25 <E1> send: write: 26 <87> pop 27 <78> returnSelf
Full list of changes:
- cleanup: moving all Reflectivity related code from Slot package to Reflectivity package - fix code generation to not use Object>>#writeToGlobal: but instead the idea with the temp as seen above - add example for Class Variable
Marcus
On 08 Mar 2015, at 20:59, stepharo <stepharo@free.fr> wrote:
marcus
I would love to see how we can use slots to have first class caches as described in guillermo paper. Why do we need to have a reflective call when it is not needed? Could not we late bound such behavior?
This example just shows how to do a Global without caring about byte code generation. You can override emit* and do something faster. Now for caches, you want the *first* call to be an indirection (to trigger the computation), and all the ones after to use the fast code. I think the best is to use MetaLinks for that: install a MetaLink on the Global for read that removes itself after the first call. This way, the first call can do a computation while all the following will be full speed. For cache invalidation, the Cache can install links to get notified (and reset it self) when those value change that it depends on. Marcus
participants (2)
-
Marcus Denker -
stepharo