From 1578d66569ddd2ca0a950d7d4040d22fab7ef878 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 25 Feb 2023 15:18:55 +0800 Subject: [PATCH] up --- src/ceval.h | 3 ++- src/common.h | 5 ++++- src/compiler.h | 5 +++++ src/frame.h | 8 ++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ceval.h b/src/ceval.h index 3e115320..73761c4d 100644 --- a/src/ceval.h +++ b/src/ceval.h @@ -315,7 +315,8 @@ PyVar VM::run_frame(Frame* frame){ if(frame->_data.size() != 1) throw std::runtime_error("_data.size() != 1 in EVAL/JSON_MODE"); return frame->pop_value(this); } - +#ifdef PK_EXTRA_CHECK if(!frame->_data.empty()) throw std::runtime_error("_data.size() != 0 in EXEC_MODE"); +#endif return None; } diff --git a/src/common.h b/src/common.h index 81a5d91f..f6b46405 100644 --- a/src/common.h +++ b/src/common.h @@ -73,4 +73,7 @@ struct Type { const float kLocalsLoadFactor = 0.67; const float kInstAttrLoadFactor = 0.67; -const float kTypeAttrLoadFactor = 0.5; \ No newline at end of file +const float kTypeAttrLoadFactor = 0.5; + +// do extra check for debug +// #define PK_EXTRA_CHECK \ No newline at end of file diff --git a/src/compiler.h b/src/compiler.h index a69c741a..97c03563 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -763,9 +763,14 @@ __LISTCOMP: GrammarFn prefix = rules[parser->prev.type].prefix; if (prefix == nullptr) SyntaxError(Str("expected an expression, but got ") + TK_STR(parser->prev.type)); (this->*prefix)(); + bool meet_assign_token = false; while (rules[peek()].precedence >= precedence) { lex_token(); TokenIndex op = parser->prev.type; + if (op == TK("=")){ + if(meet_assign_token) SyntaxError("invalid syntax"); + meet_assign_token = true; + } GrammarFn infix = rules[op].infix; if(infix == nullptr) throw std::runtime_error("(infix == nullptr) is true"); (this->*infix)(); diff --git a/src/frame.h b/src/frame.h index b70fbe75..3aa2a9c5 100644 --- a/src/frame.h +++ b/src/frame.h @@ -56,14 +56,18 @@ struct Frame { } inline PyVar pop(){ +#ifdef PK_EXTRA_CHECK if(_data.empty()) throw std::runtime_error("_data.empty() is true"); +#endif PyVar v = std::move(_data.back()); _data.pop_back(); return v; } inline void _pop(){ +#ifdef PK_EXTRA_CHECK if(_data.empty()) throw std::runtime_error("_data.empty() is true"); +#endif _data.pop_back(); } @@ -82,12 +86,16 @@ struct Frame { } inline PyVar& top(){ +#ifdef PK_EXTRA_CHECK if(_data.empty()) throw std::runtime_error("_data.empty() is true"); +#endif return _data.back(); } inline PyVar& top_1(){ +#ifdef PK_EXTRA_CHECK if(_data.size() < 2) throw std::runtime_error("_data.size() < 2"); +#endif return _data[_data.size()-2]; }