Skip to content

Commit

Permalink
Provide dispatcher-drop-arg syscall
Browse files Browse the repository at this point in the history
And fix up passing along derived captures as we delegate between
dispatchers.
  • Loading branch information
jnthn committed May 22, 2020
1 parent 4e44e64 commit d33aa6c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/core/callstack.h
Expand Up @@ -141,15 +141,18 @@ struct MVMCallStackDispatchRecord {
/* Commonalities of all records. */
MVMCallStackRecord common;

/* The argument capture going into the dispatch (always an object, but
* stored this way to let this address be safely used as an argument
* buffer. */
MVMRegister initial_capture;
/* The argument capture that started out this dispatch. */
MVMObject *initial_capture;

/* An MVMArray of derived captures, produced during the dispatch
* process. */
MVMObject *derived_captures;

/* Register holding the current capture. Starts out as the initial capture
* and then, in the case we delegate, becomes the one sent to the delegate
* dispatcher. */
MVMRegister current_capture;

/* The outcome of the dispatch. */
MVMDispProgramOutcome outcome;
/* TODO */
Expand Down
7 changes: 4 additions & 3 deletions src/disp/program.c
Expand Up @@ -4,9 +4,10 @@
static void run_dispatch(MVMThreadContext *tc, MVMCallStackDispatchRecord *record,
MVMDispDefinition *disp, MVMObject *capture, MVMuint32 *thunked) {
MVMCallsite *disp_callsite = MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG);
record->current_capture.o = capture;
MVMArgs dispatch_args = {
.callsite = disp_callsite,
.source = &(record->initial_capture),
.source = &(record->current_capture),
.map = MVM_args_identity_map(tc, disp_callsite)
};
MVMObject *dispatch = disp->dispatch;
Expand All @@ -32,7 +33,7 @@ void MVM_disp_program_run_dispatch(MVMThreadContext *tc, MVMDispDefinition *disp
/* Push a dispatch recording frame onto the callstack; this is how we'll
* keep track of the current recording state. */
MVMCallStackDispatchRecord *record = MVM_callstack_allocate_dispatch_record(tc);
record->initial_capture.o = capture;
record->initial_capture = capture;
record->derived_captures = NULL;
run_dispatch(tc, record, disp, capture, NULL);
}
Expand All @@ -41,7 +42,7 @@ void MVM_disp_program_run_dispatch(MVMThreadContext *tc, MVMDispDefinition *disp
* being recorded dispatch program. */
static void ensure_known_capture(MVMThreadContext *tc, MVMCallStackDispatchRecord *record,
MVMObject *capture) {
if (capture != record->initial_capture.o) {
if (capture != record->initial_capture) {
int found = 0;
if (record->derived_captures) {
MVMint64 elems = MVM_repr_elems(tc, record->derived_captures);
Expand Down
20 changes: 20 additions & 0 deletions src/disp/syscall.c
Expand Up @@ -45,6 +45,25 @@ static MVMDispSysCall dispatcher_delegate = {
.hash_handle = EMPTY_HASH_HANDLE
};

/* dispatcher-drop-arg */
static void dispatcher_drop_arg_impl(MVMThreadContext *tc, MVMArgs arg_info) {
MVMArgProcContext arg_ctx;
MVM_args_proc_setup(tc, &arg_ctx, arg_info);
MVMObject *capture = MVM_args_get_required_pos_obj(tc, &arg_ctx, 0);
MVMint64 idx = MVM_args_get_required_pos_int(tc, &arg_ctx, 1);
MVMObject *derived = MVM_disp_program_record_capture_drop_arg(tc, capture, (MVMuint32)idx);
MVM_args_set_result_obj(tc, derived, MVM_RETURN_CURRENT_FRAME);
}
static MVMDispSysCall dispatcher_drop_arg = {
.c_name = "dispatcher-drop-arg",
.implementation = dispatcher_drop_arg_impl,
.min_args = 2,
.max_args = 2,
.expected_kinds = { MVM_CALLSITE_ARG_OBJ, MVM_CALLSITE_ARG_INT },
.expected_reprs = { MVM_REPR_ID_MVMCapture, 0 },
.expected_concrete = { 1, 1 },
.hash_handle = EMPTY_HASH_HANDLE
};

/* Add all of the syscalls into the hash. */
MVM_STATIC_INLINE void add_to_hash(MVMThreadContext *tc, MVMDispSysCall *syscall) {
Expand All @@ -63,6 +82,7 @@ void MVM_disp_syscall_setup(MVMThreadContext *tc) {
MVM_gc_allocate_gen2_default_set(tc);
add_to_hash(tc, &dispatcher_register);
add_to_hash(tc, &dispatcher_delegate);
add_to_hash(tc, &dispatcher_drop_arg);
MVM_gc_allocate_gen2_default_clear(tc);
}

Expand Down

0 comments on commit d33aa6c

Please sign in to comment.