From 88c97271e5decad2d831a8582b58a72312e394e9 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 2 Jan 2023 18:03:37 +0800 Subject: [PATCH] up --- plugins/flutter/CHANGELOG.md | 2 +- plugins/flutter/pubspec.yaml | 2 +- plugins/flutter/src/pocketpy.h | 61 ++++++++++++++++------------------ plugins/godot/godot-cpp | 2 +- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/plugins/flutter/CHANGELOG.md b/plugins/flutter/CHANGELOG.md index 903cf042..59806075 100644 --- a/plugins/flutter/CHANGELOG.md +++ b/plugins/flutter/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.6.1+2 +## 0.6.1+3 + Break change diff --git a/plugins/flutter/pubspec.yaml b/plugins/flutter/pubspec.yaml index c35b8a27..a75a460d 100644 --- a/plugins/flutter/pubspec.yaml +++ b/plugins/flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: pocketpy description: A lightweight Python interpreter for game engines. -version: 0.6.1+2 +version: 0.6.1+3 homepage: https://pocketpy.dev repository: https://github.com/blueloveth/pocketpy diff --git a/plugins/flutter/src/pocketpy.h b/plugins/flutter/src/pocketpy.h index 27786344..7daa31a2 100644 --- a/plugins/flutter/src/pocketpy.h +++ b/plugins/flutter/src/pocketpy.h @@ -32,11 +32,6 @@ -// Modification: -// 1. Add #define EMH_WYHASH_HASH 1 -// 2. Add static for wymix -#define EMH_WYHASH_HASH 1 - #include #include #include @@ -1672,7 +1667,7 @@ one-way search strategy. #if EMH_WYHASH_HASH //#define WYHASH_CONDOM 1 - inline static uint64_t wymix(uint64_t A, uint64_t B) + inline uint64_t wymix(uint64_t A, uint64_t B) { #if defined(__SIZEOF_INT128__) __uint128_t r = A; r *= B; @@ -1801,11 +1796,11 @@ private: - #ifdef _MSC_VER #pragma warning (disable:4267) #pragma warning (disable:4101) #define _CRT_NONSTDC_NO_DEPRECATE +#define strdup _strdup #endif #include @@ -1820,7 +1815,6 @@ private: #include #include #include -#include #include #include @@ -2047,8 +2041,7 @@ public: size_t hash() const{ if(!hash_initialized){ - //_hash = std::hash()(*this); - _hash = emhash8::HashMap::wyhashstr(data(), size()); + _hash = std::hash()(*this); hash_initialized = true; } return _hash; @@ -2227,11 +2220,7 @@ public: using std::vector::vector; }; - -class PyVarDict: public emhash8::HashMap<_Str, PyVar> { - using emhash8::HashMap<_Str, PyVar>::HashMap; -}; - +typedef emhash8::HashMap<_Str, PyVar> PyVarDict; namespace pkpy { const uint8_t MAX_POOLING_N = 10; @@ -2389,33 +2378,27 @@ namespace pkpy { const char* __BUILTINS_CODE = R"( -def len(x): - return x.__len__() - def print(*args, sep=' ', end='\n'): s = sep.join([str(i) for i in args]) __sys_stdout_write(s + end) -def round(x): +def round(x, ndigits=0): + assert ndigits >= 0 + if ndigits == 0: + return x >= 0 ? int(x + 0.5) : int(x - 0.5) if x >= 0: - return int(x + 0.5) + return int(x * 10**ndigits + 0.5) / 10**ndigits else: - return int(x - 0.5) + return int(x * 10**ndigits - 0.5) / 10**ndigits def abs(x): - if x < 0: - return -x - return x + return x < 0 ? -x : x def max(a, b): - if a > b: - return a - return b + return a > b ? a : b def min(a, b): - if a < b: - return a - return b + return a < b ? a : b def sum(iterable): res = 0 @@ -3932,7 +3915,7 @@ class VM { protected: std::deque< pkpy::unique_ptr > callstack; PyVarDict _modules; // loaded modules - std::map<_Str, _Str> _lazyModules; // lazy loaded modules + emhash8::HashMap<_Str, _Str> _lazyModules; // lazy loaded modules PyVar __py2py_call_signal; void _checkStopFlag(){ @@ -5981,8 +5964,10 @@ __LISTCOMP: emitCode(OP_DELETE_REF); consumeEndStatement(); } else if(match(TK("global"))){ - consume(TK("@id")); - getCode()->co_global_names.push_back(parser->previous.str()); + do { + consume(TK("@id")); + getCode()->co_global_names.push_back(parser->previous.str()); + } while (match(TK(","))); consumeEndStatement(); } else if(match(TK("pass"))){ consumeEndStatement(); @@ -6313,6 +6298,11 @@ void __initializeBuiltinFunctions(VM* _vm) { return vm->PyInt(vm->hash(args[0])); }); + _vm->bindBuiltinFunc("len", [](VM* vm, const pkpy::ArgList& args) { + vm->__checkArgSize(args, 1); + return vm->call(args[0], __len__, pkpy::noArg()); + }); + _vm->bindBuiltinFunc("chr", [](VM* vm, const pkpy::ArgList& args) { vm->__checkArgSize(args, 1); _Int i = vm->PyInt_AS_C(args[0]); @@ -6374,6 +6364,11 @@ void __initializeBuiltinFunctions(VM* _vm) { return args[0]->_type; }); + _vm->bindMethod("type", "__eq__", [](VM* vm, const pkpy::ArgList& args) { + vm->__checkArgSize(args, 2, true); + return vm->PyBool(args[0] == args[1]); + }); + _vm->bindMethod("range", "__new__", [](VM* vm, const pkpy::ArgList& args) { _Range r; switch (args.size()) { diff --git a/plugins/godot/godot-cpp b/plugins/godot/godot-cpp index d3c5ec6f..2ddb3949 160000 --- a/plugins/godot/godot-cpp +++ b/plugins/godot/godot-cpp @@ -1 +1 @@ -Subproject commit d3c5ec6fdf62217fb18c08c0e19ccea21d41ab18 +Subproject commit 2ddb39495bb1078d5686b35a19645fd6ab4690ee