Syntax for PAST Optimizations

Patrick R. Michaud pmichaud at pobox.com
Mon May 31 14:54:42 UTC 2010


On Sun, May 30, 2010 at 09:11:18PM -0500, Tyler Curtis wrote:
> http://pastie.org/983989 is an example of an optimization for constant
> folding of addition.

Ah, more directly (again I'm just brainstorming with some P6 syntax):

    class FoldAddition {
        multi method fold(PAST::Op $/ where $/.pirop eq 'add'
                                            and $0 ~~ PAST::Val
                                            and $1 ~~ PAST::Val) {
            PAST::Val.new( :value( pir::add($0.value, $1.value) ) );
        }
        ...
    }

Or, more generally to handle constant folding for many common pirops:

    class FoldConstants {
        multi method fold(PAST::Op $/ where $/.pirop
                                            and $0 ~~ PAST::Val
                                            and $1 ~~ PAST::Val) {
            PAST::Val.new( :value( pir::{$/.pirop}($0.value, $1.value) ) );
        }
        ...
    }

No, NQP doesn't support where clauses in multimethod dispatch yet
(Parrot multi dispatch is type-based by default instead of constraint-based).  

However, it's entirely possible that a library could be developed for Parrot 
that would allow constraint-based multimethod dispatch, which NQP could then 
take advantage of (or perhaps even provide, similar to how it currently 
provides regex capabilities).  Early versions of Rakudo were able to do this
type of multidispatch to some degree on top of Parrot's existing subroutine 
dispatch, before Jonathan went and redesigned it entirely (to support a large
number of other needed semantics).

Again, I'm just brainstorming a bit here and stirring the pot of syntax ideas...
I'm not proposing that extending NQP would be the best way for the GSOC
project to go at this time (but neither would I be opposed to it).
Feel free to ignore this or run away screaming in terror at what I've written
above.  :-)

Pm


More information about the parrot-dev mailing list