@naanlang/naan 1.0.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 (98) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +46 -0
  3. package/dist/env_web.js +431 -0
  4. package/dist/naan.min.js +73 -0
  5. package/frameworks/browser/browser.nlg +30 -0
  6. package/frameworks/browser/pouchdb/pouchdb.min.js +7 -0
  7. package/frameworks/browser/spark-md5/spark-md5.min.js +1 -0
  8. package/frameworks/browser/sworker.js +192 -0
  9. package/frameworks/browser/terminals.nlg +787 -0
  10. package/frameworks/browser/workers.nlg +386 -0
  11. package/frameworks/client/apiclient.nlg +183 -0
  12. package/frameworks/client/client.nlg +29 -0
  13. package/frameworks/client/psm_client.nlg +572 -0
  14. package/frameworks/common/common.nlg +464 -0
  15. package/frameworks/common/preferences.nlg +131 -0
  16. package/frameworks/common/repltools.nlg +100 -0
  17. package/frameworks/common/watching.nlg +97 -0
  18. package/frameworks/node/apiserver.nlg +399 -0
  19. package/frameworks/node/filesystem.nlg +1012 -0
  20. package/frameworks/node/gitter.nlg +234 -0
  21. package/frameworks/node/node.nlg +81 -0
  22. package/frameworks/node/psm_server.nlg +465 -0
  23. package/frameworks/node/worker.nlg +560 -0
  24. package/frameworks/project/build.nlg +1229 -0
  25. package/frameworks/project/jszip.js +30 -0
  26. package/frameworks/project/jszip.nlg +87 -0
  27. package/frameworks/project/proj_cliser.nlg +139 -0
  28. package/frameworks/project/proj_console.nlg +137 -0
  29. package/frameworks/project/proj_folder.nlg +143 -0
  30. package/frameworks/project/proj_lambda.nlg +137 -0
  31. package/frameworks/project/proj_static.nlg +138 -0
  32. package/frameworks/project/project.nlg +29 -0
  33. package/frameworks/project/projects.nlg +587 -0
  34. package/frameworks/project/uglifyjs.js +1 -0
  35. package/frameworks/project/uglifyjs.nlg +79 -0
  36. package/frameworks/running/debugcom.nlg +163 -0
  37. package/frameworks/running/debugnub.nlg +565 -0
  38. package/frameworks/running/debugutil.nlg +510 -0
  39. package/frameworks/running/executors.nlg +767 -0
  40. package/frameworks/running/running.nlg +151 -0
  41. package/frameworks/running/sourcecode.nlg +346 -0
  42. package/frameworks/running/taskexec.nlg +196 -0
  43. package/frameworks/storage/dbt_pouch.nlg +773 -0
  44. package/frameworks/storage/file_manager.nlg +772 -0
  45. package/frameworks/storage/psm.nlg +326 -0
  46. package/frameworks/storage/psm_dbtables.nlg +814 -0
  47. package/frameworks/storage/resources.nlg +445 -0
  48. package/frameworks/storage/storage.nlg +52 -0
  49. package/lib/browser/env_web.js +431 -0
  50. package/lib/browser/env_webworker.js +146 -0
  51. package/lib/browser/require.js +1653 -0
  52. package/lib/core/naanlib.js +73 -0
  53. package/lib/env_node.js +282 -0
  54. package/lib/env_nodeworker.js +165 -0
  55. package/lib/node_repl.js +25 -0
  56. package/lib/node_repl_init.nlg +52 -0
  57. package/package.json +13 -0
  58. package/plugins/gitClient/clientops.nlg +317 -0
  59. package/plugins/gitClient/gitClient.nlg +63 -0
  60. package/plugins/gitClient/gitutils.nlg +1331 -0
  61. package/plugins/gitClient/minimatch.js +945 -0
  62. package/plugins/gitClient/minimatch_license.txt +15 -0
  63. package/plugins/gitClient/minimatch_readme.md +208 -0
  64. package/plugins/nodeLib/nodeLib.nlg +26 -0
  65. package/plugins/nodeLib/node_cp.nlg +65 -0
  66. package/plugins/nodeLib/node_fs.nlg +137 -0
  67. package/plugins/nodeLib/node_https.nlg +172 -0
  68. package/plugins/nodeLib/node_util.nlg +180 -0
  69. package/plugins/serviceAws/aws/aws-sdk.min.js +88 -0
  70. package/plugins/serviceAws/aws/lambda_rest_index.js +122 -0
  71. package/plugins/serviceAws/aws/lambda_rest_init.nlg +58 -0
  72. package/plugins/serviceAws/aws/lambda_ws_index.js +498 -0
  73. package/plugins/serviceAws/aws/lambda_ws_init.nlg +49 -0
  74. package/plugins/serviceAws/aws_cloudwatchlogs.nlg +122 -0
  75. package/plugins/serviceAws/aws_cognito.nlg +76 -0
  76. package/plugins/serviceAws/aws_dynamo.nlg +509 -0
  77. package/plugins/serviceAws/aws_lambda.nlg +95 -0
  78. package/plugins/serviceAws/aws_s3.nlg +134 -0
  79. package/plugins/serviceAws/aws_utils.nlg +86 -0
  80. package/plugins/serviceAws/dbt_aws.nlg +769 -0
  81. package/plugins/serviceAws/lambda_naan_control.nlg +175 -0
  82. package/plugins/serviceAws/psm_aws.nlg +258 -0
  83. package/plugins/serviceAws/serviceAws.nlg +38 -0
  84. package/plugins/serviceGitHub/gitops.nlg +522 -0
  85. package/plugins/serviceGitHub/psm_github.nlg +205 -0
  86. package/plugins/serviceGitHub/serviceGitHub.nlg +65 -0
  87. package/plugins/serviceGitLab/gitops.nlg +528 -0
  88. package/plugins/serviceGitLab/psm_gitlab.nlg +205 -0
  89. package/plugins/serviceGitLab/serviceGitLab.nlg +65 -0
  90. package/test/harness.nlg +312 -0
  91. package/test/node_test.js +33 -0
  92. package/test/test_01_core.nlg +768 -0
  93. package/test/test_02_context.nlg +269 -0
  94. package/test/test_03_jsinterop.nlg +137 -0
  95. package/test/test_04_numerics.nlg +450 -0
  96. package/test/test_05_strings.nlg +63 -0
  97. package/test/test_06_lingoparse.nlg +500 -0
  98. package/test/test_07_lingo.nlg +623 -0
@@ -0,0 +1,623 @@
1
+ /*
2
+ * test_07_lingo.nlg
3
+ * Test
4
+ *
5
+ * Perform basic unit tests for Naan.
6
+ *
7
+ * column positioning: // // !
8
+ *
9
+ * Copyright (c) 2018-2021 by Richard C. Zulch
10
+ *
11
+ */
12
+
13
+
14
+ /*
15
+ * Test Category 7 - Lingo
16
+ *
17
+ */
18
+
19
+ RegisterTestCategory("Lingo", [
20
+ [ "4+3;", "7" ], // generic first test
21
+ [ "Dialect eq Dialect();>", "true" ],
22
+
23
+ //
24
+ // coalescing
25
+ //
26
+
27
+ [ "\"abc\" \"def\" \"ghi\" \"jkl\";", "\"abcdefghijkl\"" ],
28
+ [ "quote(a || b);>", "(|| a b)" ],
29
+ [ "quote(a || b || c);>", "(|| a b c)" ],
30
+ [ "quote(a || b || c || d);>", "(|| a b c d)" ],
31
+ [ "quote(a && b);>", "(&& a b)" ],
32
+ [ "quote(a && b && c);>", "(&& a b c)" ],
33
+ [ "quote(a && b && c && d);>", "(&& a b c d)" ],
34
+
35
+
36
+ //
37
+ // objects
38
+ //
39
+
40
+ [ "function test1() {\n"
41
+ " {a:33,b:44} // hi there\n"
42
+ "};", "test1" ],
43
+ [ "getproc(test1);",
44
+ "function test1() {\n"
45
+ " { a: 33, b: 44 } // hi there\n"
46
+ "}" ],
47
+ [ "\"abc\".toUpperCase();", "\"ABC\"" ],
48
+ [ "{ a:print }.a(\"Hi\"); // test", "Hi|\"Hi\"" ],
49
+ [ "{ a:print }["a"](\"Hi\");", "Hi|\"Hi\"" ],
50
+ [ "{ a:quote(function(){print(\"High\")}) }.a();", "High|\"High\"" ],
51
+ [ "a.b -1;", "false" ],
52
+ [ "a.b-1;", "false" ],
53
+
54
+
55
+ //
56
+ // weakmaps
57
+ //
58
+
59
+ [ "wm=new(weakmap);", "[object WeakMap]" ],
60
+ [ "weakmap(wm);", "true" ],
61
+ [ "weakmap({});", "false" ],
62
+ [ "aa = [4,5,6];", "[4, 5, 6]" ],
63
+ [ "oo = {a:3,b:4};", "{ a: 3, b: 4 }" ],
64
+ [ "tt = `(a,b,c);", "(a, b, c)" ],
65
+ [ "wm[aa] = 33;", "33" ],
66
+ [ "wm[oo] = 44;", "44" ],
67
+ [ "wm[tt] = 55;", "55" ],
68
+ [ "wm[3] = `(1,2,3);", "(1, 2, 3)" ],
69
+ [ "wm[\"three\"] = 4;", "4" ],
70
+ [ "wm[3.3] = 5;", "5" ],
71
+ [ "wm[symbolic] = 6;", "6" ],
72
+ [ "wm[aa];", "33" ],
73
+ [ "wm[oo];", "44" ],
74
+ [ "wm[tt];", "55" ],
75
+ [ "wm[3];", "(1, 2, 3)" ],
76
+ [ "wm[3.0];", "(1, 2, 3)" ], // float converted on export
77
+ [ "wm[\"three\"];", "4" ],
78
+ [ "wm[3.3];", "5" ],
79
+ [ "wm[3.4];", "false" ],
80
+ [ "wm[symbolic];", "6" ],
81
+ [ "wm[unintern(\"symbolic\")];", "false" ],
82
+ [ "wm[2];", "false" ],
83
+ [ "wm[\"four\"];", "false" ],
84
+ [ "wm[[]];", "false" ],
85
+ [ "wm[{}];", "false" ],
86
+ [ "wm[`()];", "false" ],
87
+ [ "wm[oo] = undefined;", "undefined" ],
88
+ [ "wm[oo];", "false" ],
89
+
90
+
91
+ //
92
+ // === and !== operators
93
+ //
94
+
95
+ [ "pp = oo;", "{ a: 3, b: 4 }" ],
96
+ [ "{a:3,b:4} == oo;", "true" ],
97
+ [ "{a:3,b:4} != oo;", "false" ],
98
+ [ "{a:3,b:4} === oo;", "false" ],
99
+ [ "{a:3,b:4} !== oo;", "true" ],
100
+ [ "pp == oo;", "true" ],
101
+ [ "pp != oo;", "false" ],
102
+ [ "pp === oo;", "true" ],
103
+ [ "pp !== oo;", "false" ],
104
+
105
+
106
+ //
107
+ // <=> operator
108
+ //
109
+
110
+ [ "false <=> false;", "0" ],
111
+ [ "false <=> true;", "0" ],
112
+ [ "'a' <=> 'a';", "0" ],
113
+ [ "'a' <=> 'b';", "-1" ],
114
+ [ "'b' <=> 'a';", "1" ],
115
+ [ "1 <=> 0;", "1" ],
116
+ [ "0 <=> 1;", "-1" ],
117
+ [ "1 <=> 1;", "0" ],
118
+
119
+
120
+ //
121
+ // annotations
122
+ //
123
+
124
+ [ "quote(a@b);>", "(deref (@ a) (`` b))" ],
125
+ [ "quote(a@[b]);>", "(deref (@ a) b)" ],
126
+ [ "quote(a@*);>", "(@* a)" ],
127
+ [ "quote(a@b = 5);>", "(Lib::set\\\[ (@ a true) (`` b) 5)" ],
128
+ [ "quote(a@[b] = 6);>", "(Lib::set\\\[ (@ a true) b 6)" ],
129
+ [ "quote(a@b += 7);>", "(Lib::preadjust (deref (@ a) (`` b)) + 7)" ],
130
+ [ "quote(++a@b);>", "(Lib::preadjust (deref (@ a) (`` b)) + 1)" ],
131
+ [ "quote(a@b++);>", "(Lib::postadjust (deref (@ a) (`` b)) + 1)" ],
132
+ [ "quote(@b);>", "(Lib::set\\\. Lingo::annotations (`` b) (`` b))" ],
133
+ [ "quote(@b = 3);>", "(Lib::set\\\. Lingo::annotations (`` b) 3)" ],
134
+
135
+ [ "quote(a@b);", "a@b" ],
136
+ [ "quote(a@[b]);", "a@[b]" ],
137
+ [ "quote(a@*);", "a@*" ],
138
+ [ "quote(a@b = 5);", "a@b = 5" ],
139
+ [ "quote(a@[b] = 6);", "a@[b] = 6" ],
140
+ [ "quote(a@b += 7);", "a@b += 7" ],
141
+ [ "quote(++a@b);", "++a@b" ],
142
+ [ "quote(a@b++);", "a@b++" ],
143
+
144
+ [ "function jim(x) { \"you are annotated with \".concat(x, \"!\") };", "jim" ],
145
+ [ "call(`@, a);", "false" ],
146
+ [ "a@*;", "false" ],
147
+ [ "a@joe;", "false" ],
148
+ [ "a@joe = 55;", "55" ],
149
+ [ "a@*;", "(\"joe\")" ],
150
+ [ "a@joe;", "55" ],
151
+ [ "jim = 8;", "8" ],
152
+ [ "@joe = 3;@jim;function testat() { print(\"annotest\") };", "3|jim|testat" ],
153
+ [ "cdr(testat.proc.1);", "{\n"
154
+ " joe : 3,\n"
155
+ " jim : jim,\n"
156
+ " .sourcemap: {\n"
157
+ " count : 5,\n"
158
+ // " map : [(0, 23), 0, 9, 2, 7],\n" -- maps currently omitted
159
+ " comments : [] } }" ],
160
+ [ "testat@jim(true);", "\"you are annotated with true!\"" ],
161
+
162
+
163
+ //
164
+ // lists, objects & arrays
165
+ //
166
+
167
+ [ "divide(71, 3);", "(23 . 2)" ],
168
+ [ "[3,4+5];", "[3, 9]" ],
169
+ [ "{a:3,b:4+5};", "{ a: 3, b: 9 }" ],
170
+
171
+ [ "`(1, 2, {a:3,b:4}, 5);", "(1, 2, { a: 3, b: 4 }, 5)" ],
172
+ [ "`(1, 2, {a:3,b:4}, 5);>", "(1 2 Dictionary{2} 5)" ],
173
+ [ "`(1, 2, {a:3,b:4+5}, 6);", "(1, 2, { a: 3, b: 4+5 }, 6)" ],
174
+ [ "`(1, 2, {a:3,b:4+5}, 6);>", "(1 2 Dictionary{2} 6)" ],
175
+
176
+ [ "`(1 2 [3,4+5] 6);>", "(1 2 Array[2] 6)" ],
177
+ [ "`(1 2 [3,4+5] 6);", "(1, 2, [3, 4+5], 6)" ],
178
+ [ "`(1 2 [3,4+5] 6).2.1;", "4 + 5" ],
179
+ [ "quote(2*3+4*5);", "2*3 + 4*5" ],
180
+
181
+ [ "macro(x){x.c=5}({a:3,b:4});", { errors: "can't modify NaanConst::Dictionary{2} from Test-Lingo" } ],
182
+ [ "macro(x){x[1]=6}([3,4,5]);", { errors: "can't modify NaanConst::Array[3] from Test-Lingo" } ],
183
+
184
+ [ "js.*;", '("n", "o", "d", "g", "r", "t")' ],
185
+
186
+ [ "[1,2,3].concat(4,5,6);", "[1, 2, 3, 4, 5, 6]" ],
187
+ [ "[1,2,3].concat([4,5,6]);", "[1, 2, 3, 4, 5, 6]" ],
188
+
189
+ [ "[1,4,9].reduce(function(a,b){Math.max(a,b)});", "9" ],
190
+ [ "[1,4,9].reduce(function(a,b){Math.max(a,b)}, 10);", "10" ],
191
+ [ "[].reduce(function(a,b){Math.max(a,b)}, 10);", "10" ],
192
+ [ "[].reduce(function(a,b){Math.max(a,b)});", "false" ],
193
+ [ "[{x:\"a\"},{x:\"b\"},{x:\"c\"}].reduce(function(a,b,c,d){{x:a.x.concat(tostring(b.x))}});", "{ x: \"abc\" }" ],
194
+
195
+ [ "function(oo){oo._id=3}({a:4});", "3" ],
196
+ [ "function(xx,oo){oo._id=3}(true,{a:4});", "3" ],
197
+
198
+ [ "[1,quote(2+3),4].find(function(el){el==list(`+,2,3)});", "2 + 3" ],
199
+ [ "[1,quote(2+3),4].find(function(el){el==5});", "undefined" ],
200
+
201
+
202
+ //
203
+ // ! operator and friends
204
+ //
205
+
206
+ [ "not true;", "false" ],
207
+ [ "!true;", "false" ],
208
+ [ "not false;", "true" ],
209
+ [ "!false;", "true" ],
210
+ [ "not 0;", "false" ],
211
+ [ "!0;", "false" ],
212
+ [ "quote(!0);>", "(not 0)" ],
213
+ [ "quote(not aa);", "!aa" ],
214
+ [ "quote(!aa);", "!aa" ],
215
+ [ "quote(!aa);>", "(not aa)" ],
216
+ [ "quote(!aa>bb);", "!aa>bb" ],
217
+ [ "quote(!aa>bb);>", "(not (> aa bb))" ],
218
+ [ "quote(!a*b);", "!a*b" ],
219
+ [ "quote(!(a*b));", "!a*b" ],
220
+ [ "quote((!a)*b);", "(!a) * b" ],
221
+ [ "quote(!a||b);", "!a || b" ],
222
+ [ "quote(!(a||b));", "!(a || b)" ],
223
+
224
+ [ "Dialect.redefine(`!, function(x, local accum) { accum = x, while x-- > 1 accum *= x, accum });", "!" ],
225
+ [ "-1!;", "-1" ],
226
+ [ "3*-10!+2;", "-10886398" ],
227
+ [ "100!;", "93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000" ],
228
+ [ "quote(3*-10!+2);>", "(+ (* 3 (- (! 10))) 2)" ],
229
+ [ "quote(100!);", "100!" ],
230
+ [ "quote(100!);>", "(! 100)" ],
231
+
232
+
233
+ //
234
+ // adjusters
235
+ //
236
+
237
+ [ "vv = 3;", "3" ],
238
+ [ "++vv;", "4" ],
239
+ [ "vv;", "4" ],
240
+ [ "vv++;", "4" ],
241
+ [ "vv;", "5" ],
242
+ [ "--vv;", "4" ],
243
+ [ "vv;", "4" ],
244
+ [ "vv--;", "4" ],
245
+ [ "vv;", "3" ],
246
+ [ "vv += 2;", "5" ],
247
+ [ "vv -= 2;", "3" ],
248
+ [ "vv *= 2;", "6" ],
249
+ [ "vv /= 2;", "3" ],
250
+
251
+ [ "oo = {a:3};", "{ a: 3 }" ],
252
+ [ "oo.a;", "3" ],
253
+ [ "++oo.a;", "4" ],
254
+ [ "oo.a;", "4" ],
255
+ [ "oo.a++;", "4" ],
256
+ [ "oo.a;", "5" ],
257
+ [ "--oo.a;", "4" ],
258
+ [ "oo.a;", "4" ],
259
+ [ "oo.a--;", "4" ],
260
+ [ "oo.a;", "3" ],
261
+ [ "oo.a += 2;", "5" ],
262
+ [ "oo.a -= 2;", "3" ],
263
+ [ "oo.a *= 2;", "6" ],
264
+ [ "oo.a /= 2;", "3" ],
265
+
266
+ [ "aa = [2,3];", "[2, 3]" ],
267
+ [ "++aa[1];", "4" ],
268
+ [ "aa[1];", "4" ],
269
+ [ "aa[1]++;", "4" ],
270
+ [ "aa[1];", "5" ],
271
+ [ "--aa[1];", "4" ],
272
+ [ "aa[1];", "4" ],
273
+ [ "aa[1]--;", "4" ],
274
+ [ "aa[1];", "3" ],
275
+ [ "aa[1] += 2;", "5" ],
276
+ [ "aa[1] -= 2;", "3" ],
277
+ [ "aa[1] *= 2;", "6" ],
278
+ [ "aa[1] /= 2;", "3" ],
279
+
280
+
281
+ //
282
+ // if else
283
+ //
284
+
285
+ [ "quote(function() {"
286
+ "if 2 {"
287
+ " if c == \"w\" 3 }});>", "(function lambda false ((identity 2) ((== c \"w\") 3)))" ],
288
+
289
+ [ "quote("
290
+ "try { 1 } catch {"
291
+ " if 2 {"
292
+ " if c == \"w\" 3}});>", "(catch (1) (((identity 2) ((== c \"w\") 3))) false)" ],
293
+
294
+ [ "quote(function() {"
295
+ "loop {"
296
+ " if 2 {"
297
+ " if c == \"w\" 3 else 4,"
298
+ " break }}});>", "(function lambda false (loop false (((identity 2) (((== c \"w\") 3) 4) (break)))))" ],
299
+
300
+ [ "quote("
301
+ "function() {"
302
+ " loop {"
303
+ " if 1 {"
304
+ " 2, if false"
305
+ " break"
306
+ " }, 3, break } });>", "(function lambda false (loop false (((identity 1) 2 ((identity false) (break)))) 3 (break)))" ],
307
+
308
+ [ "quote(function(){if 1 { 2, if 3 { if 4 5 } else 6 } else 7 });",
309
+ "function () {\n"
310
+ " if 1 {\n"
311
+ " 2\n"
312
+ " if 3 {\n"
313
+ " if 4\n"
314
+ " 5 }\n"
315
+ " else\n"
316
+ " 6 }\n"
317
+ " else\n"
318
+ " 7\n"
319
+ "}" ],
320
+
321
+ [ "quote(function(){if 1 { if 3 { if 4 5 } else 6 } else 7 });",
322
+ "function () {\n"
323
+ " if 1\n"
324
+ " if 3 {\n"
325
+ " if 4\n"
326
+ " 5 }\n"
327
+ " else\n"
328
+ " 6\n"
329
+ " else\n"
330
+ " 7\n"
331
+ "}" ],
332
+
333
+ [ "quote(cond(if 1 { if 2 3 else 4 }));>", "(cond ((identity 1) ((identity 2) 3) 4))" ],
334
+ [ "quote(try { 1 } catch { if 1 { if 2 3 else 4 } });>", "(catch (1) (((identity 1) ((identity 2) 3) 4)) false)" ],
335
+ [ "quote(try { 1 } catch { if 2 3 });>", "(catch (1) (((identity 2) 3)) false)" ],
336
+ [ "quote(try { 1 } catch { if 2 3, if 4 5 });>", "(catch (1) (((identity 2) 3) ((identity 4) 5)) false)" ],
337
+
338
+ [ "cond(if 1 2, if 3 4);", "2" ],
339
+ [ "cond(if false 2, if 3 4);", "4" ],
340
+ [ "quote(cond(if 1 2, if 3 4));>", "(cond ((identity 1) 2) ((identity 3) 4))" ],
341
+
342
+ [ "quote(cond(if 3==2 a++));>", "(cond ((== 3 2) (Lib::postadjust a + 1)))" ],
343
+ [ "quote(cond(if 3==2, ++a));>", "(cond ((== 3 2) (Lib::preadjust a + 1)))" ],
344
+ [ "quote(cond(if (3==2) a++));>", "(cond ((== 3 2) (Lib::postadjust a + 1)))" ],
345
+ [ "quote(cond(if (3==2) ++a));>", "(cond ((== 3 2) (Lib::preadjust a + 1)))" ],
346
+
347
+ [ "quote(cond(if a==b 9));>", "(cond ((== a b) 9))" ],
348
+ [ "quote(cond(if a==b, -9));>", "(cond ((== a b) -9))" ],
349
+ [ "quote(cond(if (a==b) 9));>", "(cond ((== a b) 9))" ],
350
+ [ "quote(cond(if (a==b) -9));>", "(cond ((== a b) -9))" ],
351
+
352
+ [ "quote(if a == b 3);>", "(cond ((== a b) 3))" ],
353
+ [ "quote(if a == b 3 else 4);>", "(cond ((== a b) 3) ((identity true) 4))" ],
354
+ [ "function() { if a == b 3 };>", "(function lambda false ((== a b) 3))" ],
355
+ [ "function() { if a == b 3 else 4 };>", "(function lambda false ((== a b) 3) 4)" ],
356
+ [ "function() { loop { if a == b a++ else break } };>",
357
+ "(function lambda false (loop false (((== a b) (Lib::postadjust a + 1)) (break))))" ],
358
+ [ "function() { loop { if a == b break else a++ } };>",
359
+ "(function lambda false (loop false (((== a b) (break)) (Lib::postadjust a + 1))))" ],
360
+ [ "function(x) { loop { x = (if a == b a++ else break) } };>",
361
+ "(function lambda (x) (loop false (= x (cond ((== a b) (Lib::postadjust a + 1)) ((identity true) (break))))))" ],
362
+ [ "function(x) { loop { x = (if a == b a++ else break), printline(x) } };>",
363
+ "(function lambda (x) (loop false (= x (cond ((== a b) (Lib::postadjust a + 1)) ((identity true) (break)))) (printline x)))" ],
364
+
365
+
366
+ //
367
+ // while
368
+ //
369
+
370
+ [ "x=0; while (x < 10) { print(x, space), x=x+1 };", "0 1 2 3 4 5 6 7 8 9|0|true" ],
371
+ [ "function(x) { x=0, while x < 10 { print(x++, space) } }();", "0 1 2 3 4 5 6 7 8 9|true" ],
372
+
373
+ [ "quote(while 3==2 a++);>", "(while false ((not (== 3 2))) (Lib::postadjust a + 1))" ],
374
+ [ "quote(while 3==2, ++a);>", "(while false ((not (== 3 2))) (Lib::preadjust a + 1))" ],
375
+ [ "quote(while (3==2) a++);>", "(while false ((not (== 3 2))) (Lib::postadjust a + 1))" ],
376
+ [ "quote(while (3==2) ++a);>", "(while false ((not (== 3 2))) (Lib::preadjust a + 1))" ],
377
+
378
+ [ "quote(while a==b 9);>", "(while false ((not (== a b))) 9)" ],
379
+ [ "quote(while a==b, -9);>", "(while false ((not (== a b))) -9)" ],
380
+ [ "quote(while (a==b) 9);>", "(while false ((not (== a b))) 9)" ],
381
+ [ "quote(while (a==b) -9);>", "(while false ((not (== a b))) -9)" ],
382
+
383
+ //
384
+ // for
385
+ //
386
+
387
+ [ "for x in `(a b c) print(x);>", "abc|Dictionary{8}" ],
388
+ [ "function() { loop { if x > 3 break, 4 } };>", "(function lambda false (loop false ((> x 3)) 4))" ],
389
+ [ "function () { for xx in [a,b,c] { if true { if xx eq 3, break }, print(xx) } }();>", "abc|Dictionary{7}" ],
390
+ [ "function (x) { loop try { 1, if x continue, 2, break } catch { 3 } }();", "2" ],
391
+
392
+ [ "miter=iterate(`(a,b,c), `x);", "{\n"
393
+ " target : (a, b, c),\n"
394
+ " final : final_value,\n"
395
+ " traverse: (a, b, c),\n"
396
+ " index : -1,\n"
397
+ " last : 2,\n"
398
+ " next : tuple_next_value }" ],
399
+ [ "miter.next(miter);miter.value;miter.next(miter);miter.value;miter.next(miter);miter.value;miter.next(miter);",
400
+ "false|a|false|b|false|c|true" ],
401
+ [ "quote(for x in `(a b c) print(x));>",
402
+ "(for (let lambda (iter) "
403
+ "(= iter (iterate (`` (a b c)) (`` x))) "
404
+ "(loop false ((`. iter \"next\" (iter)) (`. iter \"final\" (iter))) "
405
+ "(= x (`. iter \"value\")) "
406
+ "(print x))))" ],
407
+ [ "for x in `(a b c) print(x);>", "abc|Dictionary{8}" ],
408
+ [ "quote(function () { for xx in [a,b,c] { if true { if xx eq 3, break }, print(xx) } });>",
409
+ "(function lambda false (for (let lambda (iter) "
410
+ "(= iter (iterate Array[3] (`` xx))) "
411
+ "(loop false ((`. iter \"next\" (iter)) (`. iter \"final\" (iter))) "
412
+ "(= xx (`. iter \"value\")) "
413
+ "(((identity true) ((eq xx 3) (break)))) "
414
+ "(print xx)))))" ],
415
+ [ "function () { for xx in [a,b,c] { if true { if xx eq 3, break }, print(xx) } }();>",
416
+ "abc|Dictionary{7}" ],
417
+ [ "quote(for `(v,i) in `(a b c) print(v,i));>",
418
+ "(for (let lambda (iter) "
419
+ "(= iter (iterate (`` (a b c)) (`` (v i)))) "
420
+ "(loop false ((`. iter \"next\" (iter)) (`. iter \"final\" (iter))) "
421
+ "(= (v i) (`. iter \"value\")) "
422
+ "(print v i))))" ],
423
+ [ "for `(v,i) in `(a b c) print(v,i,\"-\");>", "a0-b1-c2-|Dictionary{8}" ],
424
+ [ "for `(v,i) in [a, b, c] print(v,i,\"-\");>", "a0-b1-c2-|Dictionary{7}" ],
425
+ [ "for `(k,v,i) in {a:3,b:4,c:5 } print(k,v,i,\"-\");>", "a30-b41-c52-|Dictionary{8}" ],
426
+ [ "for `kk in {a:3,b:4,c:5 } print(kk);>", "abc|Dictionary{8}" ],
427
+ [ "function (local xx) { for xx in [a,b,c] print(xx), for xx in `(d,e,f) print(xx) }();>",
428
+ "abcdef|Dictionary{8}" ],
429
+ [ "for x in xnew({a:3,b:4,g:6}) print(x);>", "abg|Dictionary{8}"],
430
+ [ "for 3 in `(a, b, c) print(x);>",
431
+ { errors: "invalid iteration variable at (1, 5) found 3" } ],
432
+ [ "for x in xnew() print(x);>", "Dictionary{6}"],
433
+ [ "for x in Array(e, f, g) print(x);>", "efg|Dictionary{7}"],
434
+ [ "for x in false print(x);>", "Dictionary{5}"],
435
+ [ "for x in { } print(x);>", "Dictionary{7}"],
436
+
437
+ //
438
+ // procedures
439
+ //
440
+
441
+ [ "function() { function p(f) { call(f) }, p(function() { print(\"hi\") }) }();", "hi|\"hi\"" ],
442
+ [ "closure() { function p(f) { call(f) }, p(function() { print(\"hi\") }) }();", "hi|\"hi\"" ],
443
+ [ "function () { function p(f) { print(call(f,0)) }, p(function(x) { x-1}), p(function(x) {x+1}) }();", "-11|1" ],
444
+ [ "closure () { closure p(f) { print(call(f,0)) }, p(function(x) { x-1}), p(function(x) {x+1}) }();", "-11|1" ],
445
+
446
+ [ "closure(){ function(local id) { id = 3, print([id][0]) }()}();", "3|3" ],
447
+ [ "closure(){ function(local id) { id = 5, print({id:id}.id) }()}();", "5|5" ],
448
+
449
+ [ "function x() { function() {} () };", "x" ],
450
+
451
+ [ "let (joe) { joe } (5);", "5" ],
452
+ [ "let namelet(joe) { joe };>", "(let namelet (joe) joe)" ],
453
+ [ "namelet(7);", "(namelet, 7)" ],
454
+
455
+ [ "function(){function jim(){ print(\"1\"),function jim(){print(\"2\")}, jim()}, jim()}();", "12|\"2\"" ],
456
+ [ "closure(){function jim(){ print(\"1\"),function jim(){print(\"2\")}, jim()}, jim()}();", "12|\"2\"" ],
457
+ [ "function(){function jim(){print(\"1\")},function jim(){print(\"2\")}, jim()}();",
458
+ { errors: "exception: internal,duplicate procedure name jim in lambda" } ],
459
+ [ "closure(){function jim(){print(\"1\")},function jim(){print(\"2\")}, jim()}();",
460
+ { errors: "exception: internal,duplicate procedure name jim in lambda" } ],
461
+ [ "function(){function jim(){print(\"1\")}(),function jim(){print(\"2\")}, jim()}();",
462
+ { errors: "exception: internal,duplicate procedure name jim in lambda" } ],
463
+
464
+ [ "function(){{spawn:function(){[{ok:true}]}}};", "function () {\n"
465
+ " {\n"
466
+ " spawn: function () {\n"
467
+ " [\n"
468
+ " { ok: true }]\n"
469
+ " }\n"
470
+ " }\n"
471
+ "}" ],
472
+
473
+ // dynamic vs. lexical binding
474
+
475
+ [ "function& aaa(f) { ccc() };", "aaa" ],
476
+ [ "function bbb(f) { ccc() };", "bbb" ],
477
+ [ "function ccc() { f };", "ccc" ],
478
+ [ "aaa(3);", "3" ],
479
+ [ "bbb(3);", "f" ],
480
+
481
+ [ "function& ddd(f) { print(f), function iii(f) { print(f), ccc() }(5) } (2);", "25|2" ],
482
+ [ "function eee(f) { print(f), function iii(f) { print(f), ccc() }(7) } (4);", "47|f" ],
483
+ [ "function fff(f) { print(f), function& iii(f) { print(f), ccc() }(9) } (6);", "69|f" ],
484
+
485
+ [ "function (f, local jjj) { print(f), function jjj(f) { print(f), ccc() }, jjj(21) } (22);", "2221|f" ],
486
+ [ "function& (f, local jjj) { print(f), function jjj(f) { print(f), ccc() }, jjj(23) } (24);", "2423|24" ],
487
+
488
+ [ "function (g, local f) { f = 17, function f(g) { print(f, g), ccc() }, f(25) } (26);", "1725|f" ],
489
+ [ "function& (g, local f) { f = 19, function f(g) { print(f, g), ccc() }, f(27) } (28);", "1927|f" ],
490
+ [ "function& (g) { f = 21, function f(g) { print(f, g), ccc() }, f(29) } (30);", "2129|f" ],
491
+ [ "function& (g, local f) { f = 23, function ff(g) { print(f, g), ccc() }, ff(29) } (30);", "2329|23" ],
492
+
493
+ [ "function& (local f) { f = 3, function a(){++f}, function b(){++f}, a(), b(), ccc() } ();", "5" ],
494
+ [ "function (local f) { f = 7, function a(){++f}, function b(){++f}, a(), b(), ccc() } ();", "f" ],
495
+
496
+ [ "function (local hh) { function& in1() { hh }, function& in2(local hh) { hh = 55, in1() }() } ();", "55" ],
497
+
498
+ [ "function ttt() { print(f) };", "ttt" ],
499
+ [ "let(f) { f = 11, ttt() } ();", "f|f" ],
500
+ [ "let&(f) { f = 13, ttt() } ();", "13|13" ],
501
+
502
+
503
+ //
504
+ // return/break/continue (sometimes with try/catch/finally)
505
+ //
506
+
507
+ [ "function() { try { print(\"a\"), return(22) } catch { if 1 print(\"b\") } finally { print(\"c\") }, print(\"d\") }();",
508
+ "ac|22" ],
509
+ [ "function() { try { print(\"a\") } catch { if 1 print(\"b\") } finally { print(\"c\"), return(44) }, print(\"d\") }();",
510
+ "ac|44" ],
511
+
512
+ [ "function() { try { print(\"a\"),throw(\"x\") } catch { if 1 {print(\"b\")} } finally { print(\"c\") }, print(\"d\") }();",
513
+ "abcd|\"d\"" ],
514
+ [ "function() { try { print(\"a\"),throw(\"x\") } catch { if 1 {print(\"b\"),return(33)} } finally { print(\"c\") }, print(\"d\") }();",
515
+ "abc|33" ],
516
+
517
+ [ "function() { try { function() { try { print(\"a\"), throw(\"b\") } finally { print(\"c\") } }() } finally { print(\"d\") }}();",
518
+ { errors: "exception: b", text: "acd" } ],
519
+ [ "function() { try { function() { try { print(\"a\"), throw(\"b\") } finally { return(\"c\") } }() } finally { print(\"d\") }}();",
520
+ "ad|\"c\"" ],
521
+
522
+ [ "function() { loop { print(\"a\"), break, print(\"b\") }, print(\"c\") }();",
523
+ "ac|\"c\"" ],
524
+
525
+ [ "function(x) {x=0, loop {if ++x>5 break,print(x),if x==5 continue,print(\"-\")}, print(\"|\")}();'",
526
+ "1-2-3-4-5||\"|\"" ],
527
+ [ "function(x) {x=0, loop :outer { loop :inner {if ++x>5 break :inner,print(x),if x==5 continue,print(\"-\")}, print(\">\"), break}, print(\"|\")}();",
528
+ "1-2-3-4-5>||\"|\"" ],
529
+ [ "function(x) {x=0, loop :outer { loop :inner {if ++x>5 break :outer,print(x),if x==5 continue,print(\"-\")}, print(\">\"), break}, print(\"|\")}();'",
530
+ "1-2-3-4-5||\"|\"" ],
531
+ [ "function(x) {x=0, loop :outer { loop :inner {if ++x>5 break,print(x),if x==5 continue :outer ,print(\"-\")}, print(\">\"), break}, print(\"|\")}();'",
532
+ "1-2-3-4-5>||\"|\"" ],
533
+
534
+ [ "function(local x) { for x in [1,2,3] { print(x), if x == 3 return(4) }, print(\"0\") }();",
535
+ "123|4" ],
536
+
537
+ [ "function(local x) { loop :outer { for x in [1,2,3] { print(x), if x == 3 break :outer }, print(\"0\") }, return(4) }();",
538
+ "123|4" ],
539
+
540
+ [ "function(local x) { for :outer x in [1,2,3] loop { print(x), continue :outer, print(\"0\") }, return(4) }();",
541
+ "123|4" ],
542
+
543
+ [ "function(local x) { x = [3,2,1], while :outer x.length > 0 loop { print(x.pop()), continue :outer, print(\"0\") }, return(4) }();",
544
+ "123|4" ],
545
+
546
+ [ "function() { loop { try { print(1), break } catch { if true print(2) }, print(3) }, print(4) }();", "14|4" ],
547
+ [ "function(local x) { x = 0, loop { try { print(1), if x++ < 3 continue } catch { if true print(2) }, print(3), break }, print(4) }();", "111134|4" ],
548
+
549
+ [ "function(){let(){print(\"let\"),return}(), print(\"func\")}();;", "let" ], // nospread
550
+ [ "function(){let(a){print(\"let\"),return}(), print(\"func\")}();;", "let" ], // spread
551
+
552
+ //
553
+ // unparsing
554
+ //
555
+
556
+ [ "function&(a) { `(b, 33) };>", "(function\\& lambda (a) (`` (b 33)))" ],
557
+ [ "function&(a) { `(b, 33) };", "function& (a) {\n"
558
+ " `(b, 33)\n"
559
+ "}" ],
560
+
561
+ [ "let&(a) { `(b, 33) };>", "(let\\& lambda (a) (`` (b 33)))" ],
562
+ [ "let&(a) { `(b, 33) };", "let& (a) {\n"
563
+ " `(b, 33)\n"
564
+ "}" ],
565
+
566
+ [ "function (a) { if 1 { print(1) } };", "function (a) {\n"
567
+ " if 1\n"
568
+ " print(1)\n"
569
+ "}" ],
570
+
571
+ [ "function (a) { if 2 { print(1), print(2) } };", "function (a) {\n"
572
+ " if 2 {\n"
573
+ " print(1)\n"
574
+ " print(2) }\n"
575
+ "}" ],
576
+
577
+ [ "function (a) { if 3 { print(1), print(2), print(3) } };", "function (a) {\n"
578
+ " if 3 {\n"
579
+ " print(1)\n"
580
+ " print(2)\n"
581
+ " print(3) }\n"
582
+ "}" ],
583
+
584
+ //
585
+ // primitive method hooks
586
+ //
587
+
588
+ [ "sudo(tuple@tmember=function tuplemember (x, y) { member(y,x) });>", "tuplemember" ],
589
+ [ "`(a,b,c).tmember(b);", "(b, c)" ],
590
+ [ "`(a,b,c).tmember(d);", "false" ],
591
+ [ "`(3,4,5).tmember(2+2);", "(4, 5)" ], // must evaluate argument
592
+ [ "`(3,4,5).tmember(function(){print(`+),4}());", "+|(4, 5)" ], // but only once
593
+ [ "`(print,3,4).tmember(print);", "print(3, 4)" ], // and don't eval the target
594
+
595
+ [ "sudo(array@test=function arraytest args { apply(printline, args) });", "arraytest" ],
596
+ [ "[1,2,3].test;", "Array[3]|[1, 2, 3]" ],
597
+ [ "[1,2,3].test(4);", "Array[3]4|4" ],
598
+
599
+ //
600
+ // object unparsing
601
+ //
602
+
603
+ [ "closure myob(initv, local myob) {\n"
604
+ " myob = new(object)\n"
605
+ " myob.value = initv\n"
606
+ " myob.\\.tostring = function \\.tostring(obj) {\n"
607
+ " \"myob-\".concat(myob.value) }\n"
608
+ " myob };",
609
+ "myob" ],
610
+ [ "myob(3);>", "Object{2}" ],
611
+ [ "myob(3);", "myob-3" ],
612
+
613
+ //
614
+ // dialects
615
+ //
616
+
617
+ [ "dt = Dialect.derive('test');", "Object{22}" ],
618
+ [ "dt.redefine(`^, function(x,y,local z) {z=1,while y-- > 0 z *= x,z});", "^" ],
619
+ [ "$$ = dt.parse(new(textstream, '2^9;'));", "(false, 2^9)" ],
620
+ [ "eval($$);", "(false, 512)" ],
621
+ [ "dt.destroy();", "true" ],
622
+ [ "dt.destroy();", "false" ],
623
+ ]);