Changeset 21973 for src/perl6

Show
Ignore:
Timestamp:
08/20/08 21:11:51 (3 months ago)
Author:
lwall
Message:

[STD etc.] squeezing out unnecessary calls to lazymap under ratchet

Location:
src/perl6
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/Cursor.pmc

    r21905 r21973  
    10911091} 
    10921092 
     1093sub _MATCHIFYr { my $self = shift; 
     1094    return () unless @_; 
     1095    my $var = shift; 
     1096    $var->{_from} = $self->{_from}; 
     1097    $var->retm(); 
     1098} 
     1099 
    10931100sub _SCANf { my $self = shift; 
    10941101 
     
    12911298    lazymap(sub { bless($_[0],ref($self))->retm() }, 
    12921299        $block->($self)); 
     1300} 
     1301 
     1302sub _BRACKETr { my $self = shift; 
     1303    my $block = shift; 
     1304 
     1305    local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 
     1306    my ($val) = $block->($self) or return (); 
     1307    bless($val,ref($self))->retm(); 
    12931308} 
    12941309 
     
    14191434    lazymap(sub { $self->cursor_bind($names, $_[0])->retm() }, 
    14201435        $block->($self)); 
     1436} 
     1437 
     1438sub _SUBSUMEr { my $self = shift; 
     1439    my $names = shift; 
     1440    my $block = shift; 
     1441 
     1442    local $CTX = $self->callm($names ? "@$names" : "") if $DEBUG & DEBUG::trace_call; 
     1443    my ($var) = $block->($self) or return (); 
     1444    $self->cursor_bind($names, $var)->retm(); 
    14211445} 
    14221446 
     
    22192243{ package RE_noop; our @ISA = 'RE_base'; 
    22202244    sub longest { my $self = shift; my ($C) = @_;  
    2221         return; 
     2245        return $IMP; 
    22222246    } 
    22232247} 
  • src/perl6/STD.pm

    r21955 r21973  
    422422 
    423423token vws { 
    424     \v :: 
     424    \v 
    425425    { $COMPILING::LINE++ } # XXX wrong several ways, use self.lineof($¢.pos) 
    426426    [ '#DEBUG -1' { say "DEBUG"; $STD::DEBUG = $*DEBUG = -1; } ]? 
     
    441441            [ <!after ^^ . > || <.panic: "Can't use embedded comments in column 1"> ] 
    442442            <.quibble($¢.cursor_fresh( ::STD::Q ))>   {*}                               #= embedded 
    443          | :: \N*            {*}                                 #= end 
     443         | {} \N*            {*}                                 #= end 
    444444         ] 
    445445} 
     
    773773    ] 
    774774    # XXX assuming no precedence change 
    775     :: 
     775     
    776776    <prefix_postfix_meta_operator>*                 {*}         #= prepost 
    777777    { $+prevop = $<O> } 
     
    793793token termish { 
    794794    [ 
    795     | <pre>+ :: <noun> 
     795    | <pre>+ <noun> 
    796796    | <noun> 
    797797    ] 
    798     :: 
    799798 
    800799    # also queue up any postfixes, since adverbs could change things 
     
    839838 
    840839token fatarrow { 
    841     <key=identifier> \h* '=>' :: <.ws> <val=EXPR(item %item_assignment)> 
     840    <key=identifier> \h* '=>' <.ws> <val=EXPR(item %item_assignment)> 
    842841} 
    843842 
     
    862861        { $key = ""; $value = $<postcircumfix>; } 
    863862        {*}                                                     #= structural 
    864     | $<var> = (<sigil> :: <twigil>? <desigilname>) 
     863    | $<var> = (<sigil> {} <twigil>? <desigilname>) 
    865864        { $key = $<var><desigilname>.text; $value = $<var>; } 
    866865        {*}                                                     #= varname 
     
    10881087        <.unsp>? 
    10891088        [ 
    1090         | '(' :: <in: ')', 'signature'> 
    1091         | '[' :: <in: ']', 'semilist', 'shape definition'> 
    1092         | '{' :: <in: '}', 'semilist', 'shape definition'> 
     1089        | '(' <in: ')', 'signature'> 
     1090        | '[' <in: ']', 'semilist', 'shape definition'> 
     1091        | '{' <in: '}', 'semilist', 'shape definition'> 
    10931092        | <?before '<'> <postcircumfix> 
    10941093        ]* 
     
    11881187        }} 
    11891188        {*}                                                     #= block 
    1190     || <?{ $+begin_compunit }> :: <?before ';'> 
     1189    || <?{ $+begin_compunit }> {} <?before ';'> 
    11911190        { 
    11921191            $longname orelse $¢.panic("Compilation unit cannot be anonymous"); 
     
    15001499 
    15011500token variable { 
    1502     <?before <sigil> > :: 
     1501    <?before <sigil> > {} 
    15031502    [ 
    15041503    || '&' <twigil>?  <sublongname> {*}                                   #= subnoun 
     
    15611560    [ 
    15621561    | <identifier> 
    1563     | '(' :: <in: ')', 'EXPR', 'indirect name'> 
     1562    | '(' <in: ')', 'EXPR', 'indirect name'> 
    15641563    ] 
    15651564} 
     
    16651664token rad_number { 
    16661665    ':' $<radix> = [\d+] <.unsp>?      # XXX optional dot here? 
    1667     ::           # don't recurse in lexer 
     1666    {}           # don't recurse in lexer 
    16681667    [ 
    16691668    || '<' 
     
    17711770 
    17721771    $start <left=nibble($lang)> $stop  
    1773     [ <?{ $start ne $stop }> :: 
     1772    [ <?{ $start ne $stop }> 
    17741773        <.ws> 
    17751774        [ '=' || <.panic: "Missing '='"> ] 
     
    17881787 
    17891788    $start <left=nibble($lang)> $stop  
    1790     [ <?{ $start ne $stop }> :: 
     1789    [ <?{ $start ne $stop }> 
    17911790        <.ws> <quibble($lang2)> 
    17921791    ||  
     
    21532152 
    21542153token codepoint { 
    2155     '[' :: ( [<!before ']'> .]*? ) ']' 
     2154    '[' {} ( [<!before ']'> .]*? ) ']' 
    21562155} 
    21572156 
     
    21742173            | <codepoint> 
    21752174            | \d+ 
    2176             | :: [ <[ ?.._ ]> || <.panic: "Unrecognized \\c character"> ] 
     2175            | [ <[ ?.._ ]> || <.panic: "Unrecognized \\c character"> ] 
    21772176            ] 
    21782177        } 
     
    22712270 
    22722271        # in single quotes, keep backslash on random character by default 
    2273         token backslash:misc { :: (.) { $<text> = "\\" ~ $0; } } 
     2272        token backslash:misc { {} (.) { $<text> = "\\" ~ $0; } } 
    22742273 
    22752274        # begin tweaks (DO NOT ERASE) 
     
    22832282        token stopper { \" } 
    22842283        # in double quotes, omit backslash on random \W backslash by default 
    2285         token backslash:misc { :: [ (\W) { $<text> = $0.text; } | $<x>=(\w) <.panic("Unrecognized backslash sequence: '\\" ~ $<x>.text ~ "'")> ] } 
     2284        token backslash:misc { {} [ (\W) { $<text> = $0.text; } | $<x>=(\w) <.panic("Unrecognized backslash sequence: '\\" ~ $<x>.text ~ "'")> ] } 
    22862285 
    22872286        # begin tweaks (DO NOT ERASE) 
     
    23422341grammar Quasi is STD { 
    23432342    token term:unquote { 
    2344         <starter><starter><starter> :: <statementlist> <stopper><stopper><stopper> 
     2343        <starter><starter><starter> <statementlist> <stopper><stopper><stopper> 
    23452344    } 
    23462345 
     
    23872386    | <sigil> '.' 
    23882387        [ 
    2389         | '(' :: <in: ')', 'signature'> 
    2390         | '[' :: <in: ']', 'signature'> 
    2391         | '{' :: <in: '}', 'signature'> 
     2388        | '(' <in: ')', 'signature'> 
     2389        | '[' <in: ']', 'signature'> 
     2390        | '{' <in: '}', 'signature'> 
    23922391        | <?before '<'> <postcircumfix> 
    23932392        ] 
     
    25122511    [ 
    25132512        # Is it a longname declaration? 
    2514     || <?{ $<sigil>.text eq '&' }> <?identifier> :: 
     2513    || <?{ $<sigil>.text eq '&' }> <?ident> {} 
    25152514        <identifier=sublongname> 
    25162515 
     
    30893088    | '(' <in: ')', 'semilist', 'argument list'> {*}              #= func args 
    30903089    | <.unsp> '.'? '(' <in: ')', 'semilist', 'argument list'> {*} #= func args 
    3091     | :: [<?before \s> <!{ $istype }> <.ws> <!infixstopper> <arglist>]? { $listopy = 1 } 
     3090    | {} [<?before \s> <!{ $istype }> <.ws> <!infixstopper> <arglist>]? { $listopy = 1 } 
    30923091    ] 
    30933092 
     
    31033102token term:name ( --> Term) 
    31043103{ 
    3105     <longname> :: 
     3104    <longname> 
    31063105    [ 
    31073106    ||  <?{ 
    31083107            $¢.is_type($<longname>.text) or substr($<longname>.text,0,2) eq '::' 
    3109         }> :: 
     3108        }> 
    31103109        # parametric type? 
    31113110        <.unsp>? [ <?before '['> <postcircumfix> ]? 
     
    35223521        [ 
    35233522        | \w 
    3524         | <metachar> 
    3525         | :: <.panic: "Unrecognized regex metacharacter"> 
     3523        | <metachar> :: 
     3524        | <.panic: "Unrecognized regex metacharacter"> 
    35263525        ] 
    35273526    } 
     
    35453544 
    35463545    token metachar:sym<{ }> { 
     3546        <?before '{'> 
    35473547        <codeblock> 
    35483548        {{ $/<sym> := <{ }> }} 
     
    35673567 
    35683568    token metachar:sym<[ ]> { 
    3569         '[' :: [:lang(self.unbalanced(']')) <nibbler>] 
     3569        '[' {} [:lang(self.unbalanced(']')) <nibbler>] 
    35703570        [ ']' || <.panic: "Unable to parse regex; couldn't find right bracket"> ] 
    35713571        { $/<sym> := <[ ]> } 
     
    35733573 
    35743574    token metachar:sym<( )> { 
    3575         '(' :: [:lang(self.unbalanced(')')) <nibbler>] 
     3575        '(' {} [:lang(self.unbalanced(')')) <nibbler>] 
    35763576        [ ')' || <.panic: "Unable to parse regex; couldn't find right parenthesis"> ] 
    35773577        { $/<sym> := <( )> } 
     
    35923592 
    35933593    token metachar:sym«< >» { 
    3594         '<' <unsp>? :: <assertion> 
     3594        '<' <unsp>? {} <assertion> 
    35953595        [ '>' || <.panic: "regex assertion not terminated by angle bracket"> ] 
    35963596    } 
     
    36383638        | <codepoint> 
    36393639        | \d+ 
    3640         | :: [ <[ ?.._ ]> || <.panic: "Unrecognized \\c character"> ] 
     3640        | [ <[ ?.._ ]> || <.panic: "Unrecognized \\c character"> ] 
    36413641        ] 
    36423642    } 
     
    36543654    token backslash:x { :i <sym> [ <hexint> | '[' [<.ws><hexint><.ws> ] ** ',' ']' ] } 
    36553655    token backslash:misc { $<litchar>=(\W) } 
    3656     token backslash:oops { :: <.panic: "Unrecognized regex backslash sequence"> } 
     3656    token backslash:oops { <.panic: "Unrecognized regex backslash sequence"> } 
    36573657 
    36583658    token assertion:sym<...> { <sym> } 
     
    36843684                                    | ':' <.ws> 
    36853685                                        [ :lang($¢.cursor_fresh($+LANG).unbalanced('>')) <arglist> ] 
    3686                                     | '(' :: 
     3686                                    | '(' {} 
    36873687                                        [ :lang($¢.cursor_fresh($+LANG)) <arglist> ] 
    36883688                                        [ ')' || <.panic: "Assertion call missing right parenthesis"> ] 
     
    36983698                                    | ':' <.ws> 
    36993699                                        [ :lang($¢.cursor_fresh($+LANG).unbalanced('>')) <arglist> ] 
    3700                                     | '(' :: 
     3700                                    | '(' {} 
    37013701                                        [ :lang($¢.cursor_fresh($+LANG)) <arglist> ] 
    37023702                                        [ ')' || <.panic: "Assertion call missing right parenthesis"> ] 
  • src/perl6/gimme5

    r21951 r21973  
    463463            } 
    464464 
     465            my $pkg; 
    465466            if ($args =~ s/ *--> *(\w*) *$//) { 
    466                 my $pkg = $pkg_really{$1} || "${PKG}::$1"; 
    467                 $coercion = " Cursor::lazymap sub { $pkg->coerce(\$_[0]) }, "; 
     467                $pkg = $pkg_really{$1} || "${PKG}::$1"; 
    468468            } 
    469469            $args .= ', '; 
     
    605605            } 
    606606            else { 
     607                if ($pkg) { 
     608                    if ($MAYBACKTRACK) { 
     609                        $coercion = " Cursor::lazymap sub { $pkg->coerce(\$_[0]) }, "; 
     610                    } 
     611                    else { 
     612                        $coercion = " map { $pkg->coerce(\$_) } "; 
     613                    } 
     614                } 
     615                my $ratchet = $MAYBACKTRACK ? '' : 'r'; 
    607616                $body .= <<"END"; 
    608617 
    609     \$self->_MATCHIFY($coercion 
     618    \$self->_MATCHIFY$ratchet($coercion 
    610619<<MEAT>> 
    611620    ); 
     
    14921501        my $re = shift; 
    14931502        return $re unless @BINDINGS; 
    1494         $re = "\$C->_SUBSUME([" . 
     1503        my $ratchet = $MAYBACKTRACK ? '' : 'r'; 
     1504        $re = "\$C->_SUBSUME$ratchet([" . 
    14951505            join(',', map {"'$_'"} @BINDINGS) . 
    14961506            "], sub {\n" . ::indent("my \$C = shift()->cursor_fresh;\n" . $re) . "\n})"; 
     
    16381648            $re = ::indent($$self{re}->walk(@_)); 
    16391649        } 
    1640         $re = "\$C->_BRACKET$REV( sub { my \$C=shift;\n" . ::indent($re) . "\n})"; 
     1650        my $ratchet = $MAYBACKTRACK ? '' : 'r'; 
     1651        $re = "\$C->_BRACKET$ratchet( sub { my \$C=shift;\n" . ::indent($re) . "\n})"; 
    16411652        $self->bind($re); 
    16421653    }