rufus-lua-moon 0.2.3.2 → 0.2.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,45 +1,41 @@
1
1
  local types = require("moonscript.types")
2
2
  local util = require("moonscript.util")
3
3
  local data = require("moonscript.data")
4
- local reversed, unpack = util.reversed, util.unpack
5
- local ntype, mtype, build, smart_node, is_slice, value_is_singular = types.ntype, types.mtype, types.build, types.smart_node, types.is_slice, types.value_is_singular
6
- local insert = table.insert
4
+ local reversed, unpack
5
+ reversed, unpack = util.reversed, util.unpack
6
+ local ntype, mtype, build, smart_node, is_slice, value_is_singular
7
+ ntype, mtype, build, smart_node, is_slice, value_is_singular = types.ntype, types.mtype, types.build, types.smart_node, types.is_slice, types.value_is_singular
8
+ local insert
9
+ do
10
+ local _obj_0 = table
11
+ insert = _obj_0.insert
12
+ end
7
13
  local NameProxy, LocalName
8
14
  do
9
- local _table_0 = require("moonscript.transform.names")
10
- NameProxy, LocalName = _table_0.NameProxy, _table_0.LocalName
15
+ local _obj_0 = require("moonscript.transform.names")
16
+ NameProxy, LocalName = _obj_0.NameProxy, _obj_0.LocalName
11
17
  end
12
18
  local destructure = require("moonscript.transform.destructure")
13
- local implicitly_return
14
- local Run
19
+ local NOOP = {
20
+ "noop"
21
+ }
22
+ local Run, apply_to_last, is_singular, extract_declarations, expand_elseif_assign, constructor_name, with_continue_listener, Transformer, construct_comprehension, Statement, Accumulator, default_accumulator, implicitly_return, Value
15
23
  do
16
- local _parent_0 = nil
17
24
  local _base_0 = {
18
25
  call = function(self, state)
19
26
  return self.fn(state)
20
27
  end
21
28
  }
22
29
  _base_0.__index = _base_0
23
- if _parent_0 then
24
- setmetatable(_base_0, _parent_0.__base)
25
- end
26
30
  local _class_0 = setmetatable({
27
31
  __init = function(self, fn)
28
32
  self.fn = fn
29
33
  self[1] = "run"
30
34
  end,
31
35
  __base = _base_0,
32
- __name = "Run",
33
- __parent = _parent_0
36
+ __name = "Run"
34
37
  }, {
35
- __index = function(cls, name)
36
- local val = rawget(_base_0, name)
37
- if val == nil and _parent_0 then
38
- return _parent_0[name]
39
- else
40
- return val
41
- end
42
- end,
38
+ __index = _base_0,
43
39
  __call = function(cls, ...)
44
40
  local _self_0 = setmetatable({}, _base_0)
45
41
  cls.__init(_self_0, ...)
@@ -47,12 +43,8 @@ do
47
43
  end
48
44
  })
49
45
  _base_0.__class = _class_0
50
- if _parent_0 and _parent_0.__inherited then
51
- _parent_0.__inherited(_parent_0, _class_0)
52
- end
53
46
  Run = _class_0
54
47
  end
55
- local apply_to_last
56
48
  apply_to_last = function(stms, fn)
57
49
  local last_exp_id = 0
58
50
  for i = #stms, 1, -1 do
@@ -67,7 +59,11 @@ apply_to_last = function(stms, fn)
67
59
  local _len_0 = 1
68
60
  for i, stm in ipairs(stms) do
69
61
  if i == last_exp_id then
70
- _accum_0[_len_0] = fn(stm)
62
+ _accum_0[_len_0] = {
63
+ "transform",
64
+ stm,
65
+ fn
66
+ }
71
67
  else
72
68
  _accum_0[_len_0] = stm
73
69
  end
@@ -76,7 +72,6 @@ apply_to_last = function(stms, fn)
76
72
  return _accum_0
77
73
  end)()
78
74
  end
79
- local is_singular
80
75
  is_singular = function(body)
81
76
  if #body ~= 1 then
82
77
  return false
@@ -87,7 +82,6 @@ is_singular = function(body)
87
82
  return body[1]
88
83
  end
89
84
  end
90
- local extract_declarations
91
85
  extract_declarations = function(self, body, start, out)
92
86
  if body == nil then
93
87
  body = self.current_stms
@@ -128,7 +122,6 @@ extract_declarations = function(self, body, start, out)
128
122
  end
129
123
  return out
130
124
  end
131
- local expand_elseif_assign
132
125
  expand_elseif_assign = function(ifstm)
133
126
  for i = 4, #ifstm do
134
127
  local case = ifstm[i]
@@ -152,8 +145,7 @@ expand_elseif_assign = function(ifstm)
152
145
  end
153
146
  return ifstm
154
147
  end
155
- local constructor_name = "new"
156
- local with_continue_listener
148
+ constructor_name = "new"
157
149
  with_continue_listener = function(body)
158
150
  local continue_name = nil
159
151
  return {
@@ -216,10 +208,20 @@ with_continue_listener = function(body)
216
208
  end)
217
209
  }
218
210
  end
219
- local Transformer
220
211
  do
221
- local _parent_0 = nil
222
212
  local _base_0 = {
213
+ transform_once = function(self, scope, node, ...)
214
+ if self.seen_nodes[node] then
215
+ return node
216
+ end
217
+ self.seen_nodes[node] = true
218
+ local transformer = self.transformers[ntype(node)]
219
+ if transformer then
220
+ return transformer(scope, node, ...) or node
221
+ else
222
+ return node
223
+ end
224
+ end,
223
225
  transform = function(self, scope, node, ...)
224
226
  if self.seen_nodes[node] then
225
227
  return node
@@ -253,9 +255,6 @@ do
253
255
  end
254
256
  }
255
257
  _base_0.__index = _base_0
256
- if _parent_0 then
257
- setmetatable(_base_0, _parent_0.__base)
258
- end
259
258
  local _class_0 = setmetatable({
260
259
  __init = function(self, transformers)
261
260
  self.transformers = transformers
@@ -264,17 +263,9 @@ do
264
263
  })
265
264
  end,
266
265
  __base = _base_0,
267
- __name = "Transformer",
268
- __parent = _parent_0
266
+ __name = "Transformer"
269
267
  }, {
270
- __index = function(cls, name)
271
- local val = rawget(_base_0, name)
272
- if val == nil and _parent_0 then
273
- return _parent_0[name]
274
- else
275
- return val
276
- end
277
- end,
268
+ __index = _base_0,
278
269
  __call = function(cls, ...)
279
270
  local _self_0 = setmetatable({}, _base_0)
280
271
  cls.__init(_self_0, ...)
@@ -282,12 +273,8 @@ do
282
273
  end
283
274
  })
284
275
  _base_0.__class = _class_0
285
- if _parent_0 and _parent_0.__inherited then
286
- _parent_0.__inherited(_parent_0, _class_0)
287
- end
288
276
  Transformer = _class_0
289
277
  end
290
- local construct_comprehension
291
278
  construct_comprehension = function(inner, clauses)
292
279
  local current_stms = inner
293
280
  for _, clause in reversed(clauses) do
@@ -295,10 +282,7 @@ construct_comprehension = function(inner, clauses)
295
282
  local _exp_0 = t
296
283
  if "for" == _exp_0 then
297
284
  local name, bounds
298
- do
299
- local _obj_0 = clause
300
- _, name, bounds = _obj_0[1], _obj_0[2], _obj_0[3]
301
- end
285
+ _, name, bounds = clause[1], clause[2], clause[3]
302
286
  current_stms = {
303
287
  "for",
304
288
  name,
@@ -307,10 +291,7 @@ construct_comprehension = function(inner, clauses)
307
291
  }
308
292
  elseif "foreach" == _exp_0 then
309
293
  local names, iter
310
- do
311
- local _obj_0 = clause
312
- _, names, iter = _obj_0[1], _obj_0[2], _obj_0[3]
313
- end
294
+ _, names, iter = clause[1], clause[2], clause[3]
314
295
  current_stms = {
315
296
  "foreach",
316
297
  names,
@@ -321,10 +302,7 @@ construct_comprehension = function(inner, clauses)
321
302
  }
322
303
  elseif "when" == _exp_0 then
323
304
  local cond
324
- do
325
- local _obj_0 = clause
326
- _, cond = _obj_0[1], _obj_0[2]
327
- end
305
+ _, cond = clause[1], clause[2]
328
306
  current_stms = {
329
307
  "if",
330
308
  cond,
@@ -339,21 +317,37 @@ construct_comprehension = function(inner, clauses)
339
317
  end
340
318
  return current_stms[1]
341
319
  end
342
- local Statement = Transformer({
320
+ Statement = Transformer({
321
+ transform = function(self, tuple)
322
+ local _, node, fn
323
+ _, node, fn = tuple[1], tuple[2], tuple[3]
324
+ return fn(node)
325
+ end,
343
326
  root_stms = function(self, body)
344
327
  return apply_to_last(body, implicitly_return(self))
345
328
  end,
329
+ ["return"] = function(self, node)
330
+ node[2] = Value:transform_once(self, node[2])
331
+ if "block_exp" == ntype(node[2]) then
332
+ local block_exp = node[2]
333
+ local block_body = block_exp[2]
334
+ local idx = #block_body
335
+ node[2] = block_body[idx]
336
+ block_body[idx] = node
337
+ return build.group(block_body)
338
+ end
339
+ return node
340
+ end,
346
341
  declare_glob = function(self, node)
347
342
  local names = extract_declarations(self)
348
343
  if node[2] == "^" then
349
- names = (function()
344
+ do
350
345
  local _accum_0 = { }
351
346
  local _len_0 = 1
352
- local _list_0 = names
353
- for _index_0 = 1, #_list_0 do
347
+ for _index_0 = 1, #names do
354
348
  local _continue_0 = false
355
349
  repeat
356
- local name = _list_0[_index_0]
350
+ local name = names[_index_0]
357
351
  if not (name:match("^%u")) then
358
352
  _continue_0 = true
359
353
  break
@@ -367,8 +361,8 @@ local Statement = Transformer({
367
361
  break
368
362
  end
369
363
  end
370
- return _accum_0
371
- end)()
364
+ names = _accum_0
365
+ end
372
366
  end
373
367
  return {
374
368
  "declare",
@@ -377,8 +371,34 @@ local Statement = Transformer({
377
371
  end,
378
372
  assign = function(self, node)
379
373
  local names, values = unpack(node, 2)
374
+ local num_values = #values
375
+ local num_names = #values
376
+ if num_names == 1 and num_values == 1 then
377
+ local first_value = values[1]
378
+ local first_name = names[1]
379
+ local _exp_0 = ntype(first_value)
380
+ if "block_exp" == _exp_0 then
381
+ local block_body = first_value[2]
382
+ local idx = #block_body
383
+ block_body[idx] = build.assign_one(first_name, block_body[idx])
384
+ return build.group({
385
+ {
386
+ "declare",
387
+ {
388
+ first_name
389
+ }
390
+ },
391
+ {
392
+ "do",
393
+ block_body
394
+ }
395
+ })
396
+ elseif "comprehension" == _exp_0 or "tblcomprehension" == _exp_0 or "foreach" == _exp_0 or "for" == _exp_0 or "while" == _exp_0 then
397
+ return build.assign_one(first_name, Value:transform_once(self, first_value))
398
+ end
399
+ end
380
400
  local transformed
381
- if #values == 1 then
401
+ if num_values == 1 then
382
402
  local value = values[1]
383
403
  local t = ntype(value)
384
404
  if t == "decorated" then
@@ -411,7 +431,7 @@ local Statement = Transformer({
411
431
  end
412
432
  node = transformed or node
413
433
  if destructure.has_destructure(names) then
414
- return destructure.split_assign(node)
434
+ return destructure.split_assign(self, node)
415
435
  end
416
436
  return node
417
437
  end,
@@ -442,7 +462,10 @@ local Statement = Transformer({
442
462
  })
443
463
  else
444
464
  return build.group({
445
- node,
465
+ {
466
+ "export",
467
+ node[2]
468
+ },
446
469
  build.assign({
447
470
  names = node[2],
448
471
  values = node[3]
@@ -474,82 +497,44 @@ local Statement = Transformer({
474
497
  end,
475
498
  import = function(self, node)
476
499
  local _, names, source = unpack(node)
477
- local stubs = (function()
500
+ local table_values
501
+ do
478
502
  local _accum_0 = { }
479
503
  local _len_0 = 1
480
- local _list_0 = names
481
- for _index_0 = 1, #_list_0 do
482
- local name = _list_0[_index_0]
483
- if type(name) == "table" then
484
- _accum_0[_len_0] = name
504
+ for _index_0 = 1, #names do
505
+ local name = names[_index_0]
506
+ local dest_val
507
+ if ntype(name) == "colon_stub" then
508
+ dest_val = name[2]
485
509
  else
486
- _accum_0[_len_0] = {
487
- "dot",
488
- name
489
- }
510
+ dest_val = name
490
511
  end
512
+ local _value_0 = {
513
+ {
514
+ "key_literal",
515
+ name
516
+ },
517
+ dest_val
518
+ }
519
+ _accum_0[_len_0] = _value_0
491
520
  _len_0 = _len_0 + 1
492
521
  end
493
- return _accum_0
494
- end)()
495
- local real_names = (function()
496
- local _accum_0 = { }
497
- local _len_0 = 1
498
- local _list_0 = names
499
- for _index_0 = 1, #_list_0 do
500
- local name = _list_0[_index_0]
501
- _accum_0[_len_0] = type(name) == "table" and name[2] or name
502
- _len_0 = _len_0 + 1
503
- end
504
- return _accum_0
505
- end)()
506
- if type(source) == "string" then
507
- return build.assign({
508
- names = real_names,
509
- values = (function()
510
- local _accum_0 = { }
511
- local _len_0 = 1
512
- local _list_0 = stubs
513
- for _index_0 = 1, #_list_0 do
514
- local stub = _list_0[_index_0]
515
- _accum_0[_len_0] = build.chain({
516
- base = source,
517
- stub
518
- })
519
- _len_0 = _len_0 + 1
520
- end
521
- return _accum_0
522
- end)()
523
- })
524
- else
525
- local source_name = NameProxy("table")
526
- return build.group({
527
- {
528
- "declare",
529
- real_names
530
- },
531
- build["do"]({
532
- build.assign_one(source_name, source),
533
- build.assign({
534
- names = real_names,
535
- values = (function()
536
- local _accum_0 = { }
537
- local _len_0 = 1
538
- local _list_0 = stubs
539
- for _index_0 = 1, #_list_0 do
540
- local stub = _list_0[_index_0]
541
- _accum_0[_len_0] = build.chain({
542
- base = source_name,
543
- stub
544
- })
545
- _len_0 = _len_0 + 1
546
- end
547
- return _accum_0
548
- end)()
549
- })
550
- })
551
- })
522
+ table_values = _accum_0
552
523
  end
524
+ local dest = {
525
+ "table",
526
+ table_values
527
+ }
528
+ return {
529
+ "assign",
530
+ {
531
+ dest
532
+ },
533
+ {
534
+ source
535
+ },
536
+ [-1] = node[-1]
537
+ }
553
538
  end,
554
539
  comprehension = function(self, node, action)
555
540
  local _, exp, clauses = unpack(node)
@@ -646,7 +631,7 @@ local Statement = Transformer({
646
631
  if destructure.has_destructure(assign[2]) then
647
632
  local name = NameProxy("des")
648
633
  body = {
649
- destructure.build_assign(assign[2][1], name),
634
+ destructure.build_assign(self, assign[2][1], name),
650
635
  build.group(node[3])
651
636
  }
652
637
  return build["do"]({
@@ -683,28 +668,38 @@ local Statement = Transformer({
683
668
  return node
684
669
  end,
685
670
  with = function(self, node, ret)
686
- local _, exp, block = unpack(node)
687
- local scope_name = NameProxy("with")
688
- local named_assign
671
+ local exp, block = unpack(node, 2)
672
+ local copy_scope = true
673
+ local scope_name, named_assign
689
674
  if ntype(exp) == "assign" then
690
675
  local names, values = unpack(exp, 2)
691
- local assign_name = names[1]
692
- exp = values[1]
693
- values[1] = scope_name
694
- named_assign = {
695
- "assign",
696
- names,
697
- values
698
- }
676
+ local first_name = names[1]
677
+ if ntype(first_name) == "value" then
678
+ scope_name = first_name
679
+ named_assign = exp
680
+ exp = values[1]
681
+ copy_scope = false
682
+ else
683
+ scope_name = NameProxy("with")
684
+ exp = values[1]
685
+ values[1] = scope_name
686
+ named_assign = {
687
+ "assign",
688
+ names,
689
+ values
690
+ }
691
+ end
692
+ elseif self:is_local(exp) then
693
+ scope_name = exp
694
+ copy_scope = false
699
695
  end
696
+ scope_name = scope_name or NameProxy("with")
700
697
  return build["do"]({
701
698
  Run(function(self)
702
699
  return self:set("scope_var", scope_name)
703
700
  end),
704
- build.assign_one(scope_name, exp),
705
- build.group({
706
- named_assign
707
- }),
701
+ copy_scope and build.assign_one(scope_name, exp) or NOOP,
702
+ named_assign or NOOP,
708
703
  build.group(block),
709
704
  (function()
710
705
  if ret then
@@ -713,28 +708,27 @@ local Statement = Transformer({
713
708
  end)()
714
709
  })
715
710
  end,
716
- foreach = function(self, node)
711
+ foreach = function(self, node, _)
717
712
  smart_node(node)
718
713
  local source = unpack(node.iter)
719
714
  local destructures = { }
720
- node.names = (function()
715
+ do
721
716
  local _accum_0 = { }
722
717
  local _len_0 = 1
723
718
  for i, name in ipairs(node.names) do
724
719
  if ntype(name) == "table" then
725
720
  do
726
- local _with_0 = NameProxy("des")
727
- local proxy = _with_0
728
- insert(destructures, destructure.build_assign(name, proxy))
729
- _accum_0[_len_0] = _with_0
721
+ local proxy = NameProxy("des")
722
+ insert(destructures, destructure.build_assign(self, name, proxy))
723
+ _accum_0[_len_0] = proxy
730
724
  end
731
725
  else
732
726
  _accum_0[_len_0] = name
733
727
  end
734
728
  _len_0 = _len_0 + 1
735
729
  end
736
- return _accum_0
737
- end)()
730
+ node.names = _accum_0
731
+ end
738
732
  if next(destructures) then
739
733
  insert(destructures, build.group(node.body))
740
734
  node.body = destructures
@@ -742,13 +736,16 @@ local Statement = Transformer({
742
736
  if ntype(source) == "unpack" then
743
737
  local list = source[2]
744
738
  local index_name = NameProxy("index")
745
- local list_name = NameProxy("list")
739
+ local list_name = self:is_local(list) and list or NameProxy("list")
746
740
  local slice_var = nil
747
741
  local bounds
748
742
  if is_slice(list) then
749
743
  local slice = list[#list]
750
744
  table.remove(list)
751
745
  table.remove(slice, 1)
746
+ if self:is_local(list) then
747
+ list_name = list
748
+ end
752
749
  if slice[2] and slice[2] ~= "" then
753
750
  local max_tmp_name = NameProxy("max")
754
751
  slice_var = build.assign_one(max_tmp_name, slice[2])
@@ -784,8 +781,8 @@ local Statement = Transformer({
784
781
  }
785
782
  end
786
783
  return build.group({
787
- build.assign_one(list_name, list),
788
- slice_var,
784
+ list_name ~= list and build.assign_one(list_name, list) or NOOP,
785
+ slice_var or NOOP,
789
786
  build["for"]({
790
787
  name = index_name,
791
788
  bounds = bounds,
@@ -794,7 +791,7 @@ local Statement = Transformer({
794
791
  "assign",
795
792
  node.names,
796
793
  {
797
- list_name:index(index_name)
794
+ NameProxy.index(list_name, index_name)
798
795
  }
799
796
  },
800
797
  build.group(node.body)
@@ -855,9 +852,8 @@ local Statement = Transformer({
855
852
  local if_stm = {
856
853
  "if"
857
854
  }
858
- local _list_0 = conds
859
- for _index_0 = 1, #_list_0 do
860
- local cond = _list_0[_index_0]
855
+ for _index_0 = 1, #conds do
856
+ local cond = conds[_index_0]
861
857
  local if_cond = convert_cond(cond)
862
858
  if first then
863
859
  first = false
@@ -874,18 +870,19 @@ local Statement = Transformer({
874
870
  end,
875
871
  class = function(self, node, ret, parent_assign)
876
872
  local _, name, parent_val, body = unpack(node)
873
+ if parent_val == "" then
874
+ parent_val = nil
875
+ end
877
876
  local statements = { }
878
877
  local properties = { }
879
- local _list_0 = body
880
- for _index_0 = 1, #_list_0 do
881
- local item = _list_0[_index_0]
878
+ for _index_0 = 1, #body do
879
+ local item = body[_index_0]
882
880
  local _exp_0 = item[1]
883
881
  if "stm" == _exp_0 then
884
882
  insert(statements, item[2])
885
883
  elseif "props" == _exp_0 then
886
- local _list_1 = item
887
- for _index_1 = 2, #_list_1 do
888
- local tuple = _list_1[_index_1]
884
+ for _index_1 = 2, #item do
885
+ local tuple = item[_index_1]
889
886
  if ntype(tuple[1]) == "self" then
890
887
  insert(statements, build.assign_one(unpack(tuple)))
891
888
  else
@@ -895,14 +892,13 @@ local Statement = Transformer({
895
892
  end
896
893
  end
897
894
  local constructor
898
- properties = (function()
895
+ do
899
896
  local _accum_0 = { }
900
897
  local _len_0 = 1
901
- local _list_1 = properties
902
- for _index_0 = 1, #_list_1 do
898
+ for _index_0 = 1, #properties do
903
899
  local _continue_0 = false
904
900
  repeat
905
- local tuple = _list_1[_index_0]
901
+ local tuple = properties[_index_0]
906
902
  local key = tuple[1]
907
903
  local _value_0
908
904
  if key[1] == "key_literal" and key[2] == constructor_name then
@@ -920,37 +916,36 @@ local Statement = Transformer({
920
916
  break
921
917
  end
922
918
  end
923
- return _accum_0
924
- end)()
919
+ properties = _accum_0
920
+ end
925
921
  local parent_cls_name = NameProxy("parent")
926
922
  local base_name = NameProxy("base")
927
923
  local self_name = NameProxy("self")
928
924
  local cls_name = NameProxy("class")
929
925
  if not (constructor) then
930
- constructor = build.fndef({
931
- args = {
932
- {
933
- "..."
934
- }
935
- },
936
- arrow = "fat",
937
- body = {
938
- build["if"]({
939
- cond = parent_cls_name,
940
- ["then"] = {
941
- build.chain({
942
- base = "super",
926
+ if parent_val then
927
+ constructor = build.fndef({
928
+ args = {
929
+ {
930
+ "..."
931
+ }
932
+ },
933
+ arrow = "fat",
934
+ body = {
935
+ build.chain({
936
+ base = "super",
937
+ {
938
+ "call",
943
939
  {
944
- "call",
945
- {
946
- "..."
947
- }
940
+ "..."
948
941
  }
949
- })
950
- }
951
- })
952
- }
953
- })
942
+ }
943
+ })
944
+ }
945
+ })
946
+ else
947
+ constructor = build.fndef()
948
+ end
954
949
  end
955
950
  local real_name = name or parent_assign and parent_assign[2][1]
956
951
  local _exp_0 = ntype(real_name)
@@ -990,56 +985,60 @@ local Statement = Transformer({
990
985
  "__name",
991
986
  real_name
992
987
  },
993
- {
988
+ parent_val and {
994
989
  "__parent",
995
990
  parent_cls_name
996
- }
997
- })
998
- local class_lookup = build["if"]({
999
- cond = {
1000
- "exp",
1001
- "val",
1002
- "==",
1003
- "nil",
1004
- "and",
1005
- parent_cls_name
1006
- },
1007
- ["then"] = {
1008
- parent_cls_name:index("name")
1009
- }
991
+ } or nil
1010
992
  })
1011
- insert(class_lookup, {
1012
- "else",
1013
- {
1014
- "val"
1015
- }
1016
- })
1017
- local cls_mt = build.table({
1018
- {
1019
- "__index",
1020
- build.fndef({
1021
- args = {
1022
- {
1023
- "cls"
1024
- },
1025
- {
1026
- "name"
1027
- }
993
+ local class_index
994
+ if parent_val then
995
+ local class_lookup = build["if"]({
996
+ cond = {
997
+ "exp",
998
+ "val",
999
+ "==",
1000
+ "nil"
1001
+ },
1002
+ ["then"] = {
1003
+ parent_cls_name:index("name")
1004
+ }
1005
+ })
1006
+ insert(class_lookup, {
1007
+ "else",
1008
+ {
1009
+ "val"
1010
+ }
1011
+ })
1012
+ class_index = build.fndef({
1013
+ args = {
1014
+ {
1015
+ "cls"
1028
1016
  },
1029
- body = {
1030
- build.assign_one(LocalName("val"), build.chain({
1031
- base = "rawget",
1017
+ {
1018
+ "name"
1019
+ }
1020
+ },
1021
+ body = {
1022
+ build.assign_one(LocalName("val"), build.chain({
1023
+ base = "rawget",
1024
+ {
1025
+ "call",
1032
1026
  {
1033
- "call",
1034
- {
1035
- base_name,
1036
- "name"
1037
- }
1027
+ base_name,
1028
+ "name"
1038
1029
  }
1039
- })),
1040
- class_lookup
1041
- }
1042
- })
1030
+ }
1031
+ })),
1032
+ class_lookup
1033
+ }
1034
+ })
1035
+ else
1036
+ class_index = base_name
1037
+ end
1038
+ local cls_mt = build.table({
1039
+ {
1040
+ "__index",
1041
+ class_index
1043
1042
  },
1044
1043
  {
1045
1044
  "__call",
@@ -1090,7 +1089,6 @@ local Statement = Transformer({
1090
1089
  })
1091
1090
  local value = nil
1092
1091
  do
1093
- local _with_0 = build
1094
1092
  local out_body = {
1095
1093
  Run(function(self)
1096
1094
  if name then
@@ -1098,17 +1096,17 @@ local Statement = Transformer({
1098
1096
  end
1099
1097
  return self:set("super", function(block, chain)
1100
1098
  if chain then
1101
- local slice = (function()
1099
+ local slice
1100
+ do
1102
1101
  local _accum_0 = { }
1103
1102
  local _len_0 = 1
1104
- local _list_1 = chain
1105
- for _index_0 = 3, #_list_1 do
1106
- local item = _list_1[_index_0]
1103
+ for _index_0 = 3, #chain do
1104
+ local item = chain[_index_0]
1107
1105
  _accum_0[_len_0] = item
1108
1106
  _len_0 = _len_0 + 1
1109
1107
  end
1110
- return _accum_0
1111
- end)()
1108
+ slice = _accum_0
1109
+ end
1112
1110
  local new_chain = {
1113
1111
  "chain",
1114
1112
  parent_cls_name
@@ -1152,9 +1150,8 @@ local Statement = Transformer({
1152
1150
  }
1153
1151
  }
1154
1152
  end
1155
- local _list_1 = slice
1156
- for _index_0 = 1, #_list_1 do
1157
- local item = _list_1[_index_0]
1153
+ for _index_0 = 1, #slice do
1154
+ local item = slice[_index_0]
1158
1155
  insert(new_chain, item)
1159
1156
  end
1160
1157
  return new_chain
@@ -1167,48 +1164,41 @@ local Statement = Transformer({
1167
1164
  "declare_glob",
1168
1165
  "*"
1169
1166
  },
1170
- _with_0.assign_one(parent_cls_name, parent_val == "" and "nil" or parent_val),
1171
- _with_0.assign_one(base_name, {
1167
+ parent_val and build.assign_one(parent_cls_name, parent_val) or NOOP,
1168
+ build.assign_one(base_name, {
1172
1169
  "table",
1173
1170
  properties
1174
1171
  }),
1175
- _with_0.assign_one(base_name:chain("__index"), base_name),
1176
- _with_0["if"]({
1177
- cond = parent_cls_name,
1178
- ["then"] = {
1179
- _with_0.chain({
1180
- base = "setmetatable",
1181
- {
1182
- "call",
1172
+ build.assign_one(base_name:chain("__index"), base_name),
1173
+ parent_val and build.chain({
1174
+ base = "setmetatable",
1175
+ {
1176
+ "call",
1177
+ {
1178
+ base_name,
1179
+ build.chain({
1180
+ base = parent_cls_name,
1183
1181
  {
1184
- base_name,
1185
- _with_0.chain({
1186
- base = parent_cls_name,
1187
- {
1188
- "dot",
1189
- "__base"
1190
- }
1191
- })
1182
+ "dot",
1183
+ "__base"
1192
1184
  }
1193
- }
1194
- })
1185
+ })
1186
+ }
1195
1187
  }
1196
- }),
1197
- _with_0.assign_one(cls_name, cls),
1198
- _with_0.assign_one(base_name:chain("__class"), cls_name),
1199
- _with_0.group((function()
1188
+ }) or NOOP,
1189
+ build.assign_one(cls_name, cls),
1190
+ build.assign_one(base_name:chain("__class"), cls_name),
1191
+ build.group((function()
1200
1192
  if #statements > 0 then
1201
1193
  return {
1202
- _with_0.assign_one(LocalName("self"), cls_name),
1203
- _with_0.group(statements)
1194
+ build.assign_one(LocalName("self"), cls_name),
1195
+ build.group(statements)
1204
1196
  }
1205
1197
  end
1206
1198
  end)()),
1207
- _with_0["if"]({
1199
+ parent_val and build["if"]({
1208
1200
  cond = {
1209
1201
  "exp",
1210
- parent_cls_name,
1211
- "and",
1212
1202
  parent_cls_name:chain("__inherited")
1213
1203
  },
1214
1204
  ["then"] = {
@@ -1220,11 +1210,11 @@ local Statement = Transformer({
1220
1210
  }
1221
1211
  })
1222
1212
  }
1223
- }),
1224
- _with_0.group((function()
1213
+ }) or NOOP,
1214
+ build.group((function()
1225
1215
  if name then
1226
1216
  return {
1227
- _with_0.assign_one(name, cls_name)
1217
+ build.assign_one(name, cls_name)
1228
1218
  }
1229
1219
  end
1230
1220
  end)()),
@@ -1234,11 +1224,11 @@ local Statement = Transformer({
1234
1224
  end
1235
1225
  end)()
1236
1226
  }
1237
- value = _with_0.group({
1238
- _with_0.group((function()
1227
+ value = build.group({
1228
+ build.group((function()
1239
1229
  if ntype(name) == "value" then
1240
1230
  return {
1241
- _with_0.declare({
1231
+ build.declare({
1242
1232
  names = {
1243
1233
  name
1244
1234
  }
@@ -1246,15 +1236,13 @@ local Statement = Transformer({
1246
1236
  }
1247
1237
  end
1248
1238
  end)()),
1249
- _with_0["do"](out_body)
1239
+ build["do"](out_body)
1250
1240
  })
1251
1241
  end
1252
1242
  return value
1253
1243
  end
1254
1244
  })
1255
- local Accumulator
1256
1245
  do
1257
- local _parent_0 = nil
1258
1246
  local _base_0 = {
1259
1247
  body_idx = {
1260
1248
  ["for"] = 4,
@@ -1266,12 +1254,15 @@ do
1266
1254
  node[index] = self:mutate_body(node[index])
1267
1255
  return self:wrap(node)
1268
1256
  end,
1269
- wrap = function(self, node)
1270
- return build.block_exp({
1257
+ wrap = function(self, node, group_type)
1258
+ if group_type == nil then
1259
+ group_type = "block_exp"
1260
+ end
1261
+ return build[group_type]({
1271
1262
  build.assign_one(self.accum_name, build.table()),
1272
1263
  build.assign_one(self.len_name, 1),
1273
1264
  node,
1274
- self.accum_name
1265
+ group_type == "block_exp" and self.accum_name or NOOP
1275
1266
  })
1276
1267
  end,
1277
1268
  mutate_body = function(self, body)
@@ -1299,7 +1290,7 @@ do
1299
1290
  val = self.value_name
1300
1291
  end
1301
1292
  local update = {
1302
- build.assign_one(self.accum_name:index(self.len_name), val),
1293
+ build.assign_one(NameProxy.index(self.accum_name, self.len_name), val),
1303
1294
  {
1304
1295
  "update",
1305
1296
  self.len_name,
@@ -1312,27 +1303,16 @@ do
1312
1303
  end
1313
1304
  }
1314
1305
  _base_0.__index = _base_0
1315
- if _parent_0 then
1316
- setmetatable(_base_0, _parent_0.__base)
1317
- end
1318
1306
  local _class_0 = setmetatable({
1319
- __init = function(self)
1307
+ __init = function(self, accum_name)
1320
1308
  self.accum_name = NameProxy("accum")
1321
1309
  self.value_name = NameProxy("value")
1322
1310
  self.len_name = NameProxy("len")
1323
1311
  end,
1324
1312
  __base = _base_0,
1325
- __name = "Accumulator",
1326
- __parent = _parent_0
1313
+ __name = "Accumulator"
1327
1314
  }, {
1328
- __index = function(cls, name)
1329
- local val = rawget(_base_0, name)
1330
- if val == nil and _parent_0 then
1331
- return _parent_0[name]
1332
- else
1333
- return val
1334
- end
1335
- end,
1315
+ __index = _base_0,
1336
1316
  __call = function(cls, ...)
1337
1317
  local _self_0 = setmetatable({}, _base_0)
1338
1318
  cls.__init(_self_0, ...)
@@ -1340,12 +1320,8 @@ do
1340
1320
  end
1341
1321
  })
1342
1322
  _base_0.__class = _class_0
1343
- if _parent_0 and _parent_0.__inherited then
1344
- _parent_0.__inherited(_parent_0, _class_0)
1345
- end
1346
1323
  Accumulator = _class_0
1347
1324
  end
1348
- local default_accumulator
1349
1325
  default_accumulator = function(self, node)
1350
1326
  return Accumulator():convert(node)
1351
1327
  end
@@ -1363,7 +1339,7 @@ implicitly_return = function(scope)
1363
1339
  return scope.transform.statement(stm, fn)
1364
1340
  elseif types.manual_return[t] or not types.is_value(stm) then
1365
1341
  if is_top and t == "return" and stm[2] == "" then
1366
- return nil
1342
+ return NOOP
1367
1343
  else
1368
1344
  return stm
1369
1345
  end
@@ -1380,7 +1356,7 @@ implicitly_return = function(scope)
1380
1356
  end
1381
1357
  return fn
1382
1358
  end
1383
- local Value = Transformer({
1359
+ Value = Transformer({
1384
1360
  ["for"] = default_accumulator,
1385
1361
  ["while"] = default_accumulator,
1386
1362
  foreach = default_accumulator,