author | Stefan Vogel <sv@exept.de> |
Fri, 21 Jan 2005 17:49:43 +0100 | |
changeset 8687 | d6e6e2c0c27c |
parent 8596 | 5433434a9bf0 |
child 8848 | 54c8ceb41539 |
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 |
||
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 |
||
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
126 |
argumentCount |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
127 |
"VisualAge/ANSI compatibility" |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
128 |
|
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
129 |
^ 1 |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
130 |
! |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
131 |
|
8582 | 132 |
numArgs |
133 |
^ 1 |
|
134 |
! |
|
135 |
||
136 |
value |
|
137 |
self value: nil |
|
138 |
! |
|
139 |
||
140 |
value: v |
|
8596 | 141 |
|cID| |
142 |
||
143 |
(cID := id) notNil ifTrue:[ |
|
144 |
%{ |
|
145 |
__continuationResume(__intVal(cID)); |
|
146 |
%} |
|
147 |
]. |
|
8582 | 148 |
self halt. |
8596 | 149 |
|
8582 | 150 |
"/ self terminate: thisContext. |
151 |
"/ self restoreValues. |
|
152 |
"/ thisContext swapSender: values first. |
|
153 |
"/ ^v |
|
154 |
! |
|
155 |
||
156 |
valueWithArguments: v |
|
157 |
v size == 1 ifFalse: [^self error: 'continuations can only be resumed with one argument']. |
|
158 |
self value: v first |
|
159 |
! ! |
|
160 |
||
161 |
!Continuation methodsFor:'private'! |
|
162 |
||
163 |
initializeFromContext: aContext |
|
164 |
self halt. |
|
165 |
"/ | valueStream context | |
|
166 |
"/ |
|
167 |
"/ valueStream _ WriteStream on: (Array new: 20). |
|
168 |
"/ context _ aContext. |
|
169 |
"/ [context notNil] whileTrue: |
|
170 |
"/ [valueStream nextPut: context. |
|
171 |
"/ 1 to: context class instSize do: [:i | valueStream nextPut: (context instVarAt: i)]. |
|
172 |
"/ 1 to: context localSize do: [:i | valueStream nextPut: (context localAt: i)]. |
|
173 |
"/ context _ context sender]. |
|
174 |
"/ values _ valueStream contents |
|
175 |
! |
|
176 |
||
177 |
terminate: aContext |
|
178 |
self halt. |
|
179 |
"/ | context | |
|
180 |
"/ context _ aContext. |
|
181 |
"/ [context notNil] whileTrue: [context _ context swapSender: nil] |
|
182 |
! ! |
|
183 |
||
8557 | 184 |
!Continuation methodsFor:'private accessing'! |
185 |
||
8596 | 186 |
finalize |
187 |
|cId| |
|
188 |
||
189 |
(cId := id) notNil ifTrue:[ |
|
190 |
id := nil. |
|
191 |
%{ |
|
192 |
__continuationDestroy(__intVal(cId)); |
|
193 |
%} |
|
194 |
]. |
|
195 |
! |
|
196 |
||
8557 | 197 |
setId:idArg process:aProcess |
198 |
id := idArg. |
|
199 |
process := aProcess. |
|
8596 | 200 |
self registerForFinalization. |
8557 | 201 |
! ! |
202 |
||
8553 | 203 |
!Continuation class methodsFor:'documentation'! |
204 |
||
205 |
version |
|
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
206 |
^ '$Header: /cvs/stx/stx/libbasic/Continuation.st,v 1.8 2005-01-21 16:48:46 stefan Exp $' |
8553 | 207 |
! ! |