0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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
|
|
14 |
instanceVariableNames:'code codeIndex
|
|
15 |
litArray
|
|
16 |
stackDelta extra lineno
|
|
17 |
maxStackDepth
|
|
18 |
relocList'
|
1
|
19 |
classVariableNames:'JumpToAbsJump'
|
0
|
20 |
poolDictionaries:''
|
|
21 |
category:'System-Compiler'
|
|
22 |
!
|
|
23 |
|
|
24 |
ByteCodeCompiler comment:'
|
4
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
26 |
All Rights Reserved
|
3
|
27 |
'!
|
|
28 |
|
|
29 |
!ByteCodeCompiler class methodsFor:'documentation'!
|
|
30 |
|
20
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
34 |
All Rights Reserved
|
|
35 |
|
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
|
47 |
$Header: /cvs/stx/stx/libcomp/Attic/BCompiler.st,v 1.11 1994-06-02 20:25:49 claus Exp $
|
|
48 |
"
|
|
49 |
!
|
|
50 |
|
3
|
51 |
documentation
|
|
52 |
"
|
19
|
53 |
This class performs compilation into ByteCodes.
|
|
54 |
First, parsing is done using superclass methods,
|
|
55 |
then the parse-tree is converted into an array of symbolic codes
|
|
56 |
and a relocation table;
|
|
57 |
these two are finally combined into a byteArray of the codes.
|
0
|
58 |
|
19
|
59 |
(the intermediate step through symbolic codes is for debugging
|
|
60 |
only - it will vanish)
|
|
61 |
|
|
62 |
There are many dependencies to the run-time-system (especially the
|
|
63 |
interpreter) in here - be careful when playing around ...
|
0
|
64 |
|
19
|
65 |
Instance variables:
|
0
|
66 |
|
19
|
67 |
code <ByteArry> bytecodes
|
|
68 |
codeIndex <SmallInteger> next index to put into code array
|
|
69 |
litArray <OrderedCollection> literals
|
|
70 |
stackDelta <SmallInteger> return value of byteCodeFor:
|
|
71 |
extra <Symbol> return value of byteCodeFor:
|
|
72 |
lineno <Boolean> return value of byteCodeFor:
|
|
73 |
maxStackDepth <SmallInteger> stack need of method
|
|
74 |
relocList <Array> used temporary for relocation
|
|
75 |
|
|
76 |
Class variables:
|
|
77 |
|
|
78 |
JumpToAbsJump <Dictionary> internal table to map opcodes
|
3
|
79 |
"
|
|
80 |
! !
|
0
|
81 |
|
|
82 |
!ByteCodeCompiler class methodsFor:'compiling methods'!
|
|
83 |
|
|
84 |
compile:methodText forClass:classToCompileFor
|
|
85 |
"compile a source-string for a method in classToCompileFor"
|
|
86 |
|
|
87 |
^ self compile:methodText
|
|
88 |
forClass:classToCompileFor
|
|
89 |
inCategory:'others'
|
|
90 |
notifying:nil
|
|
91 |
install:true
|
|
92 |
skipIfSame:false
|
20
|
93 |
silent:false
|
0
|
94 |
!
|
|
95 |
|
|
96 |
compile:aString forClass:aClass inCategory:cat
|
|
97 |
"compile a source-string for a method in classToCompileFor.
|
|
98 |
The method will get cat as category"
|
|
99 |
|
|
100 |
^ self compile:aString
|
|
101 |
forClass:aClass
|
|
102 |
inCategory:cat
|
|
103 |
notifying:nil
|
|
104 |
install:true
|
|
105 |
skipIfSame:false
|
20
|
106 |
silent:false
|
0
|
107 |
!
|
|
108 |
|
|
109 |
compile:methodText forClass:classToCompileFor notifying:someOne
|
|
110 |
"compile a source-string for a method in classToCompileFor.
|
20
|
111 |
Errors are forwarded to someOne."
|
0
|
112 |
|
|
113 |
^ self compile:methodText
|
|
114 |
forClass:classToCompileFor
|
|
115 |
inCategory:'others'
|
|
116 |
notifying:someOne
|
|
117 |
install:true
|
|
118 |
skipIfSame:false
|
20
|
119 |
silent:false
|
0
|
120 |
!
|
|
121 |
|
|
122 |
compile:aString forClass:aClass inCategory:cat notifying:someOne
|
|
123 |
"compile a source-string for a method in classToCompileFor.
|
|
124 |
errors are forwarded to someOne.
|
|
125 |
The method will get cat as category"
|
|
126 |
|
|
127 |
^ self compile:aString
|
|
128 |
forClass:aClass
|
|
129 |
inCategory:cat
|
|
130 |
notifying:someOne
|
|
131 |
install:true
|
|
132 |
skipIfSame:false
|
20
|
133 |
silent:false
|
0
|
134 |
!
|
|
135 |
|
20
|
136 |
compile:aString forClass:aClass inCategory:cat notifying:someOne install:install
|
|
137 |
"compile a source-string for a method in classToCompileFor.
|
|
138 |
The install-argument controls if the method is to be installed into the
|
|
139 |
classes method-dictionary, or just to be compiled and a method object to be returned.
|
|
140 |
Errors are forwarded to someOne. The method will get cat as category"
|
|
141 |
|
0
|
142 |
^ self compile:aString
|
|
143 |
forClass:aClass
|
|
144 |
inCategory:cat
|
|
145 |
notifying:someOne
|
|
146 |
install:true
|
|
147 |
skipIfSame:false
|
20
|
148 |
silent:false
|
0
|
149 |
!
|
|
150 |
|
|
151 |
compile:aString forClass:aClass inCategory:cat notifying:someOne
|
|
152 |
install:install skipIfSame:skipIfSame
|
20
|
153 |
"compile a source-string for a method in classToCompileFor.
|
|
154 |
The install-argument controls if the method is to be installed into the
|
|
155 |
classes method-dictionary, or just to be compiled and a method object to be returned.
|
|
156 |
Errors are forwarded to someOne. The method will get cat as category.
|
|
157 |
If skipIsSame is true, and the source is the same as an existing
|
|
158 |
methods source, this is a noop (for fast fileIn)."
|
0
|
159 |
|
20
|
160 |
^ self compile:aString
|
|
161 |
forClass:aClass
|
|
162 |
inCategory:cat
|
|
163 |
notifying:someOne
|
|
164 |
install:true
|
|
165 |
skipIfSame:skipIfSame
|
|
166 |
silent:false
|
|
167 |
!
|
|
168 |
|
|
169 |
compile:aString forClass:aClass inCategory:cat notifying:someOne
|
|
170 |
install:install skipIfSame:skipIfSame silent:silent
|
|
171 |
|
|
172 |
"the basic workhorse method for compiling:
|
0
|
173 |
compile a source-string for a method in classToCompileFor.
|
|
174 |
errors are forwarded to someOne (report on Transcript and return
|
|
175 |
#Error, if someOne is nil).
|
|
176 |
|
20
|
177 |
The new method will get cat as category.
|
|
178 |
If install is true, the method will go into the classes method-table,
|
|
179 |
otherwise the method is simply returned (for anonymous methods).
|
0
|
180 |
If skipIsSame is true, and the source is the same as an existing
|
20
|
181 |
methods source, this is a noop (for fast fileIn).
|
|
182 |
The argument, silent controls if errors are to be reported."
|
0
|
183 |
|
19
|
184 |
|compiler newMethod tree lits symbolicCodeArray oldMethod lazy|
|
0
|
185 |
|
|
186 |
aString isNil ifTrue:[^ nil].
|
|
187 |
|
19
|
188 |
"lazy compilation is EXPERIMENTAL"
|
|
189 |
lazy := (LazyCompilation == true) and:[install].
|
|
190 |
|
0
|
191 |
"create a compiler, let it parse and create the parsetree"
|
|
192 |
|
|
193 |
compiler := self for:(ReadStream on:aString).
|
|
194 |
compiler setClassToCompileFor:aClass.
|
|
195 |
compiler notifying:someOne.
|
|
196 |
|
|
197 |
compiler nextToken.
|
|
198 |
(compiler parseMethodSpec == #Error) ifTrue:[
|
|
199 |
tree := #Error
|
|
200 |
] ifFalse:[
|
|
201 |
"check if same source"
|
|
202 |
(skipIfSame and:[compiler selector notNil]) ifTrue:[
|
|
203 |
oldMethod := aClass compiledMethodAt:(compiler selector).
|
|
204 |
oldMethod notNil ifTrue:[
|
|
205 |
oldMethod source = aString ifTrue:[
|
20
|
206 |
(silent or:[Smalltalk silentLoading == true]) ifFalse:[
|
0
|
207 |
Transcript showCr:('unchanged: ',aClass name,' ',compiler selector)
|
|
208 |
].
|
|
209 |
^ oldMethod
|
|
210 |
]
|
|
211 |
]
|
|
212 |
].
|
19
|
213 |
lazy ifFalse:[
|
|
214 |
tree := compiler parseMethodBody.
|
|
215 |
compiler tree:tree.
|
|
216 |
]
|
0
|
217 |
].
|
|
218 |
|
|
219 |
(compiler errorFlag or:[tree == #Error]) ifTrue:[
|
|
220 |
compiler selector notNil ifTrue:[
|
|
221 |
Transcript show:(compiler selector,' ')
|
|
222 |
].
|
|
223 |
Transcript showCr:'syntax error'.
|
|
224 |
^ #Error
|
|
225 |
].
|
|
226 |
|
19
|
227 |
"if no error and also no selector ..."
|
0
|
228 |
compiler selector isNil ifTrue:[
|
19
|
229 |
"... it was just a comment or other empty stuff"
|
0
|
230 |
^ nil
|
|
231 |
].
|
|
232 |
|
19
|
233 |
"will add freak-out support here soon ..."
|
|
234 |
compiler hasPrimitiveCode ifTrue:[
|
|
235 |
Transcript showCr:'cannot compile primitives (yet)'.
|
|
236 |
^ #Error
|
|
237 |
].
|
|
238 |
|
|
239 |
"EXPERIMENTAL: quick loading"
|
|
240 |
lazy ifTrue:[
|
|
241 |
newMethod := LazyMethod new.
|
|
242 |
newMethod source:aString.
|
|
243 |
newMethod category:cat.
|
|
244 |
|
|
245 |
aClass addSelector:(compiler selector) withLazyMethod:newMethod.
|
|
246 |
^ newMethod
|
|
247 |
].
|
|
248 |
|
3
|
249 |
"produce symbolic code first"
|
0
|
250 |
|
|
251 |
symbolicCodeArray := compiler genSymbolicCode.
|
|
252 |
(symbolicCodeArray == #Error) ifTrue:[
|
|
253 |
compiler selector notNil ifTrue:[
|
|
254 |
Transcript show:(compiler selector,' ')
|
|
255 |
].
|
|
256 |
Transcript showCr:'translation error'.
|
|
257 |
^ #Error
|
|
258 |
].
|
|
259 |
|
19
|
260 |
"take this, producing bytecode
|
|
261 |
(someone willin' to make machine code :-)"
|
0
|
262 |
((compiler genByteCodeFrom:symbolicCodeArray) == #Error) ifTrue:[
|
|
263 |
compiler selector notNil ifTrue:[
|
|
264 |
Transcript show:(compiler selector,' ')
|
|
265 |
].
|
|
266 |
Transcript showCr:'relocation error - must be simplified'.
|
|
267 |
^ #Error
|
|
268 |
].
|
|
269 |
|
|
270 |
"finally create the new method-object"
|
|
271 |
|
|
272 |
newMethod := Method new.
|
|
273 |
lits := compiler literalArray.
|
|
274 |
lits notNil ifTrue:[
|
|
275 |
"literals MUST be an array - not just any Collection"
|
|
276 |
lits := Array withAll:lits.
|
|
277 |
newMethod literals:lits
|
|
278 |
].
|
|
279 |
newMethod byteCode:(compiler code).
|
19
|
280 |
|
|
281 |
"if there where any corrections, install the updated source"
|
|
282 |
compiler correctedSource notNil ifTrue:[
|
|
283 |
newMethod source:compiler correctedSource
|
|
284 |
] ifFalse:[
|
|
285 |
newMethod source:aString.
|
|
286 |
].
|
0
|
287 |
newMethod category:cat.
|
|
288 |
newMethod numberOfMethodVars:(compiler numberOfMethodVars).
|
13
|
289 |
newMethod numberOfMethodArgs:(compiler numberOfMethodArgs).
|
0
|
290 |
newMethod stackSize:(compiler maxStackDepth).
|
|
291 |
|
|
292 |
install ifTrue:[
|
|
293 |
aClass addSelector:(compiler selector) withMethod:newMethod
|
|
294 |
].
|
|
295 |
|
20
|
296 |
(silent or:[Smalltalk silentLoading == true]) ifFalse:[
|
0
|
297 |
Transcript showCr:('compiled: ',aClass name,' ',compiler selector)
|
|
298 |
].
|
|
299 |
|
|
300 |
^ newMethod
|
|
301 |
! !
|
|
302 |
|
15
|
303 |
!ByteCodeCompiler class methodsFor:'constants'!
|
|
304 |
|
|
305 |
byteCodeFor:aSymbol
|
|
306 |
"only some exported codes handled here (for BlockNode)"
|
|
307 |
|
|
308 |
(aSymbol == #blockRetTop) ifTrue:[^ 6].
|
|
309 |
(aSymbol == #push0) ifTrue:[^120].
|
|
310 |
(aSymbol == #push1) ifTrue:[^121].
|
|
311 |
(aSymbol == #push2) ifTrue:[^139].
|
|
312 |
(aSymbol == #pushMinus1) ifTrue:[^122].
|
|
313 |
(aSymbol == #pushNil) ifTrue:[^ 10].
|
|
314 |
(aSymbol == #pushTrue) ifTrue:[^ 11].
|
|
315 |
(aSymbol == #pushFalse) ifTrue:[^ 12].
|
|
316 |
(aSymbol == #pushSelf) ifTrue:[^ 15].
|
|
317 |
self error
|
|
318 |
! !
|
|
319 |
|
0
|
320 |
!ByteCodeCompiler methodsFor:'accessing'!
|
|
321 |
|
|
322 |
literalArray
|
|
323 |
"return the literal array - only valid after parsing"
|
|
324 |
|
|
325 |
^ litArray
|
|
326 |
!
|
|
327 |
|
|
328 |
code
|
3
|
329 |
"return the bytecode array - only valid after code-generation"
|
0
|
330 |
|
|
331 |
^ code
|
|
332 |
!
|
|
333 |
|
|
334 |
maxStackDepth
|
|
335 |
"return the stack-need of the method - only valid after code-generation"
|
|
336 |
|
|
337 |
^ maxStackDepth
|
|
338 |
! !
|
|
339 |
|
|
340 |
!ByteCodeCompiler methodsFor:'code generation'!
|
|
341 |
|
|
342 |
genSymbolicCode
|
|
343 |
"traverse the parse-tree producing symbolicCode - return the codeArray"
|
|
344 |
|
|
345 |
|codeStream thisStatement lastStatement|
|
|
346 |
|
|
347 |
codeStream := WriteStream on:(Array new:100).
|
|
348 |
thisStatement := tree.
|
|
349 |
[thisStatement notNil] whileTrue:[
|
|
350 |
lastStatement := thisStatement.
|
|
351 |
thisStatement codeForSideEffectOn:codeStream inBlock:nil.
|
|
352 |
thisStatement := thisStatement nextStatement
|
|
353 |
].
|
|
354 |
(lastStatement isNil or:[(lastStatement isMemberOf:ReturnNode) not])
|
|
355 |
ifTrue:[
|
|
356 |
"not a return - add retSelf"
|
|
357 |
codeStream nextPut:#retSelf
|
|
358 |
].
|
|
359 |
^ codeStream contents
|
|
360 |
!
|
|
361 |
|
19
|
362 |
checkForPrimitiveCode:nr
|
0
|
363 |
"this was added to allow emulation of (some) ST-80
|
|
364 |
primitives (to fileIn Remote-Package)"
|
|
365 |
|
3
|
366 |
|cls sel|
|
|
367 |
|
19
|
368 |
(nr == 75) ifTrue:[ cls := Object. sel := #identityHash ].
|
|
369 |
(nr == 110) ifTrue:[ cls := Object. sel := #== ].
|
|
370 |
(nr == 111) ifTrue:[ cls := Object. sel := #class ].
|
3
|
371 |
cls notNil ifTrue:[
|
|
372 |
^ (cls compiledMethodAt:sel) code
|
|
373 |
].
|
0
|
374 |
^ nil
|
|
375 |
!
|
|
376 |
|
|
377 |
genByteCodeFrom:symbolicCodeArray
|
|
378 |
"convert symbolicCode into bytecodes"
|
|
379 |
|
|
380 |
|symIndex "<SmallInteger>"
|
|
381 |
codeSize "<SmallInteger>"
|
|
382 |
symCodeSize "<SmallInteger>"
|
|
383 |
index addr
|
|
384 |
codeSymbol nargs done
|
|
385 |
stackDepth relocInfo level nvars|
|
|
386 |
|
|
387 |
symbolicCodeArray isNil ifTrue:[^ self].
|
|
388 |
|
|
389 |
done := false.
|
|
390 |
symCodeSize := symbolicCodeArray size.
|
|
391 |
codeSize := symCodeSize.
|
|
392 |
|
|
393 |
[done] whileFalse:[
|
|
394 |
litArray := nil.
|
|
395 |
stackDepth := 0.
|
|
396 |
maxStackDepth := 0.
|
|
397 |
|
3
|
398 |
code := ByteArray uninitializedNew:codeSize.
|
0
|
399 |
relocInfo := Array new:(codeSize + 1).
|
|
400 |
symIndex := 1.
|
|
401 |
codeIndex := 1.
|
|
402 |
|
|
403 |
[symIndex <= symCodeSize] whileTrue:[
|
|
404 |
relocInfo at:symIndex put:codeIndex.
|
|
405 |
|
|
406 |
codeSymbol := symbolicCodeArray at:symIndex.
|
|
407 |
symIndex := symIndex + 1.
|
|
408 |
stackDelta := 0.
|
|
409 |
extra := nil.
|
|
410 |
lineno := false.
|
|
411 |
self appendByteCodeFor:codeSymbol.
|
|
412 |
lineno ifTrue:[
|
|
413 |
self appendByte:((symbolicCodeArray at:symIndex) min:255).
|
|
414 |
symIndex := symIndex + 1
|
|
415 |
].
|
|
416 |
extra notNil ifTrue:[
|
|
417 |
(extra == #number) ifTrue:[
|
|
418 |
index := symbolicCodeArray at:symIndex.
|
|
419 |
symIndex := symIndex + 1.
|
|
420 |
self appendSignedByte:index
|
|
421 |
] ifFalse:[
|
|
422 |
(extra == #index) ifTrue:[
|
|
423 |
index := symbolicCodeArray at:symIndex.
|
|
424 |
symIndex := symIndex + 1.
|
|
425 |
self appendByte:index
|
|
426 |
] ifFalse:[
|
|
427 |
(extra == #lit) ifTrue:[
|
|
428 |
index := self addLiteral:(symbolicCodeArray at:symIndex).
|
|
429 |
symIndex := symIndex + 1.
|
|
430 |
self appendByte:index
|
|
431 |
] ifFalse:[
|
|
432 |
(extra == #speciallit) ifTrue:[
|
|
433 |
index := self addLiteral:(symbolicCodeArray at:symIndex).
|
|
434 |
symIndex := symIndex + 1.
|
|
435 |
self appendByte:index.
|
|
436 |
self appendByte:0. "space for inline-generation"
|
|
437 |
self appendByte:0. "space for inline-address"
|
|
438 |
self appendByte:0.
|
|
439 |
self appendByte:0.
|
|
440 |
self appendByte:0.
|
|
441 |
symIndex := symIndex + 5
|
|
442 |
] ifFalse:[
|
|
443 |
(extra == #offset) ifTrue:[
|
|
444 |
relocInfo at:symIndex put:codeIndex.
|
|
445 |
self addReloc:symIndex.
|
|
446 |
symIndex := symIndex + 1.
|
|
447 |
self appendByte:0
|
|
448 |
] ifFalse:[
|
|
449 |
(extra == #indexLevel) ifTrue:[
|
|
450 |
index := symbolicCodeArray at:symIndex.
|
|
451 |
symIndex := symIndex + 1.
|
|
452 |
self appendByte:index.
|
|
453 |
level := symbolicCodeArray at:symIndex.
|
|
454 |
symIndex := symIndex + 1.
|
|
455 |
self appendByte:level
|
|
456 |
] ifFalse:[
|
|
457 |
(extra == #offsetNvarNarg) ifTrue:[
|
|
458 |
relocInfo at:symIndex put:codeIndex.
|
|
459 |
self addReloc:symIndex.
|
|
460 |
symIndex := symIndex + 1.
|
|
461 |
self appendByte:0.
|
|
462 |
nvars := symbolicCodeArray at:symIndex.
|
|
463 |
symIndex := symIndex + 1.
|
|
464 |
self appendByte:nvars.
|
|
465 |
level := symbolicCodeArray at:symIndex.
|
|
466 |
symIndex := symIndex + 1.
|
|
467 |
self appendByte:level
|
|
468 |
] ifFalse:[
|
|
469 |
(extra == #absoffset) ifTrue:[
|
1
|
470 |
relocInfo at:symIndex put:codeIndex.
|
3
|
471 |
self addReloc:symIndex.
|
0
|
472 |
addr := symbolicCodeArray at:symIndex.
|
|
473 |
symIndex := symIndex + 1.
|
|
474 |
self appendByte:(addr bitAnd:16rFF).
|
|
475 |
self appendByte:((addr bitShift:-8) bitAnd:16rFF).
|
|
476 |
] ifFalse:[
|
1
|
477 |
(extra == #absoffsetNvarNarg) ifTrue:[
|
|
478 |
relocInfo at:symIndex put:codeIndex.
|
3
|
479 |
self addReloc:symIndex.
|
1
|
480 |
addr := symbolicCodeArray at:symIndex.
|
|
481 |
symIndex := symIndex + 1.
|
|
482 |
self appendByte:(addr bitAnd:16rFF).
|
|
483 |
self appendByte:((addr bitShift:-8) bitAnd:16rFF).
|
|
484 |
nvars := symbolicCodeArray at:symIndex.
|
|
485 |
symIndex := symIndex + 1.
|
|
486 |
self appendByte:nvars.
|
|
487 |
level := symbolicCodeArray at:symIndex.
|
|
488 |
symIndex := symIndex + 1.
|
|
489 |
self appendByte:level
|
|
490 |
] ifFalse:[
|
|
491 |
self error:'compiler botch'
|
|
492 |
]
|
0
|
493 |
]
|
|
494 |
]
|
|
495 |
]
|
|
496 |
]
|
|
497 |
]
|
|
498 |
]
|
|
499 |
]
|
|
500 |
]
|
|
501 |
].
|
|
502 |
((codeSymbol == #send) or:[codeSymbol == #superSend]) ifTrue:[
|
|
503 |
index := self addLiteral:(symbolicCodeArray at:symIndex).
|
|
504 |
symIndex := symIndex + 1.
|
|
505 |
nargs := symbolicCodeArray at:symIndex.
|
|
506 |
symIndex := symIndex + 1.
|
|
507 |
self appendByte:nargs.
|
|
508 |
self appendByte:index.
|
|
509 |
(codeSymbol == #superSend) ifTrue:[
|
|
510 |
symIndex := symIndex + 1.
|
|
511 |
index := self addLiteral:(classToCompileFor superclass).
|
|
512 |
self appendByte:index
|
|
513 |
].
|
|
514 |
stackDelta := nargs negated
|
|
515 |
] ifFalse:[
|
|
516 |
(codeSymbol == #sendDrop) ifTrue:[
|
|
517 |
index := self addLiteral:(symbolicCodeArray at:symIndex).
|
|
518 |
symIndex := symIndex + 1.
|
|
519 |
nargs := symbolicCodeArray at:symIndex.
|
|
520 |
symIndex := symIndex + 1.
|
|
521 |
self appendByte:nargs.
|
|
522 |
self appendByte:index.
|
|
523 |
stackDelta := (nargs + 1) negated
|
|
524 |
]
|
|
525 |
].
|
|
526 |
stackDepth := stackDepth + stackDelta.
|
|
527 |
(stackDepth > maxStackDepth) ifTrue:[
|
|
528 |
maxStackDepth := stackDepth
|
|
529 |
]
|
|
530 |
].
|
|
531 |
relocInfo at:symIndex put:codeIndex.
|
|
532 |
|
|
533 |
"relocate - returns true if ok, false if we have to rerun"
|
|
534 |
done := true.
|
|
535 |
relocList notNil ifTrue:[
|
|
536 |
done := self relocateWith:symbolicCodeArray relocInfo:relocInfo.
|
1
|
537 |
"if returned with false, a relative jump was made into
|
|
538 |
an absolute jump - need to start over with one more byte space"
|
3
|
539 |
done ifFalse:[
|
|
540 |
relocList := nil.
|
|
541 |
codeSize := codeSize + 1.
|
|
542 |
]
|
0
|
543 |
].
|
|
544 |
].
|
|
545 |
"code printNewline."
|
|
546 |
^ errorFlag
|
|
547 |
!
|
|
548 |
|
1
|
549 |
absJumpFromJump:code
|
3
|
550 |
"given a jump-symbolic code, return corresponding absolute jump"
|
|
551 |
|
1
|
552 |
JumpToAbsJump isNil ifTrue:[
|
3
|
553 |
JumpToAbsJump := IdentityDictionary new.
|
|
554 |
JumpToAbsJump at:#jump put:#jumpabs.
|
|
555 |
JumpToAbsJump at:#trueJump put:#trueJumpabs.
|
|
556 |
JumpToAbsJump at:#falseJump put:#falseJumpabs.
|
|
557 |
JumpToAbsJump at:#nilJump put:#nilJumpabs.
|
|
558 |
JumpToAbsJump at:#notNilJump put:#notNilJumpabs.
|
|
559 |
JumpToAbsJump at:#eqJump put:#eqJumpabs.
|
|
560 |
JumpToAbsJump at:#notEqJump put:#notEqJumpabs.
|
|
561 |
JumpToAbsJump at:#zeroJump put:#zeroJumpabs.
|
|
562 |
JumpToAbsJump at:#notZeroJump put:#notZeroJumpabs.
|
|
563 |
JumpToAbsJump at:#makeBlock put:#makeBlockabs.
|
1
|
564 |
].
|
|
565 |
^ JumpToAbsJump at:code
|
|
566 |
!
|
|
567 |
|
0
|
568 |
relocateWith:symbolicCodeArray relocInfo:relocInfo
|
|
569 |
"helper for genByteCodeFrom - relocate code using relocInfo.
|
|
570 |
if relocation fails badly (due to long relative jumps) patch
|
|
571 |
symbolicCode to use absolute jumps instead and return false
|
3
|
572 |
(genByteCodeFrom will then try again). Otherwise return true.
|
|
573 |
Also, on the fly, jumps to jumps and jumps to return are handled."
|
0
|
574 |
|
|
575 |
|delta "<SmallInteger>"
|
|
576 |
codePos "<SmallInteger>"
|
1
|
577 |
opCodePos "<SmallInteger>"
|
0
|
578 |
codeOffset "<SmallInteger>"
|
|
579 |
symOffset opcode dstOpcode jumpTarget
|
3
|
580 |
jumpCode deleteSet|
|
0
|
581 |
|
3
|
582 |
deleteSet := OrderedCollection new.
|
0
|
583 |
relocList do:[:sIndex |
|
1
|
584 |
"have to relocate symCode at sIndex ..."
|
3
|
585 |
symOffset := symbolicCodeArray at:sIndex. "the target in the symbolic code"
|
|
586 |
codePos := relocInfo at:sIndex. "position of the offet in byte code"
|
|
587 |
codeOffset := relocInfo at:symOffset. "position of the target in byte code"
|
0
|
588 |
delta := codeOffset - codePos - 1.
|
1
|
589 |
opCodePos := codePos - 1.
|
|
590 |
opcode := code at:opCodePos.
|
|
591 |
|
3
|
592 |
(opcode between:190 and:199) ifTrue:[
|
|
593 |
"an absolute jump/makeBlock"
|
0
|
594 |
|
3
|
595 |
code at:codePos put:(codeOffset bitAnd:16rFF).
|
|
596 |
code at:(codePos + 1) put:(codeOffset bitShift:-8)
|
|
597 |
] ifFalse:[
|
|
598 |
"get jump-code from long and vlong codes"
|
|
599 |
(opcode between:50 and:59) ifFalse:[
|
|
600 |
(opcode between:60 and:69) ifTrue:[
|
|
601 |
opcode := opcode - 10
|
|
602 |
] ifFalse:[
|
|
603 |
(opcode between:70 and:79) ifTrue:[
|
|
604 |
opcode := opcode - 20
|
|
605 |
] ifFalse:[
|
1
|
606 |
self error:'invalid code to relocate'
|
3
|
607 |
]
|
1
|
608 |
].
|
3
|
609 |
].
|
1
|
610 |
|
|
611 |
"optimize jump to return and jump to jump"
|
|
612 |
|
|
613 |
(opcode == 54) ifTrue:[
|
|
614 |
"a jump"
|
|
615 |
dstOpcode := symbolicCodeArray at:symOffset.
|
3
|
616 |
|
|
617 |
(#(retSelf retTop retNil retTrue retFalse ret0 blockRetTop) includes:dstOpcode) ifTrue:[
|
1
|
618 |
"a jump to a return - put in the return instead jump"
|
3
|
619 |
|
|
620 |
symbolicCodeArray at:(sIndex - 1) put:dstOpcode.
|
|
621 |
symbolicCodeArray at:sIndex put:dstOpcode.
|
1
|
622 |
code at:opCodePos put:(self byteCodeFor:dstOpcode).
|
3
|
623 |
delta := 0.
|
|
624 |
deleteSet add:sIndex.
|
|
625 |
|
|
626 |
"
|
|
627 |
'jump to return at: ' print. (sIndex - 1) printNewline.
|
|
628 |
"
|
1
|
629 |
] ifFalse:[
|
|
630 |
(dstOpcode == #jump) ifTrue:[
|
|
631 |
"jump to jump to be done soon"
|
3
|
632 |
jumpTarget := symbolicCodeArray at:(symOffset + 1).
|
|
633 |
"
|
|
634 |
'jump to jump at: ' print. (sIndex - 1) print.
|
|
635 |
' newTarget:' print. jumpTarget printNewline.
|
|
636 |
"
|
|
637 |
|
|
638 |
symbolicCodeArray at:sIndex put:jumpTarget.
|
|
639 |
symOffset := jumpTarget.
|
|
640 |
codeOffset := relocInfo at:symOffset.
|
|
641 |
delta := codeOffset - codePos - 1.
|
|
642 |
|
|
643 |
"continue with new delta"
|
1
|
644 |
]
|
0
|
645 |
]
|
1
|
646 |
].
|
3
|
647 |
(#(50 51 52 53 56 57 58 59) includes:opcode) ifTrue:[
|
|
648 |
"a conditional jump"
|
|
649 |
|
|
650 |
dstOpcode := symbolicCodeArray at:symOffset.
|
|
651 |
(dstOpcode == #jump) ifTrue:[
|
|
652 |
"conditional jump to unconditional jump"
|
|
653 |
jumpTarget := symbolicCodeArray at:(symOffset + 1).
|
|
654 |
"
|
|
655 |
'cond jump to jump at: ' print. (sIndex - 1) print.
|
|
656 |
' newTarget:' print. jumpTarget printNewline.
|
|
657 |
"
|
|
658 |
|
|
659 |
symbolicCodeArray at:sIndex put:jumpTarget.
|
|
660 |
symOffset := jumpTarget.
|
|
661 |
codeOffset := relocInfo at:symOffset.
|
|
662 |
delta := codeOffset - codePos - 1.
|
|
663 |
|
|
664 |
"continue with new delta"
|
|
665 |
].
|
|
666 |
].
|
|
667 |
|
1
|
668 |
(delta >= 0) ifTrue:[
|
0
|
669 |
(delta > 127) ifTrue:[
|
1
|
670 |
(opcode between:50 and:59) ifFalse:[
|
|
671 |
self error:'invalid code to relocate'
|
0
|
672 |
].
|
1
|
673 |
(delta > 255) ifTrue:[
|
|
674 |
"change jmp into vljmp ..."
|
|
675 |
code at:opCodePos put:(opcode + 20).
|
|
676 |
delta := delta - 256
|
|
677 |
] ifFalse:[
|
|
678 |
"change jmp into ljmp ..."
|
|
679 |
code at:opCodePos put:(opcode + 10).
|
|
680 |
delta := delta - 128
|
0
|
681 |
].
|
1
|
682 |
(delta > 127) ifTrue:[
|
|
683 |
"change symbolic into a jump absolute and fail"
|
|
684 |
jumpCode := symbolicCodeArray at:(sIndex - 1).
|
3
|
685 |
symbolicCodeArray at:(sIndex - 1) put:(self absJumpFromJump:jumpCode).
|
1
|
686 |
symbolicCodeArray at:sIndex put:symOffset.
|
3
|
687 |
"
|
|
688 |
'change short into abs jump' printNewline.
|
|
689 |
"
|
|
690 |
deleteSet do:[:d | relocList remove:d].
|
0
|
691 |
^ false
|
|
692 |
].
|
1
|
693 |
].
|
|
694 |
code at:codePos put:delta
|
|
695 |
] ifFalse:[
|
|
696 |
(delta < -128) ifTrue:[
|
|
697 |
(opcode between:50 and:59) ifFalse:[
|
|
698 |
self error:'invalid code to relocate'
|
0
|
699 |
].
|
1
|
700 |
(delta < -256) ifTrue:[
|
|
701 |
"change jmp into vljmp ..."
|
|
702 |
code at:opCodePos put:(opcode + 20).
|
|
703 |
delta := delta + 256
|
|
704 |
] ifFalse:[
|
|
705 |
"change jmp into ljmp ..."
|
|
706 |
code at:opCodePos put:(opcode + 10).
|
|
707 |
delta := delta + 128
|
0
|
708 |
].
|
1
|
709 |
(delta < -128) ifTrue:[
|
|
710 |
"change symbolic into a jump absolute and fail"
|
|
711 |
jumpCode := symbolicCodeArray at:(sIndex - 1).
|
3
|
712 |
symbolicCodeArray at:(sIndex - 1) put:(self absJumpFromJump:jumpCode).
|
1
|
713 |
symbolicCodeArray at:sIndex put:symOffset.
|
3
|
714 |
"
|
|
715 |
'change short into abs jump' printNewline.
|
|
716 |
"
|
|
717 |
deleteSet do:[:d | relocList remove:d].
|
1
|
718 |
^ false
|
|
719 |
]
|
0
|
720 |
].
|
1
|
721 |
code at:codePos put:(256 + delta)
|
|
722 |
]
|
0
|
723 |
]
|
|
724 |
].
|
|
725 |
(errorFlag == #Error) ifTrue:[
|
|
726 |
self error:'relocation range error'
|
|
727 |
].
|
|
728 |
^ true
|
|
729 |
!
|
|
730 |
|
|
731 |
addLiteral:anObject
|
|
732 |
"add a literal to the literalArray - watch for and eliminate
|
|
733 |
duplicates. return the index of the literal in the Array"
|
|
734 |
|
3
|
735 |
|index class|
|
0
|
736 |
|
|
737 |
litArray isNil ifTrue:[
|
|
738 |
litArray := Array with:anObject.
|
|
739 |
^ 1
|
|
740 |
].
|
|
741 |
index := litArray identityIndexOf:anObject.
|
|
742 |
(index == 0) ifTrue:[
|
3
|
743 |
class := anObject class.
|
|
744 |
((class == Float) or:[class == Fraction]) ifTrue:[
|
|
745 |
index := litArray indexOf:anObject.
|
|
746 |
].
|
20
|
747 |
((index == 0) or:[(litArray at:index) class ~~ class]) ifTrue:[
|
3
|
748 |
litArray := litArray copyWith:anObject.
|
|
749 |
^ litArray size
|
|
750 |
].
|
0
|
751 |
].
|
|
752 |
^ index
|
|
753 |
!
|
|
754 |
|
|
755 |
appendByteCodeFor:codeSymbol
|
|
756 |
"append the byteCode for an instructionSymbol to the code-Array"
|
|
757 |
|
|
758 |
code at:codeIndex put:(self byteCodeFor:codeSymbol).
|
|
759 |
codeIndex := codeIndex + 1
|
|
760 |
!
|
|
761 |
|
|
762 |
appendByte:aByte
|
|
763 |
"append a byte to the code-Array, checking for byte-range (debug-only)"
|
|
764 |
|
|
765 |
(aByte between:0 and:255) ifTrue:[
|
|
766 |
code at:codeIndex put:aByte.
|
|
767 |
codeIndex := codeIndex + 1
|
|
768 |
] ifFalse:[
|
|
769 |
self error:'byte range error'.
|
|
770 |
errorFlag := #Error
|
|
771 |
]
|
|
772 |
!
|
|
773 |
|
|
774 |
appendSignedByte:aByte
|
|
775 |
"append a signedbyte (as in jump-offsets) to the code-Array,
|
|
776 |
check range and report an error if invalid"
|
|
777 |
|
|
778 |
|b "<SmallInteger>" |
|
|
779 |
|
|
780 |
b := aByte.
|
|
781 |
(b >= 0) ifTrue:[
|
|
782 |
(b > 127) ifTrue:[
|
|
783 |
self error:'jump-range error'.
|
|
784 |
errorFlag := #Error
|
|
785 |
].
|
|
786 |
code at:codeIndex put:b
|
|
787 |
] ifFalse:[
|
|
788 |
(b < -128) ifTrue:[
|
|
789 |
self error:'jump-range error'.
|
|
790 |
errorFlag := #Error
|
|
791 |
].
|
|
792 |
code at:codeIndex put:(256 + b)
|
|
793 |
].
|
|
794 |
codeIndex := codeIndex + 1
|
|
795 |
!
|
|
796 |
|
|
797 |
addReloc:symIndex
|
|
798 |
"remember to relocate offset at symIndex later ..."
|
|
799 |
|
|
800 |
relocList isNil ifTrue:[
|
|
801 |
relocList := OrderedCollection new.
|
|
802 |
].
|
|
803 |
relocList add:symIndex
|
|
804 |
!
|
|
805 |
|
|
806 |
byteCodeFor:aSymbol
|
|
807 |
"given a symbolic instruction, return the corresponding bytecode.
|
|
808 |
as a side-effect, leave number of bytes pushed/popped by this instr.
|
|
809 |
in stackDelta, and, if the instruction needs extra arguments, leave
|
|
810 |
this info in extra"
|
|
811 |
|
|
812 |
"standard bytecodes"
|
|
813 |
|
|
814 |
(aSymbol == #pushNil) ifTrue:[stackDelta := 1. ^ 10].
|
|
815 |
(aSymbol == #pushTrue) ifTrue:[stackDelta := 1. ^ 11].
|
|
816 |
(aSymbol == #pushFalse) ifTrue:[stackDelta := 1. ^ 12].
|
|
817 |
(aSymbol == #pushLit) ifTrue:[stackDelta := 1. extra := #lit. ^ 14].
|
|
818 |
(aSymbol == #pushSelf) ifTrue:[stackDelta := 1. ^ 15].
|
|
819 |
(aSymbol == #pushNum) ifTrue:[stackDelta := 1. extra := #number. ^ 16].
|
|
820 |
|
|
821 |
(aSymbol == #pushMethodArg) ifTrue:[stackDelta := 1. extra := #index. ^ 30].
|
|
822 |
(aSymbol == #pushMethodVar) ifTrue:[stackDelta := 1. extra := #index. ^ 31].
|
|
823 |
(aSymbol == #pushBlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 32].
|
|
824 |
(aSymbol == #pushBlockVar) ifTrue:[stackDelta := 1. extra := #index. ^ 33].
|
|
825 |
(aSymbol == #pushInstVar) ifTrue:[stackDelta := 1. extra := #index. ^ 34].
|
1
|
826 |
(aSymbol == #pushOuterBlockArg) ifTrue:[stackDelta := 1. extra := #indexLevel. ^ 42].
|
|
827 |
(aSymbol == #pushOuterBlockVar) ifTrue:[stackDelta := 1. extra := #indexLevel. ^ 128].
|
0
|
828 |
|
1
|
829 |
(aSymbol == #storeMethodVar) ifTrue:[extra := #index. stackDelta := -1. ^ 37].
|
|
830 |
(aSymbol == #storeBlockVar) ifTrue:[extra := #index. stackDelta := -1. ^ 38].
|
|
831 |
(aSymbol == #storeInstVar) ifTrue:[extra := #index. stackDelta := -1. ^ 39].
|
0
|
832 |
|
|
833 |
(aSymbol == #retTop) ifTrue:[stackDelta := -1. ^ 0].
|
|
834 |
(aSymbol == #blockRetTop) ifTrue:[stackDelta := -1. ^ 6].
|
|
835 |
|
|
836 |
(aSymbol == #retSelf) ifTrue:[^5].
|
|
837 |
|
|
838 |
(aSymbol == #==) ifTrue:[stackDelta := -1. self addLiteral:aSymbol. ^ 45].
|
|
839 |
(aSymbol == #~~) ifTrue:[stackDelta := -1. self addLiteral:aSymbol. ^ 46].
|
|
840 |
|
|
841 |
(aSymbol == #falseJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 50].
|
|
842 |
(aSymbol == #trueJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 51].
|
|
843 |
(aSymbol == #nilJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 52].
|
|
844 |
(aSymbol == #notNilJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 53].
|
|
845 |
(aSymbol == #jump) ifTrue:[extra := #offset. ^ 54].
|
1
|
846 |
(aSymbol == #makeBlock) ifTrue:[stackDelta := 1. extra := #offsetNvarNarg. ^ 55].
|
0
|
847 |
(aSymbol == #zeroJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 56].
|
|
848 |
(aSymbol == #notZeroJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 57].
|
|
849 |
(aSymbol == #eqJump) ifTrue:[stackDelta := -2. extra := #offset. ^ 58].
|
|
850 |
(aSymbol == #notEqJump) ifTrue:[stackDelta := -2. extra := #offset. ^ 59].
|
|
851 |
|
|
852 |
(aSymbol == #send) ifTrue:[lineno := true. ^ 19].
|
|
853 |
(aSymbol == #superSend) ifTrue:[lineno := true. ^ 20].
|
|
854 |
|
|
855 |
(aSymbol == #drop) ifTrue:[stackDelta := -1. ^ 18].
|
|
856 |
(aSymbol == #dup) ifTrue:[stackDelta := 1. ^ 47].
|
|
857 |
|
|
858 |
(aSymbol == #pushClassVar) ifTrue:[stackDelta := 1. extra := #speciallit. ^ 35].
|
|
859 |
(aSymbol == #pushClassInstVar) ifTrue:[stackDelta := 1. extra := #index. ^ 176].
|
|
860 |
(aSymbol == #pushGlobal) ifTrue:[stackDelta := 1. extra := #speciallit. ^ 36].
|
|
861 |
|
|
862 |
(aSymbol == #storeClassVar) ifTrue:[extra := #speciallit.stackDelta := -1. ^ 40].
|
|
863 |
(aSymbol == #storeClassInstVar) ifTrue:[extra := #index.stackDelta := -1. ^ 177].
|
|
864 |
(aSymbol == #storeGlobal) ifTrue:[extra := #speciallit. stackDelta := -1. ^ 41].
|
1
|
865 |
(aSymbol == #storeOuterBlockVar) ifTrue:[stackDelta := -1. extra := #indexLevel. ^ 129].
|
0
|
866 |
|
|
867 |
"optimized bytecodes"
|
|
868 |
|
|
869 |
(aSymbol == #retNil) ifTrue:[^ 1].
|
|
870 |
(aSymbol == #retTrue) ifTrue:[^ 2].
|
|
871 |
(aSymbol == #retFalse) ifTrue:[^ 3].
|
|
872 |
(aSymbol == #ret0) ifTrue:[^ 4].
|
|
873 |
(aSymbol == #retNum) ifTrue:[extra := #number. ^ 127].
|
|
874 |
|
|
875 |
(aSymbol == #pushChar) ifTrue:[stackDelta := 1. ^17].
|
|
876 |
(aSymbol == #push0) ifTrue:[stackDelta := 1. ^120].
|
|
877 |
(aSymbol == #push1) ifTrue:[stackDelta := 1. ^121].
|
3
|
878 |
(aSymbol == #push2) ifTrue:[stackDelta := 1. ^139].
|
0
|
879 |
(aSymbol == #pushMinus1) ifTrue:[stackDelta := 1. ^122].
|
|
880 |
|
|
881 |
(aSymbol == #send0) ifTrue:[lineno := true. extra := #lit. ^21].
|
|
882 |
(aSymbol == #send1) ifTrue:[lineno := true. extra := #lit. stackDelta := -1. ^22].
|
|
883 |
(aSymbol == #send2) ifTrue:[lineno := true. extra := #lit. stackDelta := -2. ^23].
|
|
884 |
(aSymbol == #send3) ifTrue:[lineno := true. extra := #lit. stackDelta := -3. ^24].
|
|
885 |
|
|
886 |
(aSymbol == #sendSelf0) ifTrue:[lineno := true. extra := #lit. stackDelta := 1. ^180].
|
|
887 |
(aSymbol == #sendSelf1) ifTrue:[lineno := true. extra := #lit. ^181].
|
|
888 |
(aSymbol == #sendSelf2) ifTrue:[lineno := true. extra := #lit. stackDelta := -1. ^182].
|
|
889 |
(aSymbol == #sendSelf3) ifTrue:[lineno := true. extra := #lit. stackDelta := -2. ^183].
|
|
890 |
(aSymbol == #sendSelfDrop0) ifTrue:[lineno := true. extra := #lit. ^184].
|
|
891 |
(aSymbol == #sendSelfDrop1) ifTrue:[lineno := true. extra := #lit. stackDelta := -1. ^185].
|
|
892 |
(aSymbol == #sendSelfDrop2) ifTrue:[lineno := true. extra := #lit. stackDelta := -2. ^186].
|
|
893 |
(aSymbol == #sendSelfDrop3) ifTrue:[lineno := true. extra := #lit. stackDelta := -3. ^187].
|
|
894 |
|
|
895 |
(aSymbol == #sendDrop) ifTrue:[lineno := true. ^25].
|
|
896 |
(aSymbol == #sendDrop0) ifTrue:[lineno := true. extra := #lit. stackDelta := -1. ^26].
|
|
897 |
(aSymbol == #sendDrop1) ifTrue:[lineno := true. extra := #lit. stackDelta := -2. ^27].
|
|
898 |
(aSymbol == #sendDrop2) ifTrue:[lineno := true. extra := #lit. stackDelta := -3. ^28].
|
|
899 |
(aSymbol == #sendDrop3) ifTrue:[lineno := true. extra := #lit. stackDelta := -4. ^29].
|
|
900 |
|
|
901 |
(aSymbol == #pushMethodVar1) ifTrue:[stackDelta := 1. ^80].
|
|
902 |
(aSymbol == #pushMethodVar2) ifTrue:[stackDelta := 1. ^81].
|
|
903 |
(aSymbol == #pushMethodVar3) ifTrue:[stackDelta := 1. ^82].
|
|
904 |
(aSymbol == #pushMethodVar4) ifTrue:[stackDelta := 1. ^83].
|
|
905 |
(aSymbol == #pushMethodVar5) ifTrue:[stackDelta := 1. ^84].
|
|
906 |
(aSymbol == #pushMethodVar6) ifTrue:[stackDelta := 1. ^85].
|
|
907 |
|
|
908 |
(aSymbol == #pushMethodArg1) ifTrue:[stackDelta := 1. ^86].
|
|
909 |
(aSymbol == #pushMethodArg2) ifTrue:[stackDelta := 1. ^87].
|
|
910 |
(aSymbol == #pushMethodArg3) ifTrue:[stackDelta := 1. ^88].
|
|
911 |
(aSymbol == #pushMethodArg4) ifTrue:[stackDelta := 1. ^89].
|
|
912 |
|
|
913 |
(aSymbol == #pushInstVar1) ifTrue:[stackDelta := 1. ^90].
|
|
914 |
(aSymbol == #pushInstVar2) ifTrue:[stackDelta := 1. ^91].
|
|
915 |
(aSymbol == #pushInstVar3) ifTrue:[stackDelta := 1. ^92].
|
|
916 |
(aSymbol == #pushInstVar4) ifTrue:[stackDelta := 1. ^93].
|
|
917 |
(aSymbol == #pushInstVar5) ifTrue:[stackDelta := 1. ^94].
|
|
918 |
(aSymbol == #pushInstVar6) ifTrue:[stackDelta := 1. ^95].
|
|
919 |
(aSymbol == #pushInstVar7) ifTrue:[stackDelta := 1. ^96].
|
|
920 |
(aSymbol == #pushInstVar8) ifTrue:[stackDelta := 1. ^97].
|
|
921 |
(aSymbol == #pushInstVar9) ifTrue:[stackDelta := 1. ^98].
|
|
922 |
(aSymbol == #pushInstVar10) ifTrue:[stackDelta := 1. ^99].
|
|
923 |
|
|
924 |
(aSymbol == #storeMethodVar1) ifTrue:[stackDelta := -1. ^100].
|
|
925 |
(aSymbol == #storeMethodVar2) ifTrue:[stackDelta := -1. ^101].
|
|
926 |
(aSymbol == #storeMethodVar3) ifTrue:[stackDelta := -1. ^102].
|
|
927 |
(aSymbol == #storeMethodVar4) ifTrue:[stackDelta := -1. ^103].
|
|
928 |
(aSymbol == #storeMethodVar5) ifTrue:[stackDelta := -1. ^104].
|
|
929 |
(aSymbol == #storeMethodVar6) ifTrue:[stackDelta := -1. ^105].
|
|
930 |
|
|
931 |
(aSymbol == #storeInstVar1) ifTrue:[stackDelta := -1. ^110].
|
|
932 |
(aSymbol == #storeInstVar2) ifTrue:[stackDelta := -1. ^111].
|
|
933 |
(aSymbol == #storeInstVar3) ifTrue:[stackDelta := -1. ^112].
|
|
934 |
(aSymbol == #storeInstVar4) ifTrue:[stackDelta := -1. ^113].
|
|
935 |
(aSymbol == #storeInstVar5) ifTrue:[stackDelta := -1. ^114].
|
|
936 |
(aSymbol == #storeInstVar6) ifTrue:[stackDelta := -1. ^115].
|
|
937 |
(aSymbol == #storeInstVar7) ifTrue:[stackDelta := -1. ^116].
|
|
938 |
(aSymbol == #storeInstVar8) ifTrue:[stackDelta := -1. ^117].
|
|
939 |
(aSymbol == #storeInstVar9) ifTrue:[stackDelta := -1. ^118].
|
|
940 |
(aSymbol == #storeInstVar10) ifTrue:[stackDelta := -1. ^119].
|
|
941 |
|
|
942 |
(aSymbol == #retMethodVar1) ifTrue:[^160].
|
|
943 |
(aSymbol == #retMethodVar2) ifTrue:[^161].
|
|
944 |
(aSymbol == #retMethodVar3) ifTrue:[^162].
|
|
945 |
(aSymbol == #retMethodVar4) ifTrue:[^163].
|
|
946 |
(aSymbol == #retMethodVar5) ifTrue:[^164].
|
|
947 |
(aSymbol == #retMethodVar6) ifTrue:[^165].
|
|
948 |
|
|
949 |
(aSymbol == #retInstVar1) ifTrue:[^166].
|
|
950 |
(aSymbol == #retInstVar2) ifTrue:[^167].
|
|
951 |
(aSymbol == #retInstVar3) ifTrue:[^168].
|
|
952 |
(aSymbol == #retInstVar4) ifTrue:[^169].
|
|
953 |
(aSymbol == #retInstVar5) ifTrue:[^170].
|
|
954 |
(aSymbol == #retInstVar6) ifTrue:[^171].
|
|
955 |
(aSymbol == #retInstVar7) ifTrue:[^172].
|
|
956 |
(aSymbol == #retInstVar8) ifTrue:[^173].
|
|
957 |
|
|
958 |
(aSymbol == #retMethodArg1) ifTrue:[^174].
|
|
959 |
(aSymbol == #retMethodArg2) ifTrue:[^175].
|
|
960 |
|
|
961 |
(aSymbol == #pushBlockArg1) ifTrue:[stackDelta := 1. ^140].
|
|
962 |
(aSymbol == #pushBlockArg2) ifTrue:[stackDelta := 1. ^141].
|
|
963 |
(aSymbol == #pushBlockArg3) ifTrue:[stackDelta := 1. ^142].
|
|
964 |
(aSymbol == #pushBlockArg4) ifTrue:[stackDelta := 1. ^143].
|
|
965 |
|
1
|
966 |
(aSymbol == #pushOuter1BlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 43].
|
|
967 |
(aSymbol == #pushOuter2BlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 44].
|
0
|
968 |
|
5
|
969 |
(aSymbol == #=) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^130].
|
|
970 |
(aSymbol == #+) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^131].
|
|
971 |
(aSymbol == #~=) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^132].
|
|
972 |
(aSymbol == #-) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^133].
|
0
|
973 |
(aSymbol == #class) ifTrue:[self addLiteral:aSymbol. ^134].
|
5
|
974 |
(aSymbol == #x) ifTrue:[lineno := true. self addLiteral:aSymbol. ^106].
|
|
975 |
(aSymbol == #y) ifTrue:[lineno := true. self addLiteral:aSymbol. ^107].
|
|
976 |
(aSymbol == #width) ifTrue:[lineno := true. self addLiteral:aSymbol. ^108].
|
|
977 |
(aSymbol == #height) ifTrue:[lineno := true. self addLiteral:aSymbol. ^109].
|
|
978 |
(aSymbol == #origin) ifTrue:[lineno := true. self addLiteral:aSymbol. ^154].
|
|
979 |
(aSymbol == #extent) ifTrue:[lineno := true. self addLiteral:aSymbol. ^155].
|
|
980 |
(aSymbol == #at:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^135].
|
|
981 |
(aSymbol == #at:put:)ifTrue:[lineno := true. stackDelta := -2. self addLiteral:aSymbol. ^136].
|
|
982 |
(aSymbol == #bitAnd:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^137].
|
|
983 |
(aSymbol == #bitOr:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^138].
|
|
984 |
(aSymbol == #plus1) ifTrue:[lineno := true. self addLiteral:#+. ^123].
|
|
985 |
(aSymbol == #minus1) ifTrue:[lineno := true. self addLiteral:#-. ^124].
|
0
|
986 |
|
5
|
987 |
(aSymbol == #incMethodVar) ifTrue:[lineno := true. self addLiteral:#+. extra := #index. ^125].
|
|
988 |
(aSymbol == #decMethodVar) ifTrue:[lineno := true. self addLiteral:#-. extra := #index. ^126].
|
0
|
989 |
|
|
990 |
(aSymbol == #eq0) ifTrue:[self addLiteral:#==. ^48].
|
|
991 |
(aSymbol == #ne0) ifTrue:[self addLiteral:#~~. ^49].
|
|
992 |
|
5
|
993 |
(aSymbol == #>) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 145].
|
|
994 |
(aSymbol == #>=) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 146].
|
|
995 |
(aSymbol == #<) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 147].
|
|
996 |
(aSymbol == #<=) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 148].
|
|
997 |
(aSymbol == #next) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 149].
|
|
998 |
(aSymbol == #peek) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 150].
|
|
999 |
(aSymbol == #value) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 151].
|
|
1000 |
(aSymbol == #value:) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 152].
|
6
|
1001 |
(aSymbol == #value:value:) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -2. ^ 178].
|
5
|
1002 |
(aSymbol == #size) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 153].
|
|
1003 |
(aSymbol == #asInteger) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 158].
|
|
1004 |
(aSymbol == #rounded) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 159].
|
0
|
1005 |
(aSymbol == #mk0Block) ifTrue:[^ 156].
|
|
1006 |
(aSymbol == #mkNilBlock) ifTrue:[^ 157].
|
|
1007 |
|
|
1008 |
(aSymbol == #falseJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 190].
|
|
1009 |
(aSymbol == #trueJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 191].
|
|
1010 |
(aSymbol == #nilJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 192].
|
|
1011 |
(aSymbol == #notNilJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 193].
|
|
1012 |
(aSymbol == #jumpabs) ifTrue:[extra := #absoffset. ^ 194].
|
1
|
1013 |
(aSymbol == #makeBlockabs) ifTrue:[stackDelta := 1. extra := #absoffsetNvarNarg. ^ 195].
|
0
|
1014 |
(aSymbol == #zeroJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 196].
|
|
1015 |
(aSymbol == #notZeroJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 197].
|
1
|
1016 |
(aSymbol == #eqJumpabs) ifTrue:[stackDelta := -2. extra := #absoffset. ^ 198].
|
|
1017 |
(aSymbol == #notEqJumpabs) ifTrue:[stackDelta := -2. extra := #absoffset. ^ 199].
|
0
|
1018 |
|
|
1019 |
(aSymbol == #pushThisContext) ifTrue:[stackDelta := 1. ^ 144].
|
|
1020 |
|
|
1021 |
self error:'invalid code symbol'.
|
|
1022 |
errorFlag := #Error
|
|
1023 |
! !
|