At 05:59 PM 11-30-2000 +0000, Nicholas Clark wrote:
>On Thu, Nov 30, 2000 at 12:46:26PM -0500, Dan Sugalski wrote:

(Note, Dan was writing about "$a=1.2; $b=3; $c = $a + $b")

>$a=1; $b =3; $c = $a + $b
>
>
> > If they don't exist already, then something like:
> >
> >          newscalar       a, num, 1.2
> >          newscalar       b, int, 3
> >          newscalar       c, num, 0
> >          add             t3, a, b
>
>and $c ends up a num?
>why that line "newscalar c, num, 0" ?
>It looks to me like add needs to be polymorphic and work out the best
>compromise for the type of scalar to create based on the integer/num/
>complex/oddball types of its two operands.

I think the "add t3, a, b" was a typo, and should be "add c, a, b"

Another way of looking at it, assuming that the Perl6 interpreter is 
stack-based, not register-based, is that the sequence would get converted 
into something like this:

     push      num 1.3  ;; literal can be precomputed at compile time
     dup
     newscaler a        ;; get value from top of stack
     push      int 3    ;; literal can be precomputed at compile time
     dup
     newscaler b
     push      a
     push      b
     add
     newscaler c

The "add" op would, in C code, do something like:

void add() {
   P6Scaler *addend;
   P6Scaler *adder;

   addend = pop();  adder = pop();
   push addend->vtable->add(addend, adder);
}

it would be up to the addend->vtable->add() to figure out how to do the 
actual addition, and what type to return.

> > But that probably doesn't help much. Let me throw together something more
> > detailed and we'll see where we go from there.
>
>Hopefully it will cover the above case too.
>
>Nicholas Clark

Reply via email to