Front page | perl.cvs.parrot |
Postings from January 2009
[svn:parrot] r34766 - trunk/compilers/pirc/new
From:
kjs
Date:
January 1, 2009 13:58
Subject:
[svn:parrot] r34766 - trunk/compilers/pirc/new
Message ID:
20090101215813.68BDFCB9FA@x12.develooper.com
Author: kjs
Date: Thu Jan 1 13:58:12 2009
New Revision: 34766
Modified:
trunk/compilers/pirc/new/bcgen.c
trunk/compilers/pirc/new/bcgen.h
trunk/compilers/pirc/new/pircompunit.h
trunk/compilers/pirc/new/piremit.c
Log:
[pirc] stuff for bytecode generation for keys. not tested, but this is a first draft. needs more thought.
Modified: trunk/compilers/pirc/new/bcgen.c
==============================================================================
--- trunk/compilers/pirc/new/bcgen.c (original)
+++ trunk/compilers/pirc/new/bcgen.c Thu Jan 1 13:58:12 2009
@@ -404,14 +404,13 @@
/*
-=item C<static void
-build_key(lexer_state * const lexer, key * const k)>
+=item C<void()>
=cut
*/
-static void
-build_key(bytecode * const bc, opcode_t * key) {
+int
+store_key_bytecode(bytecode * const bc, opcode_t * key) {
PackFile_Constant *pfc;
const opcode_t *rc;
int index;
@@ -427,23 +426,9 @@
index = add_key_const(bc, pfc->u.key);
-
mem_sys_free(pfc);
-
-/*
- const SymReg * const r =
- _get_sym(&IMCC_INFO(interp)->globals->cs->key_consts, s_key);
-
-
- if (r)
- return r->color;
-
- store_key_const(interp, s_key, k);
-
- return k;
-*/
-
+ return index;
}
/* XXX remove or update prototype once the XXX below has been resolved. */
@@ -640,7 +625,7 @@
/*
=item C<void
-add_sub_pmc(bytecode * const bc, sub_info * const info, int needlex)>
+add_sub_pmc(bytecode * const bc, sub_info * const info, int needlex, int subpragmas)>
Add a sub PMC to the constant table. This function initializes the sub PMC.
The index where the PMC is stored in the constant table is returned.
Modified: trunk/compilers/pirc/new/bcgen.h
==============================================================================
--- trunk/compilers/pirc/new/bcgen.h (original)
+++ trunk/compilers/pirc/new/bcgen.h Thu Jan 1 13:58:12 2009
@@ -101,6 +101,8 @@
int add_key_const(bytecode * const bc, PMC *key);
+int store_key_bytecode(bytecode * const bc, opcode_t *keybytecode);
+
int add_num_const(bytecode * const bc, double f);
int add_string_const(bytecode * const bc, char const * const str);
Modified: trunk/compilers/pirc/new/pircompunit.h
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.h (original)
+++ trunk/compilers/pirc/new/pircompunit.h Thu Jan 1 13:58:12 2009
@@ -173,7 +173,7 @@
} expr;
- expr_type type; /* selector for __expression_union */
+ expr_type type; /* selector for expression_union */
struct expression *next;
Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c (original)
+++ trunk/compilers/pirc/new/piremit.c Thu Jan 1 13:58:12 2009
@@ -60,8 +60,8 @@
static void emit_pir_statement(lexer_state * const lexer, subroutine * const sub);
static void emit_pir_instruction(lexer_state * const lexer, instruction * const instr);
+static void emit_pbc_expr(lexer_state * const lexer, expression * const operand);
-static void emit_pbc_key(lexer_state * const lexer, key * const k);
/* prototype declaration */
void print_expr(lexer_state * const lexer, expression * const expr);
@@ -531,6 +531,104 @@
+
+
+/*
+
+=item C<static void
+emit_pbc_key(lexer_state * const lexer, key * const k)>
+
+Emit bytecode for the key C<k>.
+
+=cut
+
+*/
+static expression *
+emit_pbc_key(lexer_state * const lexer, key * const k) {
+ key *iter = k;
+ int keylength = 0;
+
+ opcode_t key[20]; /* XXX make length variable */
+ opcode_t keysize; /* total size of key in bytecode */
+ opcode_t *pc; /* cursor to write into key array */
+ expression *operand;
+
+ fprintf(stderr, "emit pbc key\n");
+ emit_pbc_expr(lexer, k->expr);
+
+ /* initialize cursor */
+ pc = &key[1]; /* slot 0 is used for length of key */
+
+ while (iter) {
+
+ switch (iter->expr->type) {
+ case EXPR_CONSTANT: {
+ constant *c = iter->expr->expr.c;
+ switch (c->type) {
+ case INT_TYPE:
+ *pc++ = PARROT_ARG_IC;
+ *pc++ = c->val.ival;
+ break;
+ case STRING_TYPE:
+ *pc++ = PARROT_ARG_SC;
+ *pc++ = add_string_const(lexer->bc, c->val.sval);
+ break;
+ default:
+ panic(lexer, "wrong type of key");
+ break;
+ }
+
+ break;
+ }
+ case EXPR_TARGET: {
+ target *t = iter->expr->expr.t;
+
+ switch (t->info->type) {
+ case INT_TYPE:
+ *pc++ = PARROT_ARG_I;
+ break;
+ case STRING_TYPE:
+ *pc++ = PARROT_ARG_S;
+ break;
+ default:
+ panic(lexer, "wrong type of key");
+ break;
+ }
+
+ *pc++ = t->info->color;
+ break;
+ }
+ default:
+ break;
+
+ }
+ /* count the number of keys */
+ ++keylength;
+ iter = iter->next;
+ }
+
+ /* 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.
+ */
+ keysize = pc - key;
+
+ store_key_bytecode(lexer->bc, key);
+
+ operand = expr_from_key(lexer, k);
+ return operand;
+
+}
+
+/*
+
+=item C<static void
+emit_pbc_expr(lexer_state * const lexer, expression * const operand)>
+
+=cut
+
+*/
static void
emit_pbc_expr(lexer_state * const lexer, expression * const operand) {
switch (operand->type) {
@@ -560,23 +658,6 @@
/*
=item C<static void
-emit_pbc_key(lexer_state * const lexer, key * const k)>
-
-Emit bytecode for the key C<k>.
-
-=cut
-
-*/
-static void
-emit_pbc_key(lexer_state * const lexer, key * const k) {
- fprintf(stderr, "emit pbc key\n");
- emit_pbc_expr(lexer, k->expr);
- /* XXX finish this. */
-}
-
-/*
-
-=item C<static void
optimize_instr(lexer_state * const lexer, instruction * const instr)>
Optimize the instruction C<instr>. Currently, these instructions are optimized:
-
[svn:parrot] r34766 - trunk/compilers/pirc/new
by kjs