Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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...
commit e6101657f63d6e1f0d3e273f4f135951df8597ff 1 parent c7c2297
@jnthn jnthn authored
Showing with 39 additions and 0 deletions.
  1. +2 −0  src/vm/parrot/QAST/Operations.nqp
  2. +37 −0 src/vm/parrot/ops/nqp.ops
View
2  src/vm/parrot/QAST/Operations.nqp
@@ -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');
View
37 src/vm/parrot/ops/nqp.ops
@@ -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
/*
@@ -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;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.