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