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,152 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const fs = require( 'node:fs' );
5
+ const path = require( 'node:path' );
6
+ const { compileToBundle } = require( '../lib/compiler' );
7
+
8
+ function printUsage( message = '' ) {
9
+ if ( message ) {
10
+ process.stderr.write( `${message}\n` );
11
+ }
12
+ process.stderr.write( 'Usage: zuzu-js-compile [options] path/to/script.zzs\n' );
13
+ process.stderr.write( 'Options:\n' );
14
+ process.stderr.write( ' -I/path/to/lib add module include directory\n' );
15
+ process.stderr.write( ' -o, --output <file> write output to file instead of stdout\n' );
16
+ process.stderr.write( ' --sourcemap=none reserve source map option; only none is supported\n' );
17
+ process.stderr.write( ' --transpiler=new-only select transpiler implementation\n' );
18
+ process.stderr.write( ' -h, --help show this help\n' );
19
+ }
20
+
21
+ function parseArgValue( argv, index, flag ) {
22
+ if ( index + 1 >= argv.length ) {
23
+ return { error: `Missing value for ${flag}` };
24
+ }
25
+ return { value: argv[index + 1], nextIndex: index + 1 };
26
+ }
27
+
28
+ function parseArgs( argv ) {
29
+ const options = {
30
+ includePaths: [],
31
+ output: null,
32
+ sourcemap: 'none',
33
+ transpiler: null,
34
+ help: false,
35
+ entry: null,
36
+ };
37
+ for ( let i = 0; i < argv.length; i++ ) {
38
+ const arg = argv[i];
39
+ if ( arg === '-h' || arg === '--help' ) {
40
+ options.help = true;
41
+ continue;
42
+ }
43
+ if ( arg === '-o' || arg === '--output' ) {
44
+ const parsed = parseArgValue( argv, i, arg );
45
+ if ( parsed.error ) {
46
+ return { error: parsed.error };
47
+ }
48
+ options.output = parsed.value;
49
+ i = parsed.nextIndex;
50
+ continue;
51
+ }
52
+ if ( arg.startsWith( '--output=' ) ) {
53
+ options.output = arg.slice( '--output='.length );
54
+ continue;
55
+ }
56
+ if ( arg === '-I' ) {
57
+ const parsed = parseArgValue( argv, i, '-I' );
58
+ if ( parsed.error ) {
59
+ return { error: parsed.error };
60
+ }
61
+ options.includePaths.push( parsed.value );
62
+ i = parsed.nextIndex;
63
+ continue;
64
+ }
65
+ if ( arg.startsWith( '-I' ) && arg.length > 2 ) {
66
+ options.includePaths.push( arg.slice( 2 ) );
67
+ continue;
68
+ }
69
+ if ( arg === '--transpiler' ) {
70
+ const parsed = parseArgValue( argv, i, '--transpiler' );
71
+ if ( parsed.error ) {
72
+ return { error: parsed.error };
73
+ }
74
+ options.transpiler = parsed.value;
75
+ i = parsed.nextIndex;
76
+ continue;
77
+ }
78
+ if ( arg.startsWith( '--transpiler=' ) ) {
79
+ options.transpiler = arg.slice( '--transpiler='.length );
80
+ continue;
81
+ }
82
+ if ( arg === '--sourcemap' ) {
83
+ const parsed = parseArgValue( argv, i, '--sourcemap' );
84
+ if ( parsed.error ) {
85
+ return { error: parsed.error };
86
+ }
87
+ options.sourcemap = parsed.value;
88
+ i = parsed.nextIndex;
89
+ continue;
90
+ }
91
+ if ( arg.startsWith( '--sourcemap=' ) ) {
92
+ options.sourcemap = arg.slice( '--sourcemap='.length );
93
+ continue;
94
+ }
95
+ if ( arg.startsWith( '-' ) ) {
96
+ return { error: `Unknown option: ${arg}` };
97
+ }
98
+ if ( options.entry != null ) {
99
+ return { error: `Unexpected argument: ${arg}` };
100
+ }
101
+ options.entry = arg;
102
+ }
103
+ if ( options.sourcemap !== 'none' ) {
104
+ return { error: `Unsupported source map mode: ${options.sourcemap}` };
105
+ }
106
+ if ( !options.help && options.entry == null ) {
107
+ return { error: 'Missing input script' };
108
+ }
109
+ return { options };
110
+ }
111
+
112
+ function main( argv = process.argv.slice( 2 ) ) {
113
+ const parsed = parseArgs( argv );
114
+ if ( parsed.error ) {
115
+ printUsage( parsed.error );
116
+ return 2;
117
+ }
118
+ const options = parsed.options;
119
+ if ( options.help ) {
120
+ printUsage();
121
+ return 0;
122
+ }
123
+ try {
124
+ const output = compileToBundle( path.resolve( options.entry ), {
125
+ includePaths: options.includePaths,
126
+ transpiler: options.transpiler,
127
+ } );
128
+ if ( options.output ) {
129
+ fs.mkdirSync( path.dirname( path.resolve( options.output ) ), {
130
+ recursive: true,
131
+ } );
132
+ fs.writeFileSync( options.output, output, 'utf8' );
133
+ }
134
+ else {
135
+ process.stdout.write( output );
136
+ }
137
+ return 0;
138
+ }
139
+ catch ( err ) {
140
+ process.stderr.write( `${err && err.message ? err.message : String( err )}\n` );
141
+ return 1;
142
+ }
143
+ }
144
+
145
+ if ( require.main === module ) {
146
+ process.exitCode = main();
147
+ }
148
+
149
+ module.exports = {
150
+ main,
151
+ parseArgs,
152
+ };
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { runElectronMain } = require( '../lib/electron/main' );
5
+ const { launchElectronScript } = require( '../lib/electron/launcher' );
6
+
7
+ const run = process.versions && process.versions.electron
8
+ ? runElectronMain
9
+ : launchElectronScript;
10
+
11
+ run( process.argv.slice( 2 ) ).then(
12
+ (exitCode) => {
13
+ process.exitCode = exitCode;
14
+ },
15
+ (err) => {
16
+ process.stderr.write( `${err && err.stack ? err.stack : String( err )}\n` );
17
+ process.exitCode = 1;
18
+ },
19
+ );