<commit_before>/*
Copyright (C) 2001-2003, The Perl Foundation.
$Id$

=head1 NAME

src/inter_call.c - Parrot Interpreter - Argument passing code

=head1 DESCRIPTION

Functions in this file handle argument/return value passing to and from
subroutines.

=head2 Functions

=over 4

=cut

*/


#include <assert.h>
#include "parrot/parrot.h"
#include "parrot/oplib/ops.h"
#include "inter_call.str"


#define SAVE_OFF_REGS(orig, next, save) \
        save.bp = orig.bp;\
        save.bp_ps = orig.bp_ps;\
        orig.bp = next.bp;\
        orig.bp_ps = next.bp_ps;

#define RESTORE_REGS(orig, save) \
        orig.bp = save.bp;\
        orig.bp_ps = save.bp_ps;


static int next_arg(Interp *, struct call_state_item *st);
static void next_arg_sig(Interp *interp, struct call_state_item *st);
static int set_retval_util(Parrot_Interp interp, const char *sig, parrot_context_t *ctx,
        struct call_state *st);

/*

=item C<int Parrot_init_arg_nci(Interp *, struct call_state *st, const char *sig)>

Initialize the argument passing state C<call_state> for the given NCI signature.

=item C<int Parrot_init_ret_nci(Interp *, struct call_state *st, const char *sig)>

Initialize the return value passing state C<call_state> for the given NCI signature.

=cut

*/

int
Parrot_init_arg_nci(Interp *interp, struct call_state *st, const char *sig)
{
    Parrot_init_arg_op(interp, CONTEXT(interp->ctx), interp->current_args, &st->src);
    Parrot_init_arg_sig(interp, CONTEXT(interp->ctx), sig, NULL, &st->dest);
    return 1;
}

int
Parrot_init_ret_nci(Interp *interp, struct call_state *st, const char *sig)
{
    struct Parrot_Context *ctx = CONTEXT(interp->ctx);
    PMC *current_cont = ctx->current_cont;
    /*
     * if this NCI call was a taicall, return results to caller's get_results
     * this also means that we pass the caller's register base pointer
     */
    if (SUB_FLAG_TAILCALL_ISSET(current_cont)) {
        ctx = PMC_cont(current_cont)->to_ctx;
    }

    /* TODO simplify all */
    Parrot_init_arg_sig(interp, CONTEXT(interp->ctx), sig, NULL, &st->src);
    Parrot_init_arg_op(interp, ctx, ctx->current_results, &st->dest);
    return 1;
}

/*
int
=item C<Parrot_init_arg_indexes_and_sig_pmc(Interp *interp, parrot_context_t *ctx,
        opcode_t *indexes, PMC* sig_pmc, struct call_state_item *st)>

Initialize argument transfer with given context registers, register indexes, and<commit_msg>Fix to allow calling of non-PCCMETHOD methods using PCCINVOKE.<commit_after>/*
Copyright (C) 2001-2003, The Perl Foundation.
$Id$

=head1 NAME

src/inter_call.c - Parrot Interpreter - Argument passing code

=head1 DESCRIPTION

Functions in this file handle argument/return value passing to and from
subroutines.

=head2 Functions

=over 4

=cut

*/


#include <assert.h>
#include "parrot/parrot.h"
#include "parrot/oplib/ops.h"
#include "inter_call.str"


#define SAVE_OFF_REGS(orig, next, save) \
        save.bp = orig.bp;\
        save.bp_ps = orig.bp_ps;\
        orig.bp = next.bp;\
        orig.bp_ps = next.bp_ps;

#define RESTORE_REGS(orig, save) \
        orig.bp = save.bp;\
        orig.bp_ps = save.bp_ps;


static int next_arg(Interp *, struct call_state_item *st);
static void next_arg_sig(Interp *interp, struct call_state_item *st);
static int set_retval_util(Parrot_Interp interp, const char *sig, parrot_context_t *ctx,
        struct call_state *st);

/*

=item C<int Parrot_init_arg_nci(Interp *, struct call_state *st, const char *sig)>

Initialize the argument passing state C<call_state> for the given NCI signature.

=item C<int Parrot_init_ret_nci(Interp *, struct call_state *st, const char *sig)>

Initialize the return value passing state C<call_state> for the given NCI signature.

=cut

*/

int
Parrot_init_arg_nci(Interp *interp, struct call_state *st, const char *sig)
{
    if (PMC_IS_NULL(interp->args_signature))
        Parrot_init_arg_op(interp, CONTEXT(interp->ctx), interp->current_args, &st->src);
    else
        Parrot_init_arg_indexes_and_sig_pmc(interp, CONTEXT(interp->ctx),
            interp->current_args, interp->args_signature, &st->src);
    Parrot_init_arg_sig(interp, CONTEXT(interp->ctx), sig, NULL, &st->dest);
    return 1;
}

int
Parrot_init_ret_nci(Interp *interp, struct call_state *st, const char *sig)
{
    struct Parrot_Context *ctx = CONTEXT(interp->ctx);
    PMC *current_cont = ctx->current_cont;
    /*
     * if this NCI call was a taicall, return results to caller's get_results
     * this also means that we pass the caller's register base pointer
     */
    if (SUB_FLAG_TAILCALL_ISSET(current_cont)) {
        ctx = PMC_cont(current_cont)->to_ctx;
    }

    /* TODO simplify all */
    Parrot_init_arg_sig(interp, CONTEXT(interp->ctx), sig, NULL, &st->src);
    Parrot_init_arg_op(interp, ctx, ctx->current_results, &st->dest);
    return 1;
}

/*
int
=item C<Parrot_init_arg_indexes_and_sig_pmc(Interp *interp, parrot_context_t *ctx,
        opcode_t *indexes, PMC* sig_pmc, struct call_state_item *st)>

Initialize argument transfer with given context registers, register indexes, and
{'fraction_non_alphanumeric': 0.10918407567993693, 'fraction_numerical': 0.005518328734726055, 'mean_word_length': 4.014822134387352, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '301222', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1808, 'n_words': 473}