At 01:51 PM 11/30/00 -0500, Buddha Buck wrote:
>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"
D'oh! Yup. Cut'n'paste error.
>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
That looks about right, though I'm not sure we should use a stack-based
instead of register-based model. (Well, register and stack) I can see going
either way, but that's a different argument. (Unfortunately all the
stack-based interpreters I've used are all-software, while all the
register-based ones are all hardware (i.e. real assembly) so I don't have
an even basis for comparison)
>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.
Yup. I think it'll be a little more complex than that in the call,
something like:
addend->vtable->(add[typeof adder])(adder);
The extra level of indirection may hurt in the general case, but I think
it's a win to call the "add an int scalar to me" function rather than have
a generic "add this scalar to me" function that figures out the type of the
scalar passed and then Does The Right Thing. I hope. (Yeah, I'm betting
that the extra indirect will be cheaper than the extra code. But I'm not
writing that in stone until we can do some benchmarking)
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
[EMAIL PROTECTED] have teddy bears and even
teddy bears get drunk