[svn:parrot] r43961 - in branches/tt362/src: . pmc
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Mon Feb 15 04:16:22 UTC 2010
Author: plobsing
Date: Mon Feb 15 04:16:18 2010
New Revision: 43961
URL: https://trac.parrot.org/parrot/changeset/43961
Log:
abstract away ImageIO-specific details from visit and thawfinish loops and move these out into src/pmc_freeze.c
Modified:
branches/tt362/src/pmc/imageio.pmc
branches/tt362/src/pmc_freeze.c
Modified: branches/tt362/src/pmc/imageio.pmc
==============================================================================
--- branches/tt362/src/pmc/imageio.pmc Mon Feb 15 03:02:42 2010 (r43960)
+++ branches/tt362/src/pmc/imageio.pmc Mon Feb 15 04:16:18 2010 (r43961)
@@ -204,52 +204,6 @@
}
}
-static void
-visit_loop_todo_list(PARROT_INTERP, PMC *info)
-{
- INTVAL i;
- PMC * const todo = PARROT_IMAGEIO(info)->todo;
- const int thawing = VTABLE_get_integer(interp, info) == VISIT_THAW_NORMAL;
-
- /* can't cache upper limit, visit may append items */
- for (i = 0; i < VTABLE_elements(interp, todo); i++) {
- PMC *current = VTABLE_get_pmc_keyed_int(interp, todo, i);
- if (!current)
- Parrot_ex_throw_from_c_args(interp, NULL, 1,
- "NULL current PMC in visit_loop_todo_list");
-
- PARROT_ASSERT(current->vtable);
-
- VTABLE_visit(interp, current, info);
-
- VISIT_PMC(interp, info, PMC_metadata(current));
- }
-
- if (thawing)
- /* we're done reading the image */
- PARROT_ASSERT(!INFO_HAS_DATA(info));
-
- if (thawing) {
- /* on thawing call thawfinish for each processed PMC */
- const INTVAL n = VTABLE_elements(interp, todo);
- int i;
-
- /*
- * Thaw in reverse order. We have to fully thaw younger PMCs
- * before use them in older.
- *
- * XXX There are no younger or older pmcs in a directed graph
- * that allows cycles. Any code that requires a specific
- * order here is likely broken.
- */
- for (i = n-1; i >= 0; --i) {
- PMC *current = VTABLE_get_pmc_keyed_int(interp, todo, i);
- if (!PMC_IS_NULL(current))
- VTABLE_thawfinish(interp, current, info);
- }
- }
-}
-
pmclass ImageIO auto_attrs {
ATTR Buffer *buffer; /* buffer to store the image */
ATTR size_t pos; /* current read/write position in buffer */
@@ -356,6 +310,20 @@
/*
+=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_IMAGEIO(SELF)->todo;
+ }
+
+/*
+
=item C<VTABLE INTVAL get_integer()>
Returns the flags describing the visit action
@@ -527,7 +495,7 @@
parrot_new_intval_hash(INTERP));
visit_todo_list_freeze(INTERP, p, SELF);
- visit_loop_todo_list(INTERP, SELF);
+ Parrot_visit_loop_visit(INTERP, SELF);
}
VTABLE void set_string_native(STRING *image) {
@@ -556,7 +524,11 @@
}
visit_todo_list_thaw(INTERP, SELF);
- visit_loop_todo_list(INTERP, SELF);
+ Parrot_visit_loop_visit(INTERP, SELF);
+
+ /* we're done reading the image */
+ PARROT_ASSERT(!INFO_HAS_DATA(SELF));
+ Parrot_visit_loop_thawfinish(INTERP, SELF);
}
/*
Modified: branches/tt362/src/pmc_freeze.c
==============================================================================
--- branches/tt362/src/pmc_freeze.c Mon Feb 15 03:02:42 2010 (r43960)
+++ branches/tt362/src/pmc_freeze.c Mon Feb 15 04:16:18 2010 (r43961)
@@ -158,6 +158,68 @@
return VTABLE_clone(interp, pmc);
}
+/*
+
+=item C<void Parrot_visit_loop_visit(PARROT_INTERP, PMC *info)>
+
+Iterate a visitor PMC visiting each encountered target PMC.
+
+=cut
+
+*/
+
+void
+Parrot_visit_loop_visit(PARROT_INTERP, PMC *info) {
+ INTVAL i;
+ PMC * const todo = VTABLE_get_iter(interp, info);
+
+ /* can't cache upper limit, visit may append items */
+ for (i = 0; i < VTABLE_elements(interp, todo); i++) {
+ PMC *current = VTABLE_get_pmc_keyed_int(interp, todo, i);
+ if (!current)
+ Parrot_ex_throw_from_c_args(interp, NULL, 1,
+ "NULL current PMC in visit_loop_todo_list");
+
+ PARROT_ASSERT(current->vtable);
+
+ VTABLE_visit(interp, current, info);
+
+ VISIT_PMC(interp, info, PMC_metadata(current));
+ }
+}
+
+/*
+
+=item C<void Parrot_visit_loop_thawfinish(PARROT_INTERP, PMC *info)>
+
+Iterate a visitor PMC thawfinishing each encountered target PMC.
+
+=cut
+
+*/
+
+void
+Parrot_visit_loop_thawfinish(PARROT_INTERP, PMC *info) {
+ /* call thawfinish for each processed PMC */
+ /*
+ * Thaw in reverse order. We have to fully thaw younger PMCs
+ * before use them in older.
+ *
+ * XXX There are no younger or older pmcs in a directed graph
+ * that allows cycles. Any code that requires a specific
+ * order here is likely broken.
+ */
+
+ PMC * const todo = VTABLE_get_iter(interp, info);
+ const INTVAL n = VTABLE_elements(interp, todo);
+ int i;
+
+ for (i = n-1; i >= 0; --i) {
+ PMC *current = VTABLE_get_pmc_keyed_int(interp, todo, i);
+ if (!PMC_IS_NULL(current))
+ VTABLE_thawfinish(interp, current, info);
+ }
+}
/*
More information about the parrot-commits
mailing list