mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-26 14:30:17 +00:00
fix a bug
This commit is contained in:
parent
e61db0297b
commit
cb094331e7
15
src/cffi.h
15
src/cffi.h
@ -309,6 +309,16 @@ struct Value {
|
|||||||
this->head = Pointer(type, data);
|
this->head = Pointer(type, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value(Value&& other) noexcept {
|
||||||
|
data = other.data;
|
||||||
|
head = other.head;
|
||||||
|
other.data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Value& operator=(Value&& other) noexcept = delete;
|
||||||
|
Value& operator=(const Value& other) = delete;
|
||||||
|
Value(const Value& other) = delete;
|
||||||
|
|
||||||
static void _register(VM* vm, PyVar mod, PyVar type){
|
static void _register(VM* vm, PyVar mod, PyVar type){
|
||||||
vm->bind_static_method<-1>(type, "__new__", CPP_NOT_IMPLEMENTED());
|
vm->bind_static_method<-1>(type, "__new__", CPP_NOT_IMPLEMENTED());
|
||||||
|
|
||||||
@ -323,6 +333,10 @@ struct Value {
|
|||||||
return self.head._to(vm, name).get(vm);
|
return self.head._to(vm, name).get(vm);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~Value(){
|
||||||
|
delete[] data;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -459,6 +473,7 @@ template<typename T>
|
|||||||
std::enable_if_t<std::is_pointer_v<std::decay_t<T>>, PyVar>
|
std::enable_if_t<std::is_pointer_v<std::decay_t<T>>, PyVar>
|
||||||
py_var(VM* vm, T p){
|
py_var(VM* vm, T p){
|
||||||
const TypeInfo* type = _type_db.get<typename pointer<T>::baseT>();
|
const TypeInfo* type = _type_db.get<typename pointer<T>::baseT>();
|
||||||
|
if(type == nullptr) type = _type_db.get<void>();
|
||||||
return VAR_T(Pointer, type, pointer<T>::level, (char*)p);
|
return VAR_T(Pointer, type, pointer<T>::level, (char*)p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
56
src/vm.h
56
src/vm.h
@ -380,33 +380,27 @@ DEF_NATIVE_2(Slice, tp_slice)
|
|||||||
DEF_NATIVE_2(Exception, tp_exception)
|
DEF_NATIVE_2(Exception, tp_exception)
|
||||||
DEF_NATIVE_2(StarWrapper, tp_star_wrapper)
|
DEF_NATIVE_2(StarWrapper, tp_star_wrapper)
|
||||||
|
|
||||||
template<> i64 py_cast<i64>(VM* vm, const PyVar& obj){
|
#define PY_CAST_INT(T) \
|
||||||
vm->check_type(obj, vm->tp_int);
|
template<> T py_cast<T>(VM* vm, const PyVar& obj){ \
|
||||||
return obj.bits >> 2;
|
vm->check_type(obj, vm->tp_int); \
|
||||||
}
|
return (T)(obj.bits >> 2); \
|
||||||
template<> i64 _py_cast<i64>(VM* vm, const PyVar& obj){
|
} \
|
||||||
return obj.bits >> 2;
|
template<> T _py_cast<T>(VM* vm, const PyVar& obj){ \
|
||||||
}
|
return (T)(obj.bits >> 2); \
|
||||||
template<> f64 py_cast<f64>(VM* vm, const PyVar& obj){
|
|
||||||
vm->check_type(obj, vm->tp_float);
|
|
||||||
i64 bits = obj.bits;
|
|
||||||
bits = (bits >> 2) << 2;
|
|
||||||
return __8B(bits)._float;
|
|
||||||
}
|
|
||||||
template<> f64 _py_cast<f64>(VM* vm, const PyVar& obj){
|
|
||||||
i64 bits = obj.bits;
|
|
||||||
bits = (bits >> 2) << 2;
|
|
||||||
return __8B(bits)._float;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef PKPY_USE_32_BITS
|
PY_CAST_INT(char)
|
||||||
template<> int py_cast<int>(VM* vm, const PyVar& obj){
|
PY_CAST_INT(short)
|
||||||
vm->check_type(obj, vm->tp_int);
|
PY_CAST_INT(int)
|
||||||
return obj.bits >> 2;
|
PY_CAST_INT(long)
|
||||||
}
|
PY_CAST_INT(long long)
|
||||||
template<> int _py_cast<int>(VM* vm, const PyVar& obj){
|
PY_CAST_INT(unsigned char)
|
||||||
return obj.bits >> 2;
|
PY_CAST_INT(unsigned short)
|
||||||
}
|
PY_CAST_INT(unsigned int)
|
||||||
|
PY_CAST_INT(unsigned long)
|
||||||
|
PY_CAST_INT(unsigned long long)
|
||||||
|
|
||||||
|
|
||||||
template<> float py_cast<float>(VM* vm, const PyVar& obj){
|
template<> float py_cast<float>(VM* vm, const PyVar& obj){
|
||||||
vm->check_type(obj, vm->tp_float);
|
vm->check_type(obj, vm->tp_float);
|
||||||
i64 bits = obj.bits;
|
i64 bits = obj.bits;
|
||||||
@ -418,7 +412,17 @@ template<> float _py_cast<float>(VM* vm, const PyVar& obj){
|
|||||||
bits = (bits >> 2) << 2;
|
bits = (bits >> 2) << 2;
|
||||||
return __8B(bits)._float;
|
return __8B(bits)._float;
|
||||||
}
|
}
|
||||||
#endif
|
template<> double py_cast<double>(VM* vm, const PyVar& obj){
|
||||||
|
vm->check_type(obj, vm->tp_float);
|
||||||
|
i64 bits = obj.bits;
|
||||||
|
bits = (bits >> 2) << 2;
|
||||||
|
return __8B(bits)._float;
|
||||||
|
}
|
||||||
|
template<> double _py_cast<double>(VM* vm, const PyVar& obj){
|
||||||
|
i64 bits = obj.bits;
|
||||||
|
bits = (bits >> 2) << 2;
|
||||||
|
return __8B(bits)._float;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define PY_VAR_INT(T) \
|
#define PY_VAR_INT(T) \
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user