-
Notifications
You must be signed in to change notification settings - Fork 65
/
CObjectAccessor.class.st
197 lines (157 loc) · 4.76 KB
/
CObjectAccessor.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
"
I am used to simulate the indexed access to any object during plugin simulation.
"
Class {
#name : #CObjectAccessor,
#superclass : #Object,
#instVars : [
'object',
'offset'
],
#category : #'Slang-Types'
}
{ #category : #accessing }
CObjectAccessor class >> alignedByteSizeOf: aCObjectAccessor forClient: aVMClass [
"Hack; this only works if the object is actually bytes."
^aCObjectAccessor object size
]
{ #category : #'instance creation' }
CObjectAccessor class >> on: anObject [
^self new setObject: anObject
]
{ #category : #'pointer arithmetic' }
CObjectAccessor >> + increment [
^self shallowCopy += increment
]
{ #category : #'pointer arithmetic' }
CObjectAccessor >> += increment [
offset := offset + increment
]
{ #category : #'pointer arithmetic' }
CObjectAccessor >> - decrement [
^self shallowCopy -= decrement
]
{ #category : #'pointer arithmetic' }
CObjectAccessor >> -= decrement [
offset := offset - decrement
]
{ #category : #converting }
CObjectAccessor >> asDoubleAccessor [
^ self asPluggableAccessor
atBlock: [:obj :index | obj doubleAt: index]
atPutBlock: [:obj :index :value | obj doubleAt: index put: value]
]
{ #category : #converting }
CObjectAccessor >> asFloatAccessor [
^ self asPluggableAccessor
atBlock: [:obj :index | obj floatAt: index]
atPutBlock: [:obj :index :value | obj floatAt: index put: value]
]
{ #category : #converting }
CObjectAccessor >> asIntAccessor [
^ self asPluggableAccessor
atBlock: [:obj :index | obj intAt: index]
atPutBlock: [:obj :index :value | obj intAt: index put: value]
]
{ #category : #transformation }
CObjectAccessor >> asIntAccessorOfSize: byteSize signed: isSigned [
^ self asPluggableAccessor
atBlock: [:obj :index | obj integerAt: index size: byteSize signed: isSigned ]
atPutBlock: [:obj :index :value | obj integerAt: index put: value size: byteSize signed: isSigned ]
]
{ #category : #converting }
CObjectAccessor >> asInteger [
^ self
]
{ #category : #converting }
CObjectAccessor >> asOop: aClass [
(aClass ccgCanConvertFrom: object)
ifFalse: [^self error: 'incompatible object for autocoercion'].
^object
]
{ #category : #converting }
CObjectAccessor >> asPluggableAccessor [
^ (CPluggableAccessor on: object) += offset
]
{ #category : #converting }
CObjectAccessor >> asPluggableAccessor: accessorArray [
^((CPluggableAccessor on: object) += offset)
atBlock: accessorArray first
atPutBlock: accessorArray last
]
{ #category : #converting }
CObjectAccessor >> asPointerAccessor: wordSize [
^ self asPluggableAccessor
atBlock: [ :obj :index | obj integerAt: index size: wordSize signed: false ]
atPutBlock: [ :obj :index :value | obj integerAt: index put: value size: wordSize signed: false ]
]
{ #category : #accessing }
CObjectAccessor >> at: index [
^object instVarAt: index + offset + 1
]
{ #category : #accessing }
CObjectAccessor >> at: index put: value [
^object instVarAt: index + offset + 1 put: value
]
{ #category : #converting }
CObjectAccessor >> coerceTo: cTypeString sim: interpreterSimulator [
cTypeString caseOf: {
[#'float *'] -> [^self asFloatAccessor].
[#'double *'] -> [^self asDoubleAccessor].
[#'int *'] -> [^self asIntAccessor].
[#'void **'] -> [^self asPointerAccessor: interpreterSimulator objectMemory wordSize].
[#'int8_t *'] -> [^self asIntAccessorOfSize: 1 signed: true ].
[#'uint8_t *'] -> [^self asIntAccessorOfSize: 1 signed: false ].
[#'char *'] -> [^self asIntAccessorOfSize: 1 signed: false ].
[#'int16_t *'] -> [^self asIntAccessorOfSize: 2 signed: true ].
[#'uint16_t *'] -> [^self asIntAccessorOfSize: 2 signed: false ].
[#'int32_t *'] -> [^self asIntAccessorOfSize: 4 signed: true ].
[#'uint32_t *'] -> [^self asIntAccessorOfSize: 4 signed: false ].
[#'int64_t *'] -> [^self asIntAccessorOfSize: 8 signed: true ].
[#'uint64_t *'] -> [^self asIntAccessorOfSize: 8 signed: false ].
['sqInputEvent*'] -> [^self] }
otherwise: [self halt].
^ self
]
{ #category : #accessing }
CObjectAccessor >> first [
^self at: 0
]
{ #category : #private }
CObjectAccessor >> getObject [
^object
]
{ #category : #testing }
CObjectAccessor >> isCArray [
"Answer a boolean indicating whether the receiver responds to the CArray interface"
^true
]
{ #category : #accessing }
CObjectAccessor >> isCObjectAccessor [
^ true
]
{ #category : #'initialize-release' }
CObjectAccessor >> memory: anObject offset: baseIndex [
object := anObject.
offset := baseIndex
]
{ #category : #accessing }
CObjectAccessor >> object [
^ object
]
{ #category : #accessing }
CObjectAccessor >> offset [
^ offset
]
{ #category : #printing }
CObjectAccessor >> printOn: aStream [
super printOn: aStream.
aStream
nextPutAll:' on: ';
print: object.
]
{ #category : #private }
CObjectAccessor >> setObject: anObject [
object := anObject.
offset := 0.
]