Author: kjs
Date: Sat Dec 27 11:40:27 2008
New Revision: 34440

Modified:
   trunk/compilers/pirc/new/bcgen.c
   trunk/compilers/pirc/new/bcgen.h
   trunk/compilers/pirc/new/pircompunit.c

Log:
[pirc] store the constant table index for the sub in the global_label node for 
that sub.

Modified: trunk/compilers/pirc/new/bcgen.c
==============================================================================
--- trunk/compilers/pirc/new/bcgen.c    (original)
+++ trunk/compilers/pirc/new/bcgen.c    Sat Dec 27 11:40:27 2008
@@ -357,11 +357,12 @@
 add_sub_pmc(bytecode * const bc, sub_info * const info)>
 
 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.
 
 =cut
 
 */
-void
+int
 add_sub_pmc(bytecode * const bc, sub_info * const info) {
     PMC               *sub_pmc;
     Parrot_sub        *sub;
@@ -438,6 +439,9 @@
 
     /* Add a new fixup entry in the fixup table for this sub. */
     PackFile_FixupTable_new_entry(bc->interp, info->subname, enum_fixup_sub, 
subconst_index);
+
+    /* return the index in the constant table where this sub PMC is stored */
+    return subconst_index;
 }
 
 

Modified: trunk/compilers/pirc/new/bcgen.h
==============================================================================
--- trunk/compilers/pirc/new/bcgen.h    (original)
+++ trunk/compilers/pirc/new/bcgen.h    Sat Dec 27 11:40:27 2008
@@ -83,8 +83,7 @@
 int get_string_const_index(bytecode * const bc, STRING *s);
 /* retrieves the index of s in the constant table */
 
-
-void add_sub_pmc(bytecode * const bc, sub_info * const info);
+int add_sub_pmc(bytecode * const bc, sub_info * const info);
 
 
 #endif /* PARROT_BCGEN_H_GUARD */

Modified: trunk/compilers/pirc/new/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.c      (original)
+++ trunk/compilers/pirc/new/pircompunit.c      Sat Dec 27 11:40:27 2008
@@ -2377,6 +2377,8 @@
 void
 close_sub(lexer_state * const lexer) {
     int need_leaving_instr = 1;
+    int sub_const_table_index;
+    global_label *glob;
 
     /* don't generate leaving instructions if the last instruction was already
      * leaving the sub.
@@ -2405,7 +2407,15 @@
     if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC))
         linear_scan_register_allocation(lexer->lsr);
 
-    add_sub_pmc(lexer->bc, &CURRENT_SUB(lexer)->info);
+    /* store the subroutine in the bytecode constant table. */
+    sub_const_table_index = add_sub_pmc(lexer->bc, &CURRENT_SUB(lexer)->info);
+
+    /* store the sub PMC index in the constant table with the global label,
+     * so that invoking ops can find this index.
+     */
+    glob = find_global_label(lexer, CURRENT_SUB(lexer)->info.subname);
+    PARROT_ASSERT(glob != NULL); /* it was stored in new_subr(), so must be 
there. */
+    glob->const_table_index = sub_const_table_index;
 }
 
 /*

Reply via email to