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