diff --git a/src/ceval.h b/src/ceval.h index 584d716a..47649b03 100644 --- a/src/ceval.h +++ b/src/ceval.h @@ -60,9 +60,6 @@ goto *OP_LABELS[byte.op]; __NEXT_STEP:; #if DEBUG_CEVAL_STEP _log_s_data(); -#endif -#if DEBUG_CEVAL_STEP_MIN - std::cout << OP_NAMES[byte.op] << std::endl; #endif switch (byte.op) { @@ -113,7 +110,7 @@ __NEXT_STEP:; heap._auto_collect(); _name = StrName(byte.arg); _0 = frame->_locals.try_get(_name); - if(_0 != nullptr) { PUSH(_0); DISPATCH(); } + if(_0 != PY_NULL) { PUSH(_0); DISPATCH(); } _0 = frame->f_closure_try_get(_name); if(_0 != nullptr) { PUSH(_0); DISPATCH(); } _0 = frame->f_globals().try_get(_name); diff --git a/src/common.h b/src/common.h index d95cc98b..2e75afec 100644 --- a/src/common.h +++ b/src/common.h @@ -36,7 +36,6 @@ #define DEBUG_EXTRA_CHECK 0 #define DEBUG_DIS_EXEC 0 #define DEBUG_CEVAL_STEP 0 -#define DEBUG_CEVAL_STEP_MIN 0 #define DEBUG_FULL_EXCEPTION 0 #define DEBUG_MEMORY_POOL 0 #define DEBUG_NO_MEMORY_POOL 0 @@ -71,7 +70,7 @@ #define PK_ENABLE_COMPUTED_GOTO 1 #define UNREACHABLE() __builtin_unreachable() -#if DEBUG_CEVAL_STEP || DEBUG_CEVAL_STEP_MIN +#if DEBUG_CEVAL_STEP #undef PK_ENABLE_COMPUTED_GOTO #endif diff --git a/src/frame.h b/src/frame.h index facf2388..e16d45bc 100644 --- a/src/frame.h +++ b/src/frame.h @@ -49,10 +49,11 @@ struct FastLocals{ NameDict_ to_namedict(){ NameDict_ dict = make_sp(); - // TODO: optimize this - // NameDict.items() is expensive + // TODO: optimize this, NameDict.items() is expensive for(auto& kv: varnames_inv->items()){ - dict->set(kv.first, a[kv.second]); + PyObject* value = a[kv.second]; + if(value == PY_NULL) continue; + dict->set(kv.first, value); } return dict; } diff --git a/tests/42_closure_ex.py b/tests/42_closure_ex.py new file mode 100644 index 00000000..e9e3faee --- /dev/null +++ b/tests/42_closure_ex.py @@ -0,0 +1,8 @@ +def f(n): + def g(x): + if x==n: + return n + return g(x+1) + return g(0) + +assert f(10) == 10 \ No newline at end of file