~ubuntu-branches/ubuntu/raring/parrot/raring-proposed

« back to all changes in this revision

Viewing changes to src/multidispatch.c

  • Committer: Bazaar Package Importer
  • Author(s): Allison Randal
  • Date: 2011-07-30 18:45:03 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20110730184503-34d4mprtfx6pt5h3
Tags: 3.6.0-1
* New upstream release
* debian/watch:
  - Modified regular expression to capture numbered directory name
    (patch from Dominique Dumont).
* debian/rules:
  - Split build-arch and build-indep, resolving lintian warning.
  - Update path to pbc_disassemble for manpage generation (patch
    from Dominique Dumont).
* debian/patches:
  - Added patch 02_fix_perl_interpreter_path.patch, resolving
    lintian warnings.
* debian/control:
  - Added DM-Upload-Allowed field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
206
206
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
207
207
/* HEADERIZER END: static */
208
208
 
209
 
 
210
209
#define MMD_DEBUG 0
211
210
 
212
 
 
213
211
/*
214
212
 
215
213
=item C<PMC* Parrot_mmd_find_multi_from_sig_obj(PARROT_INTERP, STRING *name, PMC
305
303
    va_end(args);
306
304
}
307
305
 
308
 
 
309
306
/*
310
307
 
311
308
=item C<PMC * Parrot_mmd_find_multi_from_long_sig(PARROT_INTERP, STRING *name,
342
339
    }
343
340
}
344
341
 
345
 
 
346
342
/*
347
343
 
348
344
=item C<PMC * Parrot_mmd_sort_manhattan_by_sig_pmc(PARROT_INTERP, PMC
401
397
        INTVAL  type;
402
398
 
403
399
        if (STRING_equal(interp, type_name, CONST_STRING(interp, "DEFAULT")))
404
 
            type = enum_type_PMC;
 
400
            type = -enum_type_PMC;
405
401
        else if (STRING_equal(interp, type_name, CONST_STRING(interp, "STRING")))
406
 
            type = enum_type_STRING;
 
402
            type = -enum_type_STRING;
407
403
        else if (STRING_equal(interp, type_name, CONST_STRING(interp, "INTVAL")))
408
 
            type = enum_type_INTVAL;
 
404
            type = -enum_type_INTVAL;
409
405
        else if (STRING_equal(interp, type_name, CONST_STRING(interp, "FLOATVAL")))
410
 
            type = enum_type_FLOATVAL;
 
406
            type = -enum_type_FLOATVAL;
411
407
        else
412
408
            type = Parrot_pmc_get_type_str(interp, type_name);
413
409
 
417
413
    return multi_sig;
418
414
}
419
415
 
420
 
 
421
416
/*
422
417
 
423
418
=item C<static PMC* mmd_build_type_tuple_from_long_sig(PARROT_INTERP, STRING
441
436
    return mmd_build_type_tuple_from_type_list(interp, type_list);
442
437
}
443
438
 
444
 
 
445
439
/*
446
440
 
447
441
=item C<PMC* Parrot_mmd_build_type_tuple_from_sig_obj(PARROT_INTERP, PMC
464
458
    return VTABLE_get_pmc(interp, sig_obj);
465
459
}
466
460
 
467
 
 
468
461
/*
469
462
 
470
463
=item C<static PMC* mmd_cvt_to_types(PARROT_INTERP, PMC *multi_sig)>
526
519
    return ar;
527
520
}
528
521
 
529
 
 
530
522
/*
531
523
 
532
524
=item C<static PMC * Parrot_mmd_get_cached_multi_sig(PARROT_INTERP, PMC
569
561
    return PMCNULL;
570
562
}
571
563
 
572
 
 
573
564
#define MMD_BIG_DISTANCE 0x7fff
574
565
 
575
566
/*
654
645
         * weighing other things. A direct autobox should be cheaper than an
655
646
         * autobox plus type conversion or implicit type acceptance. */
656
647
        switch (type_call) {
657
 
          case enum_type_INTVAL:
 
648
          case -enum_type_INTVAL:
658
649
            if (type_sig == enum_class_Integer) { dist++; continue; }
659
 
            if (type_sig == enum_type_PMC ||
 
650
            if (type_sig == -enum_type_PMC ||
660
651
                (type_sig >= enum_class_default && type_sig < enum_class_core_max)) {
661
652
                ++dist;
662
653
                type_call = enum_class_Integer;
663
654
            }
664
655
            break;
665
 
          case enum_type_FLOATVAL:
 
656
          case -enum_type_FLOATVAL:
666
657
            if (type_sig == enum_class_Float)   { dist++; continue; }
667
 
            if (type_sig == enum_type_PMC ||
 
658
            if (type_sig == -enum_type_PMC ||
668
659
                (type_sig >= enum_class_default && type_sig < enum_class_core_max)) {
669
660
                ++dist;
670
661
                type_call = enum_class_Float;
671
662
            }
672
663
            break;
673
 
          case enum_type_STRING:
 
664
          case -enum_type_STRING:
674
665
            if (type_sig == enum_class_String)  { dist++; continue; }
675
 
            if (type_sig == enum_type_PMC ||
 
666
            if (type_sig == -enum_type_PMC ||
676
667
                (type_sig >= enum_class_default && type_sig < enum_class_core_max)) {
677
668
                ++dist;
678
669
                type_call = enum_class_String;
686
677
         * different native types are very different, except a PMC
687
678
         * which matches any PMC
688
679
         */
689
 
        if (type_call <= 0 && type_sig == enum_type_PMC) {
 
680
        if (type_call <= 0 && type_sig == -enum_type_PMC) {
690
681
            ++dist;
691
682
            continue;
692
683
        }
693
684
 
694
 
        if ((type_sig <= 0 && type_sig != enum_type_PMC) || type_call <= 0) {
 
685
        if ((type_sig <= 0 && type_sig != -enum_type_PMC) || type_call <= 0) {
695
686
            dist = MMD_BIG_DISTANCE;
696
687
            break;
697
688
        }
718
709
         * if the type wasn't in MRO check, if any PMC matches
719
710
         * in that case use the distance + 1 (of an any PMC parent)
720
711
         */
721
 
        if (j == m && type_sig != enum_type_PMC) {
 
712
        if (j == m && type_sig != -enum_type_PMC) {
722
713
            dist = MMD_BIG_DISTANCE;
723
714
            break;
724
715
        }
729
720
        {
730
721
            STRING *s1, *s2;
731
722
            if (type_sig < 0)
732
 
                s1 = Parrot_dt_get_datatype_name(interp, type_sig);
 
723
                s1 = Parrot_dt_get_datatype_name(interp, -type_sig);
733
724
            else
734
725
                s1 = interp->vtables[type_sig]->whoami;
735
726
 
736
727
            if (type_call < 0)
737
 
                s2 = Parrot_dt_get_datatype_name(interp, type_call);
 
728
                s2 = Parrot_dt_get_datatype_name(interp, -type_call);
738
729
            else
739
730
                s2 = interp->vtables[type_call]->whoami;
740
731
 
747
738
    return dist;
748
739
}
749
740
 
750
 
 
751
741
/*
752
742
 
753
743
=item C<static PMC * Parrot_mmd_sort_candidates(PARROT_INTERP, PMC *arg_tuple,
782
772
    return best_candidate;
783
773
}
784
774
 
785
 
 
786
775
/*
787
776
 
788
777
=item C<static int Parrot_mmd_maybe_candidate(PARROT_INTERP, PMC *pmc, PMC *cl)>
827
816
    return 0;
828
817
}
829
818
 
830
 
 
831
819
/*
832
820
 
833
821
=item C<static void mmd_search_by_sig_obj(PARROT_INTERP, STRING *name, PMC
864
852
    Parrot_mmd_maybe_candidate(interp, multi_sub, candidates);
865
853
}
866
854
 
867
 
 
868
855
/*
869
856
 
870
857
=item C<static void mmd_search_global(PARROT_INTERP, STRING *name, PMC *cl)>
890
877
    Parrot_mmd_maybe_candidate(interp, multi_sub, cl);
891
878
}
892
879
 
893
 
 
894
880
/*
895
881
 
896
882
=item C<static void mmd_add_multi_global(PARROT_INTERP, STRING *sub_name, PMC
921
907
    VTABLE_push_pmc(interp, multi_sub, sub_obj);
922
908
}
923
909
 
924
 
 
925
910
/*
926
911
 
927
912
=item C<static void mmd_add_multi_to_namespace(PARROT_INTERP, STRING *ns_name,
954
939
    VTABLE_push_pmc(interp, multi_sub, sub_obj);
955
940
}
956
941
 
957
 
 
958
942
/*
959
943
 
960
944
=item C<void Parrot_mmd_add_multi_from_long_sig(PARROT_INTERP, STRING *sub_name,
998
982
    mmd_add_multi_global(interp, sub_name, sub_obj);
999
983
}
1000
984
 
1001
 
 
1002
985
/*
1003
986
 
1004
987
=item C<void Parrot_mmd_add_multi_from_c_args(PARROT_INTERP, const char
1091
1074
    }
1092
1075
}
1093
1076
 
1094
 
 
1095
1077
/*
1096
1078
 
1097
1079
=item C<MMD_Cache * Parrot_mmd_cache_create(PARROT_INTERP)>
1113
1095
    return cache;
1114
1096
}
1115
1097
 
1116
 
 
1117
1098
/*
1118
1099
 
1119
1100
=item C<static STRING * mmd_cache_key_from_values(PARROT_INTERP, const char
1161
1142
    return key;
1162
1143
}
1163
1144
 
1164
 
 
1165
1145
/*
1166
1146
 
1167
1147
=item C<PMC * Parrot_mmd_cache_lookup_by_values(PARROT_INTERP, MMD_Cache *cache,
1189
1169
    return PMCNULL;
1190
1170
}
1191
1171
 
1192
 
 
1193
1172
/*
1194
1173
 
1195
1174
=item C<void Parrot_mmd_cache_store_by_values(PARROT_INTERP, MMD_Cache *cache,
1214
1193
        VTABLE_set_pmc_keyed_str(interp, cache, key, chosen);
1215
1194
}
1216
1195
 
1217
 
 
1218
1196
/*
1219
1197
 
1220
1198
=item C<static STRING * mmd_cache_key_from_types(PARROT_INTERP, const char
1264
1242
    return key;
1265
1243
}
1266
1244
 
1267
 
 
1268
1245
/*
1269
1246
 
1270
1247
=item C<PMC * Parrot_mmd_cache_lookup_by_types(PARROT_INTERP, MMD_Cache *cache,
1292
1269
    return PMCNULL;
1293
1270
}
1294
1271
 
1295
 
 
1296
1272
/*
1297
1273
 
1298
1274
=item C<void Parrot_mmd_cache_store_by_types(PARROT_INTERP, MMD_Cache *cache,
1318
1294
        VTABLE_set_pmc_keyed_str(interp, cache, key, chosen);
1319
1295
}
1320
1296
 
1321
 
 
1322
1297
/*
1323
1298
 
1324
1299
=item C<void Parrot_mmd_cache_mark(PARROT_INTERP, MMD_Cache *cache)>
1340
1315
    Parrot_gc_mark_PMC_alive(interp, cache);
1341
1316
}
1342
1317
 
1343
 
 
1344
1318
/*
1345
1319
 
1346
1320
=back
1348
1322
=head1 SEE ALSO
1349
1323
 
1350
1324
F<include/parrot/multidispatch.h>,
1351
 
F<http://svn.perl.org/perl6/doc/trunk/design/apo/A12.pod>,
1352
 
F<http://svn.perl.org/perl6/doc/trunk/design/syn/S12.pod>
 
1325
L<http://perlcabal.org/syn/S12.html>,
 
1326
L<http://dev.perl.org/perl6/doc/design/apo/A12.html>
1353
1327
 
1354
1328
=cut
1355
1329
 
1356
1330
*/
1357
1331
 
1358
 
 
1359
1332
/*
1360
1333
 * Local variables:
1361
1334
 *   c-file-style: "parrot"