cvsuser     04/08/05 09:47:16

  Modified:    ast      node.c
               languages/python/t/basic 02_expr.t
  Log:
  ast 19 - slower but safer - store by name
  
  Revision  Changes    Path
  1.21      +34 -13    parrot/ast/node.c
  
  Index: node.c
  ===================================================================
  RCS file: /cvs/public/parrot/ast/node.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -w -r1.20 -r1.21
  --- node.c    5 Aug 2004 15:48:33 -0000       1.20
  +++ node.c    5 Aug 2004 16:47:11 -0000       1.21
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2004 The Perl Foundation.  All Rights Reserved.
  -$Id: node.c,v 1.20 2004/08/05 15:48:33 leo Exp $
  +$Id: node.c,v 1.21 2004/08/05 16:47:11 leo Exp $
   
   =head1 NAME
   
  @@ -377,6 +377,18 @@
       return insINS(interpreter, cur_unit, ins, "find_global", regs, 2);
   }
   
  +static const char*
  +default_pmc_type(nodeType *p)
  +{
  +    const char *pmc;
  +    switch (p->u.var.r->set) {
  +        case 'I': pmc = INT_TYPE; break;
  +        case 'S': pmc = FLOAT_TYPE; break;
  +        case 'N': pmc = STRING_TYPE; break;
  +        default:  pmc = UNDEF_TYPE; break;
  +    }
  +    return pmc;
  +}
   /*
    * promote a Const or Var to a PMC node, if it isn't yet a PMC
    */
  @@ -387,12 +399,9 @@
       const char *pmc;
       nodeType *temp;
   
  -    switch (p->u.var.r->set) {
  -        case 'I': pmc = INT_TYPE; break;
  -        case 'S': pmc = FLOAT_TYPE; break;
  -        case 'N': pmc = STRING_TYPE; break;
  -        default:  return p;
  -    }
  +    if (p->u.var.r->set == 'P')
  +        return p;
  +    pmc = default_pmc_type(p);
       temp = IMCC_new_temp_node(interpreter, 'P', &p->loc);
       *ins = insert_new(interpreter, temp, pmc);
       regs[0] = temp->u.var.r;
  @@ -451,19 +460,25 @@
       nodeType *var = CHILD(p);
       nodeType *rhs = var->next;
       int assigned = 0;
  +    char buf[128];
   
       if (rhs->expand == exp_Binary) {
  -        ins = cur_unit->last_ins;
  +        /*
  +         * set the destination node, where the binary places
  +         * the result
  +         */
           rhs->dest = var;
           rhs = rhs->expand(interpreter, rhs);
           assigned = 1;
       }
       else if (rhs->expand == exp_Const) {
  +        const char *pmc;
           /* need a new value, because the name might be aliased by
            * a = b
            */
           ins = cur_unit->last_ins;
  -        rhs = node_to_pmc(interpreter, &ins, rhs);
  +        pmc = default_pmc_type(var);
  +        ins = insert_new(interpreter, var, pmc);
       }
       else {
           rhs = rhs->expand(interpreter, rhs);
  @@ -472,7 +487,12 @@
       if (!assigned) {
           regs[0] = var->u.var.r;
           regs[1] = rhs->u.var.r;
  -        insINS(interpreter, cur_unit, ins, "set", regs, 2);
  +        ins = insINS(interpreter, cur_unit, ins, "set", regs, 2);
  +        regs[0] = get_const("-1", 'I');
  +        sprintf(buf, "\"%s\"", var->u.var.r->name);
  +        regs[1] = get_const(buf, 'S');
  +        regs[2] = var->u.var.r;
  +        insINS(interpreter, cur_unit, ins, "store_lex", regs, 3);
       }
       return var;
   }
  @@ -500,7 +520,7 @@
       nodeType *op, *left, *right, *dest;
       Instruction *ins;
       SymReg *regs[IMCC_MAX_REGS];
  -    char buf[16];
  +    char buf[128];
   
       op = CHILD(p);
       left = op->next;
  @@ -527,8 +547,8 @@
            */
           regs[0] = dest->u.var.r;
           regs[1] = get_const("-1", 'I');
  -        sprintf(buf, "%d", dest->u.var.local_nr);
  -        regs[2] = get_const(buf, 'I');
  +        sprintf(buf, "\"%s\"", dest->u.var.r->name);
  +        regs[2] = get_const(buf, 'S');
           ins = insINS(interpreter, cur_unit, ins, "find_lex", regs, 3);
       }
       else {
  @@ -753,6 +773,7 @@
       sprintf(buf, "\"%s\"", var->u.var.r->name);
       regs[1] = get_const(buf, 'S');
       regs[2] = var->u.var.r;
  +    var->u.var.local_nr = cur_unit->local_count++;
       insINS(interpreter, cur_unit, ins, "store_lex", regs, 3);
       return NULL;
   }
  
  
  
  1.14      +11 -3     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.13
  retrieving revision 1.14
  diff -u -w -r1.13 -r1.14
  --- 02_expr.t 5 Aug 2004 15:48:42 -0000       1.13
  +++ 02_expr.t 5 Aug 2004 16:47:16 -0000       1.14
  @@ -1,9 +1,9 @@
  -# $Id: 02_expr.t,v 1.13 2004/08/05 15:48:42 leo Exp $
  +# $Id: 02_expr.t,v 1.14 2004/08/05 16:47:16 leo Exp $
   
   use strict;
   use lib '../../lib';
   
  -use Parrot::Test tests => 21;
  +use Parrot::Test tests => 22;
   
   sub test {
       language_output_is('python', $_[0], '', $_[1]);
  @@ -57,6 +57,14 @@
   print a,b
   CODE
   
  +test( <<'CODE', 'assign a,b - change more');
  +a=b=41
  +b=2
  +print a,b
  +a = a + b
  +print a,b
  +CODE
  +
   test( <<'CODE', 'sub I, P' );
   a = 1 + 2
   a = 4 - a
  
  
  

Reply via email to