Leopold Toetsch <[EMAIL PROTECTED]> writes: > Piers Cawley <[EMAIL PROTECTED]> wrote: >> Leopold Toetsch <[EMAIL PROTECTED]> writes: > >>> - if it calls a PASM routine, registers have to be preserved. Which >>> registers depend on the subroutine that actually gets called (ok, this >>> information - which registers are changed by the sub - can be attached >>> to the Sub's metadata) > >> No, we're in caller saves remember. > > Ok, yes. But MMD and delegated functions are a bit different. The caller > isn't knowing that it's a caller. The PASM is run from the inside of the > C code. > >> ... The registers that need saving are >> dependent on the caller. > > Not quite for this case. Or in theory yes, but... As calling the > subroutine mustn't have any changes to the caller's registers, it's just > simpler to save these registers that the subroutine might change. > >> ... Since the registers used by a function at any >> point are statically determined, maybe add's signature could be altered >> to take an integer 'save flags' argument specifying which registers >> need to be preserved for the caller, > > This has a performance penalty for the non-MMD case. I can imagine that > overloaded MMD functions are simpler (in respect of register usage) then > the caller's code. So it seems that saving, what the MMD sub might > change on behalf of the caller is just more effective.
But generating the save signature for a given sub is a compile time cost that only needs to be paid once for each sub and shoved on an I register (which could, of course, be standardized). An MMD sub with a PASM implementation simply looks at the appropriate register, saves the right stuff, sets up a return continuation and has the interpreter invoke it. Which leaves a correctly set up continuation chain and a PASM implementation which can do whatever the heck it likes, including making continuations, closures etc that can be returned to multiple times because it got invoked in the normal runloop. The work has to be done either way, but by arranging things so that everything looks like caller saves (and so that there is no MMD barrier to continuations) just seems to make the most sense. BTW, if it's a continuation barrier does that also mean it's an exception barrier?