aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yuescript/yue_compiler.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 5b8ca0d..10fd5d6 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -78,7 +78,7 @@ static std::unordered_set<std::string> Metamethods = {
78 "close"s // Lua 5.4 78 "close"s // Lua 5.4
79}; 79};
80 80
81const std::string_view version = "0.33.5"sv; 81const std::string_view version = "0.33.6"sv;
82const std::string_view extension = "yue"sv; 82const std::string_view extension = "yue"sv;
83 83
84class CompileError : public std::logic_error { 84class CompileError : public std::logic_error {
@@ -436,6 +436,7 @@ private:
436 }; 436 };
437 struct Scope; 437 struct Scope;
438 struct ImportedGlobal { 438 struct ImportedGlobal {
439 Block_t* currentBlock = nullptr;
439 std::string* globalCodeLine = nullptr; 440 std::string* globalCodeLine = nullptr;
440 std::unordered_map<std::string, VarType>* vars = nullptr; 441 std::unordered_map<std::string, VarType>* vars = nullptr;
441 std::string indent; 442 std::string indent;
@@ -5372,6 +5373,7 @@ private:
5372 auto& scope = currentScope(); 5373 auto& scope = currentScope();
5373 scope.importedGlobal = std::make_unique<ImportedGlobal>(); 5374 scope.importedGlobal = std::make_unique<ImportedGlobal>();
5374 _importedGlobal = scope.importedGlobal.get(); 5375 _importedGlobal = scope.importedGlobal.get();
5376 _importedGlobal->currentBlock = block;
5375 _importedGlobal->vars = scope.vars.get(); 5377 _importedGlobal->vars = scope.vars.get();
5376 _importedGlobal->indent = indent(); 5378 _importedGlobal->indent = indent();
5377 _importedGlobal->nl = nl(stmt); 5379 _importedGlobal->nl = nl(stmt);
@@ -5420,7 +5422,9 @@ private:
5420 transformNode(); 5422 transformNode();
5421 } 5423 }
5422 } 5424 }
5423 if (auto importedGlobal = currentScope().importedGlobal.get()) { 5425
5426 if (auto importedGlobal = currentScope().importedGlobal.get();
5427 importedGlobal && importedGlobal->currentBlock == block) {
5424 int target = getLuaTarget(block); 5428 int target = getLuaTarget(block);
5425 auto attrib = target >= 504 ? " <const>"s : Empty; 5429 auto attrib = target >= 504 ? " <const>"s : Empty;
5426 str_list globalCodes; 5430 str_list globalCodes;
@@ -9338,7 +9342,7 @@ private:
9338 auto breakLoopType = getBreakLoopType(forNum->body, true, vars); 9342 auto breakLoopType = getBreakLoopType(forNum->body, true, vars);
9339 bool isScoped = true; 9343 bool isScoped = true;
9340 if (currentScope().lastStatement) { 9344 if (currentScope().lastStatement) {
9341 isScoped = false; 9345 isScoped = false;
9342 } else if (!extraVar && hasBreakWithValue(breakLoopType)) { 9346 } else if (!extraVar && hasBreakWithValue(breakLoopType)) {
9343 isScoped = false; 9347 isScoped = false;
9344 } 9348 }
@@ -10162,9 +10166,9 @@ private:
10162 _buf << indent() << "}, {"sv << nl(classDecl); 10166 _buf << indent() << "}, {"sv << nl(classDecl);
10163 if (extend) { 10167 if (extend) {
10164 _buf << indent(1) << "__index = function(cls, name)"sv << nl(classDecl); 10168 _buf << indent(1) << "__index = function(cls, name)"sv << nl(classDecl);
10165 _buf << indent(2) << "local val = "sv << globalVar("rawget", classDecl, AccessType::Read) << '(' << baseVar << ", name)"sv << nl(classDecl); 10169 _buf << indent(2) << "local val = "sv << globalVar("rawget"sv, classDecl, AccessType::Read) << '(' << baseVar << ", name)"sv << nl(classDecl);
10166 _buf << indent(2) << "if val == nil then"sv << nl(classDecl); 10170 _buf << indent(2) << "if val == nil then"sv << nl(classDecl);
10167 _buf << indent(3) << "local parent = "sv << globalVar("rawget", classDecl, AccessType::Read) << "(cls, \"__parent\")"sv << nl(classDecl); 10171 _buf << indent(3) << "local parent = "sv << globalVar("rawget"sv, classDecl, AccessType::Read) << "(cls, \"__parent\")"sv << nl(classDecl);
10168 _buf << indent(3) << "if parent then"sv << nl(classDecl); 10172 _buf << indent(3) << "if parent then"sv << nl(classDecl);
10169 _buf << indent(4) << "return parent[name]"sv << nl(classDecl); 10173 _buf << indent(4) << "return parent[name]"sv << nl(classDecl);
10170 _buf << indent(3) << "end"sv << nl(classDecl); 10174 _buf << indent(3) << "end"sv << nl(classDecl);
@@ -10179,7 +10183,7 @@ private:
10179 pushScope(); 10183 pushScope();
10180 auto selfVar = getUnusedName("_self_"sv); 10184 auto selfVar = getUnusedName("_self_"sv);
10181 addToScope(selfVar); 10185 addToScope(selfVar);
10182 _buf << indent(1) << "local "sv << selfVar << " = "sv << globalVar("setmetatable", classDecl, AccessType::Read) << "({ }, "sv << baseVar << ")"sv << nl(classDecl); 10186 _buf << indent(1) << "local "sv << selfVar << " = "sv << globalVar("setmetatable"sv, classDecl, AccessType::Read) << "({ }, "sv << baseVar << ")"sv << nl(classDecl);
10183 _buf << indent(1) << "cls.__init("sv << selfVar << ", ...)"sv << nl(classDecl); 10187 _buf << indent(1) << "cls.__init("sv << selfVar << ", ...)"sv << nl(classDecl);
10184 _buf << indent(1) << "return "sv << selfVar << nl(classDecl); 10188 _buf << indent(1) << "return "sv << selfVar << nl(classDecl);
10185 popScope(); 10189 popScope();