fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / datatypes.c
blob7e0313776df2832a377b3c8c53f9166f11e2271b
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 Parrot_str_new_init(interp, s, strlen(s),
82 Parrot_default_encoding_ptr, PObj_external_FLAG);
87 =item C<FLOATVAL floatval_divide_by_zero(PARROT_INTERP, FLOATVAL num)>
89 Only used to generate Infinity and NaN constants in our corresponding
90 header file.
92 =cut
96 PARROT_EXPORT
97 FLOATVAL
98 floatval_divide_by_zero(SHIM_INTERP, FLOATVAL num)
100 ASSERT_ARGS(floatval_divide_by_zero)
101 const FLOATVAL zero = 0.0;
102 return num / zero;
108 =back
110 =head1 SEE ALSO
112 F<include/parrot/datatypes.h>.
114 =cut
120 * Local variables:
121 * c-file-style: "parrot"
122 * End:
123 * vim: expandtab shiftwidth=4: