Branch: Tag:

2019-08-30

2019-08-30 11:12:54 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler: Improved generator robustness.

A generator that exits via throw() should now enter the termination
state. Calling a generator recursively now also causes it to return
UNDEFINED.

Also renames and adjusts some generator-related byte codes.

2509:    }    }    -  if (Pike_compiler->compiler_frame->generator_local != -1) { -  emit1(F_SAVE_STACK, Pike_compiler->compiler_frame->generator_local + 1); -  if (CDR(n) && CDR(n)->u.sval.u.integer) { +  if ((Pike_compiler->compiler_frame->generator_local != -1) && +  CDR(n) && CDR(n)->u.sval.u.integer) {    /* Continue return. */ -  +  emit1(F_SAVE_STACK_TO_LOCAL, +  Pike_compiler->compiler_frame->generator_local + 1);    continue_label = alloc_label();    /* NB: Subtract 1 to compensate for starting cases at -1. */    emit1(F_NUMBER,    Pike_compiler->compiler_frame->generator_index-1); -  } else { -  emit1(F_NUMBER, -1); -  } +     emit1(F_ASSIGN_LOCAL_AND_POP,    Pike_compiler->compiler_frame->generator_local);    }
2958:       /* Restore the stack content and zap extra references. */    emit1(F_LOCAL, Pike_compiler->compiler_frame->generator_local + 1); -  emit0(F_PUSH_ARRAY_AND_CLEAR); +  emit0(F_PUSH_ARRAY_AND_EMPTY);       /* Emit the state-machine switch for the generator. */    emit1(F_LOCAL, Pike_compiler->compiler_frame->generator_local); -  +  emit1(F_NUMBER, -1); +  emit1(F_ASSIGN_LOCAL_AND_POP, +  Pike_compiler->compiler_frame->generator_local);    generator_switch = emit1(F_SWITCH, 0);    emit1(F_ALIGN, sizeof(INT32));