author | Jan Vrany <jan.vrany@labware.com> |
Wed, 23 Jun 2021 12:50:05 +0100 | |
branch | jv |
changeset 25430 | acd92449dc30 |
parent 18079 | 7b5afc0ad3d5 |
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 |
15554 | 70 |
"this is called current-continuation in scheme" |
71 |
||
8557 | 72 |
|cont id| |
73 |
||
10224 | 74 |
cont := self basicNew. |
8557 | 75 |
%{ |
76 |
int __cId; |
|
8559 | 77 |
extern int __continuationCreate(); |
8557 | 78 |
|
8559 | 79 |
__cId = __continuationCreate(cont); |
10224 | 80 |
if (__cId > 0) { |
15554 | 81 |
id = __mkSmallInteger(__cId); |
8557 | 82 |
} |
83 |
%}. |
|
84 |
id isNil ifTrue:[ |
|
15554 | 85 |
self error:'could not create continuation' mayProceed:true. |
86 |
^ nil. |
|
8557 | 87 |
]. |
88 |
cont setId:id process:(Processor activeProcess). |
|
89 |
^ cont |
|
8596 | 90 |
|
91 |
" |
|
10210 | 92 |
self current |
8596 | 93 |
" |
10210 | 94 |
|
15554 | 95 |
"Modified: / 25-07-2013 / 11:37:27 / cg" |
10210 | 96 |
! |
97 |
||
98 |
currentDo: aBlock |
|
15554 | 99 |
"this is is called call/cc in scheme" |
100 |
||
10210 | 101 |
^ aBlock value:self current |
102 |
||
103 |
"Modified: / 29-11-2006 / 10:14:03 / cg" |
|
15554 | 104 |
"Modified (comment): / 25-07-2013 / 11:37:00 / cg" |
10210 | 105 |
! |
106 |
||
107 |
new |
|
108 |
self error:'continuations must be created with #current' |
|
109 |
||
110 |
"Modified: / 29-11-2006 / 10:13:19 / cg" |
|
8557 | 111 |
! ! |
112 |
||
8582 | 113 |
!Continuation methodsFor:'invocation'! |
114 |
||
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
115 |
argumentCount |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
116 |
"VisualAge/ANSI compatibility" |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
117 |
|
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8596
diff
changeset
|
118 |
^ 1 |
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 |
|
8582 | 121 |
numArgs |
122 |
^ 1 |
|
123 |
! |
|
124 |
||
125 |
value |
|
126 |
self value: nil |
|
127 |
! |
|
128 |
||
129 |
value: v |
|
8596 | 130 |
|cID| |
131 |
||
132 |
(cID := id) notNil ifTrue:[ |
|
133 |
%{ |
|
11259 | 134 |
__continuationResume(__intVal(cID)); |
8596 | 135 |
%} |
136 |
]. |
|
11304
dbc86babac7d
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
11259
diff
changeset
|
137 |
self shouldImplement. |
8596 | 138 |
|
8582 | 139 |
"/ self terminate: thisContext. |
140 |
"/ self restoreValues. |
|
141 |
"/ thisContext swapSender: values first. |
|
142 |
"/ ^v |
|
143 |
! |
|
144 |
||
145 |
valueWithArguments: v |
|
146 |
v size == 1 ifFalse: [^self error: 'continuations can only be resumed with one argument']. |
|
147 |
self value: v first |
|
148 |
! ! |
|
149 |
||
150 |
!Continuation methodsFor:'private'! |
|
151 |
||
152 |
terminate: aContext |
|
11304
dbc86babac7d
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
11259
diff
changeset
|
153 |
self shouldImplement. |
8582 | 154 |
"/ | context | |
155 |
"/ context _ aContext. |
|
156 |
"/ [context notNil] whileTrue: [context _ context swapSender: nil] |
|
157 |
! ! |
|
158 |
||
8557 | 159 |
!Continuation methodsFor:'private accessing'! |
160 |
||
8596 | 161 |
finalize |
162 |
|cId| |
|
163 |
||
164 |
(cId := id) notNil ifTrue:[ |
|
10224 | 165 |
id := nil. |
8596 | 166 |
%{ |
10224 | 167 |
__continuationDestroy(__intVal(cId)); |
8596 | 168 |
%} |
169 |
]. |
|
170 |
! |
|
171 |
||
8557 | 172 |
setId:idArg process:aProcess |
173 |
id := idArg. |
|
174 |
process := aProcess. |
|
8596 | 175 |
self registerForFinalization. |
8557 | 176 |
! ! |
177 |
||
8848 | 178 |
!Continuation methodsFor:'restoration'! |
179 |
||
180 |
restoreValues |
|
11304
dbc86babac7d
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
11259
diff
changeset
|
181 |
self shouldImplement. |
8848 | 182 |
"/ | valueStream context | |
183 |
"/ |
|
184 |
"/ valueStream _ values readStream. |
|
185 |
"/ [valueStream atEnd] whileFalse: |
|
186 |
"/ [context _ valueStream next. |
|
187 |
"/ 1 to: context class instSize do: [:i | context instVarAt: i put: valueStream next]. |
|
188 |
"/ 1 to: context localSize do: [:i | context localAt: i put: valueStream next]] |
|
189 |
! ! |
|
190 |
||
8553 | 191 |
!Continuation class methodsFor:'documentation'! |
192 |
||
193 |
version |
|
15554 | 194 |
^ '$Header: /cvs/stx/stx/libbasic/Continuation.st,v 1.16 2013-07-25 09:37:35 cg Exp $' |
17865 | 195 |
! |
196 |
||
197 |
version_SVN |
|
17911 | 198 |
^ '$Id: Continuation.st 10761 2012-01-19 11:46:00Z vranyj1 $' |
8553 | 199 |
! ! |
15554 | 200 |