Author: kjs
Date: Fri Jan 2 05:54:00 2009
New Revision: 34806
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] works on keys. it's not correct yet.
Modified: trunk/compilers/pirc/new/pir.y
==============================================================================
--- trunk/compilers/pirc/new/pir.y (original)
+++ trunk/compilers/pirc/new/pir.y Fri Jan 2 05:54:00 2009
@@ -2,7 +2,7 @@
/*
* $Id$
- * Copyright (C) 2007-2008, The Perl Foundation.
+ * Copyright (C) 2007-2009, The Perl Foundation.
*/
/*
@@ -3301,11 +3301,20 @@
? get_signature_length(e->expr.t->key->head->expr) + 1
/* ... get its length. */
: 0);
case EXPR_CONSTANT:
- return 3;
+ return 3; /* for _, 'k', 'c' */
case EXPR_IDENT:
return 3; /* 1 for '_', 1 for 'i', 1 for 'c' */
- case EXPR_KEY: /* for '_', 'k' */
- return 2 + get_signature_length(e->expr.k->head->expr);
+ case EXPR_KEY: { /* for '_', 'k' */
+ int n;
+ /* if the key is an integer constant, then signature becomes
'_kic', otherwise _kc. */
+ if (e->expr.k->head->expr->type == EXPR_CONSTANT
+ && e->expr.k->head->expr->expr.c->type == INT_TYPE)
+ n = 3;
+ else
+ n = 2;
+
+ return n + get_signature_length(e->expr.k->head->expr);
+ }
default:
fprintf(stderr, "wrong expression typein
get_signature_length()\n");
break;
@@ -3361,6 +3370,10 @@
}
break;
case EXPR_CONSTANT:
+ /* integer constant key results in '_kic' signature */
+ if (iter->expr.c->type == INT_TYPE)
+ *instr_writer++ = 'i';
+
*instr_writer++ = 'c';
break;
default:
@@ -3370,31 +3383,6 @@
break;
}
-
- /*
- if ((iter->expr.t->key->expr->type == EXPR_TARGET)
- && (iter->expr.t->key->expr->expr.t->info->type == PMC_TYPE))
{
-
- }
- else {
- if ((iter->expr.t->key->expr->type == EXPR_TARGET)
- && (iter->expr.t->key->expr->expr.t->info->type ==
INT_TYPE))
- {
- *instr_writer++ = 'i';
- }
- else
-
- switch (iter->expr.t->key->expr->type) {
- case EXPR_CONSTANT:
- *instr_writer++ = 'c';
- break;
- default:
- fprintf(stderr, "write_signature: non-constant
key\n");
- instr_writer =
write_signature(iter->expr.t->key->expr, instr_writer);
- break;
- }
- }*/
-
}
break;
case EXPR_CONSTANT:
Modified: trunk/compilers/pirc/new/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.c (original)
+++ trunk/compilers/pirc/new/pircompunit.c Fri Jan 2 05:54:00 2009
@@ -1910,7 +1910,6 @@
{
key_entry *newkey = new_key_entry(lexer, exprkey);
key_entry *iter = keylist->head;
- key *list = keylist;
/* goto end of list */
while (iter->next != NULL)
@@ -1920,7 +1919,7 @@
++keylist->keylength;
- return list;
+ return keylist;
}
/*
Modified: trunk/compilers/pirc/new/pircompunit.h
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.h (original)
+++ trunk/compilers/pirc/new/pircompunit.h Fri Jan 2 05:54:00 2009
@@ -185,7 +185,7 @@
/* The key_entry node is used to represent a key */
typedef struct key_entry {
expression *expr; /* value of this key */
- struct key_entry *next; /* in ["x";"y"], there's 2 key nodes; 1 for
"x", 1 for "y",
+ struct key_entry *next; /* in ["x";"y"], there's 2 key entries; 1 for
"x", 1 for "y",
linked by "next" */
} key_entry;
@@ -201,8 +201,6 @@
-
-
/* The target node represents a .local, .param or register that can receive a
value,
* hence the name "target". When receiving arguments, it's a parameter, when
receiving
* return values, it's a local variable (or register).
Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c (original)
+++ trunk/compilers/pirc/new/piremit.c Fri Jan 2 05:54:00 2009
@@ -424,7 +424,6 @@
do {
int i;
- fprintf(stderr, "emit pir subs\n");
fprintf(out, "\n.namespace ");
print_key(lexer, subiter->name_space);
@@ -498,23 +497,6 @@
-/*
-
-=item C<static void
-emit_pbc_target_arg(lexer_state * const lexer, target * const t)>
-
-Emit the assigned register of target C<t>. The assigned register is
-stored in the C<color> field, of either the C<pir_reg> or C<symbol>
-structure, depending on whether C<t> is a register or a symbol,
-respectively.
-
-=cut
-
-*/
-static void
-emit_pbc_target_arg(lexer_state * const lexer, target * const t) {
- emit_int_arg(lexer->bc, t->info->color);
-}
/*
@@ -539,21 +521,20 @@
=item C<static void
emit_pbc_key(lexer_state * const lexer, key * const k)>
-Emit bytecode for the key C<k>.
+Emit bytecode for the key C<k>. First the bytecode is
+written to a temporary buffer, which is later unpacked
+in the actual PackFile. See C<store_key_bytecode()>.
-XXX Not sure what to return. At what point is this function
-called? Do we want to return an index in the constant table?
-or an expression (operand) node.
=cut
*/
-static expression *
+static int
emit_pbc_key(lexer_state * const lexer, key * const k) {
key_entry *iter = k->head;
int keylength = 0;
- opcode_t key[20]; /* XXX make length variable */
+ opcode_t *key;
opcode_t keysize; /* total size of key in bytecode */
opcode_t *pc; /* cursor to write into key array */
expression *operand;
@@ -561,8 +542,15 @@
fprintf(stderr, "emit pbc key\n");
- /* initialize cursor */
- pc = &key[1]; /* slot 0 is used for length of key */
+ /* create an array of opcode_t for storing the bytecode
+ * representation of the key. Initialize the cursor (pc)
+ * to write into this buffer.
+ */
+ pc = key = (opcode_t *)pir_mem_allocate(lexer, k->keylength * sizeof
(opcode_t));
+
+ /* store key length in slot 0 */
+ *pc++ = k->keylength;
+
while (iter) {
@@ -603,7 +591,10 @@
*pc++ = t->info->color;
break;
}
- /* XXX nested keys? */
+ case EXPR_KEY:
+ fprintf(stderr, "Nested keys are not supported.");
+ break;
+
default:
panic(lexer, "unknown expression type");
break;
@@ -615,10 +606,11 @@
iter = iter->next;
}
+/*
+ fprintf(stderr, "keylength is: %d, found keylength is: %d\n",
k->keylength, keylength);
assert(keylength == k->keylength);
+*/
- /* store key length in slot 0 */
- key[0] = keylength;
/* calculate size of key in bytecode; each field has 2 INTVALs:
* flags/types and the register/constant index.
*/
@@ -626,9 +618,38 @@
index = store_key_bytecode(lexer->bc, key);
- operand = expr_from_int(lexer, index);
- return operand;
+ fprintf(stderr, "store_key_bytecode index=%d\n", index);
+ return index;
+
+}
+
+
+/*
+
+=item C<static void
+emit_pbc_target_arg(lexer_state * const lexer, target * const t)>
+
+Emit the assigned register of target C<t>. The assigned register is
+stored in the C<color> field, of either the C<pir_reg> or C<symbol>
+structure, depending on whether C<t> is a register or a symbol,
+respectively.
+
+=cut
+
+*/
+static void
+emit_pbc_target_arg(lexer_state * const lexer, target * const t) {
+ emit_int_arg(lexer->bc, t->info->color);
+
+ if (t->key) {
+
+ /* XXX should do emit_pbc_key... always? */
+ /*emit_pbc_key(lexer, t->key);
+ */
+ /* this works for integers: */
+ emit_pbc_expr(lexer, t->key->head->expr);
+ }
}
/*
Modified: trunk/compilers/pirc/new/pirparser.c
==============================================================================
--- trunk/compilers/pirc/new/pirparser.c (original)
+++ trunk/compilers/pirc/new/pirparser.c Fri Jan 2 05:54:00 2009
@@ -319,7 +319,7 @@
/*
* $Id$
- * Copyright (C) 2007-2008, The Perl Foundation.
+ * Copyright (C) 2007-2009, The Perl Foundation.
*/
/*
@@ -6043,11 +6043,20 @@
? get_signature_length(e->expr.t->key->head->expr) + 1
/* ... get its length. */
: 0);
case EXPR_CONSTANT:
- return 3;
+ return 3; /* for _, 'k', 'c' */
case EXPR_IDENT:
return 3; /* 1 for '_', 1 for 'i', 1 for 'c' */
- case EXPR_KEY: /* for '_', 'k' */
- return 2 + get_signature_length(e->expr.k->head->expr);
+ case EXPR_KEY: { /* for '_', 'k' */
+ int n;
+ /* if the key is an integer constant, then signature becomes
'_kic', otherwise _kc. */
+ if (e->expr.k->head->expr->type == EXPR_CONSTANT
+ && e->expr.k->head->expr->expr.c->type == INT_TYPE)
+ n = 3;
+ else
+ n = 2;
+
+ return n + get_signature_length(e->expr.k->head->expr);
+ }
default:
fprintf(stderr, "wrong expression typein
get_signature_length()\n");
break;
@@ -6103,6 +6112,10 @@
}
break;
case EXPR_CONSTANT:
+ /* integer constant key results in '_kic' signature */
+ if (iter->expr.c->type == INT_TYPE)
+ *instr_writer++ = 'i';
+
*instr_writer++ = 'c';
break;
default:
@@ -6112,31 +6125,6 @@
break;
}
-
- /*
- if ((iter->expr.t->key->expr->type == EXPR_TARGET)
- && (iter->expr.t->key->expr->expr.t->info->type == PMC_TYPE))
{
-
- }
- else {
- if ((iter->expr.t->key->expr->type == EXPR_TARGET)
- && (iter->expr.t->key->expr->expr.t->info->type ==
INT_TYPE))
- {
- *instr_writer++ = 'i';
- }
- else
-
- switch (iter->expr.t->key->expr->type) {
- case EXPR_CONSTANT:
- *instr_writer++ = 'c';
- break;
- default:
- fprintf(stderr, "write_signature: non-constant
key\n");
- instr_writer =
write_signature(iter->expr.t->key->expr, instr_writer);
- break;
- }
- }*/
-
}
break;
case EXPR_CONSTANT: