mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
up
This commit is contained in:
parent
3bfb18e2c3
commit
5c2352fa90
@ -726,7 +726,7 @@ __LISTCOMP:
|
|||||||
tkmodule = parser->prev;
|
tkmodule = parser->prev;
|
||||||
}
|
}
|
||||||
int index = co()->add_name(tkmodule.str(), NAME_GLOBAL);
|
int index = co()->add_name(tkmodule.str(), NAME_GLOBAL);
|
||||||
emit(OP_STORE_NAME_REF, index);
|
emit(OP_STORE_NAME, index);
|
||||||
} while (match(TK(",")));
|
} while (match(TK(",")));
|
||||||
consumeEndStatement();
|
consumeEndStatement();
|
||||||
}
|
}
|
||||||
@ -746,7 +746,7 @@ __LISTCOMP:
|
|||||||
tkname = parser->prev;
|
tkname = parser->prev;
|
||||||
}
|
}
|
||||||
index = co()->add_name(tkname.str(), NAME_GLOBAL);
|
index = co()->add_name(tkname.str(), NAME_GLOBAL);
|
||||||
emit(OP_STORE_NAME_REF, index);
|
emit(OP_STORE_NAME, index);
|
||||||
} while (match(TK(",")));
|
} while (match(TK(",")));
|
||||||
emit(OP_POP_TOP);
|
emit(OP_POP_TOP);
|
||||||
consumeEndStatement();
|
consumeEndStatement();
|
||||||
@ -873,7 +873,7 @@ __LISTCOMP:
|
|||||||
tkname.str(),
|
tkname.str(),
|
||||||
codes.size()>1 ? NAME_LOCAL : NAME_GLOBAL
|
codes.size()>1 ? NAME_LOCAL : NAME_GLOBAL
|
||||||
);
|
);
|
||||||
emit(OP_STORE_NAME_REF, index);
|
emit(OP_STORE_NAME, index);
|
||||||
emit(OP_LOAD_NAME_REF, index);
|
emit(OP_LOAD_NAME_REF, index);
|
||||||
emit(OP_WITH_ENTER);
|
emit(OP_WITH_ENTER);
|
||||||
compileBlockBody();
|
compileBlockBody();
|
||||||
@ -919,7 +919,7 @@ __LISTCOMP:
|
|||||||
consumeEndStatement();
|
consumeEndStatement();
|
||||||
// If last op is not an assignment, pop the result.
|
// If last op is not an assignment, pop the result.
|
||||||
uint8_t lastOp = co()->co_code.back().op;
|
uint8_t lastOp = co()->co_code.back().op;
|
||||||
if( lastOp!=OP_STORE_NAME_REF && lastOp!=OP_STORE_REF){
|
if( lastOp!=OP_STORE_NAME && lastOp!=OP_STORE_REF){
|
||||||
if(mode()==SINGLE_MODE && parser->indents.top()==0) emit(OP_PRINT_EXPR);
|
if(mode()==SINGLE_MODE && parser->indents.top()==0) emit(OP_PRINT_EXPR);
|
||||||
emit(OP_POP_TOP);
|
emit(OP_POP_TOP);
|
||||||
}
|
}
|
||||||
|
@ -51,11 +51,11 @@ OPCODE(LOAD_NAME_REF)
|
|||||||
OPCODE(ASSERT)
|
OPCODE(ASSERT)
|
||||||
OPCODE(RAISE_ERROR)
|
OPCODE(RAISE_ERROR)
|
||||||
|
|
||||||
OPCODE(STORE_FUNCTION)
|
|
||||||
OPCODE(BUILD_CLASS)
|
OPCODE(BUILD_CLASS)
|
||||||
OPCODE(BUILD_ATTR_REF)
|
OPCODE(BUILD_ATTR_REF)
|
||||||
|
OPCODE(STORE_NAME)
|
||||||
|
OPCODE(STORE_FUNCTION)
|
||||||
OPCODE(BUILD_INDEX_REF)
|
OPCODE(BUILD_INDEX_REF)
|
||||||
OPCODE(STORE_NAME_REF)
|
|
||||||
OPCODE(STORE_REF)
|
OPCODE(STORE_REF)
|
||||||
OPCODE(DELETE_REF)
|
OPCODE(DELETE_REF)
|
||||||
|
|
||||||
|
9
src/vm.h
9
src/vm.h
@ -48,7 +48,7 @@ protected:
|
|||||||
case OP_LOAD_NAME: {
|
case OP_LOAD_NAME: {
|
||||||
frame->push(NameRef(frame->code->co_names[byte.arg]).get(this, frame));
|
frame->push(NameRef(frame->code->co_names[byte.arg]).get(this, frame));
|
||||||
} break;
|
} break;
|
||||||
case OP_STORE_NAME_REF: {
|
case OP_STORE_NAME: {
|
||||||
const auto& p = frame->code->co_names[byte.arg];
|
const auto& p = frame->code->co_names[byte.arg];
|
||||||
NameRef(p).set(this, frame, frame->pop_value(this));
|
NameRef(p).set(this, frame, frame->pop_value(this));
|
||||||
} break;
|
} break;
|
||||||
@ -960,8 +960,9 @@ void NameRef::set(VM* vm, Frame* frame, PyVar val) const{
|
|||||||
case NAME_LOCAL: frame->f_locals[pair->first] = std::move(val); break;
|
case NAME_LOCAL: frame->f_locals[pair->first] = std::move(val); break;
|
||||||
case NAME_GLOBAL:
|
case NAME_GLOBAL:
|
||||||
{
|
{
|
||||||
if(frame->f_locals.contains(pair->first)){
|
PyVar* existing = frame->f_locals.try_get(pair->first);
|
||||||
frame->f_locals[pair->first] = std::move(val);
|
if(existing != nullptr){
|
||||||
|
*existing = std::move(val);
|
||||||
}else{
|
}else{
|
||||||
frame->f_globals()[pair->first] = std::move(val);
|
frame->f_globals()[pair->first] = std::move(val);
|
||||||
}
|
}
|
||||||
@ -973,7 +974,7 @@ void NameRef::set(VM* vm, Frame* frame, PyVar val) const{
|
|||||||
void NameRef::del(VM* vm, Frame* frame) const{
|
void NameRef::del(VM* vm, Frame* frame) const{
|
||||||
switch(pair->second) {
|
switch(pair->second) {
|
||||||
case NAME_LOCAL: {
|
case NAME_LOCAL: {
|
||||||
if(frame->f_locals.count(pair->first) > 0){
|
if(frame->f_locals.contains(pair->first)){
|
||||||
frame->f_locals.erase(pair->first);
|
frame->f_locals.erase(pair->first);
|
||||||
}else{
|
}else{
|
||||||
vm->nameError(pair->first);
|
vm->nameError(pair->first);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user