zuzu-js 0.1.0

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 (167) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +113 -0
  3. package/bin/zuzu +17 -0
  4. package/bin/zuzu-build-browser-bundle +57 -0
  5. package/bin/zuzu-generate-browser-stdlib +584 -0
  6. package/bin/zuzu-js +23 -0
  7. package/bin/zuzu-js-compile +152 -0
  8. package/bin/zuzu-js-electron +19 -0
  9. package/dist/zuzu-browser-worker.js +45574 -0
  10. package/dist/zuzu-browser.js +45362 -0
  11. package/lib/browser-bundle-entry.js +160 -0
  12. package/lib/browser-gui-renderer.js +387 -0
  13. package/lib/browser-runtime.js +167 -0
  14. package/lib/browser-worker-entry.js +413 -0
  15. package/lib/browser-ztests/runner.html +103 -0
  16. package/lib/browser-ztests/runner.js +369 -0
  17. package/lib/cli.js +350 -0
  18. package/lib/collections.js +367 -0
  19. package/lib/compiler.js +303 -0
  20. package/lib/electron/launcher.js +70 -0
  21. package/lib/electron/main.js +956 -0
  22. package/lib/electron/preload.js +80 -0
  23. package/lib/electron/renderer.html +122 -0
  24. package/lib/electron/renderer.js +24 -0
  25. package/lib/execution-metadata.js +18 -0
  26. package/lib/gui/dom-renderer.js +778 -0
  27. package/lib/host/browser-host.js +278 -0
  28. package/lib/host/capabilities.js +47 -0
  29. package/lib/host/electron-host.js +15 -0
  30. package/lib/host/node-host.js +74 -0
  31. package/lib/paths.js +150 -0
  32. package/lib/runtime-entrypoints.js +60 -0
  33. package/lib/runtime-helpers.js +886 -0
  34. package/lib/runtime.js +3529 -0
  35. package/lib/tap.js +37 -0
  36. package/lib/transpiler-new/ast.js +23 -0
  37. package/lib/transpiler-new/codegen.js +2455 -0
  38. package/lib/transpiler-new/errors.js +28 -0
  39. package/lib/transpiler-new/index.js +26 -0
  40. package/lib/transpiler-new/lexer.js +834 -0
  41. package/lib/transpiler-new/parser.js +2332 -0
  42. package/lib/transpiler-new/validate-bindings.js +326 -0
  43. package/lib/transpiler-utils.js +95 -0
  44. package/lib/transpiler.js +33 -0
  45. package/lib/zuzu.js +53 -0
  46. package/modules/javascript.js +193 -0
  47. package/modules/std/archive.js +603 -0
  48. package/modules/std/clib.js +338 -0
  49. package/modules/std/data/csv.js +1331 -0
  50. package/modules/std/data/json.js +531 -0
  51. package/modules/std/data/xml.js +441 -0
  52. package/modules/std/data/yaml.js +256 -0
  53. package/modules/std/db-worker.js +250 -0
  54. package/modules/std/db.js +664 -0
  55. package/modules/std/digest/_hash.js +443 -0
  56. package/modules/std/digest/md5.js +26 -0
  57. package/modules/std/digest/sha.js +72 -0
  58. package/modules/std/eval.js +10 -0
  59. package/modules/std/gui/objects.js +1519 -0
  60. package/modules/std/internals.js +571 -0
  61. package/modules/std/io/socks-worker.js +318 -0
  62. package/modules/std/io/socks.js +186 -0
  63. package/modules/std/io.js +475 -0
  64. package/modules/std/marshal/cbor.js +463 -0
  65. package/modules/std/marshal/graph.js +1624 -0
  66. package/modules/std/marshal.js +87 -0
  67. package/modules/std/math/bignum.js +91 -0
  68. package/modules/std/math.js +79 -0
  69. package/modules/std/net/dns.js +306 -0
  70. package/modules/std/net/http.js +820 -0
  71. package/modules/std/net/smtp.js +943 -0
  72. package/modules/std/net/url.js +109 -0
  73. package/modules/std/proc.js +602 -0
  74. package/modules/std/secure.js +3724 -0
  75. package/modules/std/string/base64.js +138 -0
  76. package/modules/std/string.js +299 -0
  77. package/modules/std/task.js +914 -0
  78. package/modules/std/time.js +579 -0
  79. package/modules/std/tui.js +188 -0
  80. package/modules/std/worker-thread.js +246 -0
  81. package/modules/std/worker.js +790 -0
  82. package/package.json +67 -0
  83. package/stdlib/modules/javascript.zzm +99 -0
  84. package/stdlib/modules/perl.zzm +105 -0
  85. package/stdlib/modules/std/archive.zzm +132 -0
  86. package/stdlib/modules/std/cache/lru.zzm +174 -0
  87. package/stdlib/modules/std/clib.zzm +112 -0
  88. package/stdlib/modules/std/colour.zzm +220 -0
  89. package/stdlib/modules/std/config.zzm +818 -0
  90. package/stdlib/modules/std/data/cbor.zzm +497 -0
  91. package/stdlib/modules/std/data/csv.zzm +285 -0
  92. package/stdlib/modules/std/data/ini.zzm +472 -0
  93. package/stdlib/modules/std/data/json/schema/core.zzm +573 -0
  94. package/stdlib/modules/std/data/json/schema/format.zzm +581 -0
  95. package/stdlib/modules/std/data/json/schema/model.zzm +255 -0
  96. package/stdlib/modules/std/data/json/schema/output.zzm +272 -0
  97. package/stdlib/modules/std/data/json/schema/relative_pointer.zzm +299 -0
  98. package/stdlib/modules/std/data/json/schema/validation.zzm +1503 -0
  99. package/stdlib/modules/std/data/json/schema.zzm +306 -0
  100. package/stdlib/modules/std/data/json.zzm +102 -0
  101. package/stdlib/modules/std/data/kdl/json.zzm +460 -0
  102. package/stdlib/modules/std/data/kdl/xml.zzm +387 -0
  103. package/stdlib/modules/std/data/kdl.zzm +1631 -0
  104. package/stdlib/modules/std/data/toml.zzm +756 -0
  105. package/stdlib/modules/std/data/toon.zzm +1017 -0
  106. package/stdlib/modules/std/data/xml/escape.zzm +156 -0
  107. package/stdlib/modules/std/data/xml.zzm +276 -0
  108. package/stdlib/modules/std/data/yaml.zzm +94 -0
  109. package/stdlib/modules/std/db.zzm +173 -0
  110. package/stdlib/modules/std/defer.zzm +75 -0
  111. package/stdlib/modules/std/digest/crc32.zzm +196 -0
  112. package/stdlib/modules/std/digest/md5.zzm +54 -0
  113. package/stdlib/modules/std/digest/sha.zzm +83 -0
  114. package/stdlib/modules/std/dump.zzm +317 -0
  115. package/stdlib/modules/std/eval.zzm +63 -0
  116. package/stdlib/modules/std/getopt.zzm +432 -0
  117. package/stdlib/modules/std/gui/dialogue.zzm +592 -0
  118. package/stdlib/modules/std/gui/objects.zzm +123 -0
  119. package/stdlib/modules/std/gui.zzm +1914 -0
  120. package/stdlib/modules/std/internals.zzm +139 -0
  121. package/stdlib/modules/std/io/socks.zzm +139 -0
  122. package/stdlib/modules/std/io.zzm +157 -0
  123. package/stdlib/modules/std/lingua/en.zzm +347 -0
  124. package/stdlib/modules/std/log.zzm +169 -0
  125. package/stdlib/modules/std/mail.zzm +2726 -0
  126. package/stdlib/modules/std/marshal.zzm +138 -0
  127. package/stdlib/modules/std/math/bignum.zzm +98 -0
  128. package/stdlib/modules/std/math/range.zzm +116 -0
  129. package/stdlib/modules/std/math/roman.zzm +156 -0
  130. package/stdlib/modules/std/math.zzm +141 -0
  131. package/stdlib/modules/std/net/dns.zzm +93 -0
  132. package/stdlib/modules/std/net/http.zzm +278 -0
  133. package/stdlib/modules/std/net/smtp.zzm +257 -0
  134. package/stdlib/modules/std/net/url.zzm +69 -0
  135. package/stdlib/modules/std/path/jsonpointer.zzm +526 -0
  136. package/stdlib/modules/std/path/kdl.zzm +1003 -0
  137. package/stdlib/modules/std/path/simple.zzm +520 -0
  138. package/stdlib/modules/std/path/z/context.zzm +147 -0
  139. package/stdlib/modules/std/path/z/evaluate.zzm +549 -0
  140. package/stdlib/modules/std/path/z/functions.zzm +874 -0
  141. package/stdlib/modules/std/path/z/lexer.zzm +490 -0
  142. package/stdlib/modules/std/path/z/node.zzm +1455 -0
  143. package/stdlib/modules/std/path/z/operators.zzm +445 -0
  144. package/stdlib/modules/std/path/z/parser.zzm +359 -0
  145. package/stdlib/modules/std/path/z.zzm +403 -0
  146. package/stdlib/modules/std/path/zz/functions.zzm +828 -0
  147. package/stdlib/modules/std/path/zz/operators.zzm +1036 -0
  148. package/stdlib/modules/std/path/zz.zzm +100 -0
  149. package/stdlib/modules/std/proc.zzm +155 -0
  150. package/stdlib/modules/std/result.zzm +149 -0
  151. package/stdlib/modules/std/secure.zzm +606 -0
  152. package/stdlib/modules/std/string/base64.zzm +66 -0
  153. package/stdlib/modules/std/string/quoted_printable.zzm +485 -0
  154. package/stdlib/modules/std/string.zzm +179 -0
  155. package/stdlib/modules/std/task.zzm +221 -0
  156. package/stdlib/modules/std/template/z.zzm +531 -0
  157. package/stdlib/modules/std/template/zz.zzm +62 -0
  158. package/stdlib/modules/std/time.zzm +188 -0
  159. package/stdlib/modules/std/tui.zzm +89 -0
  160. package/stdlib/modules/std/uuid.zzm +223 -0
  161. package/stdlib/modules/std/web/session.zzm +388 -0
  162. package/stdlib/modules/std/web/static.zzm +329 -0
  163. package/stdlib/modules/std/web.zzm +1942 -0
  164. package/stdlib/modules/std/worker.zzm +202 -0
  165. package/stdlib/modules/std/zuzuzoo.zzm +3960 -0
  166. package/stdlib/modules/test/more.zzm +528 -0
  167. package/stdlib/modules/test/parser.zzm +209 -0
@@ -0,0 +1,221 @@
1
+ =encoding utf8
2
+
3
+ =head1 NAME
4
+
5
+ std/task - task helpers for async ZuzuScript code.
6
+
7
+ =head1 SYNOPSIS
8
+
9
+ from std/task import all, race, sleep, yield, timeout, Channel, CancellationSource;
10
+
11
+ async function __main__ () {
12
+ let a := spawn { await { sleep(0.1); }; "a"; };
13
+ let b := spawn { await { sleep(0.1); }; "b"; };
14
+ return await { all( [ a, b ] ); };
15
+ }
16
+
17
+ =head1 IMPLEMENTATION SUPPORT
18
+
19
+ This module is supported by all implementations of ZuzuScript.
20
+
21
+ =head1 DESCRIPTION
22
+
23
+ This runtime-supported module provides the task type, cancellation
24
+ objects, channels, timers, and combinators used with the
25
+ C<await { ... }> and C<spawn { ... }> language forms.
26
+
27
+ The Phase A model follows JavaScript promises closely: creating a task
28
+ starts independent work, and a spawned task's failure is observed only
29
+ when the task is awaited or passed to a combinator such as C<all>,
30
+ C<race>, or C<timeout>. Unawaited spawned tasks are detached background
31
+ work until the runtime shuts down. Async script entrypoints should be
32
+ written as C<async function __main__ ( argv ) { ... }>; the CLI awaits
33
+ that function after loading the script.
34
+
35
+ =head1 EXPORTS
36
+
37
+ =head2 Classes
38
+
39
+ =over
40
+
41
+ =item C<Task>
42
+
43
+ The runtime task type.
44
+
45
+ Tasks are awaitable values. Awaiting a fulfilled task returns its
46
+ result. Awaiting a rejected task throws the rejection value. Awaiting a
47
+ cancelled task throws C<CancelledException> or the stored cancellation
48
+ reason.
49
+
50
+ =over
51
+
52
+ =item C<< task.status() >>
53
+
54
+ Parameters: none. Returns: C<String>. Returns C<pending>, C<running>,
55
+ C<sleeping>, C<waiting>, C<fulfilled>, C<rejected>, or C<cancelled>.
56
+
57
+ =item C<< task.done() >>
58
+
59
+ Parameters: none. Returns: C<Boolean>. Returns true when the task has
60
+ fulfilled, rejected, or been cancelled.
61
+
62
+ =item C<< task.poll() >>
63
+
64
+ Parameters: none. Returns: C<Boolean>. Makes one non-blocking progress
65
+ check and returns whether the task has completed.
66
+
67
+ =item C<< task.cancel(reason?) >>
68
+
69
+ Parameters: C<reason> is an optional cancellation reason. Returns:
70
+ C<Task>. Cancels the task and returns the task.
71
+
72
+ =back
73
+
74
+ =item C<Channel>
75
+
76
+ Construct with C<new Channel()>. Returns a simple channel object with
77
+ C<send>, C<recv>, and C<close>. C<send> returns an immediately completed
78
+ task for the buffered first version, or fails with
79
+ C<ChannelClosedException> if the channel is closed. C<recv> returns a
80
+ pending task when no message is available and resolves to C<null> once a
81
+ closed channel has been drained.
82
+
83
+ C<null> is the documented end-of-stream result for an empty closed
84
+ channel.
85
+
86
+ =over
87
+
88
+ =item C<< channel.send(value) >>
89
+
90
+ Parameters: C<value> is any value that may be sent through the channel.
91
+ Returns: C<Task>. Sends a value or fails if the channel is closed.
92
+
93
+ =item C<< channel.recv() >>
94
+
95
+ Parameters: none. Returns: C<Task>. Resolves to the next value, or to
96
+ C<null> after a closed channel has drained.
97
+
98
+ =item C<< channel.close() >>
99
+
100
+ Parameters: none. Returns: C<null>. Closes the channel.
101
+
102
+ =back
103
+
104
+ =item C<CancellationToken>
105
+
106
+ Cancellation signal object.
107
+
108
+ =over
109
+
110
+ =item C<< token.cancelled() >>
111
+
112
+ Parameters: none. Returns: C<Boolean>. Returns true when cancellation
113
+ has been requested.
114
+
115
+ =item C<< token.reason() >>
116
+
117
+ Parameters: none. Returns: value or C<null>. Returns the cancellation
118
+ reason.
119
+
120
+ =item C<< token.throw_if_cancelled() >>
121
+
122
+ Parameters: none. Returns: C<null>. Throws when cancellation has been
123
+ requested.
124
+
125
+ =item C<< token.watch(task) >>
126
+
127
+ Parameters: C<task> is a C<Task>. Returns: C<Task>. Registers C<task>
128
+ for cancellation when the token is cancelled.
129
+
130
+ =back
131
+
132
+ =item C<CancellationSource>
133
+
134
+ Construct with C<new CancellationSource()>. Calling
135
+ C<source.cancel(reason)> marks its token as cancelled, stores the
136
+ cancellation reason, and cancels tasks registered with
137
+ C<source.token().watch(task)>.
138
+
139
+ =over
140
+
141
+ =item C<< source.token() >>
142
+
143
+ Parameters: none. Returns: C<CancellationToken>. Returns the source's
144
+ token.
145
+
146
+ =item C<< source.cancel(reason?) >>
147
+
148
+ Parameters: C<reason> is an optional cancellation reason. Returns:
149
+ C<null>. Marks the token cancelled and cancels watched tasks.
150
+
151
+ =item C<< source.cancelled() >>
152
+
153
+ Parameters: none. Returns: C<Boolean>. Returns true when the source has
154
+ been cancelled.
155
+
156
+ =item C<< source.reason() >>
157
+
158
+ Parameters: none. Returns: value or C<null>. Returns the stored
159
+ cancellation reason.
160
+
161
+ =back
162
+
163
+ =back
164
+
165
+ =head2 Functions
166
+
167
+ =over
168
+
169
+ =item C<resolved(value)>
170
+
171
+ Parameters: C<value> is any value. Returns: C<Task>. Returns a task that
172
+ resolves to C<value>.
173
+
174
+ =item C<failed(message)>
175
+
176
+ Parameters: C<message> is a failure value. Returns: C<Task>. Returns a
177
+ task that fails with C<message>.
178
+
179
+ =item C<sleep(seconds)>
180
+
181
+ Parameters: C<seconds> is a delay in seconds. Returns: C<Task>. Returns
182
+ a task that completes after the requested delay.
183
+
184
+ =item C<yield()>
185
+
186
+ Parameters: none. Returns: C<Task>. Returns a task that completes after
187
+ yielding back to the async scheduler once.
188
+
189
+ =item C<all(tasks)>
190
+
191
+ Parameters: C<tasks> is an array of tasks. Returns: C<Task>. Returns a
192
+ task that awaits all tasks and resolves to an array of results in input
193
+ order.
194
+
195
+ If any input task rejects or is cancelled, the C<all> task rejects or is
196
+ cancelled with that same failure.
197
+
198
+ =item C<race(tasks)>
199
+
200
+ Parameters: C<tasks> is an array of tasks. Returns: C<Task>. Returns a
201
+ task that resolves or fails with the first completed input task and
202
+ cancels unfinished losing tasks.
203
+
204
+ Loser cancellation is part of the public contract. Keep task handles and
205
+ await them separately if later completion is important.
206
+
207
+ =item C<timeout(seconds, task)>
208
+
209
+ Parameters: C<seconds> is a timeout in seconds and C<task> is the task
210
+ to await. Returns: C<Task>. Returns a task that fails with
211
+ C<TimeoutException> if C<task> does not complete before the timeout.
212
+
213
+ =back
214
+
215
+ =head1 COPYRIGHT AND LICENCE
216
+
217
+ B<< std/task >> is copyright Toby Inkster.
218
+
219
+ It is free software; you may redistribute it and/or modify it under
220
+ the terms of either the Artistic License 1.0 or the GNU General Public
221
+ License version 2.