Skip to content

Commit

Permalink
Consistify common callsites
Browse files Browse the repository at this point in the history
Since the names didn't really reflect their usages in various cases,
when they had taken on more general meanings. Also, we were failing to
intern some of them at startup.
  • Loading branch information
jnthn committed Jun 15, 2020
1 parent 13c24f6 commit 602d6b7
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 117 deletions.
10 changes: 5 additions & 5 deletions src/6model/6model.c
Expand Up @@ -45,7 +45,7 @@ typedef struct {
static void die_over_missing_method(MVMThreadContext *tc, MVMObject *obj, MVMString *name) {
MVMObject *handler = MVM_hll_current(tc)->method_not_found_error;
if (!MVM_is_null(tc, handler)) {
MVMCallsite *methnotfound_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_METH_NOT_FOUND);
MVMCallsite *methnotfound_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_STR);
handler = MVM_frame_find_invokee(tc, handler, NULL);
MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, methnotfound_callsite);
tc->cur_frame->args[0].o = obj;
Expand Down Expand Up @@ -148,7 +148,7 @@ void MVM_6model_find_method(MVMThreadContext *tc, MVMObject *obj, MVMString *nam

/* Set up the call, using the result register as the target. */
code = MVM_frame_find_invokee(tc, find_method, NULL);
findmeth_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_FIND_METHOD);
findmeth_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ_STR);
MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, findmeth_callsite);
{
FindMethodSRData *fm = MVM_malloc(sizeof(FindMethodSRData));
Expand Down Expand Up @@ -270,7 +270,7 @@ void MVM_6model_can_method(MVMThreadContext *tc, MVMObject *obj, MVMString *name
/* Set up the call, using the result register as the target. A little bad
* as we're really talking about */
code = MVM_frame_find_invokee(tc, find_method, NULL);
findmeth_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_FIND_METHOD);
findmeth_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ_STR);
MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, findmeth_callsite);
MVM_frame_special_return(tc, tc->cur_frame, late_bound_can_return, NULL, res, NULL);
tc->cur_frame->args[0].o = HOW;
Expand All @@ -293,7 +293,7 @@ static void do_accepts_type_check(MVMThreadContext *tc, MVMObject *obj, MVMObjec
if (!MVM_is_null(tc, meth)) {
/* Set up the call, using the result register as the target. */
MVMObject *code = MVM_frame_find_invokee(tc, meth, NULL);
MVMCallsite *typecheck_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TYPECHECK);
MVMCallsite *typecheck_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ_OBJ);

MVM_args_setup_thunk(tc, res, MVM_RETURN_INT, typecheck_callsite);
tc->cur_frame->args[0].o = HOW;
Expand Down Expand Up @@ -376,7 +376,7 @@ void MVM_6model_istype(MVMThreadContext *tc, MVMObject *obj, MVMObject *type, MV
if (!MVM_is_null(tc, meth)) {
/* Set up the call, using the result register as the target. */
MVMObject *code = MVM_frame_find_invokee(tc, meth, NULL);
MVMCallsite *typecheck_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TYPECHECK);
MVMCallsite *typecheck_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ_OBJ);

MVM_args_setup_thunk(tc, res, MVM_RETURN_INT, typecheck_callsite);
tc->cur_frame->args[0].o = HOW;
Expand Down
12 changes: 6 additions & 6 deletions src/6model/containers.c
Expand Up @@ -22,7 +22,7 @@ typedef struct {
static void code_pair_fetch_internal(MVMThreadContext *tc, MVMObject *cont, MVMRegister *res, MVMReturnType res_type) {
CodePairContData *data = (CodePairContData *)STABLE(cont)->container_data;
MVMObject *code = MVM_frame_find_invokee(tc, data->fetch_code, NULL);
MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG);
MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ);
MVM_args_setup_thunk(tc, res, res_type, inv_arg_callsite);
tc->cur_frame->args[0].o = cont;
STABLE(code)->invoke(tc, code, inv_arg_callsite, tc->cur_frame->args);
Expand Down Expand Up @@ -56,7 +56,7 @@ static void code_pair_store_internal(MVMThreadContext *tc, MVMObject *cont, MVMR
static void code_pair_store(MVMThreadContext *tc, MVMObject *cont, MVMObject *obj) {
MVMRegister r;
r.o = obj;
code_pair_store_internal(tc, cont, r, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ));
code_pair_store_internal(tc, cont, r, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ));
}

static void code_pair_store_i(MVMThreadContext *tc, MVMObject *cont, MVMint64 value) {
Expand Down Expand Up @@ -226,7 +226,7 @@ static void value_desc_cont_fetch_s(MVMThreadContext *tc, MVMObject *cont, MVMRe
static void value_desc_cont_store(MVMThreadContext *tc, MVMObject *cont, MVMObject *value) {
MVMValueDescContainer *data = (MVMValueDescContainer *)STABLE(cont)->container_data;
MVMObject *code = MVM_frame_find_invokee(tc, data->store, NULL);
MVMCallsite *cs = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ);
MVMCallsite *cs = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ);
MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, cs);
tc->cur_frame->args[0].o = cont;
tc->cur_frame->args[1].o = value;
Expand Down Expand Up @@ -260,7 +260,7 @@ static void value_desc_cont_store_s(MVMThreadContext *tc, MVMObject *cont, MVMSt
static void value_desc_cont_store_unchecked(MVMThreadContext *tc, MVMObject *cont, MVMObject *value) {
MVMValueDescContainer *data = (MVMValueDescContainer *)STABLE(cont)->container_data;
MVMObject *code = MVM_frame_find_invokee(tc, data->store_unchecked, NULL);
MVMCallsite *cs = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ);
MVMCallsite *cs = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ);
MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, cs);
tc->cur_frame->args[0].o = cont;
tc->cur_frame->args[1].o = value;
Expand Down Expand Up @@ -335,7 +335,7 @@ static void value_desc_cont_cas(MVMThreadContext *tc, MVMObject *cont,
MVMRegister *result) {
MVMValueDescContainer *data = (MVMValueDescContainer *)STABLE(cont)->container_data;
MVMObject *code = MVM_frame_find_invokee(tc, data->cas, NULL);
MVMCallsite *cs = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TYPECHECK);
MVMCallsite *cs = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ_OBJ);
MVM_args_setup_thunk(tc, result, MVM_RETURN_OBJ, cs);
tc->cur_frame->args[0].o = cont;
tc->cur_frame->args[1].o = expected;
Expand All @@ -352,7 +352,7 @@ static MVMObject * value_desc_cont_atomic_load(MVMThreadContext *tc, MVMObject *
void value_desc_cont_atomic_store(MVMThreadContext *tc, MVMObject *cont, MVMObject *value) {
MVMValueDescContainer *data = (MVMValueDescContainer *)STABLE(cont)->container_data;
MVMObject *code = MVM_frame_find_invokee(tc, data->atomic_store, NULL);
MVMCallsite *cs = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ);
MVMCallsite *cs = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ);
MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, cs);
tc->cur_frame->args[0].o = cont;
tc->cur_frame->args[1].o = value;
Expand Down
4 changes: 2 additions & 2 deletions src/6model/parametric.c
Expand Up @@ -109,10 +109,10 @@ void MVM_6model_parametric_parameterize(MVMThreadContext *tc, MVMObject *type, M
prd->result = result;
MVM_frame_special_return(tc, tc->cur_frame, finish_parameterizing, NULL,
prd, mark_parameterize_sr_data);
MVM_args_setup_thunk(tc, result, MVM_RETURN_OBJ, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ));
MVM_args_setup_thunk(tc, result, MVM_RETURN_OBJ, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ));
tc->cur_frame->args[0].o = st->WHAT;
tc->cur_frame->args[1].o = params;
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ), tc->cur_frame->args);
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ_OBJ), tc->cur_frame->args);
}

/* Try to find an existing parameterization of the specified type and
Expand Down
2 changes: 1 addition & 1 deletion src/core/args.c
Expand Up @@ -1242,7 +1242,7 @@ void MVM_args_bind_failed(MVMThreadContext *tc) {
MVM_exception_throw_adhoc(tc, "Bind error occurred, but HLL has no handler");
bind_error = MVM_frame_find_invokee(tc, bind_error, NULL);
res = MVM_calloc(1, sizeof(MVMRegister));
inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG);
inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ);
MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, inv_arg_callsite);
MVM_frame_special_return(tc, cur_frame, bind_error_return, bind_error_unwind, res, mark_sr_data);
cur_frame->args[0].o = cc_obj;
Expand Down
96 changes: 48 additions & 48 deletions src/core/callsite.c
Expand Up @@ -15,28 +15,14 @@ static MVMint32 callsites_equal(MVMThreadContext *tc, MVMCallsite *cs1, MVMCalls
return 1;
}

static MVMCallsite null_args_callsite = { NULL, 0, 0, 0, 0, 0, 0, 0 };
static MVMCallsite zero_arity_callsite = { NULL, 0, 0, 0, 0, 0, 0, 0 };

static MVMCallsiteEntry obj_arg_flags[] = { MVM_CALLSITE_ARG_OBJ };
static MVMCallsite inv_arg_callsite = { obj_arg_flags, 1, 1, 1, 0, 0, 0, 0 };
static MVMCallsite obj_callsite = { obj_arg_flags, 1, 1, 1, 0, 0, 0, 0 };

static MVMCallsiteEntry two_obj_arg_flags[] = { MVM_CALLSITE_ARG_OBJ,
static MVMCallsiteEntry obj_obj_arg_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ };
static MVMCallsite two_args_callsite = { two_obj_arg_flags, 2, 2, 2, 0, 0, NULL, NULL };

static MVMCallsiteEntry mnfe_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_STR };
static MVMCallsite methnotfound_callsite = { mnfe_flags, 2, 2, 2, 0, 0, NULL, NULL };

static MVMCallsiteEntry fm_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_STR };
static MVMCallsite findmeth_callsite = { fm_flags, 3, 3, 3, 0, 0, NULL, NULL };

static MVMCallsiteEntry tc_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ };
static MVMCallsite typecheck_callsite = { tc_flags, 3, 3, 3, 0, 0, NULL, NULL };
static MVMCallsite obj_obj_callsite = { obj_obj_arg_flags, 2, 2, 2, 0, 0, NULL, NULL };

static MVMCallsiteEntry obj_int_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_INT };
Expand All @@ -46,50 +32,58 @@ static MVMCallsiteEntry obj_num_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_NUM };
static MVMCallsite obj_num_callsite = { obj_num_flags, 2, 2, 2, 0, 0, NULL, NULL };

static MVMCallsiteEntry obj_str_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_STR };
static MVMCallsite obj_str_callsite = { obj_str_flags, 2, 2, 2, 0, 0, NULL, NULL };
static MVMCallsiteEntry obj_str_arg_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_STR };
static MVMCallsite obj_str_callsite = { obj_str_arg_flags, 2, 2, 2, 0, 0, NULL, NULL };

static MVMCallsiteEntry int_int_arg_flags[] = { MVM_CALLSITE_ARG_INT, MVM_CALLSITE_ARG_INT };
static MVMCallsite int_int_arg_callsite = { int_int_arg_flags, 2, 2, 2, 0, 0, 0, 0 };
static MVMCallsite int_int_callsite = { int_int_arg_flags, 2, 2, 2, 0, 0, 0, 0 };

static MVMCallsiteEntry obj_obj_str_arg_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_STR };
static MVMCallsite obj_obj_str_callsite = { obj_obj_str_arg_flags, 3, 3, 3, 0, 0, NULL, NULL };

static MVMCallsiteEntry obj_obj_obj_arg_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ };
static MVMCallsite obj_obj_obj_callsite = { obj_obj_obj_arg_flags, 3, 3, 3, 0, 0, NULL, NULL };

MVM_PUBLIC MVMCallsite *MVM_callsite_get_common(MVMThreadContext *tc, MVMCommonCallsiteID id) {
switch (id) {
case MVM_CALLSITE_ID_NULL_ARGS:
return &null_args_callsite;
case MVM_CALLSITE_ID_INV_ARG:
return &inv_arg_callsite;
case MVM_CALLSITE_ID_TWO_OBJ:
return &two_args_callsite;
case MVM_CALLSITE_ID_METH_NOT_FOUND:
return &methnotfound_callsite;
case MVM_CALLSITE_ID_FIND_METHOD:
return &findmeth_callsite;
case MVM_CALLSITE_ID_TYPECHECK:
return &typecheck_callsite;
case MVM_CALLSITE_ID_ZERO_ARITY:
return &zero_arity_callsite;
case MVM_CALLSITE_ID_OBJ:
return &obj_callsite;
case MVM_CALLSITE_ID_OBJ_OBJ:
return &obj_obj_callsite;
case MVM_CALLSITE_ID_OBJ_INT:
return &obj_int_callsite;
case MVM_CALLSITE_ID_OBJ_NUM:
return &obj_num_callsite;
case MVM_CALLSITE_ID_OBJ_STR:
return &obj_str_callsite;
case MVM_CALLSITE_ID_INT_INT:
return &int_int_arg_callsite;
return &int_int_callsite;
case MVM_CALLSITE_ID_OBJ_OBJ_STR:
return &obj_obj_str_callsite;
case MVM_CALLSITE_ID_OBJ_OBJ_OBJ:
return &obj_obj_obj_callsite;
default:
MVM_exception_throw_adhoc(tc, "get_common_callsite: id %d unknown", id);
}
}

int MVM_callsite_is_common(MVMCallsite *cs) {
return cs == &null_args_callsite ||
cs == &inv_arg_callsite ||
cs == &two_args_callsite ||
cs == &methnotfound_callsite ||
cs == &findmeth_callsite ||
cs == &typecheck_callsite ||
return cs == &zero_arity_callsite ||
cs == &obj_callsite ||
cs == &obj_obj_callsite ||
cs == &obj_str_callsite ||
cs == &obj_int_callsite ||
cs == &obj_num_callsite ||
cs == &obj_str_callsite;
cs == &int_int_callsite ||
cs == &obj_obj_str_callsite ||
cs == &obj_obj_obj_callsite;
}

void MVM_callsite_destroy(MVMCallsite *cs) {
Expand Down Expand Up @@ -145,17 +139,23 @@ MVMCallsite *MVM_callsite_copy(MVMThreadContext *tc, const MVMCallsite *cs) {
void MVM_callsite_initialize_common(MVMThreadContext *tc) {
MVMCallsite *ptr;

ptr = &inv_arg_callsite;
ptr = &zero_arity_callsite;
MVM_callsite_try_intern(tc, &ptr);
ptr = &obj_callsite;
MVM_callsite_try_intern(tc, &ptr);
ptr = &obj_obj_callsite;
MVM_callsite_try_intern(tc, &ptr);
ptr = &obj_int_callsite;
MVM_callsite_try_intern(tc, &ptr);
ptr = &null_args_callsite;
ptr = &obj_num_callsite;
MVM_callsite_try_intern(tc, &ptr);
ptr = &methnotfound_callsite;
ptr = &obj_str_callsite;
MVM_callsite_try_intern(tc, &ptr);
ptr = &two_args_callsite;
ptr = &int_int_callsite;
MVM_callsite_try_intern(tc, &ptr);
ptr = &findmeth_callsite;
ptr = &obj_obj_str_callsite;
MVM_callsite_try_intern(tc, &ptr);
ptr = &typecheck_callsite;
ptr = &obj_obj_obj_callsite;
MVM_callsite_try_intern(tc, &ptr);
}

Expand Down
36 changes: 6 additions & 30 deletions src/core/callsite.h
Expand Up @@ -27,41 +27,17 @@ typedef enum {
MVM_CALLSITE_ARG_FLAT_NAMED = 128
} MVMCallsiteFlags;

/* Callsites that are used within the VM. */
typedef enum {
/* Zero argument callsite. */
MVM_CALLSITE_ID_NULL_ARGS,

/* Dummy, invocant-arg callsite. Taken from coerce.c;
* OBJ */
MVM_CALLSITE_ID_INV_ARG,

/* Callsite for container store. Taken from containers.c;
* OBJ, OBJ */
MVM_CALLSITE_ID_TWO_OBJ,

/* Callsite for method not found errors. Taken from 6model.c;
* OBJ, STR */
MVM_CALLSITE_ID_METH_NOT_FOUND,

/* Callsite for finding methods. Taken from 6model.c;
* OBJ, OBJ, STR */
MVM_CALLSITE_ID_FIND_METHOD,

/* Callsite for typechecks. Taken from 6model.c;
* OBJ, OBJ, OBJ */
MVM_CALLSITE_ID_TYPECHECK,

/* Callsite OBJ, INT */
MVM_CALLSITE_ID_ZERO_ARITY,
MVM_CALLSITE_ID_OBJ,
MVM_CALLSITE_ID_OBJ_OBJ,
MVM_CALLSITE_ID_OBJ_INT,

/* Callsite OBJ, INT */
MVM_CALLSITE_ID_OBJ_NUM,

/* Callsite OBJ, STR */
MVM_CALLSITE_ID_OBJ_STR,

/* Callsite INT, INT */
MVM_CALLSITE_ID_INT_INT,
MVM_CALLSITE_ID_OBJ_OBJ_STR,
MVM_CALLSITE_ID_OBJ_OBJ_OBJ,
} MVMCommonCallsiteID;

/* A callsite entry is just one of the above flags. */
Expand Down
8 changes: 4 additions & 4 deletions src/core/coerce.c
Expand Up @@ -34,7 +34,7 @@ void MVM_coerce_istrue(MVMThreadContext *tc, MVMObject *obj, MVMRegister *res_re
switch (bs == NULL ? MVM_BOOL_MODE_NOT_TYPE_OBJECT : bs->mode) {
case MVM_BOOL_MODE_CALL_METHOD: {
MVMObject *code = MVM_frame_find_invokee(tc, bs->method, NULL);
MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG);
MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ);
if (res_reg) {
/* We need to do the invocation, and set this register
* the result. Then we just do the call. For the flip
Expand Down Expand Up @@ -301,7 +301,7 @@ void MVM_coerce_smart_stringify(MVMThreadContext *tc, MVMObject *obj, MVMRegiste
/* We need to do the invocation; just set it up with our result reg as
* the one for the call. */
MVMObject *code = MVM_frame_find_invokee(tc, strmeth, NULL);
MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG);
MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ);

MVM_args_setup_thunk(tc, res_reg, MVM_RETURN_STR, inv_arg_callsite);
tc->cur_frame->args[0].o = obj;
Expand Down Expand Up @@ -350,7 +350,7 @@ void MVM_coerce_smart_numify(MVMThreadContext *tc, MVMObject *obj, MVMRegister *
/* We need to do the invocation; just set it up with our result reg as
* the one for the call. */
MVMObject *code = MVM_frame_find_invokee(tc, nummeth, NULL);
MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG);
MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ);

MVM_args_setup_thunk(tc, res_reg, MVM_RETURN_NUM, inv_arg_callsite);
tc->cur_frame->args[0].o = obj;
Expand Down Expand Up @@ -397,7 +397,7 @@ void MVM_coerce_smart_intify(MVMThreadContext *tc, MVMObject *obj, MVMRegister *
/* We need to do the invocation; just set it up with our result reg as
* the one for the call. */
MVMObject *code = MVM_frame_find_invokee(tc, intmeth, NULL);
MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG);
MVMCallsite *inv_arg_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_OBJ);

MVM_args_setup_thunk(tc, res_reg, MVM_RETURN_INT, inv_arg_callsite);
tc->cur_frame->args[0].o = obj;
Expand Down

0 comments on commit 602d6b7

Please sign in to comment.