0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
45
|
3 |
All Rights Reserved
|
0
|
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 |
Parser subclass:#ByteCodeCompiler
|
49
|
14 |
instanceVariableNames:'codeBytes codeIndex
|
45
|
15 |
litArray
|
|
16 |
stackDelta extra lineno
|
|
17 |
maxStackDepth
|
|
18 |
relocList'
|
124
|
19 |
classVariableNames:'JumpToAbsJump SequenceNumber
|
|
20 |
STCCompilationDefines STCCompilationIncludes STCCompilationOptions
|
120
|
21 |
STCCompilation KeepSource STCKeepCIntermediate'
|
0
|
22 |
poolDictionaries:''
|
|
23 |
category:'System-Compiler'
|
|
24 |
!
|
|
25 |
|
|
26 |
ByteCodeCompiler comment:'
|
4
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
45
|
28 |
All Rights Reserved
|
25
|
29 |
|
126
|
30 |
$Header: /cvs/stx/stx/libcomp/ByteCodeCompiler.st,v 1.43 1995-10-24 15:54:48 cg Exp $
|
3
|
31 |
'!
|
|
32 |
|
|
33 |
!ByteCodeCompiler class methodsFor:'documentation'!
|
|
34 |
|
20
|
35 |
copyright
|
|
36 |
"
|
|
37 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
45
|
38 |
All Rights Reserved
|
20
|
39 |
|
|
40 |
This software is furnished under a license and may be used
|
|
41 |
only in accordance with the terms of that license and with the
|
|
42 |
inclusion of the above copyright notice. This software may not
|
|
43 |
be provided or otherwise made available to, or used by, any
|
|
44 |
other person. No title to or ownership of the software is
|
|
45 |
hereby transferred.
|
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
version
|
|
50 |
"
|
126
|
51 |
$Header: /cvs/stx/stx/libcomp/ByteCodeCompiler.st,v 1.43 1995-10-24 15:54:48 cg Exp $
|
20
|
52 |
"
|
|
53 |
!
|
|
54 |
|
3
|
55 |
documentation
|
|
56 |
"
|
19
|
57 |
This class performs compilation into ByteCodes.
|
|
58 |
First, parsing is done using superclass methods,
|
|
59 |
then the parse-tree is converted into an array of symbolic codes
|
|
60 |
and a relocation table;
|
|
61 |
these two are finally combined into a byteArray of the codes.
|
0
|
62 |
|
19
|
63 |
(the intermediate step through symbolic codes is for debugging
|
|
64 |
only - it will vanish)
|
|
65 |
|
|
66 |
There are many dependencies to the run-time-system (especially the
|
|
67 |
interpreter) in here - be careful when playing around ...
|
0
|
68 |
|
19
|
69 |
Instance variables:
|
0
|
70 |
|
49
|
71 |
codeBytes <ByteArry> bytecodes
|
45
|
72 |
codeIndex <SmallInteger> next index to put into code array
|
|
73 |
litArray <OrderedCollection> literals
|
|
74 |
stackDelta <SmallInteger> return value of byteCodeFor:
|
|
75 |
extra <Symbol> return value of byteCodeFor:
|
|
76 |
lineno <Boolean> return value of byteCodeFor:
|
|
77 |
maxStackDepth <SmallInteger> stack need of method
|
|
78 |
relocList <Array> used temporary for relocation
|
19
|
79 |
|
|
80 |
Class variables:
|
|
81 |
|
45
|
82 |
JumpToAbsJump <Dictionary> internal table to map opcodes
|
3
|
83 |
"
|
|
84 |
! !
|
0
|
85 |
|
98
|
86 |
!ByteCodeCompiler methodsFor:'ST-80 compatibility'!
|
0
|
87 |
|
98
|
88 |
compile:textOrStream in:aClass notifying:requestor ifFail:exceptionBlock
|
85
|
89 |
"name alias for ST-80 compatibility"
|
|
90 |
|
98
|
91 |
^ self class
|
|
92 |
compile:textOrStream
|
|
93 |
in:aClass
|
|
94 |
notifying:requestor
|
|
95 |
ifFail:exceptionBlock
|
|
96 |
"/ |m|
|
|
97 |
"/
|
|
98 |
"/ m := self class
|
|
99 |
"/ compile:textOrStream
|
|
100 |
"/ forClass:aClass
|
|
101 |
"/ inCategory:'no category'
|
|
102 |
"/ notifying:requestor
|
|
103 |
"/ install:true
|
|
104 |
"/ skipIfSame:false
|
|
105 |
"/ silent:false.
|
|
106 |
"/ m == #Error ifTrue:[
|
|
107 |
"/ ^ exceptionBlock value
|
|
108 |
"/ ].
|
|
109 |
"/ ^ m
|
|
110 |
! !
|
|
111 |
|
|
112 |
!ByteCodeCompiler class methodsFor:'compiling methods'!
|
|
113 |
|
|
114 |
compile:textOrStream in:aClass notifying:requestor ifFail:exceptionBlock
|
|
115 |
"name alias for ST-80 compatibility"
|
|
116 |
|
|
117 |
|m|
|
|
118 |
|
|
119 |
m := self
|
|
120 |
compile:textOrStream
|
85
|
121 |
forClass:aClass
|
|
122 |
inCategory:'others'
|
98
|
123 |
notifying:requestor
|
85
|
124 |
install:true
|
|
125 |
skipIfSame:false
|
98
|
126 |
silent:false.
|
|
127 |
m == #Error ifTrue:[
|
|
128 |
^ exceptionBlock value
|
|
129 |
].
|
|
130 |
^ m
|
|
131 |
|
85
|
132 |
!
|
|
133 |
|
0
|
134 |
compile:methodText forClass:classToCompileFor
|
|
135 |
"compile a source-string for a method in classToCompileFor"
|
|
136 |
|
|
137 |
^ self compile:methodText
|
45
|
138 |
forClass:classToCompileFor
|
|
139 |
inCategory:'others'
|
|
140 |
notifying:nil
|
|
141 |
install:true
|
|
142 |
skipIfSame:false
|
|
143 |
silent:false
|
0
|
144 |
!
|
|
145 |
|
|
146 |
compile:aString forClass:aClass inCategory:cat
|
|
147 |
"compile a source-string for a method in classToCompileFor.
|
|
148 |
The method will get cat as category"
|
|
149 |
|
|
150 |
^ self compile:aString
|
45
|
151 |
forClass:aClass
|
|
152 |
inCategory:cat
|
|
153 |
notifying:nil
|
|
154 |
install:true
|
|
155 |
skipIfSame:false
|
|
156 |
silent:false
|
0
|
157 |
!
|
|
158 |
|
84
|
159 |
compile:methodText forClass:classToCompileFor notifying:requestor
|
0
|
160 |
"compile a source-string for a method in classToCompileFor.
|
84
|
161 |
Errors are forwarded to requestor."
|
0
|
162 |
|
|
163 |
^ self compile:methodText
|
45
|
164 |
forClass:classToCompileFor
|
|
165 |
inCategory:'others'
|
84
|
166 |
notifying:requestor
|
45
|
167 |
install:true
|
|
168 |
skipIfSame:false
|
|
169 |
silent:false
|
0
|
170 |
!
|
|
171 |
|
84
|
172 |
compile:aString forClass:aClass inCategory:cat notifying:requestor
|
0
|
173 |
"compile a source-string for a method in classToCompileFor.
|
84
|
174 |
errors are forwarded to requestor.
|
0
|
175 |
The method will get cat as category"
|
|
176 |
|
|
177 |
^ self compile:aString
|
45
|
178 |
forClass:aClass
|
|
179 |
inCategory:cat
|
84
|
180 |
notifying:requestor
|
45
|
181 |
install:true
|
|
182 |
skipIfSame:false
|
|
183 |
silent:false
|
0
|
184 |
!
|
|
185 |
|
84
|
186 |
compile:aString forClass:aClass inCategory:cat notifying:requestor install:install
|
20
|
187 |
"compile a source-string for a method in classToCompileFor.
|
|
188 |
The install-argument controls if the method is to be installed into the
|
|
189 |
classes method-dictionary, or just to be compiled and a method object to be returned.
|
84
|
190 |
Errors are forwarded to requestor. The method will get cat as category"
|
20
|
191 |
|
0
|
192 |
^ self compile:aString
|
45
|
193 |
forClass:aClass
|
|
194 |
inCategory:cat
|
84
|
195 |
notifying:requestor
|
54
|
196 |
install:install
|
45
|
197 |
skipIfSame:false
|
|
198 |
silent:false
|
0
|
199 |
!
|
|
200 |
|
84
|
201 |
compile:aString forClass:aClass inCategory:cat notifying:requestor
|
45
|
202 |
install:install skipIfSame:skipIfSame
|
20
|
203 |
"compile a source-string for a method in classToCompileFor.
|
|
204 |
The install-argument controls if the method is to be installed into the
|
|
205 |
classes method-dictionary, or just to be compiled and a method object to be returned.
|
84
|
206 |
Errors are forwarded to requestor. The method will get cat as category.
|
20
|
207 |
If skipIsSame is true, and the source is the same as an existing
|
|
208 |
methods source, this is a noop (for fast fileIn)."
|
0
|
209 |
|
20
|
210 |
^ self compile:aString
|
45
|
211 |
forClass:aClass
|
|
212 |
inCategory:cat
|
84
|
213 |
notifying:requestor
|
54
|
214 |
install:install
|
45
|
215 |
skipIfSame:skipIfSame
|
|
216 |
silent:false
|
20
|
217 |
!
|
|
218 |
|
84
|
219 |
compile:aString forClass:aClass inCategory:cat notifying:requestor
|
45
|
220 |
install:install skipIfSame:skipIfSame silent:silent
|
20
|
221 |
|
|
222 |
"the basic workhorse method for compiling:
|
0
|
223 |
compile a source-string for a method in classToCompileFor.
|
84
|
224 |
errors are forwarded to requestor (report on Transcript and return
|
|
225 |
#Error, if requestor is nil).
|
0
|
226 |
|
20
|
227 |
The new method will get cat as category.
|
|
228 |
If install is true, the method will go into the classes method-table,
|
|
229 |
otherwise the method is simply returned (for anonymous methods).
|
0
|
230 |
If skipIsSame is true, and the source is the same as an existing
|
20
|
231 |
methods source, this is a noop (for fast fileIn).
|
|
232 |
The argument, silent controls if errors are to be reported."
|
0
|
233 |
|
54
|
234 |
|compiler newMethod tree lits symbolicCodeArray oldMethod lazy silencio
|
90
|
235 |
sourceFile sourceStream newSource primNr pos sel|
|
0
|
236 |
|
|
237 |
aString isNil ifTrue:[^ nil].
|
54
|
238 |
silencio := silent or:[Smalltalk silentLoading == true].
|
0
|
239 |
|
19
|
240 |
"lazy compilation is EXPERIMENTAL"
|
|
241 |
lazy := (LazyCompilation == true) and:[install].
|
|
242 |
|
0
|
243 |
"create a compiler, let it parse and create the parsetree"
|
|
244 |
|
54
|
245 |
compiler := self for:(ReadStream on:aString) in:aClass.
|
84
|
246 |
compiler parseForCode.
|
|
247 |
compiler notifying:requestor.
|
54
|
248 |
silent ifTrue:[
|
|
249 |
"/ compiler ignoreErrors.
|
|
250 |
compiler ignoreWarnings
|
|
251 |
].
|
0
|
252 |
compiler nextToken.
|
|
253 |
(compiler parseMethodSpec == #Error) ifTrue:[
|
45
|
254 |
tree := #Error
|
0
|
255 |
] ifFalse:[
|
45
|
256 |
"check if same source"
|
90
|
257 |
(skipIfSame and:[(sel := compiler selector) notNil]) ifTrue:[
|
|
258 |
oldMethod := aClass compiledMethodAt:sel.
|
45
|
259 |
oldMethod notNil ifTrue:[
|
|
260 |
oldMethod source = aString ifTrue:[
|
|
261 |
oldMethod isInvalid ifFalse:[
|
54
|
262 |
silencio ifFalse:[
|
84
|
263 |
Transcript showCr:(' unchanged: ',aClass name,' ',compiler selector)
|
45
|
264 |
].
|
49
|
265 |
"
|
|
266 |
same. however, category may be different
|
|
267 |
"
|
|
268 |
(cat notNil and:[cat ~~ oldMethod category]) ifTrue:[
|
|
269 |
oldMethod category:cat.
|
|
270 |
oldMethod changed:#category.
|
|
271 |
aClass addChangeRecordForMethodCategory:oldMethod category:cat.
|
|
272 |
].
|
45
|
273 |
^ oldMethod
|
|
274 |
]
|
|
275 |
]
|
|
276 |
]
|
|
277 |
].
|
|
278 |
lazy ifFalse:[
|
|
279 |
tree := compiler parseMethodBody.
|
|
280 |
compiler tree:tree.
|
|
281 |
]
|
0
|
282 |
].
|
|
283 |
|
90
|
284 |
sel := compiler selector.
|
0
|
285 |
(compiler errorFlag or:[tree == #Error]) ifTrue:[
|
45
|
286 |
"/ compiler parseError:'syntax error'.
|
84
|
287 |
Transcript show:' '.
|
101
|
288 |
aClass notNil ifTrue:[
|
|
289 |
Transcript show:aClass name , '>>'
|
|
290 |
].
|
90
|
291 |
sel notNil ifTrue:[
|
101
|
292 |
Transcript show:(sel)
|
45
|
293 |
].
|
101
|
294 |
Transcript showCr:' -> Error'.
|
45
|
295 |
^ #Error
|
0
|
296 |
].
|
|
297 |
|
19
|
298 |
"if no error and also no selector ..."
|
90
|
299 |
sel isNil ifTrue:[
|
45
|
300 |
"... it was just a comment or other empty stuff"
|
|
301 |
^ nil
|
0
|
302 |
].
|
|
303 |
|
54
|
304 |
"
|
|
305 |
freak-out support ...
|
|
306 |
"
|
126
|
307 |
(compiler hasNonOptionalPrimitiveCode
|
|
308 |
or:[(compiler hasPrimitiveCode and:[self canCreateMachineCode])
|
|
309 |
or:[STCCompilation == #always and:[sel ~~ #doIt]]]) ifTrue:[
|
97
|
310 |
newMethod := compiler
|
|
311 |
compileToMachineCode:aString
|
|
312 |
forClass:aClass
|
|
313 |
inCategory:cat
|
|
314 |
notifying:requestor
|
|
315 |
install:install
|
|
316 |
skipIfSame:skipIfSame
|
|
317 |
silent:silent.
|
|
318 |
|
|
319 |
newMethod ==#Error ifTrue:[
|
|
320 |
newMethod := compiler trappingStubMethodFor:aString inCategory:cat.
|
|
321 |
install ifTrue:[
|
|
322 |
aClass addSelector:sel withMethod:newMethod
|
|
323 |
].
|
118
|
324 |
Transcript show:'*** '.
|
97
|
325 |
sel notNil ifTrue:[
|
|
326 |
Transcript show:(sel ,' ')
|
|
327 |
].
|
|
328 |
Transcript showCr:'not compiled to machine code - created a stub instead.'.
|
|
329 |
].
|
|
330 |
^ newMethod
|
19
|
331 |
].
|
|
332 |
|
54
|
333 |
"
|
|
334 |
EXPERIMENTAL: quick loading
|
|
335 |
only create a lazyMethod, which has no byteCode and will
|
|
336 |
compile itself when first called.
|
|
337 |
"
|
19
|
338 |
lazy ifTrue:[
|
45
|
339 |
newMethod := LazyMethod new.
|
54
|
340 |
KeepSource == false ifTrue:[
|
|
341 |
sourceFile := ObjectMemory nameForSources.
|
|
342 |
sourceStream := sourceFile asFilename appendingWriteStream.
|
|
343 |
].
|
|
344 |
sourceStream isNil ifTrue:[
|
|
345 |
newMethod source:aString.
|
|
346 |
] ifFalse:[
|
|
347 |
sourceStream setToEnd.
|
|
348 |
pos := sourceStream position.
|
|
349 |
sourceStream nextChunkPut:aString.
|
|
350 |
sourceStream close.
|
|
351 |
newMethod sourceFilename:sourceFile position:pos.
|
|
352 |
].
|
45
|
353 |
newMethod category:cat.
|
54
|
354 |
Project notNil ifTrue:[
|
98
|
355 |
newMethod package:(Project currentPackageName)
|
54
|
356 |
].
|
19
|
357 |
|
90
|
358 |
aClass addSelector:sel withLazyMethod:newMethod.
|
45
|
359 |
^ newMethod
|
19
|
360 |
].
|
|
361 |
|
90
|
362 |
(primNr := compiler primitiveNumber) isNil ifTrue:[
|
78
|
363 |
"
|
|
364 |
produce symbolic code first
|
|
365 |
"
|
|
366 |
symbolicCodeArray := compiler genSymbolicCode.
|
90
|
367 |
|
78
|
368 |
(symbolicCodeArray == #Error) ifTrue:[
|
84
|
369 |
Transcript show:' '.
|
90
|
370 |
sel notNil ifTrue:[
|
|
371 |
Transcript show:(sel ,' ')
|
78
|
372 |
].
|
|
373 |
Transcript showCr:'translation error'.
|
|
374 |
^ #Error
|
45
|
375 |
].
|
0
|
376 |
|
78
|
377 |
"
|
|
378 |
take this, producing bytecode
|
|
379 |
(someone willin' to make machine code :-)
|
|
380 |
"
|
|
381 |
((compiler genByteCodeFrom:symbolicCodeArray) == #Error) ifTrue:[
|
84
|
382 |
Transcript show:' '.
|
90
|
383 |
sel notNil ifTrue:[
|
|
384 |
Transcript show:(sel ,' ')
|
78
|
385 |
].
|
|
386 |
Transcript showCr:'relocation error - must be simplified'.
|
|
387 |
^ #Error
|
45
|
388 |
].
|
0
|
389 |
].
|
|
390 |
|
54
|
391 |
"
|
|
392 |
finally create the new method-object
|
|
393 |
"
|
0
|
394 |
newMethod := Method new.
|
|
395 |
lits := compiler literalArray.
|
|
396 |
lits notNil ifTrue:[
|
45
|
397 |
"literals MUST be an array - not just any Collection"
|
|
398 |
lits := Array withAll:lits.
|
|
399 |
newMethod literals:lits
|
0
|
400 |
].
|
90
|
401 |
primNr notNil ifTrue:[
|
|
402 |
newMethod code:(compiler checkForPrimitiveCode:primNr).
|
78
|
403 |
] ifFalse:[
|
|
404 |
newMethod byteCode:(compiler code).
|
|
405 |
].
|
54
|
406 |
newMethod numberOfMethodVars:(compiler numberOfMethodVars).
|
|
407 |
newMethod numberOfMethodArgs:(compiler numberOfMethodArgs).
|
|
408 |
newMethod stackSize:(compiler maxStackDepth).
|
19
|
409 |
|
54
|
410 |
"
|
|
411 |
if there where any corrections, install the updated source
|
|
412 |
"
|
90
|
413 |
(newSource := compiler correctedSource) notNil ifTrue:[
|
|
414 |
newMethod source:newSource
|
19
|
415 |
] ifFalse:[
|
45
|
416 |
newMethod source:aString.
|
19
|
417 |
].
|
0
|
418 |
newMethod category:cat.
|
54
|
419 |
Project notNil ifTrue:[
|
98
|
420 |
newMethod package:(Project currentPackageName)
|
54
|
421 |
].
|
0
|
422 |
|
|
423 |
install ifTrue:[
|
90
|
424 |
aClass addSelector:sel withMethod:newMethod
|
0
|
425 |
].
|
|
426 |
|
54
|
427 |
silencio ifFalse:[
|
90
|
428 |
Transcript showCr:(' compiled: ', aClass name,' ', sel)
|
0
|
429 |
].
|
|
430 |
|
|
431 |
^ newMethod
|
|
432 |
! !
|
|
433 |
|
15
|
434 |
!ByteCodeCompiler class methodsFor:'constants'!
|
|
435 |
|
|
436 |
byteCodeFor:aSymbol
|
|
437 |
"only some exported codes handled here (for BlockNode)"
|
|
438 |
|
25
|
439 |
(aSymbol == #retNil) ifTrue:[^ 1].
|
|
440 |
(aSymbol == #retTrue) ifTrue:[^ 2].
|
|
441 |
(aSymbol == #retFalse) ifTrue:[^ 3].
|
|
442 |
(aSymbol == #ret0) ifTrue:[^ 4].
|
|
443 |
(aSymbol == #retTop) ifTrue:[^ 0].
|
|
444 |
|
15
|
445 |
(aSymbol == #push0) ifTrue:[^120].
|
|
446 |
(aSymbol == #push1) ifTrue:[^121].
|
|
447 |
(aSymbol == #push2) ifTrue:[^139].
|
|
448 |
(aSymbol == #pushMinus1) ifTrue:[^122].
|
|
449 |
(aSymbol == #pushNil) ifTrue:[^ 10].
|
|
450 |
(aSymbol == #pushTrue) ifTrue:[^ 11].
|
|
451 |
(aSymbol == #pushFalse) ifTrue:[^ 12].
|
|
452 |
(aSymbol == #pushSelf) ifTrue:[^ 15].
|
|
453 |
self error
|
|
454 |
! !
|
|
455 |
|
54
|
456 |
!ByteCodeCompiler class methodsFor:'stc compilation defaults'!
|
|
457 |
|
124
|
458 |
stcCompilationIncludes:aString
|
|
459 |
"define the include directories via additional -I flags.
|
|
460 |
These are passed to stc. Can be set in your private.rc file"
|
|
461 |
|
|
462 |
STCCompilationIncludes := aString
|
|
463 |
|
|
464 |
"
|
|
465 |
Compiler stcCompilationIncludes:'-I/usr/local/include -I../../include'
|
125
|
466 |
Compiler stcCompilationIncludes:(Compiler stcCompilationIncludes , ' -I../../libxt')
|
124
|
467 |
"
|
|
468 |
!
|
54
|
469 |
|
124
|
470 |
stcCompilationIncludes
|
|
471 |
"return the includes used with stc compilation"
|
|
472 |
|
|
473 |
^ STCCompilationIncludes
|
|
474 |
!
|
|
475 |
|
|
476 |
stcCompilationDefines:aString
|
|
477 |
"define the flags (for example, additional -D defines)
|
|
478 |
to be used when compiling to machine code.
|
|
479 |
These are passed to stc. Can be set from your private.rc file."
|
|
480 |
|
|
481 |
STCCompilationDefines := aString
|
54
|
482 |
|
|
483 |
"
|
124
|
484 |
Compiler stcCompilationDefines:'-DVGL -DDEBUG'
|
54
|
485 |
"
|
|
486 |
!
|
|
487 |
|
124
|
488 |
stcCompilationDefines
|
|
489 |
"return the defines used with stc compilation"
|
|
490 |
|
|
491 |
^ STCCompilationDefines
|
|
492 |
!
|
|
493 |
|
|
494 |
stcCompilationOptions:aString
|
|
495 |
"define the compilation options
|
|
496 |
to be used when compiling to machine code.
|
|
497 |
These are passed to stc. Can be set from your private.rc file."
|
|
498 |
|
|
499 |
STCCompilationOptions := aString
|
|
500 |
|
|
501 |
"
|
|
502 |
Compiler stcCompilationOptions:'+optinline'
|
|
503 |
"
|
|
504 |
!
|
|
505 |
|
|
506 |
stcCompilationOptions
|
|
507 |
"return the options used with stc compilation"
|
|
508 |
|
|
509 |
^ STCCompilationOptions
|
|
510 |
!
|
|
511 |
|
101
|
512 |
stcCompilation
|
|
513 |
"return the flag which controls compilation to machine code.
|
|
514 |
If #always, methods are always compiled to machine code (which takes
|
|
515 |
longer, but provides faster code). If #none, methods are never compiled
|
|
516 |
to machine code, instead for non-primitive ones, compilation is to bytecode
|
|
517 |
and for primitive ones, a trapping stub is generated.
|
|
518 |
Anything else lets the compiler compile to bytecode,
|
|
519 |
except for methods containing primitive code.
|
|
520 |
This can be set from your private.rc file or from a workspace
|
|
521 |
for selective compilation to machine code."
|
|
522 |
|
|
523 |
^ STCCompilation
|
|
524 |
|
|
525 |
"
|
|
526 |
Compiler stcCompilation
|
|
527 |
"
|
|
528 |
!
|
|
529 |
|
|
530 |
stcCompilation:how
|
|
531 |
"set the flag which controls compilation to machine code.
|
|
532 |
If #always, methods are always compiled to machine code (which takes
|
|
533 |
longer, but provides faster code). If #none, methods are never compiled
|
|
534 |
to machine code, instead for non-primitive ones, compilation is to bytecode
|
|
535 |
and for primitive ones, a trapping stub is generated.
|
|
536 |
Anything else lets the compiler compile to bytecode,
|
|
537 |
except for methods containing primitive code.
|
54
|
538 |
This can be set from your private.rc file or from a workspace
|
|
539 |
for selective compilation to machine code."
|
|
540 |
|
109
|
541 |
|ret|
|
|
542 |
|
|
543 |
ret := STCCompilation.
|
|
544 |
STCCompilation := how.
|
|
545 |
^ ret
|
54
|
546 |
|
|
547 |
"
|
101
|
548 |
Compiler stcCompilation:#always
|
|
549 |
Compiler stcCompilation:#never
|
|
550 |
Compiler stcCompilation:#default
|
54
|
551 |
"
|
|
552 |
!
|
|
553 |
|
120
|
554 |
stcPathOf:command
|
|
555 |
"return the path to an stc command, or nil if not found."
|
101
|
556 |
|
|
557 |
|f|
|
97
|
558 |
|
120
|
559 |
((f := '../../stc' asFilename construct:command)) isExecutable ifTrue:[
|
101
|
560 |
^ f pathName
|
|
561 |
].
|
126
|
562 |
^ OperatingSystem pathOfCommand:command
|
97
|
563 |
|
|
564 |
"
|
120
|
565 |
Compiler stcPathOf:'stc'
|
|
566 |
"
|
|
567 |
|
|
568 |
"Created: 13.9.1995 / 14:37:16 / claus"
|
|
569 |
!
|
|
570 |
|
|
571 |
stcPath
|
|
572 |
"return the path to the stc command, or nil if not found."
|
|
573 |
|
|
574 |
^ self stcPathOf:'stc'
|
|
575 |
|
|
576 |
"
|
101
|
577 |
Compiler stcPath
|
|
578 |
"
|
120
|
579 |
|
|
580 |
"Modified: 13.9.1995 / 14:37:26 / claus"
|
|
581 |
!
|
|
582 |
|
|
583 |
incrementalStcPath
|
|
584 |
"return the path to the stc command for incremental method compilation,
|
|
585 |
or nil if not found."
|
|
586 |
|
|
587 |
|f|
|
|
588 |
|
|
589 |
(f := self stcPathOf:'stc') notNil ifTrue:[^ f].
|
|
590 |
^ self stcPathOf:'demostc'
|
|
591 |
|
|
592 |
"
|
|
593 |
Compiler incrementalStcPath
|
|
594 |
"
|
|
595 |
|
|
596 |
"Created: 13.9.1995 / 14:36:36 / claus"
|
|
597 |
"Modified: 13.9.1995 / 15:15:04 / claus"
|
101
|
598 |
!
|
|
599 |
|
|
600 |
canCreateMachineCode
|
|
601 |
"return true, if compilation to machine code is supported.
|
118
|
602 |
Currently, all SYSV4 and Linux systems do so;
|
|
603 |
REAL/IX, AIX and HPUX do not (due to the need for dynamic loading
|
|
604 |
of object files, which is not supported by those).
|
|
605 |
MIPS ULTRIX is almost finished, but not yet released.
|
101
|
606 |
|
|
607 |
However, if no compiler is around (i.e. the demo distribution),
|
|
608 |
there is no chance ..."
|
|
609 |
|
|
610 |
|canDo|
|
|
611 |
|
106
|
612 |
ObjectFileLoader isNil ifTrue:[^ false].
|
118
|
613 |
ObjectFileLoader canLoadObjectFiles ifFalse:[^ false].
|
106
|
614 |
|
118
|
615 |
"/ no chance, if no stc is available
|
120
|
616 |
^ self incrementalStcPath notNil
|
101
|
617 |
|
|
618 |
"
|
|
619 |
Compiler canCreateMachineCode
|
97
|
620 |
"
|
120
|
621 |
|
|
622 |
"Modified: 13.9.1995 / 15:15:11 / claus"
|
97
|
623 |
!
|
|
624 |
|
54
|
625 |
keepSource:aBoolean
|
|
626 |
"if true, the source of a method is kept as a string in memory;
|
|
627 |
if false, the source is appended to the sources-file (st.src) and
|
|
628 |
only a reference to its fileposition is kept in memory - thus saving
|
|
629 |
space. You have to care for the source-file to not become corrupted
|
|
630 |
in this case; therefore, the default is to keep it as strings for now."
|
|
631 |
|
|
632 |
KeepSource := aBoolean
|
|
633 |
|
|
634 |
"
|
|
635 |
Compiler keepSource:true.
|
|
636 |
Compiler keepSource:false.
|
|
637 |
"
|
|
638 |
! !
|
|
639 |
|
0
|
640 |
!ByteCodeCompiler methodsFor:'accessing'!
|
|
641 |
|
|
642 |
literalArray
|
|
643 |
"return the literal array - only valid after parsing"
|
|
644 |
|
|
645 |
^ litArray
|
|
646 |
!
|
|
647 |
|
|
648 |
code
|
3
|
649 |
"return the bytecode array - only valid after code-generation"
|
0
|
650 |
|
49
|
651 |
^ codeBytes
|
0
|
652 |
!
|
|
653 |
|
|
654 |
maxStackDepth
|
|
655 |
"return the stack-need of the method - only valid after code-generation"
|
|
656 |
|
|
657 |
^ maxStackDepth
|
|
658 |
! !
|
|
659 |
|
|
660 |
!ByteCodeCompiler methodsFor:'code generation'!
|
|
661 |
|
|
662 |
genSymbolicCode
|
|
663 |
"traverse the parse-tree producing symbolicCode - return the codeArray"
|
|
664 |
|
120
|
665 |
|codeStream code thisStatement lastStatement|
|
0
|
666 |
|
104
|
667 |
litArray := nil.
|
76
|
668 |
codeStream := WriteStream on:(OrderedCollection new:100).
|
104
|
669 |
|
0
|
670 |
thisStatement := tree.
|
|
671 |
[thisStatement notNil] whileTrue:[
|
45
|
672 |
lastStatement := thisStatement.
|
104
|
673 |
thisStatement codeForSideEffectOn:codeStream inBlock:nil for:self.
|
45
|
674 |
thisStatement := thisStatement nextStatement
|
0
|
675 |
].
|
54
|
676 |
(lastStatement isNil or:[lastStatement isReturnNode not])
|
0
|
677 |
ifTrue:[
|
45
|
678 |
"not a return - add retSelf"
|
54
|
679 |
"
|
|
680 |
if the last statement was a send for side-effect,
|
|
681 |
replace the previous drop by a retSelf
|
|
682 |
"
|
|
683 |
lastStatement notNil ifTrue:[
|
120
|
684 |
((code := codeStream contents) notNil
|
|
685 |
and:[code size > 0
|
|
686 |
and:[code last == #drop]]) ifTrue:[
|
54
|
687 |
codeStream position:(codeStream position - 1).
|
|
688 |
codeStream nextPut:#retSelf
|
|
689 |
]
|
|
690 |
].
|
45
|
691 |
codeStream nextPut:#retSelf
|
0
|
692 |
].
|
|
693 |
^ codeStream contents
|
|
694 |
!
|
|
695 |
|
19
|
696 |
checkForPrimitiveCode:nr
|
78
|
697 |
"return the code for an ST-80 primitive method.
|
|
698 |
Since many primitives available on ST-80 should also be available
|
|
699 |
somewhere in ST/X, this may work for many primitive numbers.
|
|
700 |
However, more information is needed and more things to be added below.
|
|
701 |
|
|
702 |
This was added to allow emulation of (some) ST-80
|
|
703 |
primitives (to fileIn RemoteInvocation & Monitor41 packages)"
|
0
|
704 |
|
3
|
705 |
|cls sel|
|
|
706 |
|
19
|
707 |
(nr == 75) ifTrue:[ cls := Object. sel := #identityHash ].
|
|
708 |
(nr == 110) ifTrue:[ cls := Object. sel := #== ].
|
|
709 |
(nr == 111) ifTrue:[ cls := Object. sel := #class ].
|
49
|
710 |
"
|
|
711 |
should add more here, to be able to fileIn ST-80 methods
|
|
712 |
containing primitive calls (who gives me the numbers ... ?)
|
|
713 |
"
|
3
|
714 |
cls notNil ifTrue:[
|
45
|
715 |
^ (cls compiledMethodAt:sel) code
|
3
|
716 |
].
|
0
|
717 |
^ nil
|
|
718 |
!
|
|
719 |
|
|
720 |
genByteCodeFrom:symbolicCodeArray
|
|
721 |
"convert symbolicCode into bytecodes"
|
|
722 |
|
49
|
723 |
|symIndex "{Class: SmallInteger }"
|
|
724 |
codeSize "{Class: SmallInteger }"
|
|
725 |
symCodeSize "{Class: SmallInteger }"
|
0
|
726 |
index addr
|
45
|
727 |
codeSymbol nargs needRetry
|
46
|
728 |
stackDepth relocInfo level nvars round t|
|
0
|
729 |
|
|
730 |
symbolicCodeArray isNil ifTrue:[^ self].
|
|
731 |
|
45
|
732 |
round := 0.
|
|
733 |
needRetry := true.
|
0
|
734 |
symCodeSize := symbolicCodeArray size.
|
|
735 |
codeSize := symCodeSize.
|
|
736 |
|
45
|
737 |
[needRetry] whileTrue:[
|
|
738 |
stackDepth := 0.
|
|
739 |
maxStackDepth := 0.
|
0
|
740 |
|
49
|
741 |
codeBytes := ByteArray uninitializedNew:codeSize.
|
96
|
742 |
relocInfo := Array basicNew:(codeSize + 1).
|
45
|
743 |
symIndex := 1.
|
|
744 |
codeIndex := 1.
|
0
|
745 |
|
45
|
746 |
needRetry := false.
|
|
747 |
round := round + 1.
|
|
748 |
|
|
749 |
[symIndex <= symCodeSize] whileTrue:[
|
|
750 |
relocInfo at:symIndex put:codeIndex.
|
0
|
751 |
|
45
|
752 |
codeSymbol := symbolicCodeArray at:symIndex.
|
|
753 |
symIndex := symIndex + 1.
|
|
754 |
stackDelta := 0.
|
|
755 |
extra := nil.
|
|
756 |
lineno := false.
|
|
757 |
self appendByteCodeFor:codeSymbol.
|
|
758 |
lineno ifTrue:[
|
|
759 |
self appendByte:((symbolicCodeArray at:symIndex) min:255).
|
|
760 |
symIndex := symIndex + 1
|
|
761 |
].
|
|
762 |
extra notNil ifTrue:[
|
46
|
763 |
(extra == #number) ifTrue:[
|
|
764 |
index := symbolicCodeArray at:symIndex.
|
|
765 |
symIndex := symIndex + 1.
|
|
766 |
self appendSignedByte:index
|
|
767 |
].
|
|
768 |
(extra == #number16) ifTrue:[
|
|
769 |
index := symbolicCodeArray at:symIndex.
|
|
770 |
symIndex := symIndex + 2.
|
|
771 |
self appendSignedWord:index
|
|
772 |
].
|
54
|
773 |
(extra == #unsigned16) ifTrue:[
|
|
774 |
index := symbolicCodeArray at:symIndex.
|
|
775 |
symIndex := symIndex + 2.
|
|
776 |
self appendWord:index
|
|
777 |
].
|
45
|
778 |
(extra == #index) ifTrue:[
|
46
|
779 |
index := symbolicCodeArray at:symIndex.
|
|
780 |
symIndex := symIndex + 1.
|
|
781 |
self appendByte:index
|
|
782 |
].
|
|
783 |
(extra == #lit) ifTrue:[
|
45
|
784 |
index := self addLiteral:(symbolicCodeArray at:symIndex).
|
|
785 |
symIndex := symIndex + 1.
|
|
786 |
self appendByte:index
|
46
|
787 |
].
|
|
788 |
(extra == #speciallit) ifTrue:[
|
|
789 |
index := self addLiteral:(symbolicCodeArray at:symIndex).
|
|
790 |
index > 255 ifTrue:[
|
|
791 |
self parseError:'too many globals (' ,
|
|
792 |
(symbolicCodeArray at:symIndex) ,
|
|
793 |
' index=' , index printString ,
|
|
794 |
') in method - please simplify'.
|
|
795 |
^ #Error
|
|
796 |
].
|
|
797 |
symIndex := symIndex + 1.
|
|
798 |
self appendByte:index.
|
|
799 |
self appendByte:0. "space for inline-generation"
|
|
800 |
self appendByte:0. "space for inline-address"
|
|
801 |
self appendByte:0.
|
|
802 |
self appendByte:0.
|
|
803 |
self appendByte:0.
|
|
804 |
symIndex := symIndex + 5
|
|
805 |
].
|
117
|
806 |
(extra == #speciallitS) ifTrue:[
|
|
807 |
index := symbolicCodeArray at:symIndex.
|
|
808 |
symIndex := symIndex + 1.
|
|
809 |
self appendByte:index.
|
|
810 |
self appendByte:0. "space for inline-generation"
|
|
811 |
self appendByte:0. "space for inline-address"
|
|
812 |
self appendByte:0.
|
|
813 |
self appendByte:0.
|
|
814 |
self appendByte:0.
|
|
815 |
symIndex := symIndex + 5
|
|
816 |
].
|
|
817 |
(extra == #speciallitL) ifTrue:[
|
|
818 |
index := symbolicCodeArray at:symIndex.
|
|
819 |
symIndex := symIndex + 2.
|
|
820 |
self appendWord:index.
|
|
821 |
self appendByte:0. "space for inline-generation"
|
|
822 |
self appendByte:0. "space for inline-address"
|
|
823 |
self appendByte:0.
|
|
824 |
self appendByte:0.
|
|
825 |
self appendByte:0.
|
|
826 |
symIndex := symIndex + 5
|
|
827 |
].
|
46
|
828 |
(extra == #offset) ifTrue:[
|
|
829 |
relocInfo at:symIndex put:codeIndex.
|
|
830 |
self addReloc:symIndex.
|
|
831 |
symIndex := symIndex + 1.
|
|
832 |
self appendByte:0
|
|
833 |
].
|
|
834 |
(extra == #indexLevel) ifTrue:[
|
|
835 |
index := symbolicCodeArray at:symIndex.
|
|
836 |
symIndex := symIndex + 1.
|
|
837 |
self appendByte:index.
|
|
838 |
level := symbolicCodeArray at:symIndex.
|
|
839 |
symIndex := symIndex + 1.
|
|
840 |
self appendByte:level
|
|
841 |
].
|
|
842 |
(extra == #offsetNvarNarg) ifTrue:[
|
|
843 |
relocInfo at:symIndex put:codeIndex.
|
|
844 |
self addReloc:symIndex.
|
|
845 |
symIndex := symIndex + 1.
|
|
846 |
self appendByte:0.
|
|
847 |
nvars := symbolicCodeArray at:symIndex.
|
|
848 |
symIndex := symIndex + 1.
|
|
849 |
self appendByte:nvars.
|
|
850 |
level := symbolicCodeArray at:symIndex.
|
|
851 |
symIndex := symIndex + 1.
|
|
852 |
self appendByte:level
|
|
853 |
].
|
|
854 |
(extra == #absoffset) ifTrue:[
|
|
855 |
relocInfo at:symIndex put:codeIndex.
|
|
856 |
self addReloc:symIndex.
|
|
857 |
addr := symbolicCodeArray at:symIndex.
|
|
858 |
symIndex := symIndex + 1.
|
|
859 |
self appendByte:(addr bitAnd:16rFF).
|
|
860 |
self appendByte:((addr bitShift:-8) bitAnd:16rFF).
|
|
861 |
].
|
|
862 |
(extra == #absoffsetNvarNarg) ifTrue:[
|
|
863 |
relocInfo at:symIndex put:codeIndex.
|
|
864 |
self addReloc:symIndex.
|
|
865 |
addr := symbolicCodeArray at:symIndex.
|
|
866 |
symIndex := symIndex + 1.
|
|
867 |
self appendByte:(addr bitAnd:16rFF).
|
|
868 |
self appendByte:((addr bitShift:-8) bitAnd:16rFF).
|
|
869 |
nvars := symbolicCodeArray at:symIndex.
|
|
870 |
symIndex := symIndex + 1.
|
|
871 |
self appendByte:nvars.
|
|
872 |
level := symbolicCodeArray at:symIndex.
|
|
873 |
symIndex := symIndex + 1.
|
|
874 |
self appendByte:level
|
|
875 |
].
|
|
876 |
|
117
|
877 |
extra == #special ifTrue:[
|
|
878 |
((codeSymbol == #send)
|
|
879 |
or:[codeSymbol == #sendSelf
|
|
880 |
or:[codeSymbol == #superSend
|
|
881 |
or:[codeSymbol == #hereSend]]]) ifTrue:[
|
106
|
882 |
index := symbolicCodeArray at:symIndex.
|
|
883 |
symIndex := symIndex + 1.
|
|
884 |
nargs := symbolicCodeArray at:symIndex.
|
|
885 |
symIndex := symIndex + 1.
|
|
886 |
self appendByte:nargs.
|
|
887 |
self appendByte:index.
|
117
|
888 |
|
|
889 |
(codeSymbol == #superSend
|
|
890 |
or:[codeSymbol == #hereSend]) ifTrue:[
|
|
891 |
index := symbolicCodeArray at:symIndex.
|
|
892 |
symIndex := symIndex + 1.
|
|
893 |
self appendByte:index
|
|
894 |
].
|
|
895 |
stackDelta := nargs negated.
|
|
896 |
codeSymbol == #sendSelf ifTrue:[
|
|
897 |
stackDelta := stackDelta + 1
|
|
898 |
]
|
106
|
899 |
] ifFalse:[
|
117
|
900 |
(codeSymbol == #sendDrop) ifTrue:[
|
106
|
901 |
index := symbolicCodeArray at:symIndex.
|
117
|
902 |
symIndex := symIndex + 1.
|
106
|
903 |
nargs := symbolicCodeArray at:symIndex.
|
|
904 |
symIndex := symIndex + 1.
|
|
905 |
self appendByte:nargs.
|
117
|
906 |
self appendByte:index.
|
106
|
907 |
stackDelta := (nargs + 1) negated
|
117
|
908 |
]
|
|
909 |
]
|
|
910 |
].
|
|
911 |
|
|
912 |
extra == #specialL ifTrue:[
|
|
913 |
((codeSymbol == #sendL)
|
|
914 |
or:[codeSymbol == #sendSelfL
|
|
915 |
or:[codeSymbol == #superSendL
|
|
916 |
or:[codeSymbol == #hereSendL]]]) ifTrue:[
|
|
917 |
index := symbolicCodeArray at:symIndex.
|
|
918 |
symIndex := symIndex + 2.
|
|
919 |
nargs := symbolicCodeArray at:symIndex.
|
|
920 |
symIndex := symIndex + 1.
|
|
921 |
self appendByte:nargs.
|
|
922 |
self appendWord:index.
|
|
923 |
(codeSymbol == #superSendL
|
|
924 |
or:[codeSymbol == #hereSendL]) ifTrue:[
|
|
925 |
index := symbolicCodeArray at:symIndex.
|
|
926 |
symIndex := symIndex + 2.
|
|
927 |
self appendWord:index.
|
|
928 |
].
|
|
929 |
stackDelta := nargs negated.
|
|
930 |
codeSymbol == #sendSelfL ifTrue:[
|
|
931 |
stackDelta := stackDelta + 1
|
106
|
932 |
]
|
|
933 |
]
|
|
934 |
].
|
45
|
935 |
].
|
117
|
936 |
|
45
|
937 |
stackDepth := stackDepth + stackDelta.
|
|
938 |
(stackDepth > maxStackDepth) ifTrue:[
|
|
939 |
maxStackDepth := stackDepth
|
|
940 |
]
|
|
941 |
].
|
|
942 |
relocInfo at:symIndex put:codeIndex.
|
0
|
943 |
|
45
|
944 |
needRetry ifFalse:[
|
|
945 |
"
|
|
946 |
now relocate - returns true if ok, false if we have to do it again
|
|
947 |
(when short jumps have been changed to long jumps)
|
|
948 |
"
|
|
949 |
relocList notNil ifTrue:[
|
|
950 |
needRetry := (self relocateWith:symbolicCodeArray relocInfo:relocInfo) not.
|
|
951 |
"
|
|
952 |
if returned with false, a relative jump was made into
|
|
953 |
an absolute jump - need to start over with one more byte space
|
|
954 |
"
|
|
955 |
needRetry ifTrue:[
|
|
956 |
relocList := nil.
|
|
957 |
codeSize := codeSize + 1.
|
|
958 |
]
|
|
959 |
]
|
46
|
960 |
] ifTrue:[
|
95
|
961 |
'compiling again ...' infoPrintNL.
|
46
|
962 |
]
|
0
|
963 |
].
|
49
|
964 |
"code printNL."
|
0
|
965 |
^ errorFlag
|
117
|
966 |
|
|
967 |
"Modified: 3.9.1995 / 12:59:43 / claus"
|
0
|
968 |
!
|
|
969 |
|
1
|
970 |
absJumpFromJump:code
|
3
|
971 |
"given a jump-symbolic code, return corresponding absolute jump"
|
|
972 |
|
1
|
973 |
JumpToAbsJump isNil ifTrue:[
|
45
|
974 |
JumpToAbsJump := IdentityDictionary new.
|
|
975 |
JumpToAbsJump at:#jump put:#jumpabs.
|
|
976 |
JumpToAbsJump at:#trueJump put:#trueJumpabs.
|
|
977 |
JumpToAbsJump at:#falseJump put:#falseJumpabs.
|
|
978 |
JumpToAbsJump at:#nilJump put:#nilJumpabs.
|
|
979 |
JumpToAbsJump at:#notNilJump put:#notNilJumpabs.
|
|
980 |
JumpToAbsJump at:#eqJump put:#eqJumpabs.
|
|
981 |
JumpToAbsJump at:#notEqJump put:#notEqJumpabs.
|
|
982 |
JumpToAbsJump at:#zeroJump put:#zeroJumpabs.
|
|
983 |
JumpToAbsJump at:#notZeroJump put:#notZeroJumpabs.
|
|
984 |
JumpToAbsJump at:#makeBlock put:#makeBlockabs.
|
1
|
985 |
].
|
|
986 |
^ JumpToAbsJump at:code
|
|
987 |
!
|
|
988 |
|
0
|
989 |
relocateWith:symbolicCodeArray relocInfo:relocInfo
|
|
990 |
"helper for genByteCodeFrom - relocate code using relocInfo.
|
|
991 |
if relocation fails badly (due to long relative jumps) patch
|
|
992 |
symbolicCode to use absolute jumps instead and return false
|
3
|
993 |
(genByteCodeFrom will then try again). Otherwise return true.
|
|
994 |
Also, on the fly, jumps to jumps and jumps to return are handled."
|
0
|
995 |
|
49
|
996 |
|delta "{Class: SmallInteger }"
|
|
997 |
codePos "{Class: SmallInteger }"
|
|
998 |
opCodePos "{Class: SmallInteger }"
|
|
999 |
codeOffset "{Class: SmallInteger }"
|
|
1000 |
symOffset
|
|
1001 |
opcode "{Class: SmallInteger }"
|
|
1002 |
dstOpcode jumpTarget
|
3
|
1003 |
jumpCode deleteSet|
|
0
|
1004 |
|
3
|
1005 |
deleteSet := OrderedCollection new.
|
0
|
1006 |
relocList do:[:sIndex |
|
45
|
1007 |
"have to relocate symCode at sIndex ..."
|
|
1008 |
symOffset := symbolicCodeArray at:sIndex. "the target in the symbolic code"
|
|
1009 |
codePos := relocInfo at:sIndex. "position of the offet in byte code"
|
|
1010 |
codeOffset := relocInfo at:symOffset. "position of the target in byte code"
|
|
1011 |
delta := codeOffset - codePos - 1.
|
|
1012 |
opCodePos := codePos - 1.
|
49
|
1013 |
opcode := codeBytes at:opCodePos.
|
1
|
1014 |
|
45
|
1015 |
(opcode between:190 and:199) ifTrue:[
|
|
1016 |
"an absolute jump/makeBlock"
|
0
|
1017 |
|
49
|
1018 |
codeBytes at:codePos put:(codeOffset bitAnd:16rFF).
|
|
1019 |
codeBytes at:(codePos + 1) put:(codeOffset bitShift:-8)
|
45
|
1020 |
] ifFalse:[
|
|
1021 |
"get jump-code from long and vlong codes"
|
|
1022 |
(opcode between:50 and:59) ifFalse:[
|
|
1023 |
(opcode between:60 and:69) ifTrue:[
|
|
1024 |
opcode := opcode - 10
|
|
1025 |
] ifFalse:[
|
|
1026 |
(opcode between:70 and:79) ifTrue:[
|
|
1027 |
opcode := opcode - 20
|
|
1028 |
] ifFalse:[
|
|
1029 |
self error:'invalid code to relocate'
|
|
1030 |
]
|
|
1031 |
].
|
|
1032 |
].
|
1
|
1033 |
|
45
|
1034 |
"optimize jump to return and jump to jump"
|
1
|
1035 |
|
45
|
1036 |
(opcode == 54) ifTrue:[
|
|
1037 |
"a jump"
|
|
1038 |
dstOpcode := symbolicCodeArray at:symOffset.
|
3
|
1039 |
|
45
|
1040 |
(#(retSelf retTop retNil retTrue retFalse ret0 "blockRetTop") includes:dstOpcode) ifTrue:[
|
|
1041 |
"a jump to a return - put in the return instead jump"
|
3
|
1042 |
|
45
|
1043 |
symbolicCodeArray at:(sIndex - 1) put:dstOpcode.
|
|
1044 |
symbolicCodeArray at:sIndex put:dstOpcode.
|
49
|
1045 |
codeBytes at:opCodePos put:(self byteCodeFor:dstOpcode).
|
45
|
1046 |
delta := 0.
|
|
1047 |
deleteSet add:sIndex.
|
3
|
1048 |
|
|
1049 |
"
|
49
|
1050 |
'jump to return at: ' print. (sIndex - 1) printNL.
|
3
|
1051 |
"
|
45
|
1052 |
] ifFalse:[
|
|
1053 |
(dstOpcode == #jump) ifTrue:[
|
|
1054 |
"jump to jump to be done soon"
|
|
1055 |
jumpTarget := symbolicCodeArray at:(symOffset + 1).
|
3
|
1056 |
"
|
|
1057 |
'jump to jump at: ' print. (sIndex - 1) print.
|
49
|
1058 |
' newTarget:' print. jumpTarget printNL.
|
3
|
1059 |
"
|
|
1060 |
|
45
|
1061 |
symbolicCodeArray at:sIndex put:jumpTarget.
|
|
1062 |
symOffset := jumpTarget.
|
|
1063 |
codeOffset := relocInfo at:symOffset.
|
|
1064 |
delta := codeOffset - codePos - 1.
|
3
|
1065 |
|
45
|
1066 |
"continue with new delta"
|
|
1067 |
]
|
|
1068 |
]
|
|
1069 |
].
|
|
1070 |
(#(50 51 52 53 56 57 58 59) includes:opcode) ifTrue:[
|
|
1071 |
"a conditional jump"
|
3
|
1072 |
|
45
|
1073 |
dstOpcode := symbolicCodeArray at:symOffset.
|
|
1074 |
(dstOpcode == #jump) ifTrue:[
|
|
1075 |
"conditional jump to unconditional jump"
|
|
1076 |
jumpTarget := symbolicCodeArray at:(symOffset + 1).
|
3
|
1077 |
"
|
|
1078 |
'cond jump to jump at: ' print. (sIndex - 1) print.
|
49
|
1079 |
' newTarget:' print. jumpTarget printNL.
|
3
|
1080 |
"
|
|
1081 |
|
45
|
1082 |
symbolicCodeArray at:sIndex put:jumpTarget.
|
|
1083 |
symOffset := jumpTarget.
|
|
1084 |
codeOffset := relocInfo at:symOffset.
|
|
1085 |
delta := codeOffset - codePos - 1.
|
3
|
1086 |
|
45
|
1087 |
"continue with new delta"
|
|
1088 |
].
|
|
1089 |
].
|
3
|
1090 |
|
45
|
1091 |
(delta >= 0) ifTrue:[
|
|
1092 |
(delta > 127) ifTrue:[
|
|
1093 |
(opcode between:50 and:59) ifFalse:[
|
|
1094 |
self error:'invalid code to relocate'
|
49
|
1095 |
] ifTrue:[
|
|
1096 |
(delta > 255) ifTrue:[
|
|
1097 |
"change jmp into vljmp ..."
|
|
1098 |
codeBytes at:opCodePos put:(opcode + 20).
|
|
1099 |
delta := delta - 256
|
|
1100 |
] ifFalse:[
|
|
1101 |
"change jmp into ljmp ..."
|
|
1102 |
codeBytes at:opCodePos put:(opcode + 10).
|
|
1103 |
delta := delta - 128
|
|
1104 |
].
|
|
1105 |
(delta > 127) ifTrue:[
|
|
1106 |
"change symbolic into a jump absolute and fail"
|
|
1107 |
jumpCode := symbolicCodeArray at:(sIndex - 1).
|
|
1108 |
symbolicCodeArray at:(sIndex - 1) put:(self absJumpFromJump:jumpCode).
|
|
1109 |
symbolicCodeArray at:sIndex put:symOffset.
|
3
|
1110 |
"
|
49
|
1111 |
'change short into abs jump' printNL.
|
3
|
1112 |
"
|
49
|
1113 |
deleteSet do:[:d | relocList remove:d].
|
|
1114 |
^ false
|
|
1115 |
]
|
45
|
1116 |
].
|
|
1117 |
].
|
49
|
1118 |
codeBytes at:codePos put:delta
|
45
|
1119 |
] ifFalse:[
|
|
1120 |
(delta < -128) ifTrue:[
|
|
1121 |
(opcode between:50 and:59) ifFalse:[
|
|
1122 |
self error:'invalid code to relocate'
|
49
|
1123 |
] ifTrue:[
|
|
1124 |
(delta < -256) ifTrue:[
|
|
1125 |
"change jmp into vljmp ..."
|
|
1126 |
codeBytes at:opCodePos put:(opcode + 20).
|
|
1127 |
delta := delta + 256
|
|
1128 |
] ifFalse:[
|
|
1129 |
"change jmp into ljmp ..."
|
|
1130 |
codeBytes at:opCodePos put:(opcode + 10).
|
|
1131 |
delta := delta + 128
|
|
1132 |
].
|
|
1133 |
(delta < -128) ifTrue:[
|
|
1134 |
"change symbolic into a jump absolute and fail"
|
|
1135 |
jumpCode := symbolicCodeArray at:(sIndex - 1).
|
|
1136 |
symbolicCodeArray at:(sIndex - 1) put:(self absJumpFromJump:jumpCode).
|
|
1137 |
symbolicCodeArray at:sIndex put:symOffset.
|
3
|
1138 |
"
|
49
|
1139 |
'change short into abs jump' printNL.
|
3
|
1140 |
"
|
49
|
1141 |
deleteSet do:[:d | relocList remove:d].
|
|
1142 |
^ false
|
|
1143 |
]
|
45
|
1144 |
]
|
|
1145 |
].
|
49
|
1146 |
codeBytes at:codePos put:(256 + delta)
|
45
|
1147 |
]
|
|
1148 |
]
|
0
|
1149 |
].
|
|
1150 |
(errorFlag == #Error) ifTrue:[
|
45
|
1151 |
self error:'relocation range error'
|
0
|
1152 |
].
|
|
1153 |
^ true
|
|
1154 |
!
|
|
1155 |
|
|
1156 |
addLiteral:anObject
|
|
1157 |
"add a literal to the literalArray - watch for and eliminate
|
|
1158 |
duplicates. return the index of the literal in the Array"
|
|
1159 |
|
3
|
1160 |
|index class|
|
0
|
1161 |
|
|
1162 |
litArray isNil ifTrue:[
|
45
|
1163 |
litArray := Array with:anObject.
|
|
1164 |
^ 1
|
0
|
1165 |
].
|
|
1166 |
index := litArray identityIndexOf:anObject.
|
|
1167 |
(index == 0) ifTrue:[
|
45
|
1168 |
"
|
|
1169 |
reuse constants if same value and same class
|
|
1170 |
"
|
|
1171 |
class := anObject class.
|
|
1172 |
((class == Float)
|
|
1173 |
or:[class == Fraction]) ifTrue:[
|
|
1174 |
index := litArray indexOf:anObject.
|
|
1175 |
].
|
|
1176 |
((index == 0) or:[(litArray at:index) class ~~ class]) ifTrue:[
|
|
1177 |
litArray := litArray copyWith:anObject.
|
|
1178 |
^ litArray size
|
|
1179 |
].
|
0
|
1180 |
].
|
|
1181 |
^ index
|
|
1182 |
!
|
|
1183 |
|
|
1184 |
appendByteCodeFor:codeSymbol
|
|
1185 |
"append the byteCode for an instructionSymbol to the code-Array"
|
|
1186 |
|
49
|
1187 |
|idx "{Class: SmallInteger }"|
|
|
1188 |
|
|
1189 |
idx := codeIndex.
|
|
1190 |
codeBytes at:idx put:(self byteCodeFor:codeSymbol).
|
|
1191 |
codeIndex := idx + 1
|
0
|
1192 |
!
|
|
1193 |
|
|
1194 |
appendByte:aByte
|
|
1195 |
"append a byte to the code-Array, checking for byte-range (debug-only)"
|
|
1196 |
|
49
|
1197 |
|idx "{Class: SmallInteger }"|
|
|
1198 |
|
|
1199 |
idx := codeIndex.
|
0
|
1200 |
(aByte between:0 and:255) ifTrue:[
|
49
|
1201 |
codeBytes at:idx put:aByte.
|
|
1202 |
codeIndex := idx + 1
|
0
|
1203 |
] ifFalse:[
|
45
|
1204 |
self error:'byte range error'.
|
|
1205 |
errorFlag := #Error
|
0
|
1206 |
]
|
|
1207 |
!
|
|
1208 |
|
105
|
1209 |
appendEmptyByte
|
45
|
1210 |
"append an empty byte to the code-Array"
|
|
1211 |
|
49
|
1212 |
|idx "{Class: SmallInteger }"|
|
|
1213 |
|
|
1214 |
idx := codeIndex.
|
|
1215 |
codeBytes at:idx put:0.
|
|
1216 |
codeIndex := idx + 1
|
45
|
1217 |
!
|
|
1218 |
|
0
|
1219 |
appendSignedByte:aByte
|
|
1220 |
"append a signedbyte (as in jump-offsets) to the code-Array,
|
|
1221 |
check range and report an error if invalid"
|
|
1222 |
|
49
|
1223 |
|b "{Class: SmallInteger }"
|
|
1224 |
idx "{Class: SmallInteger }"|
|
0
|
1225 |
|
49
|
1226 |
idx := codeIndex.
|
0
|
1227 |
b := aByte.
|
|
1228 |
(b >= 0) ifTrue:[
|
45
|
1229 |
(b > 127) ifTrue:[
|
|
1230 |
self error:'jump-range error'.
|
|
1231 |
errorFlag := #Error
|
|
1232 |
].
|
49
|
1233 |
codeBytes at:idx put:b
|
0
|
1234 |
] ifFalse:[
|
45
|
1235 |
(b < -128) ifTrue:[
|
|
1236 |
self error:'jump-range error'.
|
|
1237 |
errorFlag := #Error
|
|
1238 |
].
|
49
|
1239 |
b := 256 + b
|
0
|
1240 |
].
|
49
|
1241 |
codeBytes at:idx put:b.
|
|
1242 |
codeIndex := idx + 1
|
0
|
1243 |
!
|
|
1244 |
|
45
|
1245 |
appendWord:aWord
|
54
|
1246 |
"append an unsigned word (low-high) to the code-Array,
|
45
|
1247 |
checking for word-range (debug-only)"
|
|
1248 |
|
49
|
1249 |
|idx "{Class: SmallInteger }"|
|
|
1250 |
|
|
1251 |
idx := codeIndex.
|
45
|
1252 |
(aWord between:0 and:16rFFFF) ifTrue:[
|
49
|
1253 |
codeBytes at:idx put:(aWord bitAnd:16rFF).
|
|
1254 |
idx := idx + 1.
|
|
1255 |
codeBytes at:idx put:(aWord bitShift:-8).
|
|
1256 |
codeIndex := idx + 1
|
45
|
1257 |
] ifFalse:[
|
|
1258 |
self error:'word range error'.
|
|
1259 |
errorFlag := #Error
|
|
1260 |
]
|
|
1261 |
!
|
|
1262 |
|
46
|
1263 |
appendSignedWord:aWord
|
|
1264 |
"append a signed word to the code-Array,
|
|
1265 |
check range and report an error if invalid"
|
|
1266 |
|
49
|
1267 |
|w "{Class: SmallInteger }"|
|
46
|
1268 |
|
|
1269 |
w := aWord.
|
|
1270 |
(w >= 0) ifTrue:[
|
|
1271 |
(w > 16r7FFFF) ifTrue:[
|
|
1272 |
self error:'word-range error'.
|
|
1273 |
errorFlag := #Error
|
|
1274 |
].
|
|
1275 |
] ifFalse:[
|
|
1276 |
(w < 16r-8000) ifTrue:[
|
|
1277 |
self error:'word-range error'.
|
|
1278 |
errorFlag := #Error
|
|
1279 |
].
|
|
1280 |
w := (16r10000 + w).
|
|
1281 |
].
|
|
1282 |
self appendWord:w
|
|
1283 |
!
|
|
1284 |
|
0
|
1285 |
addReloc:symIndex
|
|
1286 |
"remember to relocate offset at symIndex later ..."
|
|
1287 |
|
|
1288 |
relocList isNil ifTrue:[
|
45
|
1289 |
relocList := OrderedCollection new.
|
0
|
1290 |
].
|
|
1291 |
relocList add:symIndex
|
|
1292 |
!
|
|
1293 |
|
45
|
1294 |
moveGlobalsToFront
|
|
1295 |
"move all global-literals to the front of the literal array.
|
|
1296 |
This may be the last chance to compile the method, since
|
|
1297 |
for globals, the maximum literal index is 255 - while for normal
|
|
1298 |
literals its a stress-less 65535"
|
|
1299 |
|
|
1300 |
litArray isNil ifTrue:[
|
|
1301 |
^ self error:'oops compiler botch'.
|
|
1302 |
].
|
|
1303 |
litArray sort:[:a :b | "a < b -> #(a b)"
|
|
1304 |
(a isMemberOf:Symbol) ifFalse:[false]
|
|
1305 |
ifTrue:[
|
|
1306 |
(b isMemberOf:Symbol) ifFalse:[true]
|
|
1307 |
ifTrue:[
|
|
1308 |
(a at:1) isUppercase ifFalse:[false]
|
|
1309 |
ifTrue:[
|
|
1310 |
(b at:1) isUppercase ifFalse:[true]
|
|
1311 |
ifTrue:[a < b].
|
|
1312 |
]
|
|
1313 |
]
|
|
1314 |
]
|
|
1315 |
].
|
|
1316 |
|
|
1317 |
"
|
|
1318 |
#(#A #c #B #D #E #a #b #F)
|
|
1319 |
sort:[:a :b |
|
|
1320 |
(a isMemberOf:Symbol) ifFalse:[false]
|
|
1321 |
ifTrue:[
|
|
1322 |
(b isMemberOf:Symbol) ifFalse:[true]
|
|
1323 |
ifTrue:[
|
|
1324 |
(a at:1) isUppercase ifFalse:[false]
|
|
1325 |
ifTrue:[
|
|
1326 |
(b at:1) isUppercase ifFalse:[true]
|
|
1327 |
ifTrue:[(a < b)].
|
|
1328 |
]
|
|
1329 |
]
|
|
1330 |
]
|
|
1331 |
].
|
|
1332 |
|
|
1333 |
"
|
|
1334 |
!
|
|
1335 |
|
0
|
1336 |
byteCodeFor:aSymbol
|
|
1337 |
"given a symbolic instruction, return the corresponding bytecode.
|
|
1338 |
as a side-effect, leave number of bytes pushed/popped by this instr.
|
|
1339 |
in stackDelta, and, if the instruction needs extra arguments, leave
|
|
1340 |
this info in extra"
|
|
1341 |
|
|
1342 |
"standard bytecodes"
|
|
1343 |
|
|
1344 |
(aSymbol == #pushNil) ifTrue:[stackDelta := 1. ^ 10].
|
|
1345 |
(aSymbol == #pushTrue) ifTrue:[stackDelta := 1. ^ 11].
|
|
1346 |
(aSymbol == #pushFalse) ifTrue:[stackDelta := 1. ^ 12].
|
|
1347 |
(aSymbol == #pushLit) ifTrue:[stackDelta := 1. extra := #lit. ^ 14].
|
105
|
1348 |
(aSymbol == #pushLitS) ifTrue:[stackDelta := 1. extra := #index. ^ 14].
|
0
|
1349 |
(aSymbol == #pushSelf) ifTrue:[stackDelta := 1. ^ 15].
|
|
1350 |
(aSymbol == #pushNum) ifTrue:[stackDelta := 1. extra := #number. ^ 16].
|
|
1351 |
|
|
1352 |
(aSymbol == #pushMethodArg) ifTrue:[stackDelta := 1. extra := #index. ^ 30].
|
|
1353 |
(aSymbol == #pushMethodVar) ifTrue:[stackDelta := 1. extra := #index. ^ 31].
|
|
1354 |
(aSymbol == #pushBlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 32].
|
|
1355 |
(aSymbol == #pushBlockVar) ifTrue:[stackDelta := 1. extra := #index. ^ 33].
|
|
1356 |
(aSymbol == #pushInstVar) ifTrue:[stackDelta := 1. extra := #index. ^ 34].
|
1
|
1357 |
(aSymbol == #pushOuterBlockArg) ifTrue:[stackDelta := 1. extra := #indexLevel. ^ 42].
|
|
1358 |
(aSymbol == #pushOuterBlockVar) ifTrue:[stackDelta := 1. extra := #indexLevel. ^ 128].
|
0
|
1359 |
|
|
1360 |
(aSymbol == #retTop) ifTrue:[stackDelta := -1. ^ 0].
|
|
1361 |
(aSymbol == #retSelf) ifTrue:[^5].
|
|
1362 |
|
|
1363 |
(aSymbol == #==) ifTrue:[stackDelta := -1. self addLiteral:aSymbol. ^ 45].
|
|
1364 |
(aSymbol == #~~) ifTrue:[stackDelta := -1. self addLiteral:aSymbol. ^ 46].
|
|
1365 |
|
|
1366 |
(aSymbol == #falseJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 50].
|
|
1367 |
(aSymbol == #trueJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 51].
|
|
1368 |
(aSymbol == #nilJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 52].
|
|
1369 |
(aSymbol == #notNilJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 53].
|
|
1370 |
(aSymbol == #jump) ifTrue:[extra := #offset. ^ 54].
|
1
|
1371 |
(aSymbol == #makeBlock) ifTrue:[stackDelta := 1. extra := #offsetNvarNarg. ^ 55].
|
0
|
1372 |
(aSymbol == #zeroJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 56].
|
|
1373 |
(aSymbol == #notZeroJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 57].
|
|
1374 |
(aSymbol == #eqJump) ifTrue:[stackDelta := -2. extra := #offset. ^ 58].
|
|
1375 |
(aSymbol == #notEqJump) ifTrue:[stackDelta := -2. extra := #offset. ^ 59].
|
|
1376 |
|
54
|
1377 |
(aSymbol == #lineno) ifTrue:[lineno := true. ^ 8].
|
|
1378 |
|
106
|
1379 |
(aSymbol == #send) ifTrue:[lineno := true. extra := #special. ^ 19].
|
|
1380 |
(aSymbol == #superSend) ifTrue:[lineno := true. extra := #special. ^ 20].
|
|
1381 |
(aSymbol == #hereSend) ifTrue:[lineno := true. extra := #special. ^ 20].
|
117
|
1382 |
(aSymbol == #sendSelf) ifTrue:[lineno := true. extra := #special. ^ 13].
|
0
|
1383 |
|
|
1384 |
(aSymbol == #drop) ifTrue:[stackDelta := -1. ^ 18].
|
|
1385 |
(aSymbol == #dup) ifTrue:[stackDelta := 1. ^ 47].
|
|
1386 |
|
117
|
1387 |
(aSymbol == #storeMethodVar) ifTrue:[extra := #index. stackDelta := -1. ^ 37].
|
|
1388 |
(aSymbol == #storeBlockVar) ifTrue:[extra := #index. stackDelta := -1. ^ 38].
|
|
1389 |
(aSymbol == #storeInstVar) ifTrue:[extra := #index. stackDelta := -1. ^ 39].
|
0
|
1390 |
|
117
|
1391 |
(aSymbol == #pushClassVarS) ifTrue:[stackDelta := 1. extra := #speciallitS. ^ 35].
|
|
1392 |
(aSymbol == #pushGlobalS) ifTrue:[stackDelta := 1. extra := #speciallitS. ^ 35].
|
|
1393 |
|
|
1394 |
(aSymbol == #storeClassVarS) ifTrue:[extra := #speciallitS.stackDelta := -1. ^ 40].
|
|
1395 |
(aSymbol == #storeGlobalS) ifTrue:[extra := #speciallitS. stackDelta := -1. ^ 40].
|
|
1396 |
|
1
|
1397 |
(aSymbol == #storeOuterBlockVar) ifTrue:[stackDelta := -1. extra := #indexLevel. ^ 129].
|
0
|
1398 |
|
117
|
1399 |
(aSymbol == #pushClassInstVar) ifTrue:[stackDelta := 1. extra := #index. ^ 176].
|
|
1400 |
(aSymbol == #storeClassInstVar) ifTrue:[extra := #index.stackDelta := -1. ^ 177].
|
105
|
1401 |
|
0
|
1402 |
"optimized bytecodes"
|
|
1403 |
|
|
1404 |
(aSymbol == #retNil) ifTrue:[^ 1].
|
|
1405 |
(aSymbol == #retTrue) ifTrue:[^ 2].
|
|
1406 |
(aSymbol == #retFalse) ifTrue:[^ 3].
|
|
1407 |
(aSymbol == #ret0) ifTrue:[^ 4].
|
|
1408 |
(aSymbol == #retNum) ifTrue:[extra := #number. ^ 127].
|
25
|
1409 |
(aSymbol == #homeRetTop) ifTrue:[^ 7].
|
0
|
1410 |
|
46
|
1411 |
(aSymbol == #pushNum16) ifTrue:[stackDelta := 1. extra := #number16. ^ 17].
|
0
|
1412 |
(aSymbol == #push0) ifTrue:[stackDelta := 1. ^120].
|
|
1413 |
(aSymbol == #push1) ifTrue:[stackDelta := 1. ^121].
|
3
|
1414 |
(aSymbol == #push2) ifTrue:[stackDelta := 1. ^139].
|
0
|
1415 |
(aSymbol == #pushMinus1) ifTrue:[stackDelta := 1. ^122].
|
|
1416 |
|
106
|
1417 |
(aSymbol == #send0) ifTrue:[lineno := true. extra := #index. ^21].
|
|
1418 |
(aSymbol == #send1) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^22].
|
|
1419 |
(aSymbol == #send2) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^23].
|
|
1420 |
(aSymbol == #send3) ifTrue:[lineno := true. extra := #index. stackDelta := -3. ^24].
|
0
|
1421 |
|
106
|
1422 |
(aSymbol == #sendSelf0) ifTrue:[lineno := true. extra := #index. stackDelta := 1. ^180].
|
|
1423 |
(aSymbol == #sendSelf1) ifTrue:[lineno := true. extra := #index. ^181].
|
|
1424 |
(aSymbol == #sendSelf2) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^182].
|
|
1425 |
(aSymbol == #sendSelf3) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^183].
|
|
1426 |
(aSymbol == #sendSelfDrop0) ifTrue:[lineno := true. extra := #index. ^184].
|
|
1427 |
(aSymbol == #sendSelfDrop1) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^185].
|
|
1428 |
(aSymbol == #sendSelfDrop2) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^186].
|
|
1429 |
(aSymbol == #sendSelfDrop3) ifTrue:[lineno := true. extra := #index. stackDelta := -3. ^187].
|
0
|
1430 |
|
106
|
1431 |
(aSymbol == #sendDrop) ifTrue:[lineno := true. extra := #special. ^25].
|
|
1432 |
(aSymbol == #sendDrop0) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^26].
|
|
1433 |
(aSymbol == #sendDrop1) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^27].
|
|
1434 |
(aSymbol == #sendDrop2) ifTrue:[lineno := true. extra := #index. stackDelta := -3. ^28].
|
|
1435 |
(aSymbol == #sendDrop3) ifTrue:[lineno := true. extra := #index. stackDelta := -4. ^29].
|
0
|
1436 |
|
|
1437 |
(aSymbol == #pushMethodVar1) ifTrue:[stackDelta := 1. ^80].
|
|
1438 |
(aSymbol == #pushMethodVar2) ifTrue:[stackDelta := 1. ^81].
|
|
1439 |
(aSymbol == #pushMethodVar3) ifTrue:[stackDelta := 1. ^82].
|
|
1440 |
(aSymbol == #pushMethodVar4) ifTrue:[stackDelta := 1. ^83].
|
|
1441 |
(aSymbol == #pushMethodVar5) ifTrue:[stackDelta := 1. ^84].
|
|
1442 |
(aSymbol == #pushMethodVar6) ifTrue:[stackDelta := 1. ^85].
|
|
1443 |
|
|
1444 |
(aSymbol == #pushMethodArg1) ifTrue:[stackDelta := 1. ^86].
|
|
1445 |
(aSymbol == #pushMethodArg2) ifTrue:[stackDelta := 1. ^87].
|
|
1446 |
(aSymbol == #pushMethodArg3) ifTrue:[stackDelta := 1. ^88].
|
|
1447 |
(aSymbol == #pushMethodArg4) ifTrue:[stackDelta := 1. ^89].
|
|
1448 |
|
|
1449 |
(aSymbol == #pushInstVar1) ifTrue:[stackDelta := 1. ^90].
|
|
1450 |
(aSymbol == #pushInstVar2) ifTrue:[stackDelta := 1. ^91].
|
|
1451 |
(aSymbol == #pushInstVar3) ifTrue:[stackDelta := 1. ^92].
|
|
1452 |
(aSymbol == #pushInstVar4) ifTrue:[stackDelta := 1. ^93].
|
|
1453 |
(aSymbol == #pushInstVar5) ifTrue:[stackDelta := 1. ^94].
|
|
1454 |
(aSymbol == #pushInstVar6) ifTrue:[stackDelta := 1. ^95].
|
|
1455 |
(aSymbol == #pushInstVar7) ifTrue:[stackDelta := 1. ^96].
|
|
1456 |
(aSymbol == #pushInstVar8) ifTrue:[stackDelta := 1. ^97].
|
|
1457 |
(aSymbol == #pushInstVar9) ifTrue:[stackDelta := 1. ^98].
|
|
1458 |
(aSymbol == #pushInstVar10) ifTrue:[stackDelta := 1. ^99].
|
|
1459 |
|
|
1460 |
(aSymbol == #storeMethodVar1) ifTrue:[stackDelta := -1. ^100].
|
|
1461 |
(aSymbol == #storeMethodVar2) ifTrue:[stackDelta := -1. ^101].
|
|
1462 |
(aSymbol == #storeMethodVar3) ifTrue:[stackDelta := -1. ^102].
|
|
1463 |
(aSymbol == #storeMethodVar4) ifTrue:[stackDelta := -1. ^103].
|
|
1464 |
(aSymbol == #storeMethodVar5) ifTrue:[stackDelta := -1. ^104].
|
|
1465 |
(aSymbol == #storeMethodVar6) ifTrue:[stackDelta := -1. ^105].
|
|
1466 |
|
|
1467 |
(aSymbol == #storeInstVar1) ifTrue:[stackDelta := -1. ^110].
|
|
1468 |
(aSymbol == #storeInstVar2) ifTrue:[stackDelta := -1. ^111].
|
|
1469 |
(aSymbol == #storeInstVar3) ifTrue:[stackDelta := -1. ^112].
|
|
1470 |
(aSymbol == #storeInstVar4) ifTrue:[stackDelta := -1. ^113].
|
|
1471 |
(aSymbol == #storeInstVar5) ifTrue:[stackDelta := -1. ^114].
|
|
1472 |
(aSymbol == #storeInstVar6) ifTrue:[stackDelta := -1. ^115].
|
|
1473 |
(aSymbol == #storeInstVar7) ifTrue:[stackDelta := -1. ^116].
|
|
1474 |
(aSymbol == #storeInstVar8) ifTrue:[stackDelta := -1. ^117].
|
|
1475 |
(aSymbol == #storeInstVar9) ifTrue:[stackDelta := -1. ^118].
|
|
1476 |
(aSymbol == #storeInstVar10) ifTrue:[stackDelta := -1. ^119].
|
|
1477 |
|
103
|
1478 |
(aSymbol == #pushLit1) ifTrue:[stackDelta := 1. ^ 222].
|
|
1479 |
(aSymbol == #pushLit2) ifTrue:[stackDelta := 1. ^ 223].
|
|
1480 |
(aSymbol == #pushLit3) ifTrue:[stackDelta := 1. ^ 224].
|
|
1481 |
(aSymbol == #pushLit4) ifTrue:[stackDelta := 1. ^ 225].
|
|
1482 |
(aSymbol == #pushLit5) ifTrue:[stackDelta := 1. ^ 226].
|
|
1483 |
(aSymbol == #pushLit6) ifTrue:[stackDelta := 1. ^ 227].
|
|
1484 |
(aSymbol == #pushLit7) ifTrue:[stackDelta := 1. ^ 228].
|
|
1485 |
(aSymbol == #pushLit8) ifTrue:[stackDelta := 1. ^ 229].
|
|
1486 |
|
0
|
1487 |
(aSymbol == #retMethodVar1) ifTrue:[^160].
|
|
1488 |
(aSymbol == #retMethodVar2) ifTrue:[^161].
|
|
1489 |
(aSymbol == #retMethodVar3) ifTrue:[^162].
|
|
1490 |
(aSymbol == #retMethodVar4) ifTrue:[^163].
|
|
1491 |
(aSymbol == #retMethodVar5) ifTrue:[^164].
|
|
1492 |
(aSymbol == #retMethodVar6) ifTrue:[^165].
|
|
1493 |
|
|
1494 |
(aSymbol == #retInstVar1) ifTrue:[^166].
|
|
1495 |
(aSymbol == #retInstVar2) ifTrue:[^167].
|
|
1496 |
(aSymbol == #retInstVar3) ifTrue:[^168].
|
|
1497 |
(aSymbol == #retInstVar4) ifTrue:[^169].
|
|
1498 |
(aSymbol == #retInstVar5) ifTrue:[^170].
|
|
1499 |
(aSymbol == #retInstVar6) ifTrue:[^171].
|
|
1500 |
(aSymbol == #retInstVar7) ifTrue:[^172].
|
|
1501 |
(aSymbol == #retInstVar8) ifTrue:[^173].
|
|
1502 |
|
|
1503 |
(aSymbol == #retMethodArg1) ifTrue:[^174].
|
|
1504 |
(aSymbol == #retMethodArg2) ifTrue:[^175].
|
|
1505 |
|
|
1506 |
(aSymbol == #pushBlockArg1) ifTrue:[stackDelta := 1. ^140].
|
|
1507 |
(aSymbol == #pushBlockArg2) ifTrue:[stackDelta := 1. ^141].
|
|
1508 |
(aSymbol == #pushBlockArg3) ifTrue:[stackDelta := 1. ^142].
|
|
1509 |
(aSymbol == #pushBlockArg4) ifTrue:[stackDelta := 1. ^143].
|
|
1510 |
|
1
|
1511 |
(aSymbol == #pushOuter1BlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 43].
|
|
1512 |
(aSymbol == #pushOuter2BlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 44].
|
0
|
1513 |
|
5
|
1514 |
(aSymbol == #=) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^130].
|
|
1515 |
(aSymbol == #+) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^131].
|
|
1516 |
(aSymbol == #~=) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^132].
|
|
1517 |
(aSymbol == #-) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^133].
|
108
|
1518 |
(aSymbol == #*) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^230].
|
0
|
1519 |
(aSymbol == #class) ifTrue:[self addLiteral:aSymbol. ^134].
|
5
|
1520 |
(aSymbol == #x) ifTrue:[lineno := true. self addLiteral:aSymbol. ^106].
|
|
1521 |
(aSymbol == #y) ifTrue:[lineno := true. self addLiteral:aSymbol. ^107].
|
|
1522 |
(aSymbol == #width) ifTrue:[lineno := true. self addLiteral:aSymbol. ^108].
|
|
1523 |
(aSymbol == #height) ifTrue:[lineno := true. self addLiteral:aSymbol. ^109].
|
|
1524 |
(aSymbol == #origin) ifTrue:[lineno := true. self addLiteral:aSymbol. ^154].
|
|
1525 |
(aSymbol == #extent) ifTrue:[lineno := true. self addLiteral:aSymbol. ^155].
|
|
1526 |
(aSymbol == #at:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^135].
|
|
1527 |
(aSymbol == #at:put:)ifTrue:[lineno := true. stackDelta := -2. self addLiteral:aSymbol. ^136].
|
|
1528 |
(aSymbol == #bitAnd:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^137].
|
|
1529 |
(aSymbol == #bitOr:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^138].
|
|
1530 |
(aSymbol == #plus1) ifTrue:[lineno := true. self addLiteral:#+. ^123].
|
|
1531 |
(aSymbol == #minus1) ifTrue:[lineno := true. self addLiteral:#-. ^124].
|
0
|
1532 |
|
5
|
1533 |
(aSymbol == #incMethodVar) ifTrue:[lineno := true. self addLiteral:#+. extra := #index. ^125].
|
|
1534 |
(aSymbol == #decMethodVar) ifTrue:[lineno := true. self addLiteral:#-. extra := #index. ^126].
|
0
|
1535 |
|
|
1536 |
(aSymbol == #eq0) ifTrue:[self addLiteral:#==. ^48].
|
|
1537 |
(aSymbol == #ne0) ifTrue:[self addLiteral:#~~. ^49].
|
|
1538 |
|
5
|
1539 |
(aSymbol == #>) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 145].
|
|
1540 |
(aSymbol == #>=) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 146].
|
|
1541 |
(aSymbol == #<) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 147].
|
|
1542 |
(aSymbol == #<=) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 148].
|
|
1543 |
(aSymbol == #next) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 149].
|
|
1544 |
(aSymbol == #peek) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 150].
|
|
1545 |
(aSymbol == #value) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 151].
|
|
1546 |
(aSymbol == #value:) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 152].
|
6
|
1547 |
(aSymbol == #value:value:) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -2. ^ 178].
|
5
|
1548 |
(aSymbol == #size) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 153].
|
|
1549 |
(aSymbol == #asInteger) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 158].
|
|
1550 |
(aSymbol == #rounded) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 159].
|
0
|
1551 |
(aSymbol == #mk0Block) ifTrue:[^ 156].
|
|
1552 |
(aSymbol == #mkNilBlock) ifTrue:[^ 157].
|
|
1553 |
|
103
|
1554 |
(aSymbol == #gt0) ifTrue:[lineno := true. self addLiteral:#>. ^ 212].
|
117
|
1555 |
(aSymbol == #pushgt0) ifTrue:[lineno := true. stackDelta := 1. self addLiteral:#>. ^ 208].
|
106
|
1556 |
(aSymbol == #basicNew) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 211].
|
|
1557 |
(aSymbol == #new) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 213].
|
111
|
1558 |
(aSymbol == #basicNew:) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 214].
|
|
1559 |
(aSymbol == #new:) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 215].
|
103
|
1560 |
|
0
|
1561 |
(aSymbol == #falseJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 190].
|
|
1562 |
(aSymbol == #trueJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 191].
|
|
1563 |
(aSymbol == #nilJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 192].
|
|
1564 |
(aSymbol == #notNilJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 193].
|
|
1565 |
(aSymbol == #jumpabs) ifTrue:[extra := #absoffset. ^ 194].
|
1
|
1566 |
(aSymbol == #makeBlockabs) ifTrue:[stackDelta := 1. extra := #absoffsetNvarNarg. ^ 195].
|
0
|
1567 |
(aSymbol == #zeroJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 196].
|
|
1568 |
(aSymbol == #notZeroJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 197].
|
1
|
1569 |
(aSymbol == #eqJumpabs) ifTrue:[stackDelta := -2. extra := #absoffset. ^ 198].
|
|
1570 |
(aSymbol == #notEqJumpabs) ifTrue:[stackDelta := -2. extra := #absoffset. ^ 199].
|
0
|
1571 |
|
|
1572 |
(aSymbol == #pushThisContext) ifTrue:[stackDelta := 1. ^ 144].
|
|
1573 |
|
76
|
1574 |
(aSymbol == #isNil) ifTrue:[^ 188].
|
|
1575 |
(aSymbol == #notNil) ifTrue:[^ 189].
|
|
1576 |
(aSymbol == #not) ifTrue:[lineno := true. ^ 179].
|
110
|
1577 |
(aSymbol == #&) ifTrue:[lineno := true. ^ 216].
|
|
1578 |
(aSymbol == #|) ifTrue:[lineno := true. ^ 217].
|
76
|
1579 |
|
117
|
1580 |
(aSymbol == #pushClassVarL) ifTrue:[stackDelta := 1. extra := #speciallitL. ^ 218].
|
|
1581 |
(aSymbol == #pushGlobalL) ifTrue:[stackDelta := 1. extra := #speciallitL. ^ 218].
|
|
1582 |
(aSymbol == #storeClassVarL) ifTrue:[extra := #speciallitL.stackDelta := -1. ^ 219].
|
|
1583 |
(aSymbol == #storeGlobalL) ifTrue:[extra := #speciallitL. stackDelta := -1. ^ 219].
|
|
1584 |
(aSymbol == #pushLitL) ifTrue:[stackDelta := 1. extra := #unsigned16. ^ 201].
|
|
1585 |
|
|
1586 |
(aSymbol == #sendL) ifTrue:[lineno := true. extra := #specialL. ^ 205].
|
|
1587 |
(aSymbol == #sendSelfL) ifTrue:[lineno := true. extra := #specialL. ^ 207].
|
|
1588 |
(aSymbol == #sendDropL) ifTrue:[lineno := true. extra := #specialL. ^ 204].
|
|
1589 |
(aSymbol == #superSendL) ifTrue:[lineno := true. extra := #specialL. ^ 206].
|
|
1590 |
(aSymbol == #hereSendL) ifTrue:[lineno := true. extra := #specialL. ^ 206].
|
106
|
1591 |
|
0
|
1592 |
self error:'invalid code symbol'.
|
|
1593 |
errorFlag := #Error
|
117
|
1594 |
|
|
1595 |
"Modified: 3.9.1995 / 12:58:47 / claus"
|
0
|
1596 |
! !
|
49
|
1597 |
|
|
1598 |
!ByteCodeCompiler methodsFor:'machine code generation'!
|
|
1599 |
|
|
1600 |
compileToMachineCode:aString forClass:aClass inCategory:cat
|
84
|
1601 |
notifying:requestor install:install skipIfSame:skipIfSame silent:silent
|
49
|
1602 |
"this is called to compile primitive code.
|
|
1603 |
This is EXPERIMENTAL and going to be changed to raise an error,
|
|
1604 |
an redefined in subclasses which can do it (either by direct compilation, or by calling
|
|
1605 |
the external stc do do it.
|
|
1606 |
For a description of the arguments, see compile:forClass....."
|
|
1607 |
|
54
|
1608 |
|stFileName stream handle address flags command oFileName soFileName
|
120
|
1609 |
initName newMethod ok status className sep class stcPath
|
125
|
1610 |
errorStream errorMessages eMsg|
|
96
|
1611 |
|
125
|
1612 |
ObjectFileLoader isNil ifTrue:[^ #Error].
|
101
|
1613 |
STCCompilation == #never ifTrue:[^ #Error].
|
120
|
1614 |
(stcPath := self class incrementalStcPath) isNil ifTrue:[
|
|
1615 |
self parseError:'no stc compiler available - cannot create machine code' position:1.
|
|
1616 |
^ #Error
|
|
1617 |
].
|
54
|
1618 |
|
|
1619 |
SequenceNumber isNil ifTrue:[
|
|
1620 |
SequenceNumber := 0.
|
|
1621 |
].
|
|
1622 |
SequenceNumber := SequenceNumber + 1.
|
49
|
1623 |
|
54
|
1624 |
initName := 'ttt' , SequenceNumber printString.
|
|
1625 |
stFileName := initName , '.st'.
|
|
1626 |
stream := stFileName asFilename writeStream.
|
97
|
1627 |
sep := stream class chunkSeparator.
|
49
|
1628 |
|
101
|
1629 |
class := aClass.
|
|
1630 |
class isMeta ifTrue:[
|
|
1631 |
class := aClass soleInstance
|
|
1632 |
].
|
|
1633 |
class allSuperclasses reverseDo:[:cls|
|
54
|
1634 |
cls ~~ Object ifTrue:[
|
110
|
1635 |
cls isLoaded ifFalse:[
|
|
1636 |
^ #Error
|
|
1637 |
].
|
54
|
1638 |
cls fileOutDefinitionOn:stream.
|
96
|
1639 |
stream nextPut:sep; cr.
|
54
|
1640 |
]
|
|
1641 |
].
|
101
|
1642 |
class fileOutDefinitionOn:stream.
|
96
|
1643 |
stream nextPut:sep; cr.
|
54
|
1644 |
|
101
|
1645 |
class fileOutPrimitiveDefinitionsOn:stream.
|
49
|
1646 |
|
96
|
1647 |
stream nextPut:sep.
|
|
1648 |
className := aClass name.
|
|
1649 |
|
49
|
1650 |
aClass isMeta ifTrue:[
|
96
|
1651 |
stream nextPutAll:(className copyTo:(className size - 5)); nextPutAll:' class'.
|
49
|
1652 |
] ifFalse:[
|
96
|
1653 |
stream nextPutAll:className.
|
49
|
1654 |
].
|
96
|
1655 |
stream nextPutAll:' methodsFor:'''; nextPutAll:cat; nextPutAll:''''.
|
|
1656 |
stream nextPut:sep.
|
49
|
1657 |
stream cr.
|
|
1658 |
|
125
|
1659 |
stream nextPutAll:'"{ Line: 0 }"'; cr; nextPutAll:aString.
|
96
|
1660 |
stream nextPut:sep; space; nextPut:sep.
|
|
1661 |
|
49
|
1662 |
stream close.
|
|
1663 |
|
|
1664 |
"
|
|
1665 |
call stc to compile it
|
|
1666 |
"
|
94
|
1667 |
oFileName := './' , initName , '.o'.
|
|
1668 |
oFileName asFilename delete.
|
49
|
1669 |
|
124
|
1670 |
flags := '+sharedLibCode +newIncremental -EerrorOutput -N' , initName .
|
|
1671 |
STCCompilationDefines notNil ifTrue:[
|
|
1672 |
flags := STCCompilationDefines , ' ' , flags
|
|
1673 |
].
|
|
1674 |
STCCompilationIncludes notNil ifTrue:[
|
|
1675 |
flags := STCCompilationIncludes , ' ' , flags
|
|
1676 |
].
|
|
1677 |
STCCompilationOptions notNil ifTrue:[
|
|
1678 |
flags := STCCompilationOptions , ' ' , flags
|
54
|
1679 |
].
|
|
1680 |
|
101
|
1681 |
command := stcPath , ' ' , flags , ' -c ' , stFileName.
|
54
|
1682 |
"/ command printNL.
|
|
1683 |
|
120
|
1684 |
ok := OperatingSystem executeCommand:command.
|
|
1685 |
status := OperatingSystem lastExecStatus.
|
101
|
1686 |
|
120
|
1687 |
"for debugging - leave c intermediate"
|
|
1688 |
STCKeepCIntermediate == true ifTrue:[
|
101
|
1689 |
command := stcPath , ' ' , flags , ' -C ' , stFileName.
|
|
1690 |
command printNL.
|
120
|
1691 |
OperatingSystem executeCommand:command
|
49
|
1692 |
].
|
|
1693 |
|
94
|
1694 |
oFileName asFilename exists ifTrue:[
|
|
1695 |
ok ifFalse:[
|
|
1696 |
'oops - system says it failed - but o-file is there ...' printNL.
|
|
1697 |
ok := true
|
|
1698 |
]
|
|
1699 |
] ifFalse:[
|
|
1700 |
ok := false
|
|
1701 |
].
|
|
1702 |
|
54
|
1703 |
ok ifFalse:[
|
|
1704 |
status >= 16r200 ifTrue:[
|
120
|
1705 |
errorStream := 'errorOutput' asFilename readStream.
|
|
1706 |
errorStream notNil ifTrue:[
|
|
1707 |
errorMessages := errorStream contents.
|
|
1708 |
errorMessages notNil ifTrue:[
|
|
1709 |
errorMessages := errorMessages asStringCollection.
|
|
1710 |
errorMessages size > 20 ifTrue:[
|
|
1711 |
errorMessages := (errorMessages copyTo:20) copyWith:'... more messages skipped'
|
|
1712 |
].
|
|
1713 |
errorMessages := errorMessages asString
|
|
1714 |
].
|
|
1715 |
].
|
|
1716 |
errorMessages isNil ifTrue:[
|
|
1717 |
errorMessages := ''
|
|
1718 |
].
|
125
|
1719 |
eMsg := ('STC error during compilation:\',errorMessages) withCRs.
|
54
|
1720 |
] ifFalse:[
|
125
|
1721 |
eMsg := 'oops, no STC - cannot create machine code'
|
54
|
1722 |
].
|
125
|
1723 |
self parseError:eMsg position:1.
|
120
|
1724 |
OperatingSystem removeFile:stFileName.
|
|
1725 |
^ #Error
|
|
1726 |
].
|
|
1727 |
|
|
1728 |
(ObjectFileLoader notNil
|
|
1729 |
and:[ObjectFileLoader canLoadObjectFiles]) ifFalse:[
|
|
1730 |
self parseError:'no dynamic load configured - cannot load machine code' position:1.
|
|
1731 |
OperatingSystem removeFile:stFileName.
|
54
|
1732 |
^ #Error
|
|
1733 |
].
|
|
1734 |
|
49
|
1735 |
OperatingSystem getOSType = 'irix' ifTrue:[
|
|
1736 |
"
|
|
1737 |
link it to a shared object
|
|
1738 |
"
|
54
|
1739 |
soFileName := './' , initName , '.so'.
|
|
1740 |
OperatingSystem executeCommand:'rm -f ' , soFileName.
|
|
1741 |
OperatingSystem executeCommand:'ld -shared -all -o ' , soFileName , ' ' , oFileName.
|
120
|
1742 |
OperatingSystem removeFile:oFileName.
|
54
|
1743 |
oFileName := soFileName.
|
98
|
1744 |
] ifFalse:[
|
125
|
1745 |
OperatingSystem getOSType = 'sys5_4' ifTrue:[
|
98
|
1746 |
"
|
|
1747 |
link it to a shared object
|
|
1748 |
"
|
|
1749 |
soFileName := './' , initName , '.so'.
|
|
1750 |
OperatingSystem executeCommand:'rm -f ' , soFileName.
|
|
1751 |
OperatingSystem executeCommand:'ld -G -o ' , soFileName , ' ' , oFileName.
|
120
|
1752 |
OperatingSystem removeFile:oFileName.
|
98
|
1753 |
oFileName := soFileName.
|
|
1754 |
].
|
49
|
1755 |
].
|
|
1756 |
|
|
1757 |
"
|
|
1758 |
load the objectfile
|
|
1759 |
"
|
109
|
1760 |
handle := ObjectFileLoader loadDynamicObject:oFileName.
|
49
|
1761 |
handle isNil ifTrue:[
|
120
|
1762 |
OperatingSystem removeFile:stFileName.
|
|
1763 |
OperatingSystem removeFile:oFileName.
|
118
|
1764 |
self parseError:'dynamic load failed - cannot create machine code' position:1.
|
49
|
1765 |
^ #Error
|
|
1766 |
].
|
54
|
1767 |
"/ ('handle is ' , handle printString) printNL.
|
49
|
1768 |
|
54
|
1769 |
address := ObjectFileLoader getFunction:'__' , initName , '_Init' from:handle.
|
49
|
1770 |
address isNil ifTrue:[
|
54
|
1771 |
address := ObjectFileLoader getFunction:'_' , initName , '_Init' from:handle.
|
49
|
1772 |
address isNil ifTrue:[
|
125
|
1773 |
(ObjectFileLoader getListOfUndefinedSymbolsFrom:handle) size > 0 ifTrue:[
|
|
1774 |
ObjectFileLoader listUndefinedSymbolsIn:handle.
|
|
1775 |
eMsg := 'undefined symbols in primitive code'.
|
|
1776 |
] ifFalse:[
|
|
1777 |
eMsg := initName , '_Init() lookup failed'
|
|
1778 |
].
|
|
1779 |
|
|
1780 |
ObjectFileLoader unloadDynamicObject:handle.
|
|
1781 |
|
120
|
1782 |
OperatingSystem removeFile:stFileName.
|
|
1783 |
OperatingSystem removeFile:oFileName.
|
125
|
1784 |
self parseError:(eMsg , ' - cannot create machine code') position:1.
|
49
|
1785 |
^ #Error
|
|
1786 |
]
|
|
1787 |
].
|
|
1788 |
|
54
|
1789 |
"/ ('init at ' , address printString) printNL.
|
|
1790 |
|
94
|
1791 |
ObjectFileLoader
|
|
1792 |
callInitFunctionAt:address
|
|
1793 |
specialInit:true
|
|
1794 |
forceOld:true
|
|
1795 |
interruptable:false
|
109
|
1796 |
argument:2
|
|
1797 |
identifyAs:handle.
|
49
|
1798 |
|
54
|
1799 |
"
|
|
1800 |
did it work ?
|
|
1801 |
"
|
96
|
1802 |
newMethod := aClass compiledMethodAt:selector.
|
54
|
1803 |
newMethod notNil ifTrue:[
|
|
1804 |
newMethod source:aString.
|
|
1805 |
aClass addChangeRecordForMethod:newMethod.
|
|
1806 |
(silent or:[Smalltalk silentLoading == true]) ifFalse:[
|
96
|
1807 |
Transcript showCr:(' compiled: ', className,' ',selector,' - machine code')
|
54
|
1808 |
].
|
98
|
1809 |
ObjectMemory flushCaches.
|
120
|
1810 |
|
|
1811 |
OperatingSystem removeFile:stFileName.
|
|
1812 |
|
|
1813 |
handle method:newMethod.
|
|
1814 |
|
|
1815 |
"/ check for obsolete loaded objects and unload them
|
|
1816 |
|
|
1817 |
ObjectFileLoader loadedObjectHandlesDo:[:anotherHandle |
|
|
1818 |
anotherHandle isMethodHandle ifTrue:[
|
|
1819 |
anotherHandle method isNil ifTrue:[
|
|
1820 |
ObjectFileLoader unloadObjectFile:anotherHandle pathName.
|
|
1821 |
OperatingSystem removeFile:anotherHandle pathName.
|
|
1822 |
]
|
|
1823 |
]
|
|
1824 |
].
|
54
|
1825 |
^ newMethod.
|
|
1826 |
].
|
|
1827 |
|
120
|
1828 |
OperatingSystem removeFile:stFileName.
|
|
1829 |
OperatingSystem removeFile:oFileName.
|
54
|
1830 |
self parseError:'dynamic load failed' position:1.
|
49
|
1831 |
^ #Error
|
|
1832 |
|
|
1833 |
"
|
|
1834 |
|m|
|
|
1835 |
|
|
1836 |
Object subclass:#Test
|
|
1837 |
instanceVariableNames:''
|
|
1838 |
classVariableNames:''
|
|
1839 |
poolDictionaries:''
|
|
1840 |
category:'tests'.
|
|
1841 |
m := ByteCodeCompiler
|
|
1842 |
compile:'foo ^ ''hello'''
|
|
1843 |
forClass:Test
|
|
1844 |
inCategory:'tests'
|
|
1845 |
notifying:nil
|
|
1846 |
install:false
|
|
1847 |
skipIfSame:false.
|
|
1848 |
m inspect
|
|
1849 |
"
|
|
1850 |
"
|
|
1851 |
|m|
|
|
1852 |
|
|
1853 |
Object subclass:#Test
|
|
1854 |
instanceVariableNames:''
|
|
1855 |
classVariableNames:''
|
|
1856 |
poolDictionaries:''
|
|
1857 |
category:'tests'.
|
|
1858 |
m := ByteCodeCompiler
|
|
1859 |
compileToMachineCode:'foo %{ RETURN (_MKSMALLINT(1)); %}'
|
|
1860 |
forClass:Test
|
|
1861 |
inCategory:'tests'
|
|
1862 |
notifying:nil
|
|
1863 |
install:false
|
|
1864 |
skipIfSame:false
|
|
1865 |
silent:false.
|
|
1866 |
m inspect
|
|
1867 |
"
|
120
|
1868 |
|
|
1869 |
"Modified: 14.9.1995 / 22:33:04 / claus"
|
97
|
1870 |
!
|
|
1871 |
|
|
1872 |
trappingStubMethodFor:aString inCategory:cat
|
|
1873 |
"return a stub method which traps and reports an error whenever
|
|
1874 |
called."
|
|
1875 |
|
|
1876 |
|newMethod lits|
|
|
1877 |
|
|
1878 |
newMethod := Method new.
|
|
1879 |
lits := self literalArray.
|
|
1880 |
lits notNil ifTrue:[
|
|
1881 |
"literals MUST be an array - not just any Collection"
|
|
1882 |
lits := Array withAll:lits.
|
|
1883 |
newMethod literals:lits
|
|
1884 |
].
|
124
|
1885 |
newMethod makeUncompiled.
|
97
|
1886 |
newMethod numberOfMethodVars:(self numberOfMethodVars).
|
|
1887 |
newMethod numberOfMethodArgs:(self numberOfMethodArgs).
|
|
1888 |
newMethod source:aString.
|
|
1889 |
newMethod category:cat.
|
|
1890 |
Project notNil ifTrue:[
|
98
|
1891 |
newMethod package:(Project currentPackageName)
|
97
|
1892 |
].
|
|
1893 |
^ newMethod
|
49
|
1894 |
! !
|