diff options
author | Li Jin <dragon-fly@qq.com> | 2021-03-09 22:36:59 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2021-03-09 22:36:59 +0800 |
commit | 3eedd027bddc1ad9099d647e83ae4a83589db191 (patch) | |
tree | d35819801bb14d06b89e7bc74ff31caa768cebc8 | |
parent | e4f55032f27c0085c041c67a55af7ceec6d776f5 (diff) | |
download | yuescript-3eedd027bddc1ad9099d647e83ae4a83589db191.tar.gz yuescript-3eedd027bddc1ad9099d647e83ae4a83589db191.tar.bz2 yuescript-3eedd027bddc1ad9099d647e83ae4a83589db191.zip |
fix an issue with local statement.
-rw-r--r-- | spec/inputs/local.yue | 4 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 3 | ||||
-rw-r--r-- | src/yuescript/yuescript.h | 50 |
3 files changed, 21 insertions, 36 deletions
diff --git a/spec/inputs/local.yue b/spec/inputs/local.yue index 33251a9..8e04742 100644 --- a/spec/inputs/local.yue +++ b/spec/inputs/local.yue | |||
@@ -91,4 +91,8 @@ do | |||
91 | -- this generates a nil value in the body | 91 | -- this generates a nil value in the body |
92 | for a in *{} do _ = a | 92 | for a in *{} do _ = a |
93 | 93 | ||
94 | do | ||
95 | local * | ||
96 | x = a or b | ||
97 | |||
94 | g = 2323 -- test if anything leaked | 98 | g = 2323 -- test if anything leaked |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index e8d028d..f27a810 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -59,7 +59,7 @@ inline std::string s(std::string_view sv) { | |||
59 | return std::string(sv); | 59 | return std::string(sv); |
60 | } | 60 | } |
61 | 61 | ||
62 | const std::string_view version = "0.7.2"sv; | 62 | const std::string_view version = "0.7.3"sv; |
63 | const std::string_view extension = "yue"sv; | 63 | const std::string_view extension = "yue"sv; |
64 | 64 | ||
65 | class YueCompilerImpl { | 65 | class YueCompilerImpl { |
@@ -2380,6 +2380,7 @@ private: | |||
2380 | auto exp = ast_cast<Exp_t>(assign->values.objects().front()); | 2380 | auto exp = ast_cast<Exp_t>(assign->values.objects().front()); |
2381 | BREAK_IF(!exp); | 2381 | BREAK_IF(!exp); |
2382 | auto value = singleValueFrom(exp); | 2382 | auto value = singleValueFrom(exp); |
2383 | BREAK_IF(!value); | ||
2383 | classDecl = value->getByPath<SimpleValue_t, ClassDecl_t>(); | 2384 | classDecl = value->getByPath<SimpleValue_t, ClassDecl_t>(); |
2384 | BLOCK_END | 2385 | BLOCK_END |
2385 | } else if (auto expList = expListFrom(stmt)) { | 2386 | } else if (auto expList = expListFrom(stmt)) { |
diff --git a/src/yuescript/yuescript.h b/src/yuescript/yuescript.h index 433751e..cdbfd57 100644 --- a/src/yuescript/yuescript.h +++ b/src/yuescript/yuescript.h | |||
@@ -53,13 +53,11 @@ split = function(str, delim) | |||
53 | return { } | 53 | return { } |
54 | end | 54 | end |
55 | str = str .. delim | 55 | str = str .. delim |
56 | local _accum_0 = { } | 56 | local tokens = { } |
57 | local _len_0 = 1 | ||
58 | for m in str:gmatch("(.-)" .. delim) do | 57 | for m in str:gmatch("(.-)" .. delim) do |
59 | _accum_0[_len_0] = m | 58 | table.insert(tokens, m) |
60 | _len_0 = _len_0 + 1 | ||
61 | end | 59 | end |
62 | return _accum_0 | 60 | return tokens |
63 | end | 61 | end |
64 | get_options = function(...) | 62 | get_options = function(...) |
65 | local count = select("#", ...) | 63 | local count = select("#", ...) |
@@ -74,29 +72,14 @@ get_options = function(...) | |||
74 | end | 72 | end |
75 | create_yuepath = function(package_path) | 73 | create_yuepath = function(package_path) |
76 | local extension = yue.options.extension | 74 | local extension = yue.options.extension |
77 | local yuepaths | 75 | local yuepaths = { } |
78 | do | 76 | local tokens = split(package_path, ";") |
79 | local _accum_0 = { } | 77 | for i = 1, #tokens do |
80 | local _len_0 = 1 | 78 | local path = tokens[i] |
81 | local _list_0 = split(package_path, ";") | 79 | local prefix = path:match("^(.-)%.lua$") |
82 | for _index_0 = 1, #_list_0 do | 80 | if prefix then |
83 | local path = _list_0[_index_0] | 81 | table.insert(yuepaths, prefix .. "." .. extension) |
84 | local _continue_0 = false | ||
85 | repeat | ||
86 | local prefix = path:match("^(.-)%.lua$") | ||
87 | if not prefix then | ||
88 | _continue_0 = true | ||
89 | break | ||
90 | end | ||
91 | _accum_0[_len_0] = prefix .. "." .. extension | ||
92 | _len_0 = _len_0 + 1 | ||
93 | _continue_0 = true | ||
94 | until true | ||
95 | if not _continue_0 then | ||
96 | break | ||
97 | end | ||
98 | end | 82 | end |
99 | yuepaths = _accum_0 | ||
100 | end | 83 | end |
101 | return concat(yuepaths, ";") | 84 | return concat(yuepaths, ";") |
102 | end | 85 | end |
@@ -178,8 +161,8 @@ insert_loader = function(pos) | |||
178 | package.yuepath = create_yuepath(package.path) | 161 | package.yuepath = create_yuepath(package.path) |
179 | end | 162 | end |
180 | local loaders = package.loaders or package.searchers | 163 | local loaders = package.loaders or package.searchers |
181 | for _index_0 = 1, #loaders do | 164 | for i = 1, #loaders do |
182 | local loader = loaders[_index_0] | 165 | local loader = loaders[i] |
183 | if loader == yue_loader then | 166 | if loader == yue_loader then |
184 | return false | 167 | return false |
185 | end | 168 | end |
@@ -219,12 +202,9 @@ setmetatable(yue, { | |||
219 | end | 202 | end |
220 | local stp = rawget(yue, "stp") | 203 | local stp = rawget(yue, "stp") |
221 | if not stp then | 204 | if not stp then |
222 | do | 205 | stp = yue.load_stacktraceplus() |
223 | local _with_0 = yue.load_stacktraceplus() | 206 | stp.dump_locals = false |
224 | _with_0.dump_locals = false | 207 | stp.simplified = true |
225 | _with_0.simplified = true | ||
226 | stp = _with_0 | ||
227 | end | ||
228 | rawset(yue, "stp", stp) | 208 | rawset(yue, "stp", stp) |
229 | rawset(yue, "load_stacktraceplus", nil) | 209 | rawset(yue, "load_stacktraceplus", nil) |
230 | end | 210 | end |