diff --git a/README_zh.md b/README_zh.md
index 56b1c9ca..9dbf875f 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -5,16 +5,24 @@
+
+
+
+
+
+
+
+
pocketpy 是一个轻量级的 Python 解释器,为嵌入至游戏引擎而设计,基于 C++17 和 STL。
它包含一个编译器和基于字节码的虚拟机,以及交互式命令窗的实现。所有功能均集成在单个头文件 `pocketpy.h` 中,不包含外部依赖项,能很方便地嵌入至你的应用。
-你可以 [在浏览器中体验](https://pocketpy.dev/static/web/) pocketpy 的交互式界面(REPL)。
+你可以浏览 https://pocketpy.dev 获取更多信息或是 [在浏览器中体验](https://pocketpy.dev/static/web/) pocketpy 的交互式界面(REPL)。
## 支持的平台
@@ -34,6 +42,31 @@ pkpy 支持任何拥有 C++17 编译器的平台。
你可以在 [Github Release](https://github.com/pocketpy/pocketpy/releases) 页面下载 `pocketpy.h`,
并加入到你的工程中。请参阅 https://pocketpy.dev 以获取更详细的文档。
+你也可以是用CMake从源代码开始构建。详情请见[CMakeLists.txt](https://github.com/pocketpy/pocketpy/blob/main/CMakeLists.txt)
+修改以下变量可以控制构建过程
++ `PK_BUILD_STATIC_LIB` - 构建静态库 (默认, 推荐)
++ `PK_BUILD_SHARED_LIB` - 构建动态库
+
+在生产中使用 `main` 分支是安全的。
+
+### 编译标志
+
+若要将pocketpy与你的项目一起编译,必须设置以下标志:
+
++ `--std=c++17` 标志必须被设置
++ Exception 必须被允许
++ 对于MSVC, `/utf-8` 标志必须被设置
+
+对于开发者构建,使用以下脚本
+```bash
+# 前提
+pip install cmake
+# 构建仓库
+python cmake_build.py
+# 单元测试
+python scripts/run_tests.py
+```
+
```cpp
#include "pocketpy.h"
@@ -96,10 +129,62 @@ int main(){
| 生成器 | `yield i` | ✅ |
| 装饰器 | `@cache` | ✅ |
+## 性能
+
+目前,pkpy的速度与cpython 3.9一样快。
+cpython 3.9的性能结果适用于pkpy。
+访问 https://pocketpy.dev/performance/ 以获取详细信息。
+以下是 Intel i5-12400F、WSL(Ubuntu 20.04 LTS)上的primes基准测试的结果,大致反映了c++、lua、pkpy和cpython之间的性能。
+
+| name | version | time | file |
+| ---- | ---- | ---- | ---- |
+| c++ | gnu++11 | `0.104s ■□□□□□□□□□□□□□□□` | [benchmarks/primes.cpp](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.cpp) |
+| lua | 5.3.3 | `1.576s ■■■■■■■■■□□□□□□□` | [benchmarks/primes.lua](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.lua) |
+| pkpy | 1.2.7 | `2.385s ■■■■■■■■■■■■■□□□` | [benchmarks/primes.py](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) |
+| cpython | 3.8.10 | `2.871s ■■■■■■■■■■■■■■■■` | [benchmarks/primes.py](https://github.com/pocketpy/pocketpy/blob/9481d653b60b81f4590a4d48f2be496f6962261e/benchmarks/primes.py) |
+
+## 被使用
+
+| | Description |
+|-----------------------------------------------------------------|--------------------------------------------------------------------------|
+| [TIC-80](https://github.com/nesbox/TIC-80) | TIC-80 is a fantasy computer for making, playing and sharing tiny games. |
+| [MiniPythonIDE](https://github.com/CU-Production/MiniPythonIDE) | A python ide base on pocketpy |
+| [py-js](https://github.com/shakfu/py-js) | Python3 externals for Max / MSP |
+| [crescent](https://github.com/chukobyte/crescent) | Crescent is a cross-platform 2D fighting and beat-em-up game engine. |
+
+如果你想添加你的项目,请提交一个pr
+
+## 贡献
+
+任何形式的共享都是受欢迎的
+
+- 提交pr
+ - 修复错误
+ - 添加新的特性
+- 打开Issue
+ - 任何的建议
+ - 任何的疑问
+
+如果你觉得pkpy有用,就给这个仓库一颗星星吧 (●'◡'●)
+
+## 赞助这个项目
+
+你可以通过以下途径赞助这个项目
+
++ [Github Sponsors](https://github.com/sponsors/blueloveTH)
++ [Buy me a coffee](https://www.buymeacoffee.com/blueloveth)
+
+您的赞助将帮助我们不断发展pkpy。
+
## 参考
+ [cpython](https://github.com/python/cpython)
+ [byterun](http://qingyunha.github.io/taotao/)
++ [box2d](https://box2d.org/)
+
+## 历史
+
+[](https://star-history.com/#blueloveth/pocketpy&Date)
## 开源协议
diff --git a/include/pocketpy/bindings.h b/include/pocketpy/bindings.h
index 1cc1dac0..b8da8d13 100644
--- a/include/pocketpy/bindings.h
+++ b/include/pocketpy/bindings.h
@@ -158,7 +158,7 @@ void _bind(VM* vm, PyObject* obj, const char* sig, Ret(T::*func)(Params...)){
wT& self = _CAST(wT&, args[0]); \
return VAR_T(wT, *self._()); \
}); \
- vm->bind_method<0>(type, "sizeof", [](VM* vm, ArgsView args){ \
+ vm->bind_method<0>(type, "sizeof", [](VM* vm,[[maybe_unused]] ArgsView args){ \
return VAR(sizeof(vT)); \
}); \
vm->bind__eq__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* _0, PyObject* _1){ \
diff --git a/include/pocketpy/common.h b/include/pocketpy/common.h
index e7ca0603..a5f548c4 100644
--- a/include/pocketpy/common.h
+++ b/include/pocketpy/common.h
@@ -164,7 +164,7 @@ struct Type {
operator int() const { return this->index; }
};
-#define PK_LAMBDA(x) ([](VM* vm, ArgsView args) { return x; })
+#define PK_LAMBDA(x) ([](VM* vm, [[maybe_unused]] ArgsView args) { return x; })
#define PK_VAR_LAMBDA(x) ([](VM* vm, ArgsView args) { return VAR(x); })
#define PK_ACTION(x) ([](VM* vm, ArgsView args) { x; return vm->None; })
diff --git a/include/pocketpy/compiler.h b/include/pocketpy/compiler.h
index 133171a0..e674e06f 100644
--- a/include/pocketpy/compiler.h
+++ b/include/pocketpy/compiler.h
@@ -33,7 +33,7 @@ class Compiler {
const Token& curr() const{ return tokens.at(i); }
const Token& next() const{ return tokens.at(i+1); }
const Token& err() const{
- if(i >= tokens.size()) return prev();
+ if(i >= static_cast(tokens.size())) return prev();
return curr();
}
void advance(int delta=1) { i += delta; }
diff --git a/include/pocketpy/namedict.h b/include/pocketpy/namedict.h
index 0dff0104..980331e3 100644
--- a/include/pocketpy/namedict.h
+++ b/include/pocketpy/namedict.h
@@ -309,7 +309,7 @@ struct NameDictImpl{
std::vector keys() const{
std::vector v;
- apply([&](StrName key, V val){
+ apply([&](StrName key,[[maybe_unused]] V val){
v.push_back(key);
});
return v;
diff --git a/include/pocketpy/obj.h b/include/pocketpy/obj.h
index 2b97c0fd..a69788d8 100644
--- a/include/pocketpy/obj.h
+++ b/include/pocketpy/obj.h
@@ -202,7 +202,7 @@ struct MappingProxy{
inline void gc_mark_namedict(NameDict& t){
if(t.size() == 0) return;
- t.apply([](StrName name, PyObject* obj){
+ t.apply([]([[maybe_unused]]StrName name, PyObject* obj){
PK_OBJ_MARK(obj);
});
}
@@ -230,7 +230,7 @@ __T py_cast(VM* vm, PyObject* obj) {
}
template
-__T _py_cast(VM* vm, PyObject* obj) {
+__T _py_cast([[maybe_unused]]VM* vm, PyObject* obj) {
using T = std::decay_t<__T>;
if constexpr(std::is_enum_v){
return (__T)_py_cast(vm, obj);
diff --git a/include/pocketpy/vm.h b/include/pocketpy/vm.h
index 9c6973ad..9a2d14c3 100644
--- a/include/pocketpy/vm.h
+++ b/include/pocketpy/vm.h
@@ -416,7 +416,7 @@ public:
ImportContext _import_context;
PyObject* py_import(Str path, bool throw_err=true);
- ~VM();
+ virtual ~VM();
#if PK_DEBUG_CEVAL_STEP
void _log_s_data(const char* title = nullptr);
@@ -570,7 +570,7 @@ template<> inline CString py_cast(VM* vm, PyObject* obj){
return PK_OBJ_GET(Str, obj).c_str();
}
-template<> inline CString _py_cast(VM* vm, PyObject* obj){
+template<> inline CString _py_cast([[maybe_unused]]VM* vm, PyObject* obj){
return PK_OBJ_GET(Str, obj).c_str();
}
@@ -586,7 +586,7 @@ inline const char* py_cast(VM* vm, PyObject* obj){
}
template<>
-inline const char* _py_cast(VM* vm, PyObject* obj){
+inline const char* _py_cast([[maybe_unused]]VM* vm, PyObject* obj){
return PK_OBJ_GET(Str, obj).c_str();
}
diff --git a/src/array2d.cpp b/src/array2d.cpp
index aa40cc7c..1710d75d 100644
--- a/src/array2d.cpp
+++ b/src/array2d.cpp
@@ -39,7 +39,7 @@ struct Array2d{
data[row * n_cols + col] = value;
}
- static void _register(VM* vm, PyObject* mod, PyObject* type){
+ static void _register(VM* vm,[[maybe_unused]] PyObject* mod, PyObject* type){
vm->bind(type, "__new__(cls, *args, **kwargs)", [](VM* vm, ArgsView args){
Type cls = PK_OBJ_GET(Type, args[0]);
return vm->heap.gcnew(cls);
@@ -115,7 +115,7 @@ struct Array2d{
return vm->py_iter(VAR(std::move(t)));
});
- vm->bind__len__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* _0){
+ vm->bind__len__(PK_OBJ_GET(Type, type), []([[maybe_unused]]VM* vm, PyObject* _0){
Array2d& self = PK_OBJ_GET(Array2d, _0);
return (i64)self.n_rows;
});
diff --git a/src/cffi.cpp b/src/cffi.cpp
index 6685904a..487c53d4 100644
--- a/src/cffi.cpp
+++ b/src/cffi.cpp
@@ -2,14 +2,14 @@
namespace pkpy{
- void VoidP::_register(VM* vm, PyObject* mod, PyObject* type){
+ void VoidP::_register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
vm->bind_constructor<2>(type, [](VM* vm, ArgsView args){
Type cls = PK_OBJ_GET(Type, args[0]);
i64 addr = CAST(i64, args[1]);
return vm->heap.gcnew(cls, reinterpret_cast(addr));
});
- vm->bind__hash__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
+ vm->bind__hash__(PK_OBJ_GET(Type, type), []([[maybe_unused]] VM* vm, PyObject* obj){
VoidP& self = PK_OBJ_GET(VoidP, obj);
return reinterpret_cast(self.ptr);
});
@@ -37,7 +37,7 @@ namespace pkpy{
}
- void C99Struct::_register(VM* vm, PyObject* mod, PyObject* type){
+ void C99Struct::_register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
vm->bind_constructor<2>(type, [](VM* vm, ArgsView args){
Type cls = PK_OBJ_GET(Type, args[0]);
int size = CAST(int, args[1]);
diff --git a/src/collections.cpp b/src/collections.cpp
index bb2a99cd..cf9e3a20 100644
--- a/src/collections.cpp
+++ b/src/collections.cpp
@@ -22,13 +22,13 @@ namespace pkpy
void _gc_mark() const { PK_OBJ_MARK(ref); }
static void _register(VM *vm, PyObject *mod, PyObject *type);
};
- void PyDequeIter::_register(VM *vm, PyObject *mod, PyObject *type)
+ void PyDequeIter::_register(VM *vm, [[maybe_unused]] PyObject *mod, PyObject *type)
{
// Iterator for the deque type
vm->_all_types[PK_OBJ_GET(Type, type)].subclass_enabled = false;
vm->bind_notimplemented_constructor(type);
- vm->bind__iter__(PK_OBJ_GET(Type, type), [](VM *vm, PyObject *obj)
+ vm->bind__iter__(PK_OBJ_GET(Type, type), []([[maybe_unused]] VM *vm, PyObject *obj)
{ return obj; });
vm->bind__next__(PK_OBJ_GET(Type, type), [](VM *vm, PyObject *obj)
{
@@ -61,7 +61,7 @@ namespace pkpy
static void _register(VM *vm, PyObject *mod, PyObject *type); // register the type
void _gc_mark() const; // needed for container types, mark all objects in the deque for gc
};
- void PyDeque::_register(VM *vm, PyObject *mod, PyObject *type)
+ void PyDeque::_register(VM *vm, [[maybe_unused]] PyObject *mod, PyObject *type)
{
vm->bind(type, "__new__(cls, iterable=None, maxlen=None)",
[](VM *vm, ArgsView args)
@@ -137,7 +137,7 @@ namespace pkpy
if(!is_non_tagged_type(_0, PyDeque::_type(vm))) return vm->NotImplemented;
const PyDeque &other = _CAST(PyDeque&, _1);
if (self.dequeItems.size() != other.dequeItems.size()) return vm->False;
- for (int i = 0; i < self.dequeItems.size(); i++){
+ for (int i = 0; i < static_cast(self.dequeItems.size()); i++){
if (vm->py_ne(self.dequeItems[i], other.dequeItems[i])) return vm->False;
}
return vm->True;
@@ -231,7 +231,7 @@ namespace pkpy
{
if (vm->py_eq((*it), obj))
cnt++;
- if (sz != self.dequeItems.size())// mutating the deque during iteration is not allowed
+ if (sz != static_cast(self.dequeItems.size()))// mutating the deque during iteration is not allowed
vm->RuntimeError("deque mutated during iteration");
}
return VAR(cnt);
@@ -290,7 +290,7 @@ namespace pkpy
PyDeque &self = _CAST(PyDeque &, args[0]);
int index = CAST(int, args[1]);
PyObject *obj = args[2];
- if (self.bounded && self.dequeItems.size() == self.maxlen)
+ if (self.bounded && static_cast(self.dequeItems.size()) == self.maxlen)
vm->IndexError("deque already at its maximum size");
else
self.insertObj(false, false, index, obj); // this index shouldn't be fixed using vm->normalized_index, pass as is
@@ -364,7 +364,7 @@ namespace pkpy
return VAR(self.maxlen);
return vm->None;
},
- [](VM *vm, ArgsView args)
+ [](VM *vm, [[maybe_unused]] ArgsView args)
{
vm->AttributeError("attribute 'maxlen' of 'collections.deque' objects is not writable");
return vm->None;
diff --git a/src/compiler.cpp b/src/compiler.cpp
index 4c97fc9f..fd510576 100644
--- a/src/compiler.cpp
+++ b/src/compiler.cpp
@@ -51,7 +51,7 @@ namespace pkpy{
SyntaxError("maximum number of opcodes exceeded");
}
// pre-compute LOOP_BREAK and LOOP_CONTINUE and FOR_ITER
- for(int i=0; i(codes.size()); i++){
Bytecode& bc = codes[i];
if(bc.op == OP_LOOP_CONTINUE){
bc.arg = ctx()->co->blocks[bc.arg].start;
diff --git a/src/csv.cpp b/src/csv.cpp
index 78a1bd4e..d86edb9b 100644
--- a/src/csv.cpp
+++ b/src/csv.cpp
@@ -20,11 +20,11 @@ void add_module_csv(VM *vm){
std::string buffer;
__NEXT_LINE:
j = 0;
- while(j < line.size()){
+ while(j < static_cast(line.size())){
switch(line[j]){
case '"':
if(in_quote){
- if(j+1 < line.size() && line[j+1] == '"'){
+ if(j+1 < static_cast(line.size()) && line[j+1] == '"'){
buffer += '"';
j++;
}else{
diff --git a/src/error.cpp b/src/error.cpp
index 07dbb074..1126e744 100644
--- a/src/error.cpp
+++ b/src/error.cpp
@@ -8,7 +8,7 @@ namespace pkpy{
if (strncmp(source.data(), "\xEF\xBB\xBF", 3) == 0) index += 3;
// Drop all '\r'
SStream ss(source.size() + 1);
- while(index < source.size()){
+ while(index < static_cast(source.size())){
if(source[index] != '\r') ss << source[index];
index++;
}
diff --git a/src/expr.cpp b/src/expr.cpp
index 208c78b4..1d5ec197 100644
--- a/src/expr.cpp
+++ b/src/expr.cpp
@@ -327,7 +327,7 @@ namespace pkpy{
// TOS is an iterable
// items may contain StarredExpr, we should check it
int starred_i = -1;
- for(int i=0; i(items.size()); i++){
if(!items[i]->is_starred()) continue;
if(starred_i == -1) starred_i = i;
else return false; // multiple StarredExpr not allowed
@@ -346,7 +346,7 @@ namespace pkpy{
// starred assignment target must be in a tuple
if(items.size() == 1) return false;
// starred assignment target must be the last one (differ from cpython)
- if(starred_i != items.size()-1) return false;
+ if(starred_i != static_cast(items.size()-1)) return false;
// a,*b = [1,2,3]
// stack is [1,2,3] -> [1,[2,3]]
ctx->emit_(OP_UNPACK_EX, items.size()-1, line);
diff --git a/src/frame.cpp b/src/frame.cpp
index b5030ccb..a4c127a3 100644
--- a/src/frame.cpp
+++ b/src/frame.cpp
@@ -50,7 +50,7 @@ namespace pkpy{
void Frame::jump_abs_break(int target){
int i = co->iblocks[_ip];
_next_ip = target;
- if(_next_ip >= co->codes.size()){
+ if(_next_ip >= static_cast(co->codes.size())){
while(i>=0) i = _exit_block(i);
}else{
// BUG (solved)
diff --git a/src/gc.cpp b/src/gc.cpp
index 207e1975..7ceab948 100644
--- a/src/gc.cpp
+++ b/src/gc.cpp
@@ -62,7 +62,7 @@ namespace pkpy{
void FuncDecl::_gc_mark() const{
code->_gc_mark();
- for(int i=0; i(kwargs.size()); i++) PK_OBJ_MARK(kwargs[i].value);
}
} // namespace pkpy
\ No newline at end of file
diff --git a/src/io.cpp b/src/io.cpp
index 13be5671..bb9130a7 100644
--- a/src/io.cpp
+++ b/src/io.cpp
@@ -24,7 +24,7 @@ static size_t io_fread(void* buffer, size_t size, size_t count, FILE* fp){
#endif
-unsigned char* _default_import_handler(const char* name_p, int name_size, int* out_size){
+unsigned char* _default_import_handler([[maybe_unused]] const char* name_p, [[maybe_unused]] int name_size,[[maybe_unused]] int* out_size){
#if PK_ENABLE_OS
std::string name(name_p, name_size);
bool exists = std::filesystem::exists(std::filesystem::path(name));
@@ -109,7 +109,7 @@ unsigned char* _default_import_handler(const char* name_p, int name_size, int* o
#endif
-void add_module_io(VM* vm){
+void add_module_io([[maybe_unused]] VM* vm){
#if PK_ENABLE_OS
PyObject* mod = vm->new_module("io");
FileIO::register_class(vm, mod);
@@ -121,7 +121,7 @@ void add_module_io(VM* vm){
#endif
}
-void add_module_os(VM* vm){
+void add_module_os([[maybe_unused]] VM* vm){
#if PK_ENABLE_OS
PyObject* mod = vm->new_module("os");
PyObject* path_obj = vm->heap.gcnew(vm->tp_object);
diff --git a/src/iter.cpp b/src/iter.cpp
index eabc4790..4b176709 100644
--- a/src/iter.cpp
+++ b/src/iter.cpp
@@ -2,10 +2,10 @@
namespace pkpy{
- void RangeIter::_register(VM* vm, PyObject* mod, PyObject* type){
+ void RangeIter::_register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
vm->_all_types[PK_OBJ_GET(Type, type)].subclass_enabled = false;
vm->bind_notimplemented_constructor(type);
- vm->bind__iter__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){ return obj; });
+ vm->bind__iter__(PK_OBJ_GET(Type, type), []([[maybe_unused]] VM* vm, PyObject* obj){ return obj; });
vm->bind__next__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
RangeIter& self = _CAST(RangeIter&, obj);
bool has_next = self.r.step > 0 ? self.current < self.r.stop : self.current > self.r.stop;
@@ -15,10 +15,10 @@ namespace pkpy{
});
}
- void ArrayIter::_register(VM* vm, PyObject* mod, PyObject* type){
+ void ArrayIter::_register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
vm->_all_types[PK_OBJ_GET(Type, type)].subclass_enabled = false;
vm->bind_notimplemented_constructor(type);
- vm->bind__iter__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){ return obj; });
+ vm->bind__iter__(PK_OBJ_GET(Type, type), []([[maybe_unused]] VM* vm, PyObject* obj){ return obj; });
vm->bind__next__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
ArrayIter& self = _CAST(ArrayIter&, obj);
if(self.current == self.end) return vm->StopIteration;
@@ -26,10 +26,10 @@ namespace pkpy{
});
}
- void StringIter::_register(VM* vm, PyObject* mod, PyObject* type){
+ void StringIter::_register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
vm->_all_types[PK_OBJ_GET(Type, type)].subclass_enabled = false;
vm->bind_notimplemented_constructor(type);
- vm->bind__iter__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){ return obj; });
+ vm->bind__iter__(PK_OBJ_GET(Type, type), []([[maybe_unused]] VM* vm, PyObject* obj){ return obj; });
vm->bind__next__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
StringIter& self = _CAST(StringIter&, obj);
if(self.index == self.str->size) return vm->StopIteration;
@@ -73,10 +73,10 @@ namespace pkpy{
}
}
- void Generator::_register(VM* vm, PyObject* mod, PyObject* type){
+ void Generator::_register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
vm->_all_types[PK_OBJ_GET(Type, type)].subclass_enabled = false;
vm->bind_notimplemented_constructor(type);
- vm->bind__iter__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){ return obj; });
+ vm->bind__iter__(PK_OBJ_GET(Type, type), []([[maybe_unused]] VM* vm, PyObject* obj){ return obj; });
vm->bind__next__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
Generator& self = _CAST(Generator&, obj);
return self.next(vm);
diff --git a/src/linalg.cpp b/src/linalg.cpp
index 72b232f2..f67774e6 100644
--- a/src/linalg.cpp
+++ b/src/linalg.cpp
@@ -105,7 +105,7 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
return Vec2(output_x, output_y);
}
- void PyVec2::_register(VM* vm, PyObject* mod, PyObject* type){
+ void PyVec2::_register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
PY_STRUCT_LIKE(PyVec2)
vm->bind_constructor<3>(type, [](VM* vm, ArgsView args){
@@ -174,7 +174,7 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
BIND_VEC_FUNCTION_0(2, normalize_)
}
- void PyVec3::_register(VM* vm, PyObject* mod, PyObject* type){
+ void PyVec3::_register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
PY_STRUCT_LIKE(PyVec3)
vm->bind_constructor<4>(type, [](VM* vm, ArgsView args){
@@ -208,7 +208,7 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
BIND_VEC_FUNCTION_0(3, normalize_)
}
- void PyVec4::_register(VM* vm, PyObject* mod, PyObject* type){
+ void PyVec4::_register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
PY_STRUCT_LIKE(PyVec4)
vm->bind_constructor<1+4>(type, [](VM* vm, ArgsView args){
@@ -248,7 +248,7 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, PyVec2& currentVelocity, float
#undef BIND_VEC_FUNCTION_0
#undef BIND_VEC_FUNCTION_1
- void PyMat3x3::_register(VM* vm, PyObject* mod, PyObject* type){
+ void PyMat3x3::_register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
PY_STRUCT_LIKE(PyMat3x3)
vm->bind_constructor<-1>(type, [](VM* vm, ArgsView args){
diff --git a/src/modules.cpp b/src/modules.cpp
index acb08f17..509682f2 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -40,7 +40,7 @@ struct PyStructTime{
PyStructTime* _() { return this; }
- static void _register(VM* vm, PyObject* mod, PyObject* type){
+ static void _register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
vm->bind_notimplemented_constructor(type);
PY_READONLY_FIELD(PyStructTime, "tm_year", _, tm_year);
PY_READONLY_FIELD(PyStructTime, "tm_mon", _, tm_mon);
@@ -58,7 +58,7 @@ void add_module_time(VM* vm){
PyObject* mod = vm->new_module("time");
PyStructTime::register_class(vm, mod);
- vm->bind_func<0>(mod, "time", [](VM* vm, ArgsView args) {
+ vm->bind_func<0>(mod, "time", [](VM* vm, [[maybe_unused]] ArgsView args) {
auto now = std::chrono::system_clock::now();
return VAR(std::chrono::duration_cast(now.time_since_epoch()).count() / 1000.0);
});
@@ -74,7 +74,7 @@ void add_module_time(VM* vm){
return vm->None;
});
- vm->bind_func<0>(mod, "localtime", [](VM* vm, ArgsView args) {
+ vm->bind_func<0>(mod, "localtime", [](VM* vm, [[maybe_unused]] ArgsView args) {
auto now = std::chrono::system_clock::now();
std::time_t t = std::chrono::system_clock::to_time_t(now);
return VAR_T(PyStructTime, t);
@@ -206,14 +206,14 @@ void add_module_math(VM* vm){
void add_module_traceback(VM* vm){
PyObject* mod = vm->new_module("traceback");
- vm->bind_func<0>(mod, "print_exc", [](VM* vm, ArgsView args) {
+ vm->bind_func<0>(mod, "print_exc", [](VM* vm, [[maybe_unused]] ArgsView args) {
if(vm->_last_exception==nullptr) vm->ValueError("no exception");
Exception& e = _CAST(Exception&, vm->_last_exception);
vm->stdout_write(e.summary());
return vm->None;
});
- vm->bind_func<0>(mod, "format_exc", [](VM* vm, ArgsView args) {
+ vm->bind_func<0>(mod, "format_exc", [](VM* vm, [[maybe_unused]] ArgsView args) {
if(vm->_last_exception==nullptr) vm->ValueError("no exception");
Exception& e = _CAST(Exception&, vm->_last_exception);
return VAR(e.summary());
@@ -258,7 +258,7 @@ struct LineProfilerW{
LineProfiler profiler;
- static void _register(VM* vm, PyObject* mod, PyObject* type){
+ static void _register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
vm->bind_default_constructor(type);
vm->bind(type, "add_function(self, func)", [](VM* vm, ArgsView args){
diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp
index 866d3e2b..bc36fe3d 100644
--- a/src/pocketpy.cpp
+++ b/src/pocketpy.cpp
@@ -109,7 +109,7 @@ void init_builtins(VM* _vm) {
return VAR(vm->issubclass(PK_OBJ_GET(Type, args[0]), PK_OBJ_GET(Type, args[1])));
});
- _vm->bind_func<0>(_vm->builtins, "globals", [](VM* vm, ArgsView args) {
+ _vm->bind_func<0>(_vm->builtins, "globals", [](VM* vm, [[maybe_unused]] ArgsView args) {
PyObject* mod = vm->top_frame()->_module;
return VAR(MappingProxy(mod));
});
@@ -340,7 +340,7 @@ void init_builtins(VM* _vm) {
_vm->bind__iter__(VM::tp_range, [](VM* vm, PyObject* obj) { return VAR_T(RangeIter, PK_OBJ_GET(Range, obj)); });
// tp_nonetype
- _vm->bind__repr__(_vm->_tp(_vm->None), [](VM* vm, PyObject* _0) {
+ _vm->bind__repr__(_vm->_tp(_vm->None), [](VM* vm, [[maybe_unused]] PyObject* _0) {
return VAR("None");
});
@@ -501,7 +501,7 @@ void init_builtins(VM* _vm) {
const Str& self = _CAST(Str&, _0);
return VAR(self.index(CAST(Str&, _1)) != -1);
});
- _vm->bind__str__(VM::tp_str, [](VM* vm, PyObject* _0) { return _0; });
+ _vm->bind__str__(VM::tp_str, []([[maybe_unused]] VM* vm, PyObject* _0) { return _0; });
_vm->bind__iter__(VM::tp_str, [](VM* vm, PyObject* _0) { return VAR_T(StringIter, _0); });
_vm->bind__repr__(VM::tp_str, [](VM* vm, PyObject* _0) {
const Str& self = _CAST(Str&, _0);
@@ -554,7 +554,7 @@ void init_builtins(VM* _vm) {
parts = self.split(sep);
}
List ret(parts.size());
- for(int i=0; i(parts.size()); i++) ret[i] = VAR(Str(parts[i]));
return VAR(std::move(ret));
});
@@ -563,7 +563,7 @@ void init_builtins(VM* _vm) {
std::vector parts;
parts = self.split('\n');
List ret(parts.size());
- for(int i=0; i(parts.size()); i++) ret[i] = VAR(Str(parts[i]));
return VAR(std::move(ret));
});
@@ -1014,10 +1014,10 @@ void init_builtins(VM* _vm) {
});
// tp_ellipsis / tp_NotImplementedType
- _vm->bind__repr__(_vm->_tp(_vm->Ellipsis), [](VM* vm, PyObject* _0) {
+ _vm->bind__repr__(_vm->_tp(_vm->Ellipsis), [](VM* vm, [[maybe_unused]] PyObject* _0) {
return VAR("...");
});
- _vm->bind__repr__(_vm->_tp(_vm->NotImplemented), [](VM* vm, PyObject* _0) {
+ _vm->bind__repr__(_vm->_tp(_vm->NotImplemented), [](VM* vm, [[maybe_unused]] PyObject* _0) {
return VAR("NotImplemented");
});
@@ -1173,7 +1173,7 @@ void init_builtins(VM* _vm) {
});
// tp_dict
- _vm->bind_constructor<-1>(_vm->_t(VM::tp_dict), [](VM* vm, ArgsView args){
+ _vm->bind_constructor<-1>(_vm->_t(VM::tp_dict), [](VM* vm, [[maybe_unused]] ArgsView args){
return VAR(Dict(vm));
});
@@ -1416,7 +1416,7 @@ void init_builtins(VM* _vm) {
void VM::post_init(){
init_builtins(this);
- bind_method<-1>(tp_module, "__init__", [](VM* vm, ArgsView args) {
+ bind_method<-1>(tp_module, "__init__", [](VM* vm, [[maybe_unused]] ArgsView args) {
vm->NotImplementedError();
return vm->None;
});
@@ -1435,7 +1435,7 @@ void VM::post_init(){
});
// type
- bind__getitem__(tp_type, [](VM* vm, PyObject* self, PyObject* _){
+ bind__getitem__(tp_type, []([[maybe_unused]] VM* vm, PyObject* self, PyObject* _){
PK_UNUSED(_);
return self; // for generics
});
diff --git a/src/pocketpy_c.cpp b/src/pocketpy_c.cpp
index 22982086..daebd7c0 100644
--- a/src/pocketpy_c.cpp
+++ b/src/pocketpy_c.cpp
@@ -19,7 +19,7 @@ typedef int (*LuaStyleFuncC)(VM*);
if(vm->_c.error != nullptr) \
return false;
-static int count_extra_elements(VM* vm, int n){
+static int count_extra_elements(VM* vm, [[maybe_unused]] int n){
if(vm->callstack.empty()){
return vm->s_data.size();
}
diff --git a/src/random.cpp b/src/random.cpp
index 2b06c856..aac70bb9 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -10,7 +10,7 @@ struct Random{
gen.seed(std::chrono::high_resolution_clock::now().time_since_epoch().count());
}
- static void _register(VM* vm, PyObject* mod, PyObject* type){
+ static void _register(VM* vm, [[maybe_unused]] PyObject* mod, PyObject* type){
vm->bind_default_constructor(type);
vm->bind_method<1>(type, "seed", [](VM* vm, ArgsView args) {
diff --git a/src/repl.cpp b/src/repl.cpp
index 6d9b0941..b63746de 100644
--- a/src/repl.cpp
+++ b/src/repl.cpp
@@ -15,7 +15,7 @@ namespace pkpy {
buffer += '\n';
int n = buffer.size();
if(n>=need_more_lines){
- for(int i=buffer.size()-need_more_lines; i(buffer.size()); i++){
// no enough lines
if(buffer[i] != '\n') return true;
}