Skip to content

Commit

Permalink
Refactor out CallContext creation into a new function Parrot_pcc_new_…
Browse files Browse the repository at this point in the history
…call_object. Use that in the new_call_context op. Also, expose it through a convenient new Parrot_api_new_call_object API function. brrt++ for the suggestion
  • Loading branch information
Whiteknight committed May 18, 2012
1 parent b6bf583 commit 0ebe739
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 17 deletions.
10 changes: 10 additions & 0 deletions include/parrot/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,13 @@ Parrot_Int Parrot_api_pmc_keep_alive(
Parrot_PMC pmc,
Parrot_Int alive);

PARROT_API
Parrot_Int Parrot_api_pmc_new_call_object(
Parrot_PMC interp_pmc,
ARGOUT(Parrot_PMC *cc))
__attribute__nonnull__(2)
FUNC_MODIFIES(*cc);

PARROT_API
Parrot_Int Parrot_api_pmc_new_from_class(
ARGIN(Parrot_PMC interp_pmc),
Expand Down Expand Up @@ -791,6 +798,9 @@ Parrot_Int Parrot_api_pmc_wrap_string_array(
, PARROT_ASSERT_ARG(sub) \
, PARROT_ASSERT_ARG(signature))
#define ASSERT_ARGS_Parrot_api_pmc_keep_alive __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_api_pmc_new_call_object \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(cc))
#define ASSERT_ARGS_Parrot_api_pmc_new_from_class __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp_pmc) \
, PARROT_ASSERT_ARG(class_pmc) \
Expand Down
8 changes: 8 additions & 0 deletions include/parrot/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ void Parrot_pcc_invoke_sub_from_c_args(PARROT_INTERP,
__attribute__nonnull__(2)
__attribute__nonnull__(3);

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC * Parrot_pcc_new_call_object(PARROT_INTERP)
__attribute__nonnull__(1);

#define ASSERT_ARGS_Parrot_pcc_do_run_ops __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(sub_obj))
Expand All @@ -105,6 +111,8 @@ void Parrot_pcc_invoke_sub_from_c_args(PARROT_INTERP,
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(sub_obj) \
, PARROT_ASSERT_ARG(sig))
#define ASSERT_ARGS_Parrot_pcc_new_call_object __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/call/pcc.c */

Expand Down
20 changes: 10 additions & 10 deletions include/parrot/exit.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ void Parrot_x_on_exit(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void Parrot_x_panic_and_exit(
NULLOK_INTERP,
ARGIN_NULLOK(const char *message),
ARGIN_NULLOK(const char *file),
unsigned int line);

PARROT_COLD
void Parrot_x_execute_on_exit_handlers(PARROT_INTERP, int status)
__attribute__nonnull__(1);
Expand All @@ -74,27 +83,18 @@ void Parrot_x_force_error_exit(
...)
__attribute__nonnull__(3);

PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void Parrot_x_panic_and_exit(
NULLOK_INTERP,
ARGIN_NULLOK(const char *message),
ARGIN_NULLOK(const char *file),
unsigned int line);

#define ASSERT_ARGS_Parrot_x_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_x_jump_out __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_x_on_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(function))
#define ASSERT_ARGS_Parrot_x_panic_and_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_x_execute_on_exit_handlers \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_x_force_error_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(format))
#define ASSERT_ARGS_Parrot_x_panic_and_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/exit.c */

Expand Down
20 changes: 20 additions & 0 deletions src/call/pcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,26 @@ Parrot_pcc_invoke_from_sig_object(PARROT_INTERP, ARGIN(PMC *sub_obj),

/*
=item C<PMC * Parrot_pcc_new_call_object(PARROT_INTERP)>
Returns a new CallContext object, suitable for making a Sub call.
=cut
*/

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC *
Parrot_pcc_new_call_object(PARROT_INTERP)
{
ASSERT_ARGS(Parrot_pcc_new_call_object)
return Parrot_pmc_new(interp, enum_class_CallContext);
}

/*
=back
=head1 SEE ALSO
Expand Down
21 changes: 21 additions & 0 deletions src/embed/pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,27 @@ Parrot_api_pmc_keep_alive(Parrot_PMC interp_pmc, Parrot_PMC pmc, Parrot_Int aliv

/*
=item C<Parrot_Int Parrot_api_pmc_new_call_object(Parrot_PMC interp_pmc,
Parrot_PMC *cc)>
Create a new CallContext PMC, suitable for invoking a Sub.
=cut
*/

PARROT_API
Parrot_Int
Parrot_api_pmc_new_call_object(Parrot_PMC interp_pmc, ARGOUT(Parrot_PMC *cc))
{
ASSERT_ARGS(Parrot_api_pmc_new_call_object)
EMBED_API_CALLIN(interp_pmc, interp);
*cc = Parrot_pcc_new_call_object(interp);
EMBED_API_CALLOUT(interp_pmc, interp);
}

/*
=back
=cut
Expand Down
14 changes: 8 additions & 6 deletions src/ops/core_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -18404,15 +18404,17 @@ Parrot_addmethod_p_sc_p(opcode_t *cur_opcode, PARROT_INTERP) {

opcode_t *
Parrot_can_i_p_s(opcode_t *cur_opcode, PARROT_INTERP) {
PMC * meth = VTABLE_find_method(interp, PREG(2), SREG(3));
IREG(1) = !PMC_IS_NULL(meth);
PMC * const meth = VTABLE_find_method(interp, PREG(2), SREG(3));

IREG(1) = (!PMC_IS_NULL(meth));
return cur_opcode + 4;
}

opcode_t *
Parrot_can_i_p_sc(opcode_t *cur_opcode, PARROT_INTERP) {
PMC * meth = VTABLE_find_method(interp, PREG(2), SCONST(3));
IREG(1) = !PMC_IS_NULL(meth);
PMC * const meth = VTABLE_find_method(interp, PREG(2), SCONST(3));

IREG(1) = (!PMC_IS_NULL(meth));
return cur_opcode + 4;
}

Expand Down Expand Up @@ -24232,7 +24234,7 @@ Parrot_get_context_p(opcode_t *cur_opcode, PARROT_INTERP) {

opcode_t *
Parrot_new_call_context_p(opcode_t *cur_opcode, PARROT_INTERP) {
PREG(1) = Parrot_pmc_new(interp, enum_class_CallContext);
PREG(1) = Parrot_pcc_new_call_object(interp);
PARROT_GC_WRITE_BARRIER(interp, CURRENT_CONTEXT(interp));
return cur_opcode + 2;
}
Expand Down Expand Up @@ -24451,7 +24453,7 @@ op_lib_t core_op_lib = {
1125, /* op_count */
core_op_info_table, /* op_info_table */
core_op_func_table, /* op_func_table */
get_op /* op_code() */
get_op /* op_code() */
};

/*
Expand Down
2 changes: 1 addition & 1 deletion src/ops/experimental.ops
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ op get_context(out PMC) {
=cut

op new_call_context(out PMC) {
$1 = Parrot_pmc_new(interp, enum_class_CallContext);
$1 = Parrot_pcc_new_call_object(interp);
}

=item B<invokecc>(invar PMC, invar PMC)
Expand Down

0 comments on commit 0ebe739

Please sign in to comment.