This commit is contained in:
blueloveTH 2023-01-05 20:09:10 +08:00
parent 4bb967d426
commit 76d167437c
4 changed files with 9 additions and 16 deletions

View File

@ -220,10 +220,6 @@ public:
this->ip = i;
}
inline void jumpRelative(int i){
this->ip += i;
}
void jumpAbsoluteSafe(int target){
const ByteCode& prev = code->co_code[this->ip];
int i = prev.block;

View File

@ -837,14 +837,10 @@ __LISTCOMP:
void compileTryExcept() {
getCode()->__enterBlock(TRY_EXCEPT);
compileBlockBody();
getCode()->__exitBlock();
int patch = emitCode(OP_JUMP_ABSOLUTE);
getCode()->__exitBlock();
consume(TK("except"));
if(match(TK("@id"))){ // exception name
if(match(TK("as"))){ // exception name as alias
consume(TK("@id"));
exprName();
}
compileBlockBody();
}
if(match(TK("finally"))){
@ -915,7 +911,12 @@ __LISTCOMP:
} else if(match(TK("raise"))){
consume(TK("@id")); // dummy exception type
emitCode(OP_LOAD_CONST, getCode()->addConst(vm->PyStr(parser->previous.str())));
consume(TK("("));EXPR();consume(TK(")"));
if(match(TK("("))){
EXPR();
consume(TK(")"));
}else{
emitCode(OP_LOAD_NONE); // ...?
}
emitCode(OP_RAISE_ERROR);
consumeEndStatement();
} else if(match(TK("del"))){

View File

@ -72,8 +72,6 @@ OPCODE(GOTO)
OPCODE(WITH_ENTER)
OPCODE(WITH_EXIT)
OPCODE(JUMP_RELATIVE)
OPCODE(RAISE_VARARGS)
OPCODE(LOOP_BREAK)

View File

@ -246,7 +246,6 @@ protected:
frame->push(std::move(ret));
} break;
case OP_JUMP_ABSOLUTE: frame->jumpAbsolute(byte.arg); break;
case OP_JUMP_RELATIVE: frame->jumpRelative(byte.arg); break;
case OP_SAFE_JUMP_ABSOLUTE: frame->jumpAbsoluteSafe(byte.arg); break;
case OP_GOTO: {
PyVar obj = frame->popValue(this);
@ -277,8 +276,7 @@ protected:
auto& it = PyIter_AS_C(frame->__top());
if(it->hasNext()){
PyRef_AS_C(it->var)->set(this, frame, it->next());
}
else{
}else{
int blockEnd = frame->code->co_blocks[byte.block].end;
frame->jumpAbsoluteSafe(blockEnd);
}
@ -405,7 +403,7 @@ public:
return asRepr(obj);
}
Frame* topFrame(){
inline Frame* topFrame() const {
if(callstack.size() == 0) UNREACHABLE();
return callstack.back().get();
}