[Pharo5] New Feature: persistent properties on temporary variables

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Pharo5] New Feature: persistent properties on temporary variables

Marcus Denker-4
Hi,

Since last week, TemporaryVariable meta-objects are made persistent if you put a property on them.
(they are saved in the method’s properties).

This means we can annotate temps without having to keep the AST around.

When not used all the machinery behind has no cost in terms of memory.

testPropertyAtPutPersistent

        | testValue temp temp2 |
        testValue := Date today.
        temp := thisContext method temporaryVariableNamed: #temp.
       
        temp propertyAt: #testKeySelector put: testValue.
        self
                assert: (temp propertyAt: #testKeySelector)
                equals: testValue.
               
        temp2 := thisContext method temporaryVariableNamed: #temp.
       
        self
                assert: (temp2 propertyAt: #testKeySelector)
                equals: testValue.
               
        self assert: temp2 == temp.
        self deny: thisContext method savedTemps isNil.
        temp removeProperty: #testKeySelector.
        self assert: temp properties isNil.
       
        self assert: thisContext method savedTemps isNil.