diff options
author | Li Jin <dragon-fly@qq.com> | 2020-09-17 08:47:29 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-09-17 08:47:29 +0800 |
commit | 5440c952f2c73da6fa6a752d8628eaf25015c070 (patch) | |
tree | c57173a695bba128c4bccef78dea581ba4a87bc3 /src | |
parent | e958b59c9635f0a01e29e3f30c34adecd327cc1f (diff) | |
download | yuescript-5440c952f2c73da6fa6a752d8628eaf25015c070.tar.gz yuescript-5440c952f2c73da6fa6a752d8628eaf25015c070.tar.bz2 yuescript-5440c952f2c73da6fa6a752d8628eaf25015c070.zip |
make simple table and table block appear in the end of function arguments merged.
Diffstat (limited to 'src')
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 406b412..112cae7 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
@@ -49,7 +49,7 @@ inline std::string s(std::string_view sv) { | |||
49 | } | 49 | } |
50 | 50 | ||
51 | const std::string_view version() { | 51 | const std::string_view version() { |
52 | return "0.4.12"sv; | 52 | return "0.4.14"sv; |
53 | } | 53 | } |
54 | 54 | ||
55 | // name of table stored in lua registry | 55 | // name of table stored in lua registry |
@@ -3603,6 +3603,37 @@ private: | |||
3603 | } | 3603 | } |
3604 | 3604 | ||
3605 | void transformInvokeArgs(InvokeArgs_t* invokeArgs, str_list& out) { | 3605 | void transformInvokeArgs(InvokeArgs_t* invokeArgs, str_list& out) { |
3606 | if (invokeArgs->args.size() > 1) { | ||
3607 | /* merge all the key-value pairs into one table | ||
3608 | from arguments in the end */ | ||
3609 | auto lastArg = invokeArgs->args.back(); | ||
3610 | _ast_list* lastTable = nullptr; | ||
3611 | if (auto tableBlock = ast_cast<TableBlock_t>(lastArg)) { | ||
3612 | lastTable = &tableBlock->values; | ||
3613 | } else if (auto value = singleValueFrom(lastArg)) { | ||
3614 | if (auto simpleTable = ast_cast<simple_table_t>(value->item)) { | ||
3615 | lastTable = &simpleTable->pairs; | ||
3616 | } | ||
3617 | } | ||
3618 | if (lastTable) { | ||
3619 | ast_ptr<false, ast_node> ref(lastArg); | ||
3620 | invokeArgs->args.pop_back(); | ||
3621 | while (!invokeArgs->args.empty()) { | ||
3622 | if (Value_t* value = singleValueFrom(invokeArgs->args.back())) { | ||
3623 | if (auto tb = value->item.as<simple_table_t>()) { | ||
3624 | const auto& ps = tb->pairs.objects(); | ||
3625 | for (auto it = ps.rbegin(); it != ps.rend(); ++it) { | ||
3626 | lastTable->push_front(*it); | ||
3627 | } | ||
3628 | invokeArgs->args.pop_back(); | ||
3629 | continue; | ||
3630 | } | ||
3631 | } | ||
3632 | break; | ||
3633 | } | ||
3634 | invokeArgs->args.push_back(lastArg); | ||
3635 | } | ||
3636 | } | ||
3606 | str_list temp; | 3637 | str_list temp; |
3607 | for (auto arg : invokeArgs->args.objects()) { | 3638 | for (auto arg : invokeArgs->args.objects()) { |
3608 | switch (arg->getId()) { | 3639 | switch (arg->getId()) { |