cvsuser     04/02/22 13:06:10

  Modified:    imcc     imcc.y pcc.c
               imcc/t/syn pcc.t
  Log:
  remove some cut'n paste code
  
  Revision  Changes    Path
  1.120     +42 -33    parrot/imcc/imcc.y
  
  Index: imcc.y
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/imcc.y,v
  retrieving revision 1.119
  retrieving revision 1.120
  diff -u -w -r1.119 -r1.120
  --- imcc.y    22 Feb 2004 13:59:54 -0000      1.119
  +++ imcc.y    22 Feb 2004 21:06:07 -0000      1.120
  @@ -194,6 +194,30 @@
       return (char *) get_neg_op(op, &n);
   }
   
  +static Instruction *
  +create_itcall_label(void)
  +{
  +    char name[128];
  +    SymReg * r;
  +    Instruction *i;
  +
  +    sprintf(name, "%cpcc_sub_call_%d", IMCC_INTERNAL_CHAR, cnr++);
  +    r = mk_pcc_sub(str_dup(name), 0);
  +    current_call = i = iLABEL(cur_unit, r);
  +    i->type = ITCALL | ITPCCSUB;
  +    return i;
  +}
  +
  +static void
  +itcall_sub(SymReg* sub)
  +{
  +   current_call->r[0]->pcc_sub->sub = sub;
  +   /* FIXME use the default settings from .pragma */
  +   current_call->r[0]->pcc_sub->pragma = P_PROTOTYPED;
  +   if(cur_unit->type == IMC_PCCSUB)
  +        cur_unit->instructions->r[1]->pcc_sub->calls_a_sub = 1;
  +}
  +
   %}
   
   %union {
  @@ -236,7 +260,7 @@
   %type <i> labels _labels label statements statement sub_call
   %type <i> pcc_sub_call
   %type <sr> sub_param sub_params pcc_arg pcc_result pcc_args pcc_results pcc_params 
pcc_param
  -%type <sr> pcc_returns pcc_return pcc_call arg
  +%type <sr> pcc_returns pcc_return pcc_call arg the_sub
   %type <t> pcc_proto pcc_sub_proto proto
   %type <i> instruction assignment if_statement labeled_inst opt_label
   %type <sr> target reg const var string
  @@ -792,43 +816,28 @@
            }
      |
            {
  -            char name[128];
  -            SymReg * r;
  -            Instruction *i;
  -            sprintf(name, "%cpcc_sub_call_%d", IMCC_INTERNAL_CHAR, cnr++);
  -            r = mk_pcc_sub(str_dup(name), 0);
  -            current_call = i = iLABEL(cur_unit, r);
  -            i->type = ITCALL | ITPCCSUB;
  -            $<i>$ = i;
  +            $<i>$ = create_itcall_label();
            }
  -     '(' targetlist  ')' '=' IDENTIFIER '(' arglist ')'
  +     '(' targetlist  ')' '=' the_sub '(' arglist ')'
            {
  -            current_call->r[0]->pcc_sub->sub = mk_sub_address($6);
  -           /* FIXME use the default settings from .pragma */
  -            current_call->r[0]->pcc_sub->pragma = P_PROTOTYPED;
  -            if(cur_unit->type == IMC_PCCSUB)
  -               cur_unit->instructions->r[1]->pcc_sub->calls_a_sub = 1;
  -
  +           itcall_sub($6);
               current_call = NULL;
            }
      ;
   
  +the_sub: IDENTIFIER  { $$ = mk_sub_address($1); }
  +       /* this produces 18 shift/reduce conflicts and wrong code
  +       | target      { $$ = $1;
  +                       if ($1->set != 'P')
  +                          fataly(1, sourcefile, line, "Sub isn't a PMC");
  +       */
  +   ;
  +
   sub_call:
  -     IDENTIFIER
  +     the_sub
           {
  -           char name[128];
  -           SymReg * r;
  -           Instruction *i;
  -           sprintf(name, "%cpcc_sub_call_%d", IMCC_INTERNAL_CHAR, cnr++);
  -           r = mk_pcc_sub(str_dup(name), 0);
  -           current_call = i = iLABEL(cur_unit, r);
  -           i->type = ITCALL | ITPCCSUB;
  -           $$ = i;
  -           current_call->r[0]->pcc_sub->sub = mk_sub_address($1);
  -           /* FIXME use the default settings from .pragma */
  -           current_call->r[0]->pcc_sub->pragma = P_PROTOTYPED;
  -           if(cur_unit->type == IMC_PCCSUB)
  -              cur_unit->instructions->r[1]->pcc_sub->calls_a_sub = 1;
  +           $$ = create_itcall_label();
  +           itcall_sub($1);
           }
        '(' arglist ')'
           {  $$ = $<i>2; }
  
  
  
  1.44      +17 -9     parrot/imcc/pcc.c
  
  Index: pcc.c
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/pcc.c,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -w -r1.43 -r1.44
  --- pcc.c     22 Feb 2004 18:54:11 -0000      1.43
  +++ pcc.c     22 Feb 2004 21:06:07 -0000      1.44
  @@ -762,10 +762,15 @@
        * See if we need to create a temporary sub object
        */
       if (ins->type & ITCALL) {
  +        if (sub->pcc_sub->sub->type == VTADDRESS) {
   #if IMC_TRACE
  -        fprintf(stderr, "generating sub object [sub->name = %s]\n", 
sub->pcc_sub->sub->name);
  +            fprintf(stderr, "generating sub object [sub->name = %s]\n",
  +                    sub->pcc_sub->sub->name);
   #endif
  -        /* sub->pcc_sub->sub is an actual subroutine name, not a variable. */
  +            /*
  +             * sub->pcc_sub->sub is an actual subroutine name,
  +             * not a variable.
  +             */
           reg = mk_temp_reg('P');
           tmp = iNEWSUB(interp, unit, reg, NEWSUB, sub->pcc_sub->sub, NULL, 0);
           add_pcc_sub(sub, reg);
  @@ -774,6 +779,9 @@
   
           expand_pcc_sub_call(interp, unit, ins);
           return;
  +        }
  +        else
  +            add_pcc_sub(sub, sub->pcc_sub->sub);
       }
   
       /*
  
  
  
  1.34      +20 -1     parrot/imcc/t/syn/pcc.t
  
  Index: pcc.t
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/t/syn/pcc.t,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -w -r1.33 -r1.34
  --- pcc.t     22 Feb 2004 18:54:14 -0000      1.33
  +++ pcc.t     22 Feb 2004 21:06:10 -0000      1.34
  @@ -1,6 +1,6 @@
   #!perl
   use strict;
  -use TestCompiler tests => 30;
  +use TestCompiler tests => 31;
   
   ##############################
   # Parrot Calling Conventions
  @@ -1222,4 +1222,23 @@
   .end
   CODE
   ok
  +OUT
  +
  +output_is(<<'CODE', <<'OUT', "_func() syntax");
  +.sub _main
  +    _sub(10, 20)
  +    end
  +.end
  +.pcc_sub _sub prototyped
  +    .param int a
  +    .param int b
  +    print a
  +    print "\n"
  +    print b
  +    print "\n"
  +    end
  +.end
  +CODE
  +10
  +20
   OUT
  
  
  

Reply via email to