1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
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 |
|
85
|
13 |
ExecutableCodeObject subclass:#Method
|
93
|
14 |
instanceVariableNames:'source sourcePosition category package'
|
109
|
15 |
classVariableNames:'PrivateMethodSignal'
|
1
|
16 |
poolDictionaries:''
|
|
17 |
category:'Kernel-Methods'
|
|
18 |
!
|
|
19 |
|
|
20 |
Method comment:'
|
5
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
1
|
22 |
All Rights Reserved
|
93
|
23 |
|
142
|
24 |
$Header: /cvs/stx/stx/libbasic/Method.st,v 1.18 1994-08-23 23:09:46 claus Exp $
|
42
|
25 |
'!
|
|
26 |
|
|
27 |
!Method class methodsFor:'documentation'!
|
|
28 |
|
88
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
142
|
45 |
$Header: /cvs/stx/stx/libbasic/Method.st,v 1.18 1994-08-23 23:09:46 claus Exp $
|
88
|
46 |
"
|
|
47 |
!
|
|
48 |
|
42
|
49 |
documentation
|
|
50 |
"
|
68
|
51 |
this class defines protocol for executable methods;
|
|
52 |
both compiled and interpreted methods are represented by this class.
|
|
53 |
Compiled methods have a non-nil code field, while interpreted methods have
|
|
54 |
a nil code field and non-nil byteCode field.
|
88
|
55 |
If there are both non-nil code and bytecode fields, the VM will execute
|
|
56 |
the machine-code of a method.
|
1
|
57 |
|
68
|
58 |
The methods source-code is represented by source and sourcePosition:
|
|
59 |
if sourcePosition is a Number, the source-field is the fileName and
|
|
60 |
sourcePosition is the character offset of the source-chunk in this source file.
|
|
61 |
If sourcePosition is nil, the source is the string in the source field.
|
1
|
62 |
|
68
|
63 |
The flags field defines things like the number of method-locals,
|
|
64 |
method arguments and stack size need (for interpreted methods).
|
|
65 |
Do not depend on any value in the flags field - it may change without
|
|
66 |
notice.
|
1
|
67 |
|
93
|
68 |
Instance variables:
|
|
69 |
|
|
70 |
source <String> the source itself (if sourcePosition isNil)
|
|
71 |
or the fileName where the source is found
|
|
72 |
|
|
73 |
sourcePosition <Integer> the position of the methods chunk in the file
|
|
74 |
|
|
75 |
category <Symbol> the methods category
|
|
76 |
package <Symbol> the package, in which the methods was defined
|
|
77 |
(nil if its the standard system package)
|
|
78 |
|
68
|
79 |
WARNING: layout known by compiler and runtime system - dont change
|
42
|
80 |
"
|
|
81 |
! !
|
1
|
82 |
|
109
|
83 |
!Method class methodsFor:'initialization'!
|
|
84 |
|
|
85 |
initialize
|
|
86 |
PrivateMethodSignal isNil ifTrue:[
|
|
87 |
"EXPERIMENTAL"
|
|
88 |
PrivateMethodSignal := (Signal new) mayProceed:true.
|
|
89 |
PrivateMethodSignal notifierString:'attempt to execute private method'.
|
|
90 |
]
|
|
91 |
! !
|
|
92 |
|
3
|
93 |
!Method class methodsFor:'queries'!
|
|
94 |
|
|
95 |
isBuiltInClass
|
|
96 |
"this class is known by the run-time-system"
|
|
97 |
|
|
98 |
^ self == Method
|
44
|
99 |
!
|
|
100 |
|
|
101 |
maxNumberOfArguments
|
|
102 |
"this limit will be removed in one of the next versions ..."
|
|
103 |
|
109
|
104 |
^ 15 "cannot be easily changed"
|
3
|
105 |
! !
|
|
106 |
|
1
|
107 |
!Method methodsFor:'accessing'!
|
|
108 |
|
|
109 |
source
|
|
110 |
"return the sourcestring for the receiver"
|
|
111 |
|
|
112 |
|aStream junk|
|
|
113 |
|
|
114 |
source notNil ifTrue:[
|
|
115 |
sourcePosition isNil ifTrue:[^ source].
|
|
116 |
aStream := Smalltalk systemFileStreamFor:('source/' , source).
|
|
117 |
aStream notNil ifTrue:[
|
|
118 |
aStream position:sourcePosition.
|
|
119 |
junk := aStream nextChunk.
|
|
120 |
aStream close
|
|
121 |
]
|
|
122 |
].
|
|
123 |
^ junk
|
|
124 |
!
|
|
125 |
|
|
126 |
source:aString
|
|
127 |
"set the methods sourcestring"
|
|
128 |
|
|
129 |
source := aString.
|
|
130 |
sourcePosition := nil
|
|
131 |
!
|
|
132 |
|
|
133 |
sourceFileName
|
|
134 |
"return the sourcefilename if source is extern; nil otherwise"
|
|
135 |
|
|
136 |
sourcePosition notNil ifTrue:[^ source].
|
|
137 |
^ nil
|
|
138 |
!
|
|
139 |
|
|
140 |
sourcePosition
|
|
141 |
"return the sourceposition if source is extern; nil otherwise"
|
|
142 |
|
|
143 |
^ sourcePosition
|
|
144 |
!
|
|
145 |
|
|
146 |
sourceFileName:aFileName position:aNumber
|
|
147 |
"set the methods sourcefile/position"
|
|
148 |
|
|
149 |
source := aFileName.
|
|
150 |
sourcePosition := aNumber
|
|
151 |
!
|
|
152 |
|
39
|
153 |
comment
|
|
154 |
"return the methods comment.
|
68
|
155 |
This is done by searching for and returning the first comment
|
|
156 |
from the methods source.
|
|
157 |
Returns nil if there is no comment (or source is not available)."
|
39
|
158 |
|
68
|
159 |
|text lines line nQuote index i1 i2 commLines|
|
39
|
160 |
|
|
161 |
text := self source.
|
|
162 |
text isNil ifTrue:[^ nil].
|
68
|
163 |
lines := text asCollectionOfLines.
|
|
164 |
(lines size < 2) ifTrue:[^ nil].
|
93
|
165 |
|
|
166 |
index := 2.
|
|
167 |
|
|
168 |
"
|
|
169 |
skip empty lines
|
|
170 |
"
|
|
171 |
line := (lines at:index).
|
|
172 |
[line isBlank] whileTrue:[
|
|
173 |
index := index + 1.
|
|
174 |
index > lines size ifTrue:[^ nil].
|
|
175 |
line := (lines at:index).
|
|
176 |
].
|
|
177 |
|
39
|
178 |
nQuote := line occurrencesOf:(Character doubleQuote).
|
|
179 |
(nQuote == 0) ifTrue:[^ nil].
|
|
180 |
(nQuote == 2) ifTrue:[^ line].
|
|
181 |
(nQuote > 2) ifTrue:[
|
|
182 |
i1 := line indexOf:(Character doubleQuote).
|
|
183 |
i2 := line indexOf:(Character doubleQuote) startingAt:(i1 + 1).
|
|
184 |
^ line copyFrom:i1+1 to:i2-1
|
|
185 |
].
|
|
186 |
commLines := Text new.
|
|
187 |
commLines add:line.
|
|
188 |
[nQuote ~~ 1] whileTrue:[
|
93
|
189 |
index := index + 1.
|
|
190 |
index > lines size ifTrue:[^ nil]. "unclosed comment - could warn here"
|
|
191 |
line := lines at:index.
|
|
192 |
nQuote := line occurrencesOf:(Character doubleQuote).
|
39
|
193 |
commLines add:line.
|
|
194 |
].
|
|
195 |
^ commLines asString
|
|
196 |
|
93
|
197 |
"
|
|
198 |
(Method compiledMethodAt:#comment) comment
|
|
199 |
"
|
39
|
200 |
!
|
|
201 |
|
1
|
202 |
category
|
|
203 |
"return the methods category or nil"
|
|
204 |
|
|
205 |
^ category
|
|
206 |
!
|
|
207 |
|
|
208 |
category:aStringOrSymbol
|
|
209 |
"set the methods category"
|
|
210 |
|
|
211 |
category := aStringOrSymbol asSymbol
|
|
212 |
!
|
|
213 |
|
93
|
214 |
package
|
|
215 |
"return the package-symbol"
|
|
216 |
|
|
217 |
^ package
|
|
218 |
!
|
|
219 |
|
1
|
220 |
flags
|
44
|
221 |
"return the flags (number of method variables, stacksize etc.).
|
|
222 |
Dont depend on the values in the flag field - it may change
|
|
223 |
without notice."
|
1
|
224 |
|
|
225 |
^ flags
|
|
226 |
!
|
|
227 |
|
|
228 |
flags:newFlags
|
68
|
229 |
"set the flags (number of method variables, stacksize).
|
|
230 |
WARNING: for internal use by the compiler only."
|
1
|
231 |
|
56
|
232 |
"protect myself a bit - putting in an object would crash me ..."
|
|
233 |
(newFlags isMemberOf:SmallInteger) ifTrue:[
|
|
234 |
flags := newFlags
|
|
235 |
]
|
1
|
236 |
!
|
|
237 |
|
68
|
238 |
private:aBoolean
|
|
239 |
"set the flag bit stating that this method is private, and should only be
|
|
240 |
allowed for self-sends from the class or self/super sends from subclasses.
|
|
241 |
EXPERIMENTAL."
|
|
242 |
|
|
243 |
%{ /* NOCONTEXT */
|
|
244 |
int f = _intVal(_INST(flags));
|
|
245 |
|
|
246 |
/* made this a primitive to get define in stc.h */
|
|
247 |
#ifdef F_PRIVATE
|
|
248 |
if (aBoolean == true)
|
|
249 |
f = f | F_PRIVATE;
|
|
250 |
else
|
|
251 |
f = f & ~F_PRIVATE;
|
|
252 |
_INST(flags) = _MKSMALLINT(f);
|
|
253 |
#endif
|
|
254 |
%}
|
|
255 |
!
|
|
256 |
|
|
257 |
isPrivate
|
|
258 |
"return true, if this is a private method (i.e. on which is allowed
|
|
259 |
for self-sends from the classes methods or self/super sends from subclasses
|
|
260 |
methods only.
|
|
261 |
EXPERIMENTAL."
|
|
262 |
|
|
263 |
%{ /* NOCONTEXT */
|
|
264 |
int f = _intVal(_INST(flags));
|
|
265 |
|
|
266 |
/* made this a primitive to get define in stc.h */
|
|
267 |
#ifdef F_PRIVATE
|
|
268 |
if (f & F_PRIVATE) {
|
|
269 |
RETURN (true);
|
|
270 |
}
|
|
271 |
#endif
|
|
272 |
%}.
|
|
273 |
^ false
|
|
274 |
!
|
|
275 |
|
44
|
276 |
numberOfMethodArgs:aNumber
|
|
277 |
"currently, the number of arguments is NOT remembered in
|
49
|
278 |
methods, but this will be added soon to allow for more checking
|
|
279 |
in #perform:.
|
|
280 |
|
44
|
281 |
The limitation in the max. number of arguments is due to the
|
109
|
282 |
missing SENDxx functions in the VM and cases in #perform. This too
|
|
283 |
will be removed in a later release, allowing any number of arguments.
|
44
|
284 |
- for use by compiler only."
|
|
285 |
|
56
|
286 |
(aNumber between:0 and:self class maxNumberOfArguments) ifFalse:[
|
|
287 |
self error:('ST/X only supports up to a maximum of ' ,
|
44
|
288 |
self class maxNumberOfArguments printString ,
|
56
|
289 |
' method arguments').
|
|
290 |
^ self
|
|
291 |
].
|
|
292 |
%{
|
|
293 |
/* made this a primitive to get define in stc.h */
|
|
294 |
#ifdef F_NARGS
|
|
295 |
_INST(flags) = _MKSMALLINT( (_intVal(_INST(flags)) & ~F_NARGS) | (_intVal(aNumber) << F_NARGSHIFT) );
|
|
296 |
#endif
|
|
297 |
%}
|
44
|
298 |
!
|
|
299 |
|
49
|
300 |
numberOfMethodArgs
|
|
301 |
"return the number of arguments, the method expects."
|
|
302 |
|
56
|
303 |
%{ /* NOCONTEXT */
|
|
304 |
/* made this a primitive to get define in stc.h */
|
|
305 |
|
|
306 |
#ifdef F_NARGS
|
|
307 |
RETURN (_MKSMALLINT((_intVal(_INST(flags)) & F_NARGS) >> F_NARGSHIFT));
|
|
308 |
#endif
|
|
309 |
%}
|
|
310 |
.
|
49
|
311 |
"
|
56
|
312 |
The old implementation simply counted the arguments from
|
|
313 |
the methods source - new versions include this information
|
109
|
314 |
in the flag instVar, for more security in #perform:
|
68
|
315 |
"
|
49
|
316 |
|
|
317 |
^ self methodArgNames size
|
|
318 |
!
|
|
319 |
|
1
|
320 |
numberOfMethodVars:aNumber
|
56
|
321 |
"set the number of method variables - for use by compiler only.
|
68
|
322 |
WARNING: playing around here with incorrect values
|
|
323 |
may crash smalltalk badly."
|
1
|
324 |
|
56
|
325 |
%{ /* NOCONTEXT */
|
|
326 |
int f = _intVal(_INST(flags));
|
1
|
327 |
|
|
328 |
/* made this a primitive to get define in stc.h */
|
56
|
329 |
if (_isSmallInteger(aNumber)) {
|
|
330 |
f = (f & ~F_NVARS) | (_intVal(aNumber) << F_NVARSHIFT);
|
|
331 |
_INST(flags) = _MKSMALLINT(f);
|
|
332 |
}
|
1
|
333 |
%}
|
|
334 |
!
|
|
335 |
|
49
|
336 |
numberOfMethodVars
|
|
337 |
"return the number of method local variables.
|
|
338 |
Do not depend on the returned value - future optimizations
|
68
|
339 |
may change things here (i.e. when moving block-locals into
|
|
340 |
surrounding method for inlining).
|
49
|
341 |
- for debugging only."
|
|
342 |
|
|
343 |
%{ /* NOCONTEXT */
|
|
344 |
/* made this a primitive to get define in stc.h */
|
|
345 |
|
56
|
346 |
RETURN (_MKSMALLINT((_intVal(_INST(flags)) & F_NVARS) >> F_NVARSHIFT));
|
49
|
347 |
%}
|
|
348 |
!
|
|
349 |
|
1
|
350 |
stackSize:aNumber
|
56
|
351 |
"set the depth of the local stack - for use by compiler only.
|
68
|
352 |
WARNING: playing around here with incorrect values
|
|
353 |
may crash smalltalk badly.
|
|
354 |
(if the runtime library was compiled with DEBUG,
|
109
|
355 |
a bad stack will be detected and triggers an error)"
|
1
|
356 |
|
56
|
357 |
%{ /* NOCONTEXT */
|
|
358 |
int f = _intVal(_INST(flags));
|
|
359 |
|
1
|
360 |
/* made this a primitive to get define in stc.h */
|
56
|
361 |
if (_isSmallInteger(aNumber)) {
|
|
362 |
f = (f & ~F_NSTACK) | (_intVal(aNumber) << F_NSTACKSHIFT);
|
|
363 |
_INST(flags) = _MKSMALLINT(f);
|
|
364 |
}
|
1
|
365 |
%}
|
49
|
366 |
!
|
|
367 |
|
|
368 |
stackSize
|
|
369 |
"return the number of temporaries needed as stack in the context.
|
|
370 |
Do not depend on the returned value - future optimizations
|
|
371 |
may change things here.
|
|
372 |
- for debugging only."
|
|
373 |
|
|
374 |
%{ /* NOCONTEXT */
|
|
375 |
/* made this a primitive to get define in stc.h */
|
|
376 |
|
56
|
377 |
RETURN (_MKSMALLINT((_intVal(_INST(flags)) & F_NSTACK) >> F_NSTACKSHIFT));
|
49
|
378 |
%}
|
1
|
379 |
! !
|
|
380 |
|
|
381 |
!Method methodsFor:'queries'!
|
|
382 |
|
|
383 |
containingClass
|
56
|
384 |
"return the class I am defined in.
|
|
385 |
Since there is no information of the containing class
|
68
|
386 |
in the method, we have to search here.
|
|
387 |
|
|
388 |
Normally, this is not a problem, except when a method is
|
|
389 |
accepted in the debugger - the information about which
|
|
390 |
class the original method was in is then lost.
|
|
391 |
|
|
392 |
Q: should we add a backref from the method to the class ?"
|
1
|
393 |
|
2
|
394 |
Smalltalk allBehaviorsDo:[:aClass |
|
56
|
395 |
(aClass containsMethod:self) ifTrue:[^ aClass].
|
|
396 |
(aClass class containsMethod:self) ifTrue:[^ aClass class]
|
1
|
397 |
].
|
77
|
398 |
"
|
|
399 |
mhmh - must be a method of some anonymous class (i.e. one not
|
|
400 |
in the Smalltalk dictionary; search all instances of Behavior
|
|
401 |
"
|
|
402 |
Behavior allDerivedInstancesDo:[:someClass |
|
|
403 |
(someClass containsMethod:self) ifTrue:[
|
|
404 |
^ someClass
|
|
405 |
].
|
|
406 |
].
|
|
407 |
"
|
|
408 |
none found - sorry
|
|
409 |
"
|
1
|
410 |
^ nil
|
|
411 |
!
|
|
412 |
|
|
413 |
methodArgNames
|
|
414 |
"return a collection with the methods argument names.
|
44
|
415 |
Uses Parser to parse methods source and extract the names."
|
1
|
416 |
|
|
417 |
|parser sourceString|
|
|
418 |
|
|
419 |
sourceString := self source.
|
|
420 |
sourceString notNil ifTrue:[
|
|
421 |
parser := Parser parseMethodSpecification:sourceString.
|
68
|
422 |
(parser isNil or:[parser == #Error]) ifTrue:[^ nil].
|
1
|
423 |
^ parser methodArgs
|
|
424 |
].
|
|
425 |
^ nil
|
|
426 |
|
109
|
427 |
"
|
|
428 |
(Method compiledMethodAt:#printOn:) methodArgNames
|
|
429 |
"
|
1
|
430 |
!
|
|
431 |
|
|
432 |
methodVarNames
|
|
433 |
"return a collection with the methods local-variable names.
|
44
|
434 |
Uses Parser to parse methods source and extract the names."
|
1
|
435 |
|
|
436 |
|parser sourceString|
|
|
437 |
|
|
438 |
sourceString := self source.
|
|
439 |
sourceString notNil ifTrue:[
|
|
440 |
parser := Parser parseMethodArgAndVarSpecification:sourceString.
|
68
|
441 |
(parser isNil or:[parser == #Error]) ifTrue:[^ nil].
|
1
|
442 |
^ parser methodVars
|
|
443 |
].
|
|
444 |
^ nil
|
|
445 |
|
109
|
446 |
"
|
|
447 |
(Method compiledMethodAt:#printOn:) methodVarNames
|
|
448 |
"
|
1
|
449 |
!
|
|
450 |
|
|
451 |
methodArgAndVarNames
|
|
452 |
"return a collection with the methods argument and variable names.
|
44
|
453 |
Uses Parser to parse methods source and extract the names."
|
1
|
454 |
|
|
455 |
|parser sourceString argNames varNames|
|
|
456 |
|
|
457 |
sourceString := self source.
|
|
458 |
sourceString notNil ifTrue:[
|
|
459 |
parser := Parser parseMethodArgAndVarSpecification:sourceString.
|
68
|
460 |
(parser isNil or:[parser == #Error]) ifTrue:[^ nil].
|
1
|
461 |
argNames := parser methodArgs.
|
|
462 |
varNames := parser methodVars.
|
|
463 |
argNames isNil ifTrue:[^ varNames].
|
|
464 |
varNames isNil ifTrue:[^ argNames].
|
|
465 |
^ (argNames , varNames)
|
|
466 |
].
|
|
467 |
^ nil
|
|
468 |
|
109
|
469 |
"
|
|
470 |
(Method compiledMethodAt:#printOn:) methodArgAndVarNames
|
|
471 |
"
|
1
|
472 |
!
|
|
473 |
|
|
474 |
methodComment
|
44
|
475 |
"return the methods first comment, nil if there is none.
|
|
476 |
This is a somewhat stupid implementation."
|
1
|
477 |
|
|
478 |
|text line nQuote index qIndex qIndex2 comment|
|
|
479 |
|
142
|
480 |
text := self source asCollectionOfLines.
|
1
|
481 |
(text size < 2) ifTrue:[^nil].
|
|
482 |
|
|
483 |
line := (text at:2).
|
|
484 |
nQuote := line occurrencesOf:(Character doubleQuote).
|
|
485 |
(nQuote == 2) ifTrue:[
|
|
486 |
qIndex := line indexOf:(Character doubleQuote).
|
|
487 |
qIndex2 := line indexOf:(Character doubleQuote) startingAt:(qIndex + 1).
|
|
488 |
^ line copyFrom:(qIndex + 1) to:(qIndex2 - 1)
|
|
489 |
].
|
|
490 |
(nQuote == 1) ifTrue:[
|
|
491 |
qIndex := line indexOf:(Character doubleQuote).
|
|
492 |
comment := line copyFrom:(qIndex + 1).
|
|
493 |
|
|
494 |
index := 3.
|
|
495 |
line := text at:index.
|
|
496 |
nQuote := line occurrencesOf:(Character doubleQuote).
|
|
497 |
[nQuote ~~ 1] whileTrue:[
|
|
498 |
comment := comment , Character cr asString , line withoutSpaces.
|
|
499 |
index := index + 1.
|
|
500 |
line := text at:index.
|
|
501 |
nQuote := line occurrencesOf:(Character doubleQuote)
|
|
502 |
].
|
|
503 |
qIndex := line indexOf:(Character doubleQuote).
|
|
504 |
^ comment , Character cr asString , (line copyTo:(qIndex - 1)) withoutSpaces
|
|
505 |
].
|
|
506 |
^ nil
|
|
507 |
|
109
|
508 |
"
|
|
509 |
(Method compiledMethodAt:#methodComment) methodComment
|
|
510 |
"
|
1
|
511 |
!
|
|
512 |
|
|
513 |
referencesGlobal:aGlobalSymbol
|
|
514 |
"return true, if this method references the global
|
|
515 |
bound to aGlobalSymbol."
|
|
516 |
|
|
517 |
literals isNil ifTrue:[^ false].
|
|
518 |
^ (literals identityIndexOf:aGlobalSymbol startingAt:1) ~~ 0
|
|
519 |
!
|
|
520 |
|
|
521 |
sends:aSelectorSymbol
|
|
522 |
"return true, if this method contains a message-send
|
|
523 |
with aSelectorSymbol as selector.
|
|
524 |
- due to the simple check in the literal array, also simple uses
|
44
|
525 |
of aSelectorSymbol as symbol will return true.
|
|
526 |
Should ask compiler, if there is really a send."
|
1
|
527 |
|
|
528 |
^ self referencesGlobal:aSelectorSymbol
|
77
|
529 |
!
|
|
530 |
|
93
|
531 |
isLazyMethod
|
|
532 |
"return true, if this is a lazy method.
|
|
533 |
False is returned here - this method is redefined in LazyMethod"
|
|
534 |
|
|
535 |
^ false
|
|
536 |
!
|
|
537 |
|
77
|
538 |
isWrapped
|
93
|
539 |
"return true, if this is a wrapper method.
|
|
540 |
False is returned here - this method is redefined in WrappedMethod"
|
|
541 |
|
77
|
542 |
^ false
|
93
|
543 |
!
|
|
544 |
|
|
545 |
isInvalid
|
|
546 |
"return true, if this method is not executable due to
|
|
547 |
a (re)-compilation error. (see comment in Method>>invalidMethod)"
|
|
548 |
|
|
549 |
|m|
|
|
550 |
|
|
551 |
m := Method compiledMethodAt:#invalidMethod.
|
|
552 |
(self code notNil and:[self code == m code]) ifTrue:[^ true].
|
|
553 |
(byteCode notNil and:[byteCode == m byteCode]) ifTrue:[^ true].
|
|
554 |
^ false
|
|
555 |
|
1
|
556 |
! !
|
|
557 |
|
|
558 |
!Method methodsFor:'error handling'!
|
|
559 |
|
|
560 |
invalidMethod
|
93
|
561 |
"this method is triggered by the interpreter when a nil or non method
|
|
562 |
is about to be executed.
|
|
563 |
In this case, the VM sends this to the bad method (the receiver).
|
|
564 |
|
|
565 |
Also, the Compiler creates methods with their code/bytecode set to
|
|
566 |
this method if - after a class change - a method cannot be compiled
|
|
567 |
and is therefore no longer executable (for example, after an instvar
|
68
|
568 |
has been removed, and a method still tries to access this instvar)
|
44
|
569 |
|
93
|
570 |
Thus, we arrive here, when playing around in a classes methodArray,
|
|
571 |
or compiler/runtime system is broken :-(,
|
|
572 |
or you ignore the error messages during some recompile."
|
1
|
573 |
|
142
|
574 |
^ InvalidCodeSignal
|
109
|
575 |
raiseRequestWith:self
|
|
576 |
errorString:'invalid method - not executable'.
|
1
|
577 |
!
|
|
578 |
|
109
|
579 |
wrongNumberOfArguments:numberGiven
|
|
580 |
"this error is triggered, if a method is called with a wrong number
|
|
581 |
of arguments. This only applies to #valueWithReceiverXXX - sends.
|
|
582 |
With a normal send, this error cannot happen."
|
68
|
583 |
|
142
|
584 |
^ ArgumentSignal
|
109
|
585 |
raiseRequestWith:self
|
|
586 |
errorString:('method got ' , numberGiven printString ,
|
|
587 |
' args while ' , self numberOfMethodArgs printString , ' where expected')
|
68
|
588 |
!
|
|
589 |
|
109
|
590 |
privateMethodCalled
|
|
591 |
"this error is triggered, if a private method is called from
|
|
592 |
outside (i.e. not via a self-send and not via a super-send.
|
|
593 |
Methodprivacy is an EXPERIMENTAL feature."
|
68
|
594 |
|
142
|
595 |
^ PrivateMethodSignal raise
|
1
|
596 |
! !
|
|
597 |
|
|
598 |
!Method methodsFor:'executing'!
|
|
599 |
|
|
600 |
valueWithReceiver:anObject arguments:argArray
|
2
|
601 |
"low level call of a methods code - BIG DANGER ALERT.
|
|
602 |
Perform the receiver-method on anObject as receiver and argArray as
|
|
603 |
arguments. This does NO message lookup at all and mimics a
|
|
604 |
traditional function call.
|
44
|
605 |
This method is provided for debugging- and breakpoint-support
|
68
|
606 |
(replacing a method by a stub and recalling the original), or to implement
|
|
607 |
experimental MI implementations - it is not for general use.
|
|
608 |
|
|
609 |
The receiver must be a method compiled in anObjects class or one of its
|
|
610 |
superclasses and also, the number of arguments given must match the methods
|
|
611 |
expectations -
|
|
612 |
- otherwise strange things (and also strange crashes) can occur.
|
|
613 |
The system is NOT always detecting a wrong method/receiver combination.
|
77
|
614 |
YOU HAVE BEEN WARNED."
|
68
|
615 |
|
77
|
616 |
^ self valueWithReceiver:anObject arguments:argArray selector:nil search:nil
|
68
|
617 |
!
|
|
618 |
|
|
619 |
valueWithReceiver:anObject arguments:argArray selector:aSymbol
|
|
620 |
"low level call of a methods code - BIG DANGER ALERT.
|
|
621 |
Perform the receiver-method on anObject as receiver and argArray as
|
|
622 |
arguments. This does NO message lookup at all and mimics a
|
|
623 |
traditional function call.
|
|
624 |
This method is provided for debugging- and breakpoint-support
|
|
625 |
(replacing a method by a stub and recalling the original), or to implement
|
|
626 |
experimental MI implementations - it is not for general use.
|
|
627 |
|
44
|
628 |
The receiver must be a method compiled in anObjects class or one of its
|
56
|
629 |
superclasses and also, the number of arguments given must match the methods
|
|
630 |
expectations -
|
44
|
631 |
- otherwise strange things (and also strange crashes) can occur.
|
|
632 |
The system is NOT always detecting a wrong method/receiver combination.
|
77
|
633 |
YOU HAVE BEEN WARNED."
|
|
634 |
|
|
635 |
^ self valueWithReceiver:anObject arguments:argArray selector:aSymbol search:nil
|
|
636 |
!
|
|
637 |
|
|
638 |
valueWithReceiver:anObject arguments:argArray selector:aSymbol search:aClass
|
|
639 |
"low level call of a methods code - BIG DANGER ALERT.
|
|
640 |
Perform the receiver-method on anObject as receiver and argArray as
|
|
641 |
arguments. This does NO message lookup at all and mimics a
|
|
642 |
traditional function call.
|
|
643 |
This method is provided for debugging- and breakpoint-support
|
|
644 |
(replacing a method by a stub and recalling the original), or to implement
|
|
645 |
experimental MI implementations - it is not for general use.
|
|
646 |
|
|
647 |
The receiver must be a method compiled in anObjects class or one of its
|
|
648 |
superclasses and also, the number of arguments given must match the methods
|
|
649 |
expectations -
|
|
650 |
- otherwise strange things (and also strange crashes) can occur.
|
|
651 |
The system is NOT always detecting a wrong method/receiver combination.
|
|
652 |
YOU HAVE BEEN WARNED."
|
1
|
653 |
|
|
654 |
%{
|
|
655 |
OBJFUNC code;
|
|
656 |
OBJ searchClass;
|
|
657 |
static struct inlineCache dummy = _DUMMYILC0;
|
2
|
658 |
int nargs;
|
|
659 |
OBJ *ap;
|
68
|
660 |
extern OBJ interpret();
|
2
|
661 |
|
56
|
662 |
if (__isArray(argArray)) {
|
2
|
663 |
nargs = _arraySize(argArray);
|
13
|
664 |
ap = _ArrayInstPtr(argArray)->a_element;
|
2
|
665 |
} else {
|
13
|
666 |
if (argArray == nil) {
|
|
667 |
nargs = 0;
|
|
668 |
} else
|
|
669 |
nargs = -1;
|
2
|
670 |
}
|
1
|
671 |
|
109
|
672 |
#ifdef F_NARGS
|
|
673 |
if (((_intVal(_INST(flags)) & F_NARGS) >> F_NARGSHIFT) == nargs)
|
|
674 |
#endif
|
|
675 |
{
|
|
676 |
code = _MethodInstPtr(self)->m_code;
|
|
677 |
if (aClass == nil) {
|
|
678 |
searchClass = dummy.ilc_class = _Class(anObject);
|
|
679 |
} else {
|
|
680 |
searchClass = dummy.ilc_class = aClass;
|
|
681 |
}
|
77
|
682 |
|
109
|
683 |
if (code) {
|
|
684 |
/* compiled code */
|
|
685 |
switch (nargs) {
|
|
686 |
case 0:
|
|
687 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy) );
|
68
|
688 |
|
109
|
689 |
case 1:
|
|
690 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, ap[0]) );
|
1
|
691 |
|
109
|
692 |
case 2:
|
|
693 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, ap[0], ap[1]) );
|
68
|
694 |
|
109
|
695 |
case 3:
|
|
696 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2]) );
|
1
|
697 |
|
109
|
698 |
case 4:
|
|
699 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
68
|
700 |
ap[0], ap[1], ap[2], ap[3]) );
|
|
701 |
|
109
|
702 |
case 5:
|
|
703 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
68
|
704 |
ap[0], ap[1], ap[2], ap[3], ap[4]) );
|
1
|
705 |
|
109
|
706 |
case 6:
|
|
707 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
68
|
708 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) );
|
1
|
709 |
|
109
|
710 |
case 7:
|
|
711 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
68
|
712 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) );
|
|
713 |
|
109
|
714 |
case 8:
|
|
715 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
68
|
716 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) );
|
1
|
717 |
|
109
|
718 |
case 9:
|
|
719 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
68
|
720 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) );
|
1
|
721 |
|
109
|
722 |
case 10:
|
|
723 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
68
|
724 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8],
|
|
725 |
ap[9]) );
|
|
726 |
|
109
|
727 |
case 11:
|
|
728 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
68
|
729 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8],
|
|
730 |
ap[9], ap[10]) );
|
1
|
731 |
|
109
|
732 |
case 12:
|
|
733 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
68
|
734 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8],
|
|
735 |
ap[9], ap[10], ap[11]) );
|
77
|
736 |
|
109
|
737 |
case 13:
|
|
738 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
77
|
739 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8],
|
|
740 |
ap[9], ap[10], ap[11], ap[12]) );
|
|
741 |
|
109
|
742 |
case 14:
|
|
743 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
77
|
744 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8],
|
|
745 |
ap[9], ap[10], ap[11], ap[12], ap[13]) );
|
|
746 |
|
109
|
747 |
case 15:
|
|
748 |
RETURN ( (*code)(anObject, aSymbol, SND_COMMA searchClass, &dummy,
|
77
|
749 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8],
|
|
750 |
ap[9], ap[10], ap[11], ap[12], ap[13], ap[14]) );
|
109
|
751 |
}
|
|
752 |
} else {
|
|
753 |
/* interpreted code */
|
|
754 |
switch (nargs) {
|
|
755 |
case 0:
|
|
756 |
RETURN ( interpret(self, 0, anObject, aSymbol, SND_COMMA searchClass) );
|
68
|
757 |
|
109
|
758 |
case 1:
|
|
759 |
RETURN ( interpret(self, 1, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
760 |
ap[0]) );
|
1
|
761 |
|
109
|
762 |
case 2:
|
|
763 |
RETURN ( interpret(self, 2, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
764 |
ap[0], ap[1]) );
|
|
765 |
|
109
|
766 |
case 3:
|
|
767 |
RETURN ( interpret(self, 3, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
768 |
ap[0], ap[1], ap[2]) );
|
1
|
769 |
|
109
|
770 |
case 4:
|
|
771 |
RETURN ( interpret(self, 4, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
772 |
ap[0], ap[1], ap[2], ap[3]) );
|
|
773 |
|
109
|
774 |
case 5:
|
|
775 |
RETURN ( interpret(self, 5, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
776 |
ap[0], ap[1], ap[2], ap[3], ap[4]) );
|
1
|
777 |
|
109
|
778 |
case 6:
|
|
779 |
RETURN ( interpret(self, 6, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
780 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) );
|
|
781 |
|
109
|
782 |
case 7:
|
|
783 |
RETURN ( interpret(self, 7, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
784 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) );
|
|
785 |
|
109
|
786 |
case 8:
|
|
787 |
RETURN ( interpret(self, 8, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
788 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6],
|
|
789 |
ap[7]) );
|
1
|
790 |
|
109
|
791 |
case 9:
|
|
792 |
RETURN ( interpret(self, 9, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
793 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6],
|
|
794 |
ap[7], ap[8]) );
|
|
795 |
|
109
|
796 |
case 10:
|
|
797 |
RETURN ( interpret(self, 10, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
798 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6],
|
|
799 |
ap[7], ap[8], ap[9]) );
|
1
|
800 |
|
109
|
801 |
case 11:
|
|
802 |
RETURN ( interpret(self, 11, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
803 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6],
|
|
804 |
ap[7], ap[8], ap[9], ap[10]) );
|
|
805 |
|
109
|
806 |
case 12:
|
|
807 |
RETURN ( interpret(self, 12, anObject, aSymbol, SND_COMMA searchClass,
|
68
|
808 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6],
|
|
809 |
ap[7], ap[8], ap[9], ap[11]) );
|
77
|
810 |
|
109
|
811 |
case 13:
|
|
812 |
RETURN ( interpret(self, 13, anObject, aSymbol, SND_COMMA searchClass,
|
77
|
813 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6],
|
|
814 |
ap[7], ap[8], ap[9], ap[11], ap[12]) );
|
|
815 |
|
109
|
816 |
case 14:
|
|
817 |
RETURN ( interpret(self, 14, anObject, aSymbol, SND_COMMA searchClass,
|
77
|
818 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6],
|
|
819 |
ap[7], ap[8], ap[9], ap[11], ap[12], ap[13]) );
|
|
820 |
|
109
|
821 |
case 15:
|
|
822 |
RETURN ( interpret(self, 15, anObject, aSymbol, SND_COMMA searchClass,
|
77
|
823 |
ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6],
|
|
824 |
ap[7], ap[8], ap[9], ap[11], ap[12], ap[13], ap[14]) );
|
109
|
825 |
}
|
68
|
826 |
}
|
1
|
827 |
}
|
|
828 |
%}
|
2
|
829 |
.
|
|
830 |
(argArray isMemberOf:Array) ifFalse:[
|
109
|
831 |
"
|
|
832 |
arguments must be either nil or an array
|
|
833 |
"
|
|
834 |
^ self badArgumentArray
|
2
|
835 |
].
|
109
|
836 |
(argArray size ~~ self numberOfMethodArgs) ifTrue:[
|
|
837 |
"
|
|
838 |
the method expects a different number of arguments
|
|
839 |
"
|
|
840 |
^ self wrongNumberOfArguments:argArray size
|
|
841 |
].
|
|
842 |
"
|
|
843 |
the VM only supports a limited number of arguments in sends
|
|
844 |
"
|
|
845 |
^ self tooManyArguments
|
|
846 |
|
|
847 |
"
|
|
848 |
(Float compiledMethodAt:#+)
|
|
849 |
valueWithReceiver:1.0 arguments:#(2.0)
|
2
|
850 |
|
109
|
851 |
'the next example is a wrong one - which is detected by True's method ...'.
|
|
852 |
(True compiledMethodAt:#printString)
|
|
853 |
valueWithReceiver:false arguments:nil
|
|
854 |
|
|
855 |
'the next example is a wrong one - it is nowhere detected
|
|
856 |
and a wrong value returned ...'.
|
|
857 |
(Point compiledMethodAt:#x)
|
|
858 |
valueWithReceiver:(1->2) arguments:nil
|
|
859 |
|
|
860 |
'the next example is VERY bad one - it is nowhere detected
|
|
861 |
and may crash the system WARNING: save your work before doing this ...'.
|
|
862 |
(Point compiledMethodAt:#x)
|
|
863 |
valueWithReceiver:(Object new) arguments:nil
|
|
864 |
|
|
865 |
'the next example is a wrong one - which is detected here ...'.
|
|
866 |
(Object compiledMethodAt:#printOn:)
|
|
867 |
valueWithReceiver:false arguments:nil
|
|
868 |
|
|
869 |
'the next example is a wrong one - which is detected here ...'.
|
|
870 |
(Object compiledMethodAt:#printOn:)
|
|
871 |
valueWithReceiver:false arguments:#()
|
|
872 |
"
|
1
|
873 |
! !
|
|
874 |
|
93
|
875 |
!Method methodsFor:'printing & storing'!
|
1
|
876 |
|
|
877 |
printOn:aStream
|
56
|
878 |
"put a printed representation of the receiver onto aStream.
|
|
879 |
Since methods do not store their class/selector, we have to search
|
|
880 |
for it here."
|
1
|
881 |
|
56
|
882 |
|myClass|
|
1
|
883 |
|
56
|
884 |
aStream nextPutAll:'a Method('.
|
|
885 |
myClass := self containingClass.
|
|
886 |
myClass notNil ifTrue:[
|
|
887 |
myClass name printOn:aStream.
|
1
|
888 |
aStream nextPutAll:' '.
|
56
|
889 |
(myClass selectorForMethod:self) printOn:aStream
|
1
|
890 |
] ifFalse:[
|
56
|
891 |
aStream nextPutAll:'???'
|
|
892 |
].
|
|
893 |
aStream nextPut:$)
|
1
|
894 |
! !
|
|
895 |
|
13
|
896 |
!Method methodsFor:'binary storage'!
|
|
897 |
|
68
|
898 |
asByteCodeMethod
|
142
|
899 |
"if the receiver has no bytecodes, create & return a method having
|
|
900 |
the same semantics as the receiver, but uses interpreted bytecodes.
|
68
|
901 |
Otherwise, return the receiver. The new method is not installed in
|
|
902 |
the methodDictionary of any class - just returned.
|
142
|
903 |
Can be used to obtain a bytecode version of a machine-code method
|
|
904 |
for binary storage or dynamic recompilation (which is not yet finished)."
|
68
|
905 |
|
|
906 |
|temporaryMethod cls sourceString upd silent|
|
|
907 |
|
142
|
908 |
byteCode notNil ifTrue:[
|
|
909 |
^ self
|
|
910 |
].
|
68
|
911 |
|
|
912 |
cls := self containingClass.
|
|
913 |
sourceString := self source.
|
142
|
914 |
sourceString isNil ifTrue:[
|
|
915 |
'cannot generate bytecode (no source for compilation)' errorPrintNL.
|
|
916 |
^ nil
|
68
|
917 |
].
|
142
|
918 |
"
|
|
919 |
dont want this to go into the changes file
|
|
920 |
"
|
|
921 |
upd := Class updateChanges:false.
|
|
922 |
silent := Smalltalk silentLoading:true.
|
|
923 |
[
|
|
924 |
temporaryMethod := cls compiler compile:sourceString
|
|
925 |
forClass:cls
|
|
926 |
inCategory:(self category)
|
|
927 |
notifying:nil
|
|
928 |
install:false.
|
|
929 |
] valueNowOrOnUnwindDo:[
|
|
930 |
Class updateChanges:upd.
|
|
931 |
Smalltalk silentLoading:silent.
|
|
932 |
].
|
|
933 |
(temporaryMethod isNil or:[temporaryMethod == #Error]) ifTrue:[
|
|
934 |
'cannot generate bytecode (contains primitive code or error)' errorPrintNL.
|
|
935 |
^ nil.
|
|
936 |
].
|
|
937 |
"
|
|
938 |
try to save a bit of memory, by sharing the source (whatever it is)
|
|
939 |
"
|
|
940 |
temporaryMethod sourceFileName:source position:sourcePosition.
|
|
941 |
^ temporaryMethod
|
68
|
942 |
|
|
943 |
"
|
|
944 |
(LargeInteger compiledMethodAt:#normalize) asByteCodeMethod
|
|
945 |
(SmallInteger compiledMethodAt:#+) asByteCodeMethod
|
|
946 |
"
|
|
947 |
!
|
|
948 |
|
13
|
949 |
storeBinaryDefinitionOn: stream manager: manager
|
56
|
950 |
"can only store bytecode - machine code is not storable.
|
|
951 |
If the receiver method is a built-in (i.e. machine coded)
|
|
952 |
method, a temporary interpreted byte code method is created,
|
68
|
953 |
and its bytecode stored.
|
|
954 |
This works only, if the source of the method is available and the
|
|
955 |
method does not contain primitive code."
|
13
|
956 |
|
68
|
957 |
|storedMethod|
|
13
|
958 |
|
|
959 |
byteCode isNil ifTrue:[
|
68
|
960 |
storedMethod := self asByteCodeMethod.
|
|
961 |
storedMethod isNil ifTrue:[
|
|
962 |
self error:'store of built-in method failed'.
|
|
963 |
^ nil
|
56
|
964 |
].
|
68
|
965 |
^ storedMethod storeBinaryDefinitionOn:stream manager:manager
|
13
|
966 |
].
|
68
|
967 |
^ super storeBinaryDefinitionOn:stream manager:manager
|
13
|
968 |
! !
|
|
969 |
|
56
|
970 |
!Method methodsFor:'obsolete binary fileOut'!
|
1
|
971 |
|
|
972 |
binaryFileOutLiteralsOn:aStream
|
|
973 |
|index n|
|
|
974 |
|
|
975 |
literals isNil ifTrue:[
|
|
976 |
aStream nextPutAll:'0'.
|
|
977 |
aStream nextPut:$!!.
|
|
978 |
^ self
|
|
979 |
].
|
|
980 |
aStream nextPutAll:literals size printString.
|
|
981 |
aStream nextPut:$!!.
|
|
982 |
|
|
983 |
index := 1.
|
|
984 |
literals do:[:lit |
|
13
|
985 |
lit isNumber ifTrue:[
|
1
|
986 |
lit storeOn:aStream
|
|
987 |
] ifFalse:[
|
|
988 |
((lit isKindOf:String) or:[lit isKindOf:Character]) ifTrue:[
|
|
989 |
lit storeOn:aStream
|
|
990 |
] ifFalse:[
|
|
991 |
(lit isKindOf:Array) ifTrue:[
|
|
992 |
aStream nextPut:$(.
|
|
993 |
lit storeOn:aStream.
|
|
994 |
aStream nextPut:$)
|
|
995 |
] ifFalse:[
|
13
|
996 |
lit isBehavior ifTrue:[
|
1
|
997 |
aStream nextPutAll:'(Smalltalk at:#'.
|
|
998 |
n := lit name.
|
13
|
999 |
lit isMeta ifTrue:[
|
56
|
1000 |
n := (n copyTo:(n size - 5)) , ') class'
|
1
|
1001 |
] ifFalse:[
|
|
1002 |
n := n , ')'
|
|
1003 |
].
|
|
1004 |
aStream nextPutAll:n
|
|
1005 |
] ifFalse:[
|
|
1006 |
self error:('invalid literal ' , lit class name)
|
|
1007 |
]
|
|
1008 |
]
|
|
1009 |
]
|
|
1010 |
].
|
|
1011 |
aStream nextPut:$!!.
|
|
1012 |
index := index + 1
|
|
1013 |
]
|
|
1014 |
!
|
|
1015 |
|
|
1016 |
binaryFileOutOn:aStream
|
|
1017 |
byteCode isNil ifTrue:[
|
|
1018 |
self notify:'no bytecodes to fileout'.
|
|
1019 |
^ self
|
|
1020 |
].
|
|
1021 |
self binaryFileOutLiteralsOn:aStream.
|
|
1022 |
|
|
1023 |
flags storeOn:aStream.
|
|
1024 |
aStream nextPut:$!!.
|
|
1025 |
|
|
1026 |
byteCode size storeOn:aStream.
|
|
1027 |
aStream nextPut:$!!.
|
|
1028 |
aStream nextPutBytes:(byteCode size) from:byteCode
|
|
1029 |
! !
|