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