'From Cuis 1.0 of 28 November 2009 [latest update: #337] on 8 December 2009 at 3:57:43 pm'!

!MethodContext methodsFor: 'accessing' stamp: 'jmv 12/8/2009 15:57'!
closure
	^closureOrNil! !

!MethodContext methodsFor: 'accessing' stamp: 'jmv 12/8/2009 15:57'!
hasMethodReturn
	^closureOrNil hasMethodReturn! !

!MethodContext methodsFor: 'accessing' stamp: 'jmv 12/8/2009 15:57'!
methodReturnContext
	"Answer the context from which an ^-return should return from."

	closureOrNil == nil ifTrue:
		[^self].
	^closureOrNil outerContext methodReturnContext! !

!MethodContext methodsFor: 'accessing' stamp: 'jmv 12/8/2009 15:57'!
outerContext
	"Answer the context within which the receiver is nested."

	^closureOrNil == nil ifFalse:
		[closureOrNil outerContext]! !

!MethodContext methodsFor: 'private' stamp: 'jmv 12/8/2009 15:57'!
setSender: s receiver: r method: m closure: c startpc: startpc
	"Create the receiver's initial state."

	sender := s.
	receiver := r.
	method := m.
	closureOrNil := c.
	pc := startpc.
	stackp := 0! !

!MethodContext methodsFor: 'instruction decoding (closures)' stamp: 'jmv 12/8/2009 15:57'!
blockReturnTop
	"Simulate the interpreter's action when a ReturnTopOfStackToCaller bytecode is 
	 encountered in the receiver.  This should only happen in a closure activation."
	self assert: closureOrNil isClosure.
	^self return: self pop from: self! !

!MethodContext methodsFor: 'system simulation' stamp: 'jmv 12/8/2009 15:57'!
pushArgs: args "<Array>" from: sendr "<ContextPart>" 
	"Helps simulate action of the value primitive for closures.
	 This is used by ContextPart>>runSimulated:contextAtEachStep:"

	stackp ~= 0 ifTrue:
		[self error: 'stack pointer should be zero!!'].
	closureOrNil ifNil:
		[self error: 'context needs a closure!!'].
	args do: [:arg| self push: arg].
	1 to: closureOrNil numCopiedValues do:
		[:i|
		self push: (closureOrNil copiedValueAt: i)].
	sender := sendr! !

