Commit 1ca22ce6 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Some very basic generator support

parent 044a2e51
...@@ -354,12 +354,19 @@ extern "C" BoxedGenerator::BoxedGenerator(BoxedFunctionBase* function, Box* arg1 ...@@ -354,12 +354,19 @@ extern "C" BoxedGenerator::BoxedGenerator(BoxedFunctionBase* function, Box* arg1
my_timer(generator_timer_counter, 0, true) my_timer(generator_timer_counter, 0, true)
#endif #endif
{ {
Py_INCREF(function);
Py_XINCREF(arg1);
Py_XINCREF(arg2);
Py_XINCREF(arg3);
int numArgs = function->md->numReceivedArgs(); int numArgs = function->md->numReceivedArgs();
if (numArgs > 3) { if (numArgs > 3) {
numArgs -= 3; numArgs -= 3;
this->args = new (numArgs) GCdArray(); this->args = new (numArgs) GCdArray();
memcpy(&this->args->elts[0], args, numArgs * sizeof(Box*)); memcpy(&this->args->elts[0], args, numArgs * sizeof(Box*));
for (int i = 0; i < numArgs; i++) {
Py_INCREF(args[i]);
}
} }
static StatCounter generator_stack_reused("generator_stack_reused"); static StatCounter generator_stack_reused("generator_stack_reused");
...@@ -446,9 +453,34 @@ extern "C" int PyGen_NeedsFinalizing(PyGenObject* gen) noexcept { ...@@ -446,9 +453,34 @@ extern "C" int PyGen_NeedsFinalizing(PyGenObject* gen) noexcept {
static void generator_dealloc(BoxedGenerator* self) noexcept { static void generator_dealloc(BoxedGenerator* self) noexcept {
assert(isSubclass(self->cls, generator_cls)); assert(isSubclass(self->cls, generator_cls));
PyObject_GC_UnTrack(self);
freeGeneratorStack(self); freeGeneratorStack(self);
Py_FatalError("unimplemented"); int numArgs = self->function->md->numReceivedArgs();
if (numArgs > 3) {
numArgs -= 3;
for (int i= 0; i < numArgs; i++) {
Py_CLEAR(self->args->elts[i]);
}
}
Py_CLEAR(self->arg1);
Py_CLEAR(self->arg2);
Py_CLEAR(self->arg3);
Py_CLEAR(self->function);
Py_CLEAR(self->returnValue);
Py_CLEAR(self->exception.type);
Py_CLEAR(self->exception.value);
Py_CLEAR(self->exception.traceback);
PyObject_ClearWeakRefs(self);
self->cls->tp_free(self);
} }
static int generator_traverse(BoxedGenerator* self, visitproc visit, void *arg) noexcept { static int generator_traverse(BoxedGenerator* self, visitproc visit, void *arg) noexcept {
......
...@@ -4356,7 +4356,6 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe ...@@ -4356,7 +4356,6 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
// the call to function containing a yield should just create a new generator object. // the call to function containing a yield should just create a new generator object.
Box* res; Box* res;
if (md->isGenerator()) { if (md->isGenerator()) {
assert(0 && "check refcounting");
// TODO: we might not have a lot to gain by rewriting into createGenerator, but we could at least // TODO: we might not have a lot to gain by rewriting into createGenerator, but we could at least
// rewrite up to the call to it: // rewrite up to the call to it:
res = createGenerator(func, arg1, arg2, arg3, oargs); res = createGenerator(func, arg1, arg2, arg3, oargs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment