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:'
|
|
25 |
|
4
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
27 |
All Rights Reserved
|
|
28 |
|
13
|
29 |
$Header: /cvs/stx/stx/libcomp/ByteCodeCompiler.st,v 1.8 1994-01-16 03:51:28 claus Exp $
|
3
|
30 |
'!
|
|
31 |
|
|
32 |
!ByteCodeCompiler class methodsFor:'documentation'!
|
|
33 |
|
|
34 |
documentation
|
|
35 |
"
|
|
36 |
This class performs compilation into ByteCodes.
|
0
|
37 |
First, parsing is done using superclass methods,
|
|
38 |
then the parse-tree is converted into an array of symbolic codes
|
|
39 |
and a relocation table;
|
|
40 |
these two are finally combined into a byteArray of the codes.
|
|
41 |
|
|
42 |
There are many dependancies to the run-time-system (especially the
|
|
43 |
interpreter) in here - be careful when playing around ...
|
|
44 |
|
|
45 |
Instance variables:
|
|
46 |
|
|
47 |
code <ByteArry> bytecodes
|
|
48 |
codeIndex <SmallInteger> next index to put into code array
|
|
49 |
litArray <OrderedCollection> literals
|
|
50 |
stackDelta <SmallInteger> return value of byteCodeFor:
|
|
51 |
extra <Symbol> return value of byteCodeFor:
|
|
52 |
maxStackDepth <SmallInteger> stack need of method
|
|
53 |
relocList <Array> used temporary for relocation
|
3
|
54 |
"
|
|
55 |
! !
|
0
|
56 |
|
|
57 |
!ByteCodeCompiler class methodsFor:'compiling methods'!
|
|
58 |
|
|
59 |
compile:methodText forClass:classToCompileFor
|
|
60 |
"compile a source-string for a method in classToCompileFor"
|
|
61 |
|
|
62 |
^ self compile:methodText
|
|
63 |
forClass:classToCompileFor
|
|
64 |
inCategory:'others'
|
|
65 |
notifying:nil
|
|
66 |
install:true
|
|
67 |
skipIfSame:false
|
|
68 |
!
|
|
69 |
|
|
70 |
compile:aString forClass:aClass inCategory:cat
|
|
71 |
"compile a source-string for a method in classToCompileFor.
|
|
72 |
The method will get cat as category"
|
|
73 |
|
|
74 |
^ self compile:aString
|
|
75 |
forClass:aClass
|
|
76 |
inCategory:cat
|
|
77 |
notifying:nil
|
|
78 |
install:true
|
|
79 |
skipIfSame:false
|
|
80 |
!
|
|
81 |
|
|
82 |
compile:methodText forClass:classToCompileFor notifying:someOne
|
|
83 |
"compile a source-string for a method in classToCompileFor.
|
|
84 |
errors are forwarded to someOne."
|
|
85 |
|
|
86 |
^ self compile:methodText
|
|
87 |
forClass:classToCompileFor
|
|
88 |
inCategory:'others'
|
|
89 |
notifying:someOne
|
|
90 |
install:true
|
|
91 |
skipIfSame:false
|
|
92 |
!
|
|
93 |
|
|
94 |
compile:aString forClass:aClass inCategory:cat notifying:someOne
|
|
95 |
"compile a source-string for a method in classToCompileFor.
|
|
96 |
errors are forwarded to someOne.
|
|
97 |
The method will get cat as category"
|
|
98 |
|
|
99 |
^ self compile:aString
|
|
100 |
forClass:aClass
|
|
101 |
inCategory:cat
|
|
102 |
notifying:someOne
|
|
103 |
install:true
|
|
104 |
skipIfSame:false
|
|
105 |
!
|
|
106 |
|
|
107 |
compile:aString forClass:aClass inCategory:cat notifying:someOne
|
|
108 |
install:install
|
|
109 |
^ self compile:aString
|
|
110 |
forClass:aClass
|
|
111 |
inCategory:cat
|
|
112 |
notifying:someOne
|
|
113 |
install:true
|
|
114 |
skipIfSame:false
|
|
115 |
!
|
|
116 |
|
|
117 |
compile:aString forClass:aClass inCategory:cat notifying:someOne
|
|
118 |
install:install skipIfSame:skipIfSame
|
|
119 |
|
|
120 |
"the basic workhorse method for compiling.
|
|
121 |
compile a source-string for a method in classToCompileFor.
|
|
122 |
errors are forwarded to someOne (report on Transcript and return
|
|
123 |
#Error, if someOne is nil).
|
|
124 |
|
|
125 |
The new method will get cat as category. If install is true, the method
|
|
126 |
will go into the classes method-table, otherwise the method is simply
|
|
127 |
returned (for anonymous methods).
|
|
128 |
If skipIsSame is true, and the source is the same as an existing
|
|
129 |
methods source, this is a noop (for fast fileIn)."
|
|
130 |
|
|
131 |
|compiler newMethod tree lits machineCode
|
|
132 |
symbolicCodeArray sharedCode sharedCodeSymbol oldMethod|
|
|
133 |
|
|
134 |
aString isNil ifTrue:[^ nil].
|
|
135 |
|
|
136 |
"create a compiler, let it parse and create the parsetree"
|
|
137 |
|
|
138 |
compiler := self for:(ReadStream on:aString).
|
|
139 |
compiler setClassToCompileFor:aClass.
|
|
140 |
compiler notifying:someOne.
|
|
141 |
|
|
142 |
compiler nextToken.
|
|
143 |
(compiler parseMethodSpec == #Error) ifTrue:[
|
|
144 |
tree := #Error
|
|
145 |
] ifFalse:[
|
|
146 |
"check if same source"
|
|
147 |
(skipIfSame and:[compiler selector notNil]) ifTrue:[
|
|
148 |
oldMethod := aClass compiledMethodAt:(compiler selector).
|
|
149 |
oldMethod notNil ifTrue:[
|
|
150 |
oldMethod source = aString ifTrue:[
|
|
151 |
SilentLoading ifFalse:[
|
|
152 |
Transcript showCr:('unchanged: ',aClass name,' ',compiler selector)
|
|
153 |
].
|
|
154 |
^ oldMethod
|
|
155 |
]
|
|
156 |
]
|
|
157 |
].
|
|
158 |
tree := compiler parseMethodBody.
|
|
159 |
compiler tree:tree.
|
|
160 |
].
|
|
161 |
|
|
162 |
(compiler errorFlag or:[tree == #Error]) ifTrue:[
|
|
163 |
compiler selector notNil ifTrue:[
|
|
164 |
Transcript show:(compiler selector,' ')
|
|
165 |
].
|
|
166 |
Transcript showCr:'syntax error'.
|
|
167 |
^ #Error
|
|
168 |
].
|
|
169 |
|
|
170 |
compiler selector isNil ifTrue:[
|
|
171 |
"it was just a comment or other empty stuff"
|
|
172 |
^ nil
|
|
173 |
].
|
|
174 |
|
3
|
175 |
"produce symbolic code first"
|
0
|
176 |
|
|
177 |
symbolicCodeArray := compiler genSymbolicCode.
|
|
178 |
(symbolicCodeArray == #Error) ifTrue:[
|
|
179 |
compiler selector notNil ifTrue:[
|
|
180 |
Transcript show:(compiler selector,' ')
|
|
181 |
].
|
|
182 |
Transcript showCr:'translation error'.
|
|
183 |
^ #Error
|
|
184 |
].
|
|
185 |
|
|
186 |
((compiler genByteCodeFrom:symbolicCodeArray) == #Error) ifTrue:[
|
|
187 |
compiler selector notNil ifTrue:[
|
|
188 |
Transcript show:(compiler selector,' ')
|
|
189 |
].
|
|
190 |
Transcript showCr:'relocation error - must be simplified'.
|
|
191 |
^ #Error
|
|
192 |
].
|
|
193 |
|
12
|
194 |
(OperatingSystem getSystemType = 'hpux') ifFalse:[
|
|
195 |
"check for primitive code"
|
|
196 |
compiler primitiveNumber notNil ifTrue:[
|
|
197 |
machineCode := compiler checkForPrimitiveCode:compiler primitiveNumber.
|
|
198 |
machineCode isNil ifTrue:[
|
|
199 |
Transcript showCr:'primitive ', compiler primitiveNumber printString , ' is not supported'.
|
|
200 |
^ #Error
|
|
201 |
]
|
|
202 |
].
|
0
|
203 |
|
12
|
204 |
machineCode isNil ifTrue:[
|
|
205 |
"check for shared-code (only trivial methods)"
|
0
|
206 |
|
12
|
207 |
sharedCodeSymbol := compiler checkForSharedCode:symbolicCodeArray.
|
|
208 |
sharedCodeSymbol notNil ifTrue:[
|
|
209 |
sharedCode := self sharedCodeFunctionFor:sharedCodeSymbol
|
|
210 |
].
|
|
211 |
"try to make it machine code"
|
|
212 |
|
|
213 |
machineCode := compiler checkForMachineCode:symbolicCodeArray
|
0
|
214 |
].
|
|
215 |
].
|
|
216 |
|
|
217 |
"finally create the new method-object"
|
|
218 |
|
|
219 |
newMethod := Method new.
|
|
220 |
lits := compiler literalArray.
|
|
221 |
lits notNil ifTrue:[
|
|
222 |
"literals MUST be an array - not just any Collection"
|
|
223 |
lits := Array withAll:lits.
|
|
224 |
newMethod literals:lits
|
|
225 |
].
|
|
226 |
newMethod byteCode:(compiler code).
|
|
227 |
sharedCode notNil ifTrue:[
|
|
228 |
newMethod code:sharedCode
|
|
229 |
] ifFalse:[
|
|
230 |
machineCode notNil ifTrue:[
|
6
|
231 |
newMethod code:machineCode.
|
12
|
232 |
newMethod dynamic:true
|
0
|
233 |
]
|
|
234 |
].
|
|
235 |
newMethod source:aString.
|
|
236 |
newMethod category:cat.
|
|
237 |
newMethod numberOfMethodVars:(compiler numberOfMethodVars).
|
13
|
238 |
newMethod numberOfMethodArgs:(compiler numberOfMethodArgs).
|
0
|
239 |
newMethod stackSize:(compiler maxStackDepth).
|
|
240 |
|
|
241 |
install ifTrue:[
|
|
242 |
aClass addSelector:(compiler selector) withMethod:newMethod
|
|
243 |
].
|
|
244 |
|
|
245 |
SilentLoading ifFalse:[
|
|
246 |
Transcript showCr:('compiled: ',aClass name,' ',compiler selector)
|
|
247 |
].
|
|
248 |
|
|
249 |
^ newMethod
|
|
250 |
! !
|
|
251 |
|
|
252 |
!ByteCodeCompiler methodsFor:'accessing'!
|
|
253 |
|
|
254 |
literalArray
|
|
255 |
"return the literal array - only valid after parsing"
|
|
256 |
|
|
257 |
^ litArray
|
|
258 |
!
|
|
259 |
|
|
260 |
code
|
3
|
261 |
"return the bytecode array - only valid after code-generation"
|
0
|
262 |
|
|
263 |
^ code
|
|
264 |
!
|
|
265 |
|
|
266 |
maxStackDepth
|
|
267 |
"return the stack-need of the method - only valid after code-generation"
|
|
268 |
|
|
269 |
^ maxStackDepth
|
|
270 |
! !
|
|
271 |
|
|
272 |
!ByteCodeCompiler methodsFor:'code generation'!
|
|
273 |
|
|
274 |
genSymbolicCode
|
|
275 |
"traverse the parse-tree producing symbolicCode - return the codeArray"
|
|
276 |
|
|
277 |
|codeStream thisStatement lastStatement|
|
|
278 |
|
|
279 |
codeStream := WriteStream on:(Array new:100).
|
|
280 |
thisStatement := tree.
|
|
281 |
[thisStatement notNil] whileTrue:[
|
|
282 |
lastStatement := thisStatement.
|
|
283 |
thisStatement codeForSideEffectOn:codeStream inBlock:nil.
|
|
284 |
thisStatement := thisStatement nextStatement
|
|
285 |
].
|
|
286 |
(lastStatement isNil or:[(lastStatement isMemberOf:ReturnNode) not])
|
|
287 |
ifTrue:[
|
|
288 |
"not a return - add retSelf"
|
|
289 |
codeStream nextPut:#retSelf
|
|
290 |
].
|
|
291 |
^ codeStream contents
|
|
292 |
!
|
|
293 |
|
|
294 |
checkForPrimitiveCode:primNr
|
|
295 |
"this was added to allow emulation of (some) ST-80
|
|
296 |
primitives (to fileIn Remote-Package)"
|
|
297 |
|
3
|
298 |
|cls sel|
|
|
299 |
|
|
300 |
(primNr == 75) ifTrue:[ cls := Object. sel := #identityHash ].
|
|
301 |
(primNr == 110) ifTrue:[ cls := Object. sel := #== ].
|
|
302 |
(primNr == 111) ifTrue:[ cls := Object. sel := #class ].
|
|
303 |
cls notNil ifTrue:[
|
|
304 |
^ (cls compiledMethodAt:sel) code
|
|
305 |
].
|
0
|
306 |
^ nil
|
|
307 |
!
|
|
308 |
|
|
309 |
genByteCodeFrom:symbolicCodeArray
|
|
310 |
"convert symbolicCode into bytecodes"
|
|
311 |
|
|
312 |
|symIndex "<SmallInteger>"
|
|
313 |
codeSize "<SmallInteger>"
|
|
314 |
symCodeSize "<SmallInteger>"
|
|
315 |
index addr
|
|
316 |
codeSymbol nargs done
|
|
317 |
stackDepth relocInfo level nvars|
|
|
318 |
|
|
319 |
symbolicCodeArray isNil ifTrue:[^ self].
|
|
320 |
|
|
321 |
done := false.
|
|
322 |
symCodeSize := symbolicCodeArray size.
|
|
323 |
codeSize := symCodeSize.
|
|
324 |
|
|
325 |
[done] whileFalse:[
|
|
326 |
litArray := nil.
|
|
327 |
stackDepth := 0.
|
|
328 |
maxStackDepth := 0.
|
|
329 |
|
3
|
330 |
code := ByteArray uninitializedNew:codeSize.
|
0
|
331 |
relocInfo := Array new:(codeSize + 1).
|
|
332 |
symIndex := 1.
|
|
333 |
codeIndex := 1.
|
|
334 |
|
|
335 |
[symIndex <= symCodeSize] whileTrue:[
|
|
336 |
relocInfo at:symIndex put:codeIndex.
|
|
337 |
|
|
338 |
codeSymbol := symbolicCodeArray at:symIndex.
|
|
339 |
symIndex := symIndex + 1.
|
|
340 |
stackDelta := 0.
|
|
341 |
extra := nil.
|
|
342 |
lineno := false.
|
|
343 |
self appendByteCodeFor:codeSymbol.
|
|
344 |
lineno ifTrue:[
|
|
345 |
self appendByte:((symbolicCodeArray at:symIndex) min:255).
|
|
346 |
symIndex := symIndex + 1
|
|
347 |
].
|
|
348 |
extra notNil ifTrue:[
|
|
349 |
(extra == #number) ifTrue:[
|
|
350 |
index := symbolicCodeArray at:symIndex.
|
|
351 |
symIndex := symIndex + 1.
|
|
352 |
self appendSignedByte:index
|
|
353 |
] ifFalse:[
|
|
354 |
(extra == #index) ifTrue:[
|
|
355 |
index := symbolicCodeArray at:symIndex.
|
|
356 |
symIndex := symIndex + 1.
|
|
357 |
self appendByte:index
|
|
358 |
] ifFalse:[
|
|
359 |
(extra == #lit) ifTrue:[
|
|
360 |
index := self addLiteral:(symbolicCodeArray at:symIndex).
|
|
361 |
symIndex := symIndex + 1.
|
|
362 |
self appendByte:index
|
|
363 |
] ifFalse:[
|
|
364 |
(extra == #speciallit) ifTrue:[
|
|
365 |
index := self addLiteral:(symbolicCodeArray at:symIndex).
|
|
366 |
symIndex := symIndex + 1.
|
|
367 |
self appendByte:index.
|
|
368 |
self appendByte:0. "space for inline-generation"
|
|
369 |
self appendByte:0. "space for inline-address"
|
|
370 |
self appendByte:0.
|
|
371 |
self appendByte:0.
|
|
372 |
self appendByte:0.
|
|
373 |
symIndex := symIndex + 5
|
|
374 |
] ifFalse:[
|
|
375 |
(extra == #offset) ifTrue:[
|
|
376 |
relocInfo at:symIndex put:codeIndex.
|
|
377 |
self addReloc:symIndex.
|
|
378 |
symIndex := symIndex + 1.
|
|
379 |
self appendByte:0
|
|
380 |
] ifFalse:[
|
|
381 |
(extra == #indexLevel) ifTrue:[
|
|
382 |
index := symbolicCodeArray at:symIndex.
|
|
383 |
symIndex := symIndex + 1.
|
|
384 |
self appendByte:index.
|
|
385 |
level := symbolicCodeArray at:symIndex.
|
|
386 |
symIndex := symIndex + 1.
|
|
387 |
self appendByte:level
|
|
388 |
] ifFalse:[
|
|
389 |
(extra == #offsetNvarNarg) ifTrue:[
|
|
390 |
relocInfo at:symIndex put:codeIndex.
|
|
391 |
self addReloc:symIndex.
|
|
392 |
symIndex := symIndex + 1.
|
|
393 |
self appendByte:0.
|
|
394 |
nvars := symbolicCodeArray at:symIndex.
|
|
395 |
symIndex := symIndex + 1.
|
|
396 |
self appendByte:nvars.
|
|
397 |
level := symbolicCodeArray at:symIndex.
|
|
398 |
symIndex := symIndex + 1.
|
|
399 |
self appendByte:level
|
|
400 |
] ifFalse:[
|
|
401 |
(extra == #absoffset) ifTrue:[
|
1
|
402 |
relocInfo at:symIndex put:codeIndex.
|
3
|
403 |
self addReloc:symIndex.
|
0
|
404 |
addr := symbolicCodeArray at:symIndex.
|
|
405 |
symIndex := symIndex + 1.
|
|
406 |
self appendByte:(addr bitAnd:16rFF).
|
|
407 |
self appendByte:((addr bitShift:-8) bitAnd:16rFF).
|
|
408 |
] ifFalse:[
|
1
|
409 |
(extra == #absoffsetNvarNarg) ifTrue:[
|
|
410 |
relocInfo at:symIndex put:codeIndex.
|
3
|
411 |
self addReloc:symIndex.
|
1
|
412 |
addr := symbolicCodeArray at:symIndex.
|
|
413 |
symIndex := symIndex + 1.
|
|
414 |
self appendByte:(addr bitAnd:16rFF).
|
|
415 |
self appendByte:((addr bitShift:-8) bitAnd:16rFF).
|
|
416 |
nvars := symbolicCodeArray at:symIndex.
|
|
417 |
symIndex := symIndex + 1.
|
|
418 |
self appendByte:nvars.
|
|
419 |
level := symbolicCodeArray at:symIndex.
|
|
420 |
symIndex := symIndex + 1.
|
|
421 |
self appendByte:level
|
|
422 |
] ifFalse:[
|
|
423 |
self error:'compiler botch'
|
|
424 |
]
|
0
|
425 |
]
|
|
426 |
]
|
|
427 |
]
|
|
428 |
]
|
|
429 |
]
|
|
430 |
]
|
|
431 |
]
|
|
432 |
]
|
|
433 |
].
|
|
434 |
((codeSymbol == #send) or:[codeSymbol == #superSend]) ifTrue:[
|
|
435 |
index := self addLiteral:(symbolicCodeArray at:symIndex).
|
|
436 |
symIndex := symIndex + 1.
|
|
437 |
nargs := symbolicCodeArray at:symIndex.
|
|
438 |
symIndex := symIndex + 1.
|
|
439 |
self appendByte:nargs.
|
|
440 |
self appendByte:index.
|
|
441 |
(codeSymbol == #superSend) ifTrue:[
|
|
442 |
symIndex := symIndex + 1.
|
|
443 |
index := self addLiteral:(classToCompileFor superclass).
|
|
444 |
self appendByte:index
|
|
445 |
].
|
|
446 |
stackDelta := nargs negated
|
|
447 |
] ifFalse:[
|
|
448 |
(codeSymbol == #sendDrop) ifTrue:[
|
|
449 |
index := self addLiteral:(symbolicCodeArray at:symIndex).
|
|
450 |
symIndex := symIndex + 1.
|
|
451 |
nargs := symbolicCodeArray at:symIndex.
|
|
452 |
symIndex := symIndex + 1.
|
|
453 |
self appendByte:nargs.
|
|
454 |
self appendByte:index.
|
|
455 |
stackDelta := (nargs + 1) negated
|
|
456 |
]
|
|
457 |
].
|
|
458 |
stackDepth := stackDepth + stackDelta.
|
|
459 |
(stackDepth > maxStackDepth) ifTrue:[
|
|
460 |
maxStackDepth := stackDepth
|
|
461 |
]
|
|
462 |
].
|
|
463 |
relocInfo at:symIndex put:codeIndex.
|
|
464 |
|
|
465 |
"relocate - returns true if ok, false if we have to rerun"
|
|
466 |
done := true.
|
|
467 |
relocList notNil ifTrue:[
|
|
468 |
done := self relocateWith:symbolicCodeArray relocInfo:relocInfo.
|
1
|
469 |
"if returned with false, a relative jump was made into
|
|
470 |
an absolute jump - need to start over with one more byte space"
|
3
|
471 |
done ifFalse:[
|
|
472 |
relocList := nil.
|
|
473 |
codeSize := codeSize + 1.
|
|
474 |
]
|
0
|
475 |
].
|
|
476 |
].
|
|
477 |
"code printNewline."
|
|
478 |
^ errorFlag
|
|
479 |
!
|
|
480 |
|
1
|
481 |
absJumpFromJump:code
|
3
|
482 |
"given a jump-symbolic code, return corresponding absolute jump"
|
|
483 |
|
1
|
484 |
JumpToAbsJump isNil ifTrue:[
|
3
|
485 |
JumpToAbsJump := IdentityDictionary new.
|
|
486 |
JumpToAbsJump at:#jump put:#jumpabs.
|
|
487 |
JumpToAbsJump at:#trueJump put:#trueJumpabs.
|
|
488 |
JumpToAbsJump at:#falseJump put:#falseJumpabs.
|
|
489 |
JumpToAbsJump at:#nilJump put:#nilJumpabs.
|
|
490 |
JumpToAbsJump at:#notNilJump put:#notNilJumpabs.
|
|
491 |
JumpToAbsJump at:#eqJump put:#eqJumpabs.
|
|
492 |
JumpToAbsJump at:#notEqJump put:#notEqJumpabs.
|
|
493 |
JumpToAbsJump at:#zeroJump put:#zeroJumpabs.
|
|
494 |
JumpToAbsJump at:#notZeroJump put:#notZeroJumpabs.
|
|
495 |
JumpToAbsJump at:#makeBlock put:#makeBlockabs.
|
1
|
496 |
].
|
|
497 |
^ JumpToAbsJump at:code
|
|
498 |
!
|
|
499 |
|
0
|
500 |
relocateWith:symbolicCodeArray relocInfo:relocInfo
|
|
501 |
"helper for genByteCodeFrom - relocate code using relocInfo.
|
|
502 |
if relocation fails badly (due to long relative jumps) patch
|
|
503 |
symbolicCode to use absolute jumps instead and return false
|
3
|
504 |
(genByteCodeFrom will then try again). Otherwise return true.
|
|
505 |
Also, on the fly, jumps to jumps and jumps to return are handled."
|
0
|
506 |
|
|
507 |
|delta "<SmallInteger>"
|
|
508 |
codePos "<SmallInteger>"
|
1
|
509 |
opCodePos "<SmallInteger>"
|
0
|
510 |
codeOffset "<SmallInteger>"
|
|
511 |
symOffset opcode dstOpcode jumpTarget
|
3
|
512 |
jumpCode deleteSet|
|
0
|
513 |
|
3
|
514 |
deleteSet := OrderedCollection new.
|
0
|
515 |
relocList do:[:sIndex |
|
1
|
516 |
"have to relocate symCode at sIndex ..."
|
3
|
517 |
symOffset := symbolicCodeArray at:sIndex. "the target in the symbolic code"
|
|
518 |
codePos := relocInfo at:sIndex. "position of the offet in byte code"
|
|
519 |
codeOffset := relocInfo at:symOffset. "position of the target in byte code"
|
0
|
520 |
delta := codeOffset - codePos - 1.
|
1
|
521 |
opCodePos := codePos - 1.
|
|
522 |
opcode := code at:opCodePos.
|
|
523 |
|
3
|
524 |
(opcode between:190 and:199) ifTrue:[
|
|
525 |
"an absolute jump/makeBlock"
|
0
|
526 |
|
3
|
527 |
code at:codePos put:(codeOffset bitAnd:16rFF).
|
|
528 |
code at:(codePos + 1) put:(codeOffset bitShift:-8)
|
|
529 |
] ifFalse:[
|
|
530 |
"get jump-code from long and vlong codes"
|
|
531 |
(opcode between:50 and:59) ifFalse:[
|
|
532 |
(opcode between:60 and:69) ifTrue:[
|
|
533 |
opcode := opcode - 10
|
|
534 |
] ifFalse:[
|
|
535 |
(opcode between:70 and:79) ifTrue:[
|
|
536 |
opcode := opcode - 20
|
|
537 |
] ifFalse:[
|
1
|
538 |
self error:'invalid code to relocate'
|
3
|
539 |
]
|
1
|
540 |
].
|
3
|
541 |
].
|
1
|
542 |
|
|
543 |
"optimize jump to return and jump to jump"
|
|
544 |
|
|
545 |
(opcode == 54) ifTrue:[
|
|
546 |
"a jump"
|
|
547 |
dstOpcode := symbolicCodeArray at:symOffset.
|
3
|
548 |
|
|
549 |
(#(retSelf retTop retNil retTrue retFalse ret0 blockRetTop) includes:dstOpcode) ifTrue:[
|
1
|
550 |
"a jump to a return - put in the return instead jump"
|
3
|
551 |
|
|
552 |
symbolicCodeArray at:(sIndex - 1) put:dstOpcode.
|
|
553 |
symbolicCodeArray at:sIndex put:dstOpcode.
|
1
|
554 |
code at:opCodePos put:(self byteCodeFor:dstOpcode).
|
3
|
555 |
delta := 0.
|
|
556 |
deleteSet add:sIndex.
|
|
557 |
|
|
558 |
"
|
|
559 |
'jump to return at: ' print. (sIndex - 1) printNewline.
|
|
560 |
"
|
1
|
561 |
] ifFalse:[
|
|
562 |
(dstOpcode == #jump) ifTrue:[
|
|
563 |
"jump to jump to be done soon"
|
3
|
564 |
jumpTarget := symbolicCodeArray at:(symOffset + 1).
|
|
565 |
"
|
|
566 |
'jump to jump at: ' print. (sIndex - 1) print.
|
|
567 |
' newTarget:' print. jumpTarget printNewline.
|
|
568 |
"
|
|
569 |
|
|
570 |
symbolicCodeArray at:sIndex put:jumpTarget.
|
|
571 |
symOffset := jumpTarget.
|
|
572 |
codeOffset := relocInfo at:symOffset.
|
|
573 |
delta := codeOffset - codePos - 1.
|
|
574 |
|
|
575 |
"continue with new delta"
|
1
|
576 |
]
|
0
|
577 |
]
|
1
|
578 |
].
|
3
|
579 |
(#(50 51 52 53 56 57 58 59) includes:opcode) ifTrue:[
|
|
580 |
"a conditional jump"
|
|
581 |
|
|
582 |
dstOpcode := symbolicCodeArray at:symOffset.
|
|
583 |
(dstOpcode == #jump) ifTrue:[
|
|
584 |
"conditional jump to unconditional jump"
|
|
585 |
jumpTarget := symbolicCodeArray at:(symOffset + 1).
|
|
586 |
"
|
|
587 |
'cond jump to jump at: ' print. (sIndex - 1) print.
|
|
588 |
' newTarget:' print. jumpTarget printNewline.
|
|
589 |
"
|
|
590 |
|
|
591 |
symbolicCodeArray at:sIndex put:jumpTarget.
|
|
592 |
symOffset := jumpTarget.
|
|
593 |
codeOffset := relocInfo at:symOffset.
|
|
594 |
delta := codeOffset - codePos - 1.
|
|
595 |
|
|
596 |
"continue with new delta"
|
|
597 |
].
|
|
598 |
].
|
|
599 |
|
1
|
600 |
(delta >= 0) ifTrue:[
|
0
|
601 |
(delta > 127) ifTrue:[
|
1
|
602 |
(opcode between:50 and:59) ifFalse:[
|
|
603 |
self error:'invalid code to relocate'
|
0
|
604 |
].
|
1
|
605 |
(delta > 255) ifTrue:[
|
|
606 |
"change jmp into vljmp ..."
|
|
607 |
code at:opCodePos put:(opcode + 20).
|
|
608 |
delta := delta - 256
|
|
609 |
] ifFalse:[
|
|
610 |
"change jmp into ljmp ..."
|
|
611 |
code at:opCodePos put:(opcode + 10).
|
|
612 |
delta := delta - 128
|
0
|
613 |
].
|
1
|
614 |
(delta > 127) ifTrue:[
|
|
615 |
"change symbolic into a jump absolute and fail"
|
|
616 |
jumpCode := symbolicCodeArray at:(sIndex - 1).
|
3
|
617 |
symbolicCodeArray at:(sIndex - 1) put:(self absJumpFromJump:jumpCode).
|
1
|
618 |
symbolicCodeArray at:sIndex put:symOffset.
|
3
|
619 |
"
|
|
620 |
'change short into abs jump' printNewline.
|
|
621 |
"
|
|
622 |
deleteSet do:[:d | relocList remove:d].
|
0
|
623 |
^ false
|
|
624 |
].
|
1
|
625 |
].
|
|
626 |
code at:codePos put:delta
|
|
627 |
] ifFalse:[
|
|
628 |
(delta < -128) ifTrue:[
|
|
629 |
(opcode between:50 and:59) ifFalse:[
|
|
630 |
self error:'invalid code to relocate'
|
0
|
631 |
].
|
1
|
632 |
(delta < -256) ifTrue:[
|
|
633 |
"change jmp into vljmp ..."
|
|
634 |
code at:opCodePos put:(opcode + 20).
|
|
635 |
delta := delta + 256
|
|
636 |
] ifFalse:[
|
|
637 |
"change jmp into ljmp ..."
|
|
638 |
code at:opCodePos put:(opcode + 10).
|
|
639 |
delta := delta + 128
|
0
|
640 |
].
|
1
|
641 |
(delta < -128) ifTrue:[
|
|
642 |
"change symbolic into a jump absolute and fail"
|
|
643 |
jumpCode := symbolicCodeArray at:(sIndex - 1).
|
3
|
644 |
symbolicCodeArray at:(sIndex - 1) put:(self absJumpFromJump:jumpCode).
|
1
|
645 |
symbolicCodeArray at:sIndex put:symOffset.
|
3
|
646 |
"
|
|
647 |
'change short into abs jump' printNewline.
|
|
648 |
"
|
|
649 |
deleteSet do:[:d | relocList remove:d].
|
1
|
650 |
^ false
|
|
651 |
]
|
0
|
652 |
].
|
1
|
653 |
code at:codePos put:(256 + delta)
|
|
654 |
]
|
0
|
655 |
]
|
|
656 |
].
|
|
657 |
(errorFlag == #Error) ifTrue:[
|
|
658 |
self error:'relocation range error'
|
|
659 |
].
|
|
660 |
^ true
|
|
661 |
!
|
|
662 |
|
|
663 |
addLiteral:anObject
|
|
664 |
"add a literal to the literalArray - watch for and eliminate
|
|
665 |
duplicates. return the index of the literal in the Array"
|
|
666 |
|
3
|
667 |
|index class|
|
0
|
668 |
|
|
669 |
litArray isNil ifTrue:[
|
|
670 |
litArray := Array with:anObject.
|
|
671 |
^ 1
|
|
672 |
].
|
|
673 |
index := litArray identityIndexOf:anObject.
|
|
674 |
(index == 0) ifTrue:[
|
3
|
675 |
class := anObject class.
|
|
676 |
((class == Float) or:[class == Fraction]) ifTrue:[
|
|
677 |
index := litArray indexOf:anObject.
|
|
678 |
].
|
|
679 |
(index == 0) ifTrue:[
|
|
680 |
litArray := litArray copyWith:anObject.
|
|
681 |
^ litArray size
|
|
682 |
].
|
0
|
683 |
].
|
|
684 |
^ index
|
|
685 |
!
|
|
686 |
|
|
687 |
appendByteCodeFor:codeSymbol
|
|
688 |
"append the byteCode for an instructionSymbol to the code-Array"
|
|
689 |
|
|
690 |
code at:codeIndex put:(self byteCodeFor:codeSymbol).
|
|
691 |
codeIndex := codeIndex + 1
|
|
692 |
!
|
|
693 |
|
|
694 |
appendByte:aByte
|
|
695 |
"append a byte to the code-Array, checking for byte-range (debug-only)"
|
|
696 |
|
|
697 |
(aByte between:0 and:255) ifTrue:[
|
|
698 |
code at:codeIndex put:aByte.
|
|
699 |
codeIndex := codeIndex + 1
|
|
700 |
] ifFalse:[
|
|
701 |
self error:'byte range error'.
|
|
702 |
errorFlag := #Error
|
|
703 |
]
|
|
704 |
!
|
|
705 |
|
|
706 |
appendSignedByte:aByte
|
|
707 |
"append a signedbyte (as in jump-offsets) to the code-Array,
|
|
708 |
check range and report an error if invalid"
|
|
709 |
|
|
710 |
|b "<SmallInteger>" |
|
|
711 |
|
|
712 |
b := aByte.
|
|
713 |
(b >= 0) ifTrue:[
|
|
714 |
(b > 127) ifTrue:[
|
|
715 |
self error:'jump-range error'.
|
|
716 |
errorFlag := #Error
|
|
717 |
].
|
|
718 |
code at:codeIndex put:b
|
|
719 |
] ifFalse:[
|
|
720 |
(b < -128) ifTrue:[
|
|
721 |
self error:'jump-range error'.
|
|
722 |
errorFlag := #Error
|
|
723 |
].
|
|
724 |
code at:codeIndex put:(256 + b)
|
|
725 |
].
|
|
726 |
codeIndex := codeIndex + 1
|
|
727 |
!
|
|
728 |
|
|
729 |
addReloc:symIndex
|
|
730 |
"remember to relocate offset at symIndex later ..."
|
|
731 |
|
|
732 |
relocList isNil ifTrue:[
|
|
733 |
relocList := OrderedCollection new.
|
|
734 |
].
|
|
735 |
relocList add:symIndex
|
|
736 |
!
|
|
737 |
|
|
738 |
byteCodeFor:aSymbol
|
|
739 |
"given a symbolic instruction, return the corresponding bytecode.
|
|
740 |
as a side-effect, leave number of bytes pushed/popped by this instr.
|
|
741 |
in stackDelta, and, if the instruction needs extra arguments, leave
|
|
742 |
this info in extra"
|
|
743 |
|
|
744 |
"standard bytecodes"
|
|
745 |
|
|
746 |
(aSymbol == #pushNil) ifTrue:[stackDelta := 1. ^ 10].
|
|
747 |
(aSymbol == #pushTrue) ifTrue:[stackDelta := 1. ^ 11].
|
|
748 |
(aSymbol == #pushFalse) ifTrue:[stackDelta := 1. ^ 12].
|
|
749 |
(aSymbol == #pushLit) ifTrue:[stackDelta := 1. extra := #lit. ^ 14].
|
|
750 |
(aSymbol == #pushSelf) ifTrue:[stackDelta := 1. ^ 15].
|
|
751 |
(aSymbol == #pushNum) ifTrue:[stackDelta := 1. extra := #number. ^ 16].
|
|
752 |
|
|
753 |
(aSymbol == #pushMethodArg) ifTrue:[stackDelta := 1. extra := #index. ^ 30].
|
|
754 |
(aSymbol == #pushMethodVar) ifTrue:[stackDelta := 1. extra := #index. ^ 31].
|
|
755 |
(aSymbol == #pushBlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 32].
|
|
756 |
(aSymbol == #pushBlockVar) ifTrue:[stackDelta := 1. extra := #index. ^ 33].
|
|
757 |
(aSymbol == #pushInstVar) ifTrue:[stackDelta := 1. extra := #index. ^ 34].
|
1
|
758 |
(aSymbol == #pushOuterBlockArg) ifTrue:[stackDelta := 1. extra := #indexLevel. ^ 42].
|
|
759 |
(aSymbol == #pushOuterBlockVar) ifTrue:[stackDelta := 1. extra := #indexLevel. ^ 128].
|
0
|
760 |
|
1
|
761 |
(aSymbol == #storeMethodVar) ifTrue:[extra := #index. stackDelta := -1. ^ 37].
|
|
762 |
(aSymbol == #storeBlockVar) ifTrue:[extra := #index. stackDelta := -1. ^ 38].
|
|
763 |
(aSymbol == #storeInstVar) ifTrue:[extra := #index. stackDelta := -1. ^ 39].
|
0
|
764 |
|
|
765 |
(aSymbol == #retTop) ifTrue:[stackDelta := -1. ^ 0].
|
|
766 |
(aSymbol == #blockRetTop) ifTrue:[stackDelta := -1. ^ 6].
|
|
767 |
|
|
768 |
(aSymbol == #retSelf) ifTrue:[^5].
|
|
769 |
|
|
770 |
(aSymbol == #==) ifTrue:[stackDelta := -1. self addLiteral:aSymbol. ^ 45].
|
|
771 |
(aSymbol == #~~) ifTrue:[stackDelta := -1. self addLiteral:aSymbol. ^ 46].
|
|
772 |
|
|
773 |
(aSymbol == #falseJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 50].
|
|
774 |
(aSymbol == #trueJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 51].
|
|
775 |
(aSymbol == #nilJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 52].
|
|
776 |
(aSymbol == #notNilJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 53].
|
|
777 |
(aSymbol == #jump) ifTrue:[extra := #offset. ^ 54].
|
1
|
778 |
(aSymbol == #makeBlock) ifTrue:[stackDelta := 1. extra := #offsetNvarNarg. ^ 55].
|
0
|
779 |
(aSymbol == #zeroJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 56].
|
|
780 |
(aSymbol == #notZeroJump) ifTrue:[stackDelta := -1. extra := #offset. ^ 57].
|
|
781 |
(aSymbol == #eqJump) ifTrue:[stackDelta := -2. extra := #offset. ^ 58].
|
|
782 |
(aSymbol == #notEqJump) ifTrue:[stackDelta := -2. extra := #offset. ^ 59].
|
|
783 |
|
|
784 |
(aSymbol == #send) ifTrue:[lineno := true. ^ 19].
|
|
785 |
(aSymbol == #superSend) ifTrue:[lineno := true. ^ 20].
|
|
786 |
|
|
787 |
(aSymbol == #drop) ifTrue:[stackDelta := -1. ^ 18].
|
|
788 |
(aSymbol == #dup) ifTrue:[stackDelta := 1. ^ 47].
|
|
789 |
|
|
790 |
(aSymbol == #pushClassVar) ifTrue:[stackDelta := 1. extra := #speciallit. ^ 35].
|
|
791 |
(aSymbol == #pushClassInstVar) ifTrue:[stackDelta := 1. extra := #index. ^ 176].
|
|
792 |
(aSymbol == #pushGlobal) ifTrue:[stackDelta := 1. extra := #speciallit. ^ 36].
|
|
793 |
|
|
794 |
(aSymbol == #storeClassVar) ifTrue:[extra := #speciallit.stackDelta := -1. ^ 40].
|
|
795 |
(aSymbol == #storeClassInstVar) ifTrue:[extra := #index.stackDelta := -1. ^ 177].
|
|
796 |
(aSymbol == #storeGlobal) ifTrue:[extra := #speciallit. stackDelta := -1. ^ 41].
|
1
|
797 |
(aSymbol == #storeOuterBlockVar) ifTrue:[stackDelta := -1. extra := #indexLevel. ^ 129].
|
0
|
798 |
|
|
799 |
"optimized bytecodes"
|
|
800 |
|
|
801 |
(aSymbol == #retNil) ifTrue:[^ 1].
|
|
802 |
(aSymbol == #retTrue) ifTrue:[^ 2].
|
|
803 |
(aSymbol == #retFalse) ifTrue:[^ 3].
|
|
804 |
(aSymbol == #ret0) ifTrue:[^ 4].
|
|
805 |
(aSymbol == #retNum) ifTrue:[extra := #number. ^ 127].
|
|
806 |
|
|
807 |
(aSymbol == #pushChar) ifTrue:[stackDelta := 1. ^17].
|
|
808 |
(aSymbol == #push0) ifTrue:[stackDelta := 1. ^120].
|
|
809 |
(aSymbol == #push1) ifTrue:[stackDelta := 1. ^121].
|
3
|
810 |
(aSymbol == #push2) ifTrue:[stackDelta := 1. ^139].
|
0
|
811 |
(aSymbol == #pushMinus1) ifTrue:[stackDelta := 1. ^122].
|
|
812 |
|
|
813 |
(aSymbol == #send0) ifTrue:[lineno := true. extra := #lit. ^21].
|
|
814 |
(aSymbol == #send1) ifTrue:[lineno := true. extra := #lit. stackDelta := -1. ^22].
|
|
815 |
(aSymbol == #send2) ifTrue:[lineno := true. extra := #lit. stackDelta := -2. ^23].
|
|
816 |
(aSymbol == #send3) ifTrue:[lineno := true. extra := #lit. stackDelta := -3. ^24].
|
|
817 |
|
|
818 |
(aSymbol == #sendSelf0) ifTrue:[lineno := true. extra := #lit. stackDelta := 1. ^180].
|
|
819 |
(aSymbol == #sendSelf1) ifTrue:[lineno := true. extra := #lit. ^181].
|
|
820 |
(aSymbol == #sendSelf2) ifTrue:[lineno := true. extra := #lit. stackDelta := -1. ^182].
|
|
821 |
(aSymbol == #sendSelf3) ifTrue:[lineno := true. extra := #lit. stackDelta := -2. ^183].
|
|
822 |
(aSymbol == #sendSelfDrop0) ifTrue:[lineno := true. extra := #lit. ^184].
|
|
823 |
(aSymbol == #sendSelfDrop1) ifTrue:[lineno := true. extra := #lit. stackDelta := -1. ^185].
|
|
824 |
(aSymbol == #sendSelfDrop2) ifTrue:[lineno := true. extra := #lit. stackDelta := -2. ^186].
|
|
825 |
(aSymbol == #sendSelfDrop3) ifTrue:[lineno := true. extra := #lit. stackDelta := -3. ^187].
|
|
826 |
|
|
827 |
(aSymbol == #sendDrop) ifTrue:[lineno := true. ^25].
|
|
828 |
(aSymbol == #sendDrop0) ifTrue:[lineno := true. extra := #lit. stackDelta := -1. ^26].
|
|
829 |
(aSymbol == #sendDrop1) ifTrue:[lineno := true. extra := #lit. stackDelta := -2. ^27].
|
|
830 |
(aSymbol == #sendDrop2) ifTrue:[lineno := true. extra := #lit. stackDelta := -3. ^28].
|
|
831 |
(aSymbol == #sendDrop3) ifTrue:[lineno := true. extra := #lit. stackDelta := -4. ^29].
|
|
832 |
|
|
833 |
(aSymbol == #pushMethodVar1) ifTrue:[stackDelta := 1. ^80].
|
|
834 |
(aSymbol == #pushMethodVar2) ifTrue:[stackDelta := 1. ^81].
|
|
835 |
(aSymbol == #pushMethodVar3) ifTrue:[stackDelta := 1. ^82].
|
|
836 |
(aSymbol == #pushMethodVar4) ifTrue:[stackDelta := 1. ^83].
|
|
837 |
(aSymbol == #pushMethodVar5) ifTrue:[stackDelta := 1. ^84].
|
|
838 |
(aSymbol == #pushMethodVar6) ifTrue:[stackDelta := 1. ^85].
|
|
839 |
|
|
840 |
(aSymbol == #pushMethodArg1) ifTrue:[stackDelta := 1. ^86].
|
|
841 |
(aSymbol == #pushMethodArg2) ifTrue:[stackDelta := 1. ^87].
|
|
842 |
(aSymbol == #pushMethodArg3) ifTrue:[stackDelta := 1. ^88].
|
|
843 |
(aSymbol == #pushMethodArg4) ifTrue:[stackDelta := 1. ^89].
|
|
844 |
|
|
845 |
(aSymbol == #pushInstVar1) ifTrue:[stackDelta := 1. ^90].
|
|
846 |
(aSymbol == #pushInstVar2) ifTrue:[stackDelta := 1. ^91].
|
|
847 |
(aSymbol == #pushInstVar3) ifTrue:[stackDelta := 1. ^92].
|
|
848 |
(aSymbol == #pushInstVar4) ifTrue:[stackDelta := 1. ^93].
|
|
849 |
(aSymbol == #pushInstVar5) ifTrue:[stackDelta := 1. ^94].
|
|
850 |
(aSymbol == #pushInstVar6) ifTrue:[stackDelta := 1. ^95].
|
|
851 |
(aSymbol == #pushInstVar7) ifTrue:[stackDelta := 1. ^96].
|
|
852 |
(aSymbol == #pushInstVar8) ifTrue:[stackDelta := 1. ^97].
|
|
853 |
(aSymbol == #pushInstVar9) ifTrue:[stackDelta := 1. ^98].
|
|
854 |
(aSymbol == #pushInstVar10) ifTrue:[stackDelta := 1. ^99].
|
|
855 |
|
|
856 |
(aSymbol == #storeMethodVar1) ifTrue:[stackDelta := -1. ^100].
|
|
857 |
(aSymbol == #storeMethodVar2) ifTrue:[stackDelta := -1. ^101].
|
|
858 |
(aSymbol == #storeMethodVar3) ifTrue:[stackDelta := -1. ^102].
|
|
859 |
(aSymbol == #storeMethodVar4) ifTrue:[stackDelta := -1. ^103].
|
|
860 |
(aSymbol == #storeMethodVar5) ifTrue:[stackDelta := -1. ^104].
|
|
861 |
(aSymbol == #storeMethodVar6) ifTrue:[stackDelta := -1. ^105].
|
|
862 |
|
|
863 |
(aSymbol == #storeInstVar1) ifTrue:[stackDelta := -1. ^110].
|
|
864 |
(aSymbol == #storeInstVar2) ifTrue:[stackDelta := -1. ^111].
|
|
865 |
(aSymbol == #storeInstVar3) ifTrue:[stackDelta := -1. ^112].
|
|
866 |
(aSymbol == #storeInstVar4) ifTrue:[stackDelta := -1. ^113].
|
|
867 |
(aSymbol == #storeInstVar5) ifTrue:[stackDelta := -1. ^114].
|
|
868 |
(aSymbol == #storeInstVar6) ifTrue:[stackDelta := -1. ^115].
|
|
869 |
(aSymbol == #storeInstVar7) ifTrue:[stackDelta := -1. ^116].
|
|
870 |
(aSymbol == #storeInstVar8) ifTrue:[stackDelta := -1. ^117].
|
|
871 |
(aSymbol == #storeInstVar9) ifTrue:[stackDelta := -1. ^118].
|
|
872 |
(aSymbol == #storeInstVar10) ifTrue:[stackDelta := -1. ^119].
|
|
873 |
|
|
874 |
(aSymbol == #retMethodVar1) ifTrue:[^160].
|
|
875 |
(aSymbol == #retMethodVar2) ifTrue:[^161].
|
|
876 |
(aSymbol == #retMethodVar3) ifTrue:[^162].
|
|
877 |
(aSymbol == #retMethodVar4) ifTrue:[^163].
|
|
878 |
(aSymbol == #retMethodVar5) ifTrue:[^164].
|
|
879 |
(aSymbol == #retMethodVar6) ifTrue:[^165].
|
|
880 |
|
|
881 |
(aSymbol == #retInstVar1) ifTrue:[^166].
|
|
882 |
(aSymbol == #retInstVar2) ifTrue:[^167].
|
|
883 |
(aSymbol == #retInstVar3) ifTrue:[^168].
|
|
884 |
(aSymbol == #retInstVar4) ifTrue:[^169].
|
|
885 |
(aSymbol == #retInstVar5) ifTrue:[^170].
|
|
886 |
(aSymbol == #retInstVar6) ifTrue:[^171].
|
|
887 |
(aSymbol == #retInstVar7) ifTrue:[^172].
|
|
888 |
(aSymbol == #retInstVar8) ifTrue:[^173].
|
|
889 |
|
|
890 |
(aSymbol == #retMethodArg1) ifTrue:[^174].
|
|
891 |
(aSymbol == #retMethodArg2) ifTrue:[^175].
|
|
892 |
|
|
893 |
(aSymbol == #pushBlockArg1) ifTrue:[stackDelta := 1. ^140].
|
|
894 |
(aSymbol == #pushBlockArg2) ifTrue:[stackDelta := 1. ^141].
|
|
895 |
(aSymbol == #pushBlockArg3) ifTrue:[stackDelta := 1. ^142].
|
|
896 |
(aSymbol == #pushBlockArg4) ifTrue:[stackDelta := 1. ^143].
|
|
897 |
|
1
|
898 |
(aSymbol == #pushOuter1BlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 43].
|
|
899 |
(aSymbol == #pushOuter2BlockArg) ifTrue:[stackDelta := 1. extra := #index. ^ 44].
|
0
|
900 |
|
5
|
901 |
(aSymbol == #=) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^130].
|
|
902 |
(aSymbol == #+) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^131].
|
|
903 |
(aSymbol == #~=) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^132].
|
|
904 |
(aSymbol == #-) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^133].
|
0
|
905 |
(aSymbol == #class) ifTrue:[self addLiteral:aSymbol. ^134].
|
5
|
906 |
(aSymbol == #x) ifTrue:[lineno := true. self addLiteral:aSymbol. ^106].
|
|
907 |
(aSymbol == #y) ifTrue:[lineno := true. self addLiteral:aSymbol. ^107].
|
|
908 |
(aSymbol == #width) ifTrue:[lineno := true. self addLiteral:aSymbol. ^108].
|
|
909 |
(aSymbol == #height) ifTrue:[lineno := true. self addLiteral:aSymbol. ^109].
|
|
910 |
(aSymbol == #origin) ifTrue:[lineno := true. self addLiteral:aSymbol. ^154].
|
|
911 |
(aSymbol == #extent) ifTrue:[lineno := true. self addLiteral:aSymbol. ^155].
|
|
912 |
(aSymbol == #at:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^135].
|
|
913 |
(aSymbol == #at:put:)ifTrue:[lineno := true. stackDelta := -2. self addLiteral:aSymbol. ^136].
|
|
914 |
(aSymbol == #bitAnd:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^137].
|
|
915 |
(aSymbol == #bitOr:) ifTrue:[lineno := true. stackDelta := -1. self addLiteral:aSymbol. ^138].
|
|
916 |
(aSymbol == #plus1) ifTrue:[lineno := true. self addLiteral:#+. ^123].
|
|
917 |
(aSymbol == #minus1) ifTrue:[lineno := true. self addLiteral:#-. ^124].
|
0
|
918 |
|
5
|
919 |
(aSymbol == #incMethodVar) ifTrue:[lineno := true. self addLiteral:#+. extra := #index. ^125].
|
|
920 |
(aSymbol == #decMethodVar) ifTrue:[lineno := true. self addLiteral:#-. extra := #index. ^126].
|
0
|
921 |
|
|
922 |
(aSymbol == #eq0) ifTrue:[self addLiteral:#==. ^48].
|
|
923 |
(aSymbol == #ne0) ifTrue:[self addLiteral:#~~. ^49].
|
|
924 |
|
5
|
925 |
(aSymbol == #>) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 145].
|
|
926 |
(aSymbol == #>=) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 146].
|
|
927 |
(aSymbol == #<) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 147].
|
|
928 |
(aSymbol == #<=) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 148].
|
|
929 |
(aSymbol == #next) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 149].
|
|
930 |
(aSymbol == #peek) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 150].
|
|
931 |
(aSymbol == #value) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 151].
|
|
932 |
(aSymbol == #value:) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -1. ^ 152].
|
6
|
933 |
(aSymbol == #value:value:) ifTrue:[lineno := true. self addLiteral:aSymbol. stackDelta := -2. ^ 178].
|
5
|
934 |
(aSymbol == #size) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 153].
|
|
935 |
(aSymbol == #asInteger) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 158].
|
|
936 |
(aSymbol == #rounded) ifTrue:[lineno := true. self addLiteral:aSymbol. ^ 159].
|
0
|
937 |
(aSymbol == #mk0Block) ifTrue:[^ 156].
|
|
938 |
(aSymbol == #mkNilBlock) ifTrue:[^ 157].
|
|
939 |
|
|
940 |
(aSymbol == #falseJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 190].
|
|
941 |
(aSymbol == #trueJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 191].
|
|
942 |
(aSymbol == #nilJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 192].
|
|
943 |
(aSymbol == #notNilJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 193].
|
|
944 |
(aSymbol == #jumpabs) ifTrue:[extra := #absoffset. ^ 194].
|
1
|
945 |
(aSymbol == #makeBlockabs) ifTrue:[stackDelta := 1. extra := #absoffsetNvarNarg. ^ 195].
|
0
|
946 |
(aSymbol == #zeroJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 196].
|
|
947 |
(aSymbol == #notZeroJumpabs) ifTrue:[stackDelta := -1. extra := #absoffset. ^ 197].
|
1
|
948 |
(aSymbol == #eqJumpabs) ifTrue:[stackDelta := -2. extra := #absoffset. ^ 198].
|
|
949 |
(aSymbol == #notEqJumpabs) ifTrue:[stackDelta := -2. extra := #absoffset. ^ 199].
|
0
|
950 |
|
|
951 |
(aSymbol == #pushThisContext) ifTrue:[stackDelta := 1. ^ 144].
|
|
952 |
|
|
953 |
self error:'invalid code symbol'.
|
|
954 |
errorFlag := #Error
|
|
955 |
! !
|
|
956 |
|
|
957 |
!ByteCodeCompiler class methodsFor:'machine code constants'!
|
|
958 |
|
|
959 |
sharedCodeFunctionFor:aSymbol
|
3
|
960 |
"return the address of a shared code-function;
|
|
961 |
the code below looks ugly, but adds some speed to instvar-access
|
|
962 |
methods"
|
0
|
963 |
|
|
964 |
|codeSymbol|
|
|
965 |
|
|
966 |
(aSymbol == #retSelf) ifTrue:[
|
|
967 |
%{
|
|
968 |
extern OBJ __retSelf();
|
|
969 |
#if defined(SYSV4) && defined(i386)
|
|
970 |
OBJ (*dummy)() = __retSelf;
|
|
971 |
#endif
|
|
972 |
RETURN ( _MKSMALLINT((int)__retSelf) );
|
|
973 |
%}
|
|
974 |
].
|
|
975 |
(aSymbol == #retNil) ifTrue:[
|
|
976 |
%{
|
|
977 |
extern OBJ __retNil();
|
|
978 |
#if defined(SYSV4) && defined(i386)
|
|
979 |
OBJ (*dummy)() = __retNil;
|
|
980 |
#endif
|
|
981 |
RETURN ( _MKSMALLINT((int)__retNil) );
|
|
982 |
%}
|
|
983 |
].
|
|
984 |
(aSymbol == #retTrue) ifTrue:[
|
|
985 |
%{
|
|
986 |
extern OBJ __retTrue();
|
|
987 |
#if defined(SYSV4) && defined(i386)
|
|
988 |
OBJ (*dummy)() = __retTrue;
|
|
989 |
#endif
|
|
990 |
RETURN ( _MKSMALLINT((int)__retTrue) );
|
|
991 |
%}
|
|
992 |
].
|
|
993 |
(aSymbol == #retFalse) ifTrue:[
|
|
994 |
%{
|
|
995 |
extern OBJ __retFalse();
|
|
996 |
#if defined(SYSV4) && defined(i386)
|
|
997 |
OBJ (*dummy)() = __retFalse;
|
|
998 |
#endif
|
|
999 |
RETURN ( _MKSMALLINT((int)__retFalse) );
|
|
1000 |
%}
|
|
1001 |
].
|
|
1002 |
(aSymbol == #ret0) ifTrue:[
|
|
1003 |
%{
|
|
1004 |
extern OBJ __ret0();
|
|
1005 |
#if defined(SYSV4) && defined(i386)
|
|
1006 |
OBJ (*dummy)() = __ret0;
|
|
1007 |
#endif
|
|
1008 |
RETURN ( _MKSMALLINT((int)__ret0) );
|
|
1009 |
%}
|
|
1010 |
].
|
|
1011 |
(aSymbol == #blockRet0) ifTrue:[
|
|
1012 |
%{
|
|
1013 |
extern OBJ __bRet0();
|
|
1014 |
#if defined(SYSV4) && defined(i386)
|
|
1015 |
OBJ (*dummy)() = __bRet0;
|
|
1016 |
#endif
|
|
1017 |
RETURN ( _MKSMALLINT((int)__bRet0) );
|
|
1018 |
%}
|
|
1019 |
].
|
|
1020 |
(aSymbol == #blockRetNil) ifTrue:[
|
|
1021 |
%{
|
|
1022 |
extern OBJ __bRetNil();
|
|
1023 |
#if defined(SYSV4) && defined(i386)
|
|
1024 |
OBJ (*dummy)() = __bRetNil;
|
|
1025 |
#endif
|
|
1026 |
RETURN ( _MKSMALLINT((int)__bRetNil) );
|
|
1027 |
%}
|
|
1028 |
].
|
|
1029 |
(aSymbol == #blockRetTrue) ifTrue:[
|
|
1030 |
%{
|
|
1031 |
extern OBJ __bRetTrue();
|
|
1032 |
#if defined(SYSV4) && defined(i386)
|
|
1033 |
OBJ (*dummy)() = __bRetTrue;
|
|
1034 |
#endif
|
|
1035 |
RETURN ( _MKSMALLINT((int)__bRetTrue) );
|
|
1036 |
%}
|
|
1037 |
].
|
|
1038 |
(aSymbol == #blockRetFalse) ifTrue:[
|
|
1039 |
%{
|
|
1040 |
extern OBJ __bRetFalse();
|
|
1041 |
#if defined(SYSV4) && defined(i386)
|
|
1042 |
OBJ (*dummy)() = __bRetFalse;
|
|
1043 |
#endif
|
|
1044 |
RETURN ( _MKSMALLINT((int)__bRetFalse) );
|
|
1045 |
%}
|
|
1046 |
].
|
|
1047 |
(aSymbol == #retInstVar1) ifTrue:[
|
|
1048 |
%{
|
|
1049 |
extern OBJ __retInst0();
|
|
1050 |
#if defined(SYSV4) && defined(i386)
|
|
1051 |
OBJ (*dummy)() = __retInst0;
|
|
1052 |
#endif
|
|
1053 |
RETURN ( _MKSMALLINT((int)__retInst0) );
|
|
1054 |
%}
|
|
1055 |
].
|
|
1056 |
(aSymbol == #retInstVar2) ifTrue:[
|
|
1057 |
%{
|
|
1058 |
extern OBJ __retInst1();
|
|
1059 |
#if defined(SYSV4) && defined(i386)
|
|
1060 |
OBJ (*dummy)() = __retInst1;
|
|
1061 |
#endif
|
|
1062 |
RETURN ( _MKSMALLINT((int)__retInst1) );
|
|
1063 |
%}
|
|
1064 |
].
|
|
1065 |
(aSymbol == #retInstVar3) ifTrue:[
|
|
1066 |
%{
|
|
1067 |
extern OBJ __retInst2();
|
|
1068 |
#if defined(SYSV4) && defined(i386)
|
|
1069 |
OBJ (*dummy)() = __retInst2;
|
|
1070 |
#endif
|
|
1071 |
RETURN ( _MKSMALLINT((int)__retInst2) );
|
|
1072 |
%}
|
|
1073 |
].
|
|
1074 |
(aSymbol == #retInstVar4) ifTrue:[
|
|
1075 |
%{
|
|
1076 |
extern OBJ __retInst3();
|
|
1077 |
#if defined(SYSV4) && defined(i386)
|
|
1078 |
OBJ (*dummy)() = __retInst3;
|
|
1079 |
#endif
|
|
1080 |
RETURN ( _MKSMALLINT((int)__retInst3) );
|
|
1081 |
%}
|
|
1082 |
].
|
|
1083 |
(aSymbol == #retInstVar5) ifTrue:[
|
|
1084 |
%{
|
|
1085 |
extern OBJ __retInst4();
|
|
1086 |
#if defined(SYSV4) && defined(i386)
|
|
1087 |
OBJ (*dummy)() = __retInst4;
|
|
1088 |
#endif
|
|
1089 |
RETURN ( _MKSMALLINT((int)__retInst4) );
|
|
1090 |
%}
|
|
1091 |
].
|
|
1092 |
(aSymbol == #retInstVar6) ifTrue:[
|
|
1093 |
%{
|
|
1094 |
extern OBJ __retInst5();
|
|
1095 |
#if defined(SYSV4) && defined(i386)
|
|
1096 |
OBJ (*dummy)() = __retInst5;
|
|
1097 |
#endif
|
|
1098 |
RETURN ( _MKSMALLINT((int)__retInst5) );
|
|
1099 |
%}
|
|
1100 |
].
|
|
1101 |
(aSymbol == #retInstVar7) ifTrue:[
|
|
1102 |
%{
|
|
1103 |
extern OBJ __retInst6();
|
|
1104 |
#if defined(SYSV4) && defined(i386)
|
|
1105 |
OBJ (*dummy)() = __retInst6;
|
|
1106 |
#endif
|
|
1107 |
RETURN ( _MKSMALLINT((int)__retInst6) );
|
|
1108 |
%}
|
|
1109 |
].
|
|
1110 |
(aSymbol == #retInstVar8) ifTrue:[
|
|
1111 |
%{
|
|
1112 |
extern OBJ __retInst7();
|
|
1113 |
#if defined(SYSV4) && defined(i386)
|
|
1114 |
OBJ (*dummy)() = __retInst7;
|
|
1115 |
#endif
|
|
1116 |
RETURN ( _MKSMALLINT((int)__retInst7) );
|
|
1117 |
%}
|
|
1118 |
].
|
1
|
1119 |
(aSymbol == #retInstVar9) ifTrue:[
|
|
1120 |
%{
|
|
1121 |
extern OBJ __retInst8();
|
|
1122 |
#if defined(SYSV4) && defined(i386)
|
|
1123 |
OBJ (*dummy)() = __retInst8;
|
|
1124 |
#endif
|
|
1125 |
RETURN ( _MKSMALLINT((int)__retInst8) );
|
|
1126 |
%}
|
|
1127 |
].
|
|
1128 |
(aSymbol == #retInstVar10) ifTrue:[
|
|
1129 |
%{
|
|
1130 |
extern OBJ __retInst9();
|
|
1131 |
#if defined(SYSV4) && defined(i386)
|
|
1132 |
OBJ (*dummy)() = __retInst9;
|
|
1133 |
#endif
|
|
1134 |
RETURN ( _MKSMALLINT((int)__retInst9) );
|
|
1135 |
%}
|
|
1136 |
].
|
|
1137 |
(aSymbol == #retInstVar11) ifTrue:[
|
|
1138 |
%{
|
|
1139 |
extern OBJ __retInst10();
|
|
1140 |
#if defined(SYSV4) && defined(i386)
|
|
1141 |
OBJ (*dummy)() = __retInst10;
|
|
1142 |
#endif
|
|
1143 |
RETURN ( _MKSMALLINT((int)__retInst10) );
|
|
1144 |
%}
|
|
1145 |
].
|
|
1146 |
(aSymbol == #retInstVar12) ifTrue:[
|
|
1147 |
%{
|
|
1148 |
extern OBJ __retInst11();
|
|
1149 |
#if defined(SYSV4) && defined(i386)
|
|
1150 |
OBJ (*dummy)() = __retInst11;
|
|
1151 |
#endif
|
|
1152 |
RETURN ( _MKSMALLINT((int)__retInst11) );
|
|
1153 |
%}
|
|
1154 |
].
|
|
1155 |
(aSymbol == #retInstVar13) ifTrue:[
|
|
1156 |
%{
|
|
1157 |
extern OBJ __retInst12();
|
|
1158 |
#if defined(SYSV4) && defined(i386)
|
|
1159 |
OBJ (*dummy)() = __retInst12;
|
|
1160 |
#endif
|
|
1161 |
RETURN ( _MKSMALLINT((int)__retInst12) );
|
|
1162 |
%}
|
|
1163 |
].
|
|
1164 |
(aSymbol == #retInstVar14) ifTrue:[
|
|
1165 |
%{
|
|
1166 |
extern OBJ __retInst13();
|
|
1167 |
#if defined(SYSV4) && defined(i386)
|
|
1168 |
OBJ (*dummy)() = __retInst13;
|
|
1169 |
#endif
|
|
1170 |
RETURN ( _MKSMALLINT((int)__retInst13) );
|
|
1171 |
%}
|
|
1172 |
].
|
|
1173 |
(aSymbol == #retInstVar15) ifTrue:[
|
|
1174 |
%{
|
|
1175 |
extern OBJ __retInst14();
|
|
1176 |
#if defined(SYSV4) && defined(i386)
|
|
1177 |
OBJ (*dummy)() = __retInst14;
|
|
1178 |
#endif
|
|
1179 |
RETURN ( _MKSMALLINT((int)__retInst14) );
|
|
1180 |
%}
|
|
1181 |
].
|
|
1182 |
(aSymbol == #retInstVar16) ifTrue:[
|
|
1183 |
%{
|
|
1184 |
extern OBJ __retInst15();
|
|
1185 |
#if defined(SYSV4) && defined(i386)
|
|
1186 |
OBJ (*dummy)() = __retInst15;
|
|
1187 |
#endif
|
|
1188 |
RETURN ( _MKSMALLINT((int)__retInst15) );
|
|
1189 |
%}
|
|
1190 |
].
|
|
1191 |
(aSymbol == #retInstVar17) ifTrue:[
|
|
1192 |
%{
|
|
1193 |
extern OBJ __retInst16();
|
|
1194 |
#if defined(SYSV4) && defined(i386)
|
|
1195 |
OBJ (*dummy)() = __retInst16;
|
|
1196 |
#endif
|
|
1197 |
RETURN ( _MKSMALLINT((int)__retInst16) );
|
|
1198 |
%}
|
|
1199 |
].
|
|
1200 |
(aSymbol == #retInstVar18) ifTrue:[
|
|
1201 |
%{
|
|
1202 |
extern OBJ __retInst17();
|
|
1203 |
#if defined(SYSV4) && defined(i386)
|
|
1204 |
OBJ (*dummy)() = __retInst17;
|
|
1205 |
#endif
|
|
1206 |
RETURN ( _MKSMALLINT((int)__retInst17) );
|
|
1207 |
%}
|
|
1208 |
].
|
|
1209 |
(aSymbol == #retInstVar19) ifTrue:[
|
|
1210 |
%{
|
|
1211 |
extern OBJ __retInst18();
|
|
1212 |
#if defined(SYSV4) && defined(i386)
|
|
1213 |
OBJ (*dummy)() = __retInst18;
|
|
1214 |
#endif
|
|
1215 |
RETURN ( _MKSMALLINT((int)__retInst18) );
|
|
1216 |
%}
|
|
1217 |
].
|
|
1218 |
(aSymbol == #retInstVar20) ifTrue:[
|
|
1219 |
%{
|
|
1220 |
extern OBJ __retInst19();
|
|
1221 |
#if defined(SYSV4) && defined(i386)
|
|
1222 |
OBJ (*dummy)() = __retInst19;
|
|
1223 |
#endif
|
|
1224 |
RETURN ( _MKSMALLINT((int)__retInst19) );
|
|
1225 |
%}
|
|
1226 |
].
|
|
1227 |
(aSymbol == #retInstVar21) ifTrue:[
|
|
1228 |
%{
|
|
1229 |
extern OBJ __retInst20();
|
|
1230 |
#if defined(SYSV4) && defined(i386)
|
|
1231 |
OBJ (*dummy)() = __retInst20;
|
|
1232 |
#endif
|
|
1233 |
RETURN ( _MKSMALLINT((int)__retInst20) );
|
|
1234 |
%}
|
|
1235 |
].
|
|
1236 |
(aSymbol == #retInstVar22) ifTrue:[
|
|
1237 |
%{
|
|
1238 |
extern OBJ __retInst21();
|
|
1239 |
#if defined(SYSV4) && defined(i386)
|
|
1240 |
OBJ (*dummy)() = __retInst21;
|
|
1241 |
#endif
|
|
1242 |
RETURN ( _MKSMALLINT((int)__retInst21) );
|
|
1243 |
%}
|
|
1244 |
].
|
|
1245 |
(aSymbol == #retInstVar23) ifTrue:[
|
|
1246 |
%{
|
|
1247 |
extern OBJ __retInst22();
|
|
1248 |
#if defined(SYSV4) && defined(i386)
|
|
1249 |
OBJ (*dummy)() = __retInst22;
|
|
1250 |
#endif
|
|
1251 |
RETURN ( _MKSMALLINT((int)__retInst22) );
|
|
1252 |
%}
|
|
1253 |
].
|
|
1254 |
(aSymbol == #retInstVar24) ifTrue:[
|
|
1255 |
%{
|
|
1256 |
extern OBJ __retInst23();
|
|
1257 |
#if defined(SYSV4) && defined(i386)
|
|
1258 |
OBJ (*dummy)() = __retInst23;
|
|
1259 |
#endif
|
|
1260 |
RETURN ( _MKSMALLINT((int)__retInst23) );
|
|
1261 |
%}
|
|
1262 |
].
|
|
1263 |
(aSymbol == #retInstVar25) ifTrue:[
|
|
1264 |
%{
|
|
1265 |
extern OBJ __retInst24();
|
|
1266 |
#if defined(SYSV4) && defined(i386)
|
|
1267 |
OBJ (*dummy)() = __retInst24;
|
|
1268 |
#endif
|
|
1269 |
RETURN ( _MKSMALLINT((int)__retInst24) );
|
|
1270 |
%}
|
|
1271 |
].
|
3
|
1272 |
(aSymbol == #retInstVar26) ifTrue:[
|
|
1273 |
%{
|
|
1274 |
extern OBJ __retInst25();
|
|
1275 |
#if defined(SYSV4) && defined(i386)
|
|
1276 |
OBJ (*dummy)() = __retInst25;
|
|
1277 |
#endif
|
|
1278 |
RETURN ( _MKSMALLINT((int)__retInst25) );
|
|
1279 |
%}
|
|
1280 |
].
|
|
1281 |
(aSymbol == #retInstVar27) ifTrue:[
|
|
1282 |
%{
|
|
1283 |
extern OBJ __retInst26();
|
|
1284 |
#if defined(SYSV4) && defined(i386)
|
|
1285 |
OBJ (*dummy)() = __retInst26;
|
|
1286 |
#endif
|
|
1287 |
RETURN ( _MKSMALLINT((int)__retInst26) );
|
|
1288 |
%}
|
|
1289 |
].
|
|
1290 |
(aSymbol == #retInstVar28) ifTrue:[
|
|
1291 |
%{
|
|
1292 |
extern OBJ __retInst27();
|
|
1293 |
#if defined(SYSV4) && defined(i386)
|
|
1294 |
OBJ (*dummy)() = __retInst27;
|
|
1295 |
#endif
|
|
1296 |
RETURN ( _MKSMALLINT((int)__retInst27) );
|
|
1297 |
%}
|
|
1298 |
].
|
|
1299 |
(aSymbol == #retInstVar29) ifTrue:[
|
|
1300 |
%{
|
|
1301 |
extern OBJ __retInst28();
|
|
1302 |
#if defined(SYSV4) && defined(i386)
|
|
1303 |
OBJ (*dummy)() = __retInst28;
|
|
1304 |
#endif
|
|
1305 |
RETURN ( _MKSMALLINT((int)__retInst28) );
|
|
1306 |
%}
|
|
1307 |
].
|
|
1308 |
(aSymbol == #retInstVar30) ifTrue:[
|
|
1309 |
%{
|
|
1310 |
extern OBJ __retInst29();
|
|
1311 |
#if defined(SYSV4) && defined(i386)
|
|
1312 |
OBJ (*dummy)() = __retInst29;
|
|
1313 |
#endif
|
|
1314 |
RETURN ( _MKSMALLINT((int)__retInst29) );
|
|
1315 |
%}
|
|
1316 |
].
|
|
1317 |
(aSymbol == #retInstVar31) ifTrue:[
|
|
1318 |
%{
|
|
1319 |
extern OBJ __retInst30();
|
|
1320 |
#if defined(SYSV4) && defined(i386)
|
|
1321 |
OBJ (*dummy)() = __retInst30;
|
|
1322 |
#endif
|
|
1323 |
RETURN ( _MKSMALLINT((int)__retInst30) );
|
|
1324 |
%}
|
|
1325 |
].
|
|
1326 |
|
0
|
1327 |
(aSymbol == #storeInstVar1) ifTrue:[
|
|
1328 |
%{
|
|
1329 |
extern OBJ __setInst0();
|
|
1330 |
#if defined(SYSV4) && defined(i386)
|
|
1331 |
OBJ (*dummy)() = __setInst0;
|
|
1332 |
#endif
|
|
1333 |
RETURN ( _MKSMALLINT((int)__setInst0) );
|
|
1334 |
%}
|
|
1335 |
].
|
|
1336 |
(aSymbol == #storeInstVar2) ifTrue:[
|
|
1337 |
%{
|
|
1338 |
extern OBJ __setInst1();
|
|
1339 |
#if defined(SYSV4) && defined(i386)
|
|
1340 |
OBJ (*dummy)() = __setInst1;
|
|
1341 |
#endif
|
|
1342 |
RETURN ( _MKSMALLINT((int)__setInst1) );
|
|
1343 |
%}
|
|
1344 |
].
|
|
1345 |
(aSymbol == #storeInstVar3) ifTrue:[
|
|
1346 |
%{
|
|
1347 |
extern OBJ __setInst2();
|
|
1348 |
#if defined(SYSV4) && defined(i386)
|
|
1349 |
OBJ (*dummy)() = __setInst2;
|
|
1350 |
#endif
|
|
1351 |
RETURN ( _MKSMALLINT((int)__setInst2) );
|
|
1352 |
%}
|
|
1353 |
].
|
|
1354 |
(aSymbol == #storeInstVar4) ifTrue:[
|
|
1355 |
%{
|
|
1356 |
extern OBJ __setInst3();
|
|
1357 |
#if defined(SYSV4) && defined(i386)
|
|
1358 |
OBJ (*dummy)() = __setInst3;
|
|
1359 |
#endif
|
|
1360 |
RETURN ( _MKSMALLINT((int)__setInst3) );
|
|
1361 |
%}
|
|
1362 |
].
|
|
1363 |
(aSymbol == #storeInstVar5) ifTrue:[
|
|
1364 |
%{
|
|
1365 |
extern OBJ __setInst4();
|
|
1366 |
#if defined(SYSV4) && defined(i386)
|
|
1367 |
OBJ (*dummy)() = __setInst4;
|
|
1368 |
#endif
|
|
1369 |
RETURN ( _MKSMALLINT((int)__setInst4) );
|
|
1370 |
%}
|
|
1371 |
].
|
|
1372 |
(aSymbol == #storeInstVar6) ifTrue:[
|
|
1373 |
%{
|
|
1374 |
extern OBJ __setInst5();
|
|
1375 |
#if defined(SYSV4) && defined(i386)
|
|
1376 |
OBJ (*dummy)() = __setInst5;
|
|
1377 |
#endif
|
|
1378 |
RETURN ( _MKSMALLINT((int)__setInst5) );
|
|
1379 |
%}
|
|
1380 |
].
|
|
1381 |
(aSymbol == #storeInstVar7) ifTrue:[
|
|
1382 |
%{
|
|
1383 |
extern OBJ __setInst6();
|
|
1384 |
#if defined(SYSV4) && defined(i386)
|
|
1385 |
OBJ (*dummy)() = __setInst6;
|
|
1386 |
#endif
|
|
1387 |
RETURN ( _MKSMALLINT((int)__setInst6) );
|
|
1388 |
%}
|
|
1389 |
].
|
|
1390 |
(aSymbol == #storeInstVar8) ifTrue:[
|
|
1391 |
%{
|
|
1392 |
extern OBJ __setInst7();
|
|
1393 |
#if defined(SYSV4) && defined(i386)
|
|
1394 |
OBJ (*dummy)() = __setInst7;
|
|
1395 |
#endif
|
|
1396 |
RETURN ( _MKSMALLINT((int)__setInst7) );
|
|
1397 |
%}
|
|
1398 |
].
|
|
1399 |
(aSymbol == #storeInstVar9) ifTrue:[
|
|
1400 |
%{
|
|
1401 |
extern OBJ __setInst8();
|
|
1402 |
#if defined(SYSV4) && defined(i386)
|
|
1403 |
OBJ (*dummy)() = __setInst8;
|
|
1404 |
#endif
|
|
1405 |
RETURN ( _MKSMALLINT((int)__setInst8) );
|
|
1406 |
%}
|
|
1407 |
].
|
|
1408 |
(aSymbol == #storeInstVar10) ifTrue:[
|
|
1409 |
%{
|
|
1410 |
extern OBJ __setInst9();
|
|
1411 |
#if defined(SYSV4) && defined(i386)
|
|
1412 |
OBJ (*dummy)() = __setInst9;
|
|
1413 |
#endif
|
|
1414 |
RETURN ( _MKSMALLINT((int)__setInst9) );
|
|
1415 |
%}
|
|
1416 |
].
|
1
|
1417 |
(aSymbol == #storeInstVar11) ifTrue:[
|
|
1418 |
%{
|
|
1419 |
extern OBJ __setInst10();
|
|
1420 |
#if defined(SYSV4) && defined(i386)
|
|
1421 |
OBJ (*dummy)() = __setInst10;
|
|
1422 |
#endif
|
|
1423 |
RETURN ( _MKSMALLINT((int)__setInst10) );
|
|
1424 |
%}
|
|
1425 |
].
|
|
1426 |
(aSymbol == #storeInstVar12) ifTrue:[
|
|
1427 |
%{
|
|
1428 |
extern OBJ __setInst11();
|
|
1429 |
#if defined(SYSV4) && defined(i386)
|
|
1430 |
OBJ (*dummy)() = __setInst11;
|
|
1431 |
#endif
|
|
1432 |
RETURN ( _MKSMALLINT((int)__setInst11) );
|
|
1433 |
%}
|
|
1434 |
].
|
|
1435 |
(aSymbol == #storeInstVar13) ifTrue:[
|
|
1436 |
%{
|
|
1437 |
extern OBJ __setInst12();
|
|
1438 |
#if defined(SYSV4) && defined(i386)
|
|
1439 |
OBJ (*dummy)() = __setInst12;
|
|
1440 |
#endif
|
|
1441 |
RETURN ( _MKSMALLINT((int)__setInst12) );
|
|
1442 |
%}
|
|
1443 |
].
|
|
1444 |
(aSymbol == #storeInstVar13) ifTrue:[
|
|
1445 |
%{
|
|
1446 |
extern OBJ __setInst12();
|
|
1447 |
#if defined(SYSV4) && defined(i386)
|
|
1448 |
OBJ (*dummy)() = __setInst12;
|
|
1449 |
#endif
|
|
1450 |
RETURN ( _MKSMALLINT((int)__setInst12) );
|
|
1451 |
%}
|
|
1452 |
].
|
|
1453 |
(aSymbol == #storeInstVar14) ifTrue:[
|
|
1454 |
%{
|
|
1455 |
extern OBJ __setInst13();
|
|
1456 |
#if defined(SYSV4) && defined(i386)
|
|
1457 |
OBJ (*dummy)() = __setInst13;
|
|
1458 |
#endif
|
|
1459 |
RETURN ( _MKSMALLINT((int)__setInst13) );
|
|
1460 |
%}
|
|
1461 |
].
|
|
1462 |
(aSymbol == #storeInstVar15) ifTrue:[
|
|
1463 |
%{
|
|
1464 |
extern OBJ __setInst14();
|
|
1465 |
#if defined(SYSV4) && defined(i386)
|
|
1466 |
OBJ (*dummy)() = __setInst14;
|
|
1467 |
#endif
|
|
1468 |
RETURN ( _MKSMALLINT((int)__setInst14) );
|
|
1469 |
%}
|
|
1470 |
].
|
|
1471 |
(aSymbol == #storeInstVar16) ifTrue:[
|
|
1472 |
%{
|
|
1473 |
extern OBJ __setInst15();
|
|
1474 |
#if defined(SYSV4) && defined(i386)
|
|
1475 |
OBJ (*dummy)() = __setInst15;
|
|
1476 |
#endif
|
|
1477 |
RETURN ( _MKSMALLINT((int)__setInst15) );
|
|
1478 |
%}
|
|
1479 |
].
|
|
1480 |
(aSymbol == #storeInstVar17) ifTrue:[
|
|
1481 |
%{
|
|
1482 |
extern OBJ __setInst16();
|
|
1483 |
#if defined(SYSV4) && defined(i386)
|
|
1484 |
OBJ (*dummy)() = __setInst16;
|
|
1485 |
#endif
|
|
1486 |
RETURN ( _MKSMALLINT((int)__setInst16) );
|
|
1487 |
%}
|
|
1488 |
].
|
|
1489 |
(aSymbol == #storeInstVar18) ifTrue:[
|
|
1490 |
%{
|
|
1491 |
extern OBJ __setInst17();
|
|
1492 |
#if defined(SYSV4) && defined(i386)
|
|
1493 |
OBJ (*dummy)() = __setInst17;
|
|
1494 |
#endif
|
|
1495 |
RETURN ( _MKSMALLINT((int)__setInst17) );
|
|
1496 |
%}
|
|
1497 |
].
|
|
1498 |
(aSymbol == #storeInstVar19) ifTrue:[
|
|
1499 |
%{
|
|
1500 |
extern OBJ __setInst18();
|
|
1501 |
#if defined(SYSV4) && defined(i386)
|
|
1502 |
OBJ (*dummy)() = __setInst18;
|
|
1503 |
#endif
|
|
1504 |
RETURN ( _MKSMALLINT((int)__setInst18) );
|
|
1505 |
%}
|
|
1506 |
].
|
|
1507 |
(aSymbol == #storeInstVar20) ifTrue:[
|
|
1508 |
%{
|
|
1509 |
extern OBJ __setInst19();
|
|
1510 |
#if defined(SYSV4) && defined(i386)
|
|
1511 |
OBJ (*dummy)() = __setInst19;
|
|
1512 |
#endif
|
|
1513 |
RETURN ( _MKSMALLINT((int)__setInst19) );
|
|
1514 |
%}
|
|
1515 |
].
|
3
|
1516 |
(aSymbol == #storeInstVar21) ifTrue:[
|
|
1517 |
%{
|
|
1518 |
extern OBJ __setInst20();
|
|
1519 |
#if defined(SYSV4) && defined(i386)
|
|
1520 |
OBJ (*dummy)() = __setInst20;
|
|
1521 |
#endif
|
|
1522 |
RETURN ( _MKSMALLINT((int)__setInst20) );
|
|
1523 |
%}
|
|
1524 |
].
|
|
1525 |
(aSymbol == #storeInstVar22) ifTrue:[
|
|
1526 |
%{
|
|
1527 |
extern OBJ __setInst21();
|
|
1528 |
#if defined(SYSV4) && defined(i386)
|
|
1529 |
OBJ (*dummy)() = __setInst21;
|
|
1530 |
#endif
|
|
1531 |
RETURN ( _MKSMALLINT((int)__setInst21) );
|
|
1532 |
%}
|
|
1533 |
].
|
|
1534 |
(aSymbol == #storeInstVar23) ifTrue:[
|
|
1535 |
%{
|
|
1536 |
extern OBJ __setInst22();
|
|
1537 |
#if defined(SYSV4) && defined(i386)
|
|
1538 |
OBJ (*dummy)() = __setInst22;
|
|
1539 |
#endif
|
|
1540 |
RETURN ( _MKSMALLINT((int)__setInst22) );
|
|
1541 |
%}
|
|
1542 |
].
|
|
1543 |
(aSymbol == #storeInstVar23) ifTrue:[
|
|
1544 |
%{
|
|
1545 |
extern OBJ __setInst22();
|
|
1546 |
#if defined(SYSV4) && defined(i386)
|
|
1547 |
OBJ (*dummy)() = __setInst22;
|
|
1548 |
#endif
|
|
1549 |
RETURN ( _MKSMALLINT((int)__setInst22) );
|
|
1550 |
%}
|
|
1551 |
].
|
|
1552 |
(aSymbol == #storeInstVar24) ifTrue:[
|
|
1553 |
%{
|
|
1554 |
extern OBJ __setInst23();
|
|
1555 |
#if defined(SYSV4) && defined(i386)
|
|
1556 |
OBJ (*dummy)() = __setInst23;
|
|
1557 |
#endif
|
|
1558 |
RETURN ( _MKSMALLINT((int)__setInst23) );
|
|
1559 |
%}
|
|
1560 |
].
|
|
1561 |
(aSymbol == #storeInstVar25) ifTrue:[
|
|
1562 |
%{
|
|
1563 |
extern OBJ __setInst24();
|
|
1564 |
#if defined(SYSV4) && defined(i386)
|
|
1565 |
OBJ (*dummy)() = __setInst24;
|
|
1566 |
#endif
|
|
1567 |
RETURN ( _MKSMALLINT((int)__setInst24) );
|
|
1568 |
%}
|
|
1569 |
].
|
|
1570 |
(aSymbol == #storeInstVar26) ifTrue:[
|
|
1571 |
%{
|
|
1572 |
extern OBJ __setInst25();
|
|
1573 |
#if defined(SYSV4) && defined(i386)
|
|
1574 |
OBJ (*dummy)() = __setInst25;
|
|
1575 |
#endif
|
|
1576 |
RETURN ( _MKSMALLINT((int)__setInst25) );
|
|
1577 |
%}
|
|
1578 |
].
|
|
1579 |
(aSymbol == #storeInstVar27) ifTrue:[
|
|
1580 |
%{
|
|
1581 |
extern OBJ __setInst26();
|
|
1582 |
#if defined(SYSV4) && defined(i386)
|
|
1583 |
OBJ (*dummy)() = __setInst26;
|
|
1584 |
#endif
|
|
1585 |
RETURN ( _MKSMALLINT((int)__setInst26) );
|
|
1586 |
%}
|
|
1587 |
].
|
|
1588 |
(aSymbol == #storeInstVar28) ifTrue:[
|
|
1589 |
%{
|
|
1590 |
extern OBJ __setInst27();
|
|
1591 |
#if defined(SYSV4) && defined(i386)
|
|
1592 |
OBJ (*dummy)() = __setInst27;
|
|
1593 |
#endif
|
|
1594 |
RETURN ( _MKSMALLINT((int)__setInst27) );
|
|
1595 |
%}
|
|
1596 |
].
|
|
1597 |
(aSymbol == #storeInstVar29) ifTrue:[
|
|
1598 |
%{
|
|
1599 |
extern OBJ __setInst28();
|
|
1600 |
#if defined(SYSV4) && defined(i386)
|
|
1601 |
OBJ (*dummy)() = __setInst28;
|
|
1602 |
#endif
|
|
1603 |
RETURN ( _MKSMALLINT((int)__setInst28) );
|
|
1604 |
%}
|
|
1605 |
].
|
|
1606 |
(aSymbol == #storeInstVar30) ifTrue:[
|
|
1607 |
%{
|
|
1608 |
extern OBJ __setInst29();
|
|
1609 |
#if defined(SYSV4) && defined(i386)
|
|
1610 |
OBJ (*dummy)() = __setInst29;
|
|
1611 |
#endif
|
|
1612 |
RETURN ( _MKSMALLINT((int)__setInst29) );
|
|
1613 |
%}
|
|
1614 |
].
|
|
1615 |
(aSymbol == #storeInstVar31) ifTrue:[
|
|
1616 |
%{
|
|
1617 |
extern OBJ __setInst30();
|
|
1618 |
#if defined(SYSV4) && defined(i386)
|
|
1619 |
OBJ (*dummy)() = __setInst30;
|
|
1620 |
#endif
|
|
1621 |
RETURN ( _MKSMALLINT((int)__setInst30) );
|
|
1622 |
%}
|
|
1623 |
].
|
0
|
1624 |
^ nil
|
|
1625 |
! !
|
|
1626 |
|
|
1627 |
!ByteCodeCompiler methodsFor:'machine code generation'!
|
|
1628 |
|
|
1629 |
checkForSharedCode:symbolicCodeArray
|
|
1630 |
"if this method is a very simple one,
|
|
1631 |
we can use the shared compiled code"
|
|
1632 |
|
1
|
1633 |
|codeSymbol nArgs index|
|
0
|
1634 |
|
|
1635 |
symbolicCodeArray isNil ifTrue:[^ nil].
|
|
1636 |
codeSymbol := symbolicCodeArray at:1.
|
|
1637 |
nArgs := methodArgs size.
|
|
1638 |
(nArgs == 0) ifTrue:[
|
|
1639 |
(codeSymbol == #retSelf) ifTrue:[^ codeSymbol].
|
|
1640 |
(codeSymbol == #retTrue) ifTrue:[^ codeSymbol].
|
|
1641 |
(codeSymbol == #retFalse) ifTrue:[^ codeSymbol].
|
|
1642 |
(codeSymbol == #retNil) ifTrue:[^ codeSymbol].
|
|
1643 |
(codeSymbol == #ret0) ifTrue:[^ codeSymbol].
|
1
|
1644 |
('retInstVar*' match:codeSymbol) ifTrue:[^ codeSymbol].
|
|
1645 |
|
0
|
1646 |
(codeSymbol == #pushMethodArg1) ifTrue:[
|
1
|
1647 |
((symbolicCodeArray at:2) == #storeInstVar) ifTrue:[
|
|
1648 |
index := symbolicCodeArray at:3.
|
|
1649 |
((symbolicCodeArray at:4) == #retSelf) ifTrue:[
|
|
1650 |
^ ('storeInstVar' , index printString) asSymbol
|
3
|
1651 |
].
|
|
1652 |
^ nil
|
|
1653 |
].
|
0
|
1654 |
('storeInstVar*' match:(symbolicCodeArray at:2)) ifTrue:[
|
|
1655 |
((symbolicCodeArray at:3) == #retSelf) ifTrue:[^ symbolicCodeArray at:2]
|
|
1656 |
].
|
|
1657 |
^ nil
|
1
|
1658 |
].
|
|
1659 |
|
|
1660 |
codeSymbol == #pushInstVar ifTrue:[
|
|
1661 |
index := symbolicCodeArray at:2.
|
|
1662 |
(symbolicCodeArray at:3) == #retTop ifTrue:[
|
|
1663 |
^ ('retInstVar' , index printString) asSymbol
|
|
1664 |
].
|
|
1665 |
^ nil
|
0
|
1666 |
]
|
|
1667 |
].
|
|
1668 |
^ nil
|
|
1669 |
!
|
|
1670 |
|
|
1671 |
checkForMachineCode:symbolicCodeArray
|
|
1672 |
"if this method is a simple one,
|
|
1673 |
we can compile it into machine code"
|
|
1674 |
|
|
1675 |
|code1 code2 code3 name|
|
|
1676 |
|
|
1677 |
symbolicCodeArray isNil ifTrue:[^ nil].
|
12
|
1678 |
|
0
|
1679 |
code1 := symbolicCodeArray at:1.
|
|
1680 |
(code1 == #retNum) ifTrue:[
|
|
1681 |
^ self codeForRetNum:(symbolicCodeArray at:2)
|
|
1682 |
].
|
|
1683 |
(code1 == #pushNum) ifTrue:[
|
|
1684 |
code2 := symbolicCodeArray at:3.
|
|
1685 |
(code2 == #retTop) ifTrue:[
|
|
1686 |
^ self codeForRetNum:(symbolicCodeArray at:2)
|
|
1687 |
].
|
|
1688 |
^ nil
|
|
1689 |
].
|
|
1690 |
(code1 == #pushMethodArg1) ifTrue:[
|
|
1691 |
code2 := symbolicCodeArray at:2.
|
|
1692 |
((code2 == #storeGlobal)
|
|
1693 |
or:[code2 == #storeClassVar]) ifTrue:[
|
|
1694 |
code3 := symbolicCodeArray at:4.
|
|
1695 |
(code3 == #retSelf) ifTrue:[
|
|
1696 |
name := symbolicCodeArray at:3.
|
|
1697 |
^ self codeForSetCell:name
|
|
1698 |
]
|
|
1699 |
].
|
|
1700 |
^ nil
|
|
1701 |
].
|
|
1702 |
(code1 == #pushGlobal) ifTrue:[
|
|
1703 |
code2 := symbolicCodeArray at:8.
|
|
1704 |
(code2 == #retTop) ifTrue:[
|
|
1705 |
name := symbolicCodeArray at:2.
|
|
1706 |
^ self codeForRetCell:name
|
|
1707 |
].
|
|
1708 |
^ nil
|
|
1709 |
].
|
|
1710 |
(code1 == #pushClassVar) ifTrue:[
|
|
1711 |
code2 := symbolicCodeArray at:8.
|
|
1712 |
(code2 == #retTop) ifTrue:[
|
|
1713 |
name := symbolicCodeArray at:2.
|
|
1714 |
^ self codeForRetCell:name
|
|
1715 |
].
|
|
1716 |
^ nil
|
|
1717 |
].
|
|
1718 |
(code1 == #pushLit) ifTrue:[
|
|
1719 |
code2 := symbolicCodeArray at:3.
|
|
1720 |
(code2 == #retTop) ifTrue:[
|
|
1721 |
^ nil
|
|
1722 |
].
|
|
1723 |
^ nil
|
|
1724 |
].
|
|
1725 |
^ nil
|
|
1726 |
!
|
|
1727 |
|
|
1728 |
codeForRetNum:value
|
|
1729 |
"^ number will be coded into machine code"
|
|
1730 |
|
|
1731 |
|count b conIndex tagHi newCode|
|
|
1732 |
|
|
1733 |
count := self codeProtoForRetNumEnd - self codeProtoForRetNum.
|
|
1734 |
|
|
1735 |
b := ExternalBytes address:(self codeProtoForRetNum).
|
|
1736 |
|
|
1737 |
"search for sequence 0x92345678"
|
|
1738 |
|
|
1739 |
tagHi := false.
|
|
1740 |
1 to:count-3 do:[:index |
|
|
1741 |
(b at:index) == 16r92 ifTrue:[
|
|
1742 |
(b at:index+1) == 16r34 ifTrue:[
|
|
1743 |
(b at:index+2) == 16r56 ifTrue:[
|
|
1744 |
(b at:index+3) == 16r78 ifTrue:[
|
|
1745 |
conIndex := index.
|
|
1746 |
tagHi := true
|
|
1747 |
]
|
|
1748 |
]
|
|
1749 |
]
|
|
1750 |
]
|
|
1751 |
].
|
|
1752 |
|
|
1753 |
conIndex isNil ifTrue:["'search failed' printNewline. "^ nil].
|
|
1754 |
tagHi ifFalse:['low tag unsupported' printNewline. ^ nil].
|
|
1755 |
|
|
1756 |
"allocate code ..."
|
|
1757 |
|
|
1758 |
newCode := ExternalBytes newForText:count.
|
|
1759 |
newCode isNil ifTrue:[
|
|
1760 |
'alloc of text (size ' print. count print. ') failed' printNewline.
|
|
1761 |
^ nil
|
|
1762 |
].
|
|
1763 |
|
|
1764 |
"copy from proto"
|
|
1765 |
1 to:count do:[:index |
|
|
1766 |
newCode at:index put:(b at:index)
|
|
1767 |
].
|
|
1768 |
"put in ret-value"
|
|
1769 |
newCode at:conIndex put:((value bitShift:-24) bitAnd:16rFF).
|
|
1770 |
newCode at:conIndex+1 put:((value bitShift:-16) bitAnd:16rFF).
|
|
1771 |
newCode at:conIndex+2 put:((value bitShift:-8) bitAnd:16rFF).
|
|
1772 |
newCode at:conIndex+3 put:(value bitAnd:16rFF).
|
|
1773 |
tagHi ifTrue:[
|
6
|
1774 |
newCode at:conIndex
|
0
|
1775 |
put:((newCode at:conIndex) bitOr:16r80)
|
|
1776 |
] ifFalse:[
|
|
1777 |
].
|
6
|
1778 |
'address is:' print. (newCode address printStringRadix:16) printNewline.
|
0
|
1779 |
^ newCode address
|
|
1780 |
|
|
1781 |
"ByteCodeCompiler new codeForRetNum:15"
|
|
1782 |
!
|
|
1783 |
codeForRetCell:aGlobalOrClassVariableSymbol
|
|
1784 |
"^ global will be coded into machine code"
|
|
1785 |
|
|
1786 |
|cell count b conIndex newCode msbFirst|
|
|
1787 |
|
|
1788 |
cell := Smalltalk cellAt:aGlobalOrClassVariableSymbol.
|
|
1789 |
cell isNil ifTrue:[^ nil].
|
|
1790 |
|
|
1791 |
count := self codeProtoForRetCellEnd - self codeProtoForRetCell.
|
|
1792 |
|
|
1793 |
b := ExternalBytes address:(self codeProtoForRetCell).
|
|
1794 |
|
|
1795 |
msbFirst := true.
|
|
1796 |
|
|
1797 |
"search for sequence 0x12345678 // 78563412"
|
|
1798 |
1 to:count - 3 do:[:index |
|
|
1799 |
(b at:index) == 16r12 ifTrue:[
|
|
1800 |
(b at:index+1) == 16r34 ifTrue:[
|
|
1801 |
(b at:index+2) == 16r56 ifTrue:[
|
|
1802 |
(b at:index+3) == 16r78 ifTrue:[
|
|
1803 |
conIndex := index
|
|
1804 |
]
|
|
1805 |
]
|
|
1806 |
]
|
|
1807 |
].
|
|
1808 |
conIndex isNil ifTrue:[
|
|
1809 |
(b at:index) == 16r78 ifTrue:[
|
|
1810 |
(b at:index+1) == 16r56 ifTrue:[
|
|
1811 |
(b at:index+2) == 16r34 ifTrue:[
|
|
1812 |
(b at:index+3) == 16r12 ifTrue:[
|
|
1813 |
conIndex := index.
|
|
1814 |
msbFirst := false
|
|
1815 |
]
|
|
1816 |
]
|
|
1817 |
]
|
|
1818 |
]
|
|
1819 |
]
|
|
1820 |
].
|
|
1821 |
|
|
1822 |
conIndex isNil ifTrue:["'search failed' printNewline. " ^ nil].
|
|
1823 |
|
|
1824 |
"allocate code ..."
|
|
1825 |
|
|
1826 |
newCode := ExternalBytes newForText:count.
|
|
1827 |
newCode isNil ifTrue:['alloc of text (size ' print. count print. ') failed' printNewline.^ nil].
|
|
1828 |
|
|
1829 |
"copy from proto"
|
|
1830 |
1 to:count do:[:index |
|
|
1831 |
newCode at:index put:(b at:index)
|
|
1832 |
].
|
|
1833 |
"put in cell address"
|
|
1834 |
msbFirst ifTrue:[
|
|
1835 |
newCode at:conIndex put:((cell bitShift:-24) bitAnd:16rFF).
|
|
1836 |
newCode at:conIndex+1 put:((cell bitShift:-16) bitAnd:16rFF).
|
|
1837 |
newCode at:conIndex+2 put:((cell bitShift:-8) bitAnd:16rFF).
|
|
1838 |
newCode at:conIndex+3 put:(cell bitAnd:16rFF).
|
|
1839 |
] ifFalse:[
|
|
1840 |
newCode at:conIndex+3 put:((cell bitShift:-24) bitAnd:16rFF).
|
|
1841 |
newCode at:conIndex+2 put:((cell bitShift:-16) bitAnd:16rFF).
|
|
1842 |
newCode at:conIndex+1 put:((cell bitShift:-8) bitAnd:16rFF).
|
|
1843 |
newCode at:conIndex put:(cell bitAnd:16rFF).
|
|
1844 |
].
|
|
1845 |
|
6
|
1846 |
'address is:' print. (newCode address printStringRadix:16) printNewline.
|
0
|
1847 |
^ newCode address
|
|
1848 |
|
|
1849 |
"ByteCodeCompiler new codeForRetCell:#Transcript"
|
|
1850 |
!
|
|
1851 |
|
|
1852 |
codeForSetCell:aGlobalOrClassVariableSymbol
|
|
1853 |
"global := arg will be coded into machine code"
|
|
1854 |
|
|
1855 |
|cell count b conIndex newCode|
|
|
1856 |
|
|
1857 |
cell := Smalltalk cellAt:aGlobalOrClassVariableSymbol.
|
|
1858 |
cell isNil ifTrue:[^ nil].
|
|
1859 |
|
|
1860 |
count := self codeProtoForSetCellEnd - self codeProtoForSetCell.
|
|
1861 |
|
|
1862 |
b := ExternalBytes address:(self codeProtoForSetCell).
|
|
1863 |
|
|
1864 |
"search for sequence 0x12345678"
|
|
1865 |
1 to:count - 3 do:[:index |
|
|
1866 |
(b at:index) == 16r12 ifTrue:[
|
|
1867 |
(b at:index+1) == 16r34 ifTrue:[
|
|
1868 |
(b at:index+2) == 16r56 ifTrue:[
|
|
1869 |
(b at:index+3) == 16r78 ifTrue:[
|
|
1870 |
conIndex := index
|
|
1871 |
]
|
|
1872 |
]
|
|
1873 |
]
|
|
1874 |
]
|
|
1875 |
].
|
|
1876 |
|
|
1877 |
conIndex isNil ifTrue:["'search failed' printNewline." ^ nil].
|
|
1878 |
|
|
1879 |
"allocate code ..."
|
|
1880 |
|
|
1881 |
newCode := ExternalBytes newForData:count.
|
|
1882 |
newCode isNil ifTrue:['alloc of data (size ' print. count print. ') failed' printNewline.^ nil].
|
|
1883 |
|
|
1884 |
"copy from proto"
|
|
1885 |
1 to:count do:[:index |
|
|
1886 |
newCode at:index put:(b at:index)
|
|
1887 |
].
|
|
1888 |
"put in cell address"
|
|
1889 |
newCode at:conIndex put:((cell bitShift:-24) bitAnd:16rFF).
|
|
1890 |
newCode at:conIndex+1 put:((cell bitShift:-16) bitAnd:16rFF).
|
|
1891 |
newCode at:conIndex+2 put:((cell bitShift:-8) bitAnd:16rFF).
|
|
1892 |
newCode at:conIndex+3 put:(cell bitAnd:16rFF).
|
|
1893 |
|
6
|
1894 |
'address is:' print. (newCode address printStringRadix:16) printNewline.
|
0
|
1895 |
^ newCode address
|
|
1896 |
|
|
1897 |
"ByteCodeCompiler new codeForSetCell:#xyz"
|
|
1898 |
!
|
|
1899 |
|
|
1900 |
codeProtoForRetNum
|
|
1901 |
%{ /* NOCONTEXT */
|
|
1902 |
extern OBJ __retNumProto();
|
|
1903 |
#if defined(SYSV4) && defined(i386)
|
|
1904 |
OBJ (*dummy)() = __retNumProto;
|
|
1905 |
#endif
|
|
1906 |
RETURN ( _MKSMALLINT((int)__retNumProto) );
|
|
1907 |
%}
|
|
1908 |
!
|
|
1909 |
|
|
1910 |
codeProtoForRetNumEnd
|
|
1911 |
%{ /* NOCONTEXT */
|
|
1912 |
extern OBJ __retNumProtoEnd();
|
|
1913 |
#if defined(SYSV4) && defined(i386)
|
|
1914 |
OBJ (*dummy)() = __retNumProtoEnd;
|
|
1915 |
#endif
|
|
1916 |
RETURN ( _MKSMALLINT((int)__retNumProtoEnd) );
|
|
1917 |
%}
|
|
1918 |
!
|
|
1919 |
|
|
1920 |
codeProtoForRetCell
|
|
1921 |
%{ /* NOCONTEXT */
|
|
1922 |
extern OBJ __retCellProto();
|
|
1923 |
#if defined(SYSV4) && defined(i386)
|
|
1924 |
OBJ (*dummy)() = __retCellProto;
|
|
1925 |
#endif
|
|
1926 |
RETURN ( _MKSMALLINT((int)__retCellProto) );
|
|
1927 |
%}
|
|
1928 |
!
|
|
1929 |
|
|
1930 |
codeProtoForRetCellEnd
|
|
1931 |
%{ /* NOCONTEXT */
|
|
1932 |
extern OBJ __retCellProtoEnd();
|
|
1933 |
#if defined(SYSV4) && defined(i386)
|
|
1934 |
OBJ (*dummy)() = __retCellProtoEnd;
|
|
1935 |
#endif
|
|
1936 |
RETURN ( _MKSMALLINT((int)__retCellProtoEnd) );
|
|
1937 |
%}
|
|
1938 |
!
|
|
1939 |
|
|
1940 |
codeProtoForSetCell
|
|
1941 |
%{ /* NOCONTEXT */
|
|
1942 |
extern OBJ __setCellProto();
|
|
1943 |
#if defined(SYSV4) && defined(i386)
|
|
1944 |
OBJ (*dummy)() = __setCellProto;
|
|
1945 |
#endif
|
|
1946 |
RETURN ( _MKSMALLINT((int)__setCellProto) );
|
|
1947 |
%}
|
|
1948 |
!
|
|
1949 |
|
|
1950 |
codeProtoForSetCellEnd
|
|
1951 |
%{ /* NOCONTEXT */
|
|
1952 |
extern OBJ __setCellProtoEnd();
|
|
1953 |
#if defined(SYSV4) && defined(i386)
|
|
1954 |
OBJ (*dummy)() = __setCellProtoEnd;
|
|
1955 |
#endif
|
|
1956 |
RETURN ( _MKSMALLINT((int)__setCellProtoEnd) );
|
|
1957 |
%}
|
6
|
1958 |
|
0
|
1959 |
! !
|