From 303834e1b1e6cd9cae64b66c2ae44dcd7185238f Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sun, 24 Jul 2022 22:13:08 +0800 Subject: add option --target=5.1 to generate Lua 5.1 compatible codes. add const destructure. make import item const by default. --- spec/inputs/destructure.yue | 5 ++++- spec/inputs/export.yue | 4 ++-- spec/inputs/import.yue | 2 +- spec/inputs/macro.yue | 2 +- spec/inputs/metatable.yue | 2 +- spec/inputs/syntax.yue | 10 +++++----- spec/inputs/tables.yue | 8 ++++---- spec/inputs/with.yue | 2 +- spec/outputs/destructure.lua | 25 +++++++++++++++++++++++-- spec/outputs/export.lua | 10 ++++++++-- spec/outputs/import.lua | 2 +- spec/outputs/macro.lua | 3 ++- spec/outputs/metatable.lua | 1 - spec/outputs/syntax.lua | 10 +++++----- spec/outputs/tables.lua | 8 ++++---- spec/outputs/with.lua | 2 +- 16 files changed, 63 insertions(+), 33 deletions(-) (limited to 'spec') diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue index 3007adf..24282c0 100644 --- a/spec/inputs/destructure.yue +++ b/spec/inputs/destructure.yue @@ -11,7 +11,7 @@ do {:a,:b,:c,:d} = yeah - {a} = one, two + {a}, b = one, two {b}, c = one {d}, e = one, two @@ -184,3 +184,6 @@ do do {x: a.b = 1, y: a.c = 2} = x.x.x +do + const :width, :height = View.size + const {:x = 0.0, :y = 0.0} = point diff --git a/spec/inputs/export.yue b/spec/inputs/export.yue index 9113508..15ffbcb 100644 --- a/spec/inputs/export.yue +++ b/spec/inputs/export.yue @@ -55,7 +55,7 @@ f switch a f [i for i = 1,10] f for i = 1,10 do i f {k,v for k,v in pairs tb} -f for k,v in pairs tb do k,v +f for k,v in pairs tb do {k,v} f while a do true f with a .b = 123 @@ -70,7 +70,7 @@ _ = "#{switch a _ = "#{[i for i = 1,10]}" _ = "#{for i = 1,10 do i}" _ = "#{{k,v for k,v in pairs tb}}" -_ = "#{for k,v in pairs tb do k,v}" +_ = "#{for k,v in pairs tb do {k,v}}" _ = "#{while a do true}" _ = "#{with a .b = 123}" diff --git a/spec/inputs/import.yue b/spec/inputs/import.yue index 8e82a01..e206d04 100644 --- a/spec/inputs/import.yue +++ b/spec/inputs/import.yue @@ -70,7 +70,7 @@ do do import "m" as {a#: b} - import "m" as {e: f, a#: b} + import "m" as {e: f, a#: c} import "m" as {c: d} import "m" as {g, {h#: i}} diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue index 7bbb06d..3c89c1c 100644 --- a/spec/inputs/macro.yue +++ b/spec/inputs/macro.yue @@ -279,7 +279,7 @@ do macro skip = -> "while false do break" -_ = -> +_1 = -> print 1 <- $skip print 2 diff --git a/spec/inputs/metatable.yue b/spec/inputs/metatable.yue index ed68a17..7e9b4f2 100644 --- a/spec/inputs/metatable.yue +++ b/spec/inputs/metatable.yue @@ -23,7 +23,7 @@ do = 123, a.b.c, func! x.abc, a.b.# = 123, {} -func!.# = mt, extra +func!.# = mt --, extra a, b.c.#, d, e = 1, mt, "abc" is_same = a.#.__index == a.index# diff --git a/spec/inputs/syntax.yue b/spec/inputs/syntax.yue index f212bec..d18bd0e 100644 --- a/spec/inputs/syntax.yue +++ b/spec/inputs/syntax.yue @@ -71,10 +71,10 @@ _ = something[======[hey]======] * 2 _ = something[ [======[hey]======] ] * 2 -_ = something'else', 2 -_ = something"else", 2 -_ = something[[else]], 2 -_ = something[ [[else]] ], 2 +_, _ = something'else', 2 +_, _ = something"else", 2 +_, _ = something[[else]], 2 +_, _ = something[ [[else]] ], 2 something 'else', 2 something "else", 2 @@ -157,7 +157,7 @@ y = #"hello" x = #{#{},#{1},#{1,2}} -_ = hello, world +_, _ = hello, world something\hello(what) a,b something\hello what diff --git a/spec/inputs/tables.yue b/spec/inputs/tables.yue index e1b9e1d..0b5af46 100644 --- a/spec/inputs/tables.yue +++ b/spec/inputs/tables.yue @@ -152,12 +152,12 @@ k = { "hello": 'world', "hat": "zat" } please "hello": "world" k = "hello": "world", "one": "zone" -f = "one", "two": three, "four" -f = "two": three, "four" -f = { "one", "two": three, "four" } +f1, f2, f3 = "one", "two": three, "four" +f1, f2 = "two": three, "four" +f1 = { "one", "two": three, "four" } -j = "one", "two": three, "four": five, 6, 7 +j1, j2, j3, j4 = "one", "two": three, "four": five, 6, 7 heroine = name: "Christina" diff --git a/spec/inputs/with.yue b/spec/inputs/with.yue index 6f3e3ba..5da0980 100644 --- a/spec/inputs/with.yue +++ b/spec/inputs/with.yue @@ -45,7 +45,7 @@ do -- do - with a, b -- b is lost + with a -- only one value allowed print .world mod = with _M = {} diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua index 2fe4ba9..59ee358 100644 --- a/spec/outputs/destructure.lua +++ b/spec/outputs/destructure.lua @@ -26,7 +26,7 @@ do local _obj_0 = yeah a, b, c, d = _obj_0.a, _obj_0.b, _obj_0.c, _obj_0.d end - local _ = two + b = two a = one[1] c = nil b = one[1] @@ -56,7 +56,10 @@ do end do a = tbl - b, c = _.b, _.c + do + local _obj_0 = _ + b, c = _obj_0.b, _obj_0.c + end end do b = _ @@ -386,3 +389,21 @@ do a.c = _tmp_1 end end +do + local width, height + do + local _obj_0 = View.size + width, height = _obj_0.width, _obj_0.height + end + local x, y + do + local _obj_0 = point + x, y = _obj_0.x, _obj_0.y + if x == nil then + x = 0.0 + end + if y == nil then + y = 0.0 + end + end +end diff --git a/spec/outputs/export.lua b/spec/outputs/export.lua index 84e5424..962f18c 100644 --- a/spec/outputs/export.lua +++ b/spec/outputs/export.lua @@ -134,7 +134,10 @@ f((function() local _accum_0 = { } local _len_0 = 1 for k, v in pairs(tb) do - _accum_0[_len_0] = k, v + _accum_0[_len_0] = { + k, + v + } _len_0 = _len_0 + 1 end return _accum_0 @@ -232,7 +235,10 @@ _ = tostring((function() local _accum_0 = { } local _len_0 = 1 for k, v in pairs(tb) do - _accum_0[_len_0] = k, v + _accum_0[_len_0] = { + k, + v + } _len_0 = _len_0 + 1 end return _accum_0 diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua index 65e703f..6979e47 100644 --- a/spec/outputs/import.lua +++ b/spec/outputs/import.lua @@ -94,7 +94,7 @@ do b = getmetatable(require("m")).__a local _obj_0 = require("m") local f = _obj_0.e - b = getmetatable(_obj_0).__a + c = getmetatable(_obj_0).__a local d = require("m").c local g, i do diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua index c19b2d7..fbc1d48 100644 --- a/spec/outputs/macro.lua +++ b/spec/outputs/macro.lua @@ -282,7 +282,8 @@ print("current line: " .. tostring(268)); do print(1) end -_ = function() +local _1 +_1 = function() print(1) local _accum_0 = { } local _len_0 = 1 diff --git a/spec/outputs/metatable.lua b/spec/outputs/metatable.lua index 935202c..2d72e1d 100644 --- a/spec/outputs/metatable.lua +++ b/spec/outputs/metatable.lua @@ -65,7 +65,6 @@ end setmetatable(a.b, { }) x.abc = 123 setmetatable(func(), mt) -local _ = extra setmetatable(b.c, mt) a, d, e = 1, "abc" local is_same = getmetatable(a).__index == getmetatable(a).__index diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua index 24b78c6..a4cb8e2 100644 --- a/spec/outputs/syntax.lua +++ b/spec/outputs/syntax.lua @@ -56,10 +56,10 @@ something("else") _ = something([[hey]]) * 2 _ = something([======[hey]======]) * 2 _ = something[ [======[hey]======]] * 2 -_ = something('else'), 2 -_ = something("else"), 2 -_ = something([[else]]), 2 -_ = something[ [[else]]], 2 +_, _ = something('else'), 2 +_, _ = something("else"), 2 +_, _ = something([[else]]), 2 +_, _ = something[ [[else]]], 2 something('else', 2) something("else", 2) something([[else]], 2) @@ -165,7 +165,7 @@ x = #{ 2 } } -_ = hello, world +_, _ = hello, world something:hello(what)(a, b) something:hello(what) something.hello:world(a, b) diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua index 1d28a43..e9df1c4 100644 --- a/spec/outputs/tables.lua +++ b/spec/outputs/tables.lua @@ -187,18 +187,18 @@ k = { ["hello"] = "world", ["one"] = "zone" } -local f = "one", { +local f1, f2, f3 = "one", { ["two"] = three }, "four" -f = { +f1, f2 = { ["two"] = three }, "four" -f = { +f1 = { "one", ["two"] = three, "four" } -local j = "one", { +local j1, j2, j3, j4 = "one", { ["two"] = three, ["four"] = five }, 6, 7 diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua index 9dcaca3..304d26e 100644 --- a/spec/outputs/with.lua +++ b/spec/outputs/with.lua @@ -54,7 +54,7 @@ do end do do - local _with_0 = a, b + local _with_0 = a print(_with_0.world) end local mod -- cgit v1.2.3-55-g6feb