Author: kjs
Date: Sun Dec 28 07:41:33 2008
New Revision: 34495
Modified:
trunk/compilers/pirc/new/bcgen.c
trunk/compilers/pirc/new/bcgen.h
trunk/compilers/pirc/new/pircompunit.c
trunk/compilers/pirc/new/pircompunit.h
trunk/compilers/pirc/new/piremit.c
Log:
[pirc] clean up documentation.
Modified: trunk/compilers/pirc/new/bcgen.c
==============================================================================
--- trunk/compilers/pirc/new/bcgen.c (original)
+++ trunk/compilers/pirc/new/bcgen.c Sun Dec 28 07:41:33 2008
@@ -202,6 +202,27 @@
/*
+static void
+check_requested_constant(bytecode * const bc, unsigned index, int
expectedtype)>
+
+Perform a sanity check on a requested constant. The constant at index C<index>
+is requested; this function checks whether the index is valid. Then, if so, the
+constant is checked for its type, which must be C<expectedtype>. This must be
one
+of: PFC_PMC, PFC_NUMBER, PFC_STRING.
+
+=cut
+
+*/
+static void
+check_requested_constant(bytecode * const bc, unsigned index, int
expectedtype) {
+ /* make sure the requested PMC exists. */
+ PARROT_ASSERT(index < bc->interp->code->const_table->const_count);
+ /* make sure the requested constant is a PMC */
+ PARROT_ASSERT(bc->interp->code->const_table->constants[index]->type ==
expectedtype);
+}
+
+/*
+
=item C<PMC *
get_pmc_const(bytecode * const bc, unsigned index)>
@@ -212,16 +233,44 @@
*/
PMC *
get_pmc_const(bytecode * const bc, unsigned index) {
- /* make sure the requested PMC exists. */
- PARROT_ASSERT(index < bc->interp->code->const_table->const_count);
- /* make sure the requested constant is a PMC */
- PARROT_ASSERT(bc->interp->code->const_table->constants[index]->type ==
PFC_PMC);
-
+ check_requested_constant(bc, index, PFC_PMC);
return bc->interp->code->const_table->constants[index]->u.key;
}
/*
+=item C<FLOATVAL
+get_num_const(bytecode * const bc, unsigned index)>
+
+Get the FLOATVAL constant at index C<index> in the PBC constant table.
+
+=cut
+
+*/
+FLOATVAL
+get_num_const(bytecode * const bc, unsigned index) {
+ check_requested_constant(bc, index, PFC_NUMBER);
+ return bc->interp->code->const_table->constants[index]->u.number;
+}
+
+/*
+
+=item C<STRING *
+get_string_const(bytecode * const bc, unsigned index)>
+
+Get the STRING constant at index C<index> in the PBC constant table.
+
+=cut
+
+*/
+STRING *
+get_string_const(bytecode * const bc, unsigned index) {
+ check_requested_constant(bc, index, PFC_STRING);
+ return bc->interp->code->const_table->constants[index]->u.string;
+}
+
+/*
+
=item C<bytecode *
new_bytecode(Interp *interp, char const * const filename)>
@@ -335,31 +384,7 @@
*/
}
-/*
-
-=item C<void
-emit_op_by_name(bytecode * const bc, char const * const opname)>
-Emit the opcode by name. C<opname> must be a valid, signatured opname.
-So, C<print> is not valid, whereas C<print_ic> is. The opcode of the
-opname is looked up and written into the bytecode stream. If C<opname>
-is not valid, an error message is written.
-
-XXX Possibly bail out if error? No need to continue.
-
-=cut
-
-*/
-void
-emit_op_by_name(bytecode * const bc, char const * const opname) {
- int op = bc->interp->op_lib->op_code(opname, 1);
- if (op < 0) {
- /* error */
- fprintf(stderr, "Error: '%s' is not an op\n", opname);
- }
- else
- emit_opcode(bc, op);
-}
/* XXX remove or update prototype once the XXX below has been resolved. */
static STRING *add_string_const_from_cstring(bytecode * const bc, char const *
const str);
Modified: trunk/compilers/pirc/new/bcgen.h
==============================================================================
--- trunk/compilers/pirc/new/bcgen.h (original)
+++ trunk/compilers/pirc/new/bcgen.h Sun Dec 28 07:41:33 2008
@@ -50,13 +50,7 @@
void emit_int_arg(bytecode * const bc, int argvalue);
-/*
-void emit_pmc_arg(bytecode * const bc, int pmc_const_index);
-
-void emit_num_arg(bytecode * const bc, int num_const_index);
-
-void emit_string_arg(bytecode * const bc, int string_const_index);
-*/
+/* storing constants in constant table */
int add_key_const(bytecode * const bc, PMC *key);
@@ -68,23 +62,19 @@
PMC *get_pmc_const(bytecode * const bc, unsigned index);
-/* for adding constants */
+FLOATVAL get_num_const(bytecode * const bc, unsigned index);
+
+STRING *get_string_const(bytecode * const bc, unsigned index);
+
-/* returns the id in the constant table */
/*
-int add_pmc_const(bytecode * const bc);
int add_string_const(bytecode * const bc, STRING *s);
int add_num_const(bytecode * const bc, FLOATVAL f);
-int add_int_const(bytecode * const bc, INTVAL i);
- */
-
+*/
-/* XXX todo: define some API functions for finding values, etc. like this: */
-int get_string_const_index(bytecode * const bc, STRING *s);
-/* retrieves the index of s in the constant table */
int add_sub_pmc(bytecode * const bc, sub_info * const info);
Modified: trunk/compilers/pirc/new/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.c (original)
+++ trunk/compilers/pirc/new/pircompunit.c Sun Dec 28 07:41:33 2008
@@ -60,8 +60,12 @@
*/
void
-panic(lexer_state * lexer, char const * const message) {
- fprintf(stderr, "Fatal: %s\n", message);
+panic(lexer_state * lexer, char const * const message, ...) {
+ va_list arg_ptr;
+ fprintf(stderr, "Fatal: ");
+ va_start(arg_ptr, message);
+ vfprintf(stderr, message, arg_ptr);
+ va_end(arg_ptr);
release_resources(lexer);
exit(EXIT_FAILURE);
}
@@ -1951,6 +1955,10 @@
=item C<static void
arguments_to_operands(lexer_state * const lexer, argument * const args)>
+Convert a list of C<argument> nodes into operands. Before the operands are
+added to the I<current> instruction, a FixedIntegerArray PMC is created
+which will hold one integer for each argument in the list. The integer
+at index C<i> encodes the type and flags (such as C<:flat>) for operand C<i>.
=cut
@@ -1969,9 +1977,6 @@
/* add the index (of the signature PMC) in the PBC constant table as
operand */
push_operand(lexer, expr_from_int(lexer, array_index));
-/* fprintf(stderr, "args2ops: %u arguments\n", num_arguments);
-*/
-
/* no need to continue if there's no arguments */
if (num_arguments == 0)
return;
@@ -1979,10 +1984,6 @@
/* retrieve the signature array PMC */
signature_array = get_pmc_const(lexer->bc, array_index);
-/* fprintf(stderr, "signature array has size: %d\n",
- VTABLE_get_integer(lexer->interp, signature_array));
-*/
-
/* initialize the argument iterator for the loop */
argiter = args->next;
@@ -1991,8 +1992,6 @@
/* calculate the right flags for the current argument */
SET_FLAG(flag, get_expression_pirtype(argiter->value));
-/* fprintf(stderr, "Setting flag %d on argument %u\n", flag, i); */
-
/* set the flags for this argument in the right position in the array
*/
VTABLE_set_integer_keyed_int(lexer->interp, signature_array, i, flag);
@@ -2001,9 +2000,6 @@
argiter = argiter->next;
}
-
-/* fprintf(stderr, "args2ops done\n"); */
-
}
/*
@@ -2011,6 +2007,11 @@
=item C<static void
targets_to_operands(lexer_state * const lexer, target * const targets)>
+Convert a list of C<target> nodes into operands. Before the operands
+are added to the I<current> instruction, a FixedIntegerArray is created,
+which contains one integer for each target (to be converted into an operand).
+The integer encodes the type of the target (operand) and other flags, such
+as C<:slurpy> etc.
=cut
@@ -2022,25 +2023,38 @@
PMC *signature_array;
unsigned i;
+ /* generate a FixedIntegerArray of the right size to encode the signature
*/
array_index = generate_signature_pmc(lexer, num_targets);
- push_operand(lexer, expr_from_const(lexer, new_const(lexer, INT_TYPE,
array_index)));
+ /* add the index in the constant table of this signature PMC as an operand
*/
+ push_operand(lexer, expr_from_int(lexer, array_index));
+ /* no need to continue if there's no target nodes */
if (num_targets == 0)
return;
+ /* retrieve the FixedIntegerArray PMC */
signature_array = get_pmc_const(lexer->bc, array_index);
+ /* initialize the iterator */
iter = targets->next;
for (i = 0; i < num_targets; ++i) {
int flag = 0;
+ /* calculate the flags for the current target node */
SET_FLAG(flag, iter->info->type);
+ /* store the flag at position i in the array */
VTABLE_set_integer_keyed_int(lexer->interp, signature_array, i, flag);
+ /* add the current target as an operand; these targets have already
+ * got an assigned register, so we're emitting that register number.
+ */
+
+ PARROT_ASSERT(iter->info->color != NO_REG_ALLOCATED);
push_operand(lexer, expr_from_int(lexer, iter->info->color));
+ /* go to next target in list */
iter = iter->next;
}
@@ -2104,10 +2118,9 @@
/* count number of ints needed to store this instruction in bytecode */
lexer->codesize += CURRENT_INSTRUCTION(lexer)->opinfo->op_count;
- fprintf(stderr, "opcount for '%s' is %d\n", opname,
CURRENT_INSTRUCTION(lexer)->opinfo->op_count);
+ /* add the var. number of args for the PCC instructions. */
lexer->codesize += num_var_args;
- fprintf(stderr, "new_sub_instr(): extra args for '%s': %u (codesize:
%u)\n", opname, num_var_args, lexer->codesize);
}
/*
Modified: trunk/compilers/pirc/new/pircompunit.h
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.h (original)
+++ trunk/compilers/pirc/new/pircompunit.h Sun Dec 28 07:41:33 2008
@@ -456,7 +456,7 @@
void generate_parameters_instr(struct lexer_state * const lexer, unsigned
num_parameters);
-void panic(struct lexer_state * lexer, char const * const message);
+void panic(struct lexer_state * lexer, char const * const message, ...);
#endif /* PARROT_PIR_PIRCOMPUNIT_H_GUARD */
Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c (original)
+++ trunk/compilers/pirc/new/piremit.c Sun Dec 28 07:41:33 2008
@@ -454,25 +454,7 @@
}
}
-/***
-int
-emit_pbc_const(lexer_state * const lexer, constant * const pirconst) {
- switch (pirconst->type) {
- case INT_TYPE:
-
- break;
- case NUM_TYPE:
- return add_num_const(lexer->bc, pirconst->val.nval);
- case STRING_TYPE:
- return add_string_const(lexer->bc, pirconst->val.sval);
-
- case PMC_TYPE:
-
- break;
- }
-}
-***/
/*