diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-15 17:54:59 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-15 17:54:59 +0800 |
| commit | afb046316a15a2c3702b1f056456b58e9356e693 (patch) | |
| tree | c4820522be5c92948553673dad42c1734d30689f /spec | |
| parent | 873aced12cf65e633c95358f89a1d5ec37b81d00 (diff) | |
| download | yuescript-afb046316a15a2c3702b1f056456b58e9356e693.tar.gz yuescript-afb046316a15a2c3702b1f056456b58e9356e693.tar.bz2 yuescript-afb046316a15a2c3702b1f056456b58e9356e693.zip | |
Added const attributes.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/outputs/5.1/import_global.lua | 120 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc.lua | 60 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 60 | ||||
| -rw-r--r-- | spec/outputs/import_global.lua | 46 |
4 files changed, 219 insertions, 67 deletions
diff --git a/spec/outputs/5.1/import_global.lua b/spec/outputs/5.1/import_global.lua new file mode 100644 index 0000000..c748c78 --- /dev/null +++ b/spec/outputs/5.1/import_global.lua | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | do | ||
| 2 | local print = print | ||
| 3 | local math = math | ||
| 4 | print("hello") | ||
| 5 | math.random(10) | ||
| 6 | end | ||
| 7 | do | ||
| 8 | local print = print | ||
| 9 | local value = 1 | ||
| 10 | value = value + 2 | ||
| 11 | print(value) | ||
| 12 | end | ||
| 13 | do | ||
| 14 | local print | ||
| 15 | print = function(msg) | ||
| 16 | return msg | ||
| 17 | end | ||
| 18 | do | ||
| 19 | local math = math | ||
| 20 | print("local") | ||
| 21 | math.random(1) | ||
| 22 | end | ||
| 23 | end | ||
| 24 | do | ||
| 25 | local print = print | ||
| 26 | local tostring | ||
| 27 | tostring = function(v) | ||
| 28 | return "local" | ||
| 29 | end | ||
| 30 | tostring("value") | ||
| 31 | print(tostring(123)) | ||
| 32 | end | ||
| 33 | do | ||
| 34 | local func | ||
| 35 | func = function(x, y) | ||
| 36 | local type = type | ||
| 37 | local tostring = tostring | ||
| 38 | local print = print | ||
| 39 | return type(x, tostring(y, print)) | ||
| 40 | end | ||
| 41 | func(1, 2) | ||
| 42 | end | ||
| 43 | do | ||
| 44 | local xpcall = xpcall | ||
| 45 | local func = func | ||
| 46 | local world = world | ||
| 47 | local tostring = tostring | ||
| 48 | local print = print | ||
| 49 | xpcall(function() | ||
| 50 | return func("hello " .. tostring(world)) | ||
| 51 | end, function(err) | ||
| 52 | return print(err) | ||
| 53 | end) | ||
| 54 | end | ||
| 55 | do | ||
| 56 | local print = print | ||
| 57 | print(FLAG) | ||
| 58 | FLAG = 123 | ||
| 59 | end | ||
| 60 | do | ||
| 61 | local print = print | ||
| 62 | Foo = 10 | ||
| 63 | print(Foo) | ||
| 64 | Foo = Foo + 2 | ||
| 65 | end | ||
| 66 | do | ||
| 67 | local print = print | ||
| 68 | Bar = 1 | ||
| 69 | Baz = 2 | ||
| 70 | print(Bar, Baz) | ||
| 71 | end | ||
| 72 | do | ||
| 73 | local y = y | ||
| 74 | x = 3434 | ||
| 75 | if y then | ||
| 76 | x = 10 | ||
| 77 | end | ||
| 78 | end | ||
| 79 | do | ||
| 80 | local lowercase = lowercase | ||
| 81 | local tostring = tostring | ||
| 82 | local Uppercase = Uppercase | ||
| 83 | local foobar = "all " .. tostring(lowercase) | ||
| 84 | FooBar = "pascal case" | ||
| 85 | FOOBAR = "all " .. tostring(Uppercase) | ||
| 86 | end | ||
| 87 | do | ||
| 88 | local setmetatable = setmetatable | ||
| 89 | local print = print | ||
| 90 | do | ||
| 91 | local _class_0 | ||
| 92 | local _base_0 = { } | ||
| 93 | if _base_0.__index == nil then | ||
| 94 | _base_0.__index = _base_0 | ||
| 95 | end | ||
| 96 | _class_0 = setmetatable({ | ||
| 97 | __init = function() end, | ||
| 98 | __base = _base_0, | ||
| 99 | __name = "A" | ||
| 100 | }, { | ||
| 101 | __index = _base_0, | ||
| 102 | __call = function(cls, ...) | ||
| 103 | local _self_0 = setmetatable({ }, _base_0) | ||
| 104 | cls.__init(_self_0, ...) | ||
| 105 | return _self_0 | ||
| 106 | end | ||
| 107 | }) | ||
| 108 | _base_0.__class = _class_0 | ||
| 109 | A = _class_0 | ||
| 110 | end | ||
| 111 | Flag = 1 | ||
| 112 | const, x, y = "const", 1, 2 | ||
| 113 | print(math, table) | ||
| 114 | end | ||
| 115 | do | ||
| 116 | local X = X | ||
| 117 | X:func(1, 2, 3) | ||
| 118 | X.tag = "abc" | ||
| 119 | return X | ||
| 120 | end | ||
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index 84dfc4e..1df7cef 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
| @@ -409,17 +409,6 @@ local tb = { | |||
| 409 | } | 409 | } |
| 410 | } | 410 | } |
| 411 | do | 411 | do |
| 412 | local print = print | ||
| 413 | local math = math | ||
| 414 | print("hello") | ||
| 415 | math.random(3) | ||
| 416 | end | ||
| 417 | do | ||
| 418 | local print = print | ||
| 419 | print(FLAG) | ||
| 420 | FLAG = 123 | ||
| 421 | end | ||
| 422 | do | ||
| 423 | local insert, concat = table.insert, table.concat | 412 | local insert, concat = table.insert, table.concat |
| 424 | local C, Ct, Cmt | 413 | local C, Ct, Cmt |
| 425 | do | 414 | do |
| @@ -452,6 +441,25 @@ do | |||
| 452 | local _obj_0 = require("export") | 441 | local _obj_0 = require("export") |
| 453 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | 442 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] |
| 454 | end | 443 | end |
| 444 | do | ||
| 445 | local tostring <const> = tostring | ||
| 446 | local concat <const> = table.concat | ||
| 447 | print(concat({ | ||
| 448 | "a", | ||
| 449 | tostring(1) | ||
| 450 | })) | ||
| 451 | end | ||
| 452 | do | ||
| 453 | local print <const> = print | ||
| 454 | local math <const> = math | ||
| 455 | print("hello") | ||
| 456 | math.random(3) | ||
| 457 | end | ||
| 458 | do | ||
| 459 | local print <const> = print | ||
| 460 | print(FLAG) | ||
| 461 | FLAG = 123 | ||
| 462 | end | ||
| 455 | local _module_0 = { } | 463 | local _module_0 = { } |
| 456 | local a, b, c = 1, 2, 3 | 464 | local a, b, c = 1, 2, 3 |
| 457 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | 465 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c |
| @@ -2928,17 +2936,6 @@ local tb = { | |||
| 2928 | } | 2936 | } |
| 2929 | } | 2937 | } |
| 2930 | do | 2938 | do |
| 2931 | local print = print | ||
| 2932 | local math = math | ||
| 2933 | print("hello") | ||
| 2934 | math.random(3) | ||
| 2935 | end | ||
| 2936 | do | ||
| 2937 | local print = print | ||
| 2938 | print(FLAG) | ||
| 2939 | FLAG = 123 | ||
| 2940 | end | ||
| 2941 | do | ||
| 2942 | local insert, concat = table.insert, table.concat | 2939 | local insert, concat = table.insert, table.concat |
| 2943 | local C, Ct, Cmt | 2940 | local C, Ct, Cmt |
| 2944 | do | 2941 | do |
| @@ -2971,6 +2968,25 @@ do | |||
| 2971 | local _obj_0 = require("export") | 2968 | local _obj_0 = require("export") |
| 2972 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | 2969 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] |
| 2973 | end | 2970 | end |
| 2971 | do | ||
| 2972 | local tostring <const> = tostring | ||
| 2973 | local concat <const> = table.concat | ||
| 2974 | print(concat({ | ||
| 2975 | "a", | ||
| 2976 | tostring(1) | ||
| 2977 | })) | ||
| 2978 | end | ||
| 2979 | do | ||
| 2980 | local print <const> = print | ||
| 2981 | local math <const> = math | ||
| 2982 | print("hello") | ||
| 2983 | math.random(3) | ||
| 2984 | end | ||
| 2985 | do | ||
| 2986 | local print <const> = print | ||
| 2987 | print(FLAG) | ||
| 2988 | FLAG = 123 | ||
| 2989 | end | ||
| 2974 | local _module_0 = { } | 2990 | local _module_0 = { } |
| 2975 | local a, b, c = 1, 2, 3 | 2991 | local a, b, c = 1, 2, 3 |
| 2976 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | 2992 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index d4e8b6a..b407895 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -409,17 +409,6 @@ local tb = { | |||
| 409 | } | 409 | } |
| 410 | } | 410 | } |
| 411 | do | 411 | do |
| 412 | local print = print | ||
| 413 | local math = math | ||
| 414 | print("hello") | ||
| 415 | math.random(3) | ||
| 416 | end | ||
| 417 | do | ||
| 418 | local print = print | ||
| 419 | print(FLAG) | ||
| 420 | FLAG = 123 | ||
| 421 | end | ||
| 422 | do | ||
| 423 | local insert, concat = table.insert, table.concat | 412 | local insert, concat = table.insert, table.concat |
| 424 | local C, Ct, Cmt | 413 | local C, Ct, Cmt |
| 425 | do | 414 | do |
| @@ -452,6 +441,25 @@ do | |||
| 452 | local _obj_0 = require("export") | 441 | local _obj_0 = require("export") |
| 453 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | 442 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] |
| 454 | end | 443 | end |
| 444 | do | ||
| 445 | local tostring <const> = tostring | ||
| 446 | local concat <const> = table.concat | ||
| 447 | print(concat({ | ||
| 448 | "a", | ||
| 449 | tostring(1) | ||
| 450 | })) | ||
| 451 | end | ||
| 452 | do | ||
| 453 | local print <const> = print | ||
| 454 | local math <const> = math | ||
| 455 | print("hello") | ||
| 456 | math.random(3) | ||
| 457 | end | ||
| 458 | do | ||
| 459 | local print <const> = print | ||
| 460 | print(FLAG) | ||
| 461 | FLAG = 123 | ||
| 462 | end | ||
| 455 | local _module_0 = { } | 463 | local _module_0 = { } |
| 456 | local a, b, c = 1, 2, 3 | 464 | local a, b, c = 1, 2, 3 |
| 457 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | 465 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c |
| @@ -2922,17 +2930,6 @@ local tb = { | |||
| 2922 | } | 2930 | } |
| 2923 | } | 2931 | } |
| 2924 | do | 2932 | do |
| 2925 | local print = print | ||
| 2926 | local math = math | ||
| 2927 | print("hello") | ||
| 2928 | math.random(3) | ||
| 2929 | end | ||
| 2930 | do | ||
| 2931 | local print = print | ||
| 2932 | print(FLAG) | ||
| 2933 | FLAG = 123 | ||
| 2934 | end | ||
| 2935 | do | ||
| 2936 | local insert, concat = table.insert, table.concat | 2933 | local insert, concat = table.insert, table.concat |
| 2937 | local C, Ct, Cmt | 2934 | local C, Ct, Cmt |
| 2938 | do | 2935 | do |
| @@ -2965,6 +2962,25 @@ do | |||
| 2965 | local _obj_0 = require("export") | 2962 | local _obj_0 = require("export") |
| 2966 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] | 2963 | one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] |
| 2967 | end | 2964 | end |
| 2965 | do | ||
| 2966 | local tostring <const> = tostring | ||
| 2967 | local concat <const> = table.concat | ||
| 2968 | print(concat({ | ||
| 2969 | "a", | ||
| 2970 | tostring(1) | ||
| 2971 | })) | ||
| 2972 | end | ||
| 2973 | do | ||
| 2974 | local print <const> = print | ||
| 2975 | local math <const> = math | ||
| 2976 | print("hello") | ||
| 2977 | math.random(3) | ||
| 2978 | end | ||
| 2979 | do | ||
| 2980 | local print <const> = print | ||
| 2981 | print(FLAG) | ||
| 2982 | FLAG = 123 | ||
| 2983 | end | ||
| 2968 | local _module_0 = { } | 2984 | local _module_0 = { } |
| 2969 | local a, b, c = 1, 2, 3 | 2985 | local a, b, c = 1, 2, 3 |
| 2970 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c | 2986 | _module_0["a"], _module_0["b"], _module_0["c"] = a, b, c |
diff --git a/spec/outputs/import_global.lua b/spec/outputs/import_global.lua index c748c78..f76b4fe 100644 --- a/spec/outputs/import_global.lua +++ b/spec/outputs/import_global.lua | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | do | 1 | do |
| 2 | local print = print | 2 | local print <const> = print |
| 3 | local math = math | 3 | local math <const> = math |
| 4 | print("hello") | 4 | print("hello") |
| 5 | math.random(10) | 5 | math.random(10) |
| 6 | end | 6 | end |
| 7 | do | 7 | do |
| 8 | local print = print | 8 | local print <const> = print |
| 9 | local value = 1 | 9 | local value = 1 |
| 10 | value = value + 2 | 10 | value = value + 2 |
| 11 | print(value) | 11 | print(value) |
| @@ -16,13 +16,13 @@ do | |||
| 16 | return msg | 16 | return msg |
| 17 | end | 17 | end |
| 18 | do | 18 | do |
| 19 | local math = math | 19 | local math <const> = math |
| 20 | print("local") | 20 | print("local") |
| 21 | math.random(1) | 21 | math.random(1) |
| 22 | end | 22 | end |
| 23 | end | 23 | end |
| 24 | do | 24 | do |
| 25 | local print = print | 25 | local print <const> = print |
| 26 | local tostring | 26 | local tostring |
| 27 | tostring = function(v) | 27 | tostring = function(v) |
| 28 | return "local" | 28 | return "local" |
| @@ -33,19 +33,19 @@ end | |||
| 33 | do | 33 | do |
| 34 | local func | 34 | local func |
| 35 | func = function(x, y) | 35 | func = function(x, y) |
| 36 | local type = type | 36 | local type <const> = type |
| 37 | local tostring = tostring | 37 | local tostring <const> = tostring |
| 38 | local print = print | 38 | local print <const> = print |
| 39 | return type(x, tostring(y, print)) | 39 | return type(x, tostring(y, print)) |
| 40 | end | 40 | end |
| 41 | func(1, 2) | 41 | func(1, 2) |
| 42 | end | 42 | end |
| 43 | do | 43 | do |
| 44 | local xpcall = xpcall | 44 | local xpcall <const> = xpcall |
| 45 | local func = func | 45 | local func <const> = func |
| 46 | local world = world | 46 | local world <const> = world |
| 47 | local tostring = tostring | 47 | local tostring <const> = tostring |
| 48 | local print = print | 48 | local print <const> = print |
| 49 | xpcall(function() | 49 | xpcall(function() |
| 50 | return func("hello " .. tostring(world)) | 50 | return func("hello " .. tostring(world)) |
| 51 | end, function(err) | 51 | end, function(err) |
| @@ -53,40 +53,40 @@ do | |||
| 53 | end) | 53 | end) |
| 54 | end | 54 | end |
| 55 | do | 55 | do |
| 56 | local print = print | 56 | local print <const> = print |
| 57 | print(FLAG) | 57 | print(FLAG) |
| 58 | FLAG = 123 | 58 | FLAG = 123 |
| 59 | end | 59 | end |
| 60 | do | 60 | do |
| 61 | local print = print | 61 | local print <const> = print |
| 62 | Foo = 10 | 62 | Foo = 10 |
| 63 | print(Foo) | 63 | print(Foo) |
| 64 | Foo = Foo + 2 | 64 | Foo = Foo + 2 |
| 65 | end | 65 | end |
| 66 | do | 66 | do |
| 67 | local print = print | 67 | local print <const> = print |
| 68 | Bar = 1 | 68 | Bar = 1 |
| 69 | Baz = 2 | 69 | Baz = 2 |
| 70 | print(Bar, Baz) | 70 | print(Bar, Baz) |
| 71 | end | 71 | end |
| 72 | do | 72 | do |
| 73 | local y = y | 73 | local y <const> = y |
| 74 | x = 3434 | 74 | x = 3434 |
| 75 | if y then | 75 | if y then |
| 76 | x = 10 | 76 | x = 10 |
| 77 | end | 77 | end |
| 78 | end | 78 | end |
| 79 | do | 79 | do |
| 80 | local lowercase = lowercase | 80 | local lowercase <const> = lowercase |
| 81 | local tostring = tostring | 81 | local tostring <const> = tostring |
| 82 | local Uppercase = Uppercase | 82 | local Uppercase <const> = Uppercase |
| 83 | local foobar = "all " .. tostring(lowercase) | 83 | local foobar = "all " .. tostring(lowercase) |
| 84 | FooBar = "pascal case" | 84 | FooBar = "pascal case" |
| 85 | FOOBAR = "all " .. tostring(Uppercase) | 85 | FOOBAR = "all " .. tostring(Uppercase) |
| 86 | end | 86 | end |
| 87 | do | 87 | do |
| 88 | local setmetatable = setmetatable | 88 | local setmetatable <const> = setmetatable |
| 89 | local print = print | 89 | local print <const> = print |
| 90 | do | 90 | do |
| 91 | local _class_0 | 91 | local _class_0 |
| 92 | local _base_0 = { } | 92 | local _base_0 = { } |
| @@ -113,7 +113,7 @@ do | |||
| 113 | print(math, table) | 113 | print(math, table) |
| 114 | end | 114 | end |
| 115 | do | 115 | do |
| 116 | local X = X | 116 | local X <const> = X |
| 117 | X:func(1, 2, 3) | 117 | X:func(1, 2, 3) |
| 118 | X.tag = "abc" | 118 | X.tag = "abc" |
| 119 | return X | 119 | return X |
