From 07d8a520bf5761269e0e61c97dfd01605490fe6b Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 10 Jun 2023 00:30:53 +0800 Subject: [PATCH] ... --- src/ceval.h | 1 - src/expr.h | 2 +- src/frame.h | 10 ++++------ src/namedict.h | 8 ++++++++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ceval.h b/src/ceval.h index fa5564c9..84e42444 100644 --- a/src/ceval.h +++ b/src/ceval.h @@ -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(); diff --git a/src/expr.h b/src/expr.h index 7651f5c6..38556ad1 100644 --- a/src/expr.h +++ b/src/expr.h @@ -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); diff --git a/src/frame.h b/src/frame.h index bc6ad1e0..faf13dd7 100644 --- a/src/frame.h +++ b/src/frame.h @@ -49,12 +49,10 @@ struct FastLocals{ NameDict_ to_namedict(){ NameDict_ dict = make_sp(); - // 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; } }; diff --git a/src/namedict.h b/src/namedict.h index 6244ac62..f9334328 100644 --- a/src/namedict.h +++ b/src/namedict.h @@ -182,6 +182,14 @@ while(!_items[i].first.empty()) { \ return v; } + template + 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 keys() const { std::vector v; for(uint16_t i=0; i<_capacity; i++){