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,75 @@
1
+ =encoding utf8
2
+
3
+ =head1 NAME
4
+
5
+ std/defer - Run a callback when a guard object is demolished.
6
+
7
+ =head1 SYNOPSIS
8
+
9
+ from std/defer import Guard;
10
+
11
+ let guard := new Guard( callback: fn () { cleanup(); } );
12
+ guard.disable();
13
+
14
+ =head1 IMPLEMENTATION SUPPORT
15
+
16
+ This module is supported by all implementations of ZuzuScript.
17
+
18
+ =head1 DESCRIPTION
19
+
20
+ C<Guard> is a small scope guard. It stores a callback and can be armed or
21
+ disarmed before demolition.
22
+
23
+ =head1 EXPORTS
24
+
25
+ =head2 Classes
26
+
27
+ =over
28
+
29
+ =item C<< Guard({ callback: Function, armed?: Boolean }) >>
30
+
31
+ Constructs a guard that calls C<callback> when the object is demolished.
32
+ The guard starts armed unless C<armed> is supplied as false.
33
+
34
+ =over
35
+
36
+ =item C<< guard.enable() >>
37
+
38
+ Parameters: none. Returns: C<null>. Arms the guard so demolition will run
39
+ the callback.
40
+
41
+ =item C<< guard.disable() >>
42
+
43
+ Parameters: none. Returns: C<null>. Disarms the guard so demolition will
44
+ not run the callback.
45
+
46
+ =back
47
+
48
+ =back
49
+
50
+ =head1 COPYRIGHT AND LICENCE
51
+
52
+ B<< std/defer >> is copyright Toby Inkster.
53
+
54
+ It is free software; you may redistribute it and/or modify it under
55
+ the terms of either the Artistic License 1.0 or the GNU General Public
56
+ License version 2.
57
+
58
+ =cut
59
+
60
+ class Guard {
61
+ let Boolean armed := true;
62
+ let Function callback;
63
+
64
+ method enable () {
65
+ armed := true;
66
+ }
67
+
68
+ method disable () {
69
+ armed := false;
70
+ }
71
+
72
+ method __demolish__ () {
73
+ callback();
74
+ }
75
+ }
@@ -0,0 +1,196 @@
1
+ =encoding utf8
2
+
3
+ =head1 NAME
4
+
5
+ std/digest/crc32 - CRC32 digests for BinaryString values.
6
+
7
+ =head1 SYNOPSIS
8
+
9
+ from std/digest/crc32 import *;
10
+
11
+ let payload := to_binary( "hello" );
12
+
13
+ let raw := crc32(payload);
14
+ let hex := crc32_hex(payload);
15
+ let b64 := crc32_b64(payload);
16
+
17
+ =head1 IMPLEMENTATION SUPPORT
18
+
19
+ This module is supported by all implementations of ZuzuScript.
20
+
21
+ =head1 DESCRIPTION
22
+
23
+ This module provides CRC32 digest helpers implemented in pure
24
+ ZuzuScript.
25
+
26
+ =head1 EXPORTS
27
+
28
+ =head2 Functions
29
+
30
+ =over
31
+
32
+ =item * C<crc32(BinaryString value)>
33
+
34
+ Parameters: C<value> is binary input data. Returns: C<BinaryString>.
35
+ Returns the raw 4-byte CRC32 digest.
36
+
37
+ =item * C<crc32_hex(BinaryString value)>
38
+
39
+ Parameters: C<value> is binary input data. Returns: C<String>. Returns
40
+ the digest as lowercase hexadecimal text.
41
+
42
+ =item * C<crc32_b64(BinaryString value)>
43
+
44
+ Parameters: C<value> is binary input data. Returns: C<String>. Returns
45
+ the digest as Base64 text without trailing C<=> padding.
46
+
47
+ =back
48
+
49
+ =head1 COPYRIGHT AND LICENCE
50
+
51
+ B<< std/digest/crc32 >> is copyright Toby Inkster.
52
+
53
+ It is free software; you may redistribute it and/or modify it under
54
+ the terms of either the Artistic License 1.0 or the GNU General Public
55
+ License version 2.
56
+
57
+ =cut
58
+
59
+ from std/string/base64 import encode, decode;
60
+ from std/string import substr, index;
61
+
62
+ let _HEX := "0123456789abcdef";
63
+ let _B64_ALPHABET := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
64
+
65
+ function _div_floor ( Number n, Number d ) {
66
+ return floor( n / d );
67
+ }
68
+
69
+ function _bytes_to_binary ( Array bytes ) {
70
+ let out := "";
71
+ let i := 0;
72
+ let n := bytes.length();
73
+
74
+ while ( i < n ) {
75
+ let b0 := bytes[i];
76
+ let b1 := null;
77
+ let b2 := null;
78
+ if ( i + 1 < n ) {
79
+ b1 := bytes[i + 1];
80
+ }
81
+ if ( i + 2 < n ) {
82
+ b2 := bytes[i + 2];
83
+ }
84
+
85
+ let c0 := _div_floor( b0, 4 );
86
+ let c1 := ( b0 & 3 ) * 16;
87
+ let c2 := 64;
88
+ let c3 := 64;
89
+
90
+ if ( b1 ≢ null ) {
91
+ c1 += _div_floor( b1, 16 );
92
+ c2 := ( b1 & 15 ) * 4;
93
+ if ( b2 ≢ null ) {
94
+ c2 += _div_floor( b2, 64 );
95
+ c3 := b2 & 63;
96
+ }
97
+ }
98
+
99
+ out _= substr( _B64_ALPHABET, c0, 1 );
100
+ out _= substr( _B64_ALPHABET, c1, 1 );
101
+ out _= c2 ≡ 64 ? "=": substr( _B64_ALPHABET, c2, 1 );
102
+ out _= c3 ≡ 64 ? "=": substr( _B64_ALPHABET, c3, 1 );
103
+ i += 3;
104
+ }
105
+
106
+ return decode(out);
107
+ }
108
+
109
+ function _u32_to_binary ( Number n ) {
110
+ let b0 := _div_floor( n, 16777216 ) & 255;
111
+ let b1 := _div_floor( n, 65536 ) & 255;
112
+ let b2 := _div_floor( n, 256 ) & 255;
113
+ let b3 := n & 255;
114
+ return _bytes_to_binary( [ b0, b1, b2, b3 ] );
115
+ }
116
+
117
+ function _byte_to_hex ( Number b ) {
118
+ let hi := _div_floor( b, 16 ) & 15;
119
+ let lo := b & 15;
120
+ return substr( _HEX, hi, 1 ) _ substr( _HEX, lo, 1 );
121
+ }
122
+
123
+
124
+ function _binary_to_bytes ( BinaryString raw ) {
125
+ let b64 := encode(raw);
126
+ let out := [];
127
+ let i := 0;
128
+ let n := length b64;
129
+
130
+ while ( i < n ) {
131
+ let c0 := index( _B64_ALPHABET, substr( b64, i, 1 ) );
132
+ let c1 := index( _B64_ALPHABET, substr( b64, i + 1, 1 ) );
133
+ let ch2 := substr( b64, i + 2, 1 );
134
+ let ch3 := substr( b64, i + 3, 1 );
135
+ let c2 := -1;
136
+ let c3 := -1;
137
+ if ( ch2 ≢ "=" ) {
138
+ c2 := index( _B64_ALPHABET, ch2 );
139
+ }
140
+ if ( ch3 ≢ "=" ) {
141
+ c3 := index( _B64_ALPHABET, ch3 );
142
+ }
143
+
144
+ out.push( c0 * 4 + _div_floor( c1, 16 ) );
145
+ if ( c2 >= 0 ) {
146
+ out.push( ( c1 & 15 ) * 16 + _div_floor( c2, 4 ) );
147
+ }
148
+ if ( c3 >= 0 ) {
149
+ out.push( ( c2 & 3 ) * 64 + c3 );
150
+ }
151
+
152
+ i += 4;
153
+ }
154
+
155
+ return out;
156
+ }
157
+
158
+ function crc32 ( BinaryString value ) {
159
+ let bytes := _binary_to_bytes(value);
160
+ let crc := 4294967295;
161
+
162
+ for ( let b in bytes ) {
163
+ crc := crc ^ b;
164
+ let i := 0;
165
+ while ( i < 8 ) {
166
+ if ( ( crc & 1 ) ≡ 1 ) {
167
+ crc := _div_floor( crc, 2 ) ^ 3988292384;
168
+ }
169
+ else {
170
+ crc := _div_floor( crc, 2 );
171
+ }
172
+ i++;
173
+ }
174
+ }
175
+
176
+ crc := ( ~crc ) & 4294967295;
177
+
178
+ return _u32_to_binary(crc);
179
+ }
180
+
181
+ function crc32_hex ( BinaryString value ) {
182
+ let digest := _binary_to_bytes( crc32(value) );
183
+ let out := "";
184
+ for ( let b in digest ) {
185
+ out _= _byte_to_hex(b);
186
+ }
187
+ return out;
188
+ }
189
+
190
+ function crc32_b64 ( BinaryString value ) {
191
+ let out := encode( crc32(value) );
192
+ while ( length out > 0 and substr( out, length out - 1, 1 ) ≡ "=" ) {
193
+ out := substr( out, 0, length out - 1 );
194
+ }
195
+ return out;
196
+ }
@@ -0,0 +1,54 @@
1
+ =encoding utf8
2
+
3
+ =head1 NAME
4
+
5
+ std/digest/md5 - MD5 digests for BinaryString values.
6
+
7
+ =head1 SYNOPSIS
8
+
9
+ from std/digest/md5 import *;
10
+
11
+ let payload := to_binary( "hello" );
12
+
13
+ let raw := md5(payload);
14
+ let hex := md5_hex(payload);
15
+ let b64 := md5_b64(payload);
16
+
17
+ =head1 IMPLEMENTATION SUPPORT
18
+
19
+ This module is supported by all implementations of ZuzuScript.
20
+
21
+ =head1 DESCRIPTION
22
+
23
+ This module provides MD5 digest helpers.
24
+
25
+ =head1 EXPORTS
26
+
27
+ =head2 Functions
28
+
29
+ =over
30
+
31
+ =item * C<md5(BinaryString value)>
32
+
33
+ Parameters: C<value> is binary input data. Returns: C<BinaryString>.
34
+ Returns the raw 16-byte MD5 digest.
35
+
36
+ =item * C<md5_hex(BinaryString value)>
37
+
38
+ Parameters: C<value> is binary input data. Returns: C<String>. Returns
39
+ the digest as lowercase hexadecimal text.
40
+
41
+ =item * C<md5_b64(BinaryString value)>
42
+
43
+ Parameters: C<value> is binary input data. Returns: C<String>. Returns
44
+ the digest as Base64 text without trailing C<=> padding.
45
+
46
+ =back
47
+
48
+ =head1 COPYRIGHT AND LICENCE
49
+
50
+ B<< std/digest/md5 >> is copyright Toby Inkster.
51
+
52
+ It is free software; you may redistribute it and/or modify it under
53
+ the terms of either the Artistic License 1.0 or the GNU General Public
54
+ License version 2.
@@ -0,0 +1,83 @@
1
+ =encoding utf8
2
+
3
+ =head1 NAME
4
+
5
+ std/digest/sha - SHA digests for BinaryString values.
6
+
7
+ =head1 SYNOPSIS
8
+
9
+ from std/digest/sha import *;
10
+
11
+ let payload := to_binary( "hello" );
12
+ let key := to_binary( "shared-secret" );
13
+
14
+ let hex256 := sha256_hex(payload);
15
+ let raw512 := sha512(payload);
16
+ let auth := hmac_sha256_hex(payload, key);
17
+
18
+ =head1 IMPLEMENTATION SUPPORT
19
+
20
+ This module is supported by all implementations of ZuzuScript.
21
+
22
+ =head1 DESCRIPTION
23
+
24
+ This module provides SHA digest and HMAC helpers.
25
+
26
+ =head1 EXPORTS
27
+
28
+ =head2 Functions
29
+
30
+ For each of C<sha1>, C<sha224>, C<sha256>, C<sha384>, and
31
+ C<sha512>, this module exports three function forms:
32
+
33
+ =over
34
+
35
+ =item * C<< NAME(BinaryString value) >>
36
+
37
+ Parameters: C<value> is binary input data. Returns: C<BinaryString>.
38
+ Returns the raw digest.
39
+
40
+ =item * C<< NAME_hex(BinaryString value) >>
41
+
42
+ Parameters: C<value> is binary input data. Returns: C<String>. Returns
43
+ lowercase hexadecimal text.
44
+
45
+ =item * C<< NAME_b64(BinaryString value) >>
46
+
47
+ Parameters: C<value> is binary input data. Returns: C<String>. Returns
48
+ Base64 text without trailing C<=> padding.
49
+
50
+ =back
51
+
52
+ =head2 HMAC Functions
53
+
54
+ For each of C<hmac_sha1>, C<hmac_sha224>, C<hmac_sha256>,
55
+ C<hmac_sha384>, and C<hmac_sha512>, this module exports:
56
+
57
+ =over
58
+
59
+ =item * C<< NAME(BinaryString value, BinaryString key) >>
60
+
61
+ Parameters: C<value> is binary input data and C<key> is the HMAC key.
62
+ Returns: C<BinaryString>. Returns a raw HMAC digest.
63
+
64
+ =item * C<< NAME_hex(BinaryString value, BinaryString key) >>
65
+
66
+ Parameters: C<value> is binary input data and C<key> is the HMAC key.
67
+ Returns: C<String>. Returns lowercase hexadecimal HMAC text.
68
+
69
+ =item * C<< NAME_b64(BinaryString value, BinaryString key) >>
70
+
71
+ Parameters: C<value> is binary input data and C<key> is the HMAC key.
72
+ Returns: C<String>. Returns Base64 HMAC text with no trailing C<=>
73
+ padding.
74
+
75
+ =back
76
+
77
+ =head1 COPYRIGHT AND LICENCE
78
+
79
+ B<< std/digest/sha >> is copyright Toby Inkster.
80
+
81
+ It is free software; you may redistribute it and/or modify it under
82
+ the terms of either the Artistic License 1.0 or the GNU General Public
83
+ License version 2.