-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcandran.lua
7347 lines (7347 loc) · 398 KB
/
candran.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local candran = { ["VERSION"] = "1.0.0" } -- candran.can:2
package["loaded"]["candran"] = candran -- candran.can:4
local function _() -- candran.can:7
local candran = require("candran") -- ./candran/util.can:1
local util = {} -- ./candran/util.can:2
util["search"] = function(modpath, exts) -- ./candran/util.can:4
if exts == nil then exts = {} end -- ./candran/util.can:4
for _, ext in ipairs(exts) do -- ./candran/util.can:5
for path in package["path"]:gmatch("[^;]+") do -- ./candran/util.can:6
local fpath = path:gsub("%.lua", "." .. ext):gsub("%?", (modpath:gsub("%.", "/"))) -- ./candran/util.can:7
local f = io["open"](fpath) -- ./candran/util.can:8
if f then -- ./candran/util.can:9
f:close() -- ./candran/util.can:10
return fpath -- ./candran/util.can:11
end -- ./candran/util.can:11
end -- ./candran/util.can:11
end -- ./candran/util.can:11
end -- ./candran/util.can:11
util["load"] = function(str, name, env) -- ./candran/util.can:17
if _VERSION == "Lua 5.1" then -- ./candran/util.can:18
local fn, err = loadstring(str, name) -- ./candran/util.can:19
if not fn then -- ./candran/util.can:20
return fn, err -- ./candran/util.can:20
end -- ./candran/util.can:20
return env ~= nil and setfenv(fn, env) or fn -- ./candran/util.can:21
else -- ./candran/util.can:21
if env then -- ./candran/util.can:23
return load(str, name, nil, env) -- ./candran/util.can:24
else -- ./candran/util.can:24
return load(str, name) -- ./candran/util.can:26
end -- ./candran/util.can:26
end -- ./candran/util.can:26
end -- ./candran/util.can:26
util["recmerge"] = function(...) -- ./candran/util.can:31
local r = {} -- ./candran/util.can:32
for _, t in ipairs({ ... }) do -- ./candran/util.can:33
for k, v in pairs(t) do -- ./candran/util.can:34
if type(v) == "table" then -- ./candran/util.can:35
r[k] = util["merge"](v, r[k]) -- ./candran/util.can:36
else -- ./candran/util.can:36
r[k] = v -- ./candran/util.can:38
end -- ./candran/util.can:38
end -- ./candran/util.can:38
end -- ./candran/util.can:38
return r -- ./candran/util.can:42
end -- ./candran/util.can:42
util["merge"] = function(...) -- ./candran/util.can:45
local r = {} -- ./candran/util.can:46
for _, t in ipairs({ ... }) do -- ./candran/util.can:47
for k, v in pairs(t) do -- ./candran/util.can:48
r[k] = v -- ./candran/util.can:49
end -- ./candran/util.can:49
end -- ./candran/util.can:49
return r -- ./candran/util.can:52
end -- ./candran/util.can:52
util["cli"] = { -- ./candran/util.can:55
["addCandranOptions"] = function(parser) -- ./candran/util.can:57
parser:group("Compiler options", parser:option("-t --target"):description("Target Lua version: lua54, lua53, lua52, luajit or lua51"):default(candran["default"]["target"]), parser:option("--indentation"):description("Character(s) used for indentation in the compiled file"):default(candran["default"]["indentation"]), parser:option("--newline"):description("Character(s) used for newlines in the compiled file"):default(candran["default"]["newline"]), parser:option("--variable-prefix"):description("Prefix used when Candran needs to set a local variable to provide some functionality"):default(candran["default"]["variablePrefix"]), parser:flag("--no-map-lines"):description("Do not add comments at the end of each line indicating the associated source line and file (error rewriting will not work)")) -- ./candran/util.can:76
parser:group("Preprocessor options", parser:flag("--no-builtin-macros"):description("Disable built-in macros"), parser:option("-D --define"):description("Define a preprocessor constant"):args("1-2"):argname({ -- ./candran/util.can:86
"name", -- ./candran/util.can:86
"value" -- ./candran/util.can:86
}):count("*"), parser:option("-I --import"):description("Statically import a module into the compiled file"):argname("module"):count("*")) -- ./candran/util.can:92
parser:option("--chunkname"):description("Chunkname used when running the code") -- ./candran/util.can:96
parser:flag("--no-rewrite-errors"):description("Disable error rewriting when running the code") -- ./candran/util.can:99
end, -- ./candran/util.can:99
["makeCandranOptions"] = function(args) -- ./candran/util.can:103
local preprocessorEnv = {} -- ./candran/util.can:104
for _, o in ipairs(args["define"]) do -- ./candran/util.can:105
preprocessorEnv[o[1]] = tonumber(o[2]) or o[2] or true -- ./candran/util.can:106
end -- ./candran/util.can:106
local options = { -- ./candran/util.can:109
["target"] = args["target"], -- ./candran/util.can:110
["indentation"] = args["indentation"], -- ./candran/util.can:111
["newline"] = args["newline"], -- ./candran/util.can:112
["variablePrefix"] = args["variable_prefix"], -- ./candran/util.can:113
["mapLines"] = not args["no_map_lines"], -- ./candran/util.can:114
["chunkname"] = args["chunkname"], -- ./candran/util.can:115
["rewriteErrors"] = not args["no_rewrite_errors"], -- ./candran/util.can:116
["builtInMacros"] = not args["no_builtin_macros"], -- ./candran/util.can:117
["preprocessorEnv"] = preprocessorEnv, -- ./candran/util.can:118
["import"] = args["import"] -- ./candran/util.can:119
} -- ./candran/util.can:119
return options -- ./candran/util.can:121
end -- ./candran/util.can:121
} -- ./candran/util.can:121
return util -- ./candran/util.can:125
end -- ./candran/util.can:125
local util = _() or util -- ./candran/util.can:129
package["loaded"]["candran.util"] = util or true -- ./candran/util.can:130
local function _() -- ./candran/util.can:133
local n, v = "serpent", "0.302" -- ./candran/serpent.lua:24
local c, d = "Paul Kulchenko", "Lua serializer and pretty printer" -- ./candran/serpent.lua:25
local snum = { -- ./candran/serpent.lua:26
[tostring(1 / 0)] = "1/0 --[[math.huge]]", -- ./candran/serpent.lua:26
[tostring(- 1 / 0)] = "-1/0 --[[-math.huge]]", -- ./candran/serpent.lua:26
[tostring(0 / 0)] = "0/0" -- ./candran/serpent.lua:26
} -- ./candran/serpent.lua:26
local badtype = { -- ./candran/serpent.lua:27
["thread"] = true, -- ./candran/serpent.lua:27
["userdata"] = true, -- ./candran/serpent.lua:27
["cdata"] = true -- ./candran/serpent.lua:27
} -- ./candran/serpent.lua:27
local getmetatable = debug and debug["getmetatable"] or getmetatable -- ./candran/serpent.lua:28
local pairs = function(t) -- ./candran/serpent.lua:29
return next, t -- ./candran/serpent.lua:29
end -- ./candran/serpent.lua:29
local keyword, globals, G = {}, {}, (_G or _ENV) -- ./candran/serpent.lua:30
for _, k in ipairs({ -- ./candran/serpent.lua:31
"and", -- ./candran/serpent.lua:31
"break", -- ./candran/serpent.lua:31
"do", -- ./candran/serpent.lua:31
"else", -- ./candran/serpent.lua:31
"elseif", -- ./candran/serpent.lua:31
"end", -- ./candran/serpent.lua:31
"false", -- ./candran/serpent.lua:31
"for", -- ./candran/serpent.lua:32
"function", -- ./candran/serpent.lua:32
"goto", -- ./candran/serpent.lua:32
"if", -- ./candran/serpent.lua:32
"in", -- ./candran/serpent.lua:32
"local", -- ./candran/serpent.lua:32
"nil", -- ./candran/serpent.lua:32
"not", -- ./candran/serpent.lua:32
"or", -- ./candran/serpent.lua:32
"repeat", -- ./candran/serpent.lua:32
"return", -- ./candran/serpent.lua:33
"then", -- ./candran/serpent.lua:33
"true", -- ./candran/serpent.lua:33
"until", -- ./candran/serpent.lua:33
"while" -- ./candran/serpent.lua:33
}) do -- ./candran/serpent.lua:33
keyword[k] = true -- ./candran/serpent.lua:33
end -- ./candran/serpent.lua:33
for k, v in pairs(G) do -- ./candran/serpent.lua:34
globals[v] = k -- ./candran/serpent.lua:34
end -- ./candran/serpent.lua:34
for _, g in ipairs({ -- ./candran/serpent.lua:35
"coroutine", -- ./candran/serpent.lua:35
"debug", -- ./candran/serpent.lua:35
"io", -- ./candran/serpent.lua:35
"math", -- ./candran/serpent.lua:35
"string", -- ./candran/serpent.lua:35
"table", -- ./candran/serpent.lua:35
"os" -- ./candran/serpent.lua:35
}) do -- ./candran/serpent.lua:35
for k, v in pairs(type(G[g]) == "table" and G[g] or {}) do -- ./candran/serpent.lua:36
globals[v] = g .. "." .. k -- ./candran/serpent.lua:36
end -- ./candran/serpent.lua:36
end -- ./candran/serpent.lua:36
local function s(t, opts) -- ./candran/serpent.lua:38
local name, indent, fatal, maxnum = opts["name"], opts["indent"], opts["fatal"], opts["maxnum"] -- ./candran/serpent.lua:39
local sparse, custom, huge = opts["sparse"], opts["custom"], not opts["nohuge"] -- ./candran/serpent.lua:40
local space, maxl = (opts["compact"] and "" or " "), (opts["maxlevel"] or math["huge"]) -- ./candran/serpent.lua:41
local maxlen, metatostring = tonumber(opts["maxlength"]), opts["metatostring"] -- ./candran/serpent.lua:42
local iname, comm = "_" .. (name or ""), opts["comment"] and (tonumber(opts["comment"]) or math["huge"]) -- ./candran/serpent.lua:43
local numformat = opts["numformat"] or "%.17g" -- ./candran/serpent.lua:44
local seen, sref, syms, symn = {}, { "local " .. iname .. "={}" }, {}, 0 -- ./candran/serpent.lua:45
local function gensym(val) -- ./candran/serpent.lua:46
return "_" .. (tostring(tostring(val)):gsub("[^%w]", ""):gsub("(%d%w+)", function(s) -- ./candran/serpent.lua:48
if not syms[s] then -- ./candran/serpent.lua:48
symn = symn + 1 -- ./candran/serpent.lua:48
syms[s] = symn -- ./candran/serpent.lua:48
end -- ./candran/serpent.lua:48
return tostring(syms[s]) -- ./candran/serpent.lua:48
end)) -- ./candran/serpent.lua:48
end -- ./candran/serpent.lua:48
local function safestr(s) -- ./candran/serpent.lua:49
return type(s) == "number" and tostring(huge and snum[tostring(s)] or numformat:format(s)) or type(s) ~= "string" and tostring(s) or ("%q"):format(s):gsub("\
", "n"):gsub("\26", "\\026") -- ./candran/serpent.lua:51
end -- ./candran/serpent.lua:51
local function comment(s, l) -- ./candran/serpent.lua:52
return comm and (l or 0) < comm and " --[[" .. select(2, pcall(tostring, s)) .. "]]" or "" -- ./candran/serpent.lua:52
end -- ./candran/serpent.lua:52
local function globerr(s, l) -- ./candran/serpent.lua:53
return globals[s] and globals[s] .. comment(s, l) or not fatal and safestr(select(2, pcall(tostring, s))) or error("Can't serialize " .. tostring(s)) -- ./candran/serpent.lua:54
end -- ./candran/serpent.lua:54
local function safename(path, name) -- ./candran/serpent.lua:55
local n = name == nil and "" or name -- ./candran/serpent.lua:56
local plain = type(n) == "string" and n:match("^[%l%u_][%w_]*$") and not keyword[n] -- ./candran/serpent.lua:57
local safe = plain and n or "[" .. safestr(n) .. "]" -- ./candran/serpent.lua:58
return (path or "") .. (plain and path and "." or "") .. safe, safe -- ./candran/serpent.lua:59
end -- ./candran/serpent.lua:59
local alphanumsort = type(opts["sortkeys"]) == "function" and opts["sortkeys"] or function(k, o, n) -- ./candran/serpent.lua:60
local maxn, to = tonumber(n) or 12, { -- ./candran/serpent.lua:61
["number"] = "a", -- ./candran/serpent.lua:61
["string"] = "b" -- ./candran/serpent.lua:61
} -- ./candran/serpent.lua:61
local function padnum(d) -- ./candran/serpent.lua:62
return ("%0" .. tostring(maxn) .. "d"):format(tonumber(d)) -- ./candran/serpent.lua:62
end -- ./candran/serpent.lua:62
table["sort"](k, function(a, b) -- ./candran/serpent.lua:63
return (k[a] ~= nil and 0 or to[type(a)] or "z") .. (tostring(a):gsub("%d+", padnum)) < (k[b] ~= nil and 0 or to[type(b)] or "z") .. (tostring(b):gsub("%d+", padnum)) -- ./candran/serpent.lua:66
end) -- ./candran/serpent.lua:66
end -- ./candran/serpent.lua:66
local function val2str(t, name, indent, insref, path, plainindex, level) -- ./candran/serpent.lua:67
local ttype, level, mt = type(t), (level or 0), getmetatable(t) -- ./candran/serpent.lua:68
local spath, sname = safename(path, name) -- ./candran/serpent.lua:69
local tag = plainindex and ((type(name) == "number") and "" or name .. space .. "=" .. space) or (name ~= nil and sname .. space .. "=" .. space or "") -- ./candran/serpent.lua:72
if seen[t] then -- ./candran/serpent.lua:73
sref[# sref + 1] = spath .. space .. "=" .. space .. seen[t] -- ./candran/serpent.lua:74
return tag .. "nil" .. comment("ref", level) -- ./candran/serpent.lua:75
end -- ./candran/serpent.lua:75
if type(mt) == "table" and metatostring ~= false then -- ./candran/serpent.lua:77
local to, tr = pcall(function() -- ./candran/serpent.lua:78
return mt["__tostring"](t) -- ./candran/serpent.lua:78
end) -- ./candran/serpent.lua:78
local so, sr = pcall(function() -- ./candran/serpent.lua:79
return mt["__serialize"](t) -- ./candran/serpent.lua:79
end) -- ./candran/serpent.lua:79
if (to or so) then -- ./candran/serpent.lua:80
seen[t] = insref or spath -- ./candran/serpent.lua:81
t = so and sr or tr -- ./candran/serpent.lua:82
ttype = type(t) -- ./candran/serpent.lua:83
end -- ./candran/serpent.lua:83
end -- ./candran/serpent.lua:83
if ttype == "table" then -- ./candran/serpent.lua:86
if level >= maxl then -- ./candran/serpent.lua:87
return tag .. "{}" .. comment("maxlvl", level) -- ./candran/serpent.lua:87
end -- ./candran/serpent.lua:87
seen[t] = insref or spath -- ./candran/serpent.lua:88
if next(t) == nil then -- ./candran/serpent.lua:89
return tag .. "{}" .. comment(t, level) -- ./candran/serpent.lua:89
end -- ./candran/serpent.lua:89
if maxlen and maxlen < 0 then -- ./candran/serpent.lua:90
return tag .. "{}" .. comment("maxlen", level) -- ./candran/serpent.lua:90
end -- ./candran/serpent.lua:90
local maxn, o, out = math["min"](# t, maxnum or # t), {}, {} -- ./candran/serpent.lua:91
for key = 1, maxn do -- ./candran/serpent.lua:92
o[key] = key -- ./candran/serpent.lua:92
end -- ./candran/serpent.lua:92
if not maxnum or # o < maxnum then -- ./candran/serpent.lua:93
local n = # o -- ./candran/serpent.lua:94
for key in pairs(t) do -- ./candran/serpent.lua:95
if o[key] ~= key then -- ./candran/serpent.lua:95
n = n + 1 -- ./candran/serpent.lua:95
o[n] = key -- ./candran/serpent.lua:95
end -- ./candran/serpent.lua:95
end -- ./candran/serpent.lua:95
end -- ./candran/serpent.lua:95
if maxnum and # o > maxnum then -- ./candran/serpent.lua:96
o[maxnum + 1] = nil -- ./candran/serpent.lua:96
end -- ./candran/serpent.lua:96
if opts["sortkeys"] and # o > maxn then -- ./candran/serpent.lua:97
alphanumsort(o, t, opts["sortkeys"]) -- ./candran/serpent.lua:97
end -- ./candran/serpent.lua:97
local sparse = sparse and # o > maxn -- ./candran/serpent.lua:98
for n, key in ipairs(o) do -- ./candran/serpent.lua:99
local value, ktype, plainindex = t[key], type(key), n <= maxn and not sparse -- ./candran/serpent.lua:100
if opts["valignore"] and opts["valignore"][value] or opts["keyallow"] and not opts["keyallow"][key] or opts["keyignore"] and opts["keyignore"][key] or opts["valtypeignore"] and opts["valtypeignore"][type(value)] or sparse and value == nil then -- ./candran/serpent.lua:105
-- ./candran/serpent.lua:106
elseif ktype == "table" or ktype == "function" or badtype[ktype] then -- ./candran/serpent.lua:106
if not seen[key] and not globals[key] then -- ./candran/serpent.lua:107
sref[# sref + 1] = "placeholder" -- ./candran/serpent.lua:108
local sname = safename(iname, gensym(key)) -- ./candran/serpent.lua:109
sref[# sref] = val2str(key, sname, indent, sname, iname, true) -- ./candran/serpent.lua:110
end -- ./candran/serpent.lua:110
sref[# sref + 1] = "placeholder" -- ./candran/serpent.lua:111
local path = seen[t] .. "[" .. tostring(seen[key] or globals[key] or gensym(key)) .. "]" -- ./candran/serpent.lua:112
sref[# sref] = path .. space .. "=" .. space .. tostring(seen[value] or val2str(value, nil, indent, path)) -- ./candran/serpent.lua:113
else -- ./candran/serpent.lua:113
out[# out + 1] = val2str(value, key, indent, nil, seen[t], plainindex, level + 1) -- ./candran/serpent.lua:115
if maxlen then -- ./candran/serpent.lua:116
maxlen = maxlen - # out[# out] -- ./candran/serpent.lua:117
if maxlen < 0 then -- ./candran/serpent.lua:118
break -- ./candran/serpent.lua:118
end -- ./candran/serpent.lua:118
end -- ./candran/serpent.lua:118
end -- ./candran/serpent.lua:118
end -- ./candran/serpent.lua:118
local prefix = string["rep"](indent or "", level) -- ./candran/serpent.lua:122
local head = indent and "{\
" .. prefix .. indent or "{" -- ./candran/serpent.lua:123
local body = table["concat"](out, "," .. (indent and "\
" .. prefix .. indent or space)) -- ./candran/serpent.lua:124
local tail = indent and "\
" .. prefix .. "}" or "}" -- ./candran/serpent.lua:125
return (custom and custom(tag, head, body, tail, level) or tag .. head .. body .. tail) .. comment(t, level) -- ./candran/serpent.lua:126
elseif badtype[ttype] then -- ./candran/serpent.lua:127
seen[t] = insref or spath -- ./candran/serpent.lua:128
return tag .. globerr(t, level) -- ./candran/serpent.lua:129
elseif ttype == "function" then -- ./candran/serpent.lua:130
seen[t] = insref or spath -- ./candran/serpent.lua:131
if opts["nocode"] then -- ./candran/serpent.lua:132
return tag .. "function() --[[..skipped..]] end" .. comment(t, level) -- ./candran/serpent.lua:132
end -- ./candran/serpent.lua:132
local ok, res = pcall(string["dump"], t) -- ./candran/serpent.lua:133
local func = ok and "((loadstring or load)(" .. safestr(res) .. ",'@serialized'))" .. comment(t, level) -- ./candran/serpent.lua:134
return tag .. (func or globerr(t, level)) -- ./candran/serpent.lua:135
else -- ./candran/serpent.lua:135
return tag .. safestr(t) -- ./candran/serpent.lua:136
end -- ./candran/serpent.lua:136
end -- ./candran/serpent.lua:136
local sepr = indent and "\
" or ";" .. space -- ./candran/serpent.lua:138
local body = val2str(t, name, indent) -- ./candran/serpent.lua:139
local tail = # sref > 1 and table["concat"](sref, sepr) .. sepr or "" -- ./candran/serpent.lua:140
local warn = opts["comment"] and # sref > 1 and space .. "--[[incomplete output with shared/self-references skipped]]" or "" -- ./candran/serpent.lua:141
return not name and body .. warn or "do local " .. body .. sepr .. tail .. "return " .. name .. sepr .. "end" -- ./candran/serpent.lua:142
end -- ./candran/serpent.lua:142
local function deserialize(data, opts) -- ./candran/serpent.lua:145
local env = (opts and opts["safe"] == false) and G or setmetatable({}, { -- ./candran/serpent.lua:147
["__index"] = function(t, k) -- ./candran/serpent.lua:148
return t -- ./candran/serpent.lua:148
end, -- ./candran/serpent.lua:148
["__call"] = function(t, ...) -- ./candran/serpent.lua:149
error("cannot call functions") -- ./candran/serpent.lua:149
end -- ./candran/serpent.lua:149
}) -- ./candran/serpent.lua:149
local f, res = (loadstring or load)("return " .. data, nil, nil, env) -- ./candran/serpent.lua:151
if not f then -- ./candran/serpent.lua:152
f, res = (loadstring or load)(data, nil, nil, env) -- ./candran/serpent.lua:152
end -- ./candran/serpent.lua:152
if not f then -- ./candran/serpent.lua:153
return f, res -- ./candran/serpent.lua:153
end -- ./candran/serpent.lua:153
if setfenv then -- ./candran/serpent.lua:154
setfenv(f, env) -- ./candran/serpent.lua:154
end -- ./candran/serpent.lua:154
return pcall(f) -- ./candran/serpent.lua:155
end -- ./candran/serpent.lua:155
local function merge(a, b) -- ./candran/serpent.lua:158
if b then -- ./candran/serpent.lua:158
for k, v in pairs(b) do -- ./candran/serpent.lua:158
a[k] = v -- ./candran/serpent.lua:158
end -- ./candran/serpent.lua:158
end -- ./candran/serpent.lua:158
return a -- ./candran/serpent.lua:158
end -- ./candran/serpent.lua:158
return { -- ./candran/serpent.lua:159
["_NAME"] = n, -- ./candran/serpent.lua:159
["_COPYRIGHT"] = c, -- ./candran/serpent.lua:159
["_DESCRIPTION"] = d, -- ./candran/serpent.lua:159
["_VERSION"] = v, -- ./candran/serpent.lua:159
["serialize"] = s, -- ./candran/serpent.lua:159
["load"] = deserialize, -- ./candran/serpent.lua:160
["dump"] = function(a, opts) -- ./candran/serpent.lua:161
return s(a, merge({ -- ./candran/serpent.lua:161
["name"] = "_", -- ./candran/serpent.lua:161
["compact"] = true, -- ./candran/serpent.lua:161
["sparse"] = true -- ./candran/serpent.lua:161
}, opts)) -- ./candran/serpent.lua:161
end, -- ./candran/serpent.lua:161
["line"] = function(a, opts) -- ./candran/serpent.lua:162
return s(a, merge({ -- ./candran/serpent.lua:162
["sortkeys"] = true, -- ./candran/serpent.lua:162
["comment"] = true -- ./candran/serpent.lua:162
}, opts)) -- ./candran/serpent.lua:162
end, -- ./candran/serpent.lua:162
["block"] = function(a, opts) -- ./candran/serpent.lua:163
return s(a, merge({ -- ./candran/serpent.lua:163
["indent"] = " ", -- ./candran/serpent.lua:163
["sortkeys"] = true, -- ./candran/serpent.lua:163
["comment"] = true -- ./candran/serpent.lua:163
}, opts)) -- ./candran/serpent.lua:163
end -- ./candran/serpent.lua:163
} -- ./candran/serpent.lua:163
end -- ./candran/serpent.lua:163
local serpent = _() or serpent -- ./candran/serpent.lua:167
package["loaded"]["candran.serpent"] = serpent or true -- ./candran/serpent.lua:168
local function _() -- ./candran/serpent.lua:172
local util = require("candran.util") -- ./compiler/lua54.can:1
local targetName = "Lua 5.4" -- ./compiler/lua54.can:3
local unpack = unpack or table["unpack"] -- ./compiler/lua54.can:5
return function(code, ast, options, macros) -- ./compiler/lua54.can:7
if macros == nil then macros = { -- ./compiler/lua54.can:7
["functions"] = {}, -- ./compiler/lua54.can:7
["variables"] = {} -- ./compiler/lua54.can:7
} end -- ./compiler/lua54.can:7
local lastInputPos = 1 -- ./compiler/lua54.can:9
local prevLinePos = 1 -- ./compiler/lua54.can:10
local lastSource = options["chunkname"] or "nil" -- ./compiler/lua54.can:11
local lastLine = 1 -- ./compiler/lua54.can:12
local indentLevel = 0 -- ./compiler/lua54.can:15
local function newline() -- ./compiler/lua54.can:17
local r = options["newline"] .. string["rep"](options["indentation"], indentLevel) -- ./compiler/lua54.can:18
if options["mapLines"] then -- ./compiler/lua54.can:19
local sub = code:sub(lastInputPos) -- ./compiler/lua54.can:20
local source, line = sub:sub(1, sub:find("\
")):match(".*%-%- (.-)%:(%d+)\
") -- ./compiler/lua54.can:21
if source and line then -- ./compiler/lua54.can:23
lastSource = source -- ./compiler/lua54.can:24
lastLine = tonumber(line) -- ./compiler/lua54.can:25
else -- ./compiler/lua54.can:25
for _ in code:sub(prevLinePos, lastInputPos):gmatch("\
") do -- ./compiler/lua54.can:27
lastLine = lastLine + (1) -- ./compiler/lua54.can:28
end -- ./compiler/lua54.can:28
end -- ./compiler/lua54.can:28
prevLinePos = lastInputPos -- ./compiler/lua54.can:32
r = " -- " .. lastSource .. ":" .. lastLine .. r -- ./compiler/lua54.can:34
end -- ./compiler/lua54.can:34
return r -- ./compiler/lua54.can:36
end -- ./compiler/lua54.can:36
local function indent() -- ./compiler/lua54.can:39
indentLevel = indentLevel + (1) -- ./compiler/lua54.can:40
return newline() -- ./compiler/lua54.can:41
end -- ./compiler/lua54.can:41
local function unindent() -- ./compiler/lua54.can:44
indentLevel = indentLevel - (1) -- ./compiler/lua54.can:45
return newline() -- ./compiler/lua54.can:46
end -- ./compiler/lua54.can:46
local states = { -- ./compiler/lua54.can:51
["push"] = {}, -- ./compiler/lua54.can:52
["destructuring"] = {}, -- ./compiler/lua54.can:53
["scope"] = {}, -- ./compiler/lua54.can:54
["macroargs"] = {} -- ./compiler/lua54.can:55
} -- ./compiler/lua54.can:55
local function push(name, state) -- ./compiler/lua54.can:58
table["insert"](states[name], state) -- ./compiler/lua54.can:59
return "" -- ./compiler/lua54.can:60
end -- ./compiler/lua54.can:60
local function pop(name) -- ./compiler/lua54.can:63
table["remove"](states[name]) -- ./compiler/lua54.can:64
return "" -- ./compiler/lua54.can:65
end -- ./compiler/lua54.can:65
local function set(name, state) -- ./compiler/lua54.can:68
states[name][# states[name]] = state -- ./compiler/lua54.can:69
return "" -- ./compiler/lua54.can:70
end -- ./compiler/lua54.can:70
local function peek(name) -- ./compiler/lua54.can:73
return states[name][# states[name]] -- ./compiler/lua54.can:74
end -- ./compiler/lua54.can:74
local function var(name) -- ./compiler/lua54.can:79
return options["variablePrefix"] .. name -- ./compiler/lua54.can:80
end -- ./compiler/lua54.can:80
local function tmp() -- ./compiler/lua54.can:84
local scope = peek("scope") -- ./compiler/lua54.can:85
local var = ("%s_%s"):format(options["variablePrefix"], # scope) -- ./compiler/lua54.can:86
table["insert"](scope, var) -- ./compiler/lua54.can:87
return var -- ./compiler/lua54.can:88
end -- ./compiler/lua54.can:88
local nomacro = { -- ./compiler/lua54.can:92
["variables"] = {}, -- ./compiler/lua54.can:92
["functions"] = {} -- ./compiler/lua54.can:92
} -- ./compiler/lua54.can:92
local required = {} -- ./compiler/lua54.can:95
local requireStr = "" -- ./compiler/lua54.can:96
local function addRequire(mod, name, field) -- ./compiler/lua54.can:98
local req = ("require(%q)%s"):format(mod, field and "." .. field or "") -- ./compiler/lua54.can:99
if not required[req] then -- ./compiler/lua54.can:100
requireStr = requireStr .. (("local %s = %s%s"):format(var(name), req, options["newline"])) -- ./compiler/lua54.can:101
required[req] = true -- ./compiler/lua54.can:102
end -- ./compiler/lua54.can:102
end -- ./compiler/lua54.can:102
local loop = { -- ./compiler/lua54.can:107
"While", -- ./compiler/lua54.can:107
"Repeat", -- ./compiler/lua54.can:107
"Fornum", -- ./compiler/lua54.can:107
"Forin", -- ./compiler/lua54.can:107
"WhileExpr", -- ./compiler/lua54.can:107
"RepeatExpr", -- ./compiler/lua54.can:107
"FornumExpr", -- ./compiler/lua54.can:107
"ForinExpr" -- ./compiler/lua54.can:107
} -- ./compiler/lua54.can:107
local func = { -- ./compiler/lua54.can:108
"Function", -- ./compiler/lua54.can:108
"TableCompr", -- ./compiler/lua54.can:108
"DoExpr", -- ./compiler/lua54.can:108
"WhileExpr", -- ./compiler/lua54.can:108
"RepeatExpr", -- ./compiler/lua54.can:108
"IfExpr", -- ./compiler/lua54.can:108
"FornumExpr", -- ./compiler/lua54.can:108
"ForinExpr" -- ./compiler/lua54.can:108
} -- ./compiler/lua54.can:108
local function any(list, tags, nofollow) -- ./compiler/lua54.can:112
if nofollow == nil then nofollow = {} end -- ./compiler/lua54.can:112
local tagsCheck = {} -- ./compiler/lua54.can:113
for _, tag in ipairs(tags) do -- ./compiler/lua54.can:114
tagsCheck[tag] = true -- ./compiler/lua54.can:115
end -- ./compiler/lua54.can:115
local nofollowCheck = {} -- ./compiler/lua54.can:117
for _, tag in ipairs(nofollow) do -- ./compiler/lua54.can:118
nofollowCheck[tag] = true -- ./compiler/lua54.can:119
end -- ./compiler/lua54.can:119
for _, node in ipairs(list) do -- ./compiler/lua54.can:121
if type(node) == "table" then -- ./compiler/lua54.can:122
if tagsCheck[node["tag"]] then -- ./compiler/lua54.can:123
return node -- ./compiler/lua54.can:124
end -- ./compiler/lua54.can:124
if not nofollowCheck[node["tag"]] then -- ./compiler/lua54.can:126
local r = any(node, tags, nofollow) -- ./compiler/lua54.can:127
if r then -- ./compiler/lua54.can:128
return r -- ./compiler/lua54.can:128
end -- ./compiler/lua54.can:128
end -- ./compiler/lua54.can:128
end -- ./compiler/lua54.can:128
end -- ./compiler/lua54.can:128
return nil -- ./compiler/lua54.can:132
end -- ./compiler/lua54.can:132
local function search(list, tags, nofollow) -- ./compiler/lua54.can:137
if nofollow == nil then nofollow = {} end -- ./compiler/lua54.can:137
local tagsCheck = {} -- ./compiler/lua54.can:138
for _, tag in ipairs(tags) do -- ./compiler/lua54.can:139
tagsCheck[tag] = true -- ./compiler/lua54.can:140
end -- ./compiler/lua54.can:140
local nofollowCheck = {} -- ./compiler/lua54.can:142
for _, tag in ipairs(nofollow) do -- ./compiler/lua54.can:143
nofollowCheck[tag] = true -- ./compiler/lua54.can:144
end -- ./compiler/lua54.can:144
local found = {} -- ./compiler/lua54.can:146
for _, node in ipairs(list) do -- ./compiler/lua54.can:147
if type(node) == "table" then -- ./compiler/lua54.can:148
if not nofollowCheck[node["tag"]] then -- ./compiler/lua54.can:149
for _, n in ipairs(search(node, tags, nofollow)) do -- ./compiler/lua54.can:150
table["insert"](found, n) -- ./compiler/lua54.can:151
end -- ./compiler/lua54.can:151
end -- ./compiler/lua54.can:151
if tagsCheck[node["tag"]] then -- ./compiler/lua54.can:154
table["insert"](found, node) -- ./compiler/lua54.can:155
end -- ./compiler/lua54.can:155
end -- ./compiler/lua54.can:155
end -- ./compiler/lua54.can:155
return found -- ./compiler/lua54.can:159
end -- ./compiler/lua54.can:159
local function all(list, tags) -- ./compiler/lua54.can:163
for _, node in ipairs(list) do -- ./compiler/lua54.can:164
local ok = false -- ./compiler/lua54.can:165
for _, tag in ipairs(tags) do -- ./compiler/lua54.can:166
if node["tag"] == tag then -- ./compiler/lua54.can:167
ok = true -- ./compiler/lua54.can:168
break -- ./compiler/lua54.can:169
end -- ./compiler/lua54.can:169
end -- ./compiler/lua54.can:169
if not ok then -- ./compiler/lua54.can:172
return false -- ./compiler/lua54.can:173
end -- ./compiler/lua54.can:173
end -- ./compiler/lua54.can:173
return true -- ./compiler/lua54.can:176
end -- ./compiler/lua54.can:176
local tags -- ./compiler/lua54.can:180
local function lua(ast, forceTag, ...) -- ./compiler/lua54.can:182
if options["mapLines"] and ast["pos"] then -- ./compiler/lua54.can:183
lastInputPos = ast["pos"] -- ./compiler/lua54.can:184
end -- ./compiler/lua54.can:184
return tags[forceTag or ast["tag"]](ast, ...) -- ./compiler/lua54.can:186
end -- ./compiler/lua54.can:186
local UNPACK = function(list, i, j) -- ./compiler/lua54.can:190
return "table.unpack(" .. list .. (i and (", " .. i .. (j and (", " .. j) or "")) or "") .. ")" -- ./compiler/lua54.can:191
end -- ./compiler/lua54.can:191
local APPEND = function(t, toAppend) -- ./compiler/lua54.can:193
return "do" .. indent() .. "local " .. var("a") .. " = table.pack(" .. toAppend .. ")" .. newline() .. "table.move(" .. var("a") .. ", 1, " .. var("a") .. ".n, #" .. t .. "+1, " .. t .. ")" .. unindent() .. "end" -- ./compiler/lua54.can:194
end -- ./compiler/lua54.can:194
local CONTINUE_START = function() -- ./compiler/lua54.can:196
return "do" .. indent() -- ./compiler/lua54.can:197
end -- ./compiler/lua54.can:197
local CONTINUE_STOP = function() -- ./compiler/lua54.can:199
return unindent() .. "end" .. newline() .. "::" .. var("continue") .. "::" -- ./compiler/lua54.can:200
end -- ./compiler/lua54.can:200
local DESTRUCTURING_ASSIGN = function(destructured, newlineAfter, noLocal) -- ./compiler/lua54.can:202
if newlineAfter == nil then newlineAfter = false end -- ./compiler/lua54.can:202
if noLocal == nil then noLocal = false end -- ./compiler/lua54.can:202
local vars = {} -- ./compiler/lua54.can:203
local values = {} -- ./compiler/lua54.can:204
for _, list in ipairs(destructured) do -- ./compiler/lua54.can:205
for _, v in ipairs(list) do -- ./compiler/lua54.can:206
local var, val -- ./compiler/lua54.can:207
if v["tag"] == "Id" or v["tag"] == "AttributeId" then -- ./compiler/lua54.can:208
var = v -- ./compiler/lua54.can:209
val = { -- ./compiler/lua54.can:210
["tag"] = "Index", -- ./compiler/lua54.can:210
{ -- ./compiler/lua54.can:210
["tag"] = "Id", -- ./compiler/lua54.can:210
list["id"] -- ./compiler/lua54.can:210
}, -- ./compiler/lua54.can:210
{ -- ./compiler/lua54.can:210
["tag"] = "String", -- ./compiler/lua54.can:210
v[1] -- ./compiler/lua54.can:210
} -- ./compiler/lua54.can:210
} -- ./compiler/lua54.can:210
elseif v["tag"] == "Pair" then -- ./compiler/lua54.can:211
var = v[2] -- ./compiler/lua54.can:212
val = { -- ./compiler/lua54.can:213
["tag"] = "Index", -- ./compiler/lua54.can:213
{ -- ./compiler/lua54.can:213
["tag"] = "Id", -- ./compiler/lua54.can:213
list["id"] -- ./compiler/lua54.can:213
}, -- ./compiler/lua54.can:213
v[1] -- ./compiler/lua54.can:213
} -- ./compiler/lua54.can:213
else -- ./compiler/lua54.can:213
error("unknown destructuring element type: " .. tostring(v["tag"])) -- ./compiler/lua54.can:215
end -- ./compiler/lua54.can:215
if destructured["rightOp"] and destructured["leftOp"] then -- ./compiler/lua54.can:217
val = { -- ./compiler/lua54.can:218
["tag"] = "Op", -- ./compiler/lua54.can:218
destructured["rightOp"], -- ./compiler/lua54.can:218
var, -- ./compiler/lua54.can:218
{ -- ./compiler/lua54.can:218
["tag"] = "Op", -- ./compiler/lua54.can:218
destructured["leftOp"], -- ./compiler/lua54.can:218
val, -- ./compiler/lua54.can:218
var -- ./compiler/lua54.can:218
} -- ./compiler/lua54.can:218
} -- ./compiler/lua54.can:218
elseif destructured["rightOp"] then -- ./compiler/lua54.can:219
val = { -- ./compiler/lua54.can:220
["tag"] = "Op", -- ./compiler/lua54.can:220
destructured["rightOp"], -- ./compiler/lua54.can:220
var, -- ./compiler/lua54.can:220
val -- ./compiler/lua54.can:220
} -- ./compiler/lua54.can:220
elseif destructured["leftOp"] then -- ./compiler/lua54.can:221
val = { -- ./compiler/lua54.can:222
["tag"] = "Op", -- ./compiler/lua54.can:222
destructured["leftOp"], -- ./compiler/lua54.can:222
val, -- ./compiler/lua54.can:222
var -- ./compiler/lua54.can:222
} -- ./compiler/lua54.can:222
end -- ./compiler/lua54.can:222
table["insert"](vars, lua(var)) -- ./compiler/lua54.can:224
table["insert"](values, lua(val)) -- ./compiler/lua54.can:225
end -- ./compiler/lua54.can:225
end -- ./compiler/lua54.can:225
if # vars > 0 then -- ./compiler/lua54.can:228
local decl = noLocal and "" or "local " -- ./compiler/lua54.can:229
if newlineAfter then -- ./compiler/lua54.can:230
return decl .. table["concat"](vars, ", ") .. " = " .. table["concat"](values, ", ") .. newline() -- ./compiler/lua54.can:231
else -- ./compiler/lua54.can:231
return newline() .. decl .. table["concat"](vars, ", ") .. " = " .. table["concat"](values, ", ") -- ./compiler/lua54.can:233
end -- ./compiler/lua54.can:233
else -- ./compiler/lua54.can:233
return "" -- ./compiler/lua54.can:236
end -- ./compiler/lua54.can:236
end -- ./compiler/lua54.can:236
tags = setmetatable({ -- ./compiler/lua54.can:241
["Block"] = function(t) -- ./compiler/lua54.can:243
local hasPush = peek("push") == nil and any(t, { "Push" }, func) -- ./compiler/lua54.can:244
if hasPush and hasPush == t[# t] then -- ./compiler/lua54.can:245
hasPush["tag"] = "Return" -- ./compiler/lua54.can:246
hasPush = false -- ./compiler/lua54.can:247
end -- ./compiler/lua54.can:247
local r = push("scope", {}) -- ./compiler/lua54.can:249
if hasPush then -- ./compiler/lua54.can:250
r = r .. (push("push", var("push")) .. "local " .. var("push") .. " = {}" .. newline()) -- ./compiler/lua54.can:251
end -- ./compiler/lua54.can:251
for i = 1, # t - 1, 1 do -- ./compiler/lua54.can:253
r = r .. (lua(t[i]) .. newline()) -- ./compiler/lua54.can:254
end -- ./compiler/lua54.can:254
if t[# t] then -- ./compiler/lua54.can:256
r = r .. (lua(t[# t])) -- ./compiler/lua54.can:257
end -- ./compiler/lua54.can:257
if hasPush and (t[# t] and t[# t]["tag"] ~= "Return") then -- ./compiler/lua54.can:259
r = r .. (newline() .. "return " .. UNPACK(var("push")) .. pop("push")) -- ./compiler/lua54.can:260
end -- ./compiler/lua54.can:260
return r .. pop("scope") -- ./compiler/lua54.can:262
end, -- ./compiler/lua54.can:262
["Do"] = function(t) -- ./compiler/lua54.can:268
return "do" .. indent() .. lua(t, "Block") .. unindent() .. "end" -- ./compiler/lua54.can:269
end, -- ./compiler/lua54.can:269
["Set"] = function(t) -- ./compiler/lua54.can:272
local expr = t[# t] -- ./compiler/lua54.can:274
local vars, values = {}, {} -- ./compiler/lua54.can:275
local destructuringVars, destructuringValues = {}, {} -- ./compiler/lua54.can:276
for i, n in ipairs(t[1]) do -- ./compiler/lua54.can:277
if n["tag"] == "DestructuringId" then -- ./compiler/lua54.can:278
table["insert"](destructuringVars, n) -- ./compiler/lua54.can:279
table["insert"](destructuringValues, expr[i]) -- ./compiler/lua54.can:280
else -- ./compiler/lua54.can:280
table["insert"](vars, n) -- ./compiler/lua54.can:282
table["insert"](values, expr[i]) -- ./compiler/lua54.can:283
end -- ./compiler/lua54.can:283
end -- ./compiler/lua54.can:283
if # t == 2 or # t == 3 then -- ./compiler/lua54.can:287
local r = "" -- ./compiler/lua54.can:288
if # vars > 0 then -- ./compiler/lua54.can:289
r = lua(vars, "_lhs") .. " = " .. lua(values, "_lhs") -- ./compiler/lua54.can:290
end -- ./compiler/lua54.can:290
if # destructuringVars > 0 then -- ./compiler/lua54.can:292
local destructured = {} -- ./compiler/lua54.can:293
r = r .. ("local " .. push("destructuring", destructured) .. lua(destructuringVars, "_lhs") .. pop("destructuring") .. " = " .. lua(destructuringValues, "_lhs")) -- ./compiler/lua54.can:294
return r .. DESTRUCTURING_ASSIGN(destructured, nil, true) -- ./compiler/lua54.can:295
end -- ./compiler/lua54.can:295
return r -- ./compiler/lua54.can:297
elseif # t == 4 then -- ./compiler/lua54.can:298
if t[3] == "=" then -- ./compiler/lua54.can:299
local r = "" -- ./compiler/lua54.can:300
if # vars > 0 then -- ./compiler/lua54.can:301
r = r .. (lua(vars, "_lhs") .. " = " .. lua({ -- ./compiler/lua54.can:302
t[2], -- ./compiler/lua54.can:302
vars[1], -- ./compiler/lua54.can:302
{ -- ./compiler/lua54.can:302
["tag"] = "Paren", -- ./compiler/lua54.can:302
values[1] -- ./compiler/lua54.can:302
} -- ./compiler/lua54.can:302
}, "Op")) -- ./compiler/lua54.can:302
for i = 2, math["min"](# t[4], # vars), 1 do -- ./compiler/lua54.can:303
r = r .. (", " .. lua({ -- ./compiler/lua54.can:304
t[2], -- ./compiler/lua54.can:304
vars[i], -- ./compiler/lua54.can:304
{ -- ./compiler/lua54.can:304
["tag"] = "Paren", -- ./compiler/lua54.can:304
values[i] -- ./compiler/lua54.can:304
} -- ./compiler/lua54.can:304
}, "Op")) -- ./compiler/lua54.can:304
end -- ./compiler/lua54.can:304
end -- ./compiler/lua54.can:304
if # destructuringVars > 0 then -- ./compiler/lua54.can:307
local destructured = { ["rightOp"] = t[2] } -- ./compiler/lua54.can:308
r = r .. ("local " .. push("destructuring", destructured) .. lua(destructuringVars, "_lhs") .. pop("destructuring") .. " = " .. lua(destructuringValues, "_lhs")) -- ./compiler/lua54.can:309
return r .. DESTRUCTURING_ASSIGN(destructured, nil, true) -- ./compiler/lua54.can:310
end -- ./compiler/lua54.can:310
return r -- ./compiler/lua54.can:312
else -- ./compiler/lua54.can:312
local r = "" -- ./compiler/lua54.can:314
if # vars > 0 then -- ./compiler/lua54.can:315
r = r .. (lua(vars, "_lhs") .. " = " .. lua({ -- ./compiler/lua54.can:316
t[3], -- ./compiler/lua54.can:316
{ -- ./compiler/lua54.can:316
["tag"] = "Paren", -- ./compiler/lua54.can:316
values[1] -- ./compiler/lua54.can:316
}, -- ./compiler/lua54.can:316
vars[1] -- ./compiler/lua54.can:316
}, "Op")) -- ./compiler/lua54.can:316
for i = 2, math["min"](# t[4], # t[1]), 1 do -- ./compiler/lua54.can:317
r = r .. (", " .. lua({ -- ./compiler/lua54.can:318
t[3], -- ./compiler/lua54.can:318
{ -- ./compiler/lua54.can:318
["tag"] = "Paren", -- ./compiler/lua54.can:318
values[i] -- ./compiler/lua54.can:318
}, -- ./compiler/lua54.can:318
vars[i] -- ./compiler/lua54.can:318
}, "Op")) -- ./compiler/lua54.can:318
end -- ./compiler/lua54.can:318
end -- ./compiler/lua54.can:318
if # destructuringVars > 0 then -- ./compiler/lua54.can:321
local destructured = { ["leftOp"] = t[3] } -- ./compiler/lua54.can:322
r = r .. ("local " .. push("destructuring", destructured) .. lua(destructuringVars, "_lhs") .. pop("destructuring") .. " = " .. lua(destructuringValues, "_lhs")) -- ./compiler/lua54.can:323
return r .. DESTRUCTURING_ASSIGN(destructured, nil, true) -- ./compiler/lua54.can:324
end -- ./compiler/lua54.can:324
return r -- ./compiler/lua54.can:326
end -- ./compiler/lua54.can:326
else -- ./compiler/lua54.can:326
local r = "" -- ./compiler/lua54.can:329
if # vars > 0 then -- ./compiler/lua54.can:330
r = r .. (lua(vars, "_lhs") .. " = " .. lua({ -- ./compiler/lua54.can:331
t[2], -- ./compiler/lua54.can:331
vars[1], -- ./compiler/lua54.can:331
{ -- ./compiler/lua54.can:331
["tag"] = "Op", -- ./compiler/lua54.can:331
t[4], -- ./compiler/lua54.can:331
{ -- ./compiler/lua54.can:331
["tag"] = "Paren", -- ./compiler/lua54.can:331
values[1] -- ./compiler/lua54.can:331
}, -- ./compiler/lua54.can:331
vars[1] -- ./compiler/lua54.can:331
} -- ./compiler/lua54.can:331
}, "Op")) -- ./compiler/lua54.can:331
for i = 2, math["min"](# t[5], # t[1]), 1 do -- ./compiler/lua54.can:332
r = r .. (", " .. lua({ -- ./compiler/lua54.can:333
t[2], -- ./compiler/lua54.can:333
vars[i], -- ./compiler/lua54.can:333
{ -- ./compiler/lua54.can:333
["tag"] = "Op", -- ./compiler/lua54.can:333
t[4], -- ./compiler/lua54.can:333
{ -- ./compiler/lua54.can:333
["tag"] = "Paren", -- ./compiler/lua54.can:333
values[i] -- ./compiler/lua54.can:333
}, -- ./compiler/lua54.can:333
vars[i] -- ./compiler/lua54.can:333
} -- ./compiler/lua54.can:333
}, "Op")) -- ./compiler/lua54.can:333
end -- ./compiler/lua54.can:333
end -- ./compiler/lua54.can:333
if # destructuringVars > 0 then -- ./compiler/lua54.can:336
local destructured = { -- ./compiler/lua54.can:337
["rightOp"] = t[2], -- ./compiler/lua54.can:337
["leftOp"] = t[4] -- ./compiler/lua54.can:337
} -- ./compiler/lua54.can:337
r = r .. ("local " .. push("destructuring", destructured) .. lua(destructuringVars, "_lhs") .. pop("destructuring") .. " = " .. lua(destructuringValues, "_lhs")) -- ./compiler/lua54.can:338
return r .. DESTRUCTURING_ASSIGN(destructured, nil, true) -- ./compiler/lua54.can:339
end -- ./compiler/lua54.can:339
return r -- ./compiler/lua54.can:341
end -- ./compiler/lua54.can:341
end, -- ./compiler/lua54.can:341
["While"] = function(t) -- ./compiler/lua54.can:345
local r = "" -- ./compiler/lua54.can:346
local hasContinue = any(t[2], { "Continue" }, loop) -- ./compiler/lua54.can:347
local lets = search({ t[1] }, { "LetExpr" }) -- ./compiler/lua54.can:348
if # lets > 0 then -- ./compiler/lua54.can:349
r = r .. ("do" .. indent()) -- ./compiler/lua54.can:350
for _, l in ipairs(lets) do -- ./compiler/lua54.can:351
r = r .. (lua(l, "Let") .. newline()) -- ./compiler/lua54.can:352
end -- ./compiler/lua54.can:352
end -- ./compiler/lua54.can:352
r = r .. ("while " .. lua(t[1]) .. " do" .. indent()) -- ./compiler/lua54.can:355
if # lets > 0 then -- ./compiler/lua54.can:356
r = r .. ("do" .. indent()) -- ./compiler/lua54.can:357
end -- ./compiler/lua54.can:357
if hasContinue then -- ./compiler/lua54.can:359
r = r .. (CONTINUE_START()) -- ./compiler/lua54.can:360
end -- ./compiler/lua54.can:360
r = r .. (lua(t[2])) -- ./compiler/lua54.can:362
if hasContinue then -- ./compiler/lua54.can:363
r = r .. (CONTINUE_STOP()) -- ./compiler/lua54.can:364
end -- ./compiler/lua54.can:364
r = r .. (unindent() .. "end") -- ./compiler/lua54.can:366
if # lets > 0 then -- ./compiler/lua54.can:367
for _, l in ipairs(lets) do -- ./compiler/lua54.can:368
r = r .. (newline() .. lua(l, "Set")) -- ./compiler/lua54.can:369
end -- ./compiler/lua54.can:369
r = r .. (unindent() .. "end" .. unindent() .. "end") -- ./compiler/lua54.can:371
end -- ./compiler/lua54.can:371
return r -- ./compiler/lua54.can:373
end, -- ./compiler/lua54.can:373
["Repeat"] = function(t) -- ./compiler/lua54.can:376
local hasContinue = any(t[1], { "Continue" }, loop) -- ./compiler/lua54.can:377
local r = "repeat" .. indent() -- ./compiler/lua54.can:378
if hasContinue then -- ./compiler/lua54.can:379
r = r .. (CONTINUE_START()) -- ./compiler/lua54.can:380
end -- ./compiler/lua54.can:380
r = r .. (lua(t[1])) -- ./compiler/lua54.can:382
if hasContinue then -- ./compiler/lua54.can:383
r = r .. (CONTINUE_STOP()) -- ./compiler/lua54.can:384
end -- ./compiler/lua54.can:384
r = r .. (unindent() .. "until " .. lua(t[2])) -- ./compiler/lua54.can:386
return r -- ./compiler/lua54.can:387
end, -- ./compiler/lua54.can:387
["If"] = function(t) -- ./compiler/lua54.can:390
local r = "" -- ./compiler/lua54.can:391
local toClose = 0 -- ./compiler/lua54.can:392
local lets = search({ t[1] }, { "LetExpr" }) -- ./compiler/lua54.can:393
if # lets > 0 then -- ./compiler/lua54.can:394
r = r .. ("do" .. indent()) -- ./compiler/lua54.can:395
toClose = toClose + (1) -- ./compiler/lua54.can:396
for _, l in ipairs(lets) do -- ./compiler/lua54.can:397
r = r .. (lua(l, "Let") .. newline()) -- ./compiler/lua54.can:398
end -- ./compiler/lua54.can:398
end -- ./compiler/lua54.can:398
r = r .. ("if " .. lua(t[1]) .. " then" .. indent() .. lua(t[2]) .. unindent()) -- ./compiler/lua54.can:401
for i = 3, # t - 1, 2 do -- ./compiler/lua54.can:402
lets = search({ t[i] }, { "LetExpr" }) -- ./compiler/lua54.can:403
if # lets > 0 then -- ./compiler/lua54.can:404
r = r .. ("else" .. indent()) -- ./compiler/lua54.can:405
toClose = toClose + (1) -- ./compiler/lua54.can:406
for _, l in ipairs(lets) do -- ./compiler/lua54.can:407
r = r .. (lua(l, "Let") .. newline()) -- ./compiler/lua54.can:408
end -- ./compiler/lua54.can:408
else -- ./compiler/lua54.can:408
r = r .. ("else") -- ./compiler/lua54.can:411
end -- ./compiler/lua54.can:411
r = r .. ("if " .. lua(t[i]) .. " then" .. indent() .. lua(t[i + 1]) .. unindent()) -- ./compiler/lua54.can:413
end -- ./compiler/lua54.can:413
if # t % 2 == 1 then -- ./compiler/lua54.can:415
r = r .. ("else" .. indent() .. lua(t[# t]) .. unindent()) -- ./compiler/lua54.can:416
end -- ./compiler/lua54.can:416
r = r .. ("end") -- ./compiler/lua54.can:418
for i = 1, toClose do -- ./compiler/lua54.can:419
r = r .. (unindent() .. "end") -- ./compiler/lua54.can:420
end -- ./compiler/lua54.can:420
return r -- ./compiler/lua54.can:422
end, -- ./compiler/lua54.can:422
["Fornum"] = function(t) -- ./compiler/lua54.can:425
local r = "for " .. lua(t[1]) .. " = " .. lua(t[2]) .. ", " .. lua(t[3]) -- ./compiler/lua54.can:426
if # t == 5 then -- ./compiler/lua54.can:427
local hasContinue = any(t[5], { "Continue" }, loop) -- ./compiler/lua54.can:428
r = r .. (", " .. lua(t[4]) .. " do" .. indent()) -- ./compiler/lua54.can:429
if hasContinue then -- ./compiler/lua54.can:430
r = r .. (CONTINUE_START()) -- ./compiler/lua54.can:431
end -- ./compiler/lua54.can:431
r = r .. (lua(t[5])) -- ./compiler/lua54.can:433
if hasContinue then -- ./compiler/lua54.can:434
r = r .. (CONTINUE_STOP()) -- ./compiler/lua54.can:435
end -- ./compiler/lua54.can:435
return r .. unindent() .. "end" -- ./compiler/lua54.can:437
else -- ./compiler/lua54.can:437
local hasContinue = any(t[4], { "Continue" }, loop) -- ./compiler/lua54.can:439
r = r .. (" do" .. indent()) -- ./compiler/lua54.can:440
if hasContinue then -- ./compiler/lua54.can:441
r = r .. (CONTINUE_START()) -- ./compiler/lua54.can:442
end -- ./compiler/lua54.can:442
r = r .. (lua(t[4])) -- ./compiler/lua54.can:444
if hasContinue then -- ./compiler/lua54.can:445
r = r .. (CONTINUE_STOP()) -- ./compiler/lua54.can:446
end -- ./compiler/lua54.can:446
return r .. unindent() .. "end" -- ./compiler/lua54.can:448
end -- ./compiler/lua54.can:448
end, -- ./compiler/lua54.can:448
["Forin"] = function(t) -- ./compiler/lua54.can:452
local destructured = {} -- ./compiler/lua54.can:453
local hasContinue = any(t[3], { "Continue" }, loop) -- ./compiler/lua54.can:454
local r = "for " .. push("destructuring", destructured) .. lua(t[1], "_lhs") .. pop("destructuring") .. " in " .. lua(t[2], "_lhs") .. " do" .. indent() -- ./compiler/lua54.can:455
if hasContinue then -- ./compiler/lua54.can:456
r = r .. (CONTINUE_START()) -- ./compiler/lua54.can:457
end -- ./compiler/lua54.can:457
r = r .. (DESTRUCTURING_ASSIGN(destructured, true) .. lua(t[3])) -- ./compiler/lua54.can:459
if hasContinue then -- ./compiler/lua54.can:460
r = r .. (CONTINUE_STOP()) -- ./compiler/lua54.can:461
end -- ./compiler/lua54.can:461
return r .. unindent() .. "end" -- ./compiler/lua54.can:463
end, -- ./compiler/lua54.can:463
["Local"] = function(t) -- ./compiler/lua54.can:466
local destructured = {} -- ./compiler/lua54.can:467
local r = "local " .. push("destructuring", destructured) .. lua(t[1], "_lhs") .. pop("destructuring") -- ./compiler/lua54.can:468
if t[2][1] then -- ./compiler/lua54.can:469
r = r .. (" = " .. lua(t[2], "_lhs")) -- ./compiler/lua54.can:470
end -- ./compiler/lua54.can:470
return r .. DESTRUCTURING_ASSIGN(destructured) -- ./compiler/lua54.can:472
end, -- ./compiler/lua54.can:472
["Let"] = function(t) -- ./compiler/lua54.can:475
local destructured = {} -- ./compiler/lua54.can:476
local nameList = push("destructuring", destructured) .. lua(t[1], "_lhs") .. pop("destructuring") -- ./compiler/lua54.can:477
local r = "local " .. nameList -- ./compiler/lua54.can:478
if t[2][1] then -- ./compiler/lua54.can:479
if all(t[2], { -- ./compiler/lua54.can:480
"Nil", -- ./compiler/lua54.can:480
"Dots", -- ./compiler/lua54.can:480
"Boolean", -- ./compiler/lua54.can:480
"Number", -- ./compiler/lua54.can:480
"String" -- ./compiler/lua54.can:480
}) then -- ./compiler/lua54.can:480
r = r .. (" = " .. lua(t[2], "_lhs")) -- ./compiler/lua54.can:481
else -- ./compiler/lua54.can:481
r = r .. (newline() .. nameList .. " = " .. lua(t[2], "_lhs")) -- ./compiler/lua54.can:483
end -- ./compiler/lua54.can:483
end -- ./compiler/lua54.can:483
return r .. DESTRUCTURING_ASSIGN(destructured) -- ./compiler/lua54.can:486
end, -- ./compiler/lua54.can:486
["Localrec"] = function(t) -- ./compiler/lua54.can:489
return "local function " .. lua(t[1][1]) .. lua(t[2][1], "_functionWithoutKeyword") -- ./compiler/lua54.can:490
end, -- ./compiler/lua54.can:490
["Goto"] = function(t) -- ./compiler/lua54.can:493
return "goto " .. lua(t, "Id") -- ./compiler/lua54.can:494
end, -- ./compiler/lua54.can:494
["Label"] = function(t) -- ./compiler/lua54.can:497
return "::" .. lua(t, "Id") .. "::" -- ./compiler/lua54.can:498
end, -- ./compiler/lua54.can:498
["Return"] = function(t) -- ./compiler/lua54.can:501
local push = peek("push") -- ./compiler/lua54.can:502
if push then -- ./compiler/lua54.can:503
local r = "" -- ./compiler/lua54.can:504
for _, val in ipairs(t) do -- ./compiler/lua54.can:505
r = r .. (push .. "[#" .. push .. "+1] = " .. lua(val) .. newline()) -- ./compiler/lua54.can:506
end -- ./compiler/lua54.can:506
return r .. "return " .. UNPACK(push) -- ./compiler/lua54.can:508
else -- ./compiler/lua54.can:508
return "return " .. lua(t, "_lhs") -- ./compiler/lua54.can:510
end -- ./compiler/lua54.can:510
end, -- ./compiler/lua54.can:510
["Push"] = function(t) -- ./compiler/lua54.can:514
local var = assert(peek("push"), "no context given for push") -- ./compiler/lua54.can:515
r = "" -- ./compiler/lua54.can:516
for i = 1, # t - 1, 1 do -- ./compiler/lua54.can:517
r = r .. (var .. "[#" .. var .. "+1] = " .. lua(t[i]) .. newline()) -- ./compiler/lua54.can:518
end -- ./compiler/lua54.can:518
if t[# t] then -- ./compiler/lua54.can:520
if t[# t]["tag"] == "Call" then -- ./compiler/lua54.can:521
r = r .. (APPEND(var, lua(t[# t]))) -- ./compiler/lua54.can:522
else -- ./compiler/lua54.can:522
r = r .. (var .. "[#" .. var .. "+1] = " .. lua(t[# t])) -- ./compiler/lua54.can:524
end -- ./compiler/lua54.can:524
end -- ./compiler/lua54.can:524
return r -- ./compiler/lua54.can:527
end, -- ./compiler/lua54.can:527
["Break"] = function() -- ./compiler/lua54.can:530
return "break" -- ./compiler/lua54.can:531
end, -- ./compiler/lua54.can:531
["Continue"] = function() -- ./compiler/lua54.can:534
return "goto " .. var("continue") -- ./compiler/lua54.can:535
end, -- ./compiler/lua54.can:535
["Nil"] = function() -- ./compiler/lua54.can:542
return "nil" -- ./compiler/lua54.can:543
end, -- ./compiler/lua54.can:543
["Dots"] = function() -- ./compiler/lua54.can:546
local macroargs = peek("macroargs") -- ./compiler/lua54.can:547
if macroargs and not nomacro["variables"]["..."] and macroargs["..."] then -- ./compiler/lua54.can:548
nomacro["variables"]["..."] = true -- ./compiler/lua54.can:549
local r = lua(macroargs["..."], "_lhs") -- ./compiler/lua54.can:550
nomacro["variables"]["..."] = nil -- ./compiler/lua54.can:551
return r -- ./compiler/lua54.can:552
else -- ./compiler/lua54.can:552
return "..." -- ./compiler/lua54.can:554
end -- ./compiler/lua54.can:554
end, -- ./compiler/lua54.can:554
["Boolean"] = function(t) -- ./compiler/lua54.can:558
return tostring(t[1]) -- ./compiler/lua54.can:559
end, -- ./compiler/lua54.can:559
["Number"] = function(t) -- ./compiler/lua54.can:562
return tostring(t[1]) -- ./compiler/lua54.can:563
end, -- ./compiler/lua54.can:563
["String"] = function(t) -- ./compiler/lua54.can:566
return ("%q"):format(t[1]) -- ./compiler/lua54.can:567
end, -- ./compiler/lua54.can:567
["_functionWithoutKeyword"] = function(t) -- ./compiler/lua54.can:570
local r = "(" -- ./compiler/lua54.can:571
local decl = {} -- ./compiler/lua54.can:572
if t[1][1] then -- ./compiler/lua54.can:573
if t[1][1]["tag"] == "ParPair" then -- ./compiler/lua54.can:574
local id = lua(t[1][1][1]) -- ./compiler/lua54.can:575
indentLevel = indentLevel + (1) -- ./compiler/lua54.can:576
table["insert"](decl, "if " .. id .. " == nil then " .. id .. " = " .. lua(t[1][1][2]) .. " end") -- ./compiler/lua54.can:577
indentLevel = indentLevel - (1) -- ./compiler/lua54.can:578
r = r .. (id) -- ./compiler/lua54.can:579
else -- ./compiler/lua54.can:579
r = r .. (lua(t[1][1])) -- ./compiler/lua54.can:581
end -- ./compiler/lua54.can:581
for i = 2, # t[1], 1 do -- ./compiler/lua54.can:583
if t[1][i]["tag"] == "ParPair" then -- ./compiler/lua54.can:584
local id = lua(t[1][i][1]) -- ./compiler/lua54.can:585
indentLevel = indentLevel + (1) -- ./compiler/lua54.can:586