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