cvsuser 04/10/31 04:51:21
Modified: ast node.c
imcc imcc.y pbc.c symreg.c symreg.h unit.h
runtime/parrot/library parrotlib.imc
Log:
PMC constants 5 - better namespace handling
Revision Changes Path
1.26 +3 -3 parrot/ast/node.c
Index: node.c
===================================================================
RCS file: /cvs/public/parrot/ast/node.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- node.c 30 Sep 2004 16:00:36 -0000 1.25
+++ node.c 31 Oct 2004 12:51:18 -0000 1.26
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2004 The Perl Foundation. All Rights Reserved.
-$Id: node.c,v 1.25 2004/09/30 16:00:36 leo Exp $
+$Id: node.c,v 1.26 2004/10/31 12:51:18 leo Exp $
=head1 NAME
@@ -736,7 +736,7 @@
ins = INS_LABEL(cur_unit, sub, 1);
ins->r[1] = mk_pcc_sub(str_dup(ins->r[0]->name), 0);
- add_namespace(interpreter, ins->r[1]);
+ add_namespace(interpreter, cur_unit);
ins->r[1]->pcc_sub->pragma = P_PROTOTYPED ;
regs[0] = get_const("-1", 'I');
@@ -897,7 +897,7 @@
ins = INS_LABEL(cur_unit, sub, 1);
ins->r[1] = mk_pcc_sub(str_dup(ins->r[0]->name), 0);
- add_namespace(interpreter, ins->r[1]);
+ add_namespace(interpreter, cur_unit);
ins->r[1]->pcc_sub->pragma = P_MAIN|P_PROTOTYPED ;
regs[0] = get_const("0", 'I');
insINS(interpreter, cur_unit, ins, "new_pad", regs, 1);
1.149 +16 -7 parrot/imcc/imcc.y
Index: imcc.y
===================================================================
RCS file: /cvs/public/parrot/imcc/imcc.y,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -r1.148 -r1.149
--- imcc.y 30 Oct 2004 11:32:19 -0000 1.148
+++ imcc.y 31 Oct 2004 12:51:19 -0000 1.149
@@ -425,7 +425,7 @@
{
$$ = iSUBROUTINE(cur_unit, mk_sub_label($3));
$$->r[1] = mk_pcc_sub(str_dup($$->r[0]->name), 0);
- add_namespace(interp, $$->r[1]);
+ add_namespace(interp, cur_unit);
$$->r[1]->pcc_sub->pragma = $2;
}
| /* none */ { $$ = 0;}
@@ -448,10 +448,19 @@
;
class_namespace:
- NAMESPACE '[' keylist ']' { $$=0;
- IMCC_INFO(interp)->cur_namespace = $3;
- cur_namespace = $3;
- }
+ NAMESPACE '[' keylist ']'
+ {
+ int re_open = 0;
+ $$=0;
+ if (pasm_file && cur_namespace) {
+ imc_close_unit(interp, cur_unit);
+ re_open = 1;
+ }
+ IMCC_INFO(interp)->cur_namespace = $3;
+ cur_namespace = $3;
+ if (re_open)
+ cur_unit = imc_open_unit(interp, IMC_PASM);
+ }
;
class:
@@ -526,7 +535,7 @@
{
Instruction *i = iSUBROUTINE(cur_unit, $3);
i->r[1] = $<sr>$ = mk_pcc_sub(str_dup(i->r[0]->name), 0);
- add_namespace(interp, i->r[1]);
+ add_namespace(interp, cur_unit);
i->r[1]->pcc_sub->pragma = $4;
}
sub_params
@@ -554,7 +563,7 @@
{
Instruction *i = iSUBROUTINE(cur_unit, mk_sub_label($3));
i->r[1] = $<sr>$ = mk_pcc_sub(str_dup(i->r[0]->name), 0);
- add_namespace(interp, i->r[1]);
+ add_namespace(interp, cur_unit);
i->r[1]->pcc_sub->pragma = $4;
}
pcc_params
1.93 +34 -20 parrot/imcc/pbc.c
Index: pbc.c
===================================================================
RCS file: /cvs/public/parrot/imcc/pbc.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -r1.92 -r1.93
--- pbc.c 30 Oct 2004 15:01:07 -0000 1.92
+++ pbc.c 31 Oct 2004 12:51:20 -0000 1.93
@@ -46,6 +46,8 @@
int n_basic_blocks; /* block count */
SymReg * labels[HASH_SIZE]; /* label names */
SymReg * bsrs[HASH_SIZE]; /* bsr, set_addr locations */
+ IMC_Unit * unit;
+ int pmc_const; /* index in const table */
struct subs *prev;
struct subs *next;
};
@@ -217,10 +219,13 @@
make_new_sub(Interp *interpreter, IMC_Unit * unit)
{
struct subs *s = mem_sys_allocate_zeroed(sizeof(struct subs));
+
if (!s)
fatal(1, "get_old_size", "Out of mem");
s->prev = globals.cs->subs;
s->next = NULL;
+ s->unit = unit;
+ s->pmc_const = -1;
if (globals.cs->subs)
globals.cs->subs->next = s;
if (!globals.cs->first)
@@ -232,7 +237,6 @@
}
#else
UNUSED(interpreter);
- UNUSED(unit);
#endif
}
@@ -442,14 +446,21 @@
/* get a global label, return the pc (absolute) */
static SymReg *
-find_global_label(char *name, int *pc)
+find_global_label(char *name, struct subs *sym, int *pc, struct subs **s1)
{
SymReg * r;
struct subs *s;
*pc = 0;
for (s = globals.cs->first; s; s = s->next) {
+ if (sym && (
+ ((sym->unit->namespace && s->unit->namespace) &&
+ sym->unit->namespace == s->unit->namespace)
+ || (sym->unit->namespace && !s->unit->namespace)
+ || (!sym->unit->namespace && s->unit->namespace)))
+ continue;
if ( (r = _get_sym(s->labels, name)) ) {
*pc += r->color; /* here pc was stored */
+ *s1 = s;
return r;
}
*pc += s->size;
@@ -463,8 +474,9 @@
{
int i, pc, addr;
SymReg * bsr, *lab;
- struct subs *s;
+ struct subs *s, *s1;
int jumppc = 0;
+ int pmc_const;
for (s = globals.cs->first; s; s = s->next) {
for (i = 0; i < HASH_SIZE; i++) {
@@ -481,31 +493,33 @@
}
addr = jumppc + bsr->color;
if (bsr->set == 'p') {
- struct PackFile_FixupEntry *fe;
-
- lab = find_global_label(bsr->name, &pc);
+ /*
+ * first try with matching namespace
+ */
+ lab = find_global_label(bsr->name, s, &pc, &s1);
+ /*
+ * if failed use any matching name
+ */
+ if (!lab)
+ lab = find_global_label(bsr->name, NULL, &pc, &s1);
if (!lab) {
fatal(1, "fixup_bsrs", "couldn't find sub 1 '%s'\n",
bsr->name);
}
- /*
- * TODO investigate namespace issues - probably
- * search only current segment
- */
- fe = PackFile_find_fixup_entry(interpreter, enum_fixup_sub,
- bsr->name);
- if (!fe) {
- fatal(1, "fixup_bsrs", "couldn't find sub 2 '%s'\n",
+ pmc_const = s1->pmc_const;
+ if (pmc_const < 0) {
+ fatal(1, "fixup_bsrs",
+ "couldn't find sub 2 '%s'\n",
bsr->name);
}
interpreter->code->byte_code[addr+bsr->score] =
- fe->offset;
+ pmc_const;
debug(interpreter, DEBUG_PBC_FIXUP, "fixup const PMC"
" sub '%s' const nr: %d\n", bsr->name,
- fe->offset);
+ pmc_const);
continue;
}
- lab = find_global_label(bsr->name, &pc);
+ lab = find_global_label(bsr->name, NULL, &pc, &s1);
if (!lab) {
/* TODO continue; */
/* do fixup at runtime */
@@ -590,8 +604,8 @@
char *real_name;
char *class;
- if (r->pcc_sub->namespace) {
- ns = r->pcc_sub->namespace->reg;
+ if (globals.cs->subs->unit->namespace) {
+ ns = globals.cs->subs->unit->namespace->reg;
if (ns->set == 'K')
ns->color = build_key(interpreter, ns);
debug(interpreter, DEBUG_PBC_CONST,
@@ -628,7 +642,7 @@
k = PDB_extend_const_table(interpreter);
interpreter->code->const_table->constants[k]->type = PFC_PMC;
interpreter->code->const_table->constants[k]->u.key = pfc->u.key;
- r->color = k;
+ globals.cs->subs->pmc_const = k;
debug(interpreter, DEBUG_PBC_CONST,
"add_const_pmc_sub '%s' -> '%s' flags %d color %d\n\t%s\n",
1.56 +13 -7 parrot/imcc/symreg.c
Index: symreg.c
===================================================================
RCS file: /cvs/public/parrot/imcc/symreg.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- symreg.c 17 Jul 2004 08:07:27 -0000 1.55
+++ symreg.c 31 Oct 2004 12:51:20 -0000 1.56
@@ -136,19 +136,25 @@
* add current namespace to sub decl
*/
void
-add_namespace(Parrot_Interp interpreter, SymReg *sub)
+add_namespace(Parrot_Interp interpreter, IMC_Unit *unit)
{
SymReg *ns = IMCC_INFO(interpreter)->cur_namespace;
SymReg *r, *g;
if (!ns || strlen(ns->name) <= 2)
return;
- g = dup_sym(ns);
- sub->pcc_sub->namespace = g;
- g->reg = ns;
- g->type = VT_CONSTP;
- if (! (r = _get_sym(ghash, g->name)) || r->type != VT_CONSTP )
- _store_symreg(ghash, g);
+ if (unit->namespace)
+ return;
+ if (unit->prev && unit->prev->namespace == ns)
+ unit->namespace = ns;
+ else {
+ g = dup_sym(ns);
+ unit->namespace = g;
+ g->reg = ns;
+ g->type = VT_CONSTP;
+ if (! (r = _get_sym(ghash, g->name)) || r->type != VT_CONSTP )
+ _store_symreg(ghash, g);
+ }
}
/*
1.54 +1 -2 parrot/imcc/symreg.h
Index: symreg.h
===================================================================
RCS file: /cvs/public/parrot/imcc/symreg.h,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- symreg.h 9 Jul 2004 08:42:53 -0000 1.53
+++ symreg.h 31 Oct 2004 12:51:20 -0000 1.54
@@ -127,7 +127,7 @@
void add_pcc_result(SymReg *r, SymReg * arg);
void add_pcc_param(SymReg *r, SymReg * arg);
void add_pcc_return(SymReg *r, SymReg * arg);
-void add_namespace(Parrot_Interp interpreter, SymReg *sub);
+void add_namespace(Parrot_Interp interpreter, struct _IMC_Unit *);
typedef enum {
P_NON_PROTOTYPED = 0x00, /* must be 0 */
@@ -156,7 +156,6 @@
int nci;
int label;
SymReg * object;
- SymReg * namespace;
};
1.10 +1 -0 parrot/imcc/unit.h
Index: unit.h
===================================================================
RCS file: /cvs/public/parrot/imcc/unit.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- unit.h 8 Aug 2004 00:18:15 -0000 1.9
+++ unit.h 31 Oct 2004 12:51:20 -0000 1.10
@@ -37,6 +37,7 @@
struct _IMC_Unit * prev;
struct _IMC_Unit * next;
int local_count;
+ SymReg *namespace;
} IMC_Unit;
1.6 +10 -10 parrot/runtime/parrot/library/parrotlib.imc
Index: parrotlib.imc
===================================================================
RCS file: /cvs/public/parrot/runtime/parrot/library/parrotlib.imc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- parrotlib.imc 26 May 2004 19:30:21 -0000 1.5
+++ parrotlib.imc 31 Oct 2004 12:51:21 -0000 1.6
@@ -40,11 +40,11 @@
push paths, "."
push paths, $S0
push paths, root
-
+
# create includes array
includes = new .PMCArray
store_global "_parrotlib", "include_paths", includes
-
+
# get the directory handler
$P0 = find_global "_parrotlib::internal", "handle_directory"
@@ -76,10 +76,10 @@
.sub include_file_location
.param string name
-
+
find_global $P0, "_parrotlib", "include_paths"
$S0 = find_file_path( name, $P0 )
-
+
.pcc_begin_return
.return $S0
.pcc_end_return
@@ -99,7 +99,7 @@
find_global $P0, "_parrotlib", "include_paths"
$S0 = find_file_path( name, $P0 )
-
+
.pcc_begin_return
.return $S0
.pcc_end_return
@@ -139,7 +139,7 @@
# file not found, give the OS a chance to locate it
name = clone request
concat name, ext
-
+
END:
.pcc_begin_return
.return name
@@ -154,7 +154,7 @@
.param pmc array
.local string ret
.local pmc iter
-
+
iter = new .Iterator, array
iter = 0 #ITERATE_FROM_START
@@ -174,10 +174,10 @@
.sub handle_directory
.param string name
.local string path
-
+
getprop $P0, "path", P0
path = $P0
-
+
$S0 = clone path
concat $S0, name
stat $I0, $S0, 0
@@ -192,7 +192,7 @@
.sub set_signature
.param string name
.param string sig
-
+
$P1 = new .PerlString
$P1 = sig
find_global $P0, "_parrotlib", name