blueloveTH 2 năm trước cách đây
mục cha
commit
8a4045d2a5
2 tập tin đã thay đổi với 5 bổ sung17 xóa
  1. 1 2
      src/pocketpy.cpp
  2. 4 15
      tests/99_builtin_func.py

+ 1 - 2
src/pocketpy.cpp

@@ -179,7 +179,7 @@ void init_builtins(VM* _vm) {
     _vm->bind_builtin_func<1>("id", [](VM* vm, ArgsView args) {
         PyObject* obj = args[0];
         if(is_tagged(obj)) return vm->None;
-        return VAR_T(VoidP, obj);
+        return VAR(PK_BITS(obj));
     });
 
     _vm->bind_builtin_func<1>("staticmethod", [](VM* vm, ArgsView args) {
@@ -260,7 +260,6 @@ void init_builtins(VM* _vm) {
 
     _vm->bind_builtin_func<1>("hash", [](VM* vm, ArgsView args){
         i64 value = vm->py_hash(args[0]);
-        if(((value << 2) >> 2) != value) value >>= 2;
         return VAR(value);
     });
 

+ 4 - 15
tests/99_builtin_func.py

@@ -156,21 +156,6 @@ assert A.static_method(123) == 123
 #        67:  211:        return vm->py_import(name);
 #        67:  212:    });
 
-
-# 无法测试 -----------------------------------------------
-#       114:  238:    _vm->bind_builtin_func<-1>("exit", [](VM* vm, ArgsView args) {
-#     #####:  239:        if(args.size() == 0) std::exit(0);
-#     #####:  240:        else if(args.size() == 1) std::exit(CAST(int, args[0]));
-#     #####:  241:        else vm->TypeError("exit() takes at most 1 argument");
-#     #####:  242:        return vm->None;
-#     #####:  243:    });
-
-# -----------------------------------------------
-#       114:  253:    _vm->bind_builtin_func<1>("hash", [](VM* vm, ArgsView args){
-#     #####:  254:        i64 value = vm->py_hash(args[0]);
-#     #####:  255:        if(((value << 2) >> 2) != value) value >>= 2;
-#     #####:  256:        return VAR(value);
-#         -:  257:    });
 # test hash:
 # 测试整数类型的输入
 assert hash(0) == 0
@@ -1144,3 +1129,7 @@ assert callable(A.__call__) is True  # bound method
 assert callable(A.__init__) is True  # bound method
 assert callable(print) is True  # builtin function
 assert callable(isinstance) is True  # builtin function
+
+
+assert id(0) is None
+assert id(2**62) is not None