small fix

This commit is contained in:
blueloveTH 2023-02-11 16:46:19 +08:00
parent d70d2c6995
commit d9717abc5c
3 changed files with 6 additions and 5 deletions

View File

@ -103,7 +103,7 @@ struct Py_ : PyObject {
inline static const char* _mod() { return #mod; } \
inline static const char* _name() { return #name; }
#define PY_BUILTIN_CLASS(name) inline static PyVar _type(VM* vm) { return vm->tp_##name; }
// #define PY_BUILTIN_CLASS(name) inline static PyVar _type(VM* vm) { return vm->tp_##name; }
static thread_local emhash8::HashMap<void*, std::vector<int*>> _obj_pool;

View File

@ -578,8 +578,8 @@ void add_module_math(VM* vm){
vm->bind_func<1>(mod, "isnan", CPP_LAMBDA(vm->PyBool(std::isnan(vm->num_to_float(args[0])))));
vm->bind_func<1>(mod, "isinf", CPP_LAMBDA(vm->PyBool(std::isinf(vm->num_to_float(args[0])))));
vm->bind_func<1>(mod, "fabs", CPP_LAMBDA(vm->PyFloat(std::fabs(vm->num_to_float(args[0])))));
vm->bind_func<1>(mod, "floor", CPP_LAMBDA(vm->PyInt(std::floor(vm->num_to_float(args[0])))));
vm->bind_func<1>(mod, "ceil", CPP_LAMBDA(vm->PyInt(std::ceil(vm->num_to_float(args[0])))));
vm->bind_func<1>(mod, "floor", CPP_LAMBDA(vm->PyInt((i64)std::floor(vm->num_to_float(args[0])))));
vm->bind_func<1>(mod, "ceil", CPP_LAMBDA(vm->PyInt((i64)std::ceil(vm->num_to_float(args[0])))));
vm->bind_func<1>(mod, "sqrt", CPP_LAMBDA(vm->PyFloat(std::sqrt(vm->num_to_float(args[0])))));
}
@ -671,7 +671,7 @@ void add_module_re(VM* vm){
void add_module_random(VM* vm){
PyVar mod = vm->new_module("random");
std::srand(std::time(nullptr));
std::srand(std::time(0));
vm->bind_func<1>(mod, "seed", [](VM* vm, const pkpy::Args& args) {
std::srand((unsigned int)vm->PyInt_AS_C(args[0]));
return vm->None;

View File

@ -943,7 +943,8 @@ public:
}
inline void check_type(const PyVar& obj, const PyVar& type){
if(!obj->is_type(type)) TypeError("expected " + OBJ_NAME(type).escape(true) + ", but got " + OBJ_TP_NAME(obj).escape(true));
if(obj->is_type(type)) return;
TypeError("expected " + OBJ_NAME(type).escape(true) + ", but got " + OBJ_TP_NAME(obj).escape(true));
}
template<typename T>