[svn:parrot] r37984 - branches/packfile_revamp/src/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Apr 8 23:43:39 UTC 2009


Author: bacek
Date: Wed Apr  8 23:43:39 2009
New Revision: 37984
URL: https://trac.parrot.org/parrot/changeset/37984

Log:
Implement PackfileConstantTable.set_*_int methods.

Modified:
   branches/packfile_revamp/src/pmc/packfileconstanttable.pmc

Modified: branches/packfile_revamp/src/pmc/packfileconstanttable.pmc
==============================================================================
--- branches/packfile_revamp/src/pmc/packfileconstanttable.pmc	Wed Apr  8 23:43:16 2009	(r37983)
+++ branches/packfile_revamp/src/pmc/packfileconstanttable.pmc	Wed Apr  8 23:43:39 2009	(r37984)
@@ -40,6 +40,39 @@
     return rv;
 }
 
+/*
+ * Extend constant table if required
+ * 
+ * Implementation details: very similar to imcc/pbc.c. We need refactor
+ * it to common subroutine.
+ */
+static PackFile_Constant *
+vivify(PARROT_INTERP, PackFile_ConstTable *table, int index)
+{
+    const size_t    old_count = table->const_count;
+    const size_t    new_count = index+1;
+    size_t          i;
+
+    if (index >= table->const_count) {
+        /* Update the constant count and reallocate */
+        if (table->constants)
+            table->constants = mem_realloc_n_typed(table->constants, new_count,
+                PackFile_Constant *);
+        else
+            table->constants =
+                mem_allocate_n_typed(new_count, PackFile_Constant *);
+
+        for (i=old_count; i<new_count; ++i) {
+            table->constants[i] = PackFile_Constant_new(interp);
+        }
+
+        /* Store new size */
+        table->const_count = new_count;
+    }
+
+    return table->constants[index];
+}
+
 
 pmclass PackfileConstantTable extends PackfileSegment {
 
@@ -119,7 +152,10 @@
 
 */
     VTABLE void set_number_keyed_int(INTVAL index, FLOATVAL value)  {
-        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+        PackFile_ConstTable *pftable = PMC_data_typed(SELF, PackFile_ConstTable *);
+        PackFile_Constant   *constant = vivify(interp, pftable, index);
+        constant->type      = PFC_NUMBER;
+        constant->u.number  = value;
     }
 
 
@@ -133,7 +169,10 @@
 
 */
     VTABLE void set_string_keyed_int(INTVAL index, STRING *value)  {
-        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+        PackFile_ConstTable *pftable = PMC_data_typed(SELF, PackFile_ConstTable *);
+        PackFile_Constant *constant = vivify(interp, pftable, index);
+        constant->type      = PFC_STRING;
+        constant->u.string  = value;
     }
 
 
@@ -147,7 +186,10 @@
 
 */
     VTABLE void set_pmc_keyed_int(INTVAL index, PMC *value)  {
-        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+        PackFile_ConstTable *pftable = PMC_data_typed(SELF, PackFile_ConstTable *);
+        PackFile_Constant   *constant = vivify(interp, pftable, index);
+        constant->type  = PFC_KEY;
+        constant->u.key = value;
     }
 
 


More information about the parrot-commits mailing list