diff options
author | Li Jin <dragon-fly@qq.com> | 2022-07-28 14:45:31 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-07-28 14:45:31 +0800 |
commit | c1a599fccfd3c37ad2afc743b2a49cc5290fcb9f (patch) | |
tree | ece02d19a99c1a2038141892ae14a69097a0eb75 | |
parent | 1510038121252bd106b90e5f60b3c42978e3a572 (diff) | |
download | yuescript-c1a599fccfd3c37ad2afc743b2a49cc5290fcb9f.tar.gz yuescript-c1a599fccfd3c37ad2afc743b2a49cc5290fcb9f.tar.bz2 yuescript-c1a599fccfd3c37ad2afc743b2a49cc5290fcb9f.zip |
add missing operator checks for update assignment.
-rw-r--r-- | makefile | 3 | ||||
-rwxr-xr-x | src/yuescript/yue_compiler.cpp | 9 | ||||
-rwxr-xr-x | src/yuescript/yue_parser.cpp | 10 |
3 files changed, 11 insertions, 11 deletions
@@ -192,10 +192,11 @@ endif | |||
192 | @$(END_TIME) | 192 | @$(END_TIME) |
193 | 193 | ||
194 | .PHONY: wasm | 194 | .PHONY: wasm |
195 | wasm: | 195 | wasm: clean |
196 | @$(MAKE) generic CC='emcc -s WASM=1' AR='emar rcu' RANLIB='emranlib' -C $(SRC_PATH)/3rdParty/lua | 196 | @$(MAKE) generic CC='emcc -s WASM=1' AR='emar rcu' RANLIB='emranlib' -C $(SRC_PATH)/3rdParty/lua |
197 | @mkdir -p doc/docs/.vuepress/public/js | 197 | @mkdir -p doc/docs/.vuepress/public/js |
198 | @emcc $(SRC_PATH)/yue_wasm.cpp $(SRC_PATH)/yuescript/ast.cpp $(SRC_PATH)/yuescript/parser.cpp $(SRC_PATH)/yuescript/yue_compiler.cpp $(SRC_PATH)/yuescript/yue_parser.cpp $(SRC_PATH)/yuescript/yuescript.cpp $(SRC_PATH)/3rdParty/lua/liblua.a -s WASM=1 -O2 -o doc/docs/.vuepress/public/js/yuescript.js -I $(SRC_PATH) -I $(SRC_PATH)/3rdParty/lua -std=c++17 --bind -fexceptions | 198 | @emcc $(SRC_PATH)/yue_wasm.cpp $(SRC_PATH)/yuescript/ast.cpp $(SRC_PATH)/yuescript/parser.cpp $(SRC_PATH)/yuescript/yue_compiler.cpp $(SRC_PATH)/yuescript/yue_parser.cpp $(SRC_PATH)/yuescript/yuescript.cpp $(SRC_PATH)/3rdParty/lua/liblua.a -s WASM=1 -O2 -o doc/docs/.vuepress/public/js/yuescript.js -I $(SRC_PATH) -I $(SRC_PATH)/3rdParty/lua -std=c++17 --bind -fexceptions |
199 | @${MAKE} clean | ||
199 | 200 | ||
200 | # Debug build for gdb debugging | 201 | # Debug build for gdb debugging |
201 | .PHONY: debug | 202 | .PHONY: debug |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 1a389b0..6213631 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -2431,6 +2431,7 @@ private: | |||
2431 | chain->items.clear(); | 2431 | chain->items.clear(); |
2432 | chain->items.dup(tmpChain->items); | 2432 | chain->items.dup(tmpChain->items); |
2433 | auto op = _parser.toString(update->op); | 2433 | auto op = _parser.toString(update->op); |
2434 | checkOperatorAvailable(op, update->op); | ||
2434 | if (op == "??"sv) { | 2435 | if (op == "??"sv) { |
2435 | auto defs = getPreDefineLine(assignment); | 2436 | auto defs = getPreDefineLine(assignment); |
2436 | temp.push_back(defs); | 2437 | temp.push_back(defs); |
@@ -5802,8 +5803,7 @@ private: | |||
5802 | out.push_back(join(temp)); | 5803 | out.push_back(join(temp)); |
5803 | } | 5804 | } |
5804 | 5805 | ||
5805 | void transformBinaryOperator(BinaryOperator_t* node, str_list& out) { | 5806 | void checkOperatorAvailable(const std::string& op, ast_node* node) { |
5806 | auto op = _parser.toString(node); | ||
5807 | if (op == "&"sv || | 5807 | if (op == "&"sv || |
5808 | op == "~"sv || | 5808 | op == "~"sv || |
5809 | op == "|"sv || | 5809 | op == "|"sv || |
@@ -5817,6 +5817,11 @@ private: | |||
5817 | throw std::logic_error(_info.errorMessage("floor division is not available when not targeting Lua version 5.3 or higher"sv, node)); | 5817 | throw std::logic_error(_info.errorMessage("floor division is not available when not targeting Lua version 5.3 or higher"sv, node)); |
5818 | } | 5818 | } |
5819 | } | 5819 | } |
5820 | } | ||
5821 | |||
5822 | void transformBinaryOperator(BinaryOperator_t* node, str_list& out) { | ||
5823 | auto op = _parser.toString(node); | ||
5824 | checkOperatorAvailable(op, node); | ||
5820 | out.push_back(op == "!="sv ? "~="s : op); | 5825 | out.push_back(op == "!="sv ? "~="s : op); |
5821 | } | 5826 | } |
5822 | 5827 | ||
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 94ce550..31a2560 100755 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
@@ -328,19 +328,13 @@ YueParser::YueParser() { | |||
328 | 328 | ||
329 | update_op = | 329 | update_op = |
330 | expr("..") | | 330 | expr("..") | |
331 | expr("+") | | ||
332 | expr("-") | | ||
333 | expr("*") | | ||
334 | expr("//") | | 331 | expr("//") | |
335 | expr("/") | | ||
336 | expr("%") | | ||
337 | expr("or") | | 332 | expr("or") | |
338 | expr("and") | | 333 | expr("and") | |
339 | expr("&") | | ||
340 | expr("|") | | ||
341 | expr(">>") | | 334 | expr(">>") | |
342 | expr("<<") | | 335 | expr("<<") | |
343 | expr("??"); | 336 | expr("??") | |
337 | set("+-*/%&|"); | ||
344 | 338 | ||
345 | Update = Space >> update_op >> expr("=") >> Exp; | 339 | Update = Space >> update_op >> expr("=") >> Exp; |
346 | 340 | ||