fix compile warnings

This commit is contained in:
blueloveTH 2024-02-18 16:05:14 +08:00
parent 6ed8a262a8
commit 635aae921f
10 changed files with 13 additions and 34 deletions

5
build_with_warnings.sh Normal file
View File

@ -0,0 +1,5 @@
SRC=$(find src/ -name "*.cpp")
FLAGS="-std=c++17 -O1 -stdlib=libc++ -Iinclude -W -Wno-unused-parameter -Wno-sign-compare"
clang++ $FLAGS -o main -O1 src2/main.cpp $SRC

View File

@ -27,13 +27,11 @@ struct Expr{
// for OP_DELETE_XXX
[[nodiscard]] virtual bool emit_del(CodeEmitContext* ctx) {
PK_UNUSED(ctx);
return false;
}
// for OP_STORE_XXX
[[nodiscard]] virtual bool emit_store(CodeEmitContext* ctx) {
PK_UNUSED(ctx);
return false;
}
};

View File

@ -20,7 +20,6 @@ struct FastLocals{
PyObject* operator[](int i) const { return a[i]; }
FastLocals(const CodeObject* co, PyObject** a): varnames_inv(&co->varnames_inv), a(a) {}
FastLocals(const FastLocals& other): varnames_inv(other.varnames_inv), a(other.a) {}
PyObject** try_get_name(StrName name);
NameDict_ to_namedict();

View File

@ -10,7 +10,6 @@ struct Vec2{
float x, y;
Vec2() : x(0.0f), y(0.0f) {}
Vec2(float x, float y) : x(x), y(y) {}
Vec2(const Vec2& v) = default;
Vec2 operator+(const Vec2& v) const { return Vec2(x + v.x, y + v.y); }
Vec2 operator-(const Vec2& v) const { return Vec2(x - v.x, y - v.y); }
@ -34,7 +33,6 @@ struct Vec3{
float x, y, z;
Vec3() : x(0.0f), y(0.0f), z(0.0f) {}
Vec3(float x, float y, float z) : x(x), y(y), z(z) {}
Vec3(const Vec3& v) = default;
Vec3 operator+(const Vec3& v) const { return Vec3(x + v.x, y + v.y, z + v.z); }
Vec3 operator-(const Vec3& v) const { return Vec3(x - v.x, y - v.y, z - v.z); }
@ -57,7 +55,6 @@ struct Vec4{
float x, y, z, w;
Vec4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
Vec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
Vec4(const Vec4& v) = default;
Vec4 operator+(const Vec4& v) const { return Vec4(x + v.x, y + v.y, z + v.z, w + v.w); }
Vec4 operator-(const Vec4& v) const { return Vec4(x - v.x, y - v.y, z - v.z, w - v.w); }
@ -88,7 +85,6 @@ struct Mat3x3{
Mat3x3();
Mat3x3(float, float, float, float, float, float, float, float, float);
Mat3x3(const Mat3x3& other) = default;
static Mat3x3 zeros();
static Mat3x3 ones();
@ -122,7 +118,6 @@ struct PyVec2: Vec2 {
PyVec2() : Vec2() {}
PyVec2(const Vec2& v) : Vec2(v) {}
PyVec2(const PyVec2& v) = default;
Vec2* _() { return this; }
static void _register(VM* vm, PyObject* mod, PyObject* type);
@ -133,7 +128,6 @@ struct PyVec3: Vec3 {
PyVec3() : Vec3() {}
PyVec3(const Vec3& v) : Vec3(v) {}
PyVec3(const PyVec3& v) = default;
Vec3* _() { return this; }
static void _register(VM* vm, PyObject* mod, PyObject* type);
@ -144,7 +138,6 @@ struct PyVec4: Vec4{
PyVec4(): Vec4(){}
PyVec4(const Vec4& v): Vec4(v){}
PyVec4(const PyVec4& v) = default;
Vec4* _(){ return this; }
static void _register(VM* vm, PyObject* mod, PyObject* type);
@ -155,7 +148,6 @@ struct PyMat3x3: Mat3x3{
PyMat3x3(): Mat3x3(){}
PyMat3x3(const Mat3x3& other): Mat3x3(other){}
PyMat3x3(const PyMat3x3& other) = default;
Mat3x3* _(){ return this; }
static void _register(VM* vm, PyObject* mod, PyObject* type);

View File

@ -32,7 +32,6 @@ namespace pkpy{
return PK_OBJ_GET(ctype, obj); \
} \
template<> inline ctype _py_cast<ctype>(VM* vm, PyObject* obj) { \
PK_UNUSED(vm); \
return PK_OBJ_GET(ctype, obj); \
} \
template<> inline ctype& py_cast<ctype&>(VM* vm, PyObject* obj) { \
@ -40,7 +39,6 @@ namespace pkpy{
return PK_OBJ_GET(ctype, obj); \
} \
template<> inline ctype& _py_cast<ctype&>(VM* vm, PyObject* obj) { \
PK_UNUSED(vm); \
return PK_OBJ_GET(ctype, obj); \
} \
inline PyObject* py_var(VM* vm, const ctype& value) { return vm->heap.gcnew<ctype>(vm->ptype, value);} \
@ -56,7 +54,7 @@ struct PyTypeInfo{
StrName name;
bool subclass_enabled;
std::vector<StrName> annotated_fields;
std::vector<StrName> annotated_fields = {};
// cached special methods
// unary operators
@ -316,7 +314,6 @@ public:
template<typename T, typename __T>
PyObject* bind_notimplemented_constructor(__T&& type) {
return bind_constructor<-1>(std::forward<__T>(type), [](VM* vm, ArgsView args){
PK_UNUSED(args);
vm->NotImplementedError();
return vm->None;
});
@ -473,7 +470,6 @@ template<> inline T py_cast<T>(VM* vm, PyObject* obj){ \
return 0; \
} \
template<> inline T _py_cast<T>(VM* vm, PyObject* obj){ \
PK_UNUSED(vm); \
if(is_small_int(obj)) return (T)(PK_BITS(obj) >> 2); \
return (T)PK_OBJ_GET(i64, obj); \
}
@ -534,12 +530,10 @@ PY_VAR_INT(unsigned long long)
#undef PY_VAR_INT
inline PyObject* py_var(VM* vm, float _val){
PK_UNUSED(vm);
return tag_float(static_cast<f64>(_val));
}
inline PyObject* py_var(VM* vm, double _val){
PK_UNUSED(vm);
return tag_float(static_cast<f64>(_val));
}
@ -591,7 +585,6 @@ inline PyObject* py_var(VM* vm, std::string_view val){
}
inline PyObject* py_var(VM* vm, NoReturn val){
PK_UNUSED(val);
return vm->None;
}

View File

@ -36,7 +36,6 @@ unsigned char* _default_import_handler(const char* name_p, int name_size, int* o
unsigned char* buffer = new unsigned char[buffer_size];
fseek(fp, 0, SEEK_SET);
size_t sz = io_fread(buffer, 1, buffer_size, fp);
PK_UNUSED(sz);
fclose(fp);
*out_size = buffer_size;
return buffer;

View File

@ -64,11 +64,11 @@ static bool is_unicode_Lo_char(uint32_t c) {
// https://docs.python.org/3/reference/lexical_analysis.html#indentation
if(spaces > indents.top()){
indents.push(spaces);
nexts.push_back(Token{TK("@indent"), token_start, 0, current_line, brackets_level});
nexts.push_back(Token{TK("@indent"), token_start, 0, current_line, brackets_level, {}});
} else if(spaces < indents.top()){
while(spaces < indents.top()){
indents.pop();
nexts.push_back(Token{TK("@dedent"), token_start, 0, current_line, brackets_level});
nexts.push_back(Token{TK("@dedent"), token_start, 0, current_line, brackets_level, {}});
}
if(spaces != indents.top()){
return false;
@ -467,7 +467,7 @@ static bool is_unicode_Lo_char(uint32_t c) {
Lexer::Lexer(VM* vm, std::shared_ptr<SourceData> src) : vm(vm), src(src) {
this->token_start = src->source.c_str();
this->curr_char = src->source.c_str();
this->nexts.push_back(Token{TK("@sof"), token_start, 0, current_line, brackets_level});
this->nexts.push_back(Token{TK("@sof"), token_start, 0, current_line, brackets_level, {}});
this->indents.push(0);
}

View File

@ -422,19 +422,16 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
// @staticmethod
vm->bind(type, "zeros()", [](VM* vm, ArgsView args){
PK_UNUSED(args);
return VAR_T(PyMat3x3, Mat3x3::zeros());
}, {}, BindType::STATICMETHOD);
// @staticmethod
vm->bind(type, "ones()", [](VM* vm, ArgsView args){
PK_UNUSED(args);
return VAR_T(PyMat3x3, Mat3x3::ones());
}, {}, BindType::STATICMETHOD);
// @staticmethod
vm->bind(type, "identity()", [](VM* vm, ArgsView args){
PK_UNUSED(args);
return VAR_T(PyMat3x3, Mat3x3::identity());
}, {}, BindType::STATICMETHOD);

View File

@ -1460,7 +1460,6 @@ void VM::post_init(){
// type
bind__getitem__(tp_type, [](VM* vm, PyObject* self, PyObject* _){
PK_UNUSED(_);
return self; // for generics
});

View File

@ -79,9 +79,6 @@ namespace pkpy{
_main = nullptr;
_last_exception = nullptr;
_import_handler = [](const char* name_p, int name_size, int* out_size) -> unsigned char*{
PK_UNUSED(name_p);
PK_UNUSED(name_size);
PK_UNUSED(out_size);
return nullptr;
};
init_builtin_types();