mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
up
This commit is contained in:
parent
4bb967d426
commit
76d167437c
@ -220,10 +220,6 @@ public:
|
|||||||
this->ip = i;
|
this->ip = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void jumpRelative(int i){
|
|
||||||
this->ip += i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void jumpAbsoluteSafe(int target){
|
void jumpAbsoluteSafe(int target){
|
||||||
const ByteCode& prev = code->co_code[this->ip];
|
const ByteCode& prev = code->co_code[this->ip];
|
||||||
int i = prev.block;
|
int i = prev.block;
|
||||||
|
@ -837,14 +837,10 @@ __LISTCOMP:
|
|||||||
void compileTryExcept() {
|
void compileTryExcept() {
|
||||||
getCode()->__enterBlock(TRY_EXCEPT);
|
getCode()->__enterBlock(TRY_EXCEPT);
|
||||||
compileBlockBody();
|
compileBlockBody();
|
||||||
getCode()->__exitBlock();
|
|
||||||
int patch = emitCode(OP_JUMP_ABSOLUTE);
|
int patch = emitCode(OP_JUMP_ABSOLUTE);
|
||||||
|
getCode()->__exitBlock();
|
||||||
consume(TK("except"));
|
consume(TK("except"));
|
||||||
if(match(TK("@id"))){ // exception name
|
if(match(TK("@id"))){ // exception name
|
||||||
if(match(TK("as"))){ // exception name as alias
|
|
||||||
consume(TK("@id"));
|
|
||||||
exprName();
|
|
||||||
}
|
|
||||||
compileBlockBody();
|
compileBlockBody();
|
||||||
}
|
}
|
||||||
if(match(TK("finally"))){
|
if(match(TK("finally"))){
|
||||||
@ -915,7 +911,12 @@ __LISTCOMP:
|
|||||||
} else if(match(TK("raise"))){
|
} else if(match(TK("raise"))){
|
||||||
consume(TK("@id")); // dummy exception type
|
consume(TK("@id")); // dummy exception type
|
||||||
emitCode(OP_LOAD_CONST, getCode()->addConst(vm->PyStr(parser->previous.str())));
|
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);
|
emitCode(OP_RAISE_ERROR);
|
||||||
consumeEndStatement();
|
consumeEndStatement();
|
||||||
} else if(match(TK("del"))){
|
} else if(match(TK("del"))){
|
||||||
|
@ -72,8 +72,6 @@ OPCODE(GOTO)
|
|||||||
OPCODE(WITH_ENTER)
|
OPCODE(WITH_ENTER)
|
||||||
OPCODE(WITH_EXIT)
|
OPCODE(WITH_EXIT)
|
||||||
|
|
||||||
OPCODE(JUMP_RELATIVE)
|
|
||||||
|
|
||||||
OPCODE(RAISE_VARARGS)
|
OPCODE(RAISE_VARARGS)
|
||||||
|
|
||||||
OPCODE(LOOP_BREAK)
|
OPCODE(LOOP_BREAK)
|
||||||
|
6
src/vm.h
6
src/vm.h
@ -246,7 +246,6 @@ protected:
|
|||||||
frame->push(std::move(ret));
|
frame->push(std::move(ret));
|
||||||
} break;
|
} break;
|
||||||
case OP_JUMP_ABSOLUTE: frame->jumpAbsolute(byte.arg); 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_SAFE_JUMP_ABSOLUTE: frame->jumpAbsoluteSafe(byte.arg); break;
|
||||||
case OP_GOTO: {
|
case OP_GOTO: {
|
||||||
PyVar obj = frame->popValue(this);
|
PyVar obj = frame->popValue(this);
|
||||||
@ -277,8 +276,7 @@ protected:
|
|||||||
auto& it = PyIter_AS_C(frame->__top());
|
auto& it = PyIter_AS_C(frame->__top());
|
||||||
if(it->hasNext()){
|
if(it->hasNext()){
|
||||||
PyRef_AS_C(it->var)->set(this, frame, it->next());
|
PyRef_AS_C(it->var)->set(this, frame, it->next());
|
||||||
}
|
}else{
|
||||||
else{
|
|
||||||
int blockEnd = frame->code->co_blocks[byte.block].end;
|
int blockEnd = frame->code->co_blocks[byte.block].end;
|
||||||
frame->jumpAbsoluteSafe(blockEnd);
|
frame->jumpAbsoluteSafe(blockEnd);
|
||||||
}
|
}
|
||||||
@ -405,7 +403,7 @@ public:
|
|||||||
return asRepr(obj);
|
return asRepr(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
Frame* topFrame(){
|
inline Frame* topFrame() const {
|
||||||
if(callstack.size() == 0) UNREACHABLE();
|
if(callstack.size() == 0) UNREACHABLE();
|
||||||
return callstack.back().get();
|
return callstack.back().get();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user