-
Notifications
You must be signed in to change notification settings - Fork 65
/
CogStackPage.class.st
308 lines (260 loc) · 7.6 KB
/
CogStackPage.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
"
I am a class that helps organize the StackInterpreter's collection of stack pages. I represent the control block for a single stack page in the collection of stack pages represented by an InterpreterStackPages or CoInterpreterStackPages instance.
"
Class {
#name : #CogStackPage,
#superclass : #VMStructType,
#instVars : [
'stackLimit',
'headSP',
'headFP',
'baseFP',
'baseAddress',
'realStackLimit',
'lastAddress',
'trace',
'padToWord',
'nextPage',
'prevPage'
],
#pools : [
'VMBasicConstants',
'VMBytecodeConstants'
],
#category : #'VMMaker-Interpreter'
}
{ #category : #translation }
CogStackPage class >> alignedByteSize [
^self surrogateClass alignedByteSize
]
{ #category : #translation }
CogStackPage class >> alignedByteSizeOf: anObject forClient: aVMClass [
^self surrogateClass alignedByteSize
]
{ #category : #'code generation' }
CogStackPage class >> getter: getter bitPosition: bitPosition bitWidth: bitWidth type: typeOrNil [
^String streamContents:
[:s| | startByte endByte accessor |
startByte := bitPosition // 8.
endByte := bitPosition + bitWidth - 1 // 8.
self assert: bitPosition \\ 8 = 0.
accessor := #('byte' 'short' 'long32' 'long32')
at: endByte - startByte + 1
ifAbsent: ['long64'].
s nextPutAll: getter; crtab: 1; nextPut: $^.
(typeOrNil notNil and: [typeOrNil last = $*]) ifTrue:
[accessor := 'unsigned', (accessor copy
at: 1 put: accessor first asUppercase;
yourself)].
(typeOrNil notNil and: ['*StackPage*' match: typeOrNil]) ifTrue:
[s nextPutAll: 'stackPages surrogateAtAddress: ('].
s nextPutAll: 'memory ';
nextPutAll: accessor;
nextPutAll: 'At: address + '; print: startByte.
(typeOrNil notNil and: ['*StackPage*' match: typeOrNil]) ifTrue:
[s nextPut: $)]]
"| bitPosition |
bitPosition := 0.
(self fieldAccessorsForBytesPerWord: 4) collect:
[:spec|
bitPosition := bitPosition + spec second.
self getter: spec first
bitPosition: bitPosition - spec second
bitWidth: spec second
type: (spec at: 3 ifAbsent: [])]"
]
{ #category : #translation }
CogStackPage class >> initialize [
"self initialize"
(Smalltalk classNamed: #CogStackPageSurrogate32) ifNotNil:
[:csps32|
self checkGenerateSurrogate: csps32 bytesPerWord: 4].
(Smalltalk classNamed: #CogStackPageSurrogate64) ifNotNil:
[:csps64|
self checkGenerateSurrogate: csps64 bytesPerWord: 8]
]
{ #category : #translation }
CogStackPage class >> instVarNamesAndTypesForTranslationDo: aBinaryBlock [
"enumerate aBinaryBlock with the names and C type strings for the inst vars to include in a StackPage struct."
self allInstVarNames do:
[:ivn|
(ivn = 'padToWord' and: [BytesPerWord = 4]) ifFalse:
[aBinaryBlock
value: ivn
value: ((ivn = 'trace' or: [ivn = 'padToWord'])
ifTrue: [#int]
ifFalse:
[(ivn endsWith: 'Page')
ifTrue: ['struct _StackPage *']
ifFalse: [#'char *']])]]
]
{ #category : #'code generation' }
CogStackPage class >> setter: getter bitPosition: bitPosition bitWidth: bitWidth type: typeOrNil [
^String streamContents:
[:s| | startByte endByte accessor |
startByte := bitPosition // 8.
endByte := bitPosition + bitWidth - 1 // 8.
self assert: bitPosition \\ 8 = 0.
accessor := #('byte' 'short' 'long32' 'long32')
at: endByte - startByte + 1
ifAbsent: ['long64'].
s nextPutAll: getter; nextPutAll: ': aValue'; crtab: 1;
nextPutAll: 'self assert: (address + '; print: startByte;
nextPutAll: ' >= zoneBase and: [address + '; print: endByte;
nextPutAll: ' < zoneLimit]).'; crtab: 1.
(typeOrNil notNil and: [typeOrNil last = $*]) ifTrue:
[accessor := 'unsigned', (accessor copy
at: 1 put: accessor first asUppercase;
yourself)].
(typeOrNil notNil and: ['*StackPage*' match: typeOrNil]) ifFalse:
[s nextPut: $^].
s nextPutAll: 'memory ';
nextPutAll: accessor; nextPutAll: 'At: address + '; print: startByte;
nextPutAll: ' put: aValue'.
(typeOrNil notNil and: ['*StackPage*' match: typeOrNil]) ifTrue:
[s nextPutAll: ' asInteger.'; crtab: 1; nextPutAll: '^aValue']]
"| bitPosition |
bitPosition := 0.
(self fieldAccessorsForBytesPerWord: 4) collect:
[:spec|
bitPosition := bitPosition + spec second.
self setter: spec first
bitPosition: bitPosition - spec second
bitWidth: spec second
type: (spec at: 3 ifAbsent: [])]"
]
{ #category : #translation }
CogStackPage class >> structTypeName [
^'StackPage' "Drop initial Cog or Interpreter"
]
{ #category : #'simulation only' }
CogStackPage class >> surrogateClass [
^BytesPerWord = 4
ifTrue: [CogStackPageSurrogate32]
ifFalse: [CogStackPageSurrogate64]
]
{ #category : #'simulation only' }
CogStackPage >> address [
<doNotGenerate>
^baseAddress
]
{ #category : #testing }
CogStackPage >> addressIsInPage: address [
<var: #address type: #'char *'>
"For assert-checking"
^lastAddress < address and: [address < baseAddress]
]
{ #category : #accessing }
CogStackPage >> baseAddress [
^baseAddress
]
{ #category : #accessing }
CogStackPage >> baseAddress: anAddress [
^baseAddress := anAddress
]
{ #category : #accessing }
CogStackPage >> baseFP [
"Answer the value of baseFP"
^ baseFP
]
{ #category : #accessing }
CogStackPage >> baseFP: pointer [ "<Integer>"
"Set the value of baseFP"
self assert: (pointer = 0 or: [pointer < baseAddress and: [realStackLimit < pointer]]).
^baseFP := pointer
]
{ #category : #accessing }
CogStackPage >> headFP [
"Answer the value of headFP"
^headFP
]
{ #category : #accessing }
CogStackPage >> headFP: pointer [ "<Integer>"
"Set the value of headFP"
^headFP := pointer
]
{ #category : #accessing }
CogStackPage >> headSP [
"Answer the value of headSP"
^headSP
]
{ #category : #accessing }
CogStackPage >> headSP: pointer [ "<Integer>"
"Set the value of headSP"
^headSP := pointer
]
{ #category : #testing }
CogStackPage >> isFree [
^baseFP = 0
]
{ #category : #accessing }
CogStackPage >> lastAddress [
^lastAddress
]
{ #category : #accessing }
CogStackPage >> lastAddress: anAddress [
^lastAddress := anAddress
]
{ #category : #accessing }
CogStackPage >> nextPage [
"Answer the value of nextPage"
^ nextPage
]
{ #category : #accessing }
CogStackPage >> nextPage: anObject [
"Set the value of nextPage"
^nextPage := anObject
]
{ #category : #accessing }
CogStackPage >> prevPage [
"Answer the value of prevPage"
^ prevPage
]
{ #category : #accessing }
CogStackPage >> prevPage: anObject [
"Set the value of prevPage"
^prevPage := anObject
]
{ #category : #printing }
CogStackPage >> printOn: aStream [
<doNotGenerate>
super printOn: aStream.
aStream nextPut: $@; print: baseAddress; space.
self isFree
ifTrue: [aStream nextPutAll: 'free']
ifFalse: [aStream print: baseFP; nextPutAll: '<->'; print: headFP; space; nextPutAll: 'trace '; print: trace]
]
{ #category : #accessing }
CogStackPage >> realStackLimit [
"Answer the value of realStackLimit"
^ realStackLimit
]
{ #category : #accessing }
CogStackPage >> realStackLimit: anObject [
"Set the value of realStackLimit"
^realStackLimit := anObject
]
{ #category : #accessing }
CogStackPage >> stackLimit [
"Answer the value of stackLimit"
^ stackLimit
]
{ #category : #accessing }
CogStackPage >> stackLimit: anObject [
"Set the value of stackLimit"
^stackLimit := anObject
]
{ #category : #accessing }
CogStackPage >> trace [
"Answer the page's trace state.
0 = untraced. 1 = should be traced. 2 = has been traced.
-1 = invalid (for assertions)"
^trace
]
{ #category : #accessing }
CogStackPage >> trace: anInteger [
"Set the page's trace state.
0 = untraced. 1 = should be traced. 2 = has been traced.
-1 = invalid (for assertions)"
^trace := anInteger
]