root/src/obj_float.c

Revision 1ffd3187f60715d349b1be1c5328479b50dda298, 2.9 kB (checked in by redbrain <redbrain@…>, 2 years ago)

cleanups

  • Property mode set to 100644
Line 
1/**
2 * obj_float.c -> Part of Crules Programming language
3 *
4 * Crules is the legal property of its developers. Please refer to the
5 * COPYRIGHT file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21#ifdef HAVE_CONFIG_H
22# include "config.h"
23#else
24# define CMAKE 1
25# include "config.h.cmake"
26#endif
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31
32#include <gmp.h>
33#include <mpfr.h>
34#include <math.h>
35
36#include <crules/crules.h>
37#include <crules/opcodes.h>
38#include <crules/symbols.h>
39#include <crules/objects.h>
40#include <crules/backend.h>
41#include <crules/runtime.h>
42#include <crules/garbage.h>
43#include <crules/operators.h>
44
45static crl_type_float_t *
46crl_obj_float_init( crl_symbol_obj * args,
47                    crl_type_obj_def_t ** def )
48{
49  crl_type_float_t *s = crl_malloc( ((*def)->builtin_type_size) );
50  crl_assert( args->op_a_t == TYPE_FLOAT );
51  memcpy( &(s->f_float), &(args->op_a.floating_point),
52          sizeof(long double) );
53  return s;
54}
55
56crl_symbol_obj *
57crl_obj_float_to_string( crl_symbol_obj * caller, crl_symbol_obj * self,
58                         crl_context_table * caller_ctx,
59                         crl_context_table * function_ctx )
60{
61  return NULL;
62}
63
64bool crl_obj_float_print( crl_type_float_t * self, FILE * fd, bool newline )
65{
66  bool retval = true;
67  fprintf( fd, "%Lf", self->f_float );
68  if( newline )
69    {
70      fprintf( fd, "\n" );
71    }
72  return retval;
73}
74
75void crl_obj_float_destroy( crl_type_float_t * self )
76{
77  if( self )
78    {
79      crl_free( self );
80    }
81}
82
83struct crl_number_prot_t float_module_binary_ops = {
84  false,
85  NULL,
86  NULL,
87  NULL,
88  NULL,
89  NULL,
90  NULL,
91  NULL,
92  NULL,
93  NULL,
94  NULL,
95  NULL,
96  NULL,
97  NULL,
98};
99
100struct crl_builtin_function_def_t float_module_function_table[] = {
101  { "to_string", 0, &crl_obj_float_to_string },
102  { NULL, 0, NULL },
103} ;
104
105struct crl_builtin_member_def_t float_module_member_table[] = {
106  { 0, NULL },
107} ;
108
109struct crl_type_obj_def_t float_object = {
110  "Float",
111  sizeof( crl_type_float_t ),
112  &crl_obj_float_init,
113  &crl_obj_float_destroy,
114  &crl_obj_float_print,
115  NULL,
116  &float_module_binary_ops,
117  float_module_member_table,
118  float_module_function_table,
119  true,
120} ;
121
122bool crl_obj_float_module_init( crl_context_table * context )
123{
124  bool retval = false;
125  retval = crl_rr_context_intilize_module( &float_object, context );
126  return retval;
127}
Note: See TracBrowser for help on using the browser.