1 Object subclass:#NamedArray |
|
2 instanceVariableNames:'superclass flags selectorArray methodArray otherSupers instSize |
|
3 i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 i16 i17 i18 |
|
4 i19 i20' |
|
5 classVariableNames:'OneInstance DummyClass' |
|
6 poolDictionaries:'' |
|
7 category:'Collections-Arrayed' |
|
8 ! |
|
9 |
|
10 |
|
11 !NamedArray class methodsFor:'initialization'! |
|
12 |
|
13 initialize |
|
14 OneInstance isNil ifTrue:[ |
|
15 OneInstance := self basicNew. |
|
16 |
|
17 DummyClass := Behavior shallowCopy. |
|
18 DummyClass flags:(Behavior flagBehavior bitOr:Behavior flagPointers). |
|
19 ]. |
|
20 |
|
21 " |
|
22 OneInstance := nil |
|
23 self initialize |
|
24 " |
|
25 |
|
26 ! ! |
|
27 |
|
28 !NamedArray class methodsFor:'instance creation'! |
|
29 |
|
30 newWith:names |
|
31 ^ self newWith:names values:nil |
|
32 |
|
33 " |
|
34 NamedArray newWith:#(foo bar) |
|
35 " |
|
36 |
|
37 "Created: 13.5.1996 / 20:03:42 / cg" |
|
38 "Modified: 13.5.1996 / 20:55:21 / cg" |
|
39 ! |
|
40 |
|
41 newWith:names values:values |
|
42 |cls arr sels mthds dummyClass| |
|
43 |
|
44 sels := names collect:[:nm | nm asSymbol]. |
|
45 sels := sels , (names collect:[:nm | (nm , ':') asSymbol]). |
|
46 sels := sels , #(#doesNotUnderstand: #class #at: #at:put: #basicAt: #basicAt:put:). |
|
47 |
|
48 mthds := (1 to:names size) |
|
49 collect:[:i | (self compiledMethodAt:('i',i printString)asSymbol)]. |
|
50 mthds := mthds , |
|
51 ( (1 to:names size) |
|
52 collect:[:i | (self compiledMethodAt:('i',i printString,':')asSymbol)]). |
|
53 |
|
54 mthds := mthds , (Array |
|
55 with:(self compiledMethodAt:#doesNotUnderstand:) |
|
56 with:(Object compiledMethodAt:#class) |
|
57 ) |
|
58 , (Array |
|
59 with:(Object compiledMethodAt:#at:) |
|
60 with:(Object compiledMethodAt:#at:put:) |
|
61 with:(Object compiledMethodAt:#basicAt:) |
|
62 with:(Object compiledMethodAt:#basicAt:put:) |
|
63 ). |
|
64 |
|
65 arr := Array new:(names size + 6). |
|
66 arr at:1 put:nil. "/ superclass |
|
67 arr at:2 put:(Behavior flagBehavior bitOr:Behavior flagPointers). "/ flags |
|
68 arr at:3 put:sels asArray. "/ selectors |
|
69 arr at:4 put:mthds asArray. "/ methods |
|
70 arr at:5 put:nil. "/ other supers |
|
71 arr at:6 put:6. "/ instSize |
|
72 |
|
73 arr changeClassTo:DummyClass. |
|
74 arr changeClassTo:arr. |
|
75 |
|
76 values notNil ifTrue:[ |
|
77 values keysAndValuesDo:[:i :val | |
|
78 arr at:i put:val |
|
79 ] |
|
80 ]. |
|
81 |
|
82 ^ arr. |
|
83 |
|
84 " |
|
85 NamedArray newWith:#(foo bar) values:#('foo' 'bar') |
|
86 " |
|
87 |
|
88 "Created: 13.5.1996 / 20:03:42 / cg" |
|
89 "Modified: 13.5.1996 / 20:55:21 / cg" |
|
90 ! |
|
91 |
|
92 with:assoc |
|
93 ^ self newWith:(Array with:assoc key) values:(Array with:assoc value) |
|
94 |
|
95 " |
|
96 NamedArray with:#foo->'foo' |
|
97 " |
|
98 ! |
|
99 |
|
100 with:assoc1 with:assoc2 |
|
101 ^ self newWith:(Array with:assoc1 key |
|
102 with:assoc2 key) |
|
103 values:(Array with:assoc1 value |
|
104 with:assoc2 value) |
|
105 |
|
106 " |
|
107 NamedArray with:#foo->'foo' with:#bar->'bar' |
|
108 " |
|
109 ! |
|
110 |
|
111 with:assoc1 with:assoc2 with:assoc3 |
|
112 ^ self newWith:(Array with:assoc1 key |
|
113 with:assoc2 key |
|
114 with:assoc3 key) |
|
115 values:(Array with:assoc1 value |
|
116 with:assoc2 value |
|
117 with:assoc3 value) |
|
118 |
|
119 " |
|
120 NamedArray with:#foo->'foo' with:#bar->'bar' with:#baz->'baz' |
|
121 " |
|
122 ! |
|
123 |
|
124 with:assoc1 with:assoc2 with:assoc3 with:assoc4 |
|
125 ^ self newWith:(Array with:assoc1 key |
|
126 with:assoc2 key |
|
127 with:assoc3 key |
|
128 with:assoc4 key) |
|
129 values:(Array with:assoc1 value |
|
130 with:assoc2 value |
|
131 with:assoc3 value |
|
132 with:assoc4 value) |
|
133 |
|
134 " |
|
135 NamedArray with:#foo->'foo' with:#bar->'bar' with:#baz->'baz' with:#hello->'hello' |
|
136 " |
|
137 ! |
|
138 |
|
139 with:assoc1 with:assoc2 with:assoc3 with:assoc4 with:assoc5 |
|
140 ^ self newWith:(Array with:assoc1 key |
|
141 with:assoc2 key |
|
142 with:assoc3 key |
|
143 with:assoc4 key |
|
144 with:assoc5 key) |
|
145 values:(Array with:assoc1 value |
|
146 with:assoc2 value |
|
147 with:assoc3 value |
|
148 with:assoc4 value |
|
149 with:assoc5 value) |
|
150 |
|
151 " |
|
152 NamedArray with:#foo->'foo' with:#bar->'bar' with:#baz->'baz' with:#hello->'hello' with:#world->'world' |
|
153 " |
|
154 ! ! |
|
155 |
|
156 !NamedArray methodsFor:'accessing'! |
|
157 |
|
158 flags |
|
159 "return flags" |
|
160 |
|
161 ^ flags |
|
162 |
|
163 "Created: 13.5.1996 / 21:19:23 / cg" |
|
164 ! |
|
165 |
|
166 flags:something |
|
167 "set flags" |
|
168 |
|
169 flags := something. |
|
170 |
|
171 "Created: 13.5.1996 / 21:19:23 / cg" |
|
172 ! |
|
173 |
|
174 i1 |
|
175 "return i1" |
|
176 |
|
177 ^ i1 |
|
178 |
|
179 "Created: 13.5.1996 / 21:19:25 / cg" |
|
180 ! |
|
181 |
|
182 i10 |
|
183 "return i10" |
|
184 |
|
185 ^ i10 |
|
186 |
|
187 "Created: 13.5.1996 / 21:19:27 / cg" |
|
188 ! |
|
189 |
|
190 i10:something |
|
191 "set i10" |
|
192 |
|
193 i10 := something. |
|
194 |
|
195 "Created: 13.5.1996 / 21:19:27 / cg" |
|
196 ! |
|
197 |
|
198 i11 |
|
199 "return i11" |
|
200 |
|
201 ^ i11 |
|
202 |
|
203 "Created: 13.5.1996 / 21:19:27 / cg" |
|
204 ! |
|
205 |
|
206 i11:something |
|
207 "set i11" |
|
208 |
|
209 i11 := something. |
|
210 |
|
211 "Created: 13.5.1996 / 21:19:27 / cg" |
|
212 ! |
|
213 |
|
214 i12 |
|
215 "return i12" |
|
216 |
|
217 ^ i12 |
|
218 |
|
219 "Created: 13.5.1996 / 21:19:27 / cg" |
|
220 ! |
|
221 |
|
222 i12:something |
|
223 "set i12" |
|
224 |
|
225 i12 := something. |
|
226 |
|
227 "Created: 13.5.1996 / 21:19:27 / cg" |
|
228 ! |
|
229 |
|
230 i13 |
|
231 "return i13" |
|
232 |
|
233 ^ i13 |
|
234 |
|
235 "Created: 13.5.1996 / 21:19:28 / cg" |
|
236 ! |
|
237 |
|
238 i13:something |
|
239 "set i13" |
|
240 |
|
241 i13 := something. |
|
242 |
|
243 "Created: 13.5.1996 / 21:19:28 / cg" |
|
244 ! |
|
245 |
|
246 i14 |
|
247 "return i14" |
|
248 |
|
249 ^ i14 |
|
250 |
|
251 "Created: 13.5.1996 / 21:19:28 / cg" |
|
252 ! |
|
253 |
|
254 i14:something |
|
255 "set i14" |
|
256 |
|
257 i14 := something. |
|
258 |
|
259 "Created: 13.5.1996 / 21:19:28 / cg" |
|
260 ! |
|
261 |
|
262 i15 |
|
263 "return i15" |
|
264 |
|
265 ^ i15 |
|
266 |
|
267 "Created: 13.5.1996 / 21:19:28 / cg" |
|
268 ! |
|
269 |
|
270 i15:something |
|
271 "set i15" |
|
272 |
|
273 i15 := something. |
|
274 |
|
275 "Created: 13.5.1996 / 21:19:28 / cg" |
|
276 ! |
|
277 |
|
278 i16 |
|
279 "return i16" |
|
280 |
|
281 ^ i16 |
|
282 |
|
283 "Created: 13.5.1996 / 21:19:28 / cg" |
|
284 ! |
|
285 |
|
286 i16:something |
|
287 "set i16" |
|
288 |
|
289 i16 := something. |
|
290 |
|
291 "Created: 13.5.1996 / 21:19:28 / cg" |
|
292 ! |
|
293 |
|
294 i17 |
|
295 "return i17" |
|
296 |
|
297 ^ i17 |
|
298 |
|
299 "Created: 13.5.1996 / 21:19:28 / cg" |
|
300 ! |
|
301 |
|
302 i17:something |
|
303 "set i17" |
|
304 |
|
305 i17 := something. |
|
306 |
|
307 "Created: 13.5.1996 / 21:19:29 / cg" |
|
308 ! |
|
309 |
|
310 i18 |
|
311 "return i18" |
|
312 |
|
313 ^ i18 |
|
314 |
|
315 "Created: 13.5.1996 / 21:19:29 / cg" |
|
316 ! |
|
317 |
|
318 i18:something |
|
319 "set i18" |
|
320 |
|
321 i18 := something. |
|
322 |
|
323 "Created: 13.5.1996 / 21:19:29 / cg" |
|
324 ! |
|
325 |
|
326 i19 |
|
327 "return i19" |
|
328 |
|
329 ^ i19 |
|
330 |
|
331 "Created: 13.5.1996 / 21:19:29 / cg" |
|
332 ! |
|
333 |
|
334 i19:something |
|
335 "set i19" |
|
336 |
|
337 i19 := something. |
|
338 |
|
339 "Created: 13.5.1996 / 21:19:29 / cg" |
|
340 ! |
|
341 |
|
342 i1:something |
|
343 "set i1" |
|
344 |
|
345 i1 := something. |
|
346 |
|
347 "Created: 13.5.1996 / 21:19:25 / cg" |
|
348 ! |
|
349 |
|
350 i2 |
|
351 "return i2" |
|
352 |
|
353 ^ i2 |
|
354 |
|
355 "Created: 13.5.1996 / 21:19:25 / cg" |
|
356 ! |
|
357 |
|
358 i20 |
|
359 "return i20" |
|
360 |
|
361 ^ i20 |
|
362 |
|
363 "Created: 13.5.1996 / 21:19:29 / cg" |
|
364 ! |
|
365 |
|
366 i20:something |
|
367 "set i20" |
|
368 |
|
369 i20 := something. |
|
370 |
|
371 "Created: 13.5.1996 / 21:19:29 / cg" |
|
372 ! |
|
373 |
|
374 i2:something |
|
375 "set i2" |
|
376 |
|
377 i2 := something. |
|
378 |
|
379 "Created: 13.5.1996 / 21:19:25 / cg" |
|
380 ! |
|
381 |
|
382 i3 |
|
383 "return i3" |
|
384 |
|
385 ^ i3 |
|
386 |
|
387 "Created: 13.5.1996 / 21:19:25 / cg" |
|
388 ! |
|
389 |
|
390 i3:something |
|
391 "set i3" |
|
392 |
|
393 i3 := something. |
|
394 |
|
395 "Created: 13.5.1996 / 21:19:25 / cg" |
|
396 ! |
|
397 |
|
398 i4 |
|
399 "return i4" |
|
400 |
|
401 ^ i4 |
|
402 |
|
403 "Created: 13.5.1996 / 21:19:25 / cg" |
|
404 ! |
|
405 |
|
406 i4:something |
|
407 "set i4" |
|
408 |
|
409 i4 := something. |
|
410 |
|
411 "Created: 13.5.1996 / 21:19:25 / cg" |
|
412 ! |
|
413 |
|
414 i5 |
|
415 "return i5" |
|
416 |
|
417 ^ i5 |
|
418 |
|
419 "Created: 13.5.1996 / 21:19:26 / cg" |
|
420 ! |
|
421 |
|
422 i5:something |
|
423 "set i5" |
|
424 |
|
425 i5 := something. |
|
426 |
|
427 "Created: 13.5.1996 / 21:19:26 / cg" |
|
428 ! |
|
429 |
|
430 i6 |
|
431 "return i6" |
|
432 |
|
433 ^ i6 |
|
434 |
|
435 "Created: 13.5.1996 / 21:19:26 / cg" |
|
436 ! |
|
437 |
|
438 i6:something |
|
439 "set i6" |
|
440 |
|
441 i6 := something. |
|
442 |
|
443 "Created: 13.5.1996 / 21:19:26 / cg" |
|
444 ! |
|
445 |
|
446 i7 |
|
447 "return i7" |
|
448 |
|
449 ^ i7 |
|
450 |
|
451 "Created: 13.5.1996 / 21:19:26 / cg" |
|
452 ! |
|
453 |
|
454 i7:something |
|
455 "set i7" |
|
456 |
|
457 i7 := something. |
|
458 |
|
459 "Created: 13.5.1996 / 21:19:26 / cg" |
|
460 ! |
|
461 |
|
462 i8 |
|
463 "return i8" |
|
464 |
|
465 ^ i8 |
|
466 |
|
467 "Created: 13.5.1996 / 21:19:26 / cg" |
|
468 ! |
|
469 |
|
470 i8:something |
|
471 "set i8" |
|
472 |
|
473 i8 := something. |
|
474 |
|
475 "Created: 13.5.1996 / 21:19:26 / cg" |
|
476 ! |
|
477 |
|
478 i9 |
|
479 "return i9" |
|
480 |
|
481 ^ i9 |
|
482 |
|
483 "Created: 13.5.1996 / 21:19:26 / cg" |
|
484 ! |
|
485 |
|
486 i9:something |
|
487 "set i9" |
|
488 |
|
489 i9 := something. |
|
490 |
|
491 "Created: 13.5.1996 / 21:19:27 / cg" |
|
492 ! |
|
493 |
|
494 instSize |
|
495 "return instSize" |
|
496 |
|
497 ^ instSize |
|
498 |
|
499 "Created: 13.5.1996 / 21:19:24 / cg" |
|
500 ! |
|
501 |
|
502 instSize:something |
|
503 "set instSize" |
|
504 |
|
505 instSize := something. |
|
506 |
|
507 "Created: 13.5.1996 / 21:19:25 / cg" |
|
508 ! |
|
509 |
|
510 methodArray |
|
511 "return methodArray" |
|
512 |
|
513 ^ methodArray |
|
514 |
|
515 "Created: 13.5.1996 / 21:19:24 / cg" |
|
516 ! |
|
517 |
|
518 methodArray:something |
|
519 "set methodArray" |
|
520 |
|
521 methodArray := something. |
|
522 |
|
523 "Created: 13.5.1996 / 21:19:24 / cg" |
|
524 ! |
|
525 |
|
526 otherSupers |
|
527 "return otherSupers" |
|
528 |
|
529 ^ otherSupers |
|
530 |
|
531 "Created: 13.5.1996 / 21:19:24 / cg" |
|
532 ! |
|
533 |
|
534 otherSupers:something |
|
535 "set otherSupers" |
|
536 |
|
537 otherSupers := something. |
|
538 |
|
539 "Created: 13.5.1996 / 21:19:24 / cg" |
|
540 ! |
|
541 |
|
542 selectorArray |
|
543 "return selectorArray" |
|
544 |
|
545 ^ selectorArray |
|
546 |
|
547 "Created: 13.5.1996 / 21:19:24 / cg" |
|
548 ! |
|
549 |
|
550 selectorArray:something |
|
551 "set selectorArray" |
|
552 |
|
553 selectorArray := something. |
|
554 |
|
555 "Created: 13.5.1996 / 21:19:24 / cg" |
|
556 ! |
|
557 |
|
558 superclass |
|
559 "return superclass" |
|
560 |
|
561 ^ superclass |
|
562 |
|
563 "Created: 13.5.1996 / 21:19:23 / cg" |
|
564 ! |
|
565 |
|
566 superclass:something |
|
567 "set superclass" |
|
568 |
|
569 superclass := something. |
|
570 |
|
571 "Created: 13.5.1996 / 21:19:23 / cg" |
|
572 ! ! |
|
573 |
|
574 !NamedArray methodsFor:'stubs'! |
|
575 |
|
576 doesNotUnderstand:aMessage |
|
577 |sel args names sz s| |
|
578 |
|
579 "/ instance protocol |
|
580 |
|
581 sel := aMessage selector. |
|
582 args := aMessage arguments. |
|
583 |
|
584 sel == #displayString ifTrue:[ |
|
585 ^ super displayString |
|
586 ]. |
|
587 |
|
588 sel == #printString ifTrue:[ |
|
589 ^ super printString |
|
590 ]. |
|
591 |
|
592 sel == #printOn: ifTrue:[ |
|
593 s := args at:1. |
|
594 s nextPutAll:'NamedArray('. |
|
595 names := self allInstVarNames. |
|
596 names keysAndValuesDo:[:idx :nm | |
|
597 s nextPutAll:nm; nextPutAll:'->'. |
|
598 s nextPutAll:(self at:idx) displayString. |
|
599 s space |
|
600 ]. |
|
601 s nextPutAll:')'. |
|
602 ^ self |
|
603 ]. |
|
604 |
|
605 sel == #basicInspect ifTrue:[ |
|
606 ^ InspectorView openOn:self |
|
607 ]. |
|
608 |
|
609 sel == #inspect ifTrue:[ |
|
610 ^ InspectorView openOn:self |
|
611 ]. |
|
612 |
|
613 sel == #instVarAt: ifTrue:[ |
|
614 |nr| |
|
615 |
|
616 nr := args at:1. |
|
617 nr == 1 ifTrue:[^ i1]. |
|
618 nr == 2 ifTrue:[^ i2]. |
|
619 nr == 3 ifTrue:[^ i3]. |
|
620 nr == 4 ifTrue:[^ i4]. |
|
621 nr == 5 ifTrue:[^ i5]. |
|
622 nr == 6 ifTrue:[^ i6]. |
|
623 ^ nil |
|
624 ]. |
|
625 |
|
626 (sel == #size |
|
627 or:[sel == #basicSize]) ifTrue:[ |
|
628 ^ super basicSize |
|
629 ]. |
|
630 |
|
631 (sel == #at: |
|
632 or:[sel == #basicAt:]) ifTrue:[ |
|
633 ^ super basicAt:(args at:1) |
|
634 ]. |
|
635 |
|
636 (sel == #at:put: |
|
637 or:[sel == #basicAt:put:]) ifTrue:[ |
|
638 ^ super basicAt:(args at:1) put:(args at:2) |
|
639 ]. |
|
640 |
|
641 sel == #== ifTrue:[ |
|
642 ^ self == (args at:1) |
|
643 ]. |
|
644 |
|
645 "/ class protocol |
|
646 |
|
647 (sel := aMessage selector) == #name ifTrue:[ |
|
648 ^ 'NamedArray' |
|
649 ]. |
|
650 |
|
651 sel == #instSize ifTrue:[ |
|
652 ^ instSize |
|
653 ]. |
|
654 |
|
655 sel == #isVariable ifTrue:[ |
|
656 ^ false |
|
657 ]. |
|
658 |
|
659 sel == #isClass ifTrue:[ |
|
660 ^ false |
|
661 ]. |
|
662 |
|
663 sel == #isMeta ifTrue:[ |
|
664 ^ false |
|
665 ]. |
|
666 |
|
667 sel == #isBehavior ifTrue:[ |
|
668 ^ false |
|
669 ]. |
|
670 |
|
671 sel == #respondsTo: ifTrue:[ |
|
672 (args at:1) printNL. |
|
673 ^ false |
|
674 ]. |
|
675 |
|
676 sel == #evaluatorClass ifTrue:[ |
|
677 ^ Compiler |
|
678 ]. |
|
679 |
|
680 sel == #classNameWithArticle ifTrue:[ |
|
681 ^ self displayString |
|
682 ]. |
|
683 |
|
684 sel == #allSubclasses ifTrue:[ |
|
685 ^ #() |
|
686 ]. |
|
687 |
|
688 sel == #allClassVarNames ifTrue:[ |
|
689 ^ #() |
|
690 ]. |
|
691 |
|
692 sel == #allInstVarNames ifTrue:[ |
|
693 sz := super basicSize. |
|
694 names := Array new:sz. |
|
695 |
|
696 selectorArray copy with:methodArray copy do:[:sel :mthd| |
|
697 |index| |
|
698 (sel endsWith:$:) ifFalse:[ |
|
699 (sel ~~ #class) ifTrue:[ |
|
700 "/ |
|
701 "/ which method is it ? |
|
702 "/ |
|
703 (1 to:20) do:[:i | |
|
704 |mysel| |
|
705 |
|
706 mysel := ('i' , i printString) asSymbol. |
|
707 mthd == (NamedArray compiledMethodAt:mysel) ifTrue:[ |
|
708 index := i |
|
709 ] |
|
710 ]. |
|
711 |
|
712 index isNil ifTrue:[ |
|
713 'oops' printNL. |
|
714 ^ nil |
|
715 ]. |
|
716 |
|
717 names at:index put:sel. |
|
718 ] |
|
719 ] |
|
720 ]. |
|
721 "/ must now sort by index ... |
|
722 |
|
723 ^ names |
|
724 ]. |
|
725 |
|
726 aMessage printNL. |
|
727 'args ' print. args printNL. |
|
728 |
|
729 ^ nil. |
|
730 |
|
731 "Created: 13.5.1996 / 20:22:22 / cg" |
|
732 "Modified: 13.5.1996 / 21:12:54 / cg" |
|
733 ! ! |
|
734 |
|
735 !NamedArray class methodsFor:'documentation'! |
|
736 |
|
737 version |
|
738 ^ '$Header: /cvs/stx/stx/libcomp/Attic/NamedArray.st,v 1.2 1996-05-24 14:30:58 ca Exp $' |
|
739 ! ! |
|
740 NamedArray initialize! |
|