[svn:parrot] r46082 - in branches/pbc_frozen_strings1: src/pmc t/pmc

plobsing at svn.parrot.org plobsing at svn.parrot.org
Tue Apr 27 22:49:55 UTC 2010


Author: plobsing
Date: Tue Apr 27 22:49:55 2010
New Revision: 46082
URL: https://trac.parrot.org/parrot/changeset/46082

Log:
add ImageIOStrings pmc to traverse objects and get their strings

Added:
   branches/pbc_frozen_strings1/src/pmc/imageiostrings.pmc
   branches/pbc_frozen_strings1/t/pmc/imageiostrings.t

Added: branches/pbc_frozen_strings1/src/pmc/imageiostrings.pmc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/pbc_frozen_strings1/src/pmc/imageiostrings.pmc	Tue Apr 27 22:49:55 2010	(r46082)
@@ -0,0 +1,194 @@
+/*
+Copyright (C) 2010, Parrot Foundation.
+$Id: imageiosize.pmc 45290 2010-03-29 23:41:28Z petdance $
+
+=head1 NAME
+
+src/pmc/imageiosize.pmc - ImageIOStrings PMC
+
+=head1 DESCRIPTION
+
+Get a list of strings in an object graph. Used in packfile creation.
+
+=cut
+
+*/
+
+pmclass ImageIOStrings auto_attrs {
+    ATTR PMC *seen; /* seen hash */
+    ATTR PMC *todo; /* todo list */
+    ATTR PMC *list; /* list of strings seen */
+
+/*
+
+=head1 VTABLES
+
+=over 4
+
+=cut
+
+*/
+
+/*
+
+=item C<void init()>
+
+Initializes the PMC.
+
+=cut
+
+*/
+    VTABLE void init() {
+        PARROT_IMAGEIOSTRINGS(SELF)->todo = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
+
+        PARROT_IMAGEIOSTRINGS(SELF)->seen = Parrot_pmc_new(INTERP, enum_class_Hash);
+        VTABLE_set_pointer(INTERP, PARROT_IMAGEIOSTRINGS(SELF)->seen,
+            parrot_new_intval_hash(INTERP));
+
+        PARROT_IMAGEIOSTRINGS(SELF)->list = Parrot_pmc_new(INTERP, enum_class_ResizableStringArray);
+    }
+
+/*
+
+=item C<void mark()>
+
+Marks the PMC as alive.
+
+=cut
+
+*/
+    VTABLE void mark() {
+        Parrot_gc_mark_PMC_alive(INTERP, PARROT_IMAGEIOSTRINGS(SELF)->todo);
+        Parrot_gc_mark_PMC_alive(INTERP, PARROT_IMAGEIOSTRINGS(SELF)->seen);
+        Parrot_gc_mark_PMC_alive(INTERP, PARROT_IMAGEIOSTRINGS(SELF)->list);
+    }
+
+/*
+
+=item C<VTABLE PMC *get_pmc()>
+
+Gets the result PMC after a thaw.
+
+=cut
+
+*/
+
+    VTABLE PMC *get_pmc() {
+        return PARROT_IMAGEIOSTRINGS(SELF)->list;
+    }
+
+/*
+
+=item C<VTABLE PMC *get_iter()>
+
+Get the C<todo> list for this freeze/thaw for iterating over.
+
+=cut
+
+*/
+
+    VTABLE PMC *get_iter() {
+        return PARROT_IMAGEIOSTRINGS(SELF)->todo;
+    }
+
+/*
+
+=item C<VTABLE INTVAL get_integer()>
+
+Returns the flags describing the visit action
+
+=cut
+
+*/
+
+    VTABLE INTVAL get_integer() {
+        return VISIT_FREEZE_NORMAL;
+    }
+
+
+/*
+
+=item C<VTABLE void push_integer(INTVAL v)>
+
+Do nothing.
+
+=cut
+
+*/
+
+    VTABLE void push_integer(INTVAL v) { }
+
+
+/*
+
+=item C<VTABLE void push_float(FLOATVAL v)>
+
+Do nothing.
+
+=cut
+
+*/
+
+    VTABLE void push_float(FLOATVAL v) { }
+
+
+/*
+
+=item C<VTABLE void push_string(STRING *v)>
+
+Adds the string to the list of strings.
+
+=cut
+
+*/
+
+    VTABLE void push_string(STRING *v)
+    {
+        VTABLE_push_string(INTERP, PARROT_IMAGEIOSTRINGS(SELF)->list, v);
+    }
+
+/*
+
+=item C<VTABLE void push_pmc(PMC *v)>
+
+Checks new pmcs for strings.
+
+=cut
+
+*/
+
+    VTABLE void push_pmc(PMC *v) {
+        if (!PMC_IS_NULL(v)) {
+            Hash * const hash    = (Hash *)VTABLE_get_pointer(INTERP, PARROT_IMAGEIOSTRINGS(SELF)->seen);
+            HashBucket * const b = parrot_hash_get_bucket(INTERP, hash, v);
+            if (!b) {
+                /* not yet seen */
+                parrot_hash_put(INTERP, hash, v, v);
+                VTABLE_push_pmc(INTERP, PARROT_IMAGEIOSTRINGS(SELF)->todo, v);
+                VTABLE_freeze(INTERP, v, SELF);
+            }
+        }
+    }
+
+    VTABLE void set_pmc(PMC *p)
+    {
+        STATICSELF.push_pmc(p);
+        Parrot_visit_loop_visit(INTERP, SELF);
+    }
+
+/*
+
+=back
+
+=cut
+
+*/
+
+}
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Added: branches/pbc_frozen_strings1/t/pmc/imageiostrings.t
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/pbc_frozen_strings1/t/pmc/imageiostrings.t	Tue Apr 27 22:49:55 2010	(r46082)
@@ -0,0 +1,47 @@
+#!./parrot
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+=head1 NAME
+
+t/pmc/imageiostrings.t - test ImageIOStrings PMC
+
+=head1 SYNOPSIS
+
+    % prove t/pmc/imageiostrings.t
+
+=head1 DESCRIPTION
+
+Tests the ImageIOStringsPMC.
+
+=cut
+
+.sub main :main
+    .include 'test_more.pir'
+
+    plan(3)
+
+    .local pmc iios
+    iios = new ['ImageIOStrings']
+    ok(1, 'instantiated ImageIOStrings')
+
+    .local pmc test_pmc
+    test_pmc = null
+    iios = new ['ImageIOStrings']
+    setref iios, test_pmc
+    $P0 = deref iios
+    $I0 = $P0
+    nok( $I0, 'no strings in null pmc' )
+
+    test_pmc = split ' ', 'spam sausage spam spam bacon spam tomato and spam'
+    iios = new ['ImageIOStrings']
+    setref iios, test_pmc
+    $P0 = deref iios
+    is_deeply( $P0, test_pmc, 'correctly manages RSA' )
+.end
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:


More information about the parrot-commits mailing list