mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-10 13:40:16 +00:00
dropped support for __init__ for now
This commit is contained in:
parent
65a113792d
commit
4a189464ad
@ -152,13 +152,8 @@ class _Unpickler:
|
|||||||
if newargs is not None:
|
if newargs is not None:
|
||||||
newargs = [self.unwrap(i) for i in newargs]
|
newargs = [self.unwrap(i) for i in newargs]
|
||||||
inst = new_f(cls, *newargs)
|
inst = new_f(cls, *newargs)
|
||||||
if inst.__init__ is not None: # should be called with args if exists
|
|
||||||
inst.__init__(*newargs)
|
|
||||||
else:
|
else:
|
||||||
inst = new_f(cls)
|
inst = new_f(cls)
|
||||||
if inst.__init__ is not None:
|
|
||||||
inst.__init__() # no args
|
|
||||||
|
|
||||||
self.tag(index, inst)
|
self.tag(index, inst)
|
||||||
# restore state
|
# restore state
|
||||||
if state is not None:
|
if state is not None:
|
||||||
|
|||||||
@ -29,44 +29,44 @@ namespace pkpy
|
|||||||
PyObject *maxlen = args[2];
|
PyObject *maxlen = args[2];
|
||||||
return vm->heap.gcnew<PyDeque>(cls_t, vm, iterable, maxlen);
|
return vm->heap.gcnew<PyDeque>(cls_t, vm, iterable, maxlen);
|
||||||
});
|
});
|
||||||
vm->bind(type, "__init__(self, iterable=None, maxlen=None)",
|
// vm->bind(type, "__init__(self, iterable=None, maxlen=None)",
|
||||||
[](VM *vm, ArgsView args)
|
// [](VM *vm, ArgsView args)
|
||||||
{
|
// {
|
||||||
// printf("INIT CALLED!!\n");
|
// // printf("INIT CALLED!!\n");
|
||||||
PyDeque &self = _CAST(PyDeque &, args[0]);
|
// PyDeque &self = _CAST(PyDeque &, args[0]);
|
||||||
PyObject *iterable = args[1];
|
// PyObject *iterable = args[1];
|
||||||
PyObject *maxlen = args[2];
|
// PyObject *maxlen = args[2];
|
||||||
|
|
||||||
if (!vm->py_equals(maxlen, vm->None)) // fix the maxlen first
|
// if (!vm->py_equals(maxlen, vm->None)) // fix the maxlen first
|
||||||
{
|
// {
|
||||||
int tmp = CAST(int, maxlen);
|
// int tmp = CAST(int, maxlen);
|
||||||
if (tmp < 0)
|
// if (tmp < 0)
|
||||||
vm->ValueError("maxlen must be non-negative");
|
// vm->ValueError("maxlen must be non-negative");
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
self.maxlen = tmp;
|
// self.maxlen = tmp;
|
||||||
self.bounded = true;
|
// self.bounded = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
self.bounded = false;
|
// self.bounded = false;
|
||||||
self.maxlen = -1;
|
// self.maxlen = -1;
|
||||||
}
|
// }
|
||||||
if (!vm->py_equals(iterable, vm->None))
|
// if (!vm->py_equals(iterable, vm->None))
|
||||||
{
|
// {
|
||||||
self.dequeItems.clear(); // clear the deque
|
// self.dequeItems.clear(); // clear the deque
|
||||||
auto _lock = vm->heap.gc_scope_lock(); // locking the heap
|
// auto _lock = vm->heap.gc_scope_lock(); // locking the heap
|
||||||
PyObject *it = vm->py_iter(args[1]); // strong ref
|
// PyObject *it = vm->py_iter(args[1]); // strong ref
|
||||||
PyObject *obj = vm->py_next(it);
|
// PyObject *obj = vm->py_next(it);
|
||||||
while (obj != vm->StopIteration)
|
// while (obj != vm->StopIteration)
|
||||||
{
|
// {
|
||||||
self.insertObj(false, true, -1, obj);
|
// self.insertObj(false, true, -1, obj);
|
||||||
obj = vm->py_next(it);
|
// obj = vm->py_next(it);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return args[0];
|
// return args[0];
|
||||||
});
|
// });
|
||||||
// gets the item at the given index, if index is negative, it will be treated as index + len(deque)
|
// gets the item at the given index, if index is negative, it will be treated as index + len(deque)
|
||||||
// if the index is out of range, IndexError will be thrown --> required for [] operator
|
// if the index is out of range, IndexError will be thrown --> required for [] operator
|
||||||
vm->bind(type, "__getitem__(self, index) -> PyObject",
|
vm->bind(type, "__getitem__(self, index) -> PyObject",
|
||||||
@ -396,6 +396,35 @@ namespace pkpy
|
|||||||
/// @brief initializes a new PyDeque object, actual initialization is done in __init__
|
/// @brief initializes a new PyDeque object, actual initialization is done in __init__
|
||||||
PyDeque::PyDeque(VM *vm, PyObject *iterable, PyObject *maxlen)
|
PyDeque::PyDeque(VM *vm, PyObject *iterable, PyObject *maxlen)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (!vm->py_equals(maxlen, vm->None)) // fix the maxlen first
|
||||||
|
{
|
||||||
|
int tmp = CAST(int, maxlen);
|
||||||
|
if (tmp < 0)
|
||||||
|
vm->ValueError("maxlen must be non-negative");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->maxlen = tmp;
|
||||||
|
this->bounded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->bounded = false;
|
||||||
|
this->maxlen = -1;
|
||||||
|
}
|
||||||
|
if (!vm->py_equals(iterable, vm->None))
|
||||||
|
{
|
||||||
|
this->dequeItems.clear(); // clear the deque
|
||||||
|
auto _lock = vm->heap.gc_scope_lock(); // locking the heap
|
||||||
|
PyObject *it = vm->py_iter(iterable); // strong ref
|
||||||
|
PyObject *obj = vm->py_next(it);
|
||||||
|
while (obj != vm->StopIteration)
|
||||||
|
{
|
||||||
|
this->insertObj(false, true, -1, obj);
|
||||||
|
obj = vm->py_next(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int PyDeque::findIndex(VM *vm, PyObject *obj, int start, int stop)
|
int PyDeque::findIndex(VM *vm, PyObject *obj, int start, int stop)
|
||||||
|
|||||||
@ -44,7 +44,8 @@ def fail():
|
|||||||
|
|
||||||
|
|
||||||
d = deque(range(-5125, -5000))
|
d = deque(range(-5125, -5000))
|
||||||
d.__init__(range(200))
|
# d.__init__(range(200)) # not supported
|
||||||
|
d = deque(range(200))
|
||||||
for i in range(200, 400):
|
for i in range(200, 400):
|
||||||
d.append(i)
|
d.append(i)
|
||||||
for i in reversed(range(-200, 0)):
|
for i in reversed(range(-200, 0)):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user