'From Cuis 2.6 of 10 August 2010 [latest update: #540] on 29 August 2010 at 9:02:01 am'!

!InstructionStream methodsFor: 'scanning' stamp: 'eem 8/13/2010 11:45'!
followingBytecode
	"Answer the bytecode of the following bytecode (different to nextByte)."

	^self method at: self followingPc! !

!InstructionStream methodsFor: 'scanning' stamp: 'eem 8/13/2010 11:45'!
followingPc
	"Answer the pc of the following bytecode."

	^self nextPc: (self method at: pc)! !

!InstructionStream methodsFor: 'scanning' stamp: 'eem 8/13/2010 11:43'!
scanFor: scanBlock
	"Answer the index of the first bytecode for which scanBlock
	 answers true when supplied with that bytecode."

	| method end byte |
	method := self method.
	end := method endPC.
	[pc <= end] whileTrue: 
		[(scanBlock value: (byte := method at: pc)) ifTrue:
			[^true].
		 pc := self nextPc: byte].
	^false! !

!InstructionStream methodsFor: 'scanning' stamp: 'eem 6/16/2008 09:52'!
thirdByte
	"Answer the third byte of the current bytecode."

	^self method at: pc + 2! !

!InstructionStream methodsFor: 'private' stamp: 'eem 8/13/2010 11:38'!
nextPc: currentByte
	"Answer the pc of the next bytecode following the current one, given the current bytecode.."

	| type |
	type := currentByte // 16.
	^type = 8 "extensions"
				ifTrue: [pc + (#(2 2 2 2 3 2 2 1 1 1 2 1 3 3 3 4) at: currentByte \\ 16 + 1)]
				ifFalse: [type = 10 "long jumps"
							ifTrue: [pc + 2]
							ifFalse: [pc + 1]]! !

