Changeset 22848 for src

Show
Ignore:
Timestamp:
11/01/08 19:06:18 (2 months ago)
Author:
lwall
Message:

[STD] allow parsing of multiple *.t files in one process (works, but leaks badly)

Location:
src/perl6
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/Cursor.pmc

    r22836 r22848  
    1111our $CTX = ''; 
    1212our $DEBUG = $ENV{STD5DEBUG} // 0; 
    13 $::DEBUG = $DEBUG; 
    14  
    15 # various bits of info useful for error messages 
    16 $::HIGHWATER = 0; 
    17 $::HIGHMESS = ''; 
    18 $::HIGHEXPECT = {}; 
    19 $::COMPILING::LAST_NIBBLE = { firstline => 0, lastline => 0 }; 
    20 $::COMPILING::LAST_NIBBLE_MULTILINE = { firstline => 0, lastline => 0 }; 
    21 $::COMPILING::LINE = 1; 
    22 $::COMPILING::FILE = '(eval)'; 
    23 $::GOAL = "(eof)"; 
     13our $DEPTH = 0; 
     14our %LEXERS;       # per language, the cache of lexers, keyed by rule name 
     15 
     16sub ::init_globals { 
     17    $::DEBUG = $DEBUG; 
     18    $::CTX = ''; 
     19    $::DEPTH = 0; 
     20    $::ORIG = ''; 
     21    @::MEMOS = (); 
     22    %::LEXERS = (); 
     23 
     24    # various bits of info useful for error messages 
     25    $::HIGHWATER = 0; 
     26    $::HIGHMESS = ''; 
     27    $::HIGHEXPECT = {}; 
     28    $::COMPILING::LAST_NIBBLE = { firstline => 0, lastline => 0 }; 
     29    $::COMPILING::LAST_NIBBLE_MULTILINE = { firstline => 0, lastline => 0 }; 
     30    $::COMPILING::LINE = 1; 
     31    $::COMPILING::FILE = '(eval)'; 
     32    $::GOAL = "(eof)"; 
     33} 
    2434 
    2535{ package DEBUG; 
     
    4151} 
    4252 
    43 our $DEPTH = 0; 
    44  
    4553sub ::deb { 
    4654    print ::LOG @_, "\n"; 
     
    110118    my $text = shift; 
    111119    my $rule = shift() // 'comp_unit'; 
     120    ::init_globals(); 
     121    local $::VOID = 1 if not defined wantarray; 
    112122    local $::COMPILING::FILE = '(eval)'; 
    113123    $class->new($text)->$rule(); 
     
    118128    my $file = shift; 
    119129    my $rule = shift() // 'comp_unit'; 
     130    ::init_globals(); 
     131    local $::VOID = 1 if not defined wantarray; 
    120132    local $::COMPILING::FILE = $file; 
    121133    my $text = Encode::decode('utf8', `cat $file`); 
     
    167179use YAML::XS; 
    168180 
    169 our %lexers;       # per language, the cache of lexers, keyed by rule name 
    170  
    171181sub from { $_[0]->{_from} // $_[0]->{_pos} } 
    172182sub to { $_[0]->{_pos} } 
     
    201211    my $lang = ref $self; 
    202212    $self->deb("LANG = $lang") if $DEBUG & DEBUG::autolexer; 
    203     $lexers{$lang} //= {}; 
     213    $::LEXERS{$lang} //= {}; 
    204214} 
    205215 
     
    474484            } 
    475485            for (@pats) { 
    476                 s/\(\?#FATE (.*?)\)/(?#$i FATE $1)/ or return sub { return }; 
     486                s/\(\?#FATE +(.*?)\)/(?#$i FATE $1)/ or return sub { return }; 
    477487                my $fstr = $1; 
    478488                my $fate = $fates->[$i] = [0,0,0,$fstr]; 
     
    764774} 
    765775 
    766 sub cleanup { 
    767     my $self = shift; 
    768     delete $self->{_fate}; 
    769     $self; 
    770 } 
    771  
    772776sub clean { 
    773777    my $self = shift; 
     
    805809    my $bindings = shift; 
    806810    my $submatch = shift;               # this is the submatch's cursor 
    807     $submatch->cleanup; 
     811    delete $self->{_fate}; 
    808812 
    809813    $self->deb("cursor_bind @$bindings") if $DEBUG & DEBUG::cursors; 
     
    821825    $submatch->{_from} = $r{_from} = $r{_pos}; 
    822826    $r{_pos} = $submatch->{_pos}; 
    823     delete $r{_fate}; 
    824827    CORE::bless \%r, ref $self;         # return new match cursor for parent 
    825828} 
     
    850853            return $self, $tag, $try, $relex; 
    851854        } 
     855#       else { 
     856#           warn Dump($fate); 
     857#           warn "FATE mismatch: $name vs " . $fate->[0] . "\n"; 
     858#       } 
    852859    } 
    853860 
  • src/perl6/STD.pm

    r22836 r22848  
    1313my $ORIG is context; 
    1414my @MEMOS is context; 
     15my $VOID is context<rw>; 
    1516 
    1617# random rule for debugging, please ignore 
     
    7071# XXX shouldn't need this, it should all be defined/imported by the prelude 
    7172 
    72 my @typenames = qw[ 
     73my @basetypenames = qw[ 
    7374    Object Any Junction Whatever 
    7475    Capture Match Signature Proxy Matcher 
     
    102103    KitchenSink 
    103104]; 
    104 push @typenames, "True", "False", "Bool::True", "Bool::False";  # in quotes lest gimme5 translate them 
    105  
     105push @basetypenames, "True", "False", "Bool::True", "Bool::False";  # in quotes lest gimme5 translate them 
     106 
     107my @typenames; 
    106108my %typenames; 
    107 %typenames{@typenames} = (1 xx @typenames); 
     109 
     110sub init_types { 
     111    @PKGS = (); 
     112    @typenames = @basetypenames; 
     113    %typenames = (); 
     114    %typenames{@typenames} = (1 xx @typenames); 
     115} 
    108116 
    109117method is_type ($name) { 
     
    124132# XXX likewise for routine defs 
    125133 
    126 my @routinenames = qw[ 
     134my @baseroutinenames = qw[ 
    127135    WHAT WHICH VAR 
    128136    any all none one 
     
    172180    fork wait kill sleep 
    173181]; 
    174 push @routinenames, "HOW", "fail", "temp", "let"; 
     182push @baseroutinenames, "HOW", "fail", "temp", "let"; 
    175183 
    176184# please don't add: ref length bless delete exists 
    177185 
     186my @routinenames; 
    178187my %routinenames; 
    179 %routinenames{@routinenames} = (1 xx @routinenames); 
     188 
     189sub init_routines { 
     190    %ROUTINES = (); 
     191    @routinenames = @baseroutinenames; 
     192    %routinenames = (); 
     193    %routinenames{@routinenames} = (1 xx @routinenames); 
     194} 
    180195 
    181196method is_routine ($name) { 
     
    559574    :my $endargs        is context<rw> = -1; 
    560575 
     576    :my $LANG is context; 
     577    :my $PKGDECL is context = ""; 
     578    :my $PKG is context = ""; 
     579    :my $GOAL is context = "(eof)"; 
     580    :my $PARSER is context<rw>; 
     581    :my $IN_DECL is context<rw>; 
     582 
     583    { init_types(); init_routines() } 
     584 
    561585    <statementlist> 
    562586    [ <?unitstopper> || <.panic: "Can't understand next input--giving up"> ] 
     
    34213445                while @opstack { 
    34223446                    last if $op<O><prec> ne @opstack[*-1]<O><prec>; 
    3423                     push @chain, pop(@termstack).cleanup; 
     3447                    push @chain, pop(@termstack); 
    34243448                    push @chain, pop(@opstack); 
    34253449                } 
    3426                 push @chain, pop(@termstack).cleanup; 
     3450                push @chain, pop(@termstack); 
    34273451                @chain = reverse @chain if @chain > 1; 
    34283452                my $startpos = @chain[0].pos; 
     
    34413465                    last if $sym ne @opstack[*-1]<sym>; 
    34423466                    if @termstack and defined @termstack[0] { 
    3443                         push @list, pop(@termstack).cleanup; 
     3467                        push @list, pop(@termstack); 
    34443468                    } 
    34453469                    else { 
     
    34493473                } 
    34503474                if @termstack and defined @termstack[0] { 
    3451                     push @list, pop(@termstack).cleanup; 
     3475                    push @list, pop(@termstack); 
    34523476                } 
    34533477                elsif $sym ne ',' { 
     
    34713495 
    34723496                self.deb($op.dump) if $*DEBUG +& DEBUG::EXPR; 
    3473                 $op<arg> = (pop @termstack).cleanup; 
     3497                $op<arg> = (pop @termstack); 
    34743498                if ($op<arg><_from> < $op<_from>) { 
    34753499                    $op<_from> = $op<arg><_from>; 
     
    34863510                self.deb("Termstack size: ", +@termstack) if $*DEBUG +& DEBUG::EXPR; 
    34873511 
    3488                 $op<right> = (pop @termstack).cleanup; 
    3489                 $op<left> = (pop @termstack).cleanup; 
     3512                $op<right> = (pop @termstack); 
     3513                $op<left> = (pop @termstack); 
    34903514                $op<_from> = $op<left><_from>; 
    34913515                $op<_pos> = $op<right><_pos>; 
  • src/perl6/tryfile

    r21784 r22848  
    11#!/usr/local/bin/perl 
    2  
    3 my $file = shift; 
    42 
    53use STD; 
     
    86use Encode; 
    97 
    10 my $r = STD->parsefile($file); 
    11 print Dump($r); 
     8for my $file (@ARGV) { 
     9    warn $file,"\n"; 
     10    eval { 
     11        STD->parsefile($file); 
     12    }; 
     13    warn $@ if $@; 
     14}