author | Claus Gittinger <cg@exept.de> |
Tue, 16 Jan 1996 20:11:19 +0100 | |
changeset 872 | af04035b443d |
parent 829 | fc386319f41c |
child 877 | 63ebb325ed20 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 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 |
||
253 | 13 |
CompiledCode subclass:#Method |
93 | 14 |
instanceVariableNames:'source sourcePosition category package' |
306 | 15 |
classVariableNames:'PrivateMethodSignal |
16 |
LastFileReference LastSourceFileName |
|
17 |
LastWhoClass' |
|
1 | 18 |
poolDictionaries:'' |
19 |
category:'Kernel-Methods' |
|
20 |
! |
|
21 |
||
42 | 22 |
!Method class methodsFor:'documentation'! |
23 |
||
88 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
159 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
version |
|
872 | 39 |
^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.66 1996-01-16 19:11:11 cg Exp $' |
88 | 40 |
! |
41 |
||
42 | 42 |
documentation |
43 |
" |
|
68 | 44 |
this class defines protocol for executable methods; |
45 |
both compiled and interpreted methods are represented by this class. |
|
46 |
Compiled methods have a non-nil code field, while interpreted methods have |
|
47 |
a nil code field and non-nil byteCode field. |
|
88 | 48 |
If there are both non-nil code and bytecode fields, the VM will execute |
227 | 49 |
the machine-code of a method. If both are nil when executed, a noByteCode |
50 |
message is sent by the VM to the method where a signal is raised. |
|
1 | 51 |
|
227 | 52 |
The methods sourcecode is represented by source and sourcePosition: |
53 |
- if sourcePosition is a Number, the source-field is the fileName and |
|
54 |
sourcePosition is the character offset of the source-chunk in this source file. |
|
55 |
- If sourcePosition is nil, the source is the string in the source field. |
|
56 |
(an old version used ExternalString instances here, but that lead to |
|
57 |
10000 additional little objects ...) |
|
1 | 58 |
|
68 | 59 |
The flags field defines things like the number of method-locals, |
227 | 60 |
method arguments and stack requirements (for interpreted methods). |
68 | 61 |
Do not depend on any value in the flags field - it may change without |
62 |
notice. |
|
1 | 63 |
|
438 | 64 |
Notice, that in ST/X, method can be subclassed; executable code is |
65 |
identified not by being a subclass of Block or Method, but instead by |
|
66 |
having the executable flag bit set in the class. The VM can execute anything |
|
67 |
which is identified as executable (assuming that the first instance variable |
|
68 |
is the machine-code address) - this allows for easy future extension. |
|
69 |
||
93 | 70 |
Instance variables: |
71 |
||
159 | 72 |
source <String> the source itself (if sourcePosition isNil) |
73 |
or the fileName where the source is found |
|
93 | 74 |
|
159 | 75 |
sourcePosition <Integer> the position of the methods chunk in the file |
93 | 76 |
|
159 | 77 |
category <Symbol> the methods category |
78 |
package <Symbol> the package, in which the methods was defined |
|
227 | 79 |
|
80 |
||
81 |
Class variables: |
|
82 |
||
83 |
PrivateMethodSignal raised on privacy violation (see docu) |
|
84 |
||
85 |
LastFileReference weak reference to the last sourceFile |
|
86 |
LastSourceFileName to speedup source access via NFS |
|
93 | 87 |
|
68 | 88 |
WARNING: layout known by compiler and runtime system - dont change |
42 | 89 |
" |
176 | 90 |
! |
91 |
||
92 |
privacy |
|
93 |
" |
|
94 |
ST/X includes an EXPERIMENTAL implementation of method privacy. |
|
95 |
Individual methods may be set to private or protected via the |
|
96 |
#setPrivate and #setProtected messages. Also, categories may be |
|
202 | 97 |
filedIn as a whole as private using #privateMethodsFor: or as |
98 |
protected using #protectedMethodsFor: instead of the well known #methodsFor:. |
|
99 |
||
176 | 100 |
The additional #publicMethodsFor: is for documentation purposes, and |
227 | 101 |
is equivalent to #methodsFor: (also to support fileIn of ENVY methods). |
176 | 102 |
|
103 |
Private methods may be executed only when called via a self or super-send |
|
104 |
from the superclass, the class itself or subclasses. |
|
415 | 105 |
Protected methods may not be called from subclasses, i.e. they may only |
106 |
be called via self sends from within the current class. |
|
107 |
(i.e. private methods are less private than protected ones) |
|
176 | 108 |
|
109 |
When such a situation arises, the VM (runtime system) will raise the |
|
110 |
PrivateMethodSignal exception (if nonNil), which usually brings you into the |
|
111 |
debugger. |
|
112 |
||
227 | 113 |
If PrivateMethodSignal is nil, the VM will not check for this, and |
176 | 114 |
execution is as usual. (you may want to nil-it for production code, |
115 |
and leave it non nil during development). |
|
116 |
||
117 |
NOTICE: there is no (not yet ?) standard defined for method privacy, |
|
118 |
however, the interface was designed to be somewhat ENVY compatible (from |
|
119 |
what can be deduced by reading PD code). |
|
120 |
Also, the usability of privacy is still to be tested. |
|
415 | 121 |
This interface, the implementation and the rules for when a privacy violation |
122 |
may change (in case of some ANSI standard being defined). |
|
227 | 123 |
Be warned and send me suggestions & critics (constructive ;-) |
176 | 124 |
" |
438 | 125 |
! |
126 |
||
127 |
dynamicMethods |
|
128 |
" |
|
129 |
On systems which support dynamic loading of machine code (SYS5.4, Linux), |
|
130 |
methods may now be compiled to machine code from within the browser, |
|
131 |
and the resulting machine code object be loaded in. |
|
132 |
The ObjectFileLoader keeps (weak) handles to the resulting methods and |
|
133 |
invalidates the corresponding method objects, if the underlying methods |
|
134 |
object code is unloaded. |
|
135 |
Invalid methods will trap into the debugger when executed; |
|
136 |
also, the browser marks them as '(* not executable *)' in its method list. |
|
137 |
" |
|
42 | 138 |
! ! |
1 | 139 |
|
109 | 140 |
!Method class methodsFor:'initialization'! |
141 |
||
142 |
initialize |
|
143 |
PrivateMethodSignal isNil ifTrue:[ |
|
159 | 144 |
"EXPERIMENTAL" |
145 |
PrivateMethodSignal := ExecutionErrorSignal newSignalMayProceed:true. |
|
146 |
PrivateMethodSignal nameClass:self message:#privateMethodSignal. |
|
176 | 147 |
PrivateMethodSignal notifierString:'attempt to execute private/protected method'. |
109 | 148 |
] |
149 |
! ! |
|
150 |
||
345 | 151 |
!Method class methodsFor:'Signal constants'! |
159 | 152 |
|
153 |
privateMethodSignal |
|
176 | 154 |
"return the signal raised when a private/protected method is called |
155 |
by some other object (i.e. not a self- or super send)" |
|
156 |
||
159 | 157 |
^ PrivateMethodSignal |
158 |
! ! |
|
159 |
||
3 | 160 |
!Method class methodsFor:'queries'! |
161 |
||
162 |
isBuiltInClass |
|
163 |
"this class is known by the run-time-system" |
|
164 |
||
165 |
^ self == Method |
|
44 | 166 |
! |
167 |
||
168 |
maxNumberOfArguments |
|
169 |
"this limit will be removed in one of the next versions ..." |
|
170 |
||
423 | 171 |
^ 15 "cannot be easily changed; should ask the VM about this number" |
747 | 172 |
! |
173 |
||
174 |
methodPrivacySupported |
|
175 |
"return true, if the system was compiled to support methodPrivacy. |
|
176 |
You should not depend on that feature being available." |
|
177 |
||
178 |
%{ /* NOCONTEXT */ |
|
179 |
#if defined(F_PRIVATE) || defined(F_CLASSPRIVATE) |
|
180 |
RETURN (true); |
|
181 |
#else |
|
182 |
RETURN (false); |
|
183 |
#endif |
|
184 |
%} |
|
3 | 185 |
! ! |
186 |
||
571 | 187 |
!Method methodsFor:'copying'! |
188 |
||
189 |
copy |
|
572 | 190 |
"redefined to change source ref into a real string" |
191 |
||
571 | 192 |
|aCopy| |
193 |
||
194 |
aCopy := super copy. |
|
195 |
sourcePosition notNil ifTrue:[ |
|
196 |
aCopy source:(self source) |
|
197 |
]. |
|
198 |
^ aCopy |
|
199 |
! ! |
|
200 |
||
259 | 201 |
!Method methodsFor:'queries'! |
202 |
||
203 |
isMethod |
|
204 |
"return true, if the receiver is some kind of method; |
|
205 |
true returned here - the method is redefined from Object." |
|
206 |
||
207 |
^ true |
|
423 | 208 |
! |
209 |
||
210 |
modificationTime |
|
211 |
"try to extract the modificationTime as a timeStamp from |
|
212 |
the receivers source. If there is no source or no history line, |
|
213 |
we do not know the modification time, and nil is returned." |
|
214 |
||
215 |
|s list histLine| |
|
216 |
||
217 |
HistoryManager isNil ifTrue:[^ nil]. |
|
218 |
s := self source. |
|
219 |
s isNil ifTrue:[^ nil]. |
|
220 |
list := HistoryManager getAllHistoriesFrom:s. |
|
221 |
list size == 0 ifTrue:[^ nil]. |
|
222 |
histLine := list last. |
|
223 |
^ AbsoluteTime date:histLine date time:histLine time |
|
224 |
||
225 |
" |
|
226 |
(Method compiledMethodAt:#modificationTime) modificationTime |
|
227 |
(Method compiledMethodAt:#isMethod) modificationTime |
|
228 |
" |
|
229 |
||
230 |
"Modified: 8.9.1995 / 15:08:22 / claus" |
|
259 | 231 |
! ! |
232 |
||
1 | 233 |
!Method methodsFor:'accessing'! |
234 |
||
235 |
source |
|
236 |
"return the sourcestring for the receiver" |
|
237 |
||
737
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
238 |
|aStream fileName junk w myClass mgr className| |
1 | 239 |
|
240 |
source notNil ifTrue:[ |
|
176 | 241 |
" |
242 |
if sourcePosition is nonNil, its the fileName and |
|
243 |
sourcePosition is the offset. |
|
244 |
Otherwise, source is the real source |
|
245 |
" |
|
159 | 246 |
sourcePosition isNil ifTrue:[^ source]. |
176 | 247 |
"/ |
625
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
248 |
"/ original (old) code: |
176 | 249 |
"/ |
250 |
"/ aStream := Smalltalk systemFileStreamFor:('source/' , source). |
|
251 |
"/ aStream notNil ifTrue:[ |
|
252 |
"/ aStream position:sourcePosition. |
|
253 |
"/ junk := aStream nextChunk. |
|
254 |
"/ aStream close |
|
255 |
"/ ] |
|
256 |
||
625
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
257 |
"/ keep the last source file open, because open/close |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
258 |
"/ operations maybe slow on NFS-mounted file systems. |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
259 |
"/ Since the reference to the file is weak, it will be closed |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
260 |
"/ automatically if the file is not referenced for a while. |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
261 |
"/ Neat trick. |
176 | 262 |
|
263 |
LastSourceFileName = source ifTrue:[ |
|
264 |
aStream := LastFileReference at:1. |
|
265 |
]. |
|
266 |
||
267 |
aStream isNil ifTrue:[ |
|
625
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
268 |
"/ |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
269 |
"/ if there is no SourceManager, look in standard places |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
270 |
"/ first |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
271 |
"/ |
690
b662a2173042
access SourceCodeManager via a class specific method
Claus Gittinger <cg@exept.de>
parents:
625
diff
changeset
|
272 |
(mgr := Smalltalk at:#SourceCodeManager) isNil ifTrue:[ |
625
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
273 |
fileName := Smalltalk getSourceFileName:source. |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
274 |
fileName notNil ifTrue:[ |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
275 |
aStream := fileName asFilename readStream. |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
276 |
]. |
192 | 277 |
]. |
443 | 278 |
aStream isNil ifTrue:[ |
625
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
279 |
"/ |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
280 |
"/ nope - ask my class for the source (this also invoces the SCMgr) |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
281 |
"/ |
486
1e19564b2b5e
prepare for CVS SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
282 |
w := self who. |
1e19564b2b5e
prepare for CVS SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
283 |
w notNil ifTrue:[ |
1e19564b2b5e
prepare for CVS SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
284 |
myClass := w at:1. |
522
198bf04a3aa4
moved source-file access code into class
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
285 |
aStream := myClass sourceStream. |
486
1e19564b2b5e
prepare for CVS SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
286 |
]. |
737
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
287 |
|
601
338404aae5ec
take local source file as last chance only (in case of a fileOut,
Claus Gittinger <cg@exept.de>
parents:
572
diff
changeset
|
288 |
aStream isNil ifTrue:[ |
737
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
289 |
"/ |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
290 |
"/ nope - look in standard places |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
291 |
"/ (if there is a source-code manager - otherwise, we already did that) |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
292 |
"/ |
690
b662a2173042
access SourceCodeManager via a class specific method
Claus Gittinger <cg@exept.de>
parents:
625
diff
changeset
|
293 |
mgr notNil ifTrue:[ |
625
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
294 |
fileName := Smalltalk getSourceFileName:source. |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
295 |
fileName notNil ifTrue:[ |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
296 |
aStream := fileName asFilename readStream. |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
297 |
] |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
298 |
]. |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
299 |
"/ |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
300 |
"/ final chance: try current directory |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
301 |
"/ |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
302 |
aStream isNil ifTrue:[ |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
303 |
aStream := source asFilename readStream. |
5f45ffc4cdd4
if a SourceCodeManager is available, ask that one FIRST for the source,
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
304 |
] |
601
338404aae5ec
take local source file as last chance only (in case of a fileOut,
Claus Gittinger <cg@exept.de>
parents:
572
diff
changeset
|
305 |
]. |
737
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
306 |
|
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
307 |
(aStream isNil and:[w isNil and:[source notNil]]) ifTrue:[ |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
308 |
"/ |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
309 |
"/ mhmh - seems to be a method which used to be in some |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
310 |
"/ class, but has been overwritten by another or removed. |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
311 |
"/ (i.e. it has no containing class anyMore) |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
312 |
"/ try to guess the class from the sourceFileName. |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
313 |
"/ and retry. |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
314 |
"/ |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
315 |
className := Smalltalk classNameForFile:source. |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
316 |
className knownAsSymbol ifTrue:[ |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
317 |
myClass := Smalltalk at:className asSymbol ifAbsent:nil. |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
318 |
myClass notNil ifTrue:[ |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
319 |
aStream := myClass sourceStream. |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
320 |
] |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
321 |
] |
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
322 |
] |
443 | 323 |
] |
176 | 324 |
]. |
325 |
||
159 | 326 |
aStream notNil ifTrue:[ |
327 |
aStream position:sourcePosition. |
|
328 |
junk := aStream nextChunk. |
|
176 | 329 |
|
330 |
" |
|
737
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
331 |
keep a weak reference - it may be needed again soon ... |
176 | 332 |
" |
333 |
LastFileReference isNil ifTrue:[ |
|
334 |
LastFileReference := WeakArray new:1 |
|
335 |
]. |
|
336 |
LastFileReference at:1 put:aStream. |
|
337 |
LastSourceFileName := source |
|
159 | 338 |
] |
1 | 339 |
]. |
340 |
^ junk |
|
486
1e19564b2b5e
prepare for CVS SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
463
diff
changeset
|
341 |
|
737
4ed893ad3f0f
try more to find source of obsolete methods
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
342 |
"Modified: 11.12.1995 / 14:53:40 / cg" |
1 | 343 |
! |
344 |
||
345 |
source:aString |
|
346 |
"set the methods sourcestring" |
|
347 |
||
348 |
source := aString. |
|
349 |
sourcePosition := nil |
|
350 |
! |
|
351 |
||
192 | 352 |
sourceFilename |
1 | 353 |
"return the sourcefilename if source is extern; nil otherwise" |
354 |
||
355 |
sourcePosition notNil ifTrue:[^ source]. |
|
356 |
^ nil |
|
357 |
! |
|
358 |
||
359 |
sourcePosition |
|
360 |
"return the sourceposition if source is extern; nil otherwise" |
|
361 |
||
362 |
^ sourcePosition |
|
363 |
! |
|
364 |
||
192 | 365 |
sourceFilename:aFileName position:aNumber |
1 | 366 |
"set the methods sourcefile/position" |
367 |
||
368 |
source := aFileName. |
|
369 |
sourcePosition := aNumber |
|
370 |
! |
|
371 |
||
39 | 372 |
comment |
373 |
"return the methods comment. |
|
68 | 374 |
This is done by searching for and returning the first comment |
159 | 375 |
from the methods source (excluding any double-quotes). |
68 | 376 |
Returns nil if there is no comment (or source is not available)." |
39 | 377 |
|
159 | 378 |
|src stream| |
39 | 379 |
|
159 | 380 |
src := self source. |
381 |
src isNil ifTrue:[^ nil]. |
|
93 | 382 |
|
159 | 383 |
stream := ReadStream on:src. |
384 |
(stream skipThrough:Character doubleQuote) isNil ifTrue:[^ nil]. |
|
385 |
^ stream upTo:Character doubleQuote. |
|
93 | 386 |
|
387 |
" |
|
159 | 388 |
(Method compiledMethodAt:#comment) comment |
93 | 389 |
" |
39 | 390 |
! |
391 |
||
1 | 392 |
category |
393 |
"return the methods category or nil" |
|
394 |
||
395 |
^ category |
|
396 |
! |
|
397 |
||
398 |
category:aStringOrSymbol |
|
399 |
"set the methods category" |
|
400 |
||
401 |
category := aStringOrSymbol asSymbol |
|
402 |
! |
|
403 |
||
93 | 404 |
package |
405 |
"return the package-symbol" |
|
406 |
||
407 |
^ package |
|
408 |
! |
|
409 |
||
227 | 410 |
package:aSymbol |
411 |
"set the package-symbol" |
|
412 |
||
413 |
package := aSymbol |
|
414 |
! |
|
415 |
||
1 | 416 |
flags |
44 | 417 |
"return the flags (number of method variables, stacksize etc.). |
418 |
Dont depend on the values in the flag field - it may change |
|
419 |
without notice." |
|
1 | 420 |
|
421 |
^ flags |
|
422 |
! |
|
423 |
||
424 |
flags:newFlags |
|
68 | 425 |
"set the flags (number of method variables, stacksize). |
426 |
WARNING: for internal use by the compiler only." |
|
1 | 427 |
|
56 | 428 |
"protect myself a bit - putting in an object would crash me ..." |
429 |
(newFlags isMemberOf:SmallInteger) ifTrue:[ |
|
159 | 430 |
flags := newFlags |
56 | 431 |
] |
1 | 432 |
! |
433 |
||
414 | 434 |
privacy |
435 |
"return a symbol describing the methods access rights (privacy); |
|
747 | 436 |
Currently, this is one of #private, #protected, #public or #ignored. |
437 |
||
414 | 438 |
Notice: method privacy is a nonstandard feature, not supported |
439 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
747 | 440 |
If at all, use it for debugging purposes, to catch messagesends |
441 |
which are not supposed to be sent by others. |
|
442 |
(especially, if working in a team, while integrating other peoples work) |
|
443 |
||
414 | 444 |
This is EXPERIMENTAL - and being evaluated for usability. |
445 |
It may change or even vanish (if it shows to be not useful)." |
|
446 |
||
447 |
self isPrivate ifTrue:[^ #private]. |
|
448 |
self isProtected ifTrue:[^ #protected]. |
|
747 | 449 |
self isIgnored ifTrue:[^ #ignored]. |
414 | 450 |
^ #public |
451 |
||
452 |
"Modified: 27.8.1995 / 22:53:31 / claus" |
|
453 |
! |
|
454 |
||
455 |
privacy:aSymbol |
|
456 |
"set the methods access rights (privacy) from a symbol; |
|
747 | 457 |
Currently, this must be one of #private, #protected, #public or #ignored. |
458 |
||
414 | 459 |
Notice: method privacy is a nonstandard feature, not supported |
460 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
747 | 461 |
If at all, use it for debugging purposes, to catch messagesends |
462 |
which are not supposed to be sent by others. |
|
463 |
(especially, if working in a team, while integrating other peoples work) |
|
464 |
||
414 | 465 |
This is EXPERIMENTAL - and being evaluated for usability. |
466 |
It may change or even vanish (if it shows to be not useful)." |
|
467 |
||
747 | 468 |
aSymbol == #public ifTrue:[ |
469 |
"/ |
|
470 |
"/ no need to flush, if changing from private to public |
|
471 |
"/ |
|
472 |
self isIgnored ifFalse:[ |
|
473 |
^ self setToPublic |
|
474 |
]. |
|
475 |
self setToPublic |
|
415 | 476 |
] ifFalse:[ |
872 | 477 |
aSymbol == #private ifTrue:[ |
747 | 478 |
self setToPrivate |
872 | 479 |
] ifFalse:[ |
747 | 480 |
aSymbol == #protected ifTrue:[ |
872 | 481 |
self setToProtected |
747 | 482 |
] ifFalse:[ |
872 | 483 |
aSymbol == #ignored ifTrue:[ |
747 | 484 |
self setToIgnored |
872 | 485 |
] |
747 | 486 |
] |
487 |
] |
|
415 | 488 |
]. |
489 |
ObjectMemory flushCaches. |
|
414 | 490 |
|
491 |
"Modified: 27.8.1995 / 22:58:08 / claus" |
|
492 |
! |
|
493 |
||
176 | 494 |
setToPrivate |
495 |
"set the flag bit stating that this method is private. |
|
496 |
Execution of the receiver will only be allowed for self/super-sends from |
|
497 |
the class, superclasses or subclasses (or via #perform). |
|
498 |
If a private method is called by some other class, a runtime |
|
499 |
error (PrivateMethodSignal) is raised. |
|
747 | 500 |
|
176 | 501 |
Notice: method privacy is a nonstandard feature, not supported |
502 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
747 | 503 |
If at all, use it for debugging purposes, to catch messagesends |
504 |
which are not supposed to be sent by others. |
|
505 |
(especially, if working in a team, while integrating other peoples work) |
|
506 |
||
176 | 507 |
This is EXPERIMENTAL - and being evaluated for usability. |
508 |
It may change or even vanish (if it shows to be not useful)." |
|
68 | 509 |
|
510 |
%{ /* NOCONTEXT */ |
|
176 | 511 |
/* I made this a primitive to get the define constant from stc.h */ |
512 |
||
748 | 513 |
#if defined(F_PRIVATE) && defined(M_PRIVACY) |
68 | 514 |
int f = _intVal(_INST(flags)); |
515 |
||
747 | 516 |
f = (f & ~M_PRIVACY) | F_PRIVATE; |
68 | 517 |
_INST(flags) = _MKSMALLINT(f); |
518 |
#endif |
|
519 |
%} |
|
520 |
! |
|
521 |
||
176 | 522 |
setToProtected |
523 |
"set the flag bit stating that this method is protected. |
|
524 |
Execution of the receiver will only be allowed for self sends from |
|
525 |
the class or superclasses. (or via #perform). |
|
526 |
If a private method is called by some other class, a runtime |
|
527 |
error (PrivateMethodSignal) is raised. |
|
747 | 528 |
|
176 | 529 |
Notice: method privacy is a nonstandard feature, not supported |
530 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
747 | 531 |
If at all, use it for debugging purposes, to catch messagesends |
532 |
which are not supposed to be sent by others. |
|
533 |
(especially, if working in a team, while integrating other peoples work) |
|
534 |
||
176 | 535 |
This is EXPERIMENTAL - and being evaluated for usability. |
536 |
It may change or even vanish (if it shows to be not useful)." |
|
537 |
||
538 |
%{ /* NOCONTEXT */ |
|
539 |
/* I made this a primitive to get the define constant from stc.h */ |
|
540 |
||
748 | 541 |
#if defined(F_CLASSPRIVATE) && defined(M_PRIVACY) |
176 | 542 |
int f = _intVal(_INST(flags)); |
543 |
||
747 | 544 |
f = (f & ~M_PRIVACY) | F_CLASSPRIVATE; |
176 | 545 |
_INST(flags) = _MKSMALLINT(f); |
546 |
#endif |
|
547 |
%} |
|
548 |
! |
|
549 |
||
550 |
setToPublic |
|
747 | 551 |
"clear any privacy/ignoreFlag of the receiver. |
552 |
The receiver may be executed by any send. |
|
553 |
This is the default anyway for methods, and how other smalltalk |
|
554 |
implementations treat all methods. |
|
555 |
||
360 | 556 |
Notice: method privacy is a nonstandard feature, not supported |
557 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
747 | 558 |
If at all, use it for debugging purposes, to catch messagesends |
559 |
which are not supposed to be sent by others. |
|
560 |
(especially, if working in a team, while integrating other peoples work) |
|
561 |
||
360 | 562 |
This is EXPERIMENTAL - and being evaluated for usability. |
563 |
It may change or even vanish (if it shows to be not useful)." |
|
68 | 564 |
|
565 |
%{ /* NOCONTEXT */ |
|
176 | 566 |
/* I made this a primitive to get the define constant from stc.h */ |
567 |
||
748 | 568 |
#ifdef M_PRIVACY |
68 | 569 |
int f = _intVal(_INST(flags)); |
570 |
||
747 | 571 |
f = f & ~M_PRIVACY; |
572 |
_INST(flags) = _MKSMALLINT(f); |
|
176 | 573 |
#endif |
747 | 574 |
%} |
575 |
! |
|
576 |
||
577 |
setToIgnored |
|
578 |
"make this method be ignored w.r.t. method lookup. |
|
579 |
(i.e. setting a method to #ignored, and sending that selector, |
|
580 |
leads to either the superclasses implementation to be called, |
|
581 |
or a doesNotUnderstand exception to be raised) |
|
582 |
||
583 |
Notice: ignored methods are a nonstandard feature, not supported |
|
584 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
585 |
||
586 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
587 |
It may change or even vanish (if it shows to be not useful)." |
|
588 |
||
589 |
%{ /* NOCONTEXT */ |
|
590 |
int f = _intVal(_INST(flags)); |
|
591 |
||
748 | 592 |
#if defined(F_IGNORED) && defined(M_PRIVACY) |
747 | 593 |
f = (f & ~M_PRIVACY) | F_IGNORED; |
176 | 594 |
#endif |
595 |
_INST(flags) = _MKSMALLINT(f); |
|
596 |
%} |
|
597 |
! |
|
598 |
||
599 |
isPrivate |
|
600 |
"return true, if this is a private method. |
|
601 |
Execution of private methods is only allowed via self/super sends |
|
602 |
from superclasses, the class itself or subclasses. |
|
603 |
If a private method is called by some other class, a runtime |
|
604 |
error (PrivateMethodSignal) is raised. |
|
605 |
Notice: method privacy is a nonstandard feature, not supported |
|
606 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
747 | 607 |
|
176 | 608 |
This is EXPERIMENTAL - and being evaluated for usability. |
609 |
It may change or even vanish (if it shows to be not useful)." |
|
610 |
||
611 |
%{ /* NOCONTEXT */ |
|
612 |
/* I made this a primitive to get the define constant from stc.h */ |
|
613 |
||
748 | 614 |
#if defined(F_PRIVATE) && defined(M_PRIVACY) |
176 | 615 |
int f = _intVal(_INST(flags)); |
616 |
||
747 | 617 |
if ((f & M_PRIVACY) == F_PRIVATE) { |
159 | 618 |
RETURN (true); |
68 | 619 |
} |
620 |
#endif |
|
621 |
%}. |
|
622 |
^ false |
|
623 |
! |
|
624 |
||
176 | 625 |
isProtected |
626 |
"return true, if this is a protected method. |
|
627 |
Execution of protected methods is only allowed via self sends |
|
628 |
from superclasses or the class itself. |
|
629 |
If a protected method is called by some other class, a runtime |
|
630 |
error (PrivateMethodSignal) is raised. |
|
747 | 631 |
|
176 | 632 |
Notice: method privacy is a nonstandard feature, not supported |
633 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
747 | 634 |
|
176 | 635 |
This is EXPERIMENTAL - and being evaluated for usability. |
636 |
It may change or even vanish (if it shows to be not useful)." |
|
637 |
||
638 |
%{ /* NOCONTEXT */ |
|
639 |
/* I made this a primitive to get the define constant from stc.h */ |
|
640 |
||
748 | 641 |
#if defined(F_CLASSPRIVATE) && defined(M_PRIVACY) |
176 | 642 |
int f = _intVal(_INST(flags)); |
643 |
||
747 | 644 |
if ((f & M_PRIVACY) == F_CLASSPRIVATE) { |
176 | 645 |
RETURN (true); |
646 |
} |
|
647 |
#endif |
|
648 |
%}. |
|
649 |
^ false |
|
650 |
! |
|
651 |
||
652 |
isPublic |
|
653 |
"return true, if this is a public method - I.e. can be executed via any send. |
|
747 | 654 |
This is the default and how other smalltalk implementations treat all methods. |
655 |
||
360 | 656 |
Notice: method privacy is a nonstandard feature, not supported |
657 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
747 | 658 |
|
360 | 659 |
This is EXPERIMENTAL - and being evaluated for usability. |
660 |
It may change or even vanish (if it shows to be not useful)." |
|
176 | 661 |
|
662 |
%{ /* NOCONTEXT */ |
|
663 |
/* I made this a primitive to get the define constant from stc.h */ |
|
664 |
||
748 | 665 |
#if defined(M_PRIVACY) && (defined(F_PRIVATE) || defined(F_CLASSPRIVATE) || defined(F_IGNORED)) |
747 | 666 |
|
176 | 667 |
int f = _intVal(_INST(flags)); |
747 | 668 |
# ifdef F_PRIVATE |
669 |
if ((f & M_PRIVACY) == F_PRIVATE) { |
|
176 | 670 |
RETURN (false); |
671 |
} |
|
747 | 672 |
# endif |
673 |
# ifdef F_CLASSPRIVATE |
|
674 |
if ((f & M_PRIVACY) == F_CLASSPRIVATE) { |
|
176 | 675 |
RETURN (false); |
676 |
} |
|
747 | 677 |
# endif |
678 |
# ifdef F_IGNORED |
|
679 |
if ((f & M_PRIVACY) == F_IGNORED) { |
|
680 |
RETURN (false); |
|
681 |
} |
|
682 |
# endif |
|
176 | 683 |
#endif |
684 |
%}. |
|
685 |
^ true |
|
686 |
! |
|
687 |
||
747 | 688 |
isIgnored |
689 |
"return true, if this is an ignored method. |
|
690 |
Ignored methods are physically present in the source file, |
|
691 |
but no code is generated for it by stc, and the VM does not see |
|
692 |
it in its message lookup. |
|
693 |
(i.e. setting a method to #ignored, and sending that selector, |
|
694 |
leads to either the superclasses implementation to be called, |
|
695 |
or a doesNotUnderstand exception to be raised) |
|
696 |
||
697 |
Notice: this is a nonstandard feature, not supported |
|
698 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
699 |
||
700 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
701 |
It may change or even vanish (if it shows to be not useful)." |
|
702 |
||
703 |
%{ /* NOCONTEXT */ |
|
748 | 704 |
#if defined(F_IGNORED) && defined(M_PRIVACY) |
747 | 705 |
int f = _intVal(_INST(flags)); |
706 |
||
707 |
if ((f & M_PRIVACY) == F_IGNORED) { |
|
872 | 708 |
RETURN (true); |
747 | 709 |
} |
710 |
#endif |
|
711 |
%}. |
|
712 |
^ false |
|
713 |
! |
|
714 |
||
715 |
isRestricted |
|
716 |
"return the flag bit stating that this method is restricted. |
|
717 |
Execution of the receiver will only be allowed if the system is not in |
|
718 |
'trap restricted mode' (-->ObjectMemory) otherise a runtime |
|
719 |
error (PrivateMethodSignal) is raised. |
|
720 |
||
721 |
Notice: method restriction is a nonstandard feature, not supported |
|
722 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
723 |
||
724 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
725 |
It may change or even vanish (if it shows to be not useful)." |
|
726 |
||
727 |
%{ /* NOCONTEXT */ |
|
728 |
#ifdef F_RESTRICTED |
|
729 |
int f = _intVal(_INST(flags)); |
|
730 |
||
731 |
if (f & F_RESTRICTED) { |
|
732 |
RETURN (true); |
|
733 |
} |
|
734 |
#endif |
|
735 |
%}. |
|
736 |
^ false |
|
737 |
! |
|
738 |
||
532
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
739 |
restricted:aBoolean |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
740 |
"set or clear the flag bit stating that this method is restricted. |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
741 |
Execution of the receiver will only be allowed if the system is not in |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
742 |
'trap restricted mode' (-->ObjectMemory) otherise a runtime |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
743 |
error (PrivateMethodSignal) is raised. |
747 | 744 |
|
532
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
745 |
Notice: method restriction is a nonstandard feature, not supported |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
746 |
by other smalltalk implementations and not specified in the ANSI spec. |
747 | 747 |
|
532
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
748 |
This is EXPERIMENTAL - and being evaluated for usability. |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
749 |
It may change or even vanish (if it shows to be not useful)." |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
750 |
|
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
751 |
%{ /* NOCONTEXT */ |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
752 |
/* I made this a primitive to get the define constant from stc.h */ |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
753 |
|
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
754 |
#ifdef F_RESTRICTED |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
755 |
int f = _intVal(_INST(flags)); |
747 | 756 |
int old; |
532
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
757 |
|
747 | 758 |
old = f; |
532
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
759 |
if (aBoolean == true) |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
760 |
f |= F_RESTRICTED; |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
761 |
else |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
762 |
f &= ~F_RESTRICTED; |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
763 |
_INST(flags) = _MKSMALLINT(f); |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
764 |
if (old & F_RESTRICTED) |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
765 |
RETURN(true); |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
766 |
#endif |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
767 |
%}. |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
768 |
^ false |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
769 |
|
747 | 770 |
" |
771 |
(ObjectMemory class compiledMethodAt:#compressingGarbageCollect) restricted:true |
|
772 |
" |
|
532
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
773 |
|
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
774 |
"Created: 7.11.1995 / 20:36:19 / stefan" |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
775 |
! |
2511c99de912
New code to trap restricted (RT) methods.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
776 |
|
44 | 777 |
numberOfMethodArgs:aNumber |
778 |
"currently, the number of arguments is NOT remembered in |
|
49 | 779 |
methods, but this will be added soon to allow for more checking |
780 |
in #perform:. |
|
781 |
||
44 | 782 |
The limitation in the max. number of arguments is due to the |
109 | 783 |
missing SENDxx functions in the VM and cases in #perform. This too |
784 |
will be removed in a later release, allowing any number of arguments. |
|
44 | 785 |
- for use by compiler only." |
786 |
||
56 | 787 |
(aNumber between:0 and:self class maxNumberOfArguments) ifFalse:[ |
159 | 788 |
self error:('ST/X only supports up to a maximum of ' , |
789 |
self class maxNumberOfArguments printString , |
|
790 |
' method arguments'). |
|
791 |
^ self |
|
56 | 792 |
]. |
793 |
%{ |
|
794 |
/* made this a primitive to get define in stc.h */ |
|
795 |
#ifdef F_NARGS |
|
796 |
_INST(flags) = _MKSMALLINT( (_intVal(_INST(flags)) & ~F_NARGS) | (_intVal(aNumber) << F_NARGSHIFT) ); |
|
797 |
#endif |
|
798 |
%} |
|
44 | 799 |
! |
800 |
||
49 | 801 |
numberOfMethodArgs |
802 |
"return the number of arguments, the method expects." |
|
803 |
||
56 | 804 |
%{ /* NOCONTEXT */ |
805 |
/* made this a primitive to get define in stc.h */ |
|
806 |
||
807 |
#ifdef F_NARGS |
|
808 |
RETURN (_MKSMALLINT((_intVal(_INST(flags)) & F_NARGS) >> F_NARGSHIFT)); |
|
809 |
#endif |
|
810 |
%} |
|
811 |
. |
|
49 | 812 |
" |
56 | 813 |
The old implementation simply counted the arguments from |
814 |
the methods source - new versions include this information |
|
109 | 815 |
in the flag instVar, for more security in #perform: |
68 | 816 |
" |
49 | 817 |
|
818 |
^ self methodArgNames size |
|
819 |
! |
|
820 |
||
1 | 821 |
numberOfMethodVars:aNumber |
56 | 822 |
"set the number of method variables - for use by compiler only. |
68 | 823 |
WARNING: playing around here with incorrect values |
159 | 824 |
may crash smalltalk badly." |
1 | 825 |
|
56 | 826 |
%{ /* NOCONTEXT */ |
827 |
int f = _intVal(_INST(flags)); |
|
1 | 828 |
|
829 |
/* made this a primitive to get define in stc.h */ |
|
253 | 830 |
if (__isSmallInteger(aNumber)) { |
159 | 831 |
f = (f & ~F_NVARS) | (_intVal(aNumber) << F_NVARSHIFT); |
832 |
_INST(flags) = _MKSMALLINT(f); |
|
56 | 833 |
} |
1 | 834 |
%} |
835 |
! |
|
836 |
||
49 | 837 |
numberOfMethodVars |
838 |
"return the number of method local variables. |
|
839 |
Do not depend on the returned value - future optimizations |
|
68 | 840 |
may change things here (i.e. when moving block-locals into |
841 |
surrounding method for inlining). |
|
49 | 842 |
- for debugging only." |
843 |
||
844 |
%{ /* NOCONTEXT */ |
|
845 |
/* made this a primitive to get define in stc.h */ |
|
846 |
||
56 | 847 |
RETURN (_MKSMALLINT((_intVal(_INST(flags)) & F_NVARS) >> F_NVARSHIFT)); |
49 | 848 |
%} |
849 |
! |
|
850 |
||
1 | 851 |
stackSize:aNumber |
56 | 852 |
"set the depth of the local stack - for use by compiler only. |
68 | 853 |
WARNING: playing around here with incorrect values |
159 | 854 |
may crash smalltalk badly. |
855 |
(if the runtime library was compiled with DEBUG, |
|
856 |
a bad stack will be detected and triggers an error)" |
|
1 | 857 |
|
56 | 858 |
%{ /* NOCONTEXT */ |
859 |
int f = _intVal(_INST(flags)); |
|
860 |
||
1 | 861 |
/* made this a primitive to get define in stc.h */ |
253 | 862 |
if (__isSmallInteger(aNumber)) { |
159 | 863 |
f = (f & ~F_NSTACK) | (_intVal(aNumber) << F_NSTACKSHIFT); |
864 |
_INST(flags) = _MKSMALLINT(f); |
|
56 | 865 |
} |
1 | 866 |
%} |
49 | 867 |
! |
868 |
||
869 |
stackSize |
|
870 |
"return the number of temporaries needed as stack in the context. |
|
871 |
Do not depend on the returned value - future optimizations |
|
872 |
may change things here. |
|
873 |
- for debugging only." |
|
874 |
||
875 |
%{ /* NOCONTEXT */ |
|
876 |
/* made this a primitive to get define in stc.h */ |
|
877 |
||
56 | 878 |
RETURN (_MKSMALLINT((_intVal(_INST(flags)) & F_NSTACK) >> F_NSTACKSHIFT)); |
49 | 879 |
%} |
1 | 880 |
! ! |
881 |
||
882 |
!Method methodsFor:'queries'! |
|
883 |
||
159 | 884 |
who |
885 |
"return the class and selector of where I am defined in. |
|
56 | 886 |
Since there is no information of the containing class |
159 | 887 |
in the method, we have to do a search here. |
68 | 888 |
|
889 |
Normally, this is not a problem, except when a method is |
|
159 | 890 |
accepted in the debugger or redefined from within a method |
891 |
(maybe done indirectly, if doIt is done recursively) |
|
892 |
- the information about which class the original method was |
|
893 |
defined in is lost in this case. |
|
68 | 894 |
|
306 | 895 |
Problem: this is heavily called for in the debugger to create |
896 |
a readable context walkback. For unbound methods, it is |
|
897 |
slow, since the search (over all classes) will always fail. |
|
898 |
Q: should we add a backref from the method to the class |
|
899 |
and/or add a subclass of Method for unbound ones ?" |
|
900 |
||
901 |
|classes cls sel| |
|
902 |
||
903 |
" |
|
904 |
very first, look in the class we found something the last time |
|
905 |
this may often give a hit, when asking who repeatingly for |
|
906 |
a context chain. (keep last by its name, to not keep classes from |
|
907 |
being garbage collected) |
|
908 |
" |
|
909 |
LastWhoClass notNil ifTrue:[ |
|
910 |
cls := Smalltalk at:LastWhoClass. |
|
308 | 911 |
cls notNil ifTrue:[ |
328 | 912 |
sel := cls selectorAtMethod:self. |
308 | 913 |
sel notNil ifTrue:[^ Array with:cls with:sel]. |
914 |
] |
|
306 | 915 |
]. |
1 | 916 |
|
159 | 917 |
" |
918 |
first, limit the search to global classes only - |
|
919 |
since probability is high, that the receiver is found in there ... |
|
920 |
" |
|
307 | 921 |
classes := Smalltalk allClasses. |
306 | 922 |
" |
923 |
instance methods are usually more common - search those first |
|
924 |
" |
|
925 |
classes do:[:aClass | |
|
159 | 926 |
|sel| |
927 |
||
328 | 928 |
sel := aClass selectorAtMethod:self. |
306 | 929 |
sel notNil ifTrue:[LastWhoClass := aClass name. |
930 |
^ Array with:aClass with:sel]. |
|
931 |
]. |
|
932 |
||
933 |
LastWhoClass := nil. |
|
934 |
classes do:[:aClass | |
|
935 |
|sel| |
|
936 |
||
328 | 937 |
sel := aClass class selectorAtMethod:self. |
159 | 938 |
sel notNil ifTrue:[^ Array with:aClass class with:sel]. |
1 | 939 |
]. |
77 | 940 |
" |
941 |
mhmh - must be a method of some anonymous class (i.e. one not |
|
227 | 942 |
in the Smalltalk dictionary). Search all instances of Behavior |
77 | 943 |
" |
328 | 944 |
Behavior allSubInstancesDo:[:someClass | |
159 | 945 |
|sel| |
946 |
||
328 | 947 |
sel := someClass selectorAtMethod:self. |
159 | 948 |
sel notNil ifTrue:[^ Array with:someClass with:sel] |
77 | 949 |
]. |
950 |
" |
|
951 |
none found - sorry |
|
952 |
" |
|
1 | 953 |
^ nil |
159 | 954 |
|
955 |
"typical situation: some well-known class" |
|
956 |
" |
|
957 |
|m| |
|
958 |
m := Object compiledMethodAt:#copy. |
|
959 |
m who |
|
960 |
" |
|
961 |
||
962 |
"untypical situation: an anonymous class" |
|
963 |
" |
|
964 |
|m cls| |
|
965 |
||
966 |
Object |
|
967 |
subclass:#FunnyClass |
|
968 |
instanceVariableNames:'foo' |
|
969 |
classVariableNames:'' |
|
970 |
poolDictionaries:'' |
|
971 |
category:'testing'. |
|
972 |
cls := Smalltalk at:#FunnyClass. |
|
973 |
Smalltalk removeClass:cls. |
|
974 |
||
975 |
cls compile:'testMethod1:arg foo:=arg'. |
|
976 |
cls compile:'testMethod2 ^ foo'. |
|
977 |
m := cls compiledMethodAt:#testMethod1:. |
|
978 |
||
979 |
m who |
|
980 |
" |
|
981 |
! |
|
982 |
||
983 |
containingClass |
|
984 |
"return the class I am defined in. |
|
985 |
See comment in who." |
|
986 |
||
987 |
"based on who, which has been added for ST-80 compatibility" |
|
988 |
||
989 |
|pair| |
|
990 |
||
991 |
pair := self who. |
|
992 |
pair notNil ifTrue:[^ pair at:1]. |
|
993 |
" |
|
994 |
none found - sorry |
|
995 |
" |
|
996 |
^ nil |
|
176 | 997 |
|
998 |
" |
|
999 |
|m| |
|
1000 |
m := Object compiledMethodAt:#at:. |
|
1001 |
m containingClass |
|
1002 |
" |
|
1003 |
! |
|
1004 |
||
1005 |
selector |
|
1006 |
"return the selector under which I am found in my containingClasses |
|
1007 |
method-table. |
|
1008 |
See comment in who." |
|
1009 |
||
1010 |
"based on who, which has been added for ST-80 compatibility" |
|
1011 |
||
1012 |
|pair| |
|
1013 |
||
1014 |
pair := self who. |
|
1015 |
pair notNil ifTrue:[^ pair at:2]. |
|
1016 |
" |
|
1017 |
none found - sorry |
|
1018 |
" |
|
1019 |
^ nil |
|
1020 |
||
1021 |
" |
|
1022 |
|m| |
|
1023 |
m := Object compiledMethodAt:#at:. |
|
1024 |
m selector |
|
1025 |
" |
|
1 | 1026 |
! |
1027 |
||
227 | 1028 |
parse:parseSelector return:accessSelector or:valueIfNoSource |
1029 |
"helper for methodArgNames, methodVarNames etc. |
|
1030 |
Get the source, let parser parse it using parseSelector, |
|
1031 |
return parser info using accessSelector" |
|
1 | 1032 |
|
1033 |
|parser sourceString| |
|
1034 |
||
1035 |
sourceString := self source. |
|
1036 |
sourceString notNil ifTrue:[ |
|
227 | 1037 |
parser := Parser perform:parseSelector with:sourceString. |
159 | 1038 |
(parser isNil or:[parser == #Error]) ifTrue:[^ nil]. |
227 | 1039 |
^ parser perform:accessSelector |
1 | 1040 |
]. |
227 | 1041 |
^ valueIfNoSource |
1042 |
! |
|
1043 |
||
1044 |
methodArgNames |
|
1045 |
"return a collection with the methods argument names. |
|
1046 |
Uses Parser to parse methods source and extract the names." |
|
1047 |
||
463
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1048 |
^ self parse:#'parseMethodSpecificationSilent:' return:#methodArgs or:nil |
1 | 1049 |
|
109 | 1050 |
" |
1051 |
(Method compiledMethodAt:#printOn:) methodArgNames |
|
1052 |
" |
|
463
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1053 |
|
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1054 |
"Modified: 31.10.1995 / 14:36:46 / cg" |
1 | 1055 |
! |
1056 |
||
1057 |
methodVarNames |
|
1058 |
"return a collection with the methods local-variable names. |
|
44 | 1059 |
Uses Parser to parse methods source and extract the names." |
1 | 1060 |
|
463
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1061 |
^ self parse:#'parseMethodArgAndVarSpecificationSilent:' return:#methodVars or:nil |
1 | 1062 |
|
109 | 1063 |
" |
1064 |
(Method compiledMethodAt:#printOn:) methodVarNames |
|
1065 |
" |
|
463
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1066 |
|
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1067 |
"Modified: 31.10.1995 / 14:36:49 / cg" |
1 | 1068 |
! |
1069 |
||
227 | 1070 |
hasPrimitiveCode |
1071 |
"return true, if the method contains primitive code; false if not. |
|
1072 |
Uses Parser to parse methods source and get the information." |
|
1073 |
||
463
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1074 |
|src| |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1075 |
|
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1076 |
src := self source. |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1077 |
src notNil ifTrue:[ |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1078 |
(src includesString:'%{' ) ifFalse:[ |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1079 |
"/ cannot contain primitive code. |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1080 |
^ false |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1081 |
] |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1082 |
]. |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1083 |
^ self parse:#'parseMethodSilent:' return:#hasPrimitiveCode or:false |
227 | 1084 |
|
1085 |
" |
|
1086 |
(Method compiledMethodAt:#hasPrimitiveCode) hasPrimitiveCode |
|
1087 |
(Object compiledMethodAt:#at:) hasPrimitiveCode |
|
1088 |
(Object compiledMethodAt:#basicAt:) hasPrimitiveCode |
|
1089 |
" |
|
463
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1090 |
|
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1091 |
"Modified: 31.10.1995 / 14:43:37 / cg" |
227 | 1092 |
! |
1093 |
||
1 | 1094 |
methodArgAndVarNames |
1095 |
"return a collection with the methods argument and variable names. |
|
463
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1096 |
Uses Parser to parse methods source and extract the names. |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1097 |
Returns nil if the source is not available, or some other |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1098 |
syntax/parse error occurred. For methods with no args and no vars, |
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1099 |
an empty collection is returned." |
1 | 1100 |
|
1101 |
|parser sourceString argNames varNames| |
|
1102 |
||
1103 |
sourceString := self source. |
|
1104 |
sourceString notNil ifTrue:[ |
|
463
447ead9f870c
be silent on transcript when parsing for args, vars and primitiveCode
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1105 |
parser := Parser parseMethodArgAndVarSpecificationSilent:sourceString. |
159 | 1106 |
(parser isNil or:[parser == #Error]) ifTrue:[^ nil]. |
1107 |
argNames := parser methodArgs. |
|
1108 |
varNames := parser methodVars. |
|
1109 |
argNames isNil ifTrue:[^ varNames]. |
|
1110 |
varNames isNil ifTrue:[^ argNames]. |
|
1111 |
^ (argNames , varNames) |
|
1 | 1112 |
]. |
1113 |
^ nil |
|
1114 |
||
109 | 1115 |
" |
1116 |
(Method compiledMethodAt:#printOn:) methodArgAndVarNames |
|
1117 |
" |
|
1 | 1118 |
! |
1119 |
||
1120 |
methodComment |
|
44 | 1121 |
"return the methods first comment, nil if there is none. |
1122 |
This is a somewhat stupid implementation." |
|
1 | 1123 |
|
1124 |
|text line nQuote index qIndex qIndex2 comment| |
|
1125 |
||
142 | 1126 |
text := self source asCollectionOfLines. |
1 | 1127 |
(text size < 2) ifTrue:[^nil]. |
1128 |
||
1129 |
line := (text at:2). |
|
1130 |
nQuote := line occurrencesOf:(Character doubleQuote). |
|
1131 |
(nQuote == 2) ifTrue:[ |
|
159 | 1132 |
qIndex := line indexOf:(Character doubleQuote). |
1133 |
qIndex2 := line indexOf:(Character doubleQuote) startingAt:(qIndex + 1). |
|
1134 |
^ line copyFrom:(qIndex + 1) to:(qIndex2 - 1) |
|
1 | 1135 |
]. |
1136 |
(nQuote == 1) ifTrue:[ |
|
159 | 1137 |
qIndex := line indexOf:(Character doubleQuote). |
1138 |
comment := line copyFrom:(qIndex + 1). |
|
1 | 1139 |
|
159 | 1140 |
index := 3. |
1141 |
line := text at:index. |
|
1142 |
nQuote := line occurrencesOf:(Character doubleQuote). |
|
1143 |
[nQuote ~~ 1] whileTrue:[ |
|
1144 |
comment := comment , Character cr asString , line withoutSpaces. |
|
1145 |
index := index + 1. |
|
1146 |
line := text at:index. |
|
1147 |
nQuote := line occurrencesOf:(Character doubleQuote) |
|
1148 |
]. |
|
1149 |
qIndex := line indexOf:(Character doubleQuote). |
|
1150 |
^ comment , Character cr asString , (line copyTo:(qIndex - 1)) withoutSpaces |
|
1 | 1151 |
]. |
1152 |
^ nil |
|
1153 |
||
109 | 1154 |
" |
1155 |
(Method compiledMethodAt:#methodComment) methodComment |
|
1156 |
" |
|
1 | 1157 |
! |
1158 |
||
1159 |
referencesGlobal:aGlobalSymbol |
|
1160 |
"return true, if this method references the global |
|
1161 |
bound to aGlobalSymbol." |
|
1162 |
||
1163 |
literals isNil ifTrue:[^ false]. |
|
1164 |
^ (literals identityIndexOf:aGlobalSymbol startingAt:1) ~~ 0 |
|
1165 |
! |
|
1166 |
||
1167 |
sends:aSelectorSymbol |
|
1168 |
"return true, if this method contains a message-send |
|
1169 |
with aSelectorSymbol as selector. |
|
1170 |
- due to the simple check in the literal array, also simple uses |
|
44 | 1171 |
of aSelectorSymbol as symbol will return true. |
1172 |
Should ask compiler, if there is really a send." |
|
1 | 1173 |
|
1174 |
^ self referencesGlobal:aSelectorSymbol |
|
77 | 1175 |
! |
1176 |
||
93 | 1177 |
isLazyMethod |
1178 |
"return true, if this is a lazy method. |
|
1179 |
False is returned here - this method is redefined in LazyMethod" |
|
1180 |
||
1181 |
^ false |
|
1182 |
! |
|
1183 |
||
77 | 1184 |
isWrapped |
93 | 1185 |
"return true, if this is a wrapper method. |
1186 |
False is returned here - this method is redefined in WrappedMethod" |
|
1187 |
||
77 | 1188 |
^ false |
93 | 1189 |
! |
1190 |
||
227 | 1191 |
wrapper |
1192 |
"only for wrapped methods: return the wrapper. |
|
1193 |
Thats the WrapperMethod which contains myself." |
|
1194 |
||
1195 |
WrappedMethod allInstancesDo:[:m | |
|
1196 |
m originalMethod == self ifTrue:[^ m]. |
|
1197 |
]. |
|
1198 |
^ nil |
|
1199 |
! |
|
1200 |
||
93 | 1201 |
isInvalid |
1202 |
"return true, if this method is not executable due to |
|
328 | 1203 |
a (re)-compilation error. (see comment in Method>>invalidCodeObject)" |
93 | 1204 |
|
1205 |
|m| |
|
1206 |
||
328 | 1207 |
m := Method compiledMethodAt:#invalidCodeObject. |
391 | 1208 |
self ~~ m ifTrue:[ |
1209 |
(self code notNil and:[self code = m code]) ifTrue:[^ true]. |
|
1210 |
(byteCode notNil and:[byteCode == m byteCode]) ifTrue:[^ true]. |
|
1211 |
]. |
|
362 | 1212 |
|
375 | 1213 |
m := Method compiledMethodAt:#uncompiledCodeObject. |
391 | 1214 |
self ~~ m ifTrue:[ |
1215 |
(self code notNil and:[self code = m code]) ifTrue:[^ true]. |
|
1216 |
(byteCode notNil and:[byteCode == m byteCode]) ifTrue:[^ true]. |
|
1217 |
]. |
|
362 | 1218 |
m := Metaclass compiledMethodAt:#invalidCodeObject. |
391 | 1219 |
self ~~ m ifTrue:[ |
1220 |
(self code notNil and:[self code = m code]) ifTrue:[^ true]. |
|
1221 |
(byteCode notNil and:[byteCode == m byteCode]) ifTrue:[^ true]. |
|
1222 |
]. |
|
93 | 1223 |
^ false |
1 | 1224 |
! ! |
1225 |
||
438 | 1226 |
!Method methodsFor:'trap methods'! |
1227 |
||
1228 |
makeInvalid |
|
1229 |
"make the receiver an invalid method, which raises an invalidCodeObject |
|
1230 |
signal when executed. This is not for public use - it is required for |
|
1231 |
the objectFileLoader to invalidate methods whose code is unloaded." |
|
1232 |
||
1233 |
|invldMethod| |
|
1234 |
||
1235 |
invldMethod := self class compiledMethodAt:#invalidCodeObject. |
|
1236 |
self code:invldMethod code. |
|
1237 |
self byteCode:invldMethod byteCode. |
|
1238 |
||
1239 |
"Created: 17.9.1995 / 15:00:52 / claus" |
|
1240 |
! |
|
1241 |
||
1242 |
makeUncompiled |
|
1243 |
"make the receiver an uncompiled method, which raises an invalidCodeObject |
|
1244 |
signal when executed. This is not for public use - it is required for |
|
1245 |
the compiler to invalidate methods which cannot be compiled due to errors |
|
1246 |
after a class definition change (for example: instvars are no longer there)." |
|
1247 |
||
1248 |
|invldMethod| |
|
1249 |
||
1250 |
invldMethod := self class compiledMethodAt:#uncompiledCodeObject. |
|
1251 |
self code:invldMethod code. |
|
1252 |
self byteCode:invldMethod byteCode. |
|
1253 |
||
1254 |
"Created: 17.9.1995 / 15:01:14 / claus" |
|
1255 |
! ! |
|
1256 |
||
1 | 1257 |
!Method methodsFor:'error handling'! |
1258 |
||
328 | 1259 |
invalidCodeObject |
93 | 1260 |
"this method is triggered by the interpreter when a nil or non method |
1261 |
is about to be executed. |
|
1262 |
In this case, the VM sends this to the bad method (the receiver). |
|
1263 |
||
1264 |
Also, the Compiler creates methods with their code/bytecode set to |
|
1265 |
this method if - after a class change - a method cannot be compiled |
|
1266 |
and is therefore no longer executable (for example, after an instvar |
|
68 | 1267 |
has been removed, and a method still tries to access this instvar) |
44 | 1268 |
|
93 | 1269 |
Thus, we arrive here, when playing around in a classes methodArray, |
1270 |
or compiler/runtime system is broken :-(, |
|
1271 |
or you ignore the error messages during some recompile." |
|
1 | 1272 |
|
142 | 1273 |
^ InvalidCodeSignal |
159 | 1274 |
raiseRequestWith:self |
1275 |
errorString:'invalid method - not executable'. |
|
1 | 1276 |
! |
1277 |
||
375 | 1278 |
uncompiledCodeObject |
1279 |
"this method is invoked by methods which contain primitive code, |
|
1280 |
but have not been compiled to machine code (either due to an error |
|
1281 |
when compiling, or simply because no stc is available. |
|
1282 |
For those methods, the compiler generated a method object consisting |
|
1283 |
of the original source code, but with this methods machine/byte code. |
|
1284 |
Therefore, we patch (kludge) the lineNumber information, to show the |
|
1285 |
first line (instead of the real line below)" |
|
1286 |
||
1287 |
thisContext setLineNumber:1. |
|
1288 |
^ InvalidCodeSignal |
|
1289 |
raiseRequestWith:self |
|
1290 |
errorString:'invalid method - not compiled'. |
|
1291 |
! |
|
1292 |
||
109 | 1293 |
wrongNumberOfArguments:numberGiven |
1294 |
"this error is triggered, if a method is called with a wrong number |
|
1295 |
of arguments. This only applies to #valueWithReceiverXXX - sends. |
|
1296 |
With a normal send, this error cannot happen." |
|
68 | 1297 |
|
142 | 1298 |
^ ArgumentSignal |
159 | 1299 |
raiseRequestWith:self |
1300 |
errorString:('method got ' , numberGiven printString , |
|
1301 |
' args while ' , self numberOfMethodArgs printString , ' where expected') |
|
68 | 1302 |
! |
1303 |
||
109 | 1304 |
privateMethodCalled |
176 | 1305 |
"this error is triggered, if a private or protected method is called from |
360 | 1306 |
outside. |
1307 |
If you continue in the debugger, the method will be called, |
|
415 | 1308 |
and further privacy exceptions will NOT be reported at this call location, |
360 | 1309 |
until any new method is compiled, or the privacy of any method changes, |
1310 |
or the caches are flushed. |
|
1311 |
(the reason is that after the continue, the method is enterred into the |
|
1312 |
calling cache, for which method privacy is not checked. |
|
1313 |
Any of the above actions flushes this cache and a privacy check |
|
1314 |
is performed again.) |
|
1315 |
Future versions may not enter private methods into the cache, to fix this |
|
1316 |
(unobvious) behavior. However, then you will get an exception for EVERY |
|
1317 |
call to a private method ... |
|
1318 |
||
1319 |
Notice: method privacy is a nonstandard feature, not supported |
|
1320 |
by other smalltalk implementations and not specified in the ANSI spec. |
|
1321 |
This is EXPERIMENTAL - and being evaluated for usability. |
|
1322 |
It may change or even vanish (if it shows to be not useful)." |
|
68 | 1323 |
|
142 | 1324 |
^ PrivateMethodSignal raise |
1 | 1325 |
! ! |
1326 |
||
1327 |
!Method methodsFor:'executing'! |
|
1328 |
||
1329 |
valueWithReceiver:anObject arguments:argArray |
|
2 | 1330 |
"low level call of a methods code - BIG DANGER ALERT. |
1331 |
Perform the receiver-method on anObject as receiver and argArray as |
|
1332 |
arguments. This does NO message lookup at all and mimics a |
|
1333 |
traditional function call. |
|
44 | 1334 |
This method is provided for debugging- and breakpoint-support |
68 | 1335 |
(replacing a method by a stub and recalling the original), or to implement |
1336 |
experimental MI implementations - it is not for general use. |
|
1337 |
||
1338 |
The receiver must be a method compiled in anObjects class or one of its |
|
1339 |
superclasses and also, the number of arguments given must match the methods |
|
1340 |
expectations - |
|
1341 |
- otherwise strange things (and also strange crashes) can occur. |
|
1342 |
The system is NOT always detecting a wrong method/receiver combination. |
|
77 | 1343 |
YOU HAVE BEEN WARNED." |
68 | 1344 |
|
77 | 1345 |
^ self valueWithReceiver:anObject arguments:argArray selector:nil search:nil |
68 | 1346 |
! |
1347 |
||
1348 |
valueWithReceiver:anObject arguments:argArray selector:aSymbol |
|
1349 |
"low level call of a methods code - BIG DANGER ALERT. |
|
1350 |
Perform the receiver-method on anObject as receiver and argArray as |
|
1351 |
arguments. This does NO message lookup at all and mimics a |
|
1352 |
traditional function call. |
|
1353 |
This method is provided for debugging- and breakpoint-support |
|
1354 |
(replacing a method by a stub and recalling the original), or to implement |
|
1355 |
experimental MI implementations - it is not for general use. |
|
1356 |
||
44 | 1357 |
The receiver must be a method compiled in anObjects class or one of its |
56 | 1358 |
superclasses and also, the number of arguments given must match the methods |
1359 |
expectations - |
|
44 | 1360 |
- otherwise strange things (and also strange crashes) can occur. |
1361 |
The system is NOT always detecting a wrong method/receiver combination. |
|
77 | 1362 |
YOU HAVE BEEN WARNED." |
1363 |
||
227 | 1364 |
^ self valueWithReceiver:anObject |
1365 |
arguments:argArray |
|
1366 |
selector:aSymbol |
|
1367 |
search:nil |
|
1368 |
sender:nil |
|
77 | 1369 |
! |
1370 |
||
1371 |
valueWithReceiver:anObject arguments:argArray selector:aSymbol search:aClass |
|
1372 |
"low level call of a methods code - BIG DANGER ALERT. |
|
1373 |
Perform the receiver-method on anObject as receiver and argArray as |
|
1374 |
arguments. This does NO message lookup at all and mimics a |
|
1375 |
traditional function call. |
|
1376 |
This method is provided for debugging- and breakpoint-support |
|
1377 |
(replacing a method by a stub and recalling the original), or to implement |
|
1378 |
experimental MI implementations - it is not for general use. |
|
1379 |
||
1380 |
The receiver must be a method compiled in anObjects class or one of its |
|
1381 |
superclasses and also, the number of arguments given must match the methods |
|
1382 |
expectations - |
|
1383 |
- otherwise strange things (and also strange crashes) can occur. |
|
1384 |
The system is NOT always detecting a wrong method/receiver combination. |
|
1385 |
YOU HAVE BEEN WARNED." |
|
1 | 1386 |
|
227 | 1387 |
^ self valueWithReceiver:anObject |
1388 |
arguments:argArray |
|
1389 |
selector:aSymbol |
|
1390 |
search:nil |
|
1391 |
sender:nil |
|
1392 |
! |
|
1393 |
||
1394 |
valueWithReceiver:anObject arguments:argArray selector:aSymbol search:aClass sender:virtualSender |
|
1395 |
"low level call of a methods code - BIG DANGER ALERT. |
|
1396 |
Perform the receiver-method on anObject as receiver and argArray as |
|
1397 |
arguments. This does NO message lookup at all and mimics a |
|
1398 |
traditional function call. |
|
1399 |
This method is provided for debugging- and breakpoint-support |
|
1400 |
(replacing a method by a stub and recalling the original), or to implement |
|
1401 |
experimental MI implementations - it is not for general use. |
|
1402 |
||
1403 |
The receiver must be a method compiled in anObjects class or one of its |
|
1404 |
superclasses and also, the number of arguments given must match the methods |
|
1405 |
expectations - |
|
1406 |
- otherwise strange things (and also strange crashes) can occur. |
|
1407 |
The system is NOT always detecting a wrong method/receiver combination. |
|
1408 |
YOU HAVE BEEN WARNED." |
|
1409 |
||
1 | 1410 |
%{ |
1411 |
OBJFUNC code; |
|
1412 |
OBJ searchClass; |
|
1413 |
static struct inlineCache dummy = _DUMMYILC0; |
|
2 | 1414 |
int nargs; |
1415 |
OBJ *ap; |
|
1416 |
||
56 | 1417 |
if (__isArray(argArray)) { |
159 | 1418 |
nargs = _arraySize(argArray); |
1419 |
ap = _ArrayInstPtr(argArray)->a_element; |
|
2 | 1420 |
} else { |
159 | 1421 |
if (argArray == nil) { |
1422 |
nargs = 0; |
|
1423 |
} else |
|
1424 |
nargs = -1; |
|
2 | 1425 |
} |
1 | 1426 |
|
109 | 1427 |
#ifdef F_NARGS |
1428 |
if (((_intVal(_INST(flags)) & F_NARGS) >> F_NARGSHIFT) == nargs) |
|
1429 |
#endif |
|
1430 |
{ |
|
159 | 1431 |
code = _MethodInstPtr(self)->m_code; |
1432 |
if (aClass == nil) { |
|
328 | 1433 |
searchClass = dummy.ilc_class = __Class(anObject); |
159 | 1434 |
} else { |
1435 |
searchClass = dummy.ilc_class = aClass; |
|
1436 |
} |
|
77 | 1437 |
|
227 | 1438 |
if (nargs <= 15) { |
1439 |
/* |
|
1440 |
* add virtual sender (unwinding) here later, |
|
1441 |
* to allow hiding contexts in lazy methods. |
|
328 | 1442 |
* (this is cosmetics only; therefore its done later) |
227 | 1443 |
*/ |
1444 |
if (code) { |
|
159 | 1445 |
/* compiled code */ |
1446 |
switch (nargs) { |
|
1447 |
case 0: |
|
1448 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy) ); |
|
68 | 1449 |
|
159 | 1450 |
case 1: |
1451 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, ap[0]) ); |
|
1 | 1452 |
|
159 | 1453 |
case 2: |
1454 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, ap[0], ap[1]) ); |
|
68 | 1455 |
|
159 | 1456 |
case 3: |
1457 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2]) ); |
|
1 | 1458 |
|
159 | 1459 |
case 4: |
1460 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1461 |
ap[0], ap[1], ap[2], ap[3]) ); |
|
68 | 1462 |
|
159 | 1463 |
case 5: |
1464 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1465 |
ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1 | 1466 |
|
159 | 1467 |
case 6: |
1468 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1469 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1 | 1470 |
|
159 | 1471 |
case 7: |
1472 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1473 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
68 | 1474 |
|
159 | 1475 |
case 8: |
1476 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1477 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1 | 1478 |
|
159 | 1479 |
case 9: |
1480 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1481 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1 | 1482 |
|
159 | 1483 |
case 10: |
1484 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1485 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], |
|
1486 |
ap[9]) ); |
|
68 | 1487 |
|
159 | 1488 |
case 11: |
1489 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1490 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], |
|
1491 |
ap[9], ap[10]) ); |
|
1 | 1492 |
|
159 | 1493 |
case 12: |
1494 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1495 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], |
|
1496 |
ap[9], ap[10], ap[11]) ); |
|
77 | 1497 |
|
159 | 1498 |
case 13: |
1499 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1500 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], |
|
1501 |
ap[9], ap[10], ap[11], ap[12]) ); |
|
77 | 1502 |
|
159 | 1503 |
case 14: |
1504 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1505 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], |
|
1506 |
ap[9], ap[10], ap[11], ap[12], ap[13]) ); |
|
77 | 1507 |
|
159 | 1508 |
case 15: |
1509 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, |
|
1510 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], |
|
1511 |
ap[9], ap[10], ap[11], ap[12], ap[13], ap[14]) ); |
|
1512 |
} |
|
227 | 1513 |
} else { |
159 | 1514 |
/* interpreted code */ |
328 | 1515 |
#ifdef PASS_ARG_POINTER |
1516 |
RETURN ( __interpret(self, nargs, anObject, aSymbol, SND_COMMA searchClass, ap) ); |
|
1517 |
#else |
|
159 | 1518 |
switch (nargs) { |
1519 |
case 0: |
|
1520 |
RETURN ( interpret(self, 0, anObject, aSymbol, SND_COMMA searchClass) ); |
|
68 | 1521 |
|
159 | 1522 |
case 1: |
1523 |
RETURN ( interpret(self, 1, anObject, aSymbol, SND_COMMA searchClass, |
|
1524 |
ap[0]) ); |
|
1 | 1525 |
|
159 | 1526 |
case 2: |
1527 |
RETURN ( interpret(self, 2, anObject, aSymbol, SND_COMMA searchClass, |
|
1528 |
ap[0], ap[1]) ); |
|
68 | 1529 |
|
159 | 1530 |
case 3: |
1531 |
RETURN ( interpret(self, 3, anObject, aSymbol, SND_COMMA searchClass, |
|
1532 |
ap[0], ap[1], ap[2]) ); |
|
1 | 1533 |
|
159 | 1534 |
case 4: |
1535 |
RETURN ( interpret(self, 4, anObject, aSymbol, SND_COMMA searchClass, |
|
1536 |
ap[0], ap[1], ap[2], ap[3]) ); |
|
68 | 1537 |
|
159 | 1538 |
case 5: |
1539 |
RETURN ( interpret(self, 5, anObject, aSymbol, SND_COMMA searchClass, |
|
1540 |
ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1 | 1541 |
|
159 | 1542 |
case 6: |
1543 |
RETURN ( interpret(self, 6, anObject, aSymbol, SND_COMMA searchClass, |
|
1544 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
68 | 1545 |
|
159 | 1546 |
case 7: |
1547 |
RETURN ( interpret(self, 7, anObject, aSymbol, SND_COMMA searchClass, |
|
1548 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
68 | 1549 |
|
159 | 1550 |
case 8: |
1551 |
RETURN ( interpret(self, 8, anObject, aSymbol, SND_COMMA searchClass, |
|
1552 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], |
|
1553 |
ap[7]) ); |
|
1 | 1554 |
|
159 | 1555 |
case 9: |
1556 |
RETURN ( interpret(self, 9, anObject, aSymbol, SND_COMMA searchClass, |
|
1557 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], |
|
1558 |
ap[7], ap[8]) ); |
|
68 | 1559 |
|
159 | 1560 |
case 10: |
1561 |
RETURN ( interpret(self, 10, anObject, aSymbol, SND_COMMA searchClass, |
|
1562 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], |
|
1563 |
ap[7], ap[8], ap[9]) ); |
|
1 | 1564 |
|
159 | 1565 |
case 11: |
1566 |
RETURN ( interpret(self, 11, anObject, aSymbol, SND_COMMA searchClass, |
|
1567 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], |
|
1568 |
ap[7], ap[8], ap[9], ap[10]) ); |
|
68 | 1569 |
|
159 | 1570 |
case 12: |
1571 |
RETURN ( interpret(self, 12, anObject, aSymbol, SND_COMMA searchClass, |
|
1572 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], |
|
1573 |
ap[7], ap[8], ap[9], ap[11]) ); |
|
77 | 1574 |
|
159 | 1575 |
case 13: |
1576 |
RETURN ( interpret(self, 13, anObject, aSymbol, SND_COMMA searchClass, |
|
1577 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], |
|
1578 |
ap[7], ap[8], ap[9], ap[11], ap[12]) ); |
|
77 | 1579 |
|
159 | 1580 |
case 14: |
1581 |
RETURN ( interpret(self, 14, anObject, aSymbol, SND_COMMA searchClass, |
|
1582 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], |
|
1583 |
ap[7], ap[8], ap[9], ap[11], ap[12], ap[13]) ); |
|
77 | 1584 |
|
159 | 1585 |
case 15: |
1586 |
RETURN ( interpret(self, 15, anObject, aSymbol, SND_COMMA searchClass, |
|
1587 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], |
|
1588 |
ap[7], ap[8], ap[9], ap[11], ap[12], ap[13], ap[14]) ); |
|
1589 |
} |
|
328 | 1590 |
#endif |
227 | 1591 |
} |
159 | 1592 |
} |
1 | 1593 |
} |
1594 |
%} |
|
2 | 1595 |
. |
1596 |
(argArray isMemberOf:Array) ifFalse:[ |
|
159 | 1597 |
" |
1598 |
arguments must be either nil or an array |
|
1599 |
" |
|
1600 |
^ self badArgumentArray |
|
2 | 1601 |
]. |
109 | 1602 |
(argArray size ~~ self numberOfMethodArgs) ifTrue:[ |
159 | 1603 |
" |
1604 |
the method expects a different number of arguments |
|
1605 |
" |
|
1606 |
^ self wrongNumberOfArguments:argArray size |
|
109 | 1607 |
]. |
1608 |
" |
|
1609 |
the VM only supports a limited number of arguments in sends |
|
1610 |
" |
|
1611 |
^ self tooManyArguments |
|
1612 |
||
1613 |
" |
|
1614 |
(Float compiledMethodAt:#+) |
|
159 | 1615 |
valueWithReceiver:1.0 arguments:#(2.0) |
2 | 1616 |
|
109 | 1617 |
'the next example is a wrong one - which is detected by True's method ...'. |
1618 |
(True compiledMethodAt:#printString) |
|
159 | 1619 |
valueWithReceiver:false arguments:nil |
109 | 1620 |
|
1621 |
'the next example is a wrong one - it is nowhere detected |
|
1622 |
and a wrong value returned ...'. |
|
1623 |
(Point compiledMethodAt:#x) |
|
159 | 1624 |
valueWithReceiver:(1->2) arguments:nil |
109 | 1625 |
|
1626 |
'the next example is VERY bad one - it is nowhere detected |
|
1627 |
and may crash the system WARNING: save your work before doing this ...'. |
|
1628 |
(Point compiledMethodAt:#x) |
|
159 | 1629 |
valueWithReceiver:(Object new) arguments:nil |
109 | 1630 |
|
1631 |
'the next example is a wrong one - which is detected here ...'. |
|
1632 |
(Object compiledMethodAt:#printOn:) |
|
159 | 1633 |
valueWithReceiver:false arguments:nil |
109 | 1634 |
|
1635 |
'the next example is a wrong one - which is detected here ...'. |
|
1636 |
(Object compiledMethodAt:#printOn:) |
|
159 | 1637 |
valueWithReceiver:false arguments:#() |
109 | 1638 |
" |
1 | 1639 |
! ! |
1640 |
||
93 | 1641 |
!Method methodsFor:'printing & storing'! |
1 | 1642 |
|
275 | 1643 |
whoString |
1644 |
"return a string as className>>selector, if this is not an unbound |
|
1645 |
method. Otherwise return 'unbound'. Used with debugging." |
|
1646 |
||
1647 |
|w| |
|
1648 |
||
1649 |
w := self who. |
|
1650 |
w notNil ifTrue:[ |
|
1651 |
^ (w at:1) name , '>>' , (w at:2) |
|
1652 |
]. |
|
1653 |
^ 'unbound' |
|
1654 |
||
1655 |
" |
|
1656 |
Method new whoString |
|
1657 |
(Method compiledMethodAt:#whoString) whoString |
|
1658 |
" |
|
1659 |
! |
|
1660 |
||
1 | 1661 |
printOn:aStream |
56 | 1662 |
"put a printed representation of the receiver onto aStream. |
1663 |
Since methods do not store their class/selector, we have to search |
|
1664 |
for it here." |
|
1 | 1665 |
|
227 | 1666 |
|classAndSelector m wrapped| |
1 | 1667 |
|
253 | 1668 |
wrapped := false. |
1669 |
||
159 | 1670 |
aStream nextPutAll:(self classNameWithArticle). |
1671 |
aStream nextPut:$(. |
|
227 | 1672 |
|
176 | 1673 |
classAndSelector := self who. |
227 | 1674 |
classAndSelector isNil ifTrue:[ |
1675 |
" |
|
1676 |
not anchored in any class. |
|
1677 |
check if wrapped (to be more informative in inspectors) |
|
1678 |
" |
|
1679 |
m := self wrapper. |
|
1680 |
m notNil ifTrue:[ |
|
1681 |
classAndSelector := m who. |
|
1682 |
wrapped := true. |
|
1683 |
] |
|
1684 |
]. |
|
176 | 1685 |
classAndSelector notNil ifTrue:[ |
1686 |
(classAndSelector at:1) name printOn:aStream. |
|
159 | 1687 |
aStream nextPutAll:' '. |
227 | 1688 |
(classAndSelector at:2) printOn:aStream. |
1689 |
wrapped ifTrue:[ |
|
1690 |
aStream nextPutAll:'; wrapped' |
|
1691 |
]. |
|
1 | 1692 |
] ifFalse:[ |
202 | 1693 |
" |
227 | 1694 |
sorry, a method which is nowhere anchored |
202 | 1695 |
" |
253 | 1696 |
aStream nextPutAll:'unbound' |
56 | 1697 |
]. |
1698 |
aStream nextPut:$) |
|
176 | 1699 |
|
1700 |
" |
|
253 | 1701 |
(Object compiledMethodAt:#at:) printOn:Transcript. Transcript cr. |
1702 |
(Object compiledMethodAt:#at:) copy printOn:Transcript. Transcript cr. |
|
176 | 1703 |
" |
1 | 1704 |
! ! |
1705 |
||
159 | 1706 |
!Method class methodsFor:'binary storage'! |
1707 |
||
1708 |
binaryDefinitionFrom: stream manager: manager |
|
1709 |
"read my definition from stream." |
|
1710 |
||
1711 |
|cls sel| |
|
1712 |
||
1713 |
"type-byte" |
|
1714 |
stream nextByte == 0 ifTrue:[ |
|
1715 |
" |
|
1716 |
built-in method |
|
1717 |
" |
|
1718 |
cls := manager nextObject. |
|
1719 |
sel := manager nextObject. |
|
1720 |
||
1721 |
" |
|
1722 |
mhmh - on the source system, this was a machinecode |
|
1723 |
method, while here its an interpreted one ... |
|
1724 |
" |
|
1725 |
cls isLoaded ifFalse:[ |
|
1726 |
cls autoload |
|
1727 |
]. |
|
1728 |
^ cls compiledMethodAt:sel |
|
1729 |
]. |
|
1730 |
" |
|
1731 |
bytecode method |
|
1732 |
" |
|
1733 |
^ super binaryDefinitionFrom:stream manager:manager |
|
872 | 1734 |
! |
1735 |
||
1736 |
binaryFullDefinitionFrom:stream manager:manager |
|
1737 |
"retrieve a full bytecoded-method." |
|
1738 |
||
1739 |
|cat flags code lits m sourceFilename sourcePos source| |
|
1740 |
||
1741 |
cat := manager nextObject. |
|
1742 |
flags := manager nextObject. |
|
1743 |
lits := manager nextObject. |
|
1744 |
sourceFilename := manager nextObject. |
|
1745 |
sourcePos := manager nextObject. |
|
1746 |
sourcePos isNil ifTrue:[ |
|
1747 |
source := manager nextObject. |
|
1748 |
]. |
|
1749 |
code := manager nextObject. |
|
1750 |
||
1751 |
m := Method basicNew. |
|
1752 |
m category:cat. |
|
1753 |
m flags:flags. |
|
1754 |
m literals:lits. |
|
1755 |
m byteCode:code. |
|
1756 |
sourcePos isNil ifTrue:[ |
|
1757 |
m source:source |
|
1758 |
] ifFalse:[ |
|
1759 |
m sourceFilename:sourceFilename position:sourcePos |
|
1760 |
]. |
|
1761 |
^ m |
|
1762 |
||
1763 |
"Created: 16.1.1996 / 14:44:08 / cg" |
|
159 | 1764 |
! ! |
1765 |
||
13 | 1766 |
!Method methodsFor:'binary storage'! |
1767 |
||
444 | 1768 |
asExecutableMethod |
1769 |
"if the receiver has neither bytecodes nor machinecode, create & return a |
|
1770 |
method having semantics as the receivers source. This may be machine code, |
|
1771 |
if the system supports dynamic loading of object code and the source includes |
|
1772 |
primitive code. However, bytecode is preferred, since it compiles faster. |
|
68 | 1773 |
Otherwise, return the receiver. The new method is not installed in |
1774 |
the methodDictionary of any class - just returned. |
|
444 | 1775 |
Can be used to compile lazy methods down to executable ones." |
68 | 1776 |
|
444 | 1777 |
|temporaryMethod cls sourceString silent lazy| |
68 | 1778 |
|
142 | 1779 |
byteCode notNil ifTrue:[ |
159 | 1780 |
" |
1781 |
is already a bytecoded method |
|
1782 |
" |
|
1783 |
^ self |
|
142 | 1784 |
]. |
68 | 1785 |
|
1786 |
cls := self containingClass. |
|
159 | 1787 |
cls isNil ifTrue:[ |
1788 |
'cannot generate bytecode (no class for compilation)' errorPrintNL. |
|
1789 |
^ nil |
|
1790 |
]. |
|
68 | 1791 |
sourceString := self source. |
142 | 1792 |
sourceString isNil ifTrue:[ |
159 | 1793 |
'cannot generate bytecode (no source for compilation)' errorPrintNL. |
142 | 1794 |
^ nil |
68 | 1795 |
]. |
227 | 1796 |
|
142 | 1797 |
" |
159 | 1798 |
dont want this to go into the changes file, |
1799 |
dont want output on Transcript and definitely |
|
1800 |
dont want a lazy method ... |
|
142 | 1801 |
" |
421 | 1802 |
Class withoutUpdatingChangesDo:[ |
423 | 1803 |
silent := Smalltalk silentLoading:true. |
1804 |
lazy := Compiler compileLazy:false. |
|
159 | 1805 |
|
423 | 1806 |
[ |
421 | 1807 |
|compiler| |
350 | 1808 |
|
421 | 1809 |
compiler := cls compilerClass. |
350 | 1810 |
|
421 | 1811 |
"/ |
1812 |
"/ kludge - have to make ST/X's compiler protocol |
|
1813 |
"/ be compatible to ST-80's |
|
1814 |
"/ |
|
1815 |
(compiler respondsTo:#compile:forClass:inCategory:notifying:install:skipIfSame:) |
|
1816 |
ifTrue:[ |
|
423 | 1817 |
temporaryMethod := compiler |
421 | 1818 |
compile:sourceString |
1819 |
forClass:cls |
|
1820 |
inCategory:(self category) |
|
1821 |
notifying:nil |
|
1822 |
install:false. |
|
1823 |
] ifFalse:[ |
|
423 | 1824 |
temporaryMethod := compiler new |
421 | 1825 |
compile:sourceString |
1826 |
in:cls |
|
1827 |
notifying:nil |
|
1828 |
ifFail:nil |
|
1829 |
]. |
|
423 | 1830 |
] valueNowOrOnUnwindDo:[ |
421 | 1831 |
Compiler compileLazy:lazy. |
1832 |
Smalltalk silentLoading:silent. |
|
1833 |
] |
|
142 | 1834 |
]. |
1835 |
(temporaryMethod isNil or:[temporaryMethod == #Error]) ifTrue:[ |
|
159 | 1836 |
'cannot generate bytecode (contains primitive code or error)' errorPrintNL. |
142 | 1837 |
^ nil. |
1838 |
]. |
|
1839 |
" |
|
1840 |
try to save a bit of memory, by sharing the source (whatever it is) |
|
1841 |
" |
|
192 | 1842 |
temporaryMethod sourceFilename:source position:sourcePosition. |
142 | 1843 |
^ temporaryMethod |
68 | 1844 |
|
444 | 1845 |
"Created: 24.10.1995 / 14:02:30 / cg" |
1846 |
! |
|
1847 |
||
1848 |
asByteCodeMethod |
|
1849 |
"if the receiver has no bytecodes, create & return a method having |
|
1850 |
the same semantics as the receiver, but uses interpreted bytecodes. |
|
1851 |
Otherwise, return the receiver. The new method is not installed in |
|
1852 |
the methodDictionary of any class - just returned. |
|
1853 |
Can be used to obtain a bytecode version of a machine-code method, |
|
1854 |
for binary storage or dynamic recompilation (which is not yet finished) |
|
1855 |
or to compile lazy methods down to executable ones." |
|
1856 |
||
1857 |
|doMachineCode mthd| |
|
1858 |
||
1859 |
byteCode notNil ifTrue:[ |
|
1860 |
" |
|
1861 |
is already a bytecoded method |
|
1862 |
" |
|
1863 |
^ self |
|
1864 |
]. |
|
1865 |
doMachineCode := Compiler stcCompilation:#never. |
|
1866 |
[ |
|
1867 |
mthd := self asExecutableMethod. |
|
1868 |
] valueNowOrOnUnwindDo:[ |
|
1869 |
Compiler stcCompilation:doMachineCode. |
|
1870 |
]. |
|
1871 |
^ mthd |
|
1872 |
||
1873 |
"Created: 24.10.1995 / 14:02:32 / cg" |
|
1874 |
"Modified: 24.10.1995 / 14:17:21 / cg" |
|
68 | 1875 |
! |
1876 |
||
159 | 1877 |
storeBinaryDefinitionOn:stream manager:manager |
1878 |
"only store bytecode-methods - machinecode methods are stored |
|
1879 |
as class/selector pair and a lookup is done when restored. |
|
1880 |
||
56 | 1881 |
If the receiver method is a built-in (i.e. machine coded) |
1882 |
method, a temporary interpreted byte code method is created, |
|
68 | 1883 |
and its bytecode stored. |
1884 |
This works only, if the source of the method is available and the |
|
1885 |
method does not contain primitive code." |
|
13 | 1886 |
|
159 | 1887 |
|storedMethod who| |
13 | 1888 |
|
1889 |
byteCode isNil ifTrue:[ |
|
159 | 1890 |
self code notNil ifTrue:[ |
1891 |
(who := self who) notNil ifTrue:[ |
|
1892 |
" |
|
1893 |
machine code only - assume its a built-in method, |
|
1894 |
and store the class/selector information. |
|
1895 |
The restored method may not be exactly the same ... |
|
1896 |
" |
|
343 | 1897 |
manager putIdOfClass:(self class) on:stream. |
1898 |
stream nextPutByte:0. "means: built-in method" |
|
159 | 1899 |
manager putIdOf:(who at:1) on:stream. |
1900 |
manager putIdOf:(who at:2) on:stream. |
|
1901 |
^ self |
|
1902 |
] |
|
1903 |
]. |
|
1 | 1904 |
|
159 | 1905 |
storedMethod := self asByteCodeMethod. |
1906 |
storedMethod isNil ifTrue:[ |
|
1907 |
self error:'store of built-in method failed'. |
|
1908 |
^ nil |
|
1909 |
]. |
|
1910 |
^ storedMethod storeBinaryDefinitionOn:stream manager:manager |
|
1911 |
]. |
|
1912 |
||
343 | 1913 |
manager putIdOfClass:(self class) on:stream. |
1914 |
stream nextPutByte:1. "means: byte-coded method" |
|
159 | 1915 |
self storeBinaryDefinitionBodyOn:stream manager:manager |
1 | 1916 |
! |
1917 |
||
159 | 1918 |
readBinaryContentsFrom: stream manager: manager |
1919 |
"tell the newly restored Font about restoration" |
|
1 | 1920 |
|
159 | 1921 |
self code notNil ifTrue:[ |
1922 |
"built-in method - already complete" |
|
1923 |
^ self |
|
1924 |
]. |
|
1 | 1925 |
|
159 | 1926 |
^ super readBinaryContentsFrom: stream manager: manager |
872 | 1927 |
! |
1928 |
||
1929 |
storeFullBinaryDefinitionOn:stream manager:manager |
|
1930 |
"store full bytecoded-method." |
|
1931 |
||
1932 |
|m code| |
|
1933 |
||
1934 |
category storeBinaryOn:stream manager:manager. |
|
1935 |
byteCode isNil ifTrue:[ |
|
1936 |
m := self asByteCodeMethod. |
|
1937 |
code := m byteCode |
|
1938 |
] ifFalse:[ |
|
1939 |
m := self. |
|
1940 |
code := byteCode |
|
1941 |
]. |
|
1942 |
||
1943 |
m flags storeBinaryOn:stream manager:manager. |
|
1944 |
m literals storeBinaryOn:stream manager:manager. |
|
1945 |
m sourceFilename storeBinaryOn:stream manager:manager. |
|
1946 |
m sourcePosition storeBinaryOn:stream manager:manager. |
|
1947 |
m sourcePosition isNil ifTrue:[ |
|
1948 |
m source storeBinaryOn:stream manager:manager. |
|
1949 |
]. |
|
1950 |
code storeBinaryOn:stream manager:manager. |
|
1951 |
||
1952 |
"Created: 16.1.1996 / 14:41:45 / cg" |
|
1 | 1953 |
! ! |