Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Infrastructure to support calling a multi candidate determined at com…

…pile time, and not repeating arg type checks.
  • Loading branch information...
commit f910191dcc65747dcaa60faf7bc76ea0cfbe9b4f 1 parent d34c4e3
@jnthn jnthn authored
View
23 src/ops/perl6.ops
@@ -773,6 +773,29 @@ inline op perl6_multi_dispatch_thunk(out PMC, in PMC) :base_core {
/*
+=item perl6_multi_dispatch_cand_thunk()
+
+Creates a multi-dispatch thunk for calling the candidate at the specified
+index in the dispatchee list (for when we decided the candidate at compile
+time). Also implies that we won't re-do the type check in the binder.
+
+=cut
+
+*/
+inline op perl6_multi_dispatch_cand_thunk(out PMC, in PMC, in INT) :base_core {
+ Rakudo_Code *disp_obj = (Rakudo_Code *)PMC_data($2);
+ PMC *chosen = VTABLE_get_pmc_keyed_int(interp, disp_obj->dispatchees, $3);
+ Rakudo_Code *code_obj = (Rakudo_Code *)PMC_data(chosen);
+ if (PMC_IS_NULL(code_obj->md_thunk)) {
+ code_obj->md_thunk = pmc_new(interp, pmc_type(interp, Parrot_str_new(interp, "CTMThunk", 0)));
+ VTABLE_set_pmc(interp, code_obj->md_thunk, chosen);
+ }
+ $1 = code_obj->md_thunk;
+}
+
+
+/*
+
=item perl6_get_matching_multis()
Gets the multi dispatcher to find all candidates under the control of
View
42 src/pmc/ctmthunk.pmc
@@ -0,0 +1,42 @@
+/* Implements a thunk that calls a candidate from a multi, where the candidate
+ * to call was determined at compile time. */
+
+#include "../binder/multidispatch.h"
+
+/* Flag for not re-checking types in the binder. */
+#define PObj_P6BINDER_ALREADY_CHECKED_FLAG PObj_private0_FLAG
+
+pmclass CTMThunk
+ auto_attrs
+ dynpmc group perl6
+ hll perl6
+{
+ ATTR PMC *candidate;
+
+ VTABLE void init() {
+ PObj_custom_mark_SET(SELF);
+ }
+
+ VTABLE void set_pmc(PMC *cand) {
+ SET_ATTR_candidate(interp, SELF, cand);
+ }
+
+ VTABLE opcode_t* invoke(void *next) {
+ PMC *cand;
+ opcode_t *result;
+
+ /* Extract candidate. */
+ GET_ATTR_candidate(interp, SELF, cand);
+
+ /* Invoke it and mark it already checked. */
+ result = VTABLE_invoke(interp, cand, next);
+ PObj_flag_SET(P6BINDER_ALREADY_CHECKED, CURRENT_CONTEXT(interp));
+ return result;
+ }
+
+ VTABLE void mark() {
+ PMC *cand;
+ GET_ATTR_candidate(interp, SELF, cand);
+ Parrot_gc_mark_PMC_alive(INTERP, cand);
+ }
+}
View
2  tools/build/Makefile.in
@@ -84,7 +84,7 @@ DYNOPS = $(OPS_DIR)/$(OPS)$(LOAD_EXT)
PMC_SOURCES = \
$(PMC_DIR)/perl6lexinfo.pmc $(PMC_DIR)/perl6lexpad.pmc \
- $(PMC_DIR)/mdthunk.pmc \
+ $(PMC_DIR)/mdthunk.pmc $(PMC_DIR)/ctmthunk.pmc \
OPS_SOURCE = perl6.ops
Please sign in to comment.
Something went wrong with that request. Please try again.