aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-07-28 11:08:38 +0800
committerLi Jin <dragon-fly@qq.com>2022-07-28 11:08:38 +0800
commit1510038121252bd106b90e5f60b3c42978e3a572 (patch)
tree71b182107fcb8ad69993f5661ed9f017a91a33a2
parent8df3b854939a63b14aab3fd4688b0caea3daf1dc (diff)
downloadyuescript-1510038121252bd106b90e5f60b3c42978e3a572.tar.gz
yuescript-1510038121252bd106b90e5f60b3c42978e3a572.tar.bz2
yuescript-1510038121252bd106b90e5f60b3c42978e3a572.zip
check Lua target for some special operators.
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 1a44832..1a389b0 100755
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -54,7 +54,7 @@ namespace yue {
54 54
55typedef std::list<std::string> str_list; 55typedef std::list<std::string> str_list;
56 56
57const std::string_view version = "0.14.2"sv; 57const std::string_view version = "0.14.3"sv;
58const std::string_view extension = "yue"sv; 58const std::string_view extension = "yue"sv;
59 59
60class YueCompilerImpl { 60class YueCompilerImpl {
@@ -4830,6 +4830,9 @@ private:
4830 str_list temp; 4830 str_list temp;
4831 for (auto _op : unary_value->ops.objects()) { 4831 for (auto _op : unary_value->ops.objects()) {
4832 std::string op = _parser.toString(_op); 4832 std::string op = _parser.toString(_op);
4833 if (op == "~"sv && getLuaTarget(_op) < 503) {
4834 throw std::logic_error(_info.errorMessage("bitwise operator is not available when not targeting Lua version 5.3 or higher"sv, _op));
4835 }
4833 temp.push_back(op == "not"sv ? op + ' ' : op); 4836 temp.push_back(op == "not"sv ? op + ' ' : op);
4834 } 4837 }
4835 transformValue(unary_value->value, temp); 4838 transformValue(unary_value->value, temp);
@@ -4844,6 +4847,9 @@ private:
4844 std::string unary_op; 4847 std::string unary_op;
4845 for (auto _op : unary_exp->ops.objects()) { 4848 for (auto _op : unary_exp->ops.objects()) {
4846 std::string op = _parser.toString(_op); 4849 std::string op = _parser.toString(_op);
4850 if (op == "~"sv && getLuaTarget(_op) < 503) {
4851 throw std::logic_error(_info.errorMessage("bitwise operator is not available when not targeting Lua version 5.3 or higher"sv, _op));
4852 }
4847 unary_op.append(op == "not"sv ? op + ' ' : op); 4853 unary_op.append(op == "not"sv ? op + ' ' : op);
4848 } 4854 }
4849 str_list temp; 4855 str_list temp;
@@ -5798,6 +5804,19 @@ private:
5798 5804
5799 void transformBinaryOperator(BinaryOperator_t* node, str_list& out) { 5805 void transformBinaryOperator(BinaryOperator_t* node, str_list& out) {
5800 auto op = _parser.toString(node); 5806 auto op = _parser.toString(node);
5807 if (op == "&"sv ||
5808 op == "~"sv ||
5809 op == "|"sv ||
5810 op == ">>"sv ||
5811 op == "<<"sv) {
5812 if (getLuaTarget(node) < 503) {
5813 throw std::logic_error(_info.errorMessage("bitwise operator is not available when not targeting Lua version 5.3 or higher"sv, node));
5814 }
5815 } else if (op == "//"sv) {
5816 if (getLuaTarget(node) < 503) {
5817 throw std::logic_error(_info.errorMessage("floor division is not available when not targeting Lua version 5.3 or higher"sv, node));
5818 }
5819 }
5801 out.push_back(op == "!="sv ? "~="s : op); 5820 out.push_back(op == "!="sv ? "~="s : op);
5802 } 5821 }
5803 5822