From 3eedd027bddc1ad9099d647e83ae4a83589db191 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 9 Mar 2021 22:36:59 +0800 Subject: fix an issue with local statement. --- spec/inputs/local.yue | 4 ++++ src/yuescript/yue_compiler.cpp | 3 ++- 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 -- this generates a nil value in the body for a in *{} do _ = a +do + local * + x = a or b + 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) { return std::string(sv); } -const std::string_view version = "0.7.2"sv; +const std::string_view version = "0.7.3"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -2380,6 +2380,7 @@ private: auto exp = ast_cast(assign->values.objects().front()); BREAK_IF(!exp); auto value = singleValueFrom(exp); + BREAK_IF(!value); classDecl = value->getByPath(); BLOCK_END } 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) return { } end str = str .. delim - local _accum_0 = { } - local _len_0 = 1 + local tokens = { } for m in str:gmatch("(.-)" .. delim) do - _accum_0[_len_0] = m - _len_0 = _len_0 + 1 + table.insert(tokens, m) end - return _accum_0 + return tokens end get_options = function(...) local count = select("#", ...) @@ -74,29 +72,14 @@ get_options = function(...) end create_yuepath = function(package_path) local extension = yue.options.extension - local yuepaths - do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = split(package_path, ";") - for _index_0 = 1, #_list_0 do - local path = _list_0[_index_0] - local _continue_0 = false - repeat - local prefix = path:match("^(.-)%.lua$") - if not prefix then - _continue_0 = true - break - end - _accum_0[_len_0] = prefix .. "." .. extension - _len_0 = _len_0 + 1 - _continue_0 = true - until true - if not _continue_0 then - break - end + local yuepaths = { } + local tokens = split(package_path, ";") + for i = 1, #tokens do + local path = tokens[i] + local prefix = path:match("^(.-)%.lua$") + if prefix then + table.insert(yuepaths, prefix .. "." .. extension) end - yuepaths = _accum_0 end return concat(yuepaths, ";") end @@ -178,8 +161,8 @@ insert_loader = function(pos) package.yuepath = create_yuepath(package.path) end local loaders = package.loaders or package.searchers - for _index_0 = 1, #loaders do - local loader = loaders[_index_0] + for i = 1, #loaders do + local loader = loaders[i] if loader == yue_loader then return false end @@ -219,12 +202,9 @@ setmetatable(yue, { end local stp = rawget(yue, "stp") if not stp then - do - local _with_0 = yue.load_stacktraceplus() - _with_0.dump_locals = false - _with_0.simplified = true - stp = _with_0 - end + stp = yue.load_stacktraceplus() + stp.dump_locals = false + stp.simplified = true rawset(yue, "stp", stp) rawset(yue, "load_stacktraceplus", nil) end -- cgit v1.2.3-55-g6feb