Changeset 22553 for src/perl6

Show
Ignore:
Timestamp:
10/09/08 06:16:28 (6 weeks ago)
Author:
lwall
Message:

[viv] can now reconstruct the p6 from the ast for simple expressions

Location:
src/perl6
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/STD.pm

    r22550 r22553  
    914914    [ 
    915915    | <fatarrow> 
    916     | <variable> { $<sigil> = $<variable><sigil> } 
     916    | <variable> { $<SIGIL> = $<variable><sigil> } 
    917917    | <package_declarator> 
    918918    | <scope_declarator> 
     
    11851185token variable_declarator { 
    11861186    :my $IN_DECL is context<rw> = 1; 
    1187     <variable> { $<sigil> = $<variable><sigil> } 
     1187    <variable> { $<SIGIL> = $<variable><sigil> } 
    11881188    { $IN_DECL = 0; } 
    11891189    [   # Is it a shaped array or hash declaration? 
     
    12061206    :dba('variable initializer') 
    12071207    [ 
    1208     | '=' <.ws> <EXPR( ($<sigil> // '') eq '$' ?? item %item_assignment !! item %list_prefix )> 
     1208    | '=' <.ws> <EXPR( ($<SIGIL> // '') eq '$' ?? item %item_assignment !! item %list_prefix )> 
    12091209    | '.=' <.ws> <dottyop> 
    12101210    ]? 
     
    31473147{ 
    31483148    <sym> 
    3149     { $¢ = (self.<sigil>//'') eq '$'  
     3149    { $¢ = (self.<SIGIL> // self.<sigil> // '') eq '$'  
    31503150        ?? STD::Item_assignment.coerce($¢) 
    31513151        !! STD::List_assignment.coerce($¢); 
  • src/perl6/viv

    r22552 r22553  
    5050 
    5151    our $AUTOLOAD; 
     52    my $SEQ = 1; 
    5253 
    5354    sub AUTOLOAD { 
     
    7475                    $r{$key} = $$v{$key}; 
    7576                } 
     77            } 
     78            elsif ($k eq 'SIGIL') { 
     79                $r{SIGIL} = $v; 
    7680            } 
    7781            elsif ($k eq '_arity') { 
     
    9599                    } 
    96100                    $r{$k} = $zyg; 
     101                    $r{zygs}{$k} = $SEQ++ if @$zyg; 
    97102                } 
    98103                elsif (ref $v) { 
     
    103108                        $r{$k} = $v; 
    104109                    } 
     110                    $r{zygs}{$k} = $SEQ++; 
    105111                    unless (ref($r{$k}) =~ /^VAST/) { 
    106112                        my $class = "VAST::$k"; 
     
    144150    sub emit_p6 { my $self = shift; 
    145151        my $text; 
    146         # XXX bogus 
    147         if (exists $self->{TEXT}) { 
    148             $text = $self->{TEXT}; 
    149         } 
    150         elsif (exists $self->{sym}) { 
     152        my @sym; 
     153        if (exists $self->{sym}) { 
    151154            my $sym = $self->{sym}; 
    152155            if (ref $sym eq 'ARRAY') { 
    153                 $text = join '?', @$sym; 
     156                @sym = @$sym; 
    154157            } 
    155158            else { 
    156                 $text = $sym; 
    157             } 
    158         } 
    159         else { 
    160             for my $key (sort keys %$self) { 
    161                 my $part = $$self{$key}; 
     159                @sym = $sym; 
     160            } 
     161        } 
     162        if ($self->{zygs}) { 
     163            my @zyg = $self->visit_zygs; 
     164            my $arity = $self->{arity} // ''; 
     165            if ($arity eq 'BINARY') { 
     166                $text .= shift @zyg; 
     167                $text .= shift @sym; 
     168                $text .= shift @zyg; 
     169            } 
     170            elsif ($arity eq 'UNARY') { 
     171                if ($self->{post}) { 
     172                    $text .= shift @zyg; 
     173                    $text .= shift @sym; 
     174                } 
     175                else { 
     176                    $text .= shift @sym; 
     177                    $text .= shift @zyg; 
     178                } 
     179            } 
     180            else { 
     181                $text .= join('', @zyg); 
     182            } 
     183        } 
     184        elsif (exists $self->{TEXT}) { 
     185            $text = $self->{TEXT}; 
     186        } 
     187        elsif (@sym) { 
     188            $text .= join('', @sym); 
     189        } 
     190        $text; 
     191    } 
     192 
     193    sub visit_zygs { my $self = shift; 
     194        my @zygs; 
     195        if ($self->{zygs}) { 
     196            my $zygs = $self->{zygs}; 
     197            for my $key (sort {$zygs->{$a} <=> $zygs->{$b}} keys %$zygs) { 
     198                my $part = $self->{$key}; 
    162199                if (ref $part eq 'ARRAY') { 
    163200                    my @kids = @$part; 
    164201                    for my $kid (@kids) { 
    165                         $text .= $kid->emit_p6; 
     202                        push @zygs, $kid->emit_p6 // ''; 
    166203                    } 
    167204                } 
    168205                elsif (ref $part) { 
    169                     $text .= $part->emit_p6; 
     206                    push @zygs, $part->emit_p6 // ''; 
    170207                } 
    171208                else { 
    172                     $text = $key . '=' . $part; 
    173                 } 
    174             } 
    175         } 
    176         $text; 
     209                    push @zygs, $key . '=' . $part; 
     210                } 
     211            } 
     212        } 
     213        @zygs; 
    177214    } 
    178215}