8554
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2004 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
8553
|
13 |
"{ Package: 'stx:libbasic' }"
|
|
14 |
|
|
15 |
Object subclass:#Continuation
|
|
16 |
instanceVariableNames:'process id suspendContext'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Kernel-Processes'
|
|
20 |
!
|
|
21 |
|
8554
|
22 |
!Continuation class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 2004 by eXept Software AG
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
|
38 |
documentation
|
|
39 |
"
|
|
40 |
Initial attempt - Contnuations do not work yet.
|
|
41 |
|
|
42 |
[Instance variables:]
|
|
43 |
|
|
44 |
id <SmallInteger> a unique continuation-id;
|
|
45 |
Used to identify a corresponding
|
|
46 |
data-structure in the VM.
|
|
47 |
|
|
48 |
process <Process> the process which created this continuation.
|
|
49 |
|
|
50 |
[Class variables:]
|
|
51 |
|
|
52 |
[see also:]
|
|
53 |
Process Context Block
|
|
54 |
|
|
55 |
[author:]
|
|
56 |
Claus Gittinger
|
|
57 |
"
|
8582
|
58 |
!
|
|
59 |
|
|
60 |
supported
|
|
61 |
^ false
|
8554
|
62 |
! !
|
8553
|
63 |
|
8557
|
64 |
!Continuation class methodsFor:'instance creation'!
|
|
65 |
|
8582
|
66 |
current
|
8596
|
67 |
^ self new
|
|
68 |
"/ ^ self fromContext: thisContext sender
|
8582
|
69 |
!
|
|
70 |
|
|
71 |
currentDo: aBlock
|
8596
|
72 |
^ aBlock value:self new
|
|
73 |
|
|
74 |
"/ ^ aBlock value: (self fromContext: thisContext sender)
|
8582
|
75 |
!
|
|
76 |
|
|
77 |
fromContext: aStack
|
8596
|
78 |
aStack == thisContext sender ifFalse:[
|
|
79 |
self error.
|
|
80 |
].
|
|
81 |
^ self new
|
|
82 |
|
|
83 |
"/ ^ self new initializeFromContext: aStack
|
8582
|
84 |
!
|
|
85 |
|
8557
|
86 |
new
|
|
87 |
|cont id|
|
|
88 |
|
8558
|
89 |
cont := super new.
|
8557
|
90 |
%{
|
|
91 |
int __cId;
|
8559
|
92 |
extern int __continuationCreate();
|
8557
|
93 |
|
8559
|
94 |
__cId = __continuationCreate(cont);
|
8557
|
95 |
if (__cId) {
|
|
96 |
id = __MKSMALLINT(__cId);
|
|
97 |
}
|
|
98 |
%}.
|
|
99 |
id isNil ifTrue:[
|
|
100 |
self error:'could not create continuation' mayProceed:true.
|
|
101 |
^ nil.
|
|
102 |
].
|
|
103 |
cont setId:id process:(Processor activeProcess).
|
|
104 |
^ cont
|
8596
|
105 |
|
|
106 |
"
|
|
107 |
self new
|
|
108 |
"
|
8557
|
109 |
! !
|
|
110 |
|
8582
|
111 |
!Continuation methodsFor:'as yet unclassified'!
|
|
112 |
|
|
113 |
restoreValues
|
|
114 |
self halt.
|
|
115 |
"/ | valueStream context |
|
|
116 |
"/
|
|
117 |
"/ valueStream _ values readStream.
|
|
118 |
"/ [valueStream atEnd] whileFalse:
|
|
119 |
"/ [context _ valueStream next.
|
|
120 |
"/ 1 to: context class instSize do: [:i | context instVarAt: i put: valueStream next].
|
|
121 |
"/ 1 to: context localSize do: [:i | context localAt: i put: valueStream next]]
|
|
122 |
! !
|
|
123 |
|
|
124 |
!Continuation methodsFor:'invocation'!
|
|
125 |
|
|
126 |
numArgs
|
|
127 |
^ 1
|
|
128 |
!
|
|
129 |
|
|
130 |
value
|
|
131 |
self value: nil
|
|
132 |
!
|
|
133 |
|
|
134 |
value: v
|
8596
|
135 |
|cID|
|
|
136 |
|
|
137 |
(cID := id) notNil ifTrue:[
|
|
138 |
%{
|
|
139 |
__continuationResume(__intVal(cID));
|
|
140 |
%}
|
|
141 |
].
|
8582
|
142 |
self halt.
|
8596
|
143 |
|
8582
|
144 |
"/ self terminate: thisContext.
|
|
145 |
"/ self restoreValues.
|
|
146 |
"/ thisContext swapSender: values first.
|
|
147 |
"/ ^v
|
|
148 |
!
|
|
149 |
|
|
150 |
valueWithArguments: v
|
|
151 |
v size == 1 ifFalse: [^self error: 'continuations can only be resumed with one argument'].
|
|
152 |
self value: v first
|
|
153 |
! !
|
|
154 |
|
|
155 |
!Continuation methodsFor:'private'!
|
|
156 |
|
|
157 |
initializeFromContext: aContext
|
|
158 |
self halt.
|
|
159 |
"/ | valueStream context |
|
|
160 |
"/
|
|
161 |
"/ valueStream _ WriteStream on: (Array new: 20).
|
|
162 |
"/ context _ aContext.
|
|
163 |
"/ [context notNil] whileTrue:
|
|
164 |
"/ [valueStream nextPut: context.
|
|
165 |
"/ 1 to: context class instSize do: [:i | valueStream nextPut: (context instVarAt: i)].
|
|
166 |
"/ 1 to: context localSize do: [:i | valueStream nextPut: (context localAt: i)].
|
|
167 |
"/ context _ context sender].
|
|
168 |
"/ values _ valueStream contents
|
|
169 |
!
|
|
170 |
|
|
171 |
terminate: aContext
|
|
172 |
self halt.
|
|
173 |
"/ | context |
|
|
174 |
"/ context _ aContext.
|
|
175 |
"/ [context notNil] whileTrue: [context _ context swapSender: nil]
|
|
176 |
! !
|
|
177 |
|
8557
|
178 |
!Continuation methodsFor:'private accessing'!
|
|
179 |
|
8596
|
180 |
finalize
|
|
181 |
|cId|
|
|
182 |
|
|
183 |
(cId := id) notNil ifTrue:[
|
|
184 |
id := nil.
|
|
185 |
%{
|
|
186 |
__continuationDestroy(__intVal(cId));
|
|
187 |
%}
|
|
188 |
].
|
|
189 |
!
|
|
190 |
|
8557
|
191 |
setId:idArg process:aProcess
|
|
192 |
id := idArg.
|
|
193 |
process := aProcess.
|
8596
|
194 |
self registerForFinalization.
|
8557
|
195 |
! !
|
|
196 |
|
8553
|
197 |
!Continuation class methodsFor:'documentation'!
|
|
198 |
|
|
199 |
version
|
8596
|
200 |
^ '$Header: /cvs/stx/stx/libbasic/Continuation.st,v 1.7 2004-09-27 10:16:12 ca Exp $'
|
8553
|
201 |
! !
|