hi,

        we've started a project (will have a web-page soon) that aims to port the
        php-language (www.php.net) to run on top of parrot. we've written some
        initial code and i'm kinda stuck while writing the codegen (i target imc) 

        my problem is that php is typeless. i am writing code to to some basic
        type-recognition in my ast to be able to leverage the much speedier I S and
        N types in parrot, but for obvious reasons i have to make the php basic
        type an PMC. problem now is that using pmc for everything will make execution
        much much slower that it could be.

        my compiler currently translates:

<?php
    for ($i = 0; $i < 100; $i = $i + 5.5) {
        echo "hallo";
    }
?>

        to:

.pcc_sub _main prototyped
        .sym PerlUndef TEMP0
        TEMP0 = new PerlUndef
        .sym PerlUndef TEMP1
        TEMP1 = new PerlUndef
        .sym PerlUndef TEMP2
        TEMP2 = new PerlUndef
        .sym PerlUndef TEMP3
        TEMP3 = new PerlUndef
        .sym PerlUndef TEMP4
        TEMP4 = new PerlUndef
        .sym PerlUndef i
        i = new PerlUndef
        i = 0
LBL0:
        TEMP1 = 100
        I0 = 0
        unless i < TEMP1 goto LBL3
        I0 = 1
LBL3:
        unless I0 goto LBL2
        TEMP4 = "hallo"
        print TEMP4
        TEMP2 = 5.5
        TEMP3 = i + TEMP2
        i = clone TEMP3
        goto LBL0
LBL2:
.end

        (i know it can be made better - working on it) - but the basic dilemma is
        obvious: $i starts as an INT and becomes a FLOAT at runtime. so my compiler
        made it a PMC. (i know that i'll at one point have to write my own PMC for
        the PHP base-type, but for now PerlUndef works for me).

        because pmc as so much slower that native types i loose most of parrots
        brilliant speed due to the fact that i don't know the types at
        compile-time.

        i believe you'll face the same problem once perl6 becomes a reality on
        parrot so here's my question (i've only been on perl6-internals for some
        week, so sorry if this has been discussed in depth before):

        would't it make sense to introduce one additional new type into parrot that
        can "morph" between the normal types (I, S, N, P)?

        something like (i call the type VAL):

        typedef enum { INT, NUMBER, STRING, ... PMC } ValType;

        typedef struct {
                ValType type;
                union {
                        INTVAL i;
                        NUMBER n;
                        STRING s;
                        ...
                        PMC p;
                } u;
        } VAL;

        and add support for this in the executor in the most efficient way.


        if you think this is unneeded could you explain how you are planning to
        make untyped languages run really fast on parrot and what direction i have
        to take to use that technique? (PMC will always carry the vtable jump
        overhead, so they will be slower than what perl or php use currently in the
        inner execution loop)

        i'd also like to add that eg PHP has different semantics when you do binary
        operations on strings that perl has so this VAL type would have to be
        as flexible as a PMC. (PHP would have to use a different implementation
        than Perl6 or Python)

        thies
-- 
Thies C. Arntzen   -   Looking for all sorts of freelance work  -   just ask..
                  http://www.amazon.de/exec/obidos/wishlist/AB9DY62QWDSZ

Reply via email to