author | Claus Gittinger <cg@exept.de> |
Sat, 09 Dec 1995 22:34:58 +0100 | |
changeset 726 | 997e30ef8423 |
parent 530 | 07d0bce293c9 |
child 816 | a09ed813648b |
permissions | -rw-r--r-- |
357 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
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 |
" |
|
12 |
||
13 |
Object subclass:#VMBehavior |
|
14 |
instanceVariableNames:'superclass flags selectorArray methodArray' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Classes' |
|
18 |
! |
|
19 |
||
20 |
!VMBehavior class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
version |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/VMBehavior.st,v 1.5 1995-11-11 15:28:33 cg Exp $' |
357 | 38 |
! |
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
This class describes what the VM considers to be a classLike object. |
|
43 |
Every class in the system inherits from VMBehavior (via Behavior, Class, ClassDescription). |
|
44 |
||
45 |
In contrast to Behavior (which describes smalltalk behavior), the things defined |
|
46 |
here are valid for all objects for which the VM can do a method lookup. |
|
47 |
In theory, you can create totally different object systems on top of VMBehavior. |
|
48 |
This class is purely abstract - therefore, no smalltalk behavior is defined here. |
|
49 |
||
50 |
This is certainly not for normal applications. |
|
51 |
||
52 |
Instance variables: |
|
53 |
||
54 |
superclass <Class> where lookup continues when a selector is not |
|
55 |
found in the selector array |
|
56 |
(i.e. the superclass in Smalltalk terms) |
|
57 |
||
58 |
selectorArray <Array of Symbol> the selectors for which inst-methods are defined here |
|
59 |
||
60 |
methodArray <Array of Method> the inst-methods corresponding to the selectors |
|
61 |
||
62 |
flags <SmallInteger> special flag bits coded in a number |
|
63 |
not for application use |
|
64 |
||
65 |
flag bits (see stc.h): |
|
66 |
||
67 |
NOTICE: layout known by compiler and runtime system; be careful when changing |
|
68 |
" |
|
69 |
! ! |
|
70 |
||
71 |
!VMBehavior class methodsFor:'queries'! |
|
72 |
||
73 |
isBuiltInClass |
|
74 |
"this class is known by the run-time-system" |
|
75 |
||
76 |
^ true |
|
77 |
! ! |
|
78 |
||
79 |
!VMBehavior class methodsFor:'initialization'! |
|
80 |
||
81 |
initialize |
|
82 |
self == VMBehavior ifTrue:[ |
|
83 |
self flags:(VMBehavior class flagBehavior). |
|
84 |
] |
|
85 |
! ! |
|
86 |
||
87 |
!VMBehavior class methodsFor:'private'! |
|
88 |
||
89 |
basicNew |
|
90 |
"I dont know how to do this ..." |
|
91 |
||
92 |
^ self subclassResponsibility |
|
93 |
! |
|
94 |
||
95 |
basicNew:size |
|
96 |
"I dont know how to do this ..." |
|
97 |
||
98 |
^ self subclassResponsibility |
|
99 |
! |
|
100 |
||
101 |
new |
|
102 |
"I dont know how to do this ..." |
|
103 |
||
104 |
^ self subclassResponsibility |
|
105 |
! |
|
106 |
||
107 |
new:size |
|
108 |
"I dont know how to do this ..." |
|
109 |
||
110 |
^ self subclassResponsibility |
|
111 |
! ! |
|
112 |
||
113 |
!VMBehavior class methodsFor:'flag bit constants'! |
|
114 |
||
115 |
flagNotIndexed |
|
116 |
"return the flag code for non-indexed instances. |
|
117 |
You have to mask the flag value with indexMask when comparing |
|
118 |
it with flagNotIndexed." |
|
119 |
||
120 |
^ 0 |
|
121 |
! |
|
122 |
||
123 |
flagBytes |
|
124 |
"return the flag code for byte-valued indexed instances. |
|
125 |
You have to mask the flag value with indexMask when comparing |
|
126 |
it with flagBytes." |
|
127 |
||
128 |
%{ /* NOCONTEXT */ |
|
129 |
/* this is defined as a primitive to get defines from stc.h */ |
|
130 |
||
131 |
RETURN ( _MKSMALLINT(BYTEARRAY) ); |
|
132 |
%} |
|
133 |
" |
|
134 |
Behavior flagBytes |
|
135 |
" |
|
136 |
! |
|
137 |
||
138 |
flagWords |
|
139 |
"return the flag code for word-valued indexed instances (i.e. 2-byte). |
|
140 |
You have to mask the flag value with indexMask when comparing |
|
141 |
it with flagWords." |
|
142 |
||
143 |
%{ /* NOCONTEXT */ |
|
144 |
/* this is defined as a primitive to get defines from stc.h */ |
|
145 |
||
146 |
RETURN ( _MKSMALLINT(WORDARRAY) ); |
|
147 |
%} |
|
148 |
" |
|
149 |
Behavior flagWords |
|
150 |
" |
|
151 |
! |
|
152 |
||
153 |
flagLongs |
|
154 |
"return the flag code for long-valued indexed instances (i.e. 4-byte). |
|
155 |
You have to mask the flag value with indexMask when comparing |
|
156 |
it with flagLongs." |
|
157 |
||
158 |
%{ /* NOCONTEXT */ |
|
159 |
/* this is defined as a primitive to get defines from stc.h */ |
|
160 |
||
161 |
RETURN ( _MKSMALLINT(LONGARRAY) ); |
|
162 |
%} |
|
163 |
" |
|
164 |
Behavior flagLongs |
|
165 |
" |
|
166 |
! |
|
167 |
||
168 |
flagFloats |
|
169 |
"return the flag code for float-valued indexed instances (i.e. 4-byte reals). |
|
170 |
You have to mask the flag value with indexMask when comparing |
|
171 |
it with flagFloats." |
|
172 |
||
173 |
%{ /* NOCONTEXT */ |
|
174 |
/* this is defined as a primitive to get defines from stc.h */ |
|
175 |
||
176 |
RETURN ( _MKSMALLINT(FLOATARRAY) ); |
|
177 |
%} |
|
178 |
" |
|
179 |
Behavior flagFloats |
|
180 |
" |
|
181 |
! |
|
182 |
||
183 |
flagDoubles |
|
184 |
"return the flag code for double-valued indexed instances (i.e. 8-byte reals). |
|
185 |
You have to mask the flag value with indexMask when comparing |
|
186 |
it with flagDoubles." |
|
187 |
||
188 |
%{ /* NOCONTEXT */ |
|
189 |
/* this is defined as a primitive to get defines from stc.h */ |
|
190 |
||
191 |
RETURN ( _MKSMALLINT(DOUBLEARRAY) ); |
|
192 |
%} |
|
193 |
" |
|
194 |
Behavior flagDoubles |
|
195 |
" |
|
196 |
! |
|
197 |
||
198 |
flagPointers |
|
199 |
"return the flag code for pointer indexed instances (i.e. Array of object). |
|
200 |
You have to mask the flag value with indexMask when comparing |
|
201 |
it with flagPointers." |
|
202 |
||
203 |
%{ /* NOCONTEXT */ |
|
204 |
/* this is defined as a primitive to get defines from stc.h */ |
|
205 |
||
206 |
RETURN ( _MKSMALLINT(POINTERARRAY) ); |
|
207 |
%} |
|
208 |
" |
|
209 |
Behavior flagPointers |
|
210 |
" |
|
211 |
! |
|
212 |
||
213 |
flagWeakPointers |
|
214 |
"return the flag code for weak pointer indexed instances (i.e. WeakArray). |
|
215 |
You have to mask the flag value with indexMask when comparing |
|
216 |
it with flagWeakPointers." |
|
217 |
||
218 |
%{ /* NOCONTEXT */ |
|
219 |
/* this is defined as a primitive to get defines from stc.h */ |
|
220 |
||
221 |
RETURN ( _MKSMALLINT(WKPOINTERARRAY) ); |
|
222 |
%} |
|
223 |
! |
|
224 |
||
225 |
maskIndexType |
|
226 |
"return a mask to extract all index-type bits" |
|
227 |
||
228 |
%{ /* NOCONTEXT */ |
|
229 |
/* this is defined as a primitive to get defines from stc.h */ |
|
230 |
||
231 |
RETURN ( _MKSMALLINT(ARRAYMASK) ); |
|
232 |
%} |
|
233 |
! |
|
234 |
||
235 |
flagBehavior |
|
236 |
"return the flag code which marks Behavior-like instances. |
|
237 |
You have to check this single bit in the flag value when |
|
238 |
checking for behaviors." |
|
239 |
||
240 |
%{ /* NOCONTEXT */ |
|
241 |
/* this is defined as a primitive to get defines from stc.h */ |
|
242 |
||
243 |
RETURN ( _MKSMALLINT(BEHAVIOR_INSTS) ); |
|
244 |
%} |
|
245 |
||
246 |
"consistency check: |
|
247 |
all class-entries must be behaviors; |
|
248 |
all behaviors must be flagged so (in its class's flags) |
|
249 |
(otherwise, VM will bark) |
|
250 |
all non-behaviors may not be flagged |
|
251 |
||
252 |
|bit| |
|
253 |
bit := Class flagBehavior. |
|
254 |
||
255 |
ObjectMemory allObjectsDo:[:o| |
|
256 |
o isBehavior ifTrue:[ |
|
257 |
(o class flags bitTest:bit) ifFalse:[ |
|
258 |
self halt |
|
259 |
]. |
|
260 |
] ifFalse:[ |
|
261 |
(o class flags bitTest:bit) ifTrue:[ |
|
262 |
self halt |
|
263 |
]. |
|
264 |
]. |
|
265 |
o class isBehavior ifFalse:[ |
|
266 |
self halt |
|
267 |
] ifTrue:[ |
|
268 |
(o class class flags bitTest:bit) ifFalse:[ |
|
269 |
self halt |
|
270 |
] |
|
271 |
] |
|
272 |
] |
|
273 |
" |
|
274 |
! |
|
275 |
||
276 |
flagBlock |
|
277 |
"return the flag code which marks Block-like instances. |
|
278 |
You have to check this single bit in the flag value when |
|
279 |
checking for blocks." |
|
280 |
||
281 |
%{ /* NOCONTEXT */ |
|
282 |
/* this is defined as a primitive to get defines from stc.h */ |
|
283 |
||
284 |
RETURN ( _MKSMALLINT(BLOCK_INSTS) ); |
|
285 |
%} |
|
286 |
! |
|
287 |
||
288 |
flagMethod |
|
289 |
"return the flag code which marks Method-like instances. |
|
290 |
You have to check this single bit in the flag value when |
|
291 |
checking for methods." |
|
292 |
||
293 |
%{ /* NOCONTEXT */ |
|
294 |
/* this is defined as a primitive to get defines from stc.h */ |
|
295 |
||
296 |
RETURN ( _MKSMALLINT(METHOD_INSTS) ); |
|
297 |
%} |
|
298 |
! |
|
299 |
||
300 |
flagContext |
|
301 |
"return the flag code which marks Context-like instances. |
|
302 |
You have to check this single bit in the flag value when |
|
303 |
checking for contexts." |
|
304 |
||
305 |
%{ /* NOCONTEXT */ |
|
306 |
/* this is defined as a primitive to get defines from stc.h */ |
|
307 |
||
308 |
RETURN ( _MKSMALLINT(CONTEXT_INSTS) ); |
|
309 |
%} |
|
310 |
! |
|
311 |
||
312 |
flagBlockContext |
|
313 |
"return the flag code which marks BlockContext-like instances. |
|
314 |
You have to check this single bit in the flag value when |
|
315 |
checking for blockContexts." |
|
316 |
||
317 |
%{ /* NOCONTEXT */ |
|
318 |
/* this is defined as a primitive to get defines from stc.h */ |
|
319 |
||
320 |
RETURN ( _MKSMALLINT(BCONTEXT_INSTS) ); |
|
321 |
%} |
|
322 |
! |
|
323 |
||
324 |
flagFloat |
|
325 |
"return the flag code which marks Float-like instances. |
|
326 |
You have to check this single bit in the flag value when |
|
327 |
checking for floats." |
|
328 |
||
329 |
%{ /* NOCONTEXT */ |
|
330 |
/* this is defined as a primitive to get defines from stc.h */ |
|
331 |
||
332 |
RETURN ( _MKSMALLINT(FLOAT_INSTS) ); |
|
333 |
%} |
|
334 |
! |
|
335 |
||
336 |
flagSymbol |
|
337 |
"return the flag code which marks Symbol-like instances. |
|
338 |
You have to check this single bit in the flag value when |
|
339 |
checking for symbols." |
|
340 |
||
341 |
%{ /* NOCONTEXT */ |
|
342 |
/* this is defined as a primitive to get defines from stc.h */ |
|
343 |
||
344 |
RETURN ( _MKSMALLINT(SYMBOL_INSTS) ); |
|
345 |
%} |
|
346 |
! ! |
|
347 |
||
348 |
!VMBehavior methodsFor:'accessing'! |
|
349 |
||
350 |
superclass |
|
351 |
"return the receivers superclass" |
|
352 |
||
353 |
^ superclass |
|
354 |
! |
|
355 |
||
356 |
selectorArray |
|
357 |
"return the receivers selector array. |
|
358 |
Notice: this is not compatible with ST-80." |
|
359 |
||
360 |
^ selectorArray |
|
361 |
! |
|
362 |
||
363 |
methodArray |
|
364 |
"return the receivers method array. |
|
365 |
Notice: this is not compatible with ST-80." |
|
366 |
||
367 |
^ methodArray |
|
368 |
! |
|
369 |
||
370 |
flags |
|
371 |
"return the receivers flag bits" |
|
372 |
||
373 |
^ flags |
|
374 |
! |
|
375 |
||
376 |
selectors:newSelectors methods:newMethods |
|
377 |
"set both selector array and method array of the receiver, |
|
378 |
and flush caches" |
|
379 |
||
380 |
ObjectMemory flushCaches. |
|
381 |
selectorArray := newSelectors. |
|
382 |
methodArray := newMethods |
|
383 |
! ! |
|
384 |
||
385 |
!VMBehavior methodsFor:'queries'! |
|
386 |
||
387 |
isVariable |
|
388 |
"return true, if instances have indexed instance variables" |
|
389 |
||
390 |
"this could be defined as: |
|
391 |
^ (flags bitAnd:(VMBehavior maskIndexType)) ~~ 0 |
|
392 |
" |
|
393 |
||
394 |
%{ /* NOCONTEXT */ |
|
395 |
||
396 |
RETURN ( (_intVal(_INST(flags)) & ARRAYMASK) ? true : false ); |
|
397 |
%} |
|
398 |
! |
|
399 |
||
400 |
isFixed |
|
401 |
"return true, if instances do not have indexed instance variables" |
|
402 |
||
403 |
"this could be defined as: |
|
404 |
^ self isVariable not |
|
405 |
" |
|
406 |
||
407 |
%{ /* NOCONTEXT */ |
|
408 |
||
409 |
RETURN ( (_intVal(_INST(flags)) & ARRAYMASK) ? false : true ); |
|
410 |
%} |
|
411 |
! |
|
412 |
||
413 |
isBits |
|
414 |
"return true, if instances have indexed byte or short instance variables. |
|
415 |
Ignore long, float and double arrays, since ST-80 code using isBits are probably |
|
416 |
not prepared to handle them correctly." |
|
417 |
||
418 |
%{ /* NOCONTEXT */ |
|
419 |
||
420 |
REGISTER int flags; |
|
421 |
||
422 |
RETURN ( (((flags = (_intVal(_INST(flags)) & ARRAYMASK)) == BYTEARRAY) |
|
423 |
|| (flags == WORDARRAY)) ? true : false ); |
|
424 |
%} |
|
425 |
! |
|
426 |
||
427 |
isBytes |
|
428 |
"return true, if instances have indexed byte instance variables" |
|
429 |
||
430 |
"this could be defined as: |
|
431 |
^ (flags bitAnd:(VMBehavior maskIndexType)) == VMBehavior flagBytes |
|
432 |
" |
|
433 |
%{ /* NOCONTEXT */ |
|
434 |
||
435 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == BYTEARRAY) ? true : false ); |
|
436 |
%} |
|
437 |
! |
|
438 |
||
439 |
isWords |
|
440 |
"return true, if instances have indexed short instance variables" |
|
441 |
||
442 |
"this could be defined as: |
|
443 |
^ (flags bitAnd:(VMBehavior maskIndexType)) == VMBehavior flagWords |
|
444 |
" |
|
445 |
%{ /* NOCONTEXT */ |
|
446 |
||
447 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == WORDARRAY) ? true : false ); |
|
448 |
%} |
|
449 |
! |
|
450 |
||
451 |
isLongs |
|
452 |
"return true, if instances have indexed long instance variables" |
|
453 |
||
454 |
"this could be defined as: |
|
455 |
^ (flags bitAnd:(VMBehavior maskIndexType)) == VMBehavior flagLongs |
|
456 |
" |
|
457 |
%{ /* NOCONTEXT */ |
|
458 |
||
459 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == LONGARRAY) ? true : false ); |
|
460 |
%} |
|
461 |
! |
|
462 |
||
463 |
isFloats |
|
464 |
"return true, if instances have indexed float instance variables" |
|
465 |
||
466 |
"this could be defined as: |
|
467 |
^ (flags bitAnd:(VMBehavior maskIndexType)) == VMBehavior flagFloats |
|
468 |
" |
|
469 |
%{ /* NOCONTEXT */ |
|
470 |
||
471 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == FLOATARRAY) ? true : false ); |
|
472 |
%} |
|
473 |
! |
|
474 |
||
475 |
isDoubles |
|
476 |
"return true, if instances have indexed double instance variables" |
|
477 |
||
478 |
"this could be defined as: |
|
479 |
^ (flags bitAnd:(VMBehavior maskIndexType)) == VMBehavior flagDoubles |
|
480 |
" |
|
481 |
%{ /* NOCONTEXT */ |
|
482 |
||
483 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == DOUBLEARRAY) ? true : false ); |
|
484 |
%} |
|
485 |
! |
|
486 |
||
487 |
isPointers |
|
488 |
"return true, if instances have pointer instance variables |
|
489 |
i.e. are either non-indexed or have indexed pointer variables" |
|
490 |
||
491 |
"QUESTION: should we ignore WeakPointers ?" |
|
492 |
||
493 |
%{ /* NOCONTEXT */ |
|
494 |
||
495 |
REGISTER int flags; |
|
496 |
||
497 |
flags = _intVal(_INST(flags)) & ARRAYMASK; |
|
498 |
switch (flags) { |
|
499 |
default: |
|
500 |
/* normal objects */ |
|
501 |
RETURN ( true ); |
|
502 |
||
503 |
case BYTEARRAY: |
|
504 |
case WORDARRAY: |
|
505 |
case LONGARRAY: |
|
506 |
case FLOATARRAY: |
|
507 |
case DOUBLEARRAY: |
|
508 |
RETURN (false ); |
|
509 |
||
510 |
case WKPOINTERARRAY: |
|
511 |
/* what about those ? */ |
|
512 |
RETURN (true ); |
|
513 |
} |
|
514 |
%} |
|
515 |
! |
|
516 |
||
517 |
lookupMethodFor:aSelector |
|
518 |
"return the method, which would be executed if aSelector was sent to |
|
519 |
an instance of the receiver. I.e. the selector arrays of the receiver |
|
520 |
and all of its superclasses are searched for aSelector. |
|
521 |
Return the method, or nil if instances do not understand aSelector. |
|
522 |
EXPERIMENTAL: take care of multiple superclasses." |
|
523 |
||
524 |
|m cls| |
|
525 |
||
526 |
cls := self. |
|
527 |
[cls notNil] whileTrue:[ |
|
528 |
m := cls compiledMethodAt:aSelector. |
|
529 |
m notNil ifTrue:[^ m]. |
|
530 |
cls := cls superclass |
|
531 |
]. |
|
532 |
^ nil |
|
533 |
! |
|
534 |
||
535 |
cachedLookupMethodFor:aSelector |
|
536 |
"return the method, which would be executed if aSelector was sent to |
|
537 |
an instance of the receiver. I.e. the selector arrays of the receiver |
|
538 |
and all of its superclasses are searched for aSelector. |
|
539 |
Return the method, or nil if instances do not understand aSelector. |
|
540 |
This interface provides exactly the same information as #lookupMethodFor:, |
|
541 |
but uses the lookup-cache in the VM for faster search. |
|
542 |
However, keep in mind, that doing a lookup through the cache also adds new |
|
543 |
entries and can thus slow down the system by polluting the cache with |
|
544 |
irrelevant entries. (do NOT loop over all objects calling this method). |
|
545 |
Does NOT (currently) handle MI" |
|
546 |
||
547 |
%{ /* NOCONTEXT */ |
|
362 | 548 |
extern OBJ __lookup(); |
357 | 549 |
|
362 | 550 |
RETURN ( __lookup(self, aSelector, SENDER) ); |
357 | 551 |
%} |
552 |
||
553 |
" |
|
554 |
String cachedLookupMethodFor:#= |
|
555 |
String cachedLookupMethodFor:#asOrderedCollection |
|
556 |
" |
|
557 |
! ! |
|
558 |
||
559 |
!VMBehavior methodsFor:'private accessing'! |
|
560 |
||
561 |
setSuperclass:aClass |
|
562 |
"set the superclass of the receiver. |
|
563 |
this method is for special uses only - there will be no recompilation |
|
564 |
and no change record written here. Also, if the receiver class has |
|
565 |
already been in use, future operation of the system is not guaranteed to |
|
566 |
be correct, since no caches are flushed. |
|
567 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
568 |
||
569 |
superclass := aClass |
|
570 |
! |
|
571 |
||
572 |
setFlags:aNumber |
|
573 |
"set the flags. |
|
574 |
Do NOT use it." |
|
575 |
||
576 |
flags := aNumber |
|
577 |
! |
|
578 |
||
579 |
setSelectors:sels methods:m |
|
580 |
"set some inst vars. |
|
581 |
this method is for special uses only - there will be no recompilation |
|
582 |
and no change record written here; |
|
583 |
Do NOT use it." |
|
584 |
||
585 |
selectorArray := sels. |
|
586 |
methodArray := m. |
|
587 |
! |
|
588 |
||
589 |
setSelectorArray:anArray |
|
590 |
"set the selector array of the receiver. |
|
591 |
this method is for special uses only - there will be no recompilation |
|
592 |
and no change record written here. |
|
593 |
NOT for general use." |
|
594 |
||
595 |
selectorArray := anArray |
|
596 |
! |
|
597 |
||
598 |
setMethodArray:anArray |
|
599 |
"set the method array of the receiver. |
|
600 |
this method is for special uses only - there will be no recompilation |
|
601 |
and no change record written here. |
|
602 |
NOT for general use." |
|
603 |
||
604 |
methodArray := anArray |
|
605 |
! ! |