On Wednesday 10 July 2002 08:18 pm, Melvin Smith wrote: > I was referring to the above situation where a lexical might be optimized > away without being stored in a pad (for %MY). I would *hope* %MY is only modified at compile-time. I wouldn'd be upset if Perl ignored my attempts to access %MY at runtime. As for eval, if I ever need a CS master's thesis subject, I could always try this... Whenever the compiler runs across an eval, take a continuation from within the compiler. Make sure the compiler keeps enough state in lexicals to start where it leaves off. At runtime when the eval is reached, save the current continuation and hop over to the compile-time continuation and try compiling it in-place as a sub. It would be necessary to treat any lexicals used inside the eval"" as arguments to the sub -- otherwise usage of those lexicals inside the sub might change the optimization of those scalars and you wouldn't be able to call the continuation back to the runtime eval and have it work. Then, fiddle with the newly compiled bytecode and find the address of the eval continuation location we jumped from, and go back there. for 1..1000 -> int $i { # $i is optimized away in a nice register my $str = '$i + 1'; # assume this isn't constant voodoo'd away # eval $str; # at runtime, this could mean: my $compiletime_cont; my $runtime_cont; BEGIN { $compiletime_cont = take_continuation(); if caller(0).continued { # just guessing at a flag # this block is actually called at _runtime_ # this should morph the else clause bytecode below Perl6::compile_for_eval($str, $runtime_cont); invoke($runtime_cont); } } $runtime_cont = take_continuation(); unless caller(0).continued { invoke($compiletime_cont); } else { # this code is modified/generated/whatever by compile_for_eval above my sub &eval_expression = sub ($i) { $i + 1 } eval_expression($i); # I decided $(-> $i { $i + 1 }).($i) was too obfuscated. You're welcome } } Wouldn't it be great to have something so incredibly slow? Code morphing is so 80's! Okay, I've had my headache-inducing thought for the evening. <bow/> Yes, my Scheme interpreter written in Perl6 is coming along nicely. Muahaha! (kidding, obviously) Ashley WintersThread Previous | Thread Next