firefly-compiler 0.4.6 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/compiler/Compiler.ff +2 -0
  2. package/compiler/Deriver.ff +7 -0
  3. package/core/Array.ff +17 -4
  4. package/core/AssetSystem.ff +1 -1
  5. package/core/BrowserSystem.ff +27 -0
  6. package/core/List.ff +4 -0
  7. package/core/Lock.ff +2 -2
  8. package/core/Random.ff +148 -0
  9. package/core/SourceLocation.ff +27 -0
  10. package/core/Task.ff +3 -0
  11. package/core/WebSocket.ff +127 -0
  12. package/httpserver/HttpServer.ff +1 -1
  13. package/lux/Css.ff +648 -0
  14. package/lux/CssTest.ff +48 -0
  15. package/lux/Lux.ff +33 -18
  16. package/lux/Main.ff +4 -1
  17. package/output/js/ff/compiler/Builder.mjs +448 -444
  18. package/output/js/ff/compiler/Compiler.mjs +420 -416
  19. package/output/js/ff/compiler/Dependencies.mjs +393 -389
  20. package/output/js/ff/compiler/Deriver.mjs +1178 -1170
  21. package/output/js/ff/compiler/Dictionaries.mjs +1315 -1309
  22. package/output/js/ff/compiler/Environment.mjs +1025 -1015
  23. package/output/js/ff/compiler/Inference.mjs +4272 -4268
  24. package/output/js/ff/compiler/JsEmitter.mjs +5405 -5391
  25. package/output/js/ff/compiler/JsImporter.mjs +270 -266
  26. package/output/js/ff/compiler/LspHook.mjs +799 -793
  27. package/output/js/ff/compiler/Main.mjs +1691 -1675
  28. package/output/js/ff/compiler/Parser.mjs +4016 -4008
  29. package/output/js/ff/compiler/Patterns.mjs +935 -927
  30. package/output/js/ff/compiler/Resolver.mjs +2311 -2307
  31. package/output/js/ff/compiler/Substitution.mjs +1154 -1150
  32. package/output/js/ff/compiler/Syntax.mjs +12566 -12434
  33. package/output/js/ff/compiler/Token.mjs +3152 -3096
  34. package/output/js/ff/compiler/Tokenizer.mjs +597 -593
  35. package/output/js/ff/compiler/Unification.mjs +1762 -1752
  36. package/output/js/ff/compiler/Wildcards.mjs +612 -608
  37. package/output/js/ff/compiler/Workspace.mjs +695 -687
  38. package/output/js/ff/core/Any.mjs +147 -143
  39. package/output/js/ff/core/Array.mjs +573 -547
  40. package/output/js/ff/core/AssetSystem.mjs +278 -274
  41. package/output/js/ff/core/Atomic.mjs +158 -154
  42. package/output/js/ff/core/Bool.mjs +156 -152
  43. package/output/js/ff/core/Box.mjs +116 -112
  44. package/output/js/ff/core/BrowserSystem.mjs +181 -126
  45. package/output/js/ff/core/Buffer.mjs +399 -395
  46. package/output/js/ff/core/BuildSystem.mjs +300 -296
  47. package/output/js/ff/core/Channel.mjs +193 -189
  48. package/output/js/ff/core/Char.mjs +153 -149
  49. package/output/js/ff/core/Core.mjs +304 -300
  50. package/output/js/ff/core/Duration.mjs +120 -116
  51. package/output/js/ff/core/Equal.mjs +183 -179
  52. package/output/js/ff/core/Error.mjs +146 -142
  53. package/output/js/ff/core/FileHandle.mjs +154 -150
  54. package/output/js/ff/core/Float.mjs +229 -225
  55. package/output/js/ff/core/HttpClient.mjs +195 -191
  56. package/output/js/ff/core/Instant.mjs +113 -109
  57. package/output/js/ff/core/Int.mjs +269 -265
  58. package/output/js/ff/core/IntMap.mjs +284 -280
  59. package/output/js/ff/core/JsSystem.mjs +242 -238
  60. package/output/js/ff/core/JsValue.mjs +712 -708
  61. package/output/js/ff/core/List.mjs +2346 -2334
  62. package/output/js/ff/core/Lock.mjs +235 -231
  63. package/output/js/ff/core/Log.mjs +167 -163
  64. package/output/js/ff/core/Map.mjs +366 -362
  65. package/output/js/ff/core/NodeSystem.mjs +298 -294
  66. package/output/js/ff/core/Nothing.mjs +108 -104
  67. package/output/js/ff/core/Option.mjs +1023 -1015
  68. package/output/js/ff/core/Ordering.mjs +734 -730
  69. package/output/js/ff/core/Pair.mjs +337 -331
  70. package/output/js/ff/core/Path.mjs +549 -545
  71. package/output/js/ff/core/Random.mjs +340 -0
  72. package/output/js/ff/core/RbMap.mjs +1944 -1940
  73. package/output/js/ff/core/Serializable.mjs +432 -428
  74. package/output/js/ff/core/Set.mjs +258 -254
  75. package/output/js/ff/core/Show.mjs +209 -205
  76. package/output/js/ff/core/SourceLocation.mjs +273 -229
  77. package/output/js/ff/core/Stack.mjs +533 -529
  78. package/output/js/ff/core/Stream.mjs +1308 -1304
  79. package/output/js/ff/core/String.mjs +369 -365
  80. package/output/js/ff/core/StringMap.mjs +284 -280
  81. package/output/js/ff/core/Task.mjs +325 -319
  82. package/output/js/ff/core/Try.mjs +511 -507
  83. package/output/js/ff/core/Unit.mjs +155 -151
  84. package/output/js/ff/core/WebSocket.mjs +198 -0
  85. package/package.json +1 -1
  86. package/vscode/package.json +1 -1
  87. package/webserver/.firefly/include/package-lock.json +16 -0
  88. package/webserver/.firefly/include/package.json +5 -0
  89. package/webserver/.firefly/package.ff +2 -0
  90. package/webserver/WebServer.ff +608 -0
@@ -1,103 +1,107 @@
1
-
2
-
3
- import * as ff_core_Any from "../../ff/core/Any.mjs"
4
-
5
- import * as ff_core_Array from "../../ff/core/Array.mjs"
6
-
7
- import * as ff_core_AssetSystem from "../../ff/core/AssetSystem.mjs"
8
-
9
- import * as ff_core_Atomic from "../../ff/core/Atomic.mjs"
10
-
11
- import * as ff_core_Bool from "../../ff/core/Bool.mjs"
12
-
13
- import * as ff_core_Box from "../../ff/core/Box.mjs"
14
-
15
- import * as ff_core_BrowserSystem from "../../ff/core/BrowserSystem.mjs"
16
-
17
- import * as ff_core_Buffer from "../../ff/core/Buffer.mjs"
18
-
19
- import * as ff_core_BuildSystem from "../../ff/core/BuildSystem.mjs"
20
-
21
- import * as ff_core_Channel from "../../ff/core/Channel.mjs"
22
-
23
- import * as ff_core_Char from "../../ff/core/Char.mjs"
24
-
25
- import * as ff_core_Core from "../../ff/core/Core.mjs"
26
-
27
- import * as ff_core_Duration from "../../ff/core/Duration.mjs"
28
-
29
- import * as ff_core_Equal from "../../ff/core/Equal.mjs"
30
-
31
- import * as ff_core_Error from "../../ff/core/Error.mjs"
32
-
33
- import * as ff_core_FileHandle from "../../ff/core/FileHandle.mjs"
34
-
35
- import * as ff_core_Float from "../../ff/core/Float.mjs"
36
-
37
- import * as ff_core_HttpClient from "../../ff/core/HttpClient.mjs"
38
-
39
- import * as ff_core_Instant from "../../ff/core/Instant.mjs"
40
-
41
- import * as ff_core_Int from "../../ff/core/Int.mjs"
42
-
43
- import * as ff_core_IntMap from "../../ff/core/IntMap.mjs"
44
-
45
- import * as ff_core_JsSystem from "../../ff/core/JsSystem.mjs"
46
-
47
- import * as ff_core_JsValue from "../../ff/core/JsValue.mjs"
48
-
49
- import * as ff_core_List from "../../ff/core/List.mjs"
50
-
51
- import * as ff_core_Lock from "../../ff/core/Lock.mjs"
52
-
53
- import * as ff_core_Log from "../../ff/core/Log.mjs"
54
-
55
- import * as ff_core_Map from "../../ff/core/Map.mjs"
56
-
57
- import * as ff_core_NodeSystem from "../../ff/core/NodeSystem.mjs"
58
-
59
- import * as ff_core_Nothing from "../../ff/core/Nothing.mjs"
60
-
61
- import * as ff_core_Option from "../../ff/core/Option.mjs"
62
-
63
- import * as ff_core_Ordering from "../../ff/core/Ordering.mjs"
64
-
65
- import * as ff_core_Pair from "../../ff/core/Pair.mjs"
66
-
67
- import * as ff_core_Path from "../../ff/core/Path.mjs"
68
-
69
- import * as ff_core_Serializable from "../../ff/core/Serializable.mjs"
70
-
71
- import * as ff_core_Set from "../../ff/core/Set.mjs"
72
-
73
- import * as ff_core_Show from "../../ff/core/Show.mjs"
74
-
75
- import * as ff_core_SourceLocation from "../../ff/core/SourceLocation.mjs"
76
-
77
- import * as ff_core_Stack from "../../ff/core/Stack.mjs"
78
-
79
- import * as ff_core_Stream from "../../ff/core/Stream.mjs"
80
-
81
- import * as ff_core_String from "../../ff/core/String.mjs"
82
-
83
- import * as ff_core_StringMap from "../../ff/core/StringMap.mjs"
84
-
85
- import * as ff_core_Task from "../../ff/core/Task.mjs"
86
-
87
- import * as ff_core_Try from "../../ff/core/Try.mjs"
88
-
89
- import * as ff_core_Unit from "../../ff/core/Unit.mjs"
90
-
91
- // type Task
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
- export function Task_spawn(self_, body_) {
1
+
2
+
3
+ import * as ff_core_Any from "../../ff/core/Any.mjs"
4
+
5
+ import * as ff_core_Array from "../../ff/core/Array.mjs"
6
+
7
+ import * as ff_core_AssetSystem from "../../ff/core/AssetSystem.mjs"
8
+
9
+ import * as ff_core_Atomic from "../../ff/core/Atomic.mjs"
10
+
11
+ import * as ff_core_Bool from "../../ff/core/Bool.mjs"
12
+
13
+ import * as ff_core_Box from "../../ff/core/Box.mjs"
14
+
15
+ import * as ff_core_BrowserSystem from "../../ff/core/BrowserSystem.mjs"
16
+
17
+ import * as ff_core_Buffer from "../../ff/core/Buffer.mjs"
18
+
19
+ import * as ff_core_BuildSystem from "../../ff/core/BuildSystem.mjs"
20
+
21
+ import * as ff_core_Channel from "../../ff/core/Channel.mjs"
22
+
23
+ import * as ff_core_Char from "../../ff/core/Char.mjs"
24
+
25
+ import * as ff_core_Core from "../../ff/core/Core.mjs"
26
+
27
+ import * as ff_core_Duration from "../../ff/core/Duration.mjs"
28
+
29
+ import * as ff_core_Equal from "../../ff/core/Equal.mjs"
30
+
31
+ import * as ff_core_Error from "../../ff/core/Error.mjs"
32
+
33
+ import * as ff_core_FileHandle from "../../ff/core/FileHandle.mjs"
34
+
35
+ import * as ff_core_Float from "../../ff/core/Float.mjs"
36
+
37
+ import * as ff_core_HttpClient from "../../ff/core/HttpClient.mjs"
38
+
39
+ import * as ff_core_Instant from "../../ff/core/Instant.mjs"
40
+
41
+ import * as ff_core_Int from "../../ff/core/Int.mjs"
42
+
43
+ import * as ff_core_IntMap from "../../ff/core/IntMap.mjs"
44
+
45
+ import * as ff_core_JsSystem from "../../ff/core/JsSystem.mjs"
46
+
47
+ import * as ff_core_JsValue from "../../ff/core/JsValue.mjs"
48
+
49
+ import * as ff_core_List from "../../ff/core/List.mjs"
50
+
51
+ import * as ff_core_Lock from "../../ff/core/Lock.mjs"
52
+
53
+ import * as ff_core_Log from "../../ff/core/Log.mjs"
54
+
55
+ import * as ff_core_Map from "../../ff/core/Map.mjs"
56
+
57
+ import * as ff_core_NodeSystem from "../../ff/core/NodeSystem.mjs"
58
+
59
+ import * as ff_core_Nothing from "../../ff/core/Nothing.mjs"
60
+
61
+ import * as ff_core_Option from "../../ff/core/Option.mjs"
62
+
63
+ import * as ff_core_Ordering from "../../ff/core/Ordering.mjs"
64
+
65
+ import * as ff_core_Pair from "../../ff/core/Pair.mjs"
66
+
67
+ import * as ff_core_Path from "../../ff/core/Path.mjs"
68
+
69
+ import * as ff_core_Random from "../../ff/core/Random.mjs"
70
+
71
+ import * as ff_core_Serializable from "../../ff/core/Serializable.mjs"
72
+
73
+ import * as ff_core_Set from "../../ff/core/Set.mjs"
74
+
75
+ import * as ff_core_Show from "../../ff/core/Show.mjs"
76
+
77
+ import * as ff_core_SourceLocation from "../../ff/core/SourceLocation.mjs"
78
+
79
+ import * as ff_core_Stack from "../../ff/core/Stack.mjs"
80
+
81
+ import * as ff_core_Stream from "../../ff/core/Stream.mjs"
82
+
83
+ import * as ff_core_String from "../../ff/core/String.mjs"
84
+
85
+ import * as ff_core_StringMap from "../../ff/core/StringMap.mjs"
86
+
87
+ import * as ff_core_Task from "../../ff/core/Task.mjs"
88
+
89
+ import * as ff_core_Try from "../../ff/core/Try.mjs"
90
+
91
+ import * as ff_core_Unit from "../../ff/core/Unit.mjs"
92
+
93
+ import * as ff_core_WebSocket from "../../ff/core/WebSocket.mjs"
94
+
95
+ // type Task
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+ export function Task_spawn(self_, body_) {
101
105
 
102
106
  ff_core_Task.Task_throwIfAborted(self_)
103
107
  const task = {controller: new AbortController(), subtasks: new Set(), started: performance.now() * 0.001}
@@ -115,235 +119,237 @@ export function Task_spawn(self_, body_) {
115
119
  }
116
120
  })
117
121
  return task
118
-
119
- }
120
-
121
- export function Task_throwIfAborted(self_) {
122
+
123
+ }
124
+
125
+ export function Task_throwIfAborted(self_) {
122
126
 
123
127
  if(self_.controller.signal.aborted) {
124
128
  const signal = self_.controller.signal
125
129
  self_.controller = new AbortController()
126
130
  signal.throwIfAborted()
127
131
  }
128
-
129
- }
130
-
131
- export function Task_abort(self_) {
132
- throw new Error('Function Task_abort is missing on this target in sync context.');
133
- }
134
-
135
- export function Task_channel(self_, capacity_ = 0) {
136
- return {capacity: capacity_, buffer: [], readers: new Set(), writers: new Set()}
137
- }
138
-
139
- export function Task_lock(self_) {
140
- throw new Error('Function Task_lock is missing on this target in sync context.');
141
- }
132
+
133
+ }
134
+
135
+ export function Task_abort(self_) {
142
136
 
143
- export function Task_now(self_) {
144
- return Date.now() * 0.001
145
- }
146
-
147
- export function Task_elapsed(self_) {
148
- return performance.now() * 0.001 - self_.started
149
- }
150
-
151
- export function Task_time(self_, body_) {
152
- const start_ = ff_core_Task.Task_elapsed(self_);
153
- const result_ = body_();
154
- const stop_ = ff_core_Task.Task_elapsed(self_);
155
- const duration_ = (stop_ - start_);
156
- return ff_core_Pair.Pair(result_, duration_)
157
- }
158
-
159
- export async function Task_spawn$(self_, body_, $task) {
137
+ self_.controller.abort()
138
+
139
+ }
140
+
141
+ export function Task_channel(self_, capacity_ = 0) {
142
+ return {capacity: capacity_, buffer: [], readers: new Set(), writers: new Set()}
143
+ }
144
+
145
+ export function Task_lock(self_) {
146
+ throw new Error('Function Task_lock is missing on this target in sync context.');
147
+ }
148
+
149
+ export function Task_now(self_) {
150
+ return Date.now() * 0.001
151
+ }
152
+
153
+ export function Task_elapsed(self_) {
154
+ return performance.now() * 0.001 - self_.started
155
+ }
156
+
157
+ export function Task_time(self_, body_) {
158
+ const start_ = ff_core_Task.Task_elapsed(self_);
159
+ const result_ = body_();
160
+ const stop_ = ff_core_Task.Task_elapsed(self_);
161
+ const duration_ = (stop_ - start_);
162
+ return ff_core_Pair.Pair(result_, duration_)
163
+ }
164
+
165
+ export async function Task_spawn$(self_, body_, $task) {
160
166
 
161
167
  return ff_core_Task.Task_spawn(self_, body_)
162
-
163
- }
164
-
165
- export async function Task_throwIfAborted$(self_, $task) {
168
+
169
+ }
170
+
171
+ export async function Task_throwIfAborted$(self_, $task) {
166
172
 
167
173
  ff_core_Task.Task_throwIfAborted(self_)
168
-
169
- }
170
-
171
- export async function Task_abort$(self_, $task) {
174
+
175
+ }
176
+
177
+ export async function Task_abort$(self_, $task) {
172
178
 
173
179
  self_.controller.abort()
174
-
175
- }
176
-
177
- export async function Task_channel$(self_, capacity_ = 0, $task) {
178
- return ff_core_Task.Task_channel(capacity_)
179
- }
180
-
181
- export async function Task_lock$(self_, $task) {
182
- return {owner: null, level: 0, stack: [], queue: []}
183
- }
184
-
185
- export async function Task_now$(self_, $task) {
186
- return Date.now() * 0.001
187
- }
188
-
189
- export async function Task_elapsed$(self_, $task) {
190
- return performance.now() * 0.001 - self_.started
191
- }
192
-
193
- export async function Task_time$(self_, body_, $task) {
194
- const start_ = (await ff_core_Task.Task_elapsed$(self_, $task));
195
- const result_ = (await body_($task));
196
- const stop_ = (await ff_core_Task.Task_elapsed$(self_, $task));
197
- const duration_ = (stop_ - start_);
198
- return ff_core_Pair.Pair(result_, duration_)
199
- }
200
-
201
- export function Task_sleep(self_, duration_) {
202
- ff_core_Channel.ChannelAction_timeout(ff_core_Channel.readOr_(ff_core_Task.Task_channel(self_, 0), ((_) => {
203
-
204
- })), duration_, (() => {
205
-
206
- }))
207
- }
208
-
209
- export function Task_all(self_, tasks_) {
210
- const successChannel_ = ff_core_Task.Task_channel(self_, 0);
211
- const failureChannel_ = ff_core_Task.Task_channel(self_, 0);
212
- ff_core_Task.Task_spawn(self_, ((t_) => {
213
- const channel_ = ff_core_Task.Task_channel(t_, 0);
214
- ff_core_Try.Try_grab(ff_core_Try.Try_catchAny(ff_core_Core.try_((() => {
215
- ff_core_List.List_each(ff_core_List.List_pairs(tasks_), ((_1) => {
216
- {
217
- const i_ = _1.first_;
218
- const task_ = _1.second_;
219
- ff_core_Task.Task_spawn(t_, ((_) => {
220
- ff_core_Channel.Channel_write(channel_, ff_core_Pair.Pair(i_, task_()))
221
- }))
222
- return
223
- }
224
- }));
225
- const result_ = ff_core_List.List_map(ff_core_List.List_sortBy(ff_core_List.List_map(tasks_, ((_) => {
226
- return ff_core_Channel.Channel_read(channel_)
227
- })), ((_w1) => {
228
- return _w1.first_
229
- }), ff_core_Ordering.ff_core_Ordering_Order$ff_core_Int_Int), ((_w1) => {
230
- return _w1.second_
231
- }));
232
- return ff_core_Channel.Channel_write(successChannel_, result_)
233
- })), ((error_) => {
234
- ff_core_Channel.Channel_write(failureChannel_, error_);
235
- ff_core_Task.Task_abort(t_)
236
- })))
237
- }));
238
- return ff_core_Channel.ChannelAction_wait(ff_core_Channel.ChannelAction_readOr(ff_core_Channel.readOr_(successChannel_, ((_w1) => {
239
- return _w1
240
- })), failureChannel_, ((_w1) => {
241
- return ff_core_Error.Error_rethrow(_w1)
242
- })))
243
- }
244
-
245
- export function Task_race(self_, tasks_) {
246
- const successChannel_ = ff_core_Task.Task_channel(self_, 0);
247
- const failureChannel_ = ff_core_Task.Task_channel(self_, 0);
248
- let live_ = ff_core_List.List_size(tasks_);
249
- const started_ = ff_core_List.List_map(tasks_, ((task_) => {
250
- return ff_core_Task.Task_spawn(self_, ((_) => {
251
- ff_core_Try.Try_grab(ff_core_Try.Try_catchAny(ff_core_Core.try_((() => {
252
- return ff_core_Channel.Channel_write(successChannel_, task_())
253
- })), ((e_) => {
254
- live_ -= 1;
255
- if((live_ === 0)) {
256
- ff_core_Channel.Channel_write(failureChannel_, e_)
257
- }
258
- })))
259
- }))
260
- }));
261
- try {
262
- return ff_core_Channel.ChannelAction_wait(ff_core_Channel.ChannelAction_readOr(ff_core_Channel.readOr_(successChannel_, ((_w1) => {
263
- return _w1
264
- })), failureChannel_, ((_w1) => {
265
- return ff_core_Error.Error_rethrow(_w1)
266
- })))
267
- } finally {
268
- ff_core_List.List_each(started_, ((_w1) => {
269
- ff_core_Task.Task_abort(_w1)
270
- }))
271
- }
272
- }
273
-
274
- export async function Task_sleep$(self_, duration_, $task) {
275
- (await ff_core_Channel.ChannelAction_timeout$((await ff_core_Channel.readOr_$((await ff_core_Task.Task_channel$(self_, 0, $task)), (async (_, $task) => {
276
-
277
- }), $task)), duration_, (async ($task) => {
278
-
279
- }), $task))
280
- }
281
-
282
- export async function Task_all$(self_, tasks_, $task) {
283
- const successChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
284
- const failureChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
285
- (await ff_core_Task.Task_spawn$(self_, (async (t_, $task) => {
286
- const channel_ = (await ff_core_Task.Task_channel$(t_, 0, $task));
287
- ff_core_Try.Try_grab((await ff_core_Try.Try_catchAny$((await ff_core_Core.try_$((async ($task) => {
288
- (await ff_core_List.List_each$(ff_core_List.List_pairs(tasks_), (async (_1, $task) => {
289
- {
290
- const i_ = _1.first_;
291
- const task_ = _1.second_;
292
- (await ff_core_Task.Task_spawn$(t_, (async (_, $task) => {
293
- (await ff_core_Channel.Channel_write$(channel_, ff_core_Pair.Pair(i_, (await task_($task))), $task))
294
- }), $task))
295
- return
296
- }
297
- }), $task));
298
- const result_ = ff_core_List.List_map(ff_core_List.List_sortBy((await ff_core_List.List_map$(tasks_, (async (_, $task) => {
299
- return (await ff_core_Channel.Channel_read$(channel_, $task))
300
- }), $task)), ((_w1) => {
301
- return _w1.first_
302
- }), ff_core_Ordering.ff_core_Ordering_Order$ff_core_Int_Int), ((_w1) => {
303
- return _w1.second_
304
- }));
305
- return (await ff_core_Channel.Channel_write$(successChannel_, result_, $task))
306
- }), $task)), (async (error_, $task) => {
307
- (await ff_core_Channel.Channel_write$(failureChannel_, error_, $task));
308
- (await ff_core_Task.Task_abort$(t_, $task))
309
- }), $task)))
310
- }), $task));
311
- return (await ff_core_Channel.ChannelAction_wait$((await ff_core_Channel.ChannelAction_readOr$((await ff_core_Channel.readOr_$(successChannel_, (async (_w1, $task) => {
312
- return _w1
313
- }), $task)), failureChannel_, (async (_w1, $task) => {
314
- return ff_core_Error.Error_rethrow(_w1)
315
- }), $task)), $task))
316
- }
317
-
318
- export async function Task_race$(self_, tasks_, $task) {
319
- const successChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
320
- const failureChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
321
- let live_ = ff_core_List.List_size(tasks_);
322
- const started_ = (await ff_core_List.List_map$(tasks_, (async (task_, $task) => {
323
- return (await ff_core_Task.Task_spawn$(self_, (async (_, $task) => {
324
- ff_core_Try.Try_grab((await ff_core_Try.Try_catchAny$((await ff_core_Core.try_$((async ($task) => {
325
- return (await ff_core_Channel.Channel_write$(successChannel_, (await task_($task)), $task))
326
- }), $task)), (async (e_, $task) => {
327
- live_ -= 1;
328
- if((live_ === 0)) {
329
- (await ff_core_Channel.Channel_write$(failureChannel_, e_, $task))
330
- }
331
- }), $task)))
332
- }), $task))
333
- }), $task));
334
- try {
335
- return (await ff_core_Channel.ChannelAction_wait$((await ff_core_Channel.ChannelAction_readOr$((await ff_core_Channel.readOr_$(successChannel_, (async (_w1, $task) => {
336
- return _w1
337
- }), $task)), failureChannel_, (async (_w1, $task) => {
338
- return ff_core_Error.Error_rethrow(_w1)
339
- }), $task)), $task))
340
- } finally {
341
- (await ff_core_List.List_each$(started_, (async (_w1, $task) => {
342
- (await ff_core_Task.Task_abort$(_w1, $task))
343
- }), $task))
344
- }
345
- }
346
-
347
-
348
-
349
-
180
+
181
+ }
182
+
183
+ export async function Task_channel$(self_, capacity_ = 0, $task) {
184
+ return ff_core_Task.Task_channel(capacity_)
185
+ }
186
+
187
+ export async function Task_lock$(self_, $task) {
188
+ return {owner: null, level: 0, stack: [], queue: []}
189
+ }
190
+
191
+ export async function Task_now$(self_, $task) {
192
+ return Date.now() * 0.001
193
+ }
194
+
195
+ export async function Task_elapsed$(self_, $task) {
196
+ return performance.now() * 0.001 - self_.started
197
+ }
198
+
199
+ export async function Task_time$(self_, body_, $task) {
200
+ const start_ = (await ff_core_Task.Task_elapsed$(self_, $task));
201
+ const result_ = (await body_($task));
202
+ const stop_ = (await ff_core_Task.Task_elapsed$(self_, $task));
203
+ const duration_ = (stop_ - start_);
204
+ return ff_core_Pair.Pair(result_, duration_)
205
+ }
206
+
207
+ export function Task_sleep(self_, duration_) {
208
+ ff_core_Channel.ChannelAction_timeout(ff_core_Channel.readOr_(ff_core_Task.Task_channel(self_, 0), ((_) => {
209
+
210
+ })), duration_, (() => {
211
+
212
+ }))
213
+ }
214
+
215
+ export function Task_all(self_, tasks_) {
216
+ const successChannel_ = ff_core_Task.Task_channel(self_, 0);
217
+ const failureChannel_ = ff_core_Task.Task_channel(self_, 0);
218
+ ff_core_Task.Task_spawn(self_, ((t_) => {
219
+ const channel_ = ff_core_Task.Task_channel(t_, 0);
220
+ ff_core_Try.Try_grab(ff_core_Try.Try_catchAny(ff_core_Core.try_((() => {
221
+ ff_core_List.List_each(ff_core_List.List_pairs(tasks_), ((_1) => {
222
+ {
223
+ const i_ = _1.first_;
224
+ const task_ = _1.second_;
225
+ ff_core_Task.Task_spawn(t_, ((_) => {
226
+ ff_core_Channel.Channel_write(channel_, ff_core_Pair.Pair(i_, task_()))
227
+ }))
228
+ return
229
+ }
230
+ }));
231
+ const result_ = ff_core_List.List_map(ff_core_List.List_sortBy(ff_core_List.List_map(tasks_, ((_) => {
232
+ return ff_core_Channel.Channel_read(channel_)
233
+ })), ((_w1) => {
234
+ return _w1.first_
235
+ }), ff_core_Ordering.ff_core_Ordering_Order$ff_core_Int_Int), ((_w1) => {
236
+ return _w1.second_
237
+ }));
238
+ return ff_core_Channel.Channel_write(successChannel_, result_)
239
+ })), ((error_) => {
240
+ ff_core_Channel.Channel_write(failureChannel_, error_);
241
+ ff_core_Task.Task_abort(t_)
242
+ })))
243
+ }));
244
+ return ff_core_Channel.ChannelAction_wait(ff_core_Channel.ChannelAction_readOr(ff_core_Channel.readOr_(successChannel_, ((_w1) => {
245
+ return _w1
246
+ })), failureChannel_, ((_w1) => {
247
+ return ff_core_Error.Error_rethrow(_w1)
248
+ })))
249
+ }
250
+
251
+ export function Task_race(self_, tasks_) {
252
+ const successChannel_ = ff_core_Task.Task_channel(self_, 0);
253
+ const failureChannel_ = ff_core_Task.Task_channel(self_, 0);
254
+ let live_ = ff_core_List.List_size(tasks_);
255
+ const started_ = ff_core_List.List_map(tasks_, ((task_) => {
256
+ return ff_core_Task.Task_spawn(self_, ((_) => {
257
+ ff_core_Try.Try_grab(ff_core_Try.Try_catchAny(ff_core_Core.try_((() => {
258
+ return ff_core_Channel.Channel_write(successChannel_, task_())
259
+ })), ((e_) => {
260
+ live_ -= 1;
261
+ if((live_ === 0)) {
262
+ ff_core_Channel.Channel_write(failureChannel_, e_)
263
+ }
264
+ })))
265
+ }))
266
+ }));
267
+ try {
268
+ return ff_core_Channel.ChannelAction_wait(ff_core_Channel.ChannelAction_readOr(ff_core_Channel.readOr_(successChannel_, ((_w1) => {
269
+ return _w1
270
+ })), failureChannel_, ((_w1) => {
271
+ return ff_core_Error.Error_rethrow(_w1)
272
+ })))
273
+ } finally {
274
+ ff_core_List.List_each(started_, ((_w1) => {
275
+ ff_core_Task.Task_abort(_w1)
276
+ }))
277
+ }
278
+ }
279
+
280
+ export async function Task_sleep$(self_, duration_, $task) {
281
+ (await ff_core_Channel.ChannelAction_timeout$((await ff_core_Channel.readOr_$((await ff_core_Task.Task_channel$(self_, 0, $task)), (async (_, $task) => {
282
+
283
+ }), $task)), duration_, (async ($task) => {
284
+
285
+ }), $task))
286
+ }
287
+
288
+ export async function Task_all$(self_, tasks_, $task) {
289
+ const successChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
290
+ const failureChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
291
+ (await ff_core_Task.Task_spawn$(self_, (async (t_, $task) => {
292
+ const channel_ = (await ff_core_Task.Task_channel$(t_, 0, $task));
293
+ ff_core_Try.Try_grab((await ff_core_Try.Try_catchAny$((await ff_core_Core.try_$((async ($task) => {
294
+ (await ff_core_List.List_each$(ff_core_List.List_pairs(tasks_), (async (_1, $task) => {
295
+ {
296
+ const i_ = _1.first_;
297
+ const task_ = _1.second_;
298
+ (await ff_core_Task.Task_spawn$(t_, (async (_, $task) => {
299
+ (await ff_core_Channel.Channel_write$(channel_, ff_core_Pair.Pair(i_, (await task_($task))), $task))
300
+ }), $task))
301
+ return
302
+ }
303
+ }), $task));
304
+ const result_ = ff_core_List.List_map(ff_core_List.List_sortBy((await ff_core_List.List_map$(tasks_, (async (_, $task) => {
305
+ return (await ff_core_Channel.Channel_read$(channel_, $task))
306
+ }), $task)), ((_w1) => {
307
+ return _w1.first_
308
+ }), ff_core_Ordering.ff_core_Ordering_Order$ff_core_Int_Int), ((_w1) => {
309
+ return _w1.second_
310
+ }));
311
+ return (await ff_core_Channel.Channel_write$(successChannel_, result_, $task))
312
+ }), $task)), (async (error_, $task) => {
313
+ (await ff_core_Channel.Channel_write$(failureChannel_, error_, $task));
314
+ (await ff_core_Task.Task_abort$(t_, $task))
315
+ }), $task)))
316
+ }), $task));
317
+ return (await ff_core_Channel.ChannelAction_wait$((await ff_core_Channel.ChannelAction_readOr$((await ff_core_Channel.readOr_$(successChannel_, (async (_w1, $task) => {
318
+ return _w1
319
+ }), $task)), failureChannel_, (async (_w1, $task) => {
320
+ return ff_core_Error.Error_rethrow(_w1)
321
+ }), $task)), $task))
322
+ }
323
+
324
+ export async function Task_race$(self_, tasks_, $task) {
325
+ const successChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
326
+ const failureChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
327
+ let live_ = ff_core_List.List_size(tasks_);
328
+ const started_ = (await ff_core_List.List_map$(tasks_, (async (task_, $task) => {
329
+ return (await ff_core_Task.Task_spawn$(self_, (async (_, $task) => {
330
+ ff_core_Try.Try_grab((await ff_core_Try.Try_catchAny$((await ff_core_Core.try_$((async ($task) => {
331
+ return (await ff_core_Channel.Channel_write$(successChannel_, (await task_($task)), $task))
332
+ }), $task)), (async (e_, $task) => {
333
+ live_ -= 1;
334
+ if((live_ === 0)) {
335
+ (await ff_core_Channel.Channel_write$(failureChannel_, e_, $task))
336
+ }
337
+ }), $task)))
338
+ }), $task))
339
+ }), $task));
340
+ try {
341
+ return (await ff_core_Channel.ChannelAction_wait$((await ff_core_Channel.ChannelAction_readOr$((await ff_core_Channel.readOr_$(successChannel_, (async (_w1, $task) => {
342
+ return _w1
343
+ }), $task)), failureChannel_, (async (_w1, $task) => {
344
+ return ff_core_Error.Error_rethrow(_w1)
345
+ }), $task)), $task))
346
+ } finally {
347
+ (await ff_core_List.List_each$(started_, (async (_w1, $task) => {
348
+ (await ff_core_Task.Task_abort$(_w1, $task))
349
+ }), $task))
350
+ }
351
+ }
352
+
353
+
354
+
355
+