[svn:parrot] r43645 - branches/pmc_freeze_with_pmcs/src/pmc

darbelo at svn.parrot.org darbelo at svn.parrot.org
Sat Jan 30 03:58:56 UTC 2010


Author: darbelo
Date: Sat Jan 30 03:58:50 2010
New Revision: 43645
URL: https://trac.parrot.org/parrot/changeset/43645

Log:
Start filling out the VTABLEs.
Right now this are dumb copies from the code in pmc_freeze.c

Modified:
   branches/pmc_freeze_with_pmcs/src/pmc/imageio.pmc

Modified: branches/pmc_freeze_with_pmcs/src/pmc/imageio.pmc
==============================================================================
--- branches/pmc_freeze_with_pmcs/src/pmc/imageio.pmc	Sat Jan 30 03:20:51 2010	(r43644)
+++ branches/pmc_freeze_with_pmcs/src/pmc/imageio.pmc	Sat Jan 30 03:58:50 2010	(r43645)
@@ -81,12 +81,11 @@
         if (new_size < Buffer_buflen(buf) - need_free + 512)
             new_size = Buffer_buflen(buf) - need_free + 512;
         Parrot_gc_reallocate_buffer_storage(interp, buf, new_size);
-
         PARROT_ASSERT(Buffer_buflen(buf) - used - len >= 15);
     }
 
 #ifndef DISABLE_GC_DEBUG
-    Parrot_gc_compact_memory_pool(interp);
+    Parrot_gc_compact_memory_pool(INTERP);
 #endif
 
 }
@@ -128,9 +127,223 @@
 =cut
 
 */
+    VTABLE void init() {
+        PARROT_IMAGEIO(SELF)->buffer      = NULL;
+        PARROT_IMAGEIO(SELF)->todo        = pmc_new(INTERP, enum_class_Array);
+        PARROT_IMAGEIO(SELF)->seen        = PMCNULL;
+        PARROT_IMAGEIO(SELF)->id_list     = PMCNULL;
+        PARROT_IMAGEIO(SELF)->id          = 0;
+        PARROT_IMAGEIO(SELF)->extra_flags = EXTRA_IS_NULL;
+        PARROT_IMAGEIO(SELF)->pf          = PackFile_new(INTERP, 0);
+
+        PObj_custom_mark_destroy_SETALL(SELF);
+    }
+
+
+/*
+
+=item C<void destroy()>
+
+Destroys the PMC.
+
+=cut
+
+*/
+    VTABLE void destroy() {
+        PackFile_destroy(INTERP, PARROT_IMAGEIO(SELF)->pf);
+    }
+
+/*
+
+=item C<void mark()>
+
+Marks the PMC as alive.
+
+=cut
+
+*/
+    VTABLE void mark() {
+        Parrot_gc_mark_PObj_alive(INTERP, PARROT_IMAGEIO(SELF)->buffer);
+        Parrot_gc_mark_PMC_alive(INTERP, PARROT_IMAGEIO(SELF)->todo);
+        Parrot_gc_mark_PMC_alive(INTERP, PARROT_IMAGEIO(SELF)->seen);
+        Parrot_gc_mark_PMC_alive(INTERP, PARROT_IMAGEIO(SELF)->id_list);
+    }
+
+=item C<STRING *get_string()>
+
+Returns the content of the image as a string.
+
+=cut
+
+*/
+
+    VTABLE STRING *get_string() {
+        return Parrot_str_new_from_buffer(INTERP, 
+                                          PARROT_IMAGEIO(SELF)->buffer,
+                                          PARROT_IMAGEIO(SELF)->pos);
+    }
+/*
+
+/*
+
+=item C<VTABLE INTVAL get_integer()>
+
+Returns the flags describing the visit action
+
+=cut
+
+*/
+
+VTABLE INTVAL get_integer() {
+    return PARROT_IMAGEIO(SELF)->what;
+}
+
+/*
+
+=item C<VTABLE void push_integer(INTVAL v)>
+
+Pushes the integer C<v> onto the end of the image.
+
+=cut
+
+*/
+
+static void
+push_opcode_integer(PARROT_INTERP, ARGIN(visit_info *io), INTVAL v)
+{
+    size_t len = PF_size_integer() * sizeof (opcode_t);
+    ensure_buffer_size(interp, SELF, len);
+    SET_VISIT_CURSOR(SELF, PF_store_integer(GET_VISIT_CURSOR(SELF), v));
+}
+
+
+/*
+
+=item C<VTABLE void push_float(FLOATVAL v)>
+
+Pushes the float C<v> onto the end of the image.
+
+=cut
+
+*/
+
+VTABLE void push_float(FLOATVAL v)
+{
+    size_t len = PF_size_number() * sizeof (opcode_t);
+    ensure_buffer_size(interp, SELF, len);
+    SET_VISIT_CURSOR(SELF, PF_store_number(GET_VISIT_CURSOR(SELF), &v));
+}
+
+
+/*
+
+=item C<VTABLE void push_string(STRING *v)>
+
+Pushes the string C<*v> onto the end of the image.
+
+=cut
+
+*/
+
+VTABLE void push_string(STRING *v)
+{
+    size_t len = PF_size_string(v) * sizeof (opcode_t);
+    ensure_buffer_size(INTERP, SELF, len);
+    SET_VISIT_CURSOR(SELF, PF_store_string(GET_VISIT_CURSOR(SELF), v));
+}
+
+/*
+
+=item C<VTABLE void push_pmc(PMC *v)>
+
+Pushes a reference to pmc C<*v> onto the end of the image. If C<*v>
+hasn't been seen yet, it is also pushed onto the todo list.
+
+=cut
+
+*/
+
+VTABLE void push_pmc(PMC *v) {
+    PARROT_IMAGEIO(SELF)->thaw_ptr = &v;
+    (PARROT_IMAGEIO(SELF)->visit_pmc_now)(INTERP, v, SELF);
+}
+
+/*
+
+=item C<VTABLE INTVAL shift_integer()>
+
+Removes and returns an integer from the start of the image.
+
+=cut
+
+*/
+
+VTABLE INTVAL shift_integer()
+{
+    opcode_t *pos  = GET_VISIT_CURSOR(SELF);
+    const INTVAL i = PF_fetch_integer(PARROT_IMAGEIO(SELF)->pf, (const opcode_t **)&pos);
+    SET_VISIT_CURSOR(SELF, pos);
+    BYTECODE_SHIFT_OK(SELF);
+    return i;
+}
+
+
+/*
+
+=item C<VTABLE FLOATVAL shift_number()>
+
+Removes and returns an number from the start of the image.
+
+=cut
+
+*/
+
+VTABLE FLOATVAL shift__number() {
+    opcode_t *pos    = GET_VISIT_CURSOR(SELF);
+    const FLOATVAL f = PF_fetch_number(PARROT_IMAGEIO(SELF)->pf, (const opcode_t **)&pos);
+    SET_VISIT_CURSOR(SELF, pos);
+    BYTECODE_SHIFT_OK(SELF);
+    return f;
+}
+
 
 /*
 
+=item C<VTABLE STRING* shift_string()>
+
+Removes and returns a string from the start of the image.
+
+=cut
+
+*/
+
+VTABLE  STRING *shift__string()
+{
+    opcode_t *pos    = GET_VISIT_CURSOR(SELF);
+    STRING * const s = PF_fetch_string(interp, PARROT_IMAGEIO(SELF)->pf, (const opcode_t **)&pos);
+    SET_VISIT_CURSOR(SELF, pos);
+    BYTECODE_SHIFT_OK(SELF);
+    return s;
+}
+
+/*
+
+=item C<static PMC *shift_opcode_pmc(PARROT_INTERP, visit_info *io)>
+
+Removes and returns a reference to a pmc from the start of the C<*io> "stream".
+
+=cut
+
+*/
+
+VTABLE PMC *shift_pmc() {
+    PMC *result;
+    PARROT_IMAGEIO(SELF)->thaw_ptr = &result;
+    (PARROT_IMAGEIO(SELF)->visit_pmc_now)(interp, NULL, PARROT_IMAGEIO(SELF));
+    return result;
+}
+
+
 =back
 
 =cut


More information about the parrot-commits mailing list