Branch: Tag:

2019-09-10

2019-09-10 10:07:36 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler: Reserve some generator variables for resuming with a value.

The first argument to a generator function is now reseved to be a
resumption value, and the second a call back function that will be
called from the resumed function jyst before it starts executing
again. This may be used to eg resume the generator with an error.

816:    push_finished_type(Pike_compiler->compiler_frame->current_return_type);       if ($1 & ID_GENERATOR) { +  /* Adjust the type to be a function that returns +  * a function(mixed|void, function(mixed|void...:void):X). +  */    push_type(T_VOID);    push_type(T_MANY);    -  +  push_type(T_VOID); +  push_type(T_VOID); +  push_type(T_MIXED); +  push_type(T_OR); +  push_type(T_MANY); +  push_type(T_FUNCTION); +  +  push_type(T_VOID); +  push_type(T_MIXED); +  push_type(T_OR); +  push_type(T_FUNCTION); +     /* Entry point variable. */    add_ref(int_type_string);    Pike_compiler->compiler_frame->generator_local =    add_local_name(empty_pike_string, int_type_string, 0); -  +     /* Stack contents to restore. */    add_ref(array_type_string);    add_local_name(empty_pike_string, array_type_string, 0);    -  +  /* Resumption argument. */ +  add_ref(mixed_type_string); +  add_local_name(empty_pike_string, mixed_type_string, 0); +  +  /* Resumption callback. */ +  add_ref(function_type_string); +  add_local_name(empty_pike_string, function_type_string, 0); +     for (e = 0; e <= Pike_compiler->compiler_frame->generator_local; e++) {    Pike_compiler->compiler_frame->variable[e].flags |=    LOCAL_VAR_IS_USED | LOCAL_VAR_USED_IN_SCOPE;
927:    } else {    push_finished_type(Pike_compiler->compiler_frame->current_return_type);    } +  +  /* Adjust the type to be a function that returns +  * a function(mixed|void, function(mixed|void...:void):X). +  */    push_type(T_VOID);    push_type(T_MANY);    -  +  push_type(T_VOID); +  push_type(T_VOID); +  push_type(T_MIXED); +  push_type(T_OR); +  push_type(T_MANY); +  push_type(T_FUNCTION); +  +  push_type(T_VOID); +  push_type(T_MIXED); +  push_type(T_OR); +  push_type(T_FUNCTION); +     generator_type = compiler_pop_type();    f = dooptcode(Pike_sp[-1].u.string, $12, generator_type,    ID_INLINE|ID_PROTECTED|ID_PRIVATE|ID_USED);