'From Pharo3.0 of 18 March 2013 [Latest update: #30864] on 9 January 2016 at 12:23:34.657922 am'!
IRStackCount subclass: #IRClosureStackCount
	instanceVariableNames: 'numMethodTempVars'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'OpalCompiler-Core-Bytecode'!

!IRClosureStackCount commentStamp: '<historical>' prior: 0!
IRClosureStackCount is used to distinguish between a stack 
in the method scope and a stack within a closure block. The
closure stack size is independent of the number of tempvars from the compiled method, therefore that number is subtracted
from this stack size length.!


!IRBytecodeGenerator methodsFor: 'instructions' stamp: 'DrGeoUser 1/9/2016 00:03'!
pushClosureCopyNumCopiedValues: numCopied numArgs: numArgs2 to: toSeqId
	
	| blockSeqId |
	blockSeqId := self newDummySeqId.
	stack pop: numCopied. 
	stacks at: blockSeqId put: ((IRClosureStackCount new numMethodTempVars:(numberOfTemps)) startAt: (numArgs2+numCopied)).
	stack push.
	stacks at: toSeqId put: (stack linkTo: (stacks at: toSeqId ifAbsentPut: [nil])).
	self saveLastJump: (Message
		selector: #closureFrom:to:copyNumCopiedValues:numArgs:
		arguments: {currentSeqId.toSeqId. numCopied. numArgs2.}).

	self closureFrom: currentSeqId to: toSeqId copyNumCopiedValues: numCopied numArgs: numArgs2.
	self label: blockSeqId.
! !

!IRBytecodeGenerator methodsFor: 'instructions' stamp: 'DrGeoUser 1/9/2016 00:03'!
label: seqId
	lastSpecialReturn := nil.
	currentSeqId := seqId.
	currentSeqNum := currentSeqNum + 1.
	seqOrder at: seqId put: currentSeqNum.
	orderSeq at: currentSeqNum ifAbsentPut: [seqId].
	bytes := seqBytes at: seqId ifAbsentPut: [OrderedCollection new].
	jumps at: seqId ifAbsentPut: [nil].
	instrMap := instrMaps at: seqId ifAbsentPut: [OrderedCollection new].
	stack
		ifNil: [ stack := stacks at: currentSeqId ifAbsentPut: [ IRStackCount new ] ]
		ifNotNil: [stack := stacks at: currentSeqId ifAbsentPut: [ stack class newOn:stack ] ]! !


!IRStackCount methodsFor: 'results' stamp: 'NicolaiHess 11/8/2014 23:51'!
linkTo: stackOrNil

	stackOrNil ifNil: [^ self class newOn: self].
	^ self position = stackOrNil start
		ifTrue: [stackOrNil]
		ifFalse: [self error: 'stack out of sync in bytecode generator']! !


!IRClosureStackCount methodsFor: 'accessing' stamp: 'NicolaiHess 11/8/2014 23:47'!
numMethodTempVars
	^ numMethodTempVars! !

!IRClosureStackCount methodsFor: 'accessing' stamp: 'NicolaiHess 11/9/2014 00:05'!
numMethodTempVars: nilOrNumber
	numMethodTempVars := nilOrNumber ifNil:[0]! !

!IRClosureStackCount methodsFor: 'accessing' stamp: 'NicolaiHess 11/8/2014 23:47'!
length

	^ super length - self numMethodTempVars! !

!IRClosureStackCount methodsFor: 'initialize' stamp: 'NicolaiHess 11/8/2014 23:47'!
initialize

	super initialize.

	numMethodTempVars := 0.! !


!IRStackCount class methodsFor: 'instance creation' stamp: 'NicolaiHess 11/8/2014 23:50'!
newOn: stack

	^ self startAt: stack position! !


!IRClosureStackCount class methodsFor: 'instance creation' stamp: 'NicolaiHess 11/8/2014 23:54'!
newOn: stack
	^ (self startAt: stack position)
		numMethodTempVars: stack numMethodTempVars;
		yourself! !

