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
|
|
67 |
^ self fromContext: thisContext sender
|
|
68 |
!
|
|
69 |
|
|
70 |
currentDo: aBlock
|
|
71 |
^ aBlock value: (self fromContext: thisContext sender)
|
|
72 |
!
|
|
73 |
|
|
74 |
fromContext: aStack
|
|
75 |
^self new initializeFromContext: aStack
|
|
76 |
!
|
|
77 |
|
8557
|
78 |
new
|
|
79 |
|cont id|
|
|
80 |
|
8558
|
81 |
cont := super new.
|
8557
|
82 |
%{
|
|
83 |
int __cId;
|
8559
|
84 |
extern int __continuationCreate();
|
8557
|
85 |
|
8559
|
86 |
__cId = __continuationCreate(cont);
|
8557
|
87 |
if (__cId) {
|
|
88 |
id = __MKSMALLINT(__cId);
|
|
89 |
}
|
|
90 |
%}.
|
|
91 |
id isNil ifTrue:[
|
|
92 |
self error:'could not create continuation' mayProceed:true.
|
|
93 |
^ nil.
|
|
94 |
].
|
|
95 |
cont setId:id process:(Processor activeProcess).
|
|
96 |
^ cont
|
|
97 |
! !
|
|
98 |
|
8582
|
99 |
!Continuation methodsFor:'as yet unclassified'!
|
|
100 |
|
|
101 |
restoreValues
|
|
102 |
self halt.
|
|
103 |
"/ | valueStream context |
|
|
104 |
"/
|
|
105 |
"/ valueStream _ values readStream.
|
|
106 |
"/ [valueStream atEnd] whileFalse:
|
|
107 |
"/ [context _ valueStream next.
|
|
108 |
"/ 1 to: context class instSize do: [:i | context instVarAt: i put: valueStream next].
|
|
109 |
"/ 1 to: context localSize do: [:i | context localAt: i put: valueStream next]]
|
|
110 |
! !
|
|
111 |
|
|
112 |
!Continuation methodsFor:'invocation'!
|
|
113 |
|
|
114 |
numArgs
|
|
115 |
^ 1
|
|
116 |
!
|
|
117 |
|
|
118 |
value
|
|
119 |
self value: nil
|
|
120 |
!
|
|
121 |
|
|
122 |
value: v
|
|
123 |
self halt.
|
|
124 |
"/ self terminate: thisContext.
|
|
125 |
"/ self restoreValues.
|
|
126 |
"/ thisContext swapSender: values first.
|
|
127 |
"/ ^v
|
|
128 |
!
|
|
129 |
|
|
130 |
valueWithArguments: v
|
|
131 |
v size == 1 ifFalse: [^self error: 'continuations can only be resumed with one argument'].
|
|
132 |
self value: v first
|
|
133 |
! !
|
|
134 |
|
|
135 |
!Continuation methodsFor:'private'!
|
|
136 |
|
|
137 |
initializeFromContext: aContext
|
|
138 |
self halt.
|
|
139 |
"/ | valueStream context |
|
|
140 |
"/
|
|
141 |
"/ valueStream _ WriteStream on: (Array new: 20).
|
|
142 |
"/ context _ aContext.
|
|
143 |
"/ [context notNil] whileTrue:
|
|
144 |
"/ [valueStream nextPut: context.
|
|
145 |
"/ 1 to: context class instSize do: [:i | valueStream nextPut: (context instVarAt: i)].
|
|
146 |
"/ 1 to: context localSize do: [:i | valueStream nextPut: (context localAt: i)].
|
|
147 |
"/ context _ context sender].
|
|
148 |
"/ values _ valueStream contents
|
|
149 |
!
|
|
150 |
|
|
151 |
terminate: aContext
|
|
152 |
self halt.
|
|
153 |
"/ | context |
|
|
154 |
"/ context _ aContext.
|
|
155 |
"/ [context notNil] whileTrue: [context _ context swapSender: nil]
|
|
156 |
! !
|
|
157 |
|
8557
|
158 |
!Continuation methodsFor:'private accessing'!
|
|
159 |
|
|
160 |
setId:idArg process:aProcess
|
|
161 |
id := idArg.
|
|
162 |
process := aProcess.
|
|
163 |
! !
|
|
164 |
|
8553
|
165 |
!Continuation class methodsFor:'documentation'!
|
|
166 |
|
|
167 |
version
|
8582
|
168 |
^ '$Header: /cvs/stx/stx/libbasic/Continuation.st,v 1.6 2004-09-22 11:52:26 cg Exp $'
|
8553
|
169 |
! !
|