diff options
| author | Li Jin <dragon-fly@qq.com> | 2021-10-12 10:04:44 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2021-10-12 10:04:44 +0800 |
| commit | 60a979e224f26117f5be82bfca757a2483cef0fd (patch) | |
| tree | 7c6af44f6dcada1f23979b820ba830251997b161 | |
| parent | a19b242cbaf53721b20a3163dd06f43e9ef2b487 (diff) | |
| download | yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.gz yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.bz2 yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.zip | |
fix test.
Diffstat (limited to '')
44 files changed, 6413 insertions, 5 deletions
| @@ -2,7 +2,6 @@ yue | |||
| 2 | !src/yuescript/ | 2 | !src/yuescript/ |
| 3 | build | 3 | build |
| 4 | build.luarocks | 4 | build.luarocks |
| 5 | spec/outputs | ||
| 6 | yuescript-*.rock* | 5 | yuescript-*.rock* |
| 7 | !yuescript-dev-1.rockspec | 6 | !yuescript-dev-1.rockspec |
| 8 | .vs | 7 | .vs |
| @@ -29,7 +29,11 @@ DESTDIR = / | |||
| 29 | INSTALL_PREFIX = usr/local | 29 | INSTALL_PREFIX = usr/local |
| 30 | # Test | 30 | # Test |
| 31 | TEST_INPUT = ./spec/inputs | 31 | TEST_INPUT = ./spec/inputs |
| 32 | TEST_OUTPUT = ./spec/outputs | 32 | TEST_OUTPUT = ./spec/generated |
| 33 | GEN_OUTPUT = ./spec/outputs | ||
| 34 | |||
| 35 | PLAT = macos | ||
| 36 | |||
| 33 | #### END PROJECT SETTINGS #### | 37 | #### END PROJECT SETTINGS #### |
| 34 | 38 | ||
| 35 | # Optionally you may move the section above to a separate config.mk file, and | 39 | # Optionally you may move the section above to a separate config.mk file, and |
| @@ -54,6 +58,7 @@ endif | |||
| 54 | # Add platform related linker flag | 58 | # Add platform related linker flag |
| 55 | ifneq ($(UNAME_S),Darwin) | 59 | ifneq ($(UNAME_S),Darwin) |
| 56 | LINK_FLAGS += -lstdc++fs -Wl,-E | 60 | LINK_FLAGS += -lstdc++fs -Wl,-E |
| 61 | PLAT = linux | ||
| 57 | endif | 62 | endif |
| 58 | 63 | ||
| 59 | # Function used to check variables. Use on the command line: | 64 | # Function used to check variables. Use on the command line: |
| @@ -179,7 +184,7 @@ else | |||
| 179 | @echo "Beginning release build" | 184 | @echo "Beginning release build" |
| 180 | endif | 185 | endif |
| 181 | ifneq ($(NO_LUA),true) | 186 | ifneq ($(NO_LUA),true) |
| 182 | @$(MAKE) generic -C $(SRC_PATH)/3rdParty/lua | 187 | @$(MAKE) $(PLAT) -C $(SRC_PATH)/3rdParty/lua |
| 183 | endif | 188 | endif |
| 184 | @$(START_TIME) | 189 | @$(START_TIME) |
| 185 | @$(MAKE) all --no-print-directory | 190 | @$(MAKE) all --no-print-directory |
| @@ -231,7 +236,6 @@ dirs: | |||
| 231 | @echo "Creating directories" | 236 | @echo "Creating directories" |
| 232 | @mkdir -p $(dir $(OBJECTS)) | 237 | @mkdir -p $(dir $(OBJECTS)) |
| 233 | @mkdir -p $(BIN_PATH) | 238 | @mkdir -p $(BIN_PATH) |
| 234 | @mkdir -p $(TEST_OUTPUT) | ||
| 235 | 239 | ||
| 236 | # Installs to the set path | 240 | # Installs to the set path |
| 237 | .PHONY: install | 241 | .PHONY: install |
| @@ -254,18 +258,31 @@ clean: | |||
| 254 | @echo "Deleting directories" | 258 | @echo "Deleting directories" |
| 255 | @$(RM) -r build | 259 | @$(RM) -r build |
| 256 | @$(RM) -r bin | 260 | @$(RM) -r bin |
| 257 | @echo "Deleting generated Lua codes" | ||
| 258 | @$(RM) -r $(TEST_OUTPUT) | 261 | @$(RM) -r $(TEST_OUTPUT) |
| 259 | 262 | ||
| 260 | # Test Yuescript compiler | 263 | # Test Yuescript compiler |
| 261 | .PHONY: test | 264 | .PHONY: test |
| 262 | test: release | 265 | test: release |
| 266 | @mkdir -p $(TEST_OUTPUT) | ||
| 263 | @echo "Compiling Yuescript codes..." | 267 | @echo "Compiling Yuescript codes..." |
| 264 | @$(START_TIME) | 268 | @$(START_TIME) |
| 265 | @./$(BIN_NAME) $(TEST_INPUT) -t $(TEST_OUTPUT) -tl_enabled=true | 269 | @./$(BIN_NAME) $(TEST_INPUT) -t $(TEST_OUTPUT) -tl_enabled=true |
| 266 | @./$(BIN_NAME) $(TEST_INPUT)/teal-lang.yue -o $(TEST_OUTPUT)/teal-lang.lua | 270 | @./$(BIN_NAME) $(TEST_INPUT)/teal-lang.yue -o $(TEST_OUTPUT)/teal-lang.lua |
| 267 | @echo -en "Compile time: " | 271 | @echo -en "Compile time: " |
| 268 | @$(END_TIME) | 272 | @$(END_TIME) |
| 273 | @./$(BIN_NAME) -e "$$(printf "r = io.popen('git diff --no-index $(TEST_OUTPUT) $(GEN_OUTPUT) | head -5')\\\\read '*a'\nif r ~= ''\n print r\n os.exit 1")" | ||
| 274 | @$(RM) -r $(TEST_OUTPUT) | ||
| 275 | @echo "Done!" | ||
| 276 | |||
| 277 | # Test Yuescript compiler | ||
| 278 | .PHONY: gen | ||
| 279 | gen: release | ||
| 280 | @echo "Compiling Yuescript codes..." | ||
| 281 | @$(START_TIME) | ||
| 282 | @./$(BIN_NAME) $(TEST_INPUT) -t $(GEN_OUTPUT) -tl_enabled=true | ||
| 283 | @./$(BIN_NAME) $(TEST_INPUT)/teal-lang.yue -o $(GEN_OUTPUT)/teal-lang.lua | ||
| 284 | @echo -en "Compile time: " | ||
| 285 | @$(END_TIME) | ||
| 269 | 286 | ||
| 270 | # Main rule, checks the executable and symlinks to the output | 287 | # Main rule, checks the executable and symlinks to the output |
| 271 | all: $(BIN_PATH)/$(BIN_NAME) | 288 | all: $(BIN_PATH)/$(BIN_NAME) |
diff --git a/spec/outputs/ambiguous.lua b/spec/outputs/ambiguous.lua new file mode 100644 index 0000000..6039d73 --- /dev/null +++ b/spec/outputs/ambiguous.lua | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | local bind = grasp.bind; | ||
| 2 | (bind(stmt))({ | ||
| 3 | color = "Red" | ||
| 4 | }) | ||
| 5 | local a = 'b' | ||
| 6 | local c = d; | ||
| 7 | (a(b))(c(d)) | ||
| 8 | c = d.c; | ||
| 9 | (a(b))(c(d)); | ||
| 10 | (c(d))(a(b)) | ||
| 11 | local b | ||
| 12 | a, b = c, d; | ||
| 13 | (d(a))(c) | ||
| 14 | for i = 1, 10 do | ||
| 15 | a = function() end | ||
| 16 | (print)(1) | ||
| 17 | a = f; | ||
| 18 | (print)(2) | ||
| 19 | if cond then | ||
| 20 | (print)(3) | ||
| 21 | end | ||
| 22 | ::abc::; | ||
| 23 | (print)(4) | ||
| 24 | goto abc; | ||
| 25 | (print)(5) | ||
| 26 | end | ||
| 27 | do | ||
| 28 | print(123) | ||
| 29 | end | ||
| 30 | return nil | ||
diff --git a/spec/outputs/assign.lua b/spec/outputs/assign.lua new file mode 100644 index 0000000..628f763 --- /dev/null +++ b/spec/outputs/assign.lua | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | local _ | ||
| 2 | _ = function() | ||
| 3 | local joop = 2302 | ||
| 4 | return function(hi) | ||
| 5 | local d = 100 | ||
| 6 | hi = 1021 | ||
| 7 | local a, b, c | ||
| 8 | a, b, c, d = 1, 2, 3, 4 | ||
| 9 | local hello | ||
| 10 | hello[232], (5 + 5)[121], hello, x[99] = 100, 200, 300 | ||
| 11 | joop = 12 | ||
| 12 | end | ||
| 13 | end | ||
| 14 | local joop = 2345 | ||
| 15 | local a, b | ||
| 16 | if hello then | ||
| 17 | a, b = "hello" | ||
| 18 | else | ||
| 19 | a, b = "nothing", "yeah" | ||
| 20 | end | ||
| 21 | if hello then | ||
| 22 | if yeah then | ||
| 23 | a, b = "one", "two" | ||
| 24 | else | ||
| 25 | a, b = "mmhh" | ||
| 26 | end | ||
| 27 | else | ||
| 28 | print("the other") | ||
| 29 | a, b = "nothing", "yeah" | ||
| 30 | end | ||
| 31 | local c, d | ||
| 32 | if true then | ||
| 33 | c, d = 1, 2 | ||
| 34 | end | ||
| 35 | local x | ||
| 36 | do | ||
| 37 | local f = getHandler() | ||
| 38 | if f then | ||
| 39 | x = ((function() | ||
| 40 | f() | ||
| 41 | return 123 | ||
| 42 | end)()) | ||
| 43 | end | ||
| 44 | end | ||
diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua new file mode 100644 index 0000000..d9ac3f2 --- /dev/null +++ b/spec/outputs/attrib.lua | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | do | ||
| 2 | local a <close>, b <close> = setmetatable({ }, { | ||
| 3 | __close = function(self) | ||
| 4 | return print("closed") | ||
| 5 | end | ||
| 6 | }) | ||
| 7 | local c <const>, d <const> = 123, 'abc' | ||
| 8 | close(a, b) | ||
| 9 | const(c, d) | ||
| 10 | end | ||
| 11 | do | ||
| 12 | local v <close> = (function() | ||
| 13 | if flag then | ||
| 14 | return func() | ||
| 15 | else | ||
| 16 | return setmetatable({ }, { | ||
| 17 | __close = function(self) end | ||
| 18 | }) | ||
| 19 | end | ||
| 20 | end)() | ||
| 21 | local f <close> = (function() | ||
| 22 | local _with_0 = io.open("file.txt") | ||
| 23 | _with_0:write("Hello") | ||
| 24 | return _with_0 | ||
| 25 | end)() | ||
| 26 | end | ||
| 27 | do | ||
| 28 | local _ <close> = (function() | ||
| 29 | local _with_0 = io.open("file.txt") | ||
| 30 | _with_0:write("Hello") | ||
| 31 | return _with_0 | ||
| 32 | end)(); | ||
| 33 | local _ <close> = setmetatable({ }, { | ||
| 34 | __close = function(self) | ||
| 35 | return print("second") | ||
| 36 | end | ||
| 37 | }); | ||
| 38 | local _ <close> = setmetatable({ }, { | ||
| 39 | __close = function() | ||
| 40 | return print("first") | ||
| 41 | end | ||
| 42 | }) | ||
| 43 | end | ||
| 44 | local _defers = setmetatable({ }, { | ||
| 45 | __close = function(self) | ||
| 46 | self[#self]() | ||
| 47 | self[#self] = nil | ||
| 48 | end | ||
| 49 | }) | ||
| 50 | do | ||
| 51 | _defers[#_defers + 1] = function() | ||
| 52 | return print(3) | ||
| 53 | end | ||
| 54 | local _ <close> = _defers; | ||
| 55 | _defers[#_defers + 1] = function() | ||
| 56 | return print(2) | ||
| 57 | end | ||
| 58 | local _ <close> = _defers; | ||
| 59 | _defers[#_defers + 1] = function() | ||
| 60 | return print(1) | ||
| 61 | end | ||
| 62 | local _ <close> = _defers | ||
| 63 | end | ||
diff --git a/spec/outputs/backcall.lua b/spec/outputs/backcall.lua new file mode 100644 index 0000000..9f7ec29 --- /dev/null +++ b/spec/outputs/backcall.lua | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | do | ||
| 2 | map({ | ||
| 3 | 1, | ||
| 4 | 2, | ||
| 5 | 3 | ||
| 6 | }, function(x) | ||
| 7 | return x * 2 | ||
| 8 | end) | ||
| 9 | end | ||
| 10 | do | ||
| 11 | map(function(x) | ||
| 12 | return x * 2 | ||
| 13 | end, { | ||
| 14 | 1, | ||
| 15 | 2, | ||
| 16 | 3 | ||
| 17 | }) | ||
| 18 | end | ||
| 19 | do | ||
| 20 | filter(function(x) | ||
| 21 | return x > 2 | ||
| 22 | end, (function() | ||
| 23 | return map(function(x) | ||
| 24 | return x * 2 | ||
| 25 | end, { | ||
| 26 | 1, | ||
| 27 | 2, | ||
| 28 | 3, | ||
| 29 | 4 | ||
| 30 | }) | ||
| 31 | end)()) | ||
| 32 | end | ||
| 33 | do | ||
| 34 | if http ~= nil then | ||
| 35 | http.get("ajaxtest", function(data) | ||
| 36 | body[".result"]:html(data) | ||
| 37 | return http.post("ajaxprocess", data, function(processed) | ||
| 38 | body[".result"]:append(processed) | ||
| 39 | return setTimeout(1000, function() | ||
| 40 | return print("done") | ||
| 41 | end) | ||
| 42 | end) | ||
| 43 | end) | ||
| 44 | end | ||
| 45 | end | ||
| 46 | do | ||
| 47 | syncStatus(function() | ||
| 48 | return loadAsync("file.yue", function(err, data) | ||
| 49 | if data == nil then | ||
| 50 | data = "nil" | ||
| 51 | end | ||
| 52 | if err then | ||
| 53 | print(err) | ||
| 54 | return | ||
| 55 | end | ||
| 56 | return compileAsync(data, function(codes) | ||
| 57 | local func = loadstring(codes) | ||
| 58 | return func() | ||
| 59 | end) | ||
| 60 | end) | ||
| 61 | end) | ||
| 62 | end | ||
| 63 | do | ||
| 64 | f1(function() | ||
| 65 | return f2(function() | ||
| 66 | do | ||
| 67 | f3(function() | ||
| 68 | return f4(function() end) | ||
| 69 | end) | ||
| 70 | end | ||
| 71 | return f5(function() | ||
| 72 | return f6(function() | ||
| 73 | return f7() | ||
| 74 | end) | ||
| 75 | end) | ||
| 76 | end) | ||
| 77 | end) | ||
| 78 | end | ||
| 79 | do | ||
| 80 | local result, msg | ||
| 81 | do | ||
| 82 | do | ||
| 83 | local _obj_0 = receiveAsync("filename.txt", function(data) | ||
| 84 | print(data) | ||
| 85 | return processAsync(data, function(info) | ||
| 86 | return check(info) | ||
| 87 | end) | ||
| 88 | end) | ||
| 89 | result, msg = _obj_0.result, _obj_0.msg | ||
| 90 | end | ||
| 91 | end | ||
| 92 | print(result, msg) | ||
| 93 | local totalSize = reduce(((function() | ||
| 94 | local _accum_0 = { } | ||
| 95 | local _len_0 = 1 | ||
| 96 | local _list_0 = files | ||
| 97 | for _index_0 = 1, #_list_0 do | ||
| 98 | local file = _list_0[_index_0] | ||
| 99 | _accum_0[_len_0] = loadAsync(file, function(data) | ||
| 100 | return addToCache(file, data) | ||
| 101 | end) | ||
| 102 | _len_0 = _len_0 + 1 | ||
| 103 | end | ||
| 104 | return _accum_0 | ||
| 105 | end)()), 0, function(a, b) | ||
| 106 | return a + b | ||
| 107 | end) | ||
| 108 | end | ||
| 109 | local propA | ||
| 110 | do | ||
| 111 | propA = property(function(self) | ||
| 112 | return self._value | ||
| 113 | end, function(self, value) | ||
| 114 | print("old value: " .. tostring(self._value)) | ||
| 115 | print("new value: " .. tostring(value)) | ||
| 116 | self._value = value | ||
| 117 | end) | ||
| 118 | end | ||
| 119 | local propB | ||
| 120 | do | ||
| 121 | propB = property(function(self) | ||
| 122 | return self._value | ||
| 123 | end, function(self, value) | ||
| 124 | print("old value: " .. tostring(self._value)) | ||
| 125 | print("new value: " .. tostring(value)) | ||
| 126 | self._value = value | ||
| 127 | end) | ||
| 128 | end | ||
| 129 | alert("hi") | ||
| 130 | return nil | ||
diff --git a/spec/outputs/bubbling.lua b/spec/outputs/bubbling.lua new file mode 100644 index 0000000..7cb93c7 --- /dev/null +++ b/spec/outputs/bubbling.lua | |||
| @@ -0,0 +1,123 @@ | |||
| 1 | local f | ||
| 2 | f = function(...) | ||
| 3 | return #{ | ||
| 4 | ... | ||
| 5 | } | ||
| 6 | end | ||
| 7 | local dont_bubble | ||
| 8 | dont_bubble = function() | ||
| 9 | local _accum_0 = { } | ||
| 10 | local _len_0 = 1 | ||
| 11 | for x in (function(...) | ||
| 12 | return print(...) | ||
| 13 | end)("hello") do | ||
| 14 | _accum_0[_len_0] = x | ||
| 15 | _len_0 = _len_0 + 1 | ||
| 16 | end | ||
| 17 | return _accum_0 | ||
| 18 | end | ||
| 19 | local k | ||
| 20 | do | ||
| 21 | local _accum_0 = { } | ||
| 22 | local _len_0 = 1 | ||
| 23 | for x in (function(...) | ||
| 24 | return print(...) | ||
| 25 | end)("hello") do | ||
| 26 | _accum_0[_len_0] = x | ||
| 27 | _len_0 = _len_0 + 1 | ||
| 28 | end | ||
| 29 | k = _accum_0 | ||
| 30 | end | ||
| 31 | local j | ||
| 32 | do | ||
| 33 | local _accum_0 = { } | ||
| 34 | local _len_0 = 1 | ||
| 35 | for i = 1, 10 do | ||
| 36 | _accum_0[_len_0] = function(...) | ||
| 37 | return print(...) | ||
| 38 | end | ||
| 39 | _len_0 = _len_0 + 1 | ||
| 40 | end | ||
| 41 | j = _accum_0 | ||
| 42 | end | ||
| 43 | local m | ||
| 44 | m = function(...) | ||
| 45 | local _accum_0 = { } | ||
| 46 | local _len_0 = 1 | ||
| 47 | local _list_0 = { | ||
| 48 | ... | ||
| 49 | } | ||
| 50 | for _index_0 = 1, #_list_0 do | ||
| 51 | local x = _list_0[_index_0] | ||
| 52 | if f(...) > 4 then | ||
| 53 | _accum_0[_len_0] = x | ||
| 54 | _len_0 = _len_0 + 1 | ||
| 55 | end | ||
| 56 | end | ||
| 57 | return _accum_0 | ||
| 58 | end | ||
| 59 | local _ | ||
| 60 | _ = function(...) | ||
| 61 | local x | ||
| 62 | do | ||
| 63 | local _accum_0 = { } | ||
| 64 | local _len_0 = 1 | ||
| 65 | local _list_0 = { | ||
| 66 | ... | ||
| 67 | } | ||
| 68 | for _index_0 = 1, #_list_0 do | ||
| 69 | local i = _list_0[_index_0] | ||
| 70 | _accum_0[_len_0] = i | ||
| 71 | _len_0 = _len_0 + 1 | ||
| 72 | end | ||
| 73 | x = _accum_0 | ||
| 74 | end | ||
| 75 | local y | ||
| 76 | do | ||
| 77 | local _accum_0 = { } | ||
| 78 | local _len_0 = 1 | ||
| 79 | local _list_0 = { | ||
| 80 | ... | ||
| 81 | } | ||
| 82 | for _index_0 = 1, #_list_0 do | ||
| 83 | local x = _list_0[_index_0] | ||
| 84 | _accum_0[_len_0] = x | ||
| 85 | _len_0 = _len_0 + 1 | ||
| 86 | end | ||
| 87 | y = _accum_0 | ||
| 88 | end | ||
| 89 | local z | ||
| 90 | do | ||
| 91 | local _accum_0 = { } | ||
| 92 | local _len_0 = 1 | ||
| 93 | for x in hallo do | ||
| 94 | if f(...) > 4 then | ||
| 95 | _accum_0[_len_0] = x | ||
| 96 | _len_0 = _len_0 + 1 | ||
| 97 | end | ||
| 98 | end | ||
| 99 | z = _accum_0 | ||
| 100 | end | ||
| 101 | local a | ||
| 102 | do | ||
| 103 | local _accum_0 = { } | ||
| 104 | local _len_0 = 1 | ||
| 105 | for i = 1, 10 do | ||
| 106 | _accum_0[_len_0] = ... | ||
| 107 | _len_0 = _len_0 + 1 | ||
| 108 | end | ||
| 109 | a = _accum_0 | ||
| 110 | end | ||
| 111 | local b | ||
| 112 | do | ||
| 113 | local _accum_0 = { } | ||
| 114 | local _len_0 = 1 | ||
| 115 | for i = 1, 10 do | ||
| 116 | _accum_0[_len_0] = function(...) | ||
| 117 | return print(...) | ||
| 118 | end | ||
| 119 | _len_0 = _len_0 + 1 | ||
| 120 | end | ||
| 121 | b = _accum_0 | ||
| 122 | end | ||
| 123 | end | ||
diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua new file mode 100644 index 0000000..20b18ea --- /dev/null +++ b/spec/outputs/class.lua | |||
| @@ -0,0 +1,1057 @@ | |||
| 1 | local Hello | ||
| 2 | do | ||
| 3 | local _class_0 | ||
| 4 | local _base_0 = { | ||
| 5 | hello = function(self) | ||
| 6 | return print(self.test, self.world) | ||
| 7 | end, | ||
| 8 | __tostring = function(self) | ||
| 9 | return "hello world" | ||
| 10 | end | ||
| 11 | } | ||
| 12 | _base_0.__index = _base_0 | ||
| 13 | _class_0 = setmetatable({ | ||
| 14 | __init = function(self, test, world) | ||
| 15 | self.test = test | ||
| 16 | self.world = world | ||
| 17 | return print("creating object..") | ||
| 18 | end, | ||
| 19 | __base = _base_0, | ||
| 20 | __name = "Hello" | ||
| 21 | }, { | ||
| 22 | __index = _base_0, | ||
| 23 | __call = function(cls, ...) | ||
| 24 | local _self_0 = setmetatable({ }, _base_0) | ||
| 25 | cls.__init(_self_0, ...) | ||
| 26 | return _self_0 | ||
| 27 | end | ||
| 28 | }) | ||
| 29 | _base_0.__class = _class_0 | ||
| 30 | Hello = _class_0 | ||
| 31 | end | ||
| 32 | local x = Hello(1, 2) | ||
| 33 | x:hello() | ||
| 34 | print(x) | ||
| 35 | local Simple | ||
| 36 | do | ||
| 37 | local _class_0 | ||
| 38 | local _base_0 = { | ||
| 39 | cool = function(self) | ||
| 40 | return print("cool") | ||
| 41 | end | ||
| 42 | } | ||
| 43 | _base_0.__index = _base_0 | ||
| 44 | _class_0 = setmetatable({ | ||
| 45 | __init = function() end, | ||
| 46 | __base = _base_0, | ||
| 47 | __name = "Simple" | ||
| 48 | }, { | ||
| 49 | __index = _base_0, | ||
| 50 | __call = function(cls, ...) | ||
| 51 | local _self_0 = setmetatable({ }, _base_0) | ||
| 52 | cls.__init(_self_0, ...) | ||
| 53 | return _self_0 | ||
| 54 | end | ||
| 55 | }) | ||
| 56 | _base_0.__class = _class_0 | ||
| 57 | Simple = _class_0 | ||
| 58 | end | ||
| 59 | local Yikes | ||
| 60 | do | ||
| 61 | local _class_0 | ||
| 62 | local _parent_0 = Simple | ||
| 63 | local _base_0 = { } | ||
| 64 | _base_0.__index = _base_0 | ||
| 65 | setmetatable(_base_0, _parent_0.__base) | ||
| 66 | _class_0 = setmetatable({ | ||
| 67 | __init = function(self) | ||
| 68 | return print("created hello") | ||
| 69 | end, | ||
| 70 | __base = _base_0, | ||
| 71 | __name = "Yikes", | ||
| 72 | __parent = _parent_0 | ||
| 73 | }, { | ||
| 74 | __index = function(cls, name) | ||
| 75 | local val = rawget(_base_0, name) | ||
| 76 | if val == nil then | ||
| 77 | local parent = rawget(cls, "__parent") | ||
| 78 | if parent then | ||
| 79 | return parent[name] | ||
| 80 | end | ||
| 81 | else | ||
| 82 | return val | ||
| 83 | end | ||
| 84 | end, | ||
| 85 | __call = function(cls, ...) | ||
| 86 | local _self_0 = setmetatable({ }, _base_0) | ||
| 87 | cls.__init(_self_0, ...) | ||
| 88 | return _self_0 | ||
| 89 | end | ||
| 90 | }) | ||
| 91 | _base_0.__class = _class_0 | ||
| 92 | if _parent_0.__inherited then | ||
| 93 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 94 | end | ||
| 95 | Yikes = _class_0 | ||
| 96 | end | ||
| 97 | x = Yikes() | ||
| 98 | x:cool() | ||
| 99 | local Hi | ||
| 100 | do | ||
| 101 | local _class_0 | ||
| 102 | local _base_0 = { | ||
| 103 | cool = function(self, num) | ||
| 104 | return print("num", num) | ||
| 105 | end | ||
| 106 | } | ||
| 107 | _base_0.__index = _base_0 | ||
| 108 | _class_0 = setmetatable({ | ||
| 109 | __init = function(self, arg) | ||
| 110 | return print("init arg", arg) | ||
| 111 | end, | ||
| 112 | __base = _base_0, | ||
| 113 | __name = "Hi" | ||
| 114 | }, { | ||
| 115 | __index = _base_0, | ||
| 116 | __call = function(cls, ...) | ||
| 117 | local _self_0 = setmetatable({ }, _base_0) | ||
| 118 | cls.__init(_self_0, ...) | ||
| 119 | return _self_0 | ||
| 120 | end | ||
| 121 | }) | ||
| 122 | _base_0.__class = _class_0 | ||
| 123 | Hi = _class_0 | ||
| 124 | end | ||
| 125 | do | ||
| 126 | local _class_0 | ||
| 127 | local _parent_0 = Hi | ||
| 128 | local _base_0 = { | ||
| 129 | cool = function(self) | ||
| 130 | return _class_0.__parent.__base.cool(self, 120302) | ||
| 131 | end | ||
| 132 | } | ||
| 133 | _base_0.__index = _base_0 | ||
| 134 | setmetatable(_base_0, _parent_0.__base) | ||
| 135 | _class_0 = setmetatable({ | ||
| 136 | __init = function(self) | ||
| 137 | return _class_0.__parent.__init(self, "man") | ||
| 138 | end, | ||
| 139 | __base = _base_0, | ||
| 140 | __name = "Simple", | ||
| 141 | __parent = _parent_0 | ||
| 142 | }, { | ||
| 143 | __index = function(cls, name) | ||
| 144 | local val = rawget(_base_0, name) | ||
| 145 | if val == nil then | ||
| 146 | local parent = rawget(cls, "__parent") | ||
| 147 | if parent then | ||
| 148 | return parent[name] | ||
| 149 | end | ||
| 150 | else | ||
| 151 | return val | ||
| 152 | end | ||
| 153 | end, | ||
| 154 | __call = function(cls, ...) | ||
| 155 | local _self_0 = setmetatable({ }, _base_0) | ||
| 156 | cls.__init(_self_0, ...) | ||
| 157 | return _self_0 | ||
| 158 | end | ||
| 159 | }) | ||
| 160 | _base_0.__class = _class_0 | ||
| 161 | if _parent_0.__inherited then | ||
| 162 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 163 | end | ||
| 164 | Simple = _class_0 | ||
| 165 | end | ||
| 166 | x = Simple() | ||
| 167 | x:cool() | ||
| 168 | print(x.__class == Simple) | ||
| 169 | local Okay | ||
| 170 | do | ||
| 171 | local _class_0 | ||
| 172 | local _base_0 = { | ||
| 173 | something = 20323 | ||
| 174 | } | ||
| 175 | _base_0.__index = _base_0 | ||
| 176 | _class_0 = setmetatable({ | ||
| 177 | __init = function() end, | ||
| 178 | __base = _base_0, | ||
| 179 | __name = "Okay" | ||
| 180 | }, { | ||
| 181 | __index = _base_0, | ||
| 182 | __call = function(cls, ...) | ||
| 183 | local _self_0 = setmetatable({ }, _base_0) | ||
| 184 | cls.__init(_self_0, ...) | ||
| 185 | return _self_0 | ||
| 186 | end | ||
| 187 | }) | ||
| 188 | _base_0.__class = _class_0 | ||
| 189 | Okay = _class_0 | ||
| 190 | end | ||
| 191 | local Biggie | ||
| 192 | do | ||
| 193 | local _class_0 | ||
| 194 | local _parent_0 = Okay | ||
| 195 | local _base_0 = { | ||
| 196 | something = function(self) | ||
| 197 | _class_0.__parent.__base.something(self, 1, 2, 3, 4) | ||
| 198 | _class_0.__parent.something(another_self, 1, 2, 3, 4) | ||
| 199 | return assert(_class_0.__parent == Okay) | ||
| 200 | end | ||
| 201 | } | ||
| 202 | _base_0.__index = _base_0 | ||
| 203 | setmetatable(_base_0, _parent_0.__base) | ||
| 204 | _class_0 = setmetatable({ | ||
| 205 | __init = function(self, ...) | ||
| 206 | return _class_0.__parent.__init(self, ...) | ||
| 207 | end, | ||
| 208 | __base = _base_0, | ||
| 209 | __name = "Biggie", | ||
| 210 | __parent = _parent_0 | ||
| 211 | }, { | ||
| 212 | __index = function(cls, name) | ||
| 213 | local val = rawget(_base_0, name) | ||
| 214 | if val == nil then | ||
| 215 | local parent = rawget(cls, "__parent") | ||
| 216 | if parent then | ||
| 217 | return parent[name] | ||
| 218 | end | ||
| 219 | else | ||
| 220 | return val | ||
| 221 | end | ||
| 222 | end, | ||
| 223 | __call = function(cls, ...) | ||
| 224 | local _self_0 = setmetatable({ }, _base_0) | ||
| 225 | cls.__init(_self_0, ...) | ||
| 226 | return _self_0 | ||
| 227 | end | ||
| 228 | }) | ||
| 229 | _base_0.__class = _class_0 | ||
| 230 | if _parent_0.__inherited then | ||
| 231 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 232 | end | ||
| 233 | Biggie = _class_0 | ||
| 234 | end | ||
| 235 | local Yeah | ||
| 236 | do | ||
| 237 | local _class_0 | ||
| 238 | local _base_0 = { | ||
| 239 | okay = function(self) | ||
| 240 | return _class_0.__parent.something(self, 1, 2, 3, 4) | ||
| 241 | end | ||
| 242 | } | ||
| 243 | _base_0.__index = _base_0 | ||
| 244 | _class_0 = setmetatable({ | ||
| 245 | __init = function() end, | ||
| 246 | __base = _base_0, | ||
| 247 | __name = "Yeah" | ||
| 248 | }, { | ||
| 249 | __index = _base_0, | ||
| 250 | __call = function(cls, ...) | ||
| 251 | local _self_0 = setmetatable({ }, _base_0) | ||
| 252 | cls.__init(_self_0, ...) | ||
| 253 | return _self_0 | ||
| 254 | end | ||
| 255 | }) | ||
| 256 | _base_0.__class = _class_0 | ||
| 257 | Yeah = _class_0 | ||
| 258 | end | ||
| 259 | local What | ||
| 260 | do | ||
| 261 | local _class_0 | ||
| 262 | local _base_0 = { | ||
| 263 | something = function(self) | ||
| 264 | return print("val:", self.val) | ||
| 265 | end | ||
| 266 | } | ||
| 267 | _base_0.__index = _base_0 | ||
| 268 | _class_0 = setmetatable({ | ||
| 269 | __init = function() end, | ||
| 270 | __base = _base_0, | ||
| 271 | __name = "What" | ||
| 272 | }, { | ||
| 273 | __index = _base_0, | ||
| 274 | __call = function(cls, ...) | ||
| 275 | local _self_0 = setmetatable({ }, _base_0) | ||
| 276 | cls.__init(_self_0, ...) | ||
| 277 | return _self_0 | ||
| 278 | end | ||
| 279 | }) | ||
| 280 | _base_0.__class = _class_0 | ||
| 281 | What = _class_0 | ||
| 282 | end | ||
| 283 | do | ||
| 284 | local _class_0 | ||
| 285 | local _parent_0 = What | ||
| 286 | local _base_0 = { | ||
| 287 | val = 2323, | ||
| 288 | something = function(self) | ||
| 289 | local _base_1 = _class_0.__parent | ||
| 290 | local _fn_0 = _base_1.something | ||
| 291 | return _fn_0 and function(...) | ||
| 292 | return _fn_0(_base_1, ...) | ||
| 293 | end | ||
| 294 | end | ||
| 295 | } | ||
| 296 | _base_0.__index = _base_0 | ||
| 297 | setmetatable(_base_0, _parent_0.__base) | ||
| 298 | _class_0 = setmetatable({ | ||
| 299 | __init = function(self, ...) | ||
| 300 | return _class_0.__parent.__init(self, ...) | ||
| 301 | end, | ||
| 302 | __base = _base_0, | ||
| 303 | __name = "Hello", | ||
| 304 | __parent = _parent_0 | ||
| 305 | }, { | ||
| 306 | __index = function(cls, name) | ||
| 307 | local val = rawget(_base_0, name) | ||
| 308 | if val == nil then | ||
| 309 | local parent = rawget(cls, "__parent") | ||
| 310 | if parent then | ||
| 311 | return parent[name] | ||
| 312 | end | ||
| 313 | else | ||
| 314 | return val | ||
| 315 | end | ||
| 316 | end, | ||
| 317 | __call = function(cls, ...) | ||
| 318 | local _self_0 = setmetatable({ }, _base_0) | ||
| 319 | cls.__init(_self_0, ...) | ||
| 320 | return _self_0 | ||
| 321 | end | ||
| 322 | }) | ||
| 323 | _base_0.__class = _class_0 | ||
| 324 | if _parent_0.__inherited then | ||
| 325 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 326 | end | ||
| 327 | Hello = _class_0 | ||
| 328 | end | ||
| 329 | do | ||
| 330 | local _with_0 = Hello() | ||
| 331 | x = _with_0:something() | ||
| 332 | print(x) | ||
| 333 | x() | ||
| 334 | end | ||
| 335 | local CoolSuper | ||
| 336 | do | ||
| 337 | local _class_0 | ||
| 338 | local _base_0 = { | ||
| 339 | hi = function(self) | ||
| 340 | _class_0.__parent.__base.hi(self, 1, 2, 3, 4)(1, 2, 3, 4) | ||
| 341 | _class_0.__parent.something(1, 2, 3, 4) | ||
| 342 | local _ = _class_0.__parent.something(1, 2, 3, 4).world | ||
| 343 | _class_0.__parent.yeah(self, "world").okay(hi, hi, hi) | ||
| 344 | _ = something.super | ||
| 345 | _ = _class_0.__parent.super.super.super | ||
| 346 | do | ||
| 347 | local _base_1 = _class_0.__parent | ||
| 348 | local _fn_0 = _base_1.hello | ||
| 349 | _ = _fn_0 and function(...) | ||
| 350 | return _fn_0(_base_1, ...) | ||
| 351 | end | ||
| 352 | end | ||
| 353 | return nil | ||
| 354 | end | ||
| 355 | } | ||
| 356 | _base_0.__index = _base_0 | ||
| 357 | _class_0 = setmetatable({ | ||
| 358 | __init = function() end, | ||
| 359 | __base = _base_0, | ||
| 360 | __name = "CoolSuper" | ||
| 361 | }, { | ||
| 362 | __index = _base_0, | ||
| 363 | __call = function(cls, ...) | ||
| 364 | local _self_0 = setmetatable({ }, _base_0) | ||
| 365 | cls.__init(_self_0, ...) | ||
| 366 | return _self_0 | ||
| 367 | end | ||
| 368 | }) | ||
| 369 | _base_0.__class = _class_0 | ||
| 370 | CoolSuper = _class_0 | ||
| 371 | end | ||
| 372 | x = self.hello | ||
| 373 | x = self.__class.hello | ||
| 374 | self:hello("world") | ||
| 375 | self.__class:hello("world") | ||
| 376 | self.__class:one(self.__class:two(4, 5)(self.three, self.four)) | ||
| 377 | local xx | ||
| 378 | xx = function(hello, world, cool) | ||
| 379 | self.hello = hello | ||
| 380 | self.__class.world = world | ||
| 381 | end | ||
| 382 | local ClassMan | ||
| 383 | do | ||
| 384 | local _class_0 | ||
| 385 | local _base_0 = { | ||
| 386 | blue = function(self) end, | ||
| 387 | green = function(self) end | ||
| 388 | } | ||
| 389 | _base_0.__index = _base_0 | ||
| 390 | _class_0 = setmetatable({ | ||
| 391 | __init = function() end, | ||
| 392 | __base = _base_0, | ||
| 393 | __name = "ClassMan" | ||
| 394 | }, { | ||
| 395 | __index = _base_0, | ||
| 396 | __call = function(cls, ...) | ||
| 397 | local _self_0 = setmetatable({ }, _base_0) | ||
| 398 | cls.__init(_self_0, ...) | ||
| 399 | return _self_0 | ||
| 400 | end | ||
| 401 | }) | ||
| 402 | _base_0.__class = _class_0 | ||
| 403 | local self = _class_0; | ||
| 404 | self.yeah = 343 | ||
| 405 | self.hello = 3434 | ||
| 406 | self.world = 23423 | ||
| 407 | self.red = function(self) end | ||
| 408 | ClassMan = _class_0 | ||
| 409 | end | ||
| 410 | x = self | ||
| 411 | local y = self.__class | ||
| 412 | self(something) | ||
| 413 | self.__class(something) | ||
| 414 | local self = self + self / self | ||
| 415 | self = 343 | ||
| 416 | self.hello(2, 3, 4) | ||
| 417 | local _ = hello[self].world | ||
| 418 | local Whacko | ||
| 419 | do | ||
| 420 | local _class_0 | ||
| 421 | local hello | ||
| 422 | local _base_0 = { } | ||
| 423 | _base_0.__index = _base_0 | ||
| 424 | _class_0 = setmetatable({ | ||
| 425 | __init = function() end, | ||
| 426 | __base = _base_0, | ||
| 427 | __name = "Whacko" | ||
| 428 | }, { | ||
| 429 | __index = _base_0, | ||
| 430 | __call = function(cls, ...) | ||
| 431 | local _self_0 = setmetatable({ }, _base_0) | ||
| 432 | cls.__init(_self_0, ...) | ||
| 433 | return _self_0 | ||
| 434 | end | ||
| 435 | }) | ||
| 436 | _base_0.__class = _class_0 | ||
| 437 | local self = _class_0; | ||
| 438 | _ = self.hello | ||
| 439 | if something then | ||
| 440 | print("hello world") | ||
| 441 | end | ||
| 442 | hello = "world" | ||
| 443 | self.another = "day" | ||
| 444 | if something then | ||
| 445 | print("yeah") | ||
| 446 | end | ||
| 447 | Whacko = _class_0 | ||
| 448 | end | ||
| 449 | print("hello") | ||
| 450 | local yyy | ||
| 451 | yyy = function() | ||
| 452 | local Cool | ||
| 453 | do | ||
| 454 | local _class_0 | ||
| 455 | local _base_0 = { } | ||
| 456 | _base_0.__index = _base_0 | ||
| 457 | _class_0 = setmetatable({ | ||
| 458 | __init = function() end, | ||
| 459 | __base = _base_0, | ||
| 460 | __name = "Cool" | ||
| 461 | }, { | ||
| 462 | __index = _base_0, | ||
| 463 | __call = function(cls, ...) | ||
| 464 | local _self_0 = setmetatable({ }, _base_0) | ||
| 465 | cls.__init(_self_0, ...) | ||
| 466 | return _self_0 | ||
| 467 | end | ||
| 468 | }) | ||
| 469 | _base_0.__class = _class_0 | ||
| 470 | local self = _class_0; | ||
| 471 | _ = nil | ||
| 472 | Cool = _class_0 | ||
| 473 | return _class_0 | ||
| 474 | end | ||
| 475 | end | ||
| 476 | do | ||
| 477 | local _class_0 | ||
| 478 | local _base_0 = { } | ||
| 479 | _base_0.__index = _base_0 | ||
| 480 | _class_0 = setmetatable({ | ||
| 481 | __init = function() end, | ||
| 482 | __base = _base_0, | ||
| 483 | __name = "D" | ||
| 484 | }, { | ||
| 485 | __index = _base_0, | ||
| 486 | __call = function(cls, ...) | ||
| 487 | local _self_0 = setmetatable({ }, _base_0) | ||
| 488 | cls.__init(_self_0, ...) | ||
| 489 | return _self_0 | ||
| 490 | end | ||
| 491 | }) | ||
| 492 | _base_0.__class = _class_0 | ||
| 493 | local self = _class_0; | ||
| 494 | _ = nil | ||
| 495 | a.b.c.D = _class_0 | ||
| 496 | end | ||
| 497 | do | ||
| 498 | local _class_0 | ||
| 499 | local _base_0 = { } | ||
| 500 | _base_0.__index = _base_0 | ||
| 501 | _class_0 = setmetatable({ | ||
| 502 | __init = function() end, | ||
| 503 | __base = _base_0, | ||
| 504 | __name = "hello" | ||
| 505 | }, { | ||
| 506 | __index = _base_0, | ||
| 507 | __call = function(cls, ...) | ||
| 508 | local _self_0 = setmetatable({ }, _base_0) | ||
| 509 | cls.__init(_self_0, ...) | ||
| 510 | return _self_0 | ||
| 511 | end | ||
| 512 | }) | ||
| 513 | _base_0.__class = _class_0 | ||
| 514 | local self = _class_0; | ||
| 515 | _ = nil | ||
| 516 | a.b["hello"] = _class_0 | ||
| 517 | end | ||
| 518 | do | ||
| 519 | local _class_0 | ||
| 520 | local _parent_0 = Hello.World | ||
| 521 | local _base_0 = { } | ||
| 522 | _base_0.__index = _base_0 | ||
| 523 | setmetatable(_base_0, _parent_0.__base) | ||
| 524 | _class_0 = setmetatable({ | ||
| 525 | __init = function(self, ...) | ||
| 526 | return _class_0.__parent.__init(self, ...) | ||
| 527 | end, | ||
| 528 | __base = _base_0, | ||
| 529 | __name = "Something", | ||
| 530 | __parent = _parent_0 | ||
| 531 | }, { | ||
| 532 | __index = function(cls, name) | ||
| 533 | local val = rawget(_base_0, name) | ||
| 534 | if val == nil then | ||
| 535 | local parent = rawget(cls, "__parent") | ||
| 536 | if parent then | ||
| 537 | return parent[name] | ||
| 538 | end | ||
| 539 | else | ||
| 540 | return val | ||
| 541 | end | ||
| 542 | end, | ||
| 543 | __call = function(cls, ...) | ||
| 544 | local _self_0 = setmetatable({ }, _base_0) | ||
| 545 | cls.__init(_self_0, ...) | ||
| 546 | return _self_0 | ||
| 547 | end | ||
| 548 | }) | ||
| 549 | _base_0.__class = _class_0 | ||
| 550 | local self = _class_0; | ||
| 551 | _ = nil | ||
| 552 | if _parent_0.__inherited then | ||
| 553 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 554 | end | ||
| 555 | (function() | ||
| 556 | return require("moon") | ||
| 557 | end)().Something = _class_0 | ||
| 558 | end | ||
| 559 | local a | ||
| 560 | do | ||
| 561 | local _class_0 | ||
| 562 | local _base_0 = { } | ||
| 563 | _base_0.__index = _base_0 | ||
| 564 | _class_0 = setmetatable({ | ||
| 565 | __init = function() end, | ||
| 566 | __base = _base_0, | ||
| 567 | __name = "a" | ||
| 568 | }, { | ||
| 569 | __index = _base_0, | ||
| 570 | __call = function(cls, ...) | ||
| 571 | local _self_0 = setmetatable({ }, _base_0) | ||
| 572 | cls.__init(_self_0, ...) | ||
| 573 | return _self_0 | ||
| 574 | end | ||
| 575 | }) | ||
| 576 | _base_0.__class = _class_0 | ||
| 577 | a = _class_0 | ||
| 578 | end | ||
| 579 | local b | ||
| 580 | local Something | ||
| 581 | do | ||
| 582 | local _class_0 | ||
| 583 | local _base_0 = { } | ||
| 584 | _base_0.__index = _base_0 | ||
| 585 | _class_0 = setmetatable({ | ||
| 586 | __init = function() end, | ||
| 587 | __base = _base_0, | ||
| 588 | __name = "Something" | ||
| 589 | }, { | ||
| 590 | __index = _base_0, | ||
| 591 | __call = function(cls, ...) | ||
| 592 | local _self_0 = setmetatable({ }, _base_0) | ||
| 593 | cls.__init(_self_0, ...) | ||
| 594 | return _self_0 | ||
| 595 | end | ||
| 596 | }) | ||
| 597 | _base_0.__class = _class_0 | ||
| 598 | Something = _class_0 | ||
| 599 | b = _class_0 | ||
| 600 | end | ||
| 601 | local c | ||
| 602 | do | ||
| 603 | local _class_0 | ||
| 604 | local _parent_0 = Hello | ||
| 605 | local _base_0 = { } | ||
| 606 | _base_0.__index = _base_0 | ||
| 607 | setmetatable(_base_0, _parent_0.__base) | ||
| 608 | _class_0 = setmetatable({ | ||
| 609 | __init = function(self, ...) | ||
| 610 | return _class_0.__parent.__init(self, ...) | ||
| 611 | end, | ||
| 612 | __base = _base_0, | ||
| 613 | __name = "Something", | ||
| 614 | __parent = _parent_0 | ||
| 615 | }, { | ||
| 616 | __index = function(cls, name) | ||
| 617 | local val = rawget(_base_0, name) | ||
| 618 | if val == nil then | ||
| 619 | local parent = rawget(cls, "__parent") | ||
| 620 | if parent then | ||
| 621 | return parent[name] | ||
| 622 | end | ||
| 623 | else | ||
| 624 | return val | ||
| 625 | end | ||
| 626 | end, | ||
| 627 | __call = function(cls, ...) | ||
| 628 | local _self_0 = setmetatable({ }, _base_0) | ||
| 629 | cls.__init(_self_0, ...) | ||
| 630 | return _self_0 | ||
| 631 | end | ||
| 632 | }) | ||
| 633 | _base_0.__class = _class_0 | ||
| 634 | if _parent_0.__inherited then | ||
| 635 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 636 | end | ||
| 637 | Something = _class_0 | ||
| 638 | c = _class_0 | ||
| 639 | end | ||
| 640 | local d | ||
| 641 | do | ||
| 642 | local _class_0 | ||
| 643 | local _parent_0 = World | ||
| 644 | local _base_0 = { } | ||
| 645 | _base_0.__index = _base_0 | ||
| 646 | setmetatable(_base_0, _parent_0.__base) | ||
| 647 | _class_0 = setmetatable({ | ||
| 648 | __init = function(self, ...) | ||
| 649 | return _class_0.__parent.__init(self, ...) | ||
| 650 | end, | ||
| 651 | __base = _base_0, | ||
| 652 | __name = "d", | ||
| 653 | __parent = _parent_0 | ||
| 654 | }, { | ||
| 655 | __index = function(cls, name) | ||
| 656 | local val = rawget(_base_0, name) | ||
| 657 | if val == nil then | ||
| 658 | local parent = rawget(cls, "__parent") | ||
| 659 | if parent then | ||
| 660 | return parent[name] | ||
| 661 | end | ||
| 662 | else | ||
| 663 | return val | ||
| 664 | end | ||
| 665 | end, | ||
| 666 | __call = function(cls, ...) | ||
| 667 | local _self_0 = setmetatable({ }, _base_0) | ||
| 668 | cls.__init(_self_0, ...) | ||
| 669 | return _self_0 | ||
| 670 | end | ||
| 671 | }) | ||
| 672 | _base_0.__class = _class_0 | ||
| 673 | if _parent_0.__inherited then | ||
| 674 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 675 | end | ||
| 676 | d = _class_0 | ||
| 677 | end | ||
| 678 | print(((function() | ||
| 679 | local WhatsUp | ||
| 680 | do | ||
| 681 | local _class_0 | ||
| 682 | local _base_0 = { } | ||
| 683 | _base_0.__index = _base_0 | ||
| 684 | _class_0 = setmetatable({ | ||
| 685 | __init = function() end, | ||
| 686 | __base = _base_0, | ||
| 687 | __name = "WhatsUp" | ||
| 688 | }, { | ||
| 689 | __index = _base_0, | ||
| 690 | __call = function(cls, ...) | ||
| 691 | local _self_0 = setmetatable({ }, _base_0) | ||
| 692 | cls.__init(_self_0, ...) | ||
| 693 | return _self_0 | ||
| 694 | end | ||
| 695 | }) | ||
| 696 | _base_0.__class = _class_0 | ||
| 697 | WhatsUp = _class_0 | ||
| 698 | return _class_0 | ||
| 699 | end | ||
| 700 | end)()).__name) | ||
| 701 | do | ||
| 702 | local _class_0 | ||
| 703 | local _base_0 = { } | ||
| 704 | _base_0.__index = _base_0 | ||
| 705 | _class_0 = setmetatable({ | ||
| 706 | __init = function() end, | ||
| 707 | __base = _base_0, | ||
| 708 | __name = "Something" | ||
| 709 | }, { | ||
| 710 | __index = _base_0, | ||
| 711 | __call = function(cls, ...) | ||
| 712 | local _self_0 = setmetatable({ }, _base_0) | ||
| 713 | cls.__init(_self_0, ...) | ||
| 714 | return _self_0 | ||
| 715 | end | ||
| 716 | }) | ||
| 717 | _base_0.__class = _class_0 | ||
| 718 | local self = _class_0; | ||
| 719 | _ = nil | ||
| 720 | Something = _class_0 | ||
| 721 | end | ||
| 722 | do | ||
| 723 | local _class_0 | ||
| 724 | local val, insert | ||
| 725 | local _base_0 = { } | ||
| 726 | _base_0.__index = _base_0 | ||
| 727 | _class_0 = setmetatable({ | ||
| 728 | __init = function(self) | ||
| 729 | return print(insert, val) | ||
| 730 | end, | ||
| 731 | __base = _base_0, | ||
| 732 | __name = "Something" | ||
| 733 | }, { | ||
| 734 | __index = _base_0, | ||
| 735 | __call = function(cls, ...) | ||
| 736 | local _self_0 = setmetatable({ }, _base_0) | ||
| 737 | cls.__init(_self_0, ...) | ||
| 738 | return _self_0 | ||
| 739 | end | ||
| 740 | }) | ||
| 741 | _base_0.__class = _class_0 | ||
| 742 | local self = _class_0; | ||
| 743 | val = 23 | ||
| 744 | insert = table.insert | ||
| 745 | Something = _class_0 | ||
| 746 | end | ||
| 747 | do | ||
| 748 | local _class_0 | ||
| 749 | local _base_0 = { } | ||
| 750 | _base_0.__index = _base_0 | ||
| 751 | _class_0 = setmetatable({ | ||
| 752 | __init = hi, | ||
| 753 | __base = _base_0, | ||
| 754 | __name = "X" | ||
| 755 | }, { | ||
| 756 | __index = _base_0, | ||
| 757 | __call = function(cls, ...) | ||
| 758 | local _self_0 = setmetatable({ }, _base_0) | ||
| 759 | cls.__init(_self_0, ...) | ||
| 760 | return _self_0 | ||
| 761 | end | ||
| 762 | }) | ||
| 763 | _base_0.__class = _class_0 | ||
| 764 | X = _class_0 | ||
| 765 | end | ||
| 766 | do | ||
| 767 | local _class_0 | ||
| 768 | local _parent_0 = Thing | ||
| 769 | local _base_0 = { | ||
| 770 | dang = function(self) | ||
| 771 | return { | ||
| 772 | hello = function() | ||
| 773 | return _class_0.__parent.__base.dang(self) | ||
| 774 | end, | ||
| 775 | world = function() | ||
| 776 | return _class_0.__parent.one | ||
| 777 | end | ||
| 778 | } | ||
| 779 | end | ||
| 780 | } | ||
| 781 | _base_0.__index = _base_0 | ||
| 782 | setmetatable(_base_0, _parent_0.__base) | ||
| 783 | _class_0 = setmetatable({ | ||
| 784 | __init = function(self, ...) | ||
| 785 | return _class_0.__parent.__init(self, ...) | ||
| 786 | end, | ||
| 787 | __base = _base_0, | ||
| 788 | __name = "Cool", | ||
| 789 | __parent = _parent_0 | ||
| 790 | }, { | ||
| 791 | __index = function(cls, name) | ||
| 792 | local val = rawget(_base_0, name) | ||
| 793 | if val == nil then | ||
| 794 | local parent = rawget(cls, "__parent") | ||
| 795 | if parent then | ||
| 796 | return parent[name] | ||
| 797 | end | ||
| 798 | else | ||
| 799 | return val | ||
| 800 | end | ||
| 801 | end, | ||
| 802 | __call = function(cls, ...) | ||
| 803 | local _self_0 = setmetatable({ }, _base_0) | ||
| 804 | cls.__init(_self_0, ...) | ||
| 805 | return _self_0 | ||
| 806 | end | ||
| 807 | }) | ||
| 808 | _base_0.__class = _class_0 | ||
| 809 | if _parent_0.__inherited then | ||
| 810 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 811 | end | ||
| 812 | Cool = _class_0 | ||
| 813 | end | ||
| 814 | do | ||
| 815 | local _class_0 | ||
| 816 | local _parent_0 = Thing | ||
| 817 | local _base_0 = { | ||
| 818 | dang = do_something(function(self) | ||
| 819 | return _class_0.__parent.__base.dang(self) | ||
| 820 | end) | ||
| 821 | } | ||
| 822 | _base_0.__index = _base_0 | ||
| 823 | setmetatable(_base_0, _parent_0.__base) | ||
| 824 | _class_0 = setmetatable({ | ||
| 825 | __init = function(self, ...) | ||
| 826 | return _class_0.__parent.__init(self, ...) | ||
| 827 | end, | ||
| 828 | __base = _base_0, | ||
| 829 | __name = "Whack", | ||
| 830 | __parent = _parent_0 | ||
| 831 | }, { | ||
| 832 | __index = function(cls, name) | ||
| 833 | local val = rawget(_base_0, name) | ||
| 834 | if val == nil then | ||
| 835 | local parent = rawget(cls, "__parent") | ||
| 836 | if parent then | ||
| 837 | return parent[name] | ||
| 838 | end | ||
| 839 | else | ||
| 840 | return val | ||
| 841 | end | ||
| 842 | end, | ||
| 843 | __call = function(cls, ...) | ||
| 844 | local _self_0 = setmetatable({ }, _base_0) | ||
| 845 | cls.__init(_self_0, ...) | ||
| 846 | return _self_0 | ||
| 847 | end | ||
| 848 | }) | ||
| 849 | _base_0.__class = _class_0 | ||
| 850 | if _parent_0.__inherited then | ||
| 851 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 852 | end | ||
| 853 | Whack = _class_0 | ||
| 854 | end | ||
| 855 | do | ||
| 856 | local _class_0 | ||
| 857 | local _parent_0 = Thing | ||
| 858 | local _base_0 = { } | ||
| 859 | _base_0.__index = _base_0 | ||
| 860 | setmetatable(_base_0, _parent_0.__base) | ||
| 861 | _class_0 = setmetatable({ | ||
| 862 | __init = function(self, ...) | ||
| 863 | return _class_0.__parent.__init(self, ...) | ||
| 864 | end, | ||
| 865 | __base = _base_0, | ||
| 866 | __name = "Wowha", | ||
| 867 | __parent = _parent_0 | ||
| 868 | }, { | ||
| 869 | __index = function(cls, name) | ||
| 870 | local val = rawget(_base_0, name) | ||
| 871 | if val == nil then | ||
| 872 | local parent = rawget(cls, "__parent") | ||
| 873 | if parent then | ||
| 874 | return parent[name] | ||
| 875 | end | ||
| 876 | else | ||
| 877 | return val | ||
| 878 | end | ||
| 879 | end, | ||
| 880 | __call = function(cls, ...) | ||
| 881 | local _self_0 = setmetatable({ }, _base_0) | ||
| 882 | cls.__init(_self_0, ...) | ||
| 883 | return _self_0 | ||
| 884 | end | ||
| 885 | }) | ||
| 886 | _base_0.__class = _class_0 | ||
| 887 | local self = _class_0; | ||
| 888 | self.butt = function() | ||
| 889 | _class_0.__parent.butt(self) | ||
| 890 | _ = _class_0.__parent.hello | ||
| 891 | _class_0.__parent.hello(self) | ||
| 892 | local _base_1 = _class_0.__parent | ||
| 893 | local _fn_0 = _base_1.hello | ||
| 894 | return _fn_0 and function(...) | ||
| 895 | return _fn_0(_base_1, ...) | ||
| 896 | end | ||
| 897 | end | ||
| 898 | self.zone = cool({ | ||
| 899 | function() | ||
| 900 | _class_0.__parent.zone(self) | ||
| 901 | _ = _class_0.__parent.hello | ||
| 902 | _class_0.__parent.hello(self) | ||
| 903 | local _base_1 = _class_0.__parent | ||
| 904 | local _fn_0 = _base_1.hello | ||
| 905 | return _fn_0 and function(...) | ||
| 906 | return _fn_0(_base_1, ...) | ||
| 907 | end | ||
| 908 | end | ||
| 909 | }) | ||
| 910 | if _parent_0.__inherited then | ||
| 911 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 912 | end | ||
| 913 | Wowha = _class_0 | ||
| 914 | end | ||
| 915 | do | ||
| 916 | local Test | ||
| 917 | do | ||
| 918 | local _class_0 | ||
| 919 | local _base_0 = { | ||
| 920 | test = function(self) | ||
| 921 | return self.__class["if"] and self.__class["do"](self.__class) | ||
| 922 | end | ||
| 923 | } | ||
| 924 | _base_0.__index = _base_0 | ||
| 925 | _class_0 = setmetatable({ | ||
| 926 | __init = function(self) | ||
| 927 | self.__class["if"] = true | ||
| 928 | end, | ||
| 929 | __base = _base_0, | ||
| 930 | __name = "Test" | ||
| 931 | }, { | ||
| 932 | __index = _base_0, | ||
| 933 | __call = function(cls, ...) | ||
| 934 | local _self_0 = setmetatable({ }, _base_0) | ||
| 935 | cls.__init(_self_0, ...) | ||
| 936 | return _self_0 | ||
| 937 | end | ||
| 938 | }) | ||
| 939 | _base_0.__class = _class_0 | ||
| 940 | local self = _class_0; | ||
| 941 | self["do"] = function(self) | ||
| 942 | return 1 | ||
| 943 | end | ||
| 944 | Test = _class_0 | ||
| 945 | end | ||
| 946 | local test = Test() | ||
| 947 | test:test() | ||
| 948 | end | ||
| 949 | do | ||
| 950 | local Test | ||
| 951 | do | ||
| 952 | local _class_0 | ||
| 953 | local _base_0 = { | ||
| 954 | ["do"] = function(self) | ||
| 955 | return 1 | ||
| 956 | end, | ||
| 957 | test = function(self) | ||
| 958 | return self["if"] and self["do"](self) | ||
| 959 | end | ||
| 960 | } | ||
| 961 | _base_0.__index = _base_0 | ||
| 962 | _class_0 = setmetatable({ | ||
| 963 | __init = function(self) | ||
| 964 | self["if"] = true | ||
| 965 | end, | ||
| 966 | __base = _base_0, | ||
| 967 | __name = "Test" | ||
| 968 | }, { | ||
| 969 | __index = _base_0, | ||
| 970 | __call = function(cls, ...) | ||
| 971 | local _self_0 = setmetatable({ }, _base_0) | ||
| 972 | cls.__init(_self_0, ...) | ||
| 973 | return _self_0 | ||
| 974 | end | ||
| 975 | }) | ||
| 976 | _base_0.__class = _class_0 | ||
| 977 | Test = _class_0 | ||
| 978 | end | ||
| 979 | local test = Test() | ||
| 980 | test:test() | ||
| 981 | end | ||
| 982 | do | ||
| 983 | local _class_0 | ||
| 984 | local _parent_0 = lapis.Application | ||
| 985 | local _base_0 = { | ||
| 986 | ["/"] = function(self) | ||
| 987 | return { | ||
| 988 | json = { | ||
| 989 | status = true | ||
| 990 | } | ||
| 991 | } | ||
| 992 | end | ||
| 993 | } | ||
| 994 | _base_0.__index = _base_0 | ||
| 995 | setmetatable(_base_0, _parent_0.__base) | ||
| 996 | _class_0 = setmetatable({ | ||
| 997 | __init = function(self, ...) | ||
| 998 | return _class_0.__parent.__init(self, ...) | ||
| 999 | end, | ||
| 1000 | __base = _base_0, | ||
| 1001 | __parent = _parent_0 | ||
| 1002 | }, { | ||
| 1003 | __index = function(cls, name) | ||
| 1004 | local val = rawget(_base_0, name) | ||
| 1005 | if val == nil then | ||
| 1006 | local parent = rawget(cls, "__parent") | ||
| 1007 | if parent then | ||
| 1008 | return parent[name] | ||
| 1009 | end | ||
| 1010 | else | ||
| 1011 | return val | ||
| 1012 | end | ||
| 1013 | end, | ||
| 1014 | __call = function(cls, ...) | ||
| 1015 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1016 | cls.__init(_self_0, ...) | ||
| 1017 | return _self_0 | ||
| 1018 | end | ||
| 1019 | }) | ||
| 1020 | _base_0.__class = _class_0 | ||
| 1021 | if _parent_0.__inherited then | ||
| 1022 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1023 | end | ||
| 1024 | end | ||
| 1025 | do | ||
| 1026 | local _class_0 | ||
| 1027 | local _base_0 = { } | ||
| 1028 | local _list_0 = { | ||
| 1029 | B, | ||
| 1030 | C, | ||
| 1031 | D | ||
| 1032 | } | ||
| 1033 | for _index_0 = 1, #_list_0 do | ||
| 1034 | local _mixin_0 = _list_0[_index_0] | ||
| 1035 | for _key_0, _val_0 in pairs(_mixin_0.__base) do | ||
| 1036 | if not _key_0:match("^__") then | ||
| 1037 | _base_0[_key_0] = _val_0 | ||
| 1038 | end | ||
| 1039 | end | ||
| 1040 | end | ||
| 1041 | _base_0.__index = _base_0 | ||
| 1042 | _class_0 = setmetatable({ | ||
| 1043 | __init = function() end, | ||
| 1044 | __base = _base_0, | ||
| 1045 | __name = "A" | ||
| 1046 | }, { | ||
| 1047 | __index = _base_0, | ||
| 1048 | __call = function(cls, ...) | ||
| 1049 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1050 | cls.__init(_self_0, ...) | ||
| 1051 | return _self_0 | ||
| 1052 | end | ||
| 1053 | }) | ||
| 1054 | _base_0.__class = _class_0 | ||
| 1055 | A = _class_0 | ||
| 1056 | end | ||
| 1057 | return nil | ||
diff --git a/spec/outputs/comprehension.lua b/spec/outputs/comprehension.lua new file mode 100644 index 0000000..9a7c478 --- /dev/null +++ b/spec/outputs/comprehension.lua | |||
| @@ -0,0 +1,277 @@ | |||
| 1 | local items = { | ||
| 2 | 1, | ||
| 3 | 2, | ||
| 4 | 3, | ||
| 5 | 4, | ||
| 6 | 5, | ||
| 7 | 6 | ||
| 8 | } | ||
| 9 | local out | ||
| 10 | do | ||
| 11 | local _tbl_0 = { } | ||
| 12 | for k in items do | ||
| 13 | _tbl_0[k] = k * 2 | ||
| 14 | end | ||
| 15 | out = _tbl_0 | ||
| 16 | end | ||
| 17 | local x = { | ||
| 18 | hello = "world", | ||
| 19 | okay = 2323 | ||
| 20 | } | ||
| 21 | local copy | ||
| 22 | do | ||
| 23 | local _tbl_0 = { } | ||
| 24 | for k, v in pairs(x) do | ||
| 25 | if k ~= "okay" then | ||
| 26 | _tbl_0[k] = v | ||
| 27 | end | ||
| 28 | end | ||
| 29 | copy = _tbl_0 | ||
| 30 | end | ||
| 31 | local _ | ||
| 32 | do | ||
| 33 | local _tbl_0 = { } | ||
| 34 | for x in yes do | ||
| 35 | local _key_0, _val_0 = unpack(x) | ||
| 36 | _tbl_0[_key_0] = _val_0 | ||
| 37 | end | ||
| 38 | _ = _tbl_0 | ||
| 39 | end | ||
| 40 | do | ||
| 41 | local _tbl_0 = { } | ||
| 42 | local _list_0 = yes | ||
| 43 | for _index_0 = 1, #_list_0 do | ||
| 44 | local x = _list_0[_index_0] | ||
| 45 | local _key_0, _val_0 = unpack(x) | ||
| 46 | _tbl_0[_key_0] = _val_0 | ||
| 47 | end | ||
| 48 | _ = _tbl_0 | ||
| 49 | end | ||
| 50 | do | ||
| 51 | local _tbl_0 = { } | ||
| 52 | for x in yes do | ||
| 53 | local _key_0, _val_0 = xxxx | ||
| 54 | _tbl_0[_key_0] = _val_0 | ||
| 55 | end | ||
| 56 | _ = _tbl_0 | ||
| 57 | end | ||
| 58 | do | ||
| 59 | local _tbl_0 = { } | ||
| 60 | local _list_0 = { | ||
| 61 | { | ||
| 62 | 1, | ||
| 63 | 2 | ||
| 64 | }, | ||
| 65 | { | ||
| 66 | 3, | ||
| 67 | 4 | ||
| 68 | } | ||
| 69 | } | ||
| 70 | for _index_0 = 1, #_list_0 do | ||
| 71 | local x = _list_0[_index_0] | ||
| 72 | local _key_0, _val_0 = unpack((function() | ||
| 73 | local _accum_0 = { } | ||
| 74 | local _len_0 = 1 | ||
| 75 | for i, a in ipairs(x) do | ||
| 76 | _accum_0[_len_0] = a * i | ||
| 77 | _len_0 = _len_0 + 1 | ||
| 78 | end | ||
| 79 | return _accum_0 | ||
| 80 | end)()) | ||
| 81 | _tbl_0[_key_0] = _val_0 | ||
| 82 | end | ||
| 83 | _ = _tbl_0 | ||
| 84 | end | ||
| 85 | local n1 | ||
| 86 | do | ||
| 87 | local _accum_0 = { } | ||
| 88 | local _len_0 = 1 | ||
| 89 | for i = 1, 10 do | ||
| 90 | _accum_0[_len_0] = i | ||
| 91 | _len_0 = _len_0 + 1 | ||
| 92 | end | ||
| 93 | n1 = _accum_0 | ||
| 94 | end | ||
| 95 | local n2 | ||
| 96 | do | ||
| 97 | local _accum_0 = { } | ||
| 98 | local _len_0 = 1 | ||
| 99 | for i = 1, 10 do | ||
| 100 | if i % 2 == 1 then | ||
| 101 | _accum_0[_len_0] = i | ||
| 102 | _len_0 = _len_0 + 1 | ||
| 103 | end | ||
| 104 | end | ||
| 105 | n2 = _accum_0 | ||
| 106 | end | ||
| 107 | local aa | ||
| 108 | do | ||
| 109 | local _accum_0 = { } | ||
| 110 | local _len_0 = 1 | ||
| 111 | for x = 1, 10 do | ||
| 112 | for y = 5, 14 do | ||
| 113 | _accum_0[_len_0] = { | ||
| 114 | x, | ||
| 115 | y | ||
| 116 | } | ||
| 117 | _len_0 = _len_0 + 1 | ||
| 118 | end | ||
| 119 | end | ||
| 120 | aa = _accum_0 | ||
| 121 | end | ||
| 122 | local bb | ||
| 123 | do | ||
| 124 | local _accum_0 = { } | ||
| 125 | local _len_0 = 1 | ||
| 126 | for thing in y do | ||
| 127 | for i = 1, 10 do | ||
| 128 | _accum_0[_len_0] = y | ||
| 129 | _len_0 = _len_0 + 1 | ||
| 130 | end | ||
| 131 | end | ||
| 132 | bb = _accum_0 | ||
| 133 | end | ||
| 134 | local cc | ||
| 135 | do | ||
| 136 | local _accum_0 = { } | ||
| 137 | local _len_0 = 1 | ||
| 138 | for i = 1, 10 do | ||
| 139 | for thing in y do | ||
| 140 | _accum_0[_len_0] = y | ||
| 141 | _len_0 = _len_0 + 1 | ||
| 142 | end | ||
| 143 | end | ||
| 144 | cc = _accum_0 | ||
| 145 | end | ||
| 146 | local dd | ||
| 147 | do | ||
| 148 | local _accum_0 = { } | ||
| 149 | local _len_0 = 1 | ||
| 150 | for i = 1, 10 do | ||
| 151 | if cool then | ||
| 152 | for thing in y do | ||
| 153 | if x > 3 then | ||
| 154 | if c + 3 then | ||
| 155 | _accum_0[_len_0] = y | ||
| 156 | _len_0 = _len_0 + 1 | ||
| 157 | end | ||
| 158 | end | ||
| 159 | end | ||
| 160 | end | ||
| 161 | end | ||
| 162 | dd = _accum_0 | ||
| 163 | end | ||
| 164 | do | ||
| 165 | local _tbl_0 = { } | ||
| 166 | for i = 1, 10 do | ||
| 167 | _tbl_0["hello"] = "world" | ||
| 168 | end | ||
| 169 | _ = _tbl_0 | ||
| 170 | end | ||
| 171 | local j | ||
| 172 | do | ||
| 173 | local _accum_0 = { } | ||
| 174 | local _len_0 = 1 | ||
| 175 | for _des_0 in things do | ||
| 176 | local a, b, c = _des_0[1], _des_0[2], _des_0[3] | ||
| 177 | _accum_0[_len_0] = a | ||
| 178 | _len_0 = _len_0 + 1 | ||
| 179 | end | ||
| 180 | j = _accum_0 | ||
| 181 | end | ||
| 182 | local k | ||
| 183 | do | ||
| 184 | local _accum_0 = { } | ||
| 185 | local _len_0 = 1 | ||
| 186 | local _list_0 = things | ||
| 187 | for _index_0 = 1, #_list_0 do | ||
| 188 | local _des_0 = _list_0[_index_0] | ||
| 189 | local a, b, c = _des_0[1], _des_0[2], _des_0[3] | ||
| 190 | _accum_0[_len_0] = a | ||
| 191 | _len_0 = _len_0 + 1 | ||
| 192 | end | ||
| 193 | k = _accum_0 | ||
| 194 | end | ||
| 195 | local i | ||
| 196 | do | ||
| 197 | local _accum_0 = { } | ||
| 198 | local _len_0 = 1 | ||
| 199 | local _list_0 = things | ||
| 200 | for _index_0 = 1, #_list_0 do | ||
| 201 | local _des_0 = _list_0[_index_0] | ||
| 202 | local hello, world = _des_0.hello, _des_0.world | ||
| 203 | _accum_0[_len_0] = hello | ||
| 204 | _len_0 = _len_0 + 1 | ||
| 205 | end | ||
| 206 | i = _accum_0 | ||
| 207 | end | ||
| 208 | local hj | ||
| 209 | do | ||
| 210 | local _tbl_0 = { } | ||
| 211 | for _des_0 in things do | ||
| 212 | local a, b, c = _des_0[1], _des_0[2], _des_0[3] | ||
| 213 | _tbl_0[a] = c | ||
| 214 | end | ||
| 215 | hj = _tbl_0 | ||
| 216 | end | ||
| 217 | local hk | ||
| 218 | do | ||
| 219 | local _tbl_0 = { } | ||
| 220 | local _list_0 = things | ||
| 221 | for _index_0 = 1, #_list_0 do | ||
| 222 | local _des_0 = _list_0[_index_0] | ||
| 223 | local a, b, c = _des_0[1], _des_0[2], _des_0[3] | ||
| 224 | _tbl_0[a] = c | ||
| 225 | end | ||
| 226 | hk = _tbl_0 | ||
| 227 | end | ||
| 228 | local hi | ||
| 229 | do | ||
| 230 | local _tbl_0 = { } | ||
| 231 | local _list_0 = things | ||
| 232 | for _index_0 = 1, #_list_0 do | ||
| 233 | local _des_0 = _list_0[_index_0] | ||
| 234 | local hello, world = _des_0.hello, _des_0.world | ||
| 235 | _tbl_0[hello] = world | ||
| 236 | end | ||
| 237 | hi = _tbl_0 | ||
| 238 | end | ||
| 239 | for _des_0 in things do | ||
| 240 | local a, b, c = _des_0[1], _des_0[2], _des_0[3] | ||
| 241 | ok(a, b, c) | ||
| 242 | end | ||
| 243 | do | ||
| 244 | local _accum_0 = { } | ||
| 245 | local _len_0 = 1 | ||
| 246 | local _max_0 = 3 + 4 | ||
| 247 | for _index_0 = 1 + 2, _max_0 < 0 and #items + _max_0 or _max_0 do | ||
| 248 | local item = items[_index_0] | ||
| 249 | _accum_0[_len_0] = item | ||
| 250 | _len_0 = _len_0 + 1 | ||
| 251 | end | ||
| 252 | _ = _accum_0 | ||
| 253 | end | ||
| 254 | do | ||
| 255 | local _accum_0 = { } | ||
| 256 | local _len_0 = 1 | ||
| 257 | local _max_0 = 2 - thing[4] | ||
| 258 | for _index_0 = hello() * 4, _max_0 < 0 and #items + _max_0 or _max_0 do | ||
| 259 | local item = items[_index_0] | ||
| 260 | _accum_0[_len_0] = item | ||
| 261 | _len_0 = _len_0 + 1 | ||
| 262 | end | ||
| 263 | _ = _accum_0 | ||
| 264 | end | ||
| 265 | local list | ||
| 266 | do | ||
| 267 | local _accum_0 = { } | ||
| 268 | local _len_0 = 1 | ||
| 269 | for item in items do | ||
| 270 | if item ~= nil then | ||
| 271 | _accum_0[_len_0] = item:invoke(123) | ||
| 272 | end | ||
| 273 | _len_0 = _len_0 + 1 | ||
| 274 | end | ||
| 275 | list = _accum_0 | ||
| 276 | end | ||
| 277 | return nil | ||
diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua new file mode 100644 index 0000000..5efa237 --- /dev/null +++ b/spec/outputs/cond.lua | |||
| @@ -0,0 +1,272 @@ | |||
| 1 | local you_cool = false | ||
| 2 | local _ | ||
| 3 | if cool then | ||
| 4 | if you_cool then | ||
| 5 | _ = one | ||
| 6 | else | ||
| 7 | if eatdic then | ||
| 8 | _ = yeah | ||
| 9 | else | ||
| 10 | _ = two | ||
| 11 | _ = three | ||
| 12 | end | ||
| 13 | end | ||
| 14 | else | ||
| 15 | _ = no | ||
| 16 | end | ||
| 17 | if cool then | ||
| 18 | _ = no | ||
| 19 | end | ||
| 20 | if cool then | ||
| 21 | _ = no | ||
| 22 | else | ||
| 23 | _ = yes | ||
| 24 | end | ||
| 25 | if cool then | ||
| 26 | wow(cool) | ||
| 27 | else | ||
| 28 | noso(cool) | ||
| 29 | end | ||
| 30 | if working then | ||
| 31 | if cool then | ||
| 32 | if cool then | ||
| 33 | _ = okay | ||
| 34 | else | ||
| 35 | _ = what | ||
| 36 | end | ||
| 37 | else | ||
| 38 | _ = nah | ||
| 39 | end | ||
| 40 | end | ||
| 41 | if yeah then | ||
| 42 | no(day) | ||
| 43 | elseif cool(me) then | ||
| 44 | okay(ya) | ||
| 45 | else | ||
| 46 | u(way) | ||
| 47 | end | ||
| 48 | if yeah then | ||
| 49 | no(dad) | ||
| 50 | else | ||
| 51 | if cool(you) then | ||
| 52 | okay(bah) | ||
| 53 | else | ||
| 54 | p(way) | ||
| 55 | end | ||
| 56 | end | ||
| 57 | if (function() end)() then | ||
| 58 | what(ever) | ||
| 59 | end | ||
| 60 | if nil then | ||
| 61 | flip(me) | ||
| 62 | else | ||
| 63 | it(be, rad) | ||
| 64 | end | ||
| 65 | if things(great) then | ||
| 66 | no(way) | ||
| 67 | elseif okay(sure) then | ||
| 68 | what(here) | ||
| 69 | end | ||
| 70 | if things then | ||
| 71 | no(chance) | ||
| 72 | elseif okay then | ||
| 73 | what(now) | ||
| 74 | end | ||
| 75 | if things then | ||
| 76 | yes(man) | ||
| 77 | elseif okay(person) then | ||
| 78 | hi(there) | ||
| 79 | else | ||
| 80 | hmm(sure) | ||
| 81 | end | ||
| 82 | if lets(go) then | ||
| 83 | print("greetings") | ||
| 84 | elseif "just us" then | ||
| 85 | print("will smith") | ||
| 86 | else | ||
| 87 | show(5555555) | ||
| 88 | end | ||
| 89 | do | ||
| 90 | local something = 10 | ||
| 91 | if something then | ||
| 92 | print(something) | ||
| 93 | else | ||
| 94 | print("else") | ||
| 95 | end | ||
| 96 | end | ||
| 97 | local hello | ||
| 98 | do | ||
| 99 | local something = 10 | ||
| 100 | if something then | ||
| 101 | hello = print(something) | ||
| 102 | else | ||
| 103 | hello = print("else") | ||
| 104 | end | ||
| 105 | end | ||
| 106 | hello = 5 + (function() | ||
| 107 | local something = 10 | ||
| 108 | if something then | ||
| 109 | return print(something) | ||
| 110 | end | ||
| 111 | end)() | ||
| 112 | local z = false | ||
| 113 | if false then | ||
| 114 | _ = one | ||
| 115 | else | ||
| 116 | do | ||
| 117 | local x = true | ||
| 118 | if x then | ||
| 119 | _ = two | ||
| 120 | else | ||
| 121 | z = true | ||
| 122 | if z then | ||
| 123 | _ = three | ||
| 124 | else | ||
| 125 | _ = four | ||
| 126 | end | ||
| 127 | end | ||
| 128 | end | ||
| 129 | end | ||
| 130 | local out | ||
| 131 | if false then | ||
| 132 | out = one | ||
| 133 | else | ||
| 134 | do | ||
| 135 | local x = true | ||
| 136 | if x then | ||
| 137 | out = two | ||
| 138 | else | ||
| 139 | z = true | ||
| 140 | if z then | ||
| 141 | out = three | ||
| 142 | else | ||
| 143 | out = four | ||
| 144 | end | ||
| 145 | end | ||
| 146 | end | ||
| 147 | end | ||
| 148 | local kzy | ||
| 149 | kzy = function() | ||
| 150 | do | ||
| 151 | local something = true | ||
| 152 | if something then | ||
| 153 | return 1 | ||
| 154 | else | ||
| 155 | do | ||
| 156 | local another = false | ||
| 157 | if another then | ||
| 158 | return 2 | ||
| 159 | end | ||
| 160 | end | ||
| 161 | end | ||
| 162 | end | ||
| 163 | end | ||
| 164 | if not true then | ||
| 165 | print("cool!") | ||
| 166 | end | ||
| 167 | if not (true and false) then | ||
| 168 | print("cool!") | ||
| 169 | end | ||
| 170 | if not false then | ||
| 171 | print("cool!") | ||
| 172 | end | ||
| 173 | if not false then | ||
| 174 | print("cool!") | ||
| 175 | else | ||
| 176 | print("no way!") | ||
| 177 | end | ||
| 178 | if not nil then | ||
| 179 | print("hello") | ||
| 180 | else | ||
| 181 | print("world") | ||
| 182 | end | ||
| 183 | local x | ||
| 184 | if not true then | ||
| 185 | x = print("cool!") | ||
| 186 | end | ||
| 187 | if not (true and false) then | ||
| 188 | x = print("cool!") | ||
| 189 | end | ||
| 190 | local y | ||
| 191 | if not false then | ||
| 192 | y = print("cool!") | ||
| 193 | end | ||
| 194 | if not false then | ||
| 195 | y = print("cool!") | ||
| 196 | else | ||
| 197 | y = print("no way!") | ||
| 198 | end | ||
| 199 | if not nil then | ||
| 200 | z = print("hello") | ||
| 201 | else | ||
| 202 | z = print("world") | ||
| 203 | end | ||
| 204 | print((function() | ||
| 205 | if not true then | ||
| 206 | return print("cool!") | ||
| 207 | end | ||
| 208 | end)()) | ||
| 209 | print((function() | ||
| 210 | if not (true and false) then | ||
| 211 | return print("cool!") | ||
| 212 | end | ||
| 213 | end)()) | ||
| 214 | print((function() | ||
| 215 | if not false then | ||
| 216 | return print("cool!") | ||
| 217 | end | ||
| 218 | end)()) | ||
| 219 | print((function() | ||
| 220 | if not false then | ||
| 221 | return print("cool!") | ||
| 222 | else | ||
| 223 | return print("no way!") | ||
| 224 | end | ||
| 225 | end)()) | ||
| 226 | print((function() | ||
| 227 | if not nil then | ||
| 228 | return print("hello") | ||
| 229 | else | ||
| 230 | return print("world") | ||
| 231 | end | ||
| 232 | end)()) | ||
| 233 | if not value then | ||
| 234 | print("hello") | ||
| 235 | end | ||
| 236 | local dddd | ||
| 237 | if not value then | ||
| 238 | dddd = { | ||
| 239 | 1, | ||
| 240 | 2, | ||
| 241 | 3 | ||
| 242 | } | ||
| 243 | end | ||
| 244 | do | ||
| 245 | local j = 100 | ||
| 246 | j = hi() | ||
| 247 | if not j then | ||
| 248 | error("not j!") | ||
| 249 | end | ||
| 250 | end | ||
| 251 | local a = 12 | ||
| 252 | local c, b | ||
| 253 | if something then | ||
| 254 | a, c, b = "cool" | ||
| 255 | end | ||
| 256 | local j | ||
| 257 | if 1 then | ||
| 258 | if 2 then | ||
| 259 | j = 3 | ||
| 260 | end | ||
| 261 | else | ||
| 262 | j = 6 | ||
| 263 | end | ||
| 264 | local m | ||
| 265 | if 1 then | ||
| 266 | if 2 then | ||
| 267 | m = 3 | ||
| 268 | end | ||
| 269 | else | ||
| 270 | m = 6 | ||
| 271 | end | ||
| 272 | return nil | ||
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua new file mode 100644 index 0000000..9ca13c8 --- /dev/null +++ b/spec/outputs/destructure.lua | |||
| @@ -0,0 +1,357 @@ | |||
| 1 | do | ||
| 2 | local a, b | ||
| 3 | do | ||
| 4 | local _obj_0 = hello | ||
| 5 | a, b = _obj_0[1], _obj_0[2] | ||
| 6 | end | ||
| 7 | local c | ||
| 8 | do | ||
| 9 | local _obj_0 = hello | ||
| 10 | a, b, c = _obj_0[1][1], _obj_0[2], _obj_0[3][1] | ||
| 11 | end | ||
| 12 | local hello, world | ||
| 13 | do | ||
| 14 | local _obj_0 = value | ||
| 15 | hello, world = _obj_0.hello, _obj_0.world | ||
| 16 | end | ||
| 17 | end | ||
| 18 | do | ||
| 19 | local no, thing | ||
| 20 | do | ||
| 21 | local _obj_0 = world | ||
| 22 | no, thing = _obj_0.yes, _obj_0[1] | ||
| 23 | end | ||
| 24 | local a, b, c, d | ||
| 25 | do | ||
| 26 | local _obj_0 = yeah | ||
| 27 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0.c, _obj_0.d | ||
| 28 | end | ||
| 29 | local _ = two | ||
| 30 | a = one[1] | ||
| 31 | c = nil | ||
| 32 | b = one[1] | ||
| 33 | local e = two | ||
| 34 | d = one[1] | ||
| 35 | local x = one | ||
| 36 | local y = two[1] | ||
| 37 | local xx, yy = 1, 2 | ||
| 38 | do | ||
| 39 | local _obj_0 = { | ||
| 40 | xx, | ||
| 41 | yy | ||
| 42 | } | ||
| 43 | yy, xx = _obj_0[1], _obj_0[2] | ||
| 44 | end | ||
| 45 | local f, g | ||
| 46 | do | ||
| 47 | local _obj_0 = tbl | ||
| 48 | a, b, c, d, e, f, g = _obj_0[1], _obj_0.b, _obj_0[2], _obj_0.d, _obj_0[3], _obj_0.f, _obj_0[4] | ||
| 49 | end | ||
| 50 | do | ||
| 51 | c = nil | ||
| 52 | do | ||
| 53 | local _obj_0 = tbl | ||
| 54 | a, b = _obj_0.a, _obj_0.b | ||
| 55 | end | ||
| 56 | end | ||
| 57 | do | ||
| 58 | a = tbl | ||
| 59 | b, c = _.b, _.c | ||
| 60 | end | ||
| 61 | do | ||
| 62 | b = _ | ||
| 63 | a = tbl.a | ||
| 64 | c = _.c | ||
| 65 | end | ||
| 66 | end | ||
| 67 | do | ||
| 68 | local futurists = { | ||
| 69 | sculptor = "Umberto Boccioni", | ||
| 70 | painter = "Vladimir Burliuk", | ||
| 71 | poet = { | ||
| 72 | name = "F.T. Marinetti", | ||
| 73 | address = { | ||
| 74 | "Via Roma 42R", | ||
| 75 | "Bellagio, Italy 22021" | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | do | ||
| 80 | local name, street, city = futurists.poet.name, futurists.poet.address[1], futurists.poet.address[2] | ||
| 81 | end | ||
| 82 | do | ||
| 83 | local sculptor, painter, name, street, city = futurists.sculptor, futurists.painter, futurists.poet.name, futurists.poet.address[1], futurists.poet.address[2] | ||
| 84 | end | ||
| 85 | end | ||
| 86 | do | ||
| 87 | local c, e | ||
| 88 | do | ||
| 89 | local _obj_0 = tb | ||
| 90 | c, e = _obj_0.a.b, _obj_0.a.d | ||
| 91 | end | ||
| 92 | end | ||
| 93 | do | ||
| 94 | local c, e, f | ||
| 95 | do | ||
| 96 | local _obj_0 = tb | ||
| 97 | c, e, f = _obj_0.a[1].b, _obj_0.a[2].d, _obj_0.a[3] | ||
| 98 | end | ||
| 99 | end | ||
| 100 | do | ||
| 101 | self.world = x[1] | ||
| 102 | do | ||
| 103 | local _obj_0 = x | ||
| 104 | a.b, c.y, func().z = _obj_0[1], _obj_0[2], _obj_0[3] | ||
| 105 | end | ||
| 106 | self.world = x.world | ||
| 107 | end | ||
| 108 | do | ||
| 109 | local thing = { | ||
| 110 | { | ||
| 111 | 1, | ||
| 112 | 2 | ||
| 113 | }, | ||
| 114 | { | ||
| 115 | 3, | ||
| 116 | 4 | ||
| 117 | } | ||
| 118 | } | ||
| 119 | for _index_0 = 1, #thing do | ||
| 120 | local _des_0 = thing[_index_0] | ||
| 121 | local x, y = _des_0[1], _des_0[2] | ||
| 122 | print(x, y) | ||
| 123 | end | ||
| 124 | end | ||
| 125 | do | ||
| 126 | do | ||
| 127 | local _with_0 = thing | ||
| 128 | local a, b = _with_0[1], _with_0[2] | ||
| 129 | print(a, b) | ||
| 130 | end | ||
| 131 | end | ||
| 132 | do | ||
| 133 | local thing = nil | ||
| 134 | if thing then | ||
| 135 | local a = thing[1] | ||
| 136 | print(a) | ||
| 137 | else | ||
| 138 | print("nothing") | ||
| 139 | end | ||
| 140 | local thang = { | ||
| 141 | 1, | ||
| 142 | 2 | ||
| 143 | } | ||
| 144 | if thang then | ||
| 145 | local a, b = thang[1], thang[2] | ||
| 146 | print(a, b) | ||
| 147 | end | ||
| 148 | if thing then | ||
| 149 | local a, b = thing[1], thing[2] | ||
| 150 | print(a, b) | ||
| 151 | else | ||
| 152 | if thang then | ||
| 153 | local c, d = thang[1], thang[2] | ||
| 154 | print(c, d) | ||
| 155 | else | ||
| 156 | print("NO") | ||
| 157 | end | ||
| 158 | end | ||
| 159 | end | ||
| 160 | do | ||
| 161 | local z = "yeah" | ||
| 162 | local a, b, c = z[1], z[2], z[3] | ||
| 163 | end | ||
| 164 | do | ||
| 165 | local a, b, c | ||
| 166 | do | ||
| 167 | local _obj_0 = z | ||
| 168 | a, b, c = _obj_0[1], _obj_0[2], _obj_0[3] | ||
| 169 | end | ||
| 170 | end | ||
| 171 | local _ | ||
| 172 | _ = function(z) | ||
| 173 | local a, b, c = z[1], z[2], z[3] | ||
| 174 | end | ||
| 175 | do | ||
| 176 | local z = "oo" | ||
| 177 | _ = function(k) | ||
| 178 | local a, b, c = z[1], z[2], z[3] | ||
| 179 | end | ||
| 180 | end | ||
| 181 | do | ||
| 182 | local endVar = thing["function"]["end"] | ||
| 183 | end | ||
| 184 | do | ||
| 185 | local a, b, c | ||
| 186 | do | ||
| 187 | local _obj_0 = thing | ||
| 188 | a, b, c = _obj_0["if"][1], _obj_0["if"][2], _obj_0["if"][3] | ||
| 189 | end | ||
| 190 | end | ||
| 191 | do | ||
| 192 | local a, b | ||
| 193 | if true then | ||
| 194 | do | ||
| 195 | local _obj_0 = { | ||
| 196 | a = "Hello", | ||
| 197 | b = "World" | ||
| 198 | } | ||
| 199 | a, b = _obj_0.a, _obj_0.b | ||
| 200 | end | ||
| 201 | end | ||
| 202 | local days, hours, mins, secs | ||
| 203 | do | ||
| 204 | local _accum_0 = { } | ||
| 205 | local _len_0 = 1 | ||
| 206 | local _list_0 = { | ||
| 207 | string.match("1 2 3 4", "(.+)%s(.+)%s(.+)%s(.+)") | ||
| 208 | } | ||
| 209 | for _index_0 = 1, #_list_0 do | ||
| 210 | local a = _list_0[_index_0] | ||
| 211 | _accum_0[_len_0] = tonumber(a) | ||
| 212 | _len_0 = _len_0 + 1 | ||
| 213 | end | ||
| 214 | days, hours, mins, secs = _accum_0[1], _accum_0[2], _accum_0[3], _accum_0[4] | ||
| 215 | end | ||
| 216 | local one, two, three | ||
| 217 | do | ||
| 218 | local _tbl_0 = { } | ||
| 219 | for w in foo:gmatch("%S+") do | ||
| 220 | _tbl_0[w] = true | ||
| 221 | end | ||
| 222 | one, two, three = _tbl_0.one, _tbl_0.two, _tbl_0.three | ||
| 223 | end | ||
| 224 | b = 123 | ||
| 225 | a = (a["if"](a, 123) + t).a | ||
| 226 | end | ||
| 227 | do | ||
| 228 | local name, job | ||
| 229 | do | ||
| 230 | local _obj_0 = person | ||
| 231 | name, job = _obj_0.name, _obj_0.job | ||
| 232 | end | ||
| 233 | if name == nil then | ||
| 234 | name = "nameless" | ||
| 235 | end | ||
| 236 | if job == nil then | ||
| 237 | job = "jobless" | ||
| 238 | end | ||
| 239 | local request | ||
| 240 | request = function(url, options) | ||
| 241 | if options == nil then | ||
| 242 | options = { } | ||
| 243 | end | ||
| 244 | local method, headers, parameters, payload, ok, err, final = options.method, options.headers, options.parameters, options.payload, options.ok, options.err, options.final | ||
| 245 | if method == nil then | ||
| 246 | method = "GET" | ||
| 247 | end | ||
| 248 | if headers == nil then | ||
| 249 | headers = { } | ||
| 250 | end | ||
| 251 | if parameters == nil then | ||
| 252 | parameters = { } | ||
| 253 | end | ||
| 254 | if payload == nil then | ||
| 255 | payload = "" | ||
| 256 | end | ||
| 257 | local res = makeRequest(url, method, parameters, payload, ok, err, final) | ||
| 258 | return res | ||
| 259 | end | ||
| 260 | local value1, key3 | ||
| 261 | do | ||
| 262 | local _obj_0 = tb | ||
| 263 | value1, key3 = _obj_0.key1.key2, _obj_0.key3 | ||
| 264 | end | ||
| 265 | if value1 == nil then | ||
| 266 | value1 = 123 | ||
| 267 | end | ||
| 268 | if key3 == nil then | ||
| 269 | key3 = "abc" | ||
| 270 | end | ||
| 271 | local mt, call, add | ||
| 272 | do | ||
| 273 | local _obj_0 = getmetatable(tb) | ||
| 274 | mt, call, add = _obj_0, getmetatable(_obj_0).__call, getmetatable(_obj_0).__add | ||
| 275 | end | ||
| 276 | if mt == nil then | ||
| 277 | mt = { | ||
| 278 | __index = { | ||
| 279 | abc = 123 | ||
| 280 | } | ||
| 281 | } | ||
| 282 | end | ||
| 283 | if call == nil then | ||
| 284 | call = (function() | ||
| 285 | return { } | ||
| 286 | end) | ||
| 287 | end | ||
| 288 | local _obj_0 = tb | ||
| 289 | local mtx, y, zItem = getmetatable(_obj_0.x), _obj_0.y, _obj_0.z | ||
| 290 | if mtx == nil then | ||
| 291 | mtx = { } | ||
| 292 | end | ||
| 293 | local index = getmetatable(_obj_0).__index | ||
| 294 | if index == nil then | ||
| 295 | index = function() | ||
| 296 | return nil | ||
| 297 | end | ||
| 298 | end | ||
| 299 | local _obj_1 = getmetatable(tb).func | ||
| 300 | if _obj_1 == nil then | ||
| 301 | if item ~= nil then | ||
| 302 | _obj_1 = item.defVal | ||
| 303 | end | ||
| 304 | end | ||
| 305 | a.b(function() | ||
| 306 | return 123 | ||
| 307 | end).c = _obj_1 | ||
| 308 | end | ||
| 309 | do | ||
| 310 | local mt, subFunc | ||
| 311 | do | ||
| 312 | local _obj_0 = getmetatable(tb.x) | ||
| 313 | mt, subFunc = _obj_0, _obj_0.__sub | ||
| 314 | end | ||
| 315 | if mt == nil then | ||
| 316 | mt = { } | ||
| 317 | end | ||
| 318 | end | ||
| 319 | do | ||
| 320 | local mt, subFunc | ||
| 321 | do | ||
| 322 | local _obj_0 = tb | ||
| 323 | mt, subFunc = getmetatable(_obj_0.x), getmetatable(_obj_0.x).__sub | ||
| 324 | end | ||
| 325 | if mt == nil then | ||
| 326 | mt = { } | ||
| 327 | end | ||
| 328 | end | ||
| 329 | do | ||
| 330 | local a, b, _obj_0 | ||
| 331 | do | ||
| 332 | local _obj_1 = tb | ||
| 333 | a, b, _obj_0 = _obj_1[1], _obj_1[2], _obj_1.c[1] | ||
| 334 | end | ||
| 335 | if a == nil then | ||
| 336 | a = 1 | ||
| 337 | end | ||
| 338 | if b == nil then | ||
| 339 | b = 2 | ||
| 340 | end | ||
| 341 | if _obj_0 == nil then | ||
| 342 | _obj_0 = 3 | ||
| 343 | end | ||
| 344 | d.e = _obj_0 | ||
| 345 | local _list_0 = tuples | ||
| 346 | for _index_0 = 1, #_list_0 do | ||
| 347 | local _des_0 = _list_0[_index_0] | ||
| 348 | local left, right = _des_0[1], _des_0[2] | ||
| 349 | if left == nil then | ||
| 350 | left = "null" | ||
| 351 | end | ||
| 352 | if right == nil then | ||
| 353 | right = false | ||
| 354 | end | ||
| 355 | print(left, right) | ||
| 356 | end | ||
| 357 | end | ||
diff --git a/spec/outputs/do.lua b/spec/outputs/do.lua new file mode 100644 index 0000000..96d1022 --- /dev/null +++ b/spec/outputs/do.lua | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | do | ||
| 2 | print("hello") | ||
| 3 | print("world") | ||
| 4 | end | ||
| 5 | local x | ||
| 6 | do | ||
| 7 | print("hello") | ||
| 8 | x = print("world") | ||
| 9 | end | ||
| 10 | local y | ||
| 11 | do | ||
| 12 | local things = "shhh" | ||
| 13 | y = function() | ||
| 14 | return "hello: " .. things | ||
| 15 | end | ||
| 16 | end | ||
| 17 | local _ | ||
| 18 | _ = function() | ||
| 19 | if something then | ||
| 20 | do | ||
| 21 | return "yeah" | ||
| 22 | end | ||
| 23 | end | ||
| 24 | end | ||
| 25 | local t = { | ||
| 26 | y = (function() | ||
| 27 | local number = 100 | ||
| 28 | return function(x) | ||
| 29 | return x + number | ||
| 30 | end | ||
| 31 | end)() | ||
| 32 | } | ||
| 33 | return function(y, k) | ||
| 34 | if y == nil then | ||
| 35 | y = ((function() | ||
| 36 | x = 10 + 2 | ||
| 37 | return x | ||
| 38 | end)()) | ||
| 39 | end | ||
| 40 | if k == nil then | ||
| 41 | do | ||
| 42 | k = "nothing" | ||
| 43 | end | ||
| 44 | end | ||
| 45 | do | ||
| 46 | return "uhhh" | ||
| 47 | end | ||
| 48 | end | ||
diff --git a/spec/outputs/existential.lua b/spec/outputs/existential.lua new file mode 100644 index 0000000..4a64c49 --- /dev/null +++ b/spec/outputs/existential.lua | |||
| @@ -0,0 +1,156 @@ | |||
| 1 | if f1 ~= nil then | ||
| 2 | f1() | ||
| 3 | end | ||
| 4 | if f2 ~= nil then | ||
| 5 | f2("arg0", 123) | ||
| 6 | end | ||
| 7 | local x | ||
| 8 | if tab ~= nil then | ||
| 9 | x = tab.value | ||
| 10 | end | ||
| 11 | print((function() | ||
| 12 | if abc ~= nil then | ||
| 13 | local _obj_0 = abc["hello world"] | ||
| 14 | if _obj_0 ~= nil then | ||
| 15 | return _obj_0.xyz | ||
| 16 | end | ||
| 17 | return nil | ||
| 18 | end | ||
| 19 | return nil | ||
| 20 | end)()) | ||
| 21 | if print and (x ~= nil) then | ||
| 22 | print(x) | ||
| 23 | end | ||
| 24 | if self ~= nil then | ||
| 25 | self:func(998) | ||
| 26 | end | ||
| 27 | do | ||
| 28 | local _with_0 | ||
| 29 | if abc ~= nil then | ||
| 30 | local _obj_0 = abc() | ||
| 31 | local _obj_1 = _obj_0.func | ||
| 32 | if _obj_1 ~= nil then | ||
| 33 | _with_0 = _obj_1(_obj_0) | ||
| 34 | end | ||
| 35 | end | ||
| 36 | if (function() | ||
| 37 | local _obj_0 = _with_0.p | ||
| 38 | if _obj_0 ~= nil then | ||
| 39 | return _obj_0(_with_0, "abc") | ||
| 40 | end | ||
| 41 | return nil | ||
| 42 | end)() then | ||
| 43 | return 123 | ||
| 44 | end | ||
| 45 | end | ||
| 46 | do | ||
| 47 | local _des_0 | ||
| 48 | if a ~= nil then | ||
| 49 | local _obj_0 = a["if"] | ||
| 50 | if _obj_0 ~= nil then | ||
| 51 | local _obj_1 = _obj_0["then"] | ||
| 52 | if _obj_1 ~= nil then | ||
| 53 | local _obj_2 = _obj_1(_obj_0, 123) | ||
| 54 | if _obj_2 ~= nil then | ||
| 55 | _des_0 = _obj_2((function() | ||
| 56 | if self ~= nil then | ||
| 57 | return self["function"](self, 998) | ||
| 58 | end | ||
| 59 | return nil | ||
| 60 | end)()) | ||
| 61 | end | ||
| 62 | end | ||
| 63 | end | ||
| 64 | end | ||
| 65 | if _des_0 then | ||
| 66 | x = _des_0.x | ||
| 67 | print(x) | ||
| 68 | end | ||
| 69 | end | ||
| 70 | local res = ((function() | ||
| 71 | local _call_0 = b["function"] | ||
| 72 | local _obj_0 = _call_0["do"](_call_0) | ||
| 73 | local _obj_1 = _obj_0["while"] | ||
| 74 | if _obj_1 ~= nil then | ||
| 75 | local _call_1 = _obj_1(_obj_0, "OK") | ||
| 76 | local _base_0 = _call_1["if"](_call_1, "def", 998) | ||
| 77 | local _fn_0 = _base_0.f | ||
| 78 | return _fn_0 and function(...) | ||
| 79 | return _fn_0(_base_0, ...) | ||
| 80 | end | ||
| 81 | end | ||
| 82 | return nil | ||
| 83 | end)() ~= nil) | ||
| 84 | print(res) | ||
| 85 | local solipsism | ||
| 86 | if (mind ~= nil) and not (world ~= nil) then | ||
| 87 | solipsism = true | ||
| 88 | end | ||
| 89 | local speed = 0 | ||
| 90 | speed = speed or 15 | ||
| 91 | local footprints = yeti or "bear" | ||
| 92 | local major = 'Computer Science' | ||
| 93 | if not (major ~= nil) then | ||
| 94 | signUpForClass('Introduction to Wines') | ||
| 95 | end | ||
| 96 | if (window ~= nil) then | ||
| 97 | local environment = 'browser (probably)' | ||
| 98 | end | ||
| 99 | local zip | ||
| 100 | local _obj_0 = lottery.drawWinner | ||
| 101 | if _obj_0 ~= nil then | ||
| 102 | local _obj_1 = _obj_0().address | ||
| 103 | if _obj_1 ~= nil then | ||
| 104 | zip = _obj_1.zipcode | ||
| 105 | end | ||
| 106 | end | ||
| 107 | local len = (function() | ||
| 108 | if utf8 ~= nil then | ||
| 109 | return utf8.len | ||
| 110 | end | ||
| 111 | return nil | ||
| 112 | end)() or (function() | ||
| 113 | if string ~= nil then | ||
| 114 | return string.len | ||
| 115 | end | ||
| 116 | return nil | ||
| 117 | end)() or function(o) | ||
| 118 | return #o | ||
| 119 | end | ||
| 120 | local a | ||
| 121 | if tb1 ~= nil then | ||
| 122 | local _obj_1 = tb1["end"] | ||
| 123 | if _obj_1 ~= nil then | ||
| 124 | a = _obj_1(tb1, 123 + (function() | ||
| 125 | if tb2 ~= nil then | ||
| 126 | return tb2["then"](tb2, 456) | ||
| 127 | end | ||
| 128 | return nil | ||
| 129 | end)()) | ||
| 130 | end | ||
| 131 | end | ||
| 132 | local b = ((function() | ||
| 133 | if tb1 ~= nil then | ||
| 134 | local _base_0 = tb1 | ||
| 135 | local _fn_0 = _base_0["end"] | ||
| 136 | return _fn_0 and function(...) | ||
| 137 | return _fn_0(_base_0, ...) | ||
| 138 | end | ||
| 139 | end | ||
| 140 | return nil | ||
| 141 | end)() ~= nil) or (function() | ||
| 142 | if tb2 ~= nil then | ||
| 143 | local _base_0 = tb2 | ||
| 144 | local _fn_0 = _base_0["then"] | ||
| 145 | return _fn_0 and function(...) | ||
| 146 | return _fn_0(_base_0, ...) | ||
| 147 | end | ||
| 148 | end | ||
| 149 | return nil | ||
| 150 | end)() | ||
| 151 | local _with_0 = io.open("test.txt", "w") | ||
| 152 | if _with_0 ~= nil then | ||
| 153 | _with_0:write("hello") | ||
| 154 | _with_0:close() | ||
| 155 | end | ||
| 156 | return _with_0 | ||
diff --git a/spec/outputs/export.lua b/spec/outputs/export.lua new file mode 100644 index 0000000..02546ec --- /dev/null +++ b/spec/outputs/export.lua | |||
| @@ -0,0 +1,307 @@ | |||
| 1 | local _module_0 = { } | ||
| 2 | local a, b, c = 223, 343, 123 | ||
| 3 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | ||
| 4 | local cool = "dad" | ||
| 5 | _module_0["cool"] = cool | ||
| 6 | local d, e, f = 3, 2, 1 | ||
| 7 | _module_0[#_module_0 + 1] = d | ||
| 8 | _module_0[#_module_0 + 1] = e | ||
| 9 | _module_0[#_module_0 + 1] = f | ||
| 10 | local Something | ||
| 11 | do | ||
| 12 | local _class_0 | ||
| 13 | local _base_0 = { | ||
| 14 | umm = "cool" | ||
| 15 | } | ||
| 16 | _base_0.__index = _base_0 | ||
| 17 | _class_0 = setmetatable({ | ||
| 18 | __init = function() end, | ||
| 19 | __base = _base_0, | ||
| 20 | __name = "Something" | ||
| 21 | }, { | ||
| 22 | __index = _base_0, | ||
| 23 | __call = function(cls, ...) | ||
| 24 | local _self_0 = setmetatable({ }, _base_0) | ||
| 25 | cls.__init(_self_0, ...) | ||
| 26 | return _self_0 | ||
| 27 | end | ||
| 28 | }) | ||
| 29 | _base_0.__class = _class_0 | ||
| 30 | Something = _class_0 | ||
| 31 | end | ||
| 32 | _module_0["Something"] = Something | ||
| 33 | if this then | ||
| 34 | _module_0[#_module_0 + 1] = 232 | ||
| 35 | else | ||
| 36 | _module_0[#_module_0 + 1] = 4343 | ||
| 37 | end | ||
| 38 | local What | ||
| 39 | if this then | ||
| 40 | What = 232 | ||
| 41 | else | ||
| 42 | What = 4343 | ||
| 43 | end | ||
| 44 | _module_0["What"] = What | ||
| 45 | local y | ||
| 46 | y = function() | ||
| 47 | local hallo = 3434 | ||
| 48 | end | ||
| 49 | _module_0["y"] = y | ||
| 50 | do | ||
| 51 | local _with_0 = tmp | ||
| 52 | local j = 2000 | ||
| 53 | _module_0[#_module_0 + 1] = _with_0 | ||
| 54 | end | ||
| 55 | local cbVal | ||
| 56 | do | ||
| 57 | local h = 100 | ||
| 58 | cbVal = f(function(x) | ||
| 59 | return x(h) | ||
| 60 | end) | ||
| 61 | end | ||
| 62 | _module_0["cbVal"] = cbVal | ||
| 63 | y = function() | ||
| 64 | local h = 100 | ||
| 65 | local k = 100 | ||
| 66 | end | ||
| 67 | _module_0["y"] = y | ||
| 68 | local _exp_0 = h | ||
| 69 | if 100 == _exp_0 or 150 == _exp_0 then | ||
| 70 | _module_0[#_module_0 + 1] = 200 | ||
| 71 | elseif 200 == _exp_0 then | ||
| 72 | _module_0[#_module_0 + 1] = 300 | ||
| 73 | else | ||
| 74 | _module_0[#_module_0 + 1] = 0 | ||
| 75 | end | ||
| 76 | local Constant | ||
| 77 | local _exp_1 = value | ||
| 78 | if "good" == _exp_1 then | ||
| 79 | Constant = 1 | ||
| 80 | elseif "better" == _exp_1 then | ||
| 81 | Constant = 2 | ||
| 82 | elseif "best" == _exp_1 then | ||
| 83 | Constant = 3 | ||
| 84 | end | ||
| 85 | _module_0["Constant"] = Constant | ||
| 86 | local item = func(123) | ||
| 87 | _module_0["item"] = item | ||
| 88 | _module_0[#_module_0 + 1] = x | ||
| 89 | f((function() | ||
| 90 | if a then | ||
| 91 | return b | ||
| 92 | end | ||
| 93 | end)()) | ||
| 94 | f((function() | ||
| 95 | return 123 | ||
| 96 | end)()) | ||
| 97 | f((function() | ||
| 98 | if b == a then | ||
| 99 | return c | ||
| 100 | end | ||
| 101 | end)()) | ||
| 102 | f((function() | ||
| 103 | local _accum_0 = { } | ||
| 104 | local _len_0 = 1 | ||
| 105 | for i = 1, 10 do | ||
| 106 | _accum_0[_len_0] = i | ||
| 107 | _len_0 = _len_0 + 1 | ||
| 108 | end | ||
| 109 | return _accum_0 | ||
| 110 | end)()) | ||
| 111 | f((function() | ||
| 112 | local _accum_0 = { } | ||
| 113 | local _len_0 = 1 | ||
| 114 | for i = 1, 10 do | ||
| 115 | _accum_0[_len_0] = i | ||
| 116 | _len_0 = _len_0 + 1 | ||
| 117 | end | ||
| 118 | return _accum_0 | ||
| 119 | end)()) | ||
| 120 | f((function() | ||
| 121 | local _tbl_0 = { } | ||
| 122 | for k, v in pairs(tb) do | ||
| 123 | _tbl_0[k] = v | ||
| 124 | end | ||
| 125 | return _tbl_0 | ||
| 126 | end)()) | ||
| 127 | f((function() | ||
| 128 | local _accum_0 = { } | ||
| 129 | local _len_0 = 1 | ||
| 130 | for k, v in pairs(tb) do | ||
| 131 | _accum_0[_len_0] = k, v | ||
| 132 | _len_0 = _len_0 + 1 | ||
| 133 | end | ||
| 134 | return _accum_0 | ||
| 135 | end)()) | ||
| 136 | f((function() | ||
| 137 | local _accum_0 = { } | ||
| 138 | local _len_0 = 1 | ||
| 139 | while a do | ||
| 140 | _accum_0[_len_0] = true | ||
| 141 | _len_0 = _len_0 + 1 | ||
| 142 | end | ||
| 143 | return _accum_0 | ||
| 144 | end)()) | ||
| 145 | f((function() | ||
| 146 | a.b = 123 | ||
| 147 | return a | ||
| 148 | end)()) | ||
| 149 | f((function() | ||
| 150 | if a ~= nil then | ||
| 151 | return a.b | ||
| 152 | end | ||
| 153 | return nil | ||
| 154 | end)()) | ||
| 155 | f((function() | ||
| 156 | local _base_0 = a | ||
| 157 | local _fn_0 = _base_0.b | ||
| 158 | return _fn_0 and function(...) | ||
| 159 | return _fn_0(_base_0, ...) | ||
| 160 | end | ||
| 161 | end)()) | ||
| 162 | f((function() | ||
| 163 | local A | ||
| 164 | do | ||
| 165 | local _class_0 | ||
| 166 | local _base_0 = { } | ||
| 167 | _base_0.__index = _base_0 | ||
| 168 | _class_0 = setmetatable({ | ||
| 169 | __init = function() end, | ||
| 170 | __base = _base_0, | ||
| 171 | __name = "A" | ||
| 172 | }, { | ||
| 173 | __index = _base_0, | ||
| 174 | __call = function(cls, ...) | ||
| 175 | local _self_0 = setmetatable({ }, _base_0) | ||
| 176 | cls.__init(_self_0, ...) | ||
| 177 | return _self_0 | ||
| 178 | end | ||
| 179 | }) | ||
| 180 | _base_0.__class = _class_0 | ||
| 181 | A = _class_0 | ||
| 182 | return _class_0 | ||
| 183 | end | ||
| 184 | end)()) | ||
| 185 | local _ = tostring((function() | ||
| 186 | if a then | ||
| 187 | return b | ||
| 188 | end | ||
| 189 | end)()) | ||
| 190 | _ = tostring((function() | ||
| 191 | return 123 | ||
| 192 | end)()) | ||
| 193 | _ = tostring((function() | ||
| 194 | if b == a then | ||
| 195 | return c | ||
| 196 | end | ||
| 197 | end)()) | ||
| 198 | _ = tostring((function() | ||
| 199 | local _accum_0 = { } | ||
| 200 | local _len_0 = 1 | ||
| 201 | for i = 1, 10 do | ||
| 202 | _accum_0[_len_0] = i | ||
| 203 | _len_0 = _len_0 + 1 | ||
| 204 | end | ||
| 205 | return _accum_0 | ||
| 206 | end)()) | ||
| 207 | _ = tostring((function() | ||
| 208 | local _accum_0 = { } | ||
| 209 | local _len_0 = 1 | ||
| 210 | for i = 1, 10 do | ||
| 211 | _accum_0[_len_0] = i | ||
| 212 | _len_0 = _len_0 + 1 | ||
| 213 | end | ||
| 214 | return _accum_0 | ||
| 215 | end)()) | ||
| 216 | _ = tostring((function() | ||
| 217 | local _tbl_0 = { } | ||
| 218 | for k, v in pairs(tb) do | ||
| 219 | _tbl_0[k] = v | ||
| 220 | end | ||
| 221 | return _tbl_0 | ||
| 222 | end)()) | ||
| 223 | _ = tostring((function() | ||
| 224 | local _accum_0 = { } | ||
| 225 | local _len_0 = 1 | ||
| 226 | for k, v in pairs(tb) do | ||
| 227 | _accum_0[_len_0] = k, v | ||
| 228 | _len_0 = _len_0 + 1 | ||
| 229 | end | ||
| 230 | return _accum_0 | ||
| 231 | end)()) | ||
| 232 | _ = tostring((function() | ||
| 233 | local _accum_0 = { } | ||
| 234 | local _len_0 = 1 | ||
| 235 | while a do | ||
| 236 | _accum_0[_len_0] = true | ||
| 237 | _len_0 = _len_0 + 1 | ||
| 238 | end | ||
| 239 | return _accum_0 | ||
| 240 | end)()) | ||
| 241 | _ = tostring((function() | ||
| 242 | a.b = 123 | ||
| 243 | return a | ||
| 244 | end)()) | ||
| 245 | _ = tostring((function() | ||
| 246 | if a ~= nil then | ||
| 247 | return a.b | ||
| 248 | end | ||
| 249 | return nil | ||
| 250 | end)()) | ||
| 251 | _ = tostring((function() | ||
| 252 | local _base_0 = a | ||
| 253 | local _fn_0 = _base_0.b | ||
| 254 | return _fn_0 and function(...) | ||
| 255 | return _fn_0(_base_0, ...) | ||
| 256 | end | ||
| 257 | end)()) | ||
| 258 | _ = tostring((function() | ||
| 259 | local A | ||
| 260 | do | ||
| 261 | local _class_0 | ||
| 262 | local _base_0 = { } | ||
| 263 | _base_0.__index = _base_0 | ||
| 264 | _class_0 = setmetatable({ | ||
| 265 | __init = function() end, | ||
| 266 | __base = _base_0, | ||
| 267 | __name = "A" | ||
| 268 | }, { | ||
| 269 | __index = _base_0, | ||
| 270 | __call = function(cls, ...) | ||
| 271 | local _self_0 = setmetatable({ }, _base_0) | ||
| 272 | cls.__init(_self_0, ...) | ||
| 273 | return _self_0 | ||
| 274 | end | ||
| 275 | }) | ||
| 276 | _base_0.__class = _class_0 | ||
| 277 | A = _class_0 | ||
| 278 | return _class_0 | ||
| 279 | end | ||
| 280 | end)()) | ||
| 281 | local v1, v2, v3, v4, v5 | ||
| 282 | v1 = 1 | ||
| 283 | v2 = 2 | ||
| 284 | _module_0["v2"] = v2 | ||
| 285 | do | ||
| 286 | local _class_0 | ||
| 287 | local _base_0 = { } | ||
| 288 | _base_0.__index = _base_0 | ||
| 289 | _class_0 = setmetatable({ | ||
| 290 | __init = function() end, | ||
| 291 | __base = _base_0, | ||
| 292 | __name = "v4" | ||
| 293 | }, { | ||
| 294 | __index = _base_0, | ||
| 295 | __call = function(cls, ...) | ||
| 296 | local _self_0 = setmetatable({ }, _base_0) | ||
| 297 | cls.__init(_self_0, ...) | ||
| 298 | return _self_0 | ||
| 299 | end | ||
| 300 | }) | ||
| 301 | _base_0.__class = _class_0 | ||
| 302 | v4 = _class_0 | ||
| 303 | v3 = _class_0 | ||
| 304 | end | ||
| 305 | _module_0["v3"] = v3 | ||
| 306 | v5 = 5 | ||
| 307 | return _module_0 | ||
diff --git a/spec/outputs/export_default.lua b/spec/outputs/export_default.lua new file mode 100644 index 0000000..a9c787f --- /dev/null +++ b/spec/outputs/export_default.lua | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | local _module_0 = nil | ||
| 2 | print("OK") | ||
| 3 | _module_0 = function() | ||
| 4 | print("hello") | ||
| 5 | return 123 | ||
| 6 | end | ||
| 7 | if not isOff then | ||
| 8 | f(123, "abc", function(x, fy) | ||
| 9 | print(x) | ||
| 10 | return fy(function(y, res) | ||
| 11 | if res then | ||
| 12 | return abc + y | ||
| 13 | else | ||
| 14 | return abc | ||
| 15 | end | ||
| 16 | end) | ||
| 17 | end) | ||
| 18 | end | ||
| 19 | return _module_0 | ||
diff --git a/spec/outputs/funcs.lua b/spec/outputs/funcs.lua new file mode 100644 index 0000000..03281e4 --- /dev/null +++ b/spec/outputs/funcs.lua | |||
| @@ -0,0 +1,222 @@ | |||
| 1 | local x | ||
| 2 | x = function() | ||
| 3 | return print(what) | ||
| 4 | end | ||
| 5 | local _ | ||
| 6 | _ = function() end | ||
| 7 | _ = function() | ||
| 8 | return function() | ||
| 9 | return function() end | ||
| 10 | end | ||
| 11 | end | ||
| 12 | go(to(the(barn))) | ||
| 13 | open(function() | ||
| 14 | return the(function() | ||
| 15 | return door | ||
| 16 | end) | ||
| 17 | end) | ||
| 18 | open(function() | ||
| 19 | the(door) | ||
| 20 | local hello | ||
| 21 | hello = function() | ||
| 22 | return my(func) | ||
| 23 | end | ||
| 24 | end) | ||
| 25 | local h | ||
| 26 | h = function() | ||
| 27 | return hi | ||
| 28 | end | ||
| 29 | eat(function() end, world); | ||
| 30 | (function() end)() | ||
| 31 | x = function(...) end | ||
| 32 | hello() | ||
| 33 | hello.world() | ||
| 34 | _ = hello().something | ||
| 35 | _ = what()["ofefe"] | ||
| 36 | what()(the()(heck())) | ||
| 37 | _ = function(a, b, c, d, e) end | ||
| 38 | _ = function(a, a, a, a, a) | ||
| 39 | return print(a) | ||
| 40 | end | ||
| 41 | _ = function(x) | ||
| 42 | if x == nil then | ||
| 43 | x = 23023 | ||
| 44 | end | ||
| 45 | end | ||
| 46 | _ = function(x) | ||
| 47 | if x == nil then | ||
| 48 | x = function(y) | ||
| 49 | if y == nil then | ||
| 50 | y = function() end | ||
| 51 | end | ||
| 52 | end | ||
| 53 | end | ||
| 54 | end | ||
| 55 | _ = function(x) | ||
| 56 | if x == nil then | ||
| 57 | if something then | ||
| 58 | x = yeah | ||
| 59 | else | ||
| 60 | x = no | ||
| 61 | end | ||
| 62 | end | ||
| 63 | end | ||
| 64 | local something | ||
| 65 | something = function(hello, world) | ||
| 66 | if hello == nil then | ||
| 67 | hello = 100 | ||
| 68 | end | ||
| 69 | if world == nil then | ||
| 70 | world = function(x) | ||
| 71 | if x == nil then | ||
| 72 | x = [[yeah cool]] | ||
| 73 | end | ||
| 74 | return print("eat rice") | ||
| 75 | end | ||
| 76 | end | ||
| 77 | return print(hello) | ||
| 78 | end | ||
| 79 | _ = function(self) end | ||
| 80 | _ = function(self, x, y) end | ||
| 81 | _ = function(self, x, y) | ||
| 82 | self.x = x | ||
| 83 | self.y = y | ||
| 84 | end | ||
| 85 | _ = function(self, x) | ||
| 86 | if x == nil then | ||
| 87 | x = 1 | ||
| 88 | end | ||
| 89 | end | ||
| 90 | _ = function(self, x, y, z) | ||
| 91 | if x == nil then | ||
| 92 | x = 1 | ||
| 93 | end | ||
| 94 | if z == nil then | ||
| 95 | z = "hello world" | ||
| 96 | end | ||
| 97 | self.x = x | ||
| 98 | self.z = z | ||
| 99 | end | ||
| 100 | x(function() | ||
| 101 | return | ||
| 102 | end) | ||
| 103 | y(function() | ||
| 104 | return 1 | ||
| 105 | end) | ||
| 106 | z(function() | ||
| 107 | return 1, "hello", "world" | ||
| 108 | end) | ||
| 109 | k(function() | ||
| 110 | if yes then | ||
| 111 | return | ||
| 112 | else | ||
| 113 | return | ||
| 114 | end | ||
| 115 | end) | ||
| 116 | _ = function() | ||
| 117 | if something then | ||
| 118 | return real_name | ||
| 119 | end | ||
| 120 | end | ||
| 121 | d(function() | ||
| 122 | return print("hello world") | ||
| 123 | end, 10) | ||
| 124 | d(1, 2, 3, 4, 5, 6, (function() | ||
| 125 | if something then | ||
| 126 | print("okay") | ||
| 127 | return 10 | ||
| 128 | end | ||
| 129 | end)(), 10, 20) | ||
| 130 | f()()(what)(function() | ||
| 131 | return print("srue") | ||
| 132 | end, 123) | ||
| 133 | x = function(a, b) | ||
| 134 | return print("what") | ||
| 135 | end | ||
| 136 | local y | ||
| 137 | y = function(a, b) | ||
| 138 | if a == nil then | ||
| 139 | a = "hi" | ||
| 140 | end | ||
| 141 | if b == nil then | ||
| 142 | b = 23 | ||
| 143 | end | ||
| 144 | return print("what") | ||
| 145 | end | ||
| 146 | local z | ||
| 147 | z = function(a, b) | ||
| 148 | if a == nil then | ||
| 149 | a = "hi" | ||
| 150 | end | ||
| 151 | if b == nil then | ||
| 152 | b = 23 | ||
| 153 | end | ||
| 154 | return print("what") | ||
| 155 | end | ||
| 156 | local j | ||
| 157 | j = function(f, g, m, a, b) | ||
| 158 | if a == nil then | ||
| 159 | a = "hi" | ||
| 160 | end | ||
| 161 | if b == nil then | ||
| 162 | b = 23 | ||
| 163 | end | ||
| 164 | return print("what") | ||
| 165 | end | ||
| 166 | y = function(a, b, ...) | ||
| 167 | if a == nil then | ||
| 168 | a = "hi" | ||
| 169 | end | ||
| 170 | if b == nil then | ||
| 171 | b = 23 | ||
| 172 | end | ||
| 173 | return print("what") | ||
| 174 | end | ||
| 175 | y = function(a, b, ...) | ||
| 176 | if a == nil then | ||
| 177 | a = "hi" | ||
| 178 | end | ||
| 179 | if b == nil then | ||
| 180 | b = 23 | ||
| 181 | end | ||
| 182 | return print("what") | ||
| 183 | end | ||
| 184 | local args | ||
| 185 | args = function(a, b) | ||
| 186 | return print("what") | ||
| 187 | end | ||
| 188 | args = function(a, b) | ||
| 189 | if a == nil then | ||
| 190 | a = "hi" | ||
| 191 | end | ||
| 192 | if b == nil then | ||
| 193 | b = 23 | ||
| 194 | end | ||
| 195 | return print("what") | ||
| 196 | end | ||
| 197 | args = function(a, b) | ||
| 198 | if a == nil then | ||
| 199 | a = "hi" | ||
| 200 | end | ||
| 201 | if b == nil then | ||
| 202 | b = 23 | ||
| 203 | end | ||
| 204 | return print("what") | ||
| 205 | end | ||
| 206 | args = function(f, g, m, a, b) | ||
| 207 | if a == nil then | ||
| 208 | a = "hi" | ||
| 209 | end | ||
| 210 | if b == nil then | ||
| 211 | b = 23 | ||
| 212 | end | ||
| 213 | return print("what") | ||
| 214 | end | ||
| 215 | local self | ||
| 216 | self = function(n) | ||
| 217 | if n == 0 then | ||
| 218 | return 1 | ||
| 219 | end | ||
| 220 | return n * self(n - 1) | ||
| 221 | end | ||
| 222 | return nil | ||
diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua new file mode 100644 index 0000000..1c9a3cf --- /dev/null +++ b/spec/outputs/global.lua | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | do | ||
| 2 | a, b, c = 223, 343 | ||
| 3 | cool = "dad" | ||
| 4 | end | ||
| 5 | do | ||
| 6 | do | ||
| 7 | local _class_0 | ||
| 8 | local _base_0 = { | ||
| 9 | umm = "cool" | ||
| 10 | } | ||
| 11 | _base_0.__index = _base_0 | ||
| 12 | _class_0 = setmetatable({ | ||
| 13 | __init = function() end, | ||
| 14 | __base = _base_0, | ||
| 15 | __name = "Something" | ||
| 16 | }, { | ||
| 17 | __index = _base_0, | ||
| 18 | __call = function(cls, ...) | ||
| 19 | local _self_0 = setmetatable({ }, _base_0) | ||
| 20 | cls.__init(_self_0, ...) | ||
| 21 | return _self_0 | ||
| 22 | end | ||
| 23 | }) | ||
| 24 | _base_0.__class = _class_0 | ||
| 25 | Something = _class_0 | ||
| 26 | end | ||
| 27 | end | ||
| 28 | do | ||
| 29 | local d | ||
| 30 | a, b, c, d = "hello" | ||
| 31 | end | ||
| 32 | do | ||
| 33 | local What | ||
| 34 | if this then | ||
| 35 | What = 232 | ||
| 36 | else | ||
| 37 | What = 4343 | ||
| 38 | end | ||
| 39 | local another = 3434 | ||
| 40 | Another = 7890 | ||
| 41 | if inner then | ||
| 42 | local Yeah = "10000" | ||
| 43 | end | ||
| 44 | if this then | ||
| 45 | What = 232 | ||
| 46 | else | ||
| 47 | What = 4343 | ||
| 48 | end | ||
| 49 | end | ||
| 50 | do | ||
| 51 | if this then | ||
| 52 | What = 232 | ||
| 53 | else | ||
| 54 | What = 4343 | ||
| 55 | end | ||
| 56 | x, y, z = 1, 2, 3 | ||
| 57 | y = function() | ||
| 58 | local hallo = 3434 | ||
| 59 | end | ||
| 60 | do | ||
| 61 | local _with_0 = tmp | ||
| 62 | local j = 2000 | ||
| 63 | end | ||
| 64 | end | ||
| 65 | do | ||
| 66 | x = 3434 | ||
| 67 | if y then | ||
| 68 | x = 10 | ||
| 69 | end | ||
| 70 | end | ||
| 71 | do | ||
| 72 | if y then | ||
| 73 | local x = 10 | ||
| 74 | end | ||
| 75 | x = 3434 | ||
| 76 | end | ||
| 77 | do | ||
| 78 | do | ||
| 79 | k = 1212 | ||
| 80 | do | ||
| 81 | local h = 100 | ||
| 82 | end | ||
| 83 | y = function() | ||
| 84 | local h = 100 | ||
| 85 | k = 100 | ||
| 86 | end | ||
| 87 | end | ||
| 88 | local h = 100 | ||
| 89 | end | ||
diff --git a/spec/outputs/goto.lua b/spec/outputs/goto.lua new file mode 100644 index 0000000..d1f7b77 --- /dev/null +++ b/spec/outputs/goto.lua | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | do | ||
| 2 | local a = 0 | ||
| 3 | ::start:: | ||
| 4 | a = a + 1 | ||
| 5 | if a == 5 then | ||
| 6 | goto done | ||
| 7 | end | ||
| 8 | goto start | ||
| 9 | ::done:: | ||
| 10 | end | ||
| 11 | do | ||
| 12 | for z = 1, 10 do | ||
| 13 | for y = 1, 10 do | ||
| 14 | for x = 1, 10 do | ||
| 15 | if x ^ 2 + y ^ 2 == z ^ 2 then | ||
| 16 | print('found a Pythagorean triple:', x, y, z) | ||
| 17 | goto done | ||
| 18 | end | ||
| 19 | end | ||
| 20 | end | ||
| 21 | end | ||
| 22 | ::done:: | ||
| 23 | end | ||
| 24 | do | ||
| 25 | for z = 1, 10 do | ||
| 26 | for y = 1, 10 do | ||
| 27 | for x = 1, 10 do | ||
| 28 | if x ^ 2 + y ^ 2 == z ^ 2 then | ||
| 29 | print('found a Pythagorean triple:', x, y, z) | ||
| 30 | print('now trying next z...') | ||
| 31 | goto zcontinue | ||
| 32 | end | ||
| 33 | end | ||
| 34 | end | ||
| 35 | ::zcontinue:: | ||
| 36 | end | ||
| 37 | end | ||
| 38 | do | ||
| 39 | ::redo:: | ||
| 40 | for x = 1, 10 do | ||
| 41 | for y = 1, 10 do | ||
| 42 | if not f(x, y) then | ||
| 43 | goto continue | ||
| 44 | end | ||
| 45 | if not g(x, y) then | ||
| 46 | goto skip | ||
| 47 | end | ||
| 48 | if not h(x, y) then | ||
| 49 | goto redo | ||
| 50 | end | ||
| 51 | ::continue:: | ||
| 52 | end | ||
| 53 | end | ||
| 54 | ::skip:: | ||
| 55 | end | ||
| 56 | do | ||
| 57 | local _list_0 = t | ||
| 58 | for _index_0 = 1, #_list_0 do | ||
| 59 | local x = _list_0[_index_0] | ||
| 60 | if x % 2 == 0 then | ||
| 61 | print('list has even number') | ||
| 62 | goto has | ||
| 63 | end | ||
| 64 | end | ||
| 65 | print('list lacks even number') | ||
| 66 | ::has:: | ||
| 67 | end | ||
diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua new file mode 100644 index 0000000..02e210b --- /dev/null +++ b/spec/outputs/import.lua | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | local hello = yeah.hello | ||
| 2 | local world | ||
| 3 | do | ||
| 4 | local _obj_0 = table["cool"] | ||
| 5 | hello, world = _obj_0.hello, _obj_0.world | ||
| 6 | end | ||
| 7 | local a, b, c = items.a, (function() | ||
| 8 | local _base_0 = items | ||
| 9 | local _fn_0 = _base_0.b | ||
| 10 | return _fn_0 and function(...) | ||
| 11 | return _fn_0(_base_0, ...) | ||
| 12 | end | ||
| 13 | end)(), items.c | ||
| 14 | local master, ghost | ||
| 15 | do | ||
| 16 | local _obj_0 = find("mytable") | ||
| 17 | master, ghost = _obj_0.master, (function() | ||
| 18 | local _base_0 = _obj_0 | ||
| 19 | local _fn_0 = _base_0.ghost | ||
| 20 | return _fn_0 and function(...) | ||
| 21 | return _fn_0(_base_0, ...) | ||
| 22 | end | ||
| 23 | end)() | ||
| 24 | end | ||
| 25 | local yumm | ||
| 26 | a, yumm = 3434, "hello" | ||
| 27 | local _table_0 = 232 | ||
| 28 | local something | ||
| 29 | do | ||
| 30 | local _obj_0 = a(table) | ||
| 31 | something = _obj_0.something | ||
| 32 | end | ||
| 33 | if indent then | ||
| 34 | local okay, well | ||
| 35 | do | ||
| 36 | local _obj_0 = tables[100] | ||
| 37 | okay, well = _obj_0.okay, (function() | ||
| 38 | local _base_0 = _obj_0 | ||
| 39 | local _fn_0 = _base_0.well | ||
| 40 | return _fn_0 and function(...) | ||
| 41 | return _fn_0(_base_0, ...) | ||
| 42 | end | ||
| 43 | end)() | ||
| 44 | end | ||
| 45 | end | ||
| 46 | do | ||
| 47 | a, b, c = z.a, z.b, z.c | ||
| 48 | end | ||
| 49 | do | ||
| 50 | a, b, c = z.a, z.b, z.c | ||
| 51 | end | ||
| 52 | do | ||
| 53 | a, b, c = z.a, z.b, z.c | ||
| 54 | end | ||
| 55 | do | ||
| 56 | a, b, c = z.a, z.b, z.c | ||
| 57 | end | ||
| 58 | do | ||
| 59 | a, b, c = z.a, z.b, z.c | ||
| 60 | end | ||
| 61 | do | ||
| 62 | local module = require('module') | ||
| 63 | local module_x = require('module_x') | ||
| 64 | local d_a_s_h_e_s = require("d-a-s-h-e-s") | ||
| 65 | local part = require("module.part") | ||
| 66 | end | ||
| 67 | do | ||
| 68 | local Player = require("player") | ||
| 69 | local C, Ct, Cmt | ||
| 70 | do | ||
| 71 | local _obj_0 = require("lpeg") | ||
| 72 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
| 73 | end | ||
| 74 | local one, two, ch | ||
| 75 | do | ||
| 76 | local _obj_0 = require("export") | ||
| 77 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | ||
| 78 | end | ||
| 79 | local Another = require("export").Another | ||
| 80 | end | ||
| 81 | do | ||
| 82 | module = require('module') | ||
| 83 | module_x = require('module_x') | ||
| 84 | module_y = require("org.package.module-y") | ||
| 85 | end | ||
| 86 | do | ||
| 87 | local func, ifVar | ||
| 88 | do | ||
| 89 | local _obj_0 = require("org.package.module") | ||
| 90 | func, ifVar = _obj_0["function"], _obj_0["if"] | ||
| 91 | end | ||
| 92 | end | ||
diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua new file mode 100644 index 0000000..581cc23 --- /dev/null +++ b/spec/outputs/lists.lua | |||
| @@ -0,0 +1,282 @@ | |||
| 1 | local hi | ||
| 2 | do | ||
| 3 | local _accum_0 = { } | ||
| 4 | local _len_0 = 1 | ||
| 5 | for _, x in ipairs({ | ||
| 6 | 1, | ||
| 7 | 2, | ||
| 8 | 3, | ||
| 9 | 4 | ||
| 10 | }) do | ||
| 11 | _accum_0[_len_0] = x * 2 | ||
| 12 | _len_0 = _len_0 + 1 | ||
| 13 | end | ||
| 14 | hi = _accum_0 | ||
| 15 | end | ||
| 16 | local items = { | ||
| 17 | 1, | ||
| 18 | 2, | ||
| 19 | 3, | ||
| 20 | 4, | ||
| 21 | 5, | ||
| 22 | 6 | ||
| 23 | } | ||
| 24 | local _ | ||
| 25 | do | ||
| 26 | local _accum_0 = { } | ||
| 27 | local _len_0 = 1 | ||
| 28 | for z in ipairs(items) do | ||
| 29 | if z > 4 then | ||
| 30 | _accum_0[_len_0] = z | ||
| 31 | _len_0 = _len_0 + 1 | ||
| 32 | end | ||
| 33 | end | ||
| 34 | _ = _accum_0 | ||
| 35 | end | ||
| 36 | local rad | ||
| 37 | do | ||
| 38 | local _accum_0 = { } | ||
| 39 | local _len_0 = 1 | ||
| 40 | for a in ipairs({ | ||
| 41 | 1, | ||
| 42 | 2, | ||
| 43 | 3, | ||
| 44 | 4, | ||
| 45 | 5, | ||
| 46 | 6 | ||
| 47 | }) do | ||
| 48 | if good_number(a) then | ||
| 49 | _accum_0[_len_0] = { | ||
| 50 | a | ||
| 51 | } | ||
| 52 | _len_0 = _len_0 + 1 | ||
| 53 | end | ||
| 54 | end | ||
| 55 | rad = _accum_0 | ||
| 56 | end | ||
| 57 | do | ||
| 58 | local _accum_0 = { } | ||
| 59 | local _len_0 = 1 | ||
| 60 | for z in items do | ||
| 61 | for j in list do | ||
| 62 | if z > 4 then | ||
| 63 | _accum_0[_len_0] = z | ||
| 64 | _len_0 = _len_0 + 1 | ||
| 65 | end | ||
| 66 | end | ||
| 67 | end | ||
| 68 | _ = _accum_0 | ||
| 69 | end | ||
| 70 | require("util") | ||
| 71 | local dump | ||
| 72 | dump = function(x) | ||
| 73 | return print(util.dump(x)) | ||
| 74 | end | ||
| 75 | local range | ||
| 76 | range = function(count) | ||
| 77 | local i = 0 | ||
| 78 | return coroutine.wrap(function() | ||
| 79 | while i < count do | ||
| 80 | coroutine.yield(i) | ||
| 81 | i = i + 1 | ||
| 82 | end | ||
| 83 | end) | ||
| 84 | end | ||
| 85 | dump((function() | ||
| 86 | local _accum_0 = { } | ||
| 87 | local _len_0 = 1 | ||
| 88 | for x in range(10) do | ||
| 89 | _accum_0[_len_0] = x | ||
| 90 | _len_0 = _len_0 + 1 | ||
| 91 | end | ||
| 92 | return _accum_0 | ||
| 93 | end)()) | ||
| 94 | dump((function() | ||
| 95 | local _accum_0 = { } | ||
| 96 | local _len_0 = 1 | ||
| 97 | for x in range(5) do | ||
| 98 | if x > 2 then | ||
| 99 | for y in range(5) do | ||
| 100 | _accum_0[_len_0] = { | ||
| 101 | x, | ||
| 102 | y | ||
| 103 | } | ||
| 104 | _len_0 = _len_0 + 1 | ||
| 105 | end | ||
| 106 | end | ||
| 107 | end | ||
| 108 | return _accum_0 | ||
| 109 | end)()) | ||
| 110 | local things | ||
| 111 | do | ||
| 112 | local _accum_0 = { } | ||
| 113 | local _len_0 = 1 | ||
| 114 | for x in range(10) do | ||
| 115 | if x > 5 then | ||
| 116 | for y in range(10) do | ||
| 117 | if y > 7 then | ||
| 118 | _accum_0[_len_0] = x + y | ||
| 119 | _len_0 = _len_0 + 1 | ||
| 120 | end | ||
| 121 | end | ||
| 122 | end | ||
| 123 | end | ||
| 124 | things = _accum_0 | ||
| 125 | end | ||
| 126 | for x in ipairs({ | ||
| 127 | 1, | ||
| 128 | 2, | ||
| 129 | 4 | ||
| 130 | }) do | ||
| 131 | for y in ipairs({ | ||
| 132 | 1, | ||
| 133 | 2, | ||
| 134 | 3 | ||
| 135 | }) do | ||
| 136 | if x ~= 2 then | ||
| 137 | print(x, y) | ||
| 138 | end | ||
| 139 | end | ||
| 140 | end | ||
| 141 | for x in items do | ||
| 142 | print("hello", x) | ||
| 143 | end | ||
| 144 | do | ||
| 145 | local _accum_0 = { } | ||
| 146 | local _len_0 = 1 | ||
| 147 | for x in x do | ||
| 148 | _accum_0[_len_0] = x | ||
| 149 | _len_0 = _len_0 + 1 | ||
| 150 | end | ||
| 151 | _ = _accum_0 | ||
| 152 | end | ||
| 153 | local x | ||
| 154 | do | ||
| 155 | local _accum_0 = { } | ||
| 156 | local _len_0 = 1 | ||
| 157 | for x in x do | ||
| 158 | _accum_0[_len_0] = x | ||
| 159 | _len_0 = _len_0 + 1 | ||
| 160 | end | ||
| 161 | x = _accum_0 | ||
| 162 | end | ||
| 163 | for x in ipairs({ | ||
| 164 | 1, | ||
| 165 | 2, | ||
| 166 | 4 | ||
| 167 | }) do | ||
| 168 | for y in ipairs({ | ||
| 169 | 1, | ||
| 170 | 2, | ||
| 171 | 3 | ||
| 172 | }) do | ||
| 173 | if x ~= 2 then | ||
| 174 | print(x, y) | ||
| 175 | end | ||
| 176 | end | ||
| 177 | end | ||
| 178 | local double | ||
| 179 | do | ||
| 180 | local _accum_0 = { } | ||
| 181 | local _len_0 = 1 | ||
| 182 | for _index_0 = 1, #items do | ||
| 183 | local x = items[_index_0] | ||
| 184 | _accum_0[_len_0] = x * 2 | ||
| 185 | _len_0 = _len_0 + 1 | ||
| 186 | end | ||
| 187 | double = _accum_0 | ||
| 188 | end | ||
| 189 | for _index_0 = 1, #double do | ||
| 190 | local x = double[_index_0] | ||
| 191 | print(x) | ||
| 192 | end | ||
| 193 | local cut | ||
| 194 | do | ||
| 195 | local _accum_0 = { } | ||
| 196 | local _len_0 = 1 | ||
| 197 | for _index_0 = 1, #items do | ||
| 198 | local x = items[_index_0] | ||
| 199 | if x > 3 then | ||
| 200 | _accum_0[_len_0] = x | ||
| 201 | _len_0 = _len_0 + 1 | ||
| 202 | end | ||
| 203 | end | ||
| 204 | cut = _accum_0 | ||
| 205 | end | ||
| 206 | local hello | ||
| 207 | do | ||
| 208 | local _accum_0 = { } | ||
| 209 | local _len_0 = 1 | ||
| 210 | for _index_0 = 1, #items do | ||
| 211 | local x = items[_index_0] | ||
| 212 | for _index_1 = 1, #items do | ||
| 213 | local y = items[_index_1] | ||
| 214 | _accum_0[_len_0] = x + y | ||
| 215 | _len_0 = _len_0 + 1 | ||
| 216 | end | ||
| 217 | end | ||
| 218 | hello = _accum_0 | ||
| 219 | end | ||
| 220 | for _index_0 = 1, #hello do | ||
| 221 | local z = hello[_index_0] | ||
| 222 | print(z) | ||
| 223 | end | ||
| 224 | x = { | ||
| 225 | 1, | ||
| 226 | 2, | ||
| 227 | 3, | ||
| 228 | 4, | ||
| 229 | 5, | ||
| 230 | 6, | ||
| 231 | 7 | ||
| 232 | } | ||
| 233 | local _max_0 = -5 | ||
| 234 | for _index_0 = 2, _max_0 < 0 and #x + _max_0 or _max_0, 2 do | ||
| 235 | local y = x[_index_0] | ||
| 236 | print(y) | ||
| 237 | end | ||
| 238 | local _max_1 = 3 | ||
| 239 | for _index_0 = 1, _max_1 < 0 and #x + _max_1 or _max_1 do | ||
| 240 | local y = x[_index_0] | ||
| 241 | print(y) | ||
| 242 | end | ||
| 243 | for _index_0 = 2, #x do | ||
| 244 | local y = x[_index_0] | ||
| 245 | print(y) | ||
| 246 | end | ||
| 247 | for _index_0 = 1, #x, 2 do | ||
| 248 | local y = x[_index_0] | ||
| 249 | print(y) | ||
| 250 | end | ||
| 251 | for _index_0 = 2, #x, 2 do | ||
| 252 | local y = x[_index_0] | ||
| 253 | print(y) | ||
| 254 | end | ||
| 255 | local a, b, c = 1, 5, 2 | ||
| 256 | local _max_2 = b | ||
| 257 | for _index_0 = a, _max_2 < 0 and #x + _max_2 or _max_2, c do | ||
| 258 | local y = x[_index_0] | ||
| 259 | print(y) | ||
| 260 | end | ||
| 261 | local normal | ||
| 262 | normal = function(hello) | ||
| 263 | local _accum_0 = { } | ||
| 264 | local _len_0 = 1 | ||
| 265 | for x in yeah do | ||
| 266 | _accum_0[_len_0] = x | ||
| 267 | _len_0 = _len_0 + 1 | ||
| 268 | end | ||
| 269 | return _accum_0 | ||
| 270 | end | ||
| 271 | local test = x(1, 2, 3, 4, 5) | ||
| 272 | for _index_0 = 1, #test do | ||
| 273 | local thing = test[_index_0] | ||
| 274 | print(thing) | ||
| 275 | end | ||
| 276 | return function() | ||
| 277 | local _list_0 = rows | ||
| 278 | for _index_0 = 1, #_list_0 do | ||
| 279 | local row = _list_0[_index_0] | ||
| 280 | a = b | ||
| 281 | end | ||
| 282 | end | ||
diff --git a/spec/outputs/literals.lua b/spec/outputs/literals.lua new file mode 100644 index 0000000..1ffadc8 --- /dev/null +++ b/spec/outputs/literals.lua | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | local _ = { | ||
| 2 | 121, | ||
| 3 | 121.2323, | ||
| 4 | 121.2323e-1, | ||
| 5 | 121.2323e13434, | ||
| 6 | 2323E34, | ||
| 7 | 0x12323, | ||
| 8 | 0xfF2323, | ||
| 9 | 0xabcdef, | ||
| 10 | 0xABCDEF, | ||
| 11 | .2323, | ||
| 12 | .2323e-1, | ||
| 13 | .2323e13434, | ||
| 14 | 1LL, | ||
| 15 | 1ULL, | ||
| 16 | 9332LL, | ||
| 17 | 9332, | ||
| 18 | 0x2aLL, | ||
| 19 | 0x2aULL, | ||
| 20 | [[ hello world ]], | ||
| 21 | [=[ hello world ]=], | ||
| 22 | [====[ hello world ]====], | ||
| 23 | "another world", | ||
| 24 | 'what world', | ||
| 25 | "\n hello world\n ", | ||
| 26 | 'yeah\n what is going on\n here is something cool' | ||
| 27 | } | ||
| 28 | return nil | ||
diff --git a/spec/outputs/local.lua b/spec/outputs/local.lua new file mode 100644 index 0000000..288764a --- /dev/null +++ b/spec/outputs/local.lua | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | do | ||
| 2 | local a | ||
| 3 | local a, b, c | ||
| 4 | local g | ||
| 5 | b, g = 23232 | ||
| 6 | end | ||
| 7 | do | ||
| 8 | local x = 1212 | ||
| 9 | local something | ||
| 10 | something = function() | ||
| 11 | local x | ||
| 12 | x = 1212 | ||
| 13 | end | ||
| 14 | end | ||
| 15 | do | ||
| 16 | local y, z | ||
| 17 | y = 2323 | ||
| 18 | z = 2323 | ||
| 19 | end | ||
| 20 | do | ||
| 21 | print("Nothing Here!") | ||
| 22 | end | ||
| 23 | do | ||
| 24 | local X, Y | ||
| 25 | local x = 3434 | ||
| 26 | local y = 3434 | ||
| 27 | X = 3434 | ||
| 28 | Y = "yeah" | ||
| 29 | end | ||
| 30 | do | ||
| 31 | local x, y = "a", "b" | ||
| 32 | end | ||
| 33 | do | ||
| 34 | local x, y | ||
| 35 | x, y = "a", "b" | ||
| 36 | end | ||
| 37 | do | ||
| 38 | if something then | ||
| 39 | local x = 2323 | ||
| 40 | end | ||
| 41 | end | ||
| 42 | do | ||
| 43 | local x | ||
| 44 | do | ||
| 45 | x = "one" | ||
| 46 | end | ||
| 47 | x = 100 | ||
| 48 | do | ||
| 49 | x = "two" | ||
| 50 | end | ||
| 51 | end | ||
| 52 | do | ||
| 53 | local k, x, a, b, c | ||
| 54 | if what then | ||
| 55 | k = 10 | ||
| 56 | end | ||
| 57 | x = 100 | ||
| 58 | do | ||
| 59 | local _obj_0 = y | ||
| 60 | a, b, c = _obj_0.a, _obj_0.b, _obj_0.c | ||
| 61 | end | ||
| 62 | end | ||
| 63 | do | ||
| 64 | local a, b, c, d | ||
| 65 | a = 100 | ||
| 66 | print("hi") | ||
| 67 | b = 200 | ||
| 68 | c = 100 | ||
| 69 | print("hi") | ||
| 70 | d = 200 | ||
| 71 | d = 2323 | ||
| 72 | end | ||
| 73 | do | ||
| 74 | local Uppercase, One, Two | ||
| 75 | local lowercase = 5 | ||
| 76 | Uppercase = 3 | ||
| 77 | do | ||
| 78 | local _class_0 | ||
| 79 | local Five | ||
| 80 | local _base_0 = { } | ||
| 81 | _base_0.__index = _base_0 | ||
| 82 | _class_0 = setmetatable({ | ||
| 83 | __init = function() end, | ||
| 84 | __base = _base_0, | ||
| 85 | __name = "One" | ||
| 86 | }, { | ||
| 87 | __index = _base_0, | ||
| 88 | __call = function(cls, ...) | ||
| 89 | local _self_0 = setmetatable({ }, _base_0) | ||
| 90 | cls.__init(_self_0, ...) | ||
| 91 | return _self_0 | ||
| 92 | end | ||
| 93 | }) | ||
| 94 | _base_0.__class = _class_0 | ||
| 95 | local self = _class_0; | ||
| 96 | Five = 6 | ||
| 97 | One = _class_0 | ||
| 98 | end | ||
| 99 | do | ||
| 100 | local _class_0 | ||
| 101 | local No | ||
| 102 | local _base_0 = { } | ||
| 103 | _base_0.__index = _base_0 | ||
| 104 | _class_0 = setmetatable({ | ||
| 105 | __init = function() end, | ||
| 106 | __base = _base_0, | ||
| 107 | __name = "Two" | ||
| 108 | }, { | ||
| 109 | __index = _base_0, | ||
| 110 | __call = function(cls, ...) | ||
| 111 | local _self_0 = setmetatable({ }, _base_0) | ||
| 112 | cls.__init(_self_0, ...) | ||
| 113 | return _self_0 | ||
| 114 | end | ||
| 115 | }) | ||
| 116 | _base_0.__class = _class_0 | ||
| 117 | local self = _class_0; | ||
| 118 | do | ||
| 119 | local _class_1 | ||
| 120 | local _base_1 = { } | ||
| 121 | _base_1.__index = _base_1 | ||
| 122 | _class_1 = setmetatable({ | ||
| 123 | __init = function() end, | ||
| 124 | __base = _base_1, | ||
| 125 | __name = "No" | ||
| 126 | }, { | ||
| 127 | __index = _base_1, | ||
| 128 | __call = function(cls, ...) | ||
| 129 | local _self_0 = setmetatable({ }, _base_1) | ||
| 130 | cls.__init(_self_0, ...) | ||
| 131 | return _self_0 | ||
| 132 | end | ||
| 133 | }) | ||
| 134 | _base_1.__class = _class_1 | ||
| 135 | No = _class_1 | ||
| 136 | end | ||
| 137 | Two = _class_0 | ||
| 138 | end | ||
| 139 | end | ||
| 140 | do | ||
| 141 | local _list_0 = { } | ||
| 142 | for _index_0 = 1, #_list_0 do | ||
| 143 | local a = _list_0[_index_0] | ||
| 144 | local _ = a | ||
| 145 | end | ||
| 146 | end | ||
| 147 | do | ||
| 148 | local x | ||
| 149 | x = a or b | ||
| 150 | end | ||
| 151 | local g = 2323 | ||
diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua new file mode 100644 index 0000000..a905e4e --- /dev/null +++ b/spec/outputs/loops.lua | |||
| @@ -0,0 +1,352 @@ | |||
| 1 | for x = 1, 10 do | ||
| 2 | print("yeah") | ||
| 3 | end | ||
| 4 | for x = 1, #something do | ||
| 5 | print("yeah") | ||
| 6 | end | ||
| 7 | for y = 100, 60, -3 do | ||
| 8 | print("count down", y) | ||
| 9 | end | ||
| 10 | for a = 1, 10 do | ||
| 11 | print("okay") | ||
| 12 | end | ||
| 13 | for a = 1, 10 do | ||
| 14 | for b = 2, 43 do | ||
| 15 | print(a, b) | ||
| 16 | end | ||
| 17 | end | ||
| 18 | for i in iter do | ||
| 19 | for j in yeah do | ||
| 20 | local x = 343 + i + j | ||
| 21 | print(i, j) | ||
| 22 | end | ||
| 23 | end | ||
| 24 | local _list_0 = something | ||
| 25 | for _index_0 = 1, #_list_0 do | ||
| 26 | local x = _list_0[_index_0] | ||
| 27 | print(x) | ||
| 28 | end | ||
| 29 | for k, v in pairs(hello) do | ||
| 30 | print(k, v) | ||
| 31 | end | ||
| 32 | for x in y, z do | ||
| 33 | print(x) | ||
| 34 | end | ||
| 35 | for x in y, z, k do | ||
| 36 | print(x) | ||
| 37 | end | ||
| 38 | local _list_1 = modules | ||
| 39 | for _index_0 = 1, #_list_1 do | ||
| 40 | local name, members = _list_1[_index_0] | ||
| 41 | print(name, member) | ||
| 42 | end | ||
| 43 | local x | ||
| 44 | x = function() | ||
| 45 | for x in y do | ||
| 46 | local _ = y | ||
| 47 | end | ||
| 48 | end | ||
| 49 | local hello = { | ||
| 50 | 1, | ||
| 51 | 2, | ||
| 52 | 3, | ||
| 53 | 4, | ||
| 54 | 5 | ||
| 55 | } | ||
| 56 | do | ||
| 57 | local _accum_0 = { } | ||
| 58 | local _len_0 = 1 | ||
| 59 | for _index_0 = 1, #hello do | ||
| 60 | local y = hello[_index_0] | ||
| 61 | if y % 2 == 0 then | ||
| 62 | _accum_0[_len_0] = y | ||
| 63 | end | ||
| 64 | _len_0 = _len_0 + 1 | ||
| 65 | end | ||
| 66 | x = _accum_0 | ||
| 67 | end | ||
| 68 | x = function() | ||
| 69 | for _index_0 = 1, #hello do | ||
| 70 | local x = hello[_index_0] | ||
| 71 | local _ = y | ||
| 72 | end | ||
| 73 | end | ||
| 74 | local t | ||
| 75 | do | ||
| 76 | local _accum_0 = { } | ||
| 77 | local _len_0 = 1 | ||
| 78 | for i = 10, 20 do | ||
| 79 | _accum_0[_len_0] = i * 2 | ||
| 80 | _len_0 = _len_0 + 1 | ||
| 81 | end | ||
| 82 | t = _accum_0 | ||
| 83 | end | ||
| 84 | local hmm = 0 | ||
| 85 | local y | ||
| 86 | do | ||
| 87 | local _accum_0 = { } | ||
| 88 | local _len_0 = 1 | ||
| 89 | for j = 3, 30, 8 do | ||
| 90 | hmm = hmm + 1 | ||
| 91 | _accum_0[_len_0] = j * hmm | ||
| 92 | _len_0 = _len_0 + 1 | ||
| 93 | end | ||
| 94 | y = _accum_0 | ||
| 95 | end | ||
| 96 | local _ | ||
| 97 | _ = function() | ||
| 98 | for k = 10, 40 do | ||
| 99 | _ = "okay" | ||
| 100 | end | ||
| 101 | end | ||
| 102 | _ = function() | ||
| 103 | local _accum_0 = { } | ||
| 104 | local _len_0 = 1 | ||
| 105 | for k = 10, 40 do | ||
| 106 | _accum_0[_len_0] = "okay" | ||
| 107 | _len_0 = _len_0 + 1 | ||
| 108 | end | ||
| 109 | return _accum_0 | ||
| 110 | end | ||
| 111 | while true do | ||
| 112 | print("name") | ||
| 113 | end | ||
| 114 | while 5 + 5 do | ||
| 115 | print("okay world") | ||
| 116 | working(man) | ||
| 117 | end | ||
| 118 | while also do | ||
| 119 | i(work(too)) | ||
| 120 | _ = "okay" | ||
| 121 | end | ||
| 122 | local i = 0 | ||
| 123 | do | ||
| 124 | local _accum_0 = { } | ||
| 125 | local _len_0 = 1 | ||
| 126 | while i < 10 do | ||
| 127 | i = i + 1 | ||
| 128 | _len_0 = _len_0 + 1 | ||
| 129 | end | ||
| 130 | x = _accum_0 | ||
| 131 | end | ||
| 132 | do | ||
| 133 | local _accum_0 = { } | ||
| 134 | local _len_0 = 1 | ||
| 135 | local _list_2 = 3 | ||
| 136 | for _index_0 = 1, #_list_2 do | ||
| 137 | local thing = _list_2[_index_0] | ||
| 138 | y = "hello" | ||
| 139 | _len_0 = _len_0 + 1 | ||
| 140 | end | ||
| 141 | x = _accum_0 | ||
| 142 | end | ||
| 143 | do | ||
| 144 | local _accum_0 = { } | ||
| 145 | local _len_0 = 1 | ||
| 146 | for x = 1, 2 do | ||
| 147 | y = "hello" | ||
| 148 | _len_0 = _len_0 + 1 | ||
| 149 | end | ||
| 150 | x = _accum_0 | ||
| 151 | end | ||
| 152 | while true do | ||
| 153 | local _continue_0 = false | ||
| 154 | repeat | ||
| 155 | if false then | ||
| 156 | _continue_0 = true | ||
| 157 | break | ||
| 158 | end | ||
| 159 | print("yes") | ||
| 160 | if true then | ||
| 161 | break | ||
| 162 | end | ||
| 163 | print("no") | ||
| 164 | _continue_0 = true | ||
| 165 | until true | ||
| 166 | if not _continue_0 then | ||
| 167 | break | ||
| 168 | end | ||
| 169 | end | ||
| 170 | for i = 1, 10 do | ||
| 171 | while true do | ||
| 172 | local _continue_0 = false | ||
| 173 | repeat | ||
| 174 | if not true then | ||
| 175 | _continue_0 = true | ||
| 176 | break | ||
| 177 | end | ||
| 178 | break | ||
| 179 | _continue_0 = true | ||
| 180 | until true | ||
| 181 | if not _continue_0 then | ||
| 182 | break | ||
| 183 | end | ||
| 184 | end | ||
| 185 | end | ||
| 186 | local a = 1 | ||
| 187 | repeat | ||
| 188 | local _continue_0 = false | ||
| 189 | repeat | ||
| 190 | a = a + 1 | ||
| 191 | if a == 5 then | ||
| 192 | _continue_0 = true | ||
| 193 | break | ||
| 194 | end | ||
| 195 | if a == 6 then | ||
| 196 | break | ||
| 197 | end | ||
| 198 | print(a) | ||
| 199 | _continue_0 = true | ||
| 200 | until true | ||
| 201 | if not _continue_0 then | ||
| 202 | break | ||
| 203 | end | ||
| 204 | until a == 10 | ||
| 205 | a = 3 | ||
| 206 | while not (a == 0) do | ||
| 207 | a = a - 1 | ||
| 208 | end | ||
| 209 | local done = false | ||
| 210 | while not done do | ||
| 211 | done = true | ||
| 212 | end | ||
| 213 | repeat | ||
| 214 | print("hello") | ||
| 215 | until true | ||
| 216 | while not done do | ||
| 217 | x = 10 | ||
| 218 | repeat | ||
| 219 | x = x - 1 | ||
| 220 | until x == 0 | ||
| 221 | end | ||
| 222 | while not cond do | ||
| 223 | print("okay") | ||
| 224 | end | ||
| 225 | for x = 1, 10 do | ||
| 226 | local _continue_0 = false | ||
| 227 | repeat | ||
| 228 | if x > 3 and x < 7 then | ||
| 229 | _continue_0 = true | ||
| 230 | break | ||
| 231 | end | ||
| 232 | print(x) | ||
| 233 | _continue_0 = true | ||
| 234 | until true | ||
| 235 | if not _continue_0 then | ||
| 236 | break | ||
| 237 | end | ||
| 238 | end | ||
| 239 | local list | ||
| 240 | do | ||
| 241 | local _accum_0 = { } | ||
| 242 | local _len_0 = 1 | ||
| 243 | for x = 1, 10 do | ||
| 244 | local _continue_0 = false | ||
| 245 | repeat | ||
| 246 | if x > 3 and x < 7 then | ||
| 247 | _continue_0 = true | ||
| 248 | break | ||
| 249 | end | ||
| 250 | _accum_0[_len_0] = x | ||
| 251 | _len_0 = _len_0 + 1 | ||
| 252 | _continue_0 = true | ||
| 253 | until true | ||
| 254 | if not _continue_0 then | ||
| 255 | break | ||
| 256 | end | ||
| 257 | end | ||
| 258 | list = _accum_0 | ||
| 259 | end | ||
| 260 | local _list_2 = { | ||
| 261 | 1, | ||
| 262 | 2, | ||
| 263 | 3, | ||
| 264 | 4, | ||
| 265 | 5, | ||
| 266 | 6 | ||
| 267 | } | ||
| 268 | for _index_0 = 1, #_list_2 do | ||
| 269 | local a = _list_2[_index_0] | ||
| 270 | local _continue_0 = false | ||
| 271 | repeat | ||
| 272 | if a == 1 then | ||
| 273 | _continue_0 = true | ||
| 274 | break | ||
| 275 | end | ||
| 276 | if a == 3 then | ||
| 277 | _continue_0 = true | ||
| 278 | break | ||
| 279 | end | ||
| 280 | print(a) | ||
| 281 | _continue_0 = true | ||
| 282 | until true | ||
| 283 | if not _continue_0 then | ||
| 284 | break | ||
| 285 | end | ||
| 286 | end | ||
| 287 | for x = 1, 10 do | ||
| 288 | local _continue_0 = false | ||
| 289 | repeat | ||
| 290 | if x % 2 == 0 then | ||
| 291 | _continue_0 = true | ||
| 292 | break | ||
| 293 | end | ||
| 294 | for y = 2, 12 do | ||
| 295 | local _continue_1 = false | ||
| 296 | repeat | ||
| 297 | if y % 3 == 0 then | ||
| 298 | _continue_1 = true | ||
| 299 | break | ||
| 300 | end | ||
| 301 | _continue_1 = true | ||
| 302 | until true | ||
| 303 | if not _continue_1 then | ||
| 304 | break | ||
| 305 | end | ||
| 306 | end | ||
| 307 | _continue_0 = true | ||
| 308 | until true | ||
| 309 | if not _continue_0 then | ||
| 310 | break | ||
| 311 | end | ||
| 312 | end | ||
| 313 | while true do | ||
| 314 | local _continue_0 = false | ||
| 315 | repeat | ||
| 316 | if false then | ||
| 317 | _continue_0 = true | ||
| 318 | break | ||
| 319 | end | ||
| 320 | break | ||
| 321 | _continue_0 = true | ||
| 322 | until true | ||
| 323 | if not _continue_0 then | ||
| 324 | break | ||
| 325 | end | ||
| 326 | end | ||
| 327 | while true do | ||
| 328 | local _continue_0 = false | ||
| 329 | repeat | ||
| 330 | if false then | ||
| 331 | _continue_0 = true | ||
| 332 | break | ||
| 333 | end | ||
| 334 | return 22 | ||
| 335 | _continue_0 = true | ||
| 336 | until true | ||
| 337 | if not _continue_0 then | ||
| 338 | break | ||
| 339 | end | ||
| 340 | end | ||
| 341 | do | ||
| 342 | local xxx = { | ||
| 343 | 1, | ||
| 344 | 2, | ||
| 345 | 3, | ||
| 346 | 4 | ||
| 347 | } | ||
| 348 | for _index_0 = 1, #xxx do | ||
| 349 | local thing = xxx[_index_0] | ||
| 350 | print(thing) | ||
| 351 | end | ||
| 352 | end | ||
diff --git a/spec/outputs/macro-export.lua b/spec/outputs/macro-export.lua new file mode 100644 index 0000000..b5a63f8 --- /dev/null +++ b/spec/outputs/macro-export.lua | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | local _module_0 = { } | ||
| 2 | return _module_0 | ||
diff --git a/spec/outputs/macro-teal.tl b/spec/outputs/macro-teal.tl new file mode 100644 index 0000000..b5a63f8 --- /dev/null +++ b/spec/outputs/macro-teal.tl | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | local _module_0 = { } | ||
| 2 | return _module_0 | ||
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua new file mode 100644 index 0000000..a2430a2 --- /dev/null +++ b/spec/outputs/macro.lua | |||
| @@ -0,0 +1,233 @@ | |||
| 1 | assert(item == nil); | ||
| 2 | local v = (item == nil) | ||
| 3 | if f1() then | ||
| 4 | print("OK") | ||
| 5 | end | ||
| 6 | if (f1() and f2() and f3()) then | ||
| 7 | print("OK") | ||
| 8 | end | ||
| 9 | if (x == "Apple" or x == "Pig" or x == "Dog") then | ||
| 10 | print("exist") | ||
| 11 | end | ||
| 12 | local _list_0 = (function() | ||
| 13 | local _accum_0 = { } | ||
| 14 | local _len_0 = 1 | ||
| 15 | local _list_0 = (function() | ||
| 16 | local _accum_1 = { } | ||
| 17 | local _len_1 = 1 | ||
| 18 | local _list_0 = { | ||
| 19 | 1, | ||
| 20 | 2, | ||
| 21 | 3 | ||
| 22 | } | ||
| 23 | for _index_0 = 1, #_list_0 do | ||
| 24 | local _ = _list_0[_index_0] | ||
| 25 | _accum_1[_len_1] = _ * 2 | ||
| 26 | _len_1 = _len_1 + 1 | ||
| 27 | end | ||
| 28 | return _accum_1 | ||
| 29 | end)() | ||
| 30 | for _index_0 = 1, #_list_0 do | ||
| 31 | local _ = _list_0[_index_0] | ||
| 32 | if _ > 4 then | ||
| 33 | _accum_0[_len_0] = _ | ||
| 34 | _len_0 = _len_0 + 1 | ||
| 35 | end | ||
| 36 | end | ||
| 37 | return _accum_0 | ||
| 38 | end)() | ||
| 39 | for _index_0 = 1, #_list_0 do | ||
| 40 | local _ = _list_0[_index_0] | ||
| 41 | print(_) | ||
| 42 | end | ||
| 43 | local _list_1 = (function() | ||
| 44 | local _accum_0 = { } | ||
| 45 | local _len_0 = 1 | ||
| 46 | local _list_1 = (function() | ||
| 47 | local _accum_1 = { } | ||
| 48 | local _len_1 = 1 | ||
| 49 | local _list_1 = { | ||
| 50 | 1, | ||
| 51 | 2, | ||
| 52 | 3 | ||
| 53 | } | ||
| 54 | for _index_0 = 1, #_list_1 do | ||
| 55 | local _ = _list_1[_index_0] | ||
| 56 | _accum_1[_len_1] = _ * 2 | ||
| 57 | _len_1 = _len_1 + 1 | ||
| 58 | end | ||
| 59 | return _accum_1 | ||
| 60 | end)() | ||
| 61 | for _index_0 = 1, #_list_1 do | ||
| 62 | local _ = _list_1[_index_0] | ||
| 63 | if _ > 4 then | ||
| 64 | _accum_0[_len_0] = _ | ||
| 65 | _len_0 = _len_0 + 1 | ||
| 66 | end | ||
| 67 | end | ||
| 68 | return _accum_0 | ||
| 69 | end)() | ||
| 70 | for _index_0 = 1, #_list_1 do | ||
| 71 | local _ = _list_1[_index_0] | ||
| 72 | print(_) | ||
| 73 | end | ||
| 74 | local val | ||
| 75 | do | ||
| 76 | local _2 | ||
| 77 | do | ||
| 78 | local _accum_0 = { } | ||
| 79 | local _len_0 = 1 | ||
| 80 | local _list_2 = { | ||
| 81 | 1, | ||
| 82 | 2, | ||
| 83 | 3 | ||
| 84 | } | ||
| 85 | for _index_0 = 1, #_list_2 do | ||
| 86 | local _ = _list_2[_index_0] | ||
| 87 | _accum_0[_len_0] = _ * 2 | ||
| 88 | _len_0 = _len_0 + 1 | ||
| 89 | end | ||
| 90 | _2 = _accum_0 | ||
| 91 | end | ||
| 92 | local _3 | ||
| 93 | do | ||
| 94 | local _accum_0 = { } | ||
| 95 | local _len_0 = 1 | ||
| 96 | for _index_0 = 1, #_2 do | ||
| 97 | local _ = _2[_index_0] | ||
| 98 | if _ > 4 then | ||
| 99 | _accum_0[_len_0] = _ | ||
| 100 | _len_0 = _len_0 + 1 | ||
| 101 | end | ||
| 102 | end | ||
| 103 | _3 = _accum_0 | ||
| 104 | end | ||
| 105 | local _4 | ||
| 106 | if #_3 == 0 then | ||
| 107 | _4 = 0 | ||
| 108 | else | ||
| 109 | local _1 = 0 | ||
| 110 | for _index_0 = 1, #_3 do | ||
| 111 | local _2 = _3[_index_0] | ||
| 112 | _1 = _1 + _2 | ||
| 113 | end | ||
| 114 | _4 = _1 | ||
| 115 | end | ||
| 116 | val = _4 | ||
| 117 | end | ||
| 118 | (1 + 2):call(123) | ||
| 119 | local res = (1 + 2) | ||
| 120 | local f | ||
| 121 | f = function(x) | ||
| 122 | return function(y) | ||
| 123 | return function(z) | ||
| 124 | return print(x, y, z) | ||
| 125 | end | ||
| 126 | end | ||
| 127 | end | ||
| 128 | do | ||
| 129 | local a = 8 | ||
| 130 | do | ||
| 131 | a = 1 | ||
| 132 | a = a + 1 | ||
| 133 | end | ||
| 134 | a = a + (function() | ||
| 135 | a = 1 | ||
| 136 | return a + 1 | ||
| 137 | end)() | ||
| 138 | print(a) | ||
| 139 | end | ||
| 140 | do | ||
| 141 | local a = 8 | ||
| 142 | a = (function() | ||
| 143 | local a | ||
| 144 | a = 1 | ||
| 145 | return a + 1 | ||
| 146 | end)() | ||
| 147 | a = a + (function() | ||
| 148 | local a | ||
| 149 | a = 1 | ||
| 150 | return a + 1 | ||
| 151 | end)() | ||
| 152 | print(a) | ||
| 153 | end | ||
| 154 | local x = 0; | ||
| 155 | local function f(a) | ||
| 156 | return a + 1 | ||
| 157 | end | ||
| 158 | x = x + f(3); | ||
| 159 | function tb:func() | ||
| 160 | print(123) | ||
| 161 | end | ||
| 162 | print(x) | ||
| 163 | local sel | ||
| 164 | sel = function(a, b, c) | ||
| 165 | if a then | ||
| 166 | return b | ||
| 167 | else | ||
| 168 | return c | ||
| 169 | end | ||
| 170 | end | ||
| 171 | local function sel(a, b, c) | ||
| 172 | if a then | ||
| 173 | return b | ||
| 174 | else | ||
| 175 | return c | ||
| 176 | end | ||
| 177 | end | ||
| 178 | local function dummy() | ||
| 179 | |||
| 180 | end | ||
| 181 | -- a comment here | ||
| 182 | local _ = require('underscore') | ||
| 183 | local a = ((((_({ | ||
| 184 | 1, | ||
| 185 | 2, | ||
| 186 | 3, | ||
| 187 | 4, | ||
| 188 | -2, | ||
| 189 | 3 | ||
| 190 | })):chain()):map(function(self) | ||
| 191 | return self * 2 | ||
| 192 | end)):filter(function(self) | ||
| 193 | return self > 3 | ||
| 194 | end)):value(); | ||
| 195 | ((((_({ | ||
| 196 | 1, | ||
| 197 | 2, | ||
| 198 | 3, | ||
| 199 | 4, | ||
| 200 | -2, | ||
| 201 | 3 | ||
| 202 | })):chain()):map(function(self) | ||
| 203 | return self * 2 | ||
| 204 | end)):filter(function(self) | ||
| 205 | return self > 3 | ||
| 206 | end)):each(function(self) | ||
| 207 | return print(self) | ||
| 208 | end) | ||
| 209 | local result = ((((((origin.transform.root.gameObject:Parents()):Descendants()):SelectEnable()):SelectVisible()):TagEqual("fx")):Where(function(x) | ||
| 210 | return x.name:EndsWith("(Clone)") | ||
| 211 | end)):Destroy() | ||
| 212 | do | ||
| 213 | local _1 | ||
| 214 | _1 = origin.transform.root.gameObject:Parents() | ||
| 215 | local _2 | ||
| 216 | _2 = _1:Descendants() | ||
| 217 | local _3 | ||
| 218 | _3 = _2:SelectEnable() | ||
| 219 | local _4 | ||
| 220 | _4 = _3:SelectVisible() | ||
| 221 | local _5 | ||
| 222 | _5 = _4:TagEqual("fx") | ||
| 223 | local _6 | ||
| 224 | _6 = _5:Where(function(x) | ||
| 225 | return x.name:EndsWith("(Clone)") | ||
| 226 | end) | ||
| 227 | _6:Destroy() | ||
| 228 | end | ||
| 229 | origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) | ||
| 230 | return x.name:EndsWith("(Clone)") | ||
| 231 | end):Destroy() | ||
| 232 | print('abc') | ||
| 233 | return 123 | ||
diff --git a/spec/outputs/metatable.lua b/spec/outputs/metatable.lua new file mode 100644 index 0000000..16ae86c --- /dev/null +++ b/spec/outputs/metatable.lua | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | local a = setmetatable({ | ||
| 2 | close = true, | ||
| 3 | }, { | ||
| 4 | __close = function(self) | ||
| 5 | return print("out of scope") | ||
| 6 | end | ||
| 7 | }) | ||
| 8 | local b = setmetatable({ }, { | ||
| 9 | __add = function(left, right) | ||
| 10 | return right - left | ||
| 11 | end | ||
| 12 | }) | ||
| 13 | local c = setmetatable({ | ||
| 14 | key1 = true, | ||
| 15 | key2 = true | ||
| 16 | }, { | ||
| 17 | __add = add | ||
| 18 | }) | ||
| 19 | local w = setmetatable({ }, { | ||
| 20 | [name] = 123, | ||
| 21 | ["new"] = function(self, val) | ||
| 22 | return { | ||
| 23 | val | ||
| 24 | } | ||
| 25 | end | ||
| 26 | }) | ||
| 27 | getmetatable(w)["new"](getmetatable(w)[name]) | ||
| 28 | local _ <close> = setmetatable({ }, { | ||
| 29 | __close = function() | ||
| 30 | return print("out of scope") | ||
| 31 | end | ||
| 32 | }) | ||
| 33 | local d, e = a.close, getmetatable(a).__close | ||
| 34 | local f = getmetatable(a):__close(1) | ||
| 35 | getmetatable(a).__add = function(x, y) | ||
| 36 | return x + y | ||
| 37 | end | ||
| 38 | do | ||
| 39 | local _obj_0 = a | ||
| 40 | local new = _obj_0.new | ||
| 41 | local close, closeA | ||
| 42 | do | ||
| 43 | local _obj_1 = getmetatable(_obj_0) | ||
| 44 | close, closeA = _obj_1.__close, _obj_1.__close | ||
| 45 | end | ||
| 46 | print(new, close, closeA) | ||
| 47 | end | ||
| 48 | do | ||
| 49 | local x, new, var, close, closeA, num, add, sub | ||
| 50 | local _obj_0, _obj_1 | ||
| 51 | x, _obj_0, _obj_1 = 123, a.b.c, func() | ||
| 52 | new, var = _obj_0.new, _obj_0.var | ||
| 53 | do | ||
| 54 | local _obj_2 = getmetatable(_obj_0) | ||
| 55 | close, closeA = _obj_2.__close, _obj_2.__close | ||
| 56 | end | ||
| 57 | num = _obj_1.num | ||
| 58 | do | ||
| 59 | local _obj_2 = getmetatable(_obj_1) | ||
| 60 | add, sub = _obj_2.__add, _obj_2.__sub | ||
| 61 | end | ||
| 62 | end | ||
| 63 | setmetatable(a.b, { }) | ||
| 64 | x.abc = 123 | ||
| 65 | setmetatable(func(), mt) | ||
| 66 | _ = extra | ||
| 67 | setmetatable(b.c, mt) | ||
| 68 | a, d, e = 1, "abc" | ||
| 69 | local is_same = getmetatable(a).__index == getmetatable(a).__index | ||
| 70 | setmetatable(a, { | ||
| 71 | __index = tb | ||
| 72 | }) | ||
| 73 | getmetatable(a).__index = tb | ||
| 74 | getmetatable(a).__index = tb | ||
| 75 | local mt = getmetatable(a) | ||
| 76 | tb:func(#list) | ||
| 77 | getmetatable(tb):__func(list) | ||
| 78 | getmetatable(tb):__func(list) | ||
| 79 | local index, setFunc | ||
| 80 | do | ||
| 81 | local _obj_0 = getmetatable(require("module")) | ||
| 82 | index, setFunc = _obj_0.__index, _obj_0.__newindex | ||
| 83 | end | ||
| 84 | do | ||
| 85 | local _with_0 = tb | ||
| 86 | print(getmetatable(_with_0).__add, getmetatable(_with_0.x):__index("key")) | ||
| 87 | a = getmetatable(getmetatable(getmetatable(_with_0).__index).__add):__new(123) | ||
| 88 | b = t(#getmetatable(_with_0).__close.test) | ||
| 89 | c = t(#getmetatable(_with_0).__close(_with_0.test)) | ||
| 90 | end | ||
| 91 | mt = getmetatable(a) | ||
| 92 | a = setmetatable({ }, mt) | ||
| 93 | a = setmetatable({ }, { | ||
| 94 | __index = mt | ||
| 95 | }) | ||
| 96 | local index | ||
| 97 | index = getmetatable(a).__index | ||
| 98 | index = getmetatable(a).__index | ||
| 99 | do | ||
| 100 | local ctor, update | ||
| 101 | do | ||
| 102 | local _obj_0 = getmetatable(a) | ||
| 103 | ctor, update = _obj_0.new, _obj_0.update | ||
| 104 | end | ||
| 105 | end | ||
| 106 | do | ||
| 107 | local ctor, update | ||
| 108 | do | ||
| 109 | local _obj_0 = getmetatable(a) | ||
| 110 | ctor, update = _obj_0.new, _obj_0.update | ||
| 111 | end | ||
| 112 | end | ||
| 113 | return nil | ||
diff --git a/spec/outputs/multiline_chain.lua b/spec/outputs/multiline_chain.lua new file mode 100644 index 0000000..fea7bc6 --- /dev/null +++ b/spec/outputs/multiline_chain.lua | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | local x = a.b.c.d | ||
| 2 | x.y = a.b:c() | ||
| 3 | func(1, arg2.value:get(), arg3.value:get(), { | ||
| 4 | 1, | ||
| 5 | ((function() | ||
| 6 | if x ~= nil then | ||
| 7 | local _obj_0 = x.y | ||
| 8 | if _obj_0 ~= nil then | ||
| 9 | return _obj_0.z | ||
| 10 | end | ||
| 11 | return nil | ||
| 12 | end | ||
| 13 | return nil | ||
| 14 | end)() ~= nil), | ||
| 15 | 3 | ||
| 16 | }) | ||
| 17 | local tbb = { | ||
| 18 | k1 = a:b(123).c(), | ||
| 19 | k2 = { | ||
| 20 | w1 = a().b:c() | ||
| 21 | } | ||
| 22 | } | ||
| 23 | local tb | ||
| 24 | if f2 ~= nil then | ||
| 25 | tb = f2("abc", f1({ }).a) | ||
| 26 | end | ||
| 27 | local f | ||
| 28 | f = function() | ||
| 29 | local _accum_0 = { } | ||
| 30 | local _len_0 = 1 | ||
| 31 | local _list_0 = vals | ||
| 32 | for _index_0 = 1, #_list_0 do | ||
| 33 | local _des_0 = _list_0[_index_0] | ||
| 34 | local a = _des_0[1] | ||
| 35 | _accum_0[_len_0] = a.b:c(123) | ||
| 36 | _len_0 = _len_0 + 1 | ||
| 37 | end | ||
| 38 | return _accum_0 | ||
| 39 | end | ||
| 40 | local f1 | ||
| 41 | f1 = function() | ||
| 42 | return x, a:b(123).c("abc") | ||
| 43 | end | ||
| 44 | local result = origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) | ||
| 45 | if x:IsTargeted() then | ||
| 46 | return false | ||
| 47 | end | ||
| 48 | return x.name:EndsWith("(Clone)") | ||
| 49 | end):Destroy() | ||
| 50 | origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) | ||
| 51 | return x.name:EndsWith("(Clone)") | ||
| 52 | end):Destroy() | ||
| 53 | do | ||
| 54 | local _with_0 = item | ||
| 55 | _with_0.itemFieldA = 123 | ||
| 56 | _with_0:callMethod():chainCall() | ||
| 57 | _with_0:callMethod():chainCall() | ||
| 58 | _with_0:chainCall() | ||
| 59 | local _exp_0 = _with_0.itemFieldB:getValue() | ||
| 60 | if "Valid" == _exp_0 or _with_0:getItemState() == _exp_0 then | ||
| 61 | _with_0:itemMethodA():getValue() | ||
| 62 | else | ||
| 63 | _with_0:itemMethodB():getValue() | ||
| 64 | end | ||
| 65 | local a | ||
| 66 | if _with_0.itemFieldC then | ||
| 67 | a = _with_0.itemFieldD | ||
| 68 | else | ||
| 69 | a = _with_0.itemFieldE | ||
| 70 | end | ||
| 71 | local _list_0 = values | ||
| 72 | for _index_0 = 1, #_list_0 do | ||
| 73 | local v = _list_0[_index_0] | ||
| 74 | _with_0:itemMethodC(v) | ||
| 75 | end | ||
| 76 | for i = 1, counter do | ||
| 77 | _with_0:itemMethodC(i) | ||
| 78 | end | ||
| 79 | if not _with_0.b then | ||
| 80 | do | ||
| 81 | local _accum_0 = { } | ||
| 82 | local _len_0 = 1 | ||
| 83 | while _with_0.itemFieldD do | ||
| 84 | _accum_0[_len_0] = _with_0:itemNext():get() | ||
| 85 | _len_0 = _len_0 + 1 | ||
| 86 | end | ||
| 87 | _with_0.c = _accum_0 | ||
| 88 | end | ||
| 89 | end | ||
| 90 | end | ||
| 91 | return nil | ||
diff --git a/spec/outputs/operators.lua b/spec/outputs/operators.lua new file mode 100644 index 0000000..d782f5c --- /dev/null +++ b/spec/outputs/operators.lua | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | local x = 1 + 3 | ||
| 2 | local y = 1 + 3 | ||
| 3 | local z = 1 + 3 + 4 | ||
| 4 | local k = b and c and g | ||
| 5 | local h = thing and function() | ||
| 6 | return print("hello world") | ||
| 7 | end | ||
| 8 | local i = thing or function() | ||
| 9 | return print("hello world") | ||
| 10 | end | ||
| 11 | local p = thing and function() end | ||
| 12 | print("hello world") | ||
| 13 | local s = thing or function() end and 234 | ||
| 14 | local u = { | ||
| 15 | color = 1 and 2 and 3, | ||
| 16 | 4, | ||
| 17 | 4 | ||
| 18 | } | ||
| 19 | local v = { | ||
| 20 | color = 1 and function() | ||
| 21 | return "yeah" | ||
| 22 | end, | ||
| 23 | "great", | ||
| 24 | oksy = 3 ^ 2 | ||
| 25 | } | ||
| 26 | local nno = (yeah + 2) | ||
| 27 | local nn = (yeah + 2) | ||
| 28 | local n = hello(b)(function() end) | ||
| 29 | return hello(a, (yeah + 2) - okay) | ||
diff --git a/spec/outputs/pipe.lua b/spec/outputs/pipe.lua new file mode 100644 index 0000000..bf517ae --- /dev/null +++ b/spec/outputs/pipe.lua | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | foreach({ | ||
| 2 | "abc", | ||
| 3 | 123, | ||
| 4 | 998 | ||
| 5 | }, print) | ||
| 6 | print(reduce(filter(map({ | ||
| 7 | 1, | ||
| 8 | 2, | ||
| 9 | 3 | ||
| 10 | }, function(x) | ||
| 11 | return x * 2 | ||
| 12 | end), function(x) | ||
| 13 | return x > 4 | ||
| 14 | end), 0, function(a, b) | ||
| 15 | return a + b | ||
| 16 | end)) | ||
| 17 | print(table.concat((function() | ||
| 18 | local _accum_0 = { } | ||
| 19 | local _len_0 = 1 | ||
| 20 | for i = 0, 10 do | ||
| 21 | _accum_0[_len_0] = tostring(i) | ||
| 22 | _len_0 = _len_0 + 1 | ||
| 23 | end | ||
| 24 | return _accum_0 | ||
| 25 | end)(), ",")) | ||
| 26 | local b = 1 + 2 + (print(tostring(4), 1) or 123) | ||
| 27 | do | ||
| 28 | local x = math.max(233, 998) | ||
| 29 | if x then | ||
| 30 | print(x) | ||
| 31 | end | ||
| 32 | end | ||
| 33 | do | ||
| 34 | local _with_0 | ||
| 35 | if create ~= nil then | ||
| 36 | _with_0 = create(b, "new") | ||
| 37 | end | ||
| 38 | _with_0.value = 123 | ||
| 39 | print(_with_0:work()) | ||
| 40 | end | ||
| 41 | if f ~= nil then | ||
| 42 | f(123) | ||
| 43 | end | ||
| 44 | if f2 ~= nil then | ||
| 45 | f2((function() | ||
| 46 | if f1 ~= nil then | ||
| 47 | return f1("abc") | ||
| 48 | end | ||
| 49 | return nil | ||
| 50 | end)()) | ||
| 51 | end | ||
| 52 | local c | ||
| 53 | if f2 ~= nil then | ||
| 54 | c = f2((function() | ||
| 55 | if f1 ~= nil then | ||
| 56 | return f1("abc") | ||
| 57 | end | ||
| 58 | return nil | ||
| 59 | end)()) | ||
| 60 | end | ||
| 61 | local f | ||
| 62 | f = function() | ||
| 63 | local _obj_0 = x.y | ||
| 64 | if _obj_0 ~= nil then | ||
| 65 | return _obj_0["if"](_obj_0, arg) | ||
| 66 | end | ||
| 67 | return nil | ||
| 68 | end | ||
| 69 | func2(998, "abc", func1(func0(233))) | ||
| 70 | func2(func1(func0(998, "abc", 233))) | ||
| 71 | f(1, 2, 3, 4, 5) | ||
| 72 | f(1, val(2), 3, 4, 5) | ||
| 73 | f(1, 2, arr[3], 4, 5) | ||
| 74 | local a = f2(1, f1(1, 2, 3, tonumber(table.concat({ | ||
| 75 | "1", | ||
| 76 | "2", | ||
| 77 | "3" | ||
| 78 | }, ""))), 3) | ||
| 79 | print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) | ||
| 80 | print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) | ||
| 81 | print(render(emit(parse(extract(readFile("example.txt"), language, { }), language)))) | ||
| 82 | f(not func(123)) | ||
| 83 | do | ||
| 84 | local _1 = abc(123, -func(list({ | ||
| 85 | "abc", | ||
| 86 | "xyz", | ||
| 87 | "123" | ||
| 88 | }):map("#"):value()), "x") | ||
| 89 | _2, _3, _4 = 1, 2, f(3) | ||
| 90 | local _5 | ||
| 91 | _5 = f4(f3(f2(f1(v, 1), 2), 3), 4) | ||
| 92 | end | ||
| 93 | local x = b(a(123)) or d(c(456)) or (function() | ||
| 94 | local _call_0 = a["if"] | ||
| 95 | return _call_0["then"](_call_0, "abc") | ||
| 96 | end)() or (function() | ||
| 97 | if a ~= nil then | ||
| 98 | local _obj_0 = a.b | ||
| 99 | local _obj_1 = _obj_0.c | ||
| 100 | if _obj_1 ~= nil then | ||
| 101 | return _obj_1(_obj_0, 123) | ||
| 102 | end | ||
| 103 | return nil | ||
| 104 | end | ||
| 105 | return nil | ||
| 106 | end)() or (function() | ||
| 107 | local _base_0 = x | ||
| 108 | local _fn_0 = _base_0.y | ||
| 109 | return _fn_0 and function(...) | ||
| 110 | return _fn_0(_base_0, ...) | ||
| 111 | end | ||
| 112 | end)() | ||
| 113 | local x1 = 3 * f(-4) | ||
| 114 | local x2 = 3 * f(-2 ^ 2) | ||
| 115 | local y = 1 + b(3, (a ^ c)(not #2)) * f1(f(4 ^ -123)) or 123 | ||
| 116 | return nil | ||
diff --git a/spec/outputs/plus.lua b/spec/outputs/plus.lua new file mode 100644 index 0000000..749e830 --- /dev/null +++ b/spec/outputs/plus.lua | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | x["do"](x, "work") | ||
| 2 | func((function() | ||
| 3 | local _call_0 = a["do"](a) | ||
| 4 | local _call_1 = _call_0["end"](_call_0, "OK") | ||
| 5 | return _call_1["if"](_call_1, "abc", 123) | ||
| 6 | end)()) | ||
| 7 | local _call_0 = b["function"] | ||
| 8 | local _call_1 = _call_0["do"](_call_0) | ||
| 9 | local _call_2 = _call_1["while"](_call_1, "OK") | ||
| 10 | local res = _call_2["if"](_call_2, "def", 998) | ||
| 11 | local _call_3 = c["repeat"]["if"] | ||
| 12 | local _call_4 = _call_3["then"](_call_3, "xyz") | ||
| 13 | _call_4["else"](_call_4, res) | ||
| 14 | print(self["for"], self.__class["function"](self.__class, 123)) | ||
| 15 | do | ||
| 16 | local fcolor = message:match("<%w*>") | ||
| 17 | if fcolor then | ||
| 18 | local message = message:gsub("<%->", fcolor) | ||
| 19 | end | ||
| 20 | end | ||
| 21 | local message | ||
| 22 | do | ||
| 23 | local fcolor = message:match("<%w*>") | ||
| 24 | if fcolor then | ||
| 25 | message = message:gsub("<%->", fcolor) | ||
| 26 | end | ||
| 27 | end | ||
| 28 | local valA | ||
| 29 | do | ||
| 30 | local func = getfunc() | ||
| 31 | if func then | ||
| 32 | valA = func() | ||
| 33 | end | ||
| 34 | end | ||
| 35 | local valA | ||
| 36 | do | ||
| 37 | local func = getfunc() | ||
| 38 | if func then | ||
| 39 | valA = func() | ||
| 40 | end | ||
| 41 | end | ||
| 42 | local valB | ||
| 43 | do | ||
| 44 | local func = getfunc() | ||
| 45 | if func ~= nil then | ||
| 46 | valB = func() | ||
| 47 | end | ||
| 48 | end | ||
| 49 | backpack = { | ||
| 50 | something = { | ||
| 51 | yeah = 200, | ||
| 52 | they = function() | ||
| 53 | print("hello") | ||
| 54 | return yor_feet("small") | ||
| 55 | end, | ||
| 56 | pretty = hair, | ||
| 57 | gold = hmm | ||
| 58 | }, | ||
| 59 | yow = 1000, | ||
| 60 | eat = goo, | ||
| 61 | yeah = dudd | ||
| 62 | } | ||
| 63 | local start = { | ||
| 64 | something = "cold" | ||
| 65 | } | ||
| 66 | local bathe | ||
| 67 | bathe = { | ||
| 68 | on = "fire" | ||
| 69 | } | ||
diff --git a/spec/outputs/return.lua b/spec/outputs/return.lua new file mode 100644 index 0000000..0735b23 --- /dev/null +++ b/spec/outputs/return.lua | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | local _ | ||
| 2 | _ = function() | ||
| 3 | local _list_0 = things | ||
| 4 | for _index_0 = 1, #_list_0 do | ||
| 5 | local x = _list_0[_index_0] | ||
| 6 | _ = x | ||
| 7 | end | ||
| 8 | end | ||
| 9 | _ = function() | ||
| 10 | local _accum_0 = { } | ||
| 11 | local _len_0 = 1 | ||
| 12 | local _list_0 = things | ||
| 13 | for _index_0 = 1, #_list_0 do | ||
| 14 | local x = _list_0[_index_0] | ||
| 15 | _accum_0[_len_0] = x | ||
| 16 | _len_0 = _len_0 + 1 | ||
| 17 | end | ||
| 18 | return _accum_0 | ||
| 19 | end | ||
| 20 | do | ||
| 21 | local _list_0 = things | ||
| 22 | for _index_0 = 1, #_list_0 do | ||
| 23 | local x = _list_0[_index_0] | ||
| 24 | return x | ||
| 25 | end | ||
| 26 | end | ||
| 27 | do | ||
| 28 | local _accum_0 = { } | ||
| 29 | local _len_0 = 1 | ||
| 30 | local _list_0 = things | ||
| 31 | for _index_0 = 1, #_list_0 do | ||
| 32 | local x = _list_0[_index_0] | ||
| 33 | _accum_0[_len_0] = x | ||
| 34 | _len_0 = _len_0 + 1 | ||
| 35 | end | ||
| 36 | return _accum_0 | ||
| 37 | end | ||
| 38 | do | ||
| 39 | local _tbl_0 = { } | ||
| 40 | local _list_0 = things | ||
| 41 | for _index_0 = 1, #_list_0 do | ||
| 42 | local x, y = _list_0[_index_0] | ||
| 43 | _tbl_0[x] = y | ||
| 44 | end | ||
| 45 | return _tbl_0 | ||
| 46 | end | ||
| 47 | _ = function() | ||
| 48 | if a then | ||
| 49 | if a then | ||
| 50 | return a | ||
| 51 | else | ||
| 52 | return b | ||
| 53 | end | ||
| 54 | elseif b then | ||
| 55 | if a then | ||
| 56 | return a | ||
| 57 | else | ||
| 58 | return b | ||
| 59 | end | ||
| 60 | else | ||
| 61 | if a then | ||
| 62 | return a | ||
| 63 | else | ||
| 64 | return b | ||
| 65 | end | ||
| 66 | end | ||
| 67 | end | ||
| 68 | do | ||
| 69 | if a then | ||
| 70 | if a then | ||
| 71 | return a | ||
| 72 | else | ||
| 73 | return b | ||
| 74 | end | ||
| 75 | elseif b then | ||
| 76 | if a then | ||
| 77 | return a | ||
| 78 | else | ||
| 79 | return b | ||
| 80 | end | ||
| 81 | else | ||
| 82 | if a then | ||
| 83 | return a | ||
| 84 | else | ||
| 85 | return b | ||
| 86 | end | ||
| 87 | end | ||
| 88 | end | ||
| 89 | _ = function() | ||
| 90 | local _base_0 = a | ||
| 91 | local _fn_0 = _base_0.b | ||
| 92 | return _fn_0 and function(...) | ||
| 93 | return _fn_0(_base_0, ...) | ||
| 94 | end | ||
| 95 | end | ||
| 96 | do | ||
| 97 | local _base_0 = a | ||
| 98 | local _fn_0 = _base_0.b | ||
| 99 | return _fn_0 and function(...) | ||
| 100 | return _fn_0(_base_0, ...) | ||
| 101 | end | ||
| 102 | end | ||
diff --git a/spec/outputs/string.lua b/spec/outputs/string.lua new file mode 100644 index 0000000..84b6700 --- /dev/null +++ b/spec/outputs/string.lua | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | local hi = "hello" | ||
| 2 | local hello = "what the heckyes" | ||
| 3 | print(hi) | ||
| 4 | local umm = 'umm' | ||
| 5 | local here, another = "yeah", 'world' | ||
| 6 | local aye = "YU'M" | ||
| 7 | you('"hmmm" I said') | ||
| 8 | print(aye, you) | ||
| 9 | another = [[ hello world ]] | ||
| 10 | local hi_there = [[ hi there | ||
| 11 | ]] | ||
| 12 | local well = [==[ "helo" ]==] | ||
| 13 | local hola = [===[ eat noots]===] | ||
| 14 | local mm = [[well trhere]] | ||
| 15 | local txt = [[ | ||
| 16 | |||
| 17 | nil | ||
| 18 | Fail to compile | ||
| 19 | ]] | ||
| 20 | local oo = "" | ||
| 21 | local x = "\\" | ||
| 22 | x = "a\\b" | ||
| 23 | x = "\\\n" | ||
| 24 | x = "\"" | ||
| 25 | local a = "hello " .. tostring(hello) .. " hello" | ||
| 26 | local b = tostring(hello) .. " hello" | ||
| 27 | local c = "hello " .. tostring(5 + 1) | ||
| 28 | local d = tostring(hello(world)) | ||
| 29 | local e = tostring(1) .. " " .. tostring(2) .. " " .. tostring(3) | ||
| 30 | local f = [[hello #{world} world]] | ||
| 31 | a = 'hello #{hello} hello' | ||
| 32 | b = '#{hello} hello' | ||
| 33 | c = 'hello #{hello}' | ||
| 34 | local _ = "hello"; | ||
| 35 | ("hello"):format(1); | ||
| 36 | ("hello"):format(1, 2, 3); | ||
| 37 | ("hello"):format(1, 2, 3)(1, 2, 3); | ||
| 38 | ("hello"):world(); | ||
| 39 | ("hello"):format().hello(1, 2, 3); | ||
| 40 | ("hello"):format(1, 2, 3) | ||
| 41 | something("hello"):world() | ||
| 42 | return something(("hello"):world()) | ||
diff --git a/spec/outputs/stub.lua b/spec/outputs/stub.lua new file mode 100644 index 0000000..ff867ba --- /dev/null +++ b/spec/outputs/stub.lua | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | local x = { | ||
| 2 | val = 100, | ||
| 3 | hello = function(self) | ||
| 4 | return print(self.val) | ||
| 5 | end | ||
| 6 | } | ||
| 7 | local fn | ||
| 8 | do | ||
| 9 | local _base_0 = x | ||
| 10 | local _fn_0 = _base_0.val | ||
| 11 | fn = _fn_0 and function(...) | ||
| 12 | return _fn_0(_base_0, ...) | ||
| 13 | end | ||
| 14 | end | ||
| 15 | print(fn()) | ||
| 16 | print(x:val()); | ||
| 17 | (function(...) | ||
| 18 | do | ||
| 19 | local _base_0 = hello(...) | ||
| 20 | local _fn_0 = _base_0.world | ||
| 21 | x = _fn_0 and function(...) | ||
| 22 | return _fn_0(_base_0, ...) | ||
| 23 | end | ||
| 24 | end | ||
| 25 | end)() | ||
| 26 | return nil | ||
diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua new file mode 100644 index 0000000..1c8839f --- /dev/null +++ b/spec/outputs/switch.lua | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | local _exp_0 = value | ||
| 2 | if "cool" == _exp_0 then | ||
| 3 | print("hello world") | ||
| 4 | end | ||
| 5 | local _exp_1 = value | ||
| 6 | if "cool" == _exp_1 then | ||
| 7 | print("hello world") | ||
| 8 | else | ||
| 9 | print("okay rad") | ||
| 10 | end | ||
| 11 | local _exp_2 = value | ||
| 12 | if "cool" == _exp_2 then | ||
| 13 | print("hello world") | ||
| 14 | elseif "yeah" == _exp_2 then | ||
| 15 | local _ = [[FFFF]] + [[MMMM]] | ||
| 16 | elseif (2323 + 32434) == _exp_2 then | ||
| 17 | print("okay") | ||
| 18 | else | ||
| 19 | print("okay rad") | ||
| 20 | end | ||
| 21 | local out | ||
| 22 | local _exp_3 = value | ||
| 23 | if "cool" == _exp_3 then | ||
| 24 | out = print("hello world") | ||
| 25 | else | ||
| 26 | out = print("okay rad") | ||
| 27 | end | ||
| 28 | local _exp_4 = value | ||
| 29 | if "cool" == _exp_4 then | ||
| 30 | out = xxxx | ||
| 31 | elseif "umm" == _exp_4 then | ||
| 32 | out = 34340 | ||
| 33 | else | ||
| 34 | out = error("this failed big time") | ||
| 35 | end | ||
| 36 | do | ||
| 37 | local _with_0 = something | ||
| 38 | local _exp_5 = _with_0:value() | ||
| 39 | if _with_0.okay == _exp_5 then | ||
| 40 | local _ = "world" | ||
| 41 | else | ||
| 42 | local _ = "yesh" | ||
| 43 | end | ||
| 44 | end | ||
| 45 | fix(this) | ||
| 46 | call_func((function() | ||
| 47 | local _exp_5 = something | ||
| 48 | if 1 == _exp_5 then | ||
| 49 | return "yes" | ||
| 50 | else | ||
| 51 | return "no" | ||
| 52 | end | ||
| 53 | end)()) | ||
| 54 | local _exp_5 = hi | ||
| 55 | if (hello or world) == _exp_5 then | ||
| 56 | local _ = greene | ||
| 57 | end | ||
| 58 | local _exp_6 = hi | ||
| 59 | if "one" == _exp_6 or "two" == _exp_6 then | ||
| 60 | print("cool") | ||
| 61 | elseif "dad" == _exp_6 then | ||
| 62 | local _ = no | ||
| 63 | end | ||
| 64 | local _exp_7 = hi | ||
| 65 | if (3 + 1) == _exp_7 or hello() == _exp_7 or (function() | ||
| 66 | return 4 | ||
| 67 | end)() == _exp_7 then | ||
| 68 | return yello | ||
| 69 | else | ||
| 70 | return print("cool") | ||
| 71 | end | ||
diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua new file mode 100644 index 0000000..3187898 --- /dev/null +++ b/spec/outputs/syntax.lua | |||
| @@ -0,0 +1,360 @@ | |||
| 1 | local a = 1 + 2 * 3 / 6 | ||
| 2 | local bunch, go, here | ||
| 3 | a, bunch, go, here = another, world | ||
| 4 | func(arg1, arg2, another, arg3) | ||
| 5 | local we | ||
| 6 | here, we = function() end, yeah | ||
| 7 | local the, different | ||
| 8 | the, different = function() | ||
| 9 | return approach | ||
| 10 | end, yeah | ||
| 11 | dad() | ||
| 12 | dad(lord) | ||
| 13 | hello(one, two)(); | ||
| 14 | (5 + 5)(world) | ||
| 15 | fun(a)(b) | ||
| 16 | fun(a)(b) | ||
| 17 | fun(a)(b, bad(hello)) | ||
| 18 | hello(world(what(are(you(doing(here)))))) | ||
| 19 | what(the)[3243](world, yeck(heck)) | ||
| 20 | hairy[hands][are](gross)(okay(okay[world])) | ||
| 21 | local _ = (get[something] + 5)[years] | ||
| 22 | local i, x = 200, 300 | ||
| 23 | local yeah = (1 + 5) * 3 | ||
| 24 | yeah = ((1 + 5) * 3) / 2 | ||
| 25 | yeah = ((1 + 5) * 3) / 2 + i % 100 | ||
| 26 | local whoa = (1 + 2) * (3 + 4) * (4 + 5) | ||
| 27 | _ = function() | ||
| 28 | if something then | ||
| 29 | return 1, 2, 4 | ||
| 30 | end | ||
| 31 | return print("hello") | ||
| 32 | end | ||
| 33 | _ = function() | ||
| 34 | if hello then | ||
| 35 | return "heloo", "world" | ||
| 36 | else | ||
| 37 | return no, way | ||
| 38 | end | ||
| 39 | end | ||
| 40 | _ = function() | ||
| 41 | return 1, 2, 34 | ||
| 42 | end | ||
| 43 | return 5 + function() | ||
| 44 | return 4 + 2 | ||
| 45 | end | ||
| 46 | return 5 + (function() | ||
| 47 | return 4 | ||
| 48 | end) + 2 | ||
| 49 | print(5 + function() | ||
| 50 | _ = 34 | ||
| 51 | return good(nads) | ||
| 52 | end) | ||
| 53 | something('else', "ya") | ||
| 54 | something('else') | ||
| 55 | something("else") | ||
| 56 | _ = something([[hey]]) * 2 | ||
| 57 | _ = something([======[hey]======]) * 2 | ||
| 58 | _ = something[ [======[hey]======]] * 2 | ||
| 59 | _ = something('else'), 2 | ||
| 60 | _ = something("else"), 2 | ||
| 61 | _ = something([[else]]), 2 | ||
| 62 | _ = something[ [[else]]], 2 | ||
| 63 | something('else', 2) | ||
| 64 | something("else", 2) | ||
| 65 | something([[else]], 2) | ||
| 66 | _ = here(we)("go")[12123] | ||
| 67 | split("abc xyz 123"):map("#"):printAll() | ||
| 68 | _ = f("")[a] | ||
| 69 | _ = f(""):b() | ||
| 70 | _ = f("").c() | ||
| 71 | f(("")[a]) | ||
| 72 | f((""):b()) | ||
| 73 | f(("").c()) | ||
| 74 | list({ | ||
| 75 | "abc", | ||
| 76 | "xyz", | ||
| 77 | "123" | ||
| 78 | }):map("#"):printAll() | ||
| 79 | _ = f({ })[a] | ||
| 80 | _ = f({ }):b() | ||
| 81 | _ = f({ }).c() | ||
| 82 | local something = { | ||
| 83 | test = 12323, | ||
| 84 | what = function() | ||
| 85 | return print("hello world") | ||
| 86 | end | ||
| 87 | } | ||
| 88 | print(something.test) | ||
| 89 | local frick = { | ||
| 90 | hello = "world" | ||
| 91 | } | ||
| 92 | local argon = { | ||
| 93 | num = 100, | ||
| 94 | world = function(self) | ||
| 95 | print(self.num) | ||
| 96 | return { | ||
| 97 | something = function() | ||
| 98 | return print("hi from something") | ||
| 99 | end | ||
| 100 | } | ||
| 101 | end, | ||
| 102 | somethin = function(self, str) | ||
| 103 | print("string is", str) | ||
| 104 | return { | ||
| 105 | world = function(a, b) | ||
| 106 | return print("sum", a + b) | ||
| 107 | end | ||
| 108 | } | ||
| 109 | end | ||
| 110 | } | ||
| 111 | something.what() | ||
| 112 | argon:world().something() | ||
| 113 | argon:somethin("200").world(1, 2) | ||
| 114 | x = -434 | ||
| 115 | x = -hello(world(one(two))) | ||
| 116 | local hi = -"herfef" | ||
| 117 | x = -(function() | ||
| 118 | local _accum_0 = { } | ||
| 119 | local _len_0 = 1 | ||
| 120 | for x in x do | ||
| 121 | _accum_0[_len_0] = x | ||
| 122 | _len_0 = _len_0 + 1 | ||
| 123 | end | ||
| 124 | return _accum_0 | ||
| 125 | end)() | ||
| 126 | if cool then | ||
| 127 | print("hello") | ||
| 128 | end | ||
| 129 | if not cool then | ||
| 130 | print("hello") | ||
| 131 | end | ||
| 132 | if not (1212 and 3434) then | ||
| 133 | print("hello") | ||
| 134 | end | ||
| 135 | for i = 1, 10 do | ||
| 136 | print("hello") | ||
| 137 | end | ||
| 138 | print("nutjob") | ||
| 139 | if hello then | ||
| 140 | _ = 343 | ||
| 141 | end | ||
| 142 | if cool then | ||
| 143 | print("what") | ||
| 144 | end | ||
| 145 | (function(...) | ||
| 146 | local arg = { | ||
| 147 | ... | ||
| 148 | } | ||
| 149 | end)() | ||
| 150 | x = function(...) | ||
| 151 | return dump({ | ||
| 152 | ... | ||
| 153 | }) | ||
| 154 | end | ||
| 155 | x = not true | ||
| 156 | local y = not (5 + 5) | ||
| 157 | y = #"hello" | ||
| 158 | x = #{ | ||
| 159 | #{ }, | ||
| 160 | #{ | ||
| 161 | 1 | ||
| 162 | }, | ||
| 163 | #{ | ||
| 164 | 1, | ||
| 165 | 2 | ||
| 166 | } | ||
| 167 | } | ||
| 168 | _ = hello, world | ||
| 169 | something:hello(what)(a, b) | ||
| 170 | something:hello(what) | ||
| 171 | something.hello:world(a, b) | ||
| 172 | something.hello:world(1, 2, 3)(a, b) | ||
| 173 | something.hello:world(1, 2, 3)(a, b) | ||
| 174 | x = 1232 | ||
| 175 | x = x + (10 + 3) | ||
| 176 | local j = j - "hello" | ||
| 177 | y = y * 2 | ||
| 178 | y = y / 100 | ||
| 179 | local m = m % 2 | ||
| 180 | local hello = hello .. "world" | ||
| 181 | self.__class.something = self.__class.something + 10 | ||
| 182 | self.something = self.something + 10 | ||
| 183 | local _update_0 = "hello" | ||
| 184 | a[_update_0] = a[_update_0] + 10 | ||
| 185 | local _update_1 = "hello" .. tostring(tostring(ff)) | ||
| 186 | a[_update_1] = a[_update_1] + 10 | ||
| 187 | a[four].x = a[four].x + 10 | ||
| 188 | x = 0 | ||
| 189 | local _list_0 = values | ||
| 190 | for _index_0 = 1, #_list_0 do | ||
| 191 | local v = _list_0[_index_0] | ||
| 192 | _ = ((function() | ||
| 193 | if ntype(v) == "fndef" then | ||
| 194 | x = x + 1 | ||
| 195 | end | ||
| 196 | end)()) | ||
| 197 | end | ||
| 198 | hello = { | ||
| 199 | something = world, | ||
| 200 | ["if"] = "hello", | ||
| 201 | ["else"] = 3434, | ||
| 202 | ["function"] = "okay", | ||
| 203 | good = 230203 | ||
| 204 | } | ||
| 205 | local tb = { | ||
| 206 | ["do"] = b, | ||
| 207 | (function() | ||
| 208 | return { | ||
| 209 | b = b | ||
| 210 | } | ||
| 211 | end)() | ||
| 212 | } | ||
| 213 | div({ | ||
| 214 | class = "cool" | ||
| 215 | }) | ||
| 216 | _ = 5 + what(wack) | ||
| 217 | what(whack + 5) | ||
| 218 | _ = 5 - what(wack) | ||
| 219 | what(whack - 5) | ||
| 220 | x = hello - world - something; | ||
| 221 | (function(something) | ||
| 222 | if something == nil then | ||
| 223 | do | ||
| 224 | local _with_0 = what | ||
| 225 | _with_0:cool(100) | ||
| 226 | something = _with_0 | ||
| 227 | end | ||
| 228 | end | ||
| 229 | return print(something) | ||
| 230 | end)() | ||
| 231 | if something then | ||
| 232 | _ = 03589 | ||
| 233 | else | ||
| 234 | _ = 3434 | ||
| 235 | end | ||
| 236 | if something then | ||
| 237 | _ = yeah | ||
| 238 | elseif "ymmm" then | ||
| 239 | print("cool") | ||
| 240 | else | ||
| 241 | _ = okay | ||
| 242 | end | ||
| 243 | x = notsomething | ||
| 244 | y = ifsomething | ||
| 245 | local z = x and b | ||
| 246 | z = x(andb) | ||
| 247 | while 10 > something({ | ||
| 248 | something = "world" | ||
| 249 | }) do | ||
| 250 | print("yeah") | ||
| 251 | end | ||
| 252 | x = { | ||
| 253 | okay = sure | ||
| 254 | } | ||
| 255 | yeah({ | ||
| 256 | okay = man, | ||
| 257 | sure = sir | ||
| 258 | }) | ||
| 259 | hello("no comma", { | ||
| 260 | yeah = dada, | ||
| 261 | another = world | ||
| 262 | }) | ||
| 263 | hello("comma", { | ||
| 264 | something = hello_world, | ||
| 265 | frick = you | ||
| 266 | }) | ||
| 267 | another(hello, one, two, three, four, { | ||
| 268 | yeah = man, | ||
| 269 | okay = yeah, | ||
| 270 | fine = alright | ||
| 271 | }) | ||
| 272 | another(hello, one, two, three, four, { | ||
| 273 | yeah = man, | ||
| 274 | okay = yeah, | ||
| 275 | { | ||
| 276 | fine = alright, | ||
| 277 | okay = 1 | ||
| 278 | }, | ||
| 279 | { | ||
| 280 | fine = alright, | ||
| 281 | okay = 2 | ||
| 282 | } | ||
| 283 | }) | ||
| 284 | another(hello, one, two, three, four, { | ||
| 285 | yeah = man, | ||
| 286 | okay = yeah | ||
| 287 | }) | ||
| 288 | another(hello, one, two, three, four, { | ||
| 289 | yeah = man({ | ||
| 290 | okay = yeah | ||
| 291 | }) | ||
| 292 | }) | ||
| 293 | ajax(url, function(data) | ||
| 294 | return process(data) | ||
| 295 | end, function(error) | ||
| 296 | return print(error) | ||
| 297 | end) | ||
| 298 | a = a + (3 - 5) | ||
| 299 | a = a * (3 + 5) | ||
| 300 | a = a * 3 | ||
| 301 | a = a >> 3 | ||
| 302 | a = a << 3 | ||
| 303 | a = a / func("cool") | ||
| 304 | x["then"] = "hello" | ||
| 305 | x["while"]["true"] = "hello" | ||
| 306 | x["while"]["true"] = "hello" | ||
| 307 | x = x or "hello" | ||
| 308 | x = x and "hello" | ||
| 309 | z = a - b | ||
| 310 | z = a(-b) | ||
| 311 | z = a - b | ||
| 312 | z = a - b | ||
| 313 | local str = strA .. strB .. strC | ||
| 314 | func(3000, "192.168.1.1") | ||
| 315 | local f | ||
| 316 | f = function() | ||
| 317 | return a, b, c, d, e, f | ||
| 318 | end | ||
| 319 | f = function() | ||
| 320 | return a, b, c, d, e, f | ||
| 321 | end | ||
| 322 | do | ||
| 323 | local _with_0 = obj | ||
| 324 | invoke(_with_0:func(), 123, "abc") | ||
| 325 | end | ||
| 326 | invokeA(invokeB(invokeC(123))) | ||
| 327 | invokeA(invokeB(invokeC(123))) | ||
| 328 | local v = { | ||
| 329 | a(-1), | ||
| 330 | a(-1), | ||
| 331 | a - 1, | ||
| 332 | a - 1, | ||
| 333 | a - 1, | ||
| 334 | a - 1, | ||
| 335 | a - 1, | ||
| 336 | a - 1, | ||
| 337 | a(~1), | ||
| 338 | a(~1), | ||
| 339 | a ~ 1, | ||
| 340 | a ~ 1, | ||
| 341 | a ~ 1, | ||
| 342 | a ~ 1, | ||
| 343 | a ~ 1, | ||
| 344 | a ~ 1 | ||
| 345 | } | ||
| 346 | do | ||
| 347 | a = 1 + 2 * 3 / 4 | ||
| 348 | local _1 = f1(-1 + 2 + 3) | ||
| 349 | local _2 = f1 - 1 + 2 + 3 | ||
| 350 | local f2 | ||
| 351 | f2 = function(x) | ||
| 352 | return print(x + 1) | ||
| 353 | end | ||
| 354 | a = f2() | ||
| 355 | f2(-1) | ||
| 356 | a = f2() - f2(1) | ||
| 357 | local _3, _4 | ||
| 358 | _1, _2, _3, _4 = 1, f(2, 3, f(4, 4)) | ||
| 359 | end | ||
| 360 | return nil | ||
diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua new file mode 100644 index 0000000..086e8b3 --- /dev/null +++ b/spec/outputs/tables.lua | |||
| @@ -0,0 +1,351 @@ | |||
| 1 | local backpack = { | ||
| 2 | something = { | ||
| 3 | yeah = 200, | ||
| 4 | they = function() | ||
| 5 | print("hello") | ||
| 6 | return yor_feet("small") | ||
| 7 | end, | ||
| 8 | pretty = hair, | ||
| 9 | gold = hmm | ||
| 10 | }, | ||
| 11 | yow = 1000, | ||
| 12 | eat = goo, | ||
| 13 | yeah = dudd | ||
| 14 | } | ||
| 15 | local start = { | ||
| 16 | something = "cold" | ||
| 17 | } | ||
| 18 | local bathe = { | ||
| 19 | on = "fire" | ||
| 20 | } | ||
| 21 | local another = { | ||
| 22 | [4] = 232, | ||
| 23 | ["good food"] = "is the best" | ||
| 24 | } | ||
| 25 | local fwip = { | ||
| 26 | something = hello("what"), | ||
| 27 | number = 2323, | ||
| 28 | what = yo("momma", "yeah"), | ||
| 29 | fruit = basket, | ||
| 30 | nuts = day | ||
| 31 | } | ||
| 32 | local frick = { | ||
| 33 | hello = "world" | ||
| 34 | } | ||
| 35 | local frack, best = { | ||
| 36 | hello = "world", | ||
| 37 | rice = 3434 | ||
| 38 | }, "what" | ||
| 39 | local ya = { | ||
| 40 | 1, | ||
| 41 | 2, | ||
| 42 | 3, | ||
| 43 | key = 100, | ||
| 44 | 343, | ||
| 45 | "hello", | ||
| 46 | umm = 232 | ||
| 47 | } | ||
| 48 | local x = { | ||
| 49 | 1, | ||
| 50 | 2, | ||
| 51 | 4343, | ||
| 52 | 343, | ||
| 53 | 343 | ||
| 54 | } | ||
| 55 | local g, p = { | ||
| 56 | 1, | ||
| 57 | 2, | ||
| 58 | nowy = "yes", | ||
| 59 | 3, | ||
| 60 | 4, | ||
| 61 | hey = 232, | ||
| 62 | another = "day" | ||
| 63 | }, 234 | ||
| 64 | local annother = { | ||
| 65 | 1, | ||
| 66 | 2, | ||
| 67 | 3, | ||
| 68 | 3, | ||
| 69 | 4, | ||
| 70 | 5, | ||
| 71 | 6, | ||
| 72 | 7, | ||
| 73 | 8 | ||
| 74 | } | ||
| 75 | local yeah = { | ||
| 76 | [232] = 3434, | ||
| 77 | "helo", | ||
| 78 | ice = "cake" | ||
| 79 | } | ||
| 80 | local whatabout = { | ||
| 81 | hello(world, another), | ||
| 82 | what, | ||
| 83 | about, | ||
| 84 | now, | ||
| 85 | hello("world"), | ||
| 86 | yeah, | ||
| 87 | hello("world", yeah) | ||
| 88 | } | ||
| 89 | x = { | ||
| 90 | something = function(self) | ||
| 91 | return "hello" | ||
| 92 | end, | ||
| 93 | cool = { | ||
| 94 | bed = { | ||
| 95 | 2323, | ||
| 96 | 2323 | ||
| 97 | }, | ||
| 98 | red = 2343 | ||
| 99 | }, | ||
| 100 | name = function(self, node) | ||
| 101 | return self:value(node) | ||
| 102 | end | ||
| 103 | } | ||
| 104 | x = { | ||
| 105 | something = something, | ||
| 106 | something = something | ||
| 107 | } | ||
| 108 | local y = { | ||
| 109 | hi = hi, | ||
| 110 | there = there, | ||
| 111 | how = how, | ||
| 112 | you = you, | ||
| 113 | thing = thing | ||
| 114 | } | ||
| 115 | call_me("hello", { | ||
| 116 | x = x, | ||
| 117 | y = y, | ||
| 118 | z = z | ||
| 119 | }) | ||
| 120 | local t = { | ||
| 121 | a = 'a', | ||
| 122 | [b] = 'b' | ||
| 123 | } | ||
| 124 | local xam = { | ||
| 125 | hello = 1234, | ||
| 126 | ["hello"] = 12354, | ||
| 127 | [ [[hello]]] = 12354, | ||
| 128 | ["hello"] = 12354, | ||
| 129 | [ [[hello]]] = 12354 | ||
| 130 | } | ||
| 131 | local kam = { | ||
| 132 | hello = 12, | ||
| 133 | goodcheese = "mmm", | ||
| 134 | yeah = 12 + 232, | ||
| 135 | lets = keepit({ | ||
| 136 | going = true, | ||
| 137 | okay = "yeah" | ||
| 138 | }), | ||
| 139 | more = { | ||
| 140 | 1, | ||
| 141 | (function() | ||
| 142 | local _accum_0 = { } | ||
| 143 | local _len_0 = 1 | ||
| 144 | for x = 1, 10 do | ||
| 145 | _accum_0[_len_0] = x | ||
| 146 | _len_0 = _len_0 + 1 | ||
| 147 | end | ||
| 148 | return _accum_0 | ||
| 149 | end)() | ||
| 150 | }, | ||
| 151 | [{ | ||
| 152 | "one", | ||
| 153 | "two" | ||
| 154 | }] = one_thing(function(self) end) | ||
| 155 | } | ||
| 156 | keepit({ | ||
| 157 | going = true, | ||
| 158 | okay = "yeah", | ||
| 159 | workd = "okay" | ||
| 160 | }) | ||
| 161 | thing({ | ||
| 162 | what = "great", | ||
| 163 | no = "more", | ||
| 164 | okay = 123 | ||
| 165 | }) | ||
| 166 | thing({ | ||
| 167 | what = "great", | ||
| 168 | no = "more" | ||
| 169 | }) | ||
| 170 | local _ = { | ||
| 171 | okay = 123 | ||
| 172 | } | ||
| 173 | local k = { | ||
| 174 | ["hello"] = "world" | ||
| 175 | } | ||
| 176 | k = { | ||
| 177 | ['hello'] = 'world' | ||
| 178 | } | ||
| 179 | k = { | ||
| 180 | ["hello"] = 'world', | ||
| 181 | ["hat"] = "zat" | ||
| 182 | } | ||
| 183 | please({ | ||
| 184 | ["hello"] = "world" | ||
| 185 | }) | ||
| 186 | k = { | ||
| 187 | ["hello"] = "world", | ||
| 188 | ["one"] = "zone" | ||
| 189 | } | ||
| 190 | local f = "one", { | ||
| 191 | ["two"] = three | ||
| 192 | }, "four" | ||
| 193 | f = { | ||
| 194 | ["two"] = three | ||
| 195 | }, "four" | ||
| 196 | f = { | ||
| 197 | "one", | ||
| 198 | ["two"] = three, | ||
| 199 | "four" | ||
| 200 | } | ||
| 201 | local j = "one", { | ||
| 202 | ["two"] = three, | ||
| 203 | ["four"] = five | ||
| 204 | }, 6, 7 | ||
| 205 | local heroine = { | ||
| 206 | name = "Christina", | ||
| 207 | age = 18, | ||
| 208 | job = "Princess", | ||
| 209 | likes = { | ||
| 210 | { | ||
| 211 | name = "kittens", | ||
| 212 | img = "/image/kittens.png" | ||
| 213 | }, | ||
| 214 | { | ||
| 215 | name = "flower", | ||
| 216 | img = "/image/flower.png" | ||
| 217 | } | ||
| 218 | }, | ||
| 219 | items = { | ||
| 220 | { | ||
| 221 | name = "ring", | ||
| 222 | amount = 2 | ||
| 223 | }, | ||
| 224 | { | ||
| 225 | name = "necklace", | ||
| 226 | amount = 1 | ||
| 227 | } | ||
| 228 | }, | ||
| 229 | status = { | ||
| 230 | desc = "weak", | ||
| 231 | { | ||
| 232 | attribute = "health", | ||
| 233 | value = 50 | ||
| 234 | }, | ||
| 235 | { | ||
| 236 | attribute = "mana", | ||
| 237 | value = 100 | ||
| 238 | } | ||
| 239 | } | ||
| 240 | } | ||
| 241 | local inventory = { | ||
| 242 | equipment = { | ||
| 243 | "sword", | ||
| 244 | "shield" | ||
| 245 | }, | ||
| 246 | items = { | ||
| 247 | { | ||
| 248 | name = "potion", | ||
| 249 | count = 10 | ||
| 250 | }, | ||
| 251 | { | ||
| 252 | name = "bread", | ||
| 253 | count = 3 | ||
| 254 | } | ||
| 255 | } | ||
| 256 | } | ||
| 257 | local items = { | ||
| 258 | func(), | ||
| 259 | (function() | ||
| 260 | local _with_0 = tb | ||
| 261 | _with_0.abc = 123 | ||
| 262 | return _with_0 | ||
| 263 | end)(), | ||
| 264 | { | ||
| 265 | 1, | ||
| 266 | 2, | ||
| 267 | 3 | ||
| 268 | }, | ||
| 269 | f({ | ||
| 270 | 1, | ||
| 271 | 2, | ||
| 272 | 3 | ||
| 273 | }), | ||
| 274 | f({ | ||
| 275 | 1, | ||
| 276 | 2, | ||
| 277 | 3 | ||
| 278 | }), | ||
| 279 | (function() | ||
| 280 | local _accum_0 = { } | ||
| 281 | local _len_0 = 1 | ||
| 282 | for i = 1, 3 do | ||
| 283 | _accum_0[_len_0] = i | ||
| 284 | _len_0 = _len_0 + 1 | ||
| 285 | end | ||
| 286 | return _accum_0 | ||
| 287 | end)(), | ||
| 288 | tostring((function() | ||
| 289 | if a then | ||
| 290 | return b | ||
| 291 | end | ||
| 292 | end)()) | ||
| 293 | } | ||
| 294 | local pairs = { | ||
| 295 | { | ||
| 296 | "king", | ||
| 297 | "queen" | ||
| 298 | }, | ||
| 299 | { | ||
| 300 | "hero", | ||
| 301 | "princess" | ||
| 302 | } | ||
| 303 | } | ||
| 304 | items = { | ||
| 305 | { | ||
| 306 | name = "ring", | ||
| 307 | amount = 2 | ||
| 308 | }, | ||
| 309 | { | ||
| 310 | name = "necklace", | ||
| 311 | amount = 1 | ||
| 312 | } | ||
| 313 | } | ||
| 314 | local menus = { | ||
| 315 | { | ||
| 316 | text = "Save", | ||
| 317 | sub = { | ||
| 318 | { | ||
| 319 | text = "Slot 1: " .. (slots[1].name or "None"), | ||
| 320 | click = function() end | ||
| 321 | }, | ||
| 322 | { | ||
| 323 | text = { | ||
| 324 | "Slot 2" | ||
| 325 | }, | ||
| 326 | click = function() end | ||
| 327 | }, | ||
| 328 | { | ||
| 329 | text = [[Slot 3]], | ||
| 330 | click = function() end | ||
| 331 | }, | ||
| 332 | { | ||
| 333 | text = ("Slot 4"):name(), | ||
| 334 | click = function() end | ||
| 335 | }, | ||
| 336 | { | ||
| 337 | text = ({ | ||
| 338 | { | ||
| 339 | "slot5" | ||
| 340 | } | ||
| 341 | })[1]:name(), | ||
| 342 | click = function() end | ||
| 343 | }, | ||
| 344 | [6] = { | ||
| 345 | text = ("Slot 6"), | ||
| 346 | click = function() end | ||
| 347 | } | ||
| 348 | } | ||
| 349 | } | ||
| 350 | } | ||
| 351 | return nil | ||
diff --git a/spec/outputs/teal-lang.lua b/spec/outputs/teal-lang.lua new file mode 100644 index 0000000..0e627f4 --- /dev/null +++ b/spec/outputs/teal-lang.lua | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | local a = { | ||
| 2 | value = 123 | ||
| 3 | }; | ||
| 4 | local b = a.value; | ||
| 5 | local add = function(a, b) | ||
| 6 | return a + b | ||
| 7 | end | ||
| 8 | local s = add(a.value, b) | ||
| 9 | print(s); | ||
| 10 | local Point = {}; | ||
| 11 | Point.new = function(x, y) | ||
| 12 | local point = setmetatable({ }, { | ||
| 13 | __index = Point | ||
| 14 | }) | ||
| 15 | point.x = x or 0 | ||
| 16 | point.y = y or 0 | ||
| 17 | return point | ||
| 18 | end | ||
| 19 | Point.move = function(self, dx, dy) | ||
| 20 | self.x = self.x + dx | ||
| 21 | self.y = self.y + dy | ||
| 22 | end | ||
| 23 | local p = Point.new(100, 100) | ||
| 24 | p:move(50, 50); | ||
| 25 | local filter = function(tab, handler) | ||
| 26 | local _accum_0 = { } | ||
| 27 | local _len_0 = 1 | ||
| 28 | for _index_0 = 1, #tab do | ||
| 29 | local item = tab[_index_0] | ||
| 30 | if handler(item) then | ||
| 31 | _accum_0[_len_0] = item | ||
| 32 | _len_0 = _len_0 + 1 | ||
| 33 | end | ||
| 34 | end | ||
| 35 | return _accum_0 | ||
| 36 | end | ||
| 37 | local cond = function(item) | ||
| 38 | return item ~= "a" | ||
| 39 | end | ||
| 40 | local res = filter({ | ||
| 41 | "a", | ||
| 42 | "b", | ||
| 43 | "c", | ||
| 44 | "a" | ||
| 45 | }, cond) | ||
| 46 | for _index_0 = 1, #res do | ||
| 47 | local s = res[_index_0] | ||
| 48 | print(s) | ||
| 49 | end | ||
diff --git a/spec/outputs/teal-lang.tl b/spec/outputs/teal-lang.tl new file mode 100644 index 0000000..8f0bf36 --- /dev/null +++ b/spec/outputs/teal-lang.tl | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | local a:{string:number} = { | ||
| 2 | value = 123 | ||
| 3 | }; | ||
| 4 | local b:number = a.value; | ||
| 5 | local function add(a:number, b:number):number | ||
| 6 | |||
| 7 | return a + b | ||
| 8 | |||
| 9 | end | ||
| 10 | local s = add(a.value, b) | ||
| 11 | print(s); | ||
| 12 | local record Point | ||
| 13 | x: number | ||
| 14 | y: number | ||
| 15 | end | ||
| 16 | function Point.new(x:number, y:number):Point | ||
| 17 | local point:Point = setmetatable({ }, { | ||
| 18 | __index = Point | ||
| 19 | }) | ||
| 20 | point.x = x or 0 | ||
| 21 | point.y = y or 0 | ||
| 22 | return point | ||
| 23 | |||
| 24 | end | ||
| 25 | function Point:move(dx:number, dy:number) | ||
| 26 | self.x = self.x + dx | ||
| 27 | self.y = self.y + dy | ||
| 28 | |||
| 29 | end | ||
| 30 | local p:Point = Point.new(100, 100) | ||
| 31 | p:move(50, 50); | ||
| 32 | local function filter(tab:{string}, handler:function(item:string):boolean):{string} | ||
| 33 | |||
| 34 | local _accum_0 = { } | ||
| 35 | local _len_0 = 1 | ||
| 36 | for _index_0 = 1, #tab do | ||
| 37 | local item = tab[_index_0] | ||
| 38 | if handler(item) then | ||
| 39 | _accum_0[_len_0] = item | ||
| 40 | _len_0 = _len_0 + 1 | ||
| 41 | end | ||
| 42 | end | ||
| 43 | return _accum_0 | ||
| 44 | |||
| 45 | end | ||
| 46 | local function cond(item:string):boolean | ||
| 47 | |||
| 48 | return item ~= "a" | ||
| 49 | |||
| 50 | end | ||
| 51 | local res = filter({ | ||
| 52 | "a", | ||
| 53 | "b", | ||
| 54 | "c", | ||
| 55 | "a" | ||
| 56 | }, cond) | ||
| 57 | for _index_0 = 1, #res do | ||
| 58 | local s = res[_index_0] | ||
| 59 | print(s) | ||
| 60 | end | ||
diff --git a/spec/outputs/unless_else.lua b/spec/outputs/unless_else.lua new file mode 100644 index 0000000..c85d4bf --- /dev/null +++ b/spec/outputs/unless_else.lua | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | if a then | ||
| 2 | if not b then | ||
| 3 | return print("hi") | ||
| 4 | elseif c then | ||
| 5 | return print("not hi") | ||
| 6 | end | ||
| 7 | end | ||
diff --git a/spec/outputs/using.lua b/spec/outputs/using.lua new file mode 100644 index 0000000..6d0d888 --- /dev/null +++ b/spec/outputs/using.lua | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | local hello = "hello" | ||
| 2 | local world = "world" | ||
| 3 | local _ | ||
| 4 | _ = function() | ||
| 5 | local hello = 3223 | ||
| 6 | end | ||
| 7 | _ = function(a) | ||
| 8 | local hello = 3223 | ||
| 9 | a = 323 | ||
| 10 | end | ||
| 11 | _ = function(a, b, c) | ||
| 12 | a, b, c = 1, 2, 3 | ||
| 13 | local world = 12321 | ||
| 14 | end | ||
| 15 | _ = function(a, e, f) | ||
| 16 | local b, c | ||
| 17 | a, b, c = 1, 2, 3 | ||
| 18 | hello = 12321 | ||
| 19 | local world = "yeah" | ||
| 20 | end | ||
| 21 | _ = function() | ||
| 22 | local hello = hello or 2 | ||
| 23 | end | ||
diff --git a/spec/outputs/vararg.lua b/spec/outputs/vararg.lua new file mode 100644 index 0000000..e799a94 --- /dev/null +++ b/spec/outputs/vararg.lua | |||
| @@ -0,0 +1,218 @@ | |||
| 1 | local join | ||
| 2 | join = function(...) | ||
| 3 | f_with((function() | ||
| 4 | local _with_0 = a | ||
| 5 | _with_0:func() | ||
| 6 | return _with_0 | ||
| 7 | end)()) | ||
| 8 | f_with((function(...) | ||
| 9 | local _with_0 = a | ||
| 10 | _with_0:func(...) | ||
| 11 | return _with_0 | ||
| 12 | end)(...)) | ||
| 13 | f_listcomp((function() | ||
| 14 | local _accum_0 = { } | ||
| 15 | local _len_0 = 1 | ||
| 16 | for i = 1, 10 do | ||
| 17 | _accum_0[_len_0] = items[i] | ||
| 18 | _len_0 = _len_0 + 1 | ||
| 19 | end | ||
| 20 | return _accum_0 | ||
| 21 | end)()) | ||
| 22 | f_listcomp((function(...) | ||
| 23 | local _accum_0 = { } | ||
| 24 | local _len_0 = 1 | ||
| 25 | for i = 1, 10 do | ||
| 26 | _accum_0[_len_0] = items[i](...) | ||
| 27 | _len_0 = _len_0 + 1 | ||
| 28 | end | ||
| 29 | return _accum_0 | ||
| 30 | end)(...)) | ||
| 31 | f_listcomp((function() | ||
| 32 | local _accum_0 = { } | ||
| 33 | local _len_0 = 1 | ||
| 34 | local _list_0 = items | ||
| 35 | for _index_0 = 1, #_list_0 do | ||
| 36 | local item = _list_0[_index_0] | ||
| 37 | _accum_0[_len_0] = item | ||
| 38 | _len_0 = _len_0 + 1 | ||
| 39 | end | ||
| 40 | return _accum_0 | ||
| 41 | end)()) | ||
| 42 | f_listcomp((function(...) | ||
| 43 | local _accum_0 = { } | ||
| 44 | local _len_0 = 1 | ||
| 45 | local _list_0 = items | ||
| 46 | for _index_0 = 1, #_list_0 do | ||
| 47 | local item = _list_0[_index_0] | ||
| 48 | _accum_0[_len_0] = item(...) | ||
| 49 | _len_0 = _len_0 + 1 | ||
| 50 | end | ||
| 51 | return _accum_0 | ||
| 52 | end)(...)) | ||
| 53 | f_class((function() | ||
| 54 | local A | ||
| 55 | do | ||
| 56 | local _class_0 | ||
| 57 | local _base_0 = { } | ||
| 58 | _base_0.__index = _base_0 | ||
| 59 | _class_0 = setmetatable({ | ||
| 60 | __init = function() end, | ||
| 61 | __base = _base_0, | ||
| 62 | __name = "A" | ||
| 63 | }, { | ||
| 64 | __index = _base_0, | ||
| 65 | __call = function(cls, ...) | ||
| 66 | local _self_0 = setmetatable({ }, _base_0) | ||
| 67 | cls.__init(_self_0, ...) | ||
| 68 | return _self_0 | ||
| 69 | end | ||
| 70 | }) | ||
| 71 | _base_0.__class = _class_0 | ||
| 72 | local self = _class_0; | ||
| 73 | func() | ||
| 74 | A = _class_0 | ||
| 75 | return _class_0 | ||
| 76 | end | ||
| 77 | end)()) | ||
| 78 | f_class((function(...) | ||
| 79 | local A | ||
| 80 | do | ||
| 81 | local _class_0 | ||
| 82 | local _base_0 = { } | ||
| 83 | _base_0.__index = _base_0 | ||
| 84 | _class_0 = setmetatable({ | ||
| 85 | __init = function() end, | ||
| 86 | __base = _base_0, | ||
| 87 | __name = "A" | ||
| 88 | }, { | ||
| 89 | __index = _base_0, | ||
| 90 | __call = function(cls, ...) | ||
| 91 | local _self_0 = setmetatable({ }, _base_0) | ||
| 92 | cls.__init(_self_0, ...) | ||
| 93 | return _self_0 | ||
| 94 | end | ||
| 95 | }) | ||
| 96 | _base_0.__class = _class_0 | ||
| 97 | local self = _class_0; | ||
| 98 | func(...) | ||
| 99 | A = _class_0 | ||
| 100 | return _class_0 | ||
| 101 | end | ||
| 102 | end)(...)) | ||
| 103 | f_tblcomp((function() | ||
| 104 | local _tbl_0 = { } | ||
| 105 | for k, v in pairs(tb) do | ||
| 106 | _tbl_0[k] = v | ||
| 107 | end | ||
| 108 | return _tbl_0 | ||
| 109 | end)()) | ||
| 110 | f_tblcomp((function(...) | ||
| 111 | local _tbl_0 = { } | ||
| 112 | for k, v in pairs(tb) do | ||
| 113 | _tbl_0[k] = v(...) | ||
| 114 | end | ||
| 115 | return _tbl_0 | ||
| 116 | end)(...)) | ||
| 117 | f_tblcomp((function() | ||
| 118 | local _tbl_0 = { } | ||
| 119 | local _list_0 = items | ||
| 120 | for _index_0 = 1, #_list_0 do | ||
| 121 | local item = _list_0[_index_0] | ||
| 122 | _tbl_0[item] = true | ||
| 123 | end | ||
| 124 | return _tbl_0 | ||
| 125 | end)()) | ||
| 126 | f_tblcomp((function(...) | ||
| 127 | local _tbl_0 = { } | ||
| 128 | local _list_0 = items | ||
| 129 | for _index_0 = 1, #_list_0 do | ||
| 130 | local item = _list_0[_index_0] | ||
| 131 | _tbl_0[item(...)] = true | ||
| 132 | end | ||
| 133 | return _tbl_0 | ||
| 134 | end)(...)) | ||
| 135 | f_do((function() | ||
| 136 | return func() | ||
| 137 | end)()) | ||
| 138 | f_do((function(...) | ||
| 139 | return func(...) | ||
| 140 | end)(...)) | ||
| 141 | f_while((function() | ||
| 142 | local _accum_0 = { } | ||
| 143 | local _len_0 = 1 | ||
| 144 | while false do | ||
| 145 | _accum_0[_len_0] = func() | ||
| 146 | _len_0 = _len_0 + 1 | ||
| 147 | end | ||
| 148 | return _accum_0 | ||
| 149 | end)()) | ||
| 150 | f_while((function(...) | ||
| 151 | local _accum_0 = { } | ||
| 152 | local _len_0 = 1 | ||
| 153 | while false do | ||
| 154 | _accum_0[_len_0] = func(...) | ||
| 155 | _len_0 = _len_0 + 1 | ||
| 156 | end | ||
| 157 | return _accum_0 | ||
| 158 | end)(...)) | ||
| 159 | f_if((function() | ||
| 160 | if false then | ||
| 161 | return func() | ||
| 162 | end | ||
| 163 | end)()) | ||
| 164 | f_if((function(...) | ||
| 165 | if false then | ||
| 166 | return func(...) | ||
| 167 | end | ||
| 168 | end)(...)) | ||
| 169 | f_unless((function() | ||
| 170 | if not true then | ||
| 171 | return func() | ||
| 172 | end | ||
| 173 | end)()) | ||
| 174 | f_unless((function(...) | ||
| 175 | if not true then | ||
| 176 | return func(...) | ||
| 177 | end | ||
| 178 | end)(...)) | ||
| 179 | f_switch((function() | ||
| 180 | local _exp_0 = x | ||
| 181 | if "abc" == _exp_0 then | ||
| 182 | return func() | ||
| 183 | end | ||
| 184 | end)()) | ||
| 185 | f_switch((function(...) | ||
| 186 | local _exp_0 = x | ||
| 187 | if "abc" == _exp_0 then | ||
| 188 | return func(...) | ||
| 189 | end | ||
| 190 | end)(...)) | ||
| 191 | f_eop((function() | ||
| 192 | if func ~= nil then | ||
| 193 | return func() | ||
| 194 | end | ||
| 195 | return nil | ||
| 196 | end)()) | ||
| 197 | f_eop((function(...) | ||
| 198 | if func ~= nil then | ||
| 199 | return func(...) | ||
| 200 | end | ||
| 201 | return nil | ||
| 202 | end)(...)) | ||
| 203 | f_colon((function() | ||
| 204 | local _base_0 = f() | ||
| 205 | local _fn_0 = _base_0.func | ||
| 206 | return _fn_0 and function(...) | ||
| 207 | return _fn_0(_base_0, ...) | ||
| 208 | end | ||
| 209 | end)()) | ||
| 210 | f_colon((function(...) | ||
| 211 | local _base_0 = f(...) | ||
| 212 | local _fn_0 = _base_0.func | ||
| 213 | return _fn_0 and function(...) | ||
| 214 | return _fn_0(_base_0, ...) | ||
| 215 | end | ||
| 216 | end)(...)) | ||
| 217 | return nil | ||
| 218 | end | ||
diff --git a/spec/outputs/whitespace.lua b/spec/outputs/whitespace.lua new file mode 100644 index 0000000..1bc4503 --- /dev/null +++ b/spec/outputs/whitespace.lua | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | local _ = { | ||
| 2 | 1, | ||
| 3 | 2 | ||
| 4 | } | ||
| 5 | _ = { | ||
| 6 | 1, | ||
| 7 | 2 | ||
| 8 | } | ||
| 9 | _ = { | ||
| 10 | 1, | ||
| 11 | 2 | ||
| 12 | } | ||
| 13 | _ = { | ||
| 14 | 1, | ||
| 15 | 2 | ||
| 16 | } | ||
| 17 | _ = { | ||
| 18 | 1, | ||
| 19 | 2 | ||
| 20 | } | ||
| 21 | _ = { | ||
| 22 | something(1, 2, 4, 5, 6), | ||
| 23 | 3, | ||
| 24 | 4, | ||
| 25 | 5 | ||
| 26 | } | ||
| 27 | _ = { | ||
| 28 | a(1, 2, 3), | ||
| 29 | 4, | ||
| 30 | 5, | ||
| 31 | 6, | ||
| 32 | 1, | ||
| 33 | 2, | ||
| 34 | 3 | ||
| 35 | } | ||
| 36 | _ = { | ||
| 37 | b(1, 2, 3, 4, 5, 6), | ||
| 38 | 1, | ||
| 39 | 2, | ||
| 40 | 3, | ||
| 41 | 1, | ||
| 42 | 2, | ||
| 43 | 3 | ||
| 44 | } | ||
| 45 | _ = { | ||
| 46 | 1, | ||
| 47 | 2, | ||
| 48 | 3 | ||
| 49 | } | ||
| 50 | _ = { | ||
| 51 | c(1, 2, 3) | ||
| 52 | } | ||
| 53 | hello(1, 2, 3, 4, 1, 2, 3, 4, 4, 5) | ||
| 54 | x(1, 2, 3, 4, 5, 6) | ||
| 55 | hello(1, 2, 3, world(4, 5, 6, 5, 6, 7, 8)) | ||
| 56 | hello(1, 2, 3, world(4, 5, 6, 5, 6, 7, 8), 9, 9) | ||
| 57 | _ = { | ||
| 58 | hello(1, 2), | ||
| 59 | 3, | ||
| 60 | 4, | ||
| 61 | 5, | ||
| 62 | 6 | ||
| 63 | } | ||
| 64 | local x = { | ||
| 65 | hello(1, 2, 3, 4, 5, 6, 7), | ||
| 66 | 1, | ||
| 67 | 2, | ||
| 68 | 3, | ||
| 69 | 4 | ||
| 70 | } | ||
| 71 | if hello(1, 2, 3, world, world) then | ||
| 72 | print("hello") | ||
| 73 | end | ||
| 74 | if hello(1, 2, 3, world, world) then | ||
| 75 | print("hello") | ||
| 76 | end | ||
| 77 | a(one, two, three) | ||
| 78 | b(one, two, three) | ||
| 79 | c(one, two, three, four) | ||
| 80 | local v | ||
| 81 | v = function() | ||
| 82 | return a, b, c | ||
| 83 | end | ||
| 84 | local v1, v2, v3 | ||
| 85 | v1, v2, v3 = function() | ||
| 86 | return a | ||
| 87 | end, b, c | ||
| 88 | local a, b, c, d, e, f = 1, f2({ | ||
| 89 | abc = abc | ||
| 90 | }), 3, 4, f5(abc), 6 | ||
| 91 | for a, b, c in pairs(tb) do | ||
| 92 | print(a, b, c) | ||
| 93 | end | ||
| 94 | for i = 1, 10, -1 do | ||
| 95 | print(i) | ||
| 96 | end | ||
| 97 | local a, b, c | ||
| 98 | return nil | ||
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua new file mode 100644 index 0000000..e1497c6 --- /dev/null +++ b/spec/outputs/with.lua | |||
| @@ -0,0 +1,164 @@ | |||
| 1 | do | ||
| 2 | local a | ||
| 3 | a = function() | ||
| 4 | local _with_0 = something | ||
| 5 | print(_with_0.hello) | ||
| 6 | print(hi) | ||
| 7 | print("world") | ||
| 8 | return _with_0 | ||
| 9 | end | ||
| 10 | end | ||
| 11 | do | ||
| 12 | do | ||
| 13 | local _with_0 = leaf | ||
| 14 | _with_0.world() | ||
| 15 | _with_0.world(1, 2, 3) | ||
| 16 | local g = _with_0.what.is.this | ||
| 17 | _with_0.hi(1, 2, 3) | ||
| 18 | _with_0:hi(1, 2).world(2323) | ||
| 19 | _with_0:hi("yeah", "man") | ||
| 20 | _with_0.world = 200 | ||
| 21 | end | ||
| 22 | end | ||
| 23 | do | ||
| 24 | local zyzyzy | ||
| 25 | do | ||
| 26 | local _with_0 = something | ||
| 27 | _with_0.set_state("hello world") | ||
| 28 | zyzyzy = _with_0 | ||
| 29 | end | ||
| 30 | end | ||
| 31 | do | ||
| 32 | local x = 5 + (function() | ||
| 33 | local _with_0 = Something() | ||
| 34 | _with_0:write("hello world") | ||
| 35 | return _with_0 | ||
| 36 | end)() | ||
| 37 | end | ||
| 38 | do | ||
| 39 | local x = { | ||
| 40 | hello = (function() | ||
| 41 | local _with_0 = yeah | ||
| 42 | _with_0:okay() | ||
| 43 | return _with_0 | ||
| 44 | end)() | ||
| 45 | } | ||
| 46 | end | ||
| 47 | do | ||
| 48 | do | ||
| 49 | local _with_0 = foo | ||
| 50 | local _ = _with_0:prop("something").hello | ||
| 51 | _with_0.prop:send(one) | ||
| 52 | _with_0.prop:send(one) | ||
| 53 | end | ||
| 54 | end | ||
| 55 | do | ||
| 56 | do | ||
| 57 | local _with_0 = a, b | ||
| 58 | print(_with_0.world) | ||
| 59 | end | ||
| 60 | local mod | ||
| 61 | do | ||
| 62 | local _M = { } | ||
| 63 | _M.Thing = "hi" | ||
| 64 | mod = _M | ||
| 65 | end | ||
| 66 | do | ||
| 67 | local a, b = something, pooh | ||
| 68 | print(a.world) | ||
| 69 | end | ||
| 70 | local x | ||
| 71 | do | ||
| 72 | local a, b = 1, 2 | ||
| 73 | print(a + b) | ||
| 74 | x = a | ||
| 75 | end | ||
| 76 | print((function() | ||
| 77 | local a, b = 1, 2 | ||
| 78 | print(a + b) | ||
| 79 | return a | ||
| 80 | end)()) | ||
| 81 | local p | ||
| 82 | do | ||
| 83 | local _with_0 = 1 | ||
| 84 | hello().x, world().y = _with_0, 2 | ||
| 85 | print(a + b) | ||
| 86 | p = _with_0 | ||
| 87 | end | ||
| 88 | end | ||
| 89 | do | ||
| 90 | local x = "hello" | ||
| 91 | x:upper() | ||
| 92 | end | ||
| 93 | do | ||
| 94 | do | ||
| 95 | local k = "jo" | ||
| 96 | print(k:upper()) | ||
| 97 | end | ||
| 98 | end | ||
| 99 | do | ||
| 100 | do | ||
| 101 | local a, b, c = "", "", "" | ||
| 102 | print(a:upper()) | ||
| 103 | end | ||
| 104 | end | ||
| 105 | do | ||
| 106 | local a = "bunk" | ||
| 107 | do | ||
| 108 | local b, c | ||
| 109 | a, b, c = "", "", "" | ||
| 110 | print(a:upper()) | ||
| 111 | end | ||
| 112 | end | ||
| 113 | do | ||
| 114 | do | ||
| 115 | local _with_0 = j | ||
| 116 | print(_with_0:upper()) | ||
| 117 | end | ||
| 118 | end | ||
| 119 | do | ||
| 120 | do | ||
| 121 | local _with_0 = "jo" | ||
| 122 | k.j = _with_0 | ||
| 123 | print(_with_0:upper()) | ||
| 124 | end | ||
| 125 | end | ||
| 126 | do | ||
| 127 | do | ||
| 128 | local _with_0 = a | ||
| 129 | print(_with_0.b) | ||
| 130 | do | ||
| 131 | local _with_1 = _with_0.c | ||
| 132 | print(_with_1.d) | ||
| 133 | end | ||
| 134 | end | ||
| 135 | end | ||
| 136 | do | ||
| 137 | do | ||
| 138 | local _with_0 = a | ||
| 139 | do | ||
| 140 | local _with_1 = 2 | ||
| 141 | _with_0.b = _with_1 | ||
| 142 | print(_with_1.c) | ||
| 143 | end | ||
| 144 | end | ||
| 145 | end | ||
| 146 | do | ||
| 147 | local _ | ||
| 148 | _ = function() | ||
| 149 | local _with_0 = hi | ||
| 150 | return _with_0.a, _with_0.b | ||
| 151 | end | ||
| 152 | end | ||
| 153 | do | ||
| 154 | do | ||
| 155 | local _with_0 = tb | ||
| 156 | _with_0.x = item.field:func(123) | ||
| 157 | end | ||
| 158 | end | ||
| 159 | do | ||
| 160 | local _with_0 = dad | ||
| 161 | _with_0["if"]("yes") | ||
| 162 | local y = _with_0["end"].of["function"] | ||
| 163 | return _with_0 | ||
| 164 | end | ||
