﻿'From Squeak6.1alpha of 13 February 2023 [latest update: #22434] on 14 February 2023 at 10:13:59 pm'!

!Context methodsFor: 'instruction decoding' stamp: 'jar 2/14/2023 22:12'!
return: value from: aSender 
	"For simulation.  Roll back self to aSender and return value from it.  Execute any unwind blocks on the way.  ASSUMES aSender is a sender of self"

	| newTop |
	aSender isDead ifTrue:
		[^self send: #cannotReturn: to: self with: {value}].
	newTop := aSender sender.
	(self findNextUnwindContextUpTo: newTop) ifNotNil:
		"Send #aboutToReturn:through: with nil as the second argument to avoid this bug:
		 Cannot #stepOver '^2' in example '[^2] ensure: []'.
		 See http://lists.squeakfoundation.org/pipermail/squeak-dev/2022-June/220975.html"
		[^self send: #aboutToReturn:through: to: self with: {value. nil}].
	self releaseTo: newTop.
	newTop ifNotNil: [newTop push: value].
	^newTop! !

!Context methodsFor: 'controlling' stamp: 'jar 2/14/2023 22:06'!
restart
	"Unwind thisContext to self and resume from beginning.  Execute unwind blocks when unwinding.  ASSUMES self is a sender of thisContext"

	^self resumeEvaluating: [self privRefresh]! !

!Context methodsFor: 'controlling' stamp: 'jar 2/14/2023 22:09'!
resume: value through: firstUnwindCtxt
	"Unwind thisContext to self and resume with value as result of last send.
	 Execute any unwind blocks while unwinding.
	 ASSUMES self is a sender of thisContext."

	^self resumeEvaluating: [value] through: firstUnwindCtxt! !

!Context methodsFor: 'controlling' stamp: 'jar 2/14/2023 22:08'!
resumeEvaluating: aBlock
	"Unwind thisContext to self and resume with value as result of last send. 
	Execute unwind blocks when unwinding.
	ASSUMES self is a sender of thisContext"

	^self resumeEvaluating: aBlock through: nil! !

!Context methodsFor: 'controlling' stamp: 'jar 2/14/2023 22:08'!
resumeEvaluating: aBlock through: firstUnwindCtxtOrNil
	"Unwind thisContext to self and resume with value as result of last send. 
	 Execute unwind blocks when unwinding.
	 ASSUMES self is a sender of thisContext."

	self isDead ifTrue: [self cannotReturn: aBlock value to: self].
	(firstUnwindCtxtOrNil ifNil: thisContext) unwindTo: self safely: false.
	thisContext terminateTo: self.
	^aBlock value! !

