cvsuser 04/08/03 07:39:20
Modified: ast ast_main.c node.c
Log:
ast 9 - simpler name handling; dump to stderr
Revision Changes Path
1.5 +2 -1 parrot/ast/ast_main.c
Index: ast_main.c
===================================================================
RCS file: /cvs/public/parrot/ast/ast_main.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -r1.4 -r1.5
--- ast_main.c 3 Aug 2004 12:51:02 -0000 1.4
+++ ast_main.c 3 Aug 2004 14:39:20 -0000 1.5
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2004 The Perl Foundation. All Rights Reserved.
-$Id: ast_main.c,v 1.4 2004/08/03 12:51:02 leo Exp $
+$Id: ast_main.c,v 1.5 2004/08/03 14:39:20 leo Exp $
=head1 NAME
@@ -56,6 +56,7 @@
if (top_node) {
if (interpreter->imc_info->debug & 0x100) {
IMCC_dump_nodes(top_node); /* TODO commandline switches */
+ fprintf(stderr, "\n");
}
IMCC_free_nodes(interpreter, top_node);
}
1.11 +28 -33 parrot/ast/node.c
Index: node.c
===================================================================
RCS file: /cvs/public/parrot/ast/node.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -r1.10 -r1.11
--- node.c 3 Aug 2004 12:51:02 -0000 1.10
+++ node.c 3 Aug 2004 14:39:20 -0000 1.11
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2004 The Perl Foundation. All Rights Reserved.
-$Id: node.c,v 1.10 2004/08/03 12:51:02 leo Exp $
+$Id: node.c,v 1.11 2004/08/03 14:39:20 leo Exp $
=head1 NAME
@@ -27,13 +27,14 @@
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 nodeType* create_Name(int nr, nodeType *self, nodeType *p);
static void
pr(nodeType *p)
{
if (!p)
return;
- printf("%s", p->u.r->name);
+ fprintf(stderr, "%s", p->u.r->name);
}
static void
@@ -46,12 +47,13 @@
dump_Op(nodeType *p, int l)
{
pr(NODE0(p));
- printf("'");
+ fprintf(stderr, "'");
}
static void
dump_Var(nodeType *p, int l)
{
+ fprintf(stderr, ":");
pr(p);
}
@@ -87,8 +89,8 @@
dump(nodeType *p, int l)
{
nodeType *child;
- printf("\n%*s", l*2, "");
- printf("%s(", p->d);
+ fprintf(stderr, "\n%*s", l*2, "");
+ fprintf(stderr, "%s(", p->d);
if (p->dump)
p->dump(p, l);
else {
@@ -96,7 +98,7 @@
if (child)
dump(child, l + 1);
}
- printf(")");
+ fprintf(stderr, ")");
if (p->next )
dump(p->next, l);
}
@@ -198,12 +200,6 @@
}
static nodeType*
-exp_Name(Interp* interpreter, nodeType *p)
-{
- return NODE0(p);
-}
-
-static nodeType*
exp_next(Interp* interpreter, nodeType *p)
{
nodeType *next;
@@ -236,7 +232,7 @@
rhs = rhs->expand(interpreter, rhs);
ins = cur_unit->last_ins;
- regs[0] = NODE0(var)->u.r;
+ regs[0] = var->u.r;
regs[1] = rhs->u.r;
/*
* TODO If lhs is aliased to another name, this changes both vars.
@@ -297,7 +293,7 @@
name = NODE0(p);
params = name->next;
body = params->next;
- sub = mk_sub_address(str_dup(NODE0(name)->u.r->name));
+ sub = mk_sub_address(str_dup(name->u.r->name));
i = INS_LABEL(cur_unit, sub, 1);
i->r[1] = mk_pcc_sub(str_dup(i->r[0]->name), 0);
@@ -327,15 +323,13 @@
args = name->next;
args = args->expand(interpreter, args);
ins = IMCC_create_itcall_label(interpreter);
- IMCC_itcall_sub(interpreter, NODE0(name)->u.r);
+ IMCC_itcall_sub(interpreter, name->u.r);
return NULL;
}
static nodeType*
-exp_Py_Local(Interp* interpreter, nodeType *p)
+exp_Py_Local(Interp* interpreter, nodeType *var)
{
- nodeType *var = NODE0(p);
-
if (var->u.r->type == VTADDRESS)
insert_find_global(interpreter, var);
else
@@ -375,8 +369,7 @@
for (; child; child = child->next) {
d = child->expand(interpreter, child);
/* TODO file handle node */
- if (d->expand == exp_Const || d->expand == exp_Var ||
- d->expand == exp_Temp)
+ if (d->dump == dump_Const || d->dump == dump_Var)
regs[0] = d->u.r;
else
fatal(1, "exp_Py_Print", "unknown node to print: '%s'", d->d);
@@ -425,17 +418,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 },
+ { "AssName", create_Name, NULL, 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 },
+ { "Name", create_Name, NULL, 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_Local", create_Name, exp_Py_Local, NULL, NULL },
{ "Py_Module", create_1, exp_Py_Module, NULL, NULL },
{ "Py_Print" , create_1, exp_Py_Print, NULL, NULL },
{ "Py_Print_nl", create_0, exp_Py_Print_nl, NULL, NULL },
@@ -456,11 +449,6 @@
}
static void
-print_node_name(int i) {
- printf("%s", ast_list[i].name);
-}
-
-static void
set_fptrs(nodeType *self, int nr)
{
self->d = ast_list[nr].name;
@@ -493,7 +481,7 @@
SymReg *r;
IMC_Unit *last;
self = create_1(nr, self, p);
- r = NODE0(p)->u.r;
+ r = p->u.r;
last = cur_unit->prev; /* XXX ->caller */
r = _get_sym(last->hash, r->name);
/* mark the name being a subroutine name
@@ -502,6 +490,15 @@
r->type = VTADDRESS;
return self;
}
+
+static nodeType*
+create_Name(int nr, nodeType *self, nodeType *p)
+{
+ p->d = ast_list[nr].name;
+ p->expand = ast_list[nr].expand;
+ mem_sys_free(self);
+ return p;
+}
/*
* API
*/
@@ -571,7 +568,7 @@
if (!cur_unit)
fatal(1, "IMCC_new_var_node", "no cur_unit");
p->u.r = r = mk_symreg(name, set);
- if (!r->type)
+ if (r->type != VTADDRESS)
r->type = VTIDENTIFIER;
p->expand = exp_Var;
p->d = "Var";
@@ -676,9 +673,7 @@
IMCC_free_nodes(Interp* interpreter, nodeType *p)
{
nodeType *child, *next, *dest;
- if (p->expand == exp_Const ||
- p->expand == exp_Temp ||
- p->expand == exp_Var)
+ if (p->dump == dump_Const || p->dump == dump_Var)
;
else {
child = NODE0(p);