Author: kjs
Date: Sun Dec 28 02:48:14 2008
New Revision: 34474
Modified:
trunk/compilers/pirc/new/bcgen.c
trunk/compilers/pirc/new/pircompiler.h
trunk/compilers/pirc/new/piremit.c
trunk/compilers/pirc/t/basic.t
trunk/compilers/pirc/t/heredoc.t
trunk/compilers/pirc/t/macro.t
trunk/compilers/pirc/t/stmts.t
Log:
[pirc] fix tests and add function docs.
Modified: trunk/compilers/pirc/new/bcgen.c
==============================================================================
--- trunk/compilers/pirc/new/bcgen.c (original)
+++ trunk/compilers/pirc/new/bcgen.c Sun Dec 28 02:48:14 2008
@@ -205,7 +205,11 @@
=item C<bytecode *
new_bytecode(Interp *interp, char const * const filename)>
-Create a new bytecode struct, representing the bytecode for file C<filename>
+Create a new bytecode struct, representing the bytecode for file C<filename>.
+The bytecode struct contains a PackFile, which is initialized and
+loaded into the Parrot interpreter C<interp>. Default bytecode segments
+are created, and the interpreter's C<iglobals> field is stored as a constant
+PMC in the bytecode's constant table.
=cut
@@ -453,6 +457,8 @@
Write the generated bytecode (stored somewhere in a packfile)
to the file C<filename>.
+=cut
+
*/
void
write_pbc_file(bytecode * const bc, char const * const filename) {
Modified: trunk/compilers/pirc/new/pircompiler.h
==============================================================================
--- trunk/compilers/pirc/new/pircompiler.h (original)
+++ trunk/compilers/pirc/new/pircompiler.h Sun Dec 28 02:48:14 2008
@@ -99,7 +99,7 @@
target *curtarget; /* access to current target node being
parsed, if any */
argument *curarg; /* access to current argument node being
parsed, if any */
- int curregister[4]; /* for register allocation */
+ int curregister[NUM_PARROT_TYPES]; /* for register allocation */
int pir_reg_generator; /* for unique PIR register allocator,
for temp. PIR regs. */
unsigned stmt_counter; /* to count "logical" statements, even if
multi-line. */
Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c (original)
+++ trunk/compilers/pirc/new/piremit.c Sun Dec 28 02:48:14 2008
@@ -29,6 +29,20 @@
*/
+static char const * const subflag_names[] = {
+ "method",
+ "init",
+ "load",
+ "outer",
+ "main",
+ "anon",
+ "postcomp",
+ "immediate",
+ "vtable",
+ "lex",
+ "multi",
+ "lexid"
+};
#define out stdout
@@ -44,16 +58,16 @@
/* prototype declaration */
void print_expr(lexer_state * const lexer, expression * const expr);
void print_key(lexer_state * const lexer, key *k);
-void print_target(lexer_state *lexer, target * const t);
+void print_target(lexer_state * const lexer, target * const t);
void print_constant(lexer_state * const lexer, constant * const c);
void print_expressions(lexer_state * const lexer, expression * const expr);
-void print_instruction(lexer_state * const lexer, instruction *ins);
+void print_instruction(lexer_state * const lexer, instruction * const ins);
void print_statement(lexer_state * const lexer, subroutine * const sub);
/*
=item C<void
-print_key(key *k)>
+print_key(lexer_state * const lexer, key *k)>
Print the key C<k>. The total key is enclosed in square brackets,
and different key elements are separated by semicolons. Example:
@@ -84,7 +98,7 @@
/*
=item C<void
-print_target(target * const t)>
+print_target(lexer_state * const lexer, target * const t)>
Print the target C<t>; if C<t> has a key, that key is
printed as well. Examples:
@@ -95,7 +109,7 @@
*/
void
-print_target(lexer_state *lexer, target * const t) {
+print_target(lexer_state * const lexer, target * const t) {
fprintf(out, "%c%d", pir_register_types[t->info->type], t->info->color);
/* if the target has a key, print that too */
@@ -106,7 +120,7 @@
/*
=item C<void
-print_constant(constant *c)>
+print_constant(lexer_state * const lexer, constant * const c)>
Print the value of constant C<c>.
@@ -193,9 +207,16 @@
}
}
+/*
+
+=item C<void
+print_instruction(lexer_state * const lexer, instruction * const ins)>
+
+=cut
+*/
void
-print_instruction(lexer_state * const lexer, instruction *ins) {
+print_instruction(lexer_state * const lexer, instruction * const ins) {
PARROT_ASSERT(ins != NULL);
if (ins->label) {
@@ -225,6 +246,16 @@
}
}
+/*
+
+=item C<void
+print_statement(lexer_state * const lexer, subroutine * const sub)>
+
+XXX
+
+=cut
+
+*/
void
print_statement(lexer_state * const lexer, subroutine * const sub) {
if (sub->statements != NULL) {
@@ -239,30 +270,13 @@
}
-
-static char const * const subflag_names[] = {
- "method",
- "init",
- "load",
- "outer",
- "main",
- "anon",
- "postcomp",
- "immediate",
- "vtable",
- "lex",
- "multi",
- "lexid"
-};
-
-
-
-
/*
=item C<void
print_subs(struct lexer_state * const lexer)>
+XXX
+
=cut
*/
@@ -307,21 +321,37 @@
}
}
+/*
+
+=item C<static void
+emit_pir_instruction(lexer_state * const lexer, instruction * const instr)>
+Print the PIR representation of C<instr>.
+
+=cut
+
+*/
static void
emit_pir_instruction(lexer_state * const lexer, instruction * const instr) {
if (instr->label)
fprintf(out, " %s:\n", instr->label);
- if (instr->opinfo) {
- fprintf(out, " %-10s\t", instr->opinfo->name); /* set_p_pc became
'chopn'... XXX!!! */
+ if (instr->opinfo) {
+ fprintf(out, " %-10s\t", instr->opinfo->name);
print_expressions(lexer, instr->operands);
-
fprintf(out, "\n");
}
}
+/*
+
+=item C<static void
+emit_pir_statement(lexer_state * const lexer, subroutine * const sub)>
+
+=cut
+
+*/
static void
emit_pir_statement(lexer_state * const lexer, subroutine * const sub) {
if (sub->statements != NULL) {
@@ -335,6 +365,17 @@
}
}
+/*
+
+=item C<void
+emit_pir_subs(lexer_state * const lexer)>
+
+Print the PIR representation of all subroutines stored
+in the C<lexer>.
+
+=cut
+
+*/
void
emit_pir_subs(lexer_state * const lexer) {
if (lexer->subs != NULL) {
@@ -551,8 +592,8 @@
=item C<void
emit_pbc(lexer_state * const lexer)>
-Generate Parrot Byte Code from the abstract syntax tree. This is the top-level
-function.
+Generate Parrot Byte Code from the abstract syntax tree.
+This is the top-level function.
=cut
Modified: trunk/compilers/pirc/t/basic.t
==============================================================================
--- trunk/compilers/pirc/t/basic.t (original)
+++ trunk/compilers/pirc/t/basic.t Sun Dec 28 02:48:14 2008
@@ -47,7 +47,7 @@
CODE
.namespace []
main:
- set_returns
+ set_returns 1
returncc
OUTPUT
@@ -58,7 +58,7 @@
CODE
.namespace []
.pcc_sub main:
- set_returns
+ set_returns 1
returncc
OUTPUT
@@ -71,11 +71,11 @@
CODE
.namespace []
.pcc_sub main:
- set_returns
+ set_returns 1
returncc
.namespace []
.pcc_sub get_integer:
- set_returns
+ set_returns 5
returncc
OUTPUT
@@ -88,11 +88,11 @@
CODE
.namespace []
.pcc_sub :method main:
- set_returns
+ set_returns 1
returncc
.namespace []
.pcc_sub :method bye:
- set_returns
+ set_returns 5
returncc
OUTPUT
@@ -103,7 +103,7 @@
CODE
.namespace []
.pcc_sub main:
- set_returns
+ set_returns 1
returncc
OUTPUT
Modified: trunk/compilers/pirc/t/heredoc.t
==============================================================================
--- trunk/compilers/pirc/t/heredoc.t (original)
+++ trunk/compilers/pirc/t/heredoc.t Sun Dec 28 02:48:14 2008
@@ -29,11 +29,11 @@
CODE
.namespace []
main:
- set_args "\nthis is a simple single-line heredoc.\n", "\nthis is a
simple\nmulti\nline\nheredoc\n.\n", "\nand yet
another\nmulti\nline\nheredoc\nstring.\n"
- get_results ""
+ set_args 1
+ get_results 2
find_sub_not_null P0, "foo"
invokecc P0
- set_returns
+ set_returns 3
returncc
OUTPUT
@@ -54,9 +54,9 @@
.namespace []
foo:
get_params
- set_returns "\n This is some text returned through .yield!\n\n"
+ set_returns 1
yield
- set_returns "\n Some text returned through return\n"
+ set_returns 2
returncc
OUTPUT
@@ -75,7 +75,7 @@
main:
set S0, "\nthis is a simple assigned heredoc string to $S0.\n"
set S1, "\nthis is a simple assigned heredoc string to string s.\n"
- set_returns
+ set_returns 1
returncc
OUTPUT
Modified: trunk/compilers/pirc/t/macro.t
==============================================================================
--- trunk/compilers/pirc/t/macro.t (original)
+++ trunk/compilers/pirc/t/macro.t Sun Dec 28 02:48:14 2008
@@ -17,7 +17,7 @@
.namespace []
main:
print "hello"
- set_returns
+ set_returns 1
returncc
OUTPUT
@@ -38,7 +38,7 @@
main:
say 42
say "hi"
- set_returns
+ set_returns 1
returncc
OUTPUT
Modified: trunk/compilers/pirc/t/stmts.t
==============================================================================
--- trunk/compilers/pirc/t/stmts.t (original)
+++ trunk/compilers/pirc/t/stmts.t Sun Dec 28 02:48:14 2008
@@ -23,7 +23,7 @@
set S0, "hi"
set I0, 42
set N0, 3.140000
- set_returns
+ set_returns 1
returncc
OUTPUT
@@ -45,7 +45,7 @@
X:
Y:
Z:
- set_returns
+ set_returns 1
returncc
OUTPUT
@@ -67,7 +67,7 @@
lt I1, I0, 4
goto:
L:
- set_returns
+ set_returns 1
returncc
OUTPUT
@@ -80,11 +80,11 @@
CODE
.namespace []
main:
- set_args ""
- get_results ""
+ set_args 1
+ get_results 2
find_sub_not_null P0, "foo"
invokecc P0
- set_returns
+ set_returns 3
returncc
OUTPUT
@@ -99,15 +99,15 @@
CODE
.namespace []
main:
- set_args ""
- get_results ""
- set P0, 0
+ set_args 1
+ get_results 2
+ set P0, 10
invokecc P0
- set_returns
+ set_returns 3
returncc
.namespace []
foo:
- set_returns
+ set_returns 7
returncc
OUTPUT