This commit is contained in:
blueloveTH 2023-05-21 15:21:13 +08:00
parent 015c994c02
commit 614abcdeea
4 changed files with 14 additions and 9 deletions

View File

@ -60,9 +60,6 @@ goto *OP_LABELS[byte.op];
__NEXT_STEP:; __NEXT_STEP:;
#if DEBUG_CEVAL_STEP #if DEBUG_CEVAL_STEP
_log_s_data(); _log_s_data();
#endif
#if DEBUG_CEVAL_STEP_MIN
std::cout << OP_NAMES[byte.op] << std::endl;
#endif #endif
switch (byte.op) switch (byte.op)
{ {
@ -113,7 +110,7 @@ __NEXT_STEP:;
heap._auto_collect(); heap._auto_collect();
_name = StrName(byte.arg); _name = StrName(byte.arg);
_0 = frame->_locals.try_get(_name); _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); _0 = frame->f_closure_try_get(_name);
if(_0 != nullptr) { PUSH(_0); DISPATCH(); } if(_0 != nullptr) { PUSH(_0); DISPATCH(); }
_0 = frame->f_globals().try_get(_name); _0 = frame->f_globals().try_get(_name);

View File

@ -36,7 +36,6 @@
#define DEBUG_EXTRA_CHECK 0 #define DEBUG_EXTRA_CHECK 0
#define DEBUG_DIS_EXEC 0 #define DEBUG_DIS_EXEC 0
#define DEBUG_CEVAL_STEP 0 #define DEBUG_CEVAL_STEP 0
#define DEBUG_CEVAL_STEP_MIN 0
#define DEBUG_FULL_EXCEPTION 0 #define DEBUG_FULL_EXCEPTION 0
#define DEBUG_MEMORY_POOL 0 #define DEBUG_MEMORY_POOL 0
#define DEBUG_NO_MEMORY_POOL 0 #define DEBUG_NO_MEMORY_POOL 0
@ -71,7 +70,7 @@
#define PK_ENABLE_COMPUTED_GOTO 1 #define PK_ENABLE_COMPUTED_GOTO 1
#define UNREACHABLE() __builtin_unreachable() #define UNREACHABLE() __builtin_unreachable()
#if DEBUG_CEVAL_STEP || DEBUG_CEVAL_STEP_MIN #if DEBUG_CEVAL_STEP
#undef PK_ENABLE_COMPUTED_GOTO #undef PK_ENABLE_COMPUTED_GOTO
#endif #endif

View File

@ -49,10 +49,11 @@ struct FastLocals{
NameDict_ to_namedict(){ NameDict_ to_namedict(){
NameDict_ dict = make_sp<NameDict>(); NameDict_ dict = make_sp<NameDict>();
// TODO: optimize this // TODO: optimize this, NameDict.items() is expensive
// NameDict.items() is expensive
for(auto& kv: varnames_inv->items()){ 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; return dict;
} }

8
tests/42_closure_ex.py Normal file
View File

@ -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