author | Claus Gittinger <cg@exept.de> |
Fri, 28 Jun 2019 08:49:56 +0200 | |
changeset 24385 | dd84e4dfb5cc |
parent 21101 | 3311b5c4d2eb |
child 21242 | 19fabe339f8b |
permissions | -rw-r--r-- |
13401 | 1 |
" |
13405 | 2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
3 |
All Rights Reserved |
13401 | 4 |
|
13405 | 5 |
Permission is hereby granted, free of charge, to any person |
6 |
obtaining a copy of this software and associated documentation |
|
7 |
files (the 'Software'), to deal in the Software without |
|
8 |
restriction, including without limitation the rights to use, |
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10 |
copies of the Software, and to permit persons to whom the |
|
11 |
Software is furnished to do so, subject to the following |
|
12 |
conditions: |
|
13 |
||
14 |
The above copyright notice and this permission notice shall be |
|
15 |
included in all copies or substantial portions of the Software. |
|
16 |
||
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
24 |
OTHER DEALINGS IN THE SOFTWARE. |
|
13401 | 25 |
" |
26 |
"{ Package: 'stx:libbasic' }" |
|
27 |
||
18373 | 28 |
"{ NameSpace: Smalltalk }" |
29 |
||
13401 | 30 |
Object subclass:#Lookup |
31 |
instanceVariableNames:'' |
|
32 |
classVariableNames:'' |
|
33 |
poolDictionaries:'' |
|
13405 | 34 |
category:'Kernel-Extensions' |
13401 | 35 |
! |
36 |
||
37 |
!Lookup class methodsFor:'documentation'! |
|
38 |
||
39 |
copyright |
|
40 |
" |
|
13405 | 41 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague |
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
42 |
All Rights Reserved |
13401 | 43 |
|
13405 | 44 |
Permission is hereby granted, free of charge, to any person |
45 |
obtaining a copy of this software and associated documentation |
|
46 |
files (the 'Software'), to deal in the Software without |
|
47 |
restriction, including without limitation the rights to use, |
|
48 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
49 |
copies of the Software, and to permit persons to whom the |
|
50 |
Software is furnished to do so, subject to the following |
|
51 |
conditions: |
|
52 |
||
53 |
The above copyright notice and this permission notice shall be |
|
54 |
included in all copies or substantial portions of the Software. |
|
55 |
||
56 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
57 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
58 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
59 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
60 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
61 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
62 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
63 |
OTHER DEALINGS IN THE SOFTWARE. |
|
13401 | 64 |
" |
65 |
! ! |
|
66 |
||
67 |
!Lookup class methodsFor:'initialization'! |
|
68 |
||
69 |
initialize |
|
18373 | 70 |
"/ do we really need this? |
71 |
"/ i.e. my own messages can be resolved by the VM - can't they ? |
|
72 |
||
73 |
"/ self lookupObject: Lookup builtin |
|
13401 | 74 |
|
75 |
"Created: / 26-04-2010 / 21:15:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
76 |
! ! |
|
77 |
||
78 |
!Lookup class methodsFor:'accessing'! |
|
79 |
||
80 |
builtin |
|
81 |
^BuiltinLookup instance |
|
82 |
||
83 |
"Created: / 26-04-2010 / 19:26:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
84 |
! ! |
|
85 |
||
86 |
!Lookup methodsFor:'lookup'! |
|
87 |
||
88 |
lookupMethodForSelector: selector directedTo: initialSearchClass |
|
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
89 |
|cls md method| |
13401 | 90 |
|
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
91 |
"Following C code is just a performance optimization. |
21101 | 92 |
It is not necessary, however it speeds up UI code, |
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
93 |
since it heavily uses perform:" |
13401 | 94 |
%{ |
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
95 |
RETURN ( __lookup(initialSearchClass, selector) ); |
13401 | 96 |
%}. |
97 |
||
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
98 |
cls := initialSearchClass. |
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
99 |
[ cls notNil ] whileTrue:[ |
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
100 |
md := cls methodDictionary. |
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
101 |
method := md at:selector ifAbsent:nil. |
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
102 |
method notNil ifTrue:[^ method ]. |
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
103 |
cls := cls superclass. |
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
104 |
]. |
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
105 |
^ nil |
13401 | 106 |
|
107 |
"Created: / 27-04-2010 / 15:30:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
108 |
! |
|
109 |
||
110 |
lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext |
|
15957 | 111 |
<resource: #obsolete> |
112 |
||
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
113 |
" |
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
114 |
This method is no longer sent by the VM as it nows pass |
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
115 |
inline/poly cache object. |
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
116 |
" |
15957 | 117 |
|
13401 | 118 |
"invoked by the VM to ask me for a method to call. |
119 |
The arguments are: the selector, receiver and arguments, |
|
120 |
the class to start the search in (for here-, super and directed sends) |
|
121 |
the sending context. |
|
122 |
||
123 |
The returned method object will be put into the inline- and polyCache |
|
124 |
at the call site; it might therefore be called more than once for the |
|
125 |
same receiver-class/selector combination (once for each call site). |
|
126 |
If I return nil, a doesNotUnderstand will be invoked." |
|
127 |
||
128 |
|cls md method| |
|
129 |
||
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
130 |
"Following C code is just a performance optimization. |
21101 | 131 |
It is not necessary, however it speeds up UI code, |
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
132 |
since it heavily uses perform:" |
13401 | 133 |
%{ |
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
134 |
RETURN ( __lookup(initialSearchClass, selector) ); |
13401 | 135 |
%}. |
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
136 |
^ self lookupMethodForSelector: selector |
21101 | 137 |
directedTo: initialSearchClass |
15957 | 138 |
! |
139 |
||
140 |
lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext ilc: ilcCache |
|
141 |
"Invoked by the VM to ask me for a method to call. |
|
142 |
The arguments are: the selector, receiver and arguments, |
|
143 |
the class to start the search in (for here-, super and directed sends) |
|
144 |
the sending context and the inline/poly cache (instance of |
|
18706 | 145 |
PolymorphicInlineCache). |
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
146 |
|
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
147 |
The returned method object will NOT be put into the inline- and |
18706 | 148 |
polyCache bu default. To update the call site's cache, you have to |
149 |
call ilcCache bindTo: method forClass: initialSearch class. If you |
|
20803 | 150 |
don't call it, inline/poly cache won't be updated and next call |
18706 | 151 |
won't be cached (therefore it will be relatively slow. |
15957 | 152 |
|
153 |
If I return nil, a doesNotUnderstand: will be send." |
|
154 |
||
155 |
| method | |
|
156 |
||
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
157 |
"Following C code is just a performance optimization. |
21101 | 158 |
It is not necessary, however it speeds up UI code, |
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
159 |
since it heavily uses perform:" |
15957 | 160 |
%{ |
161 |
method = __lookup(initialSearchClass, selector); |
|
162 |
if ( method ) { |
|
18706 | 163 |
__ilcBind(ilcCache, initialSearchClass, method, selector); |
15957 | 164 |
} |
165 |
RETURN (method); |
|
166 |
%}. |
|
167 |
||
168 |
method := self lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext. |
|
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
169 |
ilcCache notNil ifTrue:[ |
18706 | 170 |
ilcCache bindTo: method forClass: initialSearchClass. |
18365
806d5402c9c0
FIX: care for nil ilc passed to fallback code
Claus Gittinger <cg@exept.de>
parents:
15957
diff
changeset
|
171 |
]. |
15957 | 172 |
^ method. |
173 |
||
174 |
"Created: / 01-10-2011 / 13:18:40 / Jan Kurs <kursjan@fit.cvut.cz>" |
|
13401 | 175 |
! ! |
176 |
||
177 |
!Lookup class methodsFor:'documentation'! |
|
178 |
||
13405 | 179 |
version_CVS |
18706 | 180 |
^ '$Header$' |
13405 | 181 |
! |
182 |
||
13401 | 183 |
version_SVN |
18706 | 184 |
^ '$Id$' |
13401 | 185 |
! ! |
186 |
||
15957 | 187 |
|
13401 | 188 |
Lookup initialize! |