mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
up
This commit is contained in:
parent
ba30626dbd
commit
88c97271e5
@ -1,4 +1,4 @@
|
|||||||
## 0.6.1+2
|
## 0.6.1+3
|
||||||
|
|
||||||
+ Break change
|
+ Break change
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: pocketpy
|
name: pocketpy
|
||||||
description: A lightweight Python interpreter for game engines.
|
description: A lightweight Python interpreter for game engines.
|
||||||
version: 0.6.1+2
|
version: 0.6.1+3
|
||||||
homepage: https://pocketpy.dev
|
homepage: https://pocketpy.dev
|
||||||
repository: https://github.com/blueloveth/pocketpy
|
repository: https://github.com/blueloveth/pocketpy
|
||||||
|
|
||||||
|
@ -32,11 +32,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Modification:
|
|
||||||
// 1. Add #define EMH_WYHASH_HASH 1
|
|
||||||
// 2. Add static for wymix
|
|
||||||
#define EMH_WYHASH_HASH 1
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -1672,7 +1667,7 @@ one-way search strategy.
|
|||||||
|
|
||||||
#if EMH_WYHASH_HASH
|
#if EMH_WYHASH_HASH
|
||||||
//#define WYHASH_CONDOM 1
|
//#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__)
|
#if defined(__SIZEOF_INT128__)
|
||||||
__uint128_t r = A; r *= B;
|
__uint128_t r = A; r *= B;
|
||||||
@ -1801,11 +1796,11 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning (disable:4267)
|
#pragma warning (disable:4267)
|
||||||
#pragma warning (disable:4101)
|
#pragma warning (disable:4101)
|
||||||
#define _CRT_NONSTDC_NO_DEPRECATE
|
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||||
|
#define strdup _strdup
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -1820,7 +1815,6 @@ private:
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -2047,8 +2041,7 @@ public:
|
|||||||
|
|
||||||
size_t hash() const{
|
size_t hash() const{
|
||||||
if(!hash_initialized){
|
if(!hash_initialized){
|
||||||
//_hash = std::hash<std::string>()(*this);
|
_hash = std::hash<std::string>()(*this);
|
||||||
_hash = emhash8::HashMap<int,int>::wyhashstr(data(), size());
|
|
||||||
hash_initialized = true;
|
hash_initialized = true;
|
||||||
}
|
}
|
||||||
return _hash;
|
return _hash;
|
||||||
@ -2227,11 +2220,7 @@ public:
|
|||||||
using std::vector<PyVar>::vector;
|
using std::vector<PyVar>::vector;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef emhash8::HashMap<_Str, PyVar> PyVarDict;
|
||||||
class PyVarDict: public emhash8::HashMap<_Str, PyVar> {
|
|
||||||
using emhash8::HashMap<_Str, PyVar>::HashMap;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
namespace pkpy {
|
namespace pkpy {
|
||||||
const uint8_t MAX_POOLING_N = 10;
|
const uint8_t MAX_POOLING_N = 10;
|
||||||
@ -2389,33 +2378,27 @@ namespace pkpy {
|
|||||||
|
|
||||||
|
|
||||||
const char* __BUILTINS_CODE = R"(
|
const char* __BUILTINS_CODE = R"(
|
||||||
def len(x):
|
|
||||||
return x.__len__()
|
|
||||||
|
|
||||||
def print(*args, sep=' ', end='\n'):
|
def print(*args, sep=' ', end='\n'):
|
||||||
s = sep.join([str(i) for i in args])
|
s = sep.join([str(i) for i in args])
|
||||||
__sys_stdout_write(s + end)
|
__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:
|
if x >= 0:
|
||||||
return int(x + 0.5)
|
return int(x * 10**ndigits + 0.5) / 10**ndigits
|
||||||
else:
|
else:
|
||||||
return int(x - 0.5)
|
return int(x * 10**ndigits - 0.5) / 10**ndigits
|
||||||
|
|
||||||
def abs(x):
|
def abs(x):
|
||||||
if x < 0:
|
return x < 0 ? -x : x
|
||||||
return -x
|
|
||||||
return x
|
|
||||||
|
|
||||||
def max(a, b):
|
def max(a, b):
|
||||||
if a > b:
|
return a > b ? a : b
|
||||||
return a
|
|
||||||
return b
|
|
||||||
|
|
||||||
def min(a, b):
|
def min(a, b):
|
||||||
if a < b:
|
return a < b ? a : b
|
||||||
return a
|
|
||||||
return b
|
|
||||||
|
|
||||||
def sum(iterable):
|
def sum(iterable):
|
||||||
res = 0
|
res = 0
|
||||||
@ -3932,7 +3915,7 @@ class VM {
|
|||||||
protected:
|
protected:
|
||||||
std::deque< pkpy::unique_ptr<Frame> > callstack;
|
std::deque< pkpy::unique_ptr<Frame> > callstack;
|
||||||
PyVarDict _modules; // loaded modules
|
PyVarDict _modules; // loaded modules
|
||||||
std::map<_Str, _Str> _lazyModules; // lazy loaded modules
|
emhash8::HashMap<_Str, _Str> _lazyModules; // lazy loaded modules
|
||||||
PyVar __py2py_call_signal;
|
PyVar __py2py_call_signal;
|
||||||
|
|
||||||
void _checkStopFlag(){
|
void _checkStopFlag(){
|
||||||
@ -5981,8 +5964,10 @@ __LISTCOMP:
|
|||||||
emitCode(OP_DELETE_REF);
|
emitCode(OP_DELETE_REF);
|
||||||
consumeEndStatement();
|
consumeEndStatement();
|
||||||
} else if(match(TK("global"))){
|
} else if(match(TK("global"))){
|
||||||
consume(TK("@id"));
|
do {
|
||||||
getCode()->co_global_names.push_back(parser->previous.str());
|
consume(TK("@id"));
|
||||||
|
getCode()->co_global_names.push_back(parser->previous.str());
|
||||||
|
} while (match(TK(",")));
|
||||||
consumeEndStatement();
|
consumeEndStatement();
|
||||||
} else if(match(TK("pass"))){
|
} else if(match(TK("pass"))){
|
||||||
consumeEndStatement();
|
consumeEndStatement();
|
||||||
@ -6313,6 +6298,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
return vm->PyInt(vm->hash(args[0]));
|
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->bindBuiltinFunc("chr", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
vm->__checkArgSize(args, 1);
|
vm->__checkArgSize(args, 1);
|
||||||
_Int i = vm->PyInt_AS_C(args[0]);
|
_Int i = vm->PyInt_AS_C(args[0]);
|
||||||
@ -6374,6 +6364,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
return args[0]->_type;
|
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) {
|
_vm->bindMethod("range", "__new__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
_Range r;
|
_Range r;
|
||||||
switch (args.size()) {
|
switch (args.size()) {
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit d3c5ec6fdf62217fb18c08c0e19ccea21d41ab18
|
Subproject commit 2ddb39495bb1078d5686b35a19645fd6ab4690ee
|
Loading…
x
Reference in New Issue
Block a user