Okay quite a bit was wrong with that, but now it's right
This commit is contained in:
parent
0c08398e4a
commit
1809ebf99e
@ -2322,6 +2322,7 @@ static void generatorInner(KrkScanner scannerBefore, Parser parserBefore) {
|
||||
|
||||
emitLoop(loopStart);
|
||||
patchJump(exitJump);
|
||||
emitByte(OP_POP);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,6 +90,11 @@ KRK_METHOD(generator,__call__,{
|
||||
size_t stackAfter = krk_currentThread.stackTop - krk_currentThread.stack;
|
||||
self->running = 0;
|
||||
|
||||
if (IS_KWARGS(result) && AS_INTEGER(result) == 0) {
|
||||
_set_generator_done(self);
|
||||
return OBJECT_VAL(self);
|
||||
}
|
||||
|
||||
/* Was there an exception? */
|
||||
if (krk_currentThread.flags & KRK_THREAD_HAS_EXCEPTION) {
|
||||
_set_generator_done(self);
|
||||
@ -102,8 +107,9 @@ KRK_METHOD(generator,__call__,{
|
||||
self->args = realloc(self->args, sizeof(KrkValue) * (self->argCount + newArgs));
|
||||
self->argCount += newArgs;
|
||||
} else if (stackAfter < stackBefore) {
|
||||
_set_generator_done(self);
|
||||
return OBJECT_VAL(self);
|
||||
size_t deadArgs = stackBefore - stackAfter;
|
||||
self->args = realloc(self->args, sizeof(KrkValue) * (self->argCount - deadArgs));
|
||||
self->argCount -= deadArgs;
|
||||
}
|
||||
|
||||
/* Save stack entries */
|
||||
|
3
src/vm.c
3
src/vm.c
@ -1870,6 +1870,9 @@ _resumeHook: (void)0;
|
||||
}
|
||||
krk_currentThread.stackTop = &krk_currentThread.stack[frame->outSlots];
|
||||
if (krk_currentThread.frameCount == (size_t)krk_currentThread.exitOnFrame) {
|
||||
if (frame->closure->function->isGenerator) {
|
||||
return KWARGS_VAL(0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
krk_push(result);
|
||||
|
16
test/testComplicatedGeneratorFunction.krk
Normal file
16
test/testComplicatedGeneratorFunction.krk
Normal file
@ -0,0 +1,16 @@
|
||||
def agenerator(a=42):
|
||||
print("First yield")
|
||||
yield 1
|
||||
if True:
|
||||
yield 2
|
||||
yield 3
|
||||
print("Into the loops")
|
||||
for i in range(a):
|
||||
yield i
|
||||
print("nest loop", i, a)
|
||||
for j in range(a):
|
||||
print("yielding",j)
|
||||
yield j
|
||||
print("Done with inner nest from",i)
|
||||
|
||||
print(list(agenerator()))
|
1851
test/testComplicatedGeneratorFunction.krk.expect
Normal file
1851
test/testComplicatedGeneratorFunction.krk.expect
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user