~ubuntu-branches/ubuntu/raring/rakudo/raring

« back to all changes in this revision

Viewing changes to src/binder/bind.c

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-11-29 01:00:04 UTC
  • mfrom: (7.1.5 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121129010004-3vmbbb2e53up4u14
Tags: 2012.10-1build1
Rebuild with the current version of the Not Quite Perl compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
/* Cache of Parrot type IDs and some strings. */
17
17
static INTVAL smo_id            = 0;
18
18
static INTVAL p6l_id            = 0;
 
19
static INTVAL qrpa_id           = 0;
19
20
static STRING *ACCEPTS          = NULL;
20
21
static STRING *HOW              = NULL;
21
22
static STRING *DO_str           = NULL;
60
61
    NAMED_str        = Parrot_str_new_constant(interp, "named");
61
62
    INSTANTIATE_GENERIC_str = Parrot_str_new_constant(interp, "instantiate_generic");
62
63
    
63
 
    smo_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "SixModelObject", 0));
64
 
    p6l_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "Perl6LexPad", 0));
 
64
    smo_id  = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "SixModelObject", 0));
 
65
    p6l_id  = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "Perl6LexPad", 0));
 
66
    qrpa_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "QRPA", 0));
65
67
}
66
68
 
67
69
 
68
70
/* Gets the ID of a 6model object PMC. */
69
71
INTVAL Rakudo_smo_id(void) { return smo_id; }
70
72
 
 
73
/* Checks that a PMC is a native list object */
 
74
INTVAL Rakudo_isnqplist(PMC *pmc) {
 
75
    return (INTVAL)(pmc->vtable->base_type == qrpa_id
 
76
                    || pmc->vtable->base_type == enum_class_ResizablePMCArray);
 
77
}
 
78
 
71
79
 
72
80
/* Return the type we'd box a native value to. */
73
81
static PMC *
226
234
static void
227
235
Rakudo_binding_bind_type_captures(PARROT_INTERP, PMC *lexpad, Rakudo_Parameter *param, Rakudo_BindVal value) {
228
236
    PMC * type_obj = value.type == BIND_VAL_OBJ ?
229
 
        STABLE(value.val.o)->WHAT :
 
237
        STABLE(Rakudo_cont_decontainerize(interp, value.val.o))->WHAT :
230
238
        box_type(value);
231
239
    PMC * iter     = VTABLE_get_iter(interp, param->type_captures);
232
240
    while (VTABLE_get_bool(interp, iter)) {
308
316
    
309
317
    /* Check if boxed/unboxed expections are met. */
310
318
    desired_native = param->flags & SIG_ELEM_NATIVE_VALUE;
311
 
    if (desired_native == 0 && orig_bv.type == BIND_VAL_OBJ ||
312
 
        desired_native == SIG_ELEM_NATIVE_INT_VALUE && orig_bv.type == BIND_VAL_INT ||
313
 
        desired_native == SIG_ELEM_NATIVE_NUM_VALUE && orig_bv.type == BIND_VAL_NUM ||
314
 
        desired_native == SIG_ELEM_NATIVE_STR_VALUE && orig_bv.type == BIND_VAL_STR)
 
319
    if ((desired_native == 0 && orig_bv.type == BIND_VAL_OBJ) ||
 
320
        (desired_native == SIG_ELEM_NATIVE_INT_VALUE && orig_bv.type == BIND_VAL_INT) ||
 
321
        (desired_native == SIG_ELEM_NATIVE_NUM_VALUE && orig_bv.type == BIND_VAL_NUM) ||
 
322
        (desired_native == SIG_ELEM_NATIVE_STR_VALUE && orig_bv.type == BIND_VAL_STR))
315
323
    {
316
324
        /* We have what we want. */
317
325
        bv = orig_bv;
779
787
        PMC *captype   = Rakudo_types_capture_get();
780
788
        PMC *list_part = VTABLE_get_attr_keyed(interp, capture, captype, LIST_str);
781
789
        PMC *hash_part = VTABLE_get_attr_keyed(interp, capture, captype, HASH_str);
782
 
        capture = list_part->vtable->base_type == enum_class_ResizablePMCArray ?
783
 
                list_part : Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
 
790
        capture = Rakudo_isnqplist(list_part) 
 
791
                    ?  list_part 
 
792
                    : Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
784
793
        if (hash_part->vtable->base_type == enum_class_Hash) {
785
794
            PMC *iter = VTABLE_get_iter(interp, hash_part);
786
795
            named_args_copy = Parrot_pmc_new(interp, enum_class_Hash);
1097
1106
            else {
1098
1107
                /* If it's the wrong type of native, there's no way it
1099
1108
                 * can ever bind. */
1100
 
                if ((param->flags & SIG_ELEM_NATIVE_INT_VALUE) && got_prim != BIND_VAL_INT ||
1101
 
                    (param->flags & SIG_ELEM_NATIVE_NUM_VALUE) && got_prim != BIND_VAL_NUM ||
1102
 
                    (param->flags & SIG_ELEM_NATIVE_STR_VALUE) && got_prim != BIND_VAL_STR)
 
1109
                if (((param->flags & SIG_ELEM_NATIVE_INT_VALUE) && got_prim != BIND_VAL_INT) ||
 
1110
                    ((param->flags & SIG_ELEM_NATIVE_NUM_VALUE) && got_prim != BIND_VAL_NUM) ||
 
1111
                    ((param->flags & SIG_ELEM_NATIVE_STR_VALUE) && got_prim != BIND_VAL_STR))
1103
1112
                    return TRIAL_BIND_NO_WAY;
1104
1113
            }
1105
1114
        }