Skip to content

Commit

Permalink
Note presence of native types in the multi-dispatcher candidate graph…
Browse files Browse the repository at this point in the history
…; not doing anything with them yet.
  • Loading branch information
jnthn committed Sep 22, 2011
1 parent 33e65ba commit 952b7bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/binder/multidispatch.c
Expand Up @@ -156,7 +156,7 @@ static Rakudo_md_candidate_info** sort_candidates(PARROT_INTERP, PMC *candidates

/* Type information. */
info->types = mem_allocate_n_zeroed_typed(num_params + 1, PMC*);
info->definednesses = mem_allocate_n_zeroed_typed(num_params + 1, INTVAL);
info->type_flags = mem_allocate_n_zeroed_typed(num_params + 1, INTVAL);
info->constraints = mem_allocate_n_zeroed_typed(num_params + 1, PMC*);
significant_param = 0;

Expand Down Expand Up @@ -208,9 +208,15 @@ static Rakudo_md_candidate_info** sort_candidates(PARROT_INTERP, PMC *candidates
if (param->flags & SIG_ELEM_MULTI_INVOCANT)
info->num_types++;
if (param->flags & SIG_ELEM_DEFINED_ONLY)
info->definednesses[significant_param] = DEFCON_DEFINED;
info->type_flags[significant_param] = DEFCON_DEFINED;
else if (param->flags & SIG_ELEM_UNDEFINED_ONLY)
info->definednesses[significant_param] = DEFCON_UNDEFINED;
info->type_flags[significant_param] = DEFCON_UNDEFINED;
if (param->flags & SIG_ELEM_NATIVE_INT_VALUE)
info->type_flags[significant_param] += TYPE_NATIVE_INT;
else if (param->flags & SIG_ELEM_NATIVE_NUM_VALUE)
info->type_flags[significant_param] += TYPE_NATIVE_NUM;
else if (param->flags & SIG_ELEM_NATIVE_STR_VALUE)
info->type_flags[significant_param] += TYPE_NATIVE_STR;
significant_param++;
}

Expand Down Expand Up @@ -292,8 +298,8 @@ static Rakudo_md_candidate_info** sort_candidates(PARROT_INTERP, PMC *candidates
if (info) {
if (info->types)
mem_sys_free(info->types);
if (info->definednesses)
mem_sys_free(info->definednesses);
if (info->type_flags)
mem_sys_free(info->type_flags);
if (info->constraints)
mem_sys_free(info->constraints);
mem_sys_free(info);
Expand Down Expand Up @@ -618,9 +624,9 @@ static PMC* find_best_candidate(PARROT_INTERP, Rakudo_md_candidate_info **candid
type_mismatch = 1;
break;
}
else if ((*cur_candidate)->definednesses[i]) {
else if ((*cur_candidate)->type_flags[i] & DEFCON_MASK) {
INTVAL defined = REPR(param)->defined(interp, param);
INTVAL desired = (*cur_candidate)->definednesses[i];
INTVAL desired = (*cur_candidate)->type_flags[i] & DEFCON_MASK;
if ((defined && desired == DEFCON_UNDEFINED) ||
(!defined && desired == DEFCON_DEFINED)) {
type_mismatch = 1;
Expand Down
8 changes: 7 additions & 1 deletion src/binder/multidispatch.h
@@ -1,6 +1,12 @@
/* Flags we have on types. */
#define DEFCON_NONE 0
#define DEFCON_DEFINED 1
#define DEFCON_UNDEFINED 2
#define DEFCON_MASK (DEFCON_DEFINED | DEFCON_UNDEFINED)
#define TYPE_NATIVE_INT 4
#define TYPE_NATIVE_NUM 8
#define TYPE_NATIVE_STR 16
#define TYPE_NATIVE_MASK (TYPE_NATIVE_INT | TYPE_NATIVE_NUM | TYPE_NATIVE_STR)

/* This is how a Code looks on the inside. Once again, C struct that should
* match what P6opaque computes for the Code class. */
Expand All @@ -23,7 +29,7 @@ typedef struct {
PMC *sub; /* The sub that is the candidate. */
PMC *signature; /* The signature of the sub. */
PMC **types; /* Class or role type constraints for each parameter. */
INTVAL *definednesses; /* Definedness flags for each of the types. */
INTVAL *type_flags; /* Definedness and native flags for each of the types. */
PMC **constraints; /* Refinement type constraints for each parameter. */
INTVAL num_types; /* Number of entries in the above two arrays. */
INTVAL min_arity; /* Number of required positional arguments. */
Expand Down

0 comments on commit 952b7bb

Please sign in to comment.