diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-07-24 22:13:08 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-07-24 22:13:08 +0800 |
| commit | 303834e1b1e6cd9cae64b66c2ae44dcd7185238f (patch) | |
| tree | 519f6a1debcc5791d35e06dc5cbb1ce22f9cfd31 /spec | |
| parent | eb367126bf3a4f5b0e51ccef93b7c7136bea170e (diff) | |
| download | yuescript-303834e1b1e6cd9cae64b66c2ae44dcd7185238f.tar.gz yuescript-303834e1b1e6cd9cae64b66c2ae44dcd7185238f.tar.bz2 yuescript-303834e1b1e6cd9cae64b66c2ae44dcd7185238f.zip | |
add option --target=5.1 to generate Lua 5.1 compatible codes. add const destructure. make import item const by default.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/inputs/destructure.yue | 5 | ||||
| -rw-r--r-- | spec/inputs/export.yue | 4 | ||||
| -rw-r--r-- | spec/inputs/import.yue | 2 | ||||
| -rw-r--r-- | spec/inputs/macro.yue | 2 | ||||
| -rw-r--r-- | spec/inputs/metatable.yue | 2 | ||||
| -rw-r--r-- | spec/inputs/syntax.yue | 10 | ||||
| -rw-r--r-- | spec/inputs/tables.yue | 8 | ||||
| -rw-r--r-- | spec/inputs/with.yue | 2 | ||||
| -rw-r--r-- | spec/outputs/destructure.lua | 25 | ||||
| -rw-r--r-- | spec/outputs/export.lua | 10 | ||||
| -rw-r--r-- | spec/outputs/import.lua | 2 | ||||
| -rw-r--r-- | spec/outputs/macro.lua | 3 | ||||
| -rw-r--r-- | spec/outputs/metatable.lua | 1 | ||||
| -rw-r--r-- | spec/outputs/syntax.lua | 10 | ||||
| -rw-r--r-- | spec/outputs/tables.lua | 8 | ||||
| -rw-r--r-- | spec/outputs/with.lua | 2 |
16 files changed, 63 insertions, 33 deletions
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 | |||
| 11 | 11 | ||
| 12 | {:a,:b,:c,:d} = yeah | 12 | {:a,:b,:c,:d} = yeah |
| 13 | 13 | ||
| 14 | {a} = one, two | 14 | {a}, b = one, two |
| 15 | {b}, c = one | 15 | {b}, c = one |
| 16 | {d}, e = one, two | 16 | {d}, e = one, two |
| 17 | 17 | ||
| @@ -184,3 +184,6 @@ do | |||
| 184 | do | 184 | do |
| 185 | {x: a.b = 1, y: a.c = 2} = x.x.x | 185 | {x: a.b = 1, y: a.c = 2} = x.x.x |
| 186 | 186 | ||
| 187 | do | ||
| 188 | const :width, :height = View.size | ||
| 189 | 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 | |||
| 55 | f [i for i = 1,10] | 55 | f [i for i = 1,10] |
| 56 | f for i = 1,10 do i | 56 | f for i = 1,10 do i |
| 57 | f {k,v for k,v in pairs tb} | 57 | f {k,v for k,v in pairs tb} |
| 58 | f for k,v in pairs tb do k,v | 58 | f for k,v in pairs tb do {k,v} |
| 59 | f while a do true | 59 | f while a do true |
| 60 | f with a | 60 | f with a |
| 61 | .b = 123 | 61 | .b = 123 |
| @@ -70,7 +70,7 @@ _ = "#{switch a | |||
| 70 | _ = "#{[i for i = 1,10]}" | 70 | _ = "#{[i for i = 1,10]}" |
| 71 | _ = "#{for i = 1,10 do i}" | 71 | _ = "#{for i = 1,10 do i}" |
| 72 | _ = "#{{k,v for k,v in pairs tb}}" | 72 | _ = "#{{k,v for k,v in pairs tb}}" |
| 73 | _ = "#{for k,v in pairs tb do k,v}" | 73 | _ = "#{for k,v in pairs tb do {k,v}}" |
| 74 | _ = "#{while a do true}" | 74 | _ = "#{while a do true}" |
| 75 | _ = "#{with a | 75 | _ = "#{with a |
| 76 | .b = 123}" | 76 | .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 | |||
| 70 | 70 | ||
| 71 | do | 71 | do |
| 72 | import "m" as {a#: b} | 72 | import "m" as {a#: b} |
| 73 | import "m" as {e: f, a#: b} | 73 | import "m" as {e: f, a#: c} |
| 74 | import "m" as {c: d} | 74 | import "m" as {c: d} |
| 75 | import "m" as {g, {h#: i}} | 75 | import "m" as {g, {h#: i}} |
| 76 | 76 | ||
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 | |||
| 279 | 279 | ||
| 280 | macro skip = -> "while false do break" | 280 | macro skip = -> "while false do break" |
| 281 | 281 | ||
| 282 | _ = -> | 282 | _1 = -> |
| 283 | print 1 | 283 | print 1 |
| 284 | <- $skip | 284 | <- $skip |
| 285 | print 2 | 285 | 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 | |||
| 23 | = 123, a.b.c, func! | 23 | = 123, a.b.c, func! |
| 24 | 24 | ||
| 25 | x.abc, a.b.# = 123, {} | 25 | x.abc, a.b.# = 123, {} |
| 26 | func!.# = mt, extra | 26 | func!.# = mt --, extra |
| 27 | a, b.c.#, d, e = 1, mt, "abc" | 27 | a, b.c.#, d, e = 1, mt, "abc" |
| 28 | 28 | ||
| 29 | is_same = a.#.__index == a.index# | 29 | 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 | |||
| 71 | _ = something[ [======[hey]======] ] * 2 | 71 | _ = something[ [======[hey]======] ] * 2 |
| 72 | 72 | ||
| 73 | 73 | ||
| 74 | _ = something'else', 2 | 74 | _, _ = something'else', 2 |
| 75 | _ = something"else", 2 | 75 | _, _ = something"else", 2 |
| 76 | _ = something[[else]], 2 | 76 | _, _ = something[[else]], 2 |
| 77 | _ = something[ [[else]] ], 2 | 77 | _, _ = something[ [[else]] ], 2 |
| 78 | 78 | ||
| 79 | something 'else', 2 | 79 | something 'else', 2 |
| 80 | something "else", 2 | 80 | something "else", 2 |
| @@ -157,7 +157,7 @@ y = #"hello" | |||
| 157 | 157 | ||
| 158 | x = #{#{},#{1},#{1,2}} | 158 | x = #{#{},#{1},#{1,2}} |
| 159 | 159 | ||
| 160 | _ = hello, world | 160 | _, _ = hello, world |
| 161 | 161 | ||
| 162 | something\hello(what) a,b | 162 | something\hello(what) a,b |
| 163 | something\hello what | 163 | 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" } | |||
| 152 | please "hello": "world" | 152 | please "hello": "world" |
| 153 | k = "hello": "world", "one": "zone" | 153 | k = "hello": "world", "one": "zone" |
| 154 | 154 | ||
| 155 | f = "one", "two": three, "four" | 155 | f1, f2, f3 = "one", "two": three, "four" |
| 156 | f = "two": three, "four" | 156 | f1, f2 = "two": three, "four" |
| 157 | f = { "one", "two": three, "four" } | 157 | f1 = { "one", "two": three, "four" } |
| 158 | 158 | ||
| 159 | 159 | ||
| 160 | j = "one", "two": three, "four": five, 6, 7 | 160 | j1, j2, j3, j4 = "one", "two": three, "four": five, 6, 7 |
| 161 | 161 | ||
| 162 | heroine = | 162 | heroine = |
| 163 | name: "Christina" | 163 | 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 | |||
| 45 | -- | 45 | -- |
| 46 | 46 | ||
| 47 | do | 47 | do |
| 48 | with a, b -- b is lost | 48 | with a -- only one value allowed |
| 49 | print .world | 49 | print .world |
| 50 | 50 | ||
| 51 | mod = with _M = {} | 51 | 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 | |||
| 26 | local _obj_0 = yeah | 26 | local _obj_0 = yeah |
| 27 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0.c, _obj_0.d | 27 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0.c, _obj_0.d |
| 28 | end | 28 | end |
| 29 | local _ = two | 29 | b = two |
| 30 | a = one[1] | 30 | a = one[1] |
| 31 | c = nil | 31 | c = nil |
| 32 | b = one[1] | 32 | b = one[1] |
| @@ -56,7 +56,10 @@ do | |||
| 56 | end | 56 | end |
| 57 | do | 57 | do |
| 58 | a = tbl | 58 | a = tbl |
| 59 | b, c = _.b, _.c | 59 | do |
| 60 | local _obj_0 = _ | ||
| 61 | b, c = _obj_0.b, _obj_0.c | ||
| 62 | end | ||
| 60 | end | 63 | end |
| 61 | do | 64 | do |
| 62 | b = _ | 65 | b = _ |
| @@ -386,3 +389,21 @@ do | |||
| 386 | a.c = _tmp_1 | 389 | a.c = _tmp_1 |
| 387 | end | 390 | end |
| 388 | end | 391 | end |
| 392 | do | ||
| 393 | local width, height | ||
| 394 | do | ||
| 395 | local _obj_0 = View.size | ||
| 396 | width, height = _obj_0.width, _obj_0.height | ||
| 397 | end | ||
| 398 | local x, y | ||
| 399 | do | ||
| 400 | local _obj_0 = point | ||
| 401 | x, y = _obj_0.x, _obj_0.y | ||
| 402 | if x == nil then | ||
| 403 | x = 0.0 | ||
| 404 | end | ||
| 405 | if y == nil then | ||
| 406 | y = 0.0 | ||
| 407 | end | ||
| 408 | end | ||
| 409 | 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() | |||
| 134 | local _accum_0 = { } | 134 | local _accum_0 = { } |
| 135 | local _len_0 = 1 | 135 | local _len_0 = 1 |
| 136 | for k, v in pairs(tb) do | 136 | for k, v in pairs(tb) do |
| 137 | _accum_0[_len_0] = k, v | 137 | _accum_0[_len_0] = { |
| 138 | k, | ||
| 139 | v | ||
| 140 | } | ||
| 138 | _len_0 = _len_0 + 1 | 141 | _len_0 = _len_0 + 1 |
| 139 | end | 142 | end |
| 140 | return _accum_0 | 143 | return _accum_0 |
| @@ -232,7 +235,10 @@ _ = tostring((function() | |||
| 232 | local _accum_0 = { } | 235 | local _accum_0 = { } |
| 233 | local _len_0 = 1 | 236 | local _len_0 = 1 |
| 234 | for k, v in pairs(tb) do | 237 | for k, v in pairs(tb) do |
| 235 | _accum_0[_len_0] = k, v | 238 | _accum_0[_len_0] = { |
| 239 | k, | ||
| 240 | v | ||
| 241 | } | ||
| 236 | _len_0 = _len_0 + 1 | 242 | _len_0 = _len_0 + 1 |
| 237 | end | 243 | end |
| 238 | return _accum_0 | 244 | 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 | |||
| 94 | b = getmetatable(require("m")).__a | 94 | b = getmetatable(require("m")).__a |
| 95 | local _obj_0 = require("m") | 95 | local _obj_0 = require("m") |
| 96 | local f = _obj_0.e | 96 | local f = _obj_0.e |
| 97 | b = getmetatable(_obj_0).__a | 97 | c = getmetatable(_obj_0).__a |
| 98 | local d = require("m").c | 98 | local d = require("m").c |
| 99 | local g, i | 99 | local g, i |
| 100 | do | 100 | 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)); | |||
| 282 | do | 282 | do |
| 283 | print(1) | 283 | print(1) |
| 284 | end | 284 | end |
| 285 | _ = function() | 285 | local _1 |
| 286 | _1 = function() | ||
| 286 | print(1) | 287 | print(1) |
| 287 | local _accum_0 = { } | 288 | local _accum_0 = { } |
| 288 | local _len_0 = 1 | 289 | 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 | |||
| 65 | setmetatable(a.b, { }) | 65 | setmetatable(a.b, { }) |
| 66 | x.abc = 123 | 66 | x.abc = 123 |
| 67 | setmetatable(func(), mt) | 67 | setmetatable(func(), mt) |
| 68 | local _ = extra | ||
| 69 | setmetatable(b.c, mt) | 68 | setmetatable(b.c, mt) |
| 70 | a, d, e = 1, "abc" | 69 | a, d, e = 1, "abc" |
| 71 | local is_same = getmetatable(a).__index == getmetatable(a).__index | 70 | 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") | |||
| 56 | _ = something([[hey]]) * 2 | 56 | _ = something([[hey]]) * 2 |
| 57 | _ = something([======[hey]======]) * 2 | 57 | _ = something([======[hey]======]) * 2 |
| 58 | _ = something[ [======[hey]======]] * 2 | 58 | _ = something[ [======[hey]======]] * 2 |
| 59 | _ = something('else'), 2 | 59 | _, _ = something('else'), 2 |
| 60 | _ = something("else"), 2 | 60 | _, _ = something("else"), 2 |
| 61 | _ = something([[else]]), 2 | 61 | _, _ = something([[else]]), 2 |
| 62 | _ = something[ [[else]]], 2 | 62 | _, _ = something[ [[else]]], 2 |
| 63 | something('else', 2) | 63 | something('else', 2) |
| 64 | something("else", 2) | 64 | something("else", 2) |
| 65 | something([[else]], 2) | 65 | something([[else]], 2) |
| @@ -165,7 +165,7 @@ x = #{ | |||
| 165 | 2 | 165 | 2 |
| 166 | } | 166 | } |
| 167 | } | 167 | } |
| 168 | _ = hello, world | 168 | _, _ = hello, world |
| 169 | something:hello(what)(a, b) | 169 | something:hello(what)(a, b) |
| 170 | something:hello(what) | 170 | something:hello(what) |
| 171 | something.hello:world(a, b) | 171 | 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 = { | |||
| 187 | ["hello"] = "world", | 187 | ["hello"] = "world", |
| 188 | ["one"] = "zone" | 188 | ["one"] = "zone" |
| 189 | } | 189 | } |
| 190 | local f = "one", { | 190 | local f1, f2, f3 = "one", { |
| 191 | ["two"] = three | 191 | ["two"] = three |
| 192 | }, "four" | 192 | }, "four" |
| 193 | f = { | 193 | f1, f2 = { |
| 194 | ["two"] = three | 194 | ["two"] = three |
| 195 | }, "four" | 195 | }, "four" |
| 196 | f = { | 196 | f1 = { |
| 197 | "one", | 197 | "one", |
| 198 | ["two"] = three, | 198 | ["two"] = three, |
| 199 | "four" | 199 | "four" |
| 200 | } | 200 | } |
| 201 | local j = "one", { | 201 | local j1, j2, j3, j4 = "one", { |
| 202 | ["two"] = three, | 202 | ["two"] = three, |
| 203 | ["four"] = five | 203 | ["four"] = five |
| 204 | }, 6, 7 | 204 | }, 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 | |||
| 54 | end | 54 | end |
| 55 | do | 55 | do |
| 56 | do | 56 | do |
| 57 | local _with_0 = a, b | 57 | local _with_0 = a |
| 58 | print(_with_0.world) | 58 | print(_with_0.world) |
| 59 | end | 59 | end |
| 60 | local mod | 60 | local mod |
