diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index a6b12301..00c7a470 100644 --- a/src/pocketpy.cpp +++ b/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); }); diff --git a/tests/99_builtin_func.py b/tests/99_builtin_func.py index adb82e9b..5a912475 100644 --- a/tests/99_builtin_func.py +++ b/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 \ No newline at end of file