author | Stefan Vogel <sv@exept.de> |
Wed, 30 Nov 2016 16:58:18 +0100 | |
changeset 21079 | d83ede99b688 |
parent 21078 | c57b7b3dc73a |
child 21084 | 5a98e59ee251 |
permissions | -rw-r--r-- |
8728 | 1 |
" |
2 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
6844 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
18351 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
6844 | 16 |
nil subclass:#ProtoObject |
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
6912 | 20 |
category:'Kernel-Objects' |
6844 | 21 |
! |
22 |
||
23 |
!ProtoObject class methodsFor:'documentation'! |
|
24 |
||
8728 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
6844 | 39 |
documentation |
40 |
" |
|
41 |
a minimum object without much protocol; |
|
7659 | 42 |
Provides the minimum required to prevent inspectors from crashing, |
43 |
and debuggers from blocking. |
|
44 |
(i.e. instead of inheriting from nil, better inherit from this). |
|
45 |
||
6844 | 46 |
Named after a similar class found in Dolphin-Smalltalk. |
47 |
||
48 |
[author:] |
|
49 |
Claus Gittinger (not much authoring, though) |
|
50 |
" |
|
51 |
! ! |
|
52 |
||
21076 | 53 |
!ProtoObject class methodsFor:'helpers'! |
54 |
||
55 |
shallowCopyOf:anObject |
|
56 |
"return a copy of anObject with shared subobjects (a shallow copy) |
|
57 |
i.e. the copy shares referenced instvars with its original." |
|
58 |
||
59 |
%{ /* NOCONTEXT */ |
|
60 |
int ninsts, spc, sz; |
|
61 |
OBJ theCopy; |
|
62 |
OBJ cls = __qClass(anObject); |
|
63 |
int flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
64 |
||
65 |
/* |
|
66 |
* bail out for special objects .. |
|
67 |
*/ |
|
68 |
if (((flags & ~ARRAYMASK) == 0) |
|
69 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
70 |
sz = __qSize(anObject); |
|
71 |
__PROTECT__(anObject); |
|
72 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
73 |
__UNPROTECT__(anObject); |
|
74 |
if (theCopy) { |
|
75 |
cls = __qClass(anObject); |
|
76 |
spc = __qSpace(theCopy); |
|
77 |
||
78 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
79 |
||
80 |
sz = sz - OHDR_SIZE; |
|
81 |
if (sz) { |
|
82 |
char *src, *dst; |
|
83 |
||
84 |
src = (char *)(__InstPtr(anObject)->i_instvars); |
|
85 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
86 |
#ifdef bcopy4 |
|
87 |
{ |
|
88 |
/* care for odd-number of longs */ |
|
89 |
int nW = sz >> 2; |
|
90 |
||
91 |
if (sz & 3) { |
|
92 |
nW++; |
|
93 |
} |
|
94 |
||
95 |
bcopy4(src, dst, nW); |
|
96 |
} |
|
97 |
#else |
|
98 |
bcopy(src, dst, sz); |
|
99 |
#endif |
|
100 |
||
101 |
flags &= ARRAYMASK; |
|
102 |
if (flags == POINTERARRAY) { |
|
103 |
ninsts = __BYTES2OBJS__(sz); |
|
104 |
} else { |
|
105 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
106 |
} |
|
107 |
if (ninsts) { |
|
108 |
do { |
|
109 |
OBJ el; |
|
110 |
||
111 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
112 |
__STORE_SPC(theCopy, el, spc); |
|
113 |
} while (--ninsts); |
|
114 |
} |
|
115 |
} |
|
116 |
RETURN (theCopy); |
|
117 |
} |
|
118 |
} |
|
119 |
%}. |
|
120 |
"/ fallBack for special objects & memoryAllocation failure case |
|
121 |
||
21079 | 122 |
^ self error:'ProtoObject>>#shallowCopyOf: failed' |
123 |
! ! |
|
124 |
||
125 |
!ProtoObject methodsFor:'StepInterruptContext'! |
|
126 |
||
127 |
inspect |
|
128 |
"this method is required to allow inspection of the object" |
|
129 |
||
130 |
^ (Object compiledMethodAt:#inspect) |
|
131 |
valueWithReceiver:self |
|
132 |
arguments:nil |
|
133 |
selector:#inspect |
|
134 |
! |
|
135 |
||
136 |
instVarAt:index |
|
137 |
"this method is required to allow inspection of the object" |
|
138 |
||
139 |
^ (Object compiledMethodAt:#instVarAt:) |
|
140 |
valueWithReceiver:self |
|
141 |
arguments:{index} |
|
142 |
selector:#instVarAt: |
|
21076 | 143 |
! ! |
144 |
||
6844 | 145 |
!ProtoObject methodsFor:'error handling'! |
146 |
||
147 |
doesNotUnderstand:aMessage |
|
148 |
"this message is sent by the runtime system (VM) when |
|
149 |
a message is not understood by some object (i.e. there |
|
150 |
is no method for that selector). The original message has |
|
151 |
been packed into aMessage (i.e. the receiver, selector and |
|
152 |
any arguments) and the original receiver is then sent the |
|
153 |
#doesNotUnderstand: message. |
|
154 |
Here, we raise another signal which usually enters the debugger. |
|
155 |
You can of course redefine #doesNotUnderstand: in your classes |
|
156 |
to implement message delegation, |
|
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
7661
diff
changeset
|
157 |
or handle the MessageNotUnderstood exception gracefully." |
6844 | 158 |
|
159 |
<context: #return> |
|
160 |
||
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
7661
diff
changeset
|
161 |
^ MessageNotUnderstood raiseRequestWith:aMessage |
6844 | 162 |
! ! |
163 |
||
164 |
!ProtoObject methodsFor:'queries'! |
|
165 |
||
166 |
class |
|
19678 | 167 |
"return the receiver's class" |
6844 | 168 |
|
169 |
%{ /* NOCONTEXT */ |
|
170 |
||
171 |
RETURN ( __Class(self) ); |
|
172 |
%} |
|
173 |
||
174 |
" |
|
175 |
*** WARNING |
|
176 |
*** |
|
177 |
*** this method has been automatically created, |
|
178 |
*** since all nil-subclasses should respond to some minimum required |
|
179 |
*** protocol. |
|
180 |
*** |
|
181 |
*** Inspection and/or debugging of instances may not be possible, |
|
182 |
*** if you remove/change this method. |
|
183 |
" |
|
19678 | 184 |
|
185 |
"Modified (comment): / 30-04-2016 / 15:51:12 / cg" |
|
10589 | 186 |
! |
187 |
||
188 |
identityHash |
|
189 |
"return an Integer useful as a hash key for the receiver. |
|
190 |
This hash should return same values for the same object (i.e. use |
|
191 |
this to hash on identity of objects). |
|
192 |
||
193 |
We cannot use the Objects address (as other smalltalks do) since |
|
194 |
no object-table exists and the hashval must not change when objects |
|
195 |
are moved by the collector. Therefore we assign each object a unique |
|
196 |
Id in the object header itself as its hashed upon. |
|
197 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
198 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
199 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
200 |
hashed-upon objects could add an instvar containing the hash value." |
|
201 |
||
202 |
%{ /* NOCONTEXT */ |
|
203 |
||
204 |
REGISTER unsigned INT hash; |
|
205 |
static unsigned nextHash = 0; |
|
206 |
||
207 |
if (__isNonNilObject(self)) { |
|
208 |
hash = __GET_HASH(self); |
|
209 |
if (hash == 0) { |
|
210 |
/* has no hash yet */ |
|
211 |
||
212 |
if (++nextHash > __MAX_HASH__) { |
|
213 |
nextHash = 1; |
|
214 |
} |
|
215 |
hash = nextHash; |
|
216 |
__SET_HASH(self, hash); |
|
217 |
} |
|
218 |
||
219 |
/* |
|
220 |
* now, we got 11 bits for hashing; |
|
221 |
* make it as large as possible; since most hashers use the returned |
|
222 |
* key and take it modulo some prime number, this will allow for |
|
223 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
224 |
*/ |
|
225 |
hash = __MAKE_HASH__(hash); |
|
226 |
RETURN ( __mkSmallInteger(hash) ); |
|
227 |
} |
|
228 |
%}. |
|
229 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
230 |
||
231 |
"Created: / 31-05-2007 / 23:18:40 / cg" |
|
6844 | 232 |
! ! |
233 |
||
234 |
!ProtoObject methodsFor:'testing'! |
|
235 |
||
21079 | 236 |
isBridgeProxy |
237 |
^ false |
|
238 |
! |
|
239 |
||
12571 | 240 |
ifNil:aBlock |
241 |
^ self |
|
242 |
! |
|
243 |
||
244 |
ifNotNil:aBlockOrValue |
|
18439 | 245 |
(aBlockOrValue isBlock and:[aBlockOrValue argumentCount == 1]) ifTrue:[ |
16158 | 246 |
^ aBlockOrValue value:self. |
247 |
]. |
|
12571 | 248 |
^ aBlockOrValue value |
249 |
! |
|
250 |
||
6844 | 251 |
isBehavior |
18351 | 252 |
"return true, if the receiver is describing another object's behavior. |
9222 | 253 |
False is returned here - the method is only redefined in Behavior." |
254 |
||
6844 | 255 |
^ false |
7661
71d2cac1b959
some tests aded to avoid trouble in debugger
Claus Gittinger <cg@exept.de>
parents:
7659
diff
changeset
|
256 |
! |
6844 | 257 |
|
7661
71d2cac1b959
some tests aded to avoid trouble in debugger
Claus Gittinger <cg@exept.de>
parents:
7659
diff
changeset
|
258 |
isBlock |
71d2cac1b959
some tests aded to avoid trouble in debugger
Claus Gittinger <cg@exept.de>
parents:
7659
diff
changeset
|
259 |
^ false |
7659 | 260 |
! |
261 |
||
21078 | 262 |
isBridgeProxy |
263 |
^ false |
|
264 |
! |
|
265 |
||
7659 | 266 |
isException |
267 |
^ false |
|
268 |
! |
|
269 |
||
270 |
isExceptionHandler |
|
271 |
^ false |
|
272 |
! |
|
273 |
||
274 |
isJavaObject |
|
275 |
^ false |
|
10589 | 276 |
! |
277 |
||
278 |
isLazyValue |
|
279 |
^ false |
|
280 |
||
281 |
"Created: / 03-06-2007 / 14:02:12 / cg" |
|
10591 | 282 |
! |
283 |
||
284 |
isLiteral |
|
285 |
^ false |
|
286 |
||
287 |
"Created: / 04-06-2007 / 17:19:10 / cg" |
|
21075 | 288 |
! |
289 |
||
290 |
isNil |
|
291 |
^ false. |
|
292 |
! |
|
293 |
||
294 |
isProtoObject |
|
295 |
^ true |
|
6844 | 296 |
! ! |
297 |
||
298 |
!ProtoObject class methodsFor:'documentation'! |
|
299 |
||
300 |
version |
|
19678 | 301 |
^ '$Header$' |
12571 | 302 |
! |
303 |
||
304 |
version_CVS |
|
19678 | 305 |
^ '$Header$' |
6844 | 306 |
! ! |
16158 | 307 |