cvsuser     04/08/03 04:21:39

  Modified:    ast      ast.h ast.y astparser.c node.c
               imcc     imc.h imcc.y
               languages/python ast2past.py
               languages/python/t/basic 02_expr.t
  Log:
  ast 7 - void function call
  
  Revision  Changes    Path
  1.7       +2 -0      parrot/ast/ast.h
  
  Index: ast.h
  ===================================================================
  RCS file: /cvs/public/parrot/ast/ast.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -r1.6 -r1.7
  --- ast.h     2 Aug 2004 13:33:02 -0000       1.6
  +++ ast.h     3 Aug 2004 11:21:30 -0000       1.7
  @@ -16,6 +16,7 @@
   typedef context_type       (*node_context_t)(struct nodeType_t*, context_type);
   
   struct _SymReg;
  +struct _IMC_Unit;
   
   typedef struct nodeType_t {
       node_expand_t expand;
  @@ -28,6 +29,7 @@
       struct nodeType_t *up;   /* parent */
       struct nodeType_t *next; /* next statement */
       struct nodeType_t *dest; /* destination or result */
  +    struct _IMC_Unit *unit;
       YYLTYPE loc;
       union {
            struct _SymReg *r;
  
  
  
  1.5       +1 -0      parrot/ast/ast.y
  
  Index: ast.y
  ===================================================================
  RCS file: /cvs/public/parrot/ast/ast.y,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- ast.y     3 Aug 2004 08:03:01 -0000       1.4
  +++ ast.y     3 Aug 2004 11:21:30 -0000       1.5
  @@ -75,6 +75,7 @@
   node: IDENTIFIER '(' nodes0 ')'   { $$ = IMCC_new_node(interp, $1, $3, &@1); }
       | FUNCTION          { cur_unit = imc_open_unit(interp, IMC_PCCSUB); }
                    '(' nodes ')'  { $$ = IMCC_new_node(interp, $1, $4, &@1);
  +                               $$->unit = cur_unit;
                                  cur_unit = cur_unit->prev; }
       | MODULE            { cur_unit = imc_open_unit(interp, IMC_PCCSUB); }
                    '(' nodes ')'  { $$ = IMCC_new_node(interp, $1, $4, &@1); }
  
  
  
  1.7       +13 -12    parrot/ast/astparser.c
  
  Index: astparser.c
  ===================================================================
  RCS file: /cvs/public/parrot/ast/astparser.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -r1.6 -r1.7
  --- astparser.c       3 Aug 2004 08:03:01 -0000       1.6
  +++ astparser.c       3 Aug 2004 11:21:30 -0000       1.7
  @@ -341,8 +341,8 @@
   static const unsigned char yyrline[] =
   {
          0,    61,    61,    62,    65,    66,    69,    70,    71,    72,
  -      75,    76,    76,    79,    79,    83,    85,    86,    87,    90,
  -      93
  +      75,    76,    76,    80,    80,    84,    86,    87,    88,    91,
  +      94
   };
   #endif
   
  @@ -1045,46 +1045,47 @@
     case 12:
   #line 77 "ast/ast.y"
       { yyval.n = IMCC_new_node(interp, yyvsp[-4].t, yyvsp[-1].n, &yylsp[-4]);
  +                               yyval.n->unit = cur_unit;
                                  cur_unit = cur_unit->prev; }
       break;
   
     case 13:
  -#line 79 "ast/ast.y"
  +#line 80 "ast/ast.y"
       { cur_unit = imc_open_unit(interp, IMC_PCCSUB); }
       break;
   
     case 14:
  -#line 80 "ast/ast.y"
  +#line 81 "ast/ast.y"
       { yyval.n = IMCC_new_node(interp, yyvsp[-4].t, yyvsp[-1].n, &yylsp[-4]); }
       break;
   
     case 15:
  -#line 84 "ast/ast.y"
  +#line 85 "ast/ast.y"
       { yyval.n = IMCC_new_const_node(interp, yyvsp[0].s, 'S', &yylsp[0]); }
       break;
   
     case 16:
  -#line 85 "ast/ast.y"
  +#line 86 "ast/ast.y"
       { yyval.n = IMCC_new_const_node(interp, yyvsp[0].s, 'I', &yylsp[0]); }
       break;
   
     case 17:
  -#line 86 "ast/ast.y"
  +#line 87 "ast/ast.y"
       { yyval.n = IMCC_new_const_node(interp, yyvsp[0].s, 'N', &yylsp[0]); }
       break;
   
     case 18:
  -#line 87 "ast/ast.y"
  +#line 88 "ast/ast.y"
       { yyval.n = IMCC_new_const_node(interp, yyvsp[0].s, 'U', &yylsp[0]); }
       break;
   
     case 19:
  -#line 90 "ast/ast.y"
  +#line 91 "ast/ast.y"
       { yyval.n = IMCC_new_var_node(interp, yyvsp[0].s, yyvsp[-1].t, &yylsp[0]); }
       break;
   
     case 20:
  -#line 93 "ast/ast.y"
  +#line 94 "ast/ast.y"
       { yyval.t = 'P'; }
       break;
   
  @@ -1092,7 +1093,7 @@
       }
   
   /* Line 1016 of /usr/share/bison/yacc.c.  */
  -#line 1096 "ast/astparser.c"
  +#line 1097 "ast/astparser.c"
   
     yyvsp -= yylen;
     yyssp -= yylen;
  @@ -1311,7 +1312,7 @@
   }
   
   
  -#line 96 "ast/ast.y"
  +#line 97 "ast/ast.y"
   
   
   static void
  
  
  
  1.9       +129 -22   parrot/ast/node.c
  
  Index: node.c
  ===================================================================
  RCS file: /cvs/public/parrot/ast/node.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- node.c    3 Aug 2004 08:03:01 -0000       1.8
  +++ node.c    3 Aug 2004 11:21:30 -0000       1.9
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2004 The Perl Foundation.  All Rights Reserved.
  -$Id: node.c,v 1.8 2004/08/03 08:03:01 leo Exp $
  +$Id: node.c,v 1.9 2004/08/03 11:21:30 leo Exp $
   
   =head1 NAME
   
  @@ -26,6 +26,7 @@
   
   static nodeType* create_0(int nr, nodeType *self, nodeType *p);
   static nodeType* create_1(int nr, nodeType *self, nodeType *p);
  +static nodeType* create_Func(int nr, nodeType *self, nodeType *p);
   
   static void
   pr(nodeType *p)
  @@ -101,6 +102,12 @@
   }
   
   static nodeType *
  +check_nodes(Interp *interpreter, nodeType *p)
  +{
  +    return p;
  +}
  +
  +static nodeType *
   new_node(YYLTYPE *loc)
   {
       nodeType *p = mem_sys_allocate_zeroed(sizeof(nodeType));
  @@ -164,6 +171,22 @@
       return insINS(interpreter, cur_unit, ins, "new", regs, 2);
   }
   
  +static Instruction *
  +insert_find_global(Interp* interpreter, nodeType *var)
  +{
  +    Instruction *ins;
  +    SymReg *regs[IMCC_MAX_REGS], *r;
  +    char name[128];
  +
  +    ins = cur_unit->last_ins;
  +    sprintf(name, "\"%s\"", var->u.r->name);
  +    r = mk_const(str_dup(name), 'S');
  +
  +    regs[0] = var->u.r;
  +    var->u.r->type = VTIDENTIFIER;
  +    regs[1] = r;
  +    return insINS(interpreter, cur_unit, ins, "find_global", regs, 2);
  +}
   /*
    * node expand aka code creation functions
    */
  @@ -206,30 +229,33 @@
   static nodeType*
   exp_Assign(Interp* interpreter, nodeType *p)
   {
  -    IMC_Unit *unit;
       Instruction *ins;
       SymReg *regs[IMCC_MAX_REGS], *r;
       nodeType *var = NODE0(p);
       nodeType *rhs = var->next;
   
       rhs = rhs->expand(interpreter, rhs);
  -    unit = interpreter->imc_info->last_unit;
  -    ins = unit->last_ins;
  +    ins = cur_unit->last_ins;
       regs[0] = NODE0(var)->u.r;
       regs[1] = rhs->u.r;
       /*
        * TODO If lhs is aliased to another name, this changes both vars.
        *      Assign is wrong too, as "a = b" implies "(a is b) == True"
        */
  -    insINS(interpreter, unit, ins, "set", regs, 2);
  +    insINS(interpreter, cur_unit, ins, "set", regs, 2);
       return rhs;
   }
   
   static nodeType*
  +exp_Args(Interp* interpreter, nodeType *p)
  +{
  +    return NULL;
  +}
  +
  +static nodeType*
   exp_Binary(Interp* interpreter, nodeType *p)
   {
       nodeType *op, *left, *right, *dest;
  -    IMC_Unit *unit;
       Instruction *ins;
       SymReg *regs[IMCC_MAX_REGS];
   
  @@ -238,8 +264,7 @@
       right = left->next;
       left = left->expand(interpreter, left);
       right = right->expand(interpreter, right);
  -    unit = interpreter->imc_info->last_unit;
  -    ins = unit->last_ins;
  +    ins = cur_unit->last_ins;
       if (!p->dest) {
           dest = IMCC_new_temp_node(interpreter, left->u.r->set, &p->loc);
           if (dest->u.r->set == 'P')
  @@ -249,16 +274,71 @@
       regs[0] = dest->u.r;
       regs[1] = left->u.r;
       regs[2] = right->u.r;
  -    insINS(interpreter, unit, ins, NODE0(op)->u.r->name + 1, regs, 3);
  +    insINS(interpreter, cur_unit, ins, NODE0(op)->u.r->name + 1, regs, 3);
       return dest;
   }
   
  +static nodeType*
  +exp_Defaults(Interp* interpreter, nodeType *p)
  +{
  +    return NULL;
  +}
  +
  +static nodeType*
  +exp_Function(Interp* interpreter, nodeType *p)
  +{
  +    nodeType *name, *params, *body;
  +    SymReg *sub;
  +    Instruction *i;
  +    IMC_Unit *last_unit = cur_unit;
  +
  +    cur_unit = p->unit;
  +
  +    name = NODE0(p);
  +    params = name->next;
  +    body = params->next;
  +    sub = mk_sub_address(str_dup(NODE0(name)->u.r->name));
  +    i = INS_LABEL(cur_unit, sub, 1);
  +
  +    i->r[1] = mk_pcc_sub(str_dup(i->r[0]->name), 0);
  +    add_namespace(interpreter, i->r[1]);
  +    i->r[1]->pcc_sub->pragma = P_PROTOTYPED ;
  +
  +    body->expand(interpreter, body);
  +
  +    cur_unit = last_unit;
  +    return NULL; /* XXX return retval */
  +}
  +
  +static nodeType*
  +exp_Params(Interp* interpreter, nodeType *p)
  +{
  +    return NULL;
  +}
  +
  +static nodeType*
  +exp_Py_Call(Interp* interpreter, nodeType *p)
  +{
  +    nodeType *name, *args;
  +    Instruction *ins;
  +    SymReg *regs[IMCC_MAX_REGS];
  +
  +    name = NODE0(p);
  +    args = name->next;
  +    args = args->expand(interpreter, args);
  +    ins = IMCC_create_itcall_label(interpreter);
  +    IMCC_itcall_sub(interpreter, NODE0(name)->u.r);
  +    return NULL;
  +}
   
   static nodeType*
   exp_Py_Local(Interp* interpreter, nodeType *p)
   {
       nodeType *var = NODE0(p);
   
  +    if (var->u.r->type == VTADDRESS)
  +        insert_find_global(interpreter, var);
  +    else
       insert_new(interpreter, var, "Undef");
       return NULL;
   }
  @@ -287,7 +367,6 @@
   static nodeType*
   exp_Py_Print(Interp* interpreter, nodeType *p)
   {
  -    IMC_Unit *unit;
       Instruction *ins;
       SymReg *regs[IMCC_MAX_REGS];
       nodeType * child = NODE0(p), *d;
  @@ -295,15 +374,14 @@
           fatal(1, "exp_Py_Print", "nothing to print");
       for (; child; child = child->next) {
           d = child->expand(interpreter, child);
  -        unit = interpreter->imc_info->last_unit;
  -        ins = unit->last_ins;
           /* TODO file handle node */
           if (d->expand == exp_Const || d->expand == exp_Var ||
                   d->expand == exp_Temp)
               regs[0] = d->u.r;
           else
               fatal(1, "exp_Py_Print", "unknown node to print: '%s'", d->d);
  -        ins = insINS(interpreter, unit, ins, "print_item", regs, 1);
  +        ins = cur_unit->last_ins;
  +        insINS(interpreter, cur_unit, ins, "print_item", regs, 1);
       }
       return NULL;
   }
  @@ -311,10 +389,9 @@
   static nodeType*
   exp_Py_Print_nl(Interp* interpreter, nodeType *p)
   {
  -    IMC_Unit *unit = interpreter->imc_info->last_unit;
  -    Instruction *ins = unit->last_ins;
  +    Instruction *ins = cur_unit->last_ins;
       SymReg *regs[IMCC_MAX_REGS];
  -    insINS(interpreter, unit, ins, "print_newline", regs, 0);
  +    insINS(interpreter, cur_unit, ins, "print_newline", regs, 0);
       return NULL;
   }
   
  @@ -347,12 +424,17 @@
   
   static node_names ast_list[] = {
       { "-no-node-",   NULL, NULL, NULL, NULL },
  +    { "Args",                create_1, exp_Args, NULL, NULL },
       { "AssName",     create_1, exp_Name, NULL, NULL },
       { "Assign",      create_1, exp_Assign, NULL, NULL },
       { "Binary",      create_1, exp_Binary, NULL, NULL },
       { "Const",               NULL,     exp_Const, NULL, dump_Const },
  +    { "Defaults",    create_1, exp_Defaults, NULL, NULL },
  +    { "Function",    create_Func, exp_Function, NULL, NULL },
       { "Name",           create_1, exp_Name, NULL, NULL },
       { "Op",             create_Op, NULL, NULL, dump_Op },
  +    { "Params",      create_1, exp_Params, NULL, NULL },
  +    { "Py_Call",     create_1, exp_Py_Call, NULL, NULL },
       { "Py_Local",    create_1, exp_Py_Local, NULL, NULL },
       { "Py_Module",   create_1, exp_Py_Module, NULL, NULL },
       { "Py_Print" ,   create_1, exp_Py_Print, NULL, NULL },
  @@ -360,8 +442,9 @@
       { "Src_File",            create_1, exp_Src_File, NULL, NULL },
       { "Src_Line",            create_1, exp_Src_Lines, NULL, NULL },
       { "Stmts",          create_1, exp_default, NULL, NULL },
  +    { "Void",           create_1, exp_default, NULL, NULL },
       { "_",              create_0, NULL, NULL, NULL }
  -#define CONST_NODE 4
  +#define CONST_NODE 5
   };
   
   static int
  @@ -396,12 +479,29 @@
   static nodeType*
   create_1(int nr, nodeType *self, nodeType *p)
   {
  +    if (p) {
       p->up = self;
       NODE0(self) = p;
  +    }
       set_fptrs(self, nr);
       return self;
   }
   
  +static nodeType*
  +create_Func(int nr, nodeType *self, nodeType *p)
  +{
  +    SymReg *r;
  +    IMC_Unit *last;
  +    self = create_1(nr, self, p);
  +    r = NODE0(p)->u.r;
  +    last = cur_unit->prev;      /* XXX  ->caller */
  +    r = _get_sym(last->hash, r->name);
  +    /* mark the name being a subroutine name
  +     * s. Py_Local
  +     */
  +    r->type = VTADDRESS;
  +    return self;
  +}
   /*
    * API
    */
  @@ -425,6 +525,9 @@
       r = bsearch(&search, ast_list, sizeof(ast_list) / sizeof(ast_list[0]),
                sizeof(ast_list[0]), ast_comp);
   
  +#if 0
  +    printf("find: '%s' - %d\n", name, r ? r - ast_list : 0);
  +#endif
       if (!r) {
        return 0;
       }
  @@ -464,9 +567,12 @@
   IMCC_new_var_node(Interp* interpreter, char *name, int set, YYLTYPE *loc)
   {
       nodeType *p = new_node(loc);
  +    SymReg *r;
       if (!cur_unit)
           fatal(1, "IMCC_new_var_node", "no cur_unit");
  -    p->u.r = mk_ident(name, set);
  +    p->u.r = r = mk_symreg(name, set);
  +    if (!r->type)
  +        r->type = VTIDENTIFIER;
       p->expand = exp_Var;
       p->dump   = dump_Var;
       return p;
  @@ -561,6 +667,7 @@
   nodeType *
   IMCC_expand_nodes(Interp* interpreter, nodeType *p)
   {
  +    p = check_nodes(interpreter, p);
       return p->expand(interpreter, p);
   }
   
  
  
  
  1.67      +2 -0      parrot/imcc/imc.h
  
  Index: imc.h
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/imc.h,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -w -r1.66 -r1.67
  --- imc.h     1 Aug 2004 16:10:18 -0000       1.66
  +++ imc.h     3 Aug 2004 11:21:33 -0000       1.67
  @@ -203,6 +203,8 @@
   
   void IMCC_ast_init(Interp* interpreter);
   void IMCC_ast_compile(Interp *interpreter, FILE *fp);
  +Instruction * IMCC_create_itcall_label(Interp *);
  +void IMCC_itcall_sub(Interp* interpreter, SymReg* sub);
   
   #endif /* PARROT_IMCC_IMC_H_GUARD */
   
  
  
  
  1.144     +10 -8     parrot/imcc/imcc.y
  
  Index: imcc.y
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/imcc.y,v
  retrieving revision 1.143
  retrieving revision 1.144
  diff -u -w -r1.143 -r1.144
  --- imcc.y    17 Jul 2004 16:01:11 -0000      1.143
  +++ imcc.y    3 Aug 2004 11:21:33 -0000       1.144
  @@ -210,13 +210,14 @@
       return (char *) get_neg_op(op, &n);
   }
   
  -static Instruction *
  -create_itcall_label(void)
  +Instruction *
  +IMCC_create_itcall_label(Interp* interpreter)
   {
       char name[128];
       SymReg * r;
       Instruction *i;
   
  +    UNUSED(interpreter);
       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);
  @@ -224,9 +225,10 @@
       return i;
   }
   
  -static void
  -itcall_sub(SymReg* sub)
  +void
  +IMCC_itcall_sub(Interp* interpreter, SymReg* sub)
   {
  +   UNUSED(interpreter);
      current_call->r[0]->pcc_sub->sub = sub;
      if (cur_obj) {
          if (cur_obj->set != 'P')
  @@ -874,11 +876,11 @@
            }
      |
            {
  -            $<i>$ = create_itcall_label();
  +            $<i>$ = IMCC_create_itcall_label(interp);
            }
        '(' targetlist  ')' '=' the_sub '(' arglist ')'
            {
  -           itcall_sub($6);
  +           IMCC_itcall_sub(interp, $6);
              current_call = NULL;
            }
      | op_assign
  @@ -937,8 +939,8 @@
   sub_call:
        the_sub
           {
  -           $$ = create_itcall_label();
  -           itcall_sub($1);
  +           $$ = IMCC_create_itcall_label(interp);
  +           IMCC_itcall_sub(interp, $1);
           }
        '(' arglist ')'
           {  $$ = $<i>2; }
  
  
  
  1.4       +1 -1      parrot/languages/python/ast2past.py
  
  Index: ast2past.py
  ===================================================================
  RCS file: /cvs/public/parrot/languages/python/ast2past.py,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- ast2past.py       2 Aug 2004 13:33:07 -0000       1.3
  +++ ast2past.py       3 Aug 2004 11:21:36 -0000       1.4
  @@ -385,7 +385,7 @@
        self.set_lineno(node)
        self.begin("Function(")
        if not is_lambda:
  -         self.append("Name(%s)" % `node.name`)
  +         self.append("Name(:%s)" % node.name)
            if node.doc:
                self.append("Py_doc(" + `node.doc` + ")")
        self.begin("Params(")
  
  
  
  1.9       +10 -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.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- 02_expr.t 3 Aug 2004 05:14:23 -0000       1.8
  +++ 02_expr.t 3 Aug 2004 11:21:39 -0000       1.9
  @@ -1,9 +1,9 @@
  -# $Id: 02_expr.t,v 1.8 2004/08/03 05:14:23 leo Exp $
  +# $Id: 02_expr.t,v 1.9 2004/08/03 11:21:39 leo Exp $
   
   use strict;
   use lib '../../lib';
   
  -use Parrot::Test tests => 11;
  +use Parrot::Test tests => 12;
   
   sub test {
       language_output_is('python', $_[0], '', $_[1]);
  @@ -51,6 +51,14 @@
   print a, b
   CODE
   
  +test( <<'CODE', 'void call' );
  +def f():
  +    print "f"
  +print "main"
  +f()
  +print "ok"
  +CODE
  +
   SKIP: {
      skip("Not yet", 3);
   
  
  
  

Reply via email to