[t][TT #1119] Convert t/op/bitwise.t to PIR
[parrot.git] / src / datatypes.c
blobe238addf88e0ee26adb8dac26e0307a7138f869e
1 /*
2 Copyright (C) 2002-2009, Parrot Foundation.
3 License: Artistic 2.0, see README and LICENSE for details
4 $Id$
6 =head1 NAME
8 src/datatypes.c - Parrot and native data types functions
10 =head1 DESCRIPTION
12 The functions in this file are used in .ops files to access the C<enum>
13 and C string constants for Parrot and native data types defined in
14 F<include/parrot/datatypes.h>.
16 =head2 Functions
18 =over 4
20 =cut
24 #include "parrot/parrot.h"
26 /* HEADERIZER HFILE: include/parrot/datatypes.h */
30 =item C<INTVAL Parrot_get_datatype_enum(PARROT_INTERP, const STRING *type_name)>
32 Return datatype C<enum> for C<STRING*> type_name.
34 =cut
38 PARROT_EXPORT
39 PARROT_WARN_UNUSED_RESULT
40 INTVAL
41 Parrot_get_datatype_enum(PARROT_INTERP, ARGIN(const STRING *type_name))
43 ASSERT_ARGS(Parrot_get_datatype_enum)
44 char * const type = Parrot_str_to_cstring(interp, type_name);
45 int i;
47 for (i = enum_first_type; i < enum_last_type; i++) {
48 if (STREQ(data_types[i - enum_first_type].name, type)) {
49 Parrot_str_free_cstring(type);
50 return i;
54 Parrot_str_free_cstring(type);
56 return enum_type_undef;
61 =item C<STRING * Parrot_get_datatype_name(PARROT_INTERP, INTVAL type)>
63 Return datatype name for C<type>.
65 =cut
69 PARROT_EXPORT
70 PARROT_WARN_UNUSED_RESULT
71 PARROT_CANNOT_RETURN_NULL
72 STRING *
73 Parrot_get_datatype_name(PARROT_INTERP, INTVAL type)
75 ASSERT_ARGS(Parrot_get_datatype_name)
76 const char * const s =
77 (type < enum_first_type || type >= enum_last_type)
78 ? "illegal"
79 : data_types[type - enum_first_type].name;
81 return string_make(interp, s, strlen(s), NULL, PObj_external_FLAG);
86 =item C<FLOATVAL floatval_divide_by_zero(PARROT_INTERP, FLOATVAL num)>
88 Only used to generate Infinity and NaN constants in our corresponding
89 header file.
91 =cut
95 PARROT_EXPORT
96 FLOATVAL
97 floatval_divide_by_zero(SHIM_INTERP, FLOATVAL num)
99 ASSERT_ARGS(floatval_divide_by_zero)
100 const FLOATVAL zero = 0.0;
101 return num / zero;
107 =back
109 =head1 SEE ALSO
111 F<include/parrot/datatypes.h>.
113 =cut
119 * Local variables:
120 * c-file-style: "parrot"
121 * End:
122 * vim: expandtab shiftwidth=4: