Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move dispatcher set/take op into NQP itself.
This will let us do better code-gen with it on the JVM and also ease
keeping it per thread.
  • Loading branch information
jnthn committed Apr 27, 2013
1 parent c7c2297 commit e610165
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/vm/parrot/QAST/Operations.nqp
Expand Up @@ -2130,6 +2130,8 @@ QAST::Operations.add_core_op('getstaticcode', -> $qastcomp, $op {
$op[0]
)))
});
QAST::Operations.add_core_pirop_mapping('setdispatcher', 'nqp_setdispatcher', '0P');
QAST::Operations.add_core_pirop_mapping('takedispatcher', 'nqp_takedispatcher', '0s');

# serialization context related opcodes
QAST::Operations.add_core_pirop_mapping('sha1', 'nqp_sha1', 'Ss');
Expand Down
37 changes: 37 additions & 0 deletions src/vm/parrot/ops/nqp.ops
Expand Up @@ -300,6 +300,10 @@ static INTVAL * nqp_nfa_run(PARROT_INTERP, NFABody *nfa, STRING *target, INTVAL
#define BIND_VAL_STR 3
#define BIND_VAL_OBJ 4

/* The current dispatcher, for the next thing that wants one to take.
* Note, should really be per thread. */
static PMC *current_dispatcher = NULL;

END_OPS_PREAMBLE

/*
Expand Down Expand Up @@ -3120,3 +3124,36 @@ inline op nqp_isstr(out INT, invar PMC) :base_core {
$1 = var->vtable->base_type == enum_class_String ? 1 : 0;
}
}

/*

=item nqp_setdispatcher(in PMC)

Sets the dispatcher that the next thing we call that is interested
in one will take.

=cut

*/
inline op nqp_setdispatcher(in PMC) :base_core {
current_dispatcher = $1;
}


/*

=item nqp_takedispatcher(in STR)

If a disptcher was set, places it into the lexical in the current frame
with the specified name.

=cut

*/
inline op nqp_takedispatcher(in STR) :base_core {
if (current_dispatcher) {
PMC *lexpad = Parrot_pcc_get_lex_pad(interp, CURRENT_CONTEXT(interp));
VTABLE_set_pmc_keyed_str(interp, lexpad, $1, current_dispatcher);
current_dispatcher = NULL;
}
}

0 comments on commit e610165

Please sign in to comment.