From 65050db97932197ce990f36fc0efed8d0c1298a2 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 23 Nov 2021 09:34:46 +0800 Subject: fix an indent issue. add more macro specs. fixing issue #69. --- spec/inputs/macro-todo.yue | 4 ++-- spec/inputs/macro.yue | 16 ++++++++++++++++ spec/outputs/macro.lua | 13 +++++++++++++ src/yuescript/yue_compiler.cpp | 8 ++++---- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/spec/inputs/macro-todo.yue b/spec/inputs/macro-todo.yue index 8477e5a..752c9cb 100644 --- a/spec/inputs/macro-todo.yue +++ b/spec/inputs/macro-todo.yue @@ -7,7 +7,7 @@ export macro todoInner = (module, line, msg)-> export macro todo = (msg)-> if msg - "$todoInner $MODULE, $LINE, #{msg}" + "$todoInner $FILE, $LINE, #{msg}" else - "$todoInner $MODULE, $LINE" + "$todoInner $FILE, $LINE" diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue index 2742bd0..37702d1 100644 --- a/spec/inputs/macro.yue +++ b/spec/inputs/macro.yue @@ -262,6 +262,22 @@ print "current line: #{ $LINE }" $todo +macro skip = -> "" + +do + print 1 + <- $skip + print 2 + print 3 + +macro skip = -> "while false do break" + +_ = -> + print 1 + <- $skip + print 2 + print 3 + macro implicitReturnMacroIsAllowed = -> "print 'abc'\n123" $implicitReturnMacroIsAllowed diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua index 9f04216..b3085bb 100644 --- a/spec/outputs/macro.lua +++ b/spec/outputs/macro.lua @@ -260,5 +260,18 @@ print((setmetatable({ })) print("current line: " .. tostring(261)); -- TODO +do + print(1) +end +_ = function() + print(1) + local _accum_0 = { } + local _len_0 = 1 + while false do + break + _len_0 = _len_0 + 1 + end + return _accum_0 +end print('abc') return 123 diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index b3f6bdd..d4996a7 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -60,7 +60,7 @@ using namespace parserlib; typedef std::list str_list; -const std::string_view version = "0.9.1"sv; +const std::string_view version = "0.9.2"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -3974,7 +3974,7 @@ private: if (name == "LINE"sv) { return std::to_string(x->m_begin.m_line + _config.lineOffset); } - if (name == "MODULE"sv) { + if (name == "FILE"sv) { return _config.module.empty() ? "\"yuescript\""s : '"' + _config.module + '"'; } return Empty; @@ -6255,8 +6255,8 @@ private: str_list temp; if (expList) { temp.push_back(indent() + "do"s + nll(whileNode)); + pushScope(); } - pushScope(); auto accumVar = getUnusedName("_accum_"sv); addToScope(accumVar); auto lenVar = getUnusedName("_len_"sv); @@ -6279,10 +6279,10 @@ private: assignment->expList.set(expList); assignment->action.set(assign); transformAssignment(assignment, temp); + popScope(); } else { temp.push_back(indent() + "return "s + accumVar + nlr(whileNode)); } - popScope(); if (expList) { temp.push_back(indent() + "end"s + nlr(whileNode)); } -- cgit v1.2.3-55-g6feb