Permalink
Browse files

Add a packfile api function Parrot_pf_all_tags_list function, to retu…

…rn an RSA of all tags in the packfile. Expose this through the all_tags() method on the PackfileView PMC. Add some missing docs. benabik++ for the suggestion
  • Loading branch information...
Whiteknight committed Aug 10, 2012
1 parent 7926733 commit 1403dd4f41449fdc2dd3332f367f6c59ab166833
Showing with 65 additions and 1 deletion.
  1. +9 −0 include/parrot/packfile.h
  2. +39 −1 src/packfile/api.c
  3. +17 −0 src/pmc/packfileview.pmc
@@ -754,6 +754,12 @@ PMC * PackFile_Annotations_lookup(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC * Parrot_pf_all_tags_list(PARROT_INTERP, ARGIN(PMC * pfpmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_PURE_FUNCTION
PARROT_CANNOT_RETURN_NULL
PackFile_ByteCode * Parrot_pf_get_current_code_segment(PARROT_INTERP)
@@ -885,6 +891,9 @@ void Parrot_pf_mark_packfile(PARROT_INTERP, ARGMOD_NULLOK(PackFile * pf))
#define ASSERT_ARGS_PackFile_Annotations_lookup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(self))
#define ASSERT_ARGS_Parrot_pf_all_tags_list __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pfpmc))
#define ASSERT_ARGS_Parrot_pf_get_current_code_segment \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
View
@@ -507,8 +507,46 @@ Parrot_pf_subs_by_tag(PARROT_INTERP, ARGIN(PMC * pfpmc), ARGIN(STRING * flag))
/*
=item C<PMC * Parrot_pf_all_tags_list(PARROT_INTERP, PMC * pfpmc)>
Return a ResizableStringArray of all tags in the packfile.
=cut
*/
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC *
Parrot_pf_all_tags_list(PARROT_INTERP, ARGIN(PMC * pfpmc))
{
ASSERT_ARGS(Parrot_pf_all_tags_list)
PackFile * const pf = (PackFile*)VTABLE_get_pointer(interp, pfpmc);
PMC * const tags = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
if (!pf || !pf->cur_cs || !pf->cur_cs->const_table)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
"NULL or invalid packfile");
{
PackFile_ConstTable * const ct = pf->cur_cs->const_table;
const opcode_t ntags = ct->ntags;
opcode_t i = 0;
opcode_t last_seen = -1;
for (; i < ntags; i++) {
const opcode_t cur_tag = ct->tag_map[i].tag_idx;
if (cur_tag == last_seen)
continue;
VTABLE_push_string(interp, tags, ct->str.constants[cur_tag]);
last_seen = cur_tag;
}
}
return tags;
}
/*
=item C<static int sub_pragma(PARROT_INTERP, pbc_action_enum_t action, const PMC
*sub_pmc)>
*sub_pmc)
Checks B<sub_pmc>'s pragmas (e.g. flags like C<:load>, C<:main>, etc.)
returning 1 if the sub should be run for C<action>, a C<pbc_action_enum_t>.
View
@@ -350,10 +350,22 @@ Get an array of all Subs with the given tag.
Trigger subs with the given flag. Currently supported values are "load" and
"init".
=item C<METHOD all_tags()>
Return an array of all tags.
=item C<METHOD all_subs()>
Return a ResizablePMCArray with all Sub constants from the constant table.
item C<METHOD mark_initialized(STRING *tag)>
Mark a given tag as being initialized
item C<METHOD is_initialized(STRING *tag)>
Determine if the given tag has been marked initialized
=cut
*/
@@ -389,6 +401,11 @@ Return a ResizablePMCArray with all Sub constants from the constant table.
RETURN(PMC *array);
}
METHOD all_tags() {
PMC * const array = Parrot_pf_all_tags_list(interp, SELF);
RETURN (PMC *array);
}
METHOD mark_initialized(STRING *tag) {
add_called_tag(INTERP, SELF, tag);
}

0 comments on commit 1403dd4

Please sign in to comment.