author | Claus Gittinger <cg@exept.de> |
Mon, 16 Dec 2019 11:42:04 +0100 | |
changeset 25127 | 22ff3c08a076 |
parent 13409 | 5353fa4f93f0 |
permissions | -rw-r--r-- |
12843 | 1 |
"{ Package: 'stx:libbasic' }" |
2 |
||
3 |
Object subclass:#PrototypeLookupAlgorithm |
|
4 |
instanceVariableNames:'' |
|
5 |
classVariableNames:'TheOneAndOnlyInstance' |
|
6 |
poolDictionaries:'' |
|
13408 | 7 |
category:'Kernel-Extensions' |
12843 | 8 |
! |
9 |
||
10 |
!PrototypeLookupAlgorithm class methodsFor:'documentation'! |
|
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
this is a dummy lookupAlgorithm class to demonstrate the meta-object-protoocol support. |
|
15 |
Create a sumclass of me, redefine the lookupmethod to return a method proper. |
|
16 |
If it returns nil, a doesNotUnderstand will be sent, as usual. |
|
17 |
||
18 |
This class does nothing real - it duplicates the algorithm as found in the VM. |
|
19 |
||
13409 | 20 |
obsoleted by Lookup |
21 |
||
12843 | 22 |
[author:] |
23 |
cg (cg@CG-PC) |
|
24 |
||
25 |
[see also:] |
|
26 |
jan Vrany's paper on Smalltalk's Meta-Object-Protocol proposal. |
|
27 |
" |
|
12852 | 28 |
! |
29 |
||
30 |
examples |
|
31 |
" |
|
32 |
this is only a test for the lookup; when installed as a class's lookupObject, |
|
33 |
the lookup will be called from the VM for instances of that class. |
|
34 |
||
35 |
|mthd| |
|
36 |
||
37 |
mthd := self new |
|
38 |
lookupMethodForSelector:#squared |
|
39 |
directedTo:nil |
|
40 |
for:100 |
|
41 |
withArguments:nil |
|
42 |
from:nil. |
|
43 |
mthd valueWithReceiver:100 arguments:#(). |
|
44 |
" |
|
12843 | 45 |
! ! |
46 |
||
47 |
!PrototypeLookupAlgorithm class methodsFor:'instance creation'! |
|
48 |
||
49 |
new |
|
50 |
TheOneAndOnlyInstance isNil ifTrue: [ |
|
51 |
TheOneAndOnlyInstance := super new. |
|
52 |
]. |
|
53 |
^ TheOneAndOnlyInstance |
|
54 |
! ! |
|
55 |
||
56 |
!PrototypeLookupAlgorithm methodsFor:'lookup'! |
|
57 |
||
12851
f533e90633a1
changed: #lookupMethodForSelector:directedTo:for:withArguments:from:
Claus Gittinger <cg@exept.de>
parents:
12843
diff
changeset
|
58 |
lookupMethodForSelector:aSelector directedTo:searchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext |
12843 | 59 |
"invoked by the VM to ask me for a method to call. |
60 |
The arguments are: the selector, receiver and arguments, |
|
61 |
the class to start the search in (for here-, super and directed sends) |
|
62 |
the sending context. |
|
63 |
||
64 |
The returned method object will be put into the inline- and polyCache |
|
65 |
at the call site; it might therefore be called more than once for the |
|
66 |
same receiver-class/selector combination (once for each call site). |
|
67 |
If I return nil, a doesNotUnderstand will be invoked." |
|
68 |
||
69 |
|cls md method| |
|
70 |
||
71 |
cls := searchClass. |
|
72 |
cls isNil ifTrue:[ cls := aReceiver class ]. |
|
73 |
[ cls notNil ] whileTrue:[ |
|
74 |
md := cls methodDictionary. |
|
75 |
method := md at:aSelector ifAbsent:nil. |
|
76 |
method notNil ifTrue:[^ method ]. |
|
77 |
cls := cls superclass. |
|
78 |
]. |
|
79 |
^ nil |
|
80 |
! ! |
|
81 |
||
82 |
!PrototypeLookupAlgorithm class methodsFor:'documentation'! |
|
83 |
||
84 |
version_CVS |
|
13409 | 85 |
^ '$Header: /cvs/stx/stx/libbasic/PrototypeLookupAlgorithm.st,v 1.5 2011-06-28 11:58:00 cg Exp $' |
12843 | 86 |
! ! |