Skip to content
This repository
tree: 210ad264c4
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 148 lines (97 sloc) 2.933 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
/*
Copyright (C) 2002-2009, Parrot Foundation.
License: Artistic 2.0, see README.pod and LICENSE for details

=head1 NAME

src/datatypes.c - Parrot and native data types functions

=head1 DESCRIPTION

The functions in this file are used in .ops files to access the C<enum>
and C string constants for Parrot and native data types defined in
F<include/parrot/datatypes.h>.

=head2 Functions

=over 4

=cut

*/

#include "parrot/parrot.h"

/* HEADERIZER HFILE: include/parrot/datatypes.h */

/*

=item C<INTVAL Parrot_dt_get_datatype_enum(PARROT_INTERP, STRING *type_name)>

Return datatype C<enum> for C<STRING*> type_name.

=cut

*/

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
INTVAL
Parrot_dt_get_datatype_enum(PARROT_INTERP, ARGIN(STRING *type_name))
{
    ASSERT_ARGS(Parrot_dt_get_datatype_enum)
    char *type;
    int flags = 0;
    int i;

    if (STRING_IS_NULL(type_name) || STRING_IS_EMPTY(type_name))
        return enum_type_undef;

    if ('&' == Parrot_str_indexed(interp, type_name, Parrot_str_length(interp, type_name) - 1)) {
        type_name = Parrot_str_substr(interp, type_name, 0,
                                        Parrot_str_length(interp, type_name) - 1);
        flags |= enum_type_ref_flag;
    }

    type = Parrot_str_to_cstring(interp, type_name);

    for (i = enum_first_type; i < enum_last_type; ++i) {
        if (STREQ(data_types[i - enum_first_type].name, type)) {
            Parrot_str_free_cstring(type);
            return i | flags;
        }
    }

    Parrot_str_free_cstring(type);

    return enum_type_undef;
}

/*

=item C<STRING * Parrot_dt_get_datatype_name(PARROT_INTERP, INTVAL type)>

Return datatype name for C<type>.

=cut

*/

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING *
Parrot_dt_get_datatype_name(PARROT_INTERP, INTVAL type)
{
    ASSERT_ARGS(Parrot_dt_get_datatype_name)
    const char *s;
    STRING *str;

    const int is_ref = type & enum_type_ref_flag;

    type &= ~enum_type_ref_flag;

    s = (type < enum_first_type || type >= enum_last_type)
            ? "illegal"
            : data_types[type - enum_first_type].name;

    str = Parrot_str_new_init(interp, s, strlen(s),
            Parrot_default_encoding_ptr, PObj_external_FLAG);

    return is_ref ? Parrot_str_concat(interp, str, Parrot_str_new(interp, "&", 0)) : str;
}

/*

=item C<FLOATVAL Parrot_dt_divide_floatval_by_zero(PARROT_INTERP, FLOATVAL num)>

Only used to generate Infinity and NaN constants in our corresponding
header file.

=cut

*/

#ifndef PARROT_HAS_INF_NAN

PARROT_EXPORT
FLOATVAL
Parrot_dt_divide_floatval_by_zero(SHIM_INTERP, FLOATVAL num)
{
    ASSERT_ARGS(Parrot_dt_divide_floatval_by_zero)
    const FLOATVAL zero = 0.0;
    return num / zero;
}

#endif


/*

=back

=head1 SEE ALSO

F<include/parrot/datatypes.h>.

=cut

*/


/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
*/
Something went wrong with that request. Please try again.