Skip to content

Commit

Permalink
Add Parrot_api_pmc_find_method() function and improve t/src/embed/pmc…
Browse files Browse the repository at this point in the history
….t to test it
  • Loading branch information
Kristaba committed Dec 19, 2010
1 parent dc35afe commit 63d7ef8
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
11 changes: 11 additions & 0 deletions include/parrot/api.h
Expand Up @@ -427,6 +427,15 @@ Parrot_Int Parrot_api_pmc_deserialize_bytes(
__attribute__nonnull__(4)
FUNC_MODIFIES(* pmc);

PARROT_API
Parrot_Int Parrot_api_pmc_find_method(
Parrot_PMC interp_pmc,
Parrot_PMC object,
Parrot_String name,
ARGOUT(Parrot_PMC *method))
__attribute__nonnull__(4)
FUNC_MODIFIES(*method);

PARROT_API
Parrot_Int Parrot_api_pmc_get_class(
Parrot_PMC interp_pmc,
Expand Down Expand Up @@ -569,6 +578,8 @@ Parrot_Int Parrot_api_pmc_wrap_string_array(
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(fpmc) \
, PARROT_ASSERT_ARG(pmc))
#define ASSERT_ARGS_Parrot_api_pmc_find_method __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(method))
#define ASSERT_ARGS_Parrot_api_pmc_get_class __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(class))
#define ASSERT_ARGS_Parrot_api_pmc_get_float __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Expand Down
12 changes: 11 additions & 1 deletion src/embed/pmc.c
Expand Up @@ -204,7 +204,7 @@ PARROT_API
Parrot_Int
Parrot_api_pmc_invoke(Parrot_PMC interp_pmc, Parrot_PMC sub, Parrot_PMC signature)
{
EMBED_API_CALLIN(interp_pmc, interp);
EMBED_API_CALLIN(interp_pmc, interp)
PMC * const old_call_obj = Parrot_pcc_get_signature(interp,
CURRENT_CONTEXT(interp));
Parrot_pcc_invoke_from_sig_object(interp, sub, signature);
Expand Down Expand Up @@ -243,3 +243,13 @@ Parrot_api_pmc_get_class(Parrot_PMC interp_pmc, Parrot_PMC key,
*class = Parrot_oo_get_class(interp, key);
EMBED_API_CALLOUT(interp_pmc, interp);
}


PARROT_API
Parrot_Int
Parrot_api_pmc_find_method(Parrot_PMC interp_pmc, Parrot_PMC object, Parrot_String name, ARGOUT(Parrot_PMC *method))
{
EMBED_API_CALLIN(interp_pmc, interp);
*method = VTABLE_find_method(interp, object, name);
EMBED_API_CALLOUT(interp_pmc, interp);
}
59 changes: 58 additions & 1 deletion t/src/embed/pmc.t
Expand Up @@ -24,7 +24,7 @@ Tests PMC API support.
=cut

plan tests => 4;
plan tests => 5;

c_output_is( <<'CODE', <<'OUTPUT', "get/set_keyed_int" );
Expand Down Expand Up @@ -206,6 +206,63 @@ This is a string!
3.1415
OUTPUT

c_output_is( <<'CODE', <<'OUTPUT', "PMC find_method" );
#include <parrot/api.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
Parrot_Init_Args *initargs = NULL;
Parrot_PMC interpmc = NULL;
Parrot_PMC p_pmc = NULL, p_method = NULL, p_signature = NULL, p_classname = NULL;
Parrot_PMC p_call_class = NULL, p_toreplace = NULL, p_replacestring = NULL;
Parrot_String s_teststr = NULL, s_outstr = NULL, s_method = NULL, s_classname = NULL;
Parrot_String s_signstring = NULL, s_toreplace = NULL, s_replacestring = NULL;
Parrot_PMC p_keyedstr = NULL;
Parrot_PMC p_idx = NULL;
char * c_out = NULL;
GET_INIT_STRUCT(initargs);
Parrot_api_make_interpreter(NULL, 0, initargs, &interpmc);
Parrot_api_string_import_ascii(interpmc, "I love Microsoft!", &s_teststr);
Parrot_api_pmc_box_string(interpmc, s_teststr, &p_pmc);
Parrot_api_string_import_ascii(interpmc, "replace", &s_teststr);
Parrot_api_pmc_find_method(interpmc, p_pmc, s_teststr, &p_method);
if(p_method != NULL) {
Parrot_api_string_import_ascii(interpmc, "CallContext", &s_classname);
Parrot_api_pmc_box_string(interpmc, s_classname, &p_classname);
Parrot_api_pmc_get_class(interpmc, p_classname, &p_call_class);
Parrot_api_pmc_new_from_class(interpmc, p_call_class, NULL, &p_signature);
Parrot_api_string_import_ascii(interpmc, "PiSS->", &s_signstring);
Parrot_api_pmc_set_string(interpmc, p_signature, s_signstring);
Parrot_api_pmc_set_keyed_int(interpmc, p_signature, 0, p_pmc);
Parrot_api_string_import_ascii(interpmc, "Microsoft", &s_toreplace);
Parrot_api_pmc_box_string(interpmc, s_toreplace, &p_toreplace);
Parrot_api_pmc_set_keyed_int(interpmc, p_signature, 1, p_toreplace);
Parrot_api_string_import_ascii(interpmc, "the Open Source community", &s_replacestring);
Parrot_api_pmc_box_string(interpmc, s_replacestring, &p_replacestring);
Parrot_api_pmc_set_keyed_int(interpmc, p_signature, 2, p_replacestring);
Parrot_api_pmc_invoke(interpmc, p_method, p_signature);
Parrot_api_pmc_get_string(interpmc, p_pmc, &s_outstr);
Parrot_api_string_export_ascii(interpmc, s_outstr, &c_out);
printf("%s\n", c_out);
}
else printf("error\n");
return 0;
}
CODE
I love the Open Source community!
OUTPUT

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down

0 comments on commit 63d7ef8

Please sign in to comment.