Skip to content

Commit

Permalink
[PMC] Tidied code in Perl6MultiSub PMC; no functional changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chromatic committed Mar 25, 2010
1 parent db9c0ea commit 4b7dbf3
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/pmc/perl6multisub.pmc
Expand Up @@ -214,13 +214,15 @@ static candidate_info** sort_candidates(PARROT_INTERP, PMC *candidates, PMC **pr
* is no ties ever, so a null between all of them, and then space
* for the terminating null. */
INTVAL num_candidates = VTABLE_elements(interp, candidates);
candidate_info** const result = mem_allocate_n_zeroed_typed(
candidate_info ** const result = mem_allocate_n_zeroed_typed(
2 * num_candidates + 1, candidate_info*);

/* Create a node for each candidate in the graph. */
candidate_graph_node** const graph = mem_allocate_n_zeroed_typed(
candidate_graph_node ** const graph = mem_allocate_n_zeroed_typed(
num_candidates, candidate_graph_node*);

INTVAL insert_pos = 0;

for (i = 0; i < num_candidates; i++) {
PMC *signature, *p6_do;
struct llsig_element **sig_elem_info;
Expand All @@ -243,7 +245,7 @@ static candidate_info** sort_candidates(PARROT_INTERP, PMC *candidates, PMC **pr
}

/* Otherwise, need an entry. */
info = mem_allocate_zeroed_typed(candidate_info);
info = mem_allocate_zeroed_typed(candidate_info);
info->sub = candidate;

/* Get hold of signature. */
Expand All @@ -266,9 +268,10 @@ static candidate_info** sort_candidates(PARROT_INTERP, PMC *candidates, PMC **pr
info->types = mem_allocate_n_zeroed_typed(sig_elems + 1, PMC*);
info->constraints = mem_allocate_n_zeroed_typed(sig_elems + 1, PMC*);
significant_param = 0;

for (j = 0; j < sig_elems; j++) {
/* If it's named (and not slurpy) don't need its type info but we will
* need a bindability check during the dispatch for it. */
/* If it's named (and not slurpy) don't need its type info but we
* will need a bindability check during the dispatch for it. */
if (!PMC_IS_NULL(sig_elem_info[j]->named_names)) {
if (!(sig_elem_info[j]->flags & SIG_ELEM_IS_OPTIONAL))
info->req_named = VTABLE_get_string_keyed_int(interp, sig_elem_info[j]->named_names, 0);
Expand Down Expand Up @@ -297,7 +300,7 @@ static candidate_info** sort_candidates(PARROT_INTERP, PMC *candidates, PMC **pr
}

/* Record type info for this parameter. */
info->types[significant_param] = sig_elem_info[j]->nominal_type;
info->types[significant_param] = sig_elem_info[j]->nominal_type;
info->constraints[significant_param] = sig_elem_info[j]->post_constraints;
if (!PMC_IS_NULL(info->constraints[significant_param]))
info->bind_check = 1;
Expand All @@ -307,10 +310,11 @@ static candidate_info** sort_candidates(PARROT_INTERP, PMC *candidates, PMC **pr
}

/* Add it to graph node, and initialize list of edges. */
graph[insert_pos] = mem_allocate_zeroed_typed(candidate_graph_node);
graph[insert_pos]->info = info;
graph[insert_pos] = mem_allocate_zeroed_typed(candidate_graph_node);
graph[insert_pos]->info = info;
graph[insert_pos]->edges = mem_allocate_n_zeroed_typed(
num_candidates, candidate_graph_node*);

insert_pos++;
}

Expand Down Expand Up @@ -361,8 +365,8 @@ static candidate_info** sort_candidates(PARROT_INTERP, PMC *candidates, PMC **pr
break;
}

/* Now we need to decrement edges in counts for things that had edges
* from candidates we added here. */
/* Now we need to decrement edges in counts for things that had
* edges from candidates we added here. */
for (i = 0; i < num_candidates; i++) {
if (graph[i]->edges_in == EDGE_REMOVAL_TODO) {
INTVAL j;
Expand Down Expand Up @@ -502,15 +506,16 @@ static PMC* do_dispatch(PARROT_INTERP, PMC *self, candidate_info **candidates, P
interp->current_cont = NEED_CONTINUATION;
Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), NULL);

/* First, if there's a required named parameter and it was not
* passed, we can very quickly eliminate this candidate without
* doing a full bindability check. */
/* First, if there's a required named parameter and it was
* not passed, we can very quickly eliminate this candidate
* without doing a full bindability check. */
if (possibles[i]->req_named) {
if (!VTABLE_exists_keyed_str(interp, capture, possibles[i]->req_named)) {
/* Required named arg not passed, so we eliminate it right
* here. Flag that we've built a list of new possibles, and
* that this was not a pure type-based result that we can
* cache. */
/* Required named arg not passed, so we eliminate
* it right here. Flag that we've built a list of
* new possibles, and that this was not a pure
* type-based result that we can cache. */

if (!new_possibles)
new_possibles = mem_allocate_n_typed(num_candidates, candidate_info *);
pure_type_result = 0;
Expand All @@ -520,8 +525,8 @@ static PMC* do_dispatch(PARROT_INTERP, PMC *self, candidate_info **candidates, P

/* Otherwise, may need full bind check. */
if (possibles[i]->bind_check) {
/* We'll invoke the sub (but not re-enter the runloop) and
* then attempt to bind the signature. */
/* We'll invoke the sub (but not re-enter the runloop)
* and then attempt to bind the signature. */
PMC *invokee = possibles[i]->sub->vtable->base_type == enum_class_Sub ?
possibles[i]->sub : VTABLE_get_attr_str(interp, possibles[i]->sub, CONST_STRING(interp, "$!do"));
opcode_t *where = VTABLE_invoke(interp, invokee, next);
Expand All @@ -547,7 +552,7 @@ static PMC* do_dispatch(PARROT_INTERP, PMC *self, candidate_info **candidates, P
new_possibles[new_possibles_count] = possibles[i];
new_possibles_count++;
}

/* Since we had to do a bindability check, this is not
* a result we can cache on nominal type. */
pure_type_result = 0;
Expand Down

0 comments on commit 4b7dbf3

Please sign in to comment.