From 3738d07941132d22f5bce5489d11da471afa5eff Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 26 Jun 2023 19:42:18 +0800 Subject: [PATCH] ... --- build.py | 2 +- src/codeobject.h | 4 ++-- src/common.h | 2 ++ src/error.h | 2 +- src/lexer.h | 2 +- src/obj.h | 2 ++ src/vm.h | 20 +++++++++++++++++--- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/build.py b/build.py index 2880f959..66b0b1e8 100644 --- a/build.py +++ b/build.py @@ -9,7 +9,7 @@ os.system("python3 preprocess.py") def DONE(code=0): exit(code) -linux_common = "-Wfatal-errors --std=c++17 -O2 -Wall -Wno-sign-compare -Wno-unused-variable -fno-rtti -stdlib=libc++" +linux_common = "-Wfatal-errors --std=c++17 -O2 -Wall -fno-rtti -stdlib=libc++" linux_cmd = "clang++ -o pocketpy src/main.cpp " + linux_common linux_lib_cmd = "clang++ -fPIC -shared -o pocketpy.so src/tmp.cpp " + linux_common diff --git a/src/codeobject.h b/src/codeobject.h index aa817eed..406b2d4f 100644 --- a/src/codeobject.h +++ b/src/codeobject.h @@ -189,8 +189,8 @@ struct CodeObject { } ss.write_end_mark(); // ] ss.write_begin_mark(); // [ - for(StrName name: varnames){ - ss.write_name(name); // name + for(StrName vn: varnames){ + ss.write_name(vn); // name } ss.write_end_mark(); // ] ss.write_begin_mark(); // [ diff --git a/src/common.h b/src/common.h index 331dd29c..67aa0ba2 100644 --- a/src/common.h +++ b/src/common.h @@ -48,6 +48,8 @@ struct GIL { /*******************************************************************************/ +#define PK_UNUSED(x) (void)(x) + namespace pkpy{ namespace std = ::std; diff --git a/src/error.h b/src/error.h index b8e7d697..f5b86f05 100644 --- a/src/error.h +++ b/src/error.h @@ -84,7 +84,7 @@ class Exception { StackTrace stacktrace; public: Exception(StrName type, Str msg): type(type), msg(msg) {} - bool match_type(StrName type) const { return this->type == type;} + bool match_type(StrName t) const { return this->type == t;} bool is_re = true; void st_push(Str snapshot){ diff --git a/src/lexer.h b/src/lexer.h index bef7cc2b..f5312c33 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -381,7 +381,7 @@ struct Lexer { } else { add_token(TK("@num"), Number::stoi(m[0], &size, base)); } - PK_ASSERT(size == m.length()); + PK_ASSERT((int)size == (int)m.length()); }catch(std::exception& _){ SyntaxError("invalid number literal"); } diff --git a/src/obj.h b/src/obj.h index 471dd71f..0fd24697 100644 --- a/src/obj.h +++ b/src/obj.h @@ -406,6 +406,7 @@ struct Py_ final: PyObject { template<> struct Py_ final: PyObject { Py_(Type type, DummyInstance val): PyObject(type) { + PK_UNUSED(val); enable_instance_dict(); } void _obj_gc_mark() override {} @@ -423,6 +424,7 @@ struct Py_ final: PyObject { template<> struct Py_ final: PyObject { Py_(Type type, DummyModule val): PyObject(type) { + PK_UNUSED(val); enable_instance_dict(kTypeAttrLoadFactor); } void _obj_gc_mark() override {} diff --git a/src/vm.h b/src/vm.h index 2eb7a6cb..d5590d21 100644 --- a/src/vm.h +++ b/src/vm.h @@ -31,6 +31,7 @@ namespace pkpy{ return PK_OBJ_GET(ctype, obj); \ } \ template<> inline ctype _py_cast(VM* vm, PyObject* obj) { \ + PK_UNUSED(vm); \ return PK_OBJ_GET(ctype, obj); \ } \ template<> inline ctype& py_cast(VM* vm, PyObject* obj) { \ @@ -38,6 +39,7 @@ namespace pkpy{ return PK_OBJ_GET(ctype, obj); \ } \ template<> inline ctype& _py_cast(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(vm->ptype, value);} \ @@ -147,12 +149,21 @@ public: VM(bool enable_os=true) : heap(this), enable_os(enable_os) { this->vm = this; - _stdout = [](VM* vm, const Str& s) { std::cout << s; }; - _stderr = [](VM* vm, const Str& s) { std::cerr << s; }; + _stdout = [](VM* vm, const Str& s) { + PK_UNUSED(vm); + std::cout << s; + }; + _stderr = [](VM* vm, const Str& s) { + PK_UNUSED(vm); + std::cerr << s; + }; callstack.reserve(8); _main = nullptr; _last_exception = nullptr; - _import_handler = [](const Str& name) { return Bytes(); }; + _import_handler = [](const Str& name) { + PK_UNUSED(name); + return Bytes(); + }; init_builtin_types(); } @@ -706,6 +717,7 @@ template<> inline T py_cast(VM* vm, PyObject* obj){ \ return (T)(PK_BITS(obj) >> 2); \ } \ template<> inline T _py_cast(VM* vm, PyObject* obj){ \ + PK_UNUSED(vm); \ return (T)(PK_BITS(obj) >> 2); \ } @@ -810,10 +822,12 @@ inline PyObject* py_var(VM* vm, std::string_view val){ } inline PyObject* py_var(VM* vm, NoReturn val){ + PK_UNUSED(val); return vm->None; } inline PyObject* py_var(VM* vm, PyObject* val){ + PK_UNUSED(vm); return val; }