diff options
author | Li Jin <dragon-fly@qq.com> | 2022-04-06 17:21:36 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-04-06 17:21:57 +0800 |
commit | 49f44f799b39dcc4ffe69502638108398732f8df (patch) | |
tree | 0e9a3ee00aac9f8fdd7ae1c69e9a21ca358d1f34 | |
parent | 1f1af19560054b47935151f298ff06ff2cad5ef9 (diff) | |
download | yuescript-49f44f799b39dcc4ffe69502638108398732f8df.tar.gz yuescript-49f44f799b39dcc4ffe69502638108398732f8df.tar.bz2 yuescript-49f44f799b39dcc4ffe69502638108398732f8df.zip |
adding support for fixing issue #85.
-rw-r--r-- | spec/outputs/class.lua | 134 | ||||
-rw-r--r-- | spec/outputs/export.lua | 16 | ||||
-rw-r--r-- | spec/outputs/global.lua | 4 | ||||
-rw-r--r-- | spec/outputs/local.lua | 12 | ||||
-rw-r--r-- | spec/outputs/vararg.lua | 8 | ||||
-rwxr-xr-x | src/yuescript/yue_compiler.cpp | 16 |
6 files changed, 138 insertions, 52 deletions
diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua index 929c243..8db5a8a 100644 --- a/spec/outputs/class.lua +++ b/spec/outputs/class.lua | |||
@@ -9,7 +9,9 @@ do | |||
9 | return "hello world" | 9 | return "hello world" |
10 | end | 10 | end |
11 | } | 11 | } |
12 | _base_0.__index = _base_0 | 12 | if _base_0.__index == nil then |
13 | _base_0.__index = _base_0 | ||
14 | end | ||
13 | _class_0 = setmetatable({ | 15 | _class_0 = setmetatable({ |
14 | __init = function(self, test, world) | 16 | __init = function(self, test, world) |
15 | self.test = test | 17 | self.test = test |
@@ -40,7 +42,9 @@ do | |||
40 | return print("cool") | 42 | return print("cool") |
41 | end | 43 | end |
42 | } | 44 | } |
43 | _base_0.__index = _base_0 | 45 | if _base_0.__index == nil then |
46 | _base_0.__index = _base_0 | ||
47 | end | ||
44 | _class_0 = setmetatable({ | 48 | _class_0 = setmetatable({ |
45 | __init = function() end, | 49 | __init = function() end, |
46 | __base = _base_0, | 50 | __base = _base_0, |
@@ -61,7 +65,9 @@ do | |||
61 | local _class_0 | 65 | local _class_0 |
62 | local _parent_0 = Simple | 66 | local _parent_0 = Simple |
63 | local _base_0 = { } | 67 | local _base_0 = { } |
64 | _base_0.__index = _base_0 | 68 | if _base_0.__index == nil then |
69 | _base_0.__index = _base_0 | ||
70 | end | ||
65 | setmetatable(_base_0, _parent_0.__base) | 71 | setmetatable(_base_0, _parent_0.__base) |
66 | _class_0 = setmetatable({ | 72 | _class_0 = setmetatable({ |
67 | __init = function(self) | 73 | __init = function(self) |
@@ -104,7 +110,9 @@ do | |||
104 | return print("num", num) | 110 | return print("num", num) |
105 | end | 111 | end |
106 | } | 112 | } |
107 | _base_0.__index = _base_0 | 113 | if _base_0.__index == nil then |
114 | _base_0.__index = _base_0 | ||
115 | end | ||
108 | _class_0 = setmetatable({ | 116 | _class_0 = setmetatable({ |
109 | __init = function(self, arg) | 117 | __init = function(self, arg) |
110 | return print("init arg", arg) | 118 | return print("init arg", arg) |
@@ -130,7 +138,9 @@ do | |||
130 | return _class_0.__parent.__base.cool(self, 120302) | 138 | return _class_0.__parent.__base.cool(self, 120302) |
131 | end | 139 | end |
132 | } | 140 | } |
133 | _base_0.__index = _base_0 | 141 | if _base_0.__index == nil then |
142 | _base_0.__index = _base_0 | ||
143 | end | ||
134 | setmetatable(_base_0, _parent_0.__base) | 144 | setmetatable(_base_0, _parent_0.__base) |
135 | _class_0 = setmetatable({ | 145 | _class_0 = setmetatable({ |
136 | __init = function(self) | 146 | __init = function(self) |
@@ -172,7 +182,9 @@ do | |||
172 | local _base_0 = { | 182 | local _base_0 = { |
173 | something = 20323 | 183 | something = 20323 |
174 | } | 184 | } |
175 | _base_0.__index = _base_0 | 185 | if _base_0.__index == nil then |
186 | _base_0.__index = _base_0 | ||
187 | end | ||
176 | _class_0 = setmetatable({ | 188 | _class_0 = setmetatable({ |
177 | __init = function() end, | 189 | __init = function() end, |
178 | __base = _base_0, | 190 | __base = _base_0, |
@@ -199,7 +211,9 @@ do | |||
199 | return assert(_class_0.__parent == Okay) | 211 | return assert(_class_0.__parent == Okay) |
200 | end | 212 | end |
201 | } | 213 | } |
202 | _base_0.__index = _base_0 | 214 | if _base_0.__index == nil then |
215 | _base_0.__index = _base_0 | ||
216 | end | ||
203 | setmetatable(_base_0, _parent_0.__base) | 217 | setmetatable(_base_0, _parent_0.__base) |
204 | _class_0 = setmetatable({ | 218 | _class_0 = setmetatable({ |
205 | __init = function(self, ...) | 219 | __init = function(self, ...) |
@@ -240,7 +254,9 @@ do | |||
240 | return _class_0.__parent.something(self, 1, 2, 3, 4) | 254 | return _class_0.__parent.something(self, 1, 2, 3, 4) |
241 | end | 255 | end |
242 | } | 256 | } |
243 | _base_0.__index = _base_0 | 257 | if _base_0.__index == nil then |
258 | _base_0.__index = _base_0 | ||
259 | end | ||
244 | _class_0 = setmetatable({ | 260 | _class_0 = setmetatable({ |
245 | __init = function() end, | 261 | __init = function() end, |
246 | __base = _base_0, | 262 | __base = _base_0, |
@@ -264,7 +280,9 @@ do | |||
264 | return print("val:", self.val) | 280 | return print("val:", self.val) |
265 | end | 281 | end |
266 | } | 282 | } |
267 | _base_0.__index = _base_0 | 283 | if _base_0.__index == nil then |
284 | _base_0.__index = _base_0 | ||
285 | end | ||
268 | _class_0 = setmetatable({ | 286 | _class_0 = setmetatable({ |
269 | __init = function() end, | 287 | __init = function() end, |
270 | __base = _base_0, | 288 | __base = _base_0, |
@@ -293,7 +311,9 @@ do | |||
293 | end | 311 | end |
294 | end | 312 | end |
295 | } | 313 | } |
296 | _base_0.__index = _base_0 | 314 | if _base_0.__index == nil then |
315 | _base_0.__index = _base_0 | ||
316 | end | ||
297 | setmetatable(_base_0, _parent_0.__base) | 317 | setmetatable(_base_0, _parent_0.__base) |
298 | _class_0 = setmetatable({ | 318 | _class_0 = setmetatable({ |
299 | __init = function(self, ...) | 319 | __init = function(self, ...) |
@@ -353,7 +373,9 @@ do | |||
353 | return nil | 373 | return nil |
354 | end | 374 | end |
355 | } | 375 | } |
356 | _base_0.__index = _base_0 | 376 | if _base_0.__index == nil then |
377 | _base_0.__index = _base_0 | ||
378 | end | ||
357 | _class_0 = setmetatable({ | 379 | _class_0 = setmetatable({ |
358 | __init = function() end, | 380 | __init = function() end, |
359 | __base = _base_0, | 381 | __base = _base_0, |
@@ -386,7 +408,9 @@ do | |||
386 | blue = function(self) end, | 408 | blue = function(self) end, |
387 | green = function(self) end | 409 | green = function(self) end |
388 | } | 410 | } |
389 | _base_0.__index = _base_0 | 411 | if _base_0.__index == nil then |
412 | _base_0.__index = _base_0 | ||
413 | end | ||
390 | _class_0 = setmetatable({ | 414 | _class_0 = setmetatable({ |
391 | __init = function() end, | 415 | __init = function() end, |
392 | __base = _base_0, | 416 | __base = _base_0, |
@@ -420,7 +444,9 @@ do | |||
420 | local _class_0 | 444 | local _class_0 |
421 | local hello | 445 | local hello |
422 | local _base_0 = { } | 446 | local _base_0 = { } |
423 | _base_0.__index = _base_0 | 447 | if _base_0.__index == nil then |
448 | _base_0.__index = _base_0 | ||
449 | end | ||
424 | _class_0 = setmetatable({ | 450 | _class_0 = setmetatable({ |
425 | __init = function() end, | 451 | __init = function() end, |
426 | __base = _base_0, | 452 | __base = _base_0, |
@@ -453,7 +479,9 @@ yyy = function() | |||
453 | do | 479 | do |
454 | local _class_0 | 480 | local _class_0 |
455 | local _base_0 = { } | 481 | local _base_0 = { } |
456 | _base_0.__index = _base_0 | 482 | if _base_0.__index == nil then |
483 | _base_0.__index = _base_0 | ||
484 | end | ||
457 | _class_0 = setmetatable({ | 485 | _class_0 = setmetatable({ |
458 | __init = function() end, | 486 | __init = function() end, |
459 | __base = _base_0, | 487 | __base = _base_0, |
@@ -476,7 +504,9 @@ end | |||
476 | do | 504 | do |
477 | local _class_0 | 505 | local _class_0 |
478 | local _base_0 = { } | 506 | local _base_0 = { } |
479 | _base_0.__index = _base_0 | 507 | if _base_0.__index == nil then |
508 | _base_0.__index = _base_0 | ||
509 | end | ||
480 | _class_0 = setmetatable({ | 510 | _class_0 = setmetatable({ |
481 | __init = function() end, | 511 | __init = function() end, |
482 | __base = _base_0, | 512 | __base = _base_0, |
@@ -497,7 +527,9 @@ end | |||
497 | do | 527 | do |
498 | local _class_0 | 528 | local _class_0 |
499 | local _base_0 = { } | 529 | local _base_0 = { } |
500 | _base_0.__index = _base_0 | 530 | if _base_0.__index == nil then |
531 | _base_0.__index = _base_0 | ||
532 | end | ||
501 | _class_0 = setmetatable({ | 533 | _class_0 = setmetatable({ |
502 | __init = function() end, | 534 | __init = function() end, |
503 | __base = _base_0, | 535 | __base = _base_0, |
@@ -519,7 +551,9 @@ do | |||
519 | local _class_0 | 551 | local _class_0 |
520 | local _parent_0 = Hello.World | 552 | local _parent_0 = Hello.World |
521 | local _base_0 = { } | 553 | local _base_0 = { } |
522 | _base_0.__index = _base_0 | 554 | if _base_0.__index == nil then |
555 | _base_0.__index = _base_0 | ||
556 | end | ||
523 | setmetatable(_base_0, _parent_0.__base) | 557 | setmetatable(_base_0, _parent_0.__base) |
524 | _class_0 = setmetatable({ | 558 | _class_0 = setmetatable({ |
525 | __init = function(self, ...) | 559 | __init = function(self, ...) |
@@ -560,7 +594,9 @@ local a | |||
560 | do | 594 | do |
561 | local _class_0 | 595 | local _class_0 |
562 | local _base_0 = { } | 596 | local _base_0 = { } |
563 | _base_0.__index = _base_0 | 597 | if _base_0.__index == nil then |
598 | _base_0.__index = _base_0 | ||
599 | end | ||
564 | _class_0 = setmetatable({ | 600 | _class_0 = setmetatable({ |
565 | __init = function() end, | 601 | __init = function() end, |
566 | __base = _base_0, | 602 | __base = _base_0, |
@@ -581,7 +617,9 @@ local Something | |||
581 | do | 617 | do |
582 | local _class_0 | 618 | local _class_0 |
583 | local _base_0 = { } | 619 | local _base_0 = { } |
584 | _base_0.__index = _base_0 | 620 | if _base_0.__index == nil then |
621 | _base_0.__index = _base_0 | ||
622 | end | ||
585 | _class_0 = setmetatable({ | 623 | _class_0 = setmetatable({ |
586 | __init = function() end, | 624 | __init = function() end, |
587 | __base = _base_0, | 625 | __base = _base_0, |
@@ -603,7 +641,9 @@ do | |||
603 | local _class_0 | 641 | local _class_0 |
604 | local _parent_0 = Hello | 642 | local _parent_0 = Hello |
605 | local _base_0 = { } | 643 | local _base_0 = { } |
606 | _base_0.__index = _base_0 | 644 | if _base_0.__index == nil then |
645 | _base_0.__index = _base_0 | ||
646 | end | ||
607 | setmetatable(_base_0, _parent_0.__base) | 647 | setmetatable(_base_0, _parent_0.__base) |
608 | _class_0 = setmetatable({ | 648 | _class_0 = setmetatable({ |
609 | __init = function(self, ...) | 649 | __init = function(self, ...) |
@@ -642,7 +682,9 @@ do | |||
642 | local _class_0 | 682 | local _class_0 |
643 | local _parent_0 = World | 683 | local _parent_0 = World |
644 | local _base_0 = { } | 684 | local _base_0 = { } |
645 | _base_0.__index = _base_0 | 685 | if _base_0.__index == nil then |
686 | _base_0.__index = _base_0 | ||
687 | end | ||
646 | setmetatable(_base_0, _parent_0.__base) | 688 | setmetatable(_base_0, _parent_0.__base) |
647 | _class_0 = setmetatable({ | 689 | _class_0 = setmetatable({ |
648 | __init = function(self, ...) | 690 | __init = function(self, ...) |
@@ -680,7 +722,9 @@ print(((function() | |||
680 | do | 722 | do |
681 | local _class_0 | 723 | local _class_0 |
682 | local _base_0 = { } | 724 | local _base_0 = { } |
683 | _base_0.__index = _base_0 | 725 | if _base_0.__index == nil then |
726 | _base_0.__index = _base_0 | ||
727 | end | ||
684 | _class_0 = setmetatable({ | 728 | _class_0 = setmetatable({ |
685 | __init = function() end, | 729 | __init = function() end, |
686 | __base = _base_0, | 730 | __base = _base_0, |
@@ -701,7 +745,9 @@ end)()).__name) | |||
701 | do | 745 | do |
702 | local _class_0 | 746 | local _class_0 |
703 | local _base_0 = { } | 747 | local _base_0 = { } |
704 | _base_0.__index = _base_0 | 748 | if _base_0.__index == nil then |
749 | _base_0.__index = _base_0 | ||
750 | end | ||
705 | _class_0 = setmetatable({ | 751 | _class_0 = setmetatable({ |
706 | __init = function() end, | 752 | __init = function() end, |
707 | __base = _base_0, | 753 | __base = _base_0, |
@@ -723,7 +769,9 @@ do | |||
723 | local _class_0 | 769 | local _class_0 |
724 | local val, insert | 770 | local val, insert |
725 | local _base_0 = { } | 771 | local _base_0 = { } |
726 | _base_0.__index = _base_0 | 772 | if _base_0.__index == nil then |
773 | _base_0.__index = _base_0 | ||
774 | end | ||
727 | _class_0 = setmetatable({ | 775 | _class_0 = setmetatable({ |
728 | __init = function(self) | 776 | __init = function(self) |
729 | return print(insert, val) | 777 | return print(insert, val) |
@@ -747,7 +795,9 @@ end | |||
747 | do | 795 | do |
748 | local _class_0 | 796 | local _class_0 |
749 | local _base_0 = { } | 797 | local _base_0 = { } |
750 | _base_0.__index = _base_0 | 798 | if _base_0.__index == nil then |
799 | _base_0.__index = _base_0 | ||
800 | end | ||
751 | _class_0 = setmetatable({ | 801 | _class_0 = setmetatable({ |
752 | __init = hi, | 802 | __init = hi, |
753 | __base = _base_0, | 803 | __base = _base_0, |
@@ -778,7 +828,9 @@ do | |||
778 | } | 828 | } |
779 | end | 829 | end |
780 | } | 830 | } |
781 | _base_0.__index = _base_0 | 831 | if _base_0.__index == nil then |
832 | _base_0.__index = _base_0 | ||
833 | end | ||
782 | setmetatable(_base_0, _parent_0.__base) | 834 | setmetatable(_base_0, _parent_0.__base) |
783 | _class_0 = setmetatable({ | 835 | _class_0 = setmetatable({ |
784 | __init = function(self, ...) | 836 | __init = function(self, ...) |
@@ -819,7 +871,9 @@ do | |||
819 | return _class_0.__parent.__base.dang(self) | 871 | return _class_0.__parent.__base.dang(self) |
820 | end) | 872 | end) |
821 | } | 873 | } |
822 | _base_0.__index = _base_0 | 874 | if _base_0.__index == nil then |
875 | _base_0.__index = _base_0 | ||
876 | end | ||
823 | setmetatable(_base_0, _parent_0.__base) | 877 | setmetatable(_base_0, _parent_0.__base) |
824 | _class_0 = setmetatable({ | 878 | _class_0 = setmetatable({ |
825 | __init = function(self, ...) | 879 | __init = function(self, ...) |
@@ -856,7 +910,9 @@ do | |||
856 | local _class_0 | 910 | local _class_0 |
857 | local _parent_0 = Thing | 911 | local _parent_0 = Thing |
858 | local _base_0 = { } | 912 | local _base_0 = { } |
859 | _base_0.__index = _base_0 | 913 | if _base_0.__index == nil then |
914 | _base_0.__index = _base_0 | ||
915 | end | ||
860 | setmetatable(_base_0, _parent_0.__base) | 916 | setmetatable(_base_0, _parent_0.__base) |
861 | _class_0 = setmetatable({ | 917 | _class_0 = setmetatable({ |
862 | __init = function(self, ...) | 918 | __init = function(self, ...) |
@@ -921,7 +977,9 @@ do | |||
921 | return self.__class["if"] and self.__class["do"](self.__class) | 977 | return self.__class["if"] and self.__class["do"](self.__class) |
922 | end | 978 | end |
923 | } | 979 | } |
924 | _base_0.__index = _base_0 | 980 | if _base_0.__index == nil then |
981 | _base_0.__index = _base_0 | ||
982 | end | ||
925 | _class_0 = setmetatable({ | 983 | _class_0 = setmetatable({ |
926 | __init = function(self) | 984 | __init = function(self) |
927 | self.__class["if"] = true | 985 | self.__class["if"] = true |
@@ -958,7 +1016,9 @@ do | |||
958 | return self["if"] and self["do"](self) | 1016 | return self["if"] and self["do"](self) |
959 | end | 1017 | end |
960 | } | 1018 | } |
961 | _base_0.__index = _base_0 | 1019 | if _base_0.__index == nil then |
1020 | _base_0.__index = _base_0 | ||
1021 | end | ||
962 | _class_0 = setmetatable({ | 1022 | _class_0 = setmetatable({ |
963 | __init = function(self) | 1023 | __init = function(self) |
964 | self["if"] = true | 1024 | self["if"] = true |
@@ -991,7 +1051,9 @@ do | |||
991 | } | 1051 | } |
992 | end | 1052 | end |
993 | } | 1053 | } |
994 | _base_0.__index = _base_0 | 1054 | if _base_0.__index == nil then |
1055 | _base_0.__index = _base_0 | ||
1056 | end | ||
995 | setmetatable(_base_0, _parent_0.__base) | 1057 | setmetatable(_base_0, _parent_0.__base) |
996 | _class_0 = setmetatable({ | 1058 | _class_0 = setmetatable({ |
997 | __init = function(self, ...) | 1059 | __init = function(self, ...) |
@@ -1025,6 +1087,9 @@ end | |||
1025 | do | 1087 | do |
1026 | local _class_0 | 1088 | local _class_0 |
1027 | local _base_0 = { } | 1089 | local _base_0 = { } |
1090 | if _base_0.__index == nil then | ||
1091 | _base_0.__index = _base_0 | ||
1092 | end | ||
1028 | local _list_0 = { | 1093 | local _list_0 = { |
1029 | B, | 1094 | B, |
1030 | C, | 1095 | C, |
@@ -1033,12 +1098,11 @@ do | |||
1033 | for _index_0 = 1, #_list_0 do | 1098 | for _index_0 = 1, #_list_0 do |
1034 | local _mixin_0 = _list_0[_index_0] | 1099 | local _mixin_0 = _list_0[_index_0] |
1035 | for _key_0, _val_0 in pairs(_mixin_0.__base) do | 1100 | for _key_0, _val_0 in pairs(_mixin_0.__base) do |
1036 | if not _key_0:match("^__") and _base_0[_key_0] == nil then | 1101 | if _key_0 ~= "__class" then |
1037 | _base_0[_key_0] = _val_0 | 1102 | _base_0[_key_0] = _val_0 |
1038 | end | 1103 | end |
1039 | end | 1104 | end |
1040 | end | 1105 | end |
1041 | _base_0.__index = _base_0 | ||
1042 | _class_0 = setmetatable({ | 1106 | _class_0 = setmetatable({ |
1043 | __init = function() end, | 1107 | __init = function() end, |
1044 | __base = _base_0, | 1108 | __base = _base_0, |
@@ -1057,7 +1121,9 @@ end | |||
1057 | do | 1121 | do |
1058 | local _class_0 | 1122 | local _class_0 |
1059 | local _base_0 = { } | 1123 | local _base_0 = { } |
1060 | _base_0.__index = _base_0 | 1124 | if _base_0.__index == nil then |
1125 | _base_0.__index = _base_0 | ||
1126 | end | ||
1061 | _class_0 = setmetatable({ | 1127 | _class_0 = setmetatable({ |
1062 | __init = function() end, | 1128 | __init = function() end, |
1063 | __base = _base_0, | 1129 | __base = _base_0, |
diff --git a/spec/outputs/export.lua b/spec/outputs/export.lua index 4d81cc0..84e5424 100644 --- a/spec/outputs/export.lua +++ b/spec/outputs/export.lua | |||
@@ -13,7 +13,9 @@ do | |||
13 | local _base_0 = { | 13 | local _base_0 = { |
14 | umm = "cool" | 14 | umm = "cool" |
15 | } | 15 | } |
16 | _base_0.__index = _base_0 | 16 | if _base_0.__index == nil then |
17 | _base_0.__index = _base_0 | ||
18 | end | ||
17 | _class_0 = setmetatable({ | 19 | _class_0 = setmetatable({ |
18 | __init = function() end, | 20 | __init = function() end, |
19 | __base = _base_0, | 21 | __base = _base_0, |
@@ -168,7 +170,9 @@ f((function() | |||
168 | do | 170 | do |
169 | local _class_0 | 171 | local _class_0 |
170 | local _base_0 = { } | 172 | local _base_0 = { } |
171 | _base_0.__index = _base_0 | 173 | if _base_0.__index == nil then |
174 | _base_0.__index = _base_0 | ||
175 | end | ||
172 | _class_0 = setmetatable({ | 176 | _class_0 = setmetatable({ |
173 | __init = function() end, | 177 | __init = function() end, |
174 | __base = _base_0, | 178 | __base = _base_0, |
@@ -264,7 +268,9 @@ _ = tostring((function() | |||
264 | do | 268 | do |
265 | local _class_0 | 269 | local _class_0 |
266 | local _base_0 = { } | 270 | local _base_0 = { } |
267 | _base_0.__index = _base_0 | 271 | if _base_0.__index == nil then |
272 | _base_0.__index = _base_0 | ||
273 | end | ||
268 | _class_0 = setmetatable({ | 274 | _class_0 = setmetatable({ |
269 | __init = function() end, | 275 | __init = function() end, |
270 | __base = _base_0, | 276 | __base = _base_0, |
@@ -289,7 +295,9 @@ _module_0["v2"] = v2 | |||
289 | do | 295 | do |
290 | local _class_0 | 296 | local _class_0 |
291 | local _base_0 = { } | 297 | local _base_0 = { } |
292 | _base_0.__index = _base_0 | 298 | if _base_0.__index == nil then |
299 | _base_0.__index = _base_0 | ||
300 | end | ||
293 | _class_0 = setmetatable({ | 301 | _class_0 = setmetatable({ |
294 | __init = function() end, | 302 | __init = function() end, |
295 | __base = _base_0, | 303 | __base = _base_0, |
diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua index 1c9a3cf..ef73823 100644 --- a/spec/outputs/global.lua +++ b/spec/outputs/global.lua | |||
@@ -8,7 +8,9 @@ do | |||
8 | local _base_0 = { | 8 | local _base_0 = { |
9 | umm = "cool" | 9 | umm = "cool" |
10 | } | 10 | } |
11 | _base_0.__index = _base_0 | 11 | if _base_0.__index == nil then |
12 | _base_0.__index = _base_0 | ||
13 | end | ||
12 | _class_0 = setmetatable({ | 14 | _class_0 = setmetatable({ |
13 | __init = function() end, | 15 | __init = function() end, |
14 | __base = _base_0, | 16 | __base = _base_0, |
diff --git a/spec/outputs/local.lua b/spec/outputs/local.lua index 288764a..524d9ef 100644 --- a/spec/outputs/local.lua +++ b/spec/outputs/local.lua | |||
@@ -78,7 +78,9 @@ do | |||
78 | local _class_0 | 78 | local _class_0 |
79 | local Five | 79 | local Five |
80 | local _base_0 = { } | 80 | local _base_0 = { } |
81 | _base_0.__index = _base_0 | 81 | if _base_0.__index == nil then |
82 | _base_0.__index = _base_0 | ||
83 | end | ||
82 | _class_0 = setmetatable({ | 84 | _class_0 = setmetatable({ |
83 | __init = function() end, | 85 | __init = function() end, |
84 | __base = _base_0, | 86 | __base = _base_0, |
@@ -100,7 +102,9 @@ do | |||
100 | local _class_0 | 102 | local _class_0 |
101 | local No | 103 | local No |
102 | local _base_0 = { } | 104 | local _base_0 = { } |
103 | _base_0.__index = _base_0 | 105 | if _base_0.__index == nil then |
106 | _base_0.__index = _base_0 | ||
107 | end | ||
104 | _class_0 = setmetatable({ | 108 | _class_0 = setmetatable({ |
105 | __init = function() end, | 109 | __init = function() end, |
106 | __base = _base_0, | 110 | __base = _base_0, |
@@ -118,7 +122,9 @@ do | |||
118 | do | 122 | do |
119 | local _class_1 | 123 | local _class_1 |
120 | local _base_1 = { } | 124 | local _base_1 = { } |
121 | _base_1.__index = _base_1 | 125 | if _base_1.__index == nil then |
126 | _base_1.__index = _base_1 | ||
127 | end | ||
122 | _class_1 = setmetatable({ | 128 | _class_1 = setmetatable({ |
123 | __init = function() end, | 129 | __init = function() end, |
124 | __base = _base_1, | 130 | __base = _base_1, |
diff --git a/spec/outputs/vararg.lua b/spec/outputs/vararg.lua index 052fce3..56e2011 100644 --- a/spec/outputs/vararg.lua +++ b/spec/outputs/vararg.lua | |||
@@ -55,7 +55,9 @@ join = function(...) | |||
55 | do | 55 | do |
56 | local _class_0 | 56 | local _class_0 |
57 | local _base_0 = { } | 57 | local _base_0 = { } |
58 | _base_0.__index = _base_0 | 58 | if _base_0.__index == nil then |
59 | _base_0.__index = _base_0 | ||
60 | end | ||
59 | _class_0 = setmetatable({ | 61 | _class_0 = setmetatable({ |
60 | __init = function() end, | 62 | __init = function() end, |
61 | __base = _base_0, | 63 | __base = _base_0, |
@@ -80,7 +82,9 @@ join = function(...) | |||
80 | do | 82 | do |
81 | local _class_0 | 83 | local _class_0 |
82 | local _base_0 = { } | 84 | local _base_0 = { } |
83 | _base_0.__index = _base_0 | 85 | if _base_0.__index == nil then |
86 | _base_0.__index = _base_0 | ||
87 | end | ||
84 | _class_0 = setmetatable({ | 88 | _class_0 = setmetatable({ |
85 | __init = function() end, | 89 | __init = function() end, |
86 | __base = _base_0, | 90 | __base = _base_0, |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 3720915..3394f1f 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -60,7 +60,7 @@ using namespace parserlib; | |||
60 | 60 | ||
61 | typedef std::list<std::string> str_list; | 61 | typedef std::list<std::string> str_list; |
62 | 62 | ||
63 | const std::string_view version = "0.10.9"sv; | 63 | const std::string_view version = "0.10.10"sv; |
64 | const std::string_view extension = "yue"sv; | 64 | const std::string_view extension = "yue"sv; |
65 | 65 | ||
66 | class YueCompilerImpl { | 66 | class YueCompilerImpl { |
@@ -5268,7 +5268,7 @@ private: | |||
5268 | if (clsDecl) { | 5268 | if (clsDecl) { |
5269 | std::string clsName; | 5269 | std::string clsName; |
5270 | bool newDefined = false; | 5270 | bool newDefined = false; |
5271 | std::tie(clsName,newDefined) = defineClassVariable(clsDecl->name); | 5271 | std::tie(clsName, newDefined) = defineClassVariable(clsDecl->name); |
5272 | if (newDefined) varDefs.push_back(clsName); | 5272 | if (newDefined) varDefs.push_back(clsName); |
5273 | } | 5273 | } |
5274 | } | 5274 | } |
@@ -5337,17 +5337,17 @@ private: | |||
5337 | } else { | 5337 | } else { |
5338 | temp.back() += "{ }"s + nll(classDecl); | 5338 | temp.back() += "{ }"s + nll(classDecl); |
5339 | } | 5339 | } |
5340 | transformAssignment(toAst<ExpListAssign_t>(baseVar + ".__index ?\?= "s + baseVar, classDecl), temp); | ||
5340 | if (classDecl->mixes) { | 5341 | if (classDecl->mixes) { |
5341 | auto mixin = getUnusedName("_mixin_"); | 5342 | auto mixin = getUnusedName("_mixin_"sv); |
5342 | auto key = getUnusedName("_key_"); | 5343 | auto key = getUnusedName("_key_"sv); |
5343 | auto val = getUnusedName("_val_"); | 5344 | auto val = getUnusedName("_val_"sv); |
5344 | auto mixins = _parser.toString(classDecl->mixes); | 5345 | auto mixins = _parser.toString(classDecl->mixes); |
5345 | _buf << "for "sv << mixin << " in *{"sv << mixins << "}\n"sv; | 5346 | _buf << "for "sv << mixin << " in *{"sv << mixins << "}\n"sv; |
5346 | _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << ".__base\n"sv; | 5347 | _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << ".__base\n"sv; |
5347 | _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if not "sv << key << "\\match\"^__\" and "sv << baseVar << '[' << key << "] == nil"sv; | 5348 | _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if "sv << key << "~=\"__class\""sv; |
5348 | transformBlock(toAst<Block_t>(clearBuf(), x), temp, ExpUsage::Common); | 5349 | transformBlock(toAst<Block_t>(clearBuf(), x), temp, ExpUsage::Common); |
5349 | } | 5350 | } |
5350 | temp.push_back(indent() + baseVar + ".__index = "s + baseVar + nll(classDecl)); | ||
5351 | str_list tmp; | 5351 | str_list tmp; |
5352 | if (usage == ExpUsage::Assignment) { | 5352 | if (usage == ExpUsage::Assignment) { |
5353 | auto assign = x->new_ptr<Assign_t>(); | 5353 | auto assign = x->new_ptr<Assign_t>(); |
@@ -5366,7 +5366,7 @@ private: | |||
5366 | } else { | 5366 | } else { |
5367 | if (extend) { | 5367 | if (extend) { |
5368 | _buf << indent(1) << "__init = function(self, ...)"sv << nll(classDecl); | 5368 | _buf << indent(1) << "__init = function(self, ...)"sv << nll(classDecl); |
5369 | _buf << indent(2) << "return _class_0.__parent.__init(self, ...)"sv << nll(classDecl); | 5369 | _buf << indent(2) << "return "sv << classVar << ".__parent.__init(self, ...)"sv << nll(classDecl); |
5370 | _buf << indent(1) << "end,"sv << nll(classDecl); | 5370 | _buf << indent(1) << "end,"sv << nll(classDecl); |
5371 | } else { | 5371 | } else { |
5372 | _buf << indent(1) << "__init = function() end,"sv << nll(classDecl); | 5372 | _buf << indent(1) << "__init = function() end,"sv << nll(classDecl); |