Leopold Toetsch <[EMAIL PROTECTED]> wrote:

> 4) A scheme for calling functions.

> a) we need a class for a namespace, e.g. the interpreter (Python might
>    have a "math" object for the call below:)

>    $P0 = getinterp

> b) we do a method call

>    $N0 = $P0."sin"(3.14)

> c) add a method to classes/ParrotInterpreter.pmc:

>     METHOD FLOATVAL sin(FLOATVAL f) {
>         return sin(f);
>     }

> d) and add the signature "dIOd" to call_list.txt.

> e) a table of builtins


> Quite easy and straightforward - and I hear all loudly crying - SLOW.

> 5) Ok - let's look (unoptimized build - see above ;) and parrot -C
> (-j is the same, except that PIC is only hacked partially into -C)

> Timings for 1 Meg sinus function opcodes [1] and methods [2]

>   sin opcode:                 0.23 s
>   sin method:                 3.20 s

> Ok, too slow man. But here comes the PIC [4]:

>   sin method PIC:             0.50 s
>   sin method PIC no I0..I5    0.37 s   [3]

And, if that's a C function, which can be looked up via Parrot_dlsym[5],
the function can be called directly

  sin method PIC no I0..I5    0.31 s

[5] f = Parrot_dlsym(NULL, "sin");

If that doesn't work with the OS, the method is still there as a fallback.

The whole PIC functionality has currently 10 opcodes (the method call is
just duplicated here as the code isn't integrated):

    static void * pic_ops_addr[] = {
        &&PC_MMD_OP_ppp,
        &&PC_MMD_OP_ppp_PASM,
        &&PC_MMD_OP_ppi,
        &&PC_MMD_OP_ppi_PASM,
        &&PC_MMD_OP_ppn,
        &&PC_MMD_OP_ppn_PASM,
        /* TBD i_p_p */

        &&PC_METH_CALL_s,
        &&PC_METH_CALL_sc,
        &&PC_CALL_nn,
        &&PC_CALL_nn_C

That's all what is needed to do any MMD function either overridden or in
C, any method call (again PASM or builtin) and almost all trig and
alike opcodes. Basically we need 2 entries per function signature,
that's all (the _C variant isn't strictly needed but it saves one
function call).

Again I'm not speaking of any changes to the surface. I'm still speaking
of the internal implementation to handle these opcodes.

Tha assembler syntax doesn't change:

   $N0 = sin 3.14

But the run core just gets:

   $N0 = Pclass."sin"(3.14)

where Pclass just defines the namespace, where this function is
searched for, e.g. math.sin(3.14) for Python.

leo

Reply via email to