mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-23 04:50:17 +00:00
some fix
This commit is contained in:
parent
d65636babb
commit
29c2618c9e
@ -1 +1 @@
|
||||
g++ -o pocketpy src/main.cpp --std=c++17 -O1 -pthread
|
||||
g++ -o pocketpy src/main.cpp --std=c++17 -O1 -pthread -Wall -Wno-sign-compare -Wno-unused-variable
|
@ -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
|
||||
|
||||
<p>
|
||||
<a title="Pub" href="https://pub.dev/packages/pocketpy" ><img src="https://img.shields.io/pub/v/pocketpy" /></a>
|
||||
</p>
|
||||
|
||||
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
|
||||
```
|
||||
|
@ -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<Function> _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<int> 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<const _Error*>(&e)){
|
||||
if(dynamic_cast<const _Error*>(&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<const _Error*>(&e)){
|
||||
if(dynamic_cast<const _Error*>(&e)){
|
||||
(*vm->_stderr) << e.what() << '\n';
|
||||
}else{
|
||||
auto ce = CompileError("UnexpectedError", e.what(), compiler.getLineSnapshot());
|
||||
|
@ -127,6 +127,7 @@ private:
|
||||
int ip = 0;
|
||||
std::stack<int> 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;
|
||||
}
|
||||
};
|
@ -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<const _Error*>(&e)){
|
||||
if(dynamic_cast<const _Error*>(&e)){
|
||||
(*vm->_stderr) << e.what() << '\n';
|
||||
}else{
|
||||
auto ce = CompileError("UnexpectedError", e.what(), compiler.getLineSnapshot());
|
||||
|
@ -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) {
|
||||
|
@ -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<void()> 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<std::chrono::microseconds>(end - start).count() / 1000000.0;
|
||||
#ifdef PK_DEBUG_TIME
|
||||
std::cout << title << ": " << elapsed << " s" << std::endl;
|
||||
#else
|
||||
f();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
@ -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<Function> _Func;
|
||||
|
@ -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 {
|
||||
|
2
src/vm.h
2
src/vm.h
@ -538,7 +538,7 @@ public:
|
||||
try {
|
||||
return _exec(code, _module, {});
|
||||
} catch (const std::exception& e) {
|
||||
if(const _Error* _ = dynamic_cast<const _Error*>(&e)){
|
||||
if(dynamic_cast<const _Error*>(&e)){
|
||||
*_stderr << e.what() << '\n';
|
||||
}else{
|
||||
auto re = RuntimeError("UnexpectedError", e.what(), _cleanErrorAndGetSnapshots());
|
||||
|
Loading…
x
Reference in New Issue
Block a user