diff options
Diffstat (limited to '')
| -rw-r--r-- | spec/inputs/nil_coalesing.yue | 5 | ||||
| -rw-r--r-- | spec/outputs/nil_coalesing.lua | 25 | ||||
| -rwxr-xr-x | src/yuescript/yue_compiler.cpp | 14 |
3 files changed, 38 insertions, 6 deletions
diff --git a/spec/inputs/nil_coalesing.yue b/spec/inputs/nil_coalesing.yue index facd64c..76915c7 100644 --- a/spec/inputs/nil_coalesing.yue +++ b/spec/inputs/nil_coalesing.yue | |||
| @@ -39,5 +39,10 @@ do | |||
| 39 | do | 39 | do |
| 40 | a = 1 ?? 2 ?? 3 | 40 | a = 1 ?? 2 ?? 3 |
| 41 | 41 | ||
| 42 | do | ||
| 43 | a.b.c ??= 1 | ||
| 44 | a = b.x ?? c.x ?? d.x | ||
| 45 | a.c ??= 1 | ||
| 46 | |||
| 42 | nil | 47 | nil |
| 43 | 48 | ||
diff --git a/spec/outputs/nil_coalesing.lua b/spec/outputs/nil_coalesing.lua index b434671..e1547df 100644 --- a/spec/outputs/nil_coalesing.lua +++ b/spec/outputs/nil_coalesing.lua | |||
| @@ -153,4 +153,29 @@ do | |||
| 153 | end | 153 | end |
| 154 | end | 154 | end |
| 155 | end | 155 | end |
| 156 | do | ||
| 157 | local _obj_0 = a.b | ||
| 158 | if _obj_0.c == nil then | ||
| 159 | _obj_0.c = 1 | ||
| 160 | end | ||
| 161 | local a | ||
| 162 | do | ||
| 163 | local _exp_0 = b.x | ||
| 164 | if _exp_0 ~= nil then | ||
| 165 | a = _exp_0 | ||
| 166 | else | ||
| 167 | do | ||
| 168 | local _exp_1 = c.x | ||
| 169 | if _exp_1 ~= nil then | ||
| 170 | a = _exp_1 | ||
| 171 | else | ||
| 172 | a = d.x | ||
| 173 | end | ||
| 174 | end | ||
| 175 | end | ||
| 176 | end | ||
| 177 | if a.c == nil then | ||
| 178 | a.c = 1 | ||
| 179 | end | ||
| 180 | end | ||
| 156 | return nil | 181 | return nil |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 852a0f4..db225f6 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -60,7 +60,7 @@ using namespace parserlib; | |||
| 60 | 60 | ||
| 61 | typedef std::list<std::string> str_list; | 61 | typedef std::list<std::string> str_list; |
| 62 | 62 | ||
| 63 | const std::string_view version = "0.9.7"sv; | 63 | const std::string_view version = "0.9.8"sv; |
| 64 | const std::string_view extension = "yue"sv; | 64 | const std::string_view extension = "yue"sv; |
| 65 | 65 | ||
| 66 | class YueCompilerImpl { | 66 | class YueCompilerImpl { |
| @@ -2081,8 +2081,9 @@ private: | |||
| 2081 | rightExp->pipeExprs.dup(leftExp->pipeExprs); | 2081 | rightExp->pipeExprs.dup(leftExp->pipeExprs); |
| 2082 | rightExp->opValues.dup(leftExp->opValues); | 2082 | rightExp->opValues.dup(leftExp->opValues); |
| 2083 | rightExp->nilCoalesed.set(update->value); | 2083 | rightExp->nilCoalesed.set(update->value); |
| 2084 | transformNilCoalesedExp(rightExp, out, ExpUsage::Assignment, assignment->expList, true); | 2084 | transformNilCoalesedExp(rightExp, temp, ExpUsage::Assignment, assignment->expList, true); |
| 2085 | if (!defs.empty()) out.back().insert(0, defs + nll(x)); | 2085 | if (!defs.empty()) temp.back().insert(0, defs + nll(x)); |
| 2086 | out.push_back(join(temp)); | ||
| 2086 | return; | 2087 | return; |
| 2087 | } | 2088 | } |
| 2088 | auto defs = getPredefine(assignment); | 2089 | auto defs = getPredefine(assignment); |
| @@ -2495,7 +2496,7 @@ private: | |||
| 2495 | assignment->expList.set(expList); | 2496 | assignment->expList.set(expList); |
| 2496 | assignment->action.set(assign); | 2497 | assignment->action.set(assign); |
| 2497 | transformAssignment(assignment, temp); | 2498 | transformAssignment(assignment, temp); |
| 2498 | return true; | 2499 | return forAssignment; |
| 2499 | } | 2500 | } |
| 2500 | return false; | 2501 | return false; |
| 2501 | }; | 2502 | }; |
| @@ -2552,8 +2553,9 @@ private: | |||
| 2552 | assign->values.push_back(exp->nilCoalesed); | 2553 | assign->values.push_back(exp->nilCoalesed); |
| 2553 | auto defs = getPredefine(assignment); | 2554 | auto defs = getPredefine(assignment); |
| 2554 | if (!defs.empty()) temp.push_back(defs + nll(x)); | 2555 | if (!defs.empty()) temp.push_back(defs + nll(x)); |
| 2555 | prepareValue(); | 2556 | transformExp(left, temp, ExpUsage::Closure); |
| 2556 | _buf << indent() << "if "sv << objVar << " == nil then"sv << nll(x); | 2557 | _buf << indent() << "if "sv << temp.back() << " == nil then"sv << nll(x); |
| 2558 | temp.pop_back(); | ||
| 2557 | temp.push_back(clearBuf()); | 2559 | temp.push_back(clearBuf()); |
| 2558 | } | 2560 | } |
| 2559 | pushScope(); | 2561 | pushScope(); |
