author | Claus Gittinger <cg@exept.de> |
Fri, 09 Feb 1996 17:18:09 +0100 | |
changeset 209 | b858b6a6880f |
parent 199 | 1b3b350a3f59 |
child 211 | 1fd13827a2fc |
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 |
||
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
70 |
!ByteCodeCompiler class methodsFor:'initialization'! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
71 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
72 |
initialize |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
73 |
ShareCode := true. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
74 |
KeepSource := true |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
75 |
! ! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
76 |
|
98 | 77 |
!ByteCodeCompiler class methodsFor:'compiling methods'! |
78 |
||
0 | 79 |
compile:methodText forClass:classToCompileFor |
80 |
"compile a source-string for a method in classToCompileFor" |
|
81 |
||
82 |
^ self compile:methodText |
|
45 | 83 |
forClass:classToCompileFor |
84 |
inCategory:'others' |
|
85 |
notifying:nil |
|
86 |
install:true |
|
87 |
skipIfSame:false |
|
88 |
silent:false |
|
0 | 89 |
! |
90 |
||
91 |
compile:aString forClass:aClass inCategory:cat |
|
92 |
"compile a source-string for a method in classToCompileFor. |
|
93 |
The method will get cat as category" |
|
94 |
||
95 |
^ self compile:aString |
|
45 | 96 |
forClass:aClass |
97 |
inCategory:cat |
|
98 |
notifying:nil |
|
99 |
install:true |
|
100 |
skipIfSame:false |
|
101 |
silent:false |
|
0 | 102 |
! |
103 |
||
84 | 104 |
compile:aString forClass:aClass inCategory:cat notifying:requestor |
0 | 105 |
"compile a source-string for a method in classToCompileFor. |
84 | 106 |
errors are forwarded to requestor. |
0 | 107 |
The method will get cat as category" |
108 |
||
109 |
^ self compile:aString |
|
45 | 110 |
forClass:aClass |
111 |
inCategory:cat |
|
84 | 112 |
notifying:requestor |
45 | 113 |
install:true |
114 |
skipIfSame:false |
|
115 |
silent:false |
|
0 | 116 |
! |
117 |
||
141 | 118 |
compile:aString forClass:aClass inCategory:cat notifying:requestor install:install |
119 |
"compile a source-string for a method in classToCompileFor. |
|
120 |
The install-argument controls if the method is to be installed into the |
|
121 |
classes method-dictionary, or just to be compiled and a method object to be returned. |
|
122 |
Errors are forwarded to requestor. The method will get cat as category" |
|
123 |
||
124 |
^ self compile:aString |
|
125 |
forClass:aClass |
|
126 |
inCategory:cat |
|
127 |
notifying:requestor |
|
128 |
install:install |
|
129 |
skipIfSame:false |
|
130 |
silent:false |
|
131 |
! |
|
132 |
||
133 |
compile:aString forClass:aClass inCategory:cat notifying:requestor |
|
134 |
install:install skipIfSame:skipIfSame |
|
135 |
"compile a source-string for a method in classToCompileFor. |
|
136 |
The install-argument controls if the method is to be installed into the |
|
137 |
classes method-dictionary, or just to be compiled and a method object to be returned. |
|
138 |
Errors are forwarded to requestor. The method will get cat as category. |
|
139 |
If skipIsSame is true, and the source is the same as an existing |
|
140 |
methods source, this is a noop (for fast fileIn)." |
|
141 |
||
142 |
^ self compile:aString |
|
143 |
forClass:aClass |
|
144 |
inCategory:cat |
|
145 |
notifying:requestor |
|
146 |
install:install |
|
147 |
skipIfSame:skipIfSame |
|
148 |
silent:false |
|
149 |
! |
|
150 |
||
84 | 151 |
compile:aString forClass:aClass inCategory:cat notifying:requestor |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
152 |
install:install skipIfSame:skipIfSame silent:silent |
20 | 153 |
|
154 |
"the basic workhorse method for compiling: |
|
0 | 155 |
compile a source-string for a method in classToCompileFor. |
84 | 156 |
errors are forwarded to requestor (report on Transcript and return |
157 |
#Error, if requestor is nil). |
|
0 | 158 |
|
20 | 159 |
The new method will get cat as category. |
160 |
If install is true, the method will go into the classes method-table, |
|
161 |
otherwise the method is simply returned (for anonymous methods). |
|
0 | 162 |
If skipIsSame is true, and the source is the same as an existing |
20 | 163 |
methods source, this is a noop (for fast fileIn). |
164 |
The argument, silent controls if errors are to be reported." |
|
0 | 165 |
|
54 | 166 |
|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
|
167 |
sourceFile sourceStream newSource primNr pos sel keptOldCode msg answer| |
0 | 168 |
|
169 |
aString isNil ifTrue:[^ nil]. |
|
54 | 170 |
silencio := silent or:[Smalltalk silentLoading == true]. |
0 | 171 |
|
19 | 172 |
"lazy compilation is EXPERIMENTAL" |
173 |
lazy := (LazyCompilation == true) and:[install]. |
|
174 |
||
0 | 175 |
"create a compiler, let it parse and create the parsetree" |
176 |
||
54 | 177 |
compiler := self for:(ReadStream on:aString) in:aClass. |
84 | 178 |
compiler parseForCode. |
179 |
compiler notifying:requestor. |
|
54 | 180 |
silent ifTrue:[ |
181 |
"/ compiler ignoreErrors. |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
182 |
compiler ignoreWarnings |
54 | 183 |
]. |
0 | 184 |
compiler nextToken. |
185 |
(compiler parseMethodSpec == #Error) ifTrue:[ |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
186 |
compiler parseError:'syntax error in method specification'. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
187 |
tree := #Error |
0 | 188 |
] ifFalse:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
189 |
lazy ifFalse:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
190 |
"check if same source" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
191 |
(skipIfSame and:[(sel := compiler selector) notNil]) ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
192 |
oldMethod := aClass compiledMethodAt:sel. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
193 |
oldMethod notNil ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
194 |
oldMethod source = aString ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
195 |
oldMethod isInvalid ifFalse:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
196 |
silencio ifFalse:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
197 |
Transcript showCr:(' unchanged: ',aClass name,' ',compiler selector) |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
198 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
199 |
" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
200 |
same. however, category may be different |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
201 |
" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
202 |
(cat notNil and:[cat ~= oldMethod category]) ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
203 |
oldMethod category:cat. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
204 |
oldMethod changed:#category. |
191 | 205 |
"/ aClass updateRevisionString. |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
206 |
aClass addChangeRecordForMethodCategory:oldMethod category:cat. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
207 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
208 |
^ oldMethod |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
209 |
] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
210 |
] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
211 |
] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
212 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
213 |
tree := compiler parseMethodBody. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
214 |
compiler tree:tree. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
215 |
] |
0 | 216 |
]. |
217 |
||
218 |
(compiler errorFlag or:[tree == #Error]) ifTrue:[ |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
219 |
compiler showErrorMessageForClass:aClass. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
220 |
^ #Error |
0 | 221 |
]. |
222 |
||
191 | 223 |
sel := compiler selector. |
19 | 224 |
"if no error and also no selector ..." |
90 | 225 |
sel isNil ifTrue:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
226 |
"... it was just a comment or other empty stuff" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
227 |
^ nil |
0 | 228 |
]. |
229 |
||
191 | 230 |
lazy ifFalse:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
231 |
" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
232 |
freak-out support ... |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
233 |
" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
234 |
(compiler hasNonOptionalPrimitiveCode |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
235 |
or:[(compiler hasPrimitiveCode and:[self canCreateMachineCode]) |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
236 |
or:[STCCompilation == #always and:[sel ~~ #doIt]]]) ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
237 |
newMethod := compiler |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
238 |
compileToMachineCode:aString |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
239 |
forClass:aClass |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
240 |
inCategory:cat |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
241 |
notifying:requestor |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
242 |
install:install |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
243 |
skipIfSame:skipIfSame |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
244 |
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
|
245 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
246 |
newMethod == #Error ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
247 |
compiler showErrorMessageForClass:aClass. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
248 |
^ #Error |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
249 |
]. |
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
|
250 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
251 |
(newMethod == #CannotLoad) ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
252 |
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
|
253 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
254 |
keptOldCode := false. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
255 |
install ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
256 |
"/ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
257 |
"/ be very careful with existing methods |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
258 |
"/ (otherwise, you could easily make your system unusable in systems which cannot load) |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
259 |
"/ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
260 |
sel notNil ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
261 |
oldMethod := aClass compiledMethodAt:sel |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
262 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
263 |
(oldMethod notNil and:[oldMethod code ~= newMethod code]) ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
264 |
answer := Dialog |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
265 |
confirm:'installation of binary code is not possible or disabled. |
97 | 266 |
|
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
|
267 |
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
|
268 |
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
|
269 |
|
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
|
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
|
274 |
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
|
275 |
' |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
276 |
yesLabel:'trap code' |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
277 |
noLabel:'keep old'. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
278 |
answer isNil ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
279 |
^ #Error |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
280 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
281 |
answer == false ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
282 |
newMethod code:(oldMethod code). |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
283 |
keptOldCode := true. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
284 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
285 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
286 |
aClass addSelector:sel withMethod:newMethod |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
287 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
288 |
Transcript show:'*** '. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
289 |
sel notNil ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
290 |
Transcript show:(sel ,' ') |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
291 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
292 |
keptOldCode ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
293 |
msg := 'not really compiled - method still shows previous behavior'. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
294 |
] ifFalse:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
295 |
msg := 'not compiled to machine code - created a stub instead.'. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
296 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
297 |
Transcript showCr:msg. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
298 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
299 |
^ newMethod |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
300 |
]. |
19 | 301 |
]. |
302 |
||
54 | 303 |
" |
304 |
EXPERIMENTAL: quick loading |
|
305 |
only create a lazyMethod, which has no byteCode and will |
|
306 |
compile itself when first called. |
|
307 |
" |
|
19 | 308 |
lazy ifTrue:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
309 |
newMethod := LazyMethod new. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
310 |
KeepSource == false ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
311 |
sourceFile := ObjectMemory nameForSources. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
312 |
sourceStream := sourceFile asFilename appendingWriteStream. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
313 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
314 |
sourceStream isNil ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
315 |
newMethod source:aString. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
316 |
] ifFalse:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
317 |
sourceStream setToEnd. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
318 |
pos := sourceStream position. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
319 |
sourceStream nextChunkPut:aString. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
320 |
sourceStream close. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
321 |
newMethod sourceFilename:sourceFile position:pos. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
322 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
323 |
newMethod category:cat. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
324 |
Project notNil ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
325 |
newMethod package:(Project currentPackageName) |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
326 |
]. |
19 | 327 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
328 |
aClass addSelector:sel withLazyMethod:newMethod. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
329 |
^ newMethod |
19 | 330 |
]. |
331 |
||
90 | 332 |
(primNr := compiler primitiveNumber) isNil ifTrue:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
333 |
" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
334 |
produce symbolic code first |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
335 |
" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
336 |
symbolicCodeArray := compiler genSymbolicCode. |
90 | 337 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
338 |
(symbolicCodeArray == #Error) ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
339 |
Transcript show:' '. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
340 |
sel notNil ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
341 |
Transcript show:(sel ,' ') |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
342 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
343 |
Transcript showCr:'translation error'. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
344 |
^ #Error |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
345 |
]. |
0 | 346 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
347 |
" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
348 |
take this, producing bytecode |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
349 |
(someone willin' to make machine code :-) |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
350 |
" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
351 |
((compiler genByteCodeFrom:symbolicCodeArray) == #Error) ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
352 |
Transcript show:' '. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
353 |
sel notNil ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
354 |
Transcript show:(sel ,' ') |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
355 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
356 |
Transcript showCr:'relocation error - must be simplified'. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
357 |
^ #Error |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
358 |
]. |
0 | 359 |
]. |
360 |
||
54 | 361 |
" |
362 |
finally create the new method-object |
|
363 |
" |
|
0 | 364 |
newMethod := Method new. |
365 |
lits := compiler literalArray. |
|
366 |
lits notNil ifTrue:[ |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
367 |
"literals MUST be an array - not just any Collection" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
368 |
lits := Array withAll:lits. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
369 |
newMethod literals:lits |
0 | 370 |
]. |
90 | 371 |
primNr notNil ifTrue:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
372 |
newMethod code:(compiler checkForPrimitiveCode:primNr). |
78 | 373 |
] ifFalse:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
374 |
newMethod byteCode:(compiler code). |
78 | 375 |
]. |
54 | 376 |
newMethod numberOfMethodVars:(compiler numberOfMethodVars). |
377 |
newMethod numberOfMethodArgs:(compiler numberOfMethodArgs). |
|
378 |
newMethod stackSize:(compiler maxStackDepth). |
|
19 | 379 |
|
54 | 380 |
" |
381 |
if there where any corrections, install the updated source |
|
382 |
" |
|
90 | 383 |
(newSource := compiler correctedSource) notNil ifTrue:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
384 |
newMethod source:newSource |
19 | 385 |
] ifFalse:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
386 |
newMethod source:aString. |
19 | 387 |
]. |
0 | 388 |
newMethod category:cat. |
54 | 389 |
Project notNil ifTrue:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
390 |
newMethod package:(Project currentPackageName) |
54 | 391 |
]. |
0 | 392 |
|
393 |
install ifTrue:[ |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
394 |
aClass addSelector:sel withMethod:newMethod |
0 | 395 |
]. |
396 |
||
54 | 397 |
silencio ifFalse:[ |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
398 |
Transcript showCr:(' compiled: ', aClass name,' ', sel) |
0 | 399 |
]. |
400 |
||
401 |
^ newMethod |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
402 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
403 |
"Created: 29.10.1995 / 19:59:36 / cg" |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
404 |
"Modified: 9.2.1996 / 17:10:36 / cg" |
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
405 |
! |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
406 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
407 |
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
|
408 |
"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
|
409 |
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
|
410 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
411 |
^ self compile:methodText |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
412 |
forClass:classToCompileFor |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
413 |
inCategory:'others' |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
414 |
notifying:requestor |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
415 |
install:true |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
416 |
skipIfSame:false |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
417 |
silent:false |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
418 |
! |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
419 |
|
141 | 420 |
compile:textOrStream in:aClass notifying:requestor ifFail:exceptionBlock |
421 |
"name alias for ST-80 compatibility" |
|
422 |
||
423 |
|m| |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
424 |
|
141 | 425 |
m := self |
426 |
compile:textOrStream |
|
427 |
forClass:aClass |
|
428 |
inCategory:'others' |
|
429 |
notifying:requestor |
|
430 |
install:true |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
431 |
skipIfSame:false |
141 | 432 |
silent:false. |
433 |
m == #Error ifTrue:[ |
|
434 |
^ exceptionBlock value |
|
435 |
]. |
|
436 |
^ m |
|
437 |
||
0 | 438 |
! ! |
439 |
||
15 | 440 |
!ByteCodeCompiler class methodsFor:'constants'! |
441 |
||
442 |
byteCodeFor:aSymbol |
|
443 |
"only some exported codes handled here (for BlockNode)" |
|
444 |
||
25 | 445 |
(aSymbol == #retNil) ifTrue:[^ 1]. |
446 |
(aSymbol == #retTrue) ifTrue:[^ 2]. |
|
447 |
(aSymbol == #retFalse) ifTrue:[^ 3]. |
|
448 |
(aSymbol == #ret0) ifTrue:[^ 4]. |
|
449 |
(aSymbol == #retTop) ifTrue:[^ 0]. |
|
450 |
||
15 | 451 |
(aSymbol == #push0) ifTrue:[^120]. |
452 |
(aSymbol == #push1) ifTrue:[^121]. |
|
453 |
(aSymbol == #push2) ifTrue:[^139]. |
|
454 |
(aSymbol == #pushMinus1) ifTrue:[^122]. |
|
455 |
(aSymbol == #pushNil) ifTrue:[^ 10]. |
|
456 |
(aSymbol == #pushTrue) ifTrue:[^ 11]. |
|
457 |
(aSymbol == #pushFalse) ifTrue:[^ 12]. |
|
458 |
(aSymbol == #pushSelf) ifTrue:[^ 15]. |
|
459 |
self error |
|
460 |
! ! |
|
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 |
||
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
785 |
appendEmptyLong |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
786 |
"append an empty long (4 bytes) to the code-Array" |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
787 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
788 |
|idx "{Class: SmallInteger }"| |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
789 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
790 |
idx := codeIndex. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
791 |
codeBytes at:idx put:0. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
792 |
codeBytes at:idx+1 put:0. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
793 |
codeBytes at:idx+2 put:0. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
794 |
codeBytes at:idx+3 put:0. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
795 |
codeIndex := idx + 4 |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
796 |
! |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
797 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
798 |
appendEmptyShort |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
799 |
"append an empty short (2 bytes) to the code-Array" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
800 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
801 |
|idx "{Class: SmallInteger }"| |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
802 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
803 |
idx := codeIndex. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
804 |
codeBytes at:idx put:0. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
805 |
codeBytes at:idx+1 put:0. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
806 |
codeIndex := idx + 2 |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
807 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
808 |
|
0 | 809 |
appendSignedByte:aByte |
810 |
"append a signedbyte (as in jump-offsets) to the code-Array, |
|
811 |
check range and report an error if invalid" |
|
812 |
||
49 | 813 |
|b "{Class: SmallInteger }" |
814 |
idx "{Class: SmallInteger }"| |
|
0 | 815 |
|
49 | 816 |
idx := codeIndex. |
0 | 817 |
b := aByte. |
818 |
(b >= 0) ifTrue:[ |
|
45 | 819 |
(b > 127) ifTrue:[ |
820 |
self error:'jump-range error'. |
|
821 |
errorFlag := #Error |
|
822 |
]. |
|
49 | 823 |
codeBytes at:idx put:b |
0 | 824 |
] ifFalse:[ |
45 | 825 |
(b < -128) ifTrue:[ |
826 |
self error:'jump-range error'. |
|
827 |
errorFlag := #Error |
|
828 |
]. |
|
49 | 829 |
b := 256 + b |
0 | 830 |
]. |
49 | 831 |
codeBytes at:idx put:b. |
832 |
codeIndex := idx + 1 |
|
0 | 833 |
! |
834 |
||
46 | 835 |
appendSignedWord:aWord |
836 |
"append a signed word to the code-Array, |
|
837 |
check range and report an error if invalid" |
|
838 |
||
49 | 839 |
|w "{Class: SmallInteger }"| |
46 | 840 |
|
841 |
w := aWord. |
|
842 |
(w >= 0) ifTrue:[ |
|
843 |
(w > 16r7FFFF) ifTrue:[ |
|
844 |
self error:'word-range error'. |
|
845 |
errorFlag := #Error |
|
846 |
]. |
|
847 |
] ifFalse:[ |
|
848 |
(w < 16r-8000) ifTrue:[ |
|
849 |
self error:'word-range error'. |
|
850 |
errorFlag := #Error |
|
851 |
]. |
|
852 |
w := (16r10000 + w). |
|
853 |
]. |
|
854 |
self appendWord:w |
|
855 |
! |
|
856 |
||
141 | 857 |
appendWord:aWord |
858 |
"append an unsigned word (low-high) to the code-Array, |
|
859 |
checking for word-range (debug-only)" |
|
860 |
||
861 |
|idx "{Class: SmallInteger }"| |
|
862 |
||
863 |
idx := codeIndex. |
|
864 |
(aWord between:0 and:16rFFFF) ifTrue:[ |
|
865 |
codeBytes at:idx put:(aWord bitAnd:16rFF). |
|
866 |
idx := idx + 1. |
|
867 |
codeBytes at:idx put:(aWord bitShift:-8). |
|
868 |
codeIndex := idx + 1 |
|
869 |
] ifFalse:[ |
|
870 |
self error:'word range error'. |
|
871 |
errorFlag := #Error |
|
872 |
] |
|
873 |
! |
|
874 |
||
0 | 875 |
byteCodeFor:aSymbol |
876 |
"given a symbolic instruction, return the corresponding bytecode. |
|
877 |
as a side-effect, leave number of bytes pushed/popped by this instr. |
|
878 |
in stackDelta, and, if the instruction needs extra arguments, leave |
|
879 |
this info in extra" |
|
880 |
||
881 |
"standard bytecodes" |
|
882 |
||
883 |
(aSymbol == #pushNil) ifTrue:[stackDelta := 1. ^ 10]. |
|
884 |
(aSymbol == #pushTrue) ifTrue:[stackDelta := 1. ^ 11]. |
|
885 |
(aSymbol == #pushFalse) ifTrue:[stackDelta := 1. ^ 12]. |
|
886 |
(aSymbol == #pushLit) ifTrue:[stackDelta := 1. extra := #lit. ^ 14]. |
|
105 | 887 |
(aSymbol == #pushLitS) ifTrue:[stackDelta := 1. extra := #index. ^ 14]. |
0 | 888 |
(aSymbol == #pushSelf) ifTrue:[stackDelta := 1. ^ 15]. |
889 |
(aSymbol == #pushNum) ifTrue:[stackDelta := 1. extra := #number. ^ 16]. |
|
890 |
||
891 |
(aSymbol == #pushMethodArg) ifTrue:[stackDelta := 1. extra := #index. ^ 30]. |
|
892 |
(aSymbol == #pushMethodVar) ifTrue:[stackDelta := 1. extra := #index. ^ 31]. |
|
893 |
(aSymbol == #pushBlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 32]. |
|
894 |
(aSymbol == #pushBlockVar) ifTrue:[stackDelta := 1. extra := #index. ^ 33]. |
|
895 |
(aSymbol == #pushInstVar) ifTrue:[stackDelta := 1. extra := #index. ^ 34]. |
|
1 | 896 |
(aSymbol == #pushOuterBlockArg) ifTrue:[stackDelta := 1. extra := #indexLevel. ^ 42]. |
897 |
(aSymbol == #pushOuterBlockVar) ifTrue:[stackDelta := 1. extra := #indexLevel. ^ 128]. |
|
0 | 898 |
|
899 |
(aSymbol == #retTop) ifTrue:[stackDelta := -1. ^ 0]. |
|
900 |
(aSymbol == #retSelf) ifTrue:[^5]. |
|
901 |
||
902 |
(aSymbol == #==) ifTrue:[stackDelta := -1. self addLiteral:aSymbol. ^ 45]. |
|
903 |
(aSymbol == #~~) ifTrue:[stackDelta := -1. self addLiteral:aSymbol. ^ 46]. |
|
904 |
||
905 |
(aSymbol == #falseJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 50]. |
|
906 |
(aSymbol == #trueJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 51]. |
|
907 |
(aSymbol == #nilJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 52]. |
|
908 |
(aSymbol == #notNilJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 53]. |
|
909 |
(aSymbol == #jump) ifTrue:[extra := #offset. ^ 54]. |
|
1 | 910 |
(aSymbol == #makeBlock) ifTrue:[stackDelta := 1. extra := #offsetNvarNarg. ^ 55]. |
0 | 911 |
(aSymbol == #zeroJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 56]. |
912 |
(aSymbol == #notZeroJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 57]. |
|
913 |
(aSymbol == #eqJump) ifTrue:[stackDelta := -2. extra := #offset. ^ 58]. |
|
914 |
(aSymbol == #notEqJump) ifTrue:[stackDelta := -2. extra := #offset. ^ 59]. |
|
915 |
||
54 | 916 |
(aSymbol == #lineno) ifTrue:[lineno := true. ^ 8]. |
917 |
||
106 | 918 |
(aSymbol == #send) ifTrue:[lineno := true. extra := #special. ^ 19]. |
919 |
(aSymbol == #superSend) ifTrue:[lineno := true. extra := #special. ^ 20]. |
|
920 |
(aSymbol == #hereSend) ifTrue:[lineno := true. extra := #special. ^ 20]. |
|
117 | 921 |
(aSymbol == #sendSelf) ifTrue:[lineno := true. extra := #special. ^ 13]. |
0 | 922 |
|
923 |
(aSymbol == #drop) ifTrue:[stackDelta := -1. ^ 18]. |
|
924 |
(aSymbol == #dup) ifTrue:[stackDelta := 1. ^ 47]. |
|
925 |
||
117 | 926 |
(aSymbol == #storeMethodVar) ifTrue:[extra := #index. stackDelta := -1. ^ 37]. |
927 |
(aSymbol == #storeBlockVar) ifTrue:[extra := #index. stackDelta := -1. ^ 38]. |
|
928 |
(aSymbol == #storeInstVar) ifTrue:[extra := #index. stackDelta := -1. ^ 39]. |
|
0 | 929 |
|
117 | 930 |
(aSymbol == #pushClassVarS) ifTrue:[stackDelta := 1. extra := #speciallitS. ^ 35]. |
931 |
(aSymbol == #pushGlobalS) ifTrue:[stackDelta := 1. extra := #speciallitS. ^ 35]. |
|
932 |
||
933 |
(aSymbol == #storeClassVarS) ifTrue:[extra := #speciallitS.stackDelta := -1. ^ 40]. |
|
934 |
(aSymbol == #storeGlobalS) ifTrue:[extra := #speciallitS. stackDelta := -1. ^ 40]. |
|
935 |
||
1 | 936 |
(aSymbol == #storeOuterBlockVar) ifTrue:[stackDelta := -1. extra := #indexLevel. ^ 129]. |
0 | 937 |
|
117 | 938 |
(aSymbol == #pushClassInstVar) ifTrue:[stackDelta := 1. extra := #index. ^ 176]. |
939 |
(aSymbol == #storeClassInstVar) ifTrue:[extra := #index.stackDelta := -1. ^ 177]. |
|
105 | 940 |
|
0 | 941 |
"optimized bytecodes" |
942 |
||
943 |
(aSymbol == #retNil) ifTrue:[^ 1]. |
|
944 |
(aSymbol == #retTrue) ifTrue:[^ 2]. |
|
945 |
(aSymbol == #retFalse) ifTrue:[^ 3]. |
|
946 |
(aSymbol == #ret0) ifTrue:[^ 4]. |
|
947 |
(aSymbol == #retNum) ifTrue:[extra := #number. ^ 127]. |
|
25 | 948 |
(aSymbol == #homeRetTop) ifTrue:[^ 7]. |
0 | 949 |
|
46 | 950 |
(aSymbol == #pushNum16) ifTrue:[stackDelta := 1. extra := #number16. ^ 17]. |
0 | 951 |
(aSymbol == #push0) ifTrue:[stackDelta := 1. ^120]. |
952 |
(aSymbol == #push1) ifTrue:[stackDelta := 1. ^121]. |
|
3 | 953 |
(aSymbol == #push2) ifTrue:[stackDelta := 1. ^139]. |
0 | 954 |
(aSymbol == #pushMinus1) ifTrue:[stackDelta := 1. ^122]. |
955 |
||
106 | 956 |
(aSymbol == #send0) ifTrue:[lineno := true. extra := #index. ^21]. |
957 |
(aSymbol == #send1) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^22]. |
|
958 |
(aSymbol == #send2) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^23]. |
|
959 |
(aSymbol == #send3) ifTrue:[lineno := true. extra := #index. stackDelta := -3. ^24]. |
|
0 | 960 |
|
106 | 961 |
(aSymbol == #sendSelf0) ifTrue:[lineno := true. extra := #index. stackDelta := 1. ^180]. |
962 |
(aSymbol == #sendSelf1) ifTrue:[lineno := true. extra := #index. ^181]. |
|
963 |
(aSymbol == #sendSelf2) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^182]. |
|
964 |
(aSymbol == #sendSelf3) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^183]. |
|
965 |
(aSymbol == #sendSelfDrop0) ifTrue:[lineno := true. extra := #index. ^184]. |
|
966 |
(aSymbol == #sendSelfDrop1) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^185]. |
|
967 |
(aSymbol == #sendSelfDrop2) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^186]. |
|
968 |
(aSymbol == #sendSelfDrop3) ifTrue:[lineno := true. extra := #index. stackDelta := -3. ^187]. |
|
0 | 969 |
|
106 | 970 |
(aSymbol == #sendDrop) ifTrue:[lineno := true. extra := #special. ^25]. |
971 |
(aSymbol == #sendDrop0) ifTrue:[lineno := true. extra := #index. stackDelta := -1. ^26]. |
|
972 |
(aSymbol == #sendDrop1) ifTrue:[lineno := true. extra := #index. stackDelta := -2. ^27]. |
|
973 |
(aSymbol == #sendDrop2) ifTrue:[lineno := true. extra := #index. stackDelta := -3. ^28]. |
|
974 |
(aSymbol == #sendDrop3) ifTrue:[lineno := true. extra := #index. stackDelta := -4. ^29]. |
|
0 | 975 |
|
976 |
(aSymbol == #pushMethodVar1) ifTrue:[stackDelta := 1. ^80]. |
|
977 |
(aSymbol == #pushMethodVar2) ifTrue:[stackDelta := 1. ^81]. |
|
978 |
(aSymbol == #pushMethodVar3) ifTrue:[stackDelta := 1. ^82]. |
|
979 |
(aSymbol == #pushMethodVar4) ifTrue:[stackDelta := 1. ^83]. |
|
980 |
(aSymbol == #pushMethodVar5) ifTrue:[stackDelta := 1. ^84]. |
|
981 |
(aSymbol == #pushMethodVar6) ifTrue:[stackDelta := 1. ^85]. |
|
982 |
||
983 |
(aSymbol == #pushMethodArg1) ifTrue:[stackDelta := 1. ^86]. |
|
984 |
(aSymbol == #pushMethodArg2) ifTrue:[stackDelta := 1. ^87]. |
|
985 |
(aSymbol == #pushMethodArg3) ifTrue:[stackDelta := 1. ^88]. |
|
986 |
(aSymbol == #pushMethodArg4) ifTrue:[stackDelta := 1. ^89]. |
|
987 |
||
988 |
(aSymbol == #pushInstVar1) ifTrue:[stackDelta := 1. ^90]. |
|
989 |
(aSymbol == #pushInstVar2) ifTrue:[stackDelta := 1. ^91]. |
|
990 |
(aSymbol == #pushInstVar3) ifTrue:[stackDelta := 1. ^92]. |
|
991 |
(aSymbol == #pushInstVar4) ifTrue:[stackDelta := 1. ^93]. |
|
992 |
(aSymbol == #pushInstVar5) ifTrue:[stackDelta := 1. ^94]. |
|
993 |
(aSymbol == #pushInstVar6) ifTrue:[stackDelta := 1. ^95]. |
|
994 |
(aSymbol == #pushInstVar7) ifTrue:[stackDelta := 1. ^96]. |
|
995 |
(aSymbol == #pushInstVar8) ifTrue:[stackDelta := 1. ^97]. |
|
996 |
(aSymbol == #pushInstVar9) ifTrue:[stackDelta := 1. ^98]. |
|
997 |
(aSymbol == #pushInstVar10) ifTrue:[stackDelta := 1. ^99]. |
|
998 |
||
999 |
(aSymbol == #storeMethodVar1) ifTrue:[stackDelta := -1. ^100]. |
|
1000 |
(aSymbol == #storeMethodVar2) ifTrue:[stackDelta := -1. ^101]. |
|
1001 |
(aSymbol == #storeMethodVar3) ifTrue:[stackDelta := -1. ^102]. |
|
1002 |
(aSymbol == #storeMethodVar4) ifTrue:[stackDelta := -1. ^103]. |
|
1003 |
(aSymbol == #storeMethodVar5) ifTrue:[stackDelta := -1. ^104]. |
|
1004 |
(aSymbol == #storeMethodVar6) ifTrue:[stackDelta := -1. ^105]. |
|
1005 |
||
1006 |
(aSymbol == #storeInstVar1) ifTrue:[stackDelta := -1. ^110]. |
|
1007 |
(aSymbol == #storeInstVar2) ifTrue:[stackDelta := -1. ^111]. |
|
1008 |
(aSymbol == #storeInstVar3) ifTrue:[stackDelta := -1. ^112]. |
|
1009 |
(aSymbol == #storeInstVar4) ifTrue:[stackDelta := -1. ^113]. |
|
1010 |
(aSymbol == #storeInstVar5) ifTrue:[stackDelta := -1. ^114]. |
|
1011 |
(aSymbol == #storeInstVar6) ifTrue:[stackDelta := -1. ^115]. |
|
1012 |
(aSymbol == #storeInstVar7) ifTrue:[stackDelta := -1. ^116]. |
|
1013 |
(aSymbol == #storeInstVar8) ifTrue:[stackDelta := -1. ^117]. |
|
1014 |
(aSymbol == #storeInstVar9) ifTrue:[stackDelta := -1. ^118]. |
|
1015 |
(aSymbol == #storeInstVar10) ifTrue:[stackDelta := -1. ^119]. |
|
1016 |
||
103 | 1017 |
(aSymbol == #pushLit1) ifTrue:[stackDelta := 1. ^ 222]. |
1018 |
(aSymbol == #pushLit2) ifTrue:[stackDelta := 1. ^ 223]. |
|
1019 |
(aSymbol == #pushLit3) ifTrue:[stackDelta := 1. ^ 224]. |
|
1020 |
(aSymbol == #pushLit4) ifTrue:[stackDelta := 1. ^ 225]. |
|
1021 |
(aSymbol == #pushLit5) ifTrue:[stackDelta := 1. ^ 226]. |
|
1022 |
(aSymbol == #pushLit6) ifTrue:[stackDelta := 1. ^ 227]. |
|
1023 |
(aSymbol == #pushLit7) ifTrue:[stackDelta := 1. ^ 228]. |
|
1024 |
(aSymbol == #pushLit8) ifTrue:[stackDelta := 1. ^ 229]. |
|
1025 |
||
0 | 1026 |
(aSymbol == #retMethodVar1) ifTrue:[^160]. |
1027 |
(aSymbol == #retMethodVar2) ifTrue:[^161]. |
|
1028 |
(aSymbol == #retMethodVar3) ifTrue:[^162]. |
|
1029 |
(aSymbol == #retMethodVar4) ifTrue:[^163]. |
|
1030 |
(aSymbol == #retMethodVar5) ifTrue:[^164]. |
|
1031 |
(aSymbol == #retMethodVar6) ifTrue:[^165]. |
|
1032 |
||
1033 |
(aSymbol == #retInstVar1) ifTrue:[^166]. |
|
1034 |
(aSymbol == #retInstVar2) ifTrue:[^167]. |
|
1035 |
(aSymbol == #retInstVar3) ifTrue:[^168]. |
|
1036 |
(aSymbol == #retInstVar4) ifTrue:[^169]. |
|
1037 |
(aSymbol == #retInstVar5) ifTrue:[^170]. |
|
1038 |
(aSymbol == #retInstVar6) ifTrue:[^171]. |
|
1039 |
(aSymbol == #retInstVar7) ifTrue:[^172]. |
|
1040 |
(aSymbol == #retInstVar8) ifTrue:[^173]. |
|
1041 |
||
1042 |
(aSymbol == #retMethodArg1) ifTrue:[^174]. |
|
1043 |
(aSymbol == #retMethodArg2) ifTrue:[^175]. |
|
1044 |
||
1045 |
(aSymbol == #pushBlockArg1) ifTrue:[stackDelta := 1. ^140]. |
|
1046 |
(aSymbol == #pushBlockArg2) ifTrue:[stackDelta := 1. ^141]. |
|
1047 |
(aSymbol == #pushBlockArg3) ifTrue:[stackDelta := 1. ^142]. |
|
1048 |
(aSymbol == #pushBlockArg4) ifTrue:[stackDelta := 1. ^143]. |
|
1049 |
||
1 | 1050 |
(aSymbol == #pushOuter1BlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 43]. |
1051 |
(aSymbol == #pushOuter2BlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 44]. |
|
0 | 1052 |
|
5 | 1053 |
(aSymbol == #=) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^130]. |
1054 |
(aSymbol == #+) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^131]. |
|
1055 |
(aSymbol == #~=) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^132]. |
|
1056 |
(aSymbol == #-) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^133]. |
|
108 | 1057 |
(aSymbol == #*) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^230]. |
0 | 1058 |
(aSymbol == #class) ifTrue:[self addLiteral:aSymbol. ^134]. |
5 | 1059 |
(aSymbol == #x) ifTrue:[lineno := true. self addLiteral:aSymbol. ^106]. |
1060 |
(aSymbol == #y) ifTrue:[lineno := true. self addLiteral:aSymbol. ^107]. |
|
1061 |
(aSymbol == #width) ifTrue:[lineno := true. self addLiteral:aSymbol. ^108]. |
|
1062 |
(aSymbol == #height) ifTrue:[lineno := true. self addLiteral:aSymbol. ^109]. |
|
1063 |
(aSymbol == #origin) ifTrue:[lineno := true. self addLiteral:aSymbol. ^154]. |
|
1064 |
(aSymbol == #extent) ifTrue:[lineno := true. self addLiteral:aSymbol. ^155]. |
|
1065 |
(aSymbol == #at:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^135]. |
|
1066 |
(aSymbol == #at:put:)ifTrue:[lineno := true. stackDelta := -2. self addLiteral:aSymbol. ^136]. |
|
1067 |
(aSymbol == #bitAnd:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^137]. |
|
1068 |
(aSymbol == #bitOr:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^138]. |
|
1069 |
(aSymbol == #plus1) ifTrue:[lineno := true. self addLiteral:#+. ^123]. |
|
1070 |
(aSymbol == #minus1) ifTrue:[lineno := true. self addLiteral:#-. ^124]. |
|
0 | 1071 |
|
5 | 1072 |
(aSymbol == #incMethodVar) ifTrue:[lineno := true. self addLiteral:#+. extra := #index. ^125]. |
1073 |
(aSymbol == #decMethodVar) ifTrue:[lineno := true. self addLiteral:#-. extra := #index. ^126]. |
|
0 | 1074 |
|
1075 |
(aSymbol == #eq0) ifTrue:[self addLiteral:#==. ^48]. |
|
1076 |
(aSymbol == #ne0) ifTrue:[self addLiteral:#~~. ^49]. |
|
1077 |
||
5 | 1078 |
(aSymbol == #>) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 145]. |
1079 |
(aSymbol == #>=) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 146]. |
|
1080 |
(aSymbol == #<) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 147]. |
|
1081 |
(aSymbol == #<=) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 148]. |
|
1082 |
(aSymbol == #next) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 149]. |
|
1083 |
(aSymbol == #peek) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 150]. |
|
1084 |
(aSymbol == #value) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 151]. |
|
1085 |
(aSymbol == #value:) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 152]. |
|
6 | 1086 |
(aSymbol == #value:value:) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -2. ^ 178]. |
5 | 1087 |
(aSymbol == #size) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 153]. |
1088 |
(aSymbol == #asInteger) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 158]. |
|
1089 |
(aSymbol == #rounded) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 159]. |
|
0 | 1090 |
(aSymbol == #mk0Block) ifTrue:[^ 156]. |
1091 |
(aSymbol == #mkNilBlock) ifTrue:[^ 157]. |
|
1092 |
||
103 | 1093 |
(aSymbol == #gt0) ifTrue:[lineno := true. self addLiteral:#>. ^ 212]. |
117 | 1094 |
(aSymbol == #pushgt0) ifTrue:[lineno := true. stackDelta := 1. self addLiteral:#>. ^ 208]. |
106 | 1095 |
(aSymbol == #basicNew) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 211]. |
1096 |
(aSymbol == #new) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 213]. |
|
111 | 1097 |
(aSymbol == #basicNew:) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 214]. |
1098 |
(aSymbol == #new:) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 215]. |
|
103 | 1099 |
|
0 | 1100 |
(aSymbol == #falseJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 190]. |
1101 |
(aSymbol == #trueJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 191]. |
|
1102 |
(aSymbol == #nilJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 192]. |
|
1103 |
(aSymbol == #notNilJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 193]. |
|
1104 |
(aSymbol == #jumpabs) ifTrue:[extra := #absoffset. ^ 194]. |
|
1 | 1105 |
(aSymbol == #makeBlockabs) ifTrue:[stackDelta := 1. extra := #absoffsetNvarNarg. ^ 195]. |
0 | 1106 |
(aSymbol == #zeroJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 196]. |
1107 |
(aSymbol == #notZeroJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 197]. |
|
1 | 1108 |
(aSymbol == #eqJumpabs) ifTrue:[stackDelta := -2. extra := #absoffset. ^ 198]. |
1109 |
(aSymbol == #notEqJumpabs) ifTrue:[stackDelta := -2. extra := #absoffset. ^ 199]. |
|
0 | 1110 |
|
1111 |
(aSymbol == #pushThisContext) ifTrue:[stackDelta := 1. ^ 144]. |
|
1112 |
||
76 | 1113 |
(aSymbol == #isNil) ifTrue:[^ 188]. |
1114 |
(aSymbol == #notNil) ifTrue:[^ 189]. |
|
1115 |
(aSymbol == #not) ifTrue:[lineno := true. ^ 179]. |
|
110 | 1116 |
(aSymbol == #&) ifTrue:[lineno := true. ^ 216]. |
1117 |
(aSymbol == #|) ifTrue:[lineno := true. ^ 217]. |
|
76 | 1118 |
|
117 | 1119 |
(aSymbol == #pushClassVarL) ifTrue:[stackDelta := 1. extra := #speciallitL. ^ 218]. |
1120 |
(aSymbol == #pushGlobalL) ifTrue:[stackDelta := 1. extra := #speciallitL. ^ 218]. |
|
1121 |
(aSymbol == #storeClassVarL) ifTrue:[extra := #speciallitL.stackDelta := -1. ^ 219]. |
|
1122 |
(aSymbol == #storeGlobalL) ifTrue:[extra := #speciallitL. stackDelta := -1. ^ 219]. |
|
1123 |
(aSymbol == #pushLitL) ifTrue:[stackDelta := 1. extra := #unsigned16. ^ 201]. |
|
1124 |
||
1125 |
(aSymbol == #sendL) ifTrue:[lineno := true. extra := #specialL. ^ 205]. |
|
1126 |
(aSymbol == #sendSelfL) ifTrue:[lineno := true. extra := #specialL. ^ 207]. |
|
1127 |
(aSymbol == #sendDropL) ifTrue:[lineno := true. extra := #specialL. ^ 204]. |
|
1128 |
(aSymbol == #superSendL) ifTrue:[lineno := true. extra := #specialL. ^ 206]. |
|
1129 |
(aSymbol == #hereSendL) ifTrue:[lineno := true. extra := #specialL. ^ 206]. |
|
106 | 1130 |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1131 |
(aSymbol == #top) ifTrue:[lineno := true. self addLiteral:aSymbol. extra := #specialSend. ^ 231]. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1132 |
(aSymbol == #bottom) ifTrue:[lineno := true. self addLiteral:aSymbol. extra := #specialSend. ^ 231]. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1133 |
(aSymbol == #left) ifTrue:[lineno := true. self addLiteral:aSymbol. extra := #specialSend. ^ 231]. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1134 |
(aSymbol == #right) ifTrue:[lineno := true. self addLiteral:aSymbol. extra := #specialSend. ^ 231]. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1135 |
|
0 | 1136 |
self error:'invalid code symbol'. |
1137 |
errorFlag := #Error |
|
117 | 1138 |
|
1139 |
"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
|
1140 |
! |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1141 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1142 |
checkForCommonCode:symbolicCodeArray |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1143 |
"hook to return the code for common code sequences. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1144 |
Not yet fully implemented - just an idea ..." |
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1145 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1146 |
|sz insn1| |
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1147 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1148 |
(sz := symbolicCodeArray size) == 2 ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1149 |
(insn1 := symbolicCodeArray at:1) == #pushLit1 ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1150 |
(symbolicCodeArray at:2) == #retTop ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1151 |
^ #[222 0] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1152 |
] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1153 |
] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1154 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1155 |
sz == 1 ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1156 |
(insn1 := symbolicCodeArray at:1) == #retSelf ifTrue:[ |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1157 |
^ #[5] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1158 |
] |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1159 |
]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1160 |
^ nil |
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1161 |
! |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1162 |
|
141 | 1163 |
checkForPrimitiveCode:nr |
1164 |
"return the code for an ST-80 primitive method. |
|
1165 |
Since many primitives available on ST-80 should also be available |
|
1166 |
somewhere in ST/X, this may work for many primitive numbers. |
|
1167 |
However, more information is needed and more things to be added below. |
|
1168 |
||
1169 |
This was added to allow emulation of (some) ST-80 |
|
1170 |
primitives (to fileIn RemoteInvocation & Monitor41 packages)" |
|
1171 |
||
1172 |
|cls sel| |
|
1173 |
||
1174 |
(nr == 75) ifTrue:[ cls := Object. sel := #identityHash ]. |
|
1175 |
(nr == 110) ifTrue:[ cls := Object. sel := #== ]. |
|
1176 |
(nr == 111) ifTrue:[ cls := Object. sel := #class ]. |
|
1177 |
" |
|
1178 |
should add more here, to be able to fileIn ST-80 methods |
|
1179 |
containing primitive calls (who gives me the numbers ... ?) |
|
1180 |
" |
|
1181 |
cls notNil ifTrue:[ |
|
1182 |
^ (cls compiledMethodAt:sel) code |
|
1183 |
]. |
|
1184 |
^ nil |
|
1185 |
! |
|
1186 |
||
1187 |
genByteCodeFrom:symbolicCodeArray |
|
1188 |
"convert symbolicCode into bytecodes" |
|
1189 |
||
1190 |
|symIndex "{Class: SmallInteger }" |
|
1191 |
codeSize "{Class: SmallInteger }" |
|
1192 |
symCodeSize "{Class: SmallInteger }" |
|
1193 |
index addr |
|
1194 |
codeSymbol nargs needRetry |
|
1195 |
stackDepth relocInfo level nvars round t| |
|
1196 |
||
1197 |
symbolicCodeArray isNil ifTrue:[^ self]. |
|
1198 |
||
1199 |
round := 0. |
|
1200 |
needRetry := true. |
|
1201 |
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
|
1202 |
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
|
1203 |
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
|
1204 |
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
|
1205 |
^ 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
|
1206 |
]. |
5f5ecdcffc67
share common byteCodes - just an idea and more is needed for most compact code
Claus Gittinger <cg@exept.de>
parents:
191
diff
changeset
|
1207 |
]. |
141 | 1208 |
codeSize := symCodeSize. |
1209 |
||
1210 |
[needRetry] whileTrue:[ |
|
1211 |
stackDepth := 0. |
|
1212 |
maxStackDepth := 0. |
|
1213 |
||
1214 |
codeBytes := ByteArray uninitializedNew:codeSize. |
|
1215 |
relocInfo := Array basicNew:(codeSize + 1). |
|
1216 |
symIndex := 1. |
|
1217 |
codeIndex := 1. |
|
1218 |
||
1219 |
needRetry := false. |
|
1220 |
round := round + 1. |
|
1221 |
||
1222 |
[symIndex <= symCodeSize] whileTrue:[ |
|
1223 |
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
|
1224 |
|
141 | 1225 |
codeSymbol := symbolicCodeArray at:symIndex. |
1226 |
symIndex := symIndex + 1. |
|
1227 |
stackDelta := 0. |
|
1228 |
extra := nil. |
|
1229 |
lineno := false. |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1230 |
|
141 | 1231 |
self appendByteCodeFor:codeSymbol. |
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1232 |
|
141 | 1233 |
lineno ifTrue:[ |
1234 |
self appendByte:((symbolicCodeArray at:symIndex) min:255). |
|
1235 |
symIndex := symIndex + 1 |
|
1236 |
]. |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1237 |
|
141 | 1238 |
extra notNil ifTrue:[ |
1239 |
(extra == #number) ifTrue:[ |
|
1240 |
index := symbolicCodeArray at:symIndex. |
|
1241 |
symIndex := symIndex + 1. |
|
1242 |
self appendSignedByte:index |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1243 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1244 |
] ifFalse:[ (extra == #number16) ifTrue:[ |
141 | 1245 |
index := symbolicCodeArray at:symIndex. |
1246 |
symIndex := symIndex + 2. |
|
1247 |
self appendSignedWord:index |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1248 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1249 |
] ifFalse:[ (extra == #unsigned16) ifTrue:[ |
141 | 1250 |
index := symbolicCodeArray at:symIndex. |
1251 |
symIndex := symIndex + 2. |
|
1252 |
self appendWord:index |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1253 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1254 |
] ifFalse:[ (extra == #index) ifTrue:[ |
141 | 1255 |
index := symbolicCodeArray at:symIndex. |
1256 |
symIndex := symIndex + 1. |
|
1257 |
self appendByte:index |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1258 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1259 |
] ifFalse:[ (extra == #lit) ifTrue:[ |
141 | 1260 |
index := self addLiteral:(symbolicCodeArray at:symIndex). |
1261 |
symIndex := symIndex + 1. |
|
1262 |
self appendByte:index |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1263 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1264 |
] ifFalse:[ (extra == #speciallit) ifTrue:[ |
141 | 1265 |
index := self addLiteral:(symbolicCodeArray at:symIndex). |
1266 |
index > 255 ifTrue:[ |
|
1267 |
self parseError:'too many globals (' , |
|
1268 |
(symbolicCodeArray at:symIndex) , |
|
1269 |
' index=' , index printString , |
|
1270 |
') in method - please simplify'. |
|
1271 |
^ #Error |
|
1272 |
]. |
|
1273 |
symIndex := symIndex + 1. |
|
1274 |
self appendByte:index. |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1275 |
self appendEmptyShort. "space for inline-generation" |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1276 |
self appendEmptyLong. "space for inline-address" |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1277 |
symIndex := symIndex + 6 |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1278 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1279 |
] ifFalse:[ (extra == #speciallitS) ifTrue:[ |
141 | 1280 |
index := symbolicCodeArray at:symIndex. |
1281 |
symIndex := symIndex + 1. |
|
1282 |
self appendByte:index. |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1283 |
self appendEmptyShort. "space for inline-generation" |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1284 |
self appendEmptyLong. "space for inline-address" |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1285 |
symIndex := symIndex + 6 |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1286 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1287 |
] ifFalse:[ (extra == #speciallitL) ifTrue:[ |
141 | 1288 |
index := symbolicCodeArray at:symIndex. |
1289 |
symIndex := symIndex + 2. |
|
1290 |
self appendWord:index. |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1291 |
self appendEmptyShort. "space for inline-generation" |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1292 |
self appendEmptyLong. "space for inline-address" |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1293 |
symIndex := symIndex + 6 |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1294 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1295 |
] ifFalse:[ (extra == #offset) ifTrue:[ |
141 | 1296 |
relocInfo at:symIndex put:codeIndex. |
1297 |
self addReloc:symIndex. |
|
1298 |
symIndex := symIndex + 1. |
|
1299 |
self appendByte:0 |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1300 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1301 |
] ifFalse:[ (extra == #indexLevel) ifTrue:[ |
141 | 1302 |
index := symbolicCodeArray at:symIndex. |
1303 |
symIndex := symIndex + 1. |
|
1304 |
self appendByte:index. |
|
1305 |
level := symbolicCodeArray at:symIndex. |
|
1306 |
symIndex := symIndex + 1. |
|
1307 |
self appendByte:level |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1308 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1309 |
] ifFalse:[ (extra == #offsetNvarNarg) ifTrue:[ |
141 | 1310 |
relocInfo at:symIndex put:codeIndex. |
1311 |
self addReloc:symIndex. |
|
1312 |
symIndex := symIndex + 1. |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1313 |
self appendEmptyByte. |
141 | 1314 |
nvars := symbolicCodeArray at:symIndex. |
1315 |
symIndex := symIndex + 1. |
|
1316 |
self appendByte:nvars. |
|
1317 |
level := symbolicCodeArray at:symIndex. |
|
1318 |
symIndex := symIndex + 1. |
|
1319 |
self appendByte:level |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1320 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1321 |
] ifFalse:[ (extra == #absoffset) ifTrue:[ |
141 | 1322 |
relocInfo at:symIndex put:codeIndex. |
1323 |
self addReloc:symIndex. |
|
1324 |
addr := symbolicCodeArray at:symIndex. |
|
1325 |
symIndex := symIndex + 1. |
|
1326 |
self appendByte:(addr bitAnd:16rFF). |
|
1327 |
self appendByte:((addr bitShift:-8) bitAnd:16rFF). |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1328 |
|
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1329 |
] ifFalse:[ (extra == #absoffsetNvarNarg) ifTrue:[ |
141 | 1330 |
relocInfo at:symIndex put:codeIndex. |
1331 |
self addReloc:symIndex. |
|
1332 |
addr := symbolicCodeArray at:symIndex. |
|
1333 |
symIndex := symIndex + 1. |
|
1334 |
self appendByte:(addr bitAnd:16rFF). |
|
1335 |
self appendByte:((addr bitShift:-8) bitAnd:16rFF). |
|
1336 |
nvars := symbolicCodeArray at:symIndex. |
|
1337 |
symIndex := symIndex + 1. |
|
1338 |
self appendByte:nvars. |
|
1339 |
level := symbolicCodeArray at:symIndex. |
|
1340 |
symIndex := symIndex + 1. |
|
1341 |
self appendByte:level |
|
1342 |
||
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1343 |
] ifFalse:[ (extra == #special) ifTrue:[ |
141 | 1344 |
((codeSymbol == #send) |
1345 |
or:[codeSymbol == #sendSelf |
|
1346 |
or:[codeSymbol == #superSend |
|
1347 |
or:[codeSymbol == #hereSend]]]) ifTrue:[ |
|
1348 |
index := symbolicCodeArray at:symIndex. |
|
1349 |
symIndex := symIndex + 1. |
|
1350 |
nargs := symbolicCodeArray at:symIndex. |
|
1351 |
symIndex := symIndex + 1. |
|
1352 |
self appendByte:nargs. |
|
1353 |
self appendByte:index. |
|
1354 |
||
1355 |
(codeSymbol == #superSend |
|
1356 |
or:[codeSymbol == #hereSend]) ifTrue:[ |
|
1357 |
index := symbolicCodeArray at:symIndex. |
|
1358 |
symIndex := symIndex + 1. |
|
1359 |
self appendByte:index |
|
1360 |
]. |
|
1361 |
stackDelta := nargs negated. |
|
1362 |
codeSymbol == #sendSelf ifTrue:[ |
|
1363 |
stackDelta := stackDelta + 1 |
|
1364 |
] |
|
1365 |
] ifFalse:[ |
|
1366 |
(codeSymbol == #sendDrop) ifTrue:[ |
|
1367 |
index := symbolicCodeArray at:symIndex. |
|
1368 |
symIndex := symIndex + 1. |
|
1369 |
nargs := symbolicCodeArray at:symIndex. |
|
1370 |
symIndex := symIndex + 1. |
|
1371 |
self appendByte:nargs. |
|
1372 |
self appendByte:index. |
|
1373 |
stackDelta := (nargs + 1) negated |
|
1374 |
] |
|
1375 |
] |
|
1376 |
||
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1377 |
] ifFalse:[ (extra == #specialL) ifTrue:[ |
141 | 1378 |
((codeSymbol == #sendL) |
1379 |
or:[codeSymbol == #sendSelfL |
|
1380 |
or:[codeSymbol == #superSendL |
|
1381 |
or:[codeSymbol == #hereSendL]]]) ifTrue:[ |
|
1382 |
index := symbolicCodeArray at:symIndex. |
|
1383 |
symIndex := symIndex + 2. |
|
1384 |
nargs := symbolicCodeArray at:symIndex. |
|
1385 |
symIndex := symIndex + 1. |
|
1386 |
self appendByte:nargs. |
|
1387 |
self appendWord:index. |
|
1388 |
(codeSymbol == #superSendL |
|
1389 |
or:[codeSymbol == #hereSendL]) ifTrue:[ |
|
1390 |
index := symbolicCodeArray at:symIndex. |
|
1391 |
symIndex := symIndex + 2. |
|
1392 |
self appendWord:index. |
|
1393 |
]. |
|
1394 |
stackDelta := nargs negated. |
|
1395 |
codeSymbol == #sendSelfL ifTrue:[ |
|
1396 |
stackDelta := stackDelta + 1 |
|
1397 |
] |
|
1398 |
] |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1399 |
] ifFalse:[ (extra == #specialSend) ifTrue:[ |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1400 |
index := symbolicCodeArray at:symIndex. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1401 |
symIndex := symIndex + 1. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1402 |
self appendByte:index. |
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
197
diff
changeset
|
1403 |
]]]]]]]]]]]]]]]] |
141 | 1404 |
]. |
1405 |
||
1406 |
stackDepth := stackDepth + stackDelta. |
|
1407 |
(stackDepth > maxStackDepth) ifTrue:[ |
|
1408 |
maxStackDepth := stackDepth |
|
1409 |
] |
|
1410 |
]. |
|
1411 |
relocInfo at:symIndex put:codeIndex. |
|
1412 |
||
1413 |
needRetry ifFalse:[ |
|
1414 |
" |
|
1415 |
now relocate - returns true if ok, false if we have to do it again |
|
1416 |
(when short jumps have been changed to long jumps) |
|
1417 |
" |
|
1418 |
relocList notNil ifTrue:[ |
|
1419 |
needRetry := (self relocateWith:symbolicCodeArray relocInfo:relocInfo) not. |
|
1420 |
" |
|
1421 |
if returned with false, a relative jump was made into |
|
1422 |
an absolute jump - need to start over with one more byte space |
|
1423 |
" |
|
1424 |
needRetry ifTrue:[ |
|
1425 |
relocList := nil. |
|
1426 |
codeSize := codeSize + 1. |
|
1427 |
] |
|
1428 |
] |
|
1429 |
] ifTrue:[ |
|
1430 |
'compiling again ...' infoPrintNL. |
|
1431 |
] |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1432 |
]. |
141 | 1433 |
"code printNL." |
1434 |
^ errorFlag |
|
1435 |
||
1436 |
"Modified: 3.9.1995 / 12:59:43 / claus" |
|
1437 |
! |
|
1438 |
||
1439 |
genSymbolicCode |
|
1440 |
"traverse the parse-tree producing symbolicCode - return the codeArray" |
|
1441 |
||
1442 |
|codeStream code thisStatement lastStatement| |
|
1443 |
||
1444 |
litArray := nil. |
|
1445 |
codeStream := WriteStream on:(OrderedCollection new:100). |
|
1446 |
||
1447 |
thisStatement := tree. |
|
1448 |
[thisStatement notNil] whileTrue:[ |
|
1449 |
lastStatement := thisStatement. |
|
1450 |
thisStatement codeForSideEffectOn:codeStream inBlock:nil for:self. |
|
1451 |
thisStatement := thisStatement nextStatement |
|
1452 |
]. |
|
1453 |
(lastStatement isNil or:[lastStatement isReturnNode not]) |
|
1454 |
ifTrue:[ |
|
1455 |
"not a return - add retSelf" |
|
1456 |
" |
|
1457 |
if the last statement was a send for side-effect, |
|
1458 |
replace the previous drop by a retSelf |
|
1459 |
" |
|
1460 |
lastStatement notNil ifTrue:[ |
|
1461 |
((code := codeStream contents) notNil |
|
1462 |
and:[code size > 0 |
|
1463 |
and:[code last == #drop]]) ifTrue:[ |
|
1464 |
codeStream position:(codeStream position - 1). |
|
1465 |
codeStream nextPut:#retSelf |
|
1466 |
] |
|
1467 |
]. |
|
1468 |
codeStream nextPut:#retSelf |
|
1469 |
]. |
|
1470 |
^ codeStream contents |
|
128
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 |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1473 |
hasLineNumber:sel |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1474 |
"return true, if special send code needs lineNr" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1475 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1476 |
(sel == #==) ifTrue:[^ false]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1477 |
(sel == #~~) ifTrue:[^ false]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1478 |
(sel == #class) ifTrue:[^ false]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1479 |
(sel == #isNil) ifTrue:[^ false]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1480 |
(sel == #notNil) ifTrue:[^ false]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1481 |
^ true |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1482 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1483 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1484 |
isBuiltIn1ArgSelector:sel |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1485 |
"return true, if selector sel is built-in. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1486 |
(i.e. there is a single bytecode for it)" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1487 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1488 |
(sel == #at:) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1489 |
(sel == #value:) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1490 |
(sel == #bitAnd:) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1491 |
(sel == #bitOr:) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1492 |
(sel == #new:) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1493 |
(sel == #basicNew:) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1494 |
^ false |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1495 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1496 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1497 |
isBuiltIn2ArgSelector:sel |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1498 |
"return true, if selector sel is built-in. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1499 |
(i.e. there is a single bytecode for it)" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1500 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1501 |
(sel == #at:put:) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1502 |
^ false |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1503 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1504 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1505 |
isBuiltInBinarySelector:sel |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1506 |
sel == #== ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1507 |
sel == #~~ ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1508 |
sel == #= ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1509 |
sel == #~= ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1510 |
sel == #+ ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1511 |
sel == #- ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1512 |
sel == #< ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1513 |
sel == #<= ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1514 |
sel == #> ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1515 |
sel == #>= ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1516 |
sel == #* ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1517 |
sel == #& ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1518 |
sel == #| ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1519 |
^ false |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1520 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1521 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1522 |
isBuiltInUnarySelector:sel |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1523 |
"return true, if unary selector sel is built-in. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1524 |
(i.e. there is a single bytecode for it)" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1525 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1526 |
(sel == #peek) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1527 |
(sel == #value) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1528 |
(sel == #next) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1529 |
(sel == #class) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1530 |
(sel == #size) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1531 |
(sel == #x) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1532 |
(sel == #y) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1533 |
(sel == #width) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1534 |
(sel == #height) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1535 |
(sel == #origin) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1536 |
(sel == #extent) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1537 |
(sel == #asInteger) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1538 |
(sel == #rounded) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1539 |
(sel == #isNil) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1540 |
(sel == #notNil) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1541 |
(sel == #not) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1542 |
(sel == #new) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1543 |
(sel == #basicNew) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1544 |
^ false |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1545 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1546 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1547 |
isSpecialSendSelector:sel |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1548 |
"return true, if unary selector sel is a special selector" |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1549 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1550 |
(sel == #top) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1551 |
(sel == #bottom) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1552 |
(sel == #left) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1553 |
(sel == #right) ifTrue:[^ true]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1554 |
^ false |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1555 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1556 |
|
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1557 |
moveGlobalsToFront |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1558 |
"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
|
1559 |
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
|
1560 |
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
|
1561 |
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
|
1562 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1563 |
litArray isNil ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1564 |
^ 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
|
1565 |
]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1566 |
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
|
1567 |
(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
|
1568 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1569 |
(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
|
1570 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1571 |
(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
|
1572 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1573 |
(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
|
1574 |
ifTrue:[a < b]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1575 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1576 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1577 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1578 |
]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1579 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1580 |
" |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1581 |
#(#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
|
1582 |
sort:[:a :b | |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1583 |
(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
|
1584 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1585 |
(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
|
1586 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1587 |
(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
|
1588 |
ifTrue:[ |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1589 |
(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
|
1590 |
ifTrue:[(a < b)]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1591 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1592 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1593 |
] |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1594 |
]. |
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1595 |
|
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
1596 |
" |
141 | 1597 |
! |
1598 |
||
1599 |
relocateWith:symbolicCodeArray relocInfo:relocInfo |
|
1600 |
"helper for genByteCodeFrom - relocate code using relocInfo. |
|
1601 |
if relocation fails badly (due to long relative jumps) patch |
|
1602 |
symbolicCode to use absolute jumps instead and return false |
|
1603 |
(genByteCodeFrom will then try again). Otherwise return true. |
|
1604 |
Also, on the fly, jumps to jumps and jumps to return are handled." |
|
1605 |
||
1606 |
|delta "{Class: SmallInteger }" |
|
1607 |
codePos "{Class: SmallInteger }" |
|
1608 |
opCodePos "{Class: SmallInteger }" |
|
1609 |
codeOffset "{Class: SmallInteger }" |
|
1610 |
symOffset |
|
1611 |
opcode "{Class: SmallInteger }" |
|
1612 |
dstOpcode jumpTarget |
|
1613 |
jumpCode deleteSet| |
|
1614 |
||
1615 |
deleteSet := OrderedCollection new. |
|
1616 |
relocList do:[:sIndex | |
|
1617 |
"have to relocate symCode at sIndex ..." |
|
1618 |
symOffset := symbolicCodeArray at:sIndex. "the target in the symbolic code" |
|
1619 |
codePos := relocInfo at:sIndex. "position of the offet in byte code" |
|
1620 |
codeOffset := relocInfo at:symOffset. "position of the target in byte code" |
|
1621 |
delta := codeOffset - codePos - 1. |
|
1622 |
opCodePos := codePos - 1. |
|
1623 |
opcode := codeBytes at:opCodePos. |
|
1624 |
||
1625 |
(opcode between:190 and:199) ifTrue:[ |
|
1626 |
"an absolute jump/makeBlock" |
|
1627 |
||
1628 |
codeBytes at:codePos put:(codeOffset bitAnd:16rFF). |
|
1629 |
codeBytes at:(codePos + 1) put:(codeOffset bitShift:-8) |
|
1630 |
] ifFalse:[ |
|
1631 |
"get jump-code from long and vlong codes" |
|
1632 |
(opcode between:50 and:59) ifFalse:[ |
|
1633 |
(opcode between:60 and:69) ifTrue:[ |
|
1634 |
opcode := opcode - 10 |
|
1635 |
] ifFalse:[ |
|
1636 |
(opcode between:70 and:79) ifTrue:[ |
|
1637 |
opcode := opcode - 20 |
|
1638 |
] ifFalse:[ |
|
1639 |
self error:'invalid code to relocate' |
|
1640 |
] |
|
1641 |
]. |
|
1642 |
]. |
|
1643 |
||
1644 |
"optimize jump to return and jump to jump" |
|
1645 |
||
1646 |
(opcode == 54) ifTrue:[ |
|
1647 |
"a jump" |
|
1648 |
dstOpcode := symbolicCodeArray at:symOffset. |
|
1649 |
||
1650 |
(#(retSelf retTop retNil retTrue retFalse ret0 "blockRetTop") includes:dstOpcode) ifTrue:[ |
|
1651 |
"a jump to a return - put in the return instead jump" |
|
1652 |
||
1653 |
symbolicCodeArray at:(sIndex - 1) put:dstOpcode. |
|
1654 |
symbolicCodeArray at:sIndex put:dstOpcode. |
|
1655 |
codeBytes at:opCodePos put:(self byteCodeFor:dstOpcode). |
|
1656 |
delta := 0. |
|
1657 |
deleteSet add:sIndex. |
|
1658 |
||
1659 |
" |
|
1660 |
'jump to return at: ' print. (sIndex - 1) printNL. |
|
1661 |
" |
|
1662 |
] ifFalse:[ |
|
1663 |
(dstOpcode == #jump) ifTrue:[ |
|
1664 |
"jump to jump to be done soon" |
|
1665 |
jumpTarget := symbolicCodeArray at:(symOffset + 1). |
|
1666 |
" |
|
1667 |
'jump to jump at: ' print. (sIndex - 1) print. |
|
1668 |
' newTarget:' print. jumpTarget printNL. |
|
1669 |
" |
|
1670 |
||
1671 |
symbolicCodeArray at:sIndex put:jumpTarget. |
|
1672 |
symOffset := jumpTarget. |
|
1673 |
codeOffset := relocInfo at:symOffset. |
|
1674 |
delta := codeOffset - codePos - 1. |
|
1675 |
||
1676 |
"continue with new delta" |
|
1677 |
] |
|
1678 |
] |
|
1679 |
]. |
|
1680 |
(#(50 51 52 53 56 57 58 59) includes:opcode) ifTrue:[ |
|
1681 |
"a conditional jump" |
|
1682 |
||
1683 |
dstOpcode := symbolicCodeArray at:symOffset. |
|
1684 |
(dstOpcode == #jump) ifTrue:[ |
|
1685 |
"conditional jump to unconditional jump" |
|
1686 |
jumpTarget := symbolicCodeArray at:(symOffset + 1). |
|
1687 |
" |
|
1688 |
'cond jump to jump at: ' print. (sIndex - 1) print. |
|
1689 |
' newTarget:' print. jumpTarget printNL. |
|
1690 |
" |
|
1691 |
||
1692 |
symbolicCodeArray at:sIndex put:jumpTarget. |
|
1693 |
symOffset := jumpTarget. |
|
1694 |
codeOffset := relocInfo at:symOffset. |
|
1695 |
delta := codeOffset - codePos - 1. |
|
1696 |
||
1697 |
"continue with new delta" |
|
1698 |
]. |
|
1699 |
]. |
|
1700 |
||
1701 |
(delta >= 0) ifTrue:[ |
|
1702 |
(delta > 127) ifTrue:[ |
|
1703 |
(opcode between:50 and:59) ifFalse:[ |
|
1704 |
self error:'invalid code to relocate' |
|
1705 |
] ifTrue:[ |
|
1706 |
(delta > 255) ifTrue:[ |
|
1707 |
"change jmp into vljmp ..." |
|
1708 |
codeBytes at:opCodePos put:(opcode + 20). |
|
1709 |
delta := delta - 256 |
|
1710 |
] ifFalse:[ |
|
1711 |
"change jmp into ljmp ..." |
|
1712 |
codeBytes at:opCodePos put:(opcode + 10). |
|
1713 |
delta := delta - 128 |
|
1714 |
]. |
|
1715 |
(delta > 127) ifTrue:[ |
|
1716 |
"change symbolic into a jump absolute and fail" |
|
1717 |
jumpCode := symbolicCodeArray at:(sIndex - 1). |
|
1718 |
symbolicCodeArray at:(sIndex - 1) put:(self absJumpFromJump:jumpCode). |
|
1719 |
symbolicCodeArray at:sIndex put:symOffset. |
|
1720 |
" |
|
1721 |
'change short into abs jump' printNL. |
|
1722 |
" |
|
1723 |
deleteSet do:[:d | relocList remove:d]. |
|
1724 |
^ false |
|
1725 |
] |
|
1726 |
]. |
|
1727 |
]. |
|
1728 |
codeBytes at:codePos put:delta |
|
1729 |
] ifFalse:[ |
|
1730 |
(delta < -128) ifTrue:[ |
|
1731 |
(opcode between:50 and:59) ifFalse:[ |
|
1732 |
self error:'invalid code to relocate' |
|
1733 |
] ifTrue:[ |
|
1734 |
(delta < -256) ifTrue:[ |
|
1735 |
"change jmp into vljmp ..." |
|
1736 |
codeBytes at:opCodePos put:(opcode + 20). |
|
1737 |
delta := delta + 256 |
|
1738 |
] ifFalse:[ |
|
1739 |
"change jmp into ljmp ..." |
|
1740 |
codeBytes at:opCodePos put:(opcode + 10). |
|
1741 |
delta := delta + 128 |
|
1742 |
]. |
|
1743 |
(delta < -128) ifTrue:[ |
|
1744 |
"change symbolic into a jump absolute and fail" |
|
1745 |
jumpCode := symbolicCodeArray at:(sIndex - 1). |
|
1746 |
symbolicCodeArray at:(sIndex - 1) put:(self absJumpFromJump:jumpCode). |
|
1747 |
symbolicCodeArray at:sIndex put:symOffset. |
|
1748 |
" |
|
1749 |
'change short into abs jump' printNL. |
|
1750 |
" |
|
1751 |
deleteSet do:[:d | relocList remove:d]. |
|
1752 |
^ false |
|
1753 |
] |
|
1754 |
] |
|
1755 |
]. |
|
1756 |
codeBytes at:codePos put:(256 + delta) |
|
1757 |
] |
|
1758 |
] |
|
1759 |
]. |
|
1760 |
(errorFlag == #Error) ifTrue:[ |
|
1761 |
self error:'relocation range error' |
|
1762 |
]. |
|
1763 |
^ true |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1764 |
! |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1765 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1766 |
specialSendCodeFor:aSymbol |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1767 |
aSymbol == #top ifTrue:[^ 0]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1768 |
aSymbol == #bottom ifTrue:[^ 1]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1769 |
aSymbol == #left ifTrue:[^ 2]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1770 |
aSymbol == #right ifTrue:[^ 3]. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1771 |
|
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1772 |
self error:'invalid special send symbol'. |
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1773 |
errorFlag := #Error |
0 | 1774 |
! ! |
49 | 1775 |
|
1776 |
!ByteCodeCompiler methodsFor:'machine code generation'! |
|
1777 |
||
1778 |
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
|
1779 |
notifying:requestor install:install skipIfSame:skipIfSame silent:silent |
49 | 1780 |
"this is called to compile primitive code. |
1781 |
This is EXPERIMENTAL and going to be changed to raise an error, |
|
1782 |
an redefined in subclasses which can do it (either by direct compilation, or by calling |
|
1783 |
the external stc do do it. |
|
1784 |
For a description of the arguments, see compile:forClass....." |
|
1785 |
||
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1786 |
|stFileName stream handle address flags command oFileName |
120 | 1787 |
initName newMethod ok status className sep class stcPath |
156 | 1788 |
errorStream errorMessages eMsg m| |
96 | 1789 |
|
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
|
1790 |
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
|
1791 |
STCCompilation == #never ifTrue:[^ #CannotLoad]. |
120 | 1792 |
(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
|
1793 |
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
|
1794 |
^ #CannotLoad |
120 | 1795 |
]. |
54 | 1796 |
|
1797 |
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
|
1798 |
SequenceNumber := 0. |
54 | 1799 |
]. |
1800 |
SequenceNumber := SequenceNumber + 1. |
|
49 | 1801 |
|
54 | 1802 |
initName := 'ttt' , SequenceNumber printString. |
1803 |
stFileName := initName , '.st'. |
|
1804 |
stream := stFileName asFilename writeStream. |
|
187 | 1805 |
stream isNil ifTrue:[ |
1806 |
self parseError:'cannot create temporary sourcefile for compilation'. |
|
1807 |
^ #CannotLoad |
|
1808 |
]. |
|
97 | 1809 |
sep := stream class chunkSeparator. |
49 | 1810 |
|
101 | 1811 |
class := aClass. |
1812 |
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
|
1813 |
class := aClass soleInstance |
101 | 1814 |
]. |
1815 |
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
|
1816 |
cls ~~ Object ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1817 |
cls isLoaded ifFalse:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1818 |
^ #CannotLoad |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1819 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1820 |
cls fileOutDefinitionOn:stream. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1821 |
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
|
1822 |
] |
54 | 1823 |
]. |
101 | 1824 |
class fileOutDefinitionOn:stream. |
96 | 1825 |
stream nextPut:sep; cr. |
54 | 1826 |
|
101 | 1827 |
class fileOutPrimitiveDefinitionsOn:stream. |
49 | 1828 |
|
96 | 1829 |
stream nextPut:sep. |
1830 |
className := aClass name. |
|
1831 |
||
49 | 1832 |
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
|
1833 |
stream nextPutAll:(className copyTo:(className size - 5)); nextPutAll:' class'. |
49 | 1834 |
] ifFalse:[ |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1835 |
stream nextPutAll:className. |
49 | 1836 |
]. |
96 | 1837 |
stream nextPutAll:' methodsFor:'''; nextPutAll:cat; nextPutAll:''''. |
1838 |
stream nextPut:sep. |
|
49 | 1839 |
stream cr. |
1840 |
||
125 | 1841 |
stream nextPutAll:'"{ Line: 0 }"'; cr; nextPutAll:aString. |
96 | 1842 |
stream nextPut:sep; space; nextPut:sep. |
1843 |
||
49 | 1844 |
stream close. |
1845 |
||
1846 |
" |
|
1847 |
call stc to compile it |
|
1848 |
" |
|
94 | 1849 |
oFileName := './' , initName , '.o'. |
1850 |
oFileName asFilename delete. |
|
49 | 1851 |
|
150 | 1852 |
flags := '-commonSymbols +sharedLibCode +newIncremental -E:errorOutput -N' , initName . |
124 | 1853 |
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
|
1854 |
flags := STCCompilationDefines , ' ' , flags |
124 | 1855 |
]. |
1856 |
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
|
1857 |
flags := STCCompilationIncludes , ' ' , flags |
124 | 1858 |
]. |
1859 |
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
|
1860 |
flags := STCCompilationOptions , ' ' , flags |
54 | 1861 |
]. |
1862 |
||
101 | 1863 |
command := stcPath , ' ' , flags , ' -c ' , stFileName. |
54 | 1864 |
"/ command printNL. |
1865 |
||
120 | 1866 |
ok := OperatingSystem executeCommand:command. |
1867 |
status := OperatingSystem lastExecStatus. |
|
101 | 1868 |
|
120 | 1869 |
"for debugging - leave c intermediate" |
1870 |
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
|
1871 |
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
|
1872 |
'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
|
1873 |
OperatingSystem executeCommand:command |
49 | 1874 |
]. |
1875 |
||
94 | 1876 |
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
|
1877 |
ok ifFalse:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1878 |
'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
|
1879 |
ok := true |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1880 |
] |
94 | 1881 |
] ifFalse:[ |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1882 |
ok := false |
94 | 1883 |
]. |
1884 |
||
54 | 1885 |
ok ifFalse:[ |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1886 |
status >= 16r200 ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1887 |
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
|
1888 |
errorStream notNil ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1889 |
errorMessages := errorStream contents. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1890 |
errorMessages notNil ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1891 |
errorMessages := errorMessages asStringCollection. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1892 |
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
|
1893 |
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
|
1894 |
]. |
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
|
1895 |
"/ 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
|
1896 |
"/ (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
|
1897 |
"/ '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
|
1898 |
"/ ] 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
|
1899 |
"/ 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
|
1900 |
"/ ] |
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
|
1901 |
"/ ]. |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1902 |
errorMessages := errorMessages asString |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1903 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1904 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1905 |
errorMessages isNil ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1906 |
errorMessages := '' |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1907 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1908 |
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
|
1909 |
] ifFalse:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1910 |
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
|
1911 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1912 |
'errorOutput' asFilename remove. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1913 |
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
|
1914 |
OperatingSystem removeFile:stFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1915 |
^ #Error |
120 | 1916 |
]. |
1917 |
||
1918 |
(ObjectFileLoader notNil |
|
1919 |
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
|
1920 |
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
|
1921 |
OperatingSystem removeFile:stFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1922 |
^ #CannotLoad |
54 | 1923 |
]. |
1924 |
||
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1925 |
oFileName := ObjectFileLoader createLoadableObjectFor:initName. |
49 | 1926 |
|
1927 |
" |
|
1928 |
load the objectfile |
|
1929 |
" |
|
109 | 1930 |
handle := ObjectFileLoader loadDynamicObject:oFileName. |
49 | 1931 |
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
|
1932 |
OperatingSystem removeFile:stFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1933 |
OperatingSystem removeFile:oFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1934 |
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
|
1935 |
^ #CannotLoad |
49 | 1936 |
]. |
174 | 1937 |
"/ ('handle is ' , handle printString) infoPrintNL. |
49 | 1938 |
|
54 | 1939 |
address := ObjectFileLoader getFunction:'__' , initName , '_Init' from:handle. |
49 | 1940 |
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
|
1941 |
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
|
1942 |
address isNil ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1943 |
(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
|
1944 |
ObjectFileLoader listUndefinedSymbolsIn:handle. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1945 |
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
|
1946 |
] ifFalse:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1947 |
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
|
1948 |
]. |
125 | 1949 |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1950 |
ObjectFileLoader unloadDynamicObject:handle. |
125 | 1951 |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1952 |
OperatingSystem removeFile:stFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1953 |
OperatingSystem removeFile:oFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1954 |
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
|
1955 |
^ #CannotLoad |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1956 |
] |
49 | 1957 |
]. |
1958 |
||
174 | 1959 |
"/ ('init at ' , address printString) infoPrintNL. |
54 | 1960 |
|
156 | 1961 |
m := ObjectFileLoader |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1962 |
callInitFunctionAt:address |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1963 |
specialInit:true |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1964 |
forceOld:true |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1965 |
interruptable:false |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1966 |
argument:2 |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1967 |
identifyAs:handle |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1968 |
returnsObject:true. |
49 | 1969 |
|
54 | 1970 |
" |
1971 |
did it work ? |
|
1972 |
" |
|
96 | 1973 |
newMethod := aClass compiledMethodAt:selector. |
54 | 1974 |
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
|
1975 |
m ~~ newMethod ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1976 |
'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
|
1977 |
]. |
156 | 1978 |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1979 |
newMethod source:aString. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1980 |
Project notNil ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1981 |
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
|
1982 |
]. |
160
5e01f0113d6e
dont forget package-info in compiled methods
Claus Gittinger <cg@exept.de>
parents:
156
diff
changeset
|
1983 |
|
162 | 1984 |
"/ aClass updateRevisionString. |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1985 |
aClass addChangeRecordForMethod:newMethod. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1986 |
(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
|
1987 |
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
|
1988 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1989 |
ObjectMemory flushCaches. |
120 | 1990 |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1991 |
OperatingSystem removeFile:stFileName. |
120 | 1992 |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1993 |
handle method:newMethod. |
120 | 1994 |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1995 |
"/ check for obsolete loaded objects and unload them |
120 | 1996 |
|
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1997 |
ObjectFileLoader loadedObjectHandlesDo:[:anotherHandle | |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1998 |
anotherHandle isMethodHandle ifTrue:[ |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
1999 |
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
|
2000 |
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
|
2001 |
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
|
2002 |
] |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2003 |
] |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2004 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2005 |
^ newMethod. |
54 | 2006 |
]. |
2007 |
||
120 | 2008 |
OperatingSystem removeFile:stFileName. |
2009 |
OperatingSystem removeFile:oFileName. |
|
54 | 2010 |
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
|
2011 |
^ #CannotLoad |
49 | 2012 |
|
2013 |
" |
|
2014 |
|m| |
|
2015 |
||
2016 |
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
|
2017 |
instanceVariableNames:'' |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2018 |
classVariableNames:'' |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2019 |
poolDictionaries:'' |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2020 |
category:'tests'. |
49 | 2021 |
m := ByteCodeCompiler |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2022 |
compile:'foo ^ ''hello''' |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2023 |
forClass:Test |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2024 |
inCategory:'tests' |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2025 |
notifying:nil |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2026 |
install:false |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2027 |
skipIfSame:false. |
49 | 2028 |
m inspect |
2029 |
" |
|
2030 |
" |
|
2031 |
|m| |
|
2032 |
||
2033 |
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
|
2034 |
instanceVariableNames:'' |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2035 |
classVariableNames:'' |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2036 |
poolDictionaries:'' |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2037 |
category:'tests'. |
49 | 2038 |
m := ByteCodeCompiler |
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2039 |
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
|
2040 |
forClass:Test |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2041 |
inCategory:'tests' |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2042 |
notifying:nil |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2043 |
install:false |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2044 |
skipIfSame:false |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2045 |
silent:false. |
49 | 2046 |
m inspect |
2047 |
" |
|
120 | 2048 |
|
2049 |
"Modified: 14.9.1995 / 22:33:04 / claus" |
|
174 | 2050 |
"Modified: 17.12.1995 / 16:03:18 / cg" |
97 | 2051 |
! |
2052 |
||
182
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2053 |
createLoadableObjectFor:baseFileName |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2054 |
|oFileName soFileName| |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2055 |
|
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2056 |
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
|
2057 |
" |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2058 |
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
|
2059 |
" |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2060 |
oFileName := './' , baseFileName , '.o'. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2061 |
soFileName := './' , baseFileName , '.so'. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2062 |
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
|
2063 |
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
|
2064 |
OperatingSystem removeFile:oFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2065 |
^ soFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2066 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2067 |
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
|
2068 |
" |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2069 |
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
|
2070 |
" |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2071 |
oFileName := './' , baseFileName , '.o'. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2072 |
soFileName := './' , baseFileName , '.so'. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2073 |
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
|
2074 |
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
|
2075 |
OperatingSystem removeFile:oFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2076 |
^ soFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2077 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2078 |
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
|
2079 |
" |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2080 |
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
|
2081 |
" |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2082 |
oFileName := './' , baseFileName , '.o'. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2083 |
soFileName := './' , baseFileName , '.so'. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2084 |
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
|
2085 |
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
|
2086 |
OperatingSystem removeFile:oFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2087 |
^ soFileName. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2088 |
]. |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2089 |
^ oFileName |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2090 |
|
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2091 |
"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
|
2092 |
! |
b8316f207380
added query for fileFormat; moved link-code from BCompiler to ObjFLoader
Claus Gittinger <cg@exept.de>
parents:
174
diff
changeset
|
2093 |
|
97 | 2094 |
trappingStubMethodFor:aString inCategory:cat |
2095 |
"return a stub method which traps and reports an error whenever |
|
2096 |
called." |
|
2097 |
||
2098 |
|newMethod lits| |
|
2099 |
||
2100 |
newMethod := Method new. |
|
2101 |
lits := self literalArray. |
|
2102 |
lits notNil ifTrue:[ |
|
2103 |
"literals MUST be an array - not just any Collection" |
|
2104 |
lits := Array withAll:lits. |
|
2105 |
newMethod literals:lits |
|
2106 |
]. |
|
124 | 2107 |
newMethod makeUncompiled. |
97 | 2108 |
newMethod numberOfMethodVars:(self numberOfMethodVars). |
2109 |
newMethod numberOfMethodArgs:(self numberOfMethodArgs). |
|
2110 |
newMethod source:aString. |
|
2111 |
newMethod category:cat. |
|
2112 |
Project notNil ifTrue:[ |
|
98 | 2113 |
newMethod package:(Project currentPackageName) |
97 | 2114 |
]. |
2115 |
^ newMethod |
|
49 | 2116 |
! ! |
128
61eb0b356b89
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
2117 |
|
148 | 2118 |
!ByteCodeCompiler class methodsFor:'documentation'! |
2119 |
||
2120 |
version |
|
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2121 |
^ '$Header: /cvs/stx/stx/libcomp/Attic/BCompiler.st,v 1.64 1996-02-09 16:18:09 cg Exp $' |
148 | 2122 |
! ! |
209
b858b6a6880f
compare categoryStrings equal before writing a change record
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2123 |
ByteCodeCompiler initialize! |