996
|
1 PLEASE NOTE
|
|
2
|
|
3 Copyright (C) 2008 Alex Smith
|
|
4
|
|
5 This program is free software; you can redistribute it and/or modify
|
|
6 it under the terms of the GNU General Public License as published by
|
|
7 the Free Software Foundation; either version 2 of the License, or
|
|
8 (at your option) any later version.
|
|
9
|
|
10 This program is distributed in the hope that it will be useful,
|
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 GNU General Public License for more details.
|
|
14
|
|
15 You should have received a copy of the GNU General Public License
|
|
16 along with this program; if not, write to the Free Software
|
|
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
18
|
|
19 PLEASE NOTE Creating the continuation statements
|
|
20 DO CREATE (8200) GET CONTINUATION IN .1 GETTING .2
|
|
21 DO CREATE (8200) GET CONTINUATION IN ,1 SUB #1 GETTING .2
|
|
22 DO CREATE (8200) GET CONTINUATION IN .1 GETTING ,2 SUB #2
|
|
23 DO CREATE (8200) GET CONTINUATION IN ,1 SUB #1 GETTING ,2 SUB #2
|
|
24 DO CREATE (8210) CONTINUE WITH .1 SENDING .2
|
|
25 DO CREATE (8210) CONTINUE WITH .1 SENDING .2~#2
|
|
26 DO CREATE (8210) CONTINUE WITH .1 SENDING ,2 SUB #2
|
|
27 DO CREATE (8210) CONTINUE WITH .1~#1 SENDING .2
|
|
28 DO CREATE (8210) CONTINUE WITH .1~#1 SENDING .2~#2
|
|
29 DO CREATE (8210) CONTINUE WITH .1~#1 SENDING ,2 SUB #2
|
|
30 DO CREATE (8210) CONTINUE WITH ,1 SUB #1 SENDING .2
|
|
31 DO CREATE (8210) CONTINUE WITH ,1 SUB #1 SENDING .2~#2
|
|
32 DO CREATE (8210) CONTINUE WITH ,1 SUB #1 SENDING ,2 SUB #2
|
|
33 DO CREATE (8205) KILL ALL THREADS
|
|
34 PLEASE NOTE Initialising the counting tracker thread
|
|
35 PLEASE DO .1 <- #0
|
|
36 (8201) DO NOTHING
|
|
37
|
|
38 PLEASE NOTE Definitions of the continuation statements
|
|
39 (8200) DO STASH .1
|
|
40 PLEASE DO (8280) NEXT
|
|
41 PLEASE DO (1020) NEXT
|
|
42 PLEASE DO (8270) NEXT
|
|
43 PLEASE NOTE It's possible for .1 to equal :1601, so we
|
|
44 have to be careful about operating on the
|
|
45 arguments while stashed. So we use the
|
|
46 temporary global variable .8200.
|
|
47 DO .8200 <- .1
|
|
48 DO RETRIEVE .1
|
|
49 DO :1601 <- .8200
|
|
50 DO (8202) NEXT
|
|
51 DO RESUME #1
|
|
52 (8202) PLEASE NOTE Fork threads, one dormant, one alive
|
|
53 DO COME FROM (8202)
|
|
54 DO RESUME #1
|
|
55 (8213) DO RESUME '?".1~.1"$#2'~#3
|
|
56 (8212) DO (8213) NEXT
|
|
57 DO RETRIEVE .1 PLEASE NOTE Restoring .1's stash
|
|
58 DO COME FROM (8202)
|
|
59 PLEASE FORGET #1
|
|
60 (8211) DO COME FROM (8211)
|
|
61 PLEASE NOTE We count how many threads are in 8275 using the
|
|
62 abstention count of 8214 and block until they're
|
|
63 all done.
|
|
64 PLEASE DO ABSTAIN #1 FROM (8214)
|
|
65 DO STASH .1
|
|
66 DO (8275) NEXT
|
|
67 DO REINSTATE (8214)
|
|
68 DO COME FROM (8215)
|
|
69 (8216) DO NOTHING
|
|
70 (8215) DO NOTHING
|
|
71 (8214) DO COME FROM (8216)
|
|
72 PLEASE DO REINSTATE (8211)
|
|
73 PLEASE NOTE If .8200 matches .1, we activate. This uses
|
|
74 a NEXT/NEXT/RESUME-style check because it's
|
|
75 done on multiple threads at once and because
|
|
76 a computed COME FROM would slow down the
|
|
77 program even further.
|
|
78 DO .1 <- '?.8200$.1'~'#0$#65535'
|
|
79 DO (8212) NEXT
|
|
80 PLEASE NOTE that if this point is reached, we've reached
|
|
81 the point where unfreezing the thread is
|
|
82 necessary. First receive one datum from
|
|
83 8277 so we can send something back in the
|
|
84 continuation (this involves signaling using
|
|
85 8217), then the other thread kills itself and
|
|
86 we make a new continuation numbered the same
|
|
87 as the old one, and continue by doubleresuming
|
|
88 (so that an unfreeze can be told apart from an
|
|
89 initial call). As this is a CREATEd statement,
|
|
90 it's important to unstash :1601 and :1602
|
|
91 ourselves when doubleresuming, as the runtime
|
|
92 only does it correctly on a single resume.
|
|
93 PLEASE DO ABSTAIN FROM (8217)
|
|
94 DO (8260) NEXT
|
|
95 DO (8276) NEXT
|
|
96 DO .8201 <- .1
|
|
97 DO RETRIEVE .1 PLEASE NOTE Restoring .1's stash
|
|
98 DO (8202) NEXT PLEASE NOTE .8200 is still correct!
|
|
99 DO :1602 <- .8201
|
|
100 PLEASE DO :1601 <- .8200
|
|
101 DO RETRIEVE :1601
|
|
102 DO RETRIEVE :1602
|
|
103 DO RESUME #2
|
|
104
|
|
105 (8210) PLEASE NOTE Here we use the timing guarantees. Once we
|
|
106 ABSTAIN FROM 8211, all the threads looping
|
|
107 there become unblocked simultaneously, so
|
|
108 all of them abstain 8214 (which is 2-3 cycles)
|
|
109 before any of them REINSTATES 8211 (which is
|
|
110 way lower down, after the call to 8275), so
|
|
111 we can guarantee that all the threads get a
|
|
112 chance to check to see if they match.
|
|
113 DO .8210 <- .1
|
|
114 PLEASE DO .1 <- :1601
|
|
115 DO (8250) NEXT
|
|
116 DO (8270) NEXT
|
|
117 PLEASE DO ABSTAIN FROM (8211)
|
|
118 (8217) DO COME FROM (8217) AGAIN
|
|
119 PLEASE NOTE This double assignment is actually correct,
|
|
120 because :1602 is overloaded.
|
|
121 PLEASE DO .1 <- .8210
|
|
122 DO .1 <- :1602
|
|
123 PLEASE DO (8277) NEXT
|
|
124 PLEASE GIVE UP
|
|
125
|
|
126 PLEASE NOTE A communications channel thread.
|
|
127 This acts like one 16-bit variable, where
|
|
128 8250 stashes the variable
|
|
129 8260 retrieves the variable
|
|
130 8270 copies it from .1
|
|
131 and 8280 copies it into .1
|
|
132
|
|
133 8275 is a mutex version of 8280 so that multiple
|
|
134 threads can try to view .1 at once and only
|
|
135 one will get it at a time.
|
|
136 8299 is a spinlock that traps until the current
|
|
137 operation is completed, which is needed as
|
|
138 part of the implementation of this, and then
|
|
139 double-resumes
|
|
140
|
|
141 (8299) DO COME FROM (8299) AGAIN
|
|
142 PLEASE DO RESUME #2
|
|
143
|
|
144 (8250) DO REINSTATE (8251)
|
|
145 PLEASE DO (8299) NEXT
|
|
146
|
|
147 (8260) DO REINSTATE (8261)
|
|
148 PLEASE DO (8299) NEXT
|
|
149
|
|
150 (8270) DO REINSTATE (8271)
|
|
151 DO (8277) NEXT
|
|
152 PLEASE DO (8299) NEXT
|
|
153
|
|
154 (8280) DO REINSTATE (8281)
|
|
155 DO (8276) NEXT
|
|
156 PLEASE DO (8299) NEXT
|
|
157
|
|
158 (8275) DO COME FROM (8274)
|
|
159 (8274) DO (8273) NEXT ONCE
|
|
160 (8273) DO (8280) NEXT
|
|
161 PLEASE DO REINSTATE (8274)
|
|
162 DO RESUME #2
|
|
163
|
|
164 PLEASE NOTE main part of the communications channel thread
|
|
165 DO COME FROM (8201)
|
|
166 PLEASE DO COME FROM (8259)
|
|
167 (8252) DO NOTHING
|
|
168 (8262) DO NOTHING
|
|
169 (8272) DO NOTHING
|
|
170 (8282) DO NOTHING
|
|
171 (8259) PLEASE DO NOTHING
|
|
172
|
|
173 (8251) DON'T NEXT FROM (8252) AGAIN
|
|
174 DO STASH .1
|
|
175 PLEASE DO ABSTAIN FROM (8299)
|
|
176 DO RESUME #1
|
|
177
|
|
178 (8261) DON'T NEXT FROM (8262) AGAIN
|
|
179 DO RETRIEVE .1
|
|
180 DO ABSTAIN FROM (8299)
|
|
181 DO RESUME #1
|
|
182
|
|
183 (8271) DON'T NEXT FROM (8272) AGAIN
|
|
184 DO (8276) NEXT
|
|
185 DO ABSTAIN FROM (8299)
|
|
186 PLEASE DO RESUME #1
|
|
187
|
|
188 (8281) DON'T NEXT FROM (8282) AGAIN
|
|
189 DO (8277) NEXT
|
|
190 DO ABSTAIN FROM (8299)
|
|
191 PLEASE DO RESUME #1
|
|
192
|
|
193
|
|
194 PLEASE NOTE 16-bit communications channel
|
|
195 8276 will block until data is sent
|
|
196 8277 will send the data
|
|
197 data transferred from .1 to .1
|
|
198
|
|
199 (8276) DO COME FROM (8276) AGAIN
|
|
200 DO .1 <- #65535
|
|
201 (8283) DO .1 <- '?.1$# 1'~'#0$#65535' AGAIN
|
|
202 (8284) DO .1 <- '?.1$# 2'~'#0$#65535' AGAIN
|
|
203 (8285) DO .1 <- '?.1$# 4'~'#0$#65535' AGAIN
|
|
204 (8286) DO .1 <- '?.1$# 8'~'#0$#65535' AGAIN
|
|
205 (8287) DO .1 <- '?.1$# 16'~'#0$#65535' AGAIN
|
|
206 (8288) DO .1 <- '?.1$# 32'~'#0$#65535' AGAIN
|
|
207 (8289) DO .1 <- '?.1$# 64'~'#0$#65535' AGAIN
|
|
208 (8290) DO .1 <- '?.1$# 128'~'#0$#65535' AGAIN
|
|
209 (8291) DO .1 <- '?.1$# 256'~'#0$#65535' AGAIN
|
|
210 (8292) DO .1 <- '?.1$# 512'~'#0$#65535' AGAIN
|
|
211 (8293) DO .1 <- '?.1$# 1024'~'#0$#65535' AGAIN
|
|
212 (8294) DO .1 <- '?.1$# 2048'~'#0$#65535' AGAIN
|
|
213 (8295) DO .1 <- '?.1$# 4096'~'#0$#65535' AGAIN
|
|
214 (8296) DO .1 <- '?.1$# 8192'~'#0$#65535' AGAIN
|
|
215 (8297) DO .1 <- '?.1$#16384'~'#0$#65535' AGAIN
|
|
216 (8298) DO .1 <- '?.1$#32768'~'#0$#65535' AGAIN
|
|
217 DO ABSTAIN FROM (8278)
|
|
218 DO RESUME #1
|
|
219
|
|
220 (8277) DO ABSTAIN .1~# 1 FROM (8283)
|
|
221 DO ABSTAIN .1~# 2 FROM (8284)
|
|
222 DO ABSTAIN .1~# 4 FROM (8285)
|
|
223 DO ABSTAIN .1~# 8 FROM (8286)
|
|
224 DO ABSTAIN .1~# 16 FROM (8287)
|
|
225 DO ABSTAIN .1~# 32 FROM (8288)
|
|
226 DO ABSTAIN .1~# 64 FROM (8289)
|
|
227 DO ABSTAIN .1~# 128 FROM (8290)
|
|
228 DO ABSTAIN .1~# 256 FROM (8291)
|
|
229 DO ABSTAIN .1~# 512 FROM (8292)
|
|
230 DO ABSTAIN .1~# 1024 FROM (8293)
|
|
231 DO ABSTAIN .1~# 2048 FROM (8294)
|
|
232 DO ABSTAIN .1~# 4096 FROM (8295)
|
|
233 DO ABSTAIN .1~# 8192 FROM (8296)
|
|
234 DO ABSTAIN .1~#16384 FROM (8297)
|
|
235 DO ABSTAIN .1~#32768 FROM (8298)
|
|
236 DO ABSTAIN FROM (8276)
|
|
237 (8278) PLEASE DO COME FROM (8278) AGAIN
|
|
238 PLEASE DO RESUME #1
|
|
239
|
|
240 PLEASE NOTE Code for killing all threads. This
|
|
241 is achieved by hoping none of them are
|
|
242 in syslib (which is after the end
|
|
243 of the program), and abstaining from
|
|
244 all flow control operations in the
|
|
245 program, all operations that hold up
|
|
246 execution, and all operations that
|
|
247 could error. Unfortunately, this
|
|
248 can be affected by ONCE/AGAIN, so
|
|
249 each thread will twice more repeat
|
|
250 the abstention in the hope of catching
|
|
251 other threads as it comes past to quit.
|
|
252 Not perfect, but hopefully good enough.
|
|
253 (Of course, a simple E000 would be
|
|
254 better at this job, but it's an error
|
|
255 and non-erroring solutions are better.)
|
|
256 PLEASE DO REINSTATE (8205) AGAIN
|
|
257 PLEASE DO REINSTATE (8206) AGAIN
|
|
258 (8205) PLEASE DO ABSTAIN FROM ABSTAINING + REINSTATING +
|
|
259 CALCULATING + NEXTING + COMING FROM + RESUMING +
|
|
260 FORGETTING + STASHING + RETRIEVING + WRITING IN +
|
|
261 READING OUT + COMMENT AGAIN
|
|
262 DON'T DO ANYTHING FOR A BIT
|
|
263 PLEASE NOTE THAT THIS IS MORE TIME WASTING
|
|
264 (8206) PLEASE DO ABSTAIN FROM ABSTAINING + REINSTATING +
|
|
265 CALCULATING + NEXTING + COMING FROM + RESUMING +
|
|
266 FORGETTING + STASHING + RETRIEVING + WRITING IN +
|
|
267 READING OUT + COMMENT AGAIN
|
|
268 PLEASE GIVE UP
|
|
269
|
|
270 PLEASE NOTE The main program.
|
|
271 DO COME FROM (8201)
|
|
272 DO .2 <- #0
|
|
273 DO (8) NEXT
|
|
274 (9) DO GET CONTINUATION IN .1 GETTING .2
|
|
275 DO (10) NEXT
|
|
276 DO (7) NEXT
|
|
277 (8) DO (9) NEXT
|
|
278 (7) DO FORGET #1
|
|
279 PLEASE DO READ OUT .2
|
|
280 DO CONTINUE WITH .1 SENDING #3 ONCE
|
|
281 DO CONTINUE WITH .1 SENDING #4 ONCE
|
|
282 DO CONTINUE WITH .1 SENDING #5 ONCE
|
|
283 DO CONTINUE WITH .1 SENDING #6 ONCE
|
|
284 DO CONTINUE WITH .1 SENDING #7 ONCE
|
|
285 DO .2 <- .1 ONCE
|
|
286 DO (11) NEXT
|
|
287 (12) DO GET CONTINUATION IN .3 GETTING .2
|
|
288 DO READ OUT #31 + .1 + .2 + .3
|
|
289 DO CONTINUE WITH .3 SENDING .2
|
|
290 (11) DO (12) NEXT
|
|
291 PLEASE DO READ OUT #30 + .1 + .2 + .3
|
|
292 PLEASE DO CONTINUE WITH .2 SENDING .3
|
|
293 PLEASE KILL ALL THREADS
|
|
294
|
|
295 (10) DO .2 <- #1
|
|
296 DO READ OUT #10
|
|
297 DO CONTINUE WITH .1 SENDING #2
|
|
298 DO RESUME #1
|