author | Claus Gittinger <cg@exept.de> |
Fri, 18 Aug 2006 16:23:48 +0200 | |
changeset 9586 | eb87399baea3 |
parent 8913 | b9498d27a554 |
child 10210 | 963dac304d35 |
permissions | -rw-r--r-- |
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 |
||
8848 | 22 |
Continuation comment:'declared from: ..\..\..\stx\libbasic\abbrev.stc' |
23 |
! |
|
24 |
||
8554 | 25 |
!Continuation class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
8849 | 43 |
Initial attempt - Uninished. |
44 |
Continuations do not work yet - there is more support needed in the VM. |
|
8554 | 45 |
|
46 |
[Instance variables:] |
|
47 |
||
48 |
id <SmallInteger> a unique continuation-id; |
|
49 |
Used to identify a corresponding |
|
50 |
data-structure in the VM. |
|
51 |
||
52 |
process <Process> the process which created this continuation. |
|
53 |
||
54 |
[Class variables:] |
|
55 |
||
56 |
[see also:] |
|
57 |
Process Context Block |
|
58 |
||
59 |
[author:] |
|
60 |
Claus Gittinger |
|
61 |
" |
|
8582 | 62 |
! |
63 |
||
64 |
supported |
|
65 |
^ false |
|
8554 | 66 |
! ! |
8553 | 67 |
|
8557 | 68 |
!Continuation class methodsFor:'instance creation'! |
69 |
||
8582 | 70 |
current |
8596 | 71 |
^ self new |
72 |
"/ ^ self fromContext: thisContext sender |
|
8582 | 73 |
! |
74 |
||
75 |
currentDo: aBlock |
|
8596 | 76 |
^ aBlock value:self new |
77 |
||
78 |
"/ ^ aBlock value: (self fromContext: thisContext sender) |
|
8582 | 79 |
! |
80 |
||
81 |
fromContext: aStack |
|
8596 | 82 |
aStack == thisContext sender ifFalse:[ |
83 |
self error. |
|
84 |
]. |
|
85 |
^ self new |
|
86 |
||
87 |
"/ ^ self new initializeFromContext: aStack |
|
8582 | 88 |
! |
89 |
||
8557 | 90 |
new |
91 |
|cont id| |
|
92 |
||
8558 | 93 |
cont := super new. |
8557 | 94 |
%{ |
95 |
int __cId; |
|
8559 | 96 |
extern int __continuationCreate(); |
8557 | 97 |
|
8559 | 98 |
__cId = __continuationCreate(cont); |
8557 | 99 |
if (__cId) { |
8913 | 100 |
id = __mkSmallInteger(__cId); |
8557 | 101 |
} |
102 |
%}. |
|
103 |
id isNil ifTrue:[ |
|
104 |
self error:'could not create continuation' mayProceed:true. |
|
105 |
^ nil. |
|
106 |
]. |
|
107 |
cont setId:id process:(Processor activeProcess). |
|
108 |
^ cont |
|
8596 | 109 |
|
110 |
" |
|
111 |
self new |
|
112 |
" |
|
8557 | 113 |
! ! |
114 |
||
8582 | 115 |
!Continuation methodsFor:'invocation'! |
116 |
||
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
117 |
argumentCount |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
118 |
"VisualAge/ANSI compatibility" |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
119 |
|
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
120 |
^ 1 |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
121 |
! |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
122 |
|
8582 | 123 |
numArgs |
124 |
^ 1 |
|
125 |
! |
|
126 |
||
127 |
value |
|
128 |
self value: nil |
|
129 |
! |
|
130 |
||
131 |
value: v |
|
8596 | 132 |
|cID| |
133 |
||
134 |
(cID := id) notNil ifTrue:[ |
|
135 |
%{ |
|
136 |
__continuationResume(__intVal(cID)); |
|
137 |
%} |
|
138 |
]. |
|
8582 | 139 |
self halt. |
8596 | 140 |
|
8582 | 141 |
"/ self terminate: thisContext. |
142 |
"/ self restoreValues. |
|
143 |
"/ thisContext swapSender: values first. |
|
144 |
"/ ^v |
|
145 |
! |
|
146 |
||
147 |
valueWithArguments: v |
|
148 |
v size == 1 ifFalse: [^self error: 'continuations can only be resumed with one argument']. |
|
149 |
self value: v first |
|
150 |
! ! |
|
151 |
||
152 |
!Continuation methodsFor:'private'! |
|
153 |
||
154 |
initializeFromContext: aContext |
|
155 |
self halt. |
|
156 |
"/ | valueStream context | |
|
157 |
"/ |
|
158 |
"/ valueStream _ WriteStream on: (Array new: 20). |
|
159 |
"/ context _ aContext. |
|
160 |
"/ [context notNil] whileTrue: |
|
161 |
"/ [valueStream nextPut: context. |
|
162 |
"/ 1 to: context class instSize do: [:i | valueStream nextPut: (context instVarAt: i)]. |
|
163 |
"/ 1 to: context localSize do: [:i | valueStream nextPut: (context localAt: i)]. |
|
164 |
"/ context _ context sender]. |
|
165 |
"/ values _ valueStream contents |
|
166 |
! |
|
167 |
||
168 |
terminate: aContext |
|
169 |
self halt. |
|
170 |
"/ | context | |
|
171 |
"/ context _ aContext. |
|
172 |
"/ [context notNil] whileTrue: [context _ context swapSender: nil] |
|
173 |
! ! |
|
174 |
||
8557 | 175 |
!Continuation methodsFor:'private accessing'! |
176 |
||
8596 | 177 |
finalize |
178 |
|cId| |
|
179 |
||
180 |
(cId := id) notNil ifTrue:[ |
|
181 |
id := nil. |
|
182 |
%{ |
|
183 |
__continuationDestroy(__intVal(cId)); |
|
184 |
%} |
|
185 |
]. |
|
186 |
! |
|
187 |
||
8557 | 188 |
setId:idArg process:aProcess |
189 |
id := idArg. |
|
190 |
process := aProcess. |
|
8596 | 191 |
self registerForFinalization. |
8557 | 192 |
! ! |
193 |
||
8848 | 194 |
!Continuation methodsFor:'restoration'! |
195 |
||
196 |
restoreValues |
|
197 |
self halt. |
|
198 |
"/ | valueStream context | |
|
199 |
"/ |
|
200 |
"/ valueStream _ values readStream. |
|
201 |
"/ [valueStream atEnd] whileFalse: |
|
202 |
"/ [context _ valueStream next. |
|
203 |
"/ 1 to: context class instSize do: [:i | context instVarAt: i put: valueStream next]. |
|
204 |
"/ 1 to: context localSize do: [:i | context localAt: i put: valueStream next]] |
|
205 |
! ! |
|
206 |
||
8553 | 207 |
!Continuation class methodsFor:'documentation'! |
208 |
||
209 |
version |
|
8913 | 210 |
^ '$Header: /cvs/stx/stx/libbasic/Continuation.st,v 1.11 2005-07-08 17:15:01 cg Exp $' |
8553 | 211 |
! ! |