forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TemporaryVariable.class.st
142 lines (119 loc) · 3.04 KB
/
TemporaryVariable.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"
I model a temporary variable, similar to Slot and LiteralVariable.
For now I am cread on need and never persisted. (this might change later
to allow me to be annotated with properties.)
I know the method that I come from. If I am a block temp, I record the startPC of that block.
"
Class {
#name : #TemporaryVariable,
#superclass : #Variable,
#instVars : [
'method',
'startpc'
],
#classVars : [
'PersistentTemps'
],
#category : #'Kernel-Variables'
}
{ #category : #'class initialization' }
TemporaryVariable class >> initialize [
Properties := Properties
ifNil: [ WeakIdentityKeyDictionary new ]
ifNotNil: [ (WeakIdentityKeyDictionary newFrom: Properties) rehash ].
PersistentTemps ifNil: [ PersistentTemps := Set new ]
]
{ #category : #'instance creation' }
TemporaryVariable class >> name: aName block: aBlock [
^(self new
name: aName;
method: aBlock method;
startpc: aBlock startpc) yourselfOrSaved.
]
{ #category : #'instance creation' }
TemporaryVariable class >> name: aName context: aContext [
^aContext isBlock
ifTrue: [ self name: aName block: aContext closure ]
ifFalse: [ self name: aName method: aContext method ]
]
{ #category : #'instance creation' }
TemporaryVariable class >> name: aName method: aMethod [
^(self new
name: aName;
method: aMethod) yourselfOrSaved
]
{ #category : #comparing }
TemporaryVariable >> = other [
self == other
ifTrue: [ ^ true ].
^ (self species == other species)
and: [ name = other name
and: [ method = other method
and: [ startpc = other startpc ] ] ]
]
{ #category : #properties }
TemporaryVariable >> ensureProperties [
method saveTemp: self.
^ super ensureProperties
]
{ #category : #comparing }
TemporaryVariable >> hash [
^ (name hash
bitXor: method hash)
bitXor: (startpc ifNil: [0])
]
{ #category : #testing }
TemporaryVariable >> isFromBlock [
^startpc isNotNil
]
{ #category : #accessing }
TemporaryVariable >> method [
^ method
]
{ #category : #accessing }
TemporaryVariable >> method: anObject [
method := anObject
]
{ #category : #accessing }
TemporaryVariable >> name [
^ name
]
{ #category : #accessing }
TemporaryVariable >> name: anObject [
name := anObject
]
{ #category : #'reflecive api' }
TemporaryVariable >> readInContext: aContext [
^aContext tempNamed: name
]
{ #category : #properties }
TemporaryVariable >> removePropertiesIfEmpty [
^ Properties at: self ifPresent: [ :dict |
dict ifEmpty: [
method removeSavedTemp: self.
Properties removeKey: self ] ]
]
{ #category : #accessing }
TemporaryVariable >> startpc [
^ startpc
]
{ #category : #accessing }
TemporaryVariable >> startpc: anObject [
startpc := anObject
]
{ #category : #queries }
TemporaryVariable >> usingMethods [
^{method}
]
{ #category : #'reflecive api' }
TemporaryVariable >> write: aValue InContext: aContext [
^aContext tempNamed: name put: aValue
]
{ #category : #'saved temps' }
TemporaryVariable >> yourselfOrSaved [
method savedTemps ifNil: [ ^self ].
^method savedTemps
detect: [ :each | each = self ]
ifFound: [ :found | found ]
ifNone: [ self ]
]