--- Gordon Henriksen <[EMAIL PROTECTED]> wrote:
> David Storrs wrote:
> 
> > This discussion seems to contain two separate problems, and I'm not
> > always sure which one is being addressed.  The components I see
> are:
> > 
> > 1) Detecting when the assumptions have been violated and the code
> has
> >    to be changed; and,
> > 
> > 2) Actually making the change after we know that we need to.
> > 
> > 
> > I have at least a vague idea of why #1 would be difficult.  As to
> > #2...assuming that the original source is available (or can be
> > recovered), then regenerating the expression does not seem
> difficult.
> > Or am I missing something?
> 
> David,
> 
> Recompiling isn't hard (assuming that compiling is already
> implemented).
> Nor is notification of changes truly very difficult.
> 

Let's try again:

 1: sub othersub {...}
 2:
 3: sub foo {
 4:   my $a = 13;
 5:   my $b = 12;
 6: 
 7:    othersub;
 8:    my $c = $a + $b;
 9: 
10:    print $c;
11: }
12:
13: eval "sub othersub { &::infix+ := &::infix-; }";
14: foo;

In theory, we should get Object(1) as a result.

So let's compile that:

4: temp_a = 13;
5: temp_b = 12;
7: call othersub
8: push temp_b
8: push temp_a
8: call ::infix+
9: call print

Now let's optimize it:

                ; temp_a, temp_b are MY, so suppress them.
7:  call othersub
                 ; We do CSE at compile time
                 ; We don't use C after the print, so drop it
9:  push 25
9:  call print

So when we execute othersub, and notice that the world has shifted
beneath our feet, what do we do?

We don't even have the right registers laying about. There are no "a"
and "b" values to pass to the operator+ routine. (An advantage,
actually: losing an intermediate value would be a worse scenario.)

Two possibilities:

1- Some classes of optimization could be forced to occupy a certain
minimum size. The act of breaking the optimization assumptions could
replace the optimization (e.g., CSE) with a thunk.

  Example:
cse: push 25
     call print

  Becomes:
cse: push 25
     branch $+3
     nop
     nop
     call print

  So that we could replace it with:
cse: call undo_cse
     call print

  Where presumably undo_cse performed the operations in source code
order. (What's more, it would make perl binaries *very* compressible
:-)

2- In the "living dangerously" category, go with my original
suggestion: GC the compiled code blocks, and just keep executing what
you've got until you leave the block. Arguably, sequence points could
be used here to partition the blocks into smaller elements.

This tends to make event loops act really stupid, but ...

=Austin

Reply via email to