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