Fixes to InterpreterSimulator for Squeak 2.3
Greg & Cindy Gritton
gritton at ibm.net
Sat Jan 30 17:40:26 UTC 1999
After updating to Squeak 2.3, Squeak would no longer simulate itself
using the InterpreterSimulator. I fixed some bugs and it now works for me.
There were two bugs:
1. fetchNextBytecode was added to the bytecode methods in the interpreter.
However, it was still present in the testStep method in
InterpreterSimulator. This resulted in advancing 2 bytes instead of 1.
I moved it from testStep to testStart.
2. primitiveShortAt had been added to the interpreter which used
inline (textual) C code to get a short from an address.
I copied the same method to InterpreterSimulator, changing the
C code to a call to halfWordAt:, and added halfWordAt: and halfWordAt:put:
to InterpreterSimulator and InterpreterSimulatorLSB.
(InterpreterSimulatorLSB is a new class added by Tim Rowledge to
simulate Squeak on little-endian systems. It is available at
http://sumeru.stanford.EDU/tim/pooters/SqFiles/deltas/VMsimulator.6Nov.cs )
File-ins follow.
Greg Gritton
gritton at ibm.net
!InterpreterSimulator methodsFor: 'testing' stamp: 'GVG 1/21/1999 18:26'!
test
self testStart.
[true] whileTrue: [
self testStep].
self testEnd
! !
!InterpreterSimulator methodsFor: 'testing' stamp: 'GVG 1/27/1999 19:57'!
testStart
Transcript clear.
byteCount _ 0.
self internalizeIPandSP.
currentBytecode _ self fetchByte.
! !
!InterpreterSimulator methodsFor: 'memory access' stamp: 'GVG 1/27/1999
20:47'!
primitiveShortAt
"Treat the receiver, which can be indexible by either bytes or words, as
an array of signed 16-bit values. Return the contents of the given index.
Note that the index specifies the i-th 16-bit entry, not the i-th byte or
word."
| index rcvr sz addr value |
index _ self stackIntegerValue: 0.
rcvr _ self stackValue: 1.
self success: ((self isIntegerObject: rcvr) not and: [self isWordsOrBytes:
rcvr]).
successFlag ifFalse: [ ^ nil ].
sz _ ((self sizeBitsOf: rcvr) - BaseHeaderSize) // 2. "number of 16-bit
fields"
self success: ((index >= 1) and: [index <= sz]).
successFlag ifTrue: [
addr _ rcvr + BaseHeaderSize + (2 * (index - 1)).
value _ self halfWordAt: addr.
self pop: 2. "pop rcvr, index"
self pushInteger: value. "push element value"
].
! !
!InterpreterSimulator methodsFor: 'memory access' stamp: 'GVG 1/27/1999
20:41'!
halfWordAt: byteAddress
"Return the half-word at byteAddress which must be even."
| lowBits |
lowBits _ byteAddress bitAnd: 2.
^((self longAt: byteAddress - lowBits)
bitShift: (lowBits - 2) * 8)
bitAnd: 16rFFFF
! !
!InterpreterSimulator methodsFor: 'memory access' stamp: 'GVG 1/27/1999
20:43'!
halfWordAt: byteAddress put: halfWord
| longWord shift lowBits |
lowBits _ byteAddress bitAnd: 2.
longWord _ self longAt: byteAddress - lowBits.
shift _ (2 - lowBits) * 8.
longWord _ longWord - (longWord bitAnd: (16rFFFF bitShift: shift)) +
(halfWord bitShift: shift).
self longAt: byteAddress put: longWord
! !
!InterpreterSimulatorLSB methodsFor: 'memory access' stamp: 'GVG 1/27/1999
20:43'!
halfWordAt: byteAddress
| lowBits |
lowBits _ byteAddress bitAnd: 2.
^((self longAt: byteAddress - lowBits)
bitShift: (0 - lowBits) * 8)
bitAnd: 16rFFFF! !
!InterpreterSimulatorLSB methodsFor: 'memory access' stamp: 'GVG 1/27/1999
21:30'!
halfWordAt: byteAddress put: halfWord
| longWord shift lowBits |
lowBits _ byteAddress bitAnd: 2.
longWord _ self longAt: byteAddress - lowBits.
shift _ lowBits * 8.
longWord _ longWord - (longWord bitAnd: (16rFFFF bitShift: shift)) +
(halfWord bitShift: shift).
self longAt: byteAddress - lowBits put: longWord
! !
More information about the Squeak-dev
mailing list
|