Continuation


Seaside-Continuations

Comment:



Hierarchy:

ProtoObject
Object
Continuation

Summary:

instance variables:

values

methods:

instance class
as yet unclassified invocation private instance creation

Detail:

instance variables:

values
inferredType:
UndefinedObject

instance methods:

as yet unclassified
restoreValues

	| valueStream context |
	valueStream _ values readStream.
	[valueStream atEnd] whileFalse:
		[context _ valueStream next.
		1 to: context class instSize do: [:i | context instVarAt: i put: valueStream next].
		1 to: context localSize do: [:i | context localAt: i put: valueStream next]]

invocation
numArgs

	^ 1
value

	self value: nil
value: v

	self terminate: thisContext.
	self restoreValues.
	thisContext swapSender: values first.
	^v
valueWithArguments: v

	v size == 1 ifFalse: [^self error: 'continuations can only be resumed with one argument'].
	self value: v first

private
initializeFromContext: aContext

	| valueStream context |
	valueStream _ WriteStream on: (Array new: 20).
	context _ aContext.
	[context notNil] whileTrue:
		[valueStream nextPut: context.
		1 to: context class instSize do: [:i | valueStream nextPut: (context instVarAt: i)].
		1 to: context localSize do: [:i | valueStream nextPut: (context localAt: i)].
		context _ context sender].
	values _ valueStream contents
terminate: aContext

	| context |
	context _ aContext.
	[context notNil] whileTrue: [context _ context swapSender: nil]

class methods:

instance creation
current

	^ self fromContext: thisContext sender
currentDo: aBlock

	^ aBlock value: (self fromContext: thisContext sender)
fromContext: aStack

	^self new initializeFromContext: aStack

^top


- made by Dandelion -