# New Ticket Created by Bram Geron # Please include the string: [perl #46593] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=46593 >
I think attached patch clarifies parameter passing a little. Non-comment changes: * enum call_state_mode becomes typedef'd call_state_mode * call_state_item.mode becomes type call_state_mode instead of int * call_state_item.sig becomes type Call_bits_enum_t instead of INTVAL include/parrot/inter_call.h | 68 +++++++++++++++++++++++++++----------------- src/inter_call.c | 13 ++++++-- 2 files changed, 52 insertions(+), 29 deletions(-) Cheers, -- Bram Geron | GPG 0xE7B9E65E
diff --git a/include/parrot/inter_call.h b/include/parrot/inter_call.h index f08e225..a16ea02 100644 --- a/include/parrot/inter_call.h +++ b/include/parrot/inter_call.h @@ -16,38 +16,54 @@ #ifndef PARROT_INTER_CALL_H_GUARD #define PARROT_INTER_CALL_H_GUARD -enum call_state_mode { - /* arg processing states - * <src>_<dest> sd nibbles */ - - CALL_STATE_SIG = 0x100, /* runops, nci */ - CALL_STATE_OP = 0x200, /* get_, set_ ops */ - CALL_S_D_MASK = 0x300, /* src/dest mask */ - - CALL_STATE_FLATTEN = 0x400 /* flatten src */ - -}; +typedef enum call_state_mode { + /* argument fetching/putting modes */ + CALL_STATE_SIG = 0x100, /* runops, nci. In case we're interfacing with + C and va_lists. */ + CALL_STATE_OP = 0x200, /* get_, set_ ops. In case we're interfacing + with Parrot code and get the signature from + call_state_item.u.op. */ + CALL_S_D_MASK = 0x300, /* src/dest mask */ + + /* whether we are busy in a :flat argument */ + CALL_STATE_FLATTEN = 0x400 +} call_state_mode; typedef struct call_state_item { - int mode; /* from_sig, from_set_ops, flatten ...*/ + /* We have one call_state_item for both the caller (source, + arguments/returns) and the callee (destination, parameters/results). */ + call_state_mode mode; /* this specifies + - where we get our arguments from / where we put + our parameters (from C code or from set_*,get_*) + - if we're in the middle of a :flat */ + union { - struct { - void *ap; /* a ptr to va_list */ - const char *sig; + struct { /* In case the caller (or callee? FIXME) + is C code: */ + void *ap; /* a ptr to va_list */ + const char *sig; /* a C string describing the type of each argument */ } sig; - struct { - opcode_t *pc; - PMC *signature; + + struct { /* In case the caller/callee was Parrot code: */ + opcode_t *pc; /* array of 'indexes' for each argument: + - in case it's about a constant, the constant number + - in case it's about a register, the register number */ + PMC *signature; /* a PMC array holding a Call_bits_enum_t + signature for each argument */ } op; } u; - parrot_context_t *ctx; - INTVAL used; - INTVAL i; - INTVAL n; - INTVAL sig; - PMC *slurp; - INTVAL slurp_i; - INTVAL slurp_n; + + parrot_context_t *ctx; /* the context where we get the args from / put the params in */ + INTVAL used; /* src: whether this argument has been consumed already (or: whether the previous arg has already been consumed?) */ + INTVAL i; /* number of args/params already consumed / filled in */ + INTVAL n; /* number of args/params we are supposed to match. may include :slurpys and :flats */ + Call_bits_enum_t sig; /* type of current arg/param (counting from 1, the i'th) */ + + /* We might encounter a :flat. */ + /* FIXME bgeron: is this used for :slurpys? I can't find a reference in slurpy-filling code. */ + PMC *slurp; /* PMC in which to put the args we slurp up / from where to flatten */ + INTVAL slurp_i; /* index of :flat/:slurpy arg/param we are trying to match */ + INTVAL slurp_n; /* number of :flat/:slurpy args/params we are supposed to match */ } call_state_item; typedef struct call_state { diff --git a/src/inter_call.c b/src/inter_call.c index 9c522d8..0e9920e 100644 --- a/src/inter_call.c +++ b/src/inter_call.c @@ -329,7 +329,9 @@ start_flatten(PARROT_INTERP, NOTNULL(call_state *st), NOTNULL(PMC *p_arg)) st->n_actual_args += st->src.slurp_n - 1; } - +/* Calculate what type of argument/parameter we get next + * (the index has already been increased by now) + */ static void next_arg_sig(NOTNULL(call_state_item *sti)) { @@ -357,6 +359,8 @@ next_arg_sig(NOTNULL(call_state_item *sti)) } } +/* Fetch an argument from C code + */ static int fetch_arg_sig(PARROT_INTERP, NOTNULL(call_state *st)) { @@ -401,7 +405,8 @@ fetch_arg_sig(PARROT_INTERP, NOTNULL(call_state *st)) return 1; } - +/* Fetch an argument from a Parrot_Context + */ static int fetch_arg_op(PARROT_INTERP, NOTNULL(call_state *st)) { @@ -448,6 +453,8 @@ fetch_arg_op(PARROT_INTERP, NOTNULL(call_state *st)) return 1; } +/* Fetch a new argument. + */ PARROT_API int Parrot_fetch_arg(PARROT_INTERP, NOTNULL(call_state *st)) @@ -460,7 +467,7 @@ Parrot_fetch_arg(PARROT_INTERP, NOTNULL(call_state *st)) next_arg_sig(&st->src); - /* check if we're at a :flat argument */ + /* check if we're supposed to continue a :flat argument */ if (st->src.mode & CALL_STATE_FLATTEN) { PMC *elem; PARROT_ASSERT(st->src.slurp_i < st->src.slurp_n);