Jos Visser <[EMAIL PROTECTED]> wrote: > My current code generator generates code to trap the LEX_NOT_FOUND > exception. However, the "set_eh" instruction is *terribly* slow...
After having a closer look at this, I can describe what's happening: - the exception handler is a continuation - these have COWed copies of the interpreter's stacks - the C<set_eh> pushes an exception handler onto the control stack this unCOWes the interpreter's control stack - when the exception is resumable, a return continuation is built again setting the control stack as COWed - so resuming after the exception puts a saved copy of the original control_stack in place, which has the COW flag set. - this causes a chunk_copy (effectively constructing a new stack) at the next set_eh :-( The COW logic for stacks is wrong. Test program follows: new_pad 0 new P0, .PerlInt set P0, 42 store_lex -1, "yep", P0 set I0, 10000 time N0 lp1: find_lex P1, "yep" dec I0 if I0, lp1 time N1 sub N2, N1, N0 print N2 print "\n" newsub P3, .Exception_Handler, _failed set_eh P3 set I0, 10000 time N0 lp2: find_lex P1, "no" ret: set_eh P3 dec I0 if I0, lp2 time N1 sub N2, N1, N0 print N2 print "\n" end _failed: set P0, P5["_invoke_cc"] invoke # resume at ret: