cvsuser     04/11/24 19:51:28

  Modified:    languages/regex README test.pl
               languages/regex/lib/Regex Rewrite.pm
               languages/regex/lib/Regex/CodeGen IMCC.pm
  Log:
  Implement subrule calling in the PIR backend, too.
  
  Revision  Changes    Path
  1.14      +23 -6     parrot/languages/regex/README
  
  Index: README
  ===================================================================
  RCS file: /cvs/public/parrot/languages/regex/README,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- README    21 Nov 2004 07:55:04 -0000      1.13
  +++ README    25 Nov 2004 03:51:25 -0000      1.14
  @@ -42,13 +42,24 @@
   
   All of this really ought to be in a usage message.
   
  -To run any of the generated code, you now need the Match and
  -MatchRange PMCs. They should be generated automatically now by the
  -root makefile, but if for some reason they aren't, run 'make' in
  -parrot/dynclasses/ to generate them.
  +To run any of the generated code, you need the Match and MatchRange
  +PMCs. They should be generated automatically now by the root makefile,
  +but if for some reason they aren't, run 'make' in parrot/dynclasses/
  +to generate them.
  +
  +The above commands only generate subroutines for matching regular
  +expressions. They don't provide fun test programs to try out. For
  +that, use the test.pl script with the -c flag to generate a test.pbc
  +file that will accept an input string on the command line:
  +
  +  perl test.pl -c --expr='a*x'
  +  ../../parrot test.pbc baax
  + (output)
  +  Match found
  +  0: 1..3
   
  -New stuff (CURRENTLY BROKEN): now you can use the compiler as an
  -embedded Parrot compiler. Run 'make regex-compiler.pbc' to generate
  +New stuff: now you can use the compiler as an embedded Parrot
  +compiler. Run 'make regex-compiler.pbc' to generate
   regex-compiler.pbc. Then run ../../parrot 01_basic.imc, ../../parrot
   02_date.imc, etc. These will dynamically load in the regex-compiler as
   the compiler for the "regex" language, and then use it to compile some
  @@ -81,6 +92,12 @@
   All of the <?foo> things are there so that the rules get nicely
   captured -- by default, nested rule calls are *not* capturing.
   
  +The above should now also work with --language=pir as well (actually,
  +that's the default).
  +
  +If you use the -d flag while generating PIR code, you'll get a very
  +verbose description of its matching progress.
  +
   STATUS
   ======
   
  
  
  
  1.20      +14 -5     parrot/languages/regex/test.pl
  
  Index: test.pl
  ===================================================================
  RCS file: /cvs/public/parrot/languages/regex/test.pl,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- test.pl   18 Nov 2004 06:55:56 -0000      1.19
  +++ test.pl   25 Nov 2004 03:51:25 -0000      1.20
  @@ -62,6 +62,9 @@
   my $list_opt = 1;
   my $language;
   my $testfile;
  +my $pattern;
  +
  +# Hm. What versions of perl provide Getopt::Long as a builtin?
   foreach (@ARGV) {
       if (/^(-h|--help)$/) {
           usage(0);
  @@ -72,6 +75,8 @@
           $list_opt = 0;
       } elsif (/--language=(.*)/) {
           $language = $1;
  +    } elsif (/--expr=(.*)/) {
  +        $pattern = $1;
       } elsif (/--optimize=(.*)/) {
           my $opts = $1;
           $tree_opt = ($opts =~ /t/i);
  @@ -86,11 +91,13 @@
   }
   
   usage "not enough args: testfile required"
  -  if ! defined $testfile;
  +  if ! defined $testfile && ! defined $pattern;
   
  -open(SPEC, $testfile) or die "open $testfile: $!";
  -my $pattern = <SPEC>;
  -chomp($pattern);
  +if (defined $testfile) {
  +    open(SPEC, $testfile) or die "open $testfile: $!";
  +    $pattern = <SPEC>;
  +    chomp($pattern);
  +}
   
   generate_regular($pattern);
   exit(0) if $compile;
  @@ -199,7 +206,9 @@
   .end
   END
   
  -    $driver->output_rule(*PIR, '_regex', $trees->[0], $ctx, DEBUG => $DEBUG);
  +    for my $tree (@$trees) {
  +        $driver->output_rule(*PIR, '_regex', $tree, $ctx, DEBUG => $DEBUG);
  +    }
   
       close PIR;
   }
  
  
  
  1.20      +1 -0      parrot/languages/regex/lib/Regex/Rewrite.pm
  
  Index: Rewrite.pm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/regex/lib/Regex/Rewrite.pm,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Rewrite.pm        18 Nov 2004 07:01:12 -0000      1.19
  +++ Rewrite.pm        25 Nov 2004 03:51:26 -0000      1.20
  @@ -905,6 +905,7 @@
   sub describe_seq { undef };
   sub describe_check { undef };
   sub describe_group { "group $_[3]" }
  +sub describe_rule { undef }
   
   sub wrap {
       my ($self, $op, $back, @ops) = @_;
  
  
  
  1.10      +23 -7     parrot/languages/regex/lib/Regex/CodeGen/IMCC.pm
  
  Index: IMCC.pm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/regex/lib/Regex/CodeGen/IMCC.pm,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- IMCC.pm   18 Nov 2004 07:01:13 -0000      1.9
  +++ IMCC.pm   25 Nov 2004 03:51:28 -0000      1.10
  @@ -452,13 +452,29 @@
               ".return (<rx_match>)");
   }
   
  -# There is no language-independent way of calling a rule, because this
  -# requires following the host language's calling conventions. If
  -# you're trying to trace through a compilation, then look for this
  -# method to be overridden in your language-specific code generation
  -# subclass, eg languages/perl6/P6C/IMCC/ExtRegex/CodeGen.pm
  -sub output_call_rule {
  -    die "unimplemented";
  +sub output_call_setup {
  +    my ($self, $name, $uid) = @_;
  +    return ".local pmc $uid";
  +}
  +
  +sub output_call {
  +    my ($self, $name, $mode, $uid) = @_;
  +    return split(/\n/, <<"END");
  +$uid = _$name($mode, <rx_input>, <rx_pos>, <rx_stack>)
  +<rx_pos> = $uid\['!POS']
  +END
  +}
  +
  +sub output_call_result {
  +    my ($self, $uid, $name, $fail) = @_;
  +    my $fail_label = $self->output_label_use($fail);
  +    my @ops;
  +    if (defined $name) {
  +        push @ops, "<rx_match>['$name'] = $uid";
  +    }
  +    return (@ops,
  +            "<rx_tmp> = $uid\['!RESULT']",
  +            "unless <rx_tmp>, $fail_label");
   }
   
   1;
  
  
  

Reply via email to