Leopold Toetsch wrote:

But C statics can of course change. The problems is, where to
store the static variable, especially native integers.

Another idea:

We keep the call frame of subs with statics (or Perl6 INIT and FIRST blocks) after returning from the sub. Additionally, we can set a new entrypoint for the sub after running the INIT code (or static initializer). The entrypoint would be reset for cloning closures to achieve perl6 FIRST block semantics.

The draw backs are increased memory usage and it doesn't work together with recursive subroutines easily, albeit I don't know, if recursive subs with statics are really meaningful.

E.g.

.sub "gen_random"
    .param float max
    .static int last                  # just an alias for .local maybe
    last = 42
    after_init gen_random_init_done   # move sub entry point
    goto gen_rand_2                   # after_init could branch too
gen_random_init_done:                 #   automatically
    .param float max                  # duplicated get_params
gen_rand_2
    ....
.end

Comments welcome,
leo

Reply via email to