Skip to content

Commit

Permalink
update Yuescript. [skip CI]
Browse files Browse the repository at this point in the history
remove one more redundant 'do' block from destructuring.
  • Loading branch information
pigpigyyy committed Mar 25, 2024
1 parent 9d3ee94 commit 8d9c242
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
6 changes: 2 additions & 4 deletions Assets/Script/Dev/Entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,8 @@ setupEventHandlers = function() -- 422
config.fullScreen = fullScreen and 1 or 0 -- 439
end) -- 438
_with_0:gslot("AppMoved", function() -- 440
do -- 441
local _obj_0 = App.winPosition -- 441
config.winX, config.winY = _obj_0.x, _obj_0.y -- 441
end -- 441
local _obj_0 = App.winPosition -- 441
config.winX, config.winY = _obj_0.x, _obj_0.y -- 441
end) -- 440
end -- 441
return _with_0 -- 423
Expand Down
28 changes: 17 additions & 11 deletions Source/3rdParty/yuescript/yue_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ class YueCompilerImpl {
if (!destruct.inlineAssignment && destruct.items.size() == 1) {
auto& pair = destruct.items.front();
if (pair.targetVar.empty() && pair.defVal) {
extraScope = true;
if (needScope) extraScope = true;
auto objVar = getUnusedName("_tmp_"sv);
auto objExp = toAst<Exp_t>(objVar, pair.target);
leftPairs.push_back({pair.target, objExp.get()});
Expand Down Expand Up @@ -2221,8 +2221,10 @@ class YueCompilerImpl {
if (isLocalValue) {
objVar = destruct.valueVar;
} else {
temp.push_back(indent() + "do"s + nll(x));
pushScope();
if (needScope) {
temp.push_back(indent() + "do"s + nll(x));
pushScope();
}
objVar = getUnusedName("_obj_"sv);
auto newAssignment = assignmentFrom(toAst<Exp_t>(objVar, x), destruct.value, x);
transformAssignment(newAssignment, temp);
Expand All @@ -2234,9 +2236,11 @@ class YueCompilerImpl {
auto newAssignment = assignmentFrom(pair.target, valueExp, x);
transformAssignment(newAssignment, temp, optionalDestruct);
if (!isLocalValue) {
popScope();
_buf << indent() << "end"sv << nlr(x);
temp.push_back(clearBuf());
if (needScope) {
popScope();
_buf << indent() << "end"sv << nlr(x);
temp.push_back(clearBuf());
}
}
} else {
str_list defs;
Expand All @@ -2249,7 +2253,7 @@ class YueCompilerImpl {
defs.push_back(item.targetVar);
}
} else if (item.defVal) {
extraScope = true;
if (needScope) extraScope = true;
auto objVar = getUnusedName("_tmp_"sv);
addToScope(objVar);
auto objExp = toAst<Exp_t>(objVar, item.target);
Expand Down Expand Up @@ -2285,9 +2289,11 @@ class YueCompilerImpl {
}
temp.push_back(indent() + "local "s + join(defs, ", "sv) + nll(x));
}
extraScope = true;
temp.push_back(indent() + "do"s + nll(x));
pushScope();
if (needScope) {
extraScope = true;
temp.push_back(indent() + "do"s + nll(x));
pushScope();
}
auto valVar = getUnusedName("_obj_"sv);
auto targetVar = toAst<Exp_t>(valVar, destruct.value);
auto newAssignment = assignmentFrom(targetVar, destruct.value, destruct.value);
Expand All @@ -2298,7 +2304,7 @@ class YueCompilerImpl {
}
}
if (destruct.inlineAssignment) {
if (!extraScope) {
if (needScope && !extraScope) {
extraScope = true;
temp.push_back(indent() + "do"s + nll(x));
pushScope();
Expand Down

0 comments on commit 8d9c242

Please sign in to comment.