blueloveTH 3 ani în urmă
părinte
comite
7ebf5f1e88
4 a modificat fișierele cu 11 adăugiri și 6 ștergeri
  1. 2 2
      src/ceval.h
  2. 2 1
      src/cffi.h
  3. 1 1
      src/pocketpy.h
  4. 6 2
      src/vm.h

+ 2 - 2
src/ceval.h

@@ -158,10 +158,10 @@ PyVar VM::run_frame(Frame* frame){
         case OP_UNARY_NOT: {
             PyVar obj = frame->pop_value(this);
             const PyVar& obj_bool = asBool(obj);
-            frame->push(PyBool(!PyBool_AS_C(obj_bool)));
+            frame->push(PyBool(!_PyBool_AS_C(obj_bool)));
         } continue;
         case OP_POP_JUMP_IF_FALSE:
-            if(!PyBool_AS_C(asBool(frame->pop_value(this)))) frame->jump_abs(byte.arg);
+            if(!_PyBool_AS_C(asBool(frame->pop_value(this)))) frame->jump_abs(byte.arg);
             continue;
         case OP_LOAD_NONE: frame->push(None); continue;
         case OP_LOAD_TRUE: frame->push(True); continue;

+ 2 - 1
src/cffi.h

@@ -77,7 +77,7 @@ struct Pointer{
                 case ctype("float64"): return vm->PyFloat(((double*)self.ptr)[index]);
                 case ctype("bool8"): return vm->PyBool(((bool*)self.ptr)[index]);
                 case ctype("void"): vm->TypeError("cannot index void*");
-                default: vm->TypeError("unsupported type");
+                default: UNREACHABLE();
             }
             return vm->None;
         });
@@ -98,6 +98,7 @@ struct Pointer{
                 case ctype("float64"): ((double*)self.ptr)[index] = vm->PyFloat_AS_C(args[2]); break;
                 case ctype("bool8"): ((bool*)self.ptr)[index] = vm->PyBool_AS_C(args[2]); break;
                 case ctype("void"): vm->TypeError("cannot index void*");
+                default: UNREACHABLE();
             }
             return vm->None;
         });

+ 1 - 1
src/pocketpy.h

@@ -210,7 +210,7 @@ void init_builtins(VM* _vm) {
     _vm->bind_static_method<1>("int", "__new__", [](VM* vm, pkpy::Args& args) {
         if (is_type(args[0], vm->tp_int)) return args[0];
         if (is_type(args[0], vm->tp_float)) return vm->PyInt((i64)vm->PyFloat_AS_C(args[0]));
-        if (is_type(args[0], vm->tp_bool)) return vm->PyInt(vm->PyBool_AS_C(args[0]) ? 1 : 0);
+        if (is_type(args[0], vm->tp_bool)) return vm->PyInt(vm->_PyBool_AS_C(args[0]) ? 1 : 0);
         if (is_type(args[0], vm->tp_str)) {
             const Str& s = vm->PyStr_AS_C(args[0]);
             try{

+ 6 - 2
src/vm.h

@@ -607,7 +607,11 @@ public:
     DEF_NATIVE(StarWrapper, pkpy::StarWrapper, tp_star_wrapper)
     
     // there is only one True/False, so no need to copy them!
-    inline bool PyBool_AS_C(const PyVar& obj){return obj == True;}
+    inline bool PyBool_AS_C(const PyVar& obj){
+        check_type(obj, tp_bool);
+        return obj == True;
+    }
+    inline bool _PyBool_AS_C(const PyVar& obj){ return obj == True; }
     inline const PyVar& PyBool(bool value){return value ? True : False;}
 
     void init_builtin_types(){
@@ -684,7 +688,7 @@ public:
             return x;
         }
         if (is_type(obj, tp_type)) return obj.bits;
-        if (is_type(obj, tp_bool)) return PyBool_AS_C(obj) ? 1 : 0;
+        if (is_type(obj, tp_bool)) return _PyBool_AS_C(obj) ? 1 : 0;
         if (is_float(obj)){
             f64 val = PyFloat_AS_C(obj);
             return (i64)std::hash<f64>()(val);