Skip to content

Commit

Permalink
Merge pull request #1566 from MasterDuke17/add_some_context_to_captur…
Browse files Browse the repository at this point in the history
…e_arg_exceptions
  • Loading branch information
MasterDuke17 committed Oct 19, 2021
2 parents 4310520 + d12d6f3 commit 7b5b6ba
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/6model/reprs/MVMCapture.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,33 +189,33 @@ static MVMint64 flag_to_spec(MVMint64 flag) {
MVMint64 MVM_capture_arg_pos_primspec(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32 idx) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->num_pos)
MVM_exception_throw_adhoc(tc, "Capture argument index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u) for captureposprimspec", idx, capture->body.callsite->num_pos);
return flag_to_spec(capture->body.callsite->arg_flags[idx]);
}

/* Get the primitive value kind for an argument. */
MVMint64 MVM_capture_arg_primspec(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32 idx) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->flag_count)
MVM_exception_throw_adhoc(tc, "Capture argument index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u)", idx, capture->body.callsite->flag_count);
return flag_to_spec(capture->body.callsite->arg_flags[idx]);
}

/* Access a positional object argument of an argument capture object. */
MVMObject * MVM_capture_arg_pos_o(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32 idx) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->num_pos)
MVM_exception_throw_adhoc(tc, "Capture argument index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u) for captureposarg", idx, capture->body.callsite->num_pos);
if ((capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK) != MVM_CALLSITE_ARG_OBJ)
MVM_exception_throw_adhoc(tc, "Capture argument is not an object argument");
MVM_exception_throw_adhoc(tc, "Capture argument is not an object argument for captureposarg");
return capture->body.args[idx].o;
}

/* Access an object argument of an argument capture object. */
MVMObject * MVM_capture_arg_o(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32 idx) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->flag_count)
MVM_exception_throw_adhoc(tc, "Capture argument index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u)", idx, capture->body.callsite->flag_count);
if ((capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK) != MVM_CALLSITE_ARG_OBJ)
MVM_exception_throw_adhoc(tc, "Capture argument is not an object argument");
return capture->body.args[idx].o;
Expand All @@ -225,29 +225,29 @@ MVMObject * MVM_capture_arg_o(MVMThreadContext *tc, MVMObject *capture_obj, MVMu
MVMString * MVM_capture_arg_pos_s(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32 idx) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->num_pos)
MVM_exception_throw_adhoc(tc, "Capture argument index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u) for captureposarg_s", idx, capture->body.callsite->num_pos);
if ((capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK) != MVM_CALLSITE_ARG_STR)
MVM_exception_throw_adhoc(tc, "Capture argument is not a string argument");
MVM_exception_throw_adhoc(tc, "Capture argument is not a string argument for captureposarg_s");
return capture->body.args[idx].s;
}

/* Access a positional integer argument of an argument capture object. */
MVMint64 MVM_capture_arg_pos_i(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32 idx) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->num_pos)
MVM_exception_throw_adhoc(tc, "Capture argument index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u) for captureposarg_i", idx, capture->body.callsite->num_pos);
if ((capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK) != MVM_CALLSITE_ARG_INT)
MVM_exception_throw_adhoc(tc, "Capture argument is not an integer argument");
MVM_exception_throw_adhoc(tc, "Capture argument is not an integer argument for captureposarg_i");
return capture->body.args[idx].i64;
}

/* Access a positional number argument of an argument capture object. */
MVMnum64 MVM_capture_arg_pos_n(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32 idx) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->num_pos)
MVM_exception_throw_adhoc(tc, "Capture argument index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u) for captureposarg_n", idx, capture->body.callsite->num_pos);
if ((capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK) != MVM_CALLSITE_ARG_NUM)
MVM_exception_throw_adhoc(tc, "Capture argument is not a number argument");
MVM_exception_throw_adhoc(tc, "Capture argument is not a number argument for captureposarg_n");
return capture->body.args[idx].n64;
}

Expand All @@ -256,7 +256,7 @@ void MVM_capture_arg_pos(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32
MVMRegister *arg_out, MVMCallsiteFlags *arg_type_out) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->num_pos)
MVM_exception_throw_adhoc(tc, "Capture argument index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u)", idx, capture->body.callsite->num_pos);
*arg_out = capture->body.args[idx];
*arg_type_out = capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK;
}
Expand All @@ -266,7 +266,7 @@ void MVM_capture_arg(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32 idx
MVMRegister *arg_out, MVMCallsiteFlags *arg_type_out) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->flag_count)
MVM_exception_throw_adhoc(tc, "Capture argument index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..^%u)", idx, capture->body.callsite->flag_count);
*arg_out = capture->body.args[idx];
*arg_type_out = capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK;
}
Expand Down Expand Up @@ -326,7 +326,7 @@ void MVM_capture_arg_by_flag_index(MVMThreadContext *tc, MVMObject *capture_obj,
MVMuint32 idx, MVMRegister *arg_out, MVMCallsiteFlags *arg_type_out) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx >= capture->body.callsite->flag_count)
MVM_exception_throw_adhoc(tc, "Capture argument flag index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument flag index (%u) out of range (0..^%u)", idx, capture->body.callsite->flag_count);
*arg_out = capture->body.args[idx];
*arg_type_out = capture->body.callsite->arg_flags[idx] & MVM_CALLSITE_ARG_TYPE_MASK;
}
Expand All @@ -342,7 +342,7 @@ MVMint64 MVM_capture_is_literal_arg(MVMThreadContext *tc, MVMObject *capture_obj
MVMObject * MVM_capture_drop_args(MVMThreadContext *tc, MVMObject *capture_obj, MVMuint32 idx, MVMuint32 count) {
MVMCapture *capture = validate_capture(tc, capture_obj);
if (idx + count > capture->body.callsite->num_pos)
MVM_exception_throw_adhoc(tc, "Capture argument index out of range");
MVM_exception_throw_adhoc(tc, "Capture argument index (%u) out of range (0..%u)", idx + count, capture->body.callsite->num_pos);

/* Allocate a new capture before we begin; this is the only GC allocation
* we do. */
Expand Down

0 comments on commit 7b5b6ba

Please sign in to comment.