Changeset 21975

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

[STD] rudimentary global symbol table to detect routine definitions

Location:
src/perl6
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/Cursor.pmc

    r21973 r21975  
    102102        $args{'_' . $name} = shift; 
    103103    } 
    104     my $self = bless \%args, ref $class || $class; 
     104    my $self = CORE::bless \%args, ref $class || $class; 
    105105    my $buf = $self->{_orig}; 
    106106#    $self->deb(" orig ", $$buf) if $DEBUG & DEBUG::cursors; 
     
    186186sub peek { $_[0]->{_peek} } 
    187187sub orig { $_[0]->{_orig} } 
    188 sub WHAT { ref $_[0] } 
     188sub WHAT { ref $_[0] || $_[0] } 
     189sub bless { CORE::bless $_[1], $_[0]->WHAT } 
    189190 
    190191sub item { exists $_[0]->{''} ? $_[0]->{''} : $_[0]->text } 
     
    692693    sub new { my $self = shift; 
    693694        my %args = @_; 
    694         bless \%args, $self; 
     695        CORE::bless \%args, $self; 
    695696    } 
    696697 
     
    708709    my %r = %$self; 
    709710    $r{_peek} = 1; 
    710     bless \%r, ref $self; 
     711    CORE::bless \%r, ref $self; 
    711712} 
    712713 
     
    720721    $r{_fate} = $self->{_fate}; 
    721722    $r{_herelang} = $self->{_herelang} if $self->{_herelang}; 
    722     bless \%r, ref $lang || $lang; 
     723    CORE::bless \%r, ref $lang || $lang; 
    723724} 
    724725 
     
    727728    my %r = %$self; 
    728729    $r{_herelang} = $self; 
    729     bless \%r, 'STD::Q'; 
     730    CORE::bless \%r, 'STD::Q'; 
    730731} 
    731732 
     
    835836    $r{_pos} = $r{_to} = $submatch->{_to}; 
    836837    delete $r{_fate}; 
    837     bless \%r, ref $self;               # return new match cursor for parent 
     838    CORE::bless \%r, ref $self;         # return new match cursor for parent 
    838839} 
    839840 
     
    874875        } 
    875876    } 
    876     return (bless \%r, ref $self), $tag, $try, $relex; 
     877    return (CORE::bless \%r, ref $self), $tag, $try, $relex; 
    877878} 
    878879 
     
    887888    $r{_pos} = $tpos; 
    888889 
    889     bless \%r, ref $self; 
     890    CORE::bless \%r, ref $self; 
    890891} 
    891892 
     
    905906    $r{_pos} = $tpos; 
    906907 
    907     bless \%r, ref $self; 
     908    CORE::bless \%r, ref $self; 
    908909} 
    909910 
     
    923924    $r{_to} = $self->{_from}; 
    924925 
    925     bless \%r, ref $self; 
     926    CORE::bless \%r, ref $self; 
    926927} 
    927928 
     
    12961297 
    12971298    local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 
    1298     lazymap(sub { bless($_[0],ref($self))->retm() }, 
     1299    lazymap(sub { CORE::bless($_[0],ref($self))->retm() }, 
    12991300        $block->($self)); 
    13001301} 
     
    13051306    local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 
    13061307    my ($val) = $block->($self) or return (); 
    1307     bless($val,ref($self))->retm(); 
     1308    CORE::bless($val,ref($self))->retm(); 
    13081309} 
    13091310 
  • src/perl6/STD.pm

    r21973 r21975  
    88my $PARSER is context<rw>; 
    99my $IN_DECL is context<rw>; 
     10my %ROUTINES; 
    1011 
    1112# random rule for debugging, please ignore 
     
    9596    Buf  buf   buf1  buf2  buf4 buf8  buf16  buf32  buf64 
    9697 
    97     Bit Bool True False 
     98    Bit Bool 
    9899    bit bool 
    99100 
     
    106107    KitchenSink 
    107108]; 
     109push @typenames, "True", "False";  # in quotes lest gimme5 translate them 
    108110 
    109111my %typenames; 
     
    123125    %typenames{$qualname} = $qualname; 
    124126    %typenames{$shortname} = $qualname; 
     127} 
     128 
     129# XXX likewise for routine defs 
     130 
     131my @routinenames = qw[ 
     132    WHAT WHICH VAR 
     133    die exit warn eval temp 
     134    callsame callwith nextsame nextwith lastcall 
     135    defined undefine item list slice 
     136    join split substr index chars pack unpack uc ucfirst lc lcfirst 
     137    say print open close printf sprintf slurp unlink 
     138    elems grep map sort push reverse take splice 
     139    zip each roundrobin caller 
     140    return leave pop shift unshift reduce 
     141    keys values hash 
     142    sqrt floor ceil 
     143    any all none one 
     144    plan is ok dies_ok lives_ok skip todo pass flunk force_todo use_ok isa_ok 
     145    cmp_ok diag is_deeply isnt like skip_rest unlike nonce skip_rest eval_dies_okay 
     146]; 
     147push @routinenames, "HOW", "fail"; 
     148 
     149# if True ref False unless length bless delete exists 
     150 
     151my %routinenames; 
     152%routinenames{@routinenames} = (1 xx @routinenames); 
     153 
     154method is_routine ($name) { 
     155    return True if %routinenames{$name}; 
     156    return True if %typenames{$name}; 
     157    #return True if GLOBAL::{$name}.:exists; 
     158    return False; 
     159} 
     160 
     161method add_routine ($name) { 
     162    %routinenames{$name} = 1; 
    125163} 
    126164 
     
    482520    <statementlist> 
    483521    [ <?unitstopper> || <.panic: "Can't understand next input--giving up"> ] 
     522    # "CHECK" time... 
     523    {{ 
     524        my %UNKNOWN; 
     525        for keys(%ROUTINES) { 
     526            next if $¢.is_routine($_); 
     527            %UNKNOWN{$_} = %ROUTINES{$_}; 
     528        } 
     529        if %UNKNOWN { 
     530            warn "Unknown routines:\n"; 
     531            for sort keys(%UNKNOWN) { 
     532                warn "\t$_ called at ", %UNKNOWN{$_}, "\n"; 
     533            } 
     534        } 
     535    }} 
    484536} 
    485537 
     
    582634    # this could either be a statement that follows a declaration 
    583635    # or a statement that is within the block of a code declaration 
    584     <!!{ bless $¢, ref $PARSER; }> 
     636    <!!{ $¢ = $+PARSER.bless($¢); }> 
    585637 
    586638    [ 
     
    15411593    # XXX too soon 
    15421594    [ <colonpair>+ { $¢.add_macro($<name>) if $+IN_DECL; } ]? 
     1595    { $¢.add_routine($<name>.text) if $+IN_DECL; } 
    15431596} 
    15441597 
     
    23762429    :my $IN_DECL is context<rw> = 1; 
    23772430    [ '&'<deflongname>? | <deflongname> ]? [ <multisig> | <trait> ]* 
    2378     <!!{ bless $¢, ref $PARSER; }> 
    2379     { $IN_DECL = 0; } 
     2431    <!{ 
     2432        $¢ = $+PARSER.bless($¢); 
     2433        $IN_DECL = 0; 
     2434    }> 
    23802435    <block> 
    23812436} 
     
    24072462    :my $IN_DECL is context<rw> = 1; 
    24082463    [ '&'<deflongname>? | <deflongname> ]? [ <multisig> | <trait> ]* 
    2409     <!!{ bless $¢, ref $PARSER; }> 
    2410     { $IN_DECL = 0; } 
     2464    <!{ 
     2465        $¢ = $+PARSER.bless($¢); 
     2466        $IN_DECL = 0; 
     2467    }> 
    24112468    <block> 
    24122469} 
     
    26262683 
    26272684token term:sym<next> ( --> Term) 
    2628     { <sym> » <.ws> <termish>? } 
     2685    { <sym> » <.ws> [<!stdstopper> <termish>]? } 
    26292686 
    26302687token term:sym<last> ( --> Term) 
    2631     { <sym> » <.ws> <termish>? } 
     2688    { <sym> » <.ws> [<!stdstopper> <termish>]? } 
    26322689 
    26332690token term:sym<redo> ( --> Term) 
    2634     { <sym> » <.ws> <termish>? } 
     2691    { <sym> » <.ws> [<!stdstopper> <termish>]? } 
    26352692 
    26362693token term:sym<goto> ( --> Term) 
     
    30753132    :my $i; 
    30763133    $i = <identifier> <args( $¢.is_type($i.text) )> 
     3134    {{ %ROUTINES{$i.text} ~= $¢.lineof($¢.pos) ~ ' ' }} 
    30773135} 
    30783136 
     
    38643922    for @text { 
    38653923        $posprops.[$pos++]<L> = $line 
    3866             for 1 .. length($_); 
     3924            for 1 .. chars($_); 
    38673925        $line++; 
    38683926    } 
  • src/perl6/gimme5

    r21973 r21975  
    182182        $f =~ s/^\bdefault\s+\{//               and $t .= qq/else {/, next; 
    183183        $f =~ s/^\btemp\b//                     and $t .= qq/local/, next; 
    184         $f =~ s/^\bchars\(\b//                  and $t .= qq/length(/, next; 
     184        $f =~ s/^\bchars\(//                    and $t .= qq/length(/, next; 
    185185 
    186186        # the following must do partial rescan of final expression 
     
    15651565        local $NEEDMATCH = 0; 
    15661566        %NEEDSEMI = (); 
    1567         my $text; 
     1567        my $text = ''; 
    15681568        for my $line (split /^/,$$self{text}) { 
    15691569            if ($line =~ /^(\s*).*?given/) { 
     
    15791579            $text .= $line; 
    15801580        } 
    1581         $text = ::un6($text); 
     1581        $text = ::un6($text) // ''; 
    15821582        my $ctx = $$self{context}; 
    15831583        $text = 'my $M = $C; ' . $text . ';' if $NEEDMATCH;