mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
small fix
This commit is contained in:
parent
d70d2c6995
commit
d9717abc5c
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
3
src/vm.h
3
src/vm.h
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user