1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
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 |
|
|
23 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
24 |
All Rights Reserved
|
|
25 |
|
|
26 |
this class defines protocol for executable methods;
|
|
27 |
both compiled and interpreted methods are represented by this class.
|
|
28 |
Compiled code has a non-nil code field, while interpreted methods have
|
|
29 |
a nil code field and non-nil byteCode field.
|
|
30 |
|
|
31 |
The methods source-code is represented by source and sourcePosition:
|
|
32 |
if sourcePosition is a Number, the source-field is the fileName and
|
|
33 |
sourcePosition is the character offset of the source-chunk in this source file.
|
|
34 |
If sourcePosition is nil, the source is the string in the source field.
|
|
35 |
|
|
36 |
The flags field defines things like the number of method-locals,
|
|
37 |
method arguments and stack size need (for interpreted methods).
|
|
38 |
|
|
39 |
WARNING: layout known by compiler and runtime system - dont change
|
|
40 |
|
|
41 |
%W% %E%
|
|
42 |
written spring 89 by claus
|
|
43 |
'!
|
|
44 |
|
|
45 |
!Method methodsFor:'accessing'!
|
|
46 |
|
|
47 |
instVarAt:index
|
|
48 |
"redefined to catch access to code-field - it is a non-object"
|
|
49 |
|
|
50 |
index == 1 ifTrue:[^ nil].
|
|
51 |
^ super instVarAt:index
|
|
52 |
!
|
|
53 |
|
|
54 |
instVarAt:index put:value
|
|
55 |
"redefined to catch access to code-field - it is a non-object"
|
|
56 |
|
|
57 |
index == 1 ifTrue:[^ nil].
|
|
58 |
^ super instVarAt:index put:value
|
|
59 |
!
|
|
60 |
|
|
61 |
code
|
|
62 |
"return code field - since its a non-object return address as integer"
|
|
63 |
%{
|
|
64 |
RETURN ( _MKSMALLINT((int)(_MethodInstPtr(self)->m_code)) );
|
|
65 |
%}
|
|
66 |
!
|
|
67 |
|
|
68 |
code:anAddress
|
|
69 |
"set the code field - you should know what you do if doing this -
|
|
70 |
should only be done by compiler.
|
|
71 |
Smalltalk can crash badly if playing around here ..."
|
|
72 |
%{
|
|
73 |
if (_isSmallInteger(anAddress)) {
|
|
74 |
_MethodInstPtr(self)->m_code = (OBJFUNC)_intVal(anAddress);
|
|
75 |
RETURN ( self );
|
|
76 |
}
|
|
77 |
%}
|
|
78 |
.
|
|
79 |
self primitiveFailed
|
|
80 |
!
|
|
81 |
|
|
82 |
source
|
|
83 |
"return the sourcestring for the receiver"
|
|
84 |
|
|
85 |
|aStream junk|
|
|
86 |
|
|
87 |
source notNil ifTrue:[
|
|
88 |
sourcePosition isNil ifTrue:[^ source].
|
|
89 |
aStream := Smalltalk systemFileStreamFor:('source/' , source).
|
|
90 |
aStream notNil ifTrue:[
|
|
91 |
aStream position:sourcePosition.
|
|
92 |
junk := aStream nextChunk.
|
|
93 |
aStream close
|
|
94 |
]
|
|
95 |
].
|
|
96 |
^ junk
|
|
97 |
!
|
|
98 |
|
|
99 |
source:aString
|
|
100 |
"set the methods sourcestring"
|
|
101 |
|
|
102 |
source := aString.
|
|
103 |
sourcePosition := nil
|
|
104 |
!
|
|
105 |
|
|
106 |
sourceFileName
|
|
107 |
"return the sourcefilename if source is extern; nil otherwise"
|
|
108 |
|
|
109 |
sourcePosition notNil ifTrue:[^ source].
|
|
110 |
^ nil
|
|
111 |
!
|
|
112 |
|
|
113 |
sourcePosition
|
|
114 |
"return the sourceposition if source is extern; nil otherwise"
|
|
115 |
|
|
116 |
^ sourcePosition
|
|
117 |
!
|
|
118 |
|
|
119 |
sourceFileName:aFileName position:aNumber
|
|
120 |
"set the methods sourcefile/position"
|
|
121 |
|
|
122 |
source := aFileName.
|
|
123 |
sourcePosition := aNumber
|
|
124 |
!
|
|
125 |
|
|
126 |
literals
|
|
127 |
"return the methods literal array"
|
|
128 |
|
|
129 |
^ literals
|
|
130 |
!
|
|
131 |
|
|
132 |
literals:anArray
|
|
133 |
"set the methods literal array"
|
|
134 |
|
|
135 |
literals := anArray
|
|
136 |
!
|
|
137 |
|
|
138 |
byteCode
|
|
139 |
"return the methods byteCode array"
|
|
140 |
|
|
141 |
^ byteCode
|
|
142 |
!
|
|
143 |
|
|
144 |
byteCode:aByteArray
|
|
145 |
"set the methods byteCode array"
|
|
146 |
|
|
147 |
byteCode := aByteArray
|
|
148 |
!
|
|
149 |
|
|
150 |
category
|
|
151 |
"return the methods category or nil"
|
|
152 |
|
|
153 |
^ category
|
|
154 |
!
|
|
155 |
|
|
156 |
category:aStringOrSymbol
|
|
157 |
"set the methods category"
|
|
158 |
|
|
159 |
category := aStringOrSymbol asSymbol
|
|
160 |
!
|
|
161 |
|
|
162 |
flags
|
|
163 |
"return the flags (number of method variables, stacksize)"
|
|
164 |
|
|
165 |
^ flags
|
|
166 |
!
|
|
167 |
|
|
168 |
flags:newFlags
|
|
169 |
"set the flags (number of method variables, stacksize)
|
|
170 |
- should only be done by the compiler"
|
|
171 |
|
|
172 |
flags := newFlags
|
|
173 |
!
|
|
174 |
|
|
175 |
numberOfMethodVars:aNumber
|
|
176 |
"set the number of method variables
|
|
177 |
- should only be done by the compiler"
|
|
178 |
|
|
179 |
|newFlags|
|
|
180 |
|
|
181 |
newFlags := flags.
|
|
182 |
%{
|
|
183 |
/* made this a primitive to get define in stc.h */
|
|
184 |
newFlags = _MKSMALLINT((_intVal(newFlags) & ~F_NVARS)
|
|
185 |
| (_intVal(aNumber) << F_NVARSHIFT));
|
|
186 |
%}
|
|
187 |
.
|
|
188 |
flags := newFlags
|
|
189 |
!
|
|
190 |
|
|
191 |
stackSize:aNumber
|
|
192 |
"set the depth of the local stack
|
|
193 |
- should only be done by the compiler"
|
|
194 |
|
|
195 |
|newFlags|
|
|
196 |
|
|
197 |
newFlags := flags.
|
|
198 |
%{
|
|
199 |
/* made this a primitive to get define in stc.h */
|
|
200 |
newFlags = _MKSMALLINT((_intVal(newFlags) & ~F_NSTACK)
|
|
201 |
| (_intVal(aNumber) << F_NSTACKSHIFT));
|
|
202 |
%}
|
|
203 |
.
|
|
204 |
flags := newFlags
|
|
205 |
! !
|
|
206 |
|
|
207 |
!Method methodsFor:'queries'!
|
|
208 |
|
|
209 |
containingClass
|
|
210 |
"return the class I am defined in"
|
|
211 |
|
2
|
212 |
Smalltalk allBehaviorsDo:[:aClass |
|
1
|
213 |
(aClass containsMethod:self) ifTrue:[^ aClass]
|
|
214 |
].
|
|
215 |
^ nil
|
|
216 |
!
|
|
217 |
|
|
218 |
methodArgNames
|
|
219 |
"return a collection with the methods argument names.
|
|
220 |
Uses Parser to parse methods source."
|
|
221 |
|
|
222 |
|parser sourceString|
|
|
223 |
|
|
224 |
sourceString := self source.
|
|
225 |
sourceString notNil ifTrue:[
|
|
226 |
parser := Parser parseMethodSpecification:sourceString.
|
|
227 |
parser isNil ifTrue:[^ nil].
|
|
228 |
^ parser methodArgs
|
|
229 |
].
|
|
230 |
^ nil
|
|
231 |
|
|
232 |
"(Method compiledMethodAt:#printOn:) methodArgNames"
|
|
233 |
!
|
|
234 |
|
|
235 |
methodVarNames
|
|
236 |
"return a collection with the methods local-variable names.
|
|
237 |
Uses Parser to parse methods source."
|
|
238 |
|
|
239 |
|parser sourceString|
|
|
240 |
|
|
241 |
sourceString := self source.
|
|
242 |
sourceString notNil ifTrue:[
|
|
243 |
parser := Parser parseMethodArgAndVarSpecification:sourceString.
|
|
244 |
parser isNil ifTrue:[^ nil].
|
|
245 |
^ parser methodVars
|
|
246 |
].
|
|
247 |
^ nil
|
|
248 |
|
|
249 |
"(Method compiledMethodAt:#printOn:) methodVarNames"
|
|
250 |
!
|
|
251 |
|
|
252 |
methodArgAndVarNames
|
|
253 |
"return a collection with the methods argument and variable names.
|
|
254 |
Uses Parser to parse methods source."
|
|
255 |
|
|
256 |
|parser sourceString argNames varNames|
|
|
257 |
|
|
258 |
sourceString := self source.
|
|
259 |
sourceString notNil ifTrue:[
|
|
260 |
parser := Parser parseMethodArgAndVarSpecification:sourceString.
|
|
261 |
parser isNil ifTrue:[^ nil].
|
|
262 |
argNames := parser methodArgs.
|
|
263 |
varNames := parser methodVars.
|
|
264 |
argNames isNil ifTrue:[^ varNames].
|
|
265 |
varNames isNil ifTrue:[^ argNames].
|
|
266 |
^ (argNames , varNames)
|
|
267 |
].
|
|
268 |
^ nil
|
|
269 |
|
|
270 |
"(Method compiledMethodAt:#printOn:) methodArgAndVarNames"
|
|
271 |
!
|
|
272 |
|
|
273 |
methodComment
|
|
274 |
"return the methods comment, nil if there is none"
|
|
275 |
|
|
276 |
|text line nQuote index qIndex qIndex2 comment|
|
|
277 |
|
|
278 |
text := self source asText.
|
|
279 |
(text size < 2) ifTrue:[^nil].
|
|
280 |
|
|
281 |
line := (text at:2).
|
|
282 |
nQuote := line occurrencesOf:(Character doubleQuote).
|
|
283 |
(nQuote == 2) ifTrue:[
|
|
284 |
qIndex := line indexOf:(Character doubleQuote).
|
|
285 |
qIndex2 := line indexOf:(Character doubleQuote) startingAt:(qIndex + 1).
|
|
286 |
^ line copyFrom:(qIndex + 1) to:(qIndex2 - 1)
|
|
287 |
].
|
|
288 |
(nQuote == 1) ifTrue:[
|
|
289 |
qIndex := line indexOf:(Character doubleQuote).
|
|
290 |
comment := line copyFrom:(qIndex + 1).
|
|
291 |
|
|
292 |
index := 3.
|
|
293 |
line := text at:index.
|
|
294 |
nQuote := line occurrencesOf:(Character doubleQuote).
|
|
295 |
[nQuote ~~ 1] whileTrue:[
|
|
296 |
comment := comment , Character cr asString , line withoutSpaces.
|
|
297 |
index := index + 1.
|
|
298 |
line := text at:index.
|
|
299 |
nQuote := line occurrencesOf:(Character doubleQuote)
|
|
300 |
].
|
|
301 |
qIndex := line indexOf:(Character doubleQuote).
|
|
302 |
^ comment , Character cr asString , (line copyTo:(qIndex - 1)) withoutSpaces
|
|
303 |
].
|
|
304 |
^ nil
|
|
305 |
|
|
306 |
"(Method compiledMethodAt:#methodComment) methodComment"
|
|
307 |
!
|
|
308 |
|
|
309 |
referencesGlobal:aGlobalSymbol
|
|
310 |
"return true, if this method references the global
|
|
311 |
bound to aGlobalSymbol."
|
|
312 |
|
|
313 |
literals isNil ifTrue:[^ false].
|
|
314 |
^ (literals identityIndexOf:aGlobalSymbol startingAt:1) ~~ 0
|
|
315 |
!
|
|
316 |
|
|
317 |
sends:aSelectorSymbol
|
|
318 |
"return true, if this method contains a message-send
|
|
319 |
with aSelectorSymbol as selector.
|
|
320 |
- due to the simple check in the literal array, also simple uses
|
|
321 |
of aSelectorSymbol as symbol will return true."
|
|
322 |
|
|
323 |
^ self referencesGlobal:aSelectorSymbol
|
|
324 |
! !
|
|
325 |
|
|
326 |
!Method methodsFor:'error handling'!
|
|
327 |
|
|
328 |
invalidMethod
|
|
329 |
"this error is triggered by the interpreter when an invalid method
|
|
330 |
is about to be executed.
|
|
331 |
When recompiling classes after a definition-change, all
|
|
332 |
uncompilable methods will be bound to this method here,
|
|
333 |
so that evaluating such an uncompilable method will trigger an error.
|
|
334 |
Can also happen when Compiler/runtime system is broken."
|
|
335 |
|
|
336 |
self error:'invalid method - not executable'
|
|
337 |
!
|
|
338 |
|
|
339 |
invalidByteCode
|
|
340 |
"this error is triggered when the bytecode-interpreter tries to
|
|
341 |
execute an invalid bytecode.
|
|
342 |
Can only happen when Compiler/runtime system is broken."
|
|
343 |
|
|
344 |
self error:'invalid byteCode in method - not executable'
|
|
345 |
!
|
|
346 |
|
|
347 |
receiverNotBoolean
|
|
348 |
"this error is triggered when the bytecode-interpreter tries to
|
|
349 |
execute ifTrue:/ifFalse or whileTrue: type of expressions where the
|
|
350 |
receiver is neither true nor false."
|
|
351 |
|
|
352 |
self error:'if/while on non-boolean receiver'
|
|
353 |
! !
|
|
354 |
|
|
355 |
!Method methodsFor:'executing'!
|
|
356 |
|
|
357 |
valueWithReceiver:anObject arguments:argArray
|
2
|
358 |
"low level call of a methods code - BIG DANGER ALERT.
|
|
359 |
Perform the receiver-method on anObject as receiver and argArray as
|
|
360 |
arguments. This does NO message lookup at all and mimics a
|
|
361 |
traditional function call.
|
1
|
362 |
This method is provided for debugging- and breakpoint-support;
|
|
363 |
not for general use. The receiver must be a method compiled in
|
|
364 |
anObjects class or one of its superclasses
|
|
365 |
- otherwise strange things (and also strange crashes) can occur.
|
|
366 |
Be warned."
|
|
367 |
|
2
|
368 |
|a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12|
|
1
|
369 |
|
|
370 |
%{
|
|
371 |
OBJFUNC code;
|
|
372 |
OBJ searchClass;
|
|
373 |
static struct inlineCache dummy = _DUMMYILC0;
|
2
|
374 |
int nargs;
|
|
375 |
OBJ *ap;
|
|
376 |
|
|
377 |
if (_isArray(argArray)) {
|
|
378 |
nargs = _arraySize(argArray);
|
|
379 |
ap = _ArrayInstPtr(argArray)->a_element;
|
|
380 |
} else {
|
|
381 |
if (argArray == nil) {
|
|
382 |
nargs = 0;
|
|
383 |
} else
|
|
384 |
nargs = -1;
|
|
385 |
}
|
1
|
386 |
|
|
387 |
code = _MethodInstPtr(self)->m_code;
|
|
388 |
searchClass = dummy.ilc_class = _Class(anObject);
|
2
|
389 |
switch (nargs) {
|
1
|
390 |
case 0:
|
|
391 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy) );
|
|
392 |
|
|
393 |
case 1:
|
|
394 |
#ifdef PASS_ARG_REF
|
2
|
395 |
a1 = ap[0];
|
|
396 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1 );
|
1
|
397 |
#else
|
2
|
398 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0]) );
|
1
|
399 |
#endif
|
|
400 |
|
|
401 |
case 2:
|
|
402 |
#ifdef PASS_ARG_REF
|
2
|
403 |
a1 = ap[0];
|
|
404 |
a2 = ap[1];
|
1
|
405 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
406 |
#else
|
2
|
407 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1]) );
|
1
|
408 |
#endif
|
|
409 |
|
|
410 |
case 3:
|
|
411 |
#ifdef PASS_ARG_REF
|
2
|
412 |
a1 = ap[0];
|
|
413 |
a2 = ap[1];
|
|
414 |
a3 = ap[2];
|
1
|
415 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
416 |
#else
|
2
|
417 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2]) );
|
1
|
418 |
#endif
|
|
419 |
|
|
420 |
case 4:
|
|
421 |
#ifdef PASS_ARG_REF
|
2
|
422 |
a1 = ap[0];
|
|
423 |
a2 = ap[1];
|
|
424 |
a3 = ap[2];
|
|
425 |
a4 = ap[3];
|
1
|
426 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
427 |
#else
|
2
|
428 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2], ap[3]) );
|
1
|
429 |
#endif
|
|
430 |
|
|
431 |
case 5:
|
|
432 |
#ifdef PASS_ARG_REF
|
2
|
433 |
a1 = ap[0];
|
|
434 |
a2 = ap[1];
|
|
435 |
a3 = ap[2];
|
|
436 |
a4 = ap[3];
|
|
437 |
a5 = ap[4];
|
1
|
438 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
439 |
#else
|
2
|
440 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2], ap[3], ap[4]) );
|
1
|
441 |
#endif
|
|
442 |
|
|
443 |
case 6:
|
|
444 |
#ifdef PASS_ARG_REF
|
2
|
445 |
a1 = ap[0];
|
|
446 |
a2 = ap[1];
|
|
447 |
a3 = ap[2];
|
|
448 |
a4 = ap[3];
|
|
449 |
a5 = ap[4];
|
|
450 |
a6 = ap[5];
|
1
|
451 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
452 |
#else
|
2
|
453 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2], ap[3], ap[4],
|
|
454 |
ap[5]) );
|
1
|
455 |
#endif
|
|
456 |
|
|
457 |
case 7:
|
|
458 |
#ifdef PASS_ARG_REF
|
2
|
459 |
a1 = ap[0];
|
|
460 |
a2 = ap[1];
|
|
461 |
a3 = ap[2];
|
|
462 |
a4 = ap[3];
|
|
463 |
a5 = ap[4];
|
|
464 |
a6 = ap[5];
|
|
465 |
a7 = ap[6];
|
1
|
466 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
467 |
#else
|
2
|
468 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2], ap[3], ap[4],
|
|
469 |
ap[5], ap[6]) );
|
1
|
470 |
#endif
|
|
471 |
|
|
472 |
case 8:
|
|
473 |
#ifdef PASS_ARG_REF
|
2
|
474 |
a1 = ap[0];
|
|
475 |
a2 = ap[1];
|
|
476 |
a3 = ap[2];
|
|
477 |
a4 = ap[3];
|
|
478 |
a5 = ap[4];
|
|
479 |
a6 = ap[5];
|
|
480 |
a7 = ap[6];
|
|
481 |
a8 = ap[7];
|
1
|
482 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
483 |
#else
|
2
|
484 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2], ap[3], ap[4],
|
|
485 |
ap[5], ap[6], ap[7]) );
|
1
|
486 |
#endif
|
|
487 |
|
|
488 |
case 9:
|
|
489 |
#ifdef PASS_ARG_REF
|
2
|
490 |
a1 = ap[0];
|
|
491 |
a2 = ap[1];
|
|
492 |
a3 = ap[2];
|
|
493 |
a4 = ap[3];
|
|
494 |
a5 = ap[4];
|
|
495 |
a6 = ap[5];
|
|
496 |
a7 = ap[6];
|
|
497 |
a8 = ap[7];
|
|
498 |
a9 = ap[8];
|
1
|
499 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
500 |
#else
|
2
|
501 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2], ap[3], ap[4],
|
|
502 |
ap[5], ap[6], ap[7], ap[8]) );
|
1
|
503 |
#endif
|
|
504 |
|
|
505 |
case 10:
|
|
506 |
#ifdef PASS_ARG_REF
|
2
|
507 |
a1 = ap[0];
|
|
508 |
a2 = ap[1];
|
|
509 |
a3 = ap[2];
|
|
510 |
a4 = ap[3];
|
|
511 |
a5 = ap[4];
|
|
512 |
a6 = ap[5];
|
|
513 |
a7 = ap[6];
|
|
514 |
a8 = ap[7];
|
|
515 |
a9 = ap[8];
|
|
516 |
a10 = ap[9];
|
1
|
517 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
518 |
#else
|
2
|
519 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2], ap[3], ap[4],
|
|
520 |
ap[5], ap[6], ap[7], ap[8], ap[9]) );
|
1
|
521 |
#endif
|
|
522 |
|
|
523 |
case 11:
|
|
524 |
#ifdef PASS_ARG_REF
|
2
|
525 |
a1 = ap[0];
|
|
526 |
a2 = ap[1];
|
|
527 |
a3 = ap[2];
|
|
528 |
a4 = ap[3];
|
|
529 |
a5 = ap[4];
|
|
530 |
a6 = ap[5];
|
|
531 |
a7 = ap[6];
|
|
532 |
a8 = ap[7];
|
|
533 |
a9 = ap[8];
|
|
534 |
a10 = ap[9];
|
|
535 |
a11 = ap[10];
|
1
|
536 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
537 |
#else
|
2
|
538 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2], ap[3], ap[4],
|
|
539 |
ap[5], ap[6], ap[7], ap[8], ap[9],
|
|
540 |
ap[10]) );
|
1
|
541 |
#endif
|
|
542 |
|
|
543 |
case 12:
|
|
544 |
#ifdef PASS_ARG_REF
|
2
|
545 |
a1 = ap[0];
|
|
546 |
a2 = ap[1];
|
|
547 |
a3 = ap[2];
|
|
548 |
a4 = ap[3];
|
|
549 |
a5 = ap[4];
|
|
550 |
a6 = ap[5];
|
|
551 |
a7 = ap[6];
|
|
552 |
a8 = ap[7];
|
|
553 |
a9 = ap[8];
|
|
554 |
a10 = ap[9];
|
|
555 |
a11 = ap[10];
|
|
556 |
a12 = ap[11];
|
1
|
557 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, &a1) );
|
|
558 |
#else
|
2
|
559 |
RETURN ( (*code)(anObject, nil, SND_COMMA searchClass, &dummy, ap[0], ap[1], ap[2], ap[3], ap[4],
|
|
560 |
ap[5], ap[6], ap[7], ap[8], ap[9],
|
|
561 |
ap[10], ap[11]) );
|
1
|
562 |
#endif
|
|
563 |
}
|
|
564 |
%}
|
2
|
565 |
.
|
|
566 |
(argArray isMemberOf:Array) ifFalse:[
|
|
567 |
^ self error:'argumentArray must be an Array'
|
|
568 |
].
|
|
569 |
^ self error:'too many arguments'
|
|
570 |
|
1
|
571 |
"(String compiledMethodAt:#print) valueWithReceiver:'hello' arguments:#()"
|
|
572 |
"(Float compiledMethodAt:#+) valueWithReceiver:1.0 arguments:#(2.0)"
|
2
|
573 |
"the next example is a wrong one - but will not crash the system ..."
|
|
574 |
"(True compiledMethodAt:#printString) valueWithReceiver:false arguments:nil"
|
1
|
575 |
! !
|
|
576 |
|
|
577 |
!Method methodsFor:'printing'!
|
|
578 |
|
|
579 |
printOn:aStream
|
|
580 |
"put a printed representation of the receiver onto aStream"
|
|
581 |
|
|
582 |
|homeClass|
|
|
583 |
|
|
584 |
homeClass := self containingClass.
|
|
585 |
homeClass notNil ifTrue:[
|
|
586 |
aStream nextPutAll:'a Method in '.
|
|
587 |
homeClass name printOn:aStream.
|
|
588 |
aStream nextPutAll:' '.
|
|
589 |
(homeClass selectorForMethod:self) printOn:aStream
|
|
590 |
] ifFalse:[
|
|
591 |
aStream nextPutAll:'a Method'
|
|
592 |
]
|
|
593 |
! !
|
|
594 |
|
|
595 |
!Method methodsFor:'binary fileOut'!
|
|
596 |
|
|
597 |
binaryFileOutLiteralsOn:aStream
|
|
598 |
|index n|
|
|
599 |
|
|
600 |
literals isNil ifTrue:[
|
|
601 |
aStream nextPutAll:'0'.
|
|
602 |
aStream nextPut:$!!.
|
|
603 |
^ self
|
|
604 |
].
|
|
605 |
aStream nextPutAll:literals size printString.
|
|
606 |
aStream nextPut:$!!.
|
|
607 |
|
|
608 |
index := 1.
|
|
609 |
literals do:[:lit |
|
|
610 |
(lit isKindOf:Number) ifTrue:[
|
|
611 |
lit storeOn:aStream
|
|
612 |
] ifFalse:[
|
|
613 |
((lit isKindOf:String) or:[lit isKindOf:Character]) ifTrue:[
|
|
614 |
lit storeOn:aStream
|
|
615 |
] ifFalse:[
|
|
616 |
(lit isKindOf:Array) ifTrue:[
|
|
617 |
aStream nextPut:$(.
|
|
618 |
lit storeOn:aStream.
|
|
619 |
aStream nextPut:$)
|
|
620 |
] ifFalse:[
|
|
621 |
(lit isBehavior "isKindOf:Class") ifTrue:[
|
|
622 |
aStream nextPutAll:'(Smalltalk at:#'.
|
|
623 |
n := lit name.
|
|
624 |
(lit isMeta "isKindOf:Metaclass") ifTrue:[
|
|
625 |
n := (n copyFrom:1 to:(n size - 5)) , ') class'
|
|
626 |
] ifFalse:[
|
|
627 |
n := n , ')'
|
|
628 |
].
|
|
629 |
aStream nextPutAll:n
|
|
630 |
] ifFalse:[
|
|
631 |
self error:('invalid literal ' , lit class name)
|
|
632 |
]
|
|
633 |
]
|
|
634 |
]
|
|
635 |
].
|
|
636 |
aStream nextPut:$!!.
|
|
637 |
index := index + 1
|
|
638 |
]
|
|
639 |
!
|
|
640 |
|
|
641 |
binaryFileOutOn:aStream
|
|
642 |
byteCode isNil ifTrue:[
|
|
643 |
self notify:'no bytecodes to fileout'.
|
|
644 |
^ self
|
|
645 |
].
|
|
646 |
self binaryFileOutLiteralsOn:aStream.
|
|
647 |
|
|
648 |
flags storeOn:aStream.
|
|
649 |
aStream nextPut:$!!.
|
|
650 |
|
|
651 |
byteCode size storeOn:aStream.
|
|
652 |
aStream nextPut:$!!.
|
|
653 |
aStream nextPutBytes:(byteCode size) from:byteCode
|
|
654 |
! !
|