author | Claus Gittinger <cg@exept.de> |
Wed, 25 Jun 1997 12:15:41 +0200 | |
changeset 549 | e403281da682 |
parent 530 | 1736f549e86d |
child 556 | 4a3775ada5d2 |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
45 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Parser subclass:#ByteCodeCompiler |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
14 |
instanceVariableNames:'codeBytes codeIndex litArray stackDelta extra lineno extraLiteral |
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
15 |
maxStackDepth relocList' |
172
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
16 |
classVariableNames:'JumpToAbsJump SequenceNumber STCCompilationDefines |
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
17 |
STCCompilationIncludes STCCompilationOptions STCCompilation |
407 | 18 |
ShareCode STCKeepSTIntermediate STCKeepCIntermediate |
411
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
19 |
STCModulePath CCCompilationOptions CC' |
172
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
20 |
poolDictionaries:'' |
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
21 |
category:'System-Compiler' |
0 | 22 |
! |
23 |
||
372
98da4d230a8d
prepare support for 16-bit lineNumbers
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
24 |
!ByteCodeCompiler class methodsFor:'documentation'! |
3 | 25 |
|
141 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
135
aa4f7b8f121e
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
128
diff
changeset
|
38 |
! |
20 | 39 |
|
3 | 40 |
documentation |
41 |
" |
|
19 | 42 |
This class performs compilation into ByteCodes. |
43 |
First, parsing is done using superclass methods, |
|
44 |
then the parse-tree is converted into an array of symbolic codes |
|
45 |
and a relocation table; |
|
46 |
these two are finally combined into a byteArray of the codes. |
|
0 | 47 |
|
19 | 48 |
(the intermediate step through symbolic codes is for debugging |
49 |
only - it will vanish) |
|
50 |
||
51 |
There are many dependencies to the run-time-system (especially the |
|
52 |
interpreter) in here - be careful when playing around ... |
|
0 | 53 |
|
259 | 54 |
[Instance variables:] |
0 | 55 |
|
512 | 56 |
codeBytes <ByteArry> bytecodes |
57 |
codeIndex <SmallInteger> next index to put into code array |
|
58 |
litArray <OrderedCollection> literals |
|
59 |
stackDelta <SmallInteger> return value of byteCodeFor: |
|
60 |
extra <Symbol> return value of byteCodeFor: |
|
61 |
lineno <Boolean> return value of byteCodeFor: |
|
62 |
extraLiteral <Symbol> return value of byteCodeFor: |
|
63 |
maxStackDepth <SmallInteger> stack need of method |
|
64 |
relocList <Array> used temporary for relocation |
|
19 | 65 |
|
259 | 66 |
[Class variables:] |
19 | 67 |
|
512 | 68 |
JumpToAbsJump <Dictionary> internal table to map opcodes |
69 |
||
70 |
SequenceNumber <Integer> counting intermediate stc-compiled |
|
71 |
objects (for unique o-file naming) |
|
72 |
||
73 |
STCCompilationDefines passed to stc as command line arguments |
|
74 |
STCCompilationIncludes |
|
75 |
STCCompilationOptions |
|
76 |
<String> |
|
77 |
||
78 |
STCCompilation <Symbol> #always, #primitiveOnly or #never |
|
79 |
controls when stc compilation is wanted |
|
80 |
||
81 |
ShareCode <Boolean> reuse byteArrays for common (simple) code sequences |
|
82 |
This is normally a 'good' optimization, |
|
83 |
expect if you plan to modify the byteCodes. |
|
263 | 84 |
|
85 |
[author:] |
|
512 | 86 |
Claus Gittinger |
263 | 87 |
|
3 | 88 |
" |
98 | 89 |
! ! |
90 |
||
372
98da4d230a8d
prepare support for 16-bit lineNumbers
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
91 |
!ByteCodeCompiler class methodsFor:'initialization'! |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
92 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
93 |
initialize |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
94 |
ShareCode := true. |
295 | 95 |
STCKeepCIntermediate := false. |
407 | 96 |
STCKeepSTIntermediate := false. |
301
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
97 |
STCModulePath := './modules'. |
211
1fd13827a2fc
ask CCReader about the sourceMode
Claus Gittinger <cg@exept.de>
parents:
209
diff
changeset
|
98 |
|
407 | 99 |
"Modified: 1.11.1996 / 19:33:26 / cg" |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
100 |
! ! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
101 |
|
372
98da4d230a8d
prepare support for 16-bit lineNumbers
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
102 |
!ByteCodeCompiler class methodsFor:'compiling methods'! |
98 | 103 |
|
0 | 104 |
compile:methodText forClass:classToCompileFor |
105 |
"compile a source-string for a method in classToCompileFor" |
|
106 |
||
107 |
^ self compile:methodText |
|
45 | 108 |
forClass:classToCompileFor |
109 |
inCategory:'others' |
|
110 |
notifying:nil |
|
111 |
install:true |
|
112 |
skipIfSame:false |
|
113 |
silent:false |
|
0 | 114 |
! |
115 |
||
116 |
compile:aString forClass:aClass inCategory:cat |
|
117 |
"compile a source-string for a method in classToCompileFor. |
|
118 |
The method will get cat as category" |
|
119 |
||
120 |
^ self compile:aString |
|
45 | 121 |
forClass:aClass |
122 |
inCategory:cat |
|
123 |
notifying:nil |
|
124 |
install:true |
|
125 |
skipIfSame:false |
|
126 |
silent:false |
|
0 | 127 |
! |
128 |
||
84 | 129 |
compile:aString forClass:aClass inCategory:cat notifying:requestor |
0 | 130 |
"compile a source-string for a method in classToCompileFor. |
84 | 131 |
errors are forwarded to requestor. |
0 | 132 |
The method will get cat as category" |
133 |
||
134 |
^ self compile:aString |
|
45 | 135 |
forClass:aClass |
136 |
inCategory:cat |
|
84 | 137 |
notifying:requestor |
45 | 138 |
install:true |
139 |
skipIfSame:false |
|
140 |
silent:false |
|
0 | 141 |
! |
142 |
||
141 | 143 |
compile:aString forClass:aClass inCategory:cat notifying:requestor install:install |
144 |
"compile a source-string for a method in classToCompileFor. |
|
145 |
The install-argument controls if the method is to be installed into the |
|
146 |
classes method-dictionary, or just to be compiled and a method object to be returned. |
|
147 |
Errors are forwarded to requestor. The method will get cat as category" |
|
148 |
||
149 |
^ self compile:aString |
|
150 |
forClass:aClass |
|
151 |
inCategory:cat |
|
152 |
notifying:requestor |
|
153 |
install:install |
|
154 |
skipIfSame:false |
|
155 |
silent:false |
|
156 |
! |
|
157 |
||
158 |
compile:aString forClass:aClass inCategory:cat notifying:requestor |
|
159 |
install:install skipIfSame:skipIfSame |
|
160 |
"compile a source-string for a method in classToCompileFor. |
|
161 |
The install-argument controls if the method is to be installed into the |
|
162 |
classes method-dictionary, or just to be compiled and a method object to be returned. |
|
163 |
Errors are forwarded to requestor. The method will get cat as category. |
|
164 |
If skipIsSame is true, and the source is the same as an existing |
|
165 |
methods source, this is a noop (for fast fileIn)." |
|
166 |
||
167 |
^ self compile:aString |
|
168 |
forClass:aClass |
|
169 |
inCategory:cat |
|
170 |
notifying:requestor |
|
171 |
install:install |
|
172 |
skipIfSame:skipIfSame |
|
173 |
silent:false |
|
174 |
! |
|
175 |
||
84 | 176 |
compile:aString forClass:aClass inCategory:cat notifying:requestor |
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
177 |
install:install skipIfSame:skipIfSame silent:silent |
230
54e13c76f143
allow constant folding to be turned off
Claus Gittinger <cg@exept.de>
parents:
217
diff
changeset
|
178 |
|
54e13c76f143
allow constant folding to be turned off
Claus Gittinger <cg@exept.de>
parents:
217
diff
changeset
|
179 |
^ self |
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
180 |
compile:aString |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
181 |
forClass:aClass |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
182 |
inCategory:cat |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
183 |
notifying:requestor |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
184 |
install:install |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
185 |
skipIfSame:skipIfSame |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
186 |
silent:silent |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
187 |
foldConstants:true |
230
54e13c76f143
allow constant folding to be turned off
Claus Gittinger <cg@exept.de>
parents:
217
diff
changeset
|
188 |
! |
54e13c76f143
allow constant folding to be turned off
Claus Gittinger <cg@exept.de>
parents:
217
diff
changeset
|
189 |
|
54e13c76f143
allow constant folding to be turned off
Claus Gittinger <cg@exept.de>
parents:
217
diff
changeset
|
190 |
compile:aString forClass:aClass inCategory:cat notifying:requestor |
512 | 191 |
install:install skipIfSame:skipIfSame silent:silent foldConstants:fold |
20 | 192 |
|
193 |
"the basic workhorse method for compiling: |
|
0 | 194 |
compile a source-string for a method in classToCompileFor. |
84 | 195 |
errors are forwarded to requestor (report on Transcript and return |
196 |
#Error, if requestor is nil). |
|
0 | 197 |
|
20 | 198 |
The new method will get cat as category. |
199 |
If install is true, the method will go into the classes method-table, |
|
200 |
otherwise the method is simply returned (for anonymous methods). |
|
0 | 201 |
If skipIsSame is true, and the source is the same as an existing |
20 | 202 |
methods source, this is a noop (for fast fileIn). |
203 |
The argument, silent controls if errors are to be reported." |
|
0 | 204 |
|
429 | 205 |
|compiler newMethod tree symbolicCodeArray oldMethod lazy silencio |
459
3a0a95c1a0e8
unchanged methods may have a new package id
Claus Gittinger <cg@exept.de>
parents:
439
diff
changeset
|
206 |
sourceFile sourceStream newSource primNr pos sel keptOldCode msg answer |
3a0a95c1a0e8
unchanged methods may have a new package id
Claus Gittinger <cg@exept.de>
parents:
439
diff
changeset
|
207 |
pkg| |
0 | 208 |
|
209 |
aString isNil ifTrue:[^ nil]. |
|
54 | 210 |
silencio := silent or:[Smalltalk silentLoading == true]. |
0 | 211 |
|
19 | 212 |
"lazy compilation is EXPERIMENTAL" |
213 |
lazy := (LazyCompilation == true) and:[install]. |
|
214 |
||
0 | 215 |
"create a compiler, let it parse and create the parsetree" |
216 |
||
54 | 217 |
compiler := self for:(ReadStream on:aString) in:aClass. |
84 | 218 |
compiler parseForCode. |
230
54e13c76f143
allow constant folding to be turned off
Claus Gittinger <cg@exept.de>
parents:
217
diff
changeset
|
219 |
fold ifFalse:[compiler foldConstants:nil]. |
84 | 220 |
compiler notifying:requestor. |
54 | 221 |
silent ifTrue:[ |
222 |
"/ compiler ignoreErrors. |
|
512 | 223 |
compiler ignoreWarnings |
54 | 224 |
]. |
256
ae09ebb4aa35
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
253
diff
changeset
|
225 |
"/ compiler nextToken. |
350
13e1dcaf87eb
oops - the classes version method may not be lazy
Claus Gittinger <cg@exept.de>
parents:
330
diff
changeset
|
226 |
|
0 | 227 |
(compiler parseMethodSpec == #Error) ifTrue:[ |
512 | 228 |
compiler parseError:'syntax error in method specification'. |
229 |
tree := #Error |
|
0 | 230 |
] ifFalse:[ |
512 | 231 |
lazy ifTrue:[ |
232 |
"/ |
|
233 |
"/ that one method IS required |
|
234 |
"/ |
|
235 |
(aClass isMeta and:[compiler selector == #version]) ifTrue:[ |
|
236 |
lazy := false |
|
237 |
] |
|
238 |
]. |
|
239 |
||
240 |
lazy ifFalse:[ |
|
241 |
"check if same source" |
|
242 |
(skipIfSame and:[(sel := compiler selector) notNil]) ifTrue:[ |
|
243 |
oldMethod := aClass compiledMethodAt:sel. |
|
244 |
oldMethod notNil ifTrue:[ |
|
245 |
oldMethod source = aString ifTrue:[ |
|
246 |
oldMethod isInvalid ifFalse:[ |
|
247 |
silencio ifFalse:[ |
|
248 |
Transcript showCR:(' unchanged: ',aClass name,' ',compiler selector) |
|
249 |
]. |
|
250 |
" |
|
251 |
same. however, category may be different |
|
252 |
" |
|
253 |
(cat notNil and:[cat ~= oldMethod category]) ifTrue:[ |
|
254 |
oldMethod category:cat. |
|
255 |
oldMethod changed:#category. |
|
459
3a0a95c1a0e8
unchanged methods may have a new package id
Claus Gittinger <cg@exept.de>
parents:
439
diff
changeset
|
256 |
"/ aClass updateRevisionString. |
512 | 257 |
aClass addChangeRecordForMethodCategory:oldMethod category:cat. |
258 |
silencio ifFalse:[ |
|
259 |
Transcript showCR:(' (category change only)') |
|
260 |
]. |
|
261 |
]. |
|
262 |
" |
|
263 |
and package may be too. |
|
264 |
" |
|
265 |
pkg := Class packageQuerySignal raise. |
|
266 |
(pkg notNil and:[pkg ~~ oldMethod package]) ifTrue:[ |
|
267 |
oldMethod package:pkg. |
|
268 |
silencio ifFalse:[ |
|
269 |
Transcript showCR:(' (package-id change only)') |
|
270 |
]. |
|
271 |
]. |
|
272 |
^ oldMethod |
|
273 |
] |
|
274 |
] |
|
275 |
] |
|
276 |
]. |
|
277 |
tree := compiler parseMethodBody. |
|
278 |
compiler tree:tree. |
|
279 |
] |
|
0 | 280 |
]. |
281 |
||
282 |
(compiler errorFlag or:[tree == #Error]) ifTrue:[ |
|
512 | 283 |
compiler showErrorMessageForClass:aClass. |
284 |
^ #Error |
|
0 | 285 |
]. |
286 |
||
191 | 287 |
sel := compiler selector. |
19 | 288 |
"if no error and also no selector ..." |
90 | 289 |
sel isNil ifTrue:[ |
512 | 290 |
"... it was just a comment or other empty stuff" |
291 |
^ nil |
|
0 | 292 |
]. |
293 |
||
191 | 294 |
lazy ifFalse:[ |
512 | 295 |
" |
296 |
freak-out support ... |
|
297 |
" |
|
298 |
(compiler hasNonOptionalPrimitiveCode |
|
299 |
or:[(compiler hasPrimitiveCode and:[self canCreateMachineCode]) |
|
300 |
or:[STCCompilation == #always and:[sel ~~ #doIt]]]) ifTrue:[ |
|
301 |
newMethod := compiler |
|
302 |
compileToMachineCode:aString |
|
303 |
forClass:aClass |
|
304 |
inCategory:cat |
|
305 |
notifying:requestor |
|
306 |
install:install |
|
307 |
skipIfSame:skipIfSame |
|
308 |
silent:silent. |
|
309 |
||
310 |
newMethod == #Error ifTrue:[ |
|
311 |
compiler showErrorMessageForClass:aClass. |
|
312 |
^ #Error |
|
313 |
]. |
|
314 |
||
315 |
(newMethod == #CannotLoad) ifTrue:[ |
|
316 |
newMethod := compiler trappingStubMethodFor:aString inCategory:cat. |
|
317 |
||
318 |
keptOldCode := false. |
|
319 |
install ifTrue:[ |
|
320 |
"/ |
|
321 |
"/ be very careful with existing methods |
|
322 |
"/ (otherwise, you could easily make your system unusable in systems which cannot load) |
|
323 |
"/ |
|
324 |
sel notNil ifTrue:[ |
|
325 |
oldMethod := aClass compiledMethodAt:sel |
|
326 |
]. |
|
327 |
(oldMethod notNil and:[oldMethod code ~= newMethod code]) ifTrue:[ |
|
328 |
answer := Dialog |
|
329 |
confirm:'installation of binary code is not possible or disabled. |
|
97 | 330 |
|
172
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
331 |
Shall I use the old methods functionality |
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
332 |
or instead create a dummy trap method for it ? |
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
333 |
|
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
334 |
Hint: |
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
335 |
if that method is needed by the system, you better leave the |
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
336 |
original functionality in the system. |
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
337 |
|
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
338 |
Close this warnBox to abort the compilation. |
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
339 |
' |
512 | 340 |
yesLabel:'trap code' |
341 |
noLabel:'keep old'. |
|
342 |
answer isNil ifTrue:[ |
|
343 |
^ #Error |
|
344 |
]. |
|
345 |
answer == false ifTrue:[ |
|
346 |
newMethod code:(oldMethod code). |
|
347 |
keptOldCode := true. |
|
348 |
]. |
|
349 |
]. |
|
350 |
aClass addSelector:sel withMethod:newMethod |
|
351 |
]. |
|
352 |
Transcript show:'*** '. |
|
353 |
sel notNil ifTrue:[ |
|
354 |
Transcript show:(sel ,' ') |
|
355 |
]. |
|
356 |
keptOldCode ifTrue:[ |
|
357 |
msg := 'not really compiled - method still shows previous behavior'. |
|
358 |
] ifFalse:[ |
|
359 |
msg := 'not compiled to machine code - created a stub instead.'. |
|
360 |
]. |
|
361 |
Transcript showCR:msg. |
|
362 |
]. |
|
363 |
^ newMethod |
|
364 |
]. |
|
19 | 365 |
]. |
366 |
||
54 | 367 |
" |
368 |
EXPERIMENTAL: quick loading |
|
369 |
only create a lazyMethod, which has no byteCode and will |
|
370 |
compile itself when first called. |
|
371 |
" |
|
19 | 372 |
lazy ifTrue:[ |
512 | 373 |
newMethod := LazyMethod new. |
374 |
(ClassCategoryReader sourceMode == #sourceReference) ifTrue:[ |
|
375 |
sourceFile := ObjectMemory nameForSources. |
|
376 |
sourceFile notNil ifTrue:[ |
|
377 |
sourceStream := sourceFile asFilename appendingWriteStream. |
|
378 |
] |
|
379 |
]. |
|
380 |
sourceStream isNil ifTrue:[ |
|
381 |
newMethod source:aString. |
|
382 |
] ifFalse:[ |
|
383 |
sourceStream setToEnd. |
|
384 |
pos := sourceStream position. |
|
385 |
sourceStream nextChunkPut:aString. |
|
386 |
sourceStream close. |
|
387 |
newMethod sourceFilename:sourceFile position:pos. |
|
388 |
]. |
|
389 |
newMethod category:cat. |
|
390 |
newMethod package:(Class packageQuerySignal raise). |
|
415 | 391 |
"/ Project notNil ifTrue:[ |
392 |
"/ newMethod package:(Project currentPackageName) |
|
393 |
"/ ]. |
|
19 | 394 |
|
512 | 395 |
aClass addSelector:sel withLazyMethod:newMethod. |
396 |
^ newMethod |
|
19 | 397 |
]. |
398 |
||
90 | 399 |
(primNr := compiler primitiveNumber) isNil ifTrue:[ |
512 | 400 |
" |
401 |
produce symbolic code first |
|
402 |
" |
|
403 |
symbolicCodeArray := compiler genSymbolicCode. |
|
404 |
||
405 |
(symbolicCodeArray == #Error) ifTrue:[ |
|
406 |
Transcript show:' '. |
|
407 |
sel notNil ifTrue:[ |
|
408 |
Transcript show:(sel ,' ') |
|
409 |
]. |
|
410 |
Transcript showCR:'translation error'. |
|
411 |
^ #Error |
|
412 |
]. |
|
413 |
||
414 |
" |
|
415 |
take this, producing bytecode |
|
416 |
(someone willin' to make machine code :-) |
|
417 |
" |
|
418 |
((compiler genByteCodeFrom:symbolicCodeArray) == #Error) ifTrue:[ |
|
419 |
Transcript show:' '. |
|
420 |
sel notNil ifTrue:[ |
|
421 |
Transcript show:(sel ,' ') |
|
422 |
]. |
|
423 |
Transcript showCR:'relocation error - must be simplified'. |
|
424 |
^ #Error |
|
425 |
]. |
|
0 | 426 |
]. |
427 |
||
54 | 428 |
" |
429 |
finally create the new method-object |
|
430 |
" |
|
277
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
431 |
newMethod := compiler createMethod. |
90 | 432 |
primNr notNil ifTrue:[ |
512 | 433 |
newMethod code:(compiler checkForPrimitiveCode:primNr). |
78 | 434 |
] ifFalse:[ |
512 | 435 |
newMethod byteCode:(compiler code). |
78 | 436 |
]. |
277
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
437 |
"/ newMethod numberOfMethodVars:(compiler numberOfMethodVars). |
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
438 |
"/ newMethod numberOfMethodArgs:(compiler numberOfMethodArgs). |
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
439 |
"/ newMethod stackSize:(compiler maxStackDepth). |
19 | 440 |
|
54 | 441 |
" |
442 |
if there where any corrections, install the updated source |
|
443 |
" |
|
90 | 444 |
(newSource := compiler correctedSource) notNil ifTrue:[ |
512 | 445 |
newMethod source:newSource |
19 | 446 |
] ifFalse:[ |
512 | 447 |
newMethod source:aString. |
19 | 448 |
]. |
0 | 449 |
newMethod category:cat. |
415 | 450 |
newMethod package:(Class packageQuerySignal raise). |
451 |
"/ Project notNil ifTrue:[ |
|
452 |
"/ newMethod package:(Project currentPackageName) |
|
453 |
"/ ]. |
|
0 | 454 |
|
455 |
install ifTrue:[ |
|
512 | 456 |
aClass addSelector:sel withMethod:newMethod |
0 | 457 |
]. |
458 |
||
54 | 459 |
silencio ifFalse:[ |
512 | 460 |
Transcript showCR:(' compiled: ', aClass name,' ', sel) |
0 | 461 |
]. |
462 |
||
463 |
^ newMethod |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
464 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
465 |
"Created: 29.10.1995 / 19:59:36 / cg" |
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
287
diff
changeset
|
466 |
"Modified: 24.6.1996 / 12:41:13 / stefan" |
459
3a0a95c1a0e8
unchanged methods may have a new package id
Claus Gittinger <cg@exept.de>
parents:
439
diff
changeset
|
467 |
"Modified: 3.1.1997 / 12:48:13 / cg" |
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
468 |
! |
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 |
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
|
471 |
"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
|
472 |
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
|
473 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
474 |
^ self compile:methodText |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
475 |
forClass:classToCompileFor |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
476 |
inCategory:'others' |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
477 |
notifying:requestor |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
478 |
install:true |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
479 |
skipIfSame:false |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
480 |
silent:false |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
481 |
! |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
482 |
|
141 | 483 |
compile:textOrStream in:aClass notifying:requestor ifFail:exceptionBlock |
484 |
"name alias for ST-80 compatibility" |
|
485 |
||
486 |
|m| |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
487 |
|
141 | 488 |
m := self |
489 |
compile:textOrStream |
|
490 |
forClass:aClass |
|
491 |
inCategory:'others' |
|
492 |
notifying:requestor |
|
493 |
install:true |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
494 |
skipIfSame:false |
141 | 495 |
silent:false. |
496 |
m == #Error ifTrue:[ |
|
497 |
^ exceptionBlock value |
|
498 |
]. |
|
499 |
^ m |
|
500 |
||
0 | 501 |
! ! |
502 |
||
372
98da4d230a8d
prepare support for 16-bit lineNumbers
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
503 |
!ByteCodeCompiler class methodsFor:'constants'! |
15 | 504 |
|
505 |
byteCodeFor:aSymbol |
|
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
506 |
"returns the numeric code for some symbolic bytecodes." |
15 | 507 |
|
25 | 508 |
(aSymbol == #retNil) ifTrue:[^ 1]. |
509 |
(aSymbol == #retTrue) ifTrue:[^ 2]. |
|
510 |
(aSymbol == #retFalse) ifTrue:[^ 3]. |
|
511 |
(aSymbol == #ret0) ifTrue:[^ 4]. |
|
512 |
(aSymbol == #retTop) ifTrue:[^ 0]. |
|
513 |
||
15 | 514 |
(aSymbol == #push0) ifTrue:[^120]. |
515 |
(aSymbol == #push1) ifTrue:[^121]. |
|
516 |
(aSymbol == #push2) ifTrue:[^139]. |
|
517 |
(aSymbol == #pushMinus1) ifTrue:[^122]. |
|
518 |
(aSymbol == #pushNil) ifTrue:[^ 10]. |
|
519 |
(aSymbol == #pushTrue) ifTrue:[^ 11]. |
|
520 |
(aSymbol == #pushFalse) ifTrue:[^ 12]. |
|
521 |
(aSymbol == #pushSelf) ifTrue:[^ 15]. |
|
522 |
self error |
|
523 |
! ! |
|
524 |
||
372
98da4d230a8d
prepare support for 16-bit lineNumbers
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
525 |
!ByteCodeCompiler class methodsFor:'stc compilation defaults'! |
54 | 526 |
|
141 | 527 |
canCreateMachineCode |
528 |
"return true, if compilation to machine code is supported. |
|
529 |
Currently, all SYSV4 and Linux systems do so; |
|
530 |
REAL/IX, AIX and HPUX do not (due to the need for dynamic loading |
|
531 |
of object files, which is not supported by those). |
|
532 |
MIPS ULTRIX is almost finished, but not yet released. |
|
124 | 533 |
|
141 | 534 |
However, if no compiler is around (i.e. the demo distribution), |
535 |
there is no chance ..." |
|
536 |
||
537 |
ObjectFileLoader isNil ifTrue:[^ false]. |
|
538 |
ObjectFileLoader canLoadObjectFiles ifFalse:[^ false]. |
|
539 |
||
540 |
"/ no chance, if no stc is available |
|
541 |
^ self incrementalStcPath notNil |
|
124 | 542 |
|
543 |
" |
|
141 | 544 |
Compiler canCreateMachineCode |
545 |
" |
|
546 |
||
547 |
"Modified: 13.9.1995 / 15:15:11 / claus" |
|
548 |
! |
|
549 |
||
411
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
550 |
ccCompilationOptions |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
551 |
"return the options used with cc compilation" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
552 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
553 |
CCCompilationOptions isNil ifTrue:[^ '']. |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
554 |
^ CCCompilationOptions |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
555 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
556 |
" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
557 |
Compiler ccCompilationOptions |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
558 |
" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
559 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
560 |
"Modified: 5.11.1996 / 17:38:56 / cg" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
561 |
! |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
562 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
563 |
ccCompilationOptions:aString |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
564 |
"define the compilation options |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
565 |
to be used when compiling to machine code. |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
566 |
These are passed to cc. Can be set from your private.rc file." |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
567 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
568 |
CCCompilationOptions := aString |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
569 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
570 |
" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
571 |
Compiler ccCompilationOptions:'-O' |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
572 |
Compiler ccCompilationOptions |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
573 |
" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
574 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
575 |
"Created: 5.11.1996 / 17:37:05 / cg" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
576 |
"Modified: 5.11.1996 / 17:38:32 / cg" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
577 |
! |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
578 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
579 |
ccPath |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
580 |
"return the path to the stc command for incremental method compilation, |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
581 |
or nil if not found." |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
582 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
583 |
CC isNil ifTrue:[ |
512 | 584 |
^ 'cc' |
411
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
585 |
]. |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
586 |
^ CC |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
587 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
588 |
" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
589 |
Compiler ccPath |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
590 |
Compiler ccPath:'gcc' |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
591 |
" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
592 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
593 |
"Modified: 13.9.1995 / 15:15:04 / claus" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
594 |
"Created: 5.11.1996 / 17:35:40 / cg" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
595 |
"Modified: 5.11.1996 / 17:37:42 / cg" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
596 |
! |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
597 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
598 |
ccPath:aPathOrCommandName |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
599 |
"set the path to the cc command for incremental method compilation" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
600 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
601 |
CC := aPathOrCommandName |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
602 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
603 |
" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
604 |
Compiler ccPath |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
605 |
Compiler ccPath:'gcc' |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
606 |
" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
607 |
|
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
608 |
"Modified: 13.9.1995 / 15:15:04 / claus" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
609 |
"Created: 5.11.1996 / 17:38:11 / cg" |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
610 |
! |
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
611 |
|
141 | 612 |
incrementalStcPath |
613 |
"return the path to the stc command for incremental method compilation, |
|
614 |
or nil if not found." |
|
615 |
||
616 |
|f| |
|
617 |
||
618 |
(f := self stcPathOf:'stc') notNil ifTrue:[^ f]. |
|
619 |
^ self stcPathOf:'demostc' |
|
620 |
||
621 |
" |
|
622 |
Compiler incrementalStcPath |
|
623 |
" |
|
624 |
||
625 |
"Created: 13.9.1995 / 14:36:36 / claus" |
|
626 |
"Modified: 13.9.1995 / 15:15:04 / claus" |
|
627 |
! |
|
628 |
||
629 |
stcCompilation |
|
630 |
"return the flag which controls compilation to machine code. |
|
631 |
If #always, methods are always compiled to machine code (which takes |
|
632 |
longer, but provides faster code). If #none, methods are never compiled |
|
633 |
to machine code, instead for non-primitive ones, compilation is to bytecode |
|
634 |
and for primitive ones, a trapping stub is generated. |
|
635 |
Anything else lets the compiler compile to bytecode, |
|
636 |
except for methods containing primitive code. |
|
637 |
This can be set from your private.rc file or from a workspace |
|
638 |
for selective compilation to machine code." |
|
124 | 639 |
|
141 | 640 |
^ STCCompilation |
54 | 641 |
|
642 |
" |
|
141 | 643 |
Compiler stcCompilation |
124 | 644 |
" |
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 |
stcCompilation:how |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
648 |
"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
|
649 |
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
|
650 |
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
|
651 |
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
|
652 |
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
|
653 |
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
|
654 |
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
|
655 |
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
|
656 |
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
|
657 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
658 |
|ret| |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
659 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
660 |
ret := STCCompilation. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
661 |
STCCompilation := how. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
662 |
^ ret |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
663 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
664 |
" |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
665 |
Compiler stcCompilation:#always |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
666 |
Compiler stcCompilation:#never |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
667 |
Compiler stcCompilation:#default |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
668 |
" |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
669 |
! |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
670 |
|
141 | 671 |
stcCompilationDefines |
672 |
"return the defines used with stc compilation" |
|
673 |
||
674 |
^ STCCompilationDefines |
|
675 |
! |
|
676 |
||
677 |
stcCompilationDefines:aString |
|
678 |
"define the flags (for example, additional -D defines) |
|
679 |
to be used when compiling to machine code. |
|
680 |
These are passed to stc. Can be set from your private.rc file." |
|
681 |
||
682 |
STCCompilationDefines := aString |
|
683 |
||
684 |
" |
|
685 |
Compiler stcCompilationDefines:'-DVGL -DDEBUG' |
|
686 |
" |
|
687 |
! |
|
688 |
||
689 |
stcCompilationIncludes |
|
690 |
"return the includes used with stc compilation" |
|
691 |
||
692 |
^ STCCompilationIncludes |
|
693 |
! |
|
694 |
||
695 |
stcCompilationIncludes:aString |
|
696 |
"define the include directories via additional -I flags. |
|
697 |
These are passed to stc. Can be set in your private.rc file" |
|
698 |
||
699 |
STCCompilationIncludes := aString |
|
700 |
||
701 |
" |
|
702 |
Compiler stcCompilationIncludes:'-I/usr/local/include -I../../include' |
|
703 |
Compiler stcCompilationIncludes:(Compiler stcCompilationIncludes , ' -I../../libxt') |
|
704 |
" |
|
705 |
! |
|
706 |
||
124 | 707 |
stcCompilationOptions |
708 |
"return the options used with stc compilation" |
|
709 |
||
710 |
^ STCCompilationOptions |
|
711 |
! |
|
712 |
||
141 | 713 |
stcCompilationOptions:aString |
714 |
"define the compilation options |
|
715 |
to be used when compiling to machine code. |
|
716 |
These are passed to stc. Can be set from your private.rc file." |
|
101 | 717 |
|
141 | 718 |
STCCompilationOptions := aString |
101 | 719 |
|
720 |
" |
|
141 | 721 |
Compiler stcCompilationOptions:'+optinline' |
101 | 722 |
" |
723 |
! |
|
724 |
||
301
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
725 |
stcModulePath |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
726 |
"return the path, where temporary modules are created" |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
727 |
|
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
728 |
^ STCModulePath |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
729 |
|
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
730 |
"Created: 12.7.1996 / 12:15:26 / cg" |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
731 |
! |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
732 |
|
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
733 |
stcModulePath:aPath |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
734 |
"set the path to the directory, where temporary modules are created" |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
735 |
|
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
736 |
STCModulePath := aPath |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
737 |
|
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
738 |
"Created: 12.7.1996 / 12:15:49 / cg" |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
739 |
! |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
740 |
|
141 | 741 |
stcPath |
742 |
"return the path to the stc command, or nil if not found." |
|
743 |
||
744 |
^ self stcPathOf:'stc' |
|
745 |
||
746 |
" |
|
747 |
Compiler stcPath |
|
748 |
" |
|
749 |
||
750 |
"Modified: 13.9.1995 / 14:37:26 / claus" |
|
751 |
! |
|
752 |
||
120 | 753 |
stcPathOf:command |
754 |
"return the path to an stc command, or nil if not found." |
|
101 | 755 |
|
756 |
|f| |
|
97 | 757 |
|
120 | 758 |
((f := '../../stc' asFilename construct:command)) isExecutable ifTrue:[ |
101 | 759 |
^ f pathName |
760 |
]. |
|
126 | 761 |
^ OperatingSystem pathOfCommand:command |
97 | 762 |
|
763 |
" |
|
120 | 764 |
Compiler stcPathOf:'stc' |
765 |
" |
|
766 |
||
767 |
"Created: 13.9.1995 / 14:37:16 / claus" |
|
54 | 768 |
! ! |
769 |
||
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
770 |
!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
|
771 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
772 |
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
|
773 |
"name alias for ST-80 compatibility" |
0 | 774 |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
775 |
^ self class |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
776 |
compile:textOrStream |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
777 |
in:aClass |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
778 |
notifying:requestor |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
779 |
ifFail:exceptionBlock |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
780 |
"/ |m| |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
781 |
"/ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
782 |
"/ m := self class |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
783 |
"/ compile:textOrStream |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
784 |
"/ forClass:aClass |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
785 |
"/ inCategory:'no category' |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
786 |
"/ notifying:requestor |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
787 |
"/ install:true |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
788 |
"/ skipIfSame:false |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
789 |
"/ silent:false. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
790 |
"/ m == #Error ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
791 |
"/ ^ exceptionBlock value |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
792 |
"/ ]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
793 |
"/ ^ m |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
794 |
! ! |
0 | 795 |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
796 |
!ByteCodeCompiler methodsFor:'accessing'! |
0 | 797 |
|
798 |
code |
|
3 | 799 |
"return the bytecode array - only valid after code-generation" |
0 | 800 |
|
49 | 801 |
^ codeBytes |
0 | 802 |
! |
803 |
||
141 | 804 |
literalArray |
805 |
"return the literal array - only valid after parsing" |
|
806 |
||
807 |
^ litArray |
|
808 |
! |
|
809 |
||
0 | 810 |
maxStackDepth |
811 |
"return the stack-need of the method - only valid after code-generation" |
|
812 |
||
813 |
^ maxStackDepth |
|
814 |
! ! |
|
815 |
||
816 |
!ByteCodeCompiler methodsFor:'code generation'! |
|
817 |
||
141 | 818 |
absJumpFromJump:code |
819 |
"given a jump-symbolic code, return corresponding absolute jump" |
|
0 | 820 |
|
141 | 821 |
JumpToAbsJump isNil ifTrue:[ |
822 |
JumpToAbsJump := IdentityDictionary new. |
|
823 |
JumpToAbsJump at:#jump put:#jumpabs. |
|
824 |
JumpToAbsJump at:#trueJump put:#trueJumpabs. |
|
825 |
JumpToAbsJump at:#falseJump put:#falseJumpabs. |
|
826 |
JumpToAbsJump at:#nilJump put:#nilJumpabs. |
|
827 |
JumpToAbsJump at:#notNilJump put:#notNilJumpabs. |
|
828 |
JumpToAbsJump at:#eqJump put:#eqJumpabs. |
|
829 |
JumpToAbsJump at:#notEqJump put:#notEqJumpabs. |
|
830 |
JumpToAbsJump at:#zeroJump put:#zeroJumpabs. |
|
831 |
JumpToAbsJump at:#notZeroJump put:#notZeroJumpabs. |
|
832 |
JumpToAbsJump at:#makeBlock put:#makeBlockabs. |
|
0 | 833 |
]. |
141 | 834 |
^ JumpToAbsJump at:code |
0 | 835 |
! |
836 |
||
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
837 |
addLiteral:anObject |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
838 |
"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
|
839 |
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
|
840 |
|
429 | 841 |
|index "{ Class: SmallInteger }" class| |
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
842 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
843 |
litArray isNil ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
844 |
litArray := Array with:anObject. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
845 |
^ 1 |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
846 |
]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
847 |
index := litArray identityIndexOf:anObject. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
848 |
(index == 0) ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
849 |
" |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
850 |
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
|
851 |
" |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
852 |
class := anObject class. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
853 |
((class == Float) |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
854 |
or:[class == Fraction]) ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
855 |
index := litArray indexOf:anObject. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
856 |
]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
857 |
((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
|
858 |
litArray := litArray copyWith:anObject. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
859 |
^ litArray size |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
860 |
]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
861 |
]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
862 |
^ index |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
863 |
! |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
864 |
|
141 | 865 |
addReloc:symIndex |
866 |
"remember to relocate offset at symIndex later ..." |
|
3 | 867 |
|
141 | 868 |
relocList isNil ifTrue:[ |
869 |
relocList := OrderedCollection new. |
|
1 | 870 |
]. |
141 | 871 |
relocList add:symIndex |
1 | 872 |
! |
873 |
||
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
874 |
appendByte:aByte |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
875 |
"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
|
876 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
877 |
|idx "{Class: SmallInteger }"| |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
878 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
879 |
idx := codeIndex. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
880 |
(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
|
881 |
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
|
882 |
codeIndex := idx + 1 |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
883 |
] ifFalse:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
884 |
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
|
885 |
errorFlag := #Error |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
886 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
887 |
! |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
888 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
889 |
appendByteCodeFor:codeSymbol |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
890 |
"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
|
891 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
892 |
|idx "{Class: SmallInteger }"| |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
893 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
894 |
idx := codeIndex. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
895 |
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
|
896 |
codeIndex := idx + 1 |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
897 |
! |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
898 |
|
141 | 899 |
appendEmptyByte |
900 |
"append an empty byte to the code-Array" |
|
3 | 901 |
|
141 | 902 |
|idx "{Class: SmallInteger }"| |
3 | 903 |
|
141 | 904 |
idx := codeIndex. |
905 |
codeBytes at:idx put:0. |
|
906 |
codeIndex := idx + 1 |
|
45 | 907 |
! |
908 |
||
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
909 |
appendEmptyLong |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
910 |
"append an empty long (4 bytes) to the code-Array" |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
911 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
912 |
|idx "{Class: SmallInteger }"| |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
913 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
914 |
idx := codeIndex. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
915 |
codeBytes at:idx put:0. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
916 |
codeBytes at:idx+1 put:0. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
917 |
codeBytes at:idx+2 put:0. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
918 |
codeBytes at:idx+3 put:0. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
919 |
codeIndex := idx + 4 |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
920 |
! |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
921 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
922 |
appendEmptyShort |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
923 |
"append an empty short (2 bytes) to the code-Array" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
924 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
925 |
|idx "{Class: SmallInteger }"| |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
926 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
927 |
idx := codeIndex. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
928 |
codeBytes at:idx put:0. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
929 |
codeBytes at:idx+1 put:0. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
930 |
codeIndex := idx + 2 |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
931 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
932 |
|
0 | 933 |
appendSignedByte:aByte |
934 |
"append a signedbyte (as in jump-offsets) to the code-Array, |
|
935 |
check range and report an error if invalid" |
|
936 |
||
49 | 937 |
|b "{Class: SmallInteger }" |
938 |
idx "{Class: SmallInteger }"| |
|
0 | 939 |
|
49 | 940 |
idx := codeIndex. |
0 | 941 |
b := aByte. |
942 |
(b >= 0) ifTrue:[ |
|
45 | 943 |
(b > 127) ifTrue:[ |
944 |
self error:'jump-range error'. |
|
945 |
errorFlag := #Error |
|
946 |
]. |
|
49 | 947 |
codeBytes at:idx put:b |
0 | 948 |
] ifFalse:[ |
45 | 949 |
(b < -128) ifTrue:[ |
950 |
self error:'jump-range error'. |
|
951 |
errorFlag := #Error |
|
952 |
]. |
|
49 | 953 |
b := 256 + b |
0 | 954 |
]. |
49 | 955 |
codeBytes at:idx put:b. |
956 |
codeIndex := idx + 1 |
|
0 | 957 |
! |
958 |
||
46 | 959 |
appendSignedWord:aWord |
960 |
"append a signed word to the code-Array, |
|
961 |
check range and report an error if invalid" |
|
962 |
||
49 | 963 |
|w "{Class: SmallInteger }"| |
46 | 964 |
|
965 |
w := aWord. |
|
966 |
(w >= 0) ifTrue:[ |
|
967 |
(w > 16r7FFFF) ifTrue:[ |
|
968 |
self error:'word-range error'. |
|
969 |
errorFlag := #Error |
|
970 |
]. |
|
971 |
] ifFalse:[ |
|
972 |
(w < 16r-8000) ifTrue:[ |
|
973 |
self error:'word-range error'. |
|
974 |
errorFlag := #Error |
|
975 |
]. |
|
976 |
w := (16r10000 + w). |
|
977 |
]. |
|
978 |
self appendWord:w |
|
979 |
! |
|
980 |
||
141 | 981 |
appendWord:aWord |
982 |
"append an unsigned word (low-high) to the code-Array, |
|
983 |
checking for word-range (debug-only)" |
|
984 |
||
985 |
|idx "{Class: SmallInteger }"| |
|
986 |
||
987 |
idx := codeIndex. |
|
988 |
(aWord between:0 and:16rFFFF) ifTrue:[ |
|
989 |
codeBytes at:idx put:(aWord bitAnd:16rFF). |
|
990 |
idx := idx + 1. |
|
991 |
codeBytes at:idx put:(aWord bitShift:-8). |
|
992 |
codeIndex := idx + 1 |
|
993 |
] ifFalse:[ |
|
994 |
self error:'word range error'. |
|
995 |
errorFlag := #Error |
|
996 |
] |
|
997 |
! |
|
998 |
||
0 | 999 |
byteCodeFor:aSymbol |
1000 |
"given a symbolic instruction, return the corresponding bytecode. |
|
1001 |
as a side-effect, leave number of bytes pushed/popped by this instr. |
|
1002 |
in stackDelta, and, if the instruction needs extra arguments, leave |
|
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1003 |
this info in extra. Also lineno is set to true, if this code has line |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1004 |
information and extraLiteral is set if any hidden send is performed by it." |
0 | 1005 |
|
1006 |
"standard bytecodes" |
|
1007 |
||
1008 |
(aSymbol == #pushNil) ifTrue:[stackDelta := 1. ^ 10]. |
|
1009 |
(aSymbol == #pushTrue) ifTrue:[stackDelta := 1. ^ 11]. |
|
1010 |
(aSymbol == #pushFalse) ifTrue:[stackDelta := 1. ^ 12]. |
|
1011 |
(aSymbol == #pushLit) ifTrue:[stackDelta := 1. extra := #lit. ^ 14]. |
|
105 | 1012 |
(aSymbol == #pushLitS) ifTrue:[stackDelta := 1. extra := #index. ^ 14]. |
0 | 1013 |
(aSymbol == #pushSelf) ifTrue:[stackDelta := 1. ^ 15]. |
1014 |
(aSymbol == #pushNum) ifTrue:[stackDelta := 1. extra := #number. ^ 16]. |
|
1015 |
||
1016 |
(aSymbol == #pushMethodArg) ifTrue:[stackDelta := 1. extra := #index. ^ 30]. |
|
1017 |
(aSymbol == #pushMethodVar) ifTrue:[stackDelta := 1. extra := #index. ^ 31]. |
|
1018 |
(aSymbol == #pushBlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 32]. |
|
1019 |
(aSymbol == #pushBlockVar) ifTrue:[stackDelta := 1. extra := #index. ^ 33]. |
|
1020 |
(aSymbol == #pushInstVar) ifTrue:[stackDelta := 1. extra := #index. ^ 34]. |
|
1 | 1021 |
(aSymbol == #pushOuterBlockArg) ifTrue:[stackDelta := 1. extra := #indexLevel. ^ 42]. |
1022 |
(aSymbol == #pushOuterBlockVar) ifTrue:[stackDelta := 1. extra := #indexLevel. ^ 128]. |
|
0 | 1023 |
|
1024 |
(aSymbol == #retTop) ifTrue:[stackDelta := -1. ^ 0]. |
|
1025 |
(aSymbol == #retSelf) ifTrue:[^5]. |
|
1026 |
||
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1027 |
(aSymbol == #==) ifTrue:[stackDelta := -1. extraLiteral := aSymbol. ^ 45]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1028 |
(aSymbol == #~~) ifTrue:[stackDelta := -1. extraLiteral := aSymbol. ^ 46]. |
0 | 1029 |
|
1030 |
(aSymbol == #falseJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 50]. |
|
1031 |
(aSymbol == #trueJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 51]. |
|
1032 |
(aSymbol == #nilJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 52]. |
|
1033 |
(aSymbol == #notNilJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 53]. |
|
1034 |
(aSymbol == #jump) ifTrue:[extra := #offset. ^ 54]. |
|
1 | 1035 |
(aSymbol == #makeBlock) ifTrue:[stackDelta := 1. extra := #offsetNvarNarg. ^ 55]. |
0 | 1036 |
(aSymbol == #zeroJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 56]. |
1037 |
(aSymbol == #notZeroJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 57]. |
|
1038 |
(aSymbol == #eqJump) ifTrue:[stackDelta := -2. extra := #offset. ^ 58]. |
|
1039 |
(aSymbol == #notEqJump) ifTrue:[stackDelta := -2. extra := #offset. ^ 59]. |
|
1040 |
||
54 | 1041 |
(aSymbol == #lineno) ifTrue:[lineno := true. ^ 8]. |
372
98da4d230a8d
prepare support for 16-bit lineNumbers
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
1042 |
(aSymbol == #lineno16) ifTrue:[lineno := true. ^ 9]. |
54 | 1043 |
|
106 | 1044 |
(aSymbol == #send) ifTrue:[lineno := true. extra := #special. ^ 19]. |
1045 |
(aSymbol == #superSend) ifTrue:[lineno := true. extra := #special. ^ 20]. |
|
1046 |
(aSymbol == #hereSend) ifTrue:[lineno := true. extra := #special. ^ 20]. |
|
117 | 1047 |
(aSymbol == #sendSelf) ifTrue:[lineno := true. extra := #special. ^ 13]. |
0 | 1048 |
|
1049 |
(aSymbol == #drop) ifTrue:[stackDelta := -1. ^ 18]. |
|
1050 |
(aSymbol == #dup) ifTrue:[stackDelta := 1. ^ 47]. |
|
1051 |
||
117 | 1052 |
(aSymbol == #storeMethodVar) ifTrue:[extra := #index. stackDelta := -1. ^ 37]. |
1053 |
(aSymbol == #storeBlockVar) ifTrue:[extra := #index. stackDelta := -1. ^ 38]. |
|
1054 |
(aSymbol == #storeInstVar) ifTrue:[extra := #index. stackDelta := -1. ^ 39]. |
|
0 | 1055 |
|
117 | 1056 |
(aSymbol == #pushClassVarS) ifTrue:[stackDelta := 1. extra := #speciallitS. ^ 35]. |
356
bb3beb18de1f
6empty slots in GLOBL/CLASSVAR bytecodes removed
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
1057 |
(aSymbol == #pushGlobalS) ifTrue:[stackDelta := 1. extra := #speciallitS. ^ 36]. |
117 | 1058 |
|
1059 |
(aSymbol == #storeClassVarS) ifTrue:[extra := #speciallitS.stackDelta := -1. ^ 40]. |
|
356
bb3beb18de1f
6empty slots in GLOBL/CLASSVAR bytecodes removed
Claus Gittinger <cg@exept.de>
parents:
350
diff
changeset
|
1060 |
(aSymbol == #storeGlobalS) ifTrue:[extra := #speciallitS. stackDelta := -1. ^ 41]. |
247 | 1061 |
(aSymbol == #pushSpecialGlobal) ifTrue:[stackDelta := 1. extra := #index. ^ 200]. |
117 | 1062 |
|
1 | 1063 |
(aSymbol == #storeOuterBlockVar) ifTrue:[stackDelta := -1. extra := #indexLevel. ^ 129]. |
0 | 1064 |
|
117 | 1065 |
(aSymbol == #pushClassInstVar) ifTrue:[stackDelta := 1. extra := #index. ^ 176]. |
1066 |
(aSymbol == #storeClassInstVar) ifTrue:[extra := #index.stackDelta := -1. ^ 177]. |
|
105 | 1067 |
|
0 | 1068 |
"optimized bytecodes" |
1069 |
||
1070 |
(aSymbol == #retNil) ifTrue:[^ 1]. |
|
1071 |
(aSymbol == #retTrue) ifTrue:[^ 2]. |
|
1072 |
(aSymbol == #retFalse) ifTrue:[^ 3]. |
|
1073 |
(aSymbol == #ret0) ifTrue:[^ 4]. |
|
1074 |
(aSymbol == #retNum) ifTrue:[extra := #number. ^ 127]. |
|
25 | 1075 |
(aSymbol == #homeRetTop) ifTrue:[^ 7]. |
0 | 1076 |
|
46 | 1077 |
(aSymbol == #pushNum16) ifTrue:[stackDelta := 1. extra := #number16. ^ 17]. |
0 | 1078 |
(aSymbol == #push0) ifTrue:[stackDelta := 1. ^120]. |
1079 |
(aSymbol == #push1) ifTrue:[stackDelta := 1. ^121]. |
|
3 | 1080 |
(aSymbol == #push2) ifTrue:[stackDelta := 1. ^139]. |
0 | 1081 |
(aSymbol == #pushMinus1) ifTrue:[stackDelta := 1. ^122]. |
1082 |
||
106 | 1083 |
(aSymbol == #send0) ifTrue:[lineno := true. extra := #index. ^21]. |
1084 |
(aSymbol == #send1) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^22]. |
|
1085 |
(aSymbol == #send2) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^23]. |
|
1086 |
(aSymbol == #send3) ifTrue:[lineno := true. extra := #index. stackDelta := -3. ^24]. |
|
0 | 1087 |
|
106 | 1088 |
(aSymbol == #sendSelf0) ifTrue:[lineno := true. extra := #index. stackDelta := 1. ^180]. |
1089 |
(aSymbol == #sendSelf1) ifTrue:[lineno := true. extra := #index. ^181]. |
|
1090 |
(aSymbol == #sendSelf2) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^182]. |
|
1091 |
(aSymbol == #sendSelf3) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^183]. |
|
1092 |
(aSymbol == #sendSelfDrop0) ifTrue:[lineno := true. extra := #index. ^184]. |
|
1093 |
(aSymbol == #sendSelfDrop1) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^185]. |
|
1094 |
(aSymbol == #sendSelfDrop2) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^186]. |
|
1095 |
(aSymbol == #sendSelfDrop3) ifTrue:[lineno := true. extra := #index. stackDelta := -3. ^187]. |
|
0 | 1096 |
|
106 | 1097 |
(aSymbol == #sendDrop) ifTrue:[lineno := true. extra := #special. ^25]. |
1098 |
(aSymbol == #sendDrop0) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^26]. |
|
1099 |
(aSymbol == #sendDrop1) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^27]. |
|
1100 |
(aSymbol == #sendDrop2) ifTrue:[lineno := true. extra := #index. stackDelta := -3. ^28]. |
|
1101 |
(aSymbol == #sendDrop3) ifTrue:[lineno := true. extra := #index. stackDelta := -4. ^29]. |
|
0 | 1102 |
|
1103 |
(aSymbol == #pushMethodVar1) ifTrue:[stackDelta := 1. ^80]. |
|
1104 |
(aSymbol == #pushMethodVar2) ifTrue:[stackDelta := 1. ^81]. |
|
1105 |
(aSymbol == #pushMethodVar3) ifTrue:[stackDelta := 1. ^82]. |
|
1106 |
(aSymbol == #pushMethodVar4) ifTrue:[stackDelta := 1. ^83]. |
|
1107 |
(aSymbol == #pushMethodVar5) ifTrue:[stackDelta := 1. ^84]. |
|
1108 |
(aSymbol == #pushMethodVar6) ifTrue:[stackDelta := 1. ^85]. |
|
1109 |
||
1110 |
(aSymbol == #pushMethodArg1) ifTrue:[stackDelta := 1. ^86]. |
|
1111 |
(aSymbol == #pushMethodArg2) ifTrue:[stackDelta := 1. ^87]. |
|
1112 |
(aSymbol == #pushMethodArg3) ifTrue:[stackDelta := 1. ^88]. |
|
1113 |
(aSymbol == #pushMethodArg4) ifTrue:[stackDelta := 1. ^89]. |
|
1114 |
||
1115 |
(aSymbol == #pushInstVar1) ifTrue:[stackDelta := 1. ^90]. |
|
1116 |
(aSymbol == #pushInstVar2) ifTrue:[stackDelta := 1. ^91]. |
|
1117 |
(aSymbol == #pushInstVar3) ifTrue:[stackDelta := 1. ^92]. |
|
1118 |
(aSymbol == #pushInstVar4) ifTrue:[stackDelta := 1. ^93]. |
|
1119 |
(aSymbol == #pushInstVar5) ifTrue:[stackDelta := 1. ^94]. |
|
1120 |
(aSymbol == #pushInstVar6) ifTrue:[stackDelta := 1. ^95]. |
|
1121 |
(aSymbol == #pushInstVar7) ifTrue:[stackDelta := 1. ^96]. |
|
1122 |
(aSymbol == #pushInstVar8) ifTrue:[stackDelta := 1. ^97]. |
|
1123 |
(aSymbol == #pushInstVar9) ifTrue:[stackDelta := 1. ^98]. |
|
1124 |
(aSymbol == #pushInstVar10) ifTrue:[stackDelta := 1. ^99]. |
|
1125 |
||
1126 |
(aSymbol == #storeMethodVar1) ifTrue:[stackDelta := -1. ^100]. |
|
1127 |
(aSymbol == #storeMethodVar2) ifTrue:[stackDelta := -1. ^101]. |
|
1128 |
(aSymbol == #storeMethodVar3) ifTrue:[stackDelta := -1. ^102]. |
|
1129 |
(aSymbol == #storeMethodVar4) ifTrue:[stackDelta := -1. ^103]. |
|
1130 |
(aSymbol == #storeMethodVar5) ifTrue:[stackDelta := -1. ^104]. |
|
1131 |
(aSymbol == #storeMethodVar6) ifTrue:[stackDelta := -1. ^105]. |
|
1132 |
||
1133 |
(aSymbol == #storeInstVar1) ifTrue:[stackDelta := -1. ^110]. |
|
1134 |
(aSymbol == #storeInstVar2) ifTrue:[stackDelta := -1. ^111]. |
|
1135 |
(aSymbol == #storeInstVar3) ifTrue:[stackDelta := -1. ^112]. |
|
1136 |
(aSymbol == #storeInstVar4) ifTrue:[stackDelta := -1. ^113]. |
|
1137 |
(aSymbol == #storeInstVar5) ifTrue:[stackDelta := -1. ^114]. |
|
1138 |
(aSymbol == #storeInstVar6) ifTrue:[stackDelta := -1. ^115]. |
|
1139 |
(aSymbol == #storeInstVar7) ifTrue:[stackDelta := -1. ^116]. |
|
1140 |
(aSymbol == #storeInstVar8) ifTrue:[stackDelta := -1. ^117]. |
|
1141 |
(aSymbol == #storeInstVar9) ifTrue:[stackDelta := -1. ^118]. |
|
1142 |
(aSymbol == #storeInstVar10) ifTrue:[stackDelta := -1. ^119]. |
|
1143 |
||
103 | 1144 |
(aSymbol == #pushLit1) ifTrue:[stackDelta := 1. ^ 222]. |
1145 |
(aSymbol == #pushLit2) ifTrue:[stackDelta := 1. ^ 223]. |
|
1146 |
(aSymbol == #pushLit3) ifTrue:[stackDelta := 1. ^ 224]. |
|
1147 |
(aSymbol == #pushLit4) ifTrue:[stackDelta := 1. ^ 225]. |
|
1148 |
(aSymbol == #pushLit5) ifTrue:[stackDelta := 1. ^ 226]. |
|
1149 |
(aSymbol == #pushLit6) ifTrue:[stackDelta := 1. ^ 227]. |
|
1150 |
(aSymbol == #pushLit7) ifTrue:[stackDelta := 1. ^ 228]. |
|
1151 |
(aSymbol == #pushLit8) ifTrue:[stackDelta := 1. ^ 229]. |
|
1152 |
||
0 | 1153 |
(aSymbol == #retMethodVar1) ifTrue:[^160]. |
1154 |
(aSymbol == #retMethodVar2) ifTrue:[^161]. |
|
1155 |
(aSymbol == #retMethodVar3) ifTrue:[^162]. |
|
1156 |
(aSymbol == #retMethodVar4) ifTrue:[^163]. |
|
1157 |
(aSymbol == #retMethodVar5) ifTrue:[^164]. |
|
1158 |
(aSymbol == #retMethodVar6) ifTrue:[^165]. |
|
1159 |
||
1160 |
(aSymbol == #retInstVar1) ifTrue:[^166]. |
|
1161 |
(aSymbol == #retInstVar2) ifTrue:[^167]. |
|
1162 |
(aSymbol == #retInstVar3) ifTrue:[^168]. |
|
1163 |
(aSymbol == #retInstVar4) ifTrue:[^169]. |
|
1164 |
(aSymbol == #retInstVar5) ifTrue:[^170]. |
|
1165 |
(aSymbol == #retInstVar6) ifTrue:[^171]. |
|
1166 |
(aSymbol == #retInstVar7) ifTrue:[^172]. |
|
1167 |
(aSymbol == #retInstVar8) ifTrue:[^173]. |
|
1168 |
||
1169 |
(aSymbol == #retMethodArg1) ifTrue:[^174]. |
|
1170 |
(aSymbol == #retMethodArg2) ifTrue:[^175]. |
|
1171 |
||
1172 |
(aSymbol == #pushBlockArg1) ifTrue:[stackDelta := 1. ^140]. |
|
1173 |
(aSymbol == #pushBlockArg2) ifTrue:[stackDelta := 1. ^141]. |
|
1174 |
(aSymbol == #pushBlockArg3) ifTrue:[stackDelta := 1. ^142]. |
|
1175 |
(aSymbol == #pushBlockArg4) ifTrue:[stackDelta := 1. ^143]. |
|
1176 |
||
1 | 1177 |
(aSymbol == #pushOuter1BlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 43]. |
1178 |
(aSymbol == #pushOuter2BlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 44]. |
|
0 | 1179 |
|
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1180 |
(aSymbol == #=) ifTrue:[lineno := true. stackDelta := -1. extraLiteral := aSymbol. ^130]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1181 |
(aSymbol == #+) ifTrue:[lineno := true. stackDelta := -1. extraLiteral := aSymbol. ^131]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1182 |
(aSymbol == #~=) ifTrue:[lineno := true. stackDelta := -1. extraLiteral := aSymbol. ^132]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1183 |
(aSymbol == #-) ifTrue:[lineno := true. stackDelta := -1. extraLiteral := aSymbol. ^133]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1184 |
(aSymbol == #*) ifTrue:[lineno := true. stackDelta := -1. extraLiteral := aSymbol. ^230]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1185 |
(aSymbol == #class) ifTrue:[extraLiteral := aSymbol. ^134]. |
400
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1186 |
"/ (aSymbol == #x) ifTrue:[lineno := true. extraLiteral := aSymbol. ^106]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1187 |
"/ (aSymbol == #y) ifTrue:[lineno := true. extraLiteral := aSymbol. ^107]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1188 |
"/ (aSymbol == #width) ifTrue:[lineno := true. extraLiteral := aSymbol. ^108]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1189 |
"/ (aSymbol == #height) ifTrue:[lineno := true. extraLiteral := aSymbol. ^109]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1190 |
"/ (aSymbol == #origin) ifTrue:[lineno := true. extraLiteral := aSymbol. ^154]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1191 |
"/ (aSymbol == #extent) ifTrue:[lineno := true. extraLiteral := aSymbol. ^155]. |
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1192 |
(aSymbol == #at:) ifTrue:[lineno := true. stackDelta := -1. extraLiteral := aSymbol. ^135]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1193 |
(aSymbol == #at:put:)ifTrue:[lineno := true. stackDelta := -2. extraLiteral := aSymbol. ^136]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1194 |
(aSymbol == #bitAnd:) ifTrue:[lineno := true. stackDelta := -1. extraLiteral := aSymbol. ^137]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1195 |
(aSymbol == #bitOr:) ifTrue:[lineno := true. stackDelta := -1. extraLiteral := aSymbol. ^138]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1196 |
(aSymbol == #plus1) ifTrue:[lineno := true. extraLiteral := #+. ^123]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1197 |
(aSymbol == #minus1) ifTrue:[lineno := true. extraLiteral := #-. ^124]. |
0 | 1198 |
|
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1199 |
(aSymbol == #incMethodVar) ifTrue:[lineno := true. extraLiteral := #+. extra := #index. ^125]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1200 |
(aSymbol == #decMethodVar) ifTrue:[lineno := true. extraLiteral := #-. extra := #index. ^126]. |
0 | 1201 |
|
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1202 |
(aSymbol == #eq0) ifTrue:[extraLiteral := #==. ^48]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1203 |
(aSymbol == #ne0) ifTrue:[extraLiteral := #~~. ^49]. |
0 | 1204 |
|
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1205 |
(aSymbol == #>) ifTrue:[lineno := true. extraLiteral := aSymbol. stackDelta := -1. ^ 145]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1206 |
(aSymbol == #>=) ifTrue:[lineno := true. extraLiteral := aSymbol. stackDelta := -1. ^ 146]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1207 |
(aSymbol == #<) ifTrue:[lineno := true. extraLiteral := aSymbol. stackDelta := -1. ^ 147]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1208 |
(aSymbol == #<=) ifTrue:[lineno := true. extraLiteral := aSymbol. stackDelta := -1. ^ 148]. |
400
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1209 |
"/ (aSymbol == #next) ifTrue:[lineno := true. extraLiteral := aSymbol. ^ 149]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1210 |
"/ (aSymbol == #peek) ifTrue:[lineno := true. extraLiteral := aSymbol. ^ 150]. |
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1211 |
(aSymbol == #value) ifTrue:[lineno := true. extraLiteral := aSymbol. ^ 151]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1212 |
(aSymbol == #value:) ifTrue:[lineno := true. extraLiteral := aSymbol. stackDelta := -1. ^ 152]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1213 |
(aSymbol == #value:value:) ifTrue:[lineno := true. extraLiteral := aSymbol. stackDelta := -2. ^ 178]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1214 |
(aSymbol == #size) ifTrue:[lineno := true. extraLiteral := aSymbol. ^ 153]. |
400
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1215 |
"/ (aSymbol == #asInteger) ifTrue:[lineno := true. extraLiteral := aSymbol. ^ 158]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1216 |
"/ (aSymbol == #rounded) ifTrue:[lineno := true. extraLiteral := aSymbol. ^ 159]. |
0 | 1217 |
(aSymbol == #mk0Block) ifTrue:[^ 156]. |
1218 |
(aSymbol == #mkNilBlock) ifTrue:[^ 157]. |
|
1219 |
||
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1220 |
(aSymbol == #gt0) ifTrue:[lineno := true. extraLiteral := #>. ^ 212]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1221 |
(aSymbol == #pushgt0) ifTrue:[lineno := true. stackDelta := 1. extraLiteral := #>. ^ 208]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1222 |
(aSymbol == #basicNew) ifTrue:[lineno := true. extraLiteral := aSymbol. ^ 211]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1223 |
(aSymbol == #new) ifTrue:[lineno := true. extraLiteral := aSymbol. ^ 213]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1224 |
(aSymbol == #basicNew:) ifTrue:[lineno := true. extraLiteral := aSymbol. ^ 214]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1225 |
(aSymbol == #new:) ifTrue:[lineno := true. extraLiteral := aSymbol. ^ 215]. |
103 | 1226 |
|
217 | 1227 |
(aSymbol == #pushBlockVar1) ifTrue:[stackDelta := 1. ^ 232]. |
1228 |
(aSymbol == #pushBlockVar2) ifTrue:[stackDelta := 1. ^ 233]. |
|
1229 |
(aSymbol == #pushBlockVar3) ifTrue:[stackDelta := 1. ^ 234]. |
|
1230 |
(aSymbol == #storeBlockVar1) ifTrue:[stackDelta := -1. ^ 235]. |
|
1231 |
(aSymbol == #storeBlockVar2) ifTrue:[stackDelta := -1. ^ 236]. |
|
1232 |
(aSymbol == #storeBlockVar3) ifTrue:[stackDelta := -1. ^ 237]. |
|
1233 |
||
0 | 1234 |
(aSymbol == #falseJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 190]. |
1235 |
(aSymbol == #trueJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 191]. |
|
1236 |
(aSymbol == #nilJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 192]. |
|
1237 |
(aSymbol == #notNilJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 193]. |
|
1238 |
(aSymbol == #jumpabs) ifTrue:[extra := #absoffset. ^ 194]. |
|
1 | 1239 |
(aSymbol == #makeBlockabs) ifTrue:[stackDelta := 1. extra := #absoffsetNvarNarg. ^ 195]. |
0 | 1240 |
(aSymbol == #zeroJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 196]. |
1241 |
(aSymbol == #notZeroJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 197]. |
|
1 | 1242 |
(aSymbol == #eqJumpabs) ifTrue:[stackDelta := -2. extra := #absoffset. ^ 198]. |
1243 |
(aSymbol == #notEqJumpabs) ifTrue:[stackDelta := -2. extra := #absoffset. ^ 199]. |
|
0 | 1244 |
|
1245 |
(aSymbol == #pushThisContext) ifTrue:[stackDelta := 1. ^ 144]. |
|
1246 |
||
425
b046a32edb08
remember &, | and not in literal array
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
1247 |
(aSymbol == #isNil) ifTrue:[extraLiteral := aSymbol. ^ 188]. |
b046a32edb08
remember &, | and not in literal array
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
1248 |
(aSymbol == #notNil) ifTrue:[extraLiteral := aSymbol. ^ 189]. |
b046a32edb08
remember &, | and not in literal array
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
1249 |
(aSymbol == #not) ifTrue:[extraLiteral := aSymbol. lineno := true. ^ 179]. |
b046a32edb08
remember &, | and not in literal array
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
1250 |
(aSymbol == #&) ifTrue:[extraLiteral := aSymbol. lineno := true. ^ 216]. |
b046a32edb08
remember &, | and not in literal array
Claus Gittinger <cg@exept.de>
parents:
415
diff
changeset
|
1251 |
(aSymbol == #|) ifTrue:[extraLiteral := aSymbol. lineno := true. ^ 217]. |
76 | 1252 |
|
117 | 1253 |
(aSymbol == #pushClassVarL) ifTrue:[stackDelta := 1. extra := #speciallitL. ^ 218]. |
1254 |
(aSymbol == #pushGlobalL) ifTrue:[stackDelta := 1. extra := #speciallitL. ^ 218]. |
|
1255 |
(aSymbol == #storeClassVarL) ifTrue:[extra := #speciallitL.stackDelta := -1. ^ 219]. |
|
1256 |
(aSymbol == #storeGlobalL) ifTrue:[extra := #speciallitL. stackDelta := -1. ^ 219]. |
|
1257 |
(aSymbol == #pushLitL) ifTrue:[stackDelta := 1. extra := #unsigned16. ^ 201]. |
|
1258 |
||
1259 |
(aSymbol == #sendL) ifTrue:[lineno := true. extra := #specialL. ^ 205]. |
|
1260 |
(aSymbol == #sendSelfL) ifTrue:[lineno := true. extra := #specialL. ^ 207]. |
|
1261 |
(aSymbol == #sendDropL) ifTrue:[lineno := true. extra := #specialL. ^ 204]. |
|
1262 |
(aSymbol == #superSendL) ifTrue:[lineno := true. extra := #specialL. ^ 206]. |
|
1263 |
(aSymbol == #hereSendL) ifTrue:[lineno := true. extra := #specialL. ^ 206]. |
|
106 | 1264 |
|
246
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1265 |
(aSymbol == #top) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1266 |
(aSymbol == #bottom) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1267 |
(aSymbol == #left) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
abf09d4821fe
new code for faster global pushes
Claus Gittinger <cg@exept.de>
parents:
235
diff
changeset
|
1268 |
(aSymbol == #right) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1269 |
|
400
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1270 |
(aSymbol == #x) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1271 |
(aSymbol == #y) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1272 |
(aSymbol == #width) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1273 |
(aSymbol == #height) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1274 |
(aSymbol == #origin) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1275 |
(aSymbol == #extent) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1276 |
(aSymbol == #next) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1277 |
(aSymbol == #peek) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1278 |
(aSymbol == #asInteger) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1279 |
(aSymbol == #rounded) ifTrue:[lineno := true. extraLiteral := aSymbol. extra := #specialSend. ^ 231]. |
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
1280 |
|
217 | 1281 |
(aSymbol == #blockRef) ifTrue:[stackDelta := 0. ^ 238]. |
549 | 1282 |
(aSymbol == #over) ifTrue:[stackDelta := 1. ^ 6]. |
217 | 1283 |
|
0 | 1284 |
self error:'invalid code symbol'. |
1285 |
errorFlag := #Error |
|
117 | 1286 |
|
1287 |
"Modified: 3.9.1995 / 12:58:47 / claus" |
|
549 | 1288 |
"Modified: 25.6.1997 / 11:47:26 / cg" |
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1289 |
! |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1290 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1291 |
checkForCommonCode:symbolicCodeArray |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1292 |
"hook to return the code for common code sequences. |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1293 |
This reduces the in-memory number of byteArrays somewhat. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1294 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1295 |
Not yet fully implemented - just an idea ... theres certainly more to do here |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1296 |
(does it make sense to scan all methods, collect code in a set and unify things |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1297 |
automatically in the background - or upon request ?)" |
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1298 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1299 |
|sz insn1| |
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1300 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1301 |
(sz := symbolicCodeArray size) == 2 ifTrue:[ |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1302 |
"/ |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1303 |
"/ a very common sequence: return the first literal |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1304 |
"/ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1305 |
(insn1 := symbolicCodeArray at:1) == #pushLit1 ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1306 |
(symbolicCodeArray at:2) == #retTop ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1307 |
^ #[222 0] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1308 |
] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1309 |
] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1310 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1311 |
sz == 1 ifTrue:[ |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1312 |
"/ |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1313 |
"/ another common sequence: return the receiver |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1314 |
"/ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1315 |
(insn1 := symbolicCodeArray at:1) == #retSelf ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1316 |
^ #[5] |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1317 |
]. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1318 |
insn1 == #retTrue ifTrue:[ |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1319 |
^ #[2] |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1320 |
]. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1321 |
insn1 == #retFalse ifTrue:[ |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1322 |
^ #[3] |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
211
diff
changeset
|
1323 |
]. |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1324 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1325 |
^ nil |
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1326 |
! |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1327 |
|
141 | 1328 |
checkForPrimitiveCode:nr |
1329 |
"return the code for an ST-80 primitive method. |
|
1330 |
Since many primitives available on ST-80 should also be available |
|
1331 |
somewhere in ST/X, this may work for many primitive numbers. |
|
1332 |
However, more information is needed and more things to be added below. |
|
1333 |
||
1334 |
This was added to allow emulation of (some) ST-80 |
|
1335 |
primitives (to fileIn RemoteInvocation & Monitor41 packages)" |
|
1336 |
||
1337 |
|cls sel| |
|
1338 |
||
1339 |
(nr == 75) ifTrue:[ cls := Object. sel := #identityHash ]. |
|
1340 |
(nr == 110) ifTrue:[ cls := Object. sel := #== ]. |
|
1341 |
(nr == 111) ifTrue:[ cls := Object. sel := #class ]. |
|
1342 |
" |
|
1343 |
should add more here, to be able to fileIn ST-80 methods |
|
1344 |
containing primitive calls (who gives me the numbers ... ?) |
|
512 | 1345 |
mhmh - got some ..." |
1346 |
||
1347 |
"/ 18 Number @ |
|
1348 |
"/ 21 LargePositiveInteger + |
|
1349 |
"/ 22 LargePositiveInteger - |
|
1350 |
"/ 29 LargePositiveInteger * |
|
1351 |
"/ 30 LargePositiveInteger / |
|
1352 |
"/ 31 LargePositiveInteger \\ |
|
1353 |
"/ 32 LargePositiveInteger // |
|
1354 |
"/ 34 LargePositiveInteger bitAnd: |
|
1355 |
"/ 35 LargePositiveInteger bitOr: |
|
1356 |
"/ 36 LargePositiveInteger bitXor: |
|
1357 |
"/ 37 LargePositiveInteger bitShift: |
|
1358 |
"/ 40 SmallInteger asFloat |
|
1359 |
"/ 41 Float + |
|
1360 |
"/ 42 Float - |
|
1361 |
"/ 49 Float * |
|
1362 |
"/ 50 Float / |
|
1363 |
"/ 52 Float fractionPart |
|
1364 |
"/ 54 Float timesTwoPower: |
|
1365 |
"/ 70 Behavior basicNew |
|
1366 |
"/ 71 Behavior basicNew: |
|
1367 |
"/ 89 Behavior flushVMmethodCache |
|
1368 |
"/ 91 InputState primCursorLocPut: |
|
1369 |
"/ 105 ByteArray replaceElementsFrom:to:withByteArray:startingAt: |
|
1370 |
"/ 223 ByteString = |
|
1371 |
"/ 306 ObjectMemory class sizesAtStartup |
|
1372 |
"/ 307 ObjectMemory class defaultSizesAtStartup |
|
1373 |
"/ 309 ObjectMemory class defaultThresholds |
|
1374 |
"/ 326 ObjectMemory class getMemoryUsageAndZeroFragmentationStatisticsIf: |
|
1375 |
"/ 395 ExternalInterface ??? |
|
1376 |
"/ 400 FormBitmap class newWidth:height: |
|
1377 |
"/ 414 TwoByteString replaceElementsFrom:to:withTwoByteString:startingAt: |
|
1378 |
"/ 415 TwoByteString = |
|
1379 |
"/ 417 String trueCompare: |
|
1380 |
"/ 418 ByteString nextIndexOf:from:to: |
|
1381 |
"/ 419 ByteString prevIndexOf:from:to: |
|
1382 |
"/ 422 WeakArray indexOf:replaceWith:startingAt:stoppingAt: |
|
1383 |
"/ 522 Behavior flushVMmethodCacheEntriesFor: |
|
1384 |
"/ 524 Context nFromVPC: |
|
1385 |
"/ 525 Context vFromNPC: |
|
1386 |
"/ 532 Object shallowCopy |
|
1387 |
"/ 536 Behavior atomicAllInstances |
|
1388 |
"/ 537 Object allOwners |
|
1389 |
"/ 538 ObjectMemory class allObjects |
|
1390 |
"/ 546 UninterpretedBytes longAt: |
|
1391 |
"/ 548 UninterpretedBytes floatAt: |
|
1392 |
"/ 550 UninterpretedBytes longFloatAt: |
|
1393 |
"/ 544 UninterpretedBytes unsignedLongAt: |
|
1394 |
"/ 559 ByteArray replaceBytesFrom:to:with:startingAt: |
|
1395 |
"/ 560 Double class fromNumber: |
|
1396 |
"/ 561 Double + |
|
1397 |
"/ 562 Double - |
|
1398 |
"/ 569 Double * |
|
1399 |
"/ 570 Double / |
|
1400 |
"/ 572 Double fractionPart |
|
1401 |
"/ 574 Double timesTwoPower: |
|
1402 |
"/ 576 Double sin |
|
1403 |
"/ 577 Double cos |
|
1404 |
"/ 578 Double tan |
|
1405 |
"/ 579 Double arcSin |
|
1406 |
"/ 580 Double arcCos |
|
1407 |
"/ 581 Double arcTan |
|
1408 |
"/ 582 Double sqrt |
|
1409 |
"/ 583 Double ln |
|
1410 |
"/ 584 Double exp |
|
1411 |
"/ 585 Double raisedTo: |
|
1412 |
"/ 587 Double floorLog10 |
|
1413 |
"/ 588 Double asFloat |
|
1414 |
"/ 591 Float cos |
|
1415 |
"/ 592 Float arcSin |
|
1416 |
"/ 593 Float arcCos |
|
1417 |
"/ 600 Float sin |
|
1418 |
"/ 601 Float tan |
|
1419 |
"/ 602 Float arcTan |
|
1420 |
"/ 603 Float sqrt |
|
1421 |
"/ 604 Float ln |
|
1422 |
"/ 605 Float exp |
|
1423 |
"/ 606 Float raisedTo: |
|
1424 |
"/ 609 Float floorLog10 |
|
1425 |
"/ 610 Filename getDatesErrInto: |
|
1426 |
"/ 614 DosFilename class getVolumes |
|
1427 |
"/ 615 UnixFilename primSetProtection:errInto: |
|
1428 |
"/ 616 UnixFilename class primSetCreationMask:errInto: |
|
1429 |
"/ 617 UnixFilename primGetProtectionErrInto: |
|
1430 |
"/ 620 Filename listDirectoryErrInto: |
|
1431 |
"/ 621 Filename deleteErrInto: |
|
1432 |
"/ 622 Filename isDirectoryErrInto: |
|
1433 |
"/ 623 Filename renameTo:errInto: |
|
1434 |
"/ 624 Filename makeDirectoryErrInto: |
|
1435 |
"/ 625 Filename class defaultDirectoryErrInto: |
|
1436 |
"/ 626 Filename fileSizeErrInto: |
|
1437 |
"/ 627 Filename isWritableErrInto: |
|
1438 |
"/ 628 Filename setWritable:errInto: |
|
1439 |
"/ 629 Filename existsErrInto: |
|
1440 |
"/ 630 SocketAccessor setOptionsLevel:name:value: |
|
1441 |
"/ 631 SocketAccessor getOptionsLevel:name: |
|
1442 |
"/ 632 SocketAccessor primGetName |
|
1443 |
"/ 633 SocketAccessor primGetPeer |
|
1444 |
"/ 634 SocketAccessor atMark |
|
1445 |
"/ 637 UnixTtyAccessor primGetOptions |
|
1446 |
"/ 638 UnixTtyAccessor setOptions: |
|
1447 |
"/ 639 UnixRealTtyAccessor modemBits:mask:sendBreak: |
|
1448 |
"/ 640 IPSocketAddress class primHostAddressByName: |
|
1449 |
"/ 641 IPSocketAddress class netAddressByName: |
|
1450 |
"/ 642 IPSocketAddress class protocolNumberByName: |
|
1451 |
"/ 643 IPSocketAddress class servicePortByName: |
|
1452 |
"/ 645 IPSocketAddress class primHostNameByAddress: |
|
1453 |
"/ 646 IPSocketAddress class netNameByAddress: |
|
1454 |
"/ 647 IPSocketAddress class protocolNameByNumber: |
|
1455 |
"/ 648 IPSocketAddress class serviceNameByPort: |
|
1456 |
"/ 649 SocketAccessor class getHostname |
|
1457 |
"/ 650 Filename primOpenFileNamed:direction:creation:errorInto: |
|
1458 |
"/ 651 IOAccessor primClose |
|
1459 |
"/ 652 UnixPipeAccessor class primPipeErrorInto: |
|
1460 |
"/ 653 UnixPseudoTtyAccessor class primPtyErrorInto: |
|
1461 |
"/ 654 SocketAccessor class primPairErrorInto: |
|
1462 |
"/ 655 UnixRealTtyAccessor class primOpen:errInto: |
|
1463 |
"/ 660 IOAccessor primReadInto:startingAt:for: |
|
1464 |
"/ 661 IOAccessor primWriteFrom:startingAt:for: |
|
1465 |
"/ 662 IOAccessor primSeekTo: |
|
1466 |
"/ 664 IOAccessor truncateTo: |
|
1467 |
"/ 665 DosDiskFileAccessor commit |
|
1468 |
"/ 666 IOAccessor primGetSize |
|
1469 |
"/ 667 MacDiskFileAccessor lock:for: |
|
1470 |
"/ 669 UnixIOAccessor bytesForRead |
|
1471 |
"/ 670 SocketAccessor class primFamily:type:protocol:errInto: |
|
1472 |
"/ 671 SocketAccessor primAccept |
|
1473 |
"/ 672 SocketAccessor bindTo: |
|
1474 |
"/ 673 SocketAccessor listenFor: |
|
1475 |
"/ 674 SocketAccessor primConnectTo: |
|
1476 |
"/ 675 SocketAccessor primReceiveFrom:buffer:start:for:flags: |
|
1477 |
"/ 676 SocketAccessor sendTo:buffer:start:for:flags: |
|
1478 |
"/ 677 SocketAccessor shutdown: |
|
1479 |
"/ 681 UnixProcess class primFork:arguments:environment:descriptors:errorTo: |
|
1480 |
"/ 682 UnixProcess class reapOne |
|
1481 |
"/ 683 UnixProcess kill: |
|
1482 |
"/ 690 CEnvironment class primEnvironment |
|
1483 |
"/ 697 OSErrorHolder class errorDescriptionFor: |
|
1484 |
"/ 697 ErrorHolder class errorDescriptionFor: |
|
1485 |
"/ 698 SocketAccessor class primInit: |
|
1486 |
"/ 700 ParagraphEditor class getExternalSelectionOrNil: |
|
1487 |
"/ 701 ParagraphEditor class putExternalSelection:with: |
|
1488 |
"/ 705 Screen ringBell |
|
1489 |
"/ 706 Cursor class primOpenImage:mask:hotSpotX:hotSpotY:background:foreground: |
|
1490 |
"/ 707 Cursor primBeCursor |
|
1491 |
"/ 708 Cursor primFreeCursor |
|
1492 |
"/ 772 SoundManager enumerateSoundsFrom: |
|
1493 |
"/ 773 SoundManager playSoundFrom:sound: |
|
1494 |
"/ 774 SoundManager simpleBeep: |
|
1495 |
"/ 775 Pixmap primFromClipboard |
|
1496 |
"/ 776 Pixmap toClipboard |
|
1497 |
"/ 808 Context findNextMarkedUpTo: |
|
1498 |
"/ 809 Context terminateTo: |
|
1499 |
"/ 710 DosTtyAccessor class primOpen:errInto: |
|
1500 |
"/ 711 DosTtyAccessor primClose |
|
1501 |
"/ 712 DosTtyAccessor primReadInto:startingAt:for: |
|
1502 |
"/ 713 DosTtyAccessor primWriteFrom:startingAt:for: |
|
1503 |
"/ 714 DosTtyAccessor primGetOptions |
|
1504 |
"/ 715 DosTtyAccessor primSetOptions: |
|
1505 |
"/ 716 DosTtyAccessor setSem:forWrite: |
|
1506 |
"/ 717 DosTtyAccessor modemBits:mask:sendBreak: |
|
1507 |
"/ 750 MacFilename class getVolumes |
|
1508 |
"/ 752 MacFilename primSetCreator:type:errInto: |
|
1509 |
"/ 754 MacIOAccessor class getAccessories |
|
1510 |
"/ 755 MacIOAccessor class runAccessory: |
|
1511 |
"/ 756 MacOSFilename class getFileTypes:errInto: |
|
1512 |
"/ 757 MacOSFilename putFileWithPrompt:errInto: |
|
1513 |
"/ 758 MacOSFilename getFileInfoErrInto: |
|
1514 |
"/ 759 MacOSFilename stringFromVRefErrInto: |
|
1515 |
"/ 761 MacOSFilename class getStartupFilesErrInto: |
|
1516 |
"/ 770 DosFilename printPSFileErrInto: |
|
1517 |
"/ 771 DosFilename printTextFileErrInto: |
|
1518 |
"/ 780 MacTtyAccessor class primOpen:errInto: |
|
1519 |
"/ 781 MacTtyAccessor primClose |
|
1520 |
"/ 782 MacTtyAccessor primReadInto:startingAt:for: |
|
1521 |
"/ 783 MacTtyAccessor primWriteFrom:startingAt:for: |
|
1522 |
"/ 786 MacTtyAccessor primGetOptions |
|
1523 |
"/ 787 MacTtyAccessor setOptions: |
|
1524 |
"/ 788 MacTtyAccessor primBreak: |
|
1525 |
"/ 790 MacTtyAccessor primGetStatus |
|
1526 |
"/ 792 MacTtyAccessor setSem:forWrite: |
|
1527 |
"/ 793 MacTtyAccessor primAssertDTR: |
|
1528 |
"/ 794 MacTtyAccessor primGetSize |
|
1529 |
"/ 933 ByteArray copyBitsClippedStride:... |
|
1530 |
"/ 934 ByteArray tileBits32By32Stride:... |
|
1531 |
"/ 935 Screen dragShape:... |
|
1532 |
"/ 936 Screen resizeRectangle... |
|
1533 |
"/ 937 Screen displayShape:... |
|
1534 |
"/ 938 Window resizeFromUserWithMinimum:maximum: |
|
1535 |
"/ 940 Window primClose |
|
1536 |
"/ 942 Window getDimensions |
|
1537 |
"/ 943 Window moveTo:resize: |
|
1538 |
"/ 944 Window primMap |
|
1539 |
"/ 945 Window class primNewAt:extent:min:max:windowType: |
|
1540 |
"/ 946 Screen flush |
|
1541 |
"/ 947 Screen getScreenDimensions |
|
1542 |
"/ 948 Window unmap |
|
1543 |
"/ 950 Screen sync |
|
1544 |
"/ 951 Window setIconMask: |
|
1545 |
"/ 952 Window label:iconLabel: |
|
1546 |
"/ 953 Window raise |
|
1547 |
"/ 954 Window lower |
|
1548 |
"/ 955 Screen queryStackingOrder |
|
1549 |
"/ 956 TextMeasurer primScanCharactersFrom:... |
|
1550 |
"/ 957 GraphicsContext displayMappedString:from:to:at:withMap: |
|
1551 |
"/ 959 Window setBackgroundPixel: |
|
1552 |
"/ 960 Screen class primOpen: |
|
1553 |
"/ 965 UnmappableSurface contentsOfAreaOriginX:y:width:height: |
|
1554 |
"/ 966 Window contentsOfAreaOriginX:y:width:height: |
|
1555 |
"/ 967 Screen contentsOfAreaOriginX:y:width:height: |
|
1556 |
"/ 970 Mask class primExtent:depth: |
|
1557 |
"/ 971 Mask privateClose |
|
1558 |
"/ 976 GraphicsContext displayCharacterOfIndex:at: |
|
1559 |
"/ 978 DeviceFont class listFonts |
|
1560 |
"/ 979 DeviceFont primLoadFont |
|
1561 |
"/ 980 DeviceFont primUnLoadFont |
|
1562 |
"/ 985 GraphicsContext displayLineFrom:to: |
|
1563 |
"/ 986 GraphicsContext displayPolyline:at: |
|
1564 |
"/ 987 GraphicsContext displayPolygon:at: |
|
1565 |
"/ 988 GraphicsContext primDisplayRectangleOrigin:extent: |
|
1566 |
"/ 989 GraphicsContext primDisplayRectangularBorderOrigin:extent: |
|
1567 |
"/ 990 GraphicsContext primDisplayArcBBoxOrigin:extent:startAngle:sweepAngle: |
|
1568 |
"/ 991 GraphicsContext primDisplayWedgeBBoxOrigin:extent:startAngle:sweepAngle: |
|
1569 |
"/ 992 GraphicsContext displayMask:at:" |
|
1570 |
"/ 993 GraphicsContext displayUninterpretedImageBits:at: |
|
1571 |
"/ 994 GraphicsContext primCopyRectangularAreaExtent:from:sourceOffset:destinationOffset: |
|
1572 |
"/ 995 GraphicsContext primCopyMaskedArea:from:sourceOffset:destinationOffset: |
|
1573 |
"/ 996 Screen deviceColormap |
|
1574 |
"/ 998 GraphicsContext displayUninterpretedMonoImageBits:foreground:background:at: |
|
1575 |
||
141 | 1576 |
cls notNil ifTrue:[ |
1577 |
^ (cls compiledMethodAt:sel) code |
|
1578 |
]. |
|
1579 |
^ nil |
|
1580 |
! |
|
1581 |
||
277
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1582 |
createMethod |
429 | 1583 |
|newMethod| |
277
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1584 |
|
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
287
diff
changeset
|
1585 |
newMethod := Method new:(litArray size). |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
287
diff
changeset
|
1586 |
litArray notNil ifTrue:[ |
512 | 1587 |
"/ fixup CheapBlocks method-field in literal array, |
1588 |
litArray do:[:aLiteral | |
|
1589 |
(aLiteral isMemberOf:CheapBlock) ifTrue:[ |
|
1590 |
aLiteral setMethod:newMethod. |
|
1591 |
] |
|
1592 |
]. |
|
1593 |
newMethod literals:litArray |
|
277
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1594 |
]. |
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1595 |
|
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1596 |
newMethod numberOfMethodVars:(self numberOfMethodVars). |
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1597 |
newMethod numberOfMethodArgs:(self numberOfMethodArgs). |
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1598 |
newMethod stackSize:(self maxStackDepth). |
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1599 |
|
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1600 |
primitiveResource notNil ifTrue:[ |
512 | 1601 |
newMethod setResourceFlag |
277
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1602 |
]. |
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1603 |
|
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1604 |
^ newMethod |
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1605 |
|
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1606 |
"Created: 18.5.1996 / 16:33:17 / cg" |
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
287
diff
changeset
|
1607 |
"Modified: 24.6.1996 / 12:32:50 / stefan" |
383 | 1608 |
"Modified: 21.10.1996 / 13:58:41 / cg" |
277
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1609 |
! |
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
1610 |
|
141 | 1611 |
genByteCodeFrom:symbolicCodeArray |
1612 |
"convert symbolicCode into bytecodes" |
|
1613 |
||
1614 |
|symIndex "{Class: SmallInteger }" |
|
1615 |
codeSize "{Class: SmallInteger }" |
|
1616 |
symCodeSize "{Class: SmallInteger }" |
|
429 | 1617 |
index nextSym addr |
141 | 1618 |
codeSymbol nargs needRetry |
429 | 1619 |
stackDepth relocInfo level nvars round| |
141 | 1620 |
|
1621 |
symbolicCodeArray isNil ifTrue:[^ self]. |
|
1622 |
||
1623 |
round := 0. |
|
1624 |
needRetry := true. |
|
1625 |
symCodeSize := symbolicCodeArray size. |
|
192
5f5ecdcffc67
share common byteCodes - just an idea and more is needed for most compact code
Claus Gittinger <cg@exept.de>
parents:
191
diff
changeset
|
1626 |
ShareCode ifTrue:[ |
512 | 1627 |
codeBytes := self checkForCommonCode:symbolicCodeArray. |
1628 |
codeBytes notNil ifTrue:[ |
|
1629 |
^ self |
|
1630 |
]. |
|
192
5f5ecdcffc67
share common byteCodes - just an idea and more is needed for most compact code
Claus Gittinger <cg@exept.de>
parents:
191
diff
changeset
|
1631 |
]. |
141 | 1632 |
codeSize := symCodeSize. |
1633 |
||
1634 |
[needRetry] whileTrue:[ |
|
512 | 1635 |
stackDepth := 0. |
1636 |
maxStackDepth := 0. |
|
1637 |
||
1638 |
codeBytes := ByteArray uninitializedNew:codeSize. |
|
1639 |
relocInfo := Array basicNew:(codeSize + 1). |
|
1640 |
symIndex := 1. |
|
1641 |
codeIndex := 1. |
|
1642 |
||
1643 |
needRetry := false. |
|
1644 |
round := round + 1. |
|
1645 |
||
1646 |
[symIndex <= symCodeSize] whileTrue:[ |
|
1647 |
relocInfo at:symIndex put:codeIndex. |
|
1648 |
||
1649 |
codeSymbol := symbolicCodeArray at:symIndex. |
|
1650 |
symIndex := symIndex + 1. |
|
1651 |
stackDelta := 0. |
|
1652 |
extra := extraLiteral := nil. |
|
1653 |
lineno := false. |
|
1654 |
||
1655 |
self appendByteCodeFor:codeSymbol. |
|
1656 |
||
1657 |
extraLiteral notNil ifTrue:[ |
|
1658 |
self addLiteral:extraLiteral |
|
1659 |
]. |
|
1660 |
||
1661 |
lineno ifTrue:[ |
|
1662 |
self appendByte:((symbolicCodeArray at:symIndex) min:255). |
|
1663 |
symIndex := symIndex + 1. |
|
1664 |
codeSymbol == #lineno16 ifTrue:[ |
|
1665 |
self appendByte:((symbolicCodeArray at:symIndex) min:255). |
|
1666 |
symIndex := symIndex + 1 |
|
1667 |
] |
|
1668 |
]. |
|
1669 |
||
1670 |
extra notNil ifTrue:[ |
|
1671 |
nextSym := symbolicCodeArray at:symIndex. |
|
1672 |
||
1673 |
(extra == #number) ifTrue:[ |
|
1674 |
index := nextSym. |
|
1675 |
symIndex := symIndex + 1. |
|
1676 |
self appendSignedByte:index |
|
1677 |
||
1678 |
] ifFalse:[ (extra == #number16) ifTrue:[ |
|
1679 |
index := nextSym. |
|
1680 |
symIndex := symIndex + 2. |
|
1681 |
self appendSignedWord:index |
|
1682 |
||
1683 |
] ifFalse:[ (extra == #unsigned16) ifTrue:[ |
|
1684 |
index := nextSym. |
|
1685 |
symIndex := symIndex + 2. |
|
1686 |
self appendWord:index |
|
1687 |
||
1688 |
] ifFalse:[ (extra == #index) ifTrue:[ |
|
1689 |
index := nextSym. |
|
1690 |
symIndex := symIndex + 1. |
|
1691 |
self appendByte:index |
|
1692 |
||
1693 |
] ifFalse:[ (extra == #lit) ifTrue:[ |
|
1694 |
index := self addLiteral:nextSym. |
|
1695 |
symIndex := symIndex + 1. |
|
1696 |
self appendByte:index |
|
1697 |
||
1698 |
] ifFalse:[ (extra == #speciallit) ifTrue:[ |
|
1699 |
index := self addLiteral:nextSym. |
|
1700 |
index > 255 ifTrue:[ |
|
1701 |
self parseError:'too many globals (' , |
|
1702 |
(symbolicCodeArray at:symIndex) , |
|
1703 |
' index=' , index printString , |
|
1704 |
') in method - please simplify'. |
|
1705 |
^ #Error |
|
1706 |
]. |
|
1707 |
symIndex := symIndex + 1. |
|
1708 |
self appendByte:index. |
|
1709 |
||
1710 |
] ifFalse:[ (extra == #speciallitS) ifTrue:[ |
|
1711 |
index := nextSym. |
|
1712 |
symIndex := symIndex + 1. |
|
1713 |
self appendByte:index. |
|
1714 |
||
1715 |
] ifFalse:[ (extra == #speciallitL) ifTrue:[ |
|
1716 |
index := nextSym. |
|
1717 |
symIndex := symIndex + 2. |
|
1718 |
self appendWord:index. |
|
1719 |
||
1720 |
] ifFalse:[ (extra == #offset) ifTrue:[ |
|
1721 |
relocInfo at:symIndex put:codeIndex. |
|
1722 |
self addReloc:symIndex. |
|
1723 |
symIndex := symIndex + 1. |
|
1724 |
self appendByte:0 |
|
1725 |
||
1726 |
] ifFalse:[ (extra == #indexLevel) ifTrue:[ |
|
1727 |
index := nextSym. |
|
1728 |
symIndex := symIndex + 1. |
|
1729 |
self appendByte:index. |
|
1730 |
level := symbolicCodeArray at:symIndex. |
|
1731 |
symIndex := symIndex + 1. |
|
1732 |
self appendByte:level |
|
1733 |
||
1734 |
] ifFalse:[ (extra == #offsetNvarNarg) ifTrue:[ |
|
1735 |
relocInfo at:symIndex put:codeIndex. |
|
1736 |
self addReloc:symIndex. |
|
1737 |
symIndex := symIndex + 1. |
|
1738 |
self appendEmptyByte. |
|
1739 |
nvars := symbolicCodeArray at:symIndex. |
|
1740 |
symIndex := symIndex + 1. |
|
1741 |
self appendByte:nvars. |
|
1742 |
level := symbolicCodeArray at:symIndex. |
|
1743 |
symIndex := symIndex + 1. |
|
1744 |
self appendByte:level |
|
1745 |
||
1746 |
] ifFalse:[ (extra == #absoffset) ifTrue:[ |
|
1747 |
relocInfo at:symIndex put:codeIndex. |
|
1748 |
self addReloc:symIndex. |
|
1749 |
addr := symbolicCodeArray at:symIndex. |
|
1750 |
symIndex := symIndex + 1. |
|
1751 |
self appendByte:(addr bitAnd:16rFF). |
|
1752 |
self appendByte:((addr bitShift:-8) bitAnd:16rFF). |
|
1753 |
||
1754 |
] ifFalse:[ (extra == #absoffsetNvarNarg) ifTrue:[ |
|
1755 |
relocInfo at:symIndex put:codeIndex. |
|
1756 |
self addReloc:symIndex. |
|
1757 |
addr := symbolicCodeArray at:symIndex. |
|
1758 |
symIndex := symIndex + 1. |
|
1759 |
self appendByte:(addr bitAnd:16rFF). |
|
1760 |
self appendByte:((addr bitShift:-8) bitAnd:16rFF). |
|
1761 |
nvars := symbolicCodeArray at:symIndex. |
|
1762 |
symIndex := symIndex + 1. |
|
1763 |
self appendByte:nvars. |
|
1764 |
level := symbolicCodeArray at:symIndex. |
|
1765 |
symIndex := symIndex + 1. |
|
1766 |
self appendByte:level |
|
1767 |
||
1768 |
] ifFalse:[ (extra == #special) ifTrue:[ |
|
1769 |
((codeSymbol == #send) |
|
1770 |
or:[codeSymbol == #sendSelf |
|
1771 |
or:[codeSymbol == #superSend |
|
1772 |
or:[codeSymbol == #hereSend]]]) ifTrue:[ |
|
1773 |
index := nextSym. |
|
1774 |
symIndex := symIndex + 1. |
|
1775 |
nargs := symbolicCodeArray at:symIndex. |
|
1776 |
symIndex := symIndex + 1. |
|
1777 |
self appendByte:nargs. |
|
1778 |
self appendByte:index. |
|
1779 |
||
1780 |
(codeSymbol == #superSend |
|
1781 |
or:[codeSymbol == #hereSend]) ifTrue:[ |
|
1782 |
index := symbolicCodeArray at:symIndex. |
|
1783 |
symIndex := symIndex + 1. |
|
1784 |
self appendByte:index |
|
1785 |
]. |
|
1786 |
stackDelta := nargs negated. |
|
1787 |
codeSymbol == #sendSelf ifTrue:[ |
|
1788 |
stackDelta := stackDelta + 1 |
|
1789 |
] |
|
1790 |
] ifFalse:[ (codeSymbol == #sendDrop) ifTrue:[ |
|
1791 |
index := nextSym. |
|
1792 |
symIndex := symIndex + 1. |
|
1793 |
nargs := symbolicCodeArray at:symIndex. |
|
1794 |
symIndex := symIndex + 1. |
|
1795 |
self appendByte:nargs. |
|
1796 |
self appendByte:index. |
|
1797 |
stackDelta := (nargs + 1) negated |
|
1798 |
]] |
|
1799 |
||
1800 |
] ifFalse:[ (extra == #specialL) ifTrue:[ |
|
1801 |
((codeSymbol == #sendL) |
|
1802 |
or:[codeSymbol == #sendSelfL |
|
1803 |
or:[codeSymbol == #superSendL |
|
1804 |
or:[codeSymbol == #hereSendL]]]) ifTrue:[ |
|
1805 |
index := nextSym. |
|
1806 |
symIndex := symIndex + 2. |
|
1807 |
nargs := symbolicCodeArray at:symIndex. |
|
1808 |
symIndex := symIndex + 1. |
|
1809 |
self appendByte:nargs. |
|
1810 |
self appendWord:index. |
|
1811 |
(codeSymbol == #superSendL |
|
1812 |
or:[codeSymbol == #hereSendL]) ifTrue:[ |
|
1813 |
index := symbolicCodeArray at:symIndex. |
|
1814 |
symIndex := symIndex + 2. |
|
1815 |
self appendWord:index. |
|
1816 |
]. |
|
1817 |
stackDelta := nargs negated. |
|
1818 |
codeSymbol == #sendSelfL ifTrue:[ |
|
1819 |
stackDelta := stackDelta + 1 |
|
1820 |
] |
|
1821 |
] |
|
1822 |
] ifFalse:[ (extra == #specialSend) ifTrue:[ |
|
1823 |
index := nextSym. |
|
1824 |
symIndex := symIndex + 1. |
|
1825 |
self appendByte:index. |
|
1826 |
||
1827 |
] ifFalse:[ |
|
1828 |
"/ self halt:'internal error' |
|
475 | 1829 |
|
512 | 1830 |
]]]]]]]]]]]]]]]] |
1831 |
]. |
|
1832 |
||
1833 |
stackDepth := stackDepth + stackDelta. |
|
1834 |
(stackDepth > maxStackDepth) ifTrue:[ |
|
1835 |
maxStackDepth := stackDepth |
|
1836 |
] |
|
1837 |
]. |
|
1838 |
relocInfo at:symIndex put:codeIndex. |
|
1839 |
||
1840 |
needRetry ifFalse:[ |
|
1841 |
" |
|
1842 |
now relocate - returns true if ok, false if we have to do it again |
|
1843 |
(when short jumps have been changed to long jumps) |
|
1844 |
" |
|
1845 |
relocList notNil ifTrue:[ |
|
1846 |
needRetry := (self relocateWith:symbolicCodeArray relocInfo:relocInfo) not. |
|
1847 |
" |
|
1848 |
if returned with false, a relative jump was made into |
|
1849 |
an absolute jump - need to start over with one more byte space |
|
1850 |
" |
|
1851 |
needRetry ifTrue:[ |
|
1852 |
relocList := nil. |
|
1853 |
codeSize := codeSize + 1. |
|
1854 |
] |
|
1855 |
] |
|
1856 |
] ifTrue:[ |
|
1857 |
'Compiler [info]: compiling again ...' infoPrintCR. |
|
1858 |
] |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1859 |
]. |
141 | 1860 |
"code printNL." |
1861 |
^ errorFlag |
|
1862 |
||
1863 |
"Modified: 3.9.1995 / 12:59:43 / claus" |
|
475 | 1864 |
"Modified: 10.1.1997 / 15:17:51 / cg" |
141 | 1865 |
! |
1866 |
||
1867 |
genSymbolicCode |
|
1868 |
"traverse the parse-tree producing symbolicCode - return the codeArray" |
|
1869 |
||
1870 |
|codeStream code thisStatement lastStatement| |
|
1871 |
||
1872 |
litArray := nil. |
|
1873 |
codeStream := WriteStream on:(OrderedCollection new:100). |
|
1874 |
||
1875 |
thisStatement := tree. |
|
1876 |
[thisStatement notNil] whileTrue:[ |
|
512 | 1877 |
lastStatement := thisStatement. |
1878 |
thisStatement codeForSideEffectOn:codeStream inBlock:nil for:self. |
|
1879 |
thisStatement := thisStatement nextStatement |
|
141 | 1880 |
]. |
1881 |
(lastStatement isNil or:[lastStatement isReturnNode not]) |
|
1882 |
ifTrue:[ |
|
512 | 1883 |
"not a return - add retSelf" |
1884 |
" |
|
1885 |
if the last statement was a send for side-effect, |
|
1886 |
replace the previous drop by a retSelf. |
|
1887 |
In this case we have to keep an extra retSelf bacause |
|
1888 |
it could be a jump target. |
|
1889 |
" |
|
1890 |
(lastStatement notNil |
|
1891 |
and:[(code := codeStream contents) notNil |
|
1892 |
and:[code size > 0 |
|
1893 |
and:[code last == #drop]]]) ifTrue:[ |
|
1894 |
codeStream backStep. |
|
1895 |
codeStream nextPut:#retSelf |
|
1896 |
]. |
|
1897 |
codeStream nextPut:#retSelf |
|
141 | 1898 |
]. |
1899 |
^ codeStream contents |
|
328 | 1900 |
|
330
9b9a1ff67ba3
Bad change in previous version. Need extra bytecode as jump target.
Stefan Vogel <sv@exept.de>
parents:
328
diff
changeset
|
1901 |
"Modified: 15.8.1996 / 17:35:02 / stefan" |
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1902 |
! |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1903 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1904 |
hasLineNumber:sel |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1905 |
"return true, if special send code needs lineNr" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1906 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1907 |
(sel == #==) ifTrue:[^ false]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1908 |
(sel == #~~) ifTrue:[^ false]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1909 |
(sel == #class) ifTrue:[^ false]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1910 |
(sel == #isNil) ifTrue:[^ false]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1911 |
(sel == #notNil) ifTrue:[^ false]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1912 |
^ true |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1913 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1914 |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1915 |
isBuiltIn1ArgSelector:sel forReceiver:receiver |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1916 |
"return true, if selector sel is built-in. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1917 |
(i.e. there is a single bytecode for it)" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1918 |
|
530 | 1919 |
(sel == #at:) ifTrue:[^ true]. |
1920 |
(sel == #value:) ifTrue:[^ true]. |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1921 |
(sel == #bitAnd:) ifTrue:[^ true]. |
530 | 1922 |
(sel == #bitOr:) ifTrue:[^ true]. |
1923 |
(sel == #new:) ifTrue:[^ true]. |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1924 |
(sel == #basicNew:) ifTrue:[ |
530 | 1925 |
"/ this one is critical - some redefine it |
1926 |
receiver isGlobal ifTrue:[ |
|
1927 |
(#('String' 'ByteArray' 'Array' |
|
1928 |
'Point' 'Rectangle' 'Object') |
|
1929 |
includes:receiver name) ifTrue:[^ true]. |
|
1930 |
]. |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1931 |
]. |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1932 |
^ false |
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1933 |
|
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1934 |
"Created: 17.4.1996 / 22:33:13 / cg" |
530 | 1935 |
"Modified: 4.6.1997 / 12:24:18 / cg" |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1936 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1937 |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1938 |
isBuiltIn2ArgSelector:sel forReceiver:receiver |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1939 |
"return true, if selector sel is built-in. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1940 |
(i.e. there is a single bytecode for it)" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1941 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1942 |
(sel == #at:put:) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1943 |
^ false |
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1944 |
|
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1945 |
"Created: 17.4.1996 / 22:33:16 / cg" |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1946 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1947 |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1948 |
isBuiltInBinarySelector:sel forReceiver:receiver |
530 | 1949 |
"return true, if binary selector sel is built-in. |
1950 |
(i.e. there is a single bytecode for it)" |
|
1951 |
||
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1952 |
sel == #== ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1953 |
sel == #~~ ifTrue:[^ true]. |
530 | 1954 |
sel == #= ifTrue:[^ true]. |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1955 |
sel == #~= ifTrue:[^ true]. |
530 | 1956 |
sel == #+ ifTrue:[^ true]. |
1957 |
sel == #- ifTrue:[^ true]. |
|
1958 |
sel == #< ifTrue:[^ true]. |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1959 |
sel == #<= ifTrue:[^ true]. |
530 | 1960 |
sel == #> ifTrue:[^ true]. |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1961 |
sel == #>= ifTrue:[^ true]. |
530 | 1962 |
sel == #* ifTrue:[^ true]. |
1963 |
sel == #& ifTrue:[^ true]. |
|
1964 |
sel == #| ifTrue:[^ true]. |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1965 |
^ false |
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1966 |
|
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1967 |
"Created: 17.4.1996 / 22:34:27 / cg" |
530 | 1968 |
"Modified: 4.6.1997 / 12:24:00 / cg" |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1969 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1970 |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1971 |
isBuiltInUnarySelector:sel forReceiver:receiver |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1972 |
"return true, if unary selector sel is built-in. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1973 |
(i.e. there is a single bytecode for it)" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1974 |
|
530 | 1975 |
(sel == #value) ifTrue:[^ true]. |
1976 |
(sel == #class) ifTrue:[^ true]. |
|
1977 |
(sel == #size) ifTrue:[^ true]. |
|
1978 |
(sel == #isNil) ifTrue:[^ true]. |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1979 |
(sel == #notNil) ifTrue:[^ true]. |
530 | 1980 |
(sel == #not) ifTrue:[^ true]. |
1981 |
||
1982 |
(sel == #new) ifTrue:[^ true]. |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1983 |
(sel == #basicNew) ifTrue:[ |
530 | 1984 |
"/ this one is critical - some redefine it |
1985 |
receiver isGlobal ifTrue:[ |
|
1986 |
(#('String' 'ByteArray' 'Array' |
|
1987 |
'Point' 'Rectangle' 'Object') |
|
1988 |
includes:receiver name) ifTrue:[^ true]. |
|
1989 |
]. |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1990 |
]. |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1991 |
^ false |
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1992 |
|
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
247
diff
changeset
|
1993 |
"Created: 17.4.1996 / 22:32:16 / cg" |
530 | 1994 |
"Modified: 4.6.1997 / 12:23:30 / cg" |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1995 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1996 |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1997 |
moveGlobalsToFront |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1998 |
"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
|
1999 |
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
|
2000 |
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
|
2001 |
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
|
2002 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2003 |
litArray isNil ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2004 |
^ 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
|
2005 |
]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2006 |
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
|
2007 |
(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
|
2008 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2009 |
(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
|
2010 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2011 |
(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
|
2012 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2013 |
(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
|
2014 |
ifTrue:[a < b]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2015 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2016 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2017 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2018 |
]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2019 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2020 |
" |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2021 |
#(#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
|
2022 |
sort:[:a :b | |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2023 |
(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
|
2024 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2025 |
(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
|
2026 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2027 |
(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
|
2028 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2029 |
(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
|
2030 |
ifTrue:[(a < b)]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2031 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2032 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2033 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2034 |
]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2035 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2036 |
" |
141 | 2037 |
! |
2038 |
||
2039 |
relocateWith:symbolicCodeArray relocInfo:relocInfo |
|
2040 |
"helper for genByteCodeFrom - relocate code using relocInfo. |
|
2041 |
if relocation fails badly (due to long relative jumps) patch |
|
2042 |
symbolicCode to use absolute jumps instead and return false |
|
2043 |
(genByteCodeFrom will then try again). Otherwise return true. |
|
2044 |
Also, on the fly, jumps to jumps and jumps to return are handled." |
|
2045 |
||
2046 |
|delta "{Class: SmallInteger }" |
|
2047 |
codePos "{Class: SmallInteger }" |
|
2048 |
opCodePos "{Class: SmallInteger }" |
|
2049 |
codeOffset "{Class: SmallInteger }" |
|
2050 |
symOffset |
|
2051 |
opcode "{Class: SmallInteger }" |
|
2052 |
dstOpcode jumpTarget |
|
2053 |
jumpCode deleteSet| |
|
2054 |
||
2055 |
deleteSet := OrderedCollection new. |
|
2056 |
relocList do:[:sIndex | |
|
2057 |
"have to relocate symCode at sIndex ..." |
|
2058 |
symOffset := symbolicCodeArray at:sIndex. "the target in the symbolic code" |
|
2059 |
codePos := relocInfo at:sIndex. "position of the offet in byte code" |
|
2060 |
codeOffset := relocInfo at:symOffset. "position of the target in byte code" |
|
2061 |
delta := codeOffset - codePos - 1. |
|
2062 |
opCodePos := codePos - 1. |
|
2063 |
opcode := codeBytes at:opCodePos. |
|
2064 |
||
2065 |
(opcode between:190 and:199) ifTrue:[ |
|
2066 |
"an absolute jump/makeBlock" |
|
2067 |
||
2068 |
codeBytes at:codePos put:(codeOffset bitAnd:16rFF). |
|
2069 |
codeBytes at:(codePos + 1) put:(codeOffset bitShift:-8) |
|
2070 |
] ifFalse:[ |
|
2071 |
"get jump-code from long and vlong codes" |
|
2072 |
(opcode between:50 and:59) ifFalse:[ |
|
2073 |
(opcode between:60 and:69) ifTrue:[ |
|
2074 |
opcode := opcode - 10 |
|
2075 |
] ifFalse:[ |
|
2076 |
(opcode between:70 and:79) ifTrue:[ |
|
2077 |
opcode := opcode - 20 |
|
2078 |
] ifFalse:[ |
|
2079 |
self error:'invalid code to relocate' |
|
2080 |
] |
|
2081 |
]. |
|
2082 |
]. |
|
2083 |
||
2084 |
"optimize jump to return and jump to jump" |
|
2085 |
||
2086 |
(opcode == 54) ifTrue:[ |
|
2087 |
"a jump" |
|
2088 |
dstOpcode := symbolicCodeArray at:symOffset. |
|
2089 |
||
2090 |
(#(retSelf retTop retNil retTrue retFalse ret0 "blockRetTop") includes:dstOpcode) ifTrue:[ |
|
2091 |
"a jump to a return - put in the return instead jump" |
|
2092 |
||
2093 |
symbolicCodeArray at:(sIndex - 1) put:dstOpcode. |
|
2094 |
symbolicCodeArray at:sIndex put:dstOpcode. |
|
2095 |
codeBytes at:opCodePos put:(self byteCodeFor:dstOpcode). |
|
2096 |
delta := 0. |
|
2097 |
deleteSet add:sIndex. |
|
2098 |
||
2099 |
" |
|
2100 |
'jump to return at: ' print. (sIndex - 1) printNL. |
|
2101 |
" |
|
2102 |
] ifFalse:[ |
|
2103 |
(dstOpcode == #jump) ifTrue:[ |
|
2104 |
"jump to jump to be done soon" |
|
2105 |
jumpTarget := symbolicCodeArray at:(symOffset + 1). |
|
2106 |
" |
|
2107 |
'jump to jump at: ' print. (sIndex - 1) print. |
|
2108 |
' newTarget:' print. jumpTarget printNL. |
|
2109 |
" |
|
2110 |
||
2111 |
symbolicCodeArray at:sIndex put:jumpTarget. |
|
2112 |
symOffset := jumpTarget. |
|
2113 |
codeOffset := relocInfo at:symOffset. |
|
2114 |
delta := codeOffset - codePos - 1. |
|
2115 |
||
2116 |
"continue with new delta" |
|
2117 |
] |
|
2118 |
] |
|
2119 |
]. |
|
2120 |
(#(50 51 52 53 56 57 58 59) includes:opcode) ifTrue:[ |
|
2121 |
"a conditional jump" |
|
2122 |
||
2123 |
dstOpcode := symbolicCodeArray at:symOffset. |
|
2124 |
(dstOpcode == #jump) ifTrue:[ |
|
2125 |
"conditional jump to unconditional jump" |
|
2126 |
jumpTarget := symbolicCodeArray at:(symOffset + 1). |
|
2127 |
" |
|
2128 |
'cond jump to jump at: ' print. (sIndex - 1) print. |
|
2129 |
' newTarget:' print. jumpTarget printNL. |
|
2130 |
" |
|
2131 |
||
2132 |
symbolicCodeArray at:sIndex put:jumpTarget. |
|
2133 |
symOffset := jumpTarget. |
|
2134 |
codeOffset := relocInfo at:symOffset. |
|
2135 |
delta := codeOffset - codePos - 1. |
|
2136 |
||
2137 |
"continue with new delta" |
|
2138 |
]. |
|
2139 |
]. |
|
2140 |
||
2141 |
(delta >= 0) ifTrue:[ |
|
2142 |
(delta > 127) ifTrue:[ |
|
2143 |
(opcode between:50 and:59) ifFalse:[ |
|
2144 |
self error:'invalid code to relocate' |
|
2145 |
] ifTrue:[ |
|
2146 |
(delta > 255) ifTrue:[ |
|
2147 |
"change jmp into vljmp ..." |
|
2148 |
codeBytes at:opCodePos put:(opcode + 20). |
|
2149 |
delta := delta - 256 |
|
2150 |
] ifFalse:[ |
|
2151 |
"change jmp into ljmp ..." |
|
2152 |
codeBytes at:opCodePos put:(opcode + 10). |
|
2153 |
delta := delta - 128 |
|
2154 |
]. |
|
2155 |
(delta > 127) ifTrue:[ |
|
2156 |
"change symbolic into a jump absolute and fail" |
|
2157 |
jumpCode := symbolicCodeArray at:(sIndex - 1). |
|
2158 |
symbolicCodeArray at:(sIndex - 1) put:(self absJumpFromJump:jumpCode). |
|
2159 |
symbolicCodeArray at:sIndex put:symOffset. |
|
2160 |
" |
|
2161 |
'change short into abs jump' printNL. |
|
2162 |
" |
|
2163 |
deleteSet do:[:d | relocList remove:d]. |
|
2164 |
^ false |
|
2165 |
] |
|
2166 |
]. |
|
2167 |
]. |
|
2168 |
codeBytes at:codePos put:delta |
|
2169 |
] ifFalse:[ |
|
2170 |
(delta < -128) ifTrue:[ |
|
2171 |
(opcode between:50 and:59) ifFalse:[ |
|
2172 |
self error:'invalid code to relocate' |
|
2173 |
] ifTrue:[ |
|
2174 |
(delta < -256) ifTrue:[ |
|
2175 |
"change jmp into vljmp ..." |
|
2176 |
codeBytes at:opCodePos put:(opcode + 20). |
|
2177 |
delta := delta + 256 |
|
2178 |
] ifFalse:[ |
|
2179 |
"change jmp into ljmp ..." |
|
2180 |
codeBytes at:opCodePos put:(opcode + 10). |
|
2181 |
delta := delta + 128 |
|
2182 |
]. |
|
2183 |
(delta < -128) ifTrue:[ |
|
2184 |
"change symbolic into a jump absolute and fail" |
|
2185 |
jumpCode := symbolicCodeArray at:(sIndex - 1). |
|
2186 |
symbolicCodeArray at:(sIndex - 1) put:(self absJumpFromJump:jumpCode). |
|
2187 |
symbolicCodeArray at:sIndex put:symOffset. |
|
2188 |
" |
|
2189 |
'change short into abs jump' printNL. |
|
2190 |
" |
|
2191 |
deleteSet do:[:d | relocList remove:d]. |
|
2192 |
^ false |
|
2193 |
] |
|
2194 |
] |
|
2195 |
]. |
|
2196 |
codeBytes at:codePos put:(256 + delta) |
|
2197 |
] |
|
2198 |
] |
|
2199 |
]. |
|
2200 |
(errorFlag == #Error) ifTrue:[ |
|
2201 |
self error:'relocation range error' |
|
2202 |
]. |
|
2203 |
^ true |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2204 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2205 |
|
247 | 2206 |
specialGlobalCodeFor:aSymbol |
530 | 2207 |
"codeExtension for globals, |
2208 |
which can be accessed by specialGlobal opCode" |
|
2209 |
||
2210 |
|idx| |
|
2211 |
||
2212 |
idx := self specialGlobals identityIndexOf:aSymbol ifAbsent:nil. |
|
2213 |
idx isNil ifTrue:[^ idx]. |
|
2214 |
^ idx - 1. |
|
2215 |
||
2216 |
"Modified: 4.6.1997 / 12:31:22 / cg" |
|
2217 |
! |
|
2218 |
||
2219 |
specialGlobals |
|
2220 |
"list of globals which can be accessed by specialGlobal opCode; |
|
2221 |
adding any here requires a new VM (i.e. you cannot change it)" |
|
2222 |
||
2223 |
^ #( |
|
2224 |
#Array "/ 0 |
|
2225 |
#String "/ 1 |
|
2226 |
#FloatArray "/ 2 |
|
2227 |
#DoubleArray "/ 3 |
|
2228 |
#Point "/ 4 |
|
2229 |
#Symbol "/ 5 |
|
2230 |
#Smalltalk "/ 6 |
|
2231 |
#Processor "/ 7 |
|
2232 |
#SmallInteger "/ 8 |
|
2233 |
#Character "/ 9 |
|
2234 |
#Float "/ 10 |
|
2235 |
#Process "/ 11 |
|
2236 |
#Set "/ 12 |
|
2237 |
#IdentitySet "/ 13 |
|
2238 |
#Dictionary "/ 14 |
|
2239 |
#IdentityDictionary "/ 15 |
|
2240 |
#Sempahore "/ 16 |
|
2241 |
#OrderedCollection "/ 17 |
|
2242 |
) |
|
2243 |
||
2244 |
"Created: 4.6.1997 / 12:17:47 / cg" |
|
2245 |
"Modified: 4.6.1997 / 12:31:35 / cg" |
|
247 | 2246 |
! |
2247 |
||
400
e5cfc008be47
bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents:
383
diff
changeset
|
2248 |
specialSendCodeFor:sel |
530 | 2249 |
"return the codeExtension for sends, |
2250 |
which can be performed by specialSend opCode" |
|
2251 |
||
2252 |
|idx| |
|
2253 |
||
2254 |
idx := self specialSends identityIndexOf:sel ifAbsent:nil. |
|
2255 |
idx isNil ifTrue:[^ idx]. |
|
2256 |
^ idx - 1. |
|
2257 |
||
2258 |
"Modified: 4.6.1997 / 12:31:08 / cg" |
|
2259 |
! |
|
2260 |
||
2261 |
specialSends |
|
2262 |
"list of selectors which can be sent by specialSend opCode; |
|
2263 |
adding any here requires a new VM (i.e. you cannot change it)" |
|
2264 |
||
2265 |
^ #( |
|
2266 |
#top "/ 0 |
|
2267 |
#bottom "/ 1 |
|
2268 |
#left "/ 2 |
|
2269 |
#right "/ 3 |
|
2270 |
#x "/ 4 |
|
2271 |
#y "/ 5 |
|
2272 |
#width "/ 6 |
|
2273 |
#height "/ 7 |
|
2274 |
#origin "/ 8 |
|
2275 |
#extent "/ 9 |
|
2276 |
#asInteger "/ 10 |
|
2277 |
#rounded "/ 11 |
|
2278 |
#next "/ 12 |
|
2279 |
#peek "/ 13 |
|
2280 |
) |
|
2281 |
||
2282 |
"Created: 4.6.1997 / 12:20:28 / cg" |
|
2283 |
"Modified: 4.6.1997 / 12:31:56 / cg" |
|
0 | 2284 |
! ! |
49 | 2285 |
|
2286 |
!ByteCodeCompiler methodsFor:'machine code generation'! |
|
2287 |
||
2288 |
compileToMachineCode:aString forClass:aClass inCategory:cat |
|
512 | 2289 |
notifying:requestor install:install skipIfSame:skipIfSame silent:silent |
49 | 2290 |
"this is called to compile primitive code. |
2291 |
This is EXPERIMENTAL and going to be changed to raise an error, |
|
2292 |
an redefined in subclasses which can do it (either by direct compilation, or by calling |
|
2293 |
the external stc do do it. |
|
2294 |
For a description of the arguments, see compile:forClass....." |
|
2295 |
||
411
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
2296 |
|stFileName stream handle address stcFlags cFlags |
429 | 2297 |
command oFileName cFileName |
411
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
2298 |
initName newMethod ok status className sep class stcPath ccPath |
510
9f19de0f8f0b
also consult searchedLibs when loading individual methods.
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
2299 |
errorStream errorMessages eMsg m supers mP moduleFileName dummyHandle| |
301
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
2300 |
|
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
2301 |
(mP := STCModulePath asFilename) exists ifFalse:[ |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
2302 |
mP makeDirectory |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
2303 |
]. |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
2304 |
(mP isDirectory |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
2305 |
and:[mP isReadable |
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
2306 |
and:[mP isWritable]]) ifFalse:[ |
512 | 2307 |
self parseError:('no access to tempDir: ' , mP pathName) position:1. |
2308 |
^ #CannotLoad |
|
301
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
2309 |
]. |
96 | 2310 |
|
172
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
2311 |
ObjectFileLoader isNil ifTrue:[^ #CannotLoad]. |
85ad12831217
give user a chance to choose between trapCode and original code if compilation to binary is not possible
Claus Gittinger <cg@exept.de>
parents:
162
diff
changeset
|
2312 |
STCCompilation == #never ifTrue:[^ #CannotLoad]. |
120 | 2313 |
(stcPath := self class incrementalStcPath) isNil ifTrue:[ |
512 | 2314 |
self parseError:'no stc compiler available - cannot create machine code' position:1. |
2315 |
^ #CannotLoad |
|
120 | 2316 |
]. |
411
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
2317 |
(ccPath := self class ccPath) isNil ifTrue:[ |
512 | 2318 |
self parseError:'no cc compiler available - cannot create machine code' position:1. |
2319 |
^ #CannotLoad |
|
411
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
2320 |
]. |
54 | 2321 |
|
298
118648c3b590
include the processID in the dynamic modules name;
Claus Gittinger <cg@exept.de>
parents:
297
diff
changeset
|
2322 |
"/ generate a unique name, consisting of my processID and a sequence number |
118648c3b590
include the processID in the dynamic modules name;
Claus Gittinger <cg@exept.de>
parents:
297
diff
changeset
|
2323 |
"/ the processId is added to allow filein of modules from different |
118648c3b590
include the processID in the dynamic modules name;
Claus Gittinger <cg@exept.de>
parents:
297
diff
changeset
|
2324 |
"/ lifes |
118648c3b590
include the processID in the dynamic modules name;
Claus Gittinger <cg@exept.de>
parents:
297
diff
changeset
|
2325 |
|
54 | 2326 |
SequenceNumber isNil ifTrue:[ |
512 | 2327 |
SequenceNumber := 0. |
54 | 2328 |
]. |
2329 |
SequenceNumber := SequenceNumber + 1. |
|
49 | 2330 |
|
298
118648c3b590
include the processID in the dynamic modules name;
Claus Gittinger <cg@exept.de>
parents:
297
diff
changeset
|
2331 |
initName := 'm_' , OperatingSystem getProcessId printString, '_' , SequenceNumber printString. |
118648c3b590
include the processID in the dynamic modules name;
Claus Gittinger <cg@exept.de>
parents:
297
diff
changeset
|
2332 |
|
301
5c0add6f00e2
create temporary method object files in an extra directory;
Claus Gittinger <cg@exept.de>
parents:
298
diff
changeset
|
2333 |
stFileName := './' , initName , '.st'. |
54 | 2334 |
stream := stFileName asFilename writeStream. |
187 | 2335 |
stream isNil ifTrue:[ |
512 | 2336 |
self parseError:'cannot create temporary sourcefile for compilation'. |
2337 |
^ #CannotLoad |
|
187 | 2338 |
]. |
49 | 2339 |
|
407 | 2340 |
[ |
512 | 2341 |
sep := stream class chunkSeparator. |
2342 |
||
2343 |
class := aClass. |
|
2344 |
class isMeta ifTrue:[ |
|
2345 |
class := aClass soleInstance |
|
2346 |
]. |
|
2347 |
supers := class allSuperclasses. |
|
2348 |
supers notNil ifTrue:[ |
|
2349 |
supers reverseDo:[:cls| |
|
2350 |
cls ~~ Object ifTrue:[ |
|
2351 |
cls isLoaded ifFalse:[ |
|
2352 |
stream close. |
|
2353 |
^ #CannotLoad |
|
2354 |
]. |
|
2355 |
cls fileOutDefinitionOn:stream. |
|
2356 |
stream nextPut:sep; cr. |
|
2357 |
] |
|
2358 |
] |
|
2359 |
]. |
|
2360 |
class fileOutDefinitionOn:stream. |
|
2361 |
stream nextPut:sep; cr. |
|
2362 |
||
2363 |
class privateClassesSorted do:[:aPrivateClass | |
|
2364 |
aPrivateClass fileOutDefinitionOn:stream. |
|
2365 |
stream nextPut:sep; cr. |
|
2366 |
]. |
|
2367 |
||
2368 |
class fileOutPrimitiveDefinitionsOn:stream. |
|
2369 |
||
2370 |
stream nextPut:sep. |
|
2371 |
className := class name. |
|
2372 |
||
2373 |
stream nextPutAll:className. |
|
2374 |
aClass isMeta ifTrue:[ |
|
2375 |
stream nextPutAll:' class'. |
|
2376 |
]. |
|
2377 |
stream nextPutAll:' methodsFor:'''; nextPutAll:cat; nextPutAll:''''. |
|
2378 |
stream nextPut:sep; cr. |
|
2379 |
||
2380 |
stream nextPutLine:'"{ Line: 0 }"'; |
|
2381 |
nextChunkPut:aString; |
|
2382 |
space; nextPut:sep. |
|
2383 |
||
2384 |
stream close. |
|
2385 |
||
2386 |
" |
|
2387 |
call stc to compile it |
|
2388 |
" |
|
2389 |
oFileName := './' , initName , '.o'. |
|
2390 |
cFileName := './' , initName , '.c'. |
|
2391 |
oFileName asFilename delete. |
|
2392 |
cFileName asFilename delete. |
|
2393 |
||
2394 |
stcFlags := '-commonSymbols +sharedLibCode +newIncremental -E:errorOutput -N' , initName . |
|
2395 |
cFlags := OperatingSystem getOSDefine. |
|
2396 |
cFlags isNil ifTrue:[ |
|
2397 |
cFlags := '' |
|
2398 |
]. |
|
2399 |
||
2400 |
STCCompilationDefines notNil ifTrue:[ |
|
2401 |
cFlags := cFlags , ' ' , STCCompilationDefines |
|
2402 |
]. |
|
2403 |
STCCompilationIncludes notNil ifTrue:[ |
|
2404 |
stcFlags := STCCompilationIncludes , ' ' , stcFlags. |
|
2405 |
cFlags := cFlags , ' ' , STCCompilationIncludes. |
|
2406 |
]. |
|
2407 |
STCCompilationOptions notNil ifTrue:[ |
|
2408 |
stcFlags := STCCompilationOptions , ' ' , stcFlags |
|
2409 |
]. |
|
2410 |
CCCompilationOptions notNil ifTrue:[ |
|
2411 |
cFlags := cFlags , ' ' , CCCompilationOptions |
|
2412 |
]. |
|
2413 |
||
2414 |
command := stcPath , ' ' , stcFlags , ' -C ' , stFileName. |
|
435 | 2415 |
|
2416 |
"/ 'executing: ' infoPrint. command infoPrintCR. |
|
512 | 2417 |
errorStream := 'errorOutput' asFilename writeStream. |
2418 |
||
2419 |
self activityNotification:'compiling (stc)'. |
|
2420 |
ok := OperatingSystem |
|
2421 |
executeCommand:command |
|
2422 |
inputFrom:nil |
|
2423 |
outputTo:errorStream |
|
2424 |
errorTo:errorStream |
|
2425 |
onError:[:stat| |
|
2426 |
status := stat. |
|
2427 |
false |
|
2428 |
]. |
|
2429 |
||
2430 |
cFileName asFilename exists ifTrue:[ |
|
2431 |
ok ifFalse:[ |
|
2432 |
'Compiler [info]: oops - system says it failed - but c-file is there ...' infoPrintCR. |
|
2433 |
ok := true |
|
2434 |
] |
|
2435 |
] ifFalse:[ |
|
2436 |
ok := false |
|
2437 |
]. |
|
2438 |
||
2439 |
ok ifTrue:[ |
|
2440 |
"/ now compile to machine code |
|
2441 |
||
2442 |
command := ccPath , ' ' , cFlags , ' -c ' , cFileName. |
|
435 | 2443 |
"/ 'executing: ' infoPrint. command infoPrintCR. |
411
d4ca24ab1f4c
more control over cc command;
Claus Gittinger <cg@exept.de>
parents:
410
diff
changeset
|
2444 |
|
512 | 2445 |
self activityNotification:'compiling (cc)'. |
2446 |
ok := OperatingSystem |
|
2447 |
executeCommand:command |
|
2448 |
inputFrom:nil |
|
2449 |
outputTo:errorStream |
|
2450 |
errorTo:errorStream |
|
2451 |
onError:[:stat| |
|
2452 |
status := stat. |
|
2453 |
false |
|
2454 |
]. |
|
2455 |
||
2456 |
oFileName asFilename exists ifTrue:[ |
|
2457 |
ok ifFalse:[ |
|
2458 |
'Compiler [info]: system says it failed - but o-file is there ...' infoPrintCR. |
|
2459 |
ok := true |
|
2460 |
] |
|
2461 |
] ifFalse:[ |
|
2462 |
ok := false |
|
2463 |
]. |
|
2464 |
||
2465 |
"for debugging - leave c intermediate" |
|
2466 |
STCKeepCIntermediate == true ifFalse:[ |
|
2467 |
OperatingSystem removeFile:cFileName. |
|
2468 |
]. |
|
2469 |
]. |
|
2470 |
||
2471 |
ok ifFalse:[ |
|
2472 |
(status notNil and:[status couldNotExecute]) ifTrue:[ |
|
2473 |
eMsg := 'oops, no STC - cannot create machine code' |
|
2474 |
] ifFalse:[ |
|
2475 |
errorStream := 'errorOutput' asFilename readStream. |
|
2476 |
errorStream notNil ifTrue:[ |
|
2477 |
errorMessages := errorStream contents. |
|
2478 |
errorMessages notNil ifTrue:[ |
|
2479 |
errorMessages := errorMessages asStringCollection. |
|
2480 |
errorMessages size > 20 ifTrue:[ |
|
2481 |
errorMessages := (errorMessages copyTo:20) copyWith:'... more messages skipped' |
|
2482 |
]. |
|
407 | 2483 |
"/ errorMessages := errorMessages collect:[:line | |
2484 |
"/ (line startsWith:(stFileName , ':')) ifTrue:[ |
|
2485 |
"/ 'Line: ' , (line copyFrom:(stFileName size + 2)) |
|
2486 |
"/ ] ifFalse:[ |
|
2487 |
"/ line |
|
2488 |
"/ ] |
|
2489 |
"/ ]. |
|
512 | 2490 |
errorMessages := errorMessages asString |
2491 |
]. |
|
2492 |
]. |
|
2493 |
errorMessages isNil ifTrue:[ |
|
2494 |
errorMessages := '' |
|
2495 |
]. |
|
2496 |
errorMessages isEmpty ifTrue:[ |
|
2497 |
eMsg := 'STC / CC error during compilation:\\unspecified error' |
|
2498 |
] ifFalse:[ |
|
2499 |
eMsg := 'STC / CC error during compilation:\\',errorMessages |
|
2500 |
]. |
|
2501 |
eMsg := eMsg withCRs |
|
2502 |
]. |
|
2503 |
'errorOutput' asFilename remove. |
|
2504 |
self activityNotification:'compilation failed'. |
|
2505 |
self parseError:eMsg position:1. |
|
2506 |
||
2507 |
OperatingSystem removeFile:oFileName. |
|
2508 |
OperatingSystem removeFile:'errorOutput'. |
|
2509 |
self activityNotification:''. |
|
2510 |
^ #Error |
|
2511 |
]. |
|
2512 |
||
2513 |
self activityNotification:''. |
|
2514 |
OperatingSystem removeFile:'errorOutput'. |
|
2515 |
||
2516 |
(ObjectFileLoader notNil |
|
2517 |
and:[ObjectFileLoader canLoadObjectFiles]) ifFalse:[ |
|
2518 |
self parseError:'no dynamic load configured - cannot load machine code' position:1. |
|
2519 |
OperatingSystem removeFile:cFileName. |
|
2520 |
OperatingSystem removeFile:oFileName. |
|
2521 |
^ #CannotLoad |
|
2522 |
]. |
|
2523 |
||
2524 |
" |
|
2525 |
if required, make a shared or otherwise loadable object file for it |
|
2526 |
" |
|
2527 |
self activityNotification:'linking'. |
|
2528 |
oFileName := ObjectFileLoader createLoadableObjectFor:initName. |
|
2529 |
oFileName isNil ifTrue:[ |
|
2530 |
"/ something went wrong |
|
2531 |
self parseError:(ObjectFileLoader lastError) position:1. |
|
2532 |
^ #CannotLoad |
|
2533 |
]. |
|
2534 |
||
2535 |
oFileName asFilename exists ifFalse:[ |
|
2536 |
OperatingSystem removeFile:oFileName. |
|
2537 |
self parseError:'link failed - cannot create machine code' position:1. |
|
2538 |
^ #CannotLoad |
|
2539 |
]. |
|
2540 |
||
2541 |
" |
|
2542 |
move it into the modules directory |
|
2543 |
" |
|
2544 |
moduleFileName := STCModulePath , '/' , initName , '.' , (oFileName asFilename suffix). |
|
2545 |
oFileName asFilename moveTo:moduleFileName. |
|
2546 |
oFileName := moduleFileName. |
|
2547 |
||
2548 |
" |
|
2549 |
load the objectfile |
|
2550 |
" |
|
2551 |
self activityNotification:'loading'. |
|
2552 |
handle := ObjectFileLoader loadDynamicObject:moduleFileName. |
|
2553 |
handle isNil ifTrue:[ |
|
2554 |
OperatingSystem removeFile:moduleFileName. |
|
2555 |
self parseError:'dynamic load failed - cannot create machine code' position:1. |
|
2556 |
^ #CannotLoad |
|
2557 |
]. |
|
407 | 2558 |
"/ ('handle is ' , handle printString) infoPrintCR. |
2559 |
||
512 | 2560 |
"/ try libs to resolve symbols. |
2561 |
address := ObjectFileLoader getFunction:'__' , initName , '_Init' from:handle. |
|
2562 |
address isNil ifTrue:[ |
|
2563 |
address := ObjectFileLoader getFunction:'_' , initName , '_Init' from:handle. |
|
2564 |
address isNil ifTrue:[ |
|
2565 |
(ObjectFileLoader hasUndefinedSymbolsIn:handle) ifTrue:[ |
|
2566 |
ObjectFileLoader searchedLibraries do:[:libName | |
|
2567 |
(ObjectFileLoader hasUndefinedSymbolsIn:handle) ifTrue:[ |
|
2568 |
Transcript showCR:' ... trying ' , libName , ' to resolve undefined symbols ...'. |
|
2569 |
dummyHandle := Array new:4. |
|
2570 |
dummyHandle := ObjectFileLoader primLoadDynamicObject:libName into:dummyHandle. |
|
2571 |
dummyHandle isNil ifTrue:[ |
|
2572 |
Transcript showCR:' ... load of library ' , libName , ' failed.'. |
|
2573 |
] |
|
2574 |
] |
|
2575 |
]. |
|
2576 |
(ObjectFileLoader hasUndefinedSymbolsIn:handle) isNil ifTrue:[ |
|
2577 |
Transcript showCR:('LOADER: still undefined symbols in ',initName,'.'). |
|
2578 |
]. |
|
2579 |
]. |
|
2580 |
||
2581 |
] |
|
2582 |
]. |
|
2583 |
||
2584 |
address := ObjectFileLoader getFunction:'__' , initName , '_Init' from:handle. |
|
2585 |
address isNil ifTrue:[ |
|
2586 |
address := ObjectFileLoader getFunction:'_' , initName , '_Init' from:handle. |
|
2587 |
address isNil ifTrue:[ |
|
2588 |
(ObjectFileLoader getListOfUndefinedSymbolsFrom:handle) size > 0 ifTrue:[ |
|
2589 |
ObjectFileLoader listUndefinedSymbolsIn:handle. |
|
2590 |
eMsg := 'undefined symbols in primitive code'. |
|
2591 |
] ifFalse:[ |
|
2592 |
eMsg := initName , '_Init() lookup failed' |
|
2593 |
]. |
|
2594 |
||
2595 |
ObjectFileLoader unloadDynamicObject:handle. |
|
2596 |
||
2597 |
OperatingSystem removeFile:moduleFileName. |
|
2598 |
self parseError:(eMsg , ' - cannot create machine code') position:1. |
|
2599 |
^ #CannotLoad |
|
2600 |
] |
|
2601 |
]. |
|
407 | 2602 |
|
2603 |
"/ ('init at ' , address printString) infoPrintCR. |
|
2604 |
||
512 | 2605 |
m := ObjectFileLoader |
2606 |
callInitFunctionAt:address |
|
2607 |
specialInit:true |
|
2608 |
forceOld:true |
|
2609 |
interruptable:false |
|
2610 |
argument:2 |
|
2611 |
identifyAs:handle |
|
2612 |
returnsObject:true. |
|
2613 |
||
2614 |
" |
|
2615 |
did it work ? |
|
2616 |
" |
|
2617 |
newMethod := aClass compiledMethodAt:selector. |
|
2618 |
newMethod notNil ifTrue:[ |
|
2619 |
m ~~ newMethod ifTrue:[ |
|
2620 |
'Compiler [error]: loaded method installed itself elsewhere' errorPrintCR. |
|
2621 |
]. |
|
2622 |
||
2623 |
newMethod source:aString. |
|
2624 |
newMethod package:(Class packageQuerySignal raise). |
|
415 | 2625 |
"/ Project notNil ifTrue:[ |
2626 |
"/ newMethod package:(Project currentPackageName) |
|
2627 |
"/ ]. |
|
407 | 2628 |
|
2629 |
"/ aClass updateRevisionString. |
|
512 | 2630 |
aClass addChangeRecordForMethod:newMethod. |
2631 |
(silent or:[Smalltalk silentLoading == true]) ifFalse:[ |
|
2632 |
Transcript showCR:(' compiled: ', className,' ',selector,' - machine code') |
|
2633 |
]. |
|
2634 |
ObjectMemory flushCaches. |
|
2635 |
||
2636 |
handle method:newMethod. |
|
2637 |
||
2638 |
"/ check for obsolete loaded objects and unload them |
|
2639 |
||
2640 |
ObjectFileLoader loadedObjectHandlesDo:[:anotherHandle | |
|
2641 |
anotherHandle isMethodHandle ifTrue:[ |
|
2642 |
anotherHandle method isNil ifTrue:[ |
|
2643 |
ObjectFileLoader unloadObjectFile:anotherHandle pathName. |
|
2644 |
OperatingSystem removeFile:anotherHandle pathName. |
|
2645 |
] |
|
2646 |
] |
|
2647 |
]. |
|
2648 |
^ newMethod. |
|
2649 |
]. |
|
2650 |
||
2651 |
OperatingSystem removeFile:moduleFileName. |
|
2652 |
self parseError:'dynamic load failed' position:1. |
|
2653 |
^ #CannotLoad |
|
407 | 2654 |
] valueNowOrOnUnwindDo:[ |
512 | 2655 |
STCKeepSTIntermediate ifFalse:[ |
2656 |
OperatingSystem removeFile:stFileName. |
|
2657 |
]. |
|
407 | 2658 |
]. |
49 | 2659 |
|
2660 |
" |
|
2661 |
|m| |
|
2662 |
||
2663 |
Object subclass:#Test |
|
512 | 2664 |
instanceVariableNames:'' |
2665 |
classVariableNames:'' |
|
2666 |
poolDictionaries:'' |
|
2667 |
category:'tests'. |
|
49 | 2668 |
m := ByteCodeCompiler |
512 | 2669 |
compile:'foo ^ ''hello''' |
2670 |
forClass:Test |
|
2671 |
inCategory:'tests' |
|
2672 |
notifying:nil |
|
2673 |
install:false |
|
2674 |
skipIfSame:false. |
|
49 | 2675 |
m inspect |
2676 |
" |
|
2677 |
" |
|
2678 |
|m| |
|
2679 |
||
2680 |
Object subclass:#Test |
|
512 | 2681 |
instanceVariableNames:'' |
2682 |
classVariableNames:'' |
|
2683 |
poolDictionaries:'' |
|
2684 |
category:'tests'. |
|
49 | 2685 |
m := ByteCodeCompiler |
512 | 2686 |
compileToMachineCode:'foo %{ RETURN (_MKSMALLINT(1)); %}' |
2687 |
forClass:Test |
|
2688 |
inCategory:'tests' |
|
2689 |
notifying:nil |
|
2690 |
install:false |
|
2691 |
skipIfSame:false |
|
2692 |
silent:false. |
|
49 | 2693 |
m inspect |
2694 |
" |
|
120 | 2695 |
|
2696 |
"Modified: 14.9.1995 / 22:33:04 / claus" |
|
287
dc42dd240e5c
Use OperatingSystem executeCommand:onError.
Stefan Vogel <sv@exept.de>
parents:
280
diff
changeset
|
2697 |
"Modified: 28.12.1995 / 15:52:48 / stefan" |
510
9f19de0f8f0b
also consult searchedLibs when loading individual methods.
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
2698 |
"Modified: 16.4.1997 / 18:50:54 / cg" |
97 | 2699 |
! |
2700 |
||
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2701 |
createLoadableObjectFor:baseFileName |
287
dc42dd240e5c
Use OperatingSystem executeCommand:onError.
Stefan Vogel <sv@exept.de>
parents:
280
diff
changeset
|
2702 |
|osType oFileName soFileName| |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2703 |
|
287
dc42dd240e5c
Use OperatingSystem executeCommand:onError.
Stefan Vogel <sv@exept.de>
parents:
280
diff
changeset
|
2704 |
osType := OperatingSystem getOSType. |
dc42dd240e5c
Use OperatingSystem executeCommand:onError.
Stefan Vogel <sv@exept.de>
parents:
280
diff
changeset
|
2705 |
osType = 'irix' ifTrue:[ |
512 | 2706 |
" |
2707 |
link it to a shared object |
|
2708 |
" |
|
2709 |
oFileName := './' , baseFileName , '.o'. |
|
2710 |
soFileName := './' , baseFileName , '.so'. |
|
2711 |
OperatingSystem removeFile:soFileName. |
|
2712 |
OperatingSystem executeCommand:'ld -shared -all -o ' , soFileName , ' ' , oFileName. |
|
2713 |
OperatingSystem removeFile:oFileName. |
|
2714 |
^ soFileName. |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2715 |
]. |
287
dc42dd240e5c
Use OperatingSystem executeCommand:onError.
Stefan Vogel <sv@exept.de>
parents:
280
diff
changeset
|
2716 |
osType = 'sys5_4' ifTrue:[ |
512 | 2717 |
" |
2718 |
link it to a shared object |
|
2719 |
" |
|
2720 |
oFileName := './' , baseFileName , '.o'. |
|
2721 |
soFileName := './' , baseFileName , '.so'. |
|
2722 |
OperatingSystem removeFile:soFileName. |
|
2723 |
OperatingSystem executeCommand:'ld -G -o ' , soFileName , ' ' , oFileName. |
|
2724 |
OperatingSystem removeFile:oFileName. |
|
2725 |
^ soFileName. |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2726 |
]. |
287
dc42dd240e5c
Use OperatingSystem executeCommand:onError.
Stefan Vogel <sv@exept.de>
parents:
280
diff
changeset
|
2727 |
osType = 'linux' ifTrue:[ |
512 | 2728 |
" |
2729 |
link it to a shared object |
|
2730 |
" |
|
2731 |
oFileName := './' , baseFileName , '.o'. |
|
2732 |
soFileName := './' , baseFileName , '.so'. |
|
2733 |
OperatingSystem removeFile:soFileName. |
|
2734 |
OperatingSystem executeCommand:'ld -shared -o ' , soFileName , ' ' , oFileName. |
|
2735 |
OperatingSystem removeFile:oFileName. |
|
2736 |
^ soFileName. |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2737 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2738 |
^ oFileName |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2739 |
|
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2740 |
"Created: 3.1.1996 / 16:04:45 / cg" |
287
dc42dd240e5c
Use OperatingSystem executeCommand:onError.
Stefan Vogel <sv@exept.de>
parents:
280
diff
changeset
|
2741 |
"Modified: 14.6.1996 / 11:16:46 / stefan" |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2742 |
! |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2743 |
|
97 | 2744 |
trappingStubMethodFor:aString inCategory:cat |
2745 |
"return a stub method which traps and reports an error whenever |
|
2746 |
called." |
|
2747 |
||
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
287
diff
changeset
|
2748 |
|newMethod| |
97 | 2749 |
|
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
287
diff
changeset
|
2750 |
newMethod := Method new:(litArray size). |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
287
diff
changeset
|
2751 |
litArray notNil ifTrue:[ |
512 | 2752 |
newMethod literals:litArray |
97 | 2753 |
]. |
277
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
2754 |
|
124 | 2755 |
newMethod makeUncompiled. |
97 | 2756 |
newMethod numberOfMethodVars:(self numberOfMethodVars). |
2757 |
newMethod numberOfMethodArgs:(self numberOfMethodArgs). |
|
2758 |
newMethod source:aString. |
|
2759 |
newMethod category:cat. |
|
415 | 2760 |
newMethod package:(Class packageQuerySignal raise). |
2761 |
"/ Project notNil ifTrue:[ |
|
2762 |
"/ newMethod package:(Project currentPackageName) |
|
2763 |
"/ ]. |
|
97 | 2764 |
^ newMethod |
277
0b599e23a936
set resourceFlag if method has a <resource> definition (prepare for fast search)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
2765 |
|
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
287
diff
changeset
|
2766 |
"Modified: 24.6.1996 / 12:28:24 / stefan" |
415 | 2767 |
"Modified: 5.11.1996 / 20:16:16 / cg" |
49 | 2768 |
! ! |
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2769 |
|
372
98da4d230a8d
prepare support for 16-bit lineNumbers
Claus Gittinger <cg@exept.de>
parents:
357
diff
changeset
|
2770 |
!ByteCodeCompiler class methodsFor:'documentation'! |
148 | 2771 |
|
2772 |
version |
|
549 | 2773 |
^ '$Header: /cvs/stx/stx/libcomp/Attic/BCompiler.st,v 1.115 1997-06-25 10:15:41 cg Exp $' |
148 | 2774 |
! ! |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2775 |
ByteCodeCompiler initialize! |