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