diff options
author | Li Jin <dragon-fly@qq.com> | 2021-11-23 09:34:46 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2021-11-23 09:34:57 +0800 |
commit | 65050db97932197ce990f36fc0efed8d0c1298a2 (patch) | |
tree | c3b8d0d941438cb6bd308b0d4ce08ecf389da821 | |
parent | 825b5d96f8a0d146615f0c6a76feab46da9baa60 (diff) | |
download | yuescript-65050db97932197ce990f36fc0efed8d0c1298a2.tar.gz yuescript-65050db97932197ce990f36fc0efed8d0c1298a2.tar.bz2 yuescript-65050db97932197ce990f36fc0efed8d0c1298a2.zip |
fix an indent issue. add more macro specs. fixing issue #69.
-rw-r--r-- | spec/inputs/macro-todo.yue | 4 | ||||
-rw-r--r-- | spec/inputs/macro.yue | 16 | ||||
-rw-r--r-- | spec/outputs/macro.lua | 13 | ||||
-rwxr-xr-x | 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)-> | |||
7 | 7 | ||
8 | export macro todo = (msg)-> | 8 | export macro todo = (msg)-> |
9 | if msg | 9 | if msg |
10 | "$todoInner $MODULE, $LINE, #{msg}" | 10 | "$todoInner $FILE, $LINE, #{msg}" |
11 | else | 11 | else |
12 | "$todoInner $MODULE, $LINE" | 12 | "$todoInner $FILE, $LINE" |
13 | 13 | ||
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 }" | |||
262 | 262 | ||
263 | $todo | 263 | $todo |
264 | 264 | ||
265 | macro skip = -> "" | ||
266 | |||
267 | do | ||
268 | print 1 | ||
269 | <- $skip | ||
270 | print 2 | ||
271 | print 3 | ||
272 | |||
273 | macro skip = -> "while false do break" | ||
274 | |||
275 | _ = -> | ||
276 | print 1 | ||
277 | <- $skip | ||
278 | print 2 | ||
279 | print 3 | ||
280 | |||
265 | macro implicitReturnMacroIsAllowed = -> "print 'abc'\n123" | 281 | macro implicitReturnMacroIsAllowed = -> "print 'abc'\n123" |
266 | 282 | ||
267 | $implicitReturnMacroIsAllowed | 283 | $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({ | |||
260 | })) | 260 | })) |
261 | print("current line: " .. tostring(261)); | 261 | print("current line: " .. tostring(261)); |
262 | -- TODO | 262 | -- TODO |
263 | do | ||
264 | print(1) | ||
265 | end | ||
266 | _ = function() | ||
267 | print(1) | ||
268 | local _accum_0 = { } | ||
269 | local _len_0 = 1 | ||
270 | while false do | ||
271 | break | ||
272 | _len_0 = _len_0 + 1 | ||
273 | end | ||
274 | return _accum_0 | ||
275 | end | ||
263 | print('abc') | 276 | print('abc') |
264 | return 123 | 277 | 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; | |||
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.1"sv; | 63 | const std::string_view version = "0.9.2"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 { |
@@ -3974,7 +3974,7 @@ private: | |||
3974 | if (name == "LINE"sv) { | 3974 | if (name == "LINE"sv) { |
3975 | return std::to_string(x->m_begin.m_line + _config.lineOffset); | 3975 | return std::to_string(x->m_begin.m_line + _config.lineOffset); |
3976 | } | 3976 | } |
3977 | if (name == "MODULE"sv) { | 3977 | if (name == "FILE"sv) { |
3978 | return _config.module.empty() ? "\"yuescript\""s : '"' + _config.module + '"'; | 3978 | return _config.module.empty() ? "\"yuescript\""s : '"' + _config.module + '"'; |
3979 | } | 3979 | } |
3980 | return Empty; | 3980 | return Empty; |
@@ -6255,8 +6255,8 @@ private: | |||
6255 | str_list temp; | 6255 | str_list temp; |
6256 | if (expList) { | 6256 | if (expList) { |
6257 | temp.push_back(indent() + "do"s + nll(whileNode)); | 6257 | temp.push_back(indent() + "do"s + nll(whileNode)); |
6258 | pushScope(); | ||
6258 | } | 6259 | } |
6259 | pushScope(); | ||
6260 | auto accumVar = getUnusedName("_accum_"sv); | 6260 | auto accumVar = getUnusedName("_accum_"sv); |
6261 | addToScope(accumVar); | 6261 | addToScope(accumVar); |
6262 | auto lenVar = getUnusedName("_len_"sv); | 6262 | auto lenVar = getUnusedName("_len_"sv); |
@@ -6279,10 +6279,10 @@ private: | |||
6279 | assignment->expList.set(expList); | 6279 | assignment->expList.set(expList); |
6280 | assignment->action.set(assign); | 6280 | assignment->action.set(assign); |
6281 | transformAssignment(assignment, temp); | 6281 | transformAssignment(assignment, temp); |
6282 | popScope(); | ||
6282 | } else { | 6283 | } else { |
6283 | temp.push_back(indent() + "return "s + accumVar + nlr(whileNode)); | 6284 | temp.push_back(indent() + "return "s + accumVar + nlr(whileNode)); |
6284 | } | 6285 | } |
6285 | popScope(); | ||
6286 | if (expList) { | 6286 | if (expList) { |
6287 | temp.push_back(indent() + "end"s + nlr(whileNode)); | 6287 | temp.push_back(indent() + "end"s + nlr(whileNode)); |
6288 | } | 6288 | } |