Author: kjs
Date: Tue Dec 16 10:57:45 2008
New Revision: 33973
Modified:
trunk/compilers/pirc/new/pir.y
trunk/compilers/pirc/new/pircompunit.c
trunk/compilers/pirc/new/pircompunit.h
trunk/compilers/pirc/new/piremit.c
trunk/compilers/pirc/new/pirparser.c
Log:
[pirc] et voila! Nice code! woohoo. Refactoring follows shortly.
Modified: trunk/compilers/pirc/new/pir.y
==============================================================================
--- trunk/compilers/pirc/new/pir.y (original)
+++ trunk/compilers/pirc/new/pir.y Tue Dec 16 10:57:45 2008
@@ -1029,10 +1029,10 @@
if (TEST_FLAG($1->flags, TARGET_FLAG_IS_REG))
$$ = $1;
else { /* it's not a register, so it must be a
declared symbol */
- if ($1->s.sym->info.type != PMC_TYPE)
+ if ($1->info->type != PMC_TYPE)
yypirerror(yyscanner, lexer,
"indexed object '%s' is not of type
'pmc'",
- $1->s.sym->info.id.name);
+ $1->info->id.name);
/* create a target node based on the symbol
node;
* sym already has a PASM register, so through
@@ -1576,9 +1576,9 @@
{ /* if $4 is not a register, it must be a declared
symbol */
if (!TEST_FLAG($4->flags, TARGET_FLAG_IS_REG)) {
- if ($4->s.sym->info.type != PMC_TYPE) /* a .lex
must be a PMC */
+ if ($4->info->type != PMC_TYPE) /* a .lex must
be a PMC */
yypirerror(yyscanner, lexer, "lexical '%s'
must be of type 'pmc'",
- $4->s.sym->info.id.name);
+ $4->info->id.name);
}
set_lex_flag($4, $2);
}
@@ -1693,14 +1693,14 @@
}
else { /* is not a register but a symbol */
- symbol *sym = find_symbol(lexer,
$1->s.sym->info.id.name);
+ symbol *sym = find_symbol(lexer,
$1->info->id.name);
if (sym == NULL)
yypirerror(yyscanner, lexer,
- "symbol '%s' was not declared",
$1->s.sym->info.id.name);
- else if ($1->s.sym->info.type != PMC_TYPE)
+ "symbol '%s' was not declared",
$1->info->id.name);
+ else if ($1->info->type != PMC_TYPE)
yypirerror(yyscanner, lexer,
"cannot invoke method: '%s' is
not of type 'pmc'",
- $1->s.sym->info.id.name);
+ $1->info->id.name);
/* get a target based on the symbol, it
contains a register */
invocant = $1;
@@ -3300,9 +3300,9 @@
switch (iter->type) {
case EXPR_TARGET:
if (TEST_FLAG(iter->expr.t->flags, TARGET_FLAG_IS_REG))
- *instr_writer++ = type_codes[iter->expr.t->s.reg->info.type];
+ *instr_writer++ = type_codes[iter->expr.t->info->type];
else
- *instr_writer++ = type_codes[iter->expr.t->s.sym->info.type];
+ *instr_writer++ = type_codes[iter->expr.t->info->type];
if (iter->expr.t->key) {
*instr_writer++ = '_';
@@ -3312,9 +3312,9 @@
&&
( (iter->expr.t->key->expr->expr.t->flags &
TARGET_FLAG_IS_REG)
?
- (iter->expr.t->key->expr->expr.t->s.reg->info.type ==
PMC_TYPE)
+ (iter->expr.t->key->expr->expr.t->info->type ==
PMC_TYPE)
:
- (iter->expr.t->key->expr->expr.t->s.sym->info.type ==
PMC_TYPE)
+ (iter->expr.t->key->expr->expr.t->info->type ==
PMC_TYPE)
)
) {
/* the key is a target, and its type is a PMC. In that
case, do not
@@ -3330,9 +3330,9 @@
(
(iter->expr.t->key->expr->expr.t->flags &
TARGET_FLAG_IS_REG)
?
- (iter->expr.t->key->expr->expr.t->s.reg->info.type ==
INT_TYPE)
+ (iter->expr.t->key->expr->expr.t->info->type ==
INT_TYPE)
:
- (iter->expr.t->key->expr->expr.t->s.sym->info.type ==
INT_TYPE)
+ (iter->expr.t->key->expr->expr.t->info->type ==
INT_TYPE)
)
)
@@ -3546,7 +3546,8 @@
if (sym) {
operand->expr.t = new_target(lexer);
- operand->expr.t->s.sym = sym; /* target's pointer set to
symbol */
+ /* operand->expr.t->s.sym = sym; */ /* target's pointer set
to symbol */
+ operand->expr.t->info = &sym->info;
operand->type = EXPR_TARGET; /* convert operand node
into EXPR_TARGET */
}
else { /* it must be a label */
Modified: trunk/compilers/pirc/new/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.c (original)
+++ trunk/compilers/pirc/new/pircompunit.c Tue Dec 16 10:57:45 2008
@@ -518,7 +518,7 @@
target *
target_from_symbol(lexer_state * const lexer, symbol * const sym) {
target *t = new_target(lexer);
- t->s.sym = sym; /* set a pointer from target to symbol */
+ /* t->s.sym = sym; *//* set a pointer from target to symbol */
t->flags = sym->flags; /* copy the flags */
t->info = &sym->info;
@@ -595,7 +595,8 @@
assign_vanilla_register(lexer, sym);
/* set a pointer from the target to the symbol object */
- targ->s.sym = sym;
+ /* targ->s.sym = sym; */
+ targ->info = &sym->info;
return targ;
}
@@ -647,14 +648,14 @@
*/
/* :slurpy can only be set on a PMC parameter */
- if (TEST_FLAG(flag, TARGET_FLAG_SLURPY) && param->s.sym->info.type !=
PMC_TYPE)
+ if (TEST_FLAG(flag, TARGET_FLAG_SLURPY) && param->info->type != PMC_TYPE)
yypirerror(lexer->yyscanner, lexer,
- "cannot set :slurpy flag on non-pmc %s",
param->s.sym->info.id.name);
+ "cannot set :slurpy flag on non-pmc %s",
param->info->id.name);
/* :opt_flag can only be set on a int parameter */
- if (TEST_FLAG(flag, TARGET_FLAG_OPT_FLAG) && param->s.sym->info.type !=
INT_TYPE)
+ if (TEST_FLAG(flag, TARGET_FLAG_OPT_FLAG) && param->info->type != INT_TYPE)
yypirerror(lexer->yyscanner, lexer,
- "cannot set :opt_flag flag on non-int %s",
param->s.sym->info.id.name);
+ "cannot set :opt_flag flag on non-int %s",
param->info->id.name);
return param;
}
@@ -1363,7 +1364,8 @@
color_reg(lexer, type, regno);
reg = find_register(lexer, type, regno);
- t->s.reg = reg;
+ /* XXX t->s.reg = reg; */
+ t->info = ®->info;
/* set a flag on this target node saying it's a register */
SET_FLAG(t->flags, TARGET_FLAG_IS_REG);
@@ -1862,9 +1864,9 @@
switch (argvalue->type) {
case EXPR_TARGET:
if (TEST_FLAG(argvalue->expr.t->flags, TARGET_FLAG_IS_REG))
- flag |= argvalue->expr.t->s.reg->info.type;
+ flag |= argvalue->expr.t->info->type;
else
- flag |= argvalue->expr.t->s.sym->info.type;
+ flag |= argvalue->expr.t->info->type;
break;
case EXPR_CONSTANT:
flag |= argvalue->expr.c->type;
@@ -2087,7 +2089,7 @@
/* if the target is a register, invoke that. */
if (TEST_FLAG(inv->sub->flags, TARGET_FLAG_IS_REG)) {
- target *sub = new_reg(lexer, PMC_TYPE,
inv->sub->s.reg->info.color);
+ target *sub = new_reg(lexer, PMC_TYPE, inv->sub->info->color);
if (inv->retcc) { /* return continuation present? */
new_sub_instr(lexer, PARROT_OP_invoke_p_p, "invoke_p_p");
add_operands(lexer, "%T%T", inv->sub, inv->retcc);
@@ -2099,7 +2101,7 @@
}
else { /* find the global label in the current file, or find it
during runtime */
target *sub = generate_unique_pir_reg(lexer, PMC_TYPE);
- global_label *glob = find_global_label(lexer,
inv->sub->s.sym->info.id.name);
+ global_label *glob = find_global_label(lexer,
inv->sub->info->id.name);
if (glob) {
/* XXX fix pmc const stuff */
@@ -2110,7 +2112,7 @@
new_sub_instr(lexer, PARROT_OP_find_sub_not_null_p_sc,
"find_sub_not_null_p_sc");
- add_operands(lexer, "%T%s", sub,
inv->sub->s.sym->info.id.name);
+ add_operands(lexer, "%T%s", sub, inv->sub->info->id.name);
/* save the current instruction in a list; entries in this
list will be
* fixed up, if possible, after the parsing phase.
@@ -2128,7 +2130,7 @@
*
*/
save_global_reference(lexer, CURRENT_INSTRUCTION(lexer),
- inv->sub->s.sym->info.id.name);
+ inv->sub->info->id.name);
}
new_sub_instr(lexer, PARROT_OP_invokecc_p, "invokecc_p");
Modified: trunk/compilers/pirc/new/pircompunit.h
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.h (original)
+++ trunk/compilers/pirc/new/pircompunit.h Tue Dec 16 10:57:45 2008
@@ -196,10 +196,12 @@
*/
typedef struct target {
- union sym_union { /* XXX this union will be replaced by
syminfo */
+ /*
+ union sym_union {
struct symbol *sym;
struct pir_reg *reg;
} s;
+ */
struct syminfo *info;
target_flag flags; /* flags like :slurpy etc. */
Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c (original)
+++ trunk/compilers/pirc/new/piremit.c Tue Dec 16 10:57:45 2008
@@ -94,13 +94,13 @@
print_target(lexer_state *lexer, target * const t) {
if (TEST_FLAG(t->flags, TARGET_FLAG_IS_REG)) {
- if (t->s.reg == NULL)
+ if (t->info == NULL)
fprintf(stderr, "reg target has no pir_reg ptr!\n");
- fprintf(out, "%c%d", pir_register_types[t->s.reg->info.type],
t->s.reg->info.color);
+ fprintf(out, "%c%d", pir_register_types[t->info->type],
t->info->color);
}
else
- fprintf(out, "%c%d", pir_register_types[t->s.sym->info.type],
t->s.sym->info.color);
+ fprintf(out, "%c%d", pir_register_types[t->info->type],
t->info->color);
/* if the target has a key, print that too */
if (t->key)
@@ -432,9 +432,9 @@
static void
emit_pbc_target_arg(lexer_state * const lexer, target * const t) {
if (TEST_FLAG(t->flags, TARGET_FLAG_IS_REG))
- emit_int_arg(lexer->bc, t->s.reg->info.color);
+ emit_int_arg(lexer->bc, t->info->color);
else
- emit_int_arg(lexer->bc, t->s.sym->info.color);
+ emit_int_arg(lexer->bc, t->info->color);
}
/*
Modified: trunk/compilers/pirc/new/pirparser.c
==============================================================================
--- trunk/compilers/pirc/new/pirparser.c (original)
+++ trunk/compilers/pirc/new/pirparser.c Tue Dec 16 10:57:45 2008
@@ -3037,10 +3037,10 @@
if (TEST_FLAG((yyvsp[(1) - (2)].targ)->flags,
TARGET_FLAG_IS_REG))
(yyval.targ) = (yyvsp[(1) - (2)].targ);
else { /* it's not a register, so it must be a
declared symbol */
- if ((yyvsp[(1) - (2)].targ)->s.sym->info.type
!= PMC_TYPE)
+ if ((yyvsp[(1) - (2)].targ)->info->type !=
PMC_TYPE)
yypirerror(yyscanner, lexer,
"indexed object '%s' is not of type
'pmc'",
- (yyvsp[(1) -
(2)].targ)->s.sym->info.id.name);
+ (yyvsp[(1) -
(2)].targ)->info->id.name);
/* create a target node based on the symbol
node;
* sym already has a PASM register, so through
@@ -3754,9 +3754,9 @@
{ /* if $4 is not a register, it must be a declared symbol */
if (!TEST_FLAG((yyvsp[(4) - (5)].targ)->flags,
TARGET_FLAG_IS_REG)) {
- if ((yyvsp[(4) - (5)].targ)->s.sym->info.type !=
PMC_TYPE) /* a .lex must be a PMC */
+ if ((yyvsp[(4) - (5)].targ)->info->type !=
PMC_TYPE) /* a .lex must be a PMC */
yypirerror(yyscanner, lexer, "lexical '%s'
must be of type 'pmc'",
- (yyvsp[(4) -
(5)].targ)->s.sym->info.id.name);
+ (yyvsp[(4) -
(5)].targ)->info->id.name);
}
set_lex_flag((yyvsp[(4) - (5)].targ), (yyvsp[(2) -
(5)].sval));
;}
@@ -3893,14 +3893,14 @@
}
else { /* is not a register but a symbol */
- symbol *sym = find_symbol(lexer, (yyvsp[(1) -
(4)].targ)->s.sym->info.id.name);
+ symbol *sym = find_symbol(lexer, (yyvsp[(1) -
(4)].targ)->info->id.name);
if (sym == NULL)
yypirerror(yyscanner, lexer,
- "symbol '%s' was not declared",
(yyvsp[(1) - (4)].targ)->s.sym->info.id.name);
- else if ((yyvsp[(1) -
(4)].targ)->s.sym->info.type != PMC_TYPE)
+ "symbol '%s' was not declared",
(yyvsp[(1) - (4)].targ)->info->id.name);
+ else if ((yyvsp[(1) - (4)].targ)->info->type
!= PMC_TYPE)
yypirerror(yyscanner, lexer,
"cannot invoke method: '%s' is
not of type 'pmc'",
- (yyvsp[(1) -
(4)].targ)->s.sym->info.id.name);
+ (yyvsp[(1) -
(4)].targ)->info->id.name);
/* get a target based on the symbol, it
contains a register */
invocant = (yyvsp[(1) - (4)].targ);
@@ -5989,9 +5989,9 @@
switch (iter->type) {
case EXPR_TARGET:
if (TEST_FLAG(iter->expr.t->flags, TARGET_FLAG_IS_REG))
- *instr_writer++ = type_codes[iter->expr.t->s.reg->info.type];
+ *instr_writer++ = type_codes[iter->expr.t->info->type];
else
- *instr_writer++ = type_codes[iter->expr.t->s.sym->info.type];
+ *instr_writer++ = type_codes[iter->expr.t->info->type];
if (iter->expr.t->key) {
*instr_writer++ = '_';
@@ -6001,9 +6001,9 @@
&&
( (iter->expr.t->key->expr->expr.t->flags &
TARGET_FLAG_IS_REG)
?
- (iter->expr.t->key->expr->expr.t->s.reg->info.type ==
PMC_TYPE)
+ (iter->expr.t->key->expr->expr.t->info->type ==
PMC_TYPE)
:
- (iter->expr.t->key->expr->expr.t->s.sym->info.type ==
PMC_TYPE)
+ (iter->expr.t->key->expr->expr.t->info->type ==
PMC_TYPE)
)
) {
/* the key is a target, and its type is a PMC. In that
case, do not
@@ -6019,9 +6019,9 @@
(
(iter->expr.t->key->expr->expr.t->flags &
TARGET_FLAG_IS_REG)
?
- (iter->expr.t->key->expr->expr.t->s.reg->info.type ==
INT_TYPE)
+ (iter->expr.t->key->expr->expr.t->info->type ==
INT_TYPE)
:
- (iter->expr.t->key->expr->expr.t->s.sym->info.type ==
INT_TYPE)
+ (iter->expr.t->key->expr->expr.t->info->type ==
INT_TYPE)
)
)
@@ -6235,7 +6235,9 @@
if (sym) {
operand->expr.t = new_target(lexer);
- operand->expr.t->s.sym = sym; /* target's pointer set to
symbol */
+ //operand->expr.t->s.sym = sym; /* target's pointer set to
symbol */
+ operand->expr.t->info =
+ &sym->info;
operand->type = EXPR_TARGET; /* convert operand node
into EXPR_TARGET */
}
else { /* it must be a label */