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