blueloveTH 2 anni fa
parent
commit
614abcdeea
4 ha cambiato i file con 14 aggiunte e 9 eliminazioni
  1. 1 4
      src/ceval.h
  2. 1 2
      src/common.h
  3. 4 3
      src/frame.h
  4. 8 0
      tests/42_closure_ex.py

+ 1 - 4
src/ceval.h

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

+ 1 - 2
src/common.h

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

+ 4 - 3
src/frame.h

@@ -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
-        // NameDict.items() is expensive
+        // TODO: optimize this, 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 - 0
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