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