cvsuser     04/09/17 19:53:07

  Modified:    languages/regex test.pl
  Log:
  Switch to using Match PMCs.
  
  Revision  Changes    Path
  1.18      +19 -19    parrot/languages/regex/test.pl
  
  Index: test.pl
  ===================================================================
  RCS file: /cvs/public/parrot/languages/regex/test.pl,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -w -r1.17 -r1.18
  --- test.pl   22 Jun 2004 07:36:21 -0000      1.17
  +++ test.pl   18 Sep 2004 02:53:07 -0000      1.18
  @@ -79,7 +79,7 @@
   usage "not enough args: testfile required"
     if ! defined $testfile;
   
  -open(SPEC, $testfile);
  +open(SPEC, $testfile) or die "open $testfile: $!";
   my $pattern = <SPEC>;
   chomp($pattern);
   
  @@ -130,6 +130,9 @@
   # Regular expression test
   # Generated by $0
   # Pattern >>$pattern<<
  +
  +    loadlib \$P0, "match_group"
  +
       set S0, P5[1] # argv[1] (or perl5's \$ARGV[0])
       newsub \$P0, .Sub, _regex
       .pcc_begin prototyped
  @@ -191,17 +194,18 @@
    .local int rx_len
    .local int rx_pos
    .local int rx_tmp
  + .local pmc rx_ptmp
    .local IntList rx_stack
  - .local PerlArray rx_starts
  - .local PerlArray rx_ends
  + .local Match rx_match
   
    rx_stack = new IntList
  - rx_starts = new PerlArray
  - rx_ends = new PerlArray
   
   END
   
  -    my @asm = Regex::compile($pattern, { },
  +    # Compile the regex and set rx_match to the resulting match
  +    # object. The code will branch to the given label 'printResult' on
  +    # success, and 'printMatchFailed' on failure.
  +    my @asm = Regex::compile($pattern, { rx_match => 'rx_match' },
                                'printResults', 'printMatchFailed',
                                DEBUG => $DEBUG);
   
  @@ -213,36 +217,32 @@
       goto done
   printResults:
       print "Match found\n"
  +    .local int num_groups
       .local int match_num
       .local int ii
       .local int valid_flag
  +    set num_groups, rx_match["!GROUPS"]
       set match_num, 0
   printLoop:
  -    set ii, match_num
  +    ge match_num, num_groups, done
       bsr printGroup
  -    add match_num, ii, 1
  -    if valid_flag goto printLoop
  +    inc match_num
  +    goto printLoop
   done:
       .pcc_begin_return
       .pcc_end_return
   
   printGroup:
  -    .local int num_groups
  -    set num_groups, rx_starts
  -    lt match_num, num_groups, groupDefined
  -    set valid_flag, 0
  -    ret
  -groupDefined:
       .local int match_start
       .local int match_end
  -    set match_start, rx_starts[match_num]
  -    set match_end, rx_ends[match_num]
  +    set match_start, rx_match[match_num;0]
  +    set match_end, rx_match[match_num;1]
  +    eq match_start, -2, skipPrint
       eq match_end, -2, skipPrint
       print match_num
       print ": "
       print match_start
       print ".."
  -    add match_end, match_end, -1 # Off by one
       print match_end
       print "\n"
   skipPrint:
  @@ -258,7 +258,7 @@
       my ($imc, $pbc) = @_;
       my $status = system("$PARROT_EXE", "-o", $pbc, $imc);
       if (! defined($status) || $status) {
  -        die "assemble failed: $!";
  +        die "assemble failed with status " . ($? >> 8);
       }
   }
   
  
  
  

Reply via email to