This commit is contained in:
blueloveTH 2023-06-10 00:30:53 +08:00
parent 1e89045f82
commit 07d8a520bf
4 changed files with 13 additions and 8 deletions

View File

@ -598,7 +598,6 @@ __NEXT_STEP:;
TOP()->attr().set(_name, _0);
DISPATCH();
/*****************************************/
// TODO: using "goto" inside with block may cause __exit__ not called
TARGET(WITH_ENTER)
call_method(POPX(), __enter__);
DISPATCH();

View File

@ -497,7 +497,7 @@ struct CompExpr: Expr{
ctx->emit(OP_FOR_ITER, BC_NOARG, BC_KEEPLINE);
bool ok = vars->emit_store(ctx);
// this error occurs in `vars` instead of this line, but...nevermind
if(!ok) FATAL_ERROR(); // TODO: raise a SyntaxError instead
PK_ASSERT(ok); // TODO: raise a SyntaxError instead
if(cond){
cond->emit(ctx);
int patch = ctx->emit(OP_POP_JUMP_IF_FALSE, BC_NOARG, BC_KEEPLINE);

View File

@ -49,12 +49,10 @@ struct FastLocals{
NameDict_ to_namedict(){
NameDict_ dict = make_sp<NameDict>();
// TODO: optimize this, NameDict.items() is expensive
for(auto& kv: varnames_inv->items()){
PyObject* value = a[kv.second];
if(value == PY_NULL) continue;
dict->set(kv.first, value);
}
varnames_inv->apply([&](StrName name, int index){
PyObject* value = a[index];
if(value != PY_NULL) dict->set(name, value);
});
return dict;
}
};

View File

@ -182,6 +182,14 @@ while(!_items[i].first.empty()) { \
return v;
}
template<typename __Func>
void apply(__Func func) const {
for(uint16_t i=0; i<_capacity; i++){
if(_items[i].first.empty()) continue;
func(_items[i].first, _items[i].second);
}
}
std::vector<StrName> keys() const {
std::vector<StrName> v;
for(uint16_t i=0; i<_capacity; i++){