fix a bug

This commit is contained in:
blueloveTH 2022-12-22 10:20:27 +08:00
parent 9a64870f89
commit 5dfd7b5fc9
7 changed files with 34 additions and 17 deletions

View File

@ -37,7 +37,7 @@
#define UNREACHABLE() throw std::runtime_error( __FILE__ + std::string(":") + std::to_string(__LINE__) + " UNREACHABLE()!");
#endif
#define PK_VERSION "0.5.0"
#define PK_VERSION "0.5.1"
//#define PKPY_NO_TYPE_CHECK
//#define PKPY_NO_INDEX_CHECK
@ -2235,7 +2235,7 @@ namespace pkpy {
#endif
}
void __tryAlloc(uint8_t n){
void __tryAlloc(size_t n){
if(n > 255) UNREACHABLE();
if(n >= MAX_POOLING_N || _poolArgList[n].empty()){
this->_size = n;
@ -2258,7 +2258,7 @@ namespace pkpy {
}
public:
ArgList(uint8_t n){
ArgList(size_t n){
if(n != 0) __tryAlloc(n);
}
@ -3887,6 +3887,12 @@ public:
return v;
}
PyVarList popNValuesReversedUnlimited(VM* vm, int n){
PyVarList v(n);
for(int i=n-1; i>=0; i--) v[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) = __pop();
@ -4128,12 +4134,13 @@ protected:
} break;
case OP_BUILD_LIST:
{
pkpy::ArgList items = frame->popNValuesReversed(this, byte.arg);
frame->push(PyList(items.toList()));
frame->push(PyList(
frame->popNValuesReversedUnlimited(this, byte.arg)
));
} break;
case OP_BUILD_MAP:
{
pkpy::ArgList items = frame->popNValuesReversed(this, byte.arg*2);
PyVarList items = frame->popNValuesReversedUnlimited(this, byte.arg*2);
PyVar obj = call(builtins->attribs["dict"]);
for(int i=0; i<items.size(); i+=2){
call(obj, __setitem__, pkpy::twoArgs(items[i], items[i+1]));
@ -4142,8 +4149,9 @@ protected:
} break;
case OP_BUILD_SET:
{
pkpy::ArgList items = frame->popNValuesReversed(this, byte.arg);
PyVar list = PyList(items.toList());
PyVar list = PyList(
frame->popNValuesReversedUnlimited(this, byte.arg)
);
PyVar obj = call(builtins->attribs["set"], pkpy::oneArg(list));
frame->push(obj);
} break;

@ -1 +1 @@
Subproject commit 28b2550f587a924f352937579873bfb4909596ca
Subproject commit 8d72bddf3e80119e0f095aea14cf669024a8bee0

View File

@ -30,7 +30,7 @@
#define UNREACHABLE() throw std::runtime_error( __FILE__ + std::string(":") + std::to_string(__LINE__) + " UNREACHABLE()!");
#endif
#define PK_VERSION "0.5.0"
#define PK_VERSION "0.5.1"
//#define PKPY_NO_TYPE_CHECK
//#define PKPY_NO_INDEX_CHECK

View File

@ -232,6 +232,12 @@ public:
return v;
}
PyVarList popNValuesReversedUnlimited(VM* vm, int n){
PyVarList v(n);
for(int i=n-1; i>=0; i--) v[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) = __pop();

View File

@ -79,7 +79,7 @@ namespace pkpy {
#endif
}
void __tryAlloc(uint8_t n){
void __tryAlloc(size_t n){
if(n > 255) UNREACHABLE();
if(n >= MAX_POOLING_N || _poolArgList[n].empty()){
this->_size = n;
@ -102,7 +102,7 @@ namespace pkpy {
}
public:
ArgList(uint8_t n){
ArgList(size_t n){
if(n != 0) __tryAlloc(n);
}

View File

@ -237,12 +237,13 @@ protected:
} break;
case OP_BUILD_LIST:
{
pkpy::ArgList items = frame->popNValuesReversed(this, byte.arg);
frame->push(PyList(items.toList()));
frame->push(PyList(
frame->popNValuesReversedUnlimited(this, byte.arg)
));
} break;
case OP_BUILD_MAP:
{
pkpy::ArgList items = frame->popNValuesReversed(this, byte.arg*2);
PyVarList items = frame->popNValuesReversedUnlimited(this, byte.arg*2);
PyVar obj = call(builtins->attribs["dict"]);
for(int i=0; i<items.size(); i+=2){
call(obj, __setitem__, pkpy::twoArgs(items[i], items[i+1]));
@ -251,8 +252,9 @@ protected:
} break;
case OP_BUILD_SET:
{
pkpy::ArgList items = frame->popNValuesReversed(this, byte.arg);
PyVar list = PyList(items.toList());
PyVar list = PyList(
frame->popNValuesReversedUnlimited(this, byte.arg)
);
PyVar obj = call(builtins->attribs["set"], pkpy::oneArg(list));
frame->push(obj);
} break;

1
tests/_json2.py Normal file

File diff suppressed because one or more lines are too long