From 29c2618c9e806272d2cf4c299aff9254ea168bf1 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 6 Dec 2022 04:45:36 +0800 Subject: [PATCH] some fix --- build_cpp.sh | 2 +- plugins/flutter/README.md | 5 +++++ plugins/flutter/src/pocketpy.h | 17 +++++++++-------- src/codeobject.h | 7 +++---- src/compiler.h | 2 +- src/iter.h | 2 +- src/main.cpp | 8 +++++--- src/obj.h | 3 ++- src/pointer.h | 1 + src/vm.h | 2 +- 10 files changed, 29 insertions(+), 20 deletions(-) diff --git a/build_cpp.sh b/build_cpp.sh index b34d05d9..c49ffc67 100644 --- a/build_cpp.sh +++ b/build_cpp.sh @@ -1 +1 @@ -g++ -o pocketpy src/main.cpp --std=c++17 -O1 -pthread \ No newline at end of file +g++ -o pocketpy src/main.cpp --std=c++17 -O1 -pthread -Wall -Wno-sign-compare -Wno-unused-variable \ No newline at end of file diff --git a/plugins/flutter/README.md b/plugins/flutter/README.md index 93c9789b..58920823 100644 --- a/plugins/flutter/README.md +++ b/plugins/flutter/README.md @@ -32,10 +32,15 @@ PocketPy is a lightweight Python interpreter for game engines. For features that are PocketPy specific, see [Extra Features](https://pocketpy.dev/extras/goto). ## Introduction +

+ +

+ This plugin provides object-oriented interfaces including full functionality of PocketPy [C-API](https://pocketpy.dev/c-api/vm). It also provides `JsonRpcServer` class and `os` module bindings. Run the following script to install this plugin. + ``` flutter pub add pocketpy ``` diff --git a/plugins/flutter/src/pocketpy.h b/plugins/flutter/src/pocketpy.h index e6b95113..8767037b 100644 --- a/plugins/flutter/src/pocketpy.h +++ b/plugins/flutter/src/pocketpy.h @@ -2970,13 +2970,14 @@ struct _Slice { class _Iterator { protected: - PyVar _ref; // keep a reference to the object so it will not be deleted while iterating VM* vm; + PyVar _ref; // keep a reference to the object so it will not be deleted while iterating public: virtual PyVar next() = 0; virtual bool hasNext() = 0; _Pointer var; _Iterator(VM* vm, PyVar _ref) : vm(vm), _ref(_ref) {} + virtual ~_Iterator() = default; }; typedef pkpy::shared_ptr _Func; @@ -3055,7 +3056,7 @@ public: class StringIterator : public _Iterator { private: - size_t index = 0; + int index = 0; _Str str; public: StringIterator(VM* vm, PyVar _ref) : _Iterator(vm, _ref) { @@ -3389,6 +3390,7 @@ struct BasePointer { virtual PyVar get(VM*, Frame*) const = 0; virtual void set(VM*, Frame*, PyVar) const = 0; virtual void del(VM*, Frame*) const = 0; + virtual ~BasePointer() = default; }; enum NameScope { @@ -3713,6 +3715,7 @@ private: int ip = 0; std::stack forLoops; // record the FOR_ITER bytecode index public: + const CodeObject* code; PyVar _module; PyVarDict f_locals; @@ -3722,8 +3725,6 @@ public: return _module->attribs; } - const CodeObject* code; - Frame(const CodeObject* code, PyVar _module, const PyVarDict& locals) : code(code), _module(_module), f_locals(locals) { @@ -3815,13 +3816,13 @@ public: pkpy::ArgList popNValuesReversed(VM* vm, int n){ pkpy::ArgList v(n); - for(int i=n-1; i>=0; i--) v._index(i) = std::move(popValue(vm)); + for(int i=n-1; i>=0; i--) v._index(i) = popValue(vm); return v; } pkpy::ArgList __popNReversed(int n){ pkpy::ArgList v(n); - for(int i=n-1; i>=0; i--) v._index(i) = std::move(__pop()); + for(int i=n-1; i>=0; i--) v._index(i) = __pop(); return v; } }; @@ -4361,7 +4362,7 @@ public: try { return _exec(code, _module, {}); } catch (const std::exception& e) { - if(const _Error* _ = dynamic_cast(&e)){ + if(dynamic_cast(&e)){ *_stderr << e.what() << '\n'; }else{ auto re = RuntimeError("UnexpectedError", e.what(), _cleanErrorAndGetSnapshots()); @@ -6012,7 +6013,7 @@ _Code compile(VM* vm, const char* source, _Str filename, CompileMode mode=EXEC_M try{ return compiler.__fillCode(); }catch(std::exception& e){ - if(const _Error* _ = dynamic_cast(&e)){ + if(dynamic_cast(&e)){ (*vm->_stderr) << e.what() << '\n'; }else{ auto ce = CompileError("UnexpectedError", e.what(), compiler.getLineSnapshot()); diff --git a/src/codeobject.h b/src/codeobject.h index a2472569..9c70a0cd 100644 --- a/src/codeobject.h +++ b/src/codeobject.h @@ -127,6 +127,7 @@ private: int ip = 0; std::stack forLoops; // record the FOR_ITER bytecode index public: + const CodeObject* code; PyVar _module; PyVarDict f_locals; @@ -136,8 +137,6 @@ public: return _module->attribs; } - const CodeObject* code; - Frame(const CodeObject* code, PyVar _module, const PyVarDict& locals) : code(code), _module(_module), f_locals(locals) { @@ -229,13 +228,13 @@ public: pkpy::ArgList popNValuesReversed(VM* vm, int n){ pkpy::ArgList v(n); - for(int i=n-1; i>=0; i--) v._index(i) = std::move(popValue(vm)); + for(int i=n-1; i>=0; i--) v._index(i) = popValue(vm); return v; } pkpy::ArgList __popNReversed(int n){ pkpy::ArgList v(n); - for(int i=n-1; i>=0; i--) v._index(i) = std::move(__pop()); + for(int i=n-1; i>=0; i--) v._index(i) = __pop(); return v; } }; \ No newline at end of file diff --git a/src/compiler.h b/src/compiler.h index 7565ee26..7de2944f 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -1028,7 +1028,7 @@ _Code compile(VM* vm, const char* source, _Str filename, CompileMode mode=EXEC_M try{ return compiler.__fillCode(); }catch(std::exception& e){ - if(const _Error* _ = dynamic_cast(&e)){ + if(dynamic_cast(&e)){ (*vm->_stderr) << e.what() << '\n'; }else{ auto ce = CompileError("UnexpectedError", e.what(), compiler.getLineSnapshot()); diff --git a/src/iter.h b/src/iter.h index 22b017a2..daeb44df 100644 --- a/src/iter.h +++ b/src/iter.h @@ -43,7 +43,7 @@ public: class StringIterator : public _Iterator { private: - size_t index = 0; + int index = 0; _Str str; public: StringIterator(VM* vm, PyVar _ref) : _Iterator(vm, _ref) { diff --git a/src/main.cpp b/src/main.cpp index 5ec1146b..347b1562 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,19 +3,21 @@ #include "pocketpy.h" -//#define PK_DEBUG_TIME -#define PK_DEBUG_THREADED +#define PK_DEBUG_TIME +//#define PK_DEBUG_THREADED struct Timer{ const char* title; Timer(const char* title) : title(title) {} void run(std::function f){ +#ifdef PK_DEBUG_TIME auto start = std::chrono::high_resolution_clock::now(); f(); auto end = std::chrono::high_resolution_clock::now(); double elapsed = std::chrono::duration_cast(end - start).count() / 1000000.0; -#ifdef PK_DEBUG_TIME std::cout << title << ": " << elapsed << " s" << std::endl; +#else + f(); #endif } }; diff --git a/src/obj.h b/src/obj.h index 28b12fa5..8ddd58e2 100644 --- a/src/obj.h +++ b/src/obj.h @@ -55,13 +55,14 @@ struct _Slice { class _Iterator { protected: - PyVar _ref; // keep a reference to the object so it will not be deleted while iterating VM* vm; + PyVar _ref; // keep a reference to the object so it will not be deleted while iterating public: virtual PyVar next() = 0; virtual bool hasNext() = 0; _Pointer var; _Iterator(VM* vm, PyVar _ref) : vm(vm), _ref(_ref) {} + virtual ~_Iterator() = default; }; typedef pkpy::shared_ptr _Func; diff --git a/src/pointer.h b/src/pointer.h index 8aea3a9c..67e797f8 100644 --- a/src/pointer.h +++ b/src/pointer.h @@ -8,6 +8,7 @@ struct BasePointer { virtual PyVar get(VM*, Frame*) const = 0; virtual void set(VM*, Frame*, PyVar) const = 0; virtual void del(VM*, Frame*) const = 0; + virtual ~BasePointer() = default; }; enum NameScope { diff --git a/src/vm.h b/src/vm.h index 0e93dc67..0a8339b6 100644 --- a/src/vm.h +++ b/src/vm.h @@ -538,7 +538,7 @@ public: try { return _exec(code, _module, {}); } catch (const std::exception& e) { - if(const _Error* _ = dynamic_cast(&e)){ + if(dynamic_cast(&e)){ *_stderr << e.what() << '\n'; }else{ auto re = RuntimeError("UnexpectedError", e.what(), _cleanErrorAndGetSnapshots());