cvsuser     05/03/21 01:10:24

  Modified:    imcc     imcc.l imcc.y
               imcc/t/syn tail.t
  Log:
  [PATCH] Return a varying number of values in IMCC
  
     1.  Makes it possible to say '.flatten foo' as part of a
  .pcc_begin_return/.pcc_end_return sequence.  Remarkably, this part of
  the patch is only a one-line change; the internals for call & return are
  closer than the syntax.
  
     2.  Makes '.flatten' equivalent to '.flatten_arg' for all other
  purposes, to emphasize the similarity.
  
  Courtesy of Bob Rogers <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.125     +1 -0      parrot/imcc/imcc.l
  
  Index: imcc.l
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/imcc.l,v
  retrieving revision 1.124
  retrieving revision 1.125
  diff -u -r1.124 -r1.125
  --- imcc.l    28 Feb 2005 10:41:18 -0000      1.124
  +++ imcc.l    21 Mar 2005 09:10:22 -0000      1.125
  @@ -193,6 +193,7 @@
   
   ".sym"          return(LOCAL);
   ".arg"          return(ARG);
  +".flatten"      return(FLATTEN);
   ".flatten_arg"  return(FLATTEN_ARG);
   ".sub"          return(SUB);
   ".end"          return(ESUB);
  
  
  
  1.155     +8 -1      parrot/imcc/imcc.y
  
  Index: imcc.y
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/imcc.y,v
  retrieving revision 1.154
  retrieving revision 1.155
  diff -u -r1.154 -r1.155
  --- imcc.y    30 Nov 2004 09:35:10 -0000      1.154
  +++ imcc.y    21 Mar 2005 09:10:22 -0000      1.155
  @@ -332,7 +332,7 @@
   %nonassoc <t> PARAM
   
   %token <t> PRAGMA
  -%token <t> CALL GOTO ARG FLATTEN_ARG IF UNLESS END SAVEALL RESTOREALL
  +%token <t> CALL GOTO ARG FLATTEN_ARG FLATTEN IF UNLESS END SAVEALL RESTOREALL
   %token <t> NEW NEWSUB NEWCLOSURE NEWCOR NEWCONT
   %token <t> NAMESPACE ENDNAMESPACE CLASS ENDCLASS FIELD DOT_METHOD
   %token <t> SUB SYM LOCAL CONST
  @@ -719,6 +719,9 @@
   
   pcc_arg:
        ARG var                           {  $$ = $2; }
  +   | FLATTEN target                    { $2->type |= VT_FLATTEN; $$ = $2; }
  +   /* .flatten is preferred, for symmetry with pcc_return, but .flatten_arg 
is
  +      accepted for backwards compatibility. */
      | FLATTEN_ARG target                {  $2->type |= VT_FLATTEN; $$ = $2; }
      ;
   
  @@ -765,6 +768,7 @@
   
   pcc_return:
        RETURN var    {  $$ = $2; }
  +   | FLATTEN target                {  $2->type |= VT_FLATTEN; $$ = $2; }
      ;
   
   pcc_return_many:
  @@ -1088,6 +1092,9 @@
   arg:
        var
                      { $$ = $1; }
  +   | FLATTEN target                    { $2->type |= VT_FLATTEN; $$ = $2; }
  +   /* .flatten is preferred, for symmetry with pcc_return, but .flatten_arg 
is
  +      accepted for backwards compatibility. */
      | FLATTEN_ARG target
                      { $2->type |= VT_FLATTEN; $$ = $2; }
      ;
  
  
  
  1.3       +66 -2     parrot/imcc/t/syn/tail.t
  
  Index: tail.t
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/t/syn/tail.t,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- tail.t    4 Mar 2005 17:49:04 -0000       1.2
  +++ tail.t    21 Mar 2005 09:10:24 -0000      1.3
  @@ -1,9 +1,9 @@
   #!perl
   # Copyright: 2005 The Perl Foundation.  All Rights Reserved.
  -# $Id: tail.t,v 1.2 2005/03/04 17:49:04 bernhard Exp $
  +# $Id: tail.t,v 1.3 2005/03/21 09:10:24 leo Exp $
   
   use strict;
  -use Parrot::Test tests => 3;
  +use Parrot::Test tests => 4;
   
   ##############################
   # Parrot Calling Conventions:  Tail call optimization.
  @@ -271,3 +271,67 @@
   [doing _funcall]
   _fib_step returned 3 values, 23, 20, and 3.
   OUT
  +
  +pir_output_is(<<'CODE', <<'OUT', ".flatten_arg in return");
  +
  +.sub _main @MAIN
  +
  +     $P1 = new PerlInt
  +     $P1 = 20
  +     $P2 = new PerlInt
  +     $P2 = 3
  +     newsub $P98, .Sub, _fib_step
  +     ($P3, $P4, $P5) = _funcall($P98, $P1, $P2)
  +     print "_fib_step returned "
  +     print argcP
  +     print " values, "
  +     print $P3
  +     print ", "
  +     print $P4
  +     print ", and "
  +     print $P5
  +     print ".\n"
  +.end
  +
  +.sub _funcall non_prototyped
  +     .param pmc function
  +     .local pmc argv
  +     argv = foldup 1
  +
  +     $I33 = defined function
  +     unless $I33 goto bad_func
  +doit:
  +     .pcc_begin prototyped
  +     .flatten_arg argv
  +     .pcc_call function
  +     .pcc_end
  +     $P35 = foldup
  +        $I35 = $P35
  +        print "[got "
  +        print $I35
  +        print " results]\n"
  +     .pcc_begin_return
  +     .flatten $P35
  +     .pcc_end_return
  +bad_func:
  +     printerr "_funcall:  Bad function.\n"
  +     die
  +.end
  +
  +## Return the sum and the two arguments as three integers.
  +.sub _fib_step
  +     .param pmc arg1
  +     .param pmc arg2
  +
  +     $P1 = new PerlInt
  +     $P1 = arg1 + arg2
  +     .pcc_begin_return
  +     .return $P1
  +     .return arg1
  +     .return arg2
  +     .pcc_end_return
  +.end
  +CODE
  +[got 3 results]
  +_fib_step returned 3 values, 23, 20, and 3.
  +OUT
  
  
  

Reply via email to