cvsuser     04/08/04 02:00:41

  Modified:    ast      node.c
               languages/python/t/basic 02_expr.t
  Log:
  ast 12 - more mixed binary operands
  
  Revision  Changes    Path
  1.13      +42 -4     parrot/ast/node.c
  
  Index: node.c
  ===================================================================
  RCS file: /cvs/public/parrot/ast/node.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -w -r1.12 -r1.13
  --- node.c    4 Aug 2004 07:48:42 -0000       1.12
  +++ node.c    4 Aug 2004 09:00:37 -0000       1.13
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2004 The Perl Foundation.  All Rights Reserved.
  -$Id: node.c,v 1.12 2004/08/04 07:48:42 leo Exp $
  +$Id: node.c,v 1.13 2004/08/04 09:00:37 leo Exp $
   
   =head1 NAME
   
  @@ -266,6 +266,26 @@
       return NULL;
   }
   
  +static int
  +is_symmetric(char *op)
  +{
  +    return strcmp(op, "add") == 0 ||
  +           strcmp(op, "mul") == 0
  +           ? 1 : 0;
  +}
  +
  +static nodeType*
  +node_to_pmc(Interp* interpreter, Instruction **ins, nodeType *p)
  +{
  +    SymReg *regs[IMCC_MAX_REGS];
  +    nodeType *temp = IMCC_new_temp_node(interpreter, 'P', &p->loc);
  +    *ins = insert_new(interpreter, temp, "Undef");
  +    regs[0] = temp->u.r;
  +    regs[1] = p->u.r;
  +    *ins = insINS(interpreter, cur_unit, *ins, "set", regs, 2);
  +    return temp;
  +}
  +
   /*
    * Op
    * left
  @@ -294,15 +314,33 @@
        */
       ins = cur_unit->last_ins;
       if (!p->dest) {
  +        int reg_set;
           /*
            * p->dest is currently unused - if the optimizer can figure out that
            * the destination can get assigned directly, C<dest> will
            * hold the destination of the binary
            *
  -         * else creae a temp of the same type as the left operand
  -         * TODO check mixed types
  +         * else create a temp of the same type as the left operand
  +         */
  +        reg_set = left->u.r->set;
  +        /*
  +         * TODO if context handling is done expansion of
  +         *      the left and right node should do the right thing
  +         */
  +        if (right->u.r->set == 'P' && reg_set != 'P') {
  +            reg_set = 'P';
  +            /* when it's a symmetric opcode, swap left and right
            */
  -        dest = IMCC_new_temp_node(interpreter, left->u.r->set, &p->loc);
  +            if (is_symmetric(op->u.r->name)) {
  +                nodeType *temp = left;
  +                left = right;
  +                right = temp;
  +            }
  +            else {
  +                left = node_to_pmc(interpreter, &ins, left);
  +            }
  +        }
  +        dest = IMCC_new_temp_node(interpreter, reg_set, &p->loc);
           if (dest->u.r->set == 'P')
               ins = insert_new(interpreter, dest, "Undef");
       }
  
  
  
  1.10      +8 -2      parrot/languages/python/t/basic/02_expr.t
  
  Index: 02_expr.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/python/t/basic/02_expr.t,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -w -r1.9 -r1.10
  --- 02_expr.t 3 Aug 2004 11:21:39 -0000       1.9
  +++ 02_expr.t 4 Aug 2004 09:00:41 -0000       1.10
  @@ -1,9 +1,9 @@
  -# $Id: 02_expr.t,v 1.9 2004/08/03 11:21:39 leo Exp $
  +# $Id: 02_expr.t,v 1.10 2004/08/04 09:00:41 leo Exp $
   
   use strict;
   use lib '../../lib';
   
  -use Parrot::Test tests => 12;
  +use Parrot::Test tests => 13;
   
   sub test {
       language_output_is('python', $_[0], '', $_[1]);
  @@ -51,6 +51,12 @@
   print a, b
   CODE
   
  +test( <<'CODE', 'sub I, P' );
  +a = 1 + 2
  +a = 4 - a
  +print a, a * 2
  +CODE
  +
   test( <<'CODE', 'void call' );
   def f():
       print "f"
  
  
  

Reply via email to