This commit is contained in:
blueloveTH 2023-02-25 15:18:55 +08:00
parent a6673e0c5e
commit 1578d66569
4 changed files with 19 additions and 2 deletions

View File

@ -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;
}

View File

@ -74,3 +74,6 @@ struct Type {
const float kLocalsLoadFactor = 0.67;
const float kInstAttrLoadFactor = 0.67;
const float kTypeAttrLoadFactor = 0.5;
// do extra check for debug
// #define PK_EXTRA_CHECK

View File

@ -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)();

View File

@ -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];
}